-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[LLVM][OpenMP] Add "version" parameter to getOpenMPDirectiveName #139114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Some OpenMP directives have different spellings in different versions of the OpenMP spec. To use the proper spelling for a given spec version pass "version" as a parameter to getOpenMPDirectiveName. This parameter won't be used at the moment, and will have a default value to allow callers not to pass it, for gradual adoption in various components. RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
@llvm/pr-subscribers-flang-openmp Author: Krzysztof Parzyszek (kparzysz) ChangesSome OpenMP directives have different spellings in different versions of the OpenMP spec. To use the proper spelling for a given spec version pass "version" as a parameter to getOpenMPDirectiveName. This parameter won't be used at the moment, and will have a default value to allow callers not to pass it, for gradual adoption in various components. RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507 Full diff: https://github.com/llvm/llvm-project/pull/139114.diff 4 Files Affected:
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index dd771ac3b416f..c3381705093ad 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -47,6 +47,7 @@ static constexpr inline bool canHaveIterator(Clause C) {
}
}
+static constexpr unsigned FallbackVersion = 52;
ArrayRef<unsigned> getOpenMPVersions();
/// Create a nicer version of a function name for humans to look at.
diff --git a/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp b/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp
index d218de225c362..6189d0954891b 100644
--- a/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp
@@ -188,7 +188,7 @@ struct StringifyClause {
}
static std::string to_str(llvm::omp::Directive D) {
- return getOpenMPDirectiveName(D).str();
+ return getOpenMPDirectiveName(D, llvm::omp::FallbackVersion).str();
}
static std::string to_str(llvm::omp::Clause C) {
return getOpenMPClauseName(C).str();
@@ -279,7 +279,7 @@ struct StringifyClause {
std::string stringify(const omp::DirectiveWithClauses &DWC) {
std::stringstream Stream;
- Stream << getOpenMPDirectiveName(DWC.id).str();
+ Stream << getOpenMPDirectiveName(DWC.id, llvm::omp::FallbackVersion).str();
for (const omp::Clause &C : DWC.clauses)
Stream << ' ' << StringifyClause(C).Str;
diff --git a/llvm/unittests/Frontend/OpenMPParsingTest.cpp b/llvm/unittests/Frontend/OpenMPParsingTest.cpp
index 80ec2f0ad4d32..6a02f8a2be69a 100644
--- a/llvm/unittests/Frontend/OpenMPParsingTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPParsingTest.cpp
@@ -23,11 +23,11 @@ TEST(OpenMPParsingTest, OpenMPDirectiveKind) {
}
TEST(OpenMPParsingTest, getOpenMPDirectiveName) {
- EXPECT_EQ(getOpenMPDirectiveName(OMPD_unknown), "unknown");
+ EXPECT_EQ(getOpenMPDirectiveName(OMPD_unknown, FallbackVersion), "unknown");
- EXPECT_EQ(getOpenMPDirectiveName(OMPD_for), "for");
- EXPECT_EQ(getOpenMPDirectiveName(OMPD_simd), "simd");
- EXPECT_EQ(getOpenMPDirectiveName(OMPD_for_simd), "for simd");
+ EXPECT_EQ(getOpenMPDirectiveName(OMPD_for, FallbackVersion), "for");
+ EXPECT_EQ(getOpenMPDirectiveName(OMPD_simd, FallbackVersion), "simd");
+ EXPECT_EQ(getOpenMPDirectiveName(OMPD_for_simd, FallbackVersion), "for simd");
}
TEST(OpenMPParsingTest, getOpenMPClauseKind) {
diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
index 9a0f647f75ad5..339b8d6acd622 100644
--- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
@@ -244,8 +244,13 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
OS << "LLVM_ABI Directive get" << DirLang.getName()
<< "DirectiveKind(llvm::StringRef Str);\n";
OS << "\n";
+ // For OpenMP the signature is
+ // getOpenMPDirectiveName(Directive D, unsigned V)
OS << "LLVM_ABI llvm::StringRef get" << DirLang.getName()
- << "DirectiveName(Directive D);\n";
+ << "DirectiveName(Directive D";
+ if (DirLang.getCppNamespace() == "omp")
+ OS << ", unsigned = 0";
+ OS << ");\n";
OS << "\n";
OS << "LLVM_ABI Clause get" << DirLang.getName()
<< "ClauseKind(llvm::StringRef Str);\n";
@@ -280,9 +285,14 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
static void generateGetName(ArrayRef<const Record *> Records, raw_ostream &OS,
StringRef Enum, const DirectiveLanguage &DirLang,
StringRef Prefix) {
+ // For OpenMP the "Directive" signature is
+ // getOpenMPDirectiveName(Directive D, unsigned V)
OS << "\n";
OS << "llvm::StringRef llvm::" << DirLang.getCppNamespace() << "::get"
- << DirLang.getName() << Enum << "Name(" << Enum << " Kind) {\n";
+ << DirLang.getName() << Enum << "Name(" << Enum << " Kind";
+ if (DirLang.getCppNamespace() == "omp" && Enum == "Directive")
+ OS << ", unsigned";
+ OS << ") {\n";
OS << " switch (Kind) {\n";
for (const BaseRecord Rec : Records) {
OS << " case " << Prefix << Rec.getFormattedName() << ":\n";
|
@llvm/pr-subscribers-tablegen Author: Krzysztof Parzyszek (kparzysz) ChangesSome OpenMP directives have different spellings in different versions of the OpenMP spec. To use the proper spelling for a given spec version pass "version" as a parameter to getOpenMPDirectiveName. This parameter won't be used at the moment, and will have a default value to allow callers not to pass it, for gradual adoption in various components. RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507 Full diff: https://github.com/llvm/llvm-project/pull/139114.diff 4 Files Affected:
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h b/llvm/include/llvm/Frontend/OpenMP/OMP.h
index dd771ac3b416f..c3381705093ad 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h
@@ -47,6 +47,7 @@ static constexpr inline bool canHaveIterator(Clause C) {
}
}
+static constexpr unsigned FallbackVersion = 52;
ArrayRef<unsigned> getOpenMPVersions();
/// Create a nicer version of a function name for humans to look at.
diff --git a/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp b/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp
index d218de225c362..6189d0954891b 100644
--- a/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPDecompositionTest.cpp
@@ -188,7 +188,7 @@ struct StringifyClause {
}
static std::string to_str(llvm::omp::Directive D) {
- return getOpenMPDirectiveName(D).str();
+ return getOpenMPDirectiveName(D, llvm::omp::FallbackVersion).str();
}
static std::string to_str(llvm::omp::Clause C) {
return getOpenMPClauseName(C).str();
@@ -279,7 +279,7 @@ struct StringifyClause {
std::string stringify(const omp::DirectiveWithClauses &DWC) {
std::stringstream Stream;
- Stream << getOpenMPDirectiveName(DWC.id).str();
+ Stream << getOpenMPDirectiveName(DWC.id, llvm::omp::FallbackVersion).str();
for (const omp::Clause &C : DWC.clauses)
Stream << ' ' << StringifyClause(C).Str;
diff --git a/llvm/unittests/Frontend/OpenMPParsingTest.cpp b/llvm/unittests/Frontend/OpenMPParsingTest.cpp
index 80ec2f0ad4d32..6a02f8a2be69a 100644
--- a/llvm/unittests/Frontend/OpenMPParsingTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPParsingTest.cpp
@@ -23,11 +23,11 @@ TEST(OpenMPParsingTest, OpenMPDirectiveKind) {
}
TEST(OpenMPParsingTest, getOpenMPDirectiveName) {
- EXPECT_EQ(getOpenMPDirectiveName(OMPD_unknown), "unknown");
+ EXPECT_EQ(getOpenMPDirectiveName(OMPD_unknown, FallbackVersion), "unknown");
- EXPECT_EQ(getOpenMPDirectiveName(OMPD_for), "for");
- EXPECT_EQ(getOpenMPDirectiveName(OMPD_simd), "simd");
- EXPECT_EQ(getOpenMPDirectiveName(OMPD_for_simd), "for simd");
+ EXPECT_EQ(getOpenMPDirectiveName(OMPD_for, FallbackVersion), "for");
+ EXPECT_EQ(getOpenMPDirectiveName(OMPD_simd, FallbackVersion), "simd");
+ EXPECT_EQ(getOpenMPDirectiveName(OMPD_for_simd, FallbackVersion), "for simd");
}
TEST(OpenMPParsingTest, getOpenMPClauseKind) {
diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
index 9a0f647f75ad5..339b8d6acd622 100644
--- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
@@ -244,8 +244,13 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
OS << "LLVM_ABI Directive get" << DirLang.getName()
<< "DirectiveKind(llvm::StringRef Str);\n";
OS << "\n";
+ // For OpenMP the signature is
+ // getOpenMPDirectiveName(Directive D, unsigned V)
OS << "LLVM_ABI llvm::StringRef get" << DirLang.getName()
- << "DirectiveName(Directive D);\n";
+ << "DirectiveName(Directive D";
+ if (DirLang.getCppNamespace() == "omp")
+ OS << ", unsigned = 0";
+ OS << ");\n";
OS << "\n";
OS << "LLVM_ABI Clause get" << DirLang.getName()
<< "ClauseKind(llvm::StringRef Str);\n";
@@ -280,9 +285,14 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
static void generateGetName(ArrayRef<const Record *> Records, raw_ostream &OS,
StringRef Enum, const DirectiveLanguage &DirLang,
StringRef Prefix) {
+ // For OpenMP the "Directive" signature is
+ // getOpenMPDirectiveName(Directive D, unsigned V)
OS << "\n";
OS << "llvm::StringRef llvm::" << DirLang.getCppNamespace() << "::get"
- << DirLang.getName() << Enum << "Name(" << Enum << " Kind) {\n";
+ << DirLang.getName() << Enum << "Name(" << Enum << " Kind";
+ if (DirLang.getCppNamespace() == "omp" && Enum == "Directive")
+ OS << ", unsigned";
+ OS << ") {\n";
OS << " switch (Kind) {\n";
for (const BaseRecord Rec : Records) {
OS << " case " << Prefix << Rec.getFormattedName() << ":\n";
|
Next PR: #139115 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Some OpenMP directives have different spellings in different versions of the OpenMP spec. To use the proper spelling for a given spec version pass "version" as a parameter to getOpenMPDirectiveName.
This parameter won't be used at the moment, and will have a default value to allow callers not to pass it, for gradual adoption in various components.
RFC: https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507