DeclOpenMP.cpp
10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
/// \file
/// This file implements OMPThreadPrivateDecl, OMPCapturedExprDecl
/// classes.
///
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/AST/Expr.h"
using namespace clang;
//===----------------------------------------------------------------------===//
// OMPThreadPrivateDecl Implementation.
//===----------------------------------------------------------------------===//
void OMPThreadPrivateDecl::anchor() { }
OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
DeclContext *DC,
SourceLocation L,
ArrayRef<Expr *> VL) {
OMPThreadPrivateDecl *D =
new (C, DC, additionalSizeToAlloc<Expr *>(VL.size()))
OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
D->NumVars = VL.size();
D->setVars(VL);
return D;
}
OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
unsigned ID,
unsigned N) {
OMPThreadPrivateDecl *D = new (C, ID, additionalSizeToAlloc<Expr *>(N))
OMPThreadPrivateDecl(OMPThreadPrivate, nullptr, SourceLocation());
D->NumVars = N;
return D;
}
void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
assert(VL.size() == NumVars &&
"Number of variables is not the same as the preallocated buffer");
std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
}
//===----------------------------------------------------------------------===//
// OMPAllocateDecl Implementation.
//===----------------------------------------------------------------------===//
void OMPAllocateDecl::anchor() { }
OMPAllocateDecl *OMPAllocateDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L, ArrayRef<Expr *> VL,
ArrayRef<OMPClause *> CL) {
OMPAllocateDecl *D = new (
C, DC, additionalSizeToAlloc<Expr *, OMPClause *>(VL.size(), CL.size()))
OMPAllocateDecl(OMPAllocate, DC, L);
D->NumVars = VL.size();
D->setVars(VL);
D->NumClauses = CL.size();
D->setClauses(CL);
return D;
}
OMPAllocateDecl *OMPAllocateDecl::CreateDeserialized(ASTContext &C, unsigned ID,
unsigned NVars,
unsigned NClauses) {
OMPAllocateDecl *D =
new (C, ID, additionalSizeToAlloc<Expr *, OMPClause *>(NVars, NClauses))
OMPAllocateDecl(OMPAllocate, nullptr, SourceLocation());
D->NumVars = NVars;
D->NumClauses = NClauses;
return D;
}
void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
assert(VL.size() == NumVars &&
"Number of variables is not the same as the preallocated buffer");
std::uninitialized_copy(VL.begin(), VL.end(), getTrailingObjects<Expr *>());
}
void OMPAllocateDecl::setClauses(ArrayRef<OMPClause *> CL) {
assert(CL.size() == NumClauses &&
"Number of variables is not the same as the preallocated buffer");
std::uninitialized_copy(CL.begin(), CL.end(),
getTrailingObjects<OMPClause *>());
}
//===----------------------------------------------------------------------===//
// OMPRequiresDecl Implementation.
//===----------------------------------------------------------------------===//
void OMPRequiresDecl::anchor() {}
OMPRequiresDecl *OMPRequiresDecl::Create(ASTContext &C, DeclContext *DC,
SourceLocation L,
ArrayRef<OMPClause *> CL) {
OMPRequiresDecl *D =
new (C, DC, additionalSizeToAlloc<OMPClause *>(CL.size()))
OMPRequiresDecl(OMPRequires, DC, L);
D->NumClauses = CL.size();
D->setClauses(CL);
return D;
}
OMPRequiresDecl *OMPRequiresDecl::CreateDeserialized(ASTContext &C, unsigned ID,
unsigned N) {
OMPRequiresDecl *D = new (C, ID, additionalSizeToAlloc<OMPClause *>(N))
OMPRequiresDecl(OMPRequires, nullptr, SourceLocation());
D->NumClauses = N;
return D;
}
void OMPRequiresDecl::setClauses(ArrayRef<OMPClause *> CL) {
assert(CL.size() == NumClauses &&
"Number of clauses is not the same as the preallocated buffer");
std::uninitialized_copy(CL.begin(), CL.end(),
getTrailingObjects<OMPClause *>());
}
//===----------------------------------------------------------------------===//
// OMPDeclareReductionDecl Implementation.
//===----------------------------------------------------------------------===//
OMPDeclareReductionDecl::OMPDeclareReductionDecl(
Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
: ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
PrevDeclInScope(PrevDeclInScope) {
setInitializer(nullptr, CallInit);
}
void OMPDeclareReductionDecl::anchor() {}
OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(
ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name,
QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
T, PrevDeclInScope);
}
OMPDeclareReductionDecl *
OMPDeclareReductionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
return new (C, ID) OMPDeclareReductionDecl(
OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
QualType(), /*PrevDeclInScope=*/nullptr);
}
OMPDeclareReductionDecl *OMPDeclareReductionDecl::getPrevDeclInScope() {
return cast_or_null<OMPDeclareReductionDecl>(
PrevDeclInScope.get(getASTContext().getExternalSource()));
}
const OMPDeclareReductionDecl *
OMPDeclareReductionDecl::getPrevDeclInScope() const {
return cast_or_null<OMPDeclareReductionDecl>(
PrevDeclInScope.get(getASTContext().getExternalSource()));
}
//===----------------------------------------------------------------------===//
// OMPDeclareMapperDecl Implementation.
//===----------------------------------------------------------------------===//
void OMPDeclareMapperDecl::anchor() {}
OMPDeclareMapperDecl *
OMPDeclareMapperDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
DeclarationName Name, QualType T,
DeclarationName VarName,
OMPDeclareMapperDecl *PrevDeclInScope) {
return new (C, DC) OMPDeclareMapperDecl(OMPDeclareMapper, DC, L, Name, T,
VarName, PrevDeclInScope);
}
OMPDeclareMapperDecl *OMPDeclareMapperDecl::CreateDeserialized(ASTContext &C,
unsigned ID,
unsigned N) {
auto *D = new (C, ID)
OMPDeclareMapperDecl(OMPDeclareMapper, /*DC=*/nullptr, SourceLocation(),
DeclarationName(), QualType(), DeclarationName(),
/*PrevDeclInScope=*/nullptr);
if (N) {
auto **ClauseStorage = C.Allocate<OMPClause *>(N);
D->Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, N);
}
return D;
}
/// Creates an array of clauses to this mapper declaration and intializes
/// them. The space used to store clause pointers is dynamically allocated,
/// because we do not know the number of clauses when creating
/// OMPDeclareMapperDecl
void OMPDeclareMapperDecl::CreateClauses(ASTContext &C,
ArrayRef<OMPClause *> CL) {
assert(Clauses.empty() && "Number of clauses should be 0 on initialization");
size_t NumClauses = CL.size();
if (NumClauses) {
auto **ClauseStorage = C.Allocate<OMPClause *>(NumClauses);
Clauses = llvm::makeMutableArrayRef<OMPClause *>(ClauseStorage, NumClauses);
setClauses(CL);
}
}
void OMPDeclareMapperDecl::setClauses(ArrayRef<OMPClause *> CL) {
assert(CL.size() == Clauses.size() &&
"Number of clauses is not the same as the preallocated buffer");
std::uninitialized_copy(CL.begin(), CL.end(), Clauses.data());
}
OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() {
return cast_or_null<OMPDeclareMapperDecl>(
PrevDeclInScope.get(getASTContext().getExternalSource()));
}
const OMPDeclareMapperDecl *OMPDeclareMapperDecl::getPrevDeclInScope() const {
return cast_or_null<OMPDeclareMapperDecl>(
PrevDeclInScope.get(getASTContext().getExternalSource()));
}
//===----------------------------------------------------------------------===//
// OMPCapturedExprDecl Implementation.
//===----------------------------------------------------------------------===//
void OMPCapturedExprDecl::anchor() {}
OMPCapturedExprDecl *OMPCapturedExprDecl::Create(ASTContext &C, DeclContext *DC,
IdentifierInfo *Id, QualType T,
SourceLocation StartLoc) {
return new (C, DC) OMPCapturedExprDecl(
C, DC, Id, T, C.getTrivialTypeSourceInfo(T), StartLoc);
}
OMPCapturedExprDecl *OMPCapturedExprDecl::CreateDeserialized(ASTContext &C,
unsigned ID) {
return new (C, ID) OMPCapturedExprDecl(C, nullptr, nullptr, QualType(),
/*TInfo=*/nullptr, SourceLocation());
}
SourceRange OMPCapturedExprDecl::getSourceRange() const {
assert(hasInit());
return SourceRange(getInit()->getBeginLoc(), getInit()->getEndLoc());
}