Skip to content

Commit 25ed0c0

Browse files
committed
[OPENMP 5.0]Add initial support for 'allocate' directive.
Added parsing/sema analysis/serialization/deserialization support for 'allocate' directive. llvm-svn: 355614
1 parent 6ca0985 commit 25ed0c0

37 files changed

+644
-33
lines changed

clang/include/clang/AST/ASTMutationListener.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ class ASTMutationListener {
127127
virtual void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
128128
const Attr *Attr) {}
129129

130+
/// A declaration is marked as a variable with OpenMP allocator.
131+
///
132+
/// \param D the declaration marked as a variable with OpenMP allocator.
133+
virtual void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) {}
134+
130135
/// A definition has been made visible by being redefined locally.
131136
///
132137
/// \param D The definition that was previously not visible.

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ class ASTNodeTraverser
393393
Visit(D->getInit());
394394
}
395395

396+
void VisitOMPAllocateDecl(const OMPAllocateDecl *D) {
397+
for (const auto *E : D->varlists())
398+
Visit(E);
399+
}
400+
396401
template <typename SpecializationDecl>
397402
void dumpTemplateDeclSpecialization(const SpecializationDecl *D) {
398403
for (const auto *RedeclWithBadType : D->redecls()) {

clang/include/clang/AST/DeclOpenMP.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,73 @@ class OMPRequiresDecl final
405405
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
406406
static bool classofKind(Kind K) { return K == OMPRequires; }
407407
};
408+
409+
/// This represents '#pragma omp allocate ...' directive.
410+
/// For example, in the following, the default allocator is used for both 'a'
411+
/// and 'A::b':
412+
///
413+
/// \code
414+
/// int a;
415+
/// #pragma omp allocate(a)
416+
/// struct A {
417+
/// static int b;
418+
/// #pragma omp allocate(b)
419+
/// };
420+
/// \endcode
421+
///
422+
class OMPAllocateDecl final
423+
: public Decl,
424+
private llvm::TrailingObjects<OMPAllocateDecl, Expr *> {
425+
friend class ASTDeclReader;
426+
friend TrailingObjects;
427+
428+
/// Number of variable within the allocate directive.
429+
unsigned NumVars = 0;
430+
431+
virtual void anchor();
432+
433+
OMPAllocateDecl(Kind DK, DeclContext *DC, SourceLocation L)
434+
: Decl(DK, DC, L) {}
435+
436+
ArrayRef<const Expr *> getVars() const {
437+
return llvm::makeArrayRef(getTrailingObjects<Expr *>(), NumVars);
438+
}
439+
440+
MutableArrayRef<Expr *> getVars() {
441+
return MutableArrayRef<Expr *>(getTrailingObjects<Expr *>(), NumVars);
442+
}
443+
444+
void setVars(ArrayRef<Expr *> VL);
445+
446+
public:
447+
static OMPAllocateDecl *Create(ASTContext &C, DeclContext *DC,
448+
SourceLocation L, ArrayRef<Expr *> VL);
449+
static OMPAllocateDecl *CreateDeserialized(ASTContext &C, unsigned ID,
450+
unsigned N);
451+
452+
typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
453+
typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
454+
typedef llvm::iterator_range<varlist_iterator> varlist_range;
455+
typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
456+
457+
unsigned varlist_size() const { return NumVars; }
458+
bool varlist_empty() const { return NumVars == 0; }
459+
460+
varlist_range varlists() {
461+
return varlist_range(varlist_begin(), varlist_end());
462+
}
463+
varlist_const_range varlists() const {
464+
return varlist_const_range(varlist_begin(), varlist_end());
465+
}
466+
varlist_iterator varlist_begin() { return getVars().begin(); }
467+
varlist_iterator varlist_end() { return getVars().end(); }
468+
varlist_const_iterator varlist_begin() const { return getVars().begin(); }
469+
varlist_const_iterator varlist_end() const { return getVars().end(); }
470+
471+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
472+
static bool classofKind(Kind K) { return K == OMPAllocate; }
473+
};
474+
408475
} // end namespace clang
409476

410477
#endif

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,12 @@ DEF_TRAVERSE_DECL(OMPDeclareMapperDecl, {
16131613

16141614
DEF_TRAVERSE_DECL(OMPCapturedExprDecl, { TRY_TO(TraverseVarHelper(D)); })
16151615

1616+
DEF_TRAVERSE_DECL(OMPAllocateDecl, {
1617+
for (auto *I : D->varlists()) {
1618+
TRY_TO(TraverseStmt(I));
1619+
}
1620+
})
1621+
16161622
// A helper method for TemplateDecl's children.
16171623
template <typename Derived>
16181624
bool RecursiveASTVisitor<Derived>::TraverseTemplateParameterListHelper(
@@ -2797,6 +2803,7 @@ bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
27972803
break;
27982804
#include "clang/Basic/OpenMPKinds.def"
27992805
case OMPC_threadprivate:
2806+
case OMPC_allocate:
28002807
case OMPC_uniform:
28012808
case OMPC_unknown:
28022809
break;

clang/include/clang/Basic/Attr.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,6 +3152,13 @@ def OMPDeclareTargetDecl : InheritableAttr {
31523152
}];
31533153
}
31543154

3155+
def OMPAllocateDecl : InheritableAttr {
3156+
// This attribute has no spellings as it is only ever created implicitly.
3157+
let Spellings = [];
3158+
let SemaHandler = 0;
3159+
let Documentation = [Undocumented];
3160+
}
3161+
31553162
def InternalLinkage : InheritableAttr {
31563163
let Spellings = [Clang<"internal_linkage">];
31573164
let Subjects = SubjectList<[Var, Function, CXXRecord]>;

clang/include/clang/Basic/DeclNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def Captured : Decl, DeclContext;
9898
def ClassScopeFunctionSpecialization : Decl;
9999
def Import : Decl;
100100
def OMPThreadPrivate : Decl;
101+
def OMPAllocate : Decl;
101102
def OMPRequires : Decl;
102103
def Empty : Decl;
103104

clang/include/clang/Basic/OpenMPKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ OPENMP_DIRECTIVE_EXT(target_teams_distribute, "target teams distribute")
244244
OPENMP_DIRECTIVE_EXT(target_teams_distribute_parallel_for, "target teams distribute parallel for")
245245
OPENMP_DIRECTIVE_EXT(target_teams_distribute_parallel_for_simd, "target teams distribute parallel for simd")
246246
OPENMP_DIRECTIVE_EXT(target_teams_distribute_simd, "target teams distribute simd")
247+
OPENMP_DIRECTIVE(allocate)
247248

248249
// OpenMP clauses.
249250
OPENMP_CLAUSE(if, OMPIfClause)

clang/include/clang/Basic/OpenMPKinds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum OpenMPClauseKind {
3535
#include "clang/Basic/OpenMPKinds.def"
3636
OMPC_threadprivate,
3737
OMPC_uniform,
38+
OMPC_allocate,
3839
OMPC_unknown
3940
};
4041

clang/include/clang/Sema/Sema.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8879,16 +8879,20 @@ class Sema {
88798879
// OpenMP directives and clauses.
88808880
/// Called on correct id-expression from the '#pragma omp
88818881
/// threadprivate'.
8882-
ExprResult ActOnOpenMPIdExpression(Scope *CurScope,
8883-
CXXScopeSpec &ScopeSpec,
8884-
const DeclarationNameInfo &Id);
8882+
ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec,
8883+
const DeclarationNameInfo &Id,
8884+
OpenMPDirectiveKind Kind);
88858885
/// Called on well-formed '#pragma omp threadprivate'.
88868886
DeclGroupPtrTy ActOnOpenMPThreadprivateDirective(
88878887
SourceLocation Loc,
88888888
ArrayRef<Expr *> VarList);
88898889
/// Builds a new OpenMPThreadPrivateDecl and checks its correctness.
88908890
OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc,
88918891
ArrayRef<Expr *> VarList);
8892+
/// Called on well-formed '#pragma omp allocate'.
8893+
DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc,
8894+
ArrayRef<Expr *> VarList,
8895+
DeclContext *Owner = nullptr);
88928896
/// Called on well-formed '#pragma omp requires'.
88938897
DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc,
88948898
ArrayRef<OMPClause *> ClauseList);

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,10 @@ namespace serialization {
15211521

15221522
/// An OMPRequiresDecl record.
15231523
DECL_OMP_REQUIRES,
1524-
1524+
1525+
/// An OMPAllocateDcl record.
1526+
DECL_OMP_ALLOCATE,
1527+
15251528
/// An EmptyDecl record.
15261529
DECL_EMPTY,
15271530

0 commit comments

Comments
 (0)