[llvm-branch-commits] [flang] [Flang][OpenMP][Offload] Modify MapInfoFinalization to handle attach mapping and 6.1's ref_* and attach map keywords (PR #177715)

Sergio Afonso via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Apr 28 05:33:12 PDT 2026


================
@@ -391,29 +414,236 @@ class MapInfoFinalizationPass
   /// of the base address index.
   void adjustMemberIndices(
       llvm::SmallVectorImpl<llvm::SmallVector<int64_t>> &memberIndices,
-      size_t memberIndex) {
-    llvm::SmallVector<int64_t> baseAddrIndex = memberIndices[memberIndex];
+      ParentAndPlacement parentAndPlacement) {
+    llvm::SmallVector<int64_t> baseAddrIndex =
+        memberIndices[parentAndPlacement.index];
+    auto &expansionIndices = expandedBaseAddr[parentAndPlacement.parent];
 
     // If we find another member that is "derived/a member of" the descriptor
     // that is not the descriptor itself, we must insert a 0 for the new base
     // address we have just added for the descriptor into the list at the
     // appropriate position to maintain correctness of the positional/index data
     // for that member.
-    for (llvm::SmallVector<int64_t> &member : memberIndices)
+    for (auto [i, member] : llvm::enumerate(memberIndices)) {
+      if (std::find(expansionIndices.begin(), expansionIndices.end(), i) !=
+          expansionIndices.end())
+        if (member.size() == baseAddrIndex.size() + 1 &&
+            member[baseAddrIndex.size()] == 0)
+          continue;
+
       if (member.size() > baseAddrIndex.size() &&
           std::equal(baseAddrIndex.begin(), baseAddrIndex.end(),
                      member.begin()))
         member.insert(std::next(member.begin(), baseAddrIndex.size()), 0);
+    }
 
     // Add the base address index to the main base address member data
     baseAddrIndex.push_back(0);
 
-    // Insert our newly created baseAddrIndex into the larger list of indices at
-    // the correct location.
-    memberIndices.insert(std::next(memberIndices.begin(), memberIndex + 1),
+    uint64_t newIdxInsert = parentAndPlacement.index + 1;
+    expansionIndices.push_back(newIdxInsert);
+
+    // Insert our newly created baseAddrIndex into the larger list of
+    // indices at the correct location.
+    memberIndices.insert(std::next(memberIndices.begin(), newIdxInsert),
                          baseAddrIndex);
   }
 
+  // This function takes a Map clause owning target operation (e.g. TargetOp or
+  // TargetDataOp) and a lambda function, the lambda function is invoked on the
+  // various map clause ranges of the target operation that was passed in (e.g.
+  // the use_device_ptr/addr and regular maps count as map clause ranges for the
+  // purpose of this function) with the intent of inserting new maps into the
+  // range in a manner that is consistent with the target that was passed in.
+  //
+  // The lambda function should take 3 parameters a range that represents the
+  // map range, an operation representing the target and an unsigned integer
+  // representing the start index for the map range in terms of the targets
+  // block argument list. The insertion behaviour of the function is left to the
+  // lambda.
----------------
skatrak wrote:

Nit: Some suggestions to make the description slightly less verbose, feel free to pick and choose whichever parts you think help or feel free to ignore.

Do use Doxygen-style comment formatting, though (here and for the documentation of all other new functions), and it would probably make sense to use the `\param` Doxygen command to describe the lambda.
```suggestion
  /// This function takes a Map clause owning target operation (e.g. TargetOp or
  /// TargetDataOp) and a function to be invoked on the
  /// various map-like clause ranges of that target operation (e.g.
  /// use_device_ptr/addr, map, etc) with the intent of inserting new maps into the
  /// range in a manner that is consistent with the target that was passed in.
  ///
  /// The lambda function should take 3 parameters: a range that represents the
  /// map range, an operation representing the target and an unsigned integer
  /// representing the start index for the map range in terms of the targets
  /// block argument list.
```

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


More information about the llvm-branch-commits mailing list