[flang-commits] [flang] c059147 - [flang][OpenMP] Support delayed privatisation for composite do simd (#150979)
via flang-commits
flang-commits at lists.llvm.org
Fri Aug 1 05:12:24 PDT 2025
Author: Kajetan Puchalski
Date: 2025-08-01T13:12:21+01:00
New Revision: c0591477ac99bf8ae51ce116a6471420f128ac9f
URL: https://github.com/llvm/llvm-project/commit/c0591477ac99bf8ae51ce116a6471420f128ac9f
DIFF: https://github.com/llvm/llvm-project/commit/c0591477ac99bf8ae51ce116a6471420f128ac9f.diff
LOG: [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 llvm#150975.
Signed-off-by: Kajetan Puchalski <kajetan.puchalski at arm.com>
Added:
Modified:
flang/lib/Lower/OpenMP/OpenMP.cpp
flang/test/Lower/OpenMP/wsloop-simd.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 575658ff8eac5..d0517c175eb61 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -3203,11 +3203,16 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
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 wsloopItemDSP(
+ converter, semaCtx, doItem->clauses, eval,
+ /*shouldCollectPreDeterminedSymbols=*/false,
+ /*useDelayedPrivatization=*/true, symTable);
+ wsloopItemDSP.processStep1(&wsloopClauseOps);
+
+ 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.
@@ -3218,7 +3223,8 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
// Operation creation.
EntryBlockArgs wsloopArgs;
- // TODO: Add private syms and vars.
+ wsloopArgs.priv.syms = wsloopItemDSP.getDelayedPrivSymbols();
+ wsloopArgs.priv.vars = wsloopClauseOps.privateVars;
wsloopArgs.reduction.syms = wsloopReductionSyms;
wsloopArgs.reduction.vars = wsloopClauseOps.reductionVars;
auto wsloopOp = genWrapperOp<mlir::omp::WsloopOp>(
@@ -3226,7 +3232,8 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
wsloopOp.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 =
@@ -3236,7 +3243,7 @@ static mlir::omp::WsloopOp genCompositeDoSimd(
genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, simdItem,
loopNestClauseOps, iv,
{{wsloopOp, wsloopArgs}, {simdOp, simdArgs}},
- llvm::omp::Directive::OMPD_do_simd, dsp);
+ llvm::omp::Directive::OMPD_do_simd, simdItemDSP);
return wsloopOp;
}
diff --git a/flang/test/Lower/OpenMP/wsloop-simd.f90 b/flang/test/Lower/OpenMP/wsloop-simd.f90
index 49a9a523e11fe..d26e93d9a5113 100644
--- a/flang/test/Lower/OpenMP/wsloop-simd.f90
+++ b/flang/test/Lower/OpenMP/wsloop-simd.f90
@@ -7,7 +7,7 @@
subroutine do_simd_aligned(A)
use iso_c_binding
type(c_ptr) :: A
-
+
! CHECK: omp.wsloop
! CHECK-NOT: aligned({{.*}})
! CHECK-SAME: {
@@ -66,3 +66,22 @@ subroutine do_simd_reduction()
end do
!$omp end do simd
end subroutine do_simd_reduction
+
+! CHECK-LABEL: func.func @_QPdo_simd_private(
+subroutine do_simd_private()
+ integer, allocatable :: tmp
+ ! CHECK: omp.wsloop
+ ! CHECK-NEXT: 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 do simd private(tmp)
+ do i=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
+ ! CHECK: %[[PRIV_BOX_LOAD:.*]] = fir.load %[[PRIV_BOX_DECL]]
+ ! CHECK: hlfir.assign %{{.*}} to %[[PRIV_BOX_DECL]]#0
+ ! CHECK: omp.yield
+ tmp = tmp + 1
+ end do
+end subroutine do_simd_private
More information about the flang-commits
mailing list