Skip to content

Commit a693b9d

Browse files
Revert "Revert "[flang][OpenMP] Support delayed privatisation for composite do simd (llvm#150979)""
This reverts commit 26db529.
1 parent de20dbc commit a693b9d

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,7 +3092,6 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
30923092
/*shouldCollectPreDeterminedSymbols=*/true,
30933093
/*useDelayedPrivatization=*/false, symTable);
30943094
dsp.processStep1();
3095-
dsp.processStep2();
30963095

30973096
// Pass the innermost leaf construct's clauses because that's where COLLAPSE
30983097
// is placed by construct decomposition.
@@ -3143,12 +3142,16 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
31433142
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
31443143
simdReductionSyms);
31453144

3146-
// TODO: Support delayed privatization.
3147-
DataSharingProcessor dsp(converter, semaCtx, simdItem->clauses, eval,
3148-
/*shouldCollectPreDeterminedSymbols=*/true,
3149-
/*useDelayedPrivatization=*/false, symTable);
3150-
dsp.processStep1();
3151-
dsp.processStep2();
3145+
DataSharingProcessor wsloopItemDSP(
3146+
converter, semaCtx, doItem->clauses, eval,
3147+
/*shouldCollectPreDeterminedSymbols=*/false,
3148+
/*useDelayedPrivatization=*/true, symTable);
3149+
wsloopItemDSP.processStep1(&wsloopClauseOps);
3150+
3151+
DataSharingProcessor simdItemDSP(converter, semaCtx, simdItem->clauses, eval,
3152+
/*shouldCollectPreDeterminedSymbols=*/true,
3153+
/*useDelayedPrivatization=*/true, symTable);
3154+
simdItemDSP.processStep1(&simdClauseOps);
31523155

31533156
// Pass the innermost leaf construct's clauses because that's where COLLAPSE
31543157
// is placed by construct decomposition.
@@ -3159,15 +3162,17 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
31593162

31603163
// Operation creation.
31613164
EntryBlockArgs wsloopArgs;
3162-
// TODO: Add private syms and vars.
3165+
wsloopArgs.priv.syms = wsloopItemDSP.getDelayedPrivSymbols();
3166+
wsloopArgs.priv.vars = wsloopClauseOps.privateVars;
31633167
wsloopArgs.reduction.syms = wsloopReductionSyms;
31643168
wsloopArgs.reduction.vars = wsloopClauseOps.reductionVars;
31653169
auto wsloopOp = genWrapperOp<mlir::omp::WsloopOp>(
31663170
converter, loc, wsloopClauseOps, wsloopArgs);
31673171
wsloopOp.setComposite(/*val=*/true);
31683172

31693173
EntryBlockArgs simdArgs;
3170-
// TODO: Add private syms and vars.
3174+
simdArgs.priv.syms = simdItemDSP.getDelayedPrivSymbols();
3175+
simdArgs.priv.vars = simdClauseOps.privateVars;
31713176
simdArgs.reduction.syms = simdReductionSyms;
31723177
simdArgs.reduction.vars = simdClauseOps.reductionVars;
31733178
auto simdOp =
@@ -3177,7 +3182,7 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
31773182
genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, simdItem,
31783183
loopNestClauseOps, iv,
31793184
{{wsloopOp, wsloopArgs}, {simdOp, simdArgs}},
3180-
llvm::omp::Directive::OMPD_do_simd, dsp);
3185+
llvm::omp::Directive::OMPD_do_simd, simdItemDSP);
31813186
return wsloopOp;
31823187
}
31833188

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
subroutine do_simd_aligned(A)
88
use iso_c_binding
99
type(c_ptr) :: A
10-
10+
1111
! CHECK: omp.wsloop
1212
! CHECK-NOT: aligned({{.*}})
1313
! CHECK-SAME: {
@@ -66,3 +66,22 @@ subroutine do_simd_reduction()
6666
end do
6767
!$omp end do simd
6868
end subroutine do_simd_reduction
69+
70+
! CHECK-LABEL: func.func @_QPdo_simd_private(
71+
subroutine do_simd_private()
72+
integer, allocatable :: tmp
73+
! CHECK: omp.wsloop
74+
! CHECK-NEXT: omp.simd
75+
! CHECK-SAME: private(@[[PRIV_BOX_SYM:.*]] %{{.*}} -> %[[PRIV_BOX:.*]], @[[PRIV_IVAR_SYM:.*]] %{{.*}} -> %[[PRIV_IVAR:.*]] : !fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<i32>)
76+
! CHECK-NEXT: omp.loop_nest (%[[IVAR:.*]]) : i32
77+
!$omp do simd private(tmp)
78+
do i=1, 10
79+
! CHECK: %[[PRIV_BOX_DECL:.*]]:2 = hlfir.declare %[[PRIV_BOX]]
80+
! CHECK: %[[PRIV_IVAR_DECL:.*]]:2 = hlfir.declare %[[PRIV_IVAR]]
81+
! CHECK: hlfir.assign %[[IVAR]] to %[[PRIV_IVAR_DECL]]#0
82+
! CHECK: %[[PRIV_BOX_LOAD:.*]] = fir.load %[[PRIV_BOX_DECL]]
83+
! CHECK: hlfir.assign %{{.*}} to %[[PRIV_BOX_DECL]]#0
84+
! CHECK: omp.yield
85+
tmp = tmp + 1
86+
end do
87+
end subroutine do_simd_private

0 commit comments

Comments
 (0)