Skip to content

Commit 943660f

Browse files
committed
[openmp] Remove OMPConstants.cpp and replace it by OMP.cpp generated by tablegen
Summary: Diff D83176 moved the last piece of code from OMPConstants.cpp and now this file was only useful to include the tablegen generated file. This patch replace OMPConstants.cpp with OMP.cpp generated by tablegen. Reviewers: sstefan1, jdoerfert, jdenny Reviewed By: sstefan1 Subscribers: mgorny, yaxunl, hiraditya, guansong, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D83583
1 parent cd0ea03 commit 943660f

8 files changed

Lines changed: 42 additions & 26 deletions

File tree

‎llvm/include/llvm/Frontend/Directive/DirectiveBase.td‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class DirectiveLanguage {
3939

4040
// Generate include and macro to enable LLVM BitmaskEnum.
4141
bit enableBitmaskEnumInNamespace = 0;
42+
43+
// Header file included in the implementation code generated. Ususally the
44+
// output file of the declaration code generation. Can be left blank.
45+
string includeHeader = "";
4246
}
4347

4448
// Information about a specific clause.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
set(LLVM_TARGET_DEFINITIONS OMP.td)
22
tablegen(LLVM OMP.h.inc --gen-directive-decl)
3-
tablegen(LLVM OMP.cpp.inc --gen-directive-impl)
43
add_public_tablegen_target(omp_gen)

‎llvm/include/llvm/Frontend/OpenMP/OMP.td‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def OpenMP : DirectiveLanguage {
2323
let clausePrefix = "OMPC_";
2424
let makeEnumAvailableInNamespace = 1;
2525
let enableBitmaskEnumInNamespace = 1;
26+
let includeHeader = "llvm/Frontend/OpenMP/OMP.h.inc";
2627
}
2728

2829
//===----------------------------------------------------------------------===//

‎llvm/lib/Frontend/OpenMP/CMakeLists.txt‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/OpenMP/OMP.td)
2+
tablegen(LLVM OMP.cpp --gen-directive-impl)
3+
add_public_tablegen_target(omp_cpp)
4+
15
add_llvm_component_library(LLVMFrontendOpenMP
2-
OMPConstants.cpp
6+
OMP.cpp # Generated by tablegen above
37
OMPContext.cpp
48
OMPIRBuilder.cpp
59

@@ -10,4 +14,5 @@ add_llvm_component_library(LLVMFrontendOpenMP
1014
DEPENDS
1115
intrinsics_gen
1216
omp_gen
13-
)
17+
omp_cpp
18+
)

‎llvm/lib/Frontend/OpenMP/OMPConstants.cpp‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎llvm/test/TableGen/directive1.td‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ def TDL_DirA : Directive<"dira"> {
7272
// CHECK-NEXT: #endif // LLVM_Tdl_INC
7373

7474

75-
// IMPL: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
75+
// IMPL: #include "llvm/ADT/StringRef.h"
76+
// IMPL-NEXT: #include "llvm/ADT/StringSwitch.h"
77+
// IMPL-EMPTY:
78+
// IMPL-NEXT: using namespace llvm;
79+
// IMPL-NEXT: using namespace tdl;
80+
// IMPL-EMPTY:
81+
// IMPL-NEXT: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
7682
// IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
7783
// IMPL-NEXT: .Case("dira",TDLD_dira)
7884
// IMPL-NEXT: .Default(TDLD_dira);

‎llvm/test/TableGen/directive2.td‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def TestDirectiveLanguage : DirectiveLanguage {
99
let cppNamespace = "tdl";
1010
let directivePrefix = "TDLD_";
1111
let clausePrefix = "TDLC_";
12+
let includeHeader = "tdl.h.inc";
1213
}
1314

1415
def TDLC_ClauseA : Clause<"clausea"> {
@@ -62,7 +63,14 @@ def TDL_DirA : Directive<"dira"> {
6263
// CHECK-NEXT: } // namespace llvm
6364
// CHECK-NEXT: #endif // LLVM_Tdl_INC
6465

65-
66+
// IMPL: #include "tdl.h.inc"
67+
// IMPL-EMPTY:
68+
// IMPL-NEXT: #include "llvm/ADT/StringRef.h"
69+
// IMPL-NEXT: #include "llvm/ADT/StringSwitch.h"
70+
// IMPL-EMPTY:
71+
// IMPL-NEXT: using namespace llvm;
72+
// IMPL-NEXT: using namespace tdl;
73+
// IMPL-EMPTY:
6674
// IMPL: Directive llvm::tdl::getTdlDirectiveKind(llvm::StringRef Str) {
6775
// IMPL-NEXT: return llvm::StringSwitch<Directive>(Str)
6876
// IMPL-NEXT: .Case("dira",TDLD_dira)

‎llvm/utils/TableGen/DirectiveEmitter.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,24 @@ void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) {
284284
StringRef LanguageName = DirectiveLanguage->getValueAsString("name");
285285
StringRef ClausePrefix = DirectiveLanguage->getValueAsString("clausePrefix");
286286
StringRef CppNamespace = DirectiveLanguage->getValueAsString("cppNamespace");
287+
StringRef IncludeHeader =
288+
DirectiveLanguage->getValueAsString("includeHeader");
287289

288290
const auto &Directives = Records.getAllDerivedDefinitions("Directive");
289291
const auto &Clauses = Records.getAllDerivedDefinitions("Clause");
290292

293+
if (!IncludeHeader.empty())
294+
OS << "#include \"" << IncludeHeader << "\"\n\n";
295+
296+
OS << "#include \"llvm/ADT/StringRef.h\"\n";
297+
OS << "#include \"llvm/ADT/StringSwitch.h\"\n";
298+
OS << "\n";
299+
OS << "using namespace llvm;\n";
300+
llvm::SmallVector<StringRef, 2> Namespaces;
301+
llvm::SplitString(CppNamespace, Namespaces, "::");
302+
for (auto Ns : Namespaces)
303+
OS << "using namespace " << Ns << ";\n";
304+
291305
// getDirectiveKind(StringRef Str)
292306
GenerateGetKind(Directives, OS, "Directive", DirectivePrefix, LanguageName,
293307
CppNamespace, /*ImplicitAsUnknown=*/false);

0 commit comments

Comments
 (0)