Skip to content

Commit 852e477

Browse files
authored
[flang][OpenMP] Add Id function to OmpClause to return clause id,… (#112712)
… NFC This replaces the two instances of `GetClauseKindForParserClass` with a localized member function.
1 parent 7be1dc0 commit 852e477

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

flang/include/flang/Parser/parse-tree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "flang/Common/idioms.h"
2727
#include "flang/Common/indirection.h"
2828
#include "llvm/Frontend/OpenACC/ACC.h.inc"
29+
#include "llvm/Frontend/OpenMP/OMP.h"
2930
#include "llvm/Frontend/OpenMP/OMPConstants.h"
3031
#include <cinttypes>
3132
#include <list>
@@ -3660,6 +3661,7 @@ struct OmpLastprivateClause {
36603661
// OpenMP Clauses
36613662
struct OmpClause {
36623663
UNION_CLASS_BOILERPLATE(OmpClause);
3664+
llvm::omp::Clause Id() const;
36633665

36643666
#define GEN_FLANG_CLAUSE_PARSER_CLASSES
36653667
#include "llvm/Frontend/OpenMP/OMP.inc"

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,6 @@
2222
#include <utility>
2323
#include <variant>
2424

25-
namespace detail {
26-
template <typename C>
27-
llvm::omp::Clause getClauseIdForClass(C &&) {
28-
using namespace Fortran;
29-
using A = llvm::remove_cvref_t<C>; // A is referenced in OMP.inc
30-
// The code included below contains a sequence of checks like the following
31-
// for each OpenMP clause
32-
// if constexpr (std::is_same_v<A, parser::OmpClause::AcqRel>)
33-
// return llvm::omp::Clause::OMPC_acq_rel;
34-
// [...]
35-
#define GEN_FLANG_CLAUSE_PARSER_KIND_MAP
36-
#include "llvm/Frontend/OpenMP/OMP.inc"
37-
}
38-
} // namespace detail
39-
40-
static llvm::omp::Clause getClauseId(const Fortran::parser::OmpClause &clause) {
41-
return Fortran::common::visit(
42-
[](auto &&s) { return detail::getClauseIdForClass(s); }, clause.u);
43-
}
44-
4525
namespace Fortran::lower::omp {
4626
using SymbolWithDesignator = std::tuple<semantics::Symbol *, MaybeExpr>;
4727

@@ -1253,8 +1233,7 @@ Clause makeClause(const parser::OmpClause &cls,
12531233
semantics::SemanticsContext &semaCtx) {
12541234
return Fortran::common::visit(
12551235
[&](auto &&s) {
1256-
return makeClause(getClauseId(cls), clause::make(s, semaCtx),
1257-
cls.source);
1236+
return makeClause(cls.Id(), clause::make(s, semaCtx), cls.source);
12581237
},
12591238
cls.u);
12601239
}

flang/lib/Parser/parse-tree.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,21 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Name &x) {
253253
return os << x.ToString();
254254
}
255255
} // namespace Fortran::parser
256+
257+
template <typename C> static llvm::omp::Clause getClauseIdForClass(C &&) {
258+
using namespace Fortran;
259+
using A = llvm::remove_cvref_t<C>; // A is referenced in OMP.inc
260+
// The code included below contains a sequence of checks like the following
261+
// for each OpenMP clause
262+
// if constexpr (std::is_same_v<A, parser::OmpClause::AcqRel>)
263+
// return llvm::omp::Clause::OMPC_acq_rel;
264+
// [...]
265+
#define GEN_FLANG_CLAUSE_PARSER_KIND_MAP
266+
#include "llvm/Frontend/OpenMP/OMP.inc"
267+
}
268+
269+
namespace Fortran::parser {
270+
llvm::omp::Clause OmpClause::Id() const {
271+
return std::visit([](auto &&s) { return getClauseIdForClass(s); }, u);
272+
}
273+
} // namespace Fortran::parser

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,11 +2363,8 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) {
23632363
void OmpStructureChecker::Enter(const parser::OmpClause &x) {
23642364
SetContextClause(x);
23652365

2366-
llvm::omp::Clause clauseId = std::visit(
2367-
[this](auto &&s) { return GetClauseKindForParserClass(s); }, x.u);
2368-
23692366
// The visitors for these clauses do their own checks.
2370-
switch (clauseId) {
2367+
switch (x.Id()) {
23712368
case llvm::omp::Clause::OMPC_copyprivate:
23722369
case llvm::omp::Clause::OMPC_enter:
23732370
case llvm::omp::Clause::OMPC_lastprivate:
@@ -3244,7 +3241,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Lastprivate &x) {
32443241
DirectivesClauseTriple dirClauseTriple;
32453242
SymbolSourceMap currSymbols;
32463243
GetSymbolsInObjectList(objectList, currSymbols);
3247-
CheckDefinableObjects(currSymbols, GetClauseKindForParserClass(x));
3244+
CheckDefinableObjects(currSymbols, llvm::omp::Clause::OMPC_lastprivate);
32483245
CheckCopyingPolymorphicAllocatable(
32493246
currSymbols, llvm::omp::Clause::OMPC_lastprivate);
32503247

@@ -3257,7 +3254,7 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Lastprivate &x) {
32573254
llvm::omp::Directive::OMPD_parallel, llvm::omp::privateReductionSet));
32583255

32593256
CheckPrivateSymbolsInOuterCxt(
3260-
currSymbols, dirClauseTriple, GetClauseKindForParserClass(x));
3257+
currSymbols, dirClauseTriple, llvm::omp::Clause::OMPC_lastprivate);
32613258

32623259
using LastprivateModifier = parser::OmpLastprivateClause::LastprivateModifier;
32633260
const auto &maybeMod{std::get<std::optional<LastprivateModifier>>(x.v.t)};

flang/lib/Semantics/check-omp-structure.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ class OmpStructureChecker
132132
#define GEN_FLANG_CLAUSE_CHECK_ENTER
133133
#include "llvm/Frontend/OpenMP/OMP.inc"
134134

135-
// Get the OpenMP Clause Kind for the corresponding Parser class
136-
template <typename A>
137-
llvm::omp::Clause GetClauseKindForParserClass(const A &) {
138-
#define GEN_FLANG_CLAUSE_PARSER_KIND_MAP
139-
#include "llvm/Frontend/OpenMP/OMP.inc"
140-
}
141-
142135
private:
143136
bool CheckAllowedClause(llvmOmpClause clause);
144137
bool IsVariableListItem(const Symbol &sym);

0 commit comments

Comments
 (0)