[Mlir-commits] [flang] [mlir] [Flang][OpenMP] Support iterator modifier in map and motion clauses (PR #197757)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 14 21:22:15 PDT 2026
================
@@ -1437,6 +1437,193 @@ resolveDeclareVariantCallee(const semantics::Symbol &base,
return variants[bestIdx];
}
+IteratorMapObjectAnalysis analyzeIteratorMapObject(const omp::Object &object) {
+ IteratorMapObjectAnalysis analysis;
+ const std::optional<ExprTy> &ref = object.ref();
+ if (!ref)
+ return analysis;
+
+ std::optional<evaluate::DataRef> dataRef = evaluate::ExtractDataRef(*ref);
+ if (!dataRef)
+ return analysis;
+
+ analysis.rootSym = &dataRef->GetFirstSymbol();
+
+ const auto *component = std::get_if<evaluate::Component>(&dataRef->u);
+ const auto *arrayRef = std::get_if<evaluate::ArrayRef>(&dataRef->u);
+ analysis.isDerivedTypeMember =
+ component || (arrayRef && arrayRef->base().UnwrapComponent());
+
+ if (!arrayRef || arrayRef->subscript().empty() ||
+ evaluate::ExtractCoarrayRef(*dataRef))
+ return analysis;
+
+ for (const auto &subscript : arrayRef->subscript()) {
+ if (!std::holds_alternative<evaluate::Triplet>(subscript.u) &&
+ subscript.Rank() > 0)
+ return analysis;
+ }
+
+ analysis.arrayRef = *arrayRef;
+ return analysis;
+}
+
+// Lower the array base (v%a for v%a(i)) with shape information for bounds.
+static hlfir::Entity getIteratorMapEntity(
+ Fortran::lower::AbstractConverter &converter, fir::FirOpBuilder &builder,
+ Fortran::semantics::SemanticsContext &semaCtx,
+ Fortran::lower::StatementContext &stmtCtx, const omp::Object &object,
+ const evaluate::ArrayRef &arrayRef, mlir::Location loc) {
+ const semantics::Symbol *sym = object.sym();
+ assert(sym && "expected symbol for iterator object");
+
+ mlir::Value addr;
+ if (!sym->owner().IsDerivedType()) {
+ // Keep the same base address as ordinary map lowering for non-component
+ // objects.
+ fir::factory::AddrAndBoundsInfo info =
+ Fortran::lower::getDataOperandBaseAddr(converter, builder, *sym, loc,
+ /*unwrapFirBox=*/false);
+ addr = info.addr;
+ } else {
+ evaluate::ExpressionAnalyzer ea{semaCtx};
+ std::optional<ExprTy> arrayBase;
+ const evaluate::NamedEntity &base = arrayRef.base();
+ // The ordinary base-address helper takes a symbol, which does not identify
+ // the containing object of a component. Lower the component base reference
+ // here, leaving its subscripts for iterator-local map bounds.
+ if (const semantics::SymbolRef *symRef = base.UnwrapSymbolRef())
+ arrayBase = ea.Designate(evaluate::DataRef{*symRef});
+ else if (const evaluate::Component *component = base.UnwrapComponent())
+ arrayBase = ea.Designate(evaluate::DataRef{*component});
----------------
MattPD wrote:
Removing the final subscript can produce a designator with two ranked parts. In this reproducer, the locator `v%p(1:1)%a(i)` has one ranked part, but the reconstructed base `v%p(1:1)%a` has two:
```fortran
subroutine ranked_parent
type :: inner_t
integer :: a(2)
end type
type :: outer_t
type(inner_t) :: p(1)
end type
!$omp declare mapper(m: outer_t :: v) &
!$omp& map(iterator(i=1:1), to: v%p(1:1)%a(i))
end subroutine
```
Save this as `repro.f90` and run `flang -c -fopenmp -fopenmp-version=52 repro.f90`. At e3eaf33, Flang fails the assertion `Fortran designators can only have one ranked part`. At the base commit 560cd8f, Flang reports the not-yet-implemented diagnostic for iterator modifiers instead. Without the iterator, `map(to: v%p(1:1)%a(1))` fails the same assertion at both commits, so the gap itself predates this PR.
Could a locator with an array-valued parent get a not-yet-implemented diagnostic until this reconstruction supports it? The scalar-parent form `v%p(1)%a(i)` already lowers.
https://github.com/llvm/llvm-project/pull/197757
More information about the Mlir-commits
mailing list