Skip to content

Commit b54be00

Browse files
authored
[Flang][OpenMP] Process motion clauses in a single call (NFC) (#108046)
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 potentially refactor `processMap()`, `processMotionClauses()`, `processUseDeviceAddr()` and `processUseDevicePtr()`, and minimize code duplication among these.
1 parent f710612 commit b54be00

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
@@ -1009,6 +1009,37 @@ bool ClauseProcessor::processMap(
10091009
return clauseFound;
10101010
}
10111011

1012+
bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
1013+
mlir::omp::MapClauseOps &result) {
1014+
std::map<const semantics::Symbol *,
1015+
llvm::SmallVector<OmpMapMemberIndicesData>>
1016+
parentMemberIndices;
1017+
llvm::SmallVector<const semantics::Symbol *> mapSymbols;
1018+
1019+
auto callbackFn = [&](const auto &clause, const parser::CharBlock &source) {
1020+
mlir::Location clauseLocation = converter.genLocation(source);
1021+
1022+
// TODO Support motion modifiers: present, mapper, iterator.
1023+
constexpr llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
1024+
std::is_same_v<llvm::remove_cvref_t<decltype(clause)>, omp::clause::To>
1025+
? llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO
1026+
: llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
1027+
1028+
processMapObjects(stmtCtx, clauseLocation, std::get<ObjectList>(clause.t),
1029+
mapTypeBits, parentMemberIndices, result.mapVars,
1030+
&mapSymbols);
1031+
};
1032+
1033+
bool clauseFound = findRepeatableClause<omp::clause::To>(callbackFn);
1034+
clauseFound =
1035+
findRepeatableClause<omp::clause::From>(callbackFn) || clauseFound;
1036+
1037+
insertChildMapInfoIntoParent(converter, parentMemberIndices, result.mapVars,
1038+
mapSymbols,
1039+
/*mapSymTypes=*/nullptr, /*mapSymLocs=*/nullptr);
1040+
return clauseFound;
1041+
}
1042+
10121043
bool ClauseProcessor::processNontemporal(
10131044
mlir::omp::NontemporalClauseOps &result) const {
10141045
return findRepeatableClause<omp::clause::Nontemporal>(

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 processNontemporal(mlir::omp::NontemporalClauseOps &result) const;
125127
bool processReduction(
126128
mlir::Location currentLocation, mlir::omp::ReductionClauseOps &result,
@@ -141,9 +143,6 @@ class ClauseProcessor {
141143
llvm::SmallVectorImpl<mlir::Location> &useDeviceLocs,
142144
llvm::SmallVectorImpl<const semantics::Symbol *> &useDeviceSyms) const;
143145

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

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