Skip to content

Commit c41dfb8

Browse files
committed
[Flang][OpenMP] Process motion clauses in a single call (NFC)
This patch removes the template parameter of the `ClauseProcessor::processMotionClauses()` method and instead processes both `TO` and `FROM` as part of a single call. This also enables moving the implementation out of the header and makes it simpler for a follow-up patch to refactor `processMotionClauses()`, `processMap()`, `processUseDeviceAddr()` and `processUseDevicePtr()` and minimize code duplication among these.
1 parent 5823ac0 commit c41dfb8

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,37 @@ bool ClauseProcessor::processUseDevicePtr(
11141114
return clauseFound;
11151115
}
11161116

1117+
bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
1118+
mlir::omp::MapClauseOps &result) {
1119+
std::map<const semantics::Symbol *,
1120+
llvm::SmallVector<OmpMapMemberIndicesData>>
1121+
parentMemberIndices;
1122+
llvm::SmallVector<const semantics::Symbol *> mapSymbols;
1123+
1124+
auto callbackFn = [&](const auto &clause, const parser::CharBlock &source) {
1125+
mlir::Location clauseLocation = converter.genLocation(source);
1126+
1127+
// TODO Support motion modifiers: present, mapper, iterator.
1128+
constexpr llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
1129+
std::is_same_v<llvm::remove_cvref_t<decltype(clause)>, omp::clause::To>
1130+
? llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO
1131+
: llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
1132+
1133+
processMapObjects(stmtCtx, clauseLocation, std::get<ObjectList>(clause.t),
1134+
mapTypeBits, parentMemberIndices, result.mapVars,
1135+
&mapSymbols);
1136+
};
1137+
1138+
bool clauseFound = findRepeatableClause<omp::clause::To>(callbackFn);
1139+
clauseFound =
1140+
findRepeatableClause<omp::clause::From>(callbackFn) || clauseFound;
1141+
1142+
insertChildMapInfoIntoParent(converter, parentMemberIndices, result.mapVars,
1143+
mapSymbols,
1144+
/*mapSymTypes=*/nullptr, /*mapSymLocs=*/nullptr);
1145+
return clauseFound;
1146+
}
1147+
11171148
} // namespace omp
11181149
} // namespace lower
11191150
} // namespace Fortran

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class ClauseProcessor {
121121
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms = nullptr,
122122
llvm::SmallVectorImpl<mlir::Location> *mapSymLocs = nullptr,
123123
llvm::SmallVectorImpl<mlir::Type> *mapSymTypes = nullptr) const;
124+
bool processMotionClauses(lower::StatementContext &stmtCtx,
125+
mlir::omp::MapClauseOps &result);
124126
bool processReduction(
125127
mlir::Location currentLocation, mlir::omp::ReductionClauseOps &result,
126128
llvm::SmallVectorImpl<mlir::Type> *reductionTypes = nullptr,
@@ -140,9 +142,6 @@ class ClauseProcessor {
140142
llvm::SmallVectorImpl<mlir::Location> &useDeviceLocs,
141143
llvm::SmallVectorImpl<const semantics::Symbol *> &useDeviceSyms) const;
142144

143-
template <typename T>
144-
bool processMotionClauses(lower::StatementContext &stmtCtx,
145-
mlir::omp::MapClauseOps &result);
146145
// Call this method for these clauses that should be supported but are not
147146
// implemented yet. It triggers a compilation error if any of the given
148147
// clauses is found.
@@ -190,38 +189,6 @@ class ClauseProcessor {
190189
List<Clause> clauses;
191190
};
192191

193-
template <typename T>
194-
bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
195-
mlir::omp::MapClauseOps &result) {
196-
std::map<const semantics::Symbol *,
197-
llvm::SmallVector<OmpMapMemberIndicesData>>
198-
parentMemberIndices;
199-
llvm::SmallVector<const semantics::Symbol *> mapSymbols;
200-
201-
bool clauseFound = findRepeatableClause<T>(
202-
[&](const T &clause, const parser::CharBlock &source) {
203-
mlir::Location clauseLocation = converter.genLocation(source);
204-
205-
static_assert(std::is_same_v<T, omp::clause::To> ||
206-
std::is_same_v<T, omp::clause::From>);
207-
208-
// TODO Support motion modifiers: present, mapper, iterator.
209-
constexpr llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
210-
std::is_same_v<T, omp::clause::To>
211-
? llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO
212-
: llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
213-
214-
processMapObjects(stmtCtx, clauseLocation,
215-
std::get<ObjectList>(clause.t), mapTypeBits,
216-
parentMemberIndices, result.mapVars, &mapSymbols);
217-
});
218-
219-
insertChildMapInfoIntoParent(converter, parentMemberIndices, result.mapVars,
220-
mapSymbols,
221-
/*mapSymTypes=*/nullptr, /*mapSymLocs=*/nullptr);
222-
return clauseFound;
223-
}
224-
225192
template <typename... Ts>
226193
void ClauseProcessor::processTODO(mlir::Location currentLocation,
227194
llvm::omp::Directive directive) const {

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,12 +1223,10 @@ static void genTargetEnterExitUpdateDataClauses(
12231223
cp.processDevice(stmtCtx, clauseOps);
12241224
cp.processIf(directive, clauseOps);
12251225

1226-
if (directive == llvm::omp::Directive::OMPD_target_update) {
1227-
cp.processMotionClauses<clause::To>(stmtCtx, clauseOps);
1228-
cp.processMotionClauses<clause::From>(stmtCtx, clauseOps);
1229-
} else {
1226+
if (directive == llvm::omp::Directive::OMPD_target_update)
1227+
cp.processMotionClauses(stmtCtx, clauseOps);
1228+
else
12301229
cp.processMap(loc, stmtCtx, clauseOps);
1231-
}
12321230

12331231
cp.processNowait(clauseOps);
12341232
}

0 commit comments

Comments
 (0)