Skip to content

Commit a361cde

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

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
@@ -3148,11 +3148,16 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
31483148
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
31493149
simdReductionSyms);
31503150

3151-
// TODO: Support delayed privatization.
3152-
DataSharingProcessor dsp(converter, semaCtx, simdItem->clauses, eval,
3153-
/*shouldCollectPreDeterminedSymbols=*/true,
3154-
/*useDelayedPrivatization=*/false, symTable);
3155-
dsp.processStep1();
3151+
DataSharingProcessor distributeItemDSP(
3152+
converter, semaCtx, distributeItem->clauses, eval,
3153+
/*shouldCollectPreDeterminedSymbols=*/false,
3154+
/*useDelayedPrivatization=*/true, symTable);
3155+
distributeItemDSP.processStep1(&distributeClauseOps);
3156+
3157+
DataSharingProcessor simdItemDSP(converter, semaCtx, simdItem->clauses, eval,
3158+
/*shouldCollectPreDeterminedSymbols=*/true,
3159+
/*useDelayedPrivatization=*/true, symTable);
3160+
simdItemDSP.processStep1(&simdClauseOps);
31563161

31573162
// Pass the innermost leaf construct's clauses because that's where COLLAPSE
31583163
// is placed by construct decomposition.
@@ -3163,13 +3168,15 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
31633168

31643169
// Operation creation.
31653170
EntryBlockArgs distributeArgs;
3166-
// TODO: Add private syms and vars.
3171+
distributeArgs.priv.syms = distributeItemDSP.getDelayedPrivSymbols();
3172+
distributeArgs.priv.vars = distributeClauseOps.privateVars;
31673173
auto distributeOp = genWrapperOp<mlir::omp::DistributeOp>(
31683174
converter, loc, distributeClauseOps, distributeArgs);
31693175
distributeOp.setComposite(/*val=*/true);
31703176

31713177
EntryBlockArgs simdArgs;
3172-
// TODO: Add private syms and vars.
3178+
simdArgs.priv.syms = simdItemDSP.getDelayedPrivSymbols();
3179+
simdArgs.priv.vars = simdClauseOps.privateVars;
31733180
simdArgs.reduction.syms = simdReductionSyms;
31743181
simdArgs.reduction.vars = simdClauseOps.reductionVars;
31753182
auto simdOp =
@@ -3179,7 +3186,7 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
31793186
genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, simdItem,
31803187
loopNestClauseOps, iv,
31813188
{{distributeOp, distributeArgs}, {simdOp, simdArgs}},
3182-
llvm::omp::Directive::OMPD_distribute_simd, dsp);
3189+
llvm::omp::Directive::OMPD_distribute_simd, simdItemDSP);
31833190
return distributeOp;
31843191
}
31853192

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
subroutine distribute_simd_aligned(A)
88
use iso_c_binding
99
type(c_ptr) :: A
10-
10+
1111
!$omp teams
1212

1313
! CHECK: omp.distribute
@@ -57,3 +57,22 @@ subroutine distribute_simd_simdlen()
5757

5858
!$omp end teams
5959
end subroutine distribute_simd_simdlen
60+
61+
! CHECK-LABEL: func.func @_QPdistribute_simd_private(
62+
subroutine distribute_simd_private()
63+
integer, allocatable :: tmp
64+
! CHECK: omp.teams
65+
!$omp teams
66+
! CHECK: omp.distribute
67+
! CHECK: omp.simd
68+
! CHECK-SAME: private(@[[PRIV_BOX_SYM:.*]] %{{.*}} -> %[[PRIV_BOX:.*]], @[[PRIV_IVAR_SYM:.*]] %{{.*}} -> %[[PRIV_IVAR:.*]] : !fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<i32>)
69+
! CHECK-NEXT: omp.loop_nest (%[[IVAR:.*]]) : i32
70+
!$omp distribute simd private(tmp)
71+
do index_ = 1, 10
72+
! CHECK: %[[PRIV_BOX_DECL:.*]]:2 = hlfir.declare %[[PRIV_BOX]]
73+
! CHECK: %[[PRIV_IVAR_DECL:.*]]:2 = hlfir.declare %[[PRIV_IVAR]]
74+
! CHECK: hlfir.assign %[[IVAR]] to %[[PRIV_IVAR_DECL]]#0
75+
end do
76+
!$omp end distribute simd
77+
!$omp end teams
78+
end subroutine distribute_simd_private

0 commit comments

Comments
 (0)