[clang] [llvm] [NFC][Clang][OpenMP] Add a util to implicitly map attach-ptr-exprs on `target`, when applicable. (PR #161294)

Abhinav Gaba via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 13:32:46 PDT 2025


================
@@ -9247,6 +9284,156 @@ class MappableExprsHandler {
     }
   }
 
+  /// On a target construct, if there's an implicit map on a struct, or that of
+  /// this[:], and an explicit map with a member of that struct/class as the
+  /// base-pointer, we need to make sure that base-pointer is implicitly mapped,
+  /// to make sure we don't map the full struct/class. For example:
+  ///
+  /// \code
+  ///   struct S {
+  ///     int dummy[10000];
+  ///     int *p;
+  ///     void f1() {
+  ///       #pragma omp target map(p[0:1])
+  ///       (void)this;
+  ///     }
+  ///   }; S s;
+  ///
+  ///   void f2() {
+  ///     #pragma omp target map(s.p[0:10])
+  ///     (void)s;
+  ///   }
+  /// \endcode
+  ///
+  /// Only `this-p` and `s.p` should be mapped in the two cases above.
+  //
+  // OpenMP 6.0: 7.9.6 map clause, pg 285
+  // If a list item with an implicitly determined data-mapping attribute does
+  // not have any corresponding storage in the device data environment prior to
+  // a task encountering the construct associated with the map clause, and one
+  // or more contiguous parts of the original storage are either list items or
+  // base pointers to list items that are explicitly mapped on the construct,
+  // only those parts of the original storage will have corresponding storage in
+  // the device data environment as a result of the map clauses on the
+  // construct.
+  void addImplicitMapForAttachPtrBaseIfMemberOfCapturedVD(
+      const ValueDecl *CapturedVD, MapDataArrayTy &DeclComponentLists,
+      SmallVectorImpl<
+          SmallVector<OMPClauseMappableExprCommon::MappableComponent, 8>>
+          &ComponentVectorStorage) const {
----------------
abhinavgaba wrote:

This function is not called in this PR, which is what makes it an NFC. Ans since we are never adding the ATTACH map-type in this PR, the changes in OMPIRBuilder changes are also never triggered.

The reason to pull these changes out of the parent was just to help with the reviews.

If you don't think it's easier to review this as a subset, then please continue with reviewing the parent https://github.com/llvm/llvm-project/pull/153683, and this one can be closed.

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


More information about the llvm-commits mailing list