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.
844
846 assert(!AllocaDecl || AllocaDecl->getInit() == nullptr);
847 }
848
849 bool isSet() const { return AllocaDecl; }
850
852 return OpenACCPrivateRecipe(nullptr, nullptr);
853 }
854};
855
856class OpenACCPrivateClause final
858 private llvm::TrailingObjects<OpenACCPrivateClause, Expr *,
859 OpenACCPrivateRecipe> {
860 friend TrailingObjects;
861
862 OpenACCPrivateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
863 ArrayRef<Expr *> VarList,
865 SourceLocation EndLoc)
867 LParenLoc, EndLoc) {
868 assert(VarList.size() == InitRecipes.size());
869 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
870 llvm::uninitialized_copy(InitRecipes,
871 getTrailingObjects<OpenACCPrivateRecipe>());
872 }
873
874public:
875 static bool classof(const OpenACCClause *C) {
876 return C->getClauseKind() == OpenACCClauseKind::Private;
877 }
878 // Gets a list of 'made up' `VarDecl` objects that can be used by codegen to
879 // ensure that we properly initialize each of these variables.
882 getTrailingObjects<OpenACCPrivateRecipe>(), getExprs().size()};
883 }
884
887 getTrailingObjects<OpenACCPrivateRecipe>(), getExprs().size()};
888 }
889
890 static OpenACCPrivateClause *
891 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
893 SourceLocation EndLoc);
894
895 size_t numTrailingObjects(OverloadToken<Expr *>) const {
896 return getExprs().size();
897 }
898};
899
900// A 'pair' to stand in for the recipe. RecipeDecl is the main declaration, and
901// InitFromTemporary is the 'temp' declaration we put in to be 'copied from'.
908 assert(!AllocaDecl || AllocaDecl->getInit() == nullptr);
909 assert(!InitFromTemporary || InitFromTemporary->getInit() == nullptr);
910 }
911
912 bool isSet() const { return AllocaDecl; }
913
915 return OpenACCFirstPrivateRecipe(nullptr, nullptr, nullptr);
916 }
917};
918
919class OpenACCFirstPrivateClause final
921 private llvm::TrailingObjects<OpenACCFirstPrivateClause, Expr *,
922 OpenACCFirstPrivateRecipe> {
923 friend TrailingObjects;
924
925 OpenACCFirstPrivateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
926 ArrayRef<Expr *> VarList,
928 SourceLocation EndLoc)
930 LParenLoc, EndLoc) {
931 assert(VarList.size() == InitRecipes.size());
932 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
933 llvm::uninitialized_copy(InitRecipes,
934 getTrailingObjects<OpenACCFirstPrivateRecipe>());
935 }
936
937public:
938 static bool classof(const OpenACCClause *C) {
939 return C->getClauseKind() == OpenACCClauseKind::FirstPrivate;
940 }
941
942 // Gets a list of 'made up' `VarDecl` objects that can be used by codegen to
943 // ensure that we properly initialize each of these variables.
946 getTrailingObjects<OpenACCFirstPrivateRecipe>(), getExprs().size()};
947 }
948
951 getTrailingObjects<OpenACCFirstPrivateRecipe>(), getExprs().size()};
952 }
953
955 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
956 ArrayRef<Expr *> VarList,
958 SourceLocation EndLoc);
959
960 size_t numTrailingObjects(OverloadToken<Expr *>) const {
961 return getExprs().size();
962 }
963};
964
965class OpenACCDevicePtrClause final
967 private llvm::TrailingObjects<OpenACCDevicePtrClause, Expr *> {
968 friend TrailingObjects;
969
970 OpenACCDevicePtrClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
971 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
973 LParenLoc, EndLoc) {
974 setExprs(getTrailingObjects(VarList.size()), VarList);
975 }
976
977public:
978 static bool classof(const OpenACCClause *C) {
979 return C->getClauseKind() == OpenACCClauseKind::DevicePtr;
980 }
982 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
983 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
984};
985
986class OpenACCAttachClause final
988 private llvm::TrailingObjects<OpenACCAttachClause, Expr *> {
989 friend TrailingObjects;
990
991 OpenACCAttachClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
992 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
994 EndLoc) {
995 setExprs(getTrailingObjects(VarList.size()), VarList);
996 }
997
998public:
999 static bool classof(const OpenACCClause *C) {
1000 return C->getClauseKind() == OpenACCClauseKind::Attach;
1001 }
1002 static OpenACCAttachClause *
1003 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1004 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1005};
1006
1007class OpenACCDetachClause final
1008 : public OpenACCClauseWithVarList,
1009 private llvm::TrailingObjects<OpenACCDetachClause, Expr *> {
1010 friend TrailingObjects;
1011
1012 OpenACCDetachClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1013 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1015 EndLoc) {
1016 setExprs(getTrailingObjects(VarList.size()), VarList);
1017 }
1018
1019public:
1020 static bool classof(const OpenACCClause *C) {
1021 return C->getClauseKind() == OpenACCClauseKind::Detach;
1022 }
1023 static OpenACCDetachClause *
1024 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1025 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1026};
1027
1028class OpenACCDeleteClause final
1029 : public OpenACCClauseWithVarList,
1030 private llvm::TrailingObjects<OpenACCDeleteClause, Expr *> {
1031 friend TrailingObjects;
1032
1033 OpenACCDeleteClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1034 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1036 EndLoc) {
1037 setExprs(getTrailingObjects(VarList.size()), VarList);
1038 }
1039
1040public:
1041 static bool classof(const OpenACCClause *C) {
1042 return C->getClauseKind() == OpenACCClauseKind::Delete;
1043 }
1044 static OpenACCDeleteClause *
1045 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1046 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1047};
1048
1049class OpenACCUseDeviceClause final
1050 : public OpenACCClauseWithVarList,
1051 private llvm::TrailingObjects<OpenACCUseDeviceClause, Expr *> {
1052 friend TrailingObjects;
1053
1054 OpenACCUseDeviceClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1055 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1057 LParenLoc, EndLoc) {
1058 setExprs(getTrailingObjects(VarList.size()), VarList);
1059 }
1060
1061public:
1062 static bool classof(const OpenACCClause *C) {
1063 return C->getClauseKind() == OpenACCClauseKind::UseDevice;
1064 }
1065 static OpenACCUseDeviceClause *
1066 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1067 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1068};
1069
1070class OpenACCNoCreateClause final
1071 : public OpenACCClauseWithVarList,
1072 private llvm::TrailingObjects<OpenACCNoCreateClause, Expr *> {
1073 friend TrailingObjects;
1074
1075 OpenACCNoCreateClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1076 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1078 LParenLoc, EndLoc) {
1079 setExprs(getTrailingObjects(VarList.size()), VarList);
1080 }
1081
1082public:
1083 static bool classof(const OpenACCClause *C) {
1084 return C->getClauseKind() == OpenACCClauseKind::NoCreate;
1085 }
1086 static OpenACCNoCreateClause *
1087 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1088 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1089};
1090
1091class OpenACCPresentClause final
1092 : public OpenACCClauseWithVarList,
1093 private llvm::TrailingObjects<OpenACCPresentClause, Expr *> {
1094 friend TrailingObjects;
1095
1096 OpenACCPresentClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1097 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1099 LParenLoc, EndLoc) {
1100 setExprs(getTrailingObjects(VarList.size()), VarList);
1101 }
1102
1103public:
1104 static bool classof(const OpenACCClause *C) {
1105 return C->getClauseKind() == OpenACCClauseKind::Present;
1106 }
1107 static OpenACCPresentClause *
1108 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1109 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1110};
1111class OpenACCHostClause final
1112 : public OpenACCClauseWithVarList,
1113 private llvm::TrailingObjects<OpenACCHostClause, Expr *> {
1114 friend TrailingObjects;
1115
1116 OpenACCHostClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1117 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1119 EndLoc) {
1120 setExprs(getTrailingObjects(VarList.size()), VarList);
1121 }
1122
1123public:
1124 static bool classof(const OpenACCClause *C) {
1125 return C->getClauseKind() == OpenACCClauseKind::Host;
1126 }
1127 static OpenACCHostClause *Create(const ASTContext &C, SourceLocation BeginLoc,
1128 SourceLocation LParenLoc,
1129 ArrayRef<Expr *> VarList,
1130 SourceLocation EndLoc);
1131};
1132
1133class OpenACCDeviceClause final
1134 : public OpenACCClauseWithVarList,
1135 private llvm::TrailingObjects<OpenACCDeviceClause, Expr *> {
1136 friend TrailingObjects;
1137
1138 OpenACCDeviceClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1139 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1141 EndLoc) {
1142 setExprs(getTrailingObjects(VarList.size()), VarList);
1143 }
1144
1145public:
1146 static bool classof(const OpenACCClause *C) {
1147 return C->getClauseKind() == OpenACCClauseKind::Device;
1148 }
1149 static OpenACCDeviceClause *
1150 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1151 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1152};
1153
1154class OpenACCCopyClause final
1155 : public OpenACCClauseWithVarList,
1156 private llvm::TrailingObjects<OpenACCCopyClause, Expr *> {
1157 friend TrailingObjects;
1158 OpenACCModifierKind Modifiers;
1159
1160 OpenACCCopyClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1161 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1162 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1163 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1164 Modifiers(Mods) {
1165 assert((Spelling == OpenACCClauseKind::Copy ||
1166 Spelling == OpenACCClauseKind::PCopy ||
1167 Spelling == OpenACCClauseKind::PresentOrCopy) &&
1168 "Invalid clause kind for copy-clause");
1169 setExprs(getTrailingObjects(VarList.size()), VarList);
1170 }
1171
1172public:
1173 static bool classof(const OpenACCClause *C) {
1174 return C->getClauseKind() == OpenACCClauseKind::Copy ||
1175 C->getClauseKind() == OpenACCClauseKind::PCopy ||
1176 C->getClauseKind() == OpenACCClauseKind::PresentOrCopy;
1177 }
1178 static OpenACCCopyClause *
1179 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1180 SourceLocation BeginLoc, SourceLocation LParenLoc,
1182 SourceLocation EndLoc);
1183
1184 OpenACCModifierKind getModifierList() const { return Modifiers; }
1185};
1186
1187class OpenACCCopyInClause final
1188 : public OpenACCClauseWithVarList,
1189 private llvm::TrailingObjects<OpenACCCopyInClause, Expr *> {
1190 friend TrailingObjects;
1191 OpenACCModifierKind Modifiers;
1192
1193 OpenACCCopyInClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1194 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1195 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1196 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1197 Modifiers(Mods) {
1198 assert((Spelling == OpenACCClauseKind::CopyIn ||
1199 Spelling == OpenACCClauseKind::PCopyIn ||
1201 "Invalid clause kind for copyin-clause");
1202 setExprs(getTrailingObjects(VarList.size()), VarList);
1203 }
1204
1205public:
1206 static bool classof(const OpenACCClause *C) {
1207 return C->getClauseKind() == OpenACCClauseKind::CopyIn ||
1208 C->getClauseKind() == OpenACCClauseKind::PCopyIn ||
1209 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyIn;
1210 }
1211 OpenACCModifierKind getModifierList() const { return Modifiers; }
1212 static OpenACCCopyInClause *
1213 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1214 SourceLocation BeginLoc, SourceLocation LParenLoc,
1216 SourceLocation EndLoc);
1217};
1218
1219class OpenACCCopyOutClause final
1220 : public OpenACCClauseWithVarList,
1221 private llvm::TrailingObjects<OpenACCCopyOutClause, Expr *> {
1222 friend TrailingObjects;
1223 OpenACCModifierKind Modifiers;
1224
1225 OpenACCCopyOutClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1226 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1227 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1228 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1229 Modifiers(Mods) {
1230 assert((Spelling == OpenACCClauseKind::CopyOut ||
1231 Spelling == OpenACCClauseKind::PCopyOut ||
1233 "Invalid clause kind for copyout-clause");
1234 setExprs(getTrailingObjects(VarList.size()), VarList);
1235 }
1236
1237public:
1238 static bool classof(const OpenACCClause *C) {
1239 return C->getClauseKind() == OpenACCClauseKind::CopyOut ||
1240 C->getClauseKind() == OpenACCClauseKind::PCopyOut ||
1241 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyOut;
1242 }
1243 OpenACCModifierKind getModifierList() const { return Modifiers; }
1244 static OpenACCCopyOutClause *
1245 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1246 SourceLocation BeginLoc, SourceLocation LParenLoc,
1248 SourceLocation EndLoc);
1249};
1250
1251class OpenACCCreateClause final
1252 : public OpenACCClauseWithVarList,
1253 private llvm::TrailingObjects<OpenACCCreateClause, Expr *> {
1254 friend TrailingObjects;
1255 OpenACCModifierKind Modifiers;
1256
1257 OpenACCCreateClause(OpenACCClauseKind Spelling, SourceLocation BeginLoc,
1258 SourceLocation LParenLoc, OpenACCModifierKind Mods,
1259 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1260 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
1261 Modifiers(Mods) {
1262 assert((Spelling == OpenACCClauseKind::Create ||
1263 Spelling == OpenACCClauseKind::PCreate ||
1265 "Invalid clause kind for create-clause");
1266 setExprs(getTrailingObjects(VarList.size()), VarList);
1267 }
1268
1269public:
1270 static bool classof(const OpenACCClause *C) {
1271 return C->getClauseKind() == OpenACCClauseKind::Create ||
1272 C->getClauseKind() == OpenACCClauseKind::PCreate ||
1273 C->getClauseKind() == OpenACCClauseKind::PresentOrCreate;
1274 }
1275 OpenACCModifierKind getModifierList() const { return Modifiers; }
1276 static OpenACCCreateClause *
1277 Create(const ASTContext &C, OpenACCClauseKind Spelling,
1278 SourceLocation BeginLoc, SourceLocation LParenLoc,
1280 SourceLocation EndLoc);
1281};
1282
1283// A structure to stand in for the recipe on a reduction. RecipeDecl is the
1284// 'main' declaration used for initializaiton, which is fixed.
1288 // TODO: OpenACC: this should eventually have the operations here too.
1289
1291 assert(!AllocaDecl || AllocaDecl->getInit() == nullptr);
1292 }
1293
1294 bool isSet() const { return AllocaDecl; }
1296 return OpenACCReductionRecipe(nullptr, nullptr);
1297 }
1298};
1299
1300class OpenACCReductionClause final
1301 : public OpenACCClauseWithVarList,
1302 private llvm::TrailingObjects<OpenACCReductionClause, Expr *,
1303 OpenACCReductionRecipe> {
1304 friend TrailingObjects;
1306
1307 OpenACCReductionClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1308 OpenACCReductionOperator Operator,
1309 ArrayRef<Expr *> VarList,
1311 SourceLocation EndLoc)
1313 LParenLoc, EndLoc),
1314 Op(Operator) {
1315 assert(VarList.size() == Recipes.size());
1316 setExprs(getTrailingObjects<Expr *>(VarList.size()), VarList);
1317 llvm::uninitialized_copy(Recipes, getTrailingObjects<
1319 }
1320
1321public:
1322 static bool classof(const OpenACCClause *C) {
1323 return C->getClauseKind() == OpenACCClauseKind::Reduction;
1324 }
1325
1328 getTrailingObjects<OpenACCReductionRecipe>(), getExprs().size()};
1329 }
1330
1333 getTrailingObjects<OpenACCReductionRecipe>(), getExprs().size()};
1334 }
1335
1336 static OpenACCReductionClause *
1337 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1340
1342
1343 size_t numTrailingObjects(OverloadToken<Expr *>) const {
1344 return getExprs().size();
1345 }
1346};
1347
1348class OpenACCLinkClause final
1349 : public OpenACCClauseWithVarList,
1350 private llvm::TrailingObjects<OpenACCLinkClause, Expr *> {
1351 friend TrailingObjects;
1352
1353 OpenACCLinkClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1354 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1356 EndLoc) {
1357 setExprs(getTrailingObjects(VarList.size()), VarList);
1358 }
1359
1360public:
1361 static bool classof(const OpenACCClause *C) {
1362 return C->getClauseKind() == OpenACCClauseKind::Link;
1363 }
1364
1365 static OpenACCLinkClause *Create(const ASTContext &C, SourceLocation BeginLoc,
1366 SourceLocation LParenLoc,
1367 ArrayRef<Expr *> VarList,
1368 SourceLocation EndLoc);
1369};
1370
1371class OpenACCDeviceResidentClause final
1372 : public OpenACCClauseWithVarList,
1373 private llvm::TrailingObjects<OpenACCDeviceResidentClause, Expr *> {
1374 friend TrailingObjects;
1375
1376 OpenACCDeviceResidentClause(SourceLocation BeginLoc, SourceLocation LParenLoc,
1377 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
1379 LParenLoc, EndLoc) {
1380 setExprs(getTrailingObjects(VarList.size()), VarList);
1381 }
1382
1383public:
1384 static bool classof(const OpenACCClause *C) {
1385 return C->getClauseKind() == OpenACCClauseKind::DeviceResident;
1386 }
1387
1389 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
1390 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
1391};
1392
1393template <class Impl> class OpenACCClauseVisitor {
1394 Impl &getDerived() { return static_cast<Impl &>(*this); }
1395
1396public:
1398 for (const OpenACCClause *Clause : List)
1399 Visit(Clause);
1400 }
1401
1402 void Visit(const OpenACCClause *C) {
1403 if (!C)
1404 return;
1405
1406 switch (C->getClauseKind()) {
1407#define VISIT_CLAUSE(CLAUSE_NAME) \
1408 case OpenACCClauseKind::CLAUSE_NAME: \
1409 getDerived().Visit##CLAUSE_NAME##Clause( \
1410 *cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1411 return;
1412#define CLAUSE_ALIAS(ALIAS_NAME, CLAUSE_NAME, DEPRECATED) \
1413 case OpenACCClauseKind::ALIAS_NAME: \
1414 getDerived().Visit##CLAUSE_NAME##Clause( \
1415 *cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
1416 return;
1417#include "clang/Basic/OpenACCClauses.def"
1418
1419 default:
1420 llvm_unreachable("Clause visitor not yet implemented");
1421 }
1422 llvm_unreachable("Invalid Clause kind");
1423 }
1424
1425#define VISIT_CLAUSE(CLAUSE_NAME) \
1426 void Visit##CLAUSE_NAME##Clause( \
1427 const OpenACC##CLAUSE_NAME##Clause &Clause) { \
1428 return getDerived().VisitClause(Clause); \
1429 }
1430
1431#include "clang/Basic/OpenACCClauses.def"
1432};
1433
1435 : public OpenACCClauseVisitor<OpenACCClausePrinter> {
1436 raw_ostream &OS;
1437 const PrintingPolicy &Policy;
1438
1439 void printExpr(const Expr *E);
1440
1441public:
1443 for (const OpenACCClause *Clause : List) {
1444 Visit(Clause);
1445
1446 if (Clause != List.back())
1447 OS << ' ';
1448 }
1449 }
1450 OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
1451 : OS(OS), Policy(Policy) {}
1452
1453#define VISIT_CLAUSE(CLAUSE_NAME) \
1454 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
1455#include "clang/Basic/OpenACCClauses.def"
1456};
1457
1458} // namespace clang
1459
1460#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:188
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:1801
Represents a variable declaration or definition.
Definition Decl.h:925
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, Expr *I, VarDecl *T)
static OpenACCPrivateRecipe Empty()
OpenACCPrivateRecipe(VarDecl *A, Expr *I)
static OpenACCReductionRecipe Empty()
OpenACCReductionRecipe(VarDecl *A, Expr *I)
Describes how types, statements, expressions, and declarations should be printed.