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
638 Expr *IntExpr, SourceLocation EndLoc);
639
640public:
641 static bool classof(const OpenACCClause *C) {
642 return C->getClauseKind() == OpenACCClauseKind::DefaultAsync;
643 }
645 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
646 Expr *IntExpr, SourceLocation EndLoc);
647};
648
649/// Represents a 'collapse' clause on a 'loop' construct. This clause takes an
650/// integer constant expression 'N' that represents how deep to collapse the
651/// construct. It also takes an optional 'force' tag that permits intervening
652/// code in the loops.
654 bool HasForce = false;
655
657 bool HasForce, Expr *LoopCount, SourceLocation EndLoc);
658
659public:
660 const Expr *getLoopCount() const { return getIntExpr(); }
661 Expr *getLoopCount() { return getIntExpr(); }
662
663 bool hasForce() const { return HasForce; }
664
665 static bool classof(const OpenACCClause *C) {
666 return C->getClauseKind() == OpenACCClauseKind::Collapse;
667 }
668
670 SourceLocation BeginLoc,
671 SourceLocation LParenLoc, bool HasForce,
672 Expr *LoopCount, SourceLocation EndLoc);
673};
674
675/// Represents a clause with one or more 'var' objects, represented as an expr,
676/// as its arguments. Var-list is expected to be stored in trailing storage.
677/// For now, we're just storing the original expression in its entirety, unlike
678/// OMP which has to do a bunch of work to create a private.
680protected:
682 SourceLocation LParenLoc, SourceLocation EndLoc)
683 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc) {}
684
685public:
686 static bool classof(const OpenACCClause *C);
689};
690
693 private llvm::TrailingObjects<OpenACCPrivateClause, Expr *> {
694 friend TrailingObjects;
695
697 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
699 LParenLoc, EndLoc) {
700 std::uninitialized_copy(VarList.begin(), VarList.end(),
701 getTrailingObjects<Expr *>());
702 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
703 }
704
705public:
706 static bool classof(const OpenACCClause *C) {
707 return C->getClauseKind() == OpenACCClauseKind::Private;
708 }
709 static OpenACCPrivateClause *
710 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
711 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
712};
713
716 private llvm::TrailingObjects<OpenACCFirstPrivateClause, Expr *> {
717 friend TrailingObjects;
718
720 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
722 LParenLoc, EndLoc) {
723 std::uninitialized_copy(VarList.begin(), VarList.end(),
724 getTrailingObjects<Expr *>());
725 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
726 }
727
728public:
729 static bool classof(const OpenACCClause *C) {
730 return C->getClauseKind() == OpenACCClauseKind::FirstPrivate;
731 }
733 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
734 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
735};
736
739 private llvm::TrailingObjects<OpenACCDevicePtrClause, Expr *> {
740 friend TrailingObjects;
741
743 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
745 LParenLoc, EndLoc) {
746 std::uninitialized_copy(VarList.begin(), VarList.end(),
747 getTrailingObjects<Expr *>());
748 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
749 }
750
751public:
752 static bool classof(const OpenACCClause *C) {
753 return C->getClauseKind() == OpenACCClauseKind::DevicePtr;
754 }
756 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
757 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
758};
759
762 private llvm::TrailingObjects<OpenACCAttachClause, Expr *> {
763 friend TrailingObjects;
764
766 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
768 EndLoc) {
769 std::uninitialized_copy(VarList.begin(), VarList.end(),
770 getTrailingObjects<Expr *>());
771 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
772 }
773
774public:
775 static bool classof(const OpenACCClause *C) {
776 return C->getClauseKind() == OpenACCClauseKind::Attach;
777 }
778 static OpenACCAttachClause *
779 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
780 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
781};
782
785 private llvm::TrailingObjects<OpenACCDetachClause, Expr *> {
786 friend TrailingObjects;
787
789 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
791 EndLoc) {
792 std::uninitialized_copy(VarList.begin(), VarList.end(),
793 getTrailingObjects<Expr *>());
794 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
795 }
796
797public:
798 static bool classof(const OpenACCClause *C) {
799 return C->getClauseKind() == OpenACCClauseKind::Detach;
800 }
801 static OpenACCDetachClause *
802 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
803 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
804};
805
808 private llvm::TrailingObjects<OpenACCDeleteClause, Expr *> {
809 friend TrailingObjects;
810
812 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
814 EndLoc) {
815 std::uninitialized_copy(VarList.begin(), VarList.end(),
816 getTrailingObjects<Expr *>());
817 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
818 }
819
820public:
821 static bool classof(const OpenACCClause *C) {
822 return C->getClauseKind() == OpenACCClauseKind::Delete;
823 }
824 static OpenACCDeleteClause *
825 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
826 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
827};
828
831 private llvm::TrailingObjects<OpenACCUseDeviceClause, Expr *> {
832 friend TrailingObjects;
833
835 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
837 LParenLoc, EndLoc) {
838 std::uninitialized_copy(VarList.begin(), VarList.end(),
839 getTrailingObjects<Expr *>());
840 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
841 }
842
843public:
844 static bool classof(const OpenACCClause *C) {
845 return C->getClauseKind() == OpenACCClauseKind::UseDevice;
846 }
848 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
849 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
850};
851
854 private llvm::TrailingObjects<OpenACCNoCreateClause, Expr *> {
855 friend TrailingObjects;
856
858 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
860 LParenLoc, EndLoc) {
861 std::uninitialized_copy(VarList.begin(), VarList.end(),
862 getTrailingObjects<Expr *>());
863 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
864 }
865
866public:
867 static bool classof(const OpenACCClause *C) {
868 return C->getClauseKind() == OpenACCClauseKind::NoCreate;
869 }
870 static OpenACCNoCreateClause *
871 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
872 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
873};
874
877 private llvm::TrailingObjects<OpenACCPresentClause, Expr *> {
878 friend TrailingObjects;
879
881 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
883 LParenLoc, EndLoc) {
884 std::uninitialized_copy(VarList.begin(), VarList.end(),
885 getTrailingObjects<Expr *>());
886 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
887 }
888
889public:
890 static bool classof(const OpenACCClause *C) {
891 return C->getClauseKind() == OpenACCClauseKind::Present;
892 }
893 static OpenACCPresentClause *
894 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
895 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
896};
897
900 private llvm::TrailingObjects<OpenACCCopyClause, Expr *> {
901 friend TrailingObjects;
902
904 SourceLocation LParenLoc, ArrayRef<Expr *> VarList,
905 SourceLocation EndLoc)
906 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc) {
907 assert((Spelling == OpenACCClauseKind::Copy ||
908 Spelling == OpenACCClauseKind::PCopy ||
910 "Invalid clause kind for copy-clause");
911 std::uninitialized_copy(VarList.begin(), VarList.end(),
912 getTrailingObjects<Expr *>());
913 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
914 }
915
916public:
917 static bool classof(const OpenACCClause *C) {
918 return C->getClauseKind() == OpenACCClauseKind::Copy ||
919 C->getClauseKind() == OpenACCClauseKind::PCopy ||
920 C->getClauseKind() == OpenACCClauseKind::PresentOrCopy;
921 }
922 static OpenACCCopyClause *
923 Create(const ASTContext &C, OpenACCClauseKind Spelling,
924 SourceLocation BeginLoc, SourceLocation LParenLoc,
925 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
926};
927
930 private llvm::TrailingObjects<OpenACCCopyInClause, Expr *> {
931 friend TrailingObjects;
932 bool IsReadOnly;
933
935 SourceLocation LParenLoc, bool IsReadOnly,
936 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
937 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
938 IsReadOnly(IsReadOnly) {
939 assert((Spelling == OpenACCClauseKind::CopyIn ||
940 Spelling == OpenACCClauseKind::PCopyIn ||
942 "Invalid clause kind for copyin-clause");
943 std::uninitialized_copy(VarList.begin(), VarList.end(),
944 getTrailingObjects<Expr *>());
945 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
946 }
947
948public:
949 static bool classof(const OpenACCClause *C) {
950 return C->getClauseKind() == OpenACCClauseKind::CopyIn ||
951 C->getClauseKind() == OpenACCClauseKind::PCopyIn ||
952 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyIn;
953 }
954 bool isReadOnly() const { return IsReadOnly; }
955 static OpenACCCopyInClause *
956 Create(const ASTContext &C, OpenACCClauseKind Spelling,
957 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsReadOnly,
958 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
959};
960
963 private llvm::TrailingObjects<OpenACCCopyOutClause, Expr *> {
964 friend TrailingObjects;
965 bool IsZero;
966
968 SourceLocation LParenLoc, bool IsZero,
969 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
970 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
971 IsZero(IsZero) {
972 assert((Spelling == OpenACCClauseKind::CopyOut ||
973 Spelling == OpenACCClauseKind::PCopyOut ||
975 "Invalid clause kind for copyout-clause");
976 std::uninitialized_copy(VarList.begin(), VarList.end(),
977 getTrailingObjects<Expr *>());
978 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
979 }
980
981public:
982 static bool classof(const OpenACCClause *C) {
983 return C->getClauseKind() == OpenACCClauseKind::CopyOut ||
984 C->getClauseKind() == OpenACCClauseKind::PCopyOut ||
985 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyOut;
986 }
987 bool isZero() const { return IsZero; }
988 static OpenACCCopyOutClause *
989 Create(const ASTContext &C, OpenACCClauseKind Spelling,
990 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero,
991 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
992};
993
996 private llvm::TrailingObjects<OpenACCCreateClause, Expr *> {
997 friend TrailingObjects;
998 bool IsZero;
999
1001 SourceLocation LParenLoc, bool IsZero,
1002 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1003 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1004 IsZero(IsZero) {
1005 assert((Spelling == OpenACCClauseKind::Create ||
1006 Spelling == OpenACCClauseKind::PCreate ||
1008 "Invalid clause kind for create-clause");
1009 std::uninitialized_copy(VarList.begin(), VarList.end(),
1010 getTrailingObjects<Expr *>());
1011 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
1012 }
1013
1014public:
1015 static bool classof(const OpenACCClause *C) {
1016 return C->getClauseKind() == OpenACCClauseKind::Create ||
1017 C->getClauseKind() == OpenACCClauseKind::PCreate ||
1018 C->getClauseKind() == OpenACCClauseKind::PresentOrCreate;
1019 }
1020 bool isZero() const { return IsZero; }
1021 static OpenACCCreateClause *
1022 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1023 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero,
1024 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1025};
1026
1028 : public OpenACCClauseWithVarList,
1029 private llvm::TrailingObjects<OpenACCReductionClause, Expr *> {
1030 friend TrailingObjects;
1032
1034 OpenACCReductionOperator Operator,
1035 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1037 LParenLoc, EndLoc),
1038 Op(Operator) {
1039 std::uninitialized_copy(VarList.begin(), VarList.end(),
1040 getTrailingObjects<Expr *>());
1041 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
1042 }
1043
1044public:
1045 static bool classof(const OpenACCClause *C) {
1046 return C->getClauseKind() == OpenACCClauseKind::Reduction;
1047 }
1048
1049 static OpenACCReductionClause *
1050 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1052 SourceLocation EndLoc);
1053
1055};
1056
1057template <class Impl> class OpenACCClauseVisitor {
1058 Impl &getDerived() { return static_cast<Impl &>(*this); }
1059
1060public:
1062 for (const OpenACCClause *Clause : List)
1063 Visit(Clause);
1064 }
1065
1066 void Visit(const OpenACCClause *C) {
1067 if (!C)
1068 return;
1069
1070 switch (C->getClauseKind()) {
1071#define VISIT_CLAUSE(CLAUSE_NAME) \
1072 case OpenACCClauseKind::CLAUSE_NAME: \
1073 Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1074 return;
1075#define CLAUSE_ALIAS(ALIAS_NAME, CLAUSE_NAME, DEPRECATED) \
1076 case OpenACCClauseKind::ALIAS_NAME: \
1077 Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1078 return;
1079#include "clang/Basic/OpenACCClauses.def"
1080
1081 default:
1082 llvm_unreachable("Clause visitor not yet implemented");
1083 }
1084 llvm_unreachable("Invalid Clause kind");
1085 }
1086
1087#define VISIT_CLAUSE(CLAUSE_NAME) \
1088 void Visit##CLAUSE_NAME##Clause( \
1089 const OpenACC##CLAUSE_NAME##Clause &Clause) { \
1090 return getDerived().Visit##CLAUSE_NAME##Clause(Clause); \
1091 }
1092
1093#include "clang/Basic/OpenACCClauses.def"
1094};
1095
1097 : public OpenACCClauseVisitor<OpenACCClausePrinter> {
1098 raw_ostream &OS;
1099 const PrintingPolicy &Policy;
1100
1101 void printExpr(const Expr *E);
1102
1103public:
1105 for (const OpenACCClause *Clause : List) {
1106 Visit(Clause);
1107
1108 if (Clause != List.back())
1109 OS << ' ';
1110 }
1111 }
1112 OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
1113 : OS(OS), Policy(Policy) {}
1114
1115#define VISIT_CLAUSE(CLAUSE_NAME) \
1116 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
1117#include "clang/Basic/OpenACCClauses.def"
1118};
1119
1120} // namespace clang
1121
1122#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)
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',...
@ DefaultAsync
'default_async' clause, allowed on 'set' construct.
@ 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