[llvm-branch-commits] [flang] [mlir] [mlir][OpenMP][flang] make private variable allocation implicit in omp.private (PR #124019)

Kareem Ergawy via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 23 03:33:43 PST 2025


================
@@ -148,41 +309,113 @@ void Fortran::lower::omp::populateByRefInitAndCleanupRegions(
 
     builder.setInsertionPointToEnd(initBlock);
     mlir::Value boxAlloca = allocatedPrivVarArg;
+
+    moldArg = builder.loadIfRef(loc, moldArg);
+    getLengthParameters(builder, loc, moldArg, lenParams);
+
+    // The initial state of a private pointer is undefined so we don't need to
+    // match the mold argument (OpenMP 5.2 end of page 106).
+    if (isPrivatization(kind) &&
+        mlir::isa<fir::PointerType>(boxTy.getEleTy())) {
+      // we need a shape with the right rank so that the embox op is lowered
+      // to an llvm struct of the right type. This returns nullptr if the types
+      // aren't right.
+      mlir::Value shape = generateZeroShapeForRank(builder, loc, moldArg);
+      // Just incase, do initialize the box with a null value
+      mlir::Value null = builder.createNullConstant(loc, boxTy.getEleTy());
+      mlir::Value nullBox;
+      if (shape)
+        nullBox = builder.create<fir::EmboxOp>(
+            loc, boxTy, null, shape, /*slice=*/mlir::Value{}, lenParams);
----------------
ergawy wrote:

I think we can get rid of the `else`, right? If `shape` is an empty value, it is the same as passing `Value{}` I think.

https://github.com/llvm/llvm-project/pull/124019


More information about the llvm-branch-commits mailing list