Skip to content

[flang][OpenMP] Support delayed privatisation for composite do simd #150979

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 2 commits into from
Aug 1, 2025

Conversation

mrkajetanp
Copy link
Contributor

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.

Fixes #150975.

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 <[email protected]>
@mrkajetanp mrkajetanp requested review from skatrak, tblah and luporl July 28, 2025 15:41
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp labels Jul 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 28, 2025

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-fir-hlfir

Author: Kajetan Puchalski (mrkajetanp)

Changes

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.

Fixes llvm#150975.


Full diff: https://github.com/llvm/llvm-project/pull/150979.diff

2 Files Affected:

  • (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+15-8)
  • (modified) flang/test/Lower/OpenMP/wsloop-simd.f90 (+20-1)
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 12089d6caa5fe..416676485cb56 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -3200,11 +3200,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.
@@ -3215,7 +3220,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>(
@@ -3223,7 +3229,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 =
@@ -3233,7 +3240,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

@mrkajetanp mrkajetanp requested a review from kparzysz July 29, 2025 10:58
Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the other one, did you run Fujitsu and gfortran tests?

@mrkajetanp
Copy link
Contributor Author

Yep, same story :)

@mrkajetanp mrkajetanp merged commit c059147 into llvm:main Aug 1, 2025
9 checks passed
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Aug 2, 2025
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Aug 6, 2025
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flang][OpenMP] Lowering crashes for composite do simd constructs with private clause
3 participants