[flang-commits] [flang] [flang][OpenMP] Support user-defined declare reduction with derived types (PR #184897)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Thu Mar 26 06:43:17 PDT 2026
================
@@ -636,6 +618,18 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxchar(
void PopulateInitAndCleanupRegionsHelper::initAndCleanupUnboxedDerivedType(
bool needsInitialization) {
builder.setInsertionPointToStart(initBlock);
+ // For reductions with a user-provided init value, store it into the
+ // private variable. Insert after the init value's defining op to
+ // maintain SSA dominance (the init value was generated by the
+ // callback before populateByRefInitAndCleanupRegions was called).
+ if (scalarInitValue && isReduction(kind)) {
+ mlir::OpBuilder::InsertionGuard guard(builder);
+ if (auto *defOp = scalarInitValue.getDefiningOp())
+ builder.setInsertionPointAfter(defOp);
+ else
+ builder.setInsertionPointToEnd(initBlock);
+ fir::StoreOp::create(builder, loc, scalarInitValue, allocatedPrivVarArg);
----------------
tblah wrote:
Okay so this is a broader design issue. Ideally these would be valid `hlfir::Entity` (aka `AnyFortranEntity`). My reading is that the derived types would need to be boxed (see `isFortranVariableType`). I find it better not to fight against the design of HLFIR
I think this can be left for a later patch, perhaps when adding support for user-defined reduction of non-trivial types. But it is up to you.
https://github.com/llvm/llvm-project/pull/184897
More information about the flang-commits
mailing list