Skip to content

[flang][OpenMP] Support delayed privatisation for composite distribute simd #151169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3148,11 +3148,16 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
genSimdClauses(converter, semaCtx, simdItem->clauses, loc, simdClauseOps,
simdReductionSyms);

// TODO: Support delayed privatization.
DataSharingProcessor dsp(converter, semaCtx, simdItem->clauses, eval,
/*shouldCollectPreDeterminedSymbols=*/true,
/*useDelayedPrivatization=*/false, symTable);
dsp.processStep1();
DataSharingProcessor distributeItemDSP(
converter, semaCtx, distributeItem->clauses, eval,
/*shouldCollectPreDeterminedSymbols=*/false,
/*useDelayedPrivatization=*/true, symTable);
distributeItemDSP.processStep1(&distributeClauseOps);

DataSharingProcessor simdItemDSP(converter, semaCtx, simdItem->clauses, eval,
/*shouldCollectPreDeterminedSymbols=*/true,
/*useDelayedPrivatization=*/true, symTable);
simdItemDSP.processStep1(&simdClauseOps);

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

// Operation creation.
EntryBlockArgs distributeArgs;
// TODO: Add private syms and vars.
distributeArgs.priv.syms = distributeItemDSP.getDelayedPrivSymbols();
distributeArgs.priv.vars = distributeClauseOps.privateVars;
auto distributeOp = genWrapperOp<mlir::omp::DistributeOp>(
converter, loc, distributeClauseOps, distributeArgs);
distributeOp.setComposite(/*val=*/true);

EntryBlockArgs simdArgs;
// TODO: Add private syms and vars.
simdArgs.priv.syms = simdItemDSP.getDelayedPrivSymbols();
simdArgs.priv.vars = simdClauseOps.privateVars;
simdArgs.reduction.syms = simdReductionSyms;
simdArgs.reduction.vars = simdClauseOps.reductionVars;
auto simdOp =
Expand All @@ -3179,7 +3186,7 @@ static mlir::omp::DistributeOp genCompositeDistributeSimd(
genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, simdItem,
loopNestClauseOps, iv,
{{distributeOp, distributeArgs}, {simdOp, simdArgs}},
llvm::omp::Directive::OMPD_distribute_simd, dsp);
llvm::omp::Directive::OMPD_distribute_simd, simdItemDSP);
return distributeOp;
}

Expand Down
21 changes: 20 additions & 1 deletion flang/test/Lower/OpenMP/distribute-simd.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
subroutine distribute_simd_aligned(A)
use iso_c_binding
type(c_ptr) :: A

!$omp teams

! CHECK: omp.distribute
Expand Down Expand Up @@ -57,3 +57,22 @@ subroutine distribute_simd_simdlen()

!$omp end teams
end subroutine distribute_simd_simdlen

! CHECK-LABEL: func.func @_QPdistribute_simd_private(
subroutine distribute_simd_private()
integer, allocatable :: tmp
! CHECK: omp.teams
!$omp teams
! CHECK: omp.distribute
! CHECK: omp.simd
! CHECK-SAME: private(@[[PRIV_BOX_SYM:.*]] %{{.*}} -> %[[PRIV_BOX:.*]], @[[PRIV_IVAR_SYM:.*]] %{{.*}} -> %[[PRIV_IVAR:.*]] : !fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<i32>)
! CHECK-NEXT: omp.loop_nest (%[[IVAR:.*]]) : i32
!$omp distribute simd private(tmp)
do index_ = 1, 10
! CHECK: %[[PRIV_BOX_DECL:.*]]:2 = hlfir.declare %[[PRIV_BOX]]
! CHECK: %[[PRIV_IVAR_DECL:.*]]:2 = hlfir.declare %[[PRIV_IVAR]]
! CHECK: hlfir.assign %[[IVAR]] to %[[PRIV_IVAR_DECL]]#0
end do
!$omp end distribute simd
!$omp end teams
end subroutine distribute_simd_private