[llvm] d709dcc - [openacc][openmp] Reduce number of generated file and prefer inclusion of .inc

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 23 06:17:01 PDT 2021


Author: Valentin Clement
Date: 2021-03-23T09:16:53-04:00
New Revision: d709dcc0909716ce23c30d9884712766aec6a628

URL: https://github.com/llvm/llvm-project/commit/d709dcc0909716ce23c30d9884712766aec6a628
DIFF: https://github.com/llvm/llvm-project/commit/d709dcc0909716ce23c30d9884712766aec6a628.diff

LOG: [openacc][openmp] Reduce number of generated file and prefer inclusion of .inc

Follow up from D92955 and D83636. This patch makes the base cpp files
OMP.cpp and ACC.cpp normal files and they now include the XXX.inc file
generated by tablegen. This reduces the number of file generated by the
DirectiveEmitter backend and makes it closer to the proposal in D83636.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D93560

Added: 
    llvm/lib/Frontend/OpenACC/ACC.cpp
    llvm/lib/Frontend/OpenMP/OMP.cpp

Modified: 
    llvm/include/llvm/Frontend/OpenACC/ACC.td
    llvm/include/llvm/Frontend/OpenACC/CMakeLists.txt
    llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt
    llvm/include/llvm/Frontend/OpenMP/OMP.td
    llvm/include/llvm/TableGen/DirectiveEmitter.h
    llvm/lib/Frontend/OpenACC/CMakeLists.txt
    llvm/lib/Frontend/OpenMP/CMakeLists.txt
    llvm/test/TableGen/directive1.td
    llvm/test/TableGen/directive2.td
    llvm/test/TableGen/directive3.td
    llvm/utils/TableGen/DirectiveEmitter.cpp
    llvm/utils/TableGen/TableGen.cpp
    llvm/utils/TableGen/TableGenBackends.h
    llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenACC/BUILD.gn
    llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenMP/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index 44de0d875730..c68330665b02 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -23,7 +23,6 @@ def OpenACC : DirectiveLanguage {
   let clausePrefix = "ACCC_";
   let makeEnumAvailableInNamespace = true;
   let enableBitmaskEnumInNamespace = true;
-  let includeHeader = "llvm/Frontend/OpenACC/ACC.h.inc";
   let clauseEnumSetClass = "AccClauseSet";
   let flangClauseBaseClass = "AccClause";
 }

diff  --git a/llvm/include/llvm/Frontend/OpenACC/CMakeLists.txt b/llvm/include/llvm/Frontend/OpenACC/CMakeLists.txt
index b8332e03ff81..558de3aa9220 100644
--- a/llvm/include/llvm/Frontend/OpenACC/CMakeLists.txt
+++ b/llvm/include/llvm/Frontend/OpenACC/CMakeLists.txt
@@ -1,4 +1,4 @@
 set(LLVM_TARGET_DEFINITIONS ACC.td)
 tablegen(LLVM ACC.h.inc --gen-directive-decl)
-tablegen(LLVM ACC.inc --gen-directive-gen)
+tablegen(LLVM ACC.inc --gen-directive-impl)
 add_public_tablegen_target(acc_gen)

diff  --git a/llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt b/llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt
index 1359929b67c7..e983cf5ca56d 100644
--- a/llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt
+++ b/llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt
@@ -1,4 +1,4 @@
 set(LLVM_TARGET_DEFINITIONS OMP.td)
 tablegen(LLVM OMP.h.inc --gen-directive-decl)
-tablegen(LLVM OMP.inc --gen-directive-gen)
+tablegen(LLVM OMP.inc --gen-directive-impl)
 add_public_tablegen_target(omp_gen)

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index abd636c07e9c..7845e4bc98db 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -23,7 +23,6 @@ def OpenMP : DirectiveLanguage {
   let clausePrefix = "OMPC_";
   let makeEnumAvailableInNamespace = true;
   let enableBitmaskEnumInNamespace = true;
-  let includeHeader = "llvm/Frontend/OpenMP/OMP.h.inc";
   let clauseEnumSetClass = "OmpClauseSet";
   let flangClauseBaseClass = "OmpClause";
 }

diff  --git a/llvm/include/llvm/TableGen/DirectiveEmitter.h b/llvm/include/llvm/TableGen/DirectiveEmitter.h
index b1757249670a..5c4a736eb107 100644
--- a/llvm/include/llvm/TableGen/DirectiveEmitter.h
+++ b/llvm/include/llvm/TableGen/DirectiveEmitter.h
@@ -30,10 +30,6 @@ class DirectiveLanguage {
     return Def->getValueAsString("clausePrefix");
   }
 
-  StringRef getIncludeHeader() const {
-    return Def->getValueAsString("includeHeader");
-  }
-
   StringRef getClauseEnumSetClass() const {
     return Def->getValueAsString("clauseEnumSetClass");
   }

diff  --git a/llvm/lib/Frontend/OpenACC/ACC.cpp b/llvm/lib/Frontend/OpenACC/ACC.cpp
new file mode 100644
index 000000000000..1e0516021bc6
--- /dev/null
+++ b/llvm/lib/Frontend/OpenACC/ACC.cpp
@@ -0,0 +1,19 @@
+//===- ACC.cpp ------ Collection of helpers for OpenACC -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Frontend/OpenACC/ACC.h.inc"
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/ErrorHandling.h"
+
+using namespace llvm;
+using namespace acc;
+
+#define GEN_DIRECTIVES_IMPL
+#include "llvm/Frontend/OpenACC/ACC.inc"

diff  --git a/llvm/lib/Frontend/OpenACC/CMakeLists.txt b/llvm/lib/Frontend/OpenACC/CMakeLists.txt
index ba340ab9c561..f35201497869 100644
--- a/llvm/lib/Frontend/OpenACC/CMakeLists.txt
+++ b/llvm/lib/Frontend/OpenACC/CMakeLists.txt
@@ -1,9 +1,5 @@
-set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/OpenACC/ACC.td)
-tablegen(LLVM ACC.cpp --gen-directive-impl)
-add_public_tablegen_target(acc_cpp)
-
 add_llvm_component_library(LLVMFrontendOpenACC
-  ACC.cpp # Generated by tablegen above
+  ACC.cpp
 
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend
@@ -11,7 +7,6 @@ add_llvm_component_library(LLVMFrontendOpenACC
 
   DEPENDS
   acc_gen
-  acc_cpp
 )
 
 target_link_libraries(LLVMFrontendOpenACC LLVMSupport)

diff  --git a/llvm/lib/Frontend/OpenMP/CMakeLists.txt b/llvm/lib/Frontend/OpenMP/CMakeLists.txt
index cc5d3a766870..17ca2c63327c 100644
--- a/llvm/lib/Frontend/OpenMP/CMakeLists.txt
+++ b/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,7 +10,6 @@ add_llvm_component_library(LLVMFrontendOpenMP
   DEPENDS
   intrinsics_gen
   omp_gen
-  omp_cpp
 
   LINK_COMPONENTS
   Core

diff  --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
new file mode 100644
index 000000000000..eac5d4168c5c
--- /dev/null
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -0,0 +1,19 @@
+//===- OMP.cpp ------ Collection of helpers for OpenMP --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Frontend/OpenMP/OMP.h.inc"
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/ErrorHandling.h"
+
+using namespace llvm;
+using namespace omp;
+
+#define GEN_DIRECTIVES_IMPL
+#include "llvm/Frontend/OpenMP/OMP.inc"

diff  --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td
index a69958175267..b5fc08c15a5d 100644
--- a/llvm/test/TableGen/directive1.td
+++ b/llvm/test/TableGen/directive1.td
@@ -1,6 +1,5 @@
 // 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-gen -I %p/../../include %s | FileCheck -match-full-lines %s -check-prefix=GEN
 
 include "llvm/Frontend/Directive/DirectiveBase.td"
 
@@ -101,12 +100,143 @@ def TDL_DirA : Directive<"dira"> {
 // CHECK-NEXT:  #endif // LLVM_Tdl_INC
 
 
-// IMPL:       #include "llvm/ADT/StringRef.h"
-// IMPL-NEXT:  #include "llvm/ADT/StringSwitch.h"
-// IMPL-NEXT:  #include "llvm/Support/ErrorHandling.h"
+// IMPL:       #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
+// IMPL-NEXT:  #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
 // IMPL-EMPTY:
-// IMPL-NEXT:  using namespace llvm;
-// IMPL-NEXT:  using namespace tdl;
+// IMPL-NEXT:  namespace llvm {
+// IMPL-NEXT:  namespace tdl {
+// IMPL-EMPTY:
+// IMPL-NEXT:    // Sets for dira
+// IMPL-EMPTY:
+// IMPL-NEXT:    static  allowedClauses_TDLD_dira {
+// IMPL-NEXT:      llvm::tdl::Clause::TDLC_clausea,
+// IMPL-NEXT:      llvm::tdl::Clause::TDLC_clauseb,
+// IMPL-NEXT:    };
+// IMPL-EMPTY:
+// IMPL-NEXT:    static  allowedOnceClauses_TDLD_dira {
+// IMPL-NEXT:    };
+// IMPL-EMPTY:
+// IMPL-NEXT:    static  allowedExclusiveClauses_TDLD_dira {
+// IMPL-NEXT:    };
+// IMPL-EMPTY:
+// IMPL-NEXT:    static  requiredClauses_TDLD_dira {
+// IMPL-NEXT:    };
+// IMPL-NEXT:  } // namespace tdl
+// IMPL-NEXT:  } // namespace llvm
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
+// IMPL-NEXT:  #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
+// IMPL-EMPTY:
+// IMPL-NEXT:  {
+// IMPL-NEXT:    {llvm::tdl::Directive::TDLD_dira,
+// IMPL-NEXT:      {
+// IMPL-NEXT:        llvm::tdl::allowedClauses_TDLD_dira,
+// IMPL-NEXT:        llvm::tdl::allowedOnceClauses_TDLD_dira,
+// IMPL-NEXT:        llvm::tdl::allowedExclusiveClauses_TDLD_dira,
+// IMPL-NEXT:        llvm::tdl::requiredClauses_TDLD_dira,
+// IMPL-NEXT:      }
+// IMPL-NEXT:    },
+// IMPL-NEXT:  }
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
+// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
+// IMPL-EMPTY:
+// IMPL-NEXT:  EMPTY_CLASS(Clausea);
+// IMPL-NEXT:  WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
+// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
+// IMPL-EMPTY:
+// IMPL-NEXT:  Clausea
+// IMPL-NEXT:  , Clauseb
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
+// IMPL-NEXT:  #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
+// IMPL-EMPTY:
+// IMPL-NEXT:  NODE(TdlClause, Clausea)
+// IMPL-NEXT:  NODE(TdlClause, Clauseb)
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_UNPARSE
+// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_UNPARSE
+// IMPL-EMPTY:
+// IMPL-NEXT:  void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
+// IMPL-NEXT:  void Unparse(const TdlClause::Clauseb &x) {
+// IMPL-NEXT:    Word("CLAUSEB");
+// IMPL-NEXT:    Walk("(", x.v, ")");
+// IMPL-NEXT:  }
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_UNPARSE
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_CHECK_ENTER
+// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_CHECK_ENTER
+// IMPL-EMPTY:
+// IMPL-NEXT:  void Enter(const parser::TdlClause::Clausea &);
+// IMPL-NEXT:  void Enter(const parser::TdlClause::Clauseb &);
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_CHECK_ENTER
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
+// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
+// IMPL-EMPTY:
+// IMPL-NEXT:  if constexpr (std::is_same_v<A, parser::TdlClause::Clausea>)
+// IMPL-NEXT:    return llvm::tdl::Clause::TDLC_clausea;
+// IMPL-NEXT:  if constexpr (std::is_same_v<A, parser::TdlClause::Clauseb>)
+// IMPL-NEXT:    return llvm::tdl::Clause::TDLC_clauseb;
+// IMPL-NEXT:  llvm_unreachable("Invalid Tdl Parser clause");
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_KIND_MAP
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_CLANG_CLAUSE_CLASS
+// IMPL-NEXT:  #undef GEN_CLANG_CLAUSE_CLASS
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifndef CLAUSE
+// IMPL-NEXT:  #define CLAUSE(Enum, Str, Implicit)
+// IMPL-NEXT:  #endif
+// IMPL-NEXT:  #ifndef CLAUSE_CLASS
+// IMPL-NEXT:  #define CLAUSE_CLASS(Enum, Str, Class)
+// IMPL-NEXT:  #endif
+// IMPL-NEXT:  #ifndef CLAUSE_NO_CLASS
+// IMPL-NEXT:  #define CLAUSE_NO_CLASS(Enum, Str)
+// IMPL-NEXT:  #endif
+// IMPL-EMPTY:
+// IMPL-NEXT:  #define __CLAUSE(Name, Class)                      \
+// IMPL-NEXT:    CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
+// IMPL-NEXT:    CLAUSE_CLASS(TDLC_##Name, #Name, Class)
+// IMPL-NEXT:  #define __CLAUSE_NO_CLASS(Name)                    \
+// IMPL-NEXT:    CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
+// IMPL-NEXT:    CLAUSE_NO_CLASS(TDLC_##Name, #Name)
+// IMPL-NEXT:  #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class)  \
+// IMPL-NEXT:    CLAUSE(TDLC_##Name, Str, /* Implicit */ true)    \
+// IMPL-NEXT:    CLAUSE_CLASS(TDLC_##Name, Str, Class)
+// IMPL-NEXT:  #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str)      \
+// IMPL-NEXT:    CLAUSE(TDLC_##Name, Str, /* Implicit */ true)    \
+// IMPL-NEXT:    CLAUSE_NO_CLASS(TDLC_##Name, Str)
+// IMPL-EMPTY:
+// IMPL-NEXT:  __CLAUSE_NO_CLASS(clausea)
+// IMPL-NEXT:  __CLAUSE_NO_CLASS(clauseb)
+// IMPL-EMPTY:
+// IMPL-NEXT:  #undef __IMPLICIT_CLAUSE_NO_CLASS
+// IMPL-NEXT:  #undef __IMPLICIT_CLAUSE_CLASS
+// IMPL-NEXT:  #undef __CLAUSE
+// IMPL-NEXT:  #undef CLAUSE_NO_CLASS
+// IMPL-NEXT:  #undef CLAUSE_CLASS
+// IMPL-NEXT:  #undef CLAUSE
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_CLANG_CLAUSE_CLASS
+// IMPL-EMPTY:
+
+// IMPL:       #ifdef GEN_DIRECTIVES_IMPL
+// IMPL-NEXT:  #undef GEN_DIRECTIVES_IMPL
 // IMPL-EMPTY:
 // IMPL-NEXT:  Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
 // IMPL-NEXT:    return llvm::StringSwitch<Directive>(Str)
@@ -177,102 +307,4 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:    llvm_unreachable("Invalid Tdl Directive kind");
 // IMPL-NEXT:  }
 // IMPL-EMPTY:
-
-
-
-// GEN:       #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
-// GEN-NEXT:  #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
-// GEN-EMPTY:
-// GEN-NEXT:  namespace llvm {
-// GEN-NEXT:  namespace tdl {
-// GEN-EMPTY:
-// GEN-NEXT:    // Sets for dira
-// GEN-EMPTY:
-// GEN-NEXT:    static  allowedClauses_TDLD_dira {
-// GEN-NEXT:      llvm::tdl::Clause::TDLC_clausea,
-// GEN-NEXT:      llvm::tdl::Clause::TDLC_clauseb,
-// GEN-NEXT:    };
-// GEN-EMPTY:
-// GEN-NEXT:    static  allowedOnceClauses_TDLD_dira {
-// GEN-NEXT:    };
-// GEN-EMPTY:
-// GEN-NEXT:    static  allowedExclusiveClauses_TDLD_dira {
-// GEN-NEXT:    };
-// GEN-EMPTY:
-// GEN-NEXT:    static  requiredClauses_TDLD_dira {
-// GEN-NEXT:    };
-// GEN-NEXT:  } // namespace tdl
-// GEN-NEXT:  } // namespace llvm
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
-// GEN-NEXT:  #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
-// GEN-EMPTY:
-// GEN-NEXT:  {
-// GEN-NEXT:    {llvm::tdl::Directive::TDLD_dira,
-// GEN-NEXT:      {
-// GEN-NEXT:        llvm::tdl::allowedClauses_TDLD_dira,
-// GEN-NEXT:        llvm::tdl::allowedOnceClauses_TDLD_dira,
-// GEN-NEXT:        llvm::tdl::allowedExclusiveClauses_TDLD_dira,
-// GEN-NEXT:        llvm::tdl::requiredClauses_TDLD_dira,
-// GEN-NEXT:      }
-// GEN-NEXT:    },
-// GEN-NEXT:  }
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
-// GEN-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
-// GEN-EMPTY:
-// GEN-NEXT:  EMPTY_CLASS(Clausea);
-// GEN-NEXT:  WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
-// GEN-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
-// GEN-EMPTY:
-// GEN-NEXT:  Clausea
-// GEN-NEXT:  , Clauseb
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
-// GEN-NEXT:  #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
-// GEN-EMPTY:
-// GEN-NEXT:  NODE(TdlClause, Clausea)
-// GEN-NEXT:  NODE(TdlClause, Clauseb)
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_CLAUSE_UNPARSE
-// GEN-NEXT:  #undef GEN_FLANG_CLAUSE_UNPARSE
-// GEN-EMPTY:
-// GEN-NEXT:  void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
-// GEN-NEXT:  void Unparse(const TdlClause::Clauseb &x) {
-// GEN-NEXT:    Word("CLAUSEB");
-// GEN-NEXT:    Walk("(", x.v, ")");
-// GEN-NEXT:  }
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_CLAUSE_UNPARSE
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_CLAUSE_CHECK_ENTER
-// GEN-NEXT:  #undef GEN_FLANG_CLAUSE_CHECK_ENTER
-// GEN-EMPTY:
-// GEN-NEXT:  void Enter(const parser::TdlClause::Clausea &);
-// GEN-NEXT:  void Enter(const parser::TdlClause::Clauseb &);
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_CLAUSE_CHECK_ENTER
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
-// GEN-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_KIND_MAP
-// GEN-EMPTY:
-// GEN-NEXT:  if constexpr (std::is_same_v<A, parser::TdlClause::Clausea>)
-// GEN-NEXT:    return llvm::tdl::Clause::TDLC_clausea;
-// GEN-NEXT:  if constexpr (std::is_same_v<A, parser::TdlClause::Clauseb>)
-// GEN-NEXT:    return llvm::tdl::Clause::TDLC_clauseb;
-// GEN-NEXT:  llvm_unreachable("Invalid Tdl Parser clause");
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_KIND_MAP
-// GEN-EMPTY:
+// IMPL-NEXT:  #endif // GEN_DIRECTIVES_IMPL

diff  --git a/llvm/test/TableGen/directive2.td b/llvm/test/TableGen/directive2.td
index 1e02cbd01dad..154d1e86ffb1 100644
--- a/llvm/test/TableGen/directive2.td
+++ b/llvm/test/TableGen/directive2.td
@@ -1,6 +1,5 @@
 // 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-gen -I %p/../../include %s | FileCheck -match-full-lines %s -check-prefix=GEN
 
 include "llvm/Frontend/Directive/DirectiveBase.td"
 
@@ -79,14 +78,143 @@ def TDL_DirA : Directive<"dira"> {
 // CHECK-NEXT:  } // namespace llvm
 // CHECK-NEXT:  #endif // LLVM_Tdl_INC
 
-// IMPL:       #include "tdl.h.inc"
+// IMPL:      #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
+// IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
 // IMPL-EMPTY:
-// IMPL-NEXT:  #include "llvm/ADT/StringRef.h"
-// IMPL-NEXT:  #include "llvm/ADT/StringSwitch.h"
-// IMPL-NEXT:  #include "llvm/Support/ErrorHandling.h"
+// IMPL-NEXT: namespace llvm {
+// IMPL-NEXT: namespace tdl {
 // IMPL-EMPTY:
-// IMPL-NEXT:  using namespace llvm;
-// IMPL-NEXT:  using namespace tdl;
+// IMPL-NEXT:   // Sets for dira
+// IMPL-EMPTY:
+// IMPL-NEXT:   static  allowedClauses_TDLD_dira {
+// IMPL-NEXT:     llvm::tdl::Clause::TDLC_clausea,
+// IMPL-NEXT:     llvm::tdl::Clause::TDLC_clauseb,
+// IMPL-NEXT:   };
+// IMPL-EMPTY:
+// IMPL-NEXT:   static  allowedOnceClauses_TDLD_dira {
+// IMPL-NEXT:   };
+// IMPL-EMPTY:
+// IMPL-NEXT:   static  allowedExclusiveClauses_TDLD_dira {
+// IMPL-NEXT:   };
+// IMPL-EMPTY:
+// IMPL-NEXT:   static  requiredClauses_TDLD_dira {
+// IMPL-NEXT:   };
+// IMPL-NEXT: } // namespace tdl
+// IMPL-NEXT: } // namespace llvm
+// IMPL-EMPTY:
+// IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
+// IMPL-EMPTY:
+// IMPL-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
+// IMPL-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
+// IMPL-EMPTY:
+// IMPL-NEXT: {
+// IMPL-NEXT:   {llvm::tdl::Directive::TDLD_dira,
+// IMPL-NEXT:     {
+// IMPL-NEXT:       llvm::tdl::allowedClauses_TDLD_dira,
+// IMPL-NEXT:       llvm::tdl::allowedOnceClauses_TDLD_dira,
+// IMPL-NEXT:       llvm::tdl::allowedExclusiveClauses_TDLD_dira,
+// IMPL-NEXT:       llvm::tdl::requiredClauses_TDLD_dira,
+// IMPL-NEXT:     }
+// IMPL-NEXT:   },
+// IMPL-NEXT: }
+// IMPL-EMPTY:
+// IMPL-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
+// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
+// IMPL-EMPTY:
+// IMPL-NEXT:  EMPTY_CLASS(Clausea);
+// IMPL-NEXT:  WRAPPER_CLASS(Clauseb, std::list<IntExpr>);
+// IMPL-NEXT:  WRAPPER_CLASS(Clausec, std::optional<Name>);
+// IMPL-NEXT:  EMPTY_CLASS(Claused);
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
+// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
+// IMPL-EMPTY:
+// IMPL-NEXT:  Clausea
+// IMPL-NEXT:  , Clauseb
+// IMPL-NEXT:  , Clausec
+// IMPL-NEXT:  , Claused
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
+// IMPL-NEXT:  #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
+// IMPL-EMPTY:
+// IMPL-NEXT:  NODE(TdlClause, Clausea)
+// IMPL-NEXT:  NODE(TdlClause, Clauseb)
+// IMPL-NEXT:  NODE(TdlClause, Clausec)
+// IMPL-NEXT:  NODE(TdlClause, Claused)
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifdef GEN_FLANG_CLAUSE_UNPARSE
+// IMPL-NEXT:  #undef GEN_FLANG_CLAUSE_UNPARSE
+// IMPL-EMPTY:
+// IMPL-NEXT:  void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
+// IMPL-NEXT:  void Unparse(const TdlClause::Clauseb &x) {
+// IMPL-NEXT:    Word("CLAUSEB");
+// IMPL-NEXT:    Put("(");
+// IMPL-NEXT:    Walk(x.v, ",");
+// IMPL-NEXT:    Put(")");
+// IMPL-NEXT:  }
+// IMPL-NEXT:  void Unparse(const TdlClause::Clausec &x) {
+// IMPL-NEXT:  Word("CLAUSEC");
+// IMPL-NEXT:    Put("(");
+// IMPL-NEXT:    if (x.v.has_value())
+// IMPL-NEXT:    Walk(x.v);
+// IMPL-NEXT:    else
+// IMPL-NEXT:    Put("*");
+// IMPL-NEXT:    Put(")");
+// IMPL-NEXT:  }
+// IMPL-NEXT:  void Before(const TdlClause::Claused &) { Word("CLAUSED"); }
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_UNPARSE
+
+// IMPL:       #ifdef GEN_CLANG_CLAUSE_CLASS
+// IMPL-NEXT:  #undef GEN_CLANG_CLAUSE_CLASS
+// IMPL-EMPTY:
+// IMPL-NEXT:  #ifndef CLAUSE
+// IMPL-NEXT:  #define CLAUSE(Enum, Str, Implicit)
+// IMPL-NEXT:  #endif
+// IMPL-NEXT:  #ifndef CLAUSE_CLASS
+// IMPL-NEXT:  #define CLAUSE_CLASS(Enum, Str, Class)
+// IMPL-NEXT:  #endif
+// IMPL-NEXT:  #ifndef CLAUSE_NO_CLASS
+// IMPL-NEXT:  #define CLAUSE_NO_CLASS(Enum, Str)
+// IMPL-NEXT:  #endif
+// IMPL-EMPTY:
+// IMPL-NEXT:  #define __CLAUSE(Name, Class)                      \
+// IMPL-NEXT:    CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
+// IMPL-NEXT:    CLAUSE_CLASS(TDLC_##Name, #Name, Class)
+// IMPL-NEXT:  #define __CLAUSE_NO_CLASS(Name)                    \
+// IMPL-NEXT:    CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
+// IMPL-NEXT:    CLAUSE_NO_CLASS(TDLC_##Name, #Name)
+// IMPL-NEXT:  #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class)  \
+// IMPL-NEXT:    CLAUSE(TDLC_##Name, Str, /* Implicit */ true)    \
+// IMPL-NEXT:  CLAUSE_CLASS(TDLC_##Name, Str, Class)
+// IMPL-NEXT:  #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str)      \
+// IMPL-NEXT:    CLAUSE(TDLC_##Name, Str, /* Implicit */ true)    \
+// IMPL-NEXT:  CLAUSE_NO_CLASS(TDLC_##Name, Str)
+// IMPL-EMPTY:
+// IMPL-NEXT:  __IMPLICIT_CLAUSE_NO_CLASS(clausea, "clausea")
+// IMPL-NEXT:  __CLAUSE_NO_CLASS(clauseb)
+// IMPL-NEXT:  __CLAUSE(clausec, ClauseC)
+// IMPL-NEXT:  __IMPLICIT_CLAUSE_CLASS(claused, "claused", ClauseD)
+// IMPL-EMPTY:
+// IMPL-NEXT:  #undef __IMPLICIT_CLAUSE_NO_CLASS
+// IMPL-NEXT:  #undef __IMPLICIT_CLAUSE_CLASS
+// IMPL-NEXT:  #undef __CLAUSE
+// IMPL-NEXT:  #undef CLAUSE_NO_CLASS
+// IMPL-NEXT:  #undef CLAUSE_CLASS
+// IMPL-NEXT:  #undef CLAUSE
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_CLANG_CLAUSE_CLASS
+
+// IMPL:       #ifdef GEN_DIRECTIVES_IMPL
+// IMPL-NEXT:  #undef GEN_DIRECTIVES_IMPL
 // IMPL-EMPTY:
 // IMPL-NEXT:  Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
 // IMPL-NEXT:    return llvm::StringSwitch<Directive>(Str)
@@ -142,140 +270,5 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:    }
 // IMPL-NEXT:    llvm_unreachable("Invalid Tdl Directive kind");
 // IMPL-NEXT:  }
-
-
-// GEN:      #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
-// GEN-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_SETS
-// GEN-EMPTY:
-// GEN-NEXT: namespace llvm {
-// GEN-NEXT: namespace tdl {
-// GEN-EMPTY:
-// GEN-NEXT:   // Sets for dira
-// GEN-EMPTY:
-// GEN-NEXT:   static  allowedClauses_TDLD_dira {
-// GEN-NEXT:     llvm::tdl::Clause::TDLC_clausea,
-// GEN-NEXT:     llvm::tdl::Clause::TDLC_clauseb,
-// GEN-NEXT:   };
-// GEN-EMPTY:
-// GEN-NEXT:   static  allowedOnceClauses_TDLD_dira {
-// GEN-NEXT:   };
-// GEN-EMPTY:
-// GEN-NEXT:   static  allowedExclusiveClauses_TDLD_dira {
-// GEN-NEXT:   };
-// GEN-EMPTY:
-// GEN-NEXT:   static  requiredClauses_TDLD_dira {
-// GEN-NEXT:   };
-// GEN-NEXT: } // namespace tdl
-// GEN-NEXT: } // namespace llvm
-// GEN-EMPTY:
-// GEN-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_SETS
-// GEN-EMPTY:
-// GEN-NEXT: #ifdef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
-// GEN-NEXT: #undef GEN_FLANG_DIRECTIVE_CLAUSE_MAP
-// GEN-EMPTY:
-// GEN-NEXT: {
-// GEN-NEXT:   {llvm::tdl::Directive::TDLD_dira,
-// GEN-NEXT:     {
-// GEN-NEXT:       llvm::tdl::allowedClauses_TDLD_dira,
-// GEN-NEXT:       llvm::tdl::allowedOnceClauses_TDLD_dira,
-// GEN-NEXT:       llvm::tdl::allowedExclusiveClauses_TDLD_dira,
-// GEN-NEXT:       llvm::tdl::requiredClauses_TDLD_dira,
-// GEN-NEXT:     }
-// GEN-NEXT:   },
-// GEN-NEXT: }
-// GEN-EMPTY:
-// GEN-NEXT: #endif // GEN_FLANG_DIRECTIVE_CLAUSE_MAP
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES
-// GEN-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES
-// GEN-EMPTY:
-// GEN-NEXT:  EMPTY_CLASS(Clausea);
-// GEN-NEXT:  WRAPPER_CLASS(Clauseb, std::list<IntExpr>);
-// GEN-NEXT:  WRAPPER_CLASS(Clausec, std::optional<Name>);
-// GEN-NEXT:  EMPTY_CLASS(Claused);
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
-// GEN-NEXT:  #undef GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
-// GEN-EMPTY:
-// GEN-NEXT:  Clausea
-// GEN-NEXT:  , Clauseb
-// GEN-NEXT:  , Clausec
-// GEN-NEXT:  , Claused
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
-// GEN-NEXT:  #undef GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
-// GEN-EMPTY:
-// GEN-NEXT:  NODE(TdlClause, Clausea)
-// GEN-NEXT:  NODE(TdlClause, Clauseb)
-// GEN-NEXT:  NODE(TdlClause, Clausec)
-// GEN-NEXT:  NODE(TdlClause, Claused)
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
-// GEN-EMPTY:
-// GEN-NEXT:  #ifdef GEN_FLANG_CLAUSE_UNPARSE
-// GEN-NEXT:  #undef GEN_FLANG_CLAUSE_UNPARSE
-// GEN-EMPTY:
-// GEN-NEXT:  void Before(const TdlClause::Clausea &) { Word("CLAUSEA"); }
-// GEN-NEXT:  void Unparse(const TdlClause::Clauseb &x) {
-// GEN-NEXT:    Word("CLAUSEB");
-// GEN-NEXT:    Put("(");
-// GEN-NEXT:    Walk(x.v, ",");
-// GEN-NEXT:    Put(")");
-// GEN-NEXT:  }
-// GEN-NEXT:  void Unparse(const TdlClause::Clausec &x) {
-// GEN-NEXT:  Word("CLAUSEC");
-// GEN-NEXT:    Put("(");
-// GEN-NEXT:    if (x.v.has_value())
-// GEN-NEXT:    Walk(x.v);
-// GEN-NEXT:    else
-// GEN-NEXT:    Put("*");
-// GEN-NEXT:    Put(")");
-// GEN-NEXT:  }
-// GEN-NEXT:  void Before(const TdlClause::Claused &) { Word("CLAUSED"); }
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_FLANG_CLAUSE_UNPARSE
-
-// GEN:       #ifdef GEN_CLANG_CLAUSE_CLASS
-// GEN-NEXT:  #undef GEN_CLANG_CLAUSE_CLASS
-// GEN-EMPTY:
-// GEN-NEXT:  #ifndef CLAUSE
-// GEN-NEXT:  #define CLAUSE(Enum, Str, Implicit)
-// GEN-NEXT:  #endif
-// GEN-NEXT:  #ifndef CLAUSE_CLASS
-// GEN-NEXT:  #define CLAUSE_CLASS(Enum, Str, Class)
-// GEN-NEXT:  #endif
-// GEN-NEXT:  #ifndef CLAUSE_NO_CLASS
-// GEN-NEXT:  #define CLAUSE_NO_CLASS(Enum, Str)
-// GEN-NEXT:  #endif
-// GEN-EMPTY:
-// GEN-NEXT:  #define __CLAUSE(Name, Class)                      \
-// GEN-NEXT:    CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
-// GEN-NEXT:    CLAUSE_CLASS(TDLC_##Name, #Name, Class)
-// GEN-NEXT:  #define __CLAUSE_NO_CLASS(Name)                    \
-// GEN-NEXT:    CLAUSE(TDLC_##Name, #Name, /* Implicit */ false) \
-// GEN-NEXT:    CLAUSE_NO_CLASS(TDLC_##Name, #Name)
-// GEN-NEXT:  #define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class)  \
-// GEN-NEXT:    CLAUSE(TDLC_##Name, Str, /* Implicit */ true)    \
-// GEN-NEXT:  CLAUSE_CLASS(TDLC_##Name, Str, Class)
-// GEN-NEXT:  #define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str)      \
-// GEN-NEXT:    CLAUSE(TDLC_##Name, Str, /* Implicit */ true)    \
-// GEN-NEXT:  CLAUSE_NO_CLASS(TDLC_##Name, Str)
-// GEN-EMPTY:
-// GEN-NEXT:  __IMPLICIT_CLAUSE_NO_CLASS(clausea, "clausea")
-// GEN-NEXT:  __CLAUSE_NO_CLASS(clauseb)
-// GEN-NEXT:  __CLAUSE(clausec, ClauseC)
-// GEN-NEXT:  __IMPLICIT_CLAUSE_CLASS(claused, "claused", ClauseD)
-// GEN-EMPTY:
-// GEN-NEXT:  #undef __IMPLICIT_CLAUSE_NO_CLASS
-// GEN-NEXT:  #undef __IMPLICIT_CLAUSE_CLASS
-// GEN-NEXT:  #undef __CLAUSE
-// GEN-NEXT:  #undef CLAUSE_NO_CLASS
-// GEN-NEXT:  #undef CLAUSE_CLASS
-// GEN-NEXT:  #undef CLAUSE
-// GEN-EMPTY:
-// GEN-NEXT:  #endif // GEN_CLANG_CLAUSE_CLASS
-
+// IMPL-EMPTY:
+// IMPL-NEXT:  #endif // GEN_DIRECTIVES_IMPL

diff  --git a/llvm/test/TableGen/directive3.td b/llvm/test/TableGen/directive3.td
index 8af4594f2994..2a82b5ebcb49 100644
--- a/llvm/test/TableGen/directive3.td
+++ b/llvm/test/TableGen/directive3.td
@@ -1,6 +1,5 @@
 // RUN: not llvm-tblgen -gen-directive-decl -I %p/../../include %s 2>&1 | FileCheck -match-full-lines %s
 // RUN: not llvm-tblgen -gen-directive-impl -I %p/../../include %s 2>&1 | FileCheck -match-full-lines %s
-// RUN: not llvm-tblgen -gen-directive-gen -I %p/../../include %s 2>&1 | FileCheck -match-full-lines %s
 
 include "llvm/Frontend/Directive/DirectiveBase.td"
 

diff  --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp
index b331fd9c0613..b21bf369d18e 100644
--- a/llvm/utils/TableGen/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -758,37 +758,11 @@ void GenerateClauseClassMacro(const DirectiveLanguage &DirLang,
   OS << "#undef CLAUSE\n";
 }
 
-// Generate the implementation section for the enumeration in the directive
-// language.
-void EmitDirectivesGen(RecordKeeper &Records, raw_ostream &OS) {
-  const auto DirLang = DirectiveLanguage{Records};
-  if (DirLang.HasValidityErrors())
-    return;
-
-  EmitDirectivesFlangImpl(DirLang, OS);
-
-  GenerateClauseClassMacro(DirLang, OS);
-}
-
-// Generate the implementation for the enumeration in the directive
+// Generate the implemenation for the enumeration in the directive
 // language. This code can be included in library.
-void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) {
-  const auto DirLang = DirectiveLanguage{Records};
-  if (DirLang.HasValidityErrors())
-    return;
-
-  if (!DirLang.getIncludeHeader().empty())
-    OS << "#include \"" << DirLang.getIncludeHeader() << "\"\n\n";
-
-  OS << "#include \"llvm/ADT/StringRef.h\"\n";
-  OS << "#include \"llvm/ADT/StringSwitch.h\"\n";
-  OS << "#include \"llvm/Support/ErrorHandling.h\"\n";
-  OS << "\n";
-  OS << "using namespace llvm;\n";
-  llvm::SmallVector<StringRef, 2> Namespaces;
-  llvm::SplitString(DirLang.getCppNamespace(), Namespaces, "::");
-  for (auto Ns : Namespaces)
-    OS << "using namespace " << Ns << ";\n";
+void EmitDirectivesBasicImpl(const DirectiveLanguage &DirLang,
+                             raw_ostream &OS) {
+  IfDefScope Scope("GEN_DIRECTIVES_IMPL", OS);
 
   // getDirectiveKind(StringRef Str)
   GenerateGetKind(DirLang.getDirectives(), OS, "Directive", DirLang,
@@ -814,4 +788,18 @@ void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) {
   GenerateIsAllowedClause(DirLang, OS);
 }
 
+// Generate the implemenation section for the enumeration in the directive
+// language.
+void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) {
+  const auto DirLang = DirectiveLanguage{Records};
+  if (DirLang.HasValidityErrors())
+    return;
+
+  EmitDirectivesFlangImpl(DirLang, OS);
+
+  GenerateClauseClassMacro(DirLang, OS);
+
+  EmitDirectivesBasicImpl(DirLang, OS);
+}
+
 } // namespace llvm

diff  --git a/llvm/utils/TableGen/TableGen.cpp b/llvm/utils/TableGen/TableGen.cpp
index a4b16179cdf7..24c11c8bc831 100644
--- a/llvm/utils/TableGen/TableGen.cpp
+++ b/llvm/utils/TableGen/TableGen.cpp
@@ -57,7 +57,6 @@ enum ActionType {
   GenAutomata,
   GenDirectivesEnumDecl,
   GenDirectivesEnumImpl,
-  GenDirectivesEnumGen,
 };
 
 namespace llvm {
@@ -139,9 +138,7 @@ cl::opt<ActionType> Action(
         clEnumValN(GenDirectivesEnumDecl, "gen-directive-decl",
                    "Generate directive related declaration code (header file)"),
         clEnumValN(GenDirectivesEnumImpl, "gen-directive-impl",
-                   "Generate directive related implementation code"),
-        clEnumValN(GenDirectivesEnumGen, "gen-directive-gen",
-                   "Generate directive related implementation code part")));
+                   "Generate directive related implementation code")));
 
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt<std::string> Class("class", cl::desc("Print Enum list for this class"),
@@ -275,9 +272,6 @@ bool LLVMTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
   case GenDirectivesEnumImpl:
     EmitDirectivesImpl(Records, OS);
     break;
-  case GenDirectivesEnumGen:
-    EmitDirectivesGen(Records, OS);
-    break;
   }
 
   return false;

diff  --git a/llvm/utils/TableGen/TableGenBackends.h b/llvm/utils/TableGen/TableGenBackends.h
index ed0057c697cf..71db8dc77b05 100644
--- a/llvm/utils/TableGen/TableGenBackends.h
+++ b/llvm/utils/TableGen/TableGenBackends.h
@@ -93,7 +93,6 @@ 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 EmitDirectivesGen(RecordKeeper &RK, raw_ostream &OS);
 
 } // End llvm namespace
 

diff  --git a/llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenACC/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenACC/BUILD.gn
index 995b7f29e521..c6d80b2be3f6 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenACC/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenACC/BUILD.gn
@@ -8,7 +8,7 @@ tablegen("ACC") {
 
 tablegen("ACCcpp") {
   visibility = [ ":acc_gen" ]
-  args = [ "-gen-directive-gen" ]
+  args = [ "-gen-directive-impl" ]
   output_name = "ACC.inc"
   td_file = "ACC.td"
 }

diff  --git a/llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenMP/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenMP/BUILD.gn
index 04bfdd6f3134..d99b8b5a1e27 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenMP/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Frontend/OpenMP/BUILD.gn
@@ -9,7 +9,7 @@ tablegen("OMPh") {
 
 tablegen("OMP") {
   visibility = [ ":public_tablegen" ]
-  args = [ "-gen-directive-gen" ]
+  args = [ "-gen-directive-impl" ]
 }
 
 # Groups all tablegen() calls that create .inc files that are included in


        


More information about the llvm-commits mailing list