clang 23.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
16
20#include "llvm/ADT/STLExtras.h"
21
22#include <utility>
23#include <variant>
24
25namespace clang {
26/// This is the base type for all OpenACC Clauses.
29 SourceRange Location;
30
31protected:
33 SourceLocation EndLoc)
34 : Kind(K), Location(BeginLoc, EndLoc) {
35 assert(!BeginLoc.isInvalid() && !EndLoc.isInvalid() &&
36 "Begin and end location must be valid for OpenACCClause");
37 }
38
39public:
40 OpenACCClauseKind getClauseKind() const { return Kind; }
41 SourceLocation getBeginLoc() const { return Location.getBegin(); }
42 SourceLocation getEndLoc() const { return Location.getEnd(); }
43 SourceRange getSourceRange() const { return Location; }
44
45 static bool classof(const OpenACCClause *) { return true; }
46
49 using child_range = llvm::iterator_range<child_iterator>;
50 using const_child_range = llvm::iterator_range<const_child_iterator>;
51
54 return const_cast<OpenACCClause *>(this)->children();
55 }
56
57 virtual ~OpenACCClause() = default;
58};
59
60// Represents the 'auto' clause.
62protected:
65
66public:
67 static bool classof(const OpenACCClause *C) {
68 return C->getClauseKind() == OpenACCClauseKind::Auto;
69 }
70
71 static OpenACCAutoClause *
72 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
73
80};
81
82// Represents the 'finalize' clause.
84protected:
87
88public:
89 static bool classof(const OpenACCClause *C) {
90 return C->getClauseKind() == OpenACCClauseKind::Finalize;
91 }
92
94 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
95
102};
103
104// Represents the 'if_present' clause.
106protected:
109
110public:
111 static bool classof(const OpenACCClause *C) {
112 return C->getClauseKind() == OpenACCClauseKind::IfPresent;
113 }
114
116 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
117
124};
125
126// Represents the 'independent' clause.
128protected:
131
132public:
133 static bool classof(const OpenACCClause *C) {
134 return C->getClauseKind() == OpenACCClauseKind::Independent;
135 }
136
138 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
139
146};
147// Represents the 'seq' clause.
149protected:
151 : OpenACCClause(OpenACCClauseKind::Seq, BeginLoc, EndLoc) {}
152
153public:
154 static bool classof(const OpenACCClause *C) {
155 return C->getClauseKind() == OpenACCClauseKind::Seq;
156 }
157
158 static OpenACCSeqClause *
159 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
160
167};
168// Represents the 'nohost' clause.
170protected:
173
174public:
175 static bool classof(const OpenACCClause *C) {
176 return C->getClauseKind() == OpenACCClauseKind::NoHost;
177 }
178 static OpenACCNoHostClause *
179 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
180
187};
188
189/// Represents a clause that has a list of parameters.
191 /// Location of the '('.
192 SourceLocation LParenLoc;
193
194protected:
196 SourceLocation LParenLoc, SourceLocation EndLoc)
197 : OpenACCClause(K, BeginLoc, EndLoc), LParenLoc(LParenLoc) {}
198
199public:
200 static bool classof(const OpenACCClause *C);
201
202 SourceLocation getLParenLoc() const { return LParenLoc; }
203
210};
211
212class OpenACCBindClause final : public OpenACCClauseWithParams {
213 std::variant<const StringLiteral *, const IdentifierInfo *> Argument;
214
215 OpenACCBindClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
216 const clang::StringLiteral *SL, SourceLocation EndLoc)
218 EndLoc),
219 Argument(SL) {}
220 OpenACCBindClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
221 const IdentifierInfo *ID, SourceLocation EndLoc)
223 EndLoc),
224 Argument(ID) {}
225
226public:
227 static bool classof(const OpenACCClause *C) {
228 return C->getClauseKind() == OpenACCClauseKind::Bind;
229 }
230 static OpenACCBindClause *Create(const ASTContext &C, SourceLocation BeginLoc,
231 SourceLocation LParenLoc,
232 const IdentifierInfo *ID,
233 SourceLocation EndLoc);
234 static OpenACCBindClause *Create(const ASTContext &C, SourceLocation BeginLoc,
235 SourceLocation LParenLoc,
236 const StringLiteral *SL,
237 SourceLocation EndLoc);
238
239 bool isStringArgument() const {
240 return std::holds_alternative<const StringLiteral *>(Argument);
241 }
242
244 return std::get<const StringLiteral *>(Argument);
245 }
246
247 bool isIdentifierArgument() const {
248 return std::holds_alternative<const IdentifierInfo *>(Argument);
249 }
250
252 return std::get<const IdentifierInfo *>(Argument);
253 }
254};
255
256bool operator==(const OpenACCBindClause &LHS, const OpenACCBindClause &RHS);
257inline bool operator!=(const OpenACCBindClause &LHS,
258 const OpenACCBindClause &RHS) {
259 return !(LHS == RHS);
260}
261
263/// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or
264/// an identifier. The 'asterisk' means 'the rest'.
265class OpenACCDeviceTypeClause final
267 private llvm::TrailingObjects<OpenACCDeviceTypeClause,
268 DeviceTypeArgument> {
269 friend TrailingObjects;
270 // Data stored in trailing objects as IdentifierInfo* /SourceLocation pairs. A
271 // nullptr IdentifierInfo* represents an asterisk.
272 unsigned NumArchs;
273 OpenACCDeviceTypeClause(OpenACCClauseKind K, SourceLocation BeginLoc,
274 SourceLocation LParenLoc,
276 SourceLocation EndLoc)
277 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
278 NumArchs(Archs.size()) {
279 assert(
281 "Invalid clause kind for device-type");
282
283 assert(!llvm::any_of(Archs, [](const DeviceTypeArgument &Arg) {
284 return Arg.getLoc().isInvalid();
285 }) && "Invalid SourceLocation for an argument");
286
287 assert((Archs.size() == 1 ||
288 !llvm::any_of(Archs,
289 [](const DeviceTypeArgument &Arg) {
290 return Arg.getIdentifierInfo() == nullptr;
291 })) &&
292 "Only a single asterisk version is permitted, and must be the "
293 "only one");
294
295 llvm::uninitialized_copy(Archs, getTrailingObjects());
296 }
297
298public:
299 static bool classof(const OpenACCClause *C) {
300 return C->getClauseKind() == OpenACCClauseKind::DType ||
301 C->getClauseKind() == OpenACCClauseKind::DeviceType;
302 }
303 bool hasAsterisk() const {
304 return getArchitectures().size() > 0 &&
305 getArchitectures()[0].getIdentifierInfo() == nullptr;
306 }
307
309 return getTrailingObjects(NumArchs);
310 }
311
315 SourceLocation EndLoc);
316};
317
318/// A 'default' clause, has the optional 'none' or 'present' argument.
320 friend class ASTReaderStmt;
321 friend class ASTWriterStmt;
322
323 OpenACCDefaultClauseKind DefaultClauseKind;
324
325protected:
327 SourceLocation LParenLoc, SourceLocation EndLoc)
328 : OpenACCClauseWithParams(OpenACCClauseKind::Default, BeginLoc, LParenLoc,
329 EndLoc),
330 DefaultClauseKind(K) {
331 assert((DefaultClauseKind == OpenACCDefaultClauseKind::None ||
332 DefaultClauseKind == OpenACCDefaultClauseKind::Present) &&
333 "Invalid Clause Kind");
334 }
335
336public:
337 static bool classof(const OpenACCClause *C) {
338 return C->getClauseKind() == OpenACCClauseKind::Default;
339 }
341 return DefaultClauseKind;
342 }
343
346 SourceLocation BeginLoc,
347 SourceLocation LParenLoc,
348 SourceLocation EndLoc);
349};
350
351/// Represents one of the handful of classes that has an optional/required
352/// 'condition' expression as an argument.
354 Expr *ConditionExpr = nullptr;
355
356protected:
358 SourceLocation LParenLoc, Expr *ConditionExpr,
359 SourceLocation EndLoc)
360 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
361 ConditionExpr(ConditionExpr) {}
362
363public:
364 static bool classof(const OpenACCClause *C);
365
366 bool hasConditionExpr() const { return ConditionExpr; }
367 const Expr *getConditionExpr() const { return ConditionExpr; }
368 Expr *getConditionExpr() { return ConditionExpr; }
369
371 if (ConditionExpr)
372 return child_range(reinterpret_cast<Stmt **>(&ConditionExpr),
373 reinterpret_cast<Stmt **>(&ConditionExpr + 1));
375 }
376
378 if (ConditionExpr)
379 return const_child_range(
380 reinterpret_cast<Stmt *const *>(&ConditionExpr),
381 reinterpret_cast<Stmt *const *>(&ConditionExpr + 1));
383 }
384};
385
386/// An 'if' clause, which has a required condition expression.
388protected:
390 Expr *ConditionExpr, SourceLocation EndLoc);
391
392public:
393 static bool classof(const OpenACCClause *C) {
394 return C->getClauseKind() == OpenACCClauseKind::If;
395 }
396 static OpenACCIfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
397 SourceLocation LParenLoc, Expr *ConditionExpr,
398 SourceLocation EndLoc);
399};
400
401/// A 'self' clause, which has an optional condition expression, or, in the
402/// event of an 'update' directive, contains a 'VarList'.
403class OpenACCSelfClause final
405 private llvm::TrailingObjects<OpenACCSelfClause, Expr *> {
406 friend TrailingObjects;
407 // Holds whether this HAS a condition expression. Lacks a value if this is NOT
408 // a condition-expr self clause.
409 std::optional<bool> HasConditionExpr;
410 // Holds the number of stored expressions. In the case of a condition-expr
411 // self clause, this is expected to be ONE (and there to be 1 trailing
412 // object), whether or not that is null.
413 unsigned NumExprs;
414
415 OpenACCSelfClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
416 Expr *ConditionExpr, SourceLocation EndLoc);
417 OpenACCSelfClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
418 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
419
420 // Intentionally internal, meant to be an implementation detail of everything
421 // else. All non-internal uses should go through getConditionExpr/getVarList.
422 ArrayRef<Expr *> getExprs() const { return getTrailingObjects(NumExprs); }
423
424public:
425 static bool classof(const OpenACCClause *C) {
426 return C->getClauseKind() == OpenACCClauseKind::Self;
427 }
428
429 bool isConditionExprClause() const { return HasConditionExpr.has_value(); }
430 bool isVarListClause() const { return !isConditionExprClause(); }
431 bool isEmptySelfClause() const {
432 return (isConditionExprClause() && !hasConditionExpr()) ||
433 (!isConditionExprClause() && getVarList().empty());
434 }
435
436 bool hasConditionExpr() const {
437 assert(HasConditionExpr.has_value() &&
438 "VarList Self Clause asked about condition expression");
439 return *HasConditionExpr;
440 }
441
442 const Expr *getConditionExpr() const {
443 assert(HasConditionExpr.has_value() &&
444 "VarList Self Clause asked about condition expression");
445 assert(getExprs().size() == 1 &&
446 "ConditionExpr Self Clause with too many Exprs");
447 return getExprs()[0];
448 }
449
451 assert(HasConditionExpr.has_value() &&
452 "VarList Self Clause asked about condition expression");
453 assert(getExprs().size() == 1 &&
454 "ConditionExpr Self Clause with too many Exprs");
455 return getExprs()[0];
456 }
457
459 assert(!HasConditionExpr.has_value() &&
460 "Condition Expr self clause asked about var list");
461 return getExprs();
462 }
463
465 return child_range(
466 reinterpret_cast<Stmt **>(getTrailingObjects()),
467 reinterpret_cast<Stmt **>(getTrailingObjects() + NumExprs));
468 }
469
471 return const_cast<OpenACCSelfClause *>(this)->children();
472 }
473
474 static OpenACCSelfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
475 SourceLocation LParenLoc,
476 Expr *ConditionExpr, SourceLocation EndLoc);
477 static OpenACCSelfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
478 SourceLocation LParenLoc,
479 ArrayRef<Expr *> ConditionExpr,
480 SourceLocation EndLoc);
481};
482
483/// Represents a clause that has one or more expressions associated with it.
486
487protected:
489 SourceLocation LParenLoc, SourceLocation EndLoc)
490 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc) {}
491
492 /// Used only for initialization, the leaf class can initialize this to
493 /// trailing storage.
495 assert(Exprs.empty() && "Cannot change Exprs list");
496 Exprs = NewExprs;
497 }
498
499 /// Used only for initialization, the leaf class can initialize this to
500 /// trailing storage, and initialize the data in the trailing storage as well.
502 assert(NewStorage.size() == Exprs.size());
503 llvm::uninitialized_copy(Exprs, NewStorage.begin());
504 setExprs(NewStorage);
505 }
506
507 /// Gets the entire list of expressions, but leave it to the
508 /// individual clauses to expose this how they'd like.
509 ArrayRef<Expr *> getExprs() const { return Exprs; }
510
511public:
512 static bool classof(const OpenACCClause *C);
514 return child_range(reinterpret_cast<Stmt **>(Exprs.begin()),
515 reinterpret_cast<Stmt **>(Exprs.end()));
516 }
517
519 return const_cast<OpenACCClauseWithExprs *>(this)->children();
520 }
521};
522
523// Represents the 'devnum' and expressions lists for the 'wait' clause.
524class OpenACCWaitClause final
525 : public OpenACCClauseWithExprs,
526 private llvm::TrailingObjects<OpenACCWaitClause, Expr *> {
527 friend TrailingObjects;
528 SourceLocation QueuesLoc;
529 OpenACCWaitClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
530 Expr *DevNumExpr, SourceLocation QueuesLoc,
531 ArrayRef<Expr *> QueueIdExprs, SourceLocation EndLoc)
532 : OpenACCClauseWithExprs(OpenACCClauseKind::Wait, BeginLoc, LParenLoc,
533 EndLoc),
534 QueuesLoc(QueuesLoc) {
535 // The first element of the trailing storage is always the devnum expr,
536 // whether it is used or not.
537 auto *Exprs = getTrailingObjects();
538 llvm::uninitialized_copy(ArrayRef(DevNumExpr), Exprs);
539 llvm::uninitialized_copy(QueueIdExprs, Exprs + 1);
540 setExprs(getTrailingObjects(QueueIdExprs.size() + 1));
541 }
542
543public:
544 static bool classof(const OpenACCClause *C) {
545 return C->getClauseKind() == OpenACCClauseKind::Wait;
546 }
547 static OpenACCWaitClause *Create(const ASTContext &C, SourceLocation BeginLoc,
548 SourceLocation LParenLoc, Expr *DevNumExpr,
549 SourceLocation QueuesLoc,
550 ArrayRef<Expr *> QueueIdExprs,
551 SourceLocation EndLoc);
552
553 bool hasQueuesTag() const { return !QueuesLoc.isInvalid(); }
554 SourceLocation getQueuesLoc() const { return QueuesLoc; }
555 bool hasDevNumExpr() const { return getExprs()[0]; }
556 Expr *getDevNumExpr() const { return getExprs()[0]; }
558 return OpenACCClauseWithExprs::getExprs().drop_front();
559 }
560 // If this is a plain `wait` (no parens) this returns 'false'. Else Sema/Parse
561 // ensures we have at least one QueueId expression.
562 bool hasExprs() const { return getLParenLoc().isValid(); }
563};
564
565class OpenACCNumGangsClause final
566 : public OpenACCClauseWithExprs,
567 private llvm::TrailingObjects<OpenACCNumGangsClause, Expr *> {
568 friend TrailingObjects;
569
570 OpenACCNumGangsClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
571 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
573 EndLoc) {
574 setExprs(getTrailingObjects(IntExprs.size()), IntExprs);
575 }
576
577public:
578 static bool classof(const OpenACCClause *C) {
579 return C->getClauseKind() == OpenACCClauseKind::NumGangs;
580 }
581 static OpenACCNumGangsClause *
582 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
583 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
584
588};
589
590class OpenACCTileClause final
591 : public OpenACCClauseWithExprs,
592 private llvm::TrailingObjects<OpenACCTileClause, Expr *> {
593 friend TrailingObjects;
594 OpenACCTileClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
595 ArrayRef<Expr *> SizeExprs, SourceLocation EndLoc)
596 : OpenACCClauseWithExprs(OpenACCClauseKind::Tile, BeginLoc, LParenLoc,
597 EndLoc) {
598 setExprs(getTrailingObjects(SizeExprs.size()), SizeExprs);
599 }
600
601public:
602 static bool classof(const OpenACCClause *C) {
603 return C->getClauseKind() == OpenACCClauseKind::Tile;
604 }
605 static OpenACCTileClause *Create(const ASTContext &C, SourceLocation BeginLoc,
606 SourceLocation LParenLoc,
607 ArrayRef<Expr *> SizeExprs,
608 SourceLocation EndLoc);
609
613};
614
615/// Represents one of a handful of clauses that have a single integer
616/// expression.
618 Expr *IntExpr;
619
620protected:
622 SourceLocation LParenLoc, Expr *IntExpr,
623 SourceLocation EndLoc)
624 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc),
625 IntExpr(IntExpr) {
626 if (IntExpr)
627 setExprs(MutableArrayRef<Expr *>{&this->IntExpr, 1});
628 }
629
630public:
631 static bool classof(const OpenACCClause *C);
632 bool hasIntExpr() const { return !getExprs().empty(); }
633 const Expr *getIntExpr() const {
634 return hasIntExpr() ? getExprs()[0] : nullptr;
635 }
636
637 Expr *getIntExpr() { return hasIntExpr() ? getExprs()[0] : nullptr; };
638};
639
641 : public OpenACCClauseWithExprs,
642 private llvm::TrailingObjects<OpenACCGangClause, Expr *, OpenACCGangKind> {
643 friend TrailingObjects;
644protected:
647 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
648
649 OpenACCGangKind getGangKind(unsigned I) const {
650 return getTrailingObjects<OpenACCGangKind>()[I];
651 }
652
653public:
654 static bool classof(const OpenACCClause *C) {
655 return C->getClauseKind() == OpenACCClauseKind::Gang;
656 }
657
658 size_t numTrailingObjects(OverloadToken<Expr *>) const {
659 return getNumExprs();
660 }
661
662 unsigned getNumExprs() const { return getExprs().size(); }
663 std::pair<OpenACCGangKind, const Expr *> getExpr(unsigned I) const {
664 return {getGangKind(I), getExprs()[I]};
665 }
666
668 for (unsigned I = 0; I < getNumExprs(); ++I) {
669 if (getGangKind(I) == GK)
670 return true;
671 }
672 return false;
673 }
674
675 static OpenACCGangClause *
676 Create(const ASTContext &Ctx, SourceLocation BeginLoc,
677 SourceLocation LParenLoc, ArrayRef<OpenACCGangKind> GangKinds,
678 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
679};
680
682protected:
684 Expr *IntExpr, SourceLocation EndLoc);
685
686public:
687 static bool classof(const OpenACCClause *C) {
688 return C->getClauseKind() == OpenACCClauseKind::Worker;
689 }
690
691 static OpenACCWorkerClause *Create(const ASTContext &Ctx,
692 SourceLocation BeginLoc,
693 SourceLocation LParenLoc, Expr *IntExpr,
694 SourceLocation EndLoc);
695};
696
698protected:
700 Expr *IntExpr, SourceLocation EndLoc);
701
702public:
703 static bool classof(const OpenACCClause *C) {
704 return C->getClauseKind() == OpenACCClauseKind::Vector;
705 }
706
707 static OpenACCVectorClause *Create(const ASTContext &Ctx,
708 SourceLocation BeginLoc,
709 SourceLocation LParenLoc, Expr *IntExpr,
710 SourceLocation EndLoc);
711};
712
713class OpenACCNumWorkersClause : public OpenACCClauseWithSingleIntExpr {
714 OpenACCNumWorkersClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
715 Expr *IntExpr, SourceLocation EndLoc);
716
717public:
718 static bool classof(const OpenACCClause *C) {
719 return C->getClauseKind() == OpenACCClauseKind::NumWorkers;
720 }
722 SourceLocation BeginLoc,
723 SourceLocation LParenLoc,
724 Expr *IntExpr, SourceLocation EndLoc);
725};
726
727class OpenACCVectorLengthClause : public OpenACCClauseWithSingleIntExpr {
728 OpenACCVectorLengthClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
729 Expr *IntExpr, SourceLocation EndLoc);
730
731public:
732 static bool classof(const OpenACCClause *C) {
733 return C->getClauseKind() == OpenACCClauseKind::VectorLength;
734 }
736 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
737 Expr *IntExpr, SourceLocation EndLoc);
738};
739
740class OpenACCAsyncClause : public OpenACCClauseWithSingleIntExpr {
741 OpenACCAsyncClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
742 Expr *IntExpr, SourceLocation EndLoc);
743
744public:
745 static bool classof(const OpenACCClause *C) {
746 return C->getClauseKind() == OpenACCClauseKind::Async;
747 }
748 static OpenACCAsyncClause *Create(const ASTContext &C,
749 SourceLocation BeginLoc,
750 SourceLocation LParenLoc, Expr *IntExpr,
751 SourceLocation EndLoc);
752};
753
754class OpenACCDeviceNumClause : public OpenACCClauseWithSingleIntExpr {
755 OpenACCDeviceNumClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
756 Expr *IntExpr, SourceLocation EndLoc);
757
758public:
759 static bool classof(const OpenACCClause *C) {
760 return C->getClauseKind() == OpenACCClauseKind::DeviceNum;
761 }
763 SourceLocation BeginLoc,
764 SourceLocation LParenLoc, Expr *IntExpr,
765 SourceLocation EndLoc);
766};
767
768class OpenACCDefaultAsyncClause : public OpenACCClauseWithSingleIntExpr {
769 OpenACCDefaultAsyncClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
770 Expr *IntExpr, SourceLocation EndLoc);
771
772public:
773 static bool classof(const OpenACCClause *C) {
774 return C->getClauseKind() == OpenACCClauseKind::DefaultAsync;
775 }
777 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
778 Expr *IntExpr, SourceLocation EndLoc);
779};
780
781/// Represents a 'collapse' clause on a 'loop' construct. This clause takes an
782/// integer constant expression 'N' that represents how deep to collapse the
783/// construct. It also takes an optional 'force' tag that permits intervening
784/// code in the loops.
785class OpenACCCollapseClause : public OpenACCClauseWithSingleIntExpr {
786 bool HasForce = false;
787
788 OpenACCCollapseClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
789 bool HasForce, Expr *LoopCount, SourceLocation EndLoc);
790
791public:
792 const Expr *getLoopCount() const { return getIntExpr(); }
793 Expr *getLoopCount() { return getIntExpr(); }
794
795 bool hasForce() const { return HasForce; }
796
797 static bool classof(const OpenACCClause *C) {
798 return C->getClauseKind() == OpenACCClauseKind::Collapse;
799 }
800
802 SourceLocation BeginLoc,
803 SourceLocation LParenLoc, bool HasForce,
804 Expr *LoopCount, SourceLocation EndLoc);
805};
806
807/// Represents a clause with one or more 'var' objects, represented as an expr,
808/// as its arguments. Var-list is expected to be stored in trailing storage.
809/// For now, we're just storing the original expression in its entirety, unlike
810/// OMP which has to do a bunch of work to create a private.
812protected:
814 SourceLocation LParenLoc, SourceLocation EndLoc)
815 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc) {}
816
817public:
818 static bool classof(const OpenACCClause *C);
820};
821
822// Represents all the data needed for recipe generation. The declaration and
823// init are stored separately, because in the case of subscripts, we do the
824// alloca at the level of the base, and the init at the element level.
827
829
830 bool isSet() const { return AllocaDecl; }
831
833 return OpenACCPrivateRecipe(/*AllocaDecl=*/nullptr);
834 }
835};
836
837class OpenACCPrivateClause final
839 private llvm::TrailingObjects<OpenACCPrivateClause, Expr *,
840 OpenACCPrivateRecipe> {
841 friend TrailingObjects;
842
843 OpenACCPrivateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
844 ArrayRef<Expr *> VarList,
846 SourceLocation EndLoc)
848 LParenLoc, EndLoc) {
849 assert(VarList.size() == InitRecipes.size());
850 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
851 llvm::uninitialized_copy(InitRecipes,
852 getTrailingObjects<OpenACCPrivateRecipe>());
853 }
854
855public:
856 static bool classof(const OpenACCClause *C) {
857 return C->getClauseKind() == OpenACCClauseKind::Private;
858 }
859 // Gets a list of 'made up' `VarDecl` objects that can be used by codegen to
860 // ensure that we properly initialize each of these variables.
863 getTrailingObjects<OpenACCPrivateRecipe>(), getExprs().size()};
864 }
865
866 static OpenACCPrivateClause *
867 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
869 SourceLocation EndLoc);
870
871 size_t numTrailingObjects(OverloadToken<Expr *>) const {
872 return getExprs().size();
873 }
874};
875
876// A 'pair' to stand in for the recipe. RecipeDecl is the main declaration, and
877// InitFromTemporary is the 'temp' declaration we put in to be 'copied from'.
883 assert(!InitFromTemporary || InitFromTemporary->getInit() == nullptr);
884 }
885
886 bool isSet() const { return AllocaDecl; }
887
889 return OpenACCFirstPrivateRecipe(/*AllocaDecl=*/nullptr,
890 /*InitFromTemporary=*/nullptr);
891 }
892};
893
894class OpenACCFirstPrivateClause final
896 private llvm::TrailingObjects<OpenACCFirstPrivateClause, Expr *,
897 OpenACCFirstPrivateRecipe> {
898 friend TrailingObjects;
899
900 OpenACCFirstPrivateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
901 ArrayRef<Expr *> VarList,
903 SourceLocation EndLoc)
905 LParenLoc, EndLoc) {
906 assert(VarList.size() == InitRecipes.size());
907 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
908 llvm::uninitialized_copy(InitRecipes,
909 getTrailingObjects<OpenACCFirstPrivateRecipe>());
910 }
911
912public:
913 static bool classof(const OpenACCClause *C) {
914 return C->getClauseKind() == OpenACCClauseKind::FirstPrivate;
915 }
916
917 // Gets a list of 'made up' `VarDecl` objects that can be used by codegen to
918 // ensure that we properly initialize each of these variables.
921 getTrailingObjects<OpenACCFirstPrivateRecipe>(), getExprs().size()};
922 }
923
925 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
926 ArrayRef<Expr *> VarList,
928 SourceLocation EndLoc);
929
930 size_t numTrailingObjects(OverloadToken<Expr *>) const {
931 return getExprs().size();
932 }
933};
934
935class OpenACCDevicePtrClause final
937 private llvm::TrailingObjects<OpenACCDevicePtrClause, Expr *> {
938 friend TrailingObjects;
939
940 OpenACCDevicePtrClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
941 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
943 LParenLoc, EndLoc) {
944 setExprs(getTrailingObjects(VarList.size()), VarList);
945 }
946
947public:
948 static bool classof(const OpenACCClause *C) {
949 return C->getClauseKind() == OpenACCClauseKind::DevicePtr;
950 }
952 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
953 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
954};
955
956class OpenACCAttachClause final
958 private llvm::TrailingObjects<OpenACCAttachClause, Expr *> {
959 friend TrailingObjects;
960
961 OpenACCAttachClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
962 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
964 EndLoc) {
965 setExprs(getTrailingObjects(VarList.size()), VarList);
966 }
967
968public:
969 static bool classof(const OpenACCClause *C) {
970 return C->getClauseKind() == OpenACCClauseKind::Attach;
971 }
972 static OpenACCAttachClause *
973 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
974 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
975};
976
977class OpenACCDetachClause final
979 private llvm::TrailingObjects<OpenACCDetachClause, Expr *> {
980 friend TrailingObjects;
981
982 OpenACCDetachClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
983 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
985 EndLoc) {
986 setExprs(getTrailingObjects(VarList.size()), VarList);
987 }
988
989public:
990 static bool classof(const OpenACCClause *C) {
991 return C->getClauseKind() == OpenACCClauseKind::Detach;
992 }
993 static OpenACCDetachClause *
994 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
995 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
996};
997
998class OpenACCDeleteClause final
1000 private llvm::TrailingObjects<OpenACCDeleteClause, Expr *> {
1001 friend TrailingObjects;
1002
1003 OpenACCDeleteClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1004 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1006 EndLoc) {
1007 setExprs(getTrailingObjects(VarList.size()), VarList);
1008 }
1009
1010public:
1011 static bool classof(const OpenACCClause *C) {
1012 return C->getClauseKind() == OpenACCClauseKind::Delete;
1013 }
1014 static OpenACCDeleteClause *
1015 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1016 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1017};
1018
1019class OpenACCUseDeviceClause final
1020 : public OpenACCClauseWithVarList,
1021 private llvm::TrailingObjects<OpenACCUseDeviceClause, Expr *> {
1022 friend TrailingObjects;
1023
1024 OpenACCUseDeviceClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1025 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1027 LParenLoc, EndLoc) {
1028 setExprs(getTrailingObjects(VarList.size()), VarList);
1029 }
1030
1031public:
1032 static bool classof(const OpenACCClause *C) {
1033 return C->getClauseKind() == OpenACCClauseKind::UseDevice;
1034 }
1035 static OpenACCUseDeviceClause *
1036 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1037 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1038};
1039
1040class OpenACCNoCreateClause final
1041 : public OpenACCClauseWithVarList,
1042 private llvm::TrailingObjects<OpenACCNoCreateClause, Expr *> {
1043 friend TrailingObjects;
1044
1045 OpenACCNoCreateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1046 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1048 LParenLoc, EndLoc) {
1049 setExprs(getTrailingObjects(VarList.size()), VarList);
1050 }
1051
1052public:
1053 static bool classof(const OpenACCClause *C) {
1054 return C->getClauseKind() == OpenACCClauseKind::NoCreate;
1055 }
1056 static OpenACCNoCreateClause *
1057 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1058 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1059};
1060
1061class OpenACCPresentClause final
1062 : public OpenACCClauseWithVarList,
1063 private llvm::TrailingObjects<OpenACCPresentClause, Expr *> {
1064 friend TrailingObjects;
1065
1066 OpenACCPresentClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1067 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1069 LParenLoc, EndLoc) {
1070 setExprs(getTrailingObjects(VarList.size()), VarList);
1071 }
1072
1073public:
1074 static bool classof(const OpenACCClause *C) {
1075 return C->getClauseKind() == OpenACCClauseKind::Present;
1076 }
1077 static OpenACCPresentClause *
1078 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1079 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1080};
1081class OpenACCHostClause final
1082 : public OpenACCClauseWithVarList,
1083 private llvm::TrailingObjects<OpenACCHostClause, Expr *> {
1084 friend TrailingObjects;
1085
1086 OpenACCHostClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1087 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1089 EndLoc) {
1090 setExprs(getTrailingObjects(VarList.size()), VarList);
1091 }
1092
1093public:
1094 static bool classof(const OpenACCClause *C) {
1095 return C->getClauseKind() == OpenACCClauseKind::Host;
1096 }
1097 static OpenACCHostClause *Create(const ASTContext &C, SourceLocation BeginLoc,
1098 SourceLocation LParenLoc,
1099 ArrayRef<Expr *> VarList,
1100 SourceLocation EndLoc);
1101};
1102
1103class OpenACCDeviceClause final
1104 : public OpenACCClauseWithVarList,
1105 private llvm::TrailingObjects<OpenACCDeviceClause, Expr *> {
1106 friend TrailingObjects;
1107
1108 OpenACCDeviceClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1109 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1111 EndLoc) {
1112 setExprs(getTrailingObjects(VarList.size()), VarList);
1113 }
1114
1115public:
1116 static bool classof(const OpenACCClause *C) {
1117 return C->getClauseKind() == OpenACCClauseKind::Device;
1118 }
1119 static OpenACCDeviceClause *
1120 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1121 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1122};
1123
1124class OpenACCCopyClause final
1125 : public OpenACCClauseWithVarList,
1126 private llvm::TrailingObjects<OpenACCCopyClause, Expr *> {
1127 friend TrailingObjects;
1128 OpenACCModifierKind Modifiers;
1129
1130 OpenACCCopyClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1131 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1132 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1133 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1134 Modifiers(Mods) {
1135 assert((Spelling == OpenACCClauseKind::Copy ||
1136 Spelling == OpenACCClauseKind::PCopy ||
1137 Spelling == OpenACCClauseKind::PresentOrCopy) &&
1138 "Invalid clause kind for copy-clause");
1139 setExprs(getTrailingObjects(VarList.size()), VarList);
1140 }
1141
1142public:
1143 static bool classof(const OpenACCClause *C) {
1144 return C->getClauseKind() == OpenACCClauseKind::Copy ||
1145 C->getClauseKind() == OpenACCClauseKind::PCopy ||
1146 C->getClauseKind() == OpenACCClauseKind::PresentOrCopy;
1147 }
1148 static OpenACCCopyClause *
1149 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1150 SourceLocation BeginLoc, SourceLocation LParenLoc,
1152 SourceLocation EndLoc);
1153
1154 OpenACCModifierKind getModifierList() const { return Modifiers; }
1155};
1156
1157class OpenACCCopyInClause final
1158 : public OpenACCClauseWithVarList,
1159 private llvm::TrailingObjects<OpenACCCopyInClause, Expr *> {
1160 friend TrailingObjects;
1161 OpenACCModifierKind Modifiers;
1162
1163 OpenACCCopyInClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1164 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1165 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1166 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1167 Modifiers(Mods) {
1168 assert((Spelling == OpenACCClauseKind::CopyIn ||
1169 Spelling == OpenACCClauseKind::PCopyIn ||
1171 "Invalid clause kind for copyin-clause");
1172 setExprs(getTrailingObjects(VarList.size()), VarList);
1173 }
1174
1175public:
1176 static bool classof(const OpenACCClause *C) {
1177 return C->getClauseKind() == OpenACCClauseKind::CopyIn ||
1178 C->getClauseKind() == OpenACCClauseKind::PCopyIn ||
1179 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyIn;
1180 }
1181 OpenACCModifierKind getModifierList() const { return Modifiers; }
1182 static OpenACCCopyInClause *
1183 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1184 SourceLocation BeginLoc, SourceLocation LParenLoc,
1186 SourceLocation EndLoc);
1187};
1188
1189class OpenACCCopyOutClause final
1190 : public OpenACCClauseWithVarList,
1191 private llvm::TrailingObjects<OpenACCCopyOutClause, Expr *> {
1192 friend TrailingObjects;
1193 OpenACCModifierKind Modifiers;
1194
1195 OpenACCCopyOutClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1196 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1197 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1198 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1199 Modifiers(Mods) {
1200 assert((Spelling == OpenACCClauseKind::CopyOut ||
1201 Spelling == OpenACCClauseKind::PCopyOut ||
1203 "Invalid clause kind for copyout-clause");
1204 setExprs(getTrailingObjects(VarList.size()), VarList);
1205 }
1206
1207public:
1208 static bool classof(const OpenACCClause *C) {
1209 return C->getClauseKind() == OpenACCClauseKind::CopyOut ||
1210 C->getClauseKind() == OpenACCClauseKind::PCopyOut ||
1211 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyOut;
1212 }
1213 OpenACCModifierKind getModifierList() const { return Modifiers; }
1214 static OpenACCCopyOutClause *
1215 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1216 SourceLocation BeginLoc, SourceLocation LParenLoc,
1218 SourceLocation EndLoc);
1219};
1220
1221class OpenACCCreateClause final
1222 : public OpenACCClauseWithVarList,
1223 private llvm::TrailingObjects<OpenACCCreateClause, Expr *> {
1224 friend TrailingObjects;
1225 OpenACCModifierKind Modifiers;
1226
1227 OpenACCCreateClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1228 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1229 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1230 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1231 Modifiers(Mods) {
1232 assert((Spelling == OpenACCClauseKind::Create ||
1233 Spelling == OpenACCClauseKind::PCreate ||
1235 "Invalid clause kind for create-clause");
1236 setExprs(getTrailingObjects(VarList.size()), VarList);
1237 }
1238
1239public:
1240 static bool classof(const OpenACCClause *C) {
1241 return C->getClauseKind() == OpenACCClauseKind::Create ||
1242 C->getClauseKind() == OpenACCClauseKind::PCreate ||
1243 C->getClauseKind() == OpenACCClauseKind::PresentOrCreate;
1244 }
1245 OpenACCModifierKind getModifierList() const { return Modifiers; }
1246 static OpenACCCreateClause *
1247 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1248 SourceLocation BeginLoc, SourceLocation LParenLoc,
1250 SourceLocation EndLoc);
1251};
1252
1253// A structure to stand in for the recipe on a reduction. RecipeDecl is the
1254// 'main' declaration used for initializaiton, which is fixed.
1255struct OpenACCReductionRecipe {
1257
1258 // A combiner recipe is represented by an operation expression. However, in
1259 // order to generate these properly, we have to make up a LHS and a RHS
1260 // expression for the purposes of generation.
1266
1267 // Contains a collection of the recipe elements we need for the combiner:
1268 // -For Scalars, there will be 1 element, just the combiner for that scalar.
1269 // -For a struct with a valid operator, this will be 1 element, just that
1270 // call.
1271 // -For a struct without the operator, this will be 1 element per field, which
1272 // should be the combiner for that element.
1273 // -For an array of any of the above, it will be the above for the element.
1274 // Note: These are necessarily stored in either Trailing Storage (when in the
1275 // AST), or in a separate collection when being semantically analyzed.
1277
1278 bool isSet() const { return AllocaDecl; }
1279
1280private:
1282 OpenACCReductionRecipe(VarDecl *A, llvm::ArrayRef<CombinerRecipe> Combiners)
1283 : AllocaDecl(A), CombinerRecipes(Combiners) {}
1284};
1285
1286// A version of the above that is used for semantic analysis, at a time before
1287// the OpenACCReductionClause node has been created. This one has storage for
1288// the CombinerRecipe, since Trailing storage for it doesn't exist yet.
1302
1303class OpenACCReductionClause final
1304 : public OpenACCClauseWithVarList,
1305 private llvm::TrailingObjects<OpenACCReductionClause, Expr *,
1306 OpenACCReductionRecipe,
1307 OpenACCReductionRecipe::CombinerRecipe> {
1308 friend TrailingObjects;
1310
1311 OpenACCReductionClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1312 OpenACCReductionOperator Operator,
1313 ArrayRef<Expr *> VarList,
1315 SourceLocation EndLoc)
1317 LParenLoc, EndLoc),
1318 Op(Operator) {
1319 assert(VarList.size() == Recipes.size());
1320 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1321
1322 // Since we're using trailing storage on this node to store the 'combiner'
1323 // recipes of the Reduction Recipes (which have a 1:M relationship), we need
1324 // to ensure we get the ArrayRef of each of our combiner 'correct'.
1326 getTrailingObjects<OpenACCReductionRecipe::CombinerRecipe>();
1327 for (const auto &[Idx, R] : llvm::enumerate(Recipes)) {
1328
1329 // ArrayRef to the 'correct' data location in trailing storage.
1331 NewCombiners{CurCombinerLoc, R.CombinerRecipes.size()};
1332 CurCombinerLoc += R.CombinerRecipes.size();
1333
1334 llvm::uninitialized_copy(R.CombinerRecipes, NewCombiners.begin());
1335
1336 // Placement new into the correct location in trailng storage.
1337 new (&getTrailingObjects<OpenACCReductionRecipe>()[Idx])
1338 OpenACCReductionRecipe(R.AllocaDecl, NewCombiners);
1339 }
1340 }
1341
1342public:
1343 static bool classof(const OpenACCClause *C) {
1344 return C->getClauseKind() == OpenACCClauseKind::Reduction;
1345 }
1346
1349 getTrailingObjects<OpenACCReductionRecipe>(), getExprs().size()};
1350 }
1351
1352 static OpenACCReductionClause *
1353 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1356 SourceLocation EndLoc);
1357
1359
1360 size_t numTrailingObjects(OverloadToken<Expr *>) const {
1361 return getExprs().size();
1362 }
1363 size_t numTrailingObjects(OverloadToken<OpenACCReductionRecipe>) const {
1364 return getExprs().size();
1365 }
1366};
1367
1368class OpenACCLinkClause final
1369 : public OpenACCClauseWithVarList,
1370 private llvm::TrailingObjects<OpenACCLinkClause, Expr *> {
1371 friend TrailingObjects;
1372
1373 OpenACCLinkClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1374 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1376 EndLoc) {
1377 setExprs(getTrailingObjects(VarList.size()), VarList);
1378 }
1379
1380public:
1381 static bool classof(const OpenACCClause *C) {
1382 return C->getClauseKind() == OpenACCClauseKind::Link;
1383 }
1384
1385 static OpenACCLinkClause *Create(const ASTContext &C, SourceLocation BeginLoc,
1386 SourceLocation LParenLoc,
1387 ArrayRef<Expr *> VarList,
1388 SourceLocation EndLoc);
1389};
1390
1391class OpenACCDeviceResidentClause final
1392 : public OpenACCClauseWithVarList,
1393 private llvm::TrailingObjects<OpenACCDeviceResidentClause, Expr *> {
1394 friend TrailingObjects;
1395
1396 OpenACCDeviceResidentClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1397 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1399 LParenLoc, EndLoc) {
1400 setExprs(getTrailingObjects(VarList.size()), VarList);
1401 }
1402
1403public:
1404 static bool classof(const OpenACCClause *C) {
1405 return C->getClauseKind() == OpenACCClauseKind::DeviceResident;
1406 }
1407
1409 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1410 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1411};
1412
1413template <class Impl> class OpenACCClauseVisitor {
1414 Impl &getDerived() { return static_cast<Impl &>(*this); }
1415
1416public:
1418 for (const OpenACCClause *Clause : List)
1419 Visit(Clause);
1420 }
1421
1422 void Visit(const OpenACCClause *C) {
1423 if (!C)
1424 return;
1425
1426 switch (C->getClauseKind()) {
1427#define VISIT_CLAUSE(CLAUSE_NAME) \
1428 case OpenACCClauseKind::CLAUSE_NAME: \
1429 getDerived().Visit##CLAUSE_NAME##Clause( \
1430 *cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1431 return;
1432#define CLAUSE_ALIAS(ALIAS_NAME, CLAUSE_NAME, DEPRECATED) \
1433 case OpenACCClauseKind::ALIAS_NAME: \
1434 getDerived().Visit##CLAUSE_NAME##Clause( \
1435 *cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1436 return;
1437#include "clang/Basic/OpenACCClauses.def"
1438
1439 default:
1440 llvm_unreachable("Clause visitor not yet implemented");
1441 }
1442 llvm_unreachable("Invalid Clause kind");
1443 }
1444
1445#define VISIT_CLAUSE(CLAUSE_NAME) \
1446 void Visit##CLAUSE_NAME##Clause( \
1447 const OpenACC##CLAUSE_NAME##Clause &Clause) { \
1448 return getDerived().VisitClause(Clause); \
1449 }
1450
1451#include "clang/Basic/OpenACCClauses.def"
1452};
1453
1455 : public OpenACCClauseVisitor<OpenACCClausePrinter> {
1456 raw_ostream &OS;
1457 const PrintingPolicy &Policy;
1458
1459 void printExpr(const Expr *E);
1460
1461public:
1463 for (const OpenACCClause *Clause : List) {
1464 Visit(Clause);
1465
1466 if (Clause != List.back())
1467 OS << ' ';
1468 }
1469 }
1470 OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
1471 : OS(OS), Policy(Policy) {}
1472
1473#define VISIT_CLAUSE(CLAUSE_NAME) \
1474 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
1475#include "clang/Basic/OpenACCClauses.def"
1476};
1477
1478} // namespace clang
1479
1480#endif // LLVM_CLANG_AST_OPENACCCLAUSE_H
Defines the clang::ASTContext interface.
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:227
This represents one expression.
Definition Expr.h:112
One of these records is kept for each identifier that is lexed.
A simple pair of identifier info and location.
SourceLocation getLoc() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
const_child_range children() const
OpenACCAutoClause(SourceLocation BeginLoc, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
const IdentifierInfo * getIdentifierArgument() const
const StringLiteral * getStringArgument() const
static bool classof(const OpenACCClause *C)
bool isIdentifierArgument() const
OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
void VisitClauseList(ArrayRef< const OpenACCClause * > List)
void Visit(const OpenACCClause *C)
void VisitClauseList(ArrayRef< const OpenACCClause * > List)
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
void setExprs(MutableArrayRef< Expr * > NewStorage, ArrayRef< Expr * > Exprs)
Used only for initialization, the leaf class can initialize this to trailing storage,...
static bool classof(const OpenACCClause *C)
OpenACCClauseWithExprs(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
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.
SourceLocation getLParenLoc() const
static bool classof(const OpenACCClause *C)
OpenACCClauseWithParams(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
const_child_range children() const
OpenACCClauseWithSingleIntExpr(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
OpenACCClauseWithVarList(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
ArrayRef< Expr * > getVarList() const
This is the base type for all OpenACC Clauses.
StmtIterator child_iterator
OpenACCClauseKind getClauseKind() const
SourceLocation getBeginLoc() const
SourceRange getSourceRange() const
const_child_range children() const
static bool classof(const OpenACCClause *)
llvm::iterator_range< child_iterator > child_range
ConstStmtIterator const_child_iterator
OpenACCClause(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation EndLoc)
virtual ~OpenACCClause()=default
llvm::iterator_range< const_child_iterator > const_child_range
SourceLocation getEndLoc() const
Represents a 'collapse' clause on a 'loop' construct.
const Expr * getLoopCount() const
static bool classof(const OpenACCClause *C)
OpenACCModifierKind getModifierList() const
static bool classof(const OpenACCClause *C)
OpenACCModifierKind getModifierList() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
OpenACCModifierKind getModifierList() const
static bool classof(const OpenACCClause *C)
OpenACCModifierKind getModifierList() const
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)
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)
static bool classof(const OpenACCClause *C)
const_child_range children() const
size_t numTrailingObjects(OverloadToken< Expr * >) const
ArrayRef< OpenACCFirstPrivateRecipe > getInitRecipes() const
static bool classof(const OpenACCClause *C)
OpenACCGangKind getGangKind(unsigned I) const
bool hasExprOfKind(OpenACCGangKind GK) const
OpenACCGangClause(SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< OpenACCGangKind > GangKinds, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
size_t numTrailingObjects(OverloadToken< Expr * >) const
static bool classof(const OpenACCClause *C)
unsigned getNumExprs() const
std::pair< OpenACCGangKind, const Expr * > getExpr(unsigned I) const
static bool classof(const OpenACCClause *C)
An 'if' clause, which has a required condition expression.
OpenACCIfClause(SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
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)
OpenACCNoHostClause(SourceLocation BeginLoc, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
const_child_range children() const
ArrayRef< Expr * > getIntExprs() 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)
size_t numTrailingObjects(OverloadToken< Expr * >) const
ArrayRef< OpenACCPrivateRecipe > getInitRecipes() const
ArrayRef< OpenACCReductionRecipe > getRecipes() const
size_t numTrailingObjects(OverloadToken< OpenACCReductionRecipe >) const
size_t numTrailingObjects(OverloadToken< Expr * >) const
static bool classof(const OpenACCClause *C)
OpenACCReductionOperator getReductionOp() const
A 'self' clause, which has an optional condition expression, or, in the event of an 'update' directiv...
const Expr * getConditionExpr() const
bool isConditionExprClause() const
const_child_range children() const
static bool classof(const OpenACCClause *C)
ArrayRef< Expr * > getVarList() const
static bool classof(const OpenACCClause *C)
const_child_range children() const
OpenACCSeqClause(SourceLocation BeginLoc, SourceLocation EndLoc)
ArrayRef< Expr * > getSizeExprs() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
OpenACCVectorClause(SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
Expr * getDevNumExpr() const
ArrayRef< Expr * > getQueueIdExprs() const
SourceLocation getQueuesLoc() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
OpenACCWorkerClause(SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition Stmt.h:86
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1802
Represents a variable declaration or definition.
Definition Decl.h:924
The JSON file list parser is used to communicate input to InstallAPI.
OpenACCReductionOperator
OpenACCModifierKind
OpenACCClauseKind
Represents the kind of an OpenACC clause.
@ Auto
'auto' clause, allowed on 'loop' directives.
@ Bind
'bind' clause, allowed on routine constructs.
@ 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.
@ NoHost
'nohost' clause, allowed on 'routine' directives.
@ 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'.
@ Link
'link' clause, allowed on 'declare' construct.
@ 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...
@ Host
'host' clause, allowed on 'update' construct.
@ 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.
@ DeviceResident
'device_resident' clause, allowed on the 'declare' construct.
@ 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',...
@ Device
'device' clause, allowed on the 'update' construct.
@ 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.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition CallGraph.h:206
OpenACCDefaultClauseKind
IdentifierLoc DeviceTypeArgument
bool operator!=(CanQual< T > x, CanQual< U > y)
static OpenACCFirstPrivateRecipe Empty()
OpenACCFirstPrivateRecipe(VarDecl *A, VarDecl *T)
static OpenACCPrivateRecipe Empty()
OpenACCReductionRecipeWithStorage(VarDecl *A, llvm::ArrayRef< OpenACCReductionRecipe::CombinerRecipe > Combiners)
llvm::SmallVector< OpenACCReductionRecipe::CombinerRecipe, 1 > CombinerRecipes
static OpenACCReductionRecipeWithStorage Empty()
llvm::ArrayRef< CombinerRecipe > CombinerRecipes
Describes how types, statements, expressions, and declarations should be printed.