[flang-commits] [flang] [flang][OpenMP] Inline the firstprivate array copy instead of calling Assign() (PR #211543)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Fri Jul 24 06:23:45 PDT 2026
================
@@ -39,6 +40,55 @@ static llvm::cl::opt<bool> inlineAllocatableExprAssignFlag(
"hlfir.expr (e.g., from hlfir.elemental)"),
llvm::cl::init(false));
+/// Is \p assign the copy-in of an `omp.private` copy region, writing the
+/// privatized clone from the original host variable?
+///
+/// `omp.private` defines the copy region's first *entry-block* argument to be
+/// the original host variable and the second to be the memory allocated for the
+/// clone, so those two cannot overlap and the copy needs no aliasing check.
+///
+/// The body of a copy region is otherwise unrestricted: it may have several
+/// blocks, and arbitrary operations may compute the operands of an assignment.
+/// So rather than reason about provenance in general, this matches only the
+/// canonical shape lowering emits for the copy-in,
+///
+/// \code
+/// ^bb0(%orig, %clone):
+/// %0 = fir.load %orig // boxed privatizer only
+/// hlfir.assign %0 to %clone
+/// \endcode
+///
+/// and requires the assignment to be in the entry block itself. Anything else,
+/// including an RHS computed by a call that might return unrelated memory,
+/// keeps the usual aliasing check; being conservative here costs only the
+/// inlining.
+static bool isOmpPrivateCopyInAssign(hlfir::AssignOp assign) {
+ auto privateOp = llvm::dyn_cast_or_null<mlir::omp::PrivateClauseOp>(
+ assign->getParentRegion()->getParentOp());
+ if (!privateOp)
+ return false;
+ mlir::Region ©Region = privateOp.getCopyRegion();
+ if (assign->getParentRegion() != ©Region)
+ return false;
+
+ // Only the entry block: the arguments of any other block are unrelated to
+ // the original/clone pair, even where they happen to have the same numbers.
+ mlir::Block &entry = copyRegion.front();
+ if (assign->getBlock() != &entry || entry.getNumArguments() != 2)
+ return false;
+
+ if (assign.getLhs() != entry.getArgument(1))
+ return false;
+
+ mlir::Value orig = entry.getArgument(0);
----------------
tblah wrote:
nit
```suggestion
mlir::Value orig = privateOp.getCopyMoldArg();
```
https://github.com/llvm/llvm-project/pull/211543
More information about the flang-commits
mailing list