Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 3fbbfdb

Browse files
committed
[OPENMP 5.0]Add initial support for 'allocate' directive.
Added parsing/sema analysis/serialization/deserialization support for 'allocate' directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355614 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d8ac2ca commit 3fbbfdb

37 files changed

+644
-33
lines changed

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.

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()) {

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

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;

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]>;

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

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)

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

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);

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

include/clang/Serialization/ASTWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ class ASTWriter : public ASTDeserializationListener,
737737
void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) override;
738738
void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
739739
const Attr *Attr) override;
740+
void DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) override;
740741
void RedefinedHiddenDefinition(const NamedDecl *D, Module *M) override;
741742
void AddedAttributeToRecord(const Attr *Attr,
742743
const RecordDecl *Record) override;

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9798,12 +9798,12 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
97989798
return false;
97999799
} else if (isa<PragmaCommentDecl>(D))
98009800
return true;
9801-
else if (isa<OMPThreadPrivateDecl>(D))
9802-
return true;
98039801
else if (isa<PragmaDetectMismatchDecl>(D))
98049802
return true;
98059803
else if (isa<OMPThreadPrivateDecl>(D))
98069804
return !D->getDeclContext()->isDependentContext();
9805+
else if (isa<OMPAllocateDecl>(D))
9806+
return !D->getDeclContext()->isDependentContext();
98079807
else if (isa<OMPDeclareReductionDecl>(D))
98089808
return !D->getDeclContext()->isDependentContext();
98099809
else if (isa<ImportDecl>(D))

lib/AST/DeclBase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
812812
case ObjCCategoryImpl:
813813
case Import:
814814
case OMPThreadPrivate:
815+
case OMPAllocate:
815816
case OMPRequires:
816817
case OMPCapturedExpr:
817818
case Empty:

lib/AST/DeclOpenMP.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
5252
std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
5353
}
5454

55+
//===----------------------------------------------------------------------===//
56+
// OMPAllocateDecl Implementation.
57+
//===----------------------------------------------------------------------===//
58+
59+
void OMPAllocateDecl::anchor() { }
60+
61+
OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
62+
SourceLocation L,
63+
ArrayRef<Expr *> VL) {
64+
OMPAllocateDecl *D = new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
65+
OMPAllocateDecl(OMPAllocate, DC, L);
66+
D->NumVars = VL.size();
67+
D->setVars(VL);
68+
return D;
69+
}
70+
71+
OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
72+
unsigned N) {
73+
OMPAllocateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
74+
OMPAllocateDecl(OMPAllocate, nullptr, SourceLocation());
75+
D->NumVars = N;
76+
return D;
77+
}
78+
79+
void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
80+
assert(VL.size() == NumVars &&
81+
"Number of variables is not the same as the preallocated buffer");
82+
std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
83+
}
84+
5585
//===----------------------------------------------------------------------===//
5686
// OMPRequiresDecl Implementation.
5787
//===----------------------------------------------------------------------===//

lib/AST/DeclPrinter.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ namespace {
9999
void VisitUsingDecl(UsingDecl *D);
100100
void VisitUsingShadowDecl(UsingShadowDecl *D);
101101
void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
102+
void VisitOMPAllocateDecl(OMPAllocateDecl *D);
102103
void VisitOMPRequiresDecl(OMPRequiresDecl *D);
103104
void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
104105
void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
@@ -424,7 +425,8 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
424425
// FIXME: Need to be able to tell the DeclPrinter when
425426
const char *Terminator = nullptr;
426427
if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D) ||
427-
isa<OMPDeclareMapperDecl>(*D) || isa<OMPRequiresDecl>(*D))
428+
isa<OMPDeclareMapperDecl>(*D) || isa<OMPRequiresDecl>(*D) ||
429+
isa<OMPAllocateDecl>(*D))
428430
Terminator = nullptr;
429431
else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
430432
Terminator = nullptr;
@@ -1546,6 +1548,20 @@ void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
15461548
}
15471549
}
15481550

1551+
void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
1552+
Out << "#pragma omp allocate";
1553+
if (!D->varlist_empty()) {
1554+
for (OMPAllocateDecl::varlist_iterator I = D->varlist_begin(),
1555+
E = D->varlist_end();
1556+
I != E; ++I) {
1557+
Out << (I == D->varlist_begin() ? '(' : ',');
1558+
NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1559+
ND->printQualifiedName(Out);
1560+
}
1561+
Out << ")";
1562+
}
1563+
}
1564+
15491565
void DeclPrinter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
15501566
Out << "#pragma omp requires ";
15511567
if (!D->clauselist_empty()) {

lib/AST/OpenMPClause.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) {
8484
case OMPC_untied:
8585
case OMPC_mergeable:
8686
case OMPC_threadprivate:
87+
case OMPC_allocate:
8788
case OMPC_flush:
8889
case OMPC_read:
8990
case OMPC_write:
@@ -155,6 +156,7 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C)
155156
case OMPC_untied:
156157
case OMPC_mergeable:
157158
case OMPC_threadprivate:
159+
case OMPC_allocate:
158160
case OMPC_flush:
159161
case OMPC_read:
160162
case OMPC_write:

lib/Basic/OpenMPKinds.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const char *clang::getOpenMPClauseName(OpenMPClauseKind Kind) {
7171
return "uniform";
7272
case OMPC_threadprivate:
7373
return "threadprivate or thread local";
74+
case OMPC_allocate:
75+
return "allocate";
7476
}
7577
llvm_unreachable("Invalid OpenMP clause kind");
7678
}
@@ -147,6 +149,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
147149
.Default(OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown);
148150
case OMPC_unknown:
149151
case OMPC_threadprivate:
152+
case OMPC_allocate:
150153
case OMPC_if:
151154
case OMPC_final:
152155
case OMPC_num_threads:
@@ -328,6 +331,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
328331
llvm_unreachable("Invalid OpenMP 'atomic_default_mem_order' clause type");
329332
case OMPC_unknown:
330333
case OMPC_threadprivate:
334+
case OMPC_allocate:
331335
case OMPC_if:
332336
case OMPC_final:
333337
case OMPC_num_threads:
@@ -810,6 +814,7 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind,
810814
case OMPD_end_declare_target:
811815
case OMPD_unknown:
812816
case OMPD_threadprivate:
817+
case OMPD_allocate:
813818
case OMPD_section:
814819
case OMPD_master:
815820
case OMPD_taskyield:
@@ -1033,6 +1038,7 @@ void clang::getOpenMPCaptureRegions(
10331038
CaptureRegions.push_back(OMPD_unknown);
10341039
break;
10351040
case OMPD_threadprivate:
1041+
case OMPD_allocate:
10361042
case OMPD_taskyield:
10371043
case OMPD_barrier:
10381044
case OMPD_taskwait:

lib/CodeGen/CGDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
103103
case Decl::Label: // __label__ x;
104104
case Decl::Import:
105105
case Decl::OMPThreadPrivate:
106+
case Decl::OMPAllocate:
106107
case Decl::OMPCapturedExpr:
107108
case Decl::OMPRequires:
108109
case Decl::Empty:

lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8215,6 +8215,7 @@ getNestedDistributeDirective(ASTContext &Ctx, const OMPExecutableDirective &D) {
82158215
case OMPD_cancellation_point:
82168216
case OMPD_ordered:
82178217
case OMPD_threadprivate:
8218+
case OMPD_allocate:
82188219
case OMPD_task:
82198220
case OMPD_simd:
82208221
case OMPD_sections:
@@ -8638,6 +8639,7 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S,
86388639
case OMPD_cancellation_point:
86398640
case OMPD_ordered:
86408641
case OMPD_threadprivate:
8642+
case OMPD_allocate:
86418643
case OMPD_task:
86428644
case OMPD_simd:
86438645
case OMPD_sections:
@@ -9156,6 +9158,7 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(
91569158
case OMPD_cancellation_point:
91579159
case OMPD_ordered:
91589160
case OMPD_threadprivate:
9161+
case OMPD_allocate:
91599162
case OMPD_task:
91609163
case OMPD_simd:
91619164
case OMPD_sections:

0 commit comments

Comments
 (0)