[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:18 PST 2026
https://github.com/agozillon created https://github.com/llvm/llvm-project/pull/177737
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.
>From 9704192825c962f77094c8f3fafb44d91a5316af Mon Sep 17 00:00:00 2001
From: agozillon <Andrew.Gozillon at amd.com>
Date: Fri, 23 Jan 2026 23:45:34 -0600
Subject: [PATCH] [Flang][OpenMP] Skip intermediate map generation for motion
modifier map directives
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
inbetween 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
memberr. 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.
---
flang/lib/Lower/OpenMP/ClauseProcessor.cpp | 7 ++++---
flang/lib/Lower/OpenMP/ClauseProcessor.h | 3 ++-
2 files changed, 6 insertions(+), 4 deletions(-)
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;
More information about the flang-commits
mailing list