Debian Codegraph @

clang/lib/AST/OpenACCClause.cpp

raw
1 //===---- OpenACCClause.cpp - Classes for OpenACC Clauses ----------------===//
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 the OpenACCClause class declared in
10 // OpenACCClause.h
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/AST/OpenACCClause.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Expr.h"
17
18 using namespace clang;
19
20 bool OpenACCClauseWithParams::classof(const OpenACCClause *C) {
21 return OpenACCDeviceTypeClause::classof(C) ||
22 OpenACCClauseWithCondition::classof(C) ||
23 OpenACCBindClause::classof(C) || OpenACCClauseWithExprs::classof(C) ||
24 OpenACCSelfClause::classof(C);
25 }
26 bool OpenACCClauseWithExprs::classof(const OpenACCClause *C) {
27 return OpenACCWaitClause::classof(C) || OpenACCNumGangsClause::classof(C) ||
28 OpenACCTileClause::classof(C) ||
29 OpenACCClauseWithSingleIntExpr::classof(C) ||
30 OpenACCGangClause::classof(C) || OpenACCClauseWithVarList::classof(C);
31 }
32 bool OpenACCClauseWithVarList::classof(const OpenACCClause *C) {
33 return OpenACCPrivateClause::classof(C) ||
34 OpenACCFirstPrivateClause::classof(C) ||
35 OpenACCDevicePtrClause::classof(C) ||
36 OpenACCDeleteClause::classof(C) ||
37 OpenACCUseDeviceClause::classof(C) ||
38 OpenACCDetachClause::classof(C) || OpenACCAttachClause::classof(C) ||
39 OpenACCNoCreateClause::classof(C) ||
40 OpenACCPresentClause::classof(C) || OpenACCCopyClause::classof(C) ||
41 OpenACCCopyInClause::classof(C) || OpenACCCopyOutClause::classof(C) ||
42 OpenACCReductionClause::classof(C) ||
43 OpenACCCreateClause::classof(C) || OpenACCDeviceClause::classof(C) ||
44 OpenACCLinkClause::classof(C) ||
45 OpenACCDeviceResidentClause::classof(C) ||
46 OpenACCHostClause::classof(C);
47 }
48 bool OpenACCClauseWithCondition::classof(const OpenACCClause *C) {
49 return OpenACCIfClause::classof(C);
50 }
51 bool OpenACCClauseWithSingleIntExpr::classof(const OpenACCClause *C) {
52 return OpenACCNumWorkersClause::classof(C) ||
53 OpenACCVectorLengthClause::classof(C) ||
54 OpenACCDeviceNumClause::classof(C) ||
55 OpenACCDefaultAsyncClause::classof(C) ||
56 OpenACCVectorClause::classof(C) || OpenACCWorkerClause::classof(C) ||
57 OpenACCCollapseClause::classof(C) || OpenACCAsyncClause::classof(C);
58 }
59 OpenACCDefaultClause *OpenACCDefaultClause::Create(const ASTContext &C,
60 OpenACCDefaultClauseKind K,
61 SourceLocation BeginLoc,
62 SourceLocation LParenLoc,
63 SourceLocation EndLoc) {
64 void *Mem =
65 C.Allocate(sizeof(OpenACCDefaultClause), alignof(OpenACCDefaultClause));
66
67 return new (Mem) OpenACCDefaultClause(K, BeginLoc, LParenLoc, EndLoc);
68 }
69
70 OpenACCIfClause *OpenACCIfClause::Create(const ASTContext &C,
71 SourceLocation BeginLoc,
72 SourceLocation LParenLoc,
73 Expr *ConditionExpr,
74 SourceLocation EndLoc) {
75 void *Mem = C.Allocate(sizeof(OpenACCIfClause), alignof(OpenACCIfClause));
76 return new (Mem) OpenACCIfClause(BeginLoc, LParenLoc, ConditionExpr, EndLoc);
77 }
78
79 OpenACCIfClause::OpenACCIfClause(SourceLocation BeginLoc,
80 SourceLocation LParenLoc, Expr *ConditionExpr,
81 SourceLocation EndLoc)
82 : OpenACCClauseWithCondition(OpenACCClauseKind::If, BeginLoc, LParenLoc,
83 ConditionExpr, EndLoc) {
84 assert(ConditionExpr && "if clause requires condition expr");
85 assert((ConditionExpr->isInstantiationDependent() ||
86 ConditionExpr->getType()->isScalarType()) &&
87 "Condition expression type not scalar/dependent");
88 }
89
90 OpenACCSelfClause *OpenACCSelfClause::Create(const ASTContext &C,
91 SourceLocation BeginLoc,
92 SourceLocation LParenLoc,
93 Expr *ConditionExpr,
94 SourceLocation EndLoc) {
95 void *Mem = C.Allocate(OpenACCSelfClause::totalSizeToAlloc<Expr *>(1));
96 return new (Mem)
97 OpenACCSelfClause(BeginLoc, LParenLoc, ConditionExpr, EndLoc);
98 }
99
100 OpenACCSelfClause *OpenACCSelfClause::Create(const ASTContext &C,
101 SourceLocation BeginLoc,
102 SourceLocation LParenLoc,
103 ArrayRef<Expr *> VarList,
104 SourceLocation EndLoc) {
105 void *Mem =
106 C.Allocate(OpenACCSelfClause::totalSizeToAlloc<Expr *>(VarList.size()));
107 return new (Mem) OpenACCSelfClause(BeginLoc, LParenLoc, VarList, EndLoc);
108 }
109
110 OpenACCSelfClause::OpenACCSelfClause(SourceLocation BeginLoc,
111 SourceLocation LParenLoc,
112 ArrayRef<Expr *> VarList,
113 SourceLocation EndLoc)
114 : OpenACCClauseWithParams(OpenACCClauseKind::Self, BeginLoc, LParenLoc,
115 EndLoc),
116 HasConditionExpr(std::nullopt), NumExprs(VarList.size()) {
117 llvm::uninitialized_copy(VarList, getTrailingObjects());
118 }
119
120 OpenACCSelfClause::OpenACCSelfClause(SourceLocation BeginLoc,
121 SourceLocation LParenLoc,
122 Expr *ConditionExpr, SourceLocation EndLoc)
123 : OpenACCClauseWithParams(OpenACCClauseKind::Self, BeginLoc, LParenLoc,
124 EndLoc),
125 HasConditionExpr(ConditionExpr != nullptr), NumExprs(1) {
126 assert((!ConditionExpr || ConditionExpr->isInstantiationDependent() ||
127 ConditionExpr->getType()->isScalarType()) &&
128 "Condition expression type not scalar/dependent");
129 llvm::uninitialized_copy(ArrayRef(ConditionExpr), getTrailingObjects());
130 }
131
132 OpenACCClause::child_range OpenACCClause::children() {
133 switch (getClauseKind()) {
134 default:
135 assert(false && "Clause children function not implemented");
136 break;
137 #define VISIT_CLAUSE(CLAUSE_NAME) \
138 case OpenACCClauseKind::CLAUSE_NAME: \
139 return cast<OpenACC##CLAUSE_NAME##Clause>(this)->children();
140 #define CLAUSE_ALIAS(ALIAS_NAME, CLAUSE_NAME, DEPRECATED) \
141 case OpenACCClauseKind::ALIAS_NAME: \
142 return cast<OpenACC##CLAUSE_NAME##Clause>(this)->children();
143
144 #include "clang/Basic/OpenACCClauses.def"
145 }
146 return child_range(child_iterator(), child_iterator());
147 }
148
149 OpenACCNumWorkersClause::OpenACCNumWorkersClause(SourceLocation BeginLoc,
150 SourceLocation LParenLoc,
151 Expr *IntExpr,
152 SourceLocation EndLoc)
153 : OpenACCClauseWithSingleIntExpr(OpenACCClauseKind::NumWorkers, BeginLoc,
154 LParenLoc, IntExpr, EndLoc) {
155 assert((!IntExpr || IntExpr->isInstantiationDependent() ||
156 IntExpr->getType()->isIntegerType()) &&
157 "Condition expression type not scalar/dependent");
158 }
159
160 OpenACCGangClause::OpenACCGangClause(SourceLocation BeginLoc,
161 SourceLocation LParenLoc,
162 ArrayRef<OpenACCGangKind> GangKinds,
163 ArrayRef<Expr *> IntExprs,
164 SourceLocation EndLoc)
165 : OpenACCClauseWithExprs(OpenACCClauseKind::Gang, BeginLoc, LParenLoc,
166 EndLoc) {
167 assert(GangKinds.size() == IntExprs.size() && "Mismatch exprs/kind?");
168 setExprs(getTrailingObjects<Expr *>(IntExprs.size()), IntExprs);
169 llvm::uninitialized_copy(GangKinds, getTrailingObjects<OpenACCGangKind>());
170 }
171
172 OpenACCNumWorkersClause *
173 OpenACCNumWorkersClause::Create(const ASTContext &C, SourceLocation BeginLoc,
174 SourceLocation LParenLoc, Expr *IntExpr,
175 SourceLocation EndLoc) {
176 void *Mem = C.Allocate(sizeof(OpenACCNumWorkersClause),
177 alignof(OpenACCNumWorkersClause));
178 return new (Mem)
179 OpenACCNumWorkersClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
180 }
181
182 OpenACCCollapseClause::OpenACCCollapseClause(SourceLocation BeginLoc,
183 SourceLocation LParenLoc,
184 bool HasForce, Expr *LoopCount,
185 SourceLocation EndLoc)
186 : OpenACCClauseWithSingleIntExpr(OpenACCClauseKind::Collapse, BeginLoc,
187 LParenLoc, LoopCount, EndLoc),
188 HasForce(HasForce) {}
189
190 OpenACCCollapseClause *
191 OpenACCCollapseClause::Create(const ASTContext &C, SourceLocation BeginLoc,
192 SourceLocation LParenLoc, bool HasForce,
193 Expr *LoopCount, SourceLocation EndLoc) {
194 assert((!LoopCount || (LoopCount->isInstantiationDependent() ||
195 isa<ConstantExpr>(LoopCount))) &&
196 "Loop count not constant expression");
197 void *Mem =
198 C.Allocate(sizeof(OpenACCCollapseClause), alignof(OpenACCCollapseClause));
199 return new (Mem)
200 OpenACCCollapseClause(BeginLoc, LParenLoc, HasForce, LoopCount, EndLoc);
201 }
202
203 OpenACCVectorLengthClause::OpenACCVectorLengthClause(SourceLocation BeginLoc,
204 SourceLocation LParenLoc,
205 Expr *IntExpr,
206 SourceLocation EndLoc)
207 : OpenACCClauseWithSingleIntExpr(OpenACCClauseKind::VectorLength, BeginLoc,
208 LParenLoc, IntExpr, EndLoc) {
209 assert((!IntExpr || IntExpr->isInstantiationDependent() ||
210 IntExpr->getType()->isIntegerType()) &&
211 "Condition expression type not scalar/dependent");
212 }
213
214 OpenACCVectorLengthClause *
215 OpenACCVectorLengthClause::Create(const ASTContext &C, SourceLocation BeginLoc,
216 SourceLocation LParenLoc, Expr *IntExpr,
217 SourceLocation EndLoc) {
218 void *Mem = C.Allocate(sizeof(OpenACCVectorLengthClause),
219 alignof(OpenACCVectorLengthClause));
220 return new (Mem)
221 OpenACCVectorLengthClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
222 }
223
224 OpenACCAsyncClause::OpenACCAsyncClause(SourceLocation BeginLoc,
225 SourceLocation LParenLoc, Expr *IntExpr,
226 SourceLocation EndLoc)
227 : OpenACCClauseWithSingleIntExpr(OpenACCClauseKind::Async, BeginLoc,
228 LParenLoc, IntExpr, EndLoc) {
229 assert((!IntExpr || IntExpr->isInstantiationDependent() ||
230 IntExpr->getType()->isIntegerType()) &&
231 "Condition expression type not scalar/dependent");
232 }
233
234 OpenACCAsyncClause *OpenACCAsyncClause::Create(const ASTContext &C,
235 SourceLocation BeginLoc,
236 SourceLocation LParenLoc,
237 Expr *IntExpr,
238 SourceLocation EndLoc) {
239 void *Mem =
240 C.Allocate(sizeof(OpenACCAsyncClause), alignof(OpenACCAsyncClause));
241 return new (Mem) OpenACCAsyncClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
242 }
243
244 OpenACCDeviceNumClause::OpenACCDeviceNumClause(SourceLocation BeginLoc,
245 SourceLocation LParenLoc, Expr *IntExpr,
246 SourceLocation EndLoc)
247 : OpenACCClauseWithSingleIntExpr(OpenACCClauseKind::DeviceNum, BeginLoc,
248 LParenLoc, IntExpr, EndLoc) {
249 assert((IntExpr->isInstantiationDependent() ||
250 IntExpr->getType()->isIntegerType()) &&
251 "device_num expression type not scalar/dependent");
252 }
253
254 OpenACCDeviceNumClause *OpenACCDeviceNumClause::Create(const ASTContext &C,
255 SourceLocation BeginLoc,
256 SourceLocation LParenLoc,
257 Expr *IntExpr,
258 SourceLocation EndLoc) {
259 void *Mem =
260 C.Allocate(sizeof(OpenACCDeviceNumClause), alignof(OpenACCDeviceNumClause));
261 return new (Mem) OpenACCDeviceNumClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
262 }
263
264 OpenACCDefaultAsyncClause::OpenACCDefaultAsyncClause(SourceLocation BeginLoc,
265 SourceLocation LParenLoc,
266 Expr *IntExpr,
267 SourceLocation EndLoc)
268 : OpenACCClauseWithSingleIntExpr(OpenACCClauseKind::DefaultAsync, BeginLoc,
269 LParenLoc, IntExpr, EndLoc) {
270 assert((IntExpr->isInstantiationDependent() ||
271 IntExpr->getType()->isIntegerType()) &&
272 "default_async expression type not scalar/dependent");
273 }
274
275 OpenACCDefaultAsyncClause *
276 OpenACCDefaultAsyncClause::Create(const ASTContext &C, SourceLocation BeginLoc,
277 SourceLocation LParenLoc, Expr *IntExpr,
278 SourceLocation EndLoc) {
279 void *Mem = C.Allocate(sizeof(OpenACCDefaultAsyncClause),
280 alignof(OpenACCDefaultAsyncClause));
281 return new (Mem)
282 OpenACCDefaultAsyncClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
283 }
284
285 OpenACCWaitClause *OpenACCWaitClause::Create(
286 const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
287 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
288 SourceLocation EndLoc) {
289 // Allocates enough room in trailing storage for all the int-exprs, plus a
290 // placeholder for the devnum.
291 void *Mem = C.Allocate(
292 OpenACCWaitClause::totalSizeToAlloc<Expr *>(QueueIdExprs.size() + 1));
293 return new (Mem) OpenACCWaitClause(BeginLoc, LParenLoc, DevNumExpr, QueuesLoc,
294 QueueIdExprs, EndLoc);
295 }
296
297 OpenACCNumGangsClause *OpenACCNumGangsClause::Create(const ASTContext &C,
298 SourceLocation BeginLoc,
299 SourceLocation LParenLoc,
300 ArrayRef<Expr *> IntExprs,
301 SourceLocation EndLoc) {
302 void *Mem = C.Allocate(
303 OpenACCNumGangsClause::totalSizeToAlloc<Expr *>(IntExprs.size()));
304 return new (Mem) OpenACCNumGangsClause(BeginLoc, LParenLoc, IntExprs, EndLoc);
305 }
306
307 OpenACCTileClause *OpenACCTileClause::Create(const ASTContext &C,
308 SourceLocation BeginLoc,
309 SourceLocation LParenLoc,
310 ArrayRef<Expr *> SizeExprs,
311 SourceLocation EndLoc) {
312 void *Mem =
313 C.Allocate(OpenACCTileClause::totalSizeToAlloc<Expr *>(SizeExprs.size()));
314 return new (Mem) OpenACCTileClause(BeginLoc, LParenLoc, SizeExprs, EndLoc);
315 }
316
317 OpenACCPrivateClause *
318 OpenACCPrivateClause::Create(const ASTContext &C, SourceLocation BeginLoc,
319 SourceLocation LParenLoc, ArrayRef<Expr *> VarList,
320 ArrayRef<OpenACCPrivateRecipe> InitRecipes,
321 SourceLocation EndLoc) {
322 assert(VarList.size() == InitRecipes.size());
323 void *Mem = C.Allocate(
324 OpenACCPrivateClause::totalSizeToAlloc<Expr *, OpenACCPrivateRecipe>(
325 VarList.size(), InitRecipes.size()));
326 return new (Mem)
327 OpenACCPrivateClause(BeginLoc, LParenLoc, VarList, InitRecipes, EndLoc);
328 }
329
330 OpenACCFirstPrivateClause *OpenACCFirstPrivateClause::Create(
331 const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
332 ArrayRef<Expr *> VarList, ArrayRef<OpenACCFirstPrivateRecipe> InitRecipes,
333 SourceLocation EndLoc) {
334 void *Mem = C.Allocate(
335 OpenACCFirstPrivateClause::totalSizeToAlloc<Expr *,
336 OpenACCFirstPrivateRecipe>(
337 VarList.size(), InitRecipes.size()));
338 return new (Mem) OpenACCFirstPrivateClause(BeginLoc, LParenLoc, VarList,
339 InitRecipes, EndLoc);
340 }
341
342 OpenACCAttachClause *OpenACCAttachClause::Create(const ASTContext &C,
343 SourceLocation BeginLoc,
344 SourceLocation LParenLoc,
345 ArrayRef<Expr *> VarList,
346 SourceLocation EndLoc) {
347 void *Mem =
348 C.Allocate(OpenACCAttachClause::totalSizeToAlloc<Expr *>(VarList.size()));
349 return new (Mem) OpenACCAttachClause(BeginLoc, LParenLoc, VarList, EndLoc);
350 }
351
352 OpenACCDetachClause *OpenACCDetachClause::Create(const ASTContext &C,
353 SourceLocation BeginLoc,
354 SourceLocation LParenLoc,
355 ArrayRef<Expr *> VarList,
356 SourceLocation EndLoc) {
357 void *Mem =
358 C.Allocate(OpenACCDetachClause::totalSizeToAlloc<Expr *>(VarList.size()));
359 return new (Mem) OpenACCDetachClause(BeginLoc, LParenLoc, VarList, EndLoc);
360 }
361
362 OpenACCDeleteClause *OpenACCDeleteClause::Create(const ASTContext &C,
363 SourceLocation BeginLoc,
364 SourceLocation LParenLoc,
365 ArrayRef<Expr *> VarList,
366 SourceLocation EndLoc) {
367 void *Mem =
368 C.Allocate(OpenACCDeleteClause::totalSizeToAlloc<Expr *>(VarList.size()));
369 return new (Mem) OpenACCDeleteClause(BeginLoc, LParenLoc, VarList, EndLoc);
370 }
371
372 OpenACCUseDeviceClause *OpenACCUseDeviceClause::Create(const ASTContext &C,
373 SourceLocation BeginLoc,
374 SourceLocation LParenLoc,
375 ArrayRef<Expr *> VarList,
376 SourceLocation EndLoc) {
377 void *Mem = C.Allocate(
378 OpenACCUseDeviceClause::totalSizeToAlloc<Expr *>(VarList.size()));
379 return new (Mem) OpenACCUseDeviceClause(BeginLoc, LParenLoc, VarList, EndLoc);
380 }
381
382 OpenACCDevicePtrClause *OpenACCDevicePtrClause::Create(const ASTContext &C,
383 SourceLocation BeginLoc,
384 SourceLocation LParenLoc,
385 ArrayRef<Expr *> VarList,
386 SourceLocation EndLoc) {
387 void *Mem = C.Allocate(
388 OpenACCDevicePtrClause::totalSizeToAlloc<Expr *>(VarList.size()));
389 return new (Mem) OpenACCDevicePtrClause(BeginLoc, LParenLoc, VarList, EndLoc);
390 }
391
392 OpenACCNoCreateClause *OpenACCNoCreateClause::Create(const ASTContext &C,
393 SourceLocation BeginLoc,
394 SourceLocation LParenLoc,
395 ArrayRef<Expr *> VarList,
396 SourceLocation EndLoc) {
397 void *Mem = C.Allocate(
398 OpenACCNoCreateClause::totalSizeToAlloc<Expr *>(VarList.size()));
399 return new (Mem) OpenACCNoCreateClause(BeginLoc, LParenLoc, VarList, EndLoc);
400 }
401
402 OpenACCPresentClause *OpenACCPresentClause::Create(const ASTContext &C,
403 SourceLocation BeginLoc,
404 SourceLocation LParenLoc,
405 ArrayRef<Expr *> VarList,
406 SourceLocation EndLoc) {
407 void *Mem = C.Allocate(
408 OpenACCPresentClause::totalSizeToAlloc<Expr *>(VarList.size()));
409 return new (Mem) OpenACCPresentClause(BeginLoc, LParenLoc, VarList, EndLoc);
410 }
411
412 OpenACCHostClause *OpenACCHostClause::Create(const ASTContext &C,
413 SourceLocation BeginLoc,
414 SourceLocation LParenLoc,
415 ArrayRef<Expr *> VarList,
416 SourceLocation EndLoc) {
417 void *Mem =
418 C.Allocate(OpenACCHostClause::totalSizeToAlloc<Expr *>(VarList.size()));
419 return new (Mem) OpenACCHostClause(BeginLoc, LParenLoc, VarList, EndLoc);
420 }
421
422 OpenACCDeviceClause *OpenACCDeviceClause::Create(const ASTContext &C,
423 SourceLocation BeginLoc,
424 SourceLocation LParenLoc,
425 ArrayRef<Expr *> VarList,
426 SourceLocation EndLoc) {
427 void *Mem =
428 C.Allocate(OpenACCDeviceClause::totalSizeToAlloc<Expr *>(VarList.size()));
429 return new (Mem) OpenACCDeviceClause(BeginLoc, LParenLoc, VarList, EndLoc);
430 }
431
432 OpenACCCopyClause *
433 OpenACCCopyClause::Create(const ASTContext &C, OpenACCClauseKind Spelling,
434 SourceLocation BeginLoc, SourceLocation LParenLoc,
435 OpenACCModifierKind Mods, ArrayRef<Expr *> VarList,
436 SourceLocation EndLoc) {
437 void *Mem =
438 C.Allocate(OpenACCCopyClause::totalSizeToAlloc<Expr *>(VarList.size()));
439 return new (Mem)
440 OpenACCCopyClause(Spelling, BeginLoc, LParenLoc, Mods, VarList, EndLoc);
441 }
442
443 OpenACCLinkClause *OpenACCLinkClause::Create(const ASTContext &C,
444 SourceLocation BeginLoc,
445 SourceLocation LParenLoc,
446 ArrayRef<Expr *> VarList,
447 SourceLocation EndLoc) {
448 void *Mem =
449 C.Allocate(OpenACCLinkClause::totalSizeToAlloc<Expr *>(VarList.size()));
450 return new (Mem) OpenACCLinkClause(BeginLoc, LParenLoc, VarList, EndLoc);
451 }
452
453 OpenACCDeviceResidentClause *OpenACCDeviceResidentClause::Create(
454 const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
455 ArrayRef<Expr *> VarList, SourceLocation EndLoc) {
456 void *Mem = C.Allocate(
457 OpenACCDeviceResidentClause::totalSizeToAlloc<Expr *>(VarList.size()));
458 return new (Mem)
459 OpenACCDeviceResidentClause(BeginLoc, LParenLoc, VarList, EndLoc);
460 }
461
462 OpenACCCopyInClause *
463 OpenACCCopyInClause::Create(const ASTContext &C, OpenACCClauseKind Spelling,
464 SourceLocation BeginLoc, SourceLocation LParenLoc,
465 OpenACCModifierKind Mods, ArrayRef<Expr *> VarList,
466 SourceLocation EndLoc) {
467 void *Mem =
468 C.Allocate(OpenACCCopyInClause::totalSizeToAlloc<Expr *>(VarList.size()));
469 return new (Mem)
470 OpenACCCopyInClause(Spelling, BeginLoc, LParenLoc, Mods, VarList, EndLoc);
471 }
472
473 OpenACCCopyOutClause *
474 OpenACCCopyOutClause::Create(const ASTContext &C, OpenACCClauseKind Spelling,
475 SourceLocation BeginLoc, SourceLocation LParenLoc,
476 OpenACCModifierKind Mods, ArrayRef<Expr *> VarList,
477 SourceLocation EndLoc) {
478 void *Mem = C.Allocate(
479 OpenACCCopyOutClause::totalSizeToAlloc<Expr *>(VarList.size()));
480 return new (Mem) OpenACCCopyOutClause(Spelling, BeginLoc, LParenLoc, Mods,
481 VarList, EndLoc);
482 }
483
484 OpenACCCreateClause *
485 OpenACCCreateClause::Create(const ASTContext &C, OpenACCClauseKind Spelling,
486 SourceLocation BeginLoc, SourceLocation LParenLoc,
487 OpenACCModifierKind Mods, ArrayRef<Expr *> VarList,
488 SourceLocation EndLoc) {
489 void *Mem =
490 C.Allocate(OpenACCCreateClause::totalSizeToAlloc<Expr *>(VarList.size()));
491 return new (Mem)
492 OpenACCCreateClause(Spelling, BeginLoc, LParenLoc, Mods, VarList, EndLoc);
493 }
494
495 OpenACCDeviceTypeClause *OpenACCDeviceTypeClause::Create(
496 const ASTContext &C, OpenACCClauseKind K, SourceLocation BeginLoc,
497 SourceLocation LParenLoc, ArrayRef<DeviceTypeArgument> Archs,
498 SourceLocation EndLoc) {
499 void *Mem =
500 C.Allocate(OpenACCDeviceTypeClause::totalSizeToAlloc<DeviceTypeArgument>(
501 Archs.size()));
502 return new (Mem)
503 OpenACCDeviceTypeClause(K, BeginLoc, LParenLoc, Archs, EndLoc);
504 }
505
506 OpenACCReductionClause *OpenACCReductionClause::Create(
507 const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
508 OpenACCReductionOperator Operator, ArrayRef<Expr *> VarList,
509 ArrayRef<OpenACCReductionRecipeWithStorage> Recipes,
510 SourceLocation EndLoc) {
511 size_t NumCombiners = llvm::accumulate(
512 Recipes, 0, [](size_t Num, const OpenACCReductionRecipeWithStorage &R) {
513 return Num + R.CombinerRecipes.size();
514 });
515
516 void *Mem = C.Allocate(OpenACCReductionClause::totalSizeToAlloc<
517 Expr *, OpenACCReductionRecipe,
518 OpenACCReductionRecipe::CombinerRecipe>(
519 VarList.size(), Recipes.size(), NumCombiners));
520 return new (Mem) OpenACCReductionClause(BeginLoc, LParenLoc, Operator,
521 VarList, Recipes, EndLoc);
522 }
523
524 OpenACCAutoClause *OpenACCAutoClause::Create(const ASTContext &C,
525 SourceLocation BeginLoc,
526 SourceLocation EndLoc) {
527 void *Mem = C.Allocate(sizeof(OpenACCAutoClause));
528 return new (Mem) OpenACCAutoClause(BeginLoc, EndLoc);
529 }
530
531 OpenACCIndependentClause *
532 OpenACCIndependentClause::Create(const ASTContext &C, SourceLocation BeginLoc,
533 SourceLocation EndLoc) {
534 void *Mem = C.Allocate(sizeof(OpenACCIndependentClause));
535 return new (Mem) OpenACCIndependentClause(BeginLoc, EndLoc);
536 }
537
538 OpenACCSeqClause *OpenACCSeqClause::Create(const ASTContext &C,
539 SourceLocation BeginLoc,
540 SourceLocation EndLoc) {
541 void *Mem = C.Allocate(sizeof(OpenACCSeqClause));
542 return new (Mem) OpenACCSeqClause(BeginLoc, EndLoc);
543 }
544
545 OpenACCNoHostClause *OpenACCNoHostClause::Create(const ASTContext &C,
546 SourceLocation BeginLoc,
547 SourceLocation EndLoc) {
548 void *Mem = C.Allocate(sizeof(OpenACCNoHostClause));
549 return new (Mem) OpenACCNoHostClause(BeginLoc, EndLoc);
550 }
551
552 OpenACCGangClause *
553 OpenACCGangClause::Create(const ASTContext &C, SourceLocation BeginLoc,
554 SourceLocation LParenLoc,
555 ArrayRef<OpenACCGangKind> GangKinds,
556 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc) {
557 void *Mem =
558 C.Allocate(OpenACCGangClause::totalSizeToAlloc<Expr *, OpenACCGangKind>(
559 IntExprs.size(), GangKinds.size()));
560 return new (Mem)
561 OpenACCGangClause(BeginLoc, LParenLoc, GangKinds, IntExprs, EndLoc);
562 }
563
564 OpenACCWorkerClause::OpenACCWorkerClause(SourceLocation BeginLoc,
565 SourceLocation LParenLoc,
566 Expr *IntExpr, SourceLocation EndLoc)
567 : OpenACCClauseWithSingleIntExpr(OpenACCClauseKind::Worker, BeginLoc,
568 LParenLoc, IntExpr, EndLoc) {
569 assert((!IntExpr || IntExpr->isInstantiationDependent() ||
570 IntExpr->getType()->isIntegerType()) &&
571 "Int expression type not scalar/dependent");
572 }
573
574 OpenACCWorkerClause *OpenACCWorkerClause::Create(const ASTContext &C,
575 SourceLocation BeginLoc,
576 SourceLocation LParenLoc,
577 Expr *IntExpr,
578 SourceLocation EndLoc) {
579 void *Mem =
580 C.Allocate(sizeof(OpenACCWorkerClause), alignof(OpenACCWorkerClause));
581 return new (Mem) OpenACCWorkerClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
582 }
583
584 OpenACCVectorClause::OpenACCVectorClause(SourceLocation BeginLoc,
585 SourceLocation LParenLoc,
586 Expr *IntExpr, SourceLocation EndLoc)
587 : OpenACCClauseWithSingleIntExpr(OpenACCClauseKind::Vector, BeginLoc,
588 LParenLoc, IntExpr, EndLoc) {
589 assert((!IntExpr || IntExpr->isInstantiationDependent() ||
590 IntExpr->getType()->isIntegerType()) &&
591 "Int expression type not scalar/dependent");
592 }
593
594 OpenACCVectorClause *OpenACCVectorClause::Create(const ASTContext &C,
595 SourceLocation BeginLoc,
596 SourceLocation LParenLoc,
597 Expr *IntExpr,
598 SourceLocation EndLoc) {
599 void *Mem =
600 C.Allocate(sizeof(OpenACCVectorClause), alignof(OpenACCVectorClause));
601 return new (Mem) OpenACCVectorClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
602 }
603
604 OpenACCFinalizeClause *OpenACCFinalizeClause::Create(const ASTContext &C,
605 SourceLocation BeginLoc,
606 SourceLocation EndLoc) {
607 void *Mem =
608 C.Allocate(sizeof(OpenACCFinalizeClause), alignof(OpenACCFinalizeClause));
609 return new (Mem) OpenACCFinalizeClause(BeginLoc, EndLoc);
610 }
611
612 OpenACCIfPresentClause *OpenACCIfPresentClause::Create(const ASTContext &C,
613 SourceLocation BeginLoc,
614 SourceLocation EndLoc) {
615 void *Mem = C.Allocate(sizeof(OpenACCIfPresentClause),
616 alignof(OpenACCIfPresentClause));
617 return new (Mem) OpenACCIfPresentClause(BeginLoc, EndLoc);
618 }
619
620 OpenACCBindClause *OpenACCBindClause::Create(const ASTContext &C,
621 SourceLocation BeginLoc,
622 SourceLocation LParenLoc,
623 const StringLiteral *SL,
624 SourceLocation EndLoc) {
625 void *Mem = C.Allocate(sizeof(OpenACCBindClause), alignof(OpenACCBindClause));
626 return new (Mem) OpenACCBindClause(BeginLoc, LParenLoc, SL, EndLoc);
627 }
628
629 OpenACCBindClause *OpenACCBindClause::Create(const ASTContext &C,
630 SourceLocation BeginLoc,
631 SourceLocation LParenLoc,
632 const IdentifierInfo *ID,
633 SourceLocation EndLoc) {
634 void *Mem = C.Allocate(sizeof(OpenACCBindClause), alignof(OpenACCBindClause));
635 return new (Mem) OpenACCBindClause(BeginLoc, LParenLoc, ID, EndLoc);
636 }
637
638 bool clang::operator==(const OpenACCBindClause &LHS,
639 const OpenACCBindClause &RHS) {
640 if (LHS.isStringArgument() != RHS.isStringArgument())
641 return false;
642
643 if (LHS.isStringArgument())
644 return LHS.getStringArgument()->getString() ==
645 RHS.getStringArgument()->getString();
646 return LHS.getIdentifierArgument()->getName() ==
647 RHS.getIdentifierArgument()->getName();
648 }
649
650 //===----------------------------------------------------------------------===//
651 // OpenACC clauses printing methods
652 //===----------------------------------------------------------------------===//
653
654 void OpenACCClausePrinter::printExpr(const Expr *E) {
655 E->printPretty(OS, nullptr, Policy, 0);
656 }
657
658 void OpenACCClausePrinter::VisitDefaultClause(const OpenACCDefaultClause &C) {
659 OS << "default(" << C.getDefaultClauseKind() << ")";
660 }
661
662 void OpenACCClausePrinter::VisitIfClause(const OpenACCIfClause &C) {
663 OS << "if(";
664 printExpr(C.getConditionExpr());
665 OS << ")";
666 }
667
668 void OpenACCClausePrinter::VisitSelfClause(const OpenACCSelfClause &C) {
669 OS << "self";
670
671 if (C.isConditionExprClause()) {
672 if (const Expr *CondExpr = C.getConditionExpr()) {
673 OS << "(";
674 printExpr(CondExpr);
675 OS << ")";
676 }
677 } else {
678 OS << "(";
679 llvm::interleaveComma(C.getVarList(), OS,
680 [&](const Expr *E) { printExpr(E); });
681 OS << ")";
682 }
683 }
684
685 void OpenACCClausePrinter::VisitNumGangsClause(const OpenACCNumGangsClause &C) {
686 OS << "num_gangs(";
687 llvm::interleaveComma(C.getIntExprs(), OS,
688 [&](const Expr *E) { printExpr(E); });
689 OS << ")";
690 }
691
692 void OpenACCClausePrinter::VisitTileClause(const OpenACCTileClause &C) {
693 OS << "tile(";
694 llvm::interleaveComma(C.getSizeExprs(), OS,
695 [&](const Expr *E) { printExpr(E); });
696 OS << ")";
697 }
698
699 void OpenACCClausePrinter::VisitNumWorkersClause(
700 const OpenACCNumWorkersClause &C) {
701 OS << "num_workers(";
702 printExpr(C.getIntExpr());
703 OS << ")";
704 }
705
706 void OpenACCClausePrinter::VisitVectorLengthClause(
707 const OpenACCVectorLengthClause &C) {
708 OS << "vector_length(";
709 printExpr(C.getIntExpr());
710 OS << ")";
711 }
712
713 void OpenACCClausePrinter::VisitDeviceNumClause(
714 const OpenACCDeviceNumClause &C) {
715 OS << "device_num(";
716 printExpr(C.getIntExpr());
717 OS << ")";
718 }
719
720 void OpenACCClausePrinter::VisitDefaultAsyncClause(
721 const OpenACCDefaultAsyncClause &C) {
722 OS << "default_async(";
723 printExpr(C.getIntExpr());
724 OS << ")";
725 }
726
727 void OpenACCClausePrinter::VisitAsyncClause(const OpenACCAsyncClause &C) {
728 OS << "async";
729 if (C.hasIntExpr()) {
730 OS << "(";
731 printExpr(C.getIntExpr());
732 OS << ")";
733 }
734 }
735
736 void OpenACCClausePrinter::VisitPrivateClause(const OpenACCPrivateClause &C) {
737 OS << "private(";
738 llvm::interleaveComma(C.getVarList(), OS,
739 [&](const Expr *E) { printExpr(E); });
740 OS << ")";
741 }
742
743 void OpenACCClausePrinter::VisitFirstPrivateClause(
744 const OpenACCFirstPrivateClause &C) {
745 OS << "firstprivate(";
746 llvm::interleaveComma(C.getVarList(), OS,
747 [&](const Expr *E) { printExpr(E); });
748 OS << ")";
749 }
750
751 void OpenACCClausePrinter::VisitAttachClause(const OpenACCAttachClause &C) {
752 OS << "attach(";
753 llvm::interleaveComma(C.getVarList(), OS,
754 [&](const Expr *E) { printExpr(E); });
755 OS << ")";
756 }
757
758 void OpenACCClausePrinter::VisitDetachClause(const OpenACCDetachClause &C) {
759 OS << "detach(";
760 llvm::interleaveComma(C.getVarList(), OS,
761 [&](const Expr *E) { printExpr(E); });
762 OS << ")";
763 }
764
765 void OpenACCClausePrinter::VisitDeleteClause(const OpenACCDeleteClause &C) {
766 OS << "delete(";
767 llvm::interleaveComma(C.getVarList(), OS,
768 [&](const Expr *E) { printExpr(E); });
769 OS << ")";
770 }
771
772 void OpenACCClausePrinter::VisitUseDeviceClause(
773 const OpenACCUseDeviceClause &C) {
774 OS << "use_device(";
775 llvm::interleaveComma(C.getVarList(), OS,
776 [&](const Expr *E) { printExpr(E); });
777 OS << ")";
778 }
779
780 void OpenACCClausePrinter::VisitDevicePtrClause(
781 const OpenACCDevicePtrClause &C) {
782 OS << "deviceptr(";
783 llvm::interleaveComma(C.getVarList(), OS,
784 [&](const Expr *E) { printExpr(E); });
785 OS << ")";
786 }
787
788 void OpenACCClausePrinter::VisitNoCreateClause(const OpenACCNoCreateClause &C) {
789 OS << "no_create(";
790 llvm::interleaveComma(C.getVarList(), OS,
791 [&](const Expr *E) { printExpr(E); });
792 OS << ")";
793 }
794
795 void OpenACCClausePrinter::VisitPresentClause(const OpenACCPresentClause &C) {
796 OS << "present(";
797 llvm::interleaveComma(C.getVarList(), OS,
798 [&](const Expr *E) { printExpr(E); });
799 OS << ")";
800 }
801
802 void OpenACCClausePrinter::VisitHostClause(const OpenACCHostClause &C) {
803 OS << "host(";
804 llvm::interleaveComma(C.getVarList(), OS,
805 [&](const Expr *E) { printExpr(E); });
806 OS << ")";
807 }
808
809 void OpenACCClausePrinter::VisitDeviceClause(const OpenACCDeviceClause &C) {
810 OS << "device(";
811 llvm::interleaveComma(C.getVarList(), OS,
812 [&](const Expr *E) { printExpr(E); });
813 OS << ")";
814 }
815
816 void OpenACCClausePrinter::VisitCopyClause(const OpenACCCopyClause &C) {
817 OS << C.getClauseKind() << '(';
818 if (C.getModifierList() != OpenACCModifierKind::Invalid)
819 OS << C.getModifierList() << ": ";
820 llvm::interleaveComma(C.getVarList(), OS,
821 [&](const Expr *E) { printExpr(E); });
822 OS << ")";
823 }
824
825 void OpenACCClausePrinter::VisitLinkClause(const OpenACCLinkClause &C) {
826 OS << "link(";
827 llvm::interleaveComma(C.getVarList(), OS,
828 [&](const Expr *E) { printExpr(E); });
829 OS << ")";
830 }
831
832 void OpenACCClausePrinter::VisitDeviceResidentClause(
833 const OpenACCDeviceResidentClause &C) {
834 OS << "device_resident(";
835 llvm::interleaveComma(C.getVarList(), OS,
836 [&](const Expr *E) { printExpr(E); });
837 OS << ")";
838 }
839
840 void OpenACCClausePrinter::VisitCopyInClause(const OpenACCCopyInClause &C) {
841 OS << C.getClauseKind() << '(';
842 if (C.getModifierList() != OpenACCModifierKind::Invalid)
843 OS << C.getModifierList() << ": ";
844 llvm::interleaveComma(C.getVarList(), OS,
845 [&](const Expr *E) { printExpr(E); });
846 OS << ")";
847 }
848
849 void OpenACCClausePrinter::VisitCopyOutClause(const OpenACCCopyOutClause &C) {
850 OS << C.getClauseKind() << '(';
851 if (C.getModifierList() != OpenACCModifierKind::Invalid)
852 OS << C.getModifierList() << ": ";
853 llvm::interleaveComma(C.getVarList(), OS,
854 [&](const Expr *E) { printExpr(E); });
855 OS << ")";
856 }
857
858 void OpenACCClausePrinter::VisitCreateClause(const OpenACCCreateClause &C) {
859 OS << C.getClauseKind() << '(';
860 if (C.getModifierList() != OpenACCModifierKind::Invalid)
861 OS << C.getModifierList() << ": ";
862 llvm::interleaveComma(C.getVarList(), OS,
863 [&](const Expr *E) { printExpr(E); });
864 OS << ")";
865 }
866
867 void OpenACCClausePrinter::VisitReductionClause(
868 const OpenACCReductionClause &C) {
869 OS << "reduction(" << C.getReductionOp() << ": ";
870 llvm::interleaveComma(C.getVarList(), OS,
871 [&](const Expr *E) { printExpr(E); });
872 OS << ")";
873 }
874
875 void OpenACCClausePrinter::VisitWaitClause(const OpenACCWaitClause &C) {
876 OS << "wait";
877 if (C.hasExprs()) {
878 OS << "(";
879 if (C.hasDevNumExpr()) {
880 OS << "devnum: ";
881 printExpr(C.getDevNumExpr());
882 OS << " : ";
883 }
884
885 if (C.hasQueuesTag())
886 OS << "queues: ";
887
888 llvm::interleaveComma(C.getQueueIdExprs(), OS,
889 [&](const Expr *E) { printExpr(E); });
890 OS << ")";
891 }
892 }
893
894 void OpenACCClausePrinter::VisitDeviceTypeClause(
895 const OpenACCDeviceTypeClause &C) {
896 OS << C.getClauseKind();
897 OS << "(";
898 llvm::interleaveComma(C.getArchitectures(), OS,
899 [&](const DeviceTypeArgument &Arch) {
900 if (Arch.getIdentifierInfo() == nullptr)
901 OS << "*";
902 else
903 OS << Arch.getIdentifierInfo()->getName();
904 });
905 OS << ")";
906 }
907
908 void OpenACCClausePrinter::VisitAutoClause(const OpenACCAutoClause &C) {
909 OS << "auto";
910 }
911
912 void OpenACCClausePrinter::VisitIndependentClause(
913 const OpenACCIndependentClause &C) {
914 OS << "independent";
915 }
916
917 void OpenACCClausePrinter::VisitSeqClause(const OpenACCSeqClause &C) {
918 OS << "seq";
919 }
920
921 void OpenACCClausePrinter::VisitNoHostClause(const OpenACCNoHostClause &C) {
922 OS << "nohost";
923 }
924
925 void OpenACCClausePrinter::VisitCollapseClause(const OpenACCCollapseClause &C) {
926 OS << "collapse(";
927 if (C.hasForce())
928 OS << "force:";
929 printExpr(C.getLoopCount());
930 OS << ")";
931 }
932
933 void OpenACCClausePrinter::VisitGangClause(const OpenACCGangClause &C) {
934 OS << "gang";
935
936 if (C.getNumExprs() > 0) {
937 OS << "(";
938 bool first = true;
939 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
940 if (!first)
941 OS << ", ";
942 first = false;
943
944 OS << C.getExpr(I).first << ": ";
945 printExpr(C.getExpr(I).second);
946 }
947 OS << ")";
948 }
949 }
950
951 void OpenACCClausePrinter::VisitWorkerClause(const OpenACCWorkerClause &C) {
952 OS << "worker";
953
954 if (C.hasIntExpr()) {
955 OS << "(num: ";
956 printExpr(C.getIntExpr());
957 OS << ")";
958 }
959 }
960
961 void OpenACCClausePrinter::VisitVectorClause(const OpenACCVectorClause &C) {
962 OS << "vector";
963
964 if (C.hasIntExpr()) {
965 OS << "(length: ";
966 printExpr(C.getIntExpr());
967 OS << ")";
968 }
969 }
970
971 void OpenACCClausePrinter::VisitFinalizeClause(const OpenACCFinalizeClause &C) {
972 OS << "finalize";
973 }
974
975 void OpenACCClausePrinter::VisitIfPresentClause(
976 const OpenACCIfPresentClause &C) {
977 OS << "if_present";
978 }
979
980 void OpenACCClausePrinter::VisitBindClause(const OpenACCBindClause &C) {
981 OS << "bind(";
982 if (C.isStringArgument())
983 OS << '"' << C.getStringArgument()->getString() << '"';
984 else
985 OS << C.getIdentifierArgument()->getName();
986 OS << ")";
987 }