Revert "[TableGen] Emit constexpr versions of some directive/clause f… (#177161)

…unctions (#176253)"

This reverts commit cf68af690ba7f98943e5f0f5cb39a91868d62098.

It increased the compilation time for a number of clang source files.
See comments in https://github.com/llvm/llvm-project/pull/176253 for
more information.
This commit is contained in:
Krzysztof Parzyszek 2026-01-21 08:06:55 -06:00 committed by GitHub
parent c13a730c89
commit 5875490909
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 90 additions and 221 deletions

View File

@ -58,7 +58,6 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// CHECK-NEXT: #include "llvm/Frontend/Directive/Spelling.h"
// CHECK-NEXT: #include "llvm/Support/Compiler.h"
// CHECK-NEXT: #include <cstddef>
// CHECK-NEXT: #include <optional>
// CHECK-NEXT: #include <utility>
// CHECK-EMPTY:
// CHECK-NEXT: namespace llvm {
@ -136,48 +135,6 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// CHECK-NEXT: constexpr auto TDLCV_valb = AKind::TDLCV_valb;
// CHECK-NEXT: constexpr auto TDLCV_valc = AKind::TDLCV_valc;
// CHECK-EMPTY:
// CHECK-NEXT: // Constexpr functions.
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::optional<bool> isAllowedClauseForDirectiveOpt(Directive D, Clause C, unsigned Version) {
// CHECK-NEXT: switch (D) {
// CHECK-NEXT: case TDLD_dira:
// CHECK-NEXT: switch (C) {
// CHECK-NEXT: case TDLC_clausea:
// CHECK-NEXT: return 1 <= Version && 2147483647 >= Version;
// CHECK-NEXT: case TDLC_clauseb:
// CHECK-NEXT: return 1 <= Version && 2147483647 >= Version;
// CHECK-NEXT: default:
// CHECK-NEXT: return false;
// CHECK-NEXT: }
// CHECK-NEXT: break;
// CHECK-NEXT: }
// CHECK-NEXT: return std::nullopt;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::optional<Association> getDirectiveAssociationOpt(Directive D) {
// CHECK-NEXT: switch (D) {
// CHECK-NEXT: case TDLD_dira:
// CHECK-NEXT: return Association::None;
// CHECK-NEXT: } // switch (D)
// CHECK-NEXT: return std::nullopt;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::optional<Category> getDirectiveCategoryOpt(Directive D) {
// CHECK-NEXT: switch (D) {
// CHECK-NEXT: case TDLD_dira:
// CHECK-NEXT: return Category::Executable;
// CHECK-NEXT: } // switch (D)
// CHECK-NEXT: return std::nullopt;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::optional<SourceLanguage> getDirectiveLanguagesOpt(Directive D) {
// CHECK-NEXT: switch (D) {
// CHECK-NEXT: case TDLD_dira:
// CHECK-NEXT: return SourceLanguage::C | SourceLanguage::Fortran;
// CHECK-NEXT: } // switch(D)
// CHECK-NEXT: return std::nullopt;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: // Enumeration helper functions
// CHECK-NEXT: LLVM_ABI std::pair<Directive, directive::VersionRange> getTdlDirectiveKindAndVersions(StringRef Str);
// CHECK-NEXT: inline Directive getTdlDirectiveKind(StringRef Str) {
@ -459,30 +416,42 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(llvm::tdl::Directive D, llvm::tdl::Clause C, unsigned Version) {
// IMPL-NEXT: assert(unsigned(D) <= Directive_enumSize);
// IMPL-NEXT: assert(unsigned(C) <= Clause_enumSize);
// IMPL-NEXT: if (auto X = isAllowedClauseForDirectiveOpt(D, C, Version)) {
// IMPL-NEXT: return *X;
// IMPL-NEXT: switch (D) {
// IMPL-NEXT: case TDLD_dira:
// IMPL-NEXT: switch (C) {
// IMPL-NEXT: case TDLC_clausea:
// IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
// IMPL-NEXT: case TDLC_clauseb:
// IMPL-NEXT: return 1 <= Version && 2147483647 >= Version;
// IMPL-NEXT: default:
// IMPL-NEXT: return false;
// IMPL-NEXT: }
// IMPL-NEXT: break;
// IMPL-NEXT: }
// IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
// IMPL-NEXT: }
// IMPL-EMPTY:
// IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive D) {
// IMPL-NEXT: if (auto X = getDirectiveAssociationOpt(D)) {
// IMPL-NEXT: return *X;
// IMPL-NEXT: }
// IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive Dir) {
// IMPL-NEXT: switch (Dir) {
// IMPL-NEXT: case TDLD_dira:
// IMPL-NEXT: return Association::None;
// IMPL-NEXT: } // switch (Dir)
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
// IMPL-NEXT: }
// IMPL-EMPTY:
// IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive D) {
// IMPL-NEXT: if (auto X = getDirectiveCategoryOpt(D)) {
// IMPL-NEXT: return *X;
// IMPL-NEXT: }
// IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive Dir) {
// IMPL-NEXT: switch (Dir) {
// IMPL-NEXT: case TDLD_dira:
// IMPL-NEXT: return Category::Executable;
// IMPL-NEXT: } // switch (Dir)
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
// IMPL-NEXT: }
// IMPL-EMPTY:
// IMPL-NEXT: llvm::tdl::SourceLanguage llvm::tdl::getDirectiveLanguages(llvm::tdl::Directive D) {
// IMPL-NEXT: if (auto X = getDirectiveLanguagesOpt(D)) {
// IMPL-NEXT: return *X;
// IMPL-NEXT: }
// IMPL-NEXT: switch (D) {
// IMPL-NEXT: case TDLD_dira:
// IMPL-NEXT: return SourceLanguage::C | SourceLanguage::Fortran;
// IMPL-NEXT: } // switch(D)
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
// IMPL-NEXT: }
// IMPL-EMPTY:

View File

@ -51,7 +51,6 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// CHECK-NEXT: #include "llvm/Frontend/Directive/Spelling.h"
// CHECK-NEXT: #include "llvm/Support/Compiler.h"
// CHECK-NEXT: #include <cstddef>
// CHECK-NEXT: #include <optional>
// CHECK-NEXT: #include <utility>
// CHECK-EMPTY:
// CHECK-NEXT: namespace llvm {
@ -112,48 +111,6 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// CHECK-EMPTY:
// CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 4;
// CHECK-EMPTY:
// CHECK-NEXT: // Constexpr functions.
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::optional<bool> isAllowedClauseForDirectiveOpt(Directive D, Clause C, unsigned Version) {
// CHECK-NEXT: switch (D) {
// CHECK-NEXT: case TDLD_dira:
// CHECK-NEXT: switch (C) {
// CHECK-NEXT: case TDLC_clausea:
// CHECK-NEXT: return 2 <= Version && 4 >= Version;
// CHECK-NEXT: case TDLC_clauseb:
// CHECK-NEXT: return 2 <= Version && 2147483647 >= Version;
// CHECK-NEXT: default:
// CHECK-NEXT: return false;
// CHECK-NEXT: }
// CHECK-NEXT: break;
// CHECK-NEXT: }
// CHECK-NEXT: return std::nullopt;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::optional<Association> getDirectiveAssociationOpt(Directive D) {
// CHECK-NEXT: switch (D) {
// CHECK-NEXT: case TDLD_dira:
// CHECK-NEXT: return Association::Block;
// CHECK-NEXT: } // switch (D)
// CHECK-NEXT: return std::nullopt;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::optional<Category> getDirectiveCategoryOpt(Directive D) {
// CHECK-NEXT: switch (D) {
// CHECK-NEXT: case TDLD_dira:
// CHECK-NEXT: return Category::Declarative;
// CHECK-NEXT: } // switch (D)
// CHECK-NEXT: return std::nullopt;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: constexpr std::optional<SourceLanguage> getDirectiveLanguagesOpt(Directive D) {
// CHECK-NEXT: switch (D) {
// CHECK-NEXT: case TDLD_dira:
// CHECK-NEXT: return SourceLanguage::C | SourceLanguage::Fortran;
// CHECK-NEXT: } // switch(D)
// CHECK-NEXT: return std::nullopt;
// CHECK-NEXT: }
// CHECK-EMPTY:
// CHECK-NEXT: // Enumeration helper functions
// CHECK-NEXT: LLVM_ABI std::pair<Directive, directive::VersionRange> getTdlDirectiveKindAndVersions(StringRef Str);
// CHECK-NEXT: inline Directive getTdlDirectiveKind(StringRef Str) {
@ -384,30 +341,42 @@ def TDL_DirA : Directive<[Spelling<"dira">]> {
// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(llvm::tdl::Directive D, llvm::tdl::Clause C, unsigned Version) {
// IMPL-NEXT: assert(unsigned(D) <= Directive_enumSize);
// IMPL-NEXT: assert(unsigned(C) <= Clause_enumSize);
// IMPL-NEXT: if (auto X = isAllowedClauseForDirectiveOpt(D, C, Version)) {
// IMPL-NEXT: return *X;
// IMPL-NEXT: switch (D) {
// IMPL-NEXT: case TDLD_dira:
// IMPL-NEXT: switch (C) {
// IMPL-NEXT: case TDLC_clausea:
// IMPL-NEXT: return 2 <= Version && 4 >= Version;
// IMPL-NEXT: case TDLC_clauseb:
// IMPL-NEXT: return 2 <= Version && 2147483647 >= Version;
// IMPL-NEXT: default:
// IMPL-NEXT: return false;
// IMPL-NEXT: }
// IMPL-NEXT: break;
// IMPL-NEXT: }
// IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind");
// IMPL-NEXT: }
// IMPL-EMPTY:
// IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive D) {
// IMPL-NEXT: if (auto X = getDirectiveAssociationOpt(D)) {
// IMPL-NEXT: return *X;
// IMPL-NEXT: }
// IMPL-NEXT: llvm::tdl::Association llvm::tdl::getDirectiveAssociation(llvm::tdl::Directive Dir) {
// IMPL-NEXT: switch (Dir) {
// IMPL-NEXT: case TDLD_dira:
// IMPL-NEXT: return Association::Block;
// IMPL-NEXT: } // switch (Dir)
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
// IMPL-NEXT: }
// IMPL-EMPTY:
// IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive D) {
// IMPL-NEXT: if (auto X = getDirectiveCategoryOpt(D)) {
// IMPL-NEXT: return *X;
// IMPL-NEXT: }
// IMPL-NEXT: llvm::tdl::Category llvm::tdl::getDirectiveCategory(llvm::tdl::Directive Dir) {
// IMPL-NEXT: switch (Dir) {
// IMPL-NEXT: case TDLD_dira:
// IMPL-NEXT: return Category::Declarative;
// IMPL-NEXT: } // switch (Dir)
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
// IMPL-NEXT: }
// IMPL-EMPTY:
// IMPL-NEXT: llvm::tdl::SourceLanguage llvm::tdl::getDirectiveLanguages(llvm::tdl::Directive D) {
// IMPL-NEXT: if (auto X = getDirectiveLanguagesOpt(D)) {
// IMPL-NEXT: return *X;
// IMPL-NEXT: }
// IMPL-NEXT: switch (D) {
// IMPL-NEXT: case TDLD_dira:
// IMPL-NEXT: return SourceLanguage::C | SourceLanguage::Fortran;
// IMPL-NEXT: } // switch(D)
// IMPL-NEXT: llvm_unreachable("Unexpected directive");
// IMPL-NEXT: }
// IMPL-EMPTY:

View File

@ -34,9 +34,6 @@ namespace {
enum class Frontend { LLVM, Flang, Clang };
} // namespace
static void emitDirectivesConstexprImpl(const DirectiveLanguage &DirLang,
raw_ostream &OS);
static StringRef getFESpelling(Frontend FE) {
switch (FE) {
case Frontend::LLVM:
@ -275,9 +272,8 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
OS << "#include \"llvm/ADT/StringRef.h\"\n";
OS << "#include \"llvm/Frontend/Directive/Spelling.h\"\n";
OS << "#include \"llvm/Support/Compiler.h\"\n";
OS << "#include <cstddef>\n"; // Needed for size_t
OS << "#include <optional>\n"; // Needed for constexpr functions
OS << "#include <utility>\n"; // Needed for std::pair
OS << "#include <cstddef>\n"; // for size_t
OS << "#include <utility>\n"; // for std::pair
OS << "\n";
NamespaceEmitter LlvmNS(OS, "llvm");
{
@ -315,11 +311,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
std::string EnumHelperFuncs;
generateClauseEnumVal(DirLang.getClauses(), OS, DirLang, EnumHelperFuncs);
// Emit constexpr functions
emitDirectivesConstexprImpl(DirLang, OS);
// Generic function signatures
OS << "\n";
OS << "// Enumeration helper functions\n";
OS << "LLVM_ABI std::pair<Directive, directive::VersionRange> get" << Lang
@ -546,12 +538,16 @@ static void generateCaseForVersionedClauses(ArrayRef<const Record *> VerClauses,
}
// Generate the isAllowedClauseForDirective function implementation.
static void generateIsAllowedClauseConstexpr(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
// The body is emitted inside the proper namespace, so no qualifications
// are needed.
OS << "constexpr std::optional<bool> isAllowedClauseForDirectiveOpt(";
OS << "Directive D, Clause C, unsigned Version) {\n";
static void generateIsAllowedClause(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
std::string Qual = getQualifier(DirLang);
OS << "\n";
OS << "bool " << Qual << "isAllowedClauseForDirective(" << Qual
<< "Directive D, " << Qual << "Clause C, unsigned Version) {\n";
OS << " assert(unsigned(D) <= Directive_enumSize);\n";
OS << " assert(unsigned(C) <= Clause_enumSize);\n";
OS << " switch (D) {\n";
StringRef Prefix = DirLang.getDirectivePrefix();
@ -588,23 +584,8 @@ static void generateIsAllowedClauseConstexpr(const DirectiveLanguage &DirLang,
}
OS << " }\n"; // End of directives switch
OS << " return std::nullopt;\n";
OS << "}\n"; // End of function isAllowedClauseForDirectiveOpt
}
static void generateIsAllowedClause(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
std::string Qual = getQualifier(DirLang);
StringRef Lang = DirLang.getName();
OS << "bool " << Qual << "isAllowedClauseForDirective(" << Qual
<< "Directive D, " << Qual << "Clause C, unsigned Version) {\n";
OS << " assert(unsigned(D) <= Directive_enumSize);\n";
OS << " assert(unsigned(C) <= Clause_enumSize);\n";
OS << " if (auto X = isAllowedClauseForDirectiveOpt(D, C, Version)) {\n";
OS << " return *X;\n";
OS << " }\n";
OS << " llvm_unreachable(\"Invalid " << Lang << " Directive kind\");\n";
OS << " llvm_unreachable(\"Invalid " << DirLang.getName()
<< " Directive kind\");\n";
OS << "}\n"; // End of function isAllowedClauseForDirective
}
@ -745,9 +726,8 @@ static void emitLeafTable(const DirectiveLanguage &DirLang, raw_ostream &OS,
OS << "\n};\n";
}
static void
generateGetDirectiveAssociationConstexpr(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
static void generateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
enum struct Association {
None = 0, // None should be the smallest value.
Block, // If the order of the rest of these changes, update the
@ -854,41 +834,33 @@ generateGetDirectiveAssociationConstexpr(const DirectiveLanguage &DirLang,
for (const Record *R : DirLang.getDirectives())
CompAssocImpl(R, CompAssocImpl); // Updates AsMap.
StringRef Prefix = DirLang.getDirectivePrefix();
OS << '\n';
OS << "constexpr std::optional<Association> ";
OS << "getDirectiveAssociationOpt(Directive D) {\n";
OS << " switch (D) {\n";
StringRef Prefix = DirLang.getDirectivePrefix();
std::string Qual = getQualifier(DirLang);
OS << Qual << "Association " << Qual << "getDirectiveAssociation(" << Qual
<< "Directive Dir) {\n";
OS << " switch (Dir) {\n";
for (const Record *R : DirLang.getDirectives()) {
if (auto F = AsMap.find(R); F != AsMap.end()) {
OS << " case " << getIdentifierName(R, Prefix) << ":\n";
OS << " return Association::" << GetAssocName(F->second) << ";\n";
}
}
OS << " } // switch (D)\n";
OS << " return std::nullopt;\n";
OS << "}\n";
}
static void generateGetDirectiveAssociation(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
std::string Qual = getQualifier(DirLang);
OS << Qual << "Association ";
OS << Qual << "getDirectiveAssociation(" << Qual << "Directive D) {\n";
OS << " if (auto X = getDirectiveAssociationOpt(D)) {\n";
OS << " return *X;\n";
OS << " }\n";
OS << " } // switch (Dir)\n";
OS << " llvm_unreachable(\"Unexpected directive\");\n";
OS << "}\n";
}
static void
generateGetDirectiveCategoryConstexpr(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
OS << "constexpr std::optional<Category> ";
OS << "getDirectiveCategoryOpt(Directive D) {\n";
OS << " switch (D) {\n";
static void generateGetDirectiveCategory(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
std::string Qual = getQualifier(DirLang);
OS << '\n';
OS << Qual << "Category " << Qual << "getDirectiveCategory(" << Qual
<< "Directive Dir) {\n";
OS << " switch (Dir) {\n";
StringRef Prefix = DirLang.getDirectivePrefix();
@ -898,29 +870,18 @@ generateGetDirectiveCategoryConstexpr(const DirectiveLanguage &DirLang,
OS << " return Category::" << D.getCategory()->getValueAsString("name")
<< ";\n";
}
OS << " } // switch (D)\n";
OS << " return std::nullopt;\n";
OS << "}\n";
}
static void generateGetDirectiveCategory(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
std::string Qual = getQualifier(DirLang);
OS << Qual << "Category ";
OS << Qual << "getDirectiveCategory(" << Qual << "Directive D) {\n";
OS << " if (auto X = getDirectiveCategoryOpt(D)) {\n";
OS << " return *X;\n";
OS << " }\n";
OS << " } // switch (Dir)\n";
OS << " llvm_unreachable(\"Unexpected directive\");\n";
OS << "}\n";
}
static void
generateGetDirectiveLanguagesConstexpr(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
OS << "constexpr std::optional<SourceLanguage> ";
OS << "getDirectiveLanguagesOpt(Directive D) {\n";
static void generateGetDirectiveLanguages(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
std::string Qual = getQualifier(DirLang);
OS << '\n';
OS << Qual << "SourceLanguage " << Qual << "getDirectiveLanguages(" << Qual
<< "Directive D) {\n";
OS << " switch (D) {\n";
StringRef Prefix = DirLang.getDirectivePrefix();
@ -939,19 +900,6 @@ generateGetDirectiveLanguagesConstexpr(const DirectiveLanguage &DirLang,
OS << ";\n";
}
OS << " } // switch(D)\n";
OS << " return std::nullopt;\n";
OS << "}\n";
}
static void generateGetDirectiveLanguages(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
std::string Qual = getQualifier(DirLang);
OS << Qual << "SourceLanguage " << Qual;
OS << "getDirectiveLanguages(" << Qual << "Directive D) {\n";
OS << " if (auto X = getDirectiveLanguagesOpt(D)) {\n";
OS << " return *X;\n";
OS << " }\n";
OS << " llvm_unreachable(\"Unexpected directive\");\n";
OS << "}\n";
}
@ -1362,19 +1310,6 @@ static void generateClauseClassMacro(const DirectiveLanguage &DirLang,
OS << "#undef CLAUSE\n";
}
static void emitDirectivesConstexprImpl(const DirectiveLanguage &DirLang,
raw_ostream &OS) {
OS << "// Constexpr functions.\n";
OS << "\n";
generateIsAllowedClauseConstexpr(DirLang, OS);
OS << "\n";
generateGetDirectiveAssociationConstexpr(DirLang, OS);
OS << "\n";
generateGetDirectiveCategoryConstexpr(DirLang, OS);
OS << "\n";
generateGetDirectiveLanguagesConstexpr(DirLang, OS);
}
// Generate the implemenation for the enumeration in the directive
// language. This code can be included in library.
void emitDirectivesBasicImpl(const DirectiveLanguage &DirLang,
@ -1407,19 +1342,15 @@ void emitDirectivesBasicImpl(const DirectiveLanguage &DirLang,
generateGetClauseVal(DirLang, OS);
// isAllowedClauseForDirective(Directive D, Clause C, unsigned Version)
OS << "\n";
generateIsAllowedClause(DirLang, OS);
// getDirectiveAssociation(Directive D)
OS << "\n";
generateGetDirectiveAssociation(DirLang, OS);
// getDirectiveCategory(Directive D)
OS << "\n";
generateGetDirectiveCategory(DirLang, OS);
// getDirectiveLanguages(Directive D)
OS << "\n";
generateGetDirectiveLanguages(DirLang, OS);
// Leaf table for getLeafConstructs, etc.