[Mlir-commits] [flang] [mlir] [Flang][OpenMP] Support iterator modifier in map and motion clauses (PR #197757)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 15 22:50:20 PDT 2026
================
@@ -6996,7 +6997,35 @@ genOpenMPDeclareMapperImpl(lower::AbstractConverter &converter,
List<Clause> clauses = makeClauses(construct.v.Clauses(), semaCtx);
ClauseProcessor cp(converter, semaCtx, clauses);
cp.processMap(loc, stmtCtx, clauseOps);
+ // Emit cleanups inside the mapper region, before its terminator.
+ stmtCtx.finalizeAndReset();
mlir::omp::DeclareMapperInfoOp::create(firOpBuilder, loc, clauseOps);
+
+ // Values of the enclosing procedure are not available in the mapper region.
+ mlir::WalkResult usesOutsideValue = region.walk([&](mlir::Operation *op) {
+ for (mlir::Value operand : op->getOperands())
+ if (!region.isAncestor(operand.getParentRegion()))
+ return mlir::WalkResult::interrupt();
+ return mlir::WalkResult::advance();
+ });
+ if (usesOutsideValue.wasInterrupted())
+ TODO(loc, "declare mapper using a value from outside the mapper region");
+
+ // The mapper region must remain a single block once control flow is lowered.
+ // With an iterator modifier, intrinsic simplification may also add loops.
+ bool hasIterator = llvm::any_of(clauses, [](const Clause &clause) {
+ const auto *map = std::get_if<clause::Map>(&clause.u);
+ return map && std::get<std::optional<clause::Iterator>>(map->t).has_value();
+ });
+ for (mlir::Operation &op : region.front()) {
+ bool mayAddLoops =
+ hasIterator && mlir::isa<hlfir::hlfirDialect>(op.getDialect()) &&
----------------
MattPD wrote:
This check also rejects parenthesized scalar expressions, although they lower to `hlfir.no_reassoc` and do not add control flow:
```fortran
subroutine paren_range
type :: t
integer :: a(4), n
end type
!$omp declare mapper(m: t :: v) &
!$omp& map(iterator(i=1:(v%n)), to: v%a(i))
end subroutine
```
Save this as `repro.f90` and run `flang -c -fopenmp -fopenmp-version=52 repro.f90`. At 7391dbf, Flang reports `not yet implemented: declare mapper with control flow`. The previous revision e3eaf33 compiles it, and 7391dbf compiles it without the parentheses.
Could the check accept `hlfir.no_reassoc` and keep rejecting operations that can become loops, such as `maxval`?
https://github.com/llvm/llvm-project/pull/197757
More information about the Mlir-commits
mailing list