Skip to content

Commit

Permalink
[MLIR][OpenMP] Remove terminators from loop wrappers (llvm#112229)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skatrak authored Oct 15, 2024
1 parent f035d9f commit 0a17bdf
Show file tree
Hide file tree
Showing 84 changed files with 50 additions and 485 deletions.
23 changes: 11 additions & 12 deletions flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,19 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
// Update the original variable just before exiting the worksharing
// loop. Conversion as follows:
//
// omp.wsloop / omp.simd { omp.wsloop / omp.simd {
// omp.loop_nest { omp.loop_nest {
// ... ...
// store ===> store
// omp.yield %v = arith.addi %iv, %step
// } %cmp = %step < 0 ? %v < %ub : %v > %ub
// omp.terminator fir.if %cmp {
// } fir.store %v to %loopIV
// ^%lpv_update_blk:
// omp.wsloop / omp.simd { omp.wsloop / omp.simd {
// omp.loop_nest { omp.loop_nest {
// ... ...
// store ===> store
// omp.yield %v = arith.addi %iv, %step
// } %cmp = %step < 0 ? %v < %ub : %v > %ub
// } fir.if %cmp {
// fir.store %v to %loopIV
// ^%lpv_update_blk:
// }
// omp.yield
// }
// omp.yield
// }
// omp.terminator
// }

// Only generate the compare once in presence of multiple LastPrivate
// clauses.
Expand Down
3 changes: 0 additions & 3 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,9 +1094,6 @@ static OpTy genWrapperOp(lower::AbstractConverter &converter,
// Create entry block with arguments.
genEntryBlock(converter, args, op.getRegion());

firOpBuilder.setInsertionPoint(
lower::genOpenMPTerminator(firOpBuilder, op, loc));

return op;
}

Expand Down
10 changes: 0 additions & 10 deletions flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func.func @_QPsb1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref<!
fir.store %3 to %6 : !fir.ref<i32>
omp.yield
}
omp.terminator
}
omp.terminator
}
Expand All @@ -43,7 +42,6 @@ func.func @_QPsb1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref<!
// CHECK: llvm.store %[[I1]], %[[ARR_I_REF]] : i32, !llvm.ptr
// CHECK: omp.yield
// CHECK: }
// CHECK: omp.terminator
// CHECK: }
// CHECK: omp.terminator
// CHECK: }
Expand Down Expand Up @@ -93,7 +91,6 @@ func.func @_QPsb(%arr: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "arr"}) {
fir.store %indx to %3 : !fir.ref<i32>
omp.yield
}
omp.terminator
}
omp.terminator
}
Expand All @@ -110,7 +107,6 @@ func.func @_QPsb(%arr: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "arr"}) {
// CHECK-NEXT: omp.loop_nest (%[[INDX:.*]]) : i32 = (%[[C1]]) to (%[[C50]]) inclusive step (%[[C1]]) {
// CHECK: llvm.store %[[INDX]], %{{.*}} : i32, !llvm.ptr
// CHECK: omp.yield
// CHECK: omp.terminator
// CHECK: omp.terminator
// CHECK: llvm.return

Expand Down Expand Up @@ -200,7 +196,6 @@ func.func @_QPsimd1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref
fir.store %3 to %6 : !fir.ref<i32>
omp.yield
}
omp.terminator
}
omp.terminator
}
Expand All @@ -226,7 +221,6 @@ func.func @_QPsimd1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref
// CHECK: llvm.store %[[I1]], %[[ARR_I_REF]] : i32, !llvm.ptr
// CHECK: omp.yield
// CHECK: }
// CHECK: omp.terminator
// CHECK: }
// CHECK: omp.terminator
// CHECK: }
Expand Down Expand Up @@ -519,7 +513,6 @@ func.func @_QPsimd_with_nested_loop() {
fir.store %7 to %3 : !fir.ref<i32>
omp.yield
}
omp.terminator
}
return
}
Expand All @@ -540,7 +533,6 @@ func.func @_QPsimd_with_nested_loop() {
// CHECK: ^bb3:
// CHECK: omp.yield
// CHECK: }
// CHECK: omp.terminator
// CHECK: }
// CHECK: llvm.return
// CHECK: }
Expand Down Expand Up @@ -736,7 +728,6 @@ func.func @_QPsb() {
// CHECK: %[[RES_EXT:.*]] = llvm.zext %[[RES]] : i1 to i32
// CHECK: llvm.store %[[RES_EXT]], %[[PRV]] : i32, !llvm.ptr
// CHECK: omp.yield
// CHECK: omp.terminator
// CHECK: omp.terminator
// CHECK: llvm.return

Expand Down Expand Up @@ -781,7 +772,6 @@ func.func @_QPsimple_reduction(%arg0: !fir.ref<!fir.array<100x!fir.logical<4>>>
fir.store %11 to %prv : !fir.ref<!fir.logical<4>>
omp.yield
}
omp.terminator
}
omp.terminator
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
! CHECK: fir.store %[[result]] to %{{.*}} : !fir.ref<i32>
! CHECK: omp.yield
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
Expand Down
2 changes: 0 additions & 2 deletions flang/test/Lower/OpenMP/copyin.f90
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ subroutine copyin_derived_type()
! CHECK: fir.call @_QPsub4(%[[VAL_9]]#1) fastmath<contract> : (!fir.ref<i32>) -> ()
! CHECK: omp.yield
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
Expand Down Expand Up @@ -338,7 +337,6 @@ subroutine common_1()
! CHECK: hlfir.assign %[[VAL_40]] to %[[VAL_31]]#0 : i32, !fir.ref<i32>
! CHECK: omp.yield
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
Expand Down
1 change: 0 additions & 1 deletion flang/test/Lower/OpenMP/default-clause-byref.f90
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ subroutine skipped_default_clause_checks()
!CHECK-NEXT: omp.loop_nest (%[[ARG:.*]]) {{.*}} {
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }
!CHECK: omp.terminator
!CHECK: }
Expand Down
1 change: 0 additions & 1 deletion flang/test/Lower/OpenMP/default-clause.f90
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ subroutine skipped_default_clause_checks()
!CHECK-NEXT: omp.loop_nest (%[[ARG:.*]]) {{.*}} {
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }
!CHECK: omp.terminator
!CHECK: }
Expand Down
1 change: 0 additions & 1 deletion flang/test/Lower/OpenMP/hlfir-wsloop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ subroutine simple_loop
print*, i
end do
! CHECK: omp.yield
! CHECK: omp.terminator
!$OMP END DO
! CHECK: omp.terminator
!$OMP END PARALLEL
Expand Down
1 change: 0 additions & 1 deletion flang/test/Lower/OpenMP/lastprivate-commonblock.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
!CHECK: }
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }
subroutine lastprivate_common
common /c/ x, y
Expand Down
2 changes: 0 additions & 2 deletions flang/test/Lower/OpenMP/lastprivate-iv.f90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
!CHECK: }
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }
subroutine lastprivate_iv_inc()
integer :: i
Expand Down Expand Up @@ -66,7 +65,6 @@ subroutine lastprivate_iv_inc()
!CHECK: }
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }
subroutine lastprivate_iv_dec()
integer :: i
Expand Down
11 changes: 5 additions & 6 deletions flang/test/Lower/OpenMP/location.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ subroutine sub_loop()
print *, i
!CHECK: omp.yield loc(#[[LOOP_LOC:.*]])
!CHECK: } loc(#[[LOOP_LOC]])
!CHECK: omp.terminator loc(#[[LOOP_LOC]])
!CHECK: } loc(#[[LOOP_LOC]])
end do
!$omp end do
Expand Down Expand Up @@ -64,8 +63,8 @@ subroutine sub_if(c)
!CHECK: #[[PAR_LOC]] = loc("{{.*}}location.f90":9:9)
!CHECK: #[[TAR_LOC]] = loc("{{.*}}location.f90":21:9)
!CHECK: #[[LOOP_LOC]] = loc("{{.*}}location.f90":33:9)
!CHECK: #[[BAR_LOC]] = loc("{{.*}}location.f90":47:9)
!CHECK: #[[TW_LOC]] = loc("{{.*}}location.f90":49:9)
!CHECK: #[[TY_LOC]] = loc("{{.*}}location.f90":51:9)
!CHECK: #[[IF_LOC]] = loc("{{.*}}location.f90":58:14)
!CHECK: #[[TASK_LOC]] = loc("{{.*}}location.f90":58:9)
!CHECK: #[[BAR_LOC]] = loc("{{.*}}location.f90":46:9)
!CHECK: #[[TW_LOC]] = loc("{{.*}}location.f90":48:9)
!CHECK: #[[TY_LOC]] = loc("{{.*}}location.f90":50:9)
!CHECK: #[[IF_LOC]] = loc("{{.*}}location.f90":57:14)
!CHECK: #[[TASK_LOC]] = loc("{{.*}}location.f90":57:9)
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
!CHECK: }
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }

subroutine lastprivate_character(arg1)
Expand Down Expand Up @@ -80,7 +79,6 @@ subroutine lastprivate_character(arg1)
!CHECK: }
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }

subroutine lastprivate_int(arg1)
Expand Down Expand Up @@ -124,7 +122,6 @@ subroutine lastprivate_int(arg1)
!CHECK: }
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }

subroutine mult_lastprivate_int(arg1, arg2)
Expand Down Expand Up @@ -169,7 +166,6 @@ subroutine mult_lastprivate_int(arg1, arg2)
!CHECK: }
!CHECK: omp.yield
!CHECK: }
!CHECK: omp.terminator
!CHECK: }

subroutine mult_lastprivate_int2(arg1, arg2)
Expand Down Expand Up @@ -217,7 +213,6 @@ subroutine mult_lastprivate_int2(arg1, arg2)
!CHECK-NEXT: }
!CHECK-NEXT: omp.yield
!CHECK-NEXT: }
!CHECK-NEXT: omp.terminator
!CHECK-NEXT: }

subroutine firstpriv_lastpriv_int(arg1, arg2)
Expand Down Expand Up @@ -265,7 +260,6 @@ subroutine firstpriv_lastpriv_int(arg1, arg2)
!CHECK-NEXT: }
!CHECK-NEXT: omp.yield
!CHECK-NEXT: }
!CHECK-NEXT: omp.terminator
!CHECK-NEXT: }

subroutine firstpriv_lastpriv_int2(arg1)
Expand Down
1 change: 0 additions & 1 deletion flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
! CHECK: fir.store %[[VAL_12]]#1 to %[[PRIV_J_DECL]]#1 : !fir.ref<i32>
! CHECK: omp.yield
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
Expand Down
3 changes: 0 additions & 3 deletions flang/test/Lower/OpenMP/parallel-private-clause.f90
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ subroutine simple_loop_1
print*, i
end do
! FIRDialect: omp.yield
! FIRDialect: omp.terminator
!$OMP END DO
! FIRDialect: omp.terminator
!$OMP END PARALLEL
Expand Down Expand Up @@ -306,7 +305,6 @@ subroutine simple_loop_2
print*, i
end do
! FIRDialect: omp.yield
! FIRDialect: omp.terminator
! FIRDialect: {{%.*}} = fir.load %[[R_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
! FIRDialect: fir.if {{%.*}} {
! FIRDialect: [[LD:%.*]] = fir.load %[[R_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
Expand Down Expand Up @@ -346,7 +344,6 @@ subroutine simple_loop_3
print*, i
end do
! FIRDialect: omp.yield
! FIRDialect: omp.terminator
! FIRDialect: {{%.*}} = fir.load [[R_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
! FIRDialect: fir.if {{%.*}} {
! FIRDialect: [[LD:%.*]] = fir.load [[R_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<f32>>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ program reduce
! CHECK: hlfir.assign %[[VAL_26]] to %[[VAL_29]] : i32, !fir.ref<i32>
! CHECK: omp.yield
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ program reduce
! CHECK: hlfir.assign %[[VAL_36]] to %[[VAL_39]] : i32, !fir.ref<i32>
! CHECK: omp.yield
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
1 change: 0 additions & 1 deletion flang/test/Lower/OpenMP/parallel-reduction3.f90
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
! CHECK: hlfir.destroy %[[VAL_28]] : !hlfir.expr<?xi32>
! CHECK: omp.yield
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
! CHECK: }
Expand Down
2 changes: 0 additions & 2 deletions flang/test/Lower/OpenMP/parallel-wsloop-firstpriv.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ subroutine omp_do_firstprivate(a)
! CHECK-NEXT: fir.call @_QPfoo(%[[I_PVT_DECL]]#1, %[[A_PVT_DECL]]#1) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> ()
! CHECK-NEXT: omp.yield
! CHECK-NEXT: }
! CHECK-NEXT: omp.terminator
! CHECK-NEXT: }
do i=1, a
call foo(i, a)
Expand Down Expand Up @@ -70,7 +69,6 @@ subroutine omp_do_firstprivate2(a, n)
! CHECK: fir.store %[[ARG2]] to %[[I_PVT_DECL]]#1 : !fir.ref<i32>
! CHECK: fir.call @_QPfoo(%[[I_PVT_DECL]]#1, %[[A_PVT_DECL]]#1) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>) -> ()
! CHECK: omp.yield
! CHECK: omp.terminator
do i= a, n
call foo(i, a)
end do
Expand Down
4 changes: 0 additions & 4 deletions flang/test/Lower/OpenMP/parallel-wsloop-lastpriv.f90
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ subroutine omp_do_lastprivate(a)

! CHECK-NEXT: omp.yield
! CHECK-NEXT: }
! CHECK-NEXT: omp.terminator
! CHECK-NEXT: }
do i=1, a
call foo(i, a)
Expand Down Expand Up @@ -90,7 +89,6 @@ subroutine omp_do_lastprivate2(a, n)
! CHECK: }

! CHECK: omp.yield
! CHECK: omp.terminator
do i= a, n
call foo(i, a)
end do
Expand Down Expand Up @@ -148,7 +146,6 @@ subroutine omp_do_lastprivate_collapse2(a)

! CHECK-NEXT: omp.yield
! CHECK-NEXT: }
! CHECK-NEXT: omp.terminator
! CHECK-NEXT: }
do i=1, a
do j=1, a
Expand Down Expand Up @@ -224,7 +221,6 @@ subroutine omp_do_lastprivate_collapse3(a)

! CHECK-NEXT: omp.yield
! CHECK-NEXT: }
! CHECK-NEXT: omp.terminator
! CHECK-NEXT: }
do i=1, a
do j=1, a
Expand Down
Loading

0 comments on commit 0a17bdf

Please sign in to comment.