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

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Jan 24 12:33:09 PST 2025


================
@@ -371,13 +426,15 @@ void Fortran::lower::omp::populateByRefInitAndCleanupRegions(
   }
 
   if (fir::isa_derived(ty)) {
-    if (needsInitialization) {
-      builder.setInsertionPointToStart(initBlock);
-      mlir::Type boxedTy = fir::BoxType::get(ty);
-      mlir::Value box =
-          builder.create<fir::EmboxOp>(loc, boxedTy, allocatedPrivVarArg);
-      fir::runtime::genDerivedTypeInitialize(builder, loc, box);
-    }
+    builder.setInsertionPointToStart(initBlock);
+    mlir::Type boxedTy = fir::BoxType::get(ty);
+    mlir::Value newBox =
+        builder.create<fir::EmboxOp>(loc, boxedTy, allocatedPrivVarArg);
+    mlir::Value moldBox = builder.create<fir::EmboxOp>(loc, boxedTy, moldArg);
+    initializeIfDerivedTypeBox(
+        builder, loc, newBox, moldBox, needsInitialization,
+        /*isFirstPrivate=*/kind == DeclOperationKind::FirstPrivate);
----------------
luporl wrote:

As a future optimization, you could move part of `initializeIfDerivedTypeBox()`'s body to a separate function. This new function would detect if any initialization is needed and could be used here to eliminate the need to always embox `newBox` and `moldBox`.

BTW, emboxing `moldArg` for derived types will always create an use of it, right? This causes barriers to be inserted for the privatization of any derived types.

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


More information about the flang-commits mailing list