Skip to content

Commit 6568062

Browse files
authored
[MLIR][OpenMP] Improve assemblyFormat handling for clause-based ops (#108023)
This patch modifies the representation of `OpenMP_Clause` to allow definitions to incorporate both required and optional arguments while still allowing operations including them and overriding the `assemblyFormat` to take advantage of automatically-populated format strings. The proposed approach is to split the `assemblyFormat` clause property into `reqAssemblyFormat` and `optAssemblyFormat`, and remove the `isRequired` template and associated `required` property. The `OpenMP_Op` class, in turn, populates the new `clausesReqAssemblyFormat` and `clausesOptAssemblyFormat` properties in addition to `clausesAssemblyFormat`. These properties can be used by clause-based OpenMP operation definitions to reconstruct parts of the clause-inherited format string in a more flexible way when overriding it. Clause definitions are updated to follow this new approach and some operation definitions overriding the `assemblyFormat` are simplified by taking advantage of the improved flexibility, reducing code duplication. The `verify-openmp-ops` tablegen pass is updated for the new `OpenMP_Clause` representation. Some MLIR and Flang unit tests had to be updated due to changes to the default printing order of clauses on updated operations.
1 parent 8e10a3f commit 6568062

File tree

17 files changed

+290
-295
lines changed

17 files changed

+290
-295
lines changed

flang/test/Lower/OpenMP/atomic-read.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
!CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X_REF]] {uniq_name = "_QFEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
2626
!CHECK: %[[Y_REF:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
2727
!CHECK: %[[Y_DECL:.*]]:2 = hlfir.declare %[[Y_REF]] {uniq_name = "_QFEy"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
28-
!CHECK: omp.atomic.read %[[X_DECL]]#1 = %[[Y_DECL]]#1 memory_order(acquire) hint(uncontended) : !fir.ref<i32>, i32
28+
!CHECK: omp.atomic.read %[[X_DECL]]#1 = %[[Y_DECL]]#1 hint(uncontended) memory_order(acquire) : !fir.ref<i32>, i32
2929
!CHECK: omp.atomic.read %[[A_DECL]]#1 = %[[B_DECL]]#1 memory_order(relaxed) : !fir.ref<i32>, i32
30-
!CHECK: omp.atomic.read %[[C_DECL]]#1 = %[[D_DECL]]#1 memory_order(seq_cst) hint(contended) : !fir.ref<!fir.logical<4>>, !fir.logical<4>
30+
!CHECK: omp.atomic.read %[[C_DECL]]#1 = %[[D_DECL]]#1 hint(contended) memory_order(seq_cst) : !fir.ref<!fir.logical<4>>, !fir.logical<4>
3131
!CHECK: omp.atomic.read %[[E_DECL]]#1 = %[[F_DECL]]#1 hint(speculative) : !fir.ref<i32>, i32
3232
!CHECK: omp.atomic.read %[[G_DECL]]#1 = %[[H_DECL]]#1 hint(nonspeculative) : !fir.ref<f32>, f32
3333
!CHECK: omp.atomic.read %[[G_DECL]]#1 = %[[H_DECL]]#1 : !fir.ref<f32>, f32

flang/test/Lower/OpenMP/atomic-update.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ program OmpAtomicUpdate
9191
z = x * z
9292

9393
!CHECK: %[[VAL_c1:.*]] = arith.constant 1 : i32
94-
!CHECK: omp.atomic.update memory_order(relaxed) hint(uncontended) %[[VAL_X_DECLARE]]#1 : !fir.ref<i32> {
94+
!CHECK: omp.atomic.update hint(uncontended) memory_order(relaxed) %[[VAL_X_DECLARE]]#1 : !fir.ref<i32> {
9595
!CHECK: ^bb0(%[[ARG:.*]]: i32):
9696
!CHECK: %[[TEMP:.*]] = arith.subi %[[ARG]], %[[VAL_c1]] : i32
9797
!CHECK: omp.yield(%[[TEMP]] : i32)
@@ -113,7 +113,7 @@ program OmpAtomicUpdate
113113
y = max(y, c, d)
114114

115115
!CHECK: %[[VAL_X_LOADED:.*]] = fir.load %[[VAL_X_DECLARE]]#0 : !fir.ref<i32>
116-
!CHECK: omp.atomic.update memory_order(relaxed) hint(contended) %[[VAL_Z_DECLARE]]#1 : !fir.ref<i32> {
116+
!CHECK: omp.atomic.update hint(contended) memory_order(relaxed) %[[VAL_Z_DECLARE]]#1 : !fir.ref<i32> {
117117
!CHECK: ^bb0(%[[ARG:.*]]: i32):
118118
!CHECK: %[[TEMP:.*]] = arith.addi %[[ARG]], %[[VAL_X_LOADED]] : i32
119119
!CHECK: omp.yield(%[[TEMP]] : i32)
@@ -122,7 +122,7 @@ program OmpAtomicUpdate
122122
z = z + x
123123

124124
!CHECK: %[[VAL_c10:.*]] = arith.constant 10 : i32
125-
!CHECK: omp.atomic.update memory_order(release) hint(contended) %[[VAL_Z_DECLARE]]#1 : !fir.ref<i32> {
125+
!CHECK: omp.atomic.update hint(contended) memory_order(release) %[[VAL_Z_DECLARE]]#1 : !fir.ref<i32> {
126126
!CHECK: ^bb0(%[[ARG:.*]]: i32):
127127
!CHECK: %[[TEMP:.*]] = arith.muli %[[VAL_c10]], %[[ARG]] : i32
128128
!CHECK: omp.yield(%[[TEMP]] : i32)
@@ -131,7 +131,7 @@ program OmpAtomicUpdate
131131
z = z * 10
132132

133133
!CHECK: %[[VAL_Z_LOADED:.*]] = fir.load %[[VAL_Z_DECLARE]]#0 : !fir.ref<i32>
134-
!CHECK: omp.atomic.update memory_order(release) hint(speculative) %[[VAL_X_DECLARE]]#1 : !fir.ref<i32> {
134+
!CHECK: omp.atomic.update hint(speculative) memory_order(release) %[[VAL_X_DECLARE]]#1 : !fir.ref<i32> {
135135
!CHECK: ^bb0(%[[ARG:.*]]: i32):
136136
!CHECK: %[[TEMP:.*]] = arith.divsi %[[ARG]], %[[VAL_Z_LOADED]] : i32
137137
!CHECK: omp.yield(%[[TEMP]] : i32)

flang/test/Lower/OpenMP/parallel.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ subroutine parallel_multiple_clauses(alpha, num_threads)
194194
!CHECK: omp.terminator
195195
!$omp end parallel
196196

197-
!CHECK: omp.parallel if({{.*}}) num_threads({{.*}} : i32) allocate(
198-
!CHECK: %{{.+}} : i64 -> %{{.+}} : !fir.ref<i32>
199-
!CHECK: ) {
197+
!CHECK: omp.parallel allocate(%{{.+}} : i64 -> %{{.+}}#1 : !fir.ref<i32>)
198+
!CHECK: if({{.*}}) num_threads({{.*}} : i32)
199+
!CHECK: private(@{{.+}} %{{.+}}#0 -> %{{.+}} : !fir.ref<i32>) {
200200
!$omp parallel num_threads(num_threads) if(alpha .le. 0) allocate(omp_high_bw_mem_alloc: alpha) private(alpha)
201201
!CHECK: fir.call
202202
call f3()

flang/test/Lower/OpenMP/wsloop-chunks.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ program wsloop
2020
! CHECK: %[[VAL_3:.*]] = arith.constant 1 : i32
2121
! CHECK: %[[VAL_4:.*]] = arith.constant 9 : i32
2222
! CHECK: %[[VAL_5:.*]] = arith.constant 1 : i32
23-
! CHECK: omp.wsloop schedule(static = %[[VAL_2]] : i32) nowait {
23+
! CHECK: omp.wsloop nowait schedule(static = %[[VAL_2]] : i32) {
2424
! CHECK-NEXT: omp.loop_nest (%[[ARG0:.*]]) : i32 = (%[[VAL_3]]) to (%[[VAL_4]]) inclusive step (%[[VAL_5]]) {
2525
! CHECK: fir.store %[[ARG0]] to %[[STORE_IV:.*]]#1 : !fir.ref<i32>
2626
! CHECK: %[[LOAD_IV:.*]] = fir.load %[[STORE_IV]]#0 : !fir.ref<i32>
@@ -41,7 +41,7 @@ program wsloop
4141
! CHECK: %[[VAL_15:.*]] = arith.constant 1 : i32
4242
! CHECK: %[[VAL_16:.*]] = arith.constant 9 : i32
4343
! CHECK: %[[VAL_17:.*]] = arith.constant 1 : i32
44-
! CHECK: omp.wsloop schedule(static = %[[VAL_14]] : i32) nowait {
44+
! CHECK: omp.wsloop nowait schedule(static = %[[VAL_14]] : i32) {
4545
! CHECK-NEXT: omp.loop_nest (%[[ARG1:.*]]) : i32 = (%[[VAL_15]]) to (%[[VAL_16]]) inclusive step (%[[VAL_17]]) {
4646
! CHECK: fir.store %[[ARG1]] to %[[STORE_IV1:.*]]#1 : !fir.ref<i32>
4747
! CHECK: %[[VAL_24:.*]] = arith.constant 2 : i32
@@ -68,7 +68,7 @@ program wsloop
6868
! CHECK: %[[VAL_30:.*]] = arith.constant 1 : i32
6969
! CHECK: %[[VAL_31:.*]] = arith.constant 9 : i32
7070
! CHECK: %[[VAL_32:.*]] = arith.constant 1 : i32
71-
! CHECK: omp.wsloop schedule(static = %[[VAL_29]] : i32) nowait {
71+
! CHECK: omp.wsloop nowait schedule(static = %[[VAL_29]] : i32) {
7272
! CHECK-NEXT: omp.loop_nest (%[[ARG2:.*]]) : i32 = (%[[VAL_30]]) to (%[[VAL_31]]) inclusive step (%[[VAL_32]]) {
7373
! CHECK: fir.store %[[ARG2]] to %[[STORE_IV2:.*]]#1 : !fir.ref<i32>
7474
! CHECK: %[[VAL_39:.*]] = arith.constant 3 : i32

flang/test/Lower/OpenMP/wsloop-monotonic.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ program wsloop_dynamic
1515
!CHECK: %[[WS_LB:.*]] = arith.constant 1 : i32
1616
!CHECK: %[[WS_UB:.*]] = arith.constant 9 : i32
1717
!CHECK: %[[WS_STEP:.*]] = arith.constant 1 : i32
18-
!CHECK: omp.wsloop schedule(dynamic, monotonic) nowait {
18+
!CHECK: omp.wsloop nowait schedule(dynamic, monotonic) {
1919
!CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[WS_LB]]) to (%[[WS_UB]]) inclusive step (%[[WS_STEP]]) {
2020
!CHECK: fir.store %[[I]] to %[[ALLOCA_IV:.*]]#1 : !fir.ref<i32>
2121

flang/test/Lower/OpenMP/wsloop-nonmonotonic.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ program wsloop_dynamic
1717
!CHECK: %[[WS_LB:.*]] = arith.constant 1 : i32
1818
!CHECK: %[[WS_UB:.*]] = arith.constant 9 : i32
1919
!CHECK: %[[WS_STEP:.*]] = arith.constant 1 : i32
20-
!CHECK: omp.wsloop schedule(dynamic, nonmonotonic) nowait {
20+
!CHECK: omp.wsloop nowait schedule(dynamic, nonmonotonic) {
2121
!CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[WS_LB]]) to (%[[WS_UB]]) inclusive step (%[[WS_STEP]]) {
2222
!CHECK: fir.store %[[I]] to %[[ALLOCA_IV]]#1 : !fir.ref<i32>
2323

flang/test/Lower/OpenMP/wsloop-schedule.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ program wsloop_dynamic
1414
!CHECK: %[[WS_LB:.*]] = arith.constant 1 : i32
1515
!CHECK: %[[WS_UB:.*]] = arith.constant 9 : i32
1616
!CHECK: %[[WS_STEP:.*]] = arith.constant 1 : i32
17-
!CHECK: omp.wsloop schedule(runtime, simd) nowait {
17+
!CHECK: omp.wsloop nowait schedule(runtime, simd) {
1818
!CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[WS_LB]]) to (%[[WS_UB]]) inclusive step (%[[WS_STEP]]) {
1919
!CHECK: fir.store %[[I]] to %[[STORE:.*]]#1 : !fir.ref<i32>
2020

flang/test/Lower/OpenMP/wsloop.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ subroutine loop_with_schedule_nowait
6464
! CHECK: %[[WS_LB:.*]] = arith.constant 1 : i32
6565
! CHECK: %[[WS_UB:.*]] = arith.constant 9 : i32
6666
! CHECK: %[[WS_STEP:.*]] = arith.constant 1 : i32
67-
! CHECK: omp.wsloop schedule(runtime) nowait {
67+
! CHECK: omp.wsloop nowait schedule(runtime) {
6868
! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[WS_LB]]) to (%[[WS_UB]]) inclusive step (%[[WS_STEP]]) {
6969
!$OMP DO SCHEDULE(runtime)
7070
do i=1, 9

0 commit comments

Comments
 (0)