clang 20.0.0git
OpenACCClause.h
Go to the documentation of this file.
1//===- OpenACCClause.h - Classes for OpenACC clauses ------------*- C++ -*-===//
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// \file
10// This file defines OpenACC AST classes for clauses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_OPENACCCLAUSE_H
15#define LLVM_CLANG_AST_OPENACCCLAUSE_H
19
20#include <utility>
21
22namespace clang {
23/// This is the base type for all OpenACC Clauses.
26 SourceRange Location;
27
28protected:
30 SourceLocation EndLoc)
31 : Kind(K), Location(BeginLoc, EndLoc) {
32 assert(!BeginLoc.isInvalid() && !EndLoc.isInvalid() &&
33 "Begin and end location must be valid for OpenACCClause");
34 }
35
36public:
37 OpenACCClauseKind getClauseKind() const { return Kind; }
38 SourceLocation getBeginLoc() const { return Location.getBegin(); }
39 SourceLocation getEndLoc() const { return Location.getEnd(); }
40
41 static bool classof(const OpenACCClause *) { return true; }
42
45 using child_range = llvm::iterator_range<child_iterator>;
46 using const_child_range = llvm::iterator_range<const_child_iterator>;
47
50 auto Children = const_cast<OpenACCClause *>(this)->children();
51 return const_child_range(Children.begin(), Children.end());
52 }
53
54 virtual ~OpenACCClause() = default;
55};
56
57// Represents the 'auto' clause.
59protected:
61 : OpenACCClause(OpenACCClauseKind::Auto, BeginLoc, EndLoc) {}
62
63public:
64 static bool classof(const OpenACCClause *C) {
65 return C->getClauseKind() == OpenACCClauseKind::Auto;
66 }
67
68 static OpenACCAutoClause *
69 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
70
73 }
76 }
77};
78
79// Represents the 'finalize' clause.
81protected:
83 : OpenACCClause(OpenACCClauseKind::Finalize, BeginLoc, EndLoc) {}
84
85public:
86 static bool classof(const OpenACCClause *C) {
87 return C->getClauseKind() == OpenACCClauseKind::Finalize;
88 }
89
91 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
92
95 }
98 }
99};
100
101// Represents the 'if_present' clause.
103protected:
105 : OpenACCClause(OpenACCClauseKind::IfPresent, BeginLoc, EndLoc) {}
106
107public:
108 static bool classof(const OpenACCClause *C) {
109 return C->getClauseKind() == OpenACCClauseKind::IfPresent;
110 }
111
113 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
114
117 }
120 }
121};
122
123// Represents the 'independent' clause.
125protected:
127 : OpenACCClause(OpenACCClauseKind::Independent, BeginLoc, EndLoc) {}
128
129public:
130 static bool classof(const OpenACCClause *C) {
131 return C->getClauseKind() == OpenACCClauseKind::Independent;
132 }
133
135 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
136
139 }
142 }
143};
144// Represents the 'seq' clause.
146protected:
148 : OpenACCClause(OpenACCClauseKind::Seq, BeginLoc, EndLoc) {}
149
150public:
151 static bool classof(const OpenACCClause *C) {
152 return C->getClauseKind() == OpenACCClauseKind::Seq;
153 }
154
155 static OpenACCSeqClause *
156 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
157
160 }
163 }
164};
165
166/// Represents a clause that has a list of parameters.
168 /// Location of the '('.
169 SourceLocation LParenLoc;
170
171protected:
173 SourceLocation LParenLoc, SourceLocation EndLoc)
174 : OpenACCClause(K, BeginLoc, EndLoc), LParenLoc(LParenLoc) {}
175
176public:
177 static bool classof(const OpenACCClause *C);
178
179 SourceLocation getLParenLoc() const { return LParenLoc; }
180
183 }
186 }
187};
188
189using DeviceTypeArgument = std::pair<IdentifierInfo *, SourceLocation>;
190/// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or
191/// an identifier. The 'asterisk' means 'the rest'.
194 private llvm::TrailingObjects<OpenACCDeviceTypeClause,
195 DeviceTypeArgument> {
196 friend TrailingObjects;
197 // Data stored in trailing objects as IdentifierInfo* /SourceLocation pairs. A
198 // nullptr IdentifierInfo* represents an asterisk.
199 unsigned NumArchs;
201 SourceLocation LParenLoc,
203 SourceLocation EndLoc)
204 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
205 NumArchs(Archs.size()) {
206 assert(
208 "Invalid clause kind for device-type");
209
210 assert(!llvm::any_of(Archs, [](const DeviceTypeArgument &Arg) {
211 return Arg.second.isInvalid();
212 }) && "Invalid SourceLocation for an argument");
213
214 assert(
215 (Archs.size() == 1 || !llvm::any_of(Archs,
216 [](const DeviceTypeArgument &Arg) {
217 return Arg.first == nullptr;
218 })) &&
219 "Only a single asterisk version is permitted, and must be the "
220 "only one");
221
222 std::uninitialized_copy(Archs.begin(), Archs.end(),
223 getTrailingObjects<DeviceTypeArgument>());
224 }
225
226public:
227 static bool classof(const OpenACCClause *C) {
228 return C->getClauseKind() == OpenACCClauseKind::DType ||
229 C->getClauseKind() == OpenACCClauseKind::DeviceType;
230 }
231 bool hasAsterisk() const {
232 return getArchitectures().size() > 0 &&
233 getArchitectures()[0].first == nullptr;
234 }
235
238 getTrailingObjects<DeviceTypeArgument>(), NumArchs);
239 }
240
244 SourceLocation EndLoc);
245};
246
247/// A 'default' clause, has the optional 'none' or 'present' argument.
249 friend class ASTReaderStmt;
250 friend class ASTWriterStmt;
251
252 OpenACCDefaultClauseKind DefaultClauseKind;
253
254protected:
256 SourceLocation LParenLoc, SourceLocation EndLoc)
257 : OpenACCClauseWithParams(OpenACCClauseKind::Default, BeginLoc, LParenLoc,
258 EndLoc),
259 DefaultClauseKind(K) {
260 assert((DefaultClauseKind == OpenACCDefaultClauseKind::None ||
261 DefaultClauseKind == OpenACCDefaultClauseKind::Present) &&
262 "Invalid Clause Kind");
263 }
264
265public:
266 static bool classof(const OpenACCClause *C) {
267 return C->getClauseKind() == OpenACCClauseKind::Default;
268 }
270 return DefaultClauseKind;
271 }
272
275 SourceLocation BeginLoc,
276 SourceLocation LParenLoc,
277 SourceLocation EndLoc);
278};
279
280/// Represents one of the handful of classes that has an optional/required
281/// 'condition' expression as an argument.
283 Expr *ConditionExpr = nullptr;
284
285protected:
287 SourceLocation LParenLoc, Expr *ConditionExpr,
288 SourceLocation EndLoc)
289 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
290 ConditionExpr(ConditionExpr) {}
291
292public:
293 static bool classof(const OpenACCClause *C);
294
295 bool hasConditionExpr() const { return ConditionExpr; }
296 const Expr *getConditionExpr() const { return ConditionExpr; }
297 Expr *getConditionExpr() { return ConditionExpr; }
298
300 if (ConditionExpr)
301 return child_range(reinterpret_cast<Stmt **>(&ConditionExpr),
302 reinterpret_cast<Stmt **>(&ConditionExpr + 1));
304 }
305
307 if (ConditionExpr)
308 return const_child_range(
309 reinterpret_cast<Stmt *const *>(&ConditionExpr),
310 reinterpret_cast<Stmt *const *>(&ConditionExpr + 1));
312 }
313};
314
315/// An 'if' clause, which has a required condition expression.
317protected:
319 Expr *ConditionExpr, SourceLocation EndLoc);
320
321public:
322 static bool classof(const OpenACCClause *C) {
323 return C->getClauseKind() == OpenACCClauseKind::If;
324 }
325 static OpenACCIfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
326 SourceLocation LParenLoc, Expr *ConditionExpr,
327 SourceLocation EndLoc);
328};
329
330/// A 'self' clause, which has an optional condition expression.
333 Expr *ConditionExpr, SourceLocation EndLoc);
334
335public:
336 static bool classof(const OpenACCClause *C) {
337 return C->getClauseKind() == OpenACCClauseKind::Self;
338 }
339 static OpenACCSelfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
340 SourceLocation LParenLoc,
341 Expr *ConditionExpr, SourceLocation EndLoc);
342};
343
344/// Represents a clause that has one or more expressions associated with it.
347
348protected:
350 SourceLocation LParenLoc, SourceLocation EndLoc)
351 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc) {}
352
353 /// Used only for initialization, the leaf class can initialize this to
354 /// trailing storage.
356 assert(Exprs.empty() && "Cannot change Exprs list");
357 Exprs = NewExprs;
358 }
359
360 /// Gets the entire list of expressions, but leave it to the
361 /// individual clauses to expose this how they'd like.
362 llvm::ArrayRef<Expr *> getExprs() const { return Exprs; }
363
364public:
365 static bool classof(const OpenACCClause *C);
367 return child_range(reinterpret_cast<Stmt **>(Exprs.begin()),
368 reinterpret_cast<Stmt **>(Exprs.end()));
369 }
370
372 child_range Children =
373 const_cast<OpenACCClauseWithExprs *>(this)->children();
374 return const_child_range(Children.begin(), Children.end());
375 }
376};
377
378// Represents the 'devnum' and expressions lists for the 'wait' clause.
380 : public OpenACCClauseWithExprs,
381 private llvm::TrailingObjects<OpenACCWaitClause, Expr *> {
382 friend TrailingObjects;
383 SourceLocation QueuesLoc;
385 Expr *DevNumExpr, SourceLocation QueuesLoc,
386 ArrayRef<Expr *> QueueIdExprs, SourceLocation EndLoc)
387 : OpenACCClauseWithExprs(OpenACCClauseKind::Wait, BeginLoc, LParenLoc,
388 EndLoc),
389 QueuesLoc(QueuesLoc) {
390 // The first element of the trailing storage is always the devnum expr,
391 // whether it is used or not.
392 std::uninitialized_copy(&DevNumExpr, &DevNumExpr + 1,
393 getTrailingObjects<Expr *>());
394 std::uninitialized_copy(QueueIdExprs.begin(), QueueIdExprs.end(),
395 getTrailingObjects<Expr *>() + 1);
396 setExprs(
397 MutableArrayRef(getTrailingObjects<Expr *>(), QueueIdExprs.size() + 1));
398 }
399
400public:
401 static bool classof(const OpenACCClause *C) {
402 return C->getClauseKind() == OpenACCClauseKind::Wait;
403 }
404 static OpenACCWaitClause *Create(const ASTContext &C, SourceLocation BeginLoc,
405 SourceLocation LParenLoc, Expr *DevNumExpr,
406 SourceLocation QueuesLoc,
407 ArrayRef<Expr *> QueueIdExprs,
408 SourceLocation EndLoc);
409
410 bool hasQueuesTag() const { return !QueuesLoc.isInvalid(); }
411 SourceLocation getQueuesLoc() const { return QueuesLoc; }
412 bool hasDevNumExpr() const { return getExprs()[0]; }
413 Expr *getDevNumExpr() const { return getExprs()[0]; }
415 return OpenACCClauseWithExprs::getExprs().drop_front();
416 }
418 return OpenACCClauseWithExprs::getExprs().drop_front();
419 }
420};
421
423 : public OpenACCClauseWithExprs,
424 private llvm::TrailingObjects<OpenACCNumGangsClause, Expr *> {
425 friend TrailingObjects;
426
428 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
430 EndLoc) {
431 std::uninitialized_copy(IntExprs.begin(), IntExprs.end(),
432 getTrailingObjects<Expr *>());
433 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), IntExprs.size()));
434 }
435
436public:
437 static bool classof(const OpenACCClause *C) {
438 return C->getClauseKind() == OpenACCClauseKind::NumGangs;
439 }
440 static OpenACCNumGangsClause *
441 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
442 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
443
446 }
447
450 }
451};
452
454 : public OpenACCClauseWithExprs,
455 private llvm::TrailingObjects<OpenACCTileClause, Expr *> {
456 friend TrailingObjects;
458 ArrayRef<Expr *> SizeExprs, SourceLocation EndLoc)
459 : OpenACCClauseWithExprs(OpenACCClauseKind::Tile, BeginLoc, LParenLoc,
460 EndLoc) {
461 std::uninitialized_copy(SizeExprs.begin(), SizeExprs.end(),
462 getTrailingObjects<Expr *>());
463 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), SizeExprs.size()));
464 }
465
466public:
467 static bool classof(const OpenACCClause *C) {
468 return C->getClauseKind() == OpenACCClauseKind::Tile;
469 }
470 static OpenACCTileClause *Create(const ASTContext &C, SourceLocation BeginLoc,
471 SourceLocation LParenLoc,
472 ArrayRef<Expr *> SizeExprs,
473 SourceLocation EndLoc);
476 }
477
480 }
481};
482
483/// Represents one of a handful of clauses that have a single integer
484/// expression.
486 Expr *IntExpr;
487
488protected:
490 SourceLocation LParenLoc, Expr *IntExpr,
491 SourceLocation EndLoc)
492 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc),
493 IntExpr(IntExpr) {
494 if (IntExpr)
495 setExprs(MutableArrayRef<Expr *>{&this->IntExpr, 1});
496 }
497
498public:
499 static bool classof(const OpenACCClause *C);
500 bool hasIntExpr() const { return !getExprs().empty(); }
501 const Expr *getIntExpr() const {
502 return hasIntExpr() ? getExprs()[0] : nullptr;
503 }
504
505 Expr *getIntExpr() { return hasIntExpr() ? getExprs()[0] : nullptr; };
506};
507
509 : public OpenACCClauseWithExprs,
510 private llvm::TrailingObjects<OpenACCGangClause, Expr *, OpenACCGangKind> {
511 friend TrailingObjects;
512protected:
515 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
516
517 OpenACCGangKind getGangKind(unsigned I) const {
518 return getTrailingObjects<OpenACCGangKind>()[I];
519 }
520
521public:
522 static bool classof(const OpenACCClause *C) {
523 return C->getClauseKind() == OpenACCClauseKind::Gang;
524 }
525
526 size_t numTrailingObjects(OverloadToken<Expr *>) const {
527 return getNumExprs();
528 }
529
530 unsigned getNumExprs() const { return getExprs().size(); }
531 std::pair<OpenACCGangKind, const Expr *> getExpr(unsigned I) const {
532 return {getGangKind(I), getExprs()[I]};
533 }
534
536 for (unsigned I = 0; I < getNumExprs(); ++I) {
537 if (getGangKind(I) == GK)
538 return true;
539 }
540 return false;
541 }
542
543 static OpenACCGangClause *
544 Create(const ASTContext &Ctx, SourceLocation BeginLoc,
545 SourceLocation LParenLoc, ArrayRef<OpenACCGangKind> GangKinds,
546 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
547};
548
550protected:
552 Expr *IntExpr, SourceLocation EndLoc);
553
554public:
555 static bool classof(const OpenACCClause *C) {
556 return C->getClauseKind() == OpenACCClauseKind::Worker;
557 }
558
559 static OpenACCWorkerClause *Create(const ASTContext &Ctx,
560 SourceLocation BeginLoc,
561 SourceLocation LParenLoc, Expr *IntExpr,
562 SourceLocation EndLoc);
563};
564
566protected:
568 Expr *IntExpr, SourceLocation EndLoc);
569
570public:
571 static bool classof(const OpenACCClause *C) {
572 return C->getClauseKind() == OpenACCClauseKind::Vector;
573 }
574
575 static OpenACCVectorClause *Create(const ASTContext &Ctx,
576 SourceLocation BeginLoc,
577 SourceLocation LParenLoc, Expr *IntExpr,
578 SourceLocation EndLoc);
579};
580
583 Expr *IntExpr, SourceLocation EndLoc);
584
585public:
586 static bool classof(const OpenACCClause *C) {
587 return C->getClauseKind() == OpenACCClauseKind::NumWorkers;
588 }
590 SourceLocation BeginLoc,
591 SourceLocation LParenLoc,
592 Expr *IntExpr, SourceLocation EndLoc);
593};
594
597 Expr *IntExpr, SourceLocation EndLoc);
598
599public:
600 static bool classof(const OpenACCClause *C) {
601 return C->getClauseKind() == OpenACCClauseKind::VectorLength;
602 }
604 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
605 Expr *IntExpr, SourceLocation EndLoc);
606};
607
610 Expr *IntExpr, SourceLocation EndLoc);
611
612public:
613 static bool classof(const OpenACCClause *C) {
614 return C->getClauseKind() == OpenACCClauseKind::Async;
615 }
616 static OpenACCAsyncClause *Create(const ASTContext &C,
617 SourceLocation BeginLoc,
618 SourceLocation LParenLoc, Expr *IntExpr,
619 SourceLocation EndLoc);
620};
621
624 Expr *IntExpr, SourceLocation EndLoc);
625
626public:
627 static bool classof(const OpenACCClause *C) {
628 return C->getClauseKind() == OpenACCClauseKind::DeviceNum;
629 }
631 SourceLocation BeginLoc,
632 SourceLocation LParenLoc, Expr *IntExpr,
633 SourceLocation EndLoc);
634};
635
636/// Represents a 'collapse' clause on a 'loop' construct. This clause takes an
637/// integer constant expression 'N' that represents how deep to collapse the
638/// construct. It also takes an optional 'force' tag that permits intervening
639/// code in the loops.
641 bool HasForce = false;
642
644 bool HasForce, Expr *LoopCount, SourceLocation EndLoc);
645
646public:
647 const Expr *getLoopCount() const { return getIntExpr(); }
648 Expr *getLoopCount() { return getIntExpr(); }
649
650 bool hasForce() const { return HasForce; }
651
652 static bool classof(const OpenACCClause *C) {
653 return C->getClauseKind() == OpenACCClauseKind::Collapse;
654 }
655
657 SourceLocation BeginLoc,
658 SourceLocation LParenLoc, bool HasForce,
659 Expr *LoopCount, SourceLocation EndLoc);
660};
661
662/// Represents a clause with one or more 'var' objects, represented as an expr,
663/// as its arguments. Var-list is expected to be stored in trailing storage.
664/// For now, we're just storing the original expression in its entirety, unlike
665/// OMP which has to do a bunch of work to create a private.
667protected:
669 SourceLocation LParenLoc, SourceLocation EndLoc)
670 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc) {}
671
672public:
673 static bool classof(const OpenACCClause *C);
676};
677
680 private llvm::TrailingObjects<OpenACCPrivateClause, Expr *> {
681 friend TrailingObjects;
682
684 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
686 LParenLoc, EndLoc) {
687 std::uninitialized_copy(VarList.begin(), VarList.end(),
688 getTrailingObjects<Expr *>());
689 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
690 }
691
692public:
693 static bool classof(const OpenACCClause *C) {
694 return C->getClauseKind() == OpenACCClauseKind::Private;
695 }
696 static OpenACCPrivateClause *
697 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
698 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
699};
700
703 private llvm::TrailingObjects<OpenACCFirstPrivateClause, Expr *> {
704 friend TrailingObjects;
705
707 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
709 LParenLoc, EndLoc) {
710 std::uninitialized_copy(VarList.begin(), VarList.end(),
711 getTrailingObjects<Expr *>());
712 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
713 }
714
715public:
716 static bool classof(const OpenACCClause *C) {
717 return C->getClauseKind() == OpenACCClauseKind::FirstPrivate;
718 }
720 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
721 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
722};
723
726 private llvm::TrailingObjects<OpenACCDevicePtrClause, Expr *> {
727 friend TrailingObjects;
728
730 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
732 LParenLoc, EndLoc) {
733 std::uninitialized_copy(VarList.begin(), VarList.end(),
734 getTrailingObjects<Expr *>());
735 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
736 }
737
738public:
739 static bool classof(const OpenACCClause *C) {
740 return C->getClauseKind() == OpenACCClauseKind::DevicePtr;
741 }
743 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
744 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
745};
746
749 private llvm::TrailingObjects<OpenACCAttachClause, Expr *> {
750 friend TrailingObjects;
751
753 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
755 EndLoc) {
756 std::uninitialized_copy(VarList.begin(), VarList.end(),
757 getTrailingObjects<Expr *>());
758 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
759 }
760
761public:
762 static bool classof(const OpenACCClause *C) {
763 return C->getClauseKind() == OpenACCClauseKind::Attach;
764 }
765 static OpenACCAttachClause *
766 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
767 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
768};
769
772 private llvm::TrailingObjects<OpenACCDetachClause, Expr *> {
773 friend TrailingObjects;
774
776 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
778 EndLoc) {
779 std::uninitialized_copy(VarList.begin(), VarList.end(),
780 getTrailingObjects<Expr *>());
781 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
782 }
783
784public:
785 static bool classof(const OpenACCClause *C) {
786 return C->getClauseKind() == OpenACCClauseKind::Detach;
787 }
788 static OpenACCDetachClause *
789 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
790 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
791};
792
795 private llvm::TrailingObjects<OpenACCDeleteClause, Expr *> {
796 friend TrailingObjects;
797
799 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
801 EndLoc) {
802 std::uninitialized_copy(VarList.begin(), VarList.end(),
803 getTrailingObjects<Expr *>());
804 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
805 }
806
807public:
808 static bool classof(const OpenACCClause *C) {
809 return C->getClauseKind() == OpenACCClauseKind::Delete;
810 }
811 static OpenACCDeleteClause *
812 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
813 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
814};
815
818 private llvm::TrailingObjects<OpenACCUseDeviceClause, Expr *> {
819 friend TrailingObjects;
820
822 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
824 LParenLoc, EndLoc) {
825 std::uninitialized_copy(VarList.begin(), VarList.end(),
826 getTrailingObjects<Expr *>());
827 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
828 }
829
830public:
831 static bool classof(const OpenACCClause *C) {
832 return C->getClauseKind() == OpenACCClauseKind::UseDevice;
833 }
835 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
836 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
837};
838
841 private llvm::TrailingObjects<OpenACCNoCreateClause, Expr *> {
842 friend TrailingObjects;
843
845 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
847 LParenLoc, EndLoc) {
848 std::uninitialized_copy(VarList.begin(), VarList.end(),
849 getTrailingObjects<Expr *>());
850 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
851 }
852
853public:
854 static bool classof(const OpenACCClause *C) {
855 return C->getClauseKind() == OpenACCClauseKind::NoCreate;
856 }
857 static OpenACCNoCreateClause *
858 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
859 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
860};
861
864 private llvm::TrailingObjects<OpenACCPresentClause, Expr *> {
865 friend TrailingObjects;
866
868 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
870 LParenLoc, EndLoc) {
871 std::uninitialized_copy(VarList.begin(), VarList.end(),
872 getTrailingObjects<Expr *>());
873 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
874 }
875
876public:
877 static bool classof(const OpenACCClause *C) {
878 return C->getClauseKind() == OpenACCClauseKind::Present;
879 }
880 static OpenACCPresentClause *
881 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
882 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
883};
884
887 private llvm::TrailingObjects<OpenACCCopyClause, Expr *> {
888 friend TrailingObjects;
889
891 SourceLocation LParenLoc, ArrayRef<Expr *> VarList,
892 SourceLocation EndLoc)
893 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc) {
894 assert((Spelling == OpenACCClauseKind::Copy ||
895 Spelling == OpenACCClauseKind::PCopy ||
897 "Invalid clause kind for copy-clause");
898 std::uninitialized_copy(VarList.begin(), VarList.end(),
899 getTrailingObjects<Expr *>());
900 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
901 }
902
903public:
904 static bool classof(const OpenACCClause *C) {
905 return C->getClauseKind() == OpenACCClauseKind::Copy ||
906 C->getClauseKind() == OpenACCClauseKind::PCopy ||
907 C->getClauseKind() == OpenACCClauseKind::PresentOrCopy;
908 }
909 static OpenACCCopyClause *
910 Create(const ASTContext &C, OpenACCClauseKind Spelling,
911 SourceLocation BeginLoc, SourceLocation LParenLoc,
912 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
913};
914
917 private llvm::TrailingObjects<OpenACCCopyInClause, Expr *> {
918 friend TrailingObjects;
919 bool IsReadOnly;
920
922 SourceLocation LParenLoc, bool IsReadOnly,
923 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
924 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
925 IsReadOnly(IsReadOnly) {
926 assert((Spelling == OpenACCClauseKind::CopyIn ||
927 Spelling == OpenACCClauseKind::PCopyIn ||
929 "Invalid clause kind for copyin-clause");
930 std::uninitialized_copy(VarList.begin(), VarList.end(),
931 getTrailingObjects<Expr *>());
932 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
933 }
934
935public:
936 static bool classof(const OpenACCClause *C) {
937 return C->getClauseKind() == OpenACCClauseKind::CopyIn ||
938 C->getClauseKind() == OpenACCClauseKind::PCopyIn ||
939 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyIn;
940 }
941 bool isReadOnly() const { return IsReadOnly; }
942 static OpenACCCopyInClause *
943 Create(const ASTContext &C, OpenACCClauseKind Spelling,
944 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsReadOnly,
945 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
946};
947
950 private llvm::TrailingObjects<OpenACCCopyOutClause, Expr *> {
951 friend TrailingObjects;
952 bool IsZero;
953
955 SourceLocation LParenLoc, bool IsZero,
956 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
957 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
958 IsZero(IsZero) {
959 assert((Spelling == OpenACCClauseKind::CopyOut ||
960 Spelling == OpenACCClauseKind::PCopyOut ||
962 "Invalid clause kind for copyout-clause");
963 std::uninitialized_copy(VarList.begin(), VarList.end(),
964 getTrailingObjects<Expr *>());
965 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
966 }
967
968public:
969 static bool classof(const OpenACCClause *C) {
970 return C->getClauseKind() == OpenACCClauseKind::CopyOut ||
971 C->getClauseKind() == OpenACCClauseKind::PCopyOut ||
972 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyOut;
973 }
974 bool isZero() const { return IsZero; }
975 static OpenACCCopyOutClause *
976 Create(const ASTContext &C, OpenACCClauseKind Spelling,
977 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero,
978 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
979};
980
983 private llvm::TrailingObjects<OpenACCCreateClause, Expr *> {
984 friend TrailingObjects;
985 bool IsZero;
986
988 SourceLocation LParenLoc, bool IsZero,
989 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
990 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
991 IsZero(IsZero) {
992 assert((Spelling == OpenACCClauseKind::Create ||
993 Spelling == OpenACCClauseKind::PCreate ||
995 "Invalid clause kind for create-clause");
996 std::uninitialized_copy(VarList.begin(), VarList.end(),
997 getTrailingObjects<Expr *>());
998 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
999 }
1000
1001public:
1002 static bool classof(const OpenACCClause *C) {
1003 return C->getClauseKind() == OpenACCClauseKind::Create ||
1004 C->getClauseKind() == OpenACCClauseKind::PCreate ||
1005 C->getClauseKind() == OpenACCClauseKind::PresentOrCreate;
1006 }
1007 bool isZero() const { return IsZero; }
1008 static OpenACCCreateClause *
1009 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1010 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero,
1011 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1012};
1013
1015 : public OpenACCClauseWithVarList,
1016 private llvm::TrailingObjects<OpenACCReductionClause, Expr *> {
1017 friend TrailingObjects;
1019
1021 OpenACCReductionOperator Operator,
1022 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1024 LParenLoc, EndLoc),
1025 Op(Operator) {
1026 std::uninitialized_copy(VarList.begin(), VarList.end(),
1027 getTrailingObjects<Expr *>());
1028 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
1029 }
1030
1031public:
1032 static bool classof(const OpenACCClause *C) {
1033 return C->getClauseKind() == OpenACCClauseKind::Reduction;
1034 }
1035
1036 static OpenACCReductionClause *
1037 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1039 SourceLocation EndLoc);
1040
1042};
1043
1044template <class Impl> class OpenACCClauseVisitor {
1045 Impl &getDerived() { return static_cast<Impl &>(*this); }
1046
1047public:
1049 for (const OpenACCClause *Clause : List)
1050 Visit(Clause);
1051 }
1052
1053 void Visit(const OpenACCClause *C) {
1054 if (!C)
1055 return;
1056
1057 switch (C->getClauseKind()) {
1058#define VISIT_CLAUSE(CLAUSE_NAME) \
1059 case OpenACCClauseKind::CLAUSE_NAME: \
1060 Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1061 return;
1062#define CLAUSE_ALIAS(ALIAS_NAME, CLAUSE_NAME, DEPRECATED) \
1063 case OpenACCClauseKind::ALIAS_NAME: \
1064 Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1065 return;
1066#include "clang/Basic/OpenACCClauses.def"
1067
1068 default:
1069 llvm_unreachable("Clause visitor not yet implemented");
1070 }
1071 llvm_unreachable("Invalid Clause kind");
1072 }
1073
1074#define VISIT_CLAUSE(CLAUSE_NAME) \
1075 void Visit##CLAUSE_NAME##Clause( \
1076 const OpenACC##CLAUSE_NAME##Clause &Clause) { \
1077 return getDerived().Visit##CLAUSE_NAME##Clause(Clause); \
1078 }
1079
1080#include "clang/Basic/OpenACCClauses.def"
1081};
1082
1084 : public OpenACCClauseVisitor<OpenACCClausePrinter> {
1085 raw_ostream &OS;
1086 const PrintingPolicy &Policy;
1087
1088 void printExpr(const Expr *E);
1089
1090public:
1092 for (const OpenACCClause *Clause : List) {
1093 Visit(Clause);
1094
1095 if (Clause != List.back())
1096 OS << ' ';
1097 }
1098 }
1099 OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
1100 : OS(OS), Policy(Policy) {}
1101
1102#define VISIT_CLAUSE(CLAUSE_NAME) \
1103 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
1104#include "clang/Basic/OpenACCClauses.def"
1105};
1106
1107} // namespace clang
1108
1109#endif // LLVM_CLANG_AST_OPENACCCLAUSE_H
Defines the clang::ASTContext interface.
Expr * E
Defines some OpenACC-specific enums and functions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
This represents one expression.
Definition: Expr.h:110
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
const_child_range children() const
Definition: OpenACCClause.h:74
OpenACCAutoClause(SourceLocation BeginLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:60
static bool classof(const OpenACCClause *C)
Definition: OpenACCClause.h:64
OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
void VisitClauseList(ArrayRef< const OpenACCClause * > List)
void Visit(const OpenACCClause *C)
void VisitClauseList(ArrayRef< const OpenACCClause * > List)
Represents one of the handful of classes that has an optional/required 'condition' expression as an a...
static bool classof(const OpenACCClause *C)
const Expr * getConditionExpr() const
OpenACCClauseWithCondition(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
const_child_range children() const
Represents a clause that has one or more expressions associated with it.
static bool classof(const OpenACCClause *C)
OpenACCClauseWithExprs(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
llvm::ArrayRef< Expr * > getExprs() const
Gets the entire list of expressions, but leave it to the individual clauses to expose this how they'd...
const_child_range children() const
void setExprs(MutableArrayRef< Expr * > NewExprs)
Used only for initialization, the leaf class can initialize this to trailing storage.
Represents a clause that has a list of parameters.
SourceLocation getLParenLoc() const
static bool classof(const OpenACCClause *C)
OpenACCClauseWithParams(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
const_child_range children() const
Represents one of a handful of clauses that have a single integer expression.
OpenACCClauseWithSingleIntExpr(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
Represents a clause with one or more 'var' objects, represented as an expr, as its arguments.
OpenACCClauseWithVarList(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
ArrayRef< Expr * > getVarList()
ArrayRef< Expr * > getVarList() const
This is the base type for all OpenACC Clauses.
Definition: OpenACCClause.h:24
child_range children()
StmtIterator child_iterator
Definition: OpenACCClause.h:43
OpenACCClauseKind getClauseKind() const
Definition: OpenACCClause.h:37
SourceLocation getBeginLoc() const
Definition: OpenACCClause.h:38
const_child_range children() const
Definition: OpenACCClause.h:49
static bool classof(const OpenACCClause *)
Definition: OpenACCClause.h:41
llvm::iterator_range< child_iterator > child_range
Definition: OpenACCClause.h:45
ConstStmtIterator const_child_iterator
Definition: OpenACCClause.h:44
OpenACCClause(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:29
virtual ~OpenACCClause()=default
llvm::iterator_range< const_child_iterator > const_child_range
Definition: OpenACCClause.h:46
SourceLocation getEndLoc() const
Definition: OpenACCClause.h:39
Represents a 'collapse' clause on a 'loop' construct.
const Expr * getLoopCount() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
A 'default' clause, has the optional 'none' or 'present' argument.
OpenACCDefaultClause(OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
OpenACCDefaultClauseKind getDefaultClauseKind() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or an identifier.
ArrayRef< DeviceTypeArgument > getArchitectures() const
static bool classof(const OpenACCClause *C)
OpenACCFinalizeClause(SourceLocation BeginLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:82
static bool classof(const OpenACCClause *C)
Definition: OpenACCClause.h:86
const_child_range children() const
Definition: OpenACCClause.h:96
static bool classof(const OpenACCClause *C)
OpenACCGangKind getGangKind(unsigned I) const
bool hasExprOfKind(OpenACCGangKind GK) const
size_t numTrailingObjects(OverloadToken< Expr * >) const
static bool classof(const OpenACCClause *C)
unsigned getNumExprs() const
std::pair< OpenACCGangKind, const Expr * > getExpr(unsigned I) const
An 'if' clause, which has a required condition expression.
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
const_child_range children() const
OpenACCIfPresentClause(SourceLocation BeginLoc, SourceLocation EndLoc)
OpenACCIndependentClause(SourceLocation BeginLoc, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
const_child_range children() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
llvm::ArrayRef< Expr * > getIntExprs() const
llvm::ArrayRef< Expr * > getIntExprs()
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
OpenACCReductionOperator getReductionOp() const
A 'self' clause, which has an optional condition expression.
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
const_child_range children() const
OpenACCSeqClause(SourceLocation BeginLoc, SourceLocation EndLoc)
llvm::ArrayRef< Expr * > getSizeExprs() const
static bool classof(const OpenACCClause *C)
llvm::ArrayRef< Expr * > getSizeExprs()
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
Expr * getDevNumExpr() const
llvm::ArrayRef< Expr * > getQueueIdExprs()
llvm::ArrayRef< Expr * > getQueueIdExprs() const
SourceLocation getQueuesLoc() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
The JSON file list parser is used to communicate input to InstallAPI.
OpenACCReductionOperator
Definition: OpenACCKinds.h:509
OpenACCClauseKind
Represents the kind of an OpenACC clause.
Definition: OpenACCKinds.h:178
@ Auto
'auto' clause, allowed on 'loop' directives.
@ Gang
'gang' clause, allowed on 'loop' and Combined constructs.
@ Wait
'wait' clause, allowed on Compute, Data, 'update', and Combined constructs.
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ PCopyOut
'copyout' clause alias 'pcopyout'. Preserved for diagnostic purposes.
@ VectorLength
'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop', and 'kernels loop' constru...
@ Async
'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined constructs.
@ PresentOrCreate
'create' clause alias 'present_or_create'.
@ Collapse
'collapse' clause, allowed on 'loop' and Combined constructs.
@ PresentOrCopy
'copy' clause alias 'present_or_copy'. Preserved for diagnostic purposes.
@ DeviceNum
'device_num' clause, allowed on 'init', 'shutdown', and 'set' constructs.
@ Private
'private' clause, allowed on 'parallel', 'serial', 'loop', 'parallel loop', and 'serial loop' constru...
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
@ Copy
'copy' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Worker
'worker' clause, allowed on 'loop', Combined, and 'routine' directives.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ DeviceType
'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown', 'set', update',...
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ NumGangs
'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs.
@ If
'if' clause, allowed on all the Compute Constructs, Data Constructs, Executable Constructs,...
@ Default
'default' clause, allowed on parallel, serial, kernel (and compound) constructs.
@ UseDevice
'use_device' clause, allowed on 'host_data' construct.
@ NoCreate
'no_create' clause, allowed on allowed on Compute and Combined constructs, plus 'data'.
@ PresentOrCopyOut
'copyout' clause alias 'present_or_copyout'.
@ Reduction
'reduction' clause, allowed on Parallel, Serial, Loop, and the combined constructs.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ CopyOut
'copyout' clause, allowed on Compute and Combined constructs, plus 'data', 'exit data',...
@ Seq
'seq' clause, allowed on 'loop' and 'routine' directives.
@ FirstPrivate
'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop', and 'serial loop' constructs...
@ PCopy
'copy' clause alias 'pcopy'. Preserved for diagnostic purposes.
@ Tile
'tile' clause, allowed on 'loop' and Combined constructs.
@ PCopyIn
'copyin' clause alias 'pcopyin'. Preserved for diagnostic purposes.
@ PCreate
'create' clause alias 'pcreate'. Preserved for diagnostic purposes.
@ Present
'present' clause, allowed on Compute and Combined constructs, plus 'data' and 'declare'.
@ DType
'dtype' clause, an alias for 'device_type', stored separately for diagnostic purposes.
@ CopyIn
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Independent
'independent' clause, allowed on 'loop' directives.
@ NumWorkers
'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs...
@ IfPresent
'if_present' clause, allowed on 'host_data' and 'update' directives.
@ Detach
'detach' clause, allowed on the 'exit data' construct.
@ Delete
'delete' clause, allowed on the 'exit data' construct.
@ PresentOrCopyIn
'copyin' clause alias 'present_or_copyin'.
@ Finalize
'finalize' clause, allowed on 'exit data' directive.
OpenACCDefaultClauseKind
Definition: OpenACCKinds.h:476
std::pair< IdentifierInfo *, SourceLocation > DeviceTypeArgument
OpenACCGangKind
Definition: OpenACCKinds.h:568
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57