[all-commits] [llvm/llvm-project] 70256d: [flang][OpenMP] Support lowering of metadirective ...
Chi-Chun, Chen via All-commits
all-commits at lists.llvm.org
Wed Jun 3 20:40:22 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 70256dff97f1393c0bceb6c90c0341215d2ba598
https://github.com/llvm/llvm-project/commit/70256dff97f1393c0bceb6c90c0341215d2ba598
Author: Chi-Chun, Chen <chichun.chen at hpe.com>
Date: 2026-06-03 (Wed, 03 Jun 2026)
Changed paths:
M flang/lib/Lower/OpenMP/OpenMP.cpp
M flang/lib/Lower/OpenMP/Utils.cpp
M flang/lib/Lower/OpenMP/Utils.h
R flang/test/Lower/OpenMP/Todo/metadirective-dynamic.f90
M flang/test/Lower/OpenMP/metadirective-user.f90
M flang/test/Semantics/OpenMP/metadirective-user.f90
Log Message:
-----------
[flang][OpenMP] Support lowering of metadirective (part 2) (#194424)
Lower non-constant `user={condition(expr)}` selectors in OpenMP
metadirectives to a runtime `fir.if` / `else` selection cascade.
Dynamic user conditions are handled in two separate phases:
- Static applicability uses only selector traits that are known at
compile time.
- Guarded ranking preserves selector specificity and dynamic-condition
scores for the path where the runtime condition evaluates to true.
Lowering first filters candidates using compile-time selector traits,
then orders the remaining candidates with the normal OpenMP variant
ranking rules. If the selected candidate has a non-constant user
condition, that condition is emitted as a `fir.if` guard. When the
condition evaluates to false, the `else` branch continues selection
among the remaining candidates.
For example:
```fortran
!$omp metadirective &
!$omp & when(user={condition(score(100): high)}: barrier) &
!$omp & when(user={condition(low)}: taskwait) &
!$omp & otherwise(nothing)
```
is selected as:
```text
if (high) barrier
else if (low) taskwait
else nothing
```
Scores attached to dynamic `condition(score(...): expr)` selectors are
preserved for the guarded candidate. As a result, those scores affect
ranking only on the runtime path where the condition is true, instead of
allowing a false runtime condition to influence unconditional selection.
This also fixes the interactions with `extension(match_any)` and
`extension(match_none)`:
- `match_any` can be satisfied by a runtime condition when no static
trait matches.
- If static traits already satisfy `match_any`, the dynamic condition
score is used only when the condition is true.
- `match_none` keeps the dynamic condition inactive for static
applicability while still preserving its score for ranking.
For example, this `match_any` selector is statically applicable through
`vendor(llvm)`, but the score on `flag` is used only when `flag`
evaluates to true:
```fortran
!$omp metadirective &
!$omp & when(implementation={extension(match_any), vendor(llvm)}, &
!$omp & user={condition(score(100): flag)}: barrier) &
!$omp & when(user={condition(score(10): .true.)}: taskwait) &
!$omp & otherwise(nothing)
```
is selected as:
```text
if (flag) barrier
else taskwait
```
The final fallback is the highest-ranked unguarded candidate, an
explicit `otherwise` / `default` clause, or implicit `nothing`.
This patch is part of the feature work for #188820 and is stacked on top
of [#193664](https://github.com/llvm/llvm-project/pull/193664).
Assisted with Copilot and GPT-5.4.
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