Skip to content

Commit 4b29ee4

Browse files
authored
[LLVM][OpenMP] Add "version" parameter to getOpenMPDirectiveName (#139114)
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
1 parent 4c69f82 commit 4b29ee4

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

llvm/include/llvm/Frontend/OpenMP/OMP.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static constexpr inline bool canHaveIterator(Clause C) {
4747
}
4848
}
4949

50+
static constexpr unsigned FallbackVersion = 52;
5051
ArrayRef<unsigned> getOpenMPVersions();
5152

5253
/// Create a nicer version of a function name for humans to look at.

llvm/unittests/Frontend/OpenMPDecompositionTest.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ struct StringifyClause {
188188
}
189189

190190
static std::string to_str(llvm::omp::Directive D) {
191-
return getOpenMPDirectiveName(D).str();
191+
return getOpenMPDirectiveName(D, llvm::omp::FallbackVersion).str();
192192
}
193193
static std::string to_str(llvm::omp::Clause C) {
194194
return getOpenMPClauseName(C).str();
@@ -279,7 +279,7 @@ struct StringifyClause {
279279
std::string stringify(const omp::DirectiveWithClauses &DWC) {
280280
std::stringstream Stream;
281281

282-
Stream << getOpenMPDirectiveName(DWC.id).str();
282+
Stream << getOpenMPDirectiveName(DWC.id, llvm::omp::FallbackVersion).str();
283283
for (const omp::Clause &C : DWC.clauses)
284284
Stream << ' ' << StringifyClause(C).Str;
285285

llvm/unittests/Frontend/OpenMPParsingTest.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ TEST(OpenMPParsingTest, OpenMPDirectiveKind) {
2323
}
2424

2525
TEST(OpenMPParsingTest, getOpenMPDirectiveName) {
26-
EXPECT_EQ(getOpenMPDirectiveName(OMPD_unknown), "unknown");
26+
EXPECT_EQ(getOpenMPDirectiveName(OMPD_unknown, FallbackVersion), "unknown");
2727

28-
EXPECT_EQ(getOpenMPDirectiveName(OMPD_for), "for");
29-
EXPECT_EQ(getOpenMPDirectiveName(OMPD_simd), "simd");
30-
EXPECT_EQ(getOpenMPDirectiveName(OMPD_for_simd), "for simd");
28+
EXPECT_EQ(getOpenMPDirectiveName(OMPD_for, FallbackVersion), "for");
29+
EXPECT_EQ(getOpenMPDirectiveName(OMPD_simd, FallbackVersion), "simd");
30+
EXPECT_EQ(getOpenMPDirectiveName(OMPD_for_simd, FallbackVersion), "for simd");
3131
}
3232

3333
TEST(OpenMPParsingTest, getOpenMPClauseKind) {

llvm/utils/TableGen/Basic/DirectiveEmitter.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,13 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
244244
OS << "LLVM_ABI Directive get" << DirLang.getName()
245245
<< "DirectiveKind(llvm::StringRef Str);\n";
246246
OS << "\n";
247+
// For OpenMP the signature is
248+
// getOpenMPDirectiveName(Directive D, unsigned V)
247249
OS << "LLVM_ABI llvm::StringRef get" << DirLang.getName()
248-
<< "DirectiveName(Directive D);\n";
250+
<< "DirectiveName(Directive D";
251+
if (DirLang.getCppNamespace() == "omp")
252+
OS << ", unsigned = 0";
253+
OS << ");\n";
249254
OS << "\n";
250255
OS << "LLVM_ABI Clause get" << DirLang.getName()
251256
<< "ClauseKind(llvm::StringRef Str);\n";
@@ -280,9 +285,14 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
280285
static void generateGetName(ArrayRef<const Record *> Records, raw_ostream &OS,
281286
StringRef Enum, const DirectiveLanguage &DirLang,
282287
StringRef Prefix) {
288+
// For OpenMP the "Directive" signature is
289+
// getOpenMPDirectiveName(Directive D, unsigned V)
283290
OS << "\n";
284291
OS << "llvm::StringRef llvm::" << DirLang.getCppNamespace() << "::get"
285-
<< DirLang.getName() << Enum << "Name(" << Enum << " Kind) {\n";
292+
<< DirLang.getName() << Enum << "Name(" << Enum << " Kind";
293+
if (DirLang.getCppNamespace() == "omp" && Enum == "Directive")
294+
OS << ", unsigned";
295+
OS << ") {\n";
286296
OS << " switch (Kind) {\n";
287297
for (const BaseRecord Rec : Records) {
288298
OS << " case " << Prefix << Rec.getFormattedName() << ":\n";

0 commit comments

Comments
 (0)