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

0 commit comments

Comments
 (0)