[OpenMP][NFCI] Move OpenMP clause information to `lib/Frontend/OpenMP`

This is a cleanup and normalization patch that also enables reuse with
Flang later on. A follow up will clean up and move the directive ->
clauses mapping.

Reviewed By: fghanim

Differential Revision: https://reviews.llvm.org/D77112
This commit is contained in:
Johannes Doerfert 2020-03-30 19:58:40 -05:00
parent b43b59fcc0
commit 419a559c5a
29 changed files with 621 additions and 544 deletions

View File

@ -27,8 +27,8 @@ class Type;
#include "clang/AST/TypeNodes.inc" #include "clang/AST/TypeNodes.inc"
class CXXCtorInitializer; class CXXCtorInitializer;
class OMPClause; class OMPClause;
#define OPENMP_CLAUSE(KIND, CLASSNAME) class CLASSNAME; #define OMP_CLAUSE_CLASS(Enum, Str, Class) class Class;
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
} // end namespace clang } // end namespace clang

View File

@ -148,8 +148,8 @@ private:
#define TYPE(DERIVED, BASE) NKI_##DERIVED##Type, #define TYPE(DERIVED, BASE) NKI_##DERIVED##Type,
#include "clang/AST/TypeNodes.inc" #include "clang/AST/TypeNodes.inc"
NKI_OMPClause, NKI_OMPClause,
#define OPENMP_CLAUSE(TextualSpelling, Class) NKI_##Class, #define OMP_CLAUSE_CLASS(Enum, Str, Class) NKI_##Class,
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
NKI_NumberOfKinds NKI_NumberOfKinds
}; };
@ -204,8 +204,8 @@ KIND_TO_KIND_ID(OMPClause)
#include "clang/AST/StmtNodes.inc" #include "clang/AST/StmtNodes.inc"
#define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type) #define TYPE(DERIVED, BASE) KIND_TO_KIND_ID(DERIVED##Type)
#include "clang/AST/TypeNodes.inc" #include "clang/AST/TypeNodes.inc"
#define OPENMP_CLAUSE(TextualSpelling, Class) KIND_TO_KIND_ID(Class) #define OMP_CLAUSE_CLASS(Enum, Str, Class) KIND_TO_KIND_ID(Class)
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
#undef KIND_TO_KIND_ID #undef KIND_TO_KIND_ID
inline raw_ostream &operator<<(raw_ostream &OS, ASTNodeKind K) { inline raw_ostream &operator<<(raw_ostream &OS, ASTNodeKind K) {

File diff suppressed because it is too large Load Diff

View File

@ -534,8 +534,8 @@ private:
bool TraverseOMPExecutableDirective(OMPExecutableDirective *S); bool TraverseOMPExecutableDirective(OMPExecutableDirective *S);
bool TraverseOMPLoopDirective(OMPLoopDirective *S); bool TraverseOMPLoopDirective(OMPLoopDirective *S);
bool TraverseOMPClause(OMPClause *C); bool TraverseOMPClause(OMPClause *C);
#define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C); #define OMP_CLAUSE_CLASS(Enum, Str, Class) bool Visit##Class(Class *C);
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
/// Process clauses with list of variables. /// Process clauses with list of variables.
template <typename T> bool VisitOMPClauseList(T *Node); template <typename T> bool VisitOMPClauseList(T *Node);
/// Process clauses with pre-initis. /// Process clauses with pre-initis.
@ -2957,17 +2957,14 @@ bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
if (!C) if (!C)
return true; return true;
switch (C->getClauseKind()) { switch (C->getClauseKind()) {
#define OPENMP_CLAUSE(Name, Class) \ #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
case OMPC_##Name: \ case llvm::omp::Clause::Enum: \
TRY_TO(Visit##Class(static_cast<Class *>(C))); \ TRY_TO(Visit##Class(static_cast<Class *>(C))); \
break; break;
#include "clang/Basic/OpenMPKinds.def" #define OMP_CLAUSE_NO_CLASS(Enum, Str) \
case OMPC_threadprivate: case llvm::omp::Clause::Enum: \
case OMPC_uniform:
case OMPC_device_type:
case OMPC_match:
case OMPC_unknown:
break; break;
#include "llvm/Frontend/OpenMP/OMPKinds.def"
} }
return true; return true;
} }

View File

@ -3242,8 +3242,13 @@ def OMPCaptureKind : Attr {
// This attribute has no spellings as it is only ever created implicitly. // This attribute has no spellings as it is only ever created implicitly.
let Spellings = []; let Spellings = [];
let SemaHandler = 0; let SemaHandler = 0;
let Args = [UnsignedArgument<"CaptureKind">]; let Args = [UnsignedArgument<"CaptureKindVal">];
let Documentation = [Undocumented]; let Documentation = [Undocumented];
let AdditionalMembers = [{
llvm::omp::Clause getCaptureKind() const {
return static_cast<llvm::omp::Clause>(getCaptureKindVal());
}
}];
} }
def OMPReferencedVar : Attr { def OMPReferencedVar : Attr {

View File

@ -222,74 +222,6 @@
#define OPENMP_REDUCTION_MODIFIER(Name) #define OPENMP_REDUCTION_MODIFIER(Name)
#endif #endif
// OpenMP clauses.
OPENMP_CLAUSE(allocator, OMPAllocatorClause)
OPENMP_CLAUSE(if, OMPIfClause)
OPENMP_CLAUSE(final, OMPFinalClause)
OPENMP_CLAUSE(num_threads, OMPNumThreadsClause)
OPENMP_CLAUSE(safelen, OMPSafelenClause)
OPENMP_CLAUSE(simdlen, OMPSimdlenClause)
OPENMP_CLAUSE(collapse, OMPCollapseClause)
OPENMP_CLAUSE(default, OMPDefaultClause)
OPENMP_CLAUSE(private, OMPPrivateClause)
OPENMP_CLAUSE(firstprivate, OMPFirstprivateClause)
OPENMP_CLAUSE(lastprivate, OMPLastprivateClause)
OPENMP_CLAUSE(shared, OMPSharedClause)
OPENMP_CLAUSE(reduction, OMPReductionClause)
OPENMP_CLAUSE(linear, OMPLinearClause)
OPENMP_CLAUSE(aligned, OMPAlignedClause)
OPENMP_CLAUSE(copyin, OMPCopyinClause)
OPENMP_CLAUSE(copyprivate, OMPCopyprivateClause)
OPENMP_CLAUSE(proc_bind, OMPProcBindClause)
OPENMP_CLAUSE(schedule, OMPScheduleClause)
OPENMP_CLAUSE(ordered, OMPOrderedClause)
OPENMP_CLAUSE(nowait, OMPNowaitClause)
OPENMP_CLAUSE(untied, OMPUntiedClause)
OPENMP_CLAUSE(mergeable, OMPMergeableClause)
OPENMP_CLAUSE(flush, OMPFlushClause)
OPENMP_CLAUSE(read, OMPReadClause)
OPENMP_CLAUSE(write, OMPWriteClause)
OPENMP_CLAUSE(update, OMPUpdateClause)
OPENMP_CLAUSE(capture, OMPCaptureClause)
OPENMP_CLAUSE(seq_cst, OMPSeqCstClause)
OPENMP_CLAUSE(acq_rel, OMPAcqRelClause)
OPENMP_CLAUSE(acquire, OMPAcquireClause)
OPENMP_CLAUSE(release, OMPReleaseClause)
OPENMP_CLAUSE(relaxed, OMPRelaxedClause)
OPENMP_CLAUSE(depend, OMPDependClause)
OPENMP_CLAUSE(device, OMPDeviceClause)
OPENMP_CLAUSE(threads, OMPThreadsClause)
OPENMP_CLAUSE(simd, OMPSIMDClause)
OPENMP_CLAUSE(map, OMPMapClause)
OPENMP_CLAUSE(num_teams, OMPNumTeamsClause)
OPENMP_CLAUSE(thread_limit, OMPThreadLimitClause)
OPENMP_CLAUSE(priority, OMPPriorityClause)
OPENMP_CLAUSE(grainsize, OMPGrainsizeClause)
OPENMP_CLAUSE(nogroup, OMPNogroupClause)
OPENMP_CLAUSE(num_tasks, OMPNumTasksClause)
OPENMP_CLAUSE(hint, OMPHintClause)
OPENMP_CLAUSE(dist_schedule, OMPDistScheduleClause)
OPENMP_CLAUSE(defaultmap, OMPDefaultmapClause)
OPENMP_CLAUSE(to, OMPToClause)
OPENMP_CLAUSE(from, OMPFromClause)
OPENMP_CLAUSE(use_device_ptr, OMPUseDevicePtrClause)
OPENMP_CLAUSE(is_device_ptr, OMPIsDevicePtrClause)
OPENMP_CLAUSE(task_reduction, OMPTaskReductionClause)
OPENMP_CLAUSE(in_reduction, OMPInReductionClause)
OPENMP_CLAUSE(unified_address, OMPUnifiedAddressClause)
OPENMP_CLAUSE(unified_shared_memory, OMPUnifiedSharedMemoryClause)
OPENMP_CLAUSE(reverse_offload, OMPReverseOffloadClause)
OPENMP_CLAUSE(dynamic_allocators, OMPDynamicAllocatorsClause)
OPENMP_CLAUSE(atomic_default_mem_order, OMPAtomicDefaultMemOrderClause)
OPENMP_CLAUSE(allocate, OMPAllocateClause)
OPENMP_CLAUSE(nontemporal, OMPNontemporalClause)
OPENMP_CLAUSE(order, OMPOrderClause)
OPENMP_CLAUSE(depobj, OMPDepobjClause)
OPENMP_CLAUSE(destroy, OMPDestroyClause)
OPENMP_CLAUSE(detach, OMPDetachClause)
OPENMP_CLAUSE(inclusive, OMPInclusiveClause)
OPENMP_CLAUSE(exclusive, OMPExclusiveClause)
// Clauses allowed for OpenMP directive 'scan'. // Clauses allowed for OpenMP directive 'scan'.
OPENMP_SCAN_CLAUSE(inclusive) OPENMP_SCAN_CLAUSE(inclusive)
OPENMP_SCAN_CLAUSE(exclusive) OPENMP_SCAN_CLAUSE(exclusive)

View File

@ -23,16 +23,7 @@ namespace clang {
using OpenMPDirectiveKind = llvm::omp::Directive; using OpenMPDirectiveKind = llvm::omp::Directive;
/// OpenMP clauses. /// OpenMP clauses.
enum OpenMPClauseKind { using OpenMPClauseKind = llvm::omp::Clause;
#define OPENMP_CLAUSE(Name, Class) \
OMPC_##Name,
#include "clang/Basic/OpenMPKinds.def"
OMPC_threadprivate,
OMPC_uniform,
OMPC_device_type,
OMPC_match,
OMPC_unknown
};
/// OpenMP attributes for 'schedule' clause. /// OpenMP attributes for 'schedule' clause.
enum OpenMPScheduleClauseKind { enum OpenMPScheduleClauseKind {
@ -179,9 +170,6 @@ enum OpenMPReductionClauseModifier {
OMPC_REDUCTION_unknown, OMPC_REDUCTION_unknown,
}; };
OpenMPClauseKind getOpenMPClauseKind(llvm::StringRef Str);
const char *getOpenMPClauseName(OpenMPClauseKind Kind);
unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str); unsigned getOpenMPSimpleClauseType(OpenMPClauseKind Kind, llvm::StringRef Str);
const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type); const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type);

View File

@ -39,8 +39,8 @@ const ASTNodeKind::KindInfo ASTNodeKind::AllKindInfo[] = {
#define TYPE(DERIVED, BASE) { NKI_##BASE, #DERIVED "Type" }, #define TYPE(DERIVED, BASE) { NKI_##BASE, #DERIVED "Type" },
#include "clang/AST/TypeNodes.inc" #include "clang/AST/TypeNodes.inc"
{ NKI_None, "OMPClause" }, { NKI_None, "OMPClause" },
#define OPENMP_CLAUSE(TextualSpelling, Class) {NKI_OMPClause, #Class}, #define OMP_CLAUSE_CLASS(Enum, Str, Class) {NKI_OMPClause, #Class},
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
}; };
bool ASTNodeKind::isBaseOf(ASTNodeKind Other, unsigned *Distance) const { bool ASTNodeKind::isBaseOf(ASTNodeKind Other, unsigned *Distance) const {
@ -111,15 +111,13 @@ ASTNodeKind ASTNodeKind::getFromNode(const Type &T) {
ASTNodeKind ASTNodeKind::getFromNode(const OMPClause &C) { ASTNodeKind ASTNodeKind::getFromNode(const OMPClause &C) {
switch (C.getClauseKind()) { switch (C.getClauseKind()) {
#define OPENMP_CLAUSE(Name, Class) \ #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
case OMPC_##Name: return ASTNodeKind(NKI_##Class); case llvm::omp::Clause::Enum: \
#include "clang/Basic/OpenMPKinds.def" return ASTNodeKind(NKI_##Class);
case OMPC_threadprivate: #define OMP_CLAUSE_NO_CLASS(Enum, Str) \
case OMPC_uniform: case llvm::omp::Clause::Enum: \
case OMPC_device_type:
case OMPC_match:
case OMPC_unknown:
llvm_unreachable("unexpected OpenMP clause kind"); llvm_unreachable("unexpected OpenMP clause kind");
#include "llvm/Frontend/OpenMP/OMPKinds.def"
} }
llvm_unreachable("invalid stmt kind"); llvm_unreachable("invalid stmt kind");
} }

View File

@ -108,7 +108,8 @@ void OMPDeclareSimdDeclAttr::printPrettyPragma(
for (auto *E : linears()) { for (auto *E : linears()) {
OS << " linear("; OS << " linear(";
if (*MI != OMPC_LINEAR_unknown) if (*MI != OMPC_LINEAR_unknown)
OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "("; OS << getOpenMPSimpleClauseTypeName(llvm::omp::Clause::OMPC_linear, *MI)
<< "(";
E->printPretty(OS, nullptr, Policy); E->printPretty(OS, nullptr, Policy);
if (*MI != OMPC_LINEAR_unknown) if (*MI != OMPC_LINEAR_unknown)
OS << ")"; OS << ")";

View File

@ -31,20 +31,20 @@ OMPClause::child_range OMPClause::children() {
switch (getClauseKind()) { switch (getClauseKind()) {
default: default:
break; break;
#define OPENMP_CLAUSE(Name, Class) \ #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
case OMPC_##Name: \ case Enum: \
return static_cast<Class *>(this)->children(); return static_cast<Class *>(this)->children();
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
} }
llvm_unreachable("unknown OMPClause"); llvm_unreachable("unknown OMPClause");
} }
OMPClause::child_range OMPClause::used_children() { OMPClause::child_range OMPClause::used_children() {
switch (getClauseKind()) { switch (getClauseKind()) {
#define OPENMP_CLAUSE(Name, Class) \ #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
case OMPC_##Name: \ case Enum: \
return static_cast<Class *>(this)->used_children(); return static_cast<Class *>(this)->used_children();
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
case OMPC_threadprivate: case OMPC_threadprivate:
case OMPC_uniform: case OMPC_uniform:
case OMPC_device_type: case OMPC_device_type:

View File

@ -414,9 +414,8 @@ class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
public: public:
OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { } OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
#define OPENMP_CLAUSE(Name, Class) \ #define OMP_CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C);
void Visit##Class(const Class *C); #include "llvm/Frontend/OpenMP/OMPKinds.def"
#include "clang/Basic/OpenMPKinds.def"
void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C); void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C); void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
}; };

View File

@ -314,7 +314,7 @@ void TextNodeDumper::Visit(const OMPClause *C) {
} }
{ {
ColorScope Color(OS, ShowColors, AttrColor); ColorScope Color(OS, ShowColors, AttrColor);
StringRef ClauseName(getOpenMPClauseName(C->getClauseKind())); StringRef ClauseName(llvm::omp::getOpenMPClauseName(C->getClauseKind()));
OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper() OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
<< ClauseName.drop_front() << "Clause"; << ClauseName.drop_front() << "Clause";
} }
@ -1534,7 +1534,8 @@ void TextNodeDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {
} }
{ {
ColorScope Color(OS, ShowColors, AttrColor); ColorScope Color(OS, ShowColors, AttrColor);
StringRef ClauseName(getOpenMPClauseName(C->getClauseKind())); StringRef ClauseName(
llvm::omp::getOpenMPClauseName(C->getClauseKind()));
OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper() OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
<< ClauseName.drop_front() << "Clause"; << ClauseName.drop_front() << "Clause";
} }

View File

@ -1,6 +1,9 @@
add_subdirectory(Dynamic) add_subdirectory(Dynamic)
set(LLVM_LINK_COMPONENTS support) set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)
add_clang_library(clangASTMatchers add_clang_library(clangASTMatchers
ASTMatchFinder.cpp ASTMatchFinder.cpp

View File

@ -170,9 +170,8 @@ template <> struct ArgTypeTraits<OpenMPClauseKind> {
private: private:
static Optional<OpenMPClauseKind> getClauseKind(llvm::StringRef ClauseKind) { static Optional<OpenMPClauseKind> getClauseKind(llvm::StringRef ClauseKind) {
return llvm::StringSwitch<Optional<OpenMPClauseKind>>(ClauseKind) return llvm::StringSwitch<Optional<OpenMPClauseKind>>(ClauseKind)
#define OPENMP_CLAUSE(TextualSpelling, Class) \ #define OMP_CLAUSE_CLASS(Enum, Str, Class) .Case(#Enum, llvm::omp::Clause::Enum)
.Case("OMPC_" #TextualSpelling, OMPC_##TextualSpelling) #include "llvm/Frontend/OpenMP/OMPKinds.def"
#include "clang/Basic/OpenMPKinds.def"
.Default(llvm::None); .Default(llvm::None);
} }

View File

@ -1,4 +1,5 @@
set(LLVM_LINK_COMPONENTS set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support Support
) )

View File

@ -20,50 +20,6 @@
using namespace clang; using namespace clang;
using namespace llvm::omp; using namespace llvm::omp;
OpenMPClauseKind clang::getOpenMPClauseKind(StringRef Str) {
// 'flush' clause cannot be specified explicitly, because this is an implicit
// clause for 'flush' directive. If the 'flush' clause is explicitly specified
// the Parser should generate a warning about extra tokens at the end of the
// directive.
// 'depobj' clause cannot be specified explicitly, because this is an implicit
// clause for 'depobj' directive. If the 'depobj' clause is explicitly
// specified the Parser should generate a warning about extra tokens at the
// end of the directive.
if (llvm::StringSwitch<bool>(Str)
.Case("flush", true)
.Case("depobj", true)
.Default(false))
return OMPC_unknown;
return llvm::StringSwitch<OpenMPClauseKind>(Str)
#define OPENMP_CLAUSE(Name, Class) .Case(#Name, OMPC_##Name)
#include "clang/Basic/OpenMPKinds.def"
.Case("uniform", OMPC_uniform)
.Case("device_type", OMPC_device_type)
.Case("match", OMPC_match)
.Default(OMPC_unknown);
}
const char *clang::getOpenMPClauseName(OpenMPClauseKind Kind) {
assert(Kind <= OMPC_unknown);
switch (Kind) {
case OMPC_unknown:
return "unknown";
#define OPENMP_CLAUSE(Name, Class) \
case OMPC_##Name: \
return #Name;
#include "clang/Basic/OpenMPKinds.def"
case OMPC_uniform:
return "uniform";
case OMPC_threadprivate:
return "threadprivate or thread local";
case OMPC_device_type:
return "device_type";
case OMPC_match:
return "match";
}
llvm_unreachable("Invalid OpenMP clause kind");
}
unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
StringRef Str) { StringRef Str) {
switch (Kind) { switch (Kind) {

View File

@ -341,8 +341,7 @@ class CheckVarsEscapingDeclContext final
if (!Attr) if (!Attr)
return; return;
if (((Attr->getCaptureKind() != OMPC_map) && if (((Attr->getCaptureKind() != OMPC_map) &&
!isOpenMPPrivate( !isOpenMPPrivate(Attr->getCaptureKind())) ||
static_cast<OpenMPClauseKind>(Attr->getCaptureKind()))) ||
((Attr->getCaptureKind() == OMPC_map) && ((Attr->getCaptureKind() == OMPC_map) &&
!FD->getType()->isAnyPointerType())) !FD->getType()->isAnyPointerType()))
return; return;

View File

@ -1389,7 +1389,7 @@ bool Parser::parseOMPDeclareVariantMatchClause(SourceLocation Loc,
// Parse '('. // Parse '('.
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
if (T.expectAndConsume(diag::err_expected_lparen_after, if (T.expectAndConsume(diag::err_expected_lparen_after,
getOpenMPClauseName(OMPC_match))) { getOpenMPClauseName(OMPC_match).data())) {
while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch)) while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch))
; ;
// Skip the last annot_pragma_openmp_end. // Skip the last annot_pragma_openmp_end.
@ -1436,7 +1436,7 @@ parseOpenMPSimpleClause(Parser &P, OpenMPClauseKind Kind) {
// Parse '('. // Parse '('.
BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end);
if (T.expectAndConsume(diag::err_expected_lparen_after, if (T.expectAndConsume(diag::err_expected_lparen_after,
getOpenMPClauseName(Kind))) getOpenMPClauseName(Kind).data()))
return llvm::None; return llvm::None;
unsigned Type = getOpenMPSimpleClauseType( unsigned Type = getOpenMPSimpleClauseType(
@ -1675,18 +1675,18 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
SmallVector<OMPClause *, 1> Clauses; SmallVector<OMPClause *, 1> Clauses;
if (Tok.isNot(tok::annot_pragma_openmp_end)) { if (Tok.isNot(tok::annot_pragma_openmp_end)) {
SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
OMPC_unknown + 1> unsigned(OMPC_unknown) + 1>
FirstClauses(OMPC_unknown + 1); FirstClauses(unsigned(OMPC_unknown) + 1);
while (Tok.isNot(tok::annot_pragma_openmp_end)) { while (Tok.isNot(tok::annot_pragma_openmp_end)) {
OpenMPClauseKind CKind = OpenMPClauseKind CKind =
Tok.isAnnotation() ? OMPC_unknown Tok.isAnnotation() ? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok)); : getOpenMPClauseKind(PP.getSpelling(Tok));
Actions.StartOpenMPClause(CKind); Actions.StartOpenMPClause(CKind);
OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind, OMPClause *Clause = ParseOpenMPClause(
!FirstClauses[CKind].getInt()); OMPD_allocate, CKind, !FirstClauses[unsigned(CKind)].getInt());
SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
StopBeforeMatch); StopBeforeMatch);
FirstClauses[CKind].setInt(true); FirstClauses[unsigned(CKind)].setInt(true);
if (Clause != nullptr) if (Clause != nullptr)
Clauses.push_back(Clause); Clauses.push_back(Clause);
if (Tok.is(tok::annot_pragma_openmp_end)) { if (Tok.is(tok::annot_pragma_openmp_end)) {
@ -1710,8 +1710,9 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
case OMPD_requires: { case OMPD_requires: {
SourceLocation StartLoc = ConsumeToken(); SourceLocation StartLoc = ConsumeToken();
SmallVector<OMPClause *, 5> Clauses; SmallVector<OMPClause *, 5> Clauses;
SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
FirstClauses(OMPC_unknown + 1); unsigned(OMPC_unknown) + 1>
FirstClauses(unsigned(OMPC_unknown) + 1);
if (Tok.is(tok::annot_pragma_openmp_end)) { if (Tok.is(tok::annot_pragma_openmp_end)) {
Diag(Tok, diag::err_omp_expected_clause) Diag(Tok, diag::err_omp_expected_clause)
<< getOpenMPDirectiveName(OMPD_requires); << getOpenMPDirectiveName(OMPD_requires);
@ -1722,11 +1723,11 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
? OMPC_unknown ? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok)); : getOpenMPClauseKind(PP.getSpelling(Tok));
Actions.StartOpenMPClause(CKind); Actions.StartOpenMPClause(CKind);
OMPClause *Clause = ParseOpenMPClause(OMPD_requires, CKind, OMPClause *Clause = ParseOpenMPClause(
!FirstClauses[CKind].getInt()); OMPD_requires, CKind, !FirstClauses[unsigned(CKind)].getInt());
SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
StopBeforeMatch); StopBeforeMatch);
FirstClauses[CKind].setInt(true); FirstClauses[unsigned(CKind)].setInt(true);
if (Clause != nullptr) if (Clause != nullptr)
Clauses.push_back(Clause); Clauses.push_back(Clause);
if (Tok.is(tok::annot_pragma_openmp_end)) { if (Tok.is(tok::annot_pragma_openmp_end)) {
@ -2025,8 +2026,9 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) {
ParsingOpenMPDirectiveRAII DirScope(*this); ParsingOpenMPDirectiveRAII DirScope(*this);
ParenBraceBracketBalancer BalancerRAIIObj(*this); ParenBraceBracketBalancer BalancerRAIIObj(*this);
SmallVector<OMPClause *, 5> Clauses; SmallVector<OMPClause *, 5> Clauses;
SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
FirstClauses(OMPC_unknown + 1); unsigned(OMPC_unknown) + 1>
FirstClauses(unsigned(OMPC_unknown) + 1);
unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope | unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope |
Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope; Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope;
SourceLocation Loc = ConsumeAnnotationToken(), EndLoc; SourceLocation Loc = ConsumeAnnotationToken(), EndLoc;
@ -2071,18 +2073,18 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) {
SmallVector<OMPClause *, 1> Clauses; SmallVector<OMPClause *, 1> Clauses;
if (Tok.isNot(tok::annot_pragma_openmp_end)) { if (Tok.isNot(tok::annot_pragma_openmp_end)) {
SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>,
OMPC_unknown + 1> unsigned(OMPC_unknown) + 1>
FirstClauses(OMPC_unknown + 1); FirstClauses(unsigned(OMPC_unknown) + 1);
while (Tok.isNot(tok::annot_pragma_openmp_end)) { while (Tok.isNot(tok::annot_pragma_openmp_end)) {
OpenMPClauseKind CKind = OpenMPClauseKind CKind =
Tok.isAnnotation() ? OMPC_unknown Tok.isAnnotation() ? OMPC_unknown
: getOpenMPClauseKind(PP.getSpelling(Tok)); : getOpenMPClauseKind(PP.getSpelling(Tok));
Actions.StartOpenMPClause(CKind); Actions.StartOpenMPClause(CKind);
OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind, OMPClause *Clause = ParseOpenMPClause(
!FirstClauses[CKind].getInt()); OMPD_allocate, CKind, !FirstClauses[unsigned(CKind)].getInt());
SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end,
StopBeforeMatch); StopBeforeMatch);
FirstClauses[CKind].setInt(true); FirstClauses[unsigned(CKind)].setInt(true);
if (Clause != nullptr) if (Clause != nullptr)
Clauses.push_back(Clause); Clauses.push_back(Clause);
if (Tok.is(tok::annot_pragma_openmp_end)) { if (Tok.is(tok::annot_pragma_openmp_end)) {
@ -2250,11 +2252,11 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) {
ImplicitClauseAllowed = false; ImplicitClauseAllowed = false;
Actions.StartOpenMPClause(CKind); Actions.StartOpenMPClause(CKind);
HasImplicitClause = false; HasImplicitClause = false;
OMPClause *Clause = OMPClause *Clause = ParseOpenMPClause(
ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); DKind, CKind, !FirstClauses[unsigned(CKind)].getInt());
FirstClauses[CKind].setInt(true); FirstClauses[unsigned(CKind)].setInt(true);
if (Clause) { if (Clause) {
FirstClauses[CKind].setPointer(Clause); FirstClauses[unsigned(CKind)].setPointer(Clause);
Clauses.push_back(Clause); Clauses.push_back(Clause);
} }
@ -2271,7 +2273,7 @@ Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) {
// OpenMP [2.13.8, ordered Construct, Syntax] // OpenMP [2.13.8, ordered Construct, Syntax]
// If the depend clause is specified, the ordered construct is a stand-alone // If the depend clause is specified, the ordered construct is a stand-alone
// directive. // directive.
if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) { if (DKind == OMPD_ordered && FirstClauses[unsigned(OMPC_depend)].getInt()) {
if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) ==
ParsedStmtContext()) { ParsedStmtContext()) {
Diag(Loc, diag::err_omp_immediate_directive) Diag(Loc, diag::err_omp_immediate_directive)
@ -2756,7 +2758,7 @@ OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPDirectiveKind DKind,
// Parse '('. // Parse '('.
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
if (T.expectAndConsume(diag::err_expected_lparen_after, if (T.expectAndConsume(diag::err_expected_lparen_after,
getOpenMPClauseName(Kind))) getOpenMPClauseName(Kind).data()))
return nullptr; return nullptr;
ExprResult Val; ExprResult Val;
@ -3176,7 +3178,7 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
// Parse '('. // Parse '('.
BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
if (T.expectAndConsume(diag::err_expected_lparen_after, if (T.expectAndConsume(diag::err_expected_lparen_after,
getOpenMPClauseName(Kind))) getOpenMPClauseName(Kind).data()))
return true; return true;
bool DependWithIterator = false; bool DependWithIterator = false;

View File

@ -2233,7 +2233,7 @@ void Sema::setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D,
} }
} }
if (OMPC != OMPC_unknown) if (OMPC != OMPC_unknown)
FD->addAttr(OMPCaptureKindAttr::CreateImplicit(Context, OMPC)); FD->addAttr(OMPCaptureKindAttr::CreateImplicit(Context, unsigned(OMPC)));
} }
bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level,

View File

@ -730,10 +730,10 @@ public:
#define ABSTRACT_STMT(Stmt) #define ABSTRACT_STMT(Stmt)
#include "clang/AST/StmtNodes.inc" #include "clang/AST/StmtNodes.inc"
#define OPENMP_CLAUSE(Name, Class) \ #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
LLVM_ATTRIBUTE_NOINLINE \ LLVM_ATTRIBUTE_NOINLINE \
OMPClause *Transform ## Class(Class *S); OMPClause *Transform ## Class(Class *S);
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
/// Build a new qualified type given its unqualified type and type location. /// Build a new qualified type given its unqualified type and type location.
/// ///
@ -3597,10 +3597,10 @@ OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
switch (S->getClauseKind()) { switch (S->getClauseKind()) {
default: break; default: break;
// Transform individual clause nodes // Transform individual clause nodes
#define OPENMP_CLAUSE(Name, Class) \ #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
case OMPC_ ## Name : \ case Enum: \
return getDerived().Transform ## Class(cast<Class>(S)); return getDerived().Transform ## Class(cast<Class>(S));
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
} }
return S; return S;

View File

@ -11616,8 +11616,8 @@ public:
OMPClauseReader(ASTRecordReader &Record) OMPClauseReader(ASTRecordReader &Record)
: Record(Record), Context(Record.getContext()) {} : Record(Record), Context(Record.getContext()) {}
#define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *C); #define OMP_CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *C);
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
OMPClause *readClause(); OMPClause *readClause();
void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
@ -11631,149 +11631,149 @@ OMPClause *ASTRecordReader::readOMPClause() {
OMPClause *OMPClauseReader::readClause() { OMPClause *OMPClauseReader::readClause() {
OMPClause *C = nullptr; OMPClause *C = nullptr;
switch (Record.readInt()) { switch (llvm::omp::Clause(Record.readInt())) {
case OMPC_if: case llvm::omp::OMPC_if:
C = new (Context) OMPIfClause(); C = new (Context) OMPIfClause();
break; break;
case OMPC_final: case llvm::omp::OMPC_final:
C = new (Context) OMPFinalClause(); C = new (Context) OMPFinalClause();
break; break;
case OMPC_num_threads: case llvm::omp::OMPC_num_threads:
C = new (Context) OMPNumThreadsClause(); C = new (Context) OMPNumThreadsClause();
break; break;
case OMPC_safelen: case llvm::omp::OMPC_safelen:
C = new (Context) OMPSafelenClause(); C = new (Context) OMPSafelenClause();
break; break;
case OMPC_simdlen: case llvm::omp::OMPC_simdlen:
C = new (Context) OMPSimdlenClause(); C = new (Context) OMPSimdlenClause();
break; break;
case OMPC_allocator: case llvm::omp::OMPC_allocator:
C = new (Context) OMPAllocatorClause(); C = new (Context) OMPAllocatorClause();
break; break;
case OMPC_collapse: case llvm::omp::OMPC_collapse:
C = new (Context) OMPCollapseClause(); C = new (Context) OMPCollapseClause();
break; break;
case OMPC_default: case llvm::omp::OMPC_default:
C = new (Context) OMPDefaultClause(); C = new (Context) OMPDefaultClause();
break; break;
case OMPC_proc_bind: case llvm::omp::OMPC_proc_bind:
C = new (Context) OMPProcBindClause(); C = new (Context) OMPProcBindClause();
break; break;
case OMPC_schedule: case llvm::omp::OMPC_schedule:
C = new (Context) OMPScheduleClause(); C = new (Context) OMPScheduleClause();
break; break;
case OMPC_ordered: case llvm::omp::OMPC_ordered:
C = OMPOrderedClause::CreateEmpty(Context, Record.readInt()); C = OMPOrderedClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_nowait: case llvm::omp::OMPC_nowait:
C = new (Context) OMPNowaitClause(); C = new (Context) OMPNowaitClause();
break; break;
case OMPC_untied: case llvm::omp::OMPC_untied:
C = new (Context) OMPUntiedClause(); C = new (Context) OMPUntiedClause();
break; break;
case OMPC_mergeable: case llvm::omp::OMPC_mergeable:
C = new (Context) OMPMergeableClause(); C = new (Context) OMPMergeableClause();
break; break;
case OMPC_read: case llvm::omp::OMPC_read:
C = new (Context) OMPReadClause(); C = new (Context) OMPReadClause();
break; break;
case OMPC_write: case llvm::omp::OMPC_write:
C = new (Context) OMPWriteClause(); C = new (Context) OMPWriteClause();
break; break;
case OMPC_update: case llvm::omp::OMPC_update:
C = OMPUpdateClause::CreateEmpty(Context, Record.readInt()); C = OMPUpdateClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_capture: case llvm::omp::OMPC_capture:
C = new (Context) OMPCaptureClause(); C = new (Context) OMPCaptureClause();
break; break;
case OMPC_seq_cst: case llvm::omp::OMPC_seq_cst:
C = new (Context) OMPSeqCstClause(); C = new (Context) OMPSeqCstClause();
break; break;
case OMPC_acq_rel: case llvm::omp::OMPC_acq_rel:
C = new (Context) OMPAcqRelClause(); C = new (Context) OMPAcqRelClause();
break; break;
case OMPC_acquire: case llvm::omp::OMPC_acquire:
C = new (Context) OMPAcquireClause(); C = new (Context) OMPAcquireClause();
break; break;
case OMPC_release: case llvm::omp::OMPC_release:
C = new (Context) OMPReleaseClause(); C = new (Context) OMPReleaseClause();
break; break;
case OMPC_relaxed: case llvm::omp::OMPC_relaxed:
C = new (Context) OMPRelaxedClause(); C = new (Context) OMPRelaxedClause();
break; break;
case OMPC_threads: case llvm::omp::OMPC_threads:
C = new (Context) OMPThreadsClause(); C = new (Context) OMPThreadsClause();
break; break;
case OMPC_simd: case llvm::omp::OMPC_simd:
C = new (Context) OMPSIMDClause(); C = new (Context) OMPSIMDClause();
break; break;
case OMPC_nogroup: case llvm::omp::OMPC_nogroup:
C = new (Context) OMPNogroupClause(); C = new (Context) OMPNogroupClause();
break; break;
case OMPC_unified_address: case llvm::omp::OMPC_unified_address:
C = new (Context) OMPUnifiedAddressClause(); C = new (Context) OMPUnifiedAddressClause();
break; break;
case OMPC_unified_shared_memory: case llvm::omp::OMPC_unified_shared_memory:
C = new (Context) OMPUnifiedSharedMemoryClause(); C = new (Context) OMPUnifiedSharedMemoryClause();
break; break;
case OMPC_reverse_offload: case llvm::omp::OMPC_reverse_offload:
C = new (Context) OMPReverseOffloadClause(); C = new (Context) OMPReverseOffloadClause();
break; break;
case OMPC_dynamic_allocators: case llvm::omp::OMPC_dynamic_allocators:
C = new (Context) OMPDynamicAllocatorsClause(); C = new (Context) OMPDynamicAllocatorsClause();
break; break;
case OMPC_atomic_default_mem_order: case llvm::omp::OMPC_atomic_default_mem_order:
C = new (Context) OMPAtomicDefaultMemOrderClause(); C = new (Context) OMPAtomicDefaultMemOrderClause();
break; break;
case OMPC_private: case llvm::omp::OMPC_private:
C = OMPPrivateClause::CreateEmpty(Context, Record.readInt()); C = OMPPrivateClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_firstprivate: case llvm::omp::OMPC_firstprivate:
C = OMPFirstprivateClause::CreateEmpty(Context, Record.readInt()); C = OMPFirstprivateClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_lastprivate: case llvm::omp::OMPC_lastprivate:
C = OMPLastprivateClause::CreateEmpty(Context, Record.readInt()); C = OMPLastprivateClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_shared: case llvm::omp::OMPC_shared:
C = OMPSharedClause::CreateEmpty(Context, Record.readInt()); C = OMPSharedClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_reduction: case llvm::omp::OMPC_reduction:
C = OMPReductionClause::CreateEmpty(Context, Record.readInt()); C = OMPReductionClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_task_reduction: case llvm::omp::OMPC_task_reduction:
C = OMPTaskReductionClause::CreateEmpty(Context, Record.readInt()); C = OMPTaskReductionClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_in_reduction: case llvm::omp::OMPC_in_reduction:
C = OMPInReductionClause::CreateEmpty(Context, Record.readInt()); C = OMPInReductionClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_linear: case llvm::omp::OMPC_linear:
C = OMPLinearClause::CreateEmpty(Context, Record.readInt()); C = OMPLinearClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_aligned: case llvm::omp::OMPC_aligned:
C = OMPAlignedClause::CreateEmpty(Context, Record.readInt()); C = OMPAlignedClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_copyin: case llvm::omp::OMPC_copyin:
C = OMPCopyinClause::CreateEmpty(Context, Record.readInt()); C = OMPCopyinClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_copyprivate: case llvm::omp::OMPC_copyprivate:
C = OMPCopyprivateClause::CreateEmpty(Context, Record.readInt()); C = OMPCopyprivateClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_flush: case llvm::omp::OMPC_flush:
C = OMPFlushClause::CreateEmpty(Context, Record.readInt()); C = OMPFlushClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_depobj: case llvm::omp::OMPC_depobj:
C = OMPDepobjClause::CreateEmpty(Context); C = OMPDepobjClause::CreateEmpty(Context);
break; break;
case OMPC_depend: { case llvm::omp::OMPC_depend: {
unsigned NumVars = Record.readInt(); unsigned NumVars = Record.readInt();
unsigned NumLoops = Record.readInt(); unsigned NumLoops = Record.readInt();
C = OMPDependClause::CreateEmpty(Context, NumVars, NumLoops); C = OMPDependClause::CreateEmpty(Context, NumVars, NumLoops);
break; break;
} }
case OMPC_device: case llvm::omp::OMPC_device:
C = new (Context) OMPDeviceClause(); C = new (Context) OMPDeviceClause();
break; break;
case OMPC_map: { case llvm::omp::OMPC_map: {
OMPMappableExprListSizeTy Sizes; OMPMappableExprListSizeTy Sizes;
Sizes.NumVars = Record.readInt(); Sizes.NumVars = Record.readInt();
Sizes.NumUniqueDeclarations = Record.readInt(); Sizes.NumUniqueDeclarations = Record.readInt();
@ -11782,31 +11782,31 @@ OMPClause *OMPClauseReader::readClause() {
C = OMPMapClause::CreateEmpty(Context, Sizes); C = OMPMapClause::CreateEmpty(Context, Sizes);
break; break;
} }
case OMPC_num_teams: case llvm::omp::OMPC_num_teams:
C = new (Context) OMPNumTeamsClause(); C = new (Context) OMPNumTeamsClause();
break; break;
case OMPC_thread_limit: case llvm::omp::OMPC_thread_limit:
C = new (Context) OMPThreadLimitClause(); C = new (Context) OMPThreadLimitClause();
break; break;
case OMPC_priority: case llvm::omp::OMPC_priority:
C = new (Context) OMPPriorityClause(); C = new (Context) OMPPriorityClause();
break; break;
case OMPC_grainsize: case llvm::omp::OMPC_grainsize:
C = new (Context) OMPGrainsizeClause(); C = new (Context) OMPGrainsizeClause();
break; break;
case OMPC_num_tasks: case llvm::omp::OMPC_num_tasks:
C = new (Context) OMPNumTasksClause(); C = new (Context) OMPNumTasksClause();
break; break;
case OMPC_hint: case llvm::omp::OMPC_hint:
C = new (Context) OMPHintClause(); C = new (Context) OMPHintClause();
break; break;
case OMPC_dist_schedule: case llvm::omp::OMPC_dist_schedule:
C = new (Context) OMPDistScheduleClause(); C = new (Context) OMPDistScheduleClause();
break; break;
case OMPC_defaultmap: case llvm::omp::OMPC_defaultmap:
C = new (Context) OMPDefaultmapClause(); C = new (Context) OMPDefaultmapClause();
break; break;
case OMPC_to: { case llvm::omp::OMPC_to: {
OMPMappableExprListSizeTy Sizes; OMPMappableExprListSizeTy Sizes;
Sizes.NumVars = Record.readInt(); Sizes.NumVars = Record.readInt();
Sizes.NumUniqueDeclarations = Record.readInt(); Sizes.NumUniqueDeclarations = Record.readInt();
@ -11815,7 +11815,7 @@ OMPClause *OMPClauseReader::readClause() {
C = OMPToClause::CreateEmpty(Context, Sizes); C = OMPToClause::CreateEmpty(Context, Sizes);
break; break;
} }
case OMPC_from: { case llvm::omp::OMPC_from: {
OMPMappableExprListSizeTy Sizes; OMPMappableExprListSizeTy Sizes;
Sizes.NumVars = Record.readInt(); Sizes.NumVars = Record.readInt();
Sizes.NumUniqueDeclarations = Record.readInt(); Sizes.NumUniqueDeclarations = Record.readInt();
@ -11824,7 +11824,7 @@ OMPClause *OMPClauseReader::readClause() {
C = OMPFromClause::CreateEmpty(Context, Sizes); C = OMPFromClause::CreateEmpty(Context, Sizes);
break; break;
} }
case OMPC_use_device_ptr: { case llvm::omp::OMPC_use_device_ptr: {
OMPMappableExprListSizeTy Sizes; OMPMappableExprListSizeTy Sizes;
Sizes.NumVars = Record.readInt(); Sizes.NumVars = Record.readInt();
Sizes.NumUniqueDeclarations = Record.readInt(); Sizes.NumUniqueDeclarations = Record.readInt();
@ -11833,7 +11833,7 @@ OMPClause *OMPClauseReader::readClause() {
C = OMPUseDevicePtrClause::CreateEmpty(Context, Sizes); C = OMPUseDevicePtrClause::CreateEmpty(Context, Sizes);
break; break;
} }
case OMPC_is_device_ptr: { case llvm::omp::OMPC_is_device_ptr: {
OMPMappableExprListSizeTy Sizes; OMPMappableExprListSizeTy Sizes;
Sizes.NumVars = Record.readInt(); Sizes.NumVars = Record.readInt();
Sizes.NumUniqueDeclarations = Record.readInt(); Sizes.NumUniqueDeclarations = Record.readInt();
@ -11842,27 +11842,31 @@ OMPClause *OMPClauseReader::readClause() {
C = OMPIsDevicePtrClause::CreateEmpty(Context, Sizes); C = OMPIsDevicePtrClause::CreateEmpty(Context, Sizes);
break; break;
} }
case OMPC_allocate: case llvm::omp::OMPC_allocate:
C = OMPAllocateClause::CreateEmpty(Context, Record.readInt()); C = OMPAllocateClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_nontemporal: case llvm::omp::OMPC_nontemporal:
C = OMPNontemporalClause::CreateEmpty(Context, Record.readInt()); C = OMPNontemporalClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_inclusive: case llvm::omp::OMPC_inclusive:
C = OMPInclusiveClause::CreateEmpty(Context, Record.readInt()); C = OMPInclusiveClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_exclusive: case llvm::omp::OMPC_exclusive:
C = OMPExclusiveClause::CreateEmpty(Context, Record.readInt()); C = OMPExclusiveClause::CreateEmpty(Context, Record.readInt());
break; break;
case OMPC_order: case llvm::omp::OMPC_order:
C = new (Context) OMPOrderClause(); C = new (Context) OMPOrderClause();
break; break;
case OMPC_destroy: case llvm::omp::OMPC_destroy:
C = new (Context) OMPDestroyClause(); C = new (Context) OMPDestroyClause();
break; break;
case OMPC_detach: case llvm::omp::OMPC_detach:
C = new (Context) OMPDetachClause(); C = new (Context) OMPDetachClause();
break; break;
#define OMP_CLAUSE_NO_CLASS(Enum, Str) \
case llvm::omp::Enum: \
break;
#include "llvm/Frontend/OpenMP/OMPKinds.def"
} }
assert(C && "Unknown OMPClause type"); assert(C && "Unknown OMPClause type");

View File

@ -6037,8 +6037,8 @@ class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> {
public: public:
OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {} OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {}
#define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *S); #define OMP_CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
void writeClause(OMPClause *C); void writeClause(OMPClause *C);
void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
@ -6051,7 +6051,7 @@ void ASTRecordWriter::writeOMPClause(OMPClause *C) {
} }
void OMPClauseWriter::writeClause(OMPClause *C) { void OMPClauseWriter::writeClause(OMPClause *C) {
Record.push_back(C->getClauseKind()); Record.push_back(unsigned(C->getClauseKind()));
Visit(C); Visit(C);
Record.AddSourceLocation(C->getBeginLoc()); Record.AddSourceLocation(C->getBeginLoc());
Record.AddSourceLocation(C->getEndLoc()); Record.AddSourceLocation(C->getEndLoc());

View File

@ -1,4 +1,5 @@
set(LLVM_LINK_COMPONENTS set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support Support
) )

View File

@ -1,4 +1,7 @@
set(LLVM_LINK_COMPONENTS support) set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)
add_clang_library(clangStaticAnalyzerCore add_clang_library(clangStaticAnalyzerCore
APSIntType.cpp APSIntType.cpp

View File

@ -2153,8 +2153,8 @@ class OMPClauseEnqueue : public ConstOMPClauseVisitor<OMPClauseEnqueue> {
public: public:
OMPClauseEnqueue(EnqueueVisitor *Visitor) : Visitor(Visitor) {} OMPClauseEnqueue(EnqueueVisitor *Visitor) : Visitor(Visitor) {}
#define OPENMP_CLAUSE(Name, Class) void Visit##Class(const Class *C); #define OMP_CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C);
#include "clang/Basic/OpenMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
void VisitOMPClauseWithPreInit(const OMPClauseWithPreInit *C); void VisitOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
void VisitOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C); void VisitOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
}; };

View File

@ -2612,7 +2612,7 @@ TEST(HasExternalFormalLinkage, Basic) {
} }
TEST(HasDefaultArgument, Basic) { TEST(HasDefaultArgument, Basic) {
EXPECT_TRUE(matches("void x(int val = 0) {}", EXPECT_TRUE(matches("void x(int val = 0) {}",
parmVarDecl(hasDefaultArgument()))); parmVarDecl(hasDefaultArgument())));
EXPECT_TRUE(notMatches("void x(int val) {}", EXPECT_TRUE(notMatches("void x(int val) {}",
parmVarDecl(hasDefaultArgument()))); parmVarDecl(hasDefaultArgument())));
@ -2665,7 +2665,7 @@ TEST(HasTrailingReturn, MatchesTrailingReturn) {
EXPECT_TRUE(matches("auto Y() -> int { return 0; }", EXPECT_TRUE(matches("auto Y() -> int { return 0; }",
functionDecl(hasTrailingReturn()))); functionDecl(hasTrailingReturn())));
EXPECT_TRUE(matches("auto X() -> int;", functionDecl(hasTrailingReturn()))); EXPECT_TRUE(matches("auto X() -> int;", functionDecl(hasTrailingReturn())));
EXPECT_TRUE(notMatches("int X() { return 0; }", EXPECT_TRUE(notMatches("int X() { return 0; }",
functionDecl(hasTrailingReturn()))); functionDecl(hasTrailingReturn())));
EXPECT_TRUE(notMatches("int X();", functionDecl(hasTrailingReturn()))); EXPECT_TRUE(notMatches("int X();", functionDecl(hasTrailingReturn())));
EXPECT_TRUE(notMatchesC("void X();", functionDecl(hasTrailingReturn()))); EXPECT_TRUE(notMatchesC("void X();", functionDecl(hasTrailingReturn())));
@ -2891,8 +2891,8 @@ void x(int x) {
} }
TEST(OMPExecutableDirective, isAllowedToContainClauseKind) { TEST(OMPExecutableDirective, isAllowedToContainClauseKind) {
auto Matcher = auto Matcher = ompExecutableDirective(
ompExecutableDirective(isAllowedToContainClauseKind(OMPC_default)); isAllowedToContainClauseKind(llvm::omp::OMPC_default));
const std::string Source0 = R"( const std::string Source0 = R"(
void x() { void x() {

View File

@ -34,11 +34,18 @@ enum class Directive {
#include "llvm/Frontend/OpenMP/OMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
}; };
/// IDs for all OpenMP clauses.
enum class Clause {
#define OMP_CLAUSE(Enum, ...) Enum,
#include "llvm/Frontend/OpenMP/OMPKinds.def"
};
/// Make the enum values available in the llvm::omp namespace. This allows us to /// Make the enum values available in the llvm::omp namespace. This allows us to
/// write something like OMPD_parallel if we have a `using namespace omp`. At /// write something like OMPD_parallel if we have a `using namespace omp`. At
/// the same time we do not loose the strong type guarantees of the enum class, /// 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. /// that is we cannot pass an unsigned as Directive without an explicit cast.
#define OMP_DIRECTIVE(Enum, ...) constexpr auto Enum = omp::Directive::Enum; #define OMP_DIRECTIVE(Enum, ...) constexpr auto Enum = omp::Directive::Enum;
#define OMP_CLAUSE(Enum, ...) constexpr auto Enum = omp::Clause::Enum;
#include "llvm/Frontend/OpenMP/OMPKinds.def" #include "llvm/Frontend/OpenMP/OMPKinds.def"
/// IDs for all omp runtime library (RTL) functions. /// IDs for all omp runtime library (RTL) functions.
@ -87,6 +94,12 @@ Directive getOpenMPDirectiveKind(StringRef Str);
/// Return a textual representation of the directive \p D. /// Return a textual representation of the directive \p D.
StringRef getOpenMPDirectiveName(Directive D); StringRef getOpenMPDirectiveName(Directive D);
/// Parse \p Str and return the clause it matches or OMPC_unknown if none.
Clause getOpenMPClauseKind(StringRef Str);
/// Return a textual representation of the clause \p C.
StringRef getOpenMPClauseName(Clause C);
/// Forward declarations for LLVM-IR types (simple, function and structure) are /// Forward declarations for LLVM-IR types (simple, function and structure) are
/// generated below. Their names are defined and used in OpenMP/OMPKinds.def. /// generated below. Their names are defined and used in OpenMP/OMPKinds.def.
/// Here we provide the forward declarations, the initializeTypes function will /// Here we provide the forward declarations, the initializeTypes function will

View File

@ -105,6 +105,117 @@ __OMP_DIRECTIVE(unknown)
///} ///}
/// OpenMP Clauses
///
///{
#ifndef OMP_CLAUSE
#define OMP_CLAUSE(Enum, Str, Implicit)
#endif
#ifndef OMP_CLAUSE_CLASS
#define OMP_CLAUSE_CLASS(Enum, Str, Class)
#endif
#ifndef OMP_CLAUSE_NO_CLASS
#define OMP_CLAUSE_NO_CLASS(Enum, Str)
#endif
#define __OMP_CLAUSE(Name, Class) \
OMP_CLAUSE(OMPC_##Name, #Name, /* Implicit */ false) \
OMP_CLAUSE_CLASS(OMPC_##Name, #Name, Class)
#define __OMP_CLAUSE_NO_CLASS(Name) \
OMP_CLAUSE(OMPC_##Name, #Name, /* Implicit */ false) \
OMP_CLAUSE_NO_CLASS(OMPC_##Name, #Name)
#define __OMP_IMPLICIT_CLAUSE_CLASS(Name, Str, Class) \
OMP_CLAUSE(OMPC_##Name, Str, /* Implicit */ true) \
OMP_CLAUSE_CLASS(OMPC_##Name, Str, Class)
#define __OMP_IMPLICIT_CLAUSE_NO_CLASS(Name, Str) \
OMP_CLAUSE(OMPC_##Name, Str, /* Implicit */ true) \
OMP_CLAUSE_NO_CLASS(OMPC_##Name, Str)
__OMP_CLAUSE(allocator, OMPAllocatorClause)
__OMP_CLAUSE(if, OMPIfClause)
__OMP_CLAUSE(final, OMPFinalClause)
__OMP_CLAUSE(num_threads, OMPNumThreadsClause)
__OMP_CLAUSE(safelen, OMPSafelenClause)
__OMP_CLAUSE(simdlen, OMPSimdlenClause)
__OMP_CLAUSE(collapse, OMPCollapseClause)
__OMP_CLAUSE(default, OMPDefaultClause)
__OMP_CLAUSE(private, OMPPrivateClause)
__OMP_CLAUSE(firstprivate, OMPFirstprivateClause)
__OMP_CLAUSE(lastprivate, OMPLastprivateClause)
__OMP_CLAUSE(shared, OMPSharedClause)
__OMP_CLAUSE(reduction, OMPReductionClause)
__OMP_CLAUSE(linear, OMPLinearClause)
__OMP_CLAUSE(aligned, OMPAlignedClause)
__OMP_CLAUSE(copyin, OMPCopyinClause)
__OMP_CLAUSE(copyprivate, OMPCopyprivateClause)
__OMP_CLAUSE(proc_bind, OMPProcBindClause)
__OMP_CLAUSE(schedule, OMPScheduleClause)
__OMP_CLAUSE(ordered, OMPOrderedClause)
__OMP_CLAUSE(nowait, OMPNowaitClause)
__OMP_CLAUSE(untied, OMPUntiedClause)
__OMP_CLAUSE(mergeable, OMPMergeableClause)
__OMP_CLAUSE(read, OMPReadClause)
__OMP_CLAUSE(write, OMPWriteClause)
__OMP_CLAUSE(update, OMPUpdateClause)
__OMP_CLAUSE(capture, OMPCaptureClause)
__OMP_CLAUSE(seq_cst, OMPSeqCstClause)
__OMP_CLAUSE(acq_rel, OMPAcqRelClause)
__OMP_CLAUSE(acquire, OMPAcquireClause)
__OMP_CLAUSE(release, OMPReleaseClause)
__OMP_CLAUSE(relaxed, OMPRelaxedClause)
__OMP_CLAUSE(depend, OMPDependClause)
__OMP_CLAUSE(device, OMPDeviceClause)
__OMP_CLAUSE(threads, OMPThreadsClause)
__OMP_CLAUSE(simd, OMPSIMDClause)
__OMP_CLAUSE(map, OMPMapClause)
__OMP_CLAUSE(num_teams, OMPNumTeamsClause)
__OMP_CLAUSE(thread_limit, OMPThreadLimitClause)
__OMP_CLAUSE(priority, OMPPriorityClause)
__OMP_CLAUSE(grainsize, OMPGrainsizeClause)
__OMP_CLAUSE(nogroup, OMPNogroupClause)
__OMP_CLAUSE(num_tasks, OMPNumTasksClause)
__OMP_CLAUSE(hint, OMPHintClause)
__OMP_CLAUSE(dist_schedule, OMPDistScheduleClause)
__OMP_CLAUSE(defaultmap, OMPDefaultmapClause)
__OMP_CLAUSE(to, OMPToClause)
__OMP_CLAUSE(from, OMPFromClause)
__OMP_CLAUSE(use_device_ptr, OMPUseDevicePtrClause)
__OMP_CLAUSE(is_device_ptr, OMPIsDevicePtrClause)
__OMP_CLAUSE(task_reduction, OMPTaskReductionClause)
__OMP_CLAUSE(in_reduction, OMPInReductionClause)
__OMP_CLAUSE(unified_address, OMPUnifiedAddressClause)
__OMP_CLAUSE(unified_shared_memory, OMPUnifiedSharedMemoryClause)
__OMP_CLAUSE(reverse_offload, OMPReverseOffloadClause)
__OMP_CLAUSE(dynamic_allocators, OMPDynamicAllocatorsClause)
__OMP_CLAUSE(atomic_default_mem_order, OMPAtomicDefaultMemOrderClause)
__OMP_CLAUSE(allocate, OMPAllocateClause)
__OMP_CLAUSE(nontemporal, OMPNontemporalClause)
__OMP_CLAUSE(order, OMPOrderClause)
__OMP_CLAUSE(destroy, OMPDestroyClause)
__OMP_CLAUSE(detach, OMPDetachClause)
__OMP_CLAUSE(inclusive, OMPInclusiveClause)
__OMP_CLAUSE(exclusive, OMPExclusiveClause)
__OMP_CLAUSE_NO_CLASS(uniform)
__OMP_CLAUSE_NO_CLASS(device_type)
__OMP_CLAUSE_NO_CLASS(match)
__OMP_IMPLICIT_CLAUSE_CLASS(depobj, "depobj", OMPDepobjClause)
__OMP_IMPLICIT_CLAUSE_CLASS(flush, "flush", OMPFlushClause)
__OMP_IMPLICIT_CLAUSE_NO_CLASS(threadprivate, "threadprivate or thread local")
__OMP_IMPLICIT_CLAUSE_NO_CLASS(unknown, "unknown")
#undef __OMP_IMPLICIT_CLAUSE_NO_CLASS
#undef __OMP_IMPLICIT_CLAUSE_CLASS
#undef __OMP_CLAUSE
#undef OMP_CLAUSE_NO_CLASS
#undef OMP_CLAUSE_CLASS
#undef OMP_CLAUSE
///}
/// Types used in runtime structs or runtime functions /// Types used in runtime structs or runtime functions
/// ///
///{ ///{
@ -232,8 +343,10 @@ __OMP_RTL(omp_set_max_active_levels, false, Void, Int32)
__OMP_RTL(__kmpc_master, false, Int32, IdentPtr, Int32) __OMP_RTL(__kmpc_master, false, Int32, IdentPtr, Int32)
__OMP_RTL(__kmpc_end_master, false, Void, IdentPtr, Int32) __OMP_RTL(__kmpc_end_master, false, Void, IdentPtr, Int32)
__OMP_RTL(__kmpc_critical, false, Void, IdentPtr, Int32, KmpCriticalNamePtrTy) __OMP_RTL(__kmpc_critical, false, Void, IdentPtr, Int32, KmpCriticalNamePtrTy)
__OMP_RTL(__kmpc_critical_with_hint, false, Void, IdentPtr, Int32, KmpCriticalNamePtrTy, Int32) __OMP_RTL(__kmpc_critical_with_hint, false, Void, IdentPtr, Int32,
__OMP_RTL(__kmpc_end_critical, false, Void, IdentPtr, Int32, KmpCriticalNamePtrTy) KmpCriticalNamePtrTy, Int32)
__OMP_RTL(__kmpc_end_critical, false, Void, IdentPtr, Int32,
KmpCriticalNamePtrTy)
__OMP_RTL(__last, false, Void, ) __OMP_RTL(__last, false, Void, )

View File

@ -36,6 +36,24 @@ StringRef llvm::omp::getOpenMPDirectiveName(Directive Kind) {
llvm_unreachable("Invalid OpenMP directive kind"); llvm_unreachable("Invalid OpenMP directive kind");
} }
Clause llvm::omp::getOpenMPClauseKind(StringRef Str) {
return llvm::StringSwitch<Clause>(Str)
#define OMP_CLAUSE(Enum, Str, Implicit) \
.Case(Str, Implicit ? OMPC_unknown : Enum)
#include "llvm/Frontend/OpenMP/OMPKinds.def"
.Default(OMPC_unknown);
}
StringRef llvm::omp::getOpenMPClauseName(Clause C) {
switch (C) {
#define OMP_CLAUSE(Enum, Str, ...) \
case Enum: \
return Str;
#include "llvm/Frontend/OpenMP/OMPKinds.def"
}
llvm_unreachable("Invalid OpenMP clause kind");
}
/// Declarations for LLVM-IR types (simple, array, function and structure) are /// Declarations for LLVM-IR types (simple, array, function and structure) are
/// generated below. Their names are defined and used in OpenMPKinds.def. Here /// generated below. Their names are defined and used in OpenMPKinds.def. Here
/// we provide the declarations, the initializeTypes function will provide the /// we provide the declarations, the initializeTypes function will provide the