1 | //===--- StmtOpenACC.cpp - Classes for OpenACC Constructs -----------------===// |
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 | // |
9 | // This file implements the subclasses of Stmt class declared in StmtOpenACC.h |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "clang/AST/StmtOpenACC.h" |
14 | #include "clang/AST/ASTContext.h" |
15 | #include "clang/AST/StmtCXX.h" |
16 | using namespace clang; |
17 | |
18 | OpenACCComputeConstruct * |
19 | OpenACCComputeConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) { |
20 | void *Mem = C.Allocate( |
21 | Size: OpenACCComputeConstruct::totalSizeToAlloc<const OpenACCClause *>( |
22 | Counts: NumClauses)); |
23 | auto *Inst = new (Mem) OpenACCComputeConstruct(NumClauses); |
24 | return Inst; |
25 | } |
26 | |
27 | OpenACCComputeConstruct *OpenACCComputeConstruct::Create( |
28 | const ASTContext &C, OpenACCDirectiveKind K, SourceLocation BeginLoc, |
29 | SourceLocation DirLoc, SourceLocation EndLoc, |
30 | ArrayRef<const OpenACCClause *> Clauses, Stmt *StructuredBlock) { |
31 | void *Mem = C.Allocate( |
32 | Size: OpenACCComputeConstruct::totalSizeToAlloc<const OpenACCClause *>( |
33 | Counts: Clauses.size())); |
34 | auto *Inst = new (Mem) OpenACCComputeConstruct(K, BeginLoc, DirLoc, EndLoc, |
35 | Clauses, StructuredBlock); |
36 | return Inst; |
37 | } |
38 | |
39 | OpenACCLoopConstruct::OpenACCLoopConstruct(unsigned NumClauses) |
40 | : OpenACCAssociatedStmtConstruct( |
41 | OpenACCLoopConstructClass, OpenACCDirectiveKind::Loop, |
42 | SourceLocation{}, SourceLocation{}, SourceLocation{}, |
43 | /*AssociatedStmt=*/nullptr) { |
44 | std::uninitialized_value_construct_n(first: getTrailingObjects(), count: NumClauses); |
45 | setClauseList(getTrailingObjects(N: NumClauses)); |
46 | } |
47 | |
48 | OpenACCLoopConstruct::OpenACCLoopConstruct( |
49 | OpenACCDirectiveKind ParentKind, SourceLocation Start, |
50 | SourceLocation DirLoc, SourceLocation End, |
51 | ArrayRef<const OpenACCClause *> Clauses, Stmt *Loop) |
52 | : OpenACCAssociatedStmtConstruct(OpenACCLoopConstructClass, |
53 | OpenACCDirectiveKind::Loop, Start, DirLoc, |
54 | End, Loop), |
55 | ParentComputeConstructKind(ParentKind) { |
56 | // accept 'nullptr' for the loop. This is diagnosed somewhere, but this gives |
57 | // us some level of AST fidelity in the error case. |
58 | assert((Loop == nullptr || isa<ForStmt, CXXForRangeStmt>(Loop)) && |
59 | "Associated Loop not a for loop?" ); |
60 | // Initialize the trailing storage. |
61 | llvm::uninitialized_copy(Src&: Clauses, Dst: getTrailingObjects()); |
62 | |
63 | setClauseList(getTrailingObjects(N: Clauses.size())); |
64 | } |
65 | |
66 | OpenACCLoopConstruct *OpenACCLoopConstruct::CreateEmpty(const ASTContext &C, |
67 | unsigned NumClauses) { |
68 | void *Mem = |
69 | C.Allocate(Size: OpenACCLoopConstruct::totalSizeToAlloc<const OpenACCClause *>( |
70 | Counts: NumClauses)); |
71 | auto *Inst = new (Mem) OpenACCLoopConstruct(NumClauses); |
72 | return Inst; |
73 | } |
74 | |
75 | OpenACCLoopConstruct *OpenACCLoopConstruct::Create( |
76 | const ASTContext &C, OpenACCDirectiveKind ParentKind, |
77 | SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, |
78 | ArrayRef<const OpenACCClause *> Clauses, Stmt *Loop) { |
79 | void *Mem = |
80 | C.Allocate(Size: OpenACCLoopConstruct::totalSizeToAlloc<const OpenACCClause *>( |
81 | Counts: Clauses.size())); |
82 | auto *Inst = new (Mem) |
83 | OpenACCLoopConstruct(ParentKind, BeginLoc, DirLoc, EndLoc, Clauses, Loop); |
84 | return Inst; |
85 | } |
86 | |
87 | OpenACCCombinedConstruct * |
88 | OpenACCCombinedConstruct::CreateEmpty(const ASTContext &C, |
89 | unsigned NumClauses) { |
90 | void *Mem = C.Allocate( |
91 | Size: OpenACCCombinedConstruct::totalSizeToAlloc<const OpenACCClause *>( |
92 | Counts: NumClauses)); |
93 | auto *Inst = new (Mem) OpenACCCombinedConstruct(NumClauses); |
94 | return Inst; |
95 | } |
96 | |
97 | OpenACCCombinedConstruct *OpenACCCombinedConstruct::Create( |
98 | const ASTContext &C, OpenACCDirectiveKind DK, SourceLocation BeginLoc, |
99 | SourceLocation DirLoc, SourceLocation EndLoc, |
100 | ArrayRef<const OpenACCClause *> Clauses, Stmt *Loop) { |
101 | void *Mem = C.Allocate( |
102 | Size: OpenACCCombinedConstruct::totalSizeToAlloc<const OpenACCClause *>( |
103 | Counts: Clauses.size())); |
104 | auto *Inst = new (Mem) |
105 | OpenACCCombinedConstruct(DK, BeginLoc, DirLoc, EndLoc, Clauses, Loop); |
106 | return Inst; |
107 | } |
108 | |
109 | OpenACCDataConstruct *OpenACCDataConstruct::CreateEmpty(const ASTContext &C, |
110 | unsigned NumClauses) { |
111 | void *Mem = |
112 | C.Allocate(Size: OpenACCDataConstruct::totalSizeToAlloc<const OpenACCClause *>( |
113 | Counts: NumClauses)); |
114 | auto *Inst = new (Mem) OpenACCDataConstruct(NumClauses); |
115 | return Inst; |
116 | } |
117 | |
118 | OpenACCDataConstruct * |
119 | OpenACCDataConstruct::Create(const ASTContext &C, SourceLocation Start, |
120 | SourceLocation DirectiveLoc, SourceLocation End, |
121 | ArrayRef<const OpenACCClause *> Clauses, |
122 | Stmt *StructuredBlock) { |
123 | void *Mem = |
124 | C.Allocate(Size: OpenACCDataConstruct::totalSizeToAlloc<const OpenACCClause *>( |
125 | Counts: Clauses.size())); |
126 | auto *Inst = new (Mem) |
127 | OpenACCDataConstruct(Start, DirectiveLoc, End, Clauses, StructuredBlock); |
128 | return Inst; |
129 | } |
130 | |
131 | OpenACCEnterDataConstruct * |
132 | OpenACCEnterDataConstruct::CreateEmpty(const ASTContext &C, |
133 | unsigned NumClauses) { |
134 | void *Mem = C.Allocate( |
135 | Size: OpenACCEnterDataConstruct::totalSizeToAlloc<const OpenACCClause *>( |
136 | Counts: NumClauses)); |
137 | auto *Inst = new (Mem) OpenACCEnterDataConstruct(NumClauses); |
138 | return Inst; |
139 | } |
140 | |
141 | OpenACCEnterDataConstruct *OpenACCEnterDataConstruct::Create( |
142 | const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, |
143 | SourceLocation End, ArrayRef<const OpenACCClause *> Clauses) { |
144 | void *Mem = C.Allocate( |
145 | Size: OpenACCEnterDataConstruct::totalSizeToAlloc<const OpenACCClause *>( |
146 | Counts: Clauses.size())); |
147 | auto *Inst = |
148 | new (Mem) OpenACCEnterDataConstruct(Start, DirectiveLoc, End, Clauses); |
149 | return Inst; |
150 | } |
151 | |
152 | OpenACCExitDataConstruct * |
153 | OpenACCExitDataConstruct::CreateEmpty(const ASTContext &C, |
154 | unsigned NumClauses) { |
155 | void *Mem = C.Allocate( |
156 | Size: OpenACCExitDataConstruct::totalSizeToAlloc<const OpenACCClause *>( |
157 | Counts: NumClauses)); |
158 | auto *Inst = new (Mem) OpenACCExitDataConstruct(NumClauses); |
159 | return Inst; |
160 | } |
161 | |
162 | OpenACCExitDataConstruct *OpenACCExitDataConstruct::Create( |
163 | const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, |
164 | SourceLocation End, ArrayRef<const OpenACCClause *> Clauses) { |
165 | void *Mem = C.Allocate( |
166 | Size: OpenACCExitDataConstruct::totalSizeToAlloc<const OpenACCClause *>( |
167 | Counts: Clauses.size())); |
168 | auto *Inst = |
169 | new (Mem) OpenACCExitDataConstruct(Start, DirectiveLoc, End, Clauses); |
170 | return Inst; |
171 | } |
172 | |
173 | OpenACCHostDataConstruct * |
174 | OpenACCHostDataConstruct::CreateEmpty(const ASTContext &C, |
175 | unsigned NumClauses) { |
176 | void *Mem = C.Allocate( |
177 | Size: OpenACCHostDataConstruct::totalSizeToAlloc<const OpenACCClause *>( |
178 | Counts: NumClauses)); |
179 | auto *Inst = new (Mem) OpenACCHostDataConstruct(NumClauses); |
180 | return Inst; |
181 | } |
182 | |
183 | OpenACCHostDataConstruct *OpenACCHostDataConstruct::Create( |
184 | const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, |
185 | SourceLocation End, ArrayRef<const OpenACCClause *> Clauses, |
186 | Stmt *StructuredBlock) { |
187 | void *Mem = C.Allocate( |
188 | Size: OpenACCHostDataConstruct::totalSizeToAlloc<const OpenACCClause *>( |
189 | Counts: Clauses.size())); |
190 | auto *Inst = new (Mem) OpenACCHostDataConstruct(Start, DirectiveLoc, End, |
191 | Clauses, StructuredBlock); |
192 | return Inst; |
193 | } |
194 | |
195 | OpenACCWaitConstruct *OpenACCWaitConstruct::CreateEmpty(const ASTContext &C, |
196 | unsigned NumExprs, |
197 | unsigned NumClauses) { |
198 | void *Mem = C.Allocate( |
199 | Size: OpenACCWaitConstruct::totalSizeToAlloc<Expr *, OpenACCClause *>( |
200 | Counts: NumExprs, Counts: NumClauses)); |
201 | |
202 | auto *Inst = new (Mem) OpenACCWaitConstruct(NumExprs, NumClauses); |
203 | return Inst; |
204 | } |
205 | |
206 | OpenACCWaitConstruct *OpenACCWaitConstruct::Create( |
207 | const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, |
208 | SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, |
209 | ArrayRef<Expr *> QueueIdExprs, SourceLocation RParenLoc, SourceLocation End, |
210 | ArrayRef<const OpenACCClause *> Clauses) { |
211 | |
212 | assert(!llvm::is_contained(QueueIdExprs, nullptr)); |
213 | |
214 | void *Mem = C.Allocate( |
215 | Size: OpenACCWaitConstruct::totalSizeToAlloc<Expr *, OpenACCClause *>( |
216 | Counts: QueueIdExprs.size() + 1, Counts: Clauses.size())); |
217 | |
218 | auto *Inst = new (Mem) |
219 | OpenACCWaitConstruct(Start, DirectiveLoc, LParenLoc, DevNumExpr, |
220 | QueuesLoc, QueueIdExprs, RParenLoc, End, Clauses); |
221 | return Inst; |
222 | } |
223 | OpenACCInitConstruct *OpenACCInitConstruct::CreateEmpty(const ASTContext &C, |
224 | unsigned NumClauses) { |
225 | void *Mem = |
226 | C.Allocate(Size: OpenACCInitConstruct::totalSizeToAlloc<const OpenACCClause *>( |
227 | Counts: NumClauses)); |
228 | auto *Inst = new (Mem) OpenACCInitConstruct(NumClauses); |
229 | return Inst; |
230 | } |
231 | |
232 | OpenACCInitConstruct * |
233 | OpenACCInitConstruct::Create(const ASTContext &C, SourceLocation Start, |
234 | SourceLocation DirectiveLoc, SourceLocation End, |
235 | ArrayRef<const OpenACCClause *> Clauses) { |
236 | void *Mem = |
237 | C.Allocate(Size: OpenACCInitConstruct::totalSizeToAlloc<const OpenACCClause *>( |
238 | Counts: Clauses.size())); |
239 | auto *Inst = |
240 | new (Mem) OpenACCInitConstruct(Start, DirectiveLoc, End, Clauses); |
241 | return Inst; |
242 | } |
243 | OpenACCShutdownConstruct * |
244 | OpenACCShutdownConstruct::CreateEmpty(const ASTContext &C, |
245 | unsigned NumClauses) { |
246 | void *Mem = C.Allocate( |
247 | Size: OpenACCShutdownConstruct::totalSizeToAlloc<const OpenACCClause *>( |
248 | Counts: NumClauses)); |
249 | auto *Inst = new (Mem) OpenACCShutdownConstruct(NumClauses); |
250 | return Inst; |
251 | } |
252 | |
253 | OpenACCShutdownConstruct *OpenACCShutdownConstruct::Create( |
254 | const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, |
255 | SourceLocation End, ArrayRef<const OpenACCClause *> Clauses) { |
256 | void *Mem = C.Allocate( |
257 | Size: OpenACCShutdownConstruct::totalSizeToAlloc<const OpenACCClause *>( |
258 | Counts: Clauses.size())); |
259 | auto *Inst = |
260 | new (Mem) OpenACCShutdownConstruct(Start, DirectiveLoc, End, Clauses); |
261 | return Inst; |
262 | } |
263 | |
264 | OpenACCSetConstruct *OpenACCSetConstruct::CreateEmpty(const ASTContext &C, |
265 | unsigned NumClauses) { |
266 | void *Mem = C.Allocate( |
267 | Size: OpenACCSetConstruct::totalSizeToAlloc<const OpenACCClause *>(Counts: NumClauses)); |
268 | auto *Inst = new (Mem) OpenACCSetConstruct(NumClauses); |
269 | return Inst; |
270 | } |
271 | |
272 | OpenACCSetConstruct * |
273 | OpenACCSetConstruct::Create(const ASTContext &C, SourceLocation Start, |
274 | SourceLocation DirectiveLoc, SourceLocation End, |
275 | ArrayRef<const OpenACCClause *> Clauses) { |
276 | void *Mem = |
277 | C.Allocate(Size: OpenACCSetConstruct::totalSizeToAlloc<const OpenACCClause *>( |
278 | Counts: Clauses.size())); |
279 | auto *Inst = new (Mem) OpenACCSetConstruct(Start, DirectiveLoc, End, Clauses); |
280 | return Inst; |
281 | } |
282 | |
283 | OpenACCUpdateConstruct * |
284 | OpenACCUpdateConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) { |
285 | void *Mem = C.Allocate( |
286 | Size: OpenACCUpdateConstruct::totalSizeToAlloc<const OpenACCClause *>( |
287 | Counts: NumClauses)); |
288 | auto *Inst = new (Mem) OpenACCUpdateConstruct(NumClauses); |
289 | return Inst; |
290 | } |
291 | |
292 | OpenACCUpdateConstruct * |
293 | OpenACCUpdateConstruct::Create(const ASTContext &C, SourceLocation Start, |
294 | SourceLocation DirectiveLoc, SourceLocation End, |
295 | ArrayRef<const OpenACCClause *> Clauses) { |
296 | void *Mem = C.Allocate( |
297 | Size: OpenACCUpdateConstruct::totalSizeToAlloc<const OpenACCClause *>( |
298 | Counts: Clauses.size())); |
299 | auto *Inst = |
300 | new (Mem) OpenACCUpdateConstruct(Start, DirectiveLoc, End, Clauses); |
301 | return Inst; |
302 | } |
303 | |
304 | OpenACCAtomicConstruct * |
305 | OpenACCAtomicConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) { |
306 | void *Mem = C.Allocate( |
307 | Size: OpenACCAtomicConstruct::totalSizeToAlloc<const OpenACCClause *>( |
308 | Counts: NumClauses)); |
309 | auto *Inst = new (Mem) OpenACCAtomicConstruct(NumClauses); |
310 | return Inst; |
311 | } |
312 | |
313 | OpenACCAtomicConstruct *OpenACCAtomicConstruct::Create( |
314 | const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, |
315 | OpenACCAtomicKind AtKind, SourceLocation End, |
316 | ArrayRef<const OpenACCClause *> Clauses, Stmt *AssociatedStmt) { |
317 | void *Mem = C.Allocate( |
318 | Size: OpenACCAtomicConstruct::totalSizeToAlloc<const OpenACCClause *>( |
319 | Counts: Clauses.size())); |
320 | auto *Inst = new (Mem) OpenACCAtomicConstruct(Start, DirectiveLoc, AtKind, |
321 | End, Clauses, AssociatedStmt); |
322 | return Inst; |
323 | } |
324 | |
325 | OpenACCCacheConstruct *OpenACCCacheConstruct::CreateEmpty(const ASTContext &C, |
326 | unsigned NumVars) { |
327 | void *Mem = |
328 | C.Allocate(Size: OpenACCCacheConstruct::totalSizeToAlloc<Expr *>(Counts: NumVars)); |
329 | auto *Inst = new (Mem) OpenACCCacheConstruct(NumVars); |
330 | return Inst; |
331 | } |
332 | |
333 | OpenACCCacheConstruct *OpenACCCacheConstruct::Create( |
334 | const ASTContext &C, SourceLocation Start, SourceLocation DirectiveLoc, |
335 | SourceLocation LParenLoc, SourceLocation ReadOnlyLoc, |
336 | ArrayRef<Expr *> VarList, SourceLocation RParenLoc, SourceLocation End) { |
337 | void *Mem = C.Allocate( |
338 | Size: OpenACCCacheConstruct::totalSizeToAlloc<Expr *>(Counts: VarList.size())); |
339 | auto *Inst = new (Mem) OpenACCCacheConstruct( |
340 | Start, DirectiveLoc, LParenLoc, ReadOnlyLoc, VarList, RParenLoc, End); |
341 | return Inst; |
342 | } |
343 | |