[llvm-branch-commits] [flang] [flang][OpenMP] Support lowering of metadirective (part 2) (PR #194424)
Abid Qadeer via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue May 26 02:25:56 PDT 2026
================
@@ -70,3 +74,250 @@ subroutine test_begin_condition_false()
x = 1
!$omp end metadirective
end subroutine
+
+!===----------------------------------------------------------------------===!
+! Dynamic (runtime) user conditions
+!===----------------------------------------------------------------------===!
+
+! CHECK-LABEL: func.func @_QPtest_dynamic_condition(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.logical<4>>
+! CHECK: %[[DECL:.*]]:2 = hlfir.declare %[[ARG0]]
+! CHECK: %[[LOAD:.*]] = fir.load %[[DECL]]#0
+! CHECK: %[[COND:.*]] = fir.convert %[[LOAD]] : (!fir.logical<4>) -> i1
+! CHECK: fir.if %[[COND]] {
+! CHECK: omp.barrier
+! CHECK: } else {
+! CHECK: }
+! CHECK: return
+subroutine test_dynamic_condition(flag)
+ logical, intent(in) :: flag
+ !$omp metadirective &
+ !$omp & when(user={condition(flag)}: barrier) &
+#ifdef OMP_52
+ !$omp & otherwise(nothing)
+#else
+ !$omp & default(nothing)
+#endif
+end subroutine
+
+! CHECK-LABEL: func.func @_QPtest_dynamic_condition_expr(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<i32>
+! CHECK: %[[DECL:.*]]:2 = hlfir.declare %[[ARG0]]
+! CHECK: %[[LOAD:.*]] = fir.load %[[DECL]]#0
+! CHECK: %[[C1000:.*]] = arith.constant 1000 : i32
+! CHECK: %[[CMP:.*]] = arith.cmpi sgt, %[[LOAD]], %[[C1000]] : i32
+! CHECK: fir.if %[[CMP]] {
+! CHECK: omp.barrier
+! CHECK: } else {
+! CHECK: }
----------------
abidh wrote:
```suggestion
! CHECK-NEXT: }
```
https://github.com/llvm/llvm-project/pull/194424
More information about the llvm-branch-commits
mailing list