clang 20.0.0git
OpenACCClause.h
Go to the documentation of this file.
1//===- OpenACCClause.h - Classes for OpenACC clauses ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// \file
10// This file defines OpenACC AST classes for clauses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_OPENACCCLAUSE_H
15#define LLVM_CLANG_AST_OPENACCCLAUSE_H
19
20#include <utility>
21
22namespace clang {
23/// This is the base type for all OpenACC Clauses.
26 SourceRange Location;
27
28protected:
30 SourceLocation EndLoc)
31 : Kind(K), Location(BeginLoc, EndLoc) {
32 assert(!BeginLoc.isInvalid() && !EndLoc.isInvalid() &&
33 "Begin and end location must be valid for OpenACCClause");
34 }
35
36public:
37 OpenACCClauseKind getClauseKind() const { return Kind; }
38 SourceLocation getBeginLoc() const { return Location.getBegin(); }
39 SourceLocation getEndLoc() const { return Location.getEnd(); }
40
41 static bool classof(const OpenACCClause *) { return false; }
42
45 using child_range = llvm::iterator_range<child_iterator>;
46 using const_child_range = llvm::iterator_range<const_child_iterator>;
47
50 auto Children = const_cast<OpenACCClause *>(this)->children();
51 return const_child_range(Children.begin(), Children.end());
52 }
53
54 virtual ~OpenACCClause() = default;
55};
56
57// Represents the 'auto' clause.
59protected:
61 : OpenACCClause(OpenACCClauseKind::Auto, BeginLoc, EndLoc) {}
62
63public:
64 static bool classof(const OpenACCClause *C) {
65 return C->getClauseKind() == OpenACCClauseKind::Auto;
66 }
67
68 static OpenACCAutoClause *
69 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
70
73 }
76 }
77};
78
79// Represents the 'independent' clause.
81protected:
83 : OpenACCClause(OpenACCClauseKind::Independent, BeginLoc, EndLoc) {}
84
85public:
86 static bool classof(const OpenACCClause *C) {
87 return C->getClauseKind() == OpenACCClauseKind::Independent;
88 }
89
91 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
92
95 }
98 }
99};
100// Represents the 'seq' clause.
102protected:
104 : OpenACCClause(OpenACCClauseKind::Seq, BeginLoc, EndLoc) {}
105
106public:
107 static bool classof(const OpenACCClause *C) {
108 return C->getClauseKind() == OpenACCClauseKind::Seq;
109 }
110
111 static OpenACCSeqClause *
112 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
113
116 }
119 }
120};
121
122// Not yet implemented, but the type name is necessary for 'seq' diagnostics, so
123// this provides a basic, do-nothing implementation. We still need to add this
124// type to the visitors/etc, as well as get it to take its proper arguments.
126protected:
128 : OpenACCClause(OpenACCClauseKind::Gang, BeginLoc, EndLoc) {
129 llvm_unreachable("Not yet implemented");
130 }
131
132public:
133 static bool classof(const OpenACCClause *C) {
134 return C->getClauseKind() == OpenACCClauseKind::Gang;
135 }
136
137 static OpenACCGangClause *
138 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
139
142 }
145 }
146};
147
148// Not yet implemented, but the type name is necessary for 'seq' diagnostics, so
149// this provides a basic, do-nothing implementation. We still need to add this
150// type to the visitors/etc, as well as get it to take its proper arguments.
152protected:
154 : OpenACCClause(OpenACCClauseKind::Vector, BeginLoc, EndLoc) {
155 llvm_unreachable("Not yet implemented");
156 }
157
158public:
159 static bool classof(const OpenACCClause *C) {
160 return C->getClauseKind() == OpenACCClauseKind::Gang;
161 }
162
163 static OpenACCVectorClause *
164 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
165
168 }
171 }
172};
173
174// Not yet implemented, but the type name is necessary for 'seq' diagnostics, so
175// this provides a basic, do-nothing implementation. We still need to add this
176// type to the visitors/etc, as well as get it to take its proper arguments.
178protected:
180 : OpenACCClause(OpenACCClauseKind::Gang, BeginLoc, EndLoc) {
181 llvm_unreachable("Not yet implemented");
182 }
183
184public:
185 static bool classof(const OpenACCClause *C) {
186 return C->getClauseKind() == OpenACCClauseKind::Gang;
187 }
188
189 static OpenACCWorkerClause *
190 Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc);
191
194 }
197 }
198};
199
200/// Represents a clause that has a list of parameters.
202 /// Location of the '('.
203 SourceLocation LParenLoc;
204
205protected:
207 SourceLocation LParenLoc, SourceLocation EndLoc)
208 : OpenACCClause(K, BeginLoc, EndLoc), LParenLoc(LParenLoc) {}
209
210public:
211 static bool classof(const OpenACCClause *C);
212
213 SourceLocation getLParenLoc() const { return LParenLoc; }
214
217 }
220 }
221};
222
223using DeviceTypeArgument = std::pair<IdentifierInfo *, SourceLocation>;
224/// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or
225/// an identifier. The 'asterisk' means 'the rest'.
228 public llvm::TrailingObjects<OpenACCDeviceTypeClause,
229 DeviceTypeArgument> {
230 // Data stored in trailing objects as IdentifierInfo* /SourceLocation pairs. A
231 // nullptr IdentifierInfo* represents an asterisk.
232 unsigned NumArchs;
234 SourceLocation LParenLoc,
236 SourceLocation EndLoc)
237 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
238 NumArchs(Archs.size()) {
239 assert(
241 "Invalid clause kind for device-type");
242
243 assert(!llvm::any_of(Archs, [](const DeviceTypeArgument &Arg) {
244 return Arg.second.isInvalid();
245 }) && "Invalid SourceLocation for an argument");
246
247 assert(
248 (Archs.size() == 1 || !llvm::any_of(Archs,
249 [](const DeviceTypeArgument &Arg) {
250 return Arg.first == nullptr;
251 })) &&
252 "Only a single asterisk version is permitted, and must be the "
253 "only one");
254
255 std::uninitialized_copy(Archs.begin(), Archs.end(),
256 getTrailingObjects<DeviceTypeArgument>());
257 }
258
259public:
260 static bool classof(const OpenACCClause *C) {
261 return C->getClauseKind() == OpenACCClauseKind::DType ||
262 C->getClauseKind() == OpenACCClauseKind::DeviceType;
263 }
264 bool hasAsterisk() const {
265 return getArchitectures().size() > 0 &&
266 getArchitectures()[0].first == nullptr;
267 }
268
271 getTrailingObjects<DeviceTypeArgument>(), NumArchs);
272 }
273
277 SourceLocation EndLoc);
278};
279
280/// A 'default' clause, has the optional 'none' or 'present' argument.
282 friend class ASTReaderStmt;
283 friend class ASTWriterStmt;
284
285 OpenACCDefaultClauseKind DefaultClauseKind;
286
287protected:
289 SourceLocation LParenLoc, SourceLocation EndLoc)
290 : OpenACCClauseWithParams(OpenACCClauseKind::Default, BeginLoc, LParenLoc,
291 EndLoc),
292 DefaultClauseKind(K) {
293 assert((DefaultClauseKind == OpenACCDefaultClauseKind::None ||
294 DefaultClauseKind == OpenACCDefaultClauseKind::Present) &&
295 "Invalid Clause Kind");
296 }
297
298public:
299 static bool classof(const OpenACCClause *C) {
300 return C->getClauseKind() == OpenACCClauseKind::Default;
301 }
303 return DefaultClauseKind;
304 }
305
308 SourceLocation BeginLoc,
309 SourceLocation LParenLoc,
310 SourceLocation EndLoc);
311};
312
313/// Represents one of the handful of classes that has an optional/required
314/// 'condition' expression as an argument.
316 Expr *ConditionExpr = nullptr;
317
318protected:
320 SourceLocation LParenLoc, Expr *ConditionExpr,
321 SourceLocation EndLoc)
322 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc),
323 ConditionExpr(ConditionExpr) {}
324
325public:
326 static bool classof(const OpenACCClause *C);
327
328 bool hasConditionExpr() const { return ConditionExpr; }
329 const Expr *getConditionExpr() const { return ConditionExpr; }
330 Expr *getConditionExpr() { return ConditionExpr; }
331
333 if (ConditionExpr)
334 return child_range(reinterpret_cast<Stmt **>(&ConditionExpr),
335 reinterpret_cast<Stmt **>(&ConditionExpr + 1));
337 }
338
340 if (ConditionExpr)
341 return const_child_range(
342 reinterpret_cast<Stmt *const *>(&ConditionExpr),
343 reinterpret_cast<Stmt *const *>(&ConditionExpr + 1));
345 }
346};
347
348/// An 'if' clause, which has a required condition expression.
350protected:
352 Expr *ConditionExpr, SourceLocation EndLoc);
353
354public:
355 static bool classof(const OpenACCClause *C) {
356 return C->getClauseKind() == OpenACCClauseKind::If;
357 }
358 static OpenACCIfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
359 SourceLocation LParenLoc, Expr *ConditionExpr,
360 SourceLocation EndLoc);
361};
362
363/// A 'self' clause, which has an optional condition expression.
366 Expr *ConditionExpr, SourceLocation EndLoc);
367
368public:
369 static bool classof(const OpenACCClause *C) {
370 return C->getClauseKind() == OpenACCClauseKind::Self;
371 }
372 static OpenACCSelfClause *Create(const ASTContext &C, SourceLocation BeginLoc,
373 SourceLocation LParenLoc,
374 Expr *ConditionExpr, SourceLocation EndLoc);
375};
376
377/// Represents a clause that has one or more expressions associated with it.
380
381protected:
383 SourceLocation LParenLoc, SourceLocation EndLoc)
384 : OpenACCClauseWithParams(K, BeginLoc, LParenLoc, EndLoc) {}
385
386 /// Used only for initialization, the leaf class can initialize this to
387 /// trailing storage.
389 assert(Exprs.empty() && "Cannot change Exprs list");
390 Exprs = NewExprs;
391 }
392
393 /// Gets the entire list of expressions, but leave it to the
394 /// individual clauses to expose this how they'd like.
395 llvm::ArrayRef<Expr *> getExprs() const { return Exprs; }
396
397public:
398 static bool classof(const OpenACCClause *C);
400 return child_range(reinterpret_cast<Stmt **>(Exprs.begin()),
401 reinterpret_cast<Stmt **>(Exprs.end()));
402 }
403
405 child_range Children =
406 const_cast<OpenACCClauseWithExprs *>(this)->children();
407 return const_child_range(Children.begin(), Children.end());
408 }
409};
410
411// Represents the 'devnum' and expressions lists for the 'wait' clause.
413 : public OpenACCClauseWithExprs,
414 public llvm::TrailingObjects<OpenACCWaitClause, Expr *> {
415 SourceLocation QueuesLoc;
417 Expr *DevNumExpr, SourceLocation QueuesLoc,
418 ArrayRef<Expr *> QueueIdExprs, SourceLocation EndLoc)
419 : OpenACCClauseWithExprs(OpenACCClauseKind::Wait, BeginLoc, LParenLoc,
420 EndLoc),
421 QueuesLoc(QueuesLoc) {
422 // The first element of the trailing storage is always the devnum expr,
423 // whether it is used or not.
424 std::uninitialized_copy(&DevNumExpr, &DevNumExpr + 1,
425 getTrailingObjects<Expr *>());
426 std::uninitialized_copy(QueueIdExprs.begin(), QueueIdExprs.end(),
427 getTrailingObjects<Expr *>() + 1);
428 setExprs(
429 MutableArrayRef(getTrailingObjects<Expr *>(), QueueIdExprs.size() + 1));
430 }
431
432public:
433 static bool classof(const OpenACCClause *C) {
434 return C->getClauseKind() == OpenACCClauseKind::Wait;
435 }
436 static OpenACCWaitClause *Create(const ASTContext &C, SourceLocation BeginLoc,
437 SourceLocation LParenLoc, Expr *DevNumExpr,
438 SourceLocation QueuesLoc,
439 ArrayRef<Expr *> QueueIdExprs,
440 SourceLocation EndLoc);
441
442 bool hasQueuesTag() const { return !QueuesLoc.isInvalid(); }
443 SourceLocation getQueuesLoc() const { return QueuesLoc; }
444 bool hasDevNumExpr() const { return getExprs()[0]; }
445 Expr *getDevNumExpr() const { return getExprs()[0]; }
447 return OpenACCClauseWithExprs::getExprs().drop_front();
448 }
450 return OpenACCClauseWithExprs::getExprs().drop_front();
451 }
452};
453
455 : public OpenACCClauseWithExprs,
456 public llvm::TrailingObjects<OpenACCNumGangsClause, Expr *> {
457
459 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc)
461 EndLoc) {
462 std::uninitialized_copy(IntExprs.begin(), IntExprs.end(),
463 getTrailingObjects<Expr *>());
464 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), IntExprs.size()));
465 }
466
467public:
468 static bool classof(const OpenACCClause *C) {
469 return C->getClauseKind() == OpenACCClauseKind::NumGangs;
470 }
471 static OpenACCNumGangsClause *
472 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
473 ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
474
477 }
478
481 }
482};
483
484/// Represents one of a handful of clauses that have a single integer
485/// expression.
487 Expr *IntExpr;
488
489protected:
491 SourceLocation LParenLoc, Expr *IntExpr,
492 SourceLocation EndLoc)
493 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc),
494 IntExpr(IntExpr) {
495 if (IntExpr)
496 setExprs(MutableArrayRef<Expr *>{&this->IntExpr, 1});
497 }
498
499public:
500 static bool classof(const OpenACCClause *C);
501 bool hasIntExpr() const { return !getExprs().empty(); }
502 const Expr *getIntExpr() const {
503 return hasIntExpr() ? getExprs()[0] : nullptr;
504 }
505
506 Expr *getIntExpr() { return hasIntExpr() ? getExprs()[0] : nullptr; };
507};
508
511 Expr *IntExpr, SourceLocation EndLoc);
512
513public:
514 static bool classof(const OpenACCClause *C) {
515 return C->getClauseKind() == OpenACCClauseKind::NumWorkers;
516 }
518 SourceLocation BeginLoc,
519 SourceLocation LParenLoc,
520 Expr *IntExpr, SourceLocation EndLoc);
521};
522
525 Expr *IntExpr, SourceLocation EndLoc);
526
527public:
528 static bool classof(const OpenACCClause *C) {
529 return C->getClauseKind() == OpenACCClauseKind::VectorLength;
530 }
532 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
533 Expr *IntExpr, SourceLocation EndLoc);
534};
535
538 Expr *IntExpr, SourceLocation EndLoc);
539
540public:
541 static bool classof(const OpenACCClause *C) {
542 return C->getClauseKind() == OpenACCClauseKind::Async;
543 }
544 static OpenACCAsyncClause *Create(const ASTContext &C,
545 SourceLocation BeginLoc,
546 SourceLocation LParenLoc, Expr *IntExpr,
547 SourceLocation EndLoc);
548};
549
550/// Represents a clause with one or more 'var' objects, represented as an expr,
551/// as its arguments. Var-list is expected to be stored in trailing storage.
552/// For now, we're just storing the original expression in its entirety, unlike
553/// OMP which has to do a bunch of work to create a private.
555protected:
557 SourceLocation LParenLoc, SourceLocation EndLoc)
558 : OpenACCClauseWithExprs(K, BeginLoc, LParenLoc, EndLoc) {}
559
560public:
561 static bool classof(const OpenACCClause *C);
564};
565
568 public llvm::TrailingObjects<OpenACCPrivateClause, Expr *> {
569
571 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
573 LParenLoc, EndLoc) {
574 std::uninitialized_copy(VarList.begin(), VarList.end(),
575 getTrailingObjects<Expr *>());
576 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
577 }
578
579public:
580 static bool classof(const OpenACCClause *C) {
581 return C->getClauseKind() == OpenACCClauseKind::Private;
582 }
583 static OpenACCPrivateClause *
584 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
585 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
586};
587
590 public llvm::TrailingObjects<OpenACCFirstPrivateClause, Expr *> {
591
593 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
595 LParenLoc, EndLoc) {
596 std::uninitialized_copy(VarList.begin(), VarList.end(),
597 getTrailingObjects<Expr *>());
598 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
599 }
600
601public:
602 static bool classof(const OpenACCClause *C) {
603 return C->getClauseKind() == OpenACCClauseKind::FirstPrivate;
604 }
606 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
607 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
608};
609
612 public llvm::TrailingObjects<OpenACCDevicePtrClause, Expr *> {
613
615 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
617 LParenLoc, EndLoc) {
618 std::uninitialized_copy(VarList.begin(), VarList.end(),
619 getTrailingObjects<Expr *>());
620 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
621 }
622
623public:
624 static bool classof(const OpenACCClause *C) {
625 return C->getClauseKind() == OpenACCClauseKind::DevicePtr;
626 }
628 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
629 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
630};
631
634 public llvm::TrailingObjects<OpenACCAttachClause, Expr *> {
635
637 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
639 EndLoc) {
640 std::uninitialized_copy(VarList.begin(), VarList.end(),
641 getTrailingObjects<Expr *>());
642 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
643 }
644
645public:
646 static bool classof(const OpenACCClause *C) {
647 return C->getClauseKind() == OpenACCClauseKind::Attach;
648 }
649 static OpenACCAttachClause *
650 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
651 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
652};
653
656 public llvm::TrailingObjects<OpenACCNoCreateClause, Expr *> {
657
659 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
661 LParenLoc, EndLoc) {
662 std::uninitialized_copy(VarList.begin(), VarList.end(),
663 getTrailingObjects<Expr *>());
664 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
665 }
666
667public:
668 static bool classof(const OpenACCClause *C) {
669 return C->getClauseKind() == OpenACCClauseKind::NoCreate;
670 }
671 static OpenACCNoCreateClause *
672 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
673 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
674};
675
678 public llvm::TrailingObjects<OpenACCPresentClause, Expr *> {
679
681 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
683 LParenLoc, EndLoc) {
684 std::uninitialized_copy(VarList.begin(), VarList.end(),
685 getTrailingObjects<Expr *>());
686 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
687 }
688
689public:
690 static bool classof(const OpenACCClause *C) {
691 return C->getClauseKind() == OpenACCClauseKind::Present;
692 }
693 static OpenACCPresentClause *
694 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
695 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
696};
697
700 public llvm::TrailingObjects<OpenACCCopyClause, Expr *> {
701
703 SourceLocation LParenLoc, ArrayRef<Expr *> VarList,
704 SourceLocation EndLoc)
705 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc) {
706 assert((Spelling == OpenACCClauseKind::Copy ||
707 Spelling == OpenACCClauseKind::PCopy ||
709 "Invalid clause kind for copy-clause");
710 std::uninitialized_copy(VarList.begin(), VarList.end(),
711 getTrailingObjects<Expr *>());
712 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
713 }
714
715public:
716 static bool classof(const OpenACCClause *C) {
717 return C->getClauseKind() == OpenACCClauseKind::Copy ||
718 C->getClauseKind() == OpenACCClauseKind::PCopy ||
719 C->getClauseKind() == OpenACCClauseKind::PresentOrCopy;
720 }
721 static OpenACCCopyClause *
722 Create(const ASTContext &C, OpenACCClauseKind Spelling,
723 SourceLocation BeginLoc, SourceLocation LParenLoc,
724 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
725};
726
729 public llvm::TrailingObjects<OpenACCCopyInClause, Expr *> {
730 bool IsReadOnly;
731
733 SourceLocation LParenLoc, bool IsReadOnly,
734 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
735 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
736 IsReadOnly(IsReadOnly) {
737 assert((Spelling == OpenACCClauseKind::CopyIn ||
738 Spelling == OpenACCClauseKind::PCopyIn ||
740 "Invalid clause kind for copyin-clause");
741 std::uninitialized_copy(VarList.begin(), VarList.end(),
742 getTrailingObjects<Expr *>());
743 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
744 }
745
746public:
747 static bool classof(const OpenACCClause *C) {
748 return C->getClauseKind() == OpenACCClauseKind::CopyIn ||
749 C->getClauseKind() == OpenACCClauseKind::PCopyIn ||
750 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyIn;
751 }
752 bool isReadOnly() const { return IsReadOnly; }
753 static OpenACCCopyInClause *
754 Create(const ASTContext &C, OpenACCClauseKind Spelling,
755 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsReadOnly,
756 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
757};
758
761 public llvm::TrailingObjects<OpenACCCopyOutClause, Expr *> {
762 bool IsZero;
763
765 SourceLocation LParenLoc, bool IsZero,
766 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
767 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
768 IsZero(IsZero) {
769 assert((Spelling == OpenACCClauseKind::CopyOut ||
770 Spelling == OpenACCClauseKind::PCopyOut ||
772 "Invalid clause kind for copyout-clause");
773 std::uninitialized_copy(VarList.begin(), VarList.end(),
774 getTrailingObjects<Expr *>());
775 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
776 }
777
778public:
779 static bool classof(const OpenACCClause *C) {
780 return C->getClauseKind() == OpenACCClauseKind::CopyOut ||
781 C->getClauseKind() == OpenACCClauseKind::PCopyOut ||
782 C->getClauseKind() == OpenACCClauseKind::PresentOrCopyOut;
783 }
784 bool isZero() const { return IsZero; }
785 static OpenACCCopyOutClause *
786 Create(const ASTContext &C, OpenACCClauseKind Spelling,
787 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero,
788 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
789};
790
793 public llvm::TrailingObjects<OpenACCCreateClause, Expr *> {
794 bool IsZero;
795
797 SourceLocation LParenLoc, bool IsZero,
798 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
799 : OpenACCClauseWithVarList(Spelling, BeginLoc, LParenLoc, EndLoc),
800 IsZero(IsZero) {
801 assert((Spelling == OpenACCClauseKind::Create ||
802 Spelling == OpenACCClauseKind::PCreate ||
804 "Invalid clause kind for create-clause");
805 std::uninitialized_copy(VarList.begin(), VarList.end(),
806 getTrailingObjects<Expr *>());
807 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
808 }
809
810public:
811 static bool classof(const OpenACCClause *C) {
812 return C->getClauseKind() == OpenACCClauseKind::Create ||
813 C->getClauseKind() == OpenACCClauseKind::PCreate ||
814 C->getClauseKind() == OpenACCClauseKind::PresentOrCreate;
815 }
816 bool isZero() const { return IsZero; }
817 static OpenACCCreateClause *
818 Create(const ASTContext &C, OpenACCClauseKind Spelling,
819 SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero,
820 ArrayRef<Expr *> VarList, SourceLocation EndLoc);
821};
822
825 public llvm::TrailingObjects<OpenACCReductionClause, Expr *> {
827
830 ArrayRef<Expr *> VarList, SourceLocation EndLoc)
832 LParenLoc, EndLoc),
833 Op(Operator) {
834 std::uninitialized_copy(VarList.begin(), VarList.end(),
835 getTrailingObjects<Expr *>());
836 setExprs(MutableArrayRef(getTrailingObjects<Expr *>(), VarList.size()));
837 }
838
839public:
840 static bool classof(const OpenACCClause *C) {
841 return C->getClauseKind() == OpenACCClauseKind::Reduction;
842 }
843
845 Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc,
847 SourceLocation EndLoc);
848
850};
851
852template <class Impl> class OpenACCClauseVisitor {
853 Impl &getDerived() { return static_cast<Impl &>(*this); }
854
855public:
857 for (const OpenACCClause *Clause : List)
858 Visit(Clause);
859 }
860
861 void Visit(const OpenACCClause *C) {
862 if (!C)
863 return;
864
865 switch (C->getClauseKind()) {
866#define VISIT_CLAUSE(CLAUSE_NAME) \
867 case OpenACCClauseKind::CLAUSE_NAME: \
868 Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
869 return;
870#define CLAUSE_ALIAS(ALIAS_NAME, CLAUSE_NAME, DEPRECATED) \
871 case OpenACCClauseKind::ALIAS_NAME: \
872 Visit##CLAUSE_NAME##Clause(*cast<OpenACC##CLAUSE_NAME##Clause>(C)); \
873 return;
874#include "clang/Basic/OpenACCClauses.def"
875
876 default:
877 llvm_unreachable("Clause visitor not yet implemented");
878 }
879 llvm_unreachable("Invalid Clause kind");
880 }
881
882#define VISIT_CLAUSE(CLAUSE_NAME) \
883 void Visit##CLAUSE_NAME##Clause( \
884 const OpenACC##CLAUSE_NAME##Clause &Clause) { \
885 return getDerived().Visit##CLAUSE_NAME##Clause(Clause); \
886 }
887
888#include "clang/Basic/OpenACCClauses.def"
889};
890
892 : public OpenACCClauseVisitor<OpenACCClausePrinter> {
893 raw_ostream &OS;
894 const PrintingPolicy &Policy;
895
896 void printExpr(const Expr *E);
897
898public:
900 for (const OpenACCClause *Clause : List) {
901 Visit(Clause);
902
903 if (Clause != List.back())
904 OS << ' ';
905 }
906 }
907 OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
908 : OS(OS), Policy(Policy) {}
909
910#define VISIT_CLAUSE(CLAUSE_NAME) \
911 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
912#include "clang/Basic/OpenACCClauses.def"
913};
914
915} // namespace clang
916
917#endif // LLVM_CLANG_AST_OPENACCCLAUSE_H
Defines the clang::ASTContext interface.
Expr * E
Defines some OpenACC-specific enums and functions.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
This represents one expression.
Definition: Expr.h:110
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
const_child_range children() const
Definition: OpenACCClause.h:74
OpenACCAutoClause(SourceLocation BeginLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:60
static bool classof(const OpenACCClause *C)
Definition: OpenACCClause.h:64
OpenACCClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
void VisitClauseList(ArrayRef< const OpenACCClause * > List)
void Visit(const OpenACCClause *C)
void VisitClauseList(ArrayRef< const OpenACCClause * > List)
Represents one of the handful of classes that has an optional/required 'condition' expression as an a...
static bool classof(const OpenACCClause *C)
const Expr * getConditionExpr() const
OpenACCClauseWithCondition(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
const_child_range children() const
Represents a clause that has one or more expressions associated with it.
static bool classof(const OpenACCClause *C)
OpenACCClauseWithExprs(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
llvm::ArrayRef< Expr * > getExprs() const
Gets the entire list of expressions, but leave it to the individual clauses to expose this how they'd...
const_child_range children() const
void setExprs(MutableArrayRef< Expr * > NewExprs)
Used only for initialization, the leaf class can initialize this to trailing storage.
Represents a clause that has a list of parameters.
SourceLocation getLParenLoc() const
static bool classof(const OpenACCClause *C)
OpenACCClauseWithParams(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
const_child_range children() const
Represents one of a handful of clauses that have a single integer expression.
OpenACCClauseWithSingleIntExpr(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
Represents a clause with one or more 'var' objects, represented as an expr, as its arguments.
OpenACCClauseWithVarList(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static bool classof(const OpenACCClause *C)
ArrayRef< Expr * > getVarList()
ArrayRef< Expr * > getVarList() const
This is the base type for all OpenACC Clauses.
Definition: OpenACCClause.h:24
child_range children()
StmtIterator child_iterator
Definition: OpenACCClause.h:43
OpenACCClauseKind getClauseKind() const
Definition: OpenACCClause.h:37
SourceLocation getBeginLoc() const
Definition: OpenACCClause.h:38
const_child_range children() const
Definition: OpenACCClause.h:49
static bool classof(const OpenACCClause *)
Definition: OpenACCClause.h:41
llvm::iterator_range< child_iterator > child_range
Definition: OpenACCClause.h:45
ConstStmtIterator const_child_iterator
Definition: OpenACCClause.h:44
OpenACCClause(OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:29
virtual ~OpenACCClause()=default
llvm::iterator_range< const_child_iterator > const_child_range
Definition: OpenACCClause.h:46
SourceLocation getEndLoc() const
Definition: OpenACCClause.h:39
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
A 'default' clause, has the optional 'none' or 'present' argument.
OpenACCDefaultClause(OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
OpenACCDefaultClauseKind getDefaultClauseKind() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
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)
static bool classof(const OpenACCClause *C)
OpenACCGangClause(SourceLocation BeginLoc, SourceLocation EndLoc)
const_child_range children() const
static bool classof(const OpenACCClause *C)
An 'if' clause, which has a required condition expression.
static bool classof(const OpenACCClause *C)
OpenACCIndependentClause(SourceLocation BeginLoc, SourceLocation EndLoc)
Definition: OpenACCClause.h:82
static bool classof(const OpenACCClause *C)
Definition: OpenACCClause.h:86
const_child_range children() const
Definition: OpenACCClause.h:96
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
llvm::ArrayRef< Expr * > getIntExprs() const
llvm::ArrayRef< Expr * > getIntExprs()
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
OpenACCReductionOperator getReductionOp() const
A 'self' clause, which has an optional condition expression.
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
const_child_range children() const
OpenACCSeqClause(SourceLocation BeginLoc, SourceLocation EndLoc)
OpenACCVectorClause(SourceLocation BeginLoc, SourceLocation EndLoc)
const_child_range children() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
Expr * getDevNumExpr() const
llvm::ArrayRef< Expr * > getQueueIdExprs()
llvm::ArrayRef< Expr * > getQueueIdExprs() const
SourceLocation getQueuesLoc() const
static bool classof(const OpenACCClause *C)
static bool classof(const OpenACCClause *C)
OpenACCWorkerClause(SourceLocation BeginLoc, SourceLocation EndLoc)
const_child_range children() const
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
The JSON file list parser is used to communicate input to InstallAPI.
OpenACCClauseKind
Represents the kind of an OpenACC clause.
Definition: OpenACCKinds.h:164
@ Auto
'auto' clause, allowed on 'loop' directives.
@ Gang
'gang' clause, allowed on 'loop' and Combined constructs.
@ Wait
'wait' clause, allowed on Compute, Data, 'update', and Combined constructs.
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ PCopyOut
'copyout' clause alias 'pcopyout'. Preserved for diagnostic purposes.
@ VectorLength
'vector_length' clause, allowed on 'parallel', 'kernels', 'parallel loop', and 'kernels loop' constru...
@ Async
'async' clause, allowed on Compute, Data, 'update', 'wait', and Combined constructs.
@ PresentOrCreate
'create' clause alias 'present_or_create'.
@ PresentOrCopy
'copy' clause alias 'present_or_copy'. Preserved for diagnostic purposes.
@ 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'.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ DeviceType
'device_type' clause, allowed on Compute, 'data', 'init', 'shutdown', 'set', update',...
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ NumGangs
'num_gangs' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs.
@ If
'if' clause, allowed on all the Compute Constructs, Data Constructs, Executable Constructs,...
@ Default
'default' clause, allowed on parallel, serial, kernel (and compound) constructs.
@ NoCreate
'no_create' clause, allowed on allowed on Compute and Combined constructs, plus 'data'.
@ PresentOrCopyOut
'copyout' clause alias 'present_or_copyout'.
@ Reduction
'reduction' clause, allowed on Parallel, Serial, Loop, and the combined constructs.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ CopyOut
'copyout' clause, allowed on Compute and Combined constructs, plus 'data', 'exit data',...
@ Seq
'seq' clause, allowed on 'loop' and 'routine' directives.
@ FirstPrivate
'firstprivate' clause, allowed on 'parallel', 'serial', 'parallel loop', and 'serial loop' constructs...
@ PCopy
'copy' clause alias 'pcopy'. Preserved for diagnostic purposes.
@ PCopyIn
'copyin' clause alias 'pcopyin'. Preserved for diagnostic purposes.
@ PCreate
'create' clause alias 'pcreate'. Preserved for diagnostic purposes.
@ Present
'present' clause, allowed on Compute and Combined constructs, plus 'data' and 'declare'.
@ DType
'dtype' clause, an alias for 'device_type', stored separately for diagnostic purposes.
@ CopyIn
'copyin' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Independent
'independent' clause, allowed on 'loop' directives.
@ NumWorkers
'num_workers' clause, allowed on 'parallel', 'kernels', parallel loop', and 'kernels loop' constructs...
@ PresentOrCopyIn
'copyin' clause alias 'present_or_copyin'.
OpenACCDefaultClauseKind
Definition: OpenACCKinds.h:462
std::pair< IdentifierInfo *, SourceLocation > DeviceTypeArgument
OpenACCReductionOperator
Definition: OpenACCKinds.h:495
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57