Skip to content

Backport #148214#189

Closed
wzssyqa wants to merge 1 commit into
rust-lang:rustc/21.1-2025-08-01from
wzssyqa:rustlang-bpo
Closed

Backport #148214#189
wzssyqa wants to merge 1 commit into
rust-lang:rustc/21.1-2025-08-01from
wzssyqa:rustlang-bpo

Conversation

@wzssyqa

@wzssyqa wzssyqa commented Sep 10, 2025

Copy link
Copy Markdown

Backport llvm#148214

[RISCV] Support PreserveMost calling convention (llvm#148214)

This adds the simplest implementation of PreserveMost calling convention and we preserve x5-x31 (except x6/x7/x28) registers.

Fixes llvm#148147.

This adds the simplest implementation of `PreserveMost` calling
convention and we preserve `x5-x31` (except x6/x7/x28) registers.

Fixes llvm#148147.
@nikic

nikic commented Sep 10, 2025

Copy link
Copy Markdown

Why is this being submitted as a backport against the Rust LLVM fork?

@wzssyqa

wzssyqa commented Sep 10, 2025

Copy link
Copy Markdown
Author

Why is this being submitted as a backport against the Rust LLVM fork?

tests/ui/abi/rust-cold-works-with-rustic-args.rs fails on riscv64gc-unknown-linux-gnu

--- stderr -------------------------------
rustc-LLVM ERROR: Unsupported calling convention
------------------------------------------

With this backport, this test can pass.

@dianqk

dianqk commented Sep 10, 2025

Copy link
Copy Markdown
Member

This shoud be backported to the upstream if possible. See also https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html.

@wzssyqa

wzssyqa commented Sep 13, 2025

Copy link
Copy Markdown
Author

See: llvm#158401

@wzssyqa

wzssyqa commented Sep 23, 2025

Copy link
Copy Markdown
Author

llvm#158402 has been merged.

@nikic nikic closed this Sep 23, 2025
@dianqk

dianqk commented Sep 23, 2025

Copy link
Copy Markdown
Member

rust-lang/rust#146953 includes this backport.

@wzssyqa wzssyqa deleted the rustlang-bpo branch September 24, 2025 00:37
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants