Backport #148214#189
Closed
wzssyqa wants to merge 1 commit into
Closed
Conversation
This adds the simplest implementation of `PreserveMost` calling convention and we preserve `x5-x31` (except x6/x7/x28) registers. Fixes llvm#148147.
|
Why is this being submitted as a backport against the Rust LLVM fork? |
Author
With this backport, this test can pass. |
Member
|
This shoud be backported to the upstream if possible. See also https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html. |
Author
|
See: llvm#158401 |
Author
|
llvm#158402 has been merged. |
Member
|
rust-lang/rust#146953 includes this backport. |
nikic
pushed a commit
to nikic/llvm-project
that referenced
this pull request
Apr 19, 2026
Flang uses the OMPIRBuilder to lower OpenMP constructs to LLVM IR. When dealing with work sharing constructs, such as DO, DISTRIBUTE or SECTIONS/SECTION, OMPIRBuilder needs to construct the call to the OpenMP runtime, typically `__kmpc_for_static_init` or `__kmpc_dist_for_static_init`. The first passed flag to these functions is the `ident_t` struct, defined in `kmp.h`. Most of the arguments are reserved for usage in Fortran and unused in `openmp`. However, the `flags` argument is used throughout the code base to identify specific constructs, such as the type of work sharing construct. In llvm#112545, it was identified that Flang does not provide the correct `ident_t` flags when calling into e.g. `__kmpc_for_static_init`, causing the following runtime warning to appear when the OpenMP Tools Interface is used: ``` OMP: Warning rust-lang#189: OMPT: Cannot determine workshare type; using the default (loop) instead. This issue is fixed in an up-to-date compiler. ``` This PR adds a test, verifying that the work sharing constructs provide the correct flags to the runtime call. The IR check for SECTIONS/SECTION maps against `KMP_IDENT_WORK_LOOP`, as the OMPIRBuilder converts the SECTIONS construct into a DO loop with a switch-case for every SECTION clause. In addition, `OMPIRBuilder` is modified, so that the work loop type is passed via `ident_t.flags` to the respective `__kmpc_for_static_init`/`__kmpc_dist_for_static_init` calls, letting the test pass and the `libomp` warning disappear. Wherever possible, provide the mapping based on the passed `LoopType`. If not available, I implemented the decision based on the `DistScheduleSchedType`, or in case of `applyDynamicWorkshareLoop`, hard-coded this to `OMP_IDENT_FLAG_WORK_LOOP`. --- As this is the first time dealing with `OMPIRBuilder`, I'm not sure if I missed anything while implementing these changes. If there's anything that can be improved here, e.g. with the ident flag mapping, I'm very grateful for any feedback. I tried to implement this with the best of my understanding based on taking a look at the existing code and tests. For example, I was not sure if adding a test to `flang/test/Integration/OpenMP/` is the correct approach here, or if I rather should try to modify `unittests/Frontend/OpenMPIRBuilderTest.cpp`. In the end, the former looked to me more straight-forward. --- Fixes llvm#112545 --------- Signed-off-by: Jan André Reuter <j.reuter@fz-juelich.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport llvm#148214
[RISCV] Support PreserveMost calling convention (llvm#148214)
This adds the simplest implementation of
PreserveMostcalling convention and we preservex5-x31(except x6/x7/x28) registers.Fixes llvm#148147.