[flang-commits] [flang] [llvm] [mlir] [flang][mlir][OpenMP] Support iterator modifier in declare mapper map clause (PR #215485)

Urvi Rav via flang-commits flang-commits at lists.llvm.org
Fri Sep 25 03:54:53 PDT 2026


================
@@ -10902,6 +10892,48 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
           getOrCreateRuntimeFunction(M, OMPRTL___tgt_push_mapper_component),
           OffloadingArgs);
     }
+    return EndBB;
+  };
+
+  // Fill up the runtime mapper handle for all statically-known components.
+  for (unsigned I = 0; I < Info->BasePointers.size(); ++I) {
+    Value *CurNameArg = Info->Names.size()
+                            ? Info->Names[I]
+                            : Constant::getNullValue(Builder.getPtrTy());
+    Expected<Function *> ChildMapperFn = CustomMapperCB(I);
+    if (!ChildMapperFn)
+      return ChildMapperFn.takeError();
+    LastBB = pushComponent(
+        Info->BasePointers[I], Info->Pointers[I], Info->Sizes[I], CurNameArg,
+        static_cast<std::underlying_type_t<OpenMPOffloadMappingFlags>>(
+            Info->Types[I]),
+        Info->HasAttachPtr[I], *ChildMapperFn);
+  }
+
+  // Fill up the runtime mapper handle for components whose count is only
+  // known at runtime (produced by an `iterator` modifier on the mapper's own
+  // map clause): push each one individually, from inside a generated loop,
+  // via the same __tgt_push_mapper_component call used above.
+  for (MapInfosTy::DynamicSegment &Seg : Info->DynamicSegments) {
+    LocationDescription Loc(Builder);
+    auto BodyGen = [&](InsertPointTy BodyIP,
+                       Value *LinearIV) -> Expected<InsertPointTy> {
+      Builder.restoreIP(BodyIP);
+      SmallVector<Value *, 3> Entry = Seg.GenEntry(Builder, LinearIV);
+      BasicBlock *EndBB = pushComponent(
+          Entry[0], Entry[1], Entry[2],
+          Constant::getNullValue(Builder.getPtrTy()),
+          static_cast<std::underlying_type_t<OpenMPOffloadMappingFlags>>(
+              Seg.Type),
+          Seg.HasAttachPtr, /*ChildMapperFn=*/nullptr);
----------------
ravurvi20 wrote:

Added `ChildMapperFn` to `DynamicSegment`, populated on the MLIR side from `mapInfoOp.getMapperId()` (resolving the referenced `DeclareMapperOp` via `getOrCreateUserDefinedMapperFunc`), and threaded it through to `pushComponent` in `emitUserDefinedMapper` instead of the hardcoded `nullptr`. The inner mapper (`map(x%data`)) is now correctly invoked for iterator-produced components.

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


More information about the flang-commits mailing list