Skip to content

[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

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/Frontend/OpenMP/OMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/Frontend/OpenMPDecompositionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions llvm/unittests/Frontend/OpenMPParsingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 12 additions & 2 deletions llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
Loading