[flang-commits] [flang] 5e1873a - [OpenMP] Add constexpr enum ranges for all clauses and all directives (#210406)
via flang-commits
flang-commits at lists.llvm.org
Sun Jul 19 05:22:04 PDT 2026
Author: Krzysztof Parzyszek
Date: 2026-07-19T07:21:59-05:00
New Revision: 5e1873abad44f622c7a18304b1552c233d47bd16
URL: https://github.com/llvm/llvm-project/commit/5e1873abad44f622c7a18304b1552c233d47bd16
DIFF: https://github.com/llvm/llvm-project/commit/5e1873abad44f622c7a18304b1552c233d47bd16.diff
LOG: [OpenMP] Add constexpr enum ranges for all clauses and all directives (#210406)
<sub>Stack created with <a
href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a
href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
Added:
Modified:
flang/lib/Parser/openmp-parsers.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.h
llvm/lib/Frontend/OpenMP/OMP.cpp
llvm/unittests/Frontend/OpenMPDirectiveNameParserTest.cpp
Removed:
################################################################################
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 105a72de5cb29..9051d5863df07 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -2622,19 +2622,16 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
Parser<OmpDelimitedMetadirectiveDirective>{}))))
static constexpr DirectiveSet GetLoopDirectives() {
- using Directive = llvm::omp::Directive;
using SourceLanguage = llvm::omp::SourceLanguage;
DirectiveSet loopDirectives;
- for (auto dirVal{llvm::to_underlying(Directive::First_)};
- dirVal != llvm::to_underlying(Directive::Last_) + 1; ++dirVal) {
- auto dirId{static_cast<Directive>(dirVal)};
+ for (auto dirId : llvm::omp::directives()) {
auto assoc{getDirectiveAssociation(dirId)};
if (assoc == llvm::omp::Association::LoopNest ||
assoc == llvm::omp::Association::LoopSeq) {
auto langs{getDirectiveLanguages(dirId)};
if (llvm::to_underlying(langs & SourceLanguage::Fortran) != 0) {
- loopDirectives.set(dirVal);
+ loopDirectives.set(llvm::to_underlying(dirId));
}
}
}
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index 530f3f1410212..f54352adaa8b8 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -17,6 +17,7 @@
#include "llvm/Support/Compiler.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
@@ -33,6 +34,14 @@ LLVM_ABI bool isLeafConstruct(Directive D);
LLVM_ABI bool isCompositeConstruct(Directive D);
LLVM_ABI bool isCombinedConstruct(Directive D);
+static constexpr inline auto clauses() {
+ return llvm::enum_seq_inclusive(Clause::First_, Clause::Last_);
+}
+
+static constexpr inline auto directives() {
+ return llvm::enum_seq_inclusive(Directive::First_, Directive::Last_);
+}
+
/// Can clause C have an iterator-modifier.
static constexpr inline bool canHaveIterator(Clause C) {
// [5.2:67:5]
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index 86e144624211c..4e18f49395e4c 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -81,14 +81,12 @@ static void
collectPrivatizingConstructs(llvm::SmallSet<Directive, 16> &Constructs,
unsigned Version) {
llvm::SmallSet<Clause, 16> Privatizing;
- for (auto C :
- llvm::enum_seq_inclusive<Clause>(Clause::First_, Clause::Last_)) {
+ for (auto C : clauses()) {
if (isPrivatizingClause(C, Version))
Privatizing.insert(C);
}
- for (auto D : llvm::enum_seq_inclusive<Directive>(Directive::First_,
- Directive::Last_)) {
+ for (auto D : directives()) {
bool AllowsPrivatizing = llvm::any_of(Privatizing, [&](Clause C) {
return isAllowedClauseForDirective(D, C, Version);
});
diff --git a/llvm/unittests/Frontend/OpenMPDirectiveNameParserTest.cpp b/llvm/unittests/Frontend/OpenMPDirectiveNameParserTest.cpp
index 10329820bef76..3d6ccc744b362 100644
--- a/llvm/unittests/Frontend/OpenMPDirectiveNameParserTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPDirectiveNameParserTest.cpp
@@ -82,8 +82,7 @@ getParamName1(const testing::TestParamInfo<Tokenize::ParamType> &Info) {
}
INSTANTIATE_TEST_SUITE_P(DirectiveNameParserTest, Tokenize,
- testing::ValuesIn(llvm::enum_seq_inclusive(
- omp::Directive::First_, omp::Directive::Last_)),
+ testing::ValuesIn(llvm::omp::directives()),
getParamName1);
// Test parsing of valid names.
@@ -123,8 +122,7 @@ getParamName2(const testing::TestParamInfo<ParseValid::ParamType> &Info) {
INSTANTIATE_TEST_SUITE_P(
DirectiveNameParserTest, ParseValid,
- testing::Combine(testing::ValuesIn(llvm::enum_seq_inclusive(
- omp::Directive::First_, omp::Directive::Last_)),
+ testing::Combine(testing::ValuesIn(llvm::omp::directives()),
testing::ValuesIn(omp::getOpenMPVersions())),
getParamName2);
More information about the flang-commits
mailing list