Skip to content

Commit ae68759

Browse files
authored
Reapply and fix - [flang][OpenMP] Support delayed privatisation for composite do simd (llvm#150979) (llvm#3448)
2 parents 3b454e2 + c610b3b commit ae68759

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,6 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
30943094
/*useDelayedPrivatization=*/false, symTable);
30953095
dsp.processStep1();
30963096
dsp.processStep2();
3097-
30983097
// Pass the innermost leaf construct's clauses because that's where COLLAPSE
30993098
// is placed by construct decomposition.
31003099
mlir::omp::LoopNestOperands loopNestClauseOps;
@@ -3144,12 +3143,18 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
31443143
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
31453144
simdReductionSyms);
31463145

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

31543159
// Pass the innermost leaf construct's clauses because that's where COLLAPSE
31553160
// is placed by construct decomposition.
@@ -3160,15 +3165,17 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
31603165

31613166
// Operation creation.
31623167
EntryBlockArgs wsloopArgs;
3163-
// TODO: Add private syms and vars.
3168+
wsloopArgs.priv.syms = wsloopItemDSP.getDelayedPrivSymbols();
3169+
wsloopArgs.priv.vars = wsloopClauseOps.privateVars;
31643170
wsloopArgs.reduction.syms = wsloopReductionSyms;
31653171
wsloopArgs.reduction.vars = wsloopClauseOps.reductionVars;
31663172
auto wsloopOp = genWrapperOp<mlir::omp::WsloopOp>(
31673173
converter, loc, wsloopClauseOps, wsloopArgs);
31683174
wsloopOp.setComposite(/*val=*/true);
31693175

31703176
EntryBlockArgs simdArgs;
3171-
// TODO: Add private syms and vars.
3177+
simdArgs.priv.syms = simdItemDSP.getDelayedPrivSymbols();
3178+
simdArgs.priv.vars = simdClauseOps.privateVars;
31723179
simdArgs.reduction.syms = simdReductionSyms;
31733180
simdArgs.reduction.vars = simdClauseOps.reductionVars;
31743181
auto simdOp =
@@ -3178,7 +3185,7 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
31783185
genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, simdItem,
31793186
loopNestClauseOps, iv,
31803187
{{wsloopOp, wsloopArgs}, {simdOp, simdArgs}},
3181-
llvm::omp::Directive::OMPD_do_simd, dsp);
3188+
llvm::omp::Directive::OMPD_do_simd, simdItemDSP);
31823189
return wsloopOp;
31833190
}
31843191

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)