[flang-commits] [flang] [mlir] [OpenACC] add acc::FirstprivateSaveOp (PR #211011)

Scott Manley via flang-commits flang-commits at lists.llvm.org
Wed Jul 22 09:04:44 PDT 2026


================
@@ -318,6 +319,17 @@ LogicalResult ACCRecipeMaterialization::materialize(
     Region &copyRegion = recipe.getCopyRegion();
     setLocation(copyRegion, loc);
     acc::cloneACCRegionInto(&copyRegion, block, std::next(ip), mapping, {});
+
+    // Create a temporary acc.firstprivate_save op to keep the value live-out
+    // until after other passes have determined it is truly firstprivate.
+    b.setInsertionPoint(accOp.getBody().getTerminator());
+    auto ptrLikeType = dyn_cast<acc::PointerLikeType>(alloca.getType());
+    assert(ptrLikeType && "alloca must be a pointer-like type");
+    auto xTyped = cast<TypedValue<acc::PointerLikeType>>(alloca);
+    assert(xTyped && "alloca must be a typed value");
+    auto loadOp = ptrLikeType.genLoad(b, op.getLoc(), xTyped, {});
----------------
rscottmanley wrote:

Maybe this is okay, I was looking at the spec. This would end up temporary, but still, not elegant.

```
The appearance of a Fortran optional argument arg in the following situations may result in undefined behavior if PRESENT(arg) is .false. when the associated construct is executed:
• as a var in private, firstprivate, and reduction clauses;
```

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


More information about the flang-commits mailing list