[all-commits] [llvm/llvm-project] 0d20c8: [OMPIRBuilder] Pass work loop type in ident flags ...
Jan André Reuter via All-commits
all-commits at lists.llvm.org
Tue Apr 14 05:32:39 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0d20c873ddaa6699083510d77a749bf96046de7c
https://github.com/llvm/llvm-project/commit/0d20c873ddaa6699083510d77a749bf96046de7c
Author: Jan André Reuter <j.reuter at fz-juelich.de>
Date: 2026-04-14 (Tue, 14 Apr 2026)
Changed paths:
M clang/test/OpenMP/cancel_codegen.cpp
M clang/test/OpenMP/irbuilder_for_iterator.cpp
M clang/test/OpenMP/irbuilder_for_rangefor.cpp
M clang/test/OpenMP/irbuilder_for_unsigned.c
M clang/test/OpenMP/irbuilder_for_unsigned_auto.c
M clang/test/OpenMP/irbuilder_for_unsigned_down.c
M clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c
M clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c
M clang/test/OpenMP/irbuilder_for_unsigned_runtime.c
M clang/test/OpenMP/irbuilder_for_unsigned_static_chunked.c
M clang/test/OpenMP/irbuilder_nested_parallel_for.c
M clang/test/OpenMP/irbuilder_unroll_partial_factor_for.c
M clang/test/OpenMP/irbuilder_unroll_partial_heuristic_constant_for.c
M clang/test/OpenMP/irbuilder_unroll_partial_heuristic_runtime_for.c
M clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c
M clang/test/OpenMP/nested_loop_codegen.cpp
A flang/test/Integration/OpenMP/workshare-ident-flag.f90
M llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
M llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
M mlir/test/Target/LLVMIR/omptarget-parallel-wsloop.mlir
M mlir/test/Target/LLVMIR/openmp-cancel-distribute-parallel-loop.mlir
M mlir/test/Target/LLVMIR/openmp-cancel.mlir
M mlir/test/Target/LLVMIR/openmp-cancellation-point.mlir
M mlir/test/Target/LLVMIR/openmp-composite-simd-if.mlir
M mlir/test/Target/LLVMIR/openmp-dist_schedule_with_wsloop.mlir
M mlir/test/Target/LLVMIR/openmp-llvm.mlir
M mlir/test/Target/LLVMIR/openmp-reduction-array-sections.mlir
M mlir/test/Target/LLVMIR/openmp-reduction-sections.mlir
M mlir/test/Target/LLVMIR/openmp-simd-guided.mlir
Log Message:
-----------
[OMPIRBuilder] Pass work loop type in ident flags (#189347)
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 https://github.com/llvm/llvm-project/issues/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 #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 https://github.com/llvm/llvm-project/issues/112545
---------
Signed-off-by: Jan André Reuter <j.reuter at fz-juelich.de>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list