Skip to content

Commit c059147

Browse files
authored
[flang][OpenMP] Support delayed privatisation for composite do simd (#150979)
Implement the lowering for delayed privatisation for composite "do simd" constructs. Fixes new crashes previously masked by simd information on composite constructs being ignored, such as #150975. Signed-off-by: Kajetan Puchalski <[email protected]>
1 parent d8ca85a commit c059147

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,11 +3203,16 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
32033203
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
32043204
simdReductionSyms);
32053205

3206-
// TODO: Support delayed privatization.
3207-
DataSharingProcessor dsp(converter, semaCtx, simdItem->clauses, eval,
3208-
/*shouldCollectPreDeterminedSymbols=*/true,
3209-
/*useDelayedPrivatization=*/false, symTable);
3210-
dsp.processStep1();
3206+
DataSharingProcessor wsloopItemDSP(
3207+
converter, semaCtx, doItem->clauses, eval,
3208+
/*shouldCollectPreDeterminedSymbols=*/false,
3209+
/*useDelayedPrivatization=*/true, symTable);
3210+
wsloopItemDSP.processStep1(&wsloopClauseOps);
3211+
3212+
DataSharingProcessor simdItemDSP(converter, semaCtx, simdItem->clauses, eval,
3213+
/*shouldCollectPreDeterminedSymbols=*/true,
3214+
/*useDelayedPrivatization=*/true, symTable);
3215+
simdItemDSP.processStep1(&simdClauseOps);
32113216

32123217
// Pass the innermost leaf construct's clauses because that's where COLLAPSE
32133218
// is placed by construct decomposition.
@@ -3218,15 +3223,17 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
32183223

32193224
// Operation creation.
32203225
EntryBlockArgs wsloopArgs;
3221-
// TODO: Add private syms and vars.
3226+
wsloopArgs.priv.syms = wsloopItemDSP.getDelayedPrivSymbols();
3227+
wsloopArgs.priv.vars = wsloopClauseOps.privateVars;
32223228
wsloopArgs.reduction.syms = wsloopReductionSyms;
32233229
wsloopArgs.reduction.vars = wsloopClauseOps.reductionVars;
32243230
auto wsloopOp = genWrapperOp<mlir::omp::WsloopOp>(
32253231
converter, loc, wsloopClauseOps, wsloopArgs);
32263232
wsloopOp.setComposite(/*val=*/true);
32273233

32283234
EntryBlockArgs simdArgs;
3229-
// TODO: Add private syms and vars.
3235+
simdArgs.priv.syms = simdItemDSP.getDelayedPrivSymbols();
3236+
simdArgs.priv.vars = simdClauseOps.privateVars;
32303237
simdArgs.reduction.syms = simdReductionSyms;
32313238
simdArgs.reduction.vars = simdClauseOps.reductionVars;
32323239
auto simdOp =
@@ -3236,7 +3243,7 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
32363243
genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, simdItem,
32373244
loopNestClauseOps, iv,
32383245
{{wsloopOp, wsloopArgs}, {simdOp, simdArgs}},
3239-
llvm::omp::Directive::OMPD_do_simd, dsp);
3246+
llvm::omp::Directive::OMPD_do_simd, simdItemDSP);
32403247
return wsloopOp;
32413248
}
32423249

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)