diff --git a/llvm/include/llvm/Frontend/Directive/DirectiveBase.td b/llvm/include/llvm/Frontend/Directive/DirectiveBase.td --- a/llvm/include/llvm/Frontend/Directive/DirectiveBase.td +++ b/llvm/include/llvm/Frontend/Directive/DirectiveBase.td @@ -39,6 +39,10 @@ // 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. diff --git a/llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt b/llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt --- a/llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt +++ b/llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt @@ -1,4 +1,3 @@ set(LLVM_TARGET_DEFINITIONS OMP.td) tablegen(LLVM OMP.h.inc --gen-directive-decl) -tablegen(LLVM OMP.cpp.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 --- a/llvm/include/llvm/Frontend/OpenMP/OMP.td +++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td @@ -23,6 +23,7 @@ let clausePrefix = "OMPC_"; let makeEnumAvailableInNamespace = 1; let enableBitmaskEnumInNamespace = 1; + let includeHeader = "llvm/Frontend/OpenMP/OMP.h.inc"; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Frontend/OpenMP/CMakeLists.txt b/llvm/lib/Frontend/OpenMP/CMakeLists.txt --- a/llvm/lib/Frontend/OpenMP/CMakeLists.txt +++ b/llvm/lib/Frontend/OpenMP/CMakeLists.txt @@ -1,5 +1,9 @@ +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 - OMPConstants.cpp + OMP.cpp # Generated by tablegen above OMPContext.cpp OMPIRBuilder.cpp @@ -10,4 +14,5 @@ DEPENDS intrinsics_gen omp_gen - ) + omp_cpp + ) \ No newline at end of file diff --git a/llvm/lib/Frontend/OpenMP/OMPConstants.cpp b/llvm/lib/Frontend/OpenMP/OMPConstants.cpp deleted file mode 100644 --- a/llvm/lib/Frontend/OpenMP/OMPConstants.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//===- OMPConstants.cpp - Helpers related to OpenMP code generation ---===// -// -// 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/OMPConstants.h" - -#include "llvm/ADT/StringRef.h" -#include "llvm/ADT/StringSwitch.h" -#include "llvm/IR/Module.h" -#include "llvm/IR/Type.h" - -using namespace llvm; -using namespace omp; - -#include "llvm/Frontend/OpenMP/OMP.cpp.inc" diff --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td --- a/llvm/test/TableGen/directive1.td +++ b/llvm/test/TableGen/directive1.td @@ -72,7 +72,13 @@ // CHECK-NEXT: #endif // LLVM_Tdl_INC -// IMPL: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) { +// 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); diff --git a/llvm/test/TableGen/directive2.td b/llvm/test/TableGen/directive2.td --- a/llvm/test/TableGen/directive2.td +++ b/llvm/test/TableGen/directive2.td @@ -9,6 +9,7 @@ let cppNamespace = "tdl"; let directivePrefix = "TDLD_"; let clausePrefix = "TDLC_"; + let includeHeader = "tdl.h.inc"; } def TDLC_ClauseA : Clause<"clausea"> { @@ -62,7 +63,14 @@ // 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) diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp --- a/llvm/utils/TableGen/DirectiveEmitter.cpp +++ b/llvm/utils/TableGen/DirectiveEmitter.cpp @@ -284,10 +284,24 @@ 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);