clang  10.0.0svn
DeclOpenMP.cpp
Go to the documentation of this file.
1 //===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
10 /// classes.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/DeclBase.h"
17 #include "clang/AST/DeclOpenMP.h"
18 #include "clang/AST/Expr.h"
19 
20 using namespace clang;
21 
22 //===----------------------------------------------------------------------===//
23 // OMPThreadPrivateDecl Implementation.
24 //===----------------------------------------------------------------------===//
25 
26 void OMPThreadPrivateDecl::anchor() { }
27 
29  DeclContext *DC,
31  ArrayRef<Expr *> VL) {
33  new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
34  OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
35  D->NumVars = VL.size();
36  D->setVars(VL);
37  return D;
38 }
39 
41  unsigned ID,
42  unsigned N) {
43  OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
44  OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
45  D->NumVars = N;
46  return D;
47 }
48 
49 void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
50  assert(VL.size() == NumVars &&
51  "Number of variables is not the same as the preallocated buffer");
52  std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
53 }
54 
55 //===----------------------------------------------------------------------===//
56 // OMPAllocateDecl Implementation.
57 //===----------------------------------------------------------------------===//
58 
59 void OMPAllocateDecl::anchor() { }
60 
64  OMPAllocateDecl *D = new (
65  C, DC, additionalSizeToAlloc<Expr *, OMPClause *>(VL.size(), CL.size()))
66  OMPAllocateDecl(OMPAllocate, DC, L);
67  D->NumVars = VL.size();
68  D->setVars(VL);
69  D->NumClauses = CL.size();
70  D->setClauses(CL);
71  return D;
72 }
73 
75  unsigned NVars,
76  unsigned NClauses) {
77  OMPAllocateDecl *D =
78  new (C, ID, additionalSizeToAlloc<Expr *, OMPClause *>(NVars, NClauses))
79  OMPAllocateDecl(OMPAllocate, nullptr, SourceLocation());
80  D->NumVars = NVars;
81  D->NumClauses = NClauses;
82  return D;
83 }
84 
85 void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
86  assert(VL.size() == NumVars &&
87  "Number of variables is not the same as the preallocated buffer");
88  std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
89 }
90 
91 void OMPAllocateDecl::setClauses(ArrayRef<OMPClause *> CL) {
92  assert(CL.size() == NumClauses &&
93  "Number of variables is not the same as the preallocated buffer");
94  std::uninitialized_copy(CL.begin(), CL.end(),
95  getTrailingObjects<OMPClause *>());
96 }
97 
98 //===----------------------------------------------------------------------===//
99 // OMPRequiresDecl Implementation.
100 //===----------------------------------------------------------------------===//
101 
102 void OMPRequiresDecl::anchor() {}
103 
105  SourceLocation L,
107  OMPRequiresDecl *D =
108  new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
109  OMPRequiresDecl(OMPRequires, DC, L);
110  D->NumClauses = CL.size();
111  D->setClauses(CL);
112  return D;
113 }
114 
116  unsigned N) {
117  OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
118  OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
119  D->NumClauses = N;
120  return D;
121 }
122 
123 void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
124  assert(CL.size() == NumClauses &&
125  "Number of clauses is not the same as the preallocated buffer");
126  std::uninitialized_copy(CL.begin(), CL.end(),
127  getTrailingObjects<OMPClause *>());
128 }
129 
130 //===----------------------------------------------------------------------===//
131 // OMPDeclareReductionDecl Implementation.
132 //===----------------------------------------------------------------------===//
133 
134 OMPDeclareReductionDecl::OMPDeclareReductionDecl(
136  QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
137  : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
138  PrevDeclInScope(PrevDeclInScope) {
139  setInitializer(nullptr, CallInit);
140 }
141 
142 void OMPDeclareReductionDecl::anchor() {}
143 
146  QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
147  return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
148  T, PrevDeclInScope);
149 }
150 
153  return new (C, ID) OMPDeclareReductionDecl(
154  OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
155  QualType(), /*PrevDeclInScope=*/nullptr);
156 }
157 
159  return cast_or_null<OMPDeclareReductionDecl>(
160  PrevDeclInScope.get(getASTContext().getExternalSource()));
161 }
164  return cast_or_null<OMPDeclareReductionDecl>(
165  PrevDeclInScope.get(getASTContext().getExternalSource()));
166 }
167 
168 //===----------------------------------------------------------------------===//
169 // OMPDeclareMapperDecl Implementation.
170 //===----------------------------------------------------------------------===//
171 
172 void OMPDeclareMapperDecl::anchor() {}
173 
176  DeclarationName Name, QualType T,
177  DeclarationName VarName,
178  OMPDeclareMapperDecl *PrevDeclInScope) {
179  return new (C, DC) OMPDeclareMapperDecl(OMPDeclareMapper, DC, L, Name, T,
180  VarName, PrevDeclInScope);
181 }
182 
184  unsigned ID,
185  unsigned N) {
186  auto *D = new (C, ID)
187  OMPDeclareMapperDecl(OMPDeclareMapper, /*DC=*/nullptr, SourceLocation(),
189  /*PrevDeclInScope=*/nullptr);
190  if (N) {
191  auto **ClauseStorage = C.Allocate<OMPClause *>(N);
192  D->Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, N);
193  }
194  return D;
195 }
196 
197 /// Creates an array of clauses to this mapper declaration and intializes
198 /// them. The space used to store clause pointers is dynamically allocated,
199 /// because we do not know the number of clauses when creating
200 /// OMPDeclareMapperDecl
203  assert(Clauses.empty() && "Number of clauses should be 0 on initialization");
204  size_t NumClauses = CL.size();
205  if (NumClauses) {
206  auto **ClauseStorage = C.Allocate<OMPClause *>(NumClauses);
207  Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, NumClauses);
208  setClauses(CL);
209  }
210 }
211 
212 void OMPDeclareMapperDecl::setClauses(ArrayRef<OMPClause *> CL) {
213  assert(CL.size() == Clauses.size() &&
214  "Number of clauses is not the same as the preallocated buffer");
215  std::uninitialized_copy(CL.begin(), CL.end(), Clauses.data());
216 }
217 
219  return cast_or_null<OMPDeclareMapperDecl>(
220  PrevDeclInScope.get(getASTContext().getExternalSource()));
221 }
222 
224  return cast_or_null<OMPDeclareMapperDecl>(
225  PrevDeclInScope.get(getASTContext().getExternalSource()));
226 }
227 
228 //===----------------------------------------------------------------------===//
229 // OMPCapturedExprDecl Implementation.
230 //===----------------------------------------------------------------------===//
231 
232 void OMPCapturedExprDecl::anchor() {}
233 
236  SourceLocation StartLoc) {
237  return new (C, DC) OMPCapturedExprDecl(
238  C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
239 }
240 
242  unsigned ID) {
243  return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
244  /*TInfo=*/nullptr, SourceLocation());
245 }
246 
248  assert(hasInit());
249  return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
250 }
Defines the clang::ASTContext interface.
OMPDeclareMapperDecl * getPrevDeclInScope()
Get reference to previous declare mapper construct in the same scope with the same name...
Definition: DeclOpenMP.cpp:218
A (possibly-)qualified type.
Definition: Type.h:643
This represents &#39;#pragma omp allocate ...&#39; directive.
Definition: DeclOpenMP.h:422
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:421
static OMPDeclareReductionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, QualType T, OMPDeclareReductionDecl *PrevDeclInScope)
Create declare reduction node.
Definition: DeclOpenMP.cpp:144
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:425
static OMPDeclareMapperDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Creates deserialized declare mapper node.
Definition: DeclOpenMP.cpp:183
One of these records is kept for each identifier that is lexed.
static OMPThreadPrivateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Definition: DeclOpenMP.cpp:40
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
void CreateClauses(ASTContext &C, ArrayRef< OMPClause *> CL)
Creates an array of clauses to this mapper declaration and intializes them.
Definition: DeclOpenMP.cpp:201
friend class DeclContext
Definition: DeclBase.h:247
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition: DeclOpenMP.cpp:247
static OMPCapturedExprDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclOpenMP.cpp:241
static OMPRequiresDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Create deserialized requires node.
Definition: DeclOpenMP.cpp:115
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
This represents &#39;#pragma omp requires...&#39; directive.
Definition: DeclOpenMP.h:345
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:644
int Id
Definition: ASTDiff.cpp:190
OMPDeclareReductionDecl * getPrevDeclInScope()
Get reference to previous declare reduction construct in the same scope with the same name...
Definition: DeclOpenMP.cpp:158
static OMPAllocateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NVars, unsigned NClauses)
Definition: DeclOpenMP.cpp:74
Encodes a location in the source.
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:312
static OMPAllocateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr *> VL, ArrayRef< OMPClause *> CL)
Definition: DeclOpenMP.cpp:61
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:377
This file defines OpenMP nodes for declarative directives.
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:50
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:685
static OMPCapturedExprDecl * Create(ASTContext &C, DeclContext *DC, IdentifierInfo *Id, QualType T, SourceLocation StartLoc)
Definition: DeclOpenMP.cpp:234
static OMPDeclareMapperDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, QualType T, DeclarationName VarName, OMPDeclareMapperDecl *PrevDeclInScope)
Creates declare mapper node.
Definition: DeclOpenMP.cpp:175
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
static OMPThreadPrivateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< Expr *> VL)
Definition: DeclOpenMP.cpp:28
The name of a declaration.
static OMPRequiresDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, ArrayRef< OMPClause *> CL)
Create requires node.
Definition: DeclOpenMP.cpp:104
static OMPDeclareReductionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create deserialized declare reduction node.
Definition: DeclOpenMP.cpp:152
This represents &#39;#pragma omp declare mapper ...&#39; directive.
Definition: DeclOpenMP.h:217
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:91
A trivial tuple used to represent a source range.
This represents &#39;#pragma omp threadprivate ...&#39; directive.
Definition: DeclOpenMP.h:39