Skip to content

Commit 0a17bdf

Browse files
authored
[MLIR][OpenMP] Remove terminators from loop wrappers (#112229)
This patch simplifies the representation of OpenMP loop wrapper operations by introducing the `NoTerminator` trait and updating accordingly the verifier for the `LoopWrapperInterface`. Since loop wrappers are already limited to having exactly one region containing exactly one block, and this block can only hold a single `omp.loop_nest` or loop wrapper and an `omp.terminator` that does not return any values, it makes sense to simplify the representation of loop wrappers by removing the terminator. There is an extensive list of Lit tests that needed updating to remove the `omp.terminator`s adding some noise to this patch, but actual changes are limited to the definition of the `omp.wsloop`, `omp.simd`, `omp.distribute` and `omp.taskloop` loop wrapper ops, Flang lowering for those, `LoopWrapperInterface::verifyImpl()`, SCF to OpenMP conversion and OpenMP dialect documentation.
1 parent f035d9f commit 0a17bdf

File tree

84 files changed

+50
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+50
-485
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,19 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
195195
// Update the original variable just before exiting the worksharing
196196
// loop. Conversion as follows:
197197
//
198-
// omp.wsloop / omp.simd { omp.wsloop / omp.simd {
199-
// omp.loop_nest { omp.loop_nest {
200-
// ... ...
201-
// store ===> store
202-
// omp.yield %v = arith.addi %iv, %step
203-
// } %cmp = %step < 0 ? %v < %ub : %v > %ub
204-
// omp.terminator fir.if %cmp {
205-
// } fir.store %v to %loopIV
206-
// ^%lpv_update_blk:
198+
// omp.wsloop / omp.simd { omp.wsloop / omp.simd {
199+
// omp.loop_nest { omp.loop_nest {
200+
// ... ...
201+
// store ===> store
202+
// omp.yield %v = arith.addi %iv, %step
203+
// } %cmp = %step < 0 ? %v < %ub : %v > %ub
204+
// } fir.if %cmp {
205+
// fir.store %v to %loopIV
206+
// ^%lpv_update_blk:
207+
// }
208+
// omp.yield
207209
// }
208-
// omp.yield
209210
// }
210-
// omp.terminator
211-
// }
212211

213212
// Only generate the compare once in presence of multiple LastPrivate
214213
// clauses.

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,9 +1094,6 @@ static OpTy genWrapperOp(lower::AbstractConverter &converter,
10941094
// Create entry block with arguments.
10951095
genEntryBlock(converter, args, op.getRegion());
10961096

1097-
firOpBuilder.setInsertionPoint(
1098-
lower::genOpenMPTerminator(firOpBuilder, op, loc));
1099-
11001097
return op;
11011098
}
11021099

flang/test/Fir/convert-to-llvm-openmp-and-fir.fir

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func.func @_QPsb1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref<!
1717
fir.store %3 to %6 : !fir.ref<i32>
1818
omp.yield
1919
}
20-
omp.terminator
2120
}
2221
omp.terminator
2322
}
@@ -43,7 +42,6 @@ func.func @_QPsb1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref<!
4342
// CHECK: llvm.store %[[I1]], %[[ARR_I_REF]] : i32, !llvm.ptr
4443
// CHECK: omp.yield
4544
// CHECK: }
46-
// CHECK: omp.terminator
4745
// CHECK: }
4846
// CHECK: omp.terminator
4947
// CHECK: }
@@ -93,7 +91,6 @@ func.func @_QPsb(%arr: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "arr"}) {
9391
fir.store %indx to %3 : !fir.ref<i32>
9492
omp.yield
9593
}
96-
omp.terminator
9794
}
9895
omp.terminator
9996
}
@@ -110,7 +107,6 @@ func.func @_QPsb(%arr: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "arr"}) {
110107
// CHECK-NEXT: omp.loop_nest (%[[INDX:.*]]) : i32 = (%[[C1]]) to (%[[C50]]) inclusive step (%[[C1]]) {
111108
// CHECK: llvm.store %[[INDX]], %{{.*}} : i32, !llvm.ptr
112109
// CHECK: omp.yield
113-
// CHECK: omp.terminator
114110
// CHECK: omp.terminator
115111
// CHECK: llvm.return
116112

@@ -200,7 +196,6 @@ func.func @_QPsimd1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref
200196
fir.store %3 to %6 : !fir.ref<i32>
201197
omp.yield
202198
}
203-
omp.terminator
204199
}
205200
omp.terminator
206201
}
@@ -226,7 +221,6 @@ func.func @_QPsimd1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref
226221
// CHECK: llvm.store %[[I1]], %[[ARR_I_REF]] : i32, !llvm.ptr
227222
// CHECK: omp.yield
228223
// CHECK: }
229-
// CHECK: omp.terminator
230224
// CHECK: }
231225
// CHECK: omp.terminator
232226
// CHECK: }
@@ -519,7 +513,6 @@ func.func @_QPsimd_with_nested_loop() {
519513
fir.store %7 to %3 : !fir.ref<i32>
520514
omp.yield
521515
}
522-
omp.terminator
523516
}
524517
return
525518
}
@@ -540,7 +533,6 @@ func.func @_QPsimd_with_nested_loop() {
540533
// CHECK: ^bb3:
541534
// CHECK: omp.yield
542535
// CHECK: }
543-
// CHECK: omp.terminator
544536
// CHECK: }
545537
// CHECK: llvm.return
546538
// CHECK: }
@@ -736,7 +728,6 @@ func.func @_QPsb() {
736728
// CHECK: %[[RES_EXT:.*]] = llvm.zext %[[RES]] : i1 to i32
737729
// CHECK: llvm.store %[[RES_EXT]], %[[PRV]] : i32, !llvm.ptr
738730
// CHECK: omp.yield
739-
// CHECK: omp.terminator
740731
// CHECK: omp.terminator
741732
// CHECK: llvm.return
742733

@@ -781,7 +772,6 @@ func.func @_QPsimple_reduction(%arg0: !fir.ref<!fir.array<100x!fir.logical<4>>>
781772
fir.store %11 to %prv : !fir.ref<!fir.logical<4>>
782773
omp.yield
783774
}
784-
omp.terminator
785775
}
786776
omp.terminator
787777
}

flang/test/Lower/OpenMP/Todo/omp-default-clause-inner-loop.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
! CHECK: fir.store %[[result]] to %{{.*}} : !fir.ref<i32>
2525
! CHECK: omp.yield
2626
! CHECK: }
27-
! CHECK: omp.terminator
2827
! CHECK: }
2928
! CHECK: omp.terminator
3029
! CHECK: }

flang/test/Lower/OpenMP/copyin.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ subroutine copyin_derived_type()
166166
! CHECK: fir.call @_QPsub4(%[[VAL_9]]#1) fastmath<contract> : (!fir.ref<i32>) -> ()
167167
! CHECK: omp.yield
168168
! CHECK: }
169-
! CHECK: omp.terminator
170169
! CHECK: }
171170
! CHECK: omp.terminator
172171
! CHECK: }
@@ -338,7 +337,6 @@ subroutine common_1()
338337
! CHECK: hlfir.assign %[[VAL_40]] to %[[VAL_31]]#0 : i32, !fir.ref<i32>
339338
! CHECK: omp.yield
340339
! CHECK: }
341-
! CHECK: omp.terminator
342340
! CHECK: }
343341
! CHECK: omp.terminator
344342
! CHECK: }

flang/test/Lower/OpenMP/default-clause-byref.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ subroutine skipped_default_clause_checks()
350350
!CHECK-NEXT: omp.loop_nest (%[[ARG:.*]]) {{.*}} {
351351
!CHECK: omp.yield
352352
!CHECK: }
353-
!CHECK: omp.terminator
354353
!CHECK: }
355354
!CHECK: omp.terminator
356355
!CHECK: }

flang/test/Lower/OpenMP/default-clause.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ subroutine skipped_default_clause_checks()
390390
!CHECK-NEXT: omp.loop_nest (%[[ARG:.*]]) {{.*}} {
391391
!CHECK: omp.yield
392392
!CHECK: }
393-
!CHECK: omp.terminator
394393
!CHECK: }
395394
!CHECK: omp.terminator
396395
!CHECK: }

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ subroutine simple_loop
2222
print*, i
2323
end do
2424
! CHECK: omp.yield
25-
! CHECK: omp.terminator
2625
!$OMP END DO
2726
! CHECK: omp.terminator
2827
!$OMP END PARALLEL

flang/test/Lower/OpenMP/lastprivate-commonblock.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
!CHECK: }
3333
!CHECK: omp.yield
3434
!CHECK: }
35-
!CHECK: omp.terminator
3635
!CHECK: }
3736
subroutine lastprivate_common
3837
common /c/ x, y

flang/test/Lower/OpenMP/lastprivate-iv.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
!CHECK: }
2929
!CHECK: omp.yield
3030
!CHECK: }
31-
!CHECK: omp.terminator
3231
!CHECK: }
3332
subroutine lastprivate_iv_inc()
3433
integer :: i
@@ -66,7 +65,6 @@ subroutine lastprivate_iv_inc()
6665
!CHECK: }
6766
!CHECK: omp.yield
6867
!CHECK: }
69-
!CHECK: omp.terminator
7068
!CHECK: }
7169
subroutine lastprivate_iv_dec()
7270
integer :: i

flang/test/Lower/OpenMP/location.f90

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ subroutine sub_loop()
3535
print *, i
3636
!CHECK: omp.yield loc(#[[LOOP_LOC:.*]])
3737
!CHECK: } loc(#[[LOOP_LOC]])
38-
!CHECK: omp.terminator loc(#[[LOOP_LOC]])
3938
!CHECK: } loc(#[[LOOP_LOC]])
4039
end do
4140
!$omp end do
@@ -64,8 +63,8 @@ subroutine sub_if(c)
6463
!CHECK: #[[PAR_LOC]] = loc("{{.*}}location.f90":9:9)
6564
!CHECK: #[[TAR_LOC]] = loc("{{.*}}location.f90":21:9)
6665
!CHECK: #[[LOOP_LOC]] = loc("{{.*}}location.f90":33:9)
67-
!CHECK: #[[BAR_LOC]] = loc("{{.*}}location.f90":47:9)
68-
!CHECK: #[[TW_LOC]] = loc("{{.*}}location.f90":49:9)
69-
!CHECK: #[[TY_LOC]] = loc("{{.*}}location.f90":51:9)
70-
!CHECK: #[[IF_LOC]] = loc("{{.*}}location.f90":58:14)
71-
!CHECK: #[[TASK_LOC]] = loc("{{.*}}location.f90":58:9)
66+
!CHECK: #[[BAR_LOC]] = loc("{{.*}}location.f90":46:9)
67+
!CHECK: #[[TW_LOC]] = loc("{{.*}}location.f90":48:9)
68+
!CHECK: #[[TY_LOC]] = loc("{{.*}}location.f90":50:9)
69+
!CHECK: #[[IF_LOC]] = loc("{{.*}}location.f90":57:14)
70+
!CHECK: #[[TASK_LOC]] = loc("{{.*}}location.f90":57:9)

flang/test/Lower/OpenMP/parallel-lastprivate-clause-scalar.f90

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
!CHECK: }
4242
!CHECK: omp.yield
4343
!CHECK: }
44-
!CHECK: omp.terminator
4544
!CHECK: }
4645

4746
subroutine lastprivate_character(arg1)
@@ -80,7 +79,6 @@ subroutine lastprivate_character(arg1)
8079
!CHECK: }
8180
!CHECK: omp.yield
8281
!CHECK: }
83-
!CHECK: omp.terminator
8482
!CHECK: }
8583

8684
subroutine lastprivate_int(arg1)
@@ -124,7 +122,6 @@ subroutine lastprivate_int(arg1)
124122
!CHECK: }
125123
!CHECK: omp.yield
126124
!CHECK: }
127-
!CHECK: omp.terminator
128125
!CHECK: }
129126

130127
subroutine mult_lastprivate_int(arg1, arg2)
@@ -169,7 +166,6 @@ subroutine mult_lastprivate_int(arg1, arg2)
169166
!CHECK: }
170167
!CHECK: omp.yield
171168
!CHECK: }
172-
!CHECK: omp.terminator
173169
!CHECK: }
174170

175171
subroutine mult_lastprivate_int2(arg1, arg2)
@@ -217,7 +213,6 @@ subroutine mult_lastprivate_int2(arg1, arg2)
217213
!CHECK-NEXT: }
218214
!CHECK-NEXT: omp.yield
219215
!CHECK-NEXT: }
220-
!CHECK-NEXT: omp.terminator
221216
!CHECK-NEXT: }
222217

223218
subroutine firstpriv_lastpriv_int(arg1, arg2)
@@ -265,7 +260,6 @@ subroutine firstpriv_lastpriv_int(arg1, arg2)
265260
!CHECK-NEXT: }
266261
!CHECK-NEXT: omp.yield
267262
!CHECK-NEXT: }
268-
!CHECK-NEXT: omp.terminator
269263
!CHECK-NEXT: }
270264

271265
subroutine firstpriv_lastpriv_int2(arg1)

flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
! CHECK: fir.store %[[VAL_12]]#1 to %[[PRIV_J_DECL]]#1 : !fir.ref<i32>
9292
! CHECK: omp.yield
9393
! CHECK: }
94-
! CHECK: omp.terminator
9594
! CHECK: }
9695
! CHECK: omp.terminator
9796
! CHECK: }

flang/test/Lower/OpenMP/parallel-private-clause.f90

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ subroutine simple_loop_1
272272
print*, i
273273
end do
274274
! FIRDialect: omp.yield
275-
! FIRDialect: omp.terminator
276275
!$OMP END DO
277276
! FIRDialect: omp.terminator
278277
!$OMP END PARALLEL
@@ -306,7 +305,6 @@ subroutine simple_loop_2
306305
print*, i
307306
end do
308307
! FIRDialect: omp.yield
309-
! FIRDialect: omp.terminator
310308
! FIRDialect: {{%.*}} = fir.load %[[R_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
311309
! FIRDialect: fir.if {{%.*}} {
312310
! FIRDialect: [[LD:%.*]] = fir.load %[[R_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
@@ -346,7 +344,6 @@ subroutine simple_loop_3
346344
print*, i
347345
end do
348346
! FIRDialect: omp.yield
349-
! FIRDialect: omp.terminator
350347
! FIRDialect: {{%.*}} = fir.load [[R_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
351348
! FIRDialect: fir.if {{%.*}} {
352349
! FIRDialect: [[LD:%.*]] = fir.load [[R_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>

flang/test/Lower/OpenMP/parallel-reduction-allocatable-array.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ program reduce
115115
! CHECK: hlfir.assign %[[VAL_26]] to %[[VAL_29]] : i32, !fir.ref<i32>
116116
! CHECK: omp.yield
117117
! CHECK: }
118-
! CHECK: omp.terminator
119118
! CHECK: }
120119
! CHECK: omp.terminator
121120
! CHECK: }

flang/test/Lower/OpenMP/parallel-reduction-pointer-array.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ program reduce
127127
! CHECK: hlfir.assign %[[VAL_36]] to %[[VAL_39]] : i32, !fir.ref<i32>
128128
! CHECK: omp.yield
129129
! CHECK: }
130-
! CHECK: omp.terminator
131130
! CHECK: }
132131
! CHECK: omp.terminator
133132
! CHECK: }

flang/test/Lower/OpenMP/parallel-reduction3.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
! CHECK: hlfir.destroy %[[VAL_28]] : !hlfir.expr<?xi32>
103103
! CHECK: omp.yield
104104
! CHECK: }
105-
! CHECK: omp.terminator
106105
! CHECK: }
107106
! CHECK: omp.terminator
108107
! CHECK: }

flang/test/Lower/OpenMP/parallel-wsloop-firstpriv.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ subroutine omp_do_firstprivate(a)
2929
! CHECK-NEXT: fir.call @_QPfoo(%[[I_PVT_DECL]]#1, %[[A_PVT_DECL]]#1) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> ()
3030
! CHECK-NEXT: omp.yield
3131
! CHECK-NEXT: }
32-
! CHECK-NEXT: omp.terminator
3332
! CHECK-NEXT: }
3433
do i=1, a
3534
call foo(i, a)
@@ -70,7 +69,6 @@ subroutine omp_do_firstprivate2(a, n)
7069
! CHECK: fir.store %[[ARG2]] to %[[I_PVT_DECL]]#1 : !fir.ref<i32>
7170
! CHECK: fir.call @_QPfoo(%[[I_PVT_DECL]]#1, %[[A_PVT_DECL]]#1) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> ()
7271
! CHECK: omp.yield
73-
! CHECK: omp.terminator
7472
do i= a, n
7573
call foo(i, a)
7674
end do

flang/test/Lower/OpenMP/parallel-wsloop-lastpriv.f90

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ subroutine omp_do_lastprivate(a)
3939

4040
! CHECK-NEXT: omp.yield
4141
! CHECK-NEXT: }
42-
! CHECK-NEXT: omp.terminator
4342
! CHECK-NEXT: }
4443
do i=1, a
4544
call foo(i, a)
@@ -90,7 +89,6 @@ subroutine omp_do_lastprivate2(a, n)
9089
! CHECK: }
9190

9291
! CHECK: omp.yield
93-
! CHECK: omp.terminator
9492
do i= a, n
9593
call foo(i, a)
9694
end do
@@ -148,7 +146,6 @@ subroutine omp_do_lastprivate_collapse2(a)
148146

149147
! CHECK-NEXT: omp.yield
150148
! CHECK-NEXT: }
151-
! CHECK-NEXT: omp.terminator
152149
! CHECK-NEXT: }
153150
do i=1, a
154151
do j=1, a
@@ -224,7 +221,6 @@ subroutine omp_do_lastprivate_collapse3(a)
224221

225222
! CHECK-NEXT: omp.yield
226223
! CHECK-NEXT: }
227-
! CHECK-NEXT: omp.terminator
228224
! CHECK-NEXT: }
229225
do i=1, a
230226
do j=1, a

0 commit comments

Comments
 (0)