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
18using namespace clang;
19
20bool 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}
26bool 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}
32bool 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}
48bool OpenACCClauseWithCondition::classof(const OpenACCClause *C) {
49 return OpenACCIfClause::classof(C);
50}
51bool 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}
59OpenACCDefaultClause *OpenACCDefaultClause::Create(const ASTContext &C,
60 OpenACCDefaultClauseKind K,
61 SourceLocation BeginLoc,
62 SourceLocation LParenLoc,
63 SourceLocation EndLoc) {
64 void *Mem =
65 C.Allocate(Size: sizeof(OpenACCDefaultClause), Align: alignof(OpenACCDefaultClause));
66
67 return new (Mem) OpenACCDefaultClause(K, BeginLoc, LParenLoc, EndLoc);
68}
69
70OpenACCIfClause *OpenACCIfClause::Create(const ASTContext &C,
71 SourceLocation BeginLoc,
72 SourceLocation LParenLoc,
73 Expr *ConditionExpr,
74 SourceLocation EndLoc) {
75 void *Mem = C.Allocate(Size: sizeof(OpenACCIfClause), Align: alignof(OpenACCIfClause));
76 return new (Mem) OpenACCIfClause(BeginLoc, LParenLoc, ConditionExpr, EndLoc);
77}
78
79OpenACCIfClause::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
90OpenACCSelfClause *OpenACCSelfClause::Create(const ASTContext &C,
91 SourceLocation BeginLoc,
92 SourceLocation LParenLoc,
93 Expr *ConditionExpr,
94 SourceLocation EndLoc) {
95 void *Mem = C.Allocate(Size: OpenACCSelfClause::totalSizeToAlloc<Expr *>(Counts: 1));
96 return new (Mem)
97 OpenACCSelfClause(BeginLoc, LParenLoc, ConditionExpr, EndLoc);
98}
99
100OpenACCSelfClause *OpenACCSelfClause::Create(const ASTContext &C,
101 SourceLocation BeginLoc,
102 SourceLocation LParenLoc,
103 ArrayRef<Expr *> VarList,
104 SourceLocation EndLoc) {
105 void *Mem =
106 C.Allocate(Size: OpenACCSelfClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
107 return new (Mem) OpenACCSelfClause(BeginLoc, LParenLoc, VarList, EndLoc);
108}
109
110OpenACCSelfClause::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(Src&: VarList, Dst: getTrailingObjects());
118}
119
120OpenACCSelfClause::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(Src: ArrayRef(ConditionExpr), Dst: getTrailingObjects());
130}
131
132OpenACCClause::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
149OpenACCNumWorkersClause::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
160OpenACCGangClause::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(NewStorage: getTrailingObjects<Expr *>(N: IntExprs.size()), Exprs: IntExprs);
169 llvm::uninitialized_copy(Src&: GangKinds, Dst: getTrailingObjects<OpenACCGangKind>());
170}
171
172OpenACCNumWorkersClause *
173OpenACCNumWorkersClause::Create(const ASTContext &C, SourceLocation BeginLoc,
174 SourceLocation LParenLoc, Expr *IntExpr,
175 SourceLocation EndLoc) {
176 void *Mem = C.Allocate(Size: sizeof(OpenACCNumWorkersClause),
177 Align: alignof(OpenACCNumWorkersClause));
178 return new (Mem)
179 OpenACCNumWorkersClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
180}
181
182OpenACCCollapseClause::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
190OpenACCCollapseClause *
191OpenACCCollapseClause::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(Size: sizeof(OpenACCCollapseClause), Align: alignof(OpenACCCollapseClause));
199 return new (Mem)
200 OpenACCCollapseClause(BeginLoc, LParenLoc, HasForce, LoopCount, EndLoc);
201}
202
203OpenACCVectorLengthClause::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
214OpenACCVectorLengthClause *
215OpenACCVectorLengthClause::Create(const ASTContext &C, SourceLocation BeginLoc,
216 SourceLocation LParenLoc, Expr *IntExpr,
217 SourceLocation EndLoc) {
218 void *Mem = C.Allocate(Size: sizeof(OpenACCVectorLengthClause),
219 Align: alignof(OpenACCVectorLengthClause));
220 return new (Mem)
221 OpenACCVectorLengthClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
222}
223
224OpenACCAsyncClause::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
234OpenACCAsyncClause *OpenACCAsyncClause::Create(const ASTContext &C,
235 SourceLocation BeginLoc,
236 SourceLocation LParenLoc,
237 Expr *IntExpr,
238 SourceLocation EndLoc) {
239 void *Mem =
240 C.Allocate(Size: sizeof(OpenACCAsyncClause), Align: alignof(OpenACCAsyncClause));
241 return new (Mem) OpenACCAsyncClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
242}
243
244OpenACCDeviceNumClause::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
254OpenACCDeviceNumClause *OpenACCDeviceNumClause::Create(const ASTContext &C,
255 SourceLocation BeginLoc,
256 SourceLocation LParenLoc,
257 Expr *IntExpr,
258 SourceLocation EndLoc) {
259 void *Mem =
260 C.Allocate(Size: sizeof(OpenACCDeviceNumClause), Align: alignof(OpenACCDeviceNumClause));
261 return new (Mem) OpenACCDeviceNumClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
262}
263
264OpenACCDefaultAsyncClause::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
275OpenACCDefaultAsyncClause *
276OpenACCDefaultAsyncClause::Create(const ASTContext &C, SourceLocation BeginLoc,
277 SourceLocation LParenLoc, Expr *IntExpr,
278 SourceLocation EndLoc) {
279 void *Mem = C.Allocate(Size: sizeof(OpenACCDefaultAsyncClause),
280 Align: alignof(OpenACCDefaultAsyncClause));
281 return new (Mem)
282 OpenACCDefaultAsyncClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
283}
284
285OpenACCWaitClause *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 Size: OpenACCWaitClause::totalSizeToAlloc<Expr *>(Counts: QueueIdExprs.size() + 1));
293 return new (Mem) OpenACCWaitClause(BeginLoc, LParenLoc, DevNumExpr, QueuesLoc,
294 QueueIdExprs, EndLoc);
295}
296
297OpenACCNumGangsClause *OpenACCNumGangsClause::Create(const ASTContext &C,
298 SourceLocation BeginLoc,
299 SourceLocation LParenLoc,
300 ArrayRef<Expr *> IntExprs,
301 SourceLocation EndLoc) {
302 void *Mem = C.Allocate(
303 Size: OpenACCNumGangsClause::totalSizeToAlloc<Expr *>(Counts: IntExprs.size()));
304 return new (Mem) OpenACCNumGangsClause(BeginLoc, LParenLoc, IntExprs, EndLoc);
305}
306
307OpenACCTileClause *OpenACCTileClause::Create(const ASTContext &C,
308 SourceLocation BeginLoc,
309 SourceLocation LParenLoc,
310 ArrayRef<Expr *> SizeExprs,
311 SourceLocation EndLoc) {
312 void *Mem =
313 C.Allocate(Size: OpenACCTileClause::totalSizeToAlloc<Expr *>(Counts: SizeExprs.size()));
314 return new (Mem) OpenACCTileClause(BeginLoc, LParenLoc, SizeExprs, EndLoc);
315}
316
317OpenACCPrivateClause *
318OpenACCPrivateClause::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 Size: OpenACCPrivateClause::totalSizeToAlloc<Expr *, OpenACCPrivateRecipe>(
325 Counts: VarList.size(), Counts: InitRecipes.size()));
326 return new (Mem)
327 OpenACCPrivateClause(BeginLoc, LParenLoc, VarList, InitRecipes, EndLoc);
328}
329
330OpenACCFirstPrivateClause *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 Size: OpenACCFirstPrivateClause::totalSizeToAlloc<Expr *,
336 OpenACCFirstPrivateRecipe>(
337 Counts: VarList.size(), Counts: InitRecipes.size()));
338 return new (Mem) OpenACCFirstPrivateClause(BeginLoc, LParenLoc, VarList,
339 InitRecipes, EndLoc);
340}
341
342OpenACCAttachClause *OpenACCAttachClause::Create(const ASTContext &C,
343 SourceLocation BeginLoc,
344 SourceLocation LParenLoc,
345 ArrayRef<Expr *> VarList,
346 SourceLocation EndLoc) {
347 void *Mem =
348 C.Allocate(Size: OpenACCAttachClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
349 return new (Mem) OpenACCAttachClause(BeginLoc, LParenLoc, VarList, EndLoc);
350}
351
352OpenACCDetachClause *OpenACCDetachClause::Create(const ASTContext &C,
353 SourceLocation BeginLoc,
354 SourceLocation LParenLoc,
355 ArrayRef<Expr *> VarList,
356 SourceLocation EndLoc) {
357 void *Mem =
358 C.Allocate(Size: OpenACCDetachClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
359 return new (Mem) OpenACCDetachClause(BeginLoc, LParenLoc, VarList, EndLoc);
360}
361
362OpenACCDeleteClause *OpenACCDeleteClause::Create(const ASTContext &C,
363 SourceLocation BeginLoc,
364 SourceLocation LParenLoc,
365 ArrayRef<Expr *> VarList,
366 SourceLocation EndLoc) {
367 void *Mem =
368 C.Allocate(Size: OpenACCDeleteClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
369 return new (Mem) OpenACCDeleteClause(BeginLoc, LParenLoc, VarList, EndLoc);
370}
371
372OpenACCUseDeviceClause *OpenACCUseDeviceClause::Create(const ASTContext &C,
373 SourceLocation BeginLoc,
374 SourceLocation LParenLoc,
375 ArrayRef<Expr *> VarList,
376 SourceLocation EndLoc) {
377 void *Mem = C.Allocate(
378 Size: OpenACCUseDeviceClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
379 return new (Mem) OpenACCUseDeviceClause(BeginLoc, LParenLoc, VarList, EndLoc);
380}
381
382OpenACCDevicePtrClause *OpenACCDevicePtrClause::Create(const ASTContext &C,
383 SourceLocation BeginLoc,
384 SourceLocation LParenLoc,
385 ArrayRef<Expr *> VarList,
386 SourceLocation EndLoc) {
387 void *Mem = C.Allocate(
388 Size: OpenACCDevicePtrClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
389 return new (Mem) OpenACCDevicePtrClause(BeginLoc, LParenLoc, VarList, EndLoc);
390}
391
392OpenACCNoCreateClause *OpenACCNoCreateClause::Create(const ASTContext &C,
393 SourceLocation BeginLoc,
394 SourceLocation LParenLoc,
395 ArrayRef<Expr *> VarList,
396 SourceLocation EndLoc) {
397 void *Mem = C.Allocate(
398 Size: OpenACCNoCreateClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
399 return new (Mem) OpenACCNoCreateClause(BeginLoc, LParenLoc, VarList, EndLoc);
400}
401
402OpenACCPresentClause *OpenACCPresentClause::Create(const ASTContext &C,
403 SourceLocation BeginLoc,
404 SourceLocation LParenLoc,
405 ArrayRef<Expr *> VarList,
406 SourceLocation EndLoc) {
407 void *Mem = C.Allocate(
408 Size: OpenACCPresentClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
409 return new (Mem) OpenACCPresentClause(BeginLoc, LParenLoc, VarList, EndLoc);
410}
411
412OpenACCHostClause *OpenACCHostClause::Create(const ASTContext &C,
413 SourceLocation BeginLoc,
414 SourceLocation LParenLoc,
415 ArrayRef<Expr *> VarList,
416 SourceLocation EndLoc) {
417 void *Mem =
418 C.Allocate(Size: OpenACCHostClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
419 return new (Mem) OpenACCHostClause(BeginLoc, LParenLoc, VarList, EndLoc);
420}
421
422OpenACCDeviceClause *OpenACCDeviceClause::Create(const ASTContext &C,
423 SourceLocation BeginLoc,
424 SourceLocation LParenLoc,
425 ArrayRef<Expr *> VarList,
426 SourceLocation EndLoc) {
427 void *Mem =
428 C.Allocate(Size: OpenACCDeviceClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
429 return new (Mem) OpenACCDeviceClause(BeginLoc, LParenLoc, VarList, EndLoc);
430}
431
432OpenACCCopyClause *
433OpenACCCopyClause::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(Size: OpenACCCopyClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
439 return new (Mem)
440 OpenACCCopyClause(Spelling, BeginLoc, LParenLoc, Mods, VarList, EndLoc);
441}
442
443OpenACCLinkClause *OpenACCLinkClause::Create(const ASTContext &C,
444 SourceLocation BeginLoc,
445 SourceLocation LParenLoc,
446 ArrayRef<Expr *> VarList,
447 SourceLocation EndLoc) {
448 void *Mem =
449 C.Allocate(Size: OpenACCLinkClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
450 return new (Mem) OpenACCLinkClause(BeginLoc, LParenLoc, VarList, EndLoc);
451}
452
453OpenACCDeviceResidentClause *OpenACCDeviceResidentClause::Create(
454 const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
455 ArrayRef<Expr *> VarList, SourceLocation EndLoc) {
456 void *Mem = C.Allocate(
457 Size: OpenACCDeviceResidentClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
458 return new (Mem)
459 OpenACCDeviceResidentClause(BeginLoc, LParenLoc, VarList, EndLoc);
460}
461
462OpenACCCopyInClause *
463OpenACCCopyInClause::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(Size: OpenACCCopyInClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
469 return new (Mem)
470 OpenACCCopyInClause(Spelling, BeginLoc, LParenLoc, Mods, VarList, EndLoc);
471}
472
473OpenACCCopyOutClause *
474OpenACCCopyOutClause::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 Size: OpenACCCopyOutClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
480 return new (Mem) OpenACCCopyOutClause(Spelling, BeginLoc, LParenLoc, Mods,
481 VarList, EndLoc);
482}
483
484OpenACCCreateClause *
485OpenACCCreateClause::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(Size: OpenACCCreateClause::totalSizeToAlloc<Expr *>(Counts: VarList.size()));
491 return new (Mem)
492 OpenACCCreateClause(Spelling, BeginLoc, LParenLoc, Mods, VarList, EndLoc);
493}
494
495OpenACCDeviceTypeClause *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(Size: OpenACCDeviceTypeClause::totalSizeToAlloc<DeviceTypeArgument>(
501 Counts: Archs.size()));
502 return new (Mem)
503 OpenACCDeviceTypeClause(K, BeginLoc, LParenLoc, Archs, EndLoc);
504}
505
506OpenACCReductionClause *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 Range&: Recipes, Init: 0, Op: [](size_t Num, const OpenACCReductionRecipeWithStorage &R) {
513 return Num + R.CombinerRecipes.size();
514 });
515
516 void *Mem = C.Allocate(Size: OpenACCReductionClause::totalSizeToAlloc<
517 Expr *, OpenACCReductionRecipe,
518 OpenACCReductionRecipe::CombinerRecipe>(
519 Counts: VarList.size(), Counts: Recipes.size(), Counts: NumCombiners));
520 return new (Mem) OpenACCReductionClause(BeginLoc, LParenLoc, Operator,
521 VarList, Recipes, EndLoc);
522}
523
524OpenACCAutoClause *OpenACCAutoClause::Create(const ASTContext &C,
525 SourceLocation BeginLoc,
526 SourceLocation EndLoc) {
527 void *Mem = C.Allocate(Size: sizeof(OpenACCAutoClause));
528 return new (Mem) OpenACCAutoClause(BeginLoc, EndLoc);
529}
530
531OpenACCIndependentClause *
532OpenACCIndependentClause::Create(const ASTContext &C, SourceLocation BeginLoc,
533 SourceLocation EndLoc) {
534 void *Mem = C.Allocate(Size: sizeof(OpenACCIndependentClause));
535 return new (Mem) OpenACCIndependentClause(BeginLoc, EndLoc);
536}
537
538OpenACCSeqClause *OpenACCSeqClause::Create(const ASTContext &C,
539 SourceLocation BeginLoc,
540 SourceLocation EndLoc) {
541 void *Mem = C.Allocate(Size: sizeof(OpenACCSeqClause));
542 return new (Mem) OpenACCSeqClause(BeginLoc, EndLoc);
543}
544
545OpenACCNoHostClause *OpenACCNoHostClause::Create(const ASTContext &C,
546 SourceLocation BeginLoc,
547 SourceLocation EndLoc) {
548 void *Mem = C.Allocate(Size: sizeof(OpenACCNoHostClause));
549 return new (Mem) OpenACCNoHostClause(BeginLoc, EndLoc);
550}
551
552OpenACCGangClause *
553OpenACCGangClause::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(Size: OpenACCGangClause::totalSizeToAlloc<Expr *, OpenACCGangKind>(
559 Counts: IntExprs.size(), Counts: GangKinds.size()));
560 return new (Mem)
561 OpenACCGangClause(BeginLoc, LParenLoc, GangKinds, IntExprs, EndLoc);
562}
563
564OpenACCWorkerClause::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
574OpenACCWorkerClause *OpenACCWorkerClause::Create(const ASTContext &C,
575 SourceLocation BeginLoc,
576 SourceLocation LParenLoc,
577 Expr *IntExpr,
578 SourceLocation EndLoc) {
579 void *Mem =
580 C.Allocate(Size: sizeof(OpenACCWorkerClause), Align: alignof(OpenACCWorkerClause));
581 return new (Mem) OpenACCWorkerClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
582}
583
584OpenACCVectorClause::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
594OpenACCVectorClause *OpenACCVectorClause::Create(const ASTContext &C,
595 SourceLocation BeginLoc,
596 SourceLocation LParenLoc,
597 Expr *IntExpr,
598 SourceLocation EndLoc) {
599 void *Mem =
600 C.Allocate(Size: sizeof(OpenACCVectorClause), Align: alignof(OpenACCVectorClause));
601 return new (Mem) OpenACCVectorClause(BeginLoc, LParenLoc, IntExpr, EndLoc);
602}
603
604OpenACCFinalizeClause *OpenACCFinalizeClause::Create(const ASTContext &C,
605 SourceLocation BeginLoc,
606 SourceLocation EndLoc) {
607 void *Mem =
608 C.Allocate(Size: sizeof(OpenACCFinalizeClause), Align: alignof(OpenACCFinalizeClause));
609 return new (Mem) OpenACCFinalizeClause(BeginLoc, EndLoc);
610}
611
612OpenACCIfPresentClause *OpenACCIfPresentClause::Create(const ASTContext &C,
613 SourceLocation BeginLoc,
614 SourceLocation EndLoc) {
615 void *Mem = C.Allocate(Size: sizeof(OpenACCIfPresentClause),
616 Align: alignof(OpenACCIfPresentClause));
617 return new (Mem) OpenACCIfPresentClause(BeginLoc, EndLoc);
618}
619
620OpenACCBindClause *OpenACCBindClause::Create(const ASTContext &C,
621 SourceLocation BeginLoc,
622 SourceLocation LParenLoc,
623 const StringLiteral *SL,
624 SourceLocation EndLoc) {
625 void *Mem = C.Allocate(Size: sizeof(OpenACCBindClause), Align: alignof(OpenACCBindClause));
626 return new (Mem) OpenACCBindClause(BeginLoc, LParenLoc, SL, EndLoc);
627}
628
629OpenACCBindClause *OpenACCBindClause::Create(const ASTContext &C,
630 SourceLocation BeginLoc,
631 SourceLocation LParenLoc,
632 const IdentifierInfo *ID,
633 SourceLocation EndLoc) {
634 void *Mem = C.Allocate(Size: sizeof(OpenACCBindClause), Align: alignof(OpenACCBindClause));
635 return new (Mem) OpenACCBindClause(BeginLoc, LParenLoc, ID, EndLoc);
636}
637
638bool 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
654void OpenACCClausePrinter::printExpr(const Expr *E) {
655 E->printPretty(OS, Helper: nullptr, Policy, Indentation: 0);
656}
657
658void OpenACCClausePrinter::VisitDefaultClause(const OpenACCDefaultClause &C) {
659 OS << "default(" << C.getDefaultClauseKind() << ")";
660}
661
662void OpenACCClausePrinter::VisitIfClause(const OpenACCIfClause &C) {
663 OS << "if(";
664 printExpr(E: C.getConditionExpr());
665 OS << ")";
666}
667
668void OpenACCClausePrinter::VisitSelfClause(const OpenACCSelfClause &C) {
669 OS << "self";
670
671 if (C.isConditionExprClause()) {
672 if (const Expr *CondExpr = C.getConditionExpr()) {
673 OS << "(";
674 printExpr(E: CondExpr);
675 OS << ")";
676 }
677 } else {
678 OS << "(";
679 llvm::interleaveComma(c: C.getVarList(), os&: OS,
680 each_fn: [&](const Expr *E) { printExpr(E); });
681 OS << ")";
682 }
683}
684
685void OpenACCClausePrinter::VisitNumGangsClause(const OpenACCNumGangsClause &C) {
686 OS << "num_gangs(";
687 llvm::interleaveComma(c: C.getIntExprs(), os&: OS,
688 each_fn: [&](const Expr *E) { printExpr(E); });
689 OS << ")";
690}
691
692void OpenACCClausePrinter::VisitTileClause(const OpenACCTileClause &C) {
693 OS << "tile(";
694 llvm::interleaveComma(c: C.getSizeExprs(), os&: OS,
695 each_fn: [&](const Expr *E) { printExpr(E); });
696 OS << ")";
697}
698
699void OpenACCClausePrinter::VisitNumWorkersClause(
700 const OpenACCNumWorkersClause &C) {
701 OS << "num_workers(";
702 printExpr(E: C.getIntExpr());
703 OS << ")";
704}
705
706void OpenACCClausePrinter::VisitVectorLengthClause(
707 const OpenACCVectorLengthClause &C) {
708 OS << "vector_length(";
709 printExpr(E: C.getIntExpr());
710 OS << ")";
711}
712
713void OpenACCClausePrinter::VisitDeviceNumClause(
714 const OpenACCDeviceNumClause &C) {
715 OS << "device_num(";
716 printExpr(E: C.getIntExpr());
717 OS << ")";
718}
719
720void OpenACCClausePrinter::VisitDefaultAsyncClause(
721 const OpenACCDefaultAsyncClause &C) {
722 OS << "default_async(";
723 printExpr(E: C.getIntExpr());
724 OS << ")";
725}
726
727void OpenACCClausePrinter::VisitAsyncClause(const OpenACCAsyncClause &C) {
728 OS << "async";
729 if (C.hasIntExpr()) {
730 OS << "(";
731 printExpr(E: C.getIntExpr());
732 OS << ")";
733 }
734}
735
736void OpenACCClausePrinter::VisitPrivateClause(const OpenACCPrivateClause &C) {
737 OS << "private(";
738 llvm::interleaveComma(c: C.getVarList(), os&: OS,
739 each_fn: [&](const Expr *E) { printExpr(E); });
740 OS << ")";
741}
742
743void OpenACCClausePrinter::VisitFirstPrivateClause(
744 const OpenACCFirstPrivateClause &C) {
745 OS << "firstprivate(";
746 llvm::interleaveComma(c: C.getVarList(), os&: OS,
747 each_fn: [&](const Expr *E) { printExpr(E); });
748 OS << ")";
749}
750
751void OpenACCClausePrinter::VisitAttachClause(const OpenACCAttachClause &C) {
752 OS << "attach(";
753 llvm::interleaveComma(c: C.getVarList(), os&: OS,
754 each_fn: [&](const Expr *E) { printExpr(E); });
755 OS << ")";
756}
757
758void OpenACCClausePrinter::VisitDetachClause(const OpenACCDetachClause &C) {
759 OS << "detach(";
760 llvm::interleaveComma(c: C.getVarList(), os&: OS,
761 each_fn: [&](const Expr *E) { printExpr(E); });
762 OS << ")";
763}
764
765void OpenACCClausePrinter::VisitDeleteClause(const OpenACCDeleteClause &C) {
766 OS << "delete(";
767 llvm::interleaveComma(c: C.getVarList(), os&: OS,
768 each_fn: [&](const Expr *E) { printExpr(E); });
769 OS << ")";
770}
771
772void OpenACCClausePrinter::VisitUseDeviceClause(
773 const OpenACCUseDeviceClause &C) {
774 OS << "use_device(";
775 llvm::interleaveComma(c: C.getVarList(), os&: OS,
776 each_fn: [&](const Expr *E) { printExpr(E); });
777 OS << ")";
778}
779
780void OpenACCClausePrinter::VisitDevicePtrClause(
781 const OpenACCDevicePtrClause &C) {
782 OS << "deviceptr(";
783 llvm::interleaveComma(c: C.getVarList(), os&: OS,
784 each_fn: [&](const Expr *E) { printExpr(E); });
785 OS << ")";
786}
787
788void OpenACCClausePrinter::VisitNoCreateClause(const OpenACCNoCreateClause &C) {
789 OS << "no_create(";
790 llvm::interleaveComma(c: C.getVarList(), os&: OS,
791 each_fn: [&](const Expr *E) { printExpr(E); });
792 OS << ")";
793}
794
795void OpenACCClausePrinter::VisitPresentClause(const OpenACCPresentClause &C) {
796 OS << "present(";
797 llvm::interleaveComma(c: C.getVarList(), os&: OS,
798 each_fn: [&](const Expr *E) { printExpr(E); });
799 OS << ")";
800}
801
802void OpenACCClausePrinter::VisitHostClause(const OpenACCHostClause &C) {
803 OS << "host(";
804 llvm::interleaveComma(c: C.getVarList(), os&: OS,
805 each_fn: [&](const Expr *E) { printExpr(E); });
806 OS << ")";
807}
808
809void OpenACCClausePrinter::VisitDeviceClause(const OpenACCDeviceClause &C) {
810 OS << "device(";
811 llvm::interleaveComma(c: C.getVarList(), os&: OS,
812 each_fn: [&](const Expr *E) { printExpr(E); });
813 OS << ")";
814}
815
816void OpenACCClausePrinter::VisitCopyClause(const OpenACCCopyClause &C) {
817 OS << C.getClauseKind() << '(';
818 if (C.getModifierList() != OpenACCModifierKind::Invalid)
819 OS << C.getModifierList() << ": ";
820 llvm::interleaveComma(c: C.getVarList(), os&: OS,
821 each_fn: [&](const Expr *E) { printExpr(E); });
822 OS << ")";
823}
824
825void OpenACCClausePrinter::VisitLinkClause(const OpenACCLinkClause &C) {
826 OS << "link(";
827 llvm::interleaveComma(c: C.getVarList(), os&: OS,
828 each_fn: [&](const Expr *E) { printExpr(E); });
829 OS << ")";
830}
831
832void OpenACCClausePrinter::VisitDeviceResidentClause(
833 const OpenACCDeviceResidentClause &C) {
834 OS << "device_resident(";
835 llvm::interleaveComma(c: C.getVarList(), os&: OS,
836 each_fn: [&](const Expr *E) { printExpr(E); });
837 OS << ")";
838}
839
840void OpenACCClausePrinter::VisitCopyInClause(const OpenACCCopyInClause &C) {
841 OS << C.getClauseKind() << '(';
842 if (C.getModifierList() != OpenACCModifierKind::Invalid)
843 OS << C.getModifierList() << ": ";
844 llvm::interleaveComma(c: C.getVarList(), os&: OS,
845 each_fn: [&](const Expr *E) { printExpr(E); });
846 OS << ")";
847}
848
849void OpenACCClausePrinter::VisitCopyOutClause(const OpenACCCopyOutClause &C) {
850 OS << C.getClauseKind() << '(';
851 if (C.getModifierList() != OpenACCModifierKind::Invalid)
852 OS << C.getModifierList() << ": ";
853 llvm::interleaveComma(c: C.getVarList(), os&: OS,
854 each_fn: [&](const Expr *E) { printExpr(E); });
855 OS << ")";
856}
857
858void OpenACCClausePrinter::VisitCreateClause(const OpenACCCreateClause &C) {
859 OS << C.getClauseKind() << '(';
860 if (C.getModifierList() != OpenACCModifierKind::Invalid)
861 OS << C.getModifierList() << ": ";
862 llvm::interleaveComma(c: C.getVarList(), os&: OS,
863 each_fn: [&](const Expr *E) { printExpr(E); });
864 OS << ")";
865}
866
867void OpenACCClausePrinter::VisitReductionClause(
868 const OpenACCReductionClause &C) {
869 OS << "reduction(" << C.getReductionOp() << ": ";
870 llvm::interleaveComma(c: C.getVarList(), os&: OS,
871 each_fn: [&](const Expr *E) { printExpr(E); });
872 OS << ")";
873}
874
875void OpenACCClausePrinter::VisitWaitClause(const OpenACCWaitClause &C) {
876 OS << "wait";
877 if (C.hasExprs()) {
878 OS << "(";
879 if (C.hasDevNumExpr()) {
880 OS << "devnum: ";
881 printExpr(E: C.getDevNumExpr());
882 OS << " : ";
883 }
884
885 if (C.hasQueuesTag())
886 OS << "queues: ";
887
888 llvm::interleaveComma(c: C.getQueueIdExprs(), os&: OS,
889 each_fn: [&](const Expr *E) { printExpr(E); });
890 OS << ")";
891 }
892}
893
894void OpenACCClausePrinter::VisitDeviceTypeClause(
895 const OpenACCDeviceTypeClause &C) {
896 OS << C.getClauseKind();
897 OS << "(";
898 llvm::interleaveComma(c: C.getArchitectures(), os&: OS,
899 each_fn: [&](const DeviceTypeArgument &Arch) {
900 if (Arch.getIdentifierInfo() == nullptr)
901 OS << "*";
902 else
903 OS << Arch.getIdentifierInfo()->getName();
904 });
905 OS << ")";
906}
907
908void OpenACCClausePrinter::VisitAutoClause(const OpenACCAutoClause &C) {
909 OS << "auto";
910}
911
912void OpenACCClausePrinter::VisitIndependentClause(
913 const OpenACCIndependentClause &C) {
914 OS << "independent";
915}
916
917void OpenACCClausePrinter::VisitSeqClause(const OpenACCSeqClause &C) {
918 OS << "seq";
919}
920
921void OpenACCClausePrinter::VisitNoHostClause(const OpenACCNoHostClause &C) {
922 OS << "nohost";
923}
924
925void OpenACCClausePrinter::VisitCollapseClause(const OpenACCCollapseClause &C) {
926 OS << "collapse(";
927 if (C.hasForce())
928 OS << "force:";
929 printExpr(E: C.getLoopCount());
930 OS << ")";
931}
932
933void 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(E: C.getExpr(I).second);
946 }
947 OS << ")";
948 }
949}
950
951void OpenACCClausePrinter::VisitWorkerClause(const OpenACCWorkerClause &C) {
952 OS << "worker";
953
954 if (C.hasIntExpr()) {
955 OS << "(num: ";
956 printExpr(E: C.getIntExpr());
957 OS << ")";
958 }
959}
960
961void OpenACCClausePrinter::VisitVectorClause(const OpenACCVectorClause &C) {
962 OS << "vector";
963
964 if (C.hasIntExpr()) {
965 OS << "(length: ";
966 printExpr(E: C.getIntExpr());
967 OS << ")";
968 }
969}
970
971void OpenACCClausePrinter::VisitFinalizeClause(const OpenACCFinalizeClause &C) {
972 OS << "finalize";
973}
974
975void OpenACCClausePrinter::VisitIfPresentClause(
976 const OpenACCIfPresentClause &C) {
977 OS << "if_present";
978}
979
980void 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}
988