[flang-commits] [flang] [Flang][OpenMP] Skip intermediate map generation for motion modifier map directives (PR #177737)

via flang-commits flang-commits at lists.llvm.org
Fri Jan 23 22:00:51 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: None (agozillon)

<details>
<summary>Changes</summary>

Currently if we create the following map:

!$omp target update from/to(derived_type%allocatable)

We'll generate an extra map for the derived type (and any other allocatable maps that may be in-between the final mapped allocatable member). However, for cases like this, and other motion modifier related map directives we don't need to do so. All the user cares about is the specified member. Removing the intermediate member will minimize extra performance overhead. It also maintains correctness, as currently, the MLIR diagnostics for the motion modifiers restricts possible map types for updates to to and from, and applying this map type to an intermediate map will result in unintended side affects, e.g. mapping back data the user didn't want to or over-writing data they didn't intend to on device. This minor modification addresses that.

---
Full diff: https://github.com/llvm/llvm-project/pull/177737.diff


2 Files Affected:

- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+4-3) 
- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.h (+2-1) 


``````````diff
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index ec2c880437f33..76c5ff58a2257 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -1283,7 +1283,7 @@ void ClauseProcessor::processMapObjects(
     std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
     llvm::SmallVectorImpl<mlir::Value> &mapVars,
     llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
-    llvm::StringRef mapperIdNameRef) const {
+    llvm::StringRef mapperIdNameRef, bool isMotionModifier) const {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
 
   auto getSymbolDerivedType = [](const semantics::Symbol &symbol)
@@ -1381,7 +1381,7 @@ void ClauseProcessor::processMapObjects(
             treatIndexAsSection);
 
     mlir::Value baseOp = info.rawInput;
-    if (object.sym()->owner().IsDerivedType()) {
+    if (object.sym()->owner().IsDerivedType() && !isMotionModifier) {
       omp::ObjectList objectList = gatherObjectsOf(object, semaCtx);
       assert(!objectList.empty() &&
              "could not find parent objects of derived type member");
@@ -1559,7 +1559,8 @@ bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
     if (expectation && *expectation == omp::clause::To::Expectation::Present)
       mapTypeBits |= mlir::omp::ClauseMapFlags::present;
     processMapObjects(stmtCtx, clauseLocation, objects, mapTypeBits,
-                      parentMemberIndices, result.mapVars, mapSymbols);
+                      parentMemberIndices, result.mapVars, mapSymbols, "",
+                      true);
   };
 
   bool clauseFound = findRepeatableClause<omp::clause::To>(callbackFn);
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index 063da68fb5702..56e90b59a1e52 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -203,7 +203,8 @@ class ClauseProcessor {
       std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
       llvm::SmallVectorImpl<mlir::Value> &mapVars,
       llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
-      llvm::StringRef mapperIdNameRef = "") const;
+      llvm::StringRef mapperIdNameRef = "",
+      bool isMotionModifier = false) const;
 
   lower::AbstractConverter &converter;
   semantics::SemanticsContext &semaCtx;

``````````

</details>


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


More information about the flang-commits mailing list