Skip to content

Commit f4c8b80

Browse files
committed
[openmp] Remove clause from OMPKinds.def and use OMP.td info
Remove the OpenMP clause information from the OMPKinds.def file and use the information from the new OMP.td file. There is now a single source of truth for the directives and clauses. To avoid generate lots of specific small code from tablegen, the macros previously used in OMPKinds.def are generated almost as identical. This can be polished and possibly removed in a further patch. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D92955
1 parent cb77e87 commit f4c8b80

File tree

22 files changed

+216
-202
lines changed

22 files changed

+216
-202
lines changed

clang/include/clang/AST/ASTFwd.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Type;
2727
#include "clang/AST/TypeNodes.inc"
2828
class CXXCtorInitializer;
2929
class OMPClause;
30-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) class Class;
31-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
32-
30+
#define GEN_CLANG_CLAUSE_CLASS
31+
#define CLAUSE_CLASS(Enum, Str, Class) class Class;
32+
#include "llvm/Frontend/OpenMP/OMP.inc"
3333

3434
} // end namespace clang
3535

clang/include/clang/AST/ASTTypeTraits.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ class ASTNodeKind {
147147
#define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
148148
#include "clang/AST/TypeNodes.inc"
149149
NKI_OMPClause,
150-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) NKI_##Class,
151-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
150+
#define GEN_CLANG_CLAUSE_CLASS
151+
#define CLAUSE_CLASS(Enum, Str, Class) NKI_##Class,
152+
#include "llvm/Frontend/OpenMP/OMP.inc"
152153
NKI_NumberOfKinds
153154
};
154155

@@ -205,8 +206,9 @@ KIND_TO_KIND_ID(CXXBaseSpecifier)
205206
#include "clang/AST/StmtNodes.inc"
206207
#define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
207208
#include "clang/AST/TypeNodes.inc"
208-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) KIND_TO_KIND_ID(Class)
209-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
209+
#define GEN_CLANG_CLAUSE_CLASS
210+
#define CLAUSE_CLASS(Enum, Str, Class) KIND_TO_KIND_ID(Class)
211+
#include "llvm/Frontend/OpenMP/OMP.inc"
210212
#undef KIND_TO_KIND_ID
211213

212214
inline raw_ostream &operator<<(raw_ostream &OS, ASTNodeKind K) {

clang/include/clang/AST/OpenMPClause.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7758,22 +7758,22 @@ class OMPClauseVisitorBase {
77587758
#define DISPATCH(CLASS) \
77597759
return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
77607760

7761-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
7762-
RetTy Visit ## Class (PTR(Class) S) { DISPATCH(Class); }
7763-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
7761+
#define GEN_CLANG_CLAUSE_CLASS
7762+
#define CLAUSE_CLASS(Enum, Str, Class) \
7763+
RetTy Visit##Class(PTR(Class) S) { DISPATCH(Class); }
7764+
#include "llvm/Frontend/OpenMP/OMP.inc"
77647765

77657766
RetTy Visit(PTR(OMPClause) S) {
77667767
// Top switch clause: visit each OMPClause.
77677768
switch (S->getClauseKind()) {
7768-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
7769+
#define GEN_CLANG_CLAUSE_CLASS
7770+
#define CLAUSE_CLASS(Enum, Str, Class) \
77697771
case llvm::omp::Clause::Enum: \
77707772
return Visit##Class(static_cast<PTR(Class)>(S));
7771-
#define OMP_CLAUSE_NO_CLASS(Enum, Str) \
7773+
#define CLAUSE_NO_CLASS(Enum, Str) \
77727774
case llvm::omp::Clause::Enum: \
77737775
break;
7774-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
7775-
default:
7776-
break;
7776+
#include "llvm/Frontend/OpenMP/OMP.inc"
77777777
}
77787778
}
77797779
// Base case, ignore it. :)
@@ -7804,9 +7804,9 @@ class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
78047804
OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
78057805
: OS(OS), Policy(Policy) {}
78067806

7807-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
7808-
void Visit##Class(Class *S);
7809-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
7807+
#define GEN_CLANG_CLAUSE_CLASS
7808+
#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);
7809+
#include "llvm/Frontend/OpenMP/OMP.inc"
78107810
};
78117811

78127812
struct OMPTraitProperty {

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,9 @@ template <typename Derived> class RecursiveASTVisitor {
488488
bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
489489
bool TraverseOMPLoopDirective(OMPLoopDirective *S);
490490
bool TraverseOMPClause(OMPClause *C);
491-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) bool Visit##Class(Class *C);
492-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
491+
#define GEN_CLANG_CLAUSE_CLASS
492+
#define CLAUSE_CLASS(Enum, Str, Class) bool Visit##Class(Class *C);
493+
#include "llvm/Frontend/OpenMP/OMP.inc"
493494
/// Process clauses with list of variables.
494495
template <typename T> bool VisitOMPClauseList(T *Node);
495496
/// Process clauses with pre-initis.
@@ -2949,16 +2950,15 @@ bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
29492950
if (!C)
29502951
return true;
29512952
switch (C->getClauseKind()) {
2952-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
2953+
#define GEN_CLANG_CLAUSE_CLASS
2954+
#define CLAUSE_CLASS(Enum, Str, Class) \
29532955
case llvm::omp::Clause::Enum: \
29542956
TRY_TO(Visit##Class(static_cast<Class *>(C))); \
29552957
break;
2956-
#define OMP_CLAUSE_NO_CLASS(Enum, Str) \
2958+
#define CLAUSE_NO_CLASS(Enum, Str) \
29572959
case llvm::omp::Clause::Enum: \
29582960
break;
2959-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
2960-
default:
2961-
break;
2961+
#include "llvm/Frontend/OpenMP/OMP.inc"
29622962
}
29632963
return true;
29642964
}

clang/lib/AST/ASTTypeTraits.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,29 @@
2121
using namespace clang;
2222

2323
const ASTNodeKind::KindInfo ASTNodeKind::AllKindInfo[] = {
24-
{ NKI_None, "<None>" },
25-
{ NKI_None, "TemplateArgument" },
26-
{ NKI_None, "TemplateArgumentLoc" },
27-
{ NKI_None, "TemplateName" },
28-
{ NKI_None, "NestedNameSpecifierLoc" },
29-
{ NKI_None, "QualType" },
30-
{ NKI_None, "TypeLoc" },
31-
{ NKI_None, "CXXBaseSpecifier" },
32-
{ NKI_None, "CXXCtorInitializer" },
33-
{ NKI_None, "NestedNameSpecifier" },
34-
{ NKI_None, "Decl" },
24+
{NKI_None, "<None>"},
25+
{NKI_None, "TemplateArgument"},
26+
{NKI_None, "TemplateArgumentLoc"},
27+
{NKI_None, "TemplateName"},
28+
{NKI_None, "NestedNameSpecifierLoc"},
29+
{NKI_None, "QualType"},
30+
{NKI_None, "TypeLoc"},
31+
{NKI_None, "CXXBaseSpecifier"},
32+
{NKI_None, "CXXCtorInitializer"},
33+
{NKI_None, "NestedNameSpecifier"},
34+
{NKI_None, "Decl"},
3535
#define DECL(DERIVED, BASE) { NKI_##BASE, #DERIVED "Decl" },
3636
#include "clang/AST/DeclNodes.inc"
37-
{ NKI_None, "Stmt" },
37+
{NKI_None, "Stmt"},
3838
#define STMT(DERIVED, BASE) { NKI_##BASE, #DERIVED },
3939
#include "clang/AST/StmtNodes.inc"
40-
{ NKI_None, "Type" },
40+
{NKI_None, "Type"},
4141
#define TYPE(DERIVED, BASE) { NKI_##BASE, #DERIVED "Type" },
4242
#include "clang/AST/TypeNodes.inc"
43-
{ NKI_None, "OMPClause" },
44-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) {NKI_OMPClause, #Class},
45-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
43+
{NKI_None, "OMPClause"},
44+
#define GEN_CLANG_CLAUSE_CLASS
45+
#define CLAUSE_CLASS(Enum, Str, Class) {NKI_OMPClause, #Class},
46+
#include "llvm/Frontend/OpenMP/OMP.inc"
4647
};
4748

4849
bool ASTNodeKind::isBaseOf(ASTNodeKind Other, unsigned *Distance) const {
@@ -113,15 +114,14 @@ ASTNodeKind ASTNodeKind::getFromNode(const Type &T) {
113114

114115
ASTNodeKind ASTNodeKind::getFromNode(const OMPClause &C) {
115116
switch (C.getClauseKind()) {
116-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
117+
#define GEN_CLANG_CLAUSE_CLASS
118+
#define CLAUSE_CLASS(Enum, Str, Class) \
117119
case llvm::omp::Clause::Enum: \
118120
return ASTNodeKind(NKI_##Class);
119-
#define OMP_CLAUSE_NO_CLASS(Enum, Str) \
121+
#define CLAUSE_NO_CLASS(Enum, Str) \
120122
case llvm::omp::Clause::Enum: \
121123
llvm_unreachable("unexpected OpenMP clause kind");
122-
default:
123-
break;
124-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
124+
#include "llvm/Frontend/OpenMP/OMP.inc"
125125
}
126126
llvm_unreachable("invalid stmt kind");
127127
}

clang/lib/AST/OpenMPClause.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,25 @@ OMPClause::child_range OMPClause::children() {
3232
switch (getClauseKind()) {
3333
default:
3434
break;
35-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
35+
#define GEN_CLANG_CLAUSE_CLASS
36+
#define CLAUSE_CLASS(Enum, Str, Class) \
3637
case Enum: \
3738
return static_cast<Class *>(this)->children();
38-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
39+
#include "llvm/Frontend/OpenMP/OMP.inc"
3940
}
4041
llvm_unreachable("unknown OMPClause");
4142
}
4243

4344
OMPClause::child_range OMPClause::used_children() {
4445
switch (getClauseKind()) {
45-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
46+
#define GEN_CLANG_CLAUSE_CLASS
47+
#define CLAUSE_CLASS(Enum, Str, Class) \
4648
case Enum: \
4749
return static_cast<Class *>(this)->used_children();
48-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
49-
case OMPC_threadprivate:
50-
case OMPC_uniform:
51-
case OMPC_device_type:
52-
case OMPC_match:
53-
case OMPC_unknown:
54-
break;
55-
default:
50+
#define CLAUSE_NO_CLASS(Enum, Str) \
51+
case Enum: \
5652
break;
53+
#include "llvm/Frontend/OpenMP/OMP.inc"
5754
}
5855
llvm_unreachable("unknown OMPClause");
5956
}

clang/lib/AST/StmtProfile.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,9 @@ class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
414414

415415
public:
416416
OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
417-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C);
418-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
417+
#define GEN_CLANG_CLAUSE_CLASS
418+
#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C);
419+
#include "llvm/Frontend/OpenMP/OMP.inc"
419420
void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
420421
void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
421422
};

clang/lib/ASTMatchers/Dynamic/Marshallers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ llvm::Optional<std::string>
8989
clang::ast_matchers::dynamic::internal::ArgTypeTraits<
9090
clang::OpenMPClauseKind>::getBestGuess(const VariantValue &Value) {
9191
static constexpr llvm::StringRef Allowed[] = {
92-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) #Enum,
93-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
92+
#define GEN_CLANG_CLAUSE_CLASS
93+
#define CLAUSE_CLASS(Enum, Str, Class) #Enum,
94+
#include "llvm/Frontend/OpenMP/OMP.inc"
9495
};
9596
if (Value.isString())
9697
return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),

clang/lib/ASTMatchers/Dynamic/Marshallers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ template <> struct ArgTypeTraits<OpenMPClauseKind> {
243243
private:
244244
static Optional<OpenMPClauseKind> getClauseKind(llvm::StringRef ClauseKind) {
245245
return llvm::StringSwitch<Optional<OpenMPClauseKind>>(ClauseKind)
246-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) .Case(#Enum, llvm::omp::Clause::Enum)
247-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
246+
#define GEN_CLANG_CLAUSE_CLASS
247+
#define CLAUSE_CLASS(Enum, Str, Class) .Case(#Enum, llvm::omp::Clause::Enum)
248+
#include "llvm/Frontend/OpenMP/OMP.inc"
248249
.Default(llvm::None);
249250
}
250251

clang/lib/Sema/TreeTransform.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,11 @@ class TreeTransform {
731731
#define ABSTRACT_STMT(Stmt)
732732
#include "clang/AST/StmtNodes.inc"
733733

734-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
735-
LLVM_ATTRIBUTE_NOINLINE \
736-
OMPClause *Transform ## Class(Class *S);
737-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
734+
#define GEN_CLANG_CLAUSE_CLASS
735+
#define CLAUSE_CLASS(Enum, Str, Class) \
736+
LLVM_ATTRIBUTE_NOINLINE \
737+
OMPClause *Transform##Class(Class *S);
738+
#include "llvm/Frontend/OpenMP/OMP.inc"
738739

739740
/// Build a new qualified type given its unqualified type and type location.
740741
///
@@ -3691,10 +3692,11 @@ OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
36913692
switch (S->getClauseKind()) {
36923693
default: break;
36933694
// Transform individual clause nodes
3694-
#define OMP_CLAUSE_CLASS(Enum, Str, Class) \
3695+
#define GEN_CLANG_CLAUSE_CLASS
3696+
#define CLAUSE_CLASS(Enum, Str, Class) \
36953697
case Enum: \
3696-
return getDerived().Transform ## Class(cast<Class>(S));
3697-
#include "llvm/Frontend/OpenMP/OMPKinds.def"
3698+
return getDerived().Transform##Class(cast<Class>(S));
3699+
#include "llvm/Frontend/OpenMP/OMP.inc"
36983700
}
36993701

37003702
return S;

0 commit comments

Comments
 (0)