Index: llvm/include/llvm/Frontend/Directive/DirectiveBase.td =================================================================== --- llvm/include/llvm/Frontend/Directive/DirectiveBase.td +++ llvm/include/llvm/Frontend/Directive/DirectiveBase.td @@ -32,17 +32,6 @@ // Optional prefix used for the generation of the enumerator in the Clause // enum. string clausePrefix = ""; - - // Make the enum values available in the namespace. This allows us to - // write something like Enum_X if we have a `using namespace cppNamespace`. - bit makeEnumAvailableInNamespace = 0; - - // Generate include and macro to enable LLVM BitmaskEnum. - bit enableBitmaskEnumInNamespace = 0; - - // Header file included in the implementation code generated. Ususally the - // output file of the declaration code generation. Can be left blank. - string includeHeader = ""; } // Information about a specific clause. Index: llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt =================================================================== --- llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt +++ llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt @@ -1,3 +1,3 @@ set(LLVM_TARGET_DEFINITIONS OMP.td) -tablegen(LLVM OMP.h.inc --gen-directive-decl) +tablegen(LLVM OMP.inc --gen-directive) add_public_tablegen_target(omp_gen) Index: llvm/include/llvm/Frontend/OpenMP/OMP.h =================================================================== --- /dev/null +++ llvm/include/llvm/Frontend/OpenMP/OMP.h @@ -0,0 +1,53 @@ +#ifndef LLVM_OPENMP_OMP_H +#define LLVM_OPENMP_OMP_H + + +#include "llvm/ADT/BitmaskEnum.h" + +namespace llvm { +class StringRef; +namespace omp { + +LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); + +enum class Directive { +#define DIRECTIVE(name, _) OMPD_ ## name, +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef DIRECTIVE +}; +#define DIRECTIVE_SIZE(n) static constexpr std::size_t Directive_enumSize = n; +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef DIRECTIVE_SIZE + +#define DIRECTIVE(name, _) constexpr auto OMPD_ ## name = Directive::OMPD_ ## name; +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef DIRECTIVE + +enum class Clause { +#define CLAUSE(name) OMPC_ ## name, +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef CLAUSE +}; +#define CLAUSE_SIZE(n) static constexpr std::size_t Clause_enumSize = n; +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef CLAUSE_SIZE + +#define CLAUSE(name) constexpr auto OMPC_ ## name = Clause::OMPC_ ## name; +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef CLAUSE + +// Enumeration helper functions +Directive getOpenMPDirectiveKind(llvm::StringRef Str); + +llvm::StringRef getOpenMPDirectiveName(Directive D); + +Clause getOpenMPClauseKind(llvm::StringRef Str); + +llvm::StringRef getOpenMPClauseName(Clause C); + +/// Return true if \p C is a valid clause for \p D in version \p Version. +bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version); + +} // namespace omp +} // namespace llvm +#endif // LLVM_OpenMP_INC Index: llvm/include/llvm/Frontend/OpenMP/OMP.td =================================================================== --- llvm/include/llvm/Frontend/OpenMP/OMP.td +++ llvm/include/llvm/Frontend/OpenMP/OMP.td @@ -21,9 +21,6 @@ let cppNamespace = "omp"; // final namespace will be llvm::omp let directivePrefix = "OMPD_"; let clausePrefix = "OMPC_"; - let makeEnumAvailableInNamespace = 1; - let enableBitmaskEnumInNamespace = 1; - let includeHeader = "llvm/Frontend/OpenMP/OMP.h.inc"; } //===----------------------------------------------------------------------===// Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h =================================================================== --- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h +++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// /// \file /// -/// This file defines constans and helpers used when dealing with OpenMP. +/// This file defines constants and helpers used when dealing with OpenMP. /// //===----------------------------------------------------------------------===// Index: llvm/lib/Frontend/OpenMP/CMakeLists.txt =================================================================== --- llvm/lib/Frontend/OpenMP/CMakeLists.txt +++ llvm/lib/Frontend/OpenMP/CMakeLists.txt @@ -1,9 +1,5 @@ -set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/OpenMP/OMP.td) -tablegen(LLVM OMP.cpp --gen-directive-impl) -add_public_tablegen_target(omp_cpp) - add_llvm_component_library(LLVMFrontendOpenMP - OMP.cpp # Generated by tablegen above + OMP.cpp OMPContext.cpp OMPIRBuilder.cpp @@ -14,5 +10,4 @@ DEPENDS intrinsics_gen omp_gen - omp_cpp ) Index: llvm/lib/Frontend/OpenMP/OMP.cpp =================================================================== --- /dev/null +++ llvm/lib/Frontend/OpenMP/OMP.cpp @@ -0,0 +1,47 @@ +#include "llvm/Frontend/OpenMP/OMP.h" + +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h" + +using namespace llvm; +using namespace omp; + +#include "llvm/Frontend/OpenMP/OMP.inc" + +Directive llvm::omp::getOpenMPDirectiveKind(llvm::StringRef Str) { + return llvm::StringSwitch(Str) +#define DIRECTIVE(a, b) .Case(b, OMPD_##a) +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef DIRECTIVE + .Default(OMPD_unknown); +} + +llvm::StringRef llvm::omp::getOpenMPDirectiveName(Directive Kind) { + switch (Kind) { +#define DIRECTIVE(a, b) case OMPD_##a: return b; +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef DIRECTIVE + } + llvm_unreachable("Invalid OpenMP Directive kind"); +} + +Clause llvm::omp::getOpenMPClauseKind(llvm::StringRef Str) { + return llvm::StringSwitch(Str) +#define CLAUSE(name) .Case(#name, OMPC_##name) +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef CLAUSE + .Default(OMPC_unknown); +} + +llvm::StringRef llvm::omp::getOpenMPClauseName(Clause Kind) { + switch (Kind) { +#define CLAUSE(name) case OMPC_##name: return #name; +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef CLAUSE + } + llvm_unreachable("Invalid OpenMP Clause kind"); +} + +#define GET_IS_ALLOWED_CLAUSE_FOR_DIRECTIVE_IMPL +#include "llvm/Frontend/OpenMP/OMP.inc" +#undef GET_IS_ALLOWED_CLAUSE_FOR_DIRECTIVE_IMPL Index: llvm/test/TableGen/directive1.td =================================================================== --- llvm/test/TableGen/directive1.td +++ llvm/test/TableGen/directive1.td @@ -1,5 +1,4 @@ -// RUN: llvm-tblgen -gen-directive-decl -I %p/../../include %s | FileCheck -match-full-lines %s -// RUN: llvm-tblgen -gen-directive-impl -I %p/../../include %s | FileCheck -match-full-lines %s -check-prefix=IMPL +// RUN: llvm-tblgen -gen-directive -I %p/../../include %s | FileCheck -match-full-lines %s include "llvm/Frontend/Directive/DirectiveBase.td" @@ -9,8 +8,6 @@ let cppNamespace = "tdl"; let directivePrefix = "TDLD_"; let clausePrefix = "TDLC_"; - let makeEnumAvailableInNamespace = 1; - let enableBitmaskEnumInNamespace = 1; } def TDLC_ClauseA : Clause<"clausea"> {} @@ -26,103 +23,41 @@ let isDefault = 1; } -// CHECK: #ifndef LLVM_Tdl_INC -// CHECK-NEXT: #define LLVM_Tdl_INC -// CHECK-EMPTY: -// CHECK-NEXT: #include "llvm/ADT/BitmaskEnum.h" -// CHECK-EMPTY: -// CHECK-NEXT: namespace llvm { -// CHECK-NEXT: class StringRef; -// CHECK-NEXT: namespace tdl { -// CHECK-EMPTY: -// CHECK-NEXT: LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); -// CHECK-EMPTY: -// CHECK-NEXT: enum class Directive { -// CHECK-NEXT: TDLD_dira, -// CHECK-NEXT: }; -// CHECK-EMPTY: -// CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1; -// CHECK-EMPTY: -// CHECK-NEXT: constexpr auto TDLD_dira = llvm::tdl::Directive::TDLD_dira; -// CHECK-EMPTY: -// CHECK-NEXT: enum class Clause { -// CHECK-NEXT: TDLC_clausea, -// CHECK-NEXT: TDLC_clauseb, -// CHECK-NEXT: }; -// CHECK-EMPTY: -// CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 2; -// CHECK-EMPTY: -// CHECK-NEXT: constexpr auto TDLC_clausea = llvm::tdl::Clause::TDLC_clausea; -// CHECK-NEXT: constexpr auto TDLC_clauseb = llvm::tdl::Clause::TDLC_clauseb; -// CHECK-EMPTY: -// CHECK-NEXT: // Enumeration helper functions -// CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str); -// CHECK-EMPTY: -// CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D); -// CHECK-EMPTY: -// CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str); -// CHECK-EMPTY: -// CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C); -// CHECK-EMPTY: -// CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version. -// CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version); -// CHECK-EMPTY: -// CHECK-NEXT: } // namespace tdl -// CHECK-NEXT: } // namespace llvm -// CHECK-NEXT: #endif // LLVM_Tdl_INC - - -// IMPL: #include "llvm/ADT/StringRef.h" -// IMPL-NEXT: #include "llvm/ADT/StringSwitch.h" -// IMPL-EMPTY: -// IMPL-NEXT: using namespace llvm; -// IMPL-NEXT: using namespace tdl; -// IMPL-EMPTY: -// IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) { -// IMPL-NEXT: return llvm::StringSwitch(Str) -// IMPL-NEXT: .Case("dira",TDLD_dira) -// IMPL-NEXT: .Default(TDLD_dira); -// IMPL-NEXT: } -// IMPL-EMPTY: -// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) { -// IMPL-NEXT: switch (Kind) { -// IMPL-NEXT: case TDLD_dira: -// IMPL-NEXT: return "dira"; -// IMPL-NEXT: } -// IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind"); -// IMPL-NEXT: } -// IMPL-EMPTY: -// IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) { -// IMPL-NEXT: return llvm::StringSwitch(Str) -// IMPL-NEXT: .Case("clausea",TDLC_clausea) -// IMPL-NEXT: .Case("clauseb",TDLC_clauseb) -// IMPL-NEXT: .Default(TDLC_clauseb); -// IMPL-NEXT: } -// IMPL-EMPTY: -// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) { -// IMPL-NEXT: switch (Kind) { -// IMPL-NEXT: case TDLC_clausea: -// IMPL-NEXT: return "clausea"; -// IMPL-NEXT: case TDLC_clauseb: -// IMPL-NEXT: return "clauseb"; -// IMPL-NEXT: } -// IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind"); -// IMPL-NEXT: } -// IMPL-EMPTY: -// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) { -// IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize); -// IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize); -// 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: } +// CHECK: // Generated by llvm-tblgen. Do not edit. +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef DIRECTIVE +// CHECK-NEXT: DIRECTIVE(dira, "dira") +// CHECK-NEXT: #endif +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef DIRECTIVE_SIZE +// CHECK-NEXT: DIRECTIVE_SIZE(1) +// CHECK-NEXT: #endif +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef CLAUSE +// CHECK-NEXT: CLAUSE(clausea) +// CHECK-NEXT: CLAUSE(clauseb) +// CHECK-NEXT: #endif +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef CLAUSE_SIZE +// CHECK-NEXT: CLAUSE_SIZE(2) +// CHECK-NEXT: #endif +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef GET_IS_ALLOWED_CLAUSE_FOR_DIRECTIVE_IMPL +// CHECK-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) { +// CHECK-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize); +// CHECK-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize); +// 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: llvm_unreachable("Invalid Tdl Directive kind"); +// CHECK-NEXT: } +// CHECK-NEXT: #endif Index: llvm/test/TableGen/directive2.td =================================================================== --- llvm/test/TableGen/directive2.td +++ llvm/test/TableGen/directive2.td @@ -1,5 +1,4 @@ -// RUN: llvm-tblgen -gen-directive-decl -I %p/../../include %s | FileCheck -match-full-lines %s -// RUN: llvm-tblgen -gen-directive-impl -I %p/../../include %s | FileCheck -match-full-lines %s -check-prefix=IMPL +// RUN: llvm-tblgen -gen-directive -I %p/../../include %s | FileCheck -match-full-lines %s include "llvm/Frontend/Directive/DirectiveBase.td" @@ -9,7 +8,6 @@ let cppNamespace = "tdl"; let directivePrefix = "TDLD_"; let clausePrefix = "TDLC_"; - let includeHeader = "tdl.h.inc"; } def TDLC_ClauseA : Clause<"clausea"> { @@ -27,95 +25,41 @@ let isDefault = 1; } -// CHECK: #ifndef LLVM_Tdl_INC -// CHECK-NEXT: #define LLVM_Tdl_INC -// CHECK-EMPTY: -// CHECK-NEXT: namespace llvm { -// CHECK-NEXT: class StringRef; -// CHECK-NEXT: namespace tdl { -// CHECK-EMPTY: -// CHECK-NEXT: enum class Directive { -// CHECK-NEXT: TDLD_dira, -// CHECK-NEXT: }; -// CHECK-EMPTY: -// CHECK-NEXT: static constexpr std::size_t Directive_enumSize = 1; -// CHECK-EMPTY: -// CHECK-NEXT: enum class Clause { -// CHECK-NEXT: TDLC_clausea, -// CHECK-NEXT: TDLC_clauseb, -// CHECK-NEXT: }; -// CHECK-EMPTY: -// CHECK-NEXT: static constexpr std::size_t Clause_enumSize = 2; -// CHECK-EMPTY: -// CHECK-NEXT: // Enumeration helper functions -// CHECK-NEXT: Directive getTdlDirectiveKind(llvm::StringRef Str); -// CHECK-EMPTY: -// CHECK-NEXT: llvm::StringRef getTdlDirectiveName(Directive D); -// CHECK-EMPTY: -// CHECK-NEXT: Clause getTdlClauseKind(llvm::StringRef Str); -// CHECK-EMPTY: -// CHECK-NEXT: llvm::StringRef getTdlClauseName(Clause C); -// CHECK-EMPTY: -// CHECK-NEXT: /// Return true if \p C is a valid clause for \p D in version \p Version. -// CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version); -// CHECK-EMPTY: -// CHECK-NEXT: } // namespace tdl -// CHECK-NEXT: } // namespace llvm -// CHECK-NEXT: #endif // LLVM_Tdl_INC - -// IMPL: #include "tdl.h.inc" -// IMPL-EMPTY: -// IMPL-NEXT: #include "llvm/ADT/StringRef.h" -// IMPL-NEXT: #include "llvm/ADT/StringSwitch.h" -// IMPL-EMPTY: -// IMPL-NEXT: using namespace llvm; -// IMPL-NEXT: using namespace tdl; -// IMPL-EMPTY: -// IMPL: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) { -// IMPL-NEXT: return llvm::StringSwitch(Str) -// IMPL-NEXT: .Case("dira",TDLD_dira) -// IMPL-NEXT: .Default(TDLD_dira); -// IMPL-NEXT: } -// IMPL-EMPTY: -// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlDirectiveName(Directive Kind) { -// IMPL-NEXT: switch (Kind) { -// IMPL-NEXT: case TDLD_dira: -// IMPL-NEXT: return "dira"; -// IMPL-NEXT: } -// IMPL-NEXT: llvm_unreachable("Invalid Tdl Directive kind"); -// IMPL-NEXT: } -// IMPL-EMPTY: -// IMPL-NEXT: Clause llvm::tdl::getTdlClauseKind(llvm::StringRef Str) { -// IMPL-NEXT: return llvm::StringSwitch(Str) -// IMPL-NEXT: .Case("clausea",TDLC_clauseb) -// IMPL-NEXT: .Case("clauseb",TDLC_clauseb) -// IMPL-NEXT: .Default(TDLC_clauseb); -// IMPL-NEXT: } -// IMPL-EMPTY: -// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlClauseName(Clause Kind) { -// IMPL-NEXT: switch (Kind) { -// IMPL-NEXT: case TDLC_clausea: -// IMPL-NEXT: return "clausea"; -// IMPL-NEXT: case TDLC_clauseb: -// IMPL-NEXT: return "clauseb"; -// IMPL-NEXT: } -// IMPL-NEXT: llvm_unreachable("Invalid Tdl Clause kind"); -// IMPL-NEXT: } -// IMPL-EMPTY: -// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) { -// IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize); -// IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize); -// 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: } +// CHECK: // Generated by llvm-tblgen. Do not edit. +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef DIRECTIVE +// CHECK-NEXT: DIRECTIVE(dira, "dira") +// CHECK-NEXT: #endif +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef DIRECTIVE_SIZE +// CHECK-NEXT: DIRECTIVE_SIZE(1) +// CHECK-NEXT: #endif +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef CLAUSE +// CHECK-NEXT: CLAUSE(clausea) +// CHECK-NEXT: CLAUSE(clauseb) +// CHECK-NEXT: #endif +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef CLAUSE_SIZE +// CHECK-NEXT: CLAUSE_SIZE(2) +// CHECK-NEXT: #endif +// CHECK-EMPTY: +// CHECK-NEXT: #ifdef GET_IS_ALLOWED_CLAUSE_FOR_DIRECTIVE_IMPL +// CHECK-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) { +// CHECK-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize); +// CHECK-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize); +// 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: llvm_unreachable("Invalid Tdl Directive kind"); +// CHECK-NEXT: } +// CHECK-NEXT: #endif Index: llvm/utils/TableGen/DirectiveEmitter.cpp =================================================================== --- llvm/utils/TableGen/DirectiveEmitter.cpp +++ llvm/utils/TableGen/DirectiveEmitter.cpp @@ -30,178 +30,6 @@ return N; } -// Generate enum class -void GenerateEnumClass(const std::vector &Records, raw_ostream &OS, - StringRef Enum, StringRef Prefix, StringRef CppNamespace, - bool MakeEnumAvailableInNamespace) { - OS << "\n"; - OS << "enum class " << Enum << " {\n"; - for (const auto &R : Records) { - const auto Name = R->getValueAsString("name"); - OS << " " << Prefix << getFormattedName(Name) << ",\n"; - } - OS << "};\n"; - OS << "\n"; - OS << "static constexpr std::size_t " << Enum - << "_enumSize = " << Records.size() << ";\n"; - - // Make the enum values available in the defined namespace. This allows us to - // write something like Enum_X if we have a `using namespace `. - // At the same time we do not loose the strong type guarantees of the enum - // class, that is we cannot pass an unsigned as Directive without an explicit - // cast. - if (MakeEnumAvailableInNamespace) { - OS << "\n"; - for (const auto &R : Records) { - const auto FormattedName = getFormattedName(R->getValueAsString("name")); - OS << "constexpr auto " << Prefix << FormattedName << " = " - << "llvm::" << CppNamespace << "::" << Enum << "::" << Prefix - << FormattedName << ";\n"; - } - } -} - -// Generate the declaration section for the enumeration in the directive -// language -void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) { - - const auto &DirectiveLanguages = - Records.getAllDerivedDefinitions("DirectiveLanguage"); - - if (DirectiveLanguages.size() != 1) { - PrintError("A single definition of DirectiveLanguage is needed."); - return; - } - - const auto &DirectiveLanguage = DirectiveLanguages[0]; - StringRef LanguageName = DirectiveLanguage->getValueAsString("name"); - StringRef DirectivePrefix = - DirectiveLanguage->getValueAsString("directivePrefix"); - StringRef ClausePrefix = DirectiveLanguage->getValueAsString("clausePrefix"); - StringRef CppNamespace = DirectiveLanguage->getValueAsString("cppNamespace"); - bool MakeEnumAvailableInNamespace = - DirectiveLanguage->getValueAsBit("makeEnumAvailableInNamespace"); - bool EnableBitmaskEnumInNamespace = - DirectiveLanguage->getValueAsBit("enableBitmaskEnumInNamespace"); - - OS << "#ifndef LLVM_" << LanguageName << "_INC\n"; - OS << "#define LLVM_" << LanguageName << "_INC\n"; - - if (EnableBitmaskEnumInNamespace) - OS << "\n#include \"llvm/ADT/BitmaskEnum.h\"\n"; - - OS << "\n"; - OS << "namespace llvm {\n"; - OS << "class StringRef;\n"; - - // Open namespaces defined in the directive language - llvm::SmallVector Namespaces; - llvm::SplitString(CppNamespace, Namespaces, "::"); - for (auto Ns : Namespaces) - OS << "namespace " << Ns << " {\n"; - - if (EnableBitmaskEnumInNamespace) - OS << "\nLLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n"; - - // Emit Directive enumeration - const auto &Directives = Records.getAllDerivedDefinitions("Directive"); - GenerateEnumClass(Directives, OS, "Directive", DirectivePrefix, CppNamespace, - MakeEnumAvailableInNamespace); - - // Emit Clause enumeration - const auto &Clauses = Records.getAllDerivedDefinitions("Clause"); - GenerateEnumClass(Clauses, OS, "Clause", ClausePrefix, CppNamespace, - MakeEnumAvailableInNamespace); - - // Generic function signatures - OS << "\n"; - OS << "// Enumeration helper functions\n"; - OS << "Directive get" << LanguageName - << "DirectiveKind(llvm::StringRef Str);\n"; - OS << "\n"; - OS << "llvm::StringRef get" << LanguageName - << "DirectiveName(Directive D);\n"; - OS << "\n"; - OS << "Clause get" << LanguageName << "ClauseKind(llvm::StringRef Str);\n"; - OS << "\n"; - OS << "llvm::StringRef get" << LanguageName << "ClauseName(Clause C);\n"; - OS << "\n"; - OS << "/// Return true if \\p C is a valid clause for \\p D in version \\p " - << "Version.\n"; - OS << "bool isAllowedClauseForDirective(Directive D, " - << "Clause C, unsigned Version);\n"; - OS << "\n"; - - // Closing namespaces - for (auto Ns : llvm::reverse(Namespaces)) - OS << "} // namespace " << Ns << "\n"; - - OS << "} // namespace llvm\n"; - - OS << "#endif // LLVM_" << LanguageName << "_INC\n"; -} - -// Generate function implementation for getName(StringRef Str) -void GenerateGetName(const std::vector &Records, raw_ostream &OS, - StringRef Enum, StringRef Prefix, StringRef LanguageName, - StringRef Namespace) { - OS << "\n"; - OS << "llvm::StringRef llvm::" << Namespace << "::get" << LanguageName << Enum - << "Name(" << Enum << " Kind) {\n"; - OS << " switch (Kind) {\n"; - for (const auto &R : Records) { - const auto Name = R->getValueAsString("name"); - const auto AlternativeName = R->getValueAsString("alternativeName"); - OS << " case " << Prefix << getFormattedName(Name) << ":\n"; - OS << " return \""; - if (AlternativeName.empty()) - OS << Name; - else - OS << AlternativeName; - OS << "\";\n"; - } - OS << " }\n"; // switch - OS << " llvm_unreachable(\"Invalid " << LanguageName << " " << Enum - << " kind\");\n"; - OS << "}\n"; -} - -// Generate function implementation for getKind(StringRef Str) -void GenerateGetKind(const std::vector &Records, raw_ostream &OS, - StringRef Enum, StringRef Prefix, StringRef LanguageName, - StringRef Namespace, bool ImplicitAsUnknown) { - - auto DefaultIt = std::find_if(Records.begin(), Records.end(), [](Record *R) { - return R->getValueAsBit("isDefault") == true; - }); - - if (DefaultIt == Records.end()) { - PrintError("A least one " + Enum + " must be defined as default."); - return; - } - - const auto FormattedDefaultName = - getFormattedName((*DefaultIt)->getValueAsString("name")); - - OS << "\n"; - OS << Enum << " llvm::" << Namespace << "::get" << LanguageName << Enum - << "Kind(llvm::StringRef Str) {\n"; - OS << " return llvm::StringSwitch<" << Enum << ">(Str)\n"; - - for (const auto &R : Records) { - const auto Name = R->getValueAsString("name"); - if (ImplicitAsUnknown && R->getValueAsBit("isImplicit")) { - OS << " .Case(\"" << Name << "\"," << Prefix << FormattedDefaultName - << ")\n"; - } else { - OS << " .Case(\"" << Name << "\"," << Prefix << getFormattedName(Name) - << ")\n"; - } - } - OS << " .Default(" << Prefix << FormattedDefaultName << ");\n"; - OS << "}\n"; -} - void GenerateCaseForVersionedClauses(const std::vector &Clauses, raw_ostream &OS, StringRef DirectiveName, StringRef DirectivePrefix, @@ -223,7 +51,6 @@ raw_ostream &OS, StringRef LanguageName, StringRef DirectivePrefix, StringRef ClausePrefix, StringRef CppNamespace) { - OS << "\n"; OS << "bool llvm::" << CppNamespace << "::isAllowedClauseForDirective(" << "Directive D, Clause C, unsigned Version) {\n"; OS << " assert(unsigned(D) <= llvm::" << CppNamespace @@ -271,10 +98,9 @@ OS << "}\n"; // End of function isAllowedClauseForDirective } -// Generate the implemenation section for the enumeration in the directive +// Generate the declaration section for the enumeration in the directive // language -void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) { - +void EmitDirectives(RecordKeeper &Records, raw_ostream &OS) { const auto &DirectiveLanguages = Records.getAllDerivedDefinitions("DirectiveLanguage"); @@ -283,48 +109,43 @@ return; } + OS << "// Generated by llvm-tblgen. Do not edit.\n"; + + // Emit Directive enumeration + const auto &Directives = Records.getAllDerivedDefinitions("Directive"); + OS << "\n#ifdef DIRECTIVE\n"; + for (const auto &D : Directives) { + const auto& Name = D->getValueAsString("name"); + OS << "DIRECTIVE(" << getFormattedName(Name) << ", \"" << Name + << "\")\n"; + } + OS << "#endif\n"; + OS << "\n#ifdef DIRECTIVE_SIZE\n"; + OS << "DIRECTIVE_SIZE(" << Directives.size() << ")\n"; + OS << "#endif\n"; + + // Emit Clause enumeration + const auto &Clauses = Records.getAllDerivedDefinitions("Clause"); + OS << "\n#ifdef CLAUSE\n"; + for (const auto &C : Clauses) { + const auto& Name = C->getValueAsString("name"); + OS << "CLAUSE(" << Name << ")\n"; + } + OS << "#endif\n"; + OS << "\n#ifdef CLAUSE_SIZE\n"; + OS << "CLAUSE_SIZE(" << Clauses.size() << ")\n"; + OS << "#endif\n"; + const auto &DirectiveLanguage = DirectiveLanguages[0]; StringRef DirectivePrefix = DirectiveLanguage->getValueAsString("directivePrefix"); StringRef LanguageName = DirectiveLanguage->getValueAsString("name"); StringRef ClausePrefix = DirectiveLanguage->getValueAsString("clausePrefix"); StringRef CppNamespace = DirectiveLanguage->getValueAsString("cppNamespace"); - StringRef IncludeHeader = - DirectiveLanguage->getValueAsString("includeHeader"); - - const auto &Directives = Records.getAllDerivedDefinitions("Directive"); - const auto &Clauses = Records.getAllDerivedDefinitions("Clause"); - - if (!IncludeHeader.empty()) - OS << "#include \"" << IncludeHeader << "\"\n\n"; - - OS << "#include \"llvm/ADT/StringRef.h\"\n"; - OS << "#include \"llvm/ADT/StringSwitch.h\"\n"; - OS << "\n"; - OS << "using namespace llvm;\n"; - llvm::SmallVector Namespaces; - llvm::SplitString(CppNamespace, Namespaces, "::"); - for (auto Ns : Namespaces) - OS << "using namespace " << Ns << ";\n"; - - // getDirectiveKind(StringRef Str) - GenerateGetKind(Directives, OS, "Directive", DirectivePrefix, LanguageName, - CppNamespace, /*ImplicitAsUnknown=*/false); - - // getDirectiveName(Directive Kind) - GenerateGetName(Directives, OS, "Directive", DirectivePrefix, LanguageName, - CppNamespace); - - // getClauseKind(StringRef Str) - GenerateGetKind(Clauses, OS, "Clause", ClausePrefix, LanguageName, - CppNamespace, /*ImplicitAsUnknown=*/true); - - // getClauseName(Clause Kind) - GenerateGetName(Clauses, OS, "Clause", ClausePrefix, LanguageName, - CppNamespace); - + OS << "\n#ifdef GET_IS_ALLOWED_CLAUSE_FOR_DIRECTIVE_IMPL\n"; GenerateIsAllowedClause(Directives, OS, LanguageName, DirectivePrefix, ClausePrefix, CppNamespace); + OS << "#endif\n"; } } // namespace llvm Index: llvm/utils/TableGen/TableGen.cpp =================================================================== --- llvm/utils/TableGen/TableGen.cpp +++ llvm/utils/TableGen/TableGen.cpp @@ -54,8 +54,7 @@ GenRegisterBank, GenExegesis, GenAutomata, - GenDirectivesEnumDecl, - GenDirectivesEnumImpl, + GenDirectives, }; namespace llvm { @@ -131,10 +130,8 @@ clEnumValN(GenExegesis, "gen-exegesis", "Generate llvm-exegesis tables"), clEnumValN(GenAutomata, "gen-automata", "Generate generic automata"), - clEnumValN(GenDirectivesEnumDecl, "gen-directive-decl", - "Generate directive related declaration code"), - clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl", - "Generate directive related implementation code"))); + clEnumValN(GenDirectives, "gen-directive", + "Generate directive related code"))); cl::OptionCategory PrintEnumsCat("Options for -print-enums"); cl::opt Class("class", cl::desc("Print Enum list for this class"), @@ -259,11 +256,8 @@ case GenAutomata: EmitAutomata(Records, OS); break; - case GenDirectivesEnumDecl: - EmitDirectivesDecl(Records, OS); - break; - case GenDirectivesEnumImpl: - EmitDirectivesImpl(Records, OS); + case GenDirectives: + EmitDirectives(Records, OS); break; } Index: llvm/utils/TableGen/TableGenBackends.h =================================================================== --- llvm/utils/TableGen/TableGenBackends.h +++ llvm/utils/TableGen/TableGenBackends.h @@ -90,8 +90,7 @@ void EmitRegisterBank(RecordKeeper &RK, raw_ostream &OS); void EmitExegesis(RecordKeeper &RK, raw_ostream &OS); void EmitAutomata(RecordKeeper &RK, raw_ostream &OS); -void EmitDirectivesDecl(RecordKeeper &RK, raw_ostream &OS); -void EmitDirectivesImpl(RecordKeeper &RK, raw_ostream &OS); +void EmitDirectives(RecordKeeper &RK, raw_ostream &OS); } // End llvm namespace Index: llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenMP/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenMP/BUILD.gn +++ llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenMP/BUILD.gn @@ -2,8 +2,7 @@ tablegen("OMP") { visibility = [ ":public_tablegen" ] - args = [ "-gen-directive-decl" ] - output_name = "OMP.h.inc" + args = [ "-gen-directive" ] } # Groups all tablegen() calls that create .inc files that are included in @@ -12,7 +11,7 @@ # //llvm/lib/Frontend/OpenMP don't need to depend on this. group("public_tablegen") { public_deps = [ - # Frontend/OpenMP's public headers include OMP.h.inc. + # Frontend/OpenMP's public headers include OMP.inc. ":OMP", ] } Index: llvm/utils/gn/secondary/llvm/lib/Frontend/OpenMP/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/lib/Frontend/OpenMP/BUILD.gn +++ llvm/utils/gn/secondary/llvm/lib/Frontend/OpenMP/BUILD.gn @@ -1,23 +1,14 @@ -import("//llvm/utils/TableGen/tablegen.gni") - -tablegen("OMPImpl") { - visibility = [ ":OpenMP" ] - args = [ "-gen-directive-impl" ] - td_file = "//llvm/include/llvm/Frontend/OpenMP/OMP.td" - output_name = "OMP.cpp" -} - static_library("OpenMP") { output_name = "LLVMFrontendOpenMP" deps = [ - ":OMPImpl", "//llvm/lib/IR", "//llvm/lib/Support", "//llvm/lib/Transforms/Utils", ] public_deps = [ "//llvm/include/llvm/Frontend/OpenMP:public_tablegen" ] sources = [ + "OMP.cpp", "OMPContext.cpp", "OMPIRBuilder.cpp", - ] + get_target_outputs(":OMPImpl") + ] }