clang 22.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 auto Children = const_cast<OpenACCClause *>(this)->children();
55 return const_child_range(Children.begin(), Children.end());
56 }
57
58 virtual ~OpenACCClause() = default;
59};
60
61// Represents the 'auto' clause.
63protected:
66
67public:
68 static bool classof(const OpenACCClause *C) {
69 return C->getClauseKind() == OpenACCClauseKind::Auto;
70 }
71
72 static OpenACCAutoClause *
73 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
74
81};
82
83// Represents the 'finalize' clause.
85protected:
88
89public:
90 static bool classof(const OpenACCClause *C) {
91 return C->getClauseKind() == OpenACCClauseKind::Finalize;
92 }
93
95 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
96
103};
104
105// Represents the 'if_present' clause.
107protected:
110
111public:
112 static bool classof(const OpenACCClause *C) {
113 return C->getClauseKind() == OpenACCClauseKind::IfPresent;
114 }
115
117 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
118
125};
126
127// Represents the 'independent' clause.
129protected:
132
133public:
134 static bool classof(const OpenACCClause *C) {
135 return C->getClauseKind() == OpenACCClauseKind::Independent;
136 }
137
139 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
140
147};
148// Represents the 'seq' clause.
150protected:
152 : OpenACCClause(OpenACCClauseKind::Seq, BeginLoc, EndLoc) {}
153
154public:
155 static bool classof(const OpenACCClause *C) {
156 return C->getClauseKind() == OpenACCClauseKind::Seq;
157 }
158
159 static OpenACCSeqClause *
160 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
161
168};
169// Represents the 'nohost' clause.
171protected:
174
175public:
176 static bool classof(const OpenACCClause *C) {
177 return C->getClauseKind() == OpenACCClauseKind::NoHost;
178 }
179 static OpenACCNoHostClause *
180 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
181
188};
189
190/// Represents a clause that has a list of parameters.
192 /// Location of the '('.
193 SourceLocation LParenLoc;
194
195protected:
197 SourceLocation LParenLoc, SourceLocation EndLoc)
198 : OpenACCClause(K, BeginLoc, EndLoc), LParenLoc(LParenLoc) {}
199
200public:
201 static bool classof(const OpenACCClause *C);
202
203 SourceLocation getLParenLoc() const { return LParenLoc; }
204
211};
212
213class OpenACCBindClause final : public OpenACCClauseWithParams {
214 std::variant<const StringLiteral *, const IdentifierInfo *> Argument;
215
216 OpenACCBindClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
217 const clang::StringLiteral *SL, SourceLocation EndLoc)
219 EndLoc),
220 Argument(SL) {}
221 OpenACCBindClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
222 const IdentifierInfo *ID, SourceLocation EndLoc)
224 EndLoc),
225 Argument(ID) {}
226
227public:
228 static bool classof(const OpenACCClause *C) {
229 return C->getClauseKind() == OpenACCClauseKind::Bind;
230 }
231 static OpenACCBindClause *Create(const ASTContext &C, SourceLocation BeginLoc,
232 SourceLocation LParenLoc,
233 const IdentifierInfo *ID,
234 SourceLocation EndLoc);
235 static OpenACCBindClause *Create(const ASTContext &C, SourceLocation BeginLoc,
236 SourceLocation LParenLoc,
237 const StringLiteral *SL,
238 SourceLocation EndLoc);
239
240 bool isStringArgument() const {
241 return std::holds_alternative<const StringLiteral *>(Argument);
242 }
243
245 return std::get<const StringLiteral *>(Argument);
246 }
247
248 bool isIdentifierArgument() const {
249 return std::holds_alternative<const IdentifierInfo *>(Argument);
250 }
251
253 return std::get<const IdentifierInfo *>(Argument);
254 }
255};
256
257bool operator==(const OpenACCBindClause &LHS, const OpenACCBindClause &RHS);
258inline bool operator!=(const OpenACCBindClause &LHS,
259 const OpenACCBindClause &RHS) {
260 return !(LHS == RHS);
261}
262
264/// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or
265/// an identifier. The 'asterisk' means 'the rest'.
266class OpenACCDeviceTypeClause final
268 private llvm::TrailingObjects<OpenACCDeviceTypeClause,
269 DeviceTypeArgument> {
270 friend TrailingObjects;
271 // Data stored in trailing objects as IdentifierInfo* /SourceLocation pairs. A
272 // nullptr IdentifierInfo* represents an asterisk.
273 unsigned NumArchs;
274 OpenACCDeviceTypeClause(OpenACCClauseKind K, SourceLocation BeginLoc,
275 SourceLocation LParenLoc,
277 SourceLocation EndLoc)
278 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
279 NumArchs(Archs.size()) {
280 assert(
282 "Invalid clause kind for device-type");
283
284 assert(!llvm::any_of(Archs, [](const DeviceTypeArgument &Arg) {
285 return Arg.getLoc().isInvalid();
286 }) && "Invalid SourceLocation for an argument");
287
288 assert((Archs.size() == 1 ||
289 !llvm::any_of(Archs,
290 [](const DeviceTypeArgument &Arg) {
291 return Arg.getIdentifierInfo() == nullptr;
292 })) &&
293 "Only a single asterisk version is permitted, and must be the "
294 "only one");
295
296 llvm::uninitialized_copy(Archs, getTrailingObjects());
297 }
298
299public:
300 static bool classof(const OpenACCClause *C) {
301 return C->getClauseKind() == OpenACCClauseKind::DType ||
302 C->getClauseKind() == OpenACCClauseKind::DeviceType;
303 }
304 bool hasAsterisk() const {
305 return getArchitectures().size() > 0 &&
306 getArchitectures()[0].getIdentifierInfo() == nullptr;
307 }
308
310 return getTrailingObjects(NumArchs);
311 }
312
316 SourceLocation EndLoc);
317};
318
319/// A 'default' clause, has the optional 'none' or 'present' argument.
321 friend class ASTReaderStmt;
322 friend class ASTWriterStmt;
323
324 OpenACCDefaultClauseKind DefaultClauseKind;
325
326protected:
328 SourceLocation LParenLoc, SourceLocation EndLoc)
329 : OpenACCClauseWithParams(OpenACCClauseKind::Default, BeginLoc, LParenLoc,
330 EndLoc),
331 DefaultClauseKind(K) {
332 assert((DefaultClauseKind == OpenACCDefaultClauseKind::None ||
333 DefaultClauseKind == OpenACCDefaultClauseKind::Present) &&
334 "Invalid Clause Kind");
335 }
336
337public:
338 static bool classof(const OpenACCClause *C) {
339 return C->getClauseKind() == OpenACCClauseKind::Default;
340 }
342 return DefaultClauseKind;
343 }
344
347 SourceLocation BeginLoc,
348 SourceLocation LParenLoc,
349 SourceLocation EndLoc);
350};
351
352/// Represents one of the handful of classes that has an optional/required
353/// 'condition' expression as an argument.
355 Expr *ConditionExpr = nullptr;
356
357protected:
359 SourceLocation LParenLoc, Expr *ConditionExpr,
360 SourceLocation EndLoc)
361 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
362 ConditionExpr(ConditionExpr) {}
363
364public:
365 static bool classof(const OpenACCClause *C);
366
367 bool hasConditionExpr() const { return ConditionExpr; }
368 const Expr *getConditionExpr() const { return ConditionExpr; }
369 Expr *getConditionExpr() { return ConditionExpr; }
370
372 if (ConditionExpr)
373 return child_range(reinterpret_cast<Stmt **>(&ConditionExpr),
374 reinterpret_cast<Stmt **>(&ConditionExpr + 1));
376 }
377
379 if (ConditionExpr)
380 return const_child_range(
381 reinterpret_cast<Stmt *const *>(&ConditionExpr),
382 reinterpret_cast<Stmt *const *>(&ConditionExpr + 1));
384 }
385};
386
387/// An 'if' clause, which has a required condition expression.
389protected:
391 Expr *ConditionExpr, SourceLocation EndLoc);
392
393public:
394 static bool classof(const OpenACCClause *C) {
395 return C->getClauseKind() == OpenACCClauseKind::If;
396 }
397 static OpenACCIfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
398 SourceLocation LParenLoc, Expr *ConditionExpr,
399 SourceLocation EndLoc);
400};
401
402/// A 'self' clause, which has an optional condition expression, or, in the
403/// event of an 'update' directive, contains a 'VarList'.
404class OpenACCSelfClause final
406 private llvm::TrailingObjects<OpenACCSelfClause, Expr *> {
407 friend TrailingObjects;
408 // Holds whether this HAS a condition expression. Lacks a value if this is NOT
409 // a condition-expr self clause.
410 std::optional<bool> HasConditionExpr;
411 // Holds the number of stored expressions. In the case of a condition-expr
412 // self clause, this is expected to be ONE (and there to be 1 trailing
413 // object), whether or not that is null.
414 unsigned NumExprs;
415
416 OpenACCSelfClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
417 Expr *ConditionExpr, SourceLocation EndLoc);
418 OpenACCSelfClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
419 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
420
421 // Intentionally internal, meant to be an implementation detail of everything
422 // else. All non-internal uses should go through getConditionExpr/getVarList.
423 ArrayRef<Expr *> getExprs() const { return getTrailingObjects(NumExprs); }
424
425public:
426 static bool classof(const OpenACCClause *C) {
427 return C->getClauseKind() == OpenACCClauseKind::Self;
428 }
429
430 bool isConditionExprClause() const { return HasConditionExpr.has_value(); }
431 bool isVarListClause() const { return !isConditionExprClause(); }
432 bool isEmptySelfClause() const {
433 return (isConditionExprClause() && !hasConditionExpr()) ||
434 (!isConditionExprClause() && getVarList().empty());
435 }
436
437 bool hasConditionExpr() const {
438 assert(HasConditionExpr.has_value() &&
439 "VarList Self Clause asked about condition expression");
440 return *HasConditionExpr;
441 }
442
443 const Expr *getConditionExpr() const {
444 assert(HasConditionExpr.has_value() &&
445 "VarList Self Clause asked about condition expression");
446 assert(getExprs().size() == 1 &&
447 "ConditionExpr Self Clause with too many Exprs");
448 return getExprs()[0];
449 }
450
452 assert(HasConditionExpr.has_value() &&
453 "VarList Self Clause asked about condition expression");
454 assert(getExprs().size() == 1 &&
455 "ConditionExpr Self Clause with too many Exprs");
456 return getExprs()[0];
457 }
458
460 assert(!HasConditionExpr.has_value() &&
461 "Condition Expr self clause asked about var list");
462 return getExprs();
463 }
465 assert(!HasConditionExpr.has_value() &&
466 "Condition Expr self clause asked about var list");
467 return getExprs();
468 }
469
471 return child_range(
472 reinterpret_cast<Stmt **>(getTrailingObjects()),
473 reinterpret_cast<Stmt **>(getTrailingObjects() + NumExprs));
474 }
475
477 child_range Children = const_cast<OpenACCSelfClause *>(this)->children();
478 return const_child_range(Children.begin(), Children.end());
479 }
480
481 static OpenACCSelfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
482 SourceLocation LParenLoc,
483 Expr *ConditionExpr, SourceLocation EndLoc);
484 static OpenACCSelfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
485 SourceLocation LParenLoc,
486 ArrayRef<Expr *> ConditionExpr,
487 SourceLocation EndLoc);
488};
489
490/// Represents a clause that has one or more expressions associated with it.
493
494protected:
496 SourceLocation LParenLoc, SourceLocation EndLoc)
497 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc) {}
498
499 /// Used only for initialization, the leaf class can initialize this to
500 /// trailing storage.
502 assert(Exprs.empty() && "Cannot change Exprs list");
503 Exprs = NewExprs;
504 }
505
506 /// Used only for initialization, the leaf class can initialize this to
507 /// trailing storage, and initialize the data in the trailing storage as well.
509 assert(NewStorage.size() == Exprs.size());
510 llvm::uninitialized_copy(Exprs, NewStorage.begin());
511 setExprs(NewStorage);
512 }
513
514 /// Gets the entire list of expressions, but leave it to the
515 /// individual clauses to expose this how they'd like.
516 ArrayRef<Expr *> getExprs() const { return Exprs; }
517
518public:
519 static bool classof(const OpenACCClause *C);
521 return child_range(reinterpret_cast<Stmt **>(Exprs.begin()),
522 reinterpret_cast<Stmt **>(Exprs.end()));
523 }
524
527 const_cast<OpenACCClauseWithExprs *>(this)->children();
528 return const_child_range(Children.begin(), Children.end());
529 }
530};
531
532// Represents the 'devnum' and expressions lists for the 'wait' clause.
533class OpenACCWaitClause final
534 : public OpenACCClauseWithExprs,
535 private llvm::TrailingObjects<OpenACCWaitClause, Expr *> {
536 friend TrailingObjects;
537 SourceLocation QueuesLoc;
538 OpenACCWaitClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
539 Expr *DevNumExpr, SourceLocation QueuesLoc,
540 ArrayRef<Expr *> QueueIdExprs, SourceLocation EndLoc)
541 : OpenACCClauseWithExprs(OpenACCClauseKind::Wait, BeginLoc, LParenLoc,
542 EndLoc),
543 QueuesLoc(QueuesLoc) {
544 // The first element of the trailing storage is always the devnum expr,
545 // whether it is used or not.
546 auto *Exprs = getTrailingObjects();
547 llvm::uninitialized_copy(ArrayRef(DevNumExpr), Exprs);
548 llvm::uninitialized_copy(QueueIdExprs, Exprs + 1);
549 setExprs(getTrailingObjects(QueueIdExprs.size() + 1));
550 }
551
552public:
553 static bool classof(const OpenACCClause *C) {
554 return C->getClauseKind() == OpenACCClauseKind::Wait;
555 }
556 static OpenACCWaitClause *Create(const ASTContext &C, SourceLocation BeginLoc,
557 SourceLocation LParenLoc, Expr *DevNumExpr,
558 SourceLocation QueuesLoc,
559 ArrayRef<Expr *> QueueIdExprs,
560 SourceLocation EndLoc);
561
562 bool hasQueuesTag() const { return !QueuesLoc.isInvalid(); }
563 SourceLocation getQueuesLoc() const { return QueuesLoc; }
564 bool hasDevNumExpr() const { return getExprs()[0]; }
565 Expr *getDevNumExpr() const { return getExprs()[0]; }
570 return OpenACCClauseWithExprs::getExprs().drop_front();
571 }
572 // If this is a plain `wait` (no parens) this returns 'false'. Else Sema/Parse
573 // ensures we have at least one QueueId expression.
574 bool hasExprs() const { return getLParenLoc().isValid(); }
575};
576
577class OpenACCNumGangsClause final
578 : public OpenACCClauseWithExprs,
579 private llvm::TrailingObjects<OpenACCNumGangsClause, Expr *> {
580 friend TrailingObjects;
581
582 OpenACCNumGangsClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
583 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
585 EndLoc) {
586 setExprs(getTrailingObjects(IntExprs.size()), IntExprs);
587 }
588
589public:
590 static bool classof(const OpenACCClause *C) {
591 return C->getClauseKind() == OpenACCClauseKind::NumGangs;
592 }
593 static OpenACCNumGangsClause *
594 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
595 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
596
598
602};
603
604class OpenACCTileClause final
605 : public OpenACCClauseWithExprs,
606 private llvm::TrailingObjects<OpenACCTileClause, Expr *> {
607 friend TrailingObjects;
608 OpenACCTileClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
609 ArrayRef<Expr *> SizeExprs, SourceLocation EndLoc)
610 : OpenACCClauseWithExprs(OpenACCClauseKind::Tile, BeginLoc, LParenLoc,
611 EndLoc) {
612 setExprs(getTrailingObjects(SizeExprs.size()), SizeExprs);
613 }
614
615public:
616 static bool classof(const OpenACCClause *C) {
617 return C->getClauseKind() == OpenACCClauseKind::Tile;
618 }
619 static OpenACCTileClause *Create(const ASTContext &C, SourceLocation BeginLoc,
620 SourceLocation LParenLoc,
621 ArrayRef<Expr *> SizeExprs,
622 SourceLocation EndLoc);
624
628};
629
630/// Represents one of a handful of clauses that have a single integer
631/// expression.
633 Expr *IntExpr;
634
635protected:
637 SourceLocation LParenLoc, Expr *IntExpr,
638 SourceLocation EndLoc)
639 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc),
640 IntExpr(IntExpr) {
641 if (IntExpr)
642 setExprs(MutableArrayRef<Expr *>{&this->IntExpr, 1});
643 }
644
645public:
646 static bool classof(const OpenACCClause *C);
647 bool hasIntExpr() const { return !getExprs().empty(); }
648 const Expr *getIntExpr() const {
649 return hasIntExpr() ? getExprs()[0] : nullptr;
650 }
651
652 Expr *getIntExpr() { return hasIntExpr() ? getExprs()[0] : nullptr; };
653};
654
656 : public OpenACCClauseWithExprs,
657 private llvm::TrailingObjects<OpenACCGangClause, Expr *, OpenACCGangKind> {
658 friend TrailingObjects;
659protected:
662 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
663
664 OpenACCGangKind getGangKind(unsigned I) const {
665 return getTrailingObjects<OpenACCGangKind>()[I];
666 }
667
668public:
669 static bool classof(const OpenACCClause *C) {
670 return C->getClauseKind() == OpenACCClauseKind::Gang;
671 }
672
673 size_t numTrailingObjects(OverloadToken<Expr *>) const {
674 return getNumExprs();
675 }
676
677 unsigned getNumExprs() const { return getExprs().size(); }
678 std::pair<OpenACCGangKind, const Expr *> getExpr(unsigned I) const {
679 return {getGangKind(I), getExprs()[I]};
680 }
681
683 for (unsigned I = 0; I < getNumExprs(); ++I) {
684 if (getGangKind(I) == GK)
685 return true;
686 }
687 return false;
688 }
689
690 static OpenACCGangClause *
691 Create(const ASTContext &Ctx, SourceLocation BeginLoc,
692 SourceLocation LParenLoc, ArrayRef<OpenACCGangKind> GangKinds,
693 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
694};
695
697protected:
699 Expr *IntExpr, SourceLocation EndLoc);
700
701public:
702 static bool classof(const OpenACCClause *C) {
703 return C->getClauseKind() == OpenACCClauseKind::Worker;
704 }
705
706 static OpenACCWorkerClause *Create(const ASTContext &Ctx,
707 SourceLocation BeginLoc,
708 SourceLocation LParenLoc, Expr *IntExpr,
709 SourceLocation EndLoc);
710};
711
713protected:
715 Expr *IntExpr, SourceLocation EndLoc);
716
717public:
718 static bool classof(const OpenACCClause *C) {
719 return C->getClauseKind() == OpenACCClauseKind::Vector;
720 }
721
722 static OpenACCVectorClause *Create(const ASTContext &Ctx,
723 SourceLocation BeginLoc,
724 SourceLocation LParenLoc, Expr *IntExpr,
725 SourceLocation EndLoc);
726};
727
728class OpenACCNumWorkersClause : public OpenACCClauseWithSingleIntExpr {
729 OpenACCNumWorkersClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
730 Expr *IntExpr, SourceLocation EndLoc);
731
732public:
733 static bool classof(const OpenACCClause *C) {
734 return C->getClauseKind() == OpenACCClauseKind::NumWorkers;
735 }
737 SourceLocation BeginLoc,
738 SourceLocation LParenLoc,
739 Expr *IntExpr, SourceLocation EndLoc);
740};
741
742class OpenACCVectorLengthClause : public OpenACCClauseWithSingleIntExpr {
743 OpenACCVectorLengthClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
744 Expr *IntExpr, SourceLocation EndLoc);
745
746public:
747 static bool classof(const OpenACCClause *C) {
748 return C->getClauseKind() == OpenACCClauseKind::VectorLength;
749 }
751 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
752 Expr *IntExpr, SourceLocation EndLoc);
753};
754
755class OpenACCAsyncClause : public OpenACCClauseWithSingleIntExpr {
756 OpenACCAsyncClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
757 Expr *IntExpr, SourceLocation EndLoc);
758
759public:
760 static bool classof(const OpenACCClause *C) {
761 return C->getClauseKind() == OpenACCClauseKind::Async;
762 }
763 static OpenACCAsyncClause *Create(const ASTContext &C,
764 SourceLocation BeginLoc,
765 SourceLocation LParenLoc, Expr *IntExpr,
766 SourceLocation EndLoc);
767};
768
769class OpenACCDeviceNumClause : public OpenACCClauseWithSingleIntExpr {
770 OpenACCDeviceNumClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
771 Expr *IntExpr, SourceLocation EndLoc);
772
773public:
774 static bool classof(const OpenACCClause *C) {
775 return C->getClauseKind() == OpenACCClauseKind::DeviceNum;
776 }
778 SourceLocation BeginLoc,
779 SourceLocation LParenLoc, Expr *IntExpr,
780 SourceLocation EndLoc);
781};
782
783class OpenACCDefaultAsyncClause : public OpenACCClauseWithSingleIntExpr {
784 OpenACCDefaultAsyncClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
785 Expr *IntExpr, SourceLocation EndLoc);
786
787public:
788 static bool classof(const OpenACCClause *C) {
789 return C->getClauseKind() == OpenACCClauseKind::DefaultAsync;
790 }
792 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
793 Expr *IntExpr, SourceLocation EndLoc);
794};
795
796/// Represents a 'collapse' clause on a 'loop' construct. This clause takes an
797/// integer constant expression 'N' that represents how deep to collapse the
798/// construct. It also takes an optional 'force' tag that permits intervening
799/// code in the loops.
800class OpenACCCollapseClause : public OpenACCClauseWithSingleIntExpr {
801 bool HasForce = false;
802
803 OpenACCCollapseClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
804 bool HasForce, Expr *LoopCount, SourceLocation EndLoc);
805
806public:
807 const Expr *getLoopCount() const { return getIntExpr(); }
808 Expr *getLoopCount() { return getIntExpr(); }
809
810 bool hasForce() const { return HasForce; }
811
812 static bool classof(const OpenACCClause *C) {
813 return C->getClauseKind() == OpenACCClauseKind::Collapse;
814 }
815
817 SourceLocation BeginLoc,
818 SourceLocation LParenLoc, bool HasForce,
819 Expr *LoopCount, SourceLocation EndLoc);
820};
821
822/// Represents a clause with one or more 'var' objects, represented as an expr,
823/// as its arguments. Var-list is expected to be stored in trailing storage.
824/// For now, we're just storing the original expression in its entirety, unlike
825/// OMP which has to do a bunch of work to create a private.
827protected:
829 SourceLocation LParenLoc, SourceLocation EndLoc)
830 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc) {}
831
832public:
833 static bool classof(const OpenACCClause *C);
836};
837
838// Represents all the data needed for recipe generation. The declaration and
839// init are stored separately, because in the case of subscripts, we do the
840// alloca at the level of the base, and the init at the element level.
843
845
846 bool isSet() const { return AllocaDecl; }
847
849 return OpenACCPrivateRecipe(/*AllocaDecl=*/nullptr);
850 }
851};
852
853class OpenACCPrivateClause final
855 private llvm::TrailingObjects<OpenACCPrivateClause, Expr *,
856 OpenACCPrivateRecipe> {
857 friend TrailingObjects;
858
859 OpenACCPrivateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
860 ArrayRef<Expr *> VarList,
862 SourceLocation EndLoc)
864 LParenLoc, EndLoc) {
865 assert(VarList.size() == InitRecipes.size());
866 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
867 llvm::uninitialized_copy(InitRecipes,
868 getTrailingObjects<OpenACCPrivateRecipe>());
869 }
870
871public:
872 static bool classof(const OpenACCClause *C) {
873 return C->getClauseKind() == OpenACCClauseKind::Private;
874 }
875 // Gets a list of 'made up' `VarDecl` objects that can be used by codegen to
876 // ensure that we properly initialize each of these variables.
879 getTrailingObjects<OpenACCPrivateRecipe>(), getExprs().size()};
880 }
881
884 getTrailingObjects<OpenACCPrivateRecipe>(), getExprs().size()};
885 }
886
887 static OpenACCPrivateClause *
888 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
890 SourceLocation EndLoc);
891
892 size_t numTrailingObjects(OverloadToken<Expr *>) const {
893 return getExprs().size();
894 }
895};
896
897// A 'pair' to stand in for the recipe. RecipeDecl is the main declaration, and
898// InitFromTemporary is the 'temp' declaration we put in to be 'copied from'.
904 assert(!InitFromTemporary || InitFromTemporary->getInit() == nullptr);
905 }
906
907 bool isSet() const { return AllocaDecl; }
908
910 return OpenACCFirstPrivateRecipe(/*AllocaDecl=*/nullptr,
911 /*InitFromTemporary=*/nullptr);
912 }
913};
914
915class OpenACCFirstPrivateClause final
917 private llvm::TrailingObjects<OpenACCFirstPrivateClause, Expr *,
918 OpenACCFirstPrivateRecipe> {
919 friend TrailingObjects;
920
921 OpenACCFirstPrivateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
922 ArrayRef<Expr *> VarList,
924 SourceLocation EndLoc)
926 LParenLoc, EndLoc) {
927 assert(VarList.size() == InitRecipes.size());
928 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
929 llvm::uninitialized_copy(InitRecipes,
930 getTrailingObjects<OpenACCFirstPrivateRecipe>());
931 }
932
933public:
934 static bool classof(const OpenACCClause *C) {
935 return C->getClauseKind() == OpenACCClauseKind::FirstPrivate;
936 }
937
938 // Gets a list of 'made up' `VarDecl` objects that can be used by codegen to
939 // ensure that we properly initialize each of these variables.
942 getTrailingObjects<OpenACCFirstPrivateRecipe>(), getExprs().size()};
943 }
944
947 getTrailingObjects<OpenACCFirstPrivateRecipe>(), getExprs().size()};
948 }
949
951 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
952 ArrayRef<Expr *> VarList,
954 SourceLocation EndLoc);
955
956 size_t numTrailingObjects(OverloadToken<Expr *>) const {
957 return getExprs().size();
958 }
959};
960
961class OpenACCDevicePtrClause final
963 private llvm::TrailingObjects<OpenACCDevicePtrClause, Expr *> {
964 friend TrailingObjects;
965
966 OpenACCDevicePtrClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
967 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
969 LParenLoc, EndLoc) {
970 setExprs(getTrailingObjects(VarList.size()), VarList);
971 }
972
973public:
974 static bool classof(const OpenACCClause *C) {
975 return C->getClauseKind() == OpenACCClauseKind::DevicePtr;
976 }
978 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
979 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
980};
981
982class OpenACCAttachClause final
984 private llvm::TrailingObjects<OpenACCAttachClause, Expr *> {
985 friend TrailingObjects;
986
987 OpenACCAttachClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
988 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
990 EndLoc) {
991 setExprs(getTrailingObjects(VarList.size()), VarList);
992 }
993
994public:
995 static bool classof(const OpenACCClause *C) {
996 return C->getClauseKind() == OpenACCClauseKind::Attach;
997 }
998 static OpenACCAttachClause *
999 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1000 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1001};
1002
1003class OpenACCDetachClause final
1004 : public OpenACCClauseWithVarList,
1005 private llvm::TrailingObjects<OpenACCDetachClause, Expr *> {
1006 friend TrailingObjects;
1007
1008 OpenACCDetachClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1009 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1011 EndLoc) {
1012 setExprs(getTrailingObjects(VarList.size()), VarList);
1013 }
1014
1015public:
1016 static bool classof(const OpenACCClause *C) {
1017 return C->getClauseKind() == OpenACCClauseKind::Detach;
1018 }
1019 static OpenACCDetachClause *
1020 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1021 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1022};
1023
1024class OpenACCDeleteClause final
1025 : public OpenACCClauseWithVarList,
1026 private llvm::TrailingObjects<OpenACCDeleteClause, Expr *> {
1027 friend TrailingObjects;
1028
1029 OpenACCDeleteClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1030 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1032 EndLoc) {
1033 setExprs(getTrailingObjects(VarList.size()), VarList);
1034 }
1035
1036public:
1037 static bool classof(const OpenACCClause *C) {
1038 return C->getClauseKind() == OpenACCClauseKind::Delete;
1039 }
1040 static OpenACCDeleteClause *
1041 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1042 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1043};
1044
1045class OpenACCUseDeviceClause final
1046 : public OpenACCClauseWithVarList,
1047 private llvm::TrailingObjects<OpenACCUseDeviceClause, Expr *> {
1048 friend TrailingObjects;
1049
1050 OpenACCUseDeviceClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1051 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1053 LParenLoc, EndLoc) {
1054 setExprs(getTrailingObjects(VarList.size()), VarList);
1055 }
1056
1057public:
1058 static bool classof(const OpenACCClause *C) {
1059 return C->getClauseKind() == OpenACCClauseKind::UseDevice;
1060 }
1061 static OpenACCUseDeviceClause *
1062 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1063 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1064};
1065
1066class OpenACCNoCreateClause final
1067 : public OpenACCClauseWithVarList,
1068 private llvm::TrailingObjects<OpenACCNoCreateClause, Expr *> {
1069 friend TrailingObjects;
1070
1071 OpenACCNoCreateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1072 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1074 LParenLoc, EndLoc) {
1075 setExprs(getTrailingObjects(VarList.size()), VarList);
1076 }
1077
1078public:
1079 static bool classof(const OpenACCClause *C) {
1080 return C->getClauseKind() == OpenACCClauseKind::NoCreate;
1081 }
1082 static OpenACCNoCreateClause *
1083 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1084 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1085};
1086
1087class OpenACCPresentClause final
1088 : public OpenACCClauseWithVarList,
1089 private llvm::TrailingObjects<OpenACCPresentClause, Expr *> {
1090 friend TrailingObjects;
1091
1092 OpenACCPresentClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1093 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1095 LParenLoc, EndLoc) {
1096 setExprs(getTrailingObjects(VarList.size()), VarList);
1097 }
1098
1099public:
1100 static bool classof(const OpenACCClause *C) {
1101 return C->getClauseKind() == OpenACCClauseKind::Present;
1102 }
1103 static OpenACCPresentClause *
1104 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1105 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1106};
1107class OpenACCHostClause final
1108 : public OpenACCClauseWithVarList,
1109 private llvm::TrailingObjects<OpenACCHostClause, Expr *> {
1110 friend TrailingObjects;
1111
1112 OpenACCHostClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1113 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1115 EndLoc) {
1116 setExprs(getTrailingObjects(VarList.size()), VarList);
1117 }
1118
1119public:
1120 static bool classof(const OpenACCClause *C) {
1121 return C->getClauseKind() == OpenACCClauseKind::Host;
1122 }
1123 static OpenACCHostClause *Create(const ASTContext &C, SourceLocation BeginLoc,
1124 SourceLocation LParenLoc,
1125 ArrayRef<Expr *> VarList,
1126 SourceLocation EndLoc);
1127};
1128
1129class OpenACCDeviceClause final
1130 : public OpenACCClauseWithVarList,
1131 private llvm::TrailingObjects<OpenACCDeviceClause, Expr *> {
1132 friend TrailingObjects;
1133
1134 OpenACCDeviceClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1135 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1137 EndLoc) {
1138 setExprs(getTrailingObjects(VarList.size()), VarList);
1139 }
1140
1141public:
1142 static bool classof(const OpenACCClause *C) {
1143 return C->getClauseKind() == OpenACCClauseKind::Device;
1144 }
1145 static OpenACCDeviceClause *
1146 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1147 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1148};
1149
1150class OpenACCCopyClause final
1151 : public OpenACCClauseWithVarList,
1152 private llvm::TrailingObjects<OpenACCCopyClause, Expr *> {
1153 friend TrailingObjects;
1154 OpenACCModifierKind Modifiers;
1155
1156 OpenACCCopyClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1157 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1158 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1159 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1160 Modifiers(Mods) {
1161 assert((Spelling == OpenACCClauseKind::Copy ||
1162 Spelling == OpenACCClauseKind::PCopy ||
1163 Spelling == OpenACCClauseKind::PresentOrCopy) &&
1164 "Invalid clause kind for copy-clause");
1165 setExprs(getTrailingObjects(VarList.size()), VarList);
1166 }
1167
1168public:
1169 static bool classof(const OpenACCClause *C) {
1170 return C->getClauseKind() == OpenACCClauseKind::Copy ||
1171 C->getClauseKind() == OpenACCClauseKind::PCopy ||
1172 C->getClauseKind() == OpenACCClauseKind::PresentOrCopy;
1173 }
1174 static OpenACCCopyClause *
1175 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1176 SourceLocation BeginLoc, SourceLocation LParenLoc,
1178 SourceLocation EndLoc);
1179
1180 OpenACCModifierKind getModifierList() const { return Modifiers; }
1181};
1182
1183class OpenACCCopyInClause final
1184 : public OpenACCClauseWithVarList,
1185 private llvm::TrailingObjects<OpenACCCopyInClause, Expr *> {
1186 friend TrailingObjects;
1187 OpenACCModifierKind Modifiers;
1188
1189 OpenACCCopyInClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1190 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1191 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1192 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1193 Modifiers(Mods) {
1194 assert((Spelling == OpenACCClauseKind::CopyIn ||
1195 Spelling == OpenACCClauseKind::PCopyIn ||
1197 "Invalid clause kind for copyin-clause");
1198 setExprs(getTrailingObjects(VarList.size()), VarList);
1199 }
1200
1201public:
1202 static bool classof(const OpenACCClause *C) {
1203 return C->getClauseKind() == OpenACCClauseKind::CopyIn ||
1204 C->getClauseKind() == OpenACCClauseKind::PCopyIn ||
1205 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyIn;
1206 }
1207 OpenACCModifierKind getModifierList() const { return Modifiers; }
1208 static OpenACCCopyInClause *
1209 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1210 SourceLocation BeginLoc, SourceLocation LParenLoc,
1212 SourceLocation EndLoc);
1213};
1214
1215class OpenACCCopyOutClause final
1216 : public OpenACCClauseWithVarList,
1217 private llvm::TrailingObjects<OpenACCCopyOutClause, Expr *> {
1218 friend TrailingObjects;
1219 OpenACCModifierKind Modifiers;
1220
1221 OpenACCCopyOutClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1222 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1223 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1224 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1225 Modifiers(Mods) {
1226 assert((Spelling == OpenACCClauseKind::CopyOut ||
1227 Spelling == OpenACCClauseKind::PCopyOut ||
1229 "Invalid clause kind for copyout-clause");
1230 setExprs(getTrailingObjects(VarList.size()), VarList);
1231 }
1232
1233public:
1234 static bool classof(const OpenACCClause *C) {
1235 return C->getClauseKind() == OpenACCClauseKind::CopyOut ||
1236 C->getClauseKind() == OpenACCClauseKind::PCopyOut ||
1237 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyOut;
1238 }
1239 OpenACCModifierKind getModifierList() const { return Modifiers; }
1240 static OpenACCCopyOutClause *
1241 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1242 SourceLocation BeginLoc, SourceLocation LParenLoc,
1244 SourceLocation EndLoc);
1245};
1246
1247class OpenACCCreateClause final
1248 : public OpenACCClauseWithVarList,
1249 private llvm::TrailingObjects<OpenACCCreateClause, Expr *> {
1250 friend TrailingObjects;
1251 OpenACCModifierKind Modifiers;
1252
1253 OpenACCCreateClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1254 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1255 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1256 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1257 Modifiers(Mods) {
1258 assert((Spelling == OpenACCClauseKind::Create ||
1259 Spelling == OpenACCClauseKind::PCreate ||
1261 "Invalid clause kind for create-clause");
1262 setExprs(getTrailingObjects(VarList.size()), VarList);
1263 }
1264
1265public:
1266 static bool classof(const OpenACCClause *C) {
1267 return C->getClauseKind() == OpenACCClauseKind::Create ||
1268 C->getClauseKind() == OpenACCClauseKind::PCreate ||
1269 C->getClauseKind() == OpenACCClauseKind::PresentOrCreate;
1270 }
1271 OpenACCModifierKind getModifierList() const { return Modifiers; }
1272 static OpenACCCreateClause *
1273 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1274 SourceLocation BeginLoc, SourceLocation LParenLoc,
1276 SourceLocation EndLoc);
1277};
1278
1279// A structure to stand in for the recipe on a reduction. RecipeDecl is the
1280// 'main' declaration used for initializaiton, which is fixed.
1283 // TODO: OpenACC: this should eventually have the operations here too.
1284
1286
1287 bool isSet() const { return AllocaDecl; }
1289 return OpenACCReductionRecipe(/*AllocaDecl=*/nullptr);
1290 }
1291};
1292
1293class OpenACCReductionClause final
1294 : public OpenACCClauseWithVarList,
1295 private llvm::TrailingObjects<OpenACCReductionClause, Expr *,
1296 OpenACCReductionRecipe> {
1297 friend TrailingObjects;
1299
1300 OpenACCReductionClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1301 OpenACCReductionOperator Operator,
1302 ArrayRef<Expr *> VarList,
1304 SourceLocation EndLoc)
1306 LParenLoc, EndLoc),
1307 Op(Operator) {
1308 assert(VarList.size() == Recipes.size());
1309 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1310 llvm::uninitialized_copy(Recipes, getTrailingObjects<
1312 }
1313
1314public:
1315 static bool classof(const OpenACCClause *C) {
1316 return C->getClauseKind() == OpenACCClauseKind::Reduction;
1317 }
1318
1321 getTrailingObjects<OpenACCReductionRecipe>(), getExprs().size()};
1322 }
1323
1326 getTrailingObjects<OpenACCReductionRecipe>(), getExprs().size()};
1327 }
1328
1329 static OpenACCReductionClause *
1330 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1333
1335
1336 size_t numTrailingObjects(OverloadToken<Expr *>) const {
1337 return getExprs().size();
1338 }
1339};
1340
1341class OpenACCLinkClause final
1342 : public OpenACCClauseWithVarList,
1343 private llvm::TrailingObjects<OpenACCLinkClause, Expr *> {
1344 friend TrailingObjects;
1345
1346 OpenACCLinkClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1347 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1349 EndLoc) {
1350 setExprs(getTrailingObjects(VarList.size()), VarList);
1351 }
1352
1353public:
1354 static bool classof(const OpenACCClause *C) {
1355 return C->getClauseKind() == OpenACCClauseKind::Link;
1356 }
1357
1358 static OpenACCLinkClause *Create(const ASTContext &C, SourceLocation BeginLoc,
1359 SourceLocation LParenLoc,
1360 ArrayRef<Expr *> VarList,
1361 SourceLocation EndLoc);
1362};
1363
1364class OpenACCDeviceResidentClause final
1365 : public OpenACCClauseWithVarList,
1366 private llvm::TrailingObjects<OpenACCDeviceResidentClause, Expr *> {
1367 friend TrailingObjects;
1368
1369 OpenACCDeviceResidentClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1370 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1372 LParenLoc, EndLoc) {
1373 setExprs(getTrailingObjects(VarList.size()), VarList);
1374 }
1375
1376public:
1377 static bool classof(const OpenACCClause *C) {
1378 return C->getClauseKind() == OpenACCClauseKind::DeviceResident;
1379 }
1380
1382 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1383 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1384};
1385
1386template <class Impl> class OpenACCClauseVisitor {
1387 Impl &getDerived() { return static_cast<Impl &>(*this); }
1388
1389public:
1391 for (const OpenACCClause *Clause : List)
1392 Visit(Clause);
1393 }
1394
1395 void Visit(const OpenACCClause *C) {
1396 if (!C)
1397 return;
1398
1399 switch (C->getClauseKind()) {
1400#define VISIT_CLAUSE(CLAUSE_NAME) \
1401 case OpenACCClauseKind::CLAUSE_NAME: \
1402 getDerived().Visit##CLAUSE_NAME##Clause( \
1403 *cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1404 return;
1405#define CLAUSE_ALIAS(ALIAS_NAME, CLAUSE_NAME, DEPRECATED) \
1406 case OpenACCClauseKind::ALIAS_NAME: \
1407 getDerived().Visit##CLAUSE_NAME##Clause( \
1408 *cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1409 return;
1410#include "clang/Basic/OpenACCClauses.def"
1411
1412 default:
1413 llvm_unreachable("Clause visitor not yet implemented");
1414 }
1415 llvm_unreachable("Invalid Clause kind");
1416 }
1417
1418#define VISIT_CLAUSE(CLAUSE_NAME) \
1419 void Visit##CLAUSE_NAME##Clause( \
1420 const OpenACC##CLAUSE_NAME##Clause &Clause) { \
1421 return getDerived().VisitClause(Clause); \
1422 }
1423
1424#include "clang/Basic/OpenACCClauses.def"
1425};
1426
1428 : public OpenACCClauseVisitor<OpenACCClausePrinter> {
1429 raw_ostream &OS;
1430 const PrintingPolicy &Policy;
1431
1432 void printExpr(const Expr *E);
1433
1434public:
1436 for (const OpenACCClause *Clause : List) {
1437 Visit(Clause);
1438
1439 if (Clause != List.back())
1440 OS << ' ';
1441 }
1442 }
1443 OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
1444 : OS(OS), Policy(Policy) {}
1445
1446#define VISIT_CLAUSE(CLAUSE_NAME) \
1447 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
1448#include "clang/Basic/OpenACCClauses.def"
1449};
1450
1451} // namespace clang
1452
1453#endif // LLVM_CLANG_AST_OPENACCCLAUSE_H
Defines the clang::ASTContext interface.
SmallVector< AnnotatedLine *, 1 > Children
If this token starts a block, this contains all the unwrapped lines in it.
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:220
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()
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
ArrayRef< OpenACCFirstPrivateRecipe > getInitRecipes()
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)
ArrayRef< Expr * > getIntExprs()
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< OpenACCPrivateRecipe > getInitRecipes()
ArrayRef< OpenACCReductionRecipe > getRecipes() const
size_t numTrailingObjects(OverloadToken< Expr * >) const
ArrayRef< OpenACCReductionRecipe > getRecipes()
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()
ArrayRef< Expr * > getVarList() const
static bool classof(const OpenACCClause *C)
const_child_range children() const
OpenACCSeqClause(SourceLocation BeginLoc, SourceLocation EndLoc)
ArrayRef< Expr * > getSizeExprs()
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)
ArrayRef< Expr * > getQueueIdExprs()
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:85
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1799
Represents a variable declaration or definition.
Definition Decl.h:926
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:204
OpenACCDefaultClauseKind
IdentifierLoc DeviceTypeArgument
const FunctionProtoType * T
bool operator!=(CanQual< T > x, CanQual< U > y)
static OpenACCFirstPrivateRecipe Empty()
OpenACCFirstPrivateRecipe(VarDecl *A, VarDecl *T)
static OpenACCPrivateRecipe Empty()
static OpenACCReductionRecipe Empty()
Describes how types, statements, expressions, and declarations should be printed.