[flang-commits] [flang] [Flang][OpenMP] Support iterator modifier in map and motion clauses (PR #197757)

via flang-commits flang-commits at lists.llvm.org
Tue Aug 11 22:46:00 PDT 2026


================
@@ -1924,6 +1968,92 @@ void ClauseProcessor::processMapObjects(
   }
 }
 
+// Process objects in map/motion clauses, lowering iterator-dependent
+// locators into `result.mapIterated` and all others through the regular
+// map-lowering path. A null `ivSyms` indicates that no iterator modifier
+// is present.
+void ClauseProcessor::processMapObjectsWithIterator(
+    lower::StatementContext &stmtCtx, mlir::Location clauseLocation,
+    const omp::ObjectList &objects,
+    llvm::ArrayRef<IteratorRange> iteratorRanges,
+    const llvm::SmallPtrSetImpl<const semantics::Symbol *> *ivSyms,
+    mlir::omp::ClauseMapFlags mapTypeBits,
+    std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
+    mlir::omp::MapClauseOps &result, llvm::SmallVectorImpl<Object> &mapObjects,
+    llvm::StringRef mapperIdNameRef, bool isMotionModifier,
+    llvm::omp::Directive directive) const {
+  if (!ivSyms) {
+    processMapObjects(stmtCtx, clauseLocation, objects, mapTypeBits,
+                      parentMemberIndices, result.mapVars, mapObjects,
+                      mapperIdNameRef, isMotionModifier, directive);
+    return;
+  }
+
+  auto declareMapper = mlir::dyn_cast_if_present<mlir::omp::DeclareMapperOp>(
+      converter.getFirOpBuilder().getRegion().getParentOp());
+  auto isDeclareMapperVariable = [&](const omp::Object &object) {
+    if (!declareMapper)
+      return false;
+
+    omp::Object rootObject{object};
+    while (std::optional<omp::Object> baseObject =
+               getBaseObject(rootObject, semaCtx))
+      rootObject = *baseObject;
+
+    mlir::Value rootAddress = converter.getSymbolAddress(*rootObject.sym());
+    while (rootAddress) {
+      if (auto declare = rootAddress.getDefiningOp<hlfir::DeclareOp>()) {
+        rootAddress = declare.getMemref();
+        continue;
+      }
+      if (auto declare = rootAddress.getDefiningOp<fir::DeclareOp>()) {
+        rootAddress = declare.getMemref();
+        continue;
+      }
+      break;
+    }
+
+    return rootAddress == declareMapper.getRegion().front().getArgument(0);
+  };
+
+  constexpr mlir::omp::ClauseMapFlags unsupportedReferenceModifiers =
+      mlir::omp::ClauseMapFlags::ref_ptr | mlir::omp::ClauseMapFlags::ref_ptee |
+      mlir::omp::ClauseMapFlags::attach_always |
+      mlir::omp::ClauseMapFlags::attach_never |
+      mlir::omp::ClauseMapFlags::attach_auto;
+  bool hasUnsupportedReferenceModifier =
+      (mapTypeBits & unsupportedReferenceModifiers) !=
+      mlir::omp::ClauseMapFlags::none;
+
+  // Objects in an iterator-modified clause may independently reference
+  // iterator variables, so handle each object separately.
+  for (const omp::Object &object : objects) {
+    if (hasIteratorIVReference(object, *ivSyms)) {
+      bool isMapperVariable = isDeclareMapperVariable(object);
+      if (hasUnsupportedReferenceModifier)
+        TODO(clauseLocation,
+             "iterator modifier with reference or attach modifier");
+      if (getBaseObject(object, semaCtx) && !isMapperVariable)
+        TODO(clauseLocation, "iterator modifier with derived type member map");
+      if (declareMapper && !isMapperVariable)
+        TODO(clauseLocation,
+             "iterator modifier with locator outside declare mapper variable");
----------------
MattPD wrote:

Confirmed, Flang now reports the correct `object type not supported by iterator modifier` diagnostic for `v%c(i)%re` inside a declare mapper.

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


More information about the flang-commits mailing list