Skip to content

Commit cc03d94

Browse files
committed
[flang][OpenMP] Support delayed privatisation for composite distribute simd
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 3ede2de commit cc03d94

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
@@ -3145,11 +3145,16 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
31453145
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
31463146
simdReductionSyms);
31473147

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

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

31613166
// Operation creation.
31623167
EntryBlockArgs distributeArgs;
3163-
// TODO: Add private syms and vars.
3168+
distributeArgs.priv.syms = distributeItemDSP.getDelayedPrivSymbols();
3169+
distributeArgs.priv.vars = distributeClauseOps.privateVars;
31643170
auto distributeOp = genWrapperOp<mlir::omp::DistributeOp>(
31653171
converter, loc, distributeClauseOps, distributeArgs);
31663172
distributeOp.setComposite(/*val=*/true);
31673173

31683174
EntryBlockArgs simdArgs;
3169-
// TODO: Add private syms and vars.
3175+
simdArgs.priv.syms = simdItemDSP.getDelayedPrivSymbols();
3176+
simdArgs.priv.vars = simdClauseOps.privateVars;
31703177
simdArgs.reduction.syms = simdReductionSyms;
31713178
simdArgs.reduction.vars = simdClauseOps.reductionVars;
31723179
auto simdOp =
@@ -3176,7 +3183,7 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
31763183
genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, simdItem,
31773184
loopNestClauseOps, iv,
31783185
{{distributeOp, distributeArgs}, {simdOp, simdArgs}},
3179-
llvm::omp::Directive::OMPD_distribute_simd, dsp);
3186+
llvm::omp::Directive::OMPD_distribute_simd, simdItemDSP);
31803187
return distributeOp;
31813188
}
31823189

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)