Skip to content

Commit ebb0c9c

Browse files
authored
[flang][OpenMP] Move some utilities from openmp-parsers to openmp-uti… (llvm#169188)
…ls, NFC
1 parent d96a93f commit ebb0c9c

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

flang/include/flang/Parser/openmp-utils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ const OpenMPConstruct *GetOmp(const ExecutionPartConstruct &x);
126126
const OpenMPLoopConstruct *GetOmpLoop(const ExecutionPartConstruct &x);
127127
const DoConstruct *GetDoConstruct(const ExecutionPartConstruct &x);
128128

129+
// Is the template argument "Statement<T>" for some T?
130+
template <typename T> struct IsStatement {
131+
static constexpr bool value{false};
132+
};
133+
template <typename T> struct IsStatement<Statement<T>> {
134+
static constexpr bool value{true};
135+
};
136+
137+
std::optional<Label> GetStatementLabel(const ExecutionPartConstruct &x);
138+
129139
const OmpObjectList *GetOmpObjectList(const OmpClause &clause);
130140

131141
template <typename T>

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,30 +1731,6 @@ struct NonBlockDoConstructParser {
17311731
}
17321732
return std::nullopt;
17331733
}
1734-
1735-
private:
1736-
// Is the template argument "Statement<T>" for some T?
1737-
template <typename T> struct IsStatement {
1738-
static constexpr bool value{false};
1739-
};
1740-
template <typename T> struct IsStatement<Statement<T>> {
1741-
static constexpr bool value{true};
1742-
};
1743-
1744-
// Get the Label from a Statement<...> contained in an ExecutionPartConstruct,
1745-
// or std::nullopt, if there is no Statement<...> contained in there.
1746-
template <typename T>
1747-
static std::optional<Label> GetStatementLabel(const T &stmt) {
1748-
if constexpr (IsStatement<T>::value) {
1749-
return stmt.label;
1750-
} else if constexpr (WrapperTrait<T>) {
1751-
return GetStatementLabel(stmt.v);
1752-
} else if constexpr (UnionTrait<T>) {
1753-
return common::visit(
1754-
[&](auto &&s) { return GetStatementLabel(s); }, stmt.u);
1755-
}
1756-
return std::nullopt;
1757-
}
17581734
};
17591735

17601736
struct LoopNestParser {

flang/lib/Parser/openmp-utils.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ const DoConstruct *GetDoConstruct(const ExecutionPartConstruct &x) {
5858
return nullptr;
5959
}
6060

61+
// Get the Label from a Statement<...> contained in an ExecutionPartConstruct,
62+
// or std::nullopt, if there is no Statement<...> contained in there.
63+
template <typename T>
64+
static std::optional<Label> GetStatementLabelHelper(const T &stmt) {
65+
if constexpr (IsStatement<T>::value) {
66+
return stmt.label;
67+
} else if constexpr (WrapperTrait<T>) {
68+
return GetStatementLabelHelper(stmt.v);
69+
} else if constexpr (UnionTrait<T>) {
70+
return common::visit(
71+
[&](auto &&s) { return GetStatementLabelHelper(s); }, stmt.u);
72+
}
73+
return std::nullopt;
74+
}
75+
76+
std::optional<Label> GetStatementLabel(const ExecutionPartConstruct &x) {
77+
return GetStatementLabelHelper(x);
78+
}
79+
6180
const OmpObjectList *GetOmpObjectList(const OmpClause &clause) {
6281
// Clauses with OmpObjectList as its data member
6382
using MemberObjectListClauses = std::tuple<OmpClause::Copyin,

0 commit comments

Comments
 (0)