Skip to content

Commit ebf3eb9

Browse files
committed
[flang][OpenMP] Enable lastprivate on simd
1 parent 1034b4d commit ebf3eb9

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
199199
for (const omp::Clause &clause : clauses) {
200200
if (clause.id != llvm::omp::OMPC_lastprivate)
201201
continue;
202-
// TODO: Add lastprivate support for simd construct
203-
if (mlir::isa<mlir::omp::WsloopOp>(op)) {
202+
if (mlir::isa<mlir::omp::WsloopOp>(op) or
203+
mlir::isa<mlir::omp::SimdOp>(op)) {
204204
// Update the original variable just before exiting the worksharing
205205
// loop. Conversion as follows:
206206
//
207-
// omp.wsloop { omp.wsloop {
207+
// omp.wsloop / omp.simd { omp.wsloop / omp.simd {
208208
// omp.loop_nest { omp.loop_nest {
209209
// ... ...
210210
// store ===> store

flang/test/Lower/OpenMP/simd.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,30 @@ subroutine simd_with_collapse_clause(n)
182182
end do
183183
!$OMP END SIMD
184184
end subroutine
185+
186+
!CHECK: func.func @_QPlastprivate_with_simd() {
187+
subroutine lastprivate_with_simd
188+
189+
!CHECK: %[[VAR_SUM:.*]] = fir.alloca f32 {bindc_name = "sum", uniq_name = "_QFlastprivate_with_simdEsum"}
190+
!CHECK: %[[VAR_SUM_DECLARE:.*]]:2 = hlfir.declare %[[VAR_SUM]] {{.*}}
191+
!CHECK: %[[VAR_SUM_PINNED:.*]] = fir.alloca f32 {bindc_name = "sum", pinned, uniq_name = "_QFlastprivate_with_simdEsum"}
192+
!CHECK: %[[VAR_SUM_PINNED_DECLARE:.*]]:2 = hlfir.declare %[[VAR_SUM_PINNED]] {{.*}}
193+
implicit none
194+
integer :: i
195+
real :: sum
196+
197+
!CHECK: omp.simd {
198+
!CHECK: omp.loop_nest (%[[ARG:.*]]) : i32 = ({{.*}} to ({{.*}}) inclusive step ({{.*}}) {
199+
!CHECK: %[[ADD_RESULT:.*]] = arith.addi {{.*}}
200+
!CHECK: %[[ADD_RESULT_CONVERT:.*]] = fir.convert %[[ADD_RESULT]] : (i32) -> f32
201+
!CHECK: hlfir.assign %[[ADD_RESULT_CONVERT]] to %[[VAR_SUM_PINNED_DECLARE]]#0 : f32, !fir.ref<f32>
202+
!$omp simd lastprivate(sum)
203+
do i = 1, 100
204+
sum = i + 1
205+
end do
206+
!CHECK: %[[SELECT_RESULT:.*]] = arith.select {{.*}}, {{.*}}, {{.*}} : i1
207+
!CHECK: fir.if %[[SELECT_RESULT]] {
208+
!CHECK: %[[LOADED_SUM:.*]] = fir.load %[[VAR_SUM_PINNED_DECLARE]]#0 : !fir.ref<f32>
209+
!CHECK: hlfir.assign %[[LOADED_SUM]] to %[[VAR_SUM_DECLARE]]#0 temporary_lhs : f32, !fir.ref<f32>
210+
!CHECK: }
211+
end subroutine

0 commit comments

Comments
 (0)