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 *
CreateEmpty(const ASTContext & C,unsigned NumClauses)19 OpenACCComputeConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) {
20 void *Mem = C.Allocate(
21 OpenACCComputeConstruct::totalSizeToAlloc<const OpenACCClause *>(
22 NumClauses));
23 auto *Inst = new (Mem) OpenACCComputeConstruct(NumClauses);
24 return Inst;
25 }
26
Create(const ASTContext & C,OpenACCDirectiveKind K,SourceLocation BeginLoc,SourceLocation DirLoc,SourceLocation EndLoc,ArrayRef<const OpenACCClause * > Clauses,Stmt * StructuredBlock)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 OpenACCComputeConstruct::totalSizeToAlloc<const OpenACCClause *>(
33 Clauses.size()));
34 auto *Inst = new (Mem) OpenACCComputeConstruct(K, BeginLoc, DirLoc, EndLoc,
35 Clauses, StructuredBlock);
36 return Inst;
37 }
38
OpenACCLoopConstruct(unsigned NumClauses)39 OpenACCLoopConstruct::OpenACCLoopConstruct(unsigned NumClauses)
40 : OpenACCAssociatedStmtConstruct(
41 OpenACCLoopConstructClass, OpenACCDirectiveKind::Loop,
42 SourceLocation{}, SourceLocation{}, SourceLocation{},
43 /*AssociatedStmt=*/nullptr) {
44 std::uninitialized_value_construct_n(getTrailingObjects(), NumClauses);
45 setClauseList(getTrailingObjects(NumClauses));
46 }
47
OpenACCLoopConstruct(OpenACCDirectiveKind ParentKind,SourceLocation Start,SourceLocation DirLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses,Stmt * Loop)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(Clauses, getTrailingObjects());
62
63 setClauseList(getTrailingObjects(Clauses.size()));
64 }
65
CreateEmpty(const ASTContext & C,unsigned NumClauses)66 OpenACCLoopConstruct *OpenACCLoopConstruct::CreateEmpty(const ASTContext &C,
67 unsigned NumClauses) {
68 void *Mem =
69 C.Allocate(OpenACCLoopConstruct::totalSizeToAlloc<const OpenACCClause *>(
70 NumClauses));
71 auto *Inst = new (Mem) OpenACCLoopConstruct(NumClauses);
72 return Inst;
73 }
74
Create(const ASTContext & C,OpenACCDirectiveKind ParentKind,SourceLocation BeginLoc,SourceLocation DirLoc,SourceLocation EndLoc,ArrayRef<const OpenACCClause * > Clauses,Stmt * Loop)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(OpenACCLoopConstruct::totalSizeToAlloc<const OpenACCClause *>(
81 Clauses.size()));
82 auto *Inst = new (Mem)
83 OpenACCLoopConstruct(ParentKind, BeginLoc, DirLoc, EndLoc, Clauses, Loop);
84 return Inst;
85 }
86
87 OpenACCCombinedConstruct *
CreateEmpty(const ASTContext & C,unsigned NumClauses)88 OpenACCCombinedConstruct::CreateEmpty(const ASTContext &C,
89 unsigned NumClauses) {
90 void *Mem = C.Allocate(
91 OpenACCCombinedConstruct::totalSizeToAlloc<const OpenACCClause *>(
92 NumClauses));
93 auto *Inst = new (Mem) OpenACCCombinedConstruct(NumClauses);
94 return Inst;
95 }
96
Create(const ASTContext & C,OpenACCDirectiveKind DK,SourceLocation BeginLoc,SourceLocation DirLoc,SourceLocation EndLoc,ArrayRef<const OpenACCClause * > Clauses,Stmt * Loop)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 OpenACCCombinedConstruct::totalSizeToAlloc<const OpenACCClause *>(
103 Clauses.size()));
104 auto *Inst = new (Mem)
105 OpenACCCombinedConstruct(DK, BeginLoc, DirLoc, EndLoc, Clauses, Loop);
106 return Inst;
107 }
108
CreateEmpty(const ASTContext & C,unsigned NumClauses)109 OpenACCDataConstruct *OpenACCDataConstruct::CreateEmpty(const ASTContext &C,
110 unsigned NumClauses) {
111 void *Mem =
112 C.Allocate(OpenACCDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
113 NumClauses));
114 auto *Inst = new (Mem) OpenACCDataConstruct(NumClauses);
115 return Inst;
116 }
117
118 OpenACCDataConstruct *
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses,Stmt * StructuredBlock)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(OpenACCDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
125 Clauses.size()));
126 auto *Inst = new (Mem)
127 OpenACCDataConstruct(Start, DirectiveLoc, End, Clauses, StructuredBlock);
128 return Inst;
129 }
130
131 OpenACCEnterDataConstruct *
CreateEmpty(const ASTContext & C,unsigned NumClauses)132 OpenACCEnterDataConstruct::CreateEmpty(const ASTContext &C,
133 unsigned NumClauses) {
134 void *Mem = C.Allocate(
135 OpenACCEnterDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
136 NumClauses));
137 auto *Inst = new (Mem) OpenACCEnterDataConstruct(NumClauses);
138 return Inst;
139 }
140
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses)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 OpenACCEnterDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
146 Clauses.size()));
147 auto *Inst =
148 new (Mem) OpenACCEnterDataConstruct(Start, DirectiveLoc, End, Clauses);
149 return Inst;
150 }
151
152 OpenACCExitDataConstruct *
CreateEmpty(const ASTContext & C,unsigned NumClauses)153 OpenACCExitDataConstruct::CreateEmpty(const ASTContext &C,
154 unsigned NumClauses) {
155 void *Mem = C.Allocate(
156 OpenACCExitDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
157 NumClauses));
158 auto *Inst = new (Mem) OpenACCExitDataConstruct(NumClauses);
159 return Inst;
160 }
161
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses)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 OpenACCExitDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
167 Clauses.size()));
168 auto *Inst =
169 new (Mem) OpenACCExitDataConstruct(Start, DirectiveLoc, End, Clauses);
170 return Inst;
171 }
172
173 OpenACCHostDataConstruct *
CreateEmpty(const ASTContext & C,unsigned NumClauses)174 OpenACCHostDataConstruct::CreateEmpty(const ASTContext &C,
175 unsigned NumClauses) {
176 void *Mem = C.Allocate(
177 OpenACCHostDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
178 NumClauses));
179 auto *Inst = new (Mem) OpenACCHostDataConstruct(NumClauses);
180 return Inst;
181 }
182
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses,Stmt * StructuredBlock)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 OpenACCHostDataConstruct::totalSizeToAlloc<const OpenACCClause *>(
189 Clauses.size()));
190 auto *Inst = new (Mem) OpenACCHostDataConstruct(Start, DirectiveLoc, End,
191 Clauses, StructuredBlock);
192 return Inst;
193 }
194
CreateEmpty(const ASTContext & C,unsigned NumExprs,unsigned NumClauses)195 OpenACCWaitConstruct *OpenACCWaitConstruct::CreateEmpty(const ASTContext &C,
196 unsigned NumExprs,
197 unsigned NumClauses) {
198 void *Mem = C.Allocate(
199 OpenACCWaitConstruct::totalSizeToAlloc<Expr *, OpenACCClause *>(
200 NumExprs, NumClauses));
201
202 auto *Inst = new (Mem) OpenACCWaitConstruct(NumExprs, NumClauses);
203 return Inst;
204 }
205
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation LParenLoc,Expr * DevNumExpr,SourceLocation QueuesLoc,ArrayRef<Expr * > QueueIdExprs,SourceLocation RParenLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses)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 OpenACCWaitConstruct::totalSizeToAlloc<Expr *, OpenACCClause *>(
216 QueueIdExprs.size() + 1, Clauses.size()));
217
218 auto *Inst = new (Mem)
219 OpenACCWaitConstruct(Start, DirectiveLoc, LParenLoc, DevNumExpr,
220 QueuesLoc, QueueIdExprs, RParenLoc, End, Clauses);
221 return Inst;
222 }
CreateEmpty(const ASTContext & C,unsigned NumClauses)223 OpenACCInitConstruct *OpenACCInitConstruct::CreateEmpty(const ASTContext &C,
224 unsigned NumClauses) {
225 void *Mem =
226 C.Allocate(OpenACCInitConstruct::totalSizeToAlloc<const OpenACCClause *>(
227 NumClauses));
228 auto *Inst = new (Mem) OpenACCInitConstruct(NumClauses);
229 return Inst;
230 }
231
232 OpenACCInitConstruct *
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses)233 OpenACCInitConstruct::Create(const ASTContext &C, SourceLocation Start,
234 SourceLocation DirectiveLoc, SourceLocation End,
235 ArrayRef<const OpenACCClause *> Clauses) {
236 void *Mem =
237 C.Allocate(OpenACCInitConstruct::totalSizeToAlloc<const OpenACCClause *>(
238 Clauses.size()));
239 auto *Inst =
240 new (Mem) OpenACCInitConstruct(Start, DirectiveLoc, End, Clauses);
241 return Inst;
242 }
243 OpenACCShutdownConstruct *
CreateEmpty(const ASTContext & C,unsigned NumClauses)244 OpenACCShutdownConstruct::CreateEmpty(const ASTContext &C,
245 unsigned NumClauses) {
246 void *Mem = C.Allocate(
247 OpenACCShutdownConstruct::totalSizeToAlloc<const OpenACCClause *>(
248 NumClauses));
249 auto *Inst = new (Mem) OpenACCShutdownConstruct(NumClauses);
250 return Inst;
251 }
252
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses)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 OpenACCShutdownConstruct::totalSizeToAlloc<const OpenACCClause *>(
258 Clauses.size()));
259 auto *Inst =
260 new (Mem) OpenACCShutdownConstruct(Start, DirectiveLoc, End, Clauses);
261 return Inst;
262 }
263
CreateEmpty(const ASTContext & C,unsigned NumClauses)264 OpenACCSetConstruct *OpenACCSetConstruct::CreateEmpty(const ASTContext &C,
265 unsigned NumClauses) {
266 void *Mem = C.Allocate(
267 OpenACCSetConstruct::totalSizeToAlloc<const OpenACCClause *>(NumClauses));
268 auto *Inst = new (Mem) OpenACCSetConstruct(NumClauses);
269 return Inst;
270 }
271
272 OpenACCSetConstruct *
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses)273 OpenACCSetConstruct::Create(const ASTContext &C, SourceLocation Start,
274 SourceLocation DirectiveLoc, SourceLocation End,
275 ArrayRef<const OpenACCClause *> Clauses) {
276 void *Mem =
277 C.Allocate(OpenACCSetConstruct::totalSizeToAlloc<const OpenACCClause *>(
278 Clauses.size()));
279 auto *Inst = new (Mem) OpenACCSetConstruct(Start, DirectiveLoc, End, Clauses);
280 return Inst;
281 }
282
283 OpenACCUpdateConstruct *
CreateEmpty(const ASTContext & C,unsigned NumClauses)284 OpenACCUpdateConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) {
285 void *Mem = C.Allocate(
286 OpenACCUpdateConstruct::totalSizeToAlloc<const OpenACCClause *>(
287 NumClauses));
288 auto *Inst = new (Mem) OpenACCUpdateConstruct(NumClauses);
289 return Inst;
290 }
291
292 OpenACCUpdateConstruct *
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses)293 OpenACCUpdateConstruct::Create(const ASTContext &C, SourceLocation Start,
294 SourceLocation DirectiveLoc, SourceLocation End,
295 ArrayRef<const OpenACCClause *> Clauses) {
296 void *Mem = C.Allocate(
297 OpenACCUpdateConstruct::totalSizeToAlloc<const OpenACCClause *>(
298 Clauses.size()));
299 auto *Inst =
300 new (Mem) OpenACCUpdateConstruct(Start, DirectiveLoc, End, Clauses);
301 return Inst;
302 }
303
304 OpenACCAtomicConstruct *
CreateEmpty(const ASTContext & C,unsigned NumClauses)305 OpenACCAtomicConstruct::CreateEmpty(const ASTContext &C, unsigned NumClauses) {
306 void *Mem = C.Allocate(
307 OpenACCAtomicConstruct::totalSizeToAlloc<const OpenACCClause *>(
308 NumClauses));
309 auto *Inst = new (Mem) OpenACCAtomicConstruct(NumClauses);
310 return Inst;
311 }
312
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,OpenACCAtomicKind AtKind,SourceLocation End,ArrayRef<const OpenACCClause * > Clauses,Stmt * AssociatedStmt)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 OpenACCAtomicConstruct::totalSizeToAlloc<const OpenACCClause *>(
319 Clauses.size()));
320 auto *Inst = new (Mem) OpenACCAtomicConstruct(Start, DirectiveLoc, AtKind,
321 End, Clauses, AssociatedStmt);
322 return Inst;
323 }
324
CreateEmpty(const ASTContext & C,unsigned NumVars)325 OpenACCCacheConstruct *OpenACCCacheConstruct::CreateEmpty(const ASTContext &C,
326 unsigned NumVars) {
327 void *Mem =
328 C.Allocate(OpenACCCacheConstruct::totalSizeToAlloc<Expr *>(NumVars));
329 auto *Inst = new (Mem) OpenACCCacheConstruct(NumVars);
330 return Inst;
331 }
332
Create(const ASTContext & C,SourceLocation Start,SourceLocation DirectiveLoc,SourceLocation LParenLoc,SourceLocation ReadOnlyLoc,ArrayRef<Expr * > VarList,SourceLocation RParenLoc,SourceLocation End)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 OpenACCCacheConstruct::totalSizeToAlloc<Expr *>(VarList.size()));
339 auto *Inst = new (Mem) OpenACCCacheConstruct(
340 Start, DirectiveLoc, LParenLoc, ReadOnlyLoc, VarList, RParenLoc, End);
341 return Inst;
342 }
343