clang 24.0.0git
OpenMPClause.h
Go to the documentation of this file.
1//===- OpenMPClause.h - Classes for OpenMP 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 OpenMP AST classes for clauses.
11/// There are clauses for executable directives, clauses for declarative
12/// directives and clauses which can be used in both kinds of directives.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17#define LLVM_CLANG_AST_OPENMPCLAUSE_H
18
19#include "clang/AST/ASTFwd.h"
20#include "clang/AST/Decl.h"
22#include "clang/AST/Expr.h"
24#include "clang/AST/Stmt.h"
26#include "clang/Basic/LLVM.h"
29#include "llvm/ADT/ArrayRef.h"
30#include "llvm/ADT/MapVector.h"
31#include "llvm/ADT/PointerIntPair.h"
32#include "llvm/ADT/SmallVector.h"
33#include "llvm/ADT/iterator.h"
34#include "llvm/ADT/iterator_range.h"
35#include "llvm/Frontend/OpenMP/OMPAssume.h"
36#include "llvm/Frontend/OpenMP/OMPConstants.h"
37#include "llvm/Frontend/OpenMP/OMPContext.h"
38#include "llvm/Frontend/OpenMP/OMPVersion.h"
39#include "llvm/Support/Casting.h"
40#include "llvm/Support/Compiler.h"
41#include "llvm/Support/TrailingObjects.h"
42#include <cassert>
43#include <climits>
44#include <cstddef>
45#include <iterator>
46#include <utility>
47
48namespace clang {
49
50class ASTContext;
51
52/// One item in an OpenMP 'adjust_args' parameter list.
54 /// One bound of a parameter range.
55 struct Bound {
57
59 /// The bound expression, or the logical offset for a NumArgs bound.
60 Expr *E = nullptr;
61 bool IsSubtraction = false;
62 };
63
65
67 /// A named parameter or positional expression for a Single item.
68 Expr *E = nullptr;
71};
72
73/// Describes the source-level contents of one OpenMP 'adjust_args' clause.
74class OMPAdjustArgsDescriptor final
75 : private llvm::TrailingObjects<OMPAdjustArgsDescriptor,
76 OMPAdjustArgsItem> {
77 friend TrailingObjects;
78
79 unsigned NumItems;
80
81 OMPAdjustArgsDescriptor(OpenMPAdjustArgsOpKind AdjustOp,
83 unsigned NumItems)
84 : NumItems(NumItems), AdjustOp(AdjustOp),
86
87public:
90
91 static OMPAdjustArgsDescriptor *
95
97 return {getTrailingObjects(), NumItems};
98 }
99};
100
101//===----------------------------------------------------------------------===//
102// AST classes for clauses.
103//===----------------------------------------------------------------------===//
104
105/// This is a basic class for representing single OpenMP clause.
107 /// Starting location of the clause (the clause keyword).
108 SourceLocation StartLoc;
109
110 /// Ending location of the clause.
111 SourceLocation EndLoc;
112
113 /// Kind of the clause.
114 OpenMPClauseKind Kind;
115
116protected:
118 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
119
120public:
121 /// Returns the starting location of the clause.
122 SourceLocation getBeginLoc() const { return StartLoc; }
123
124 /// Returns the ending location of the clause.
125 SourceLocation getEndLoc() const { return EndLoc; }
126
127 /// Sets the starting location of the clause.
128 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
129
130 /// Sets the ending location of the clause.
131 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
132
133 /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
134 OpenMPClauseKind getClauseKind() const { return Kind; }
135
136 bool isImplicit() const { return StartLoc.isInvalid(); }
137
140 using child_range = llvm::iterator_range<child_iterator>;
141 using const_child_range = llvm::iterator_range<const_child_iterator>;
142
145 return const_cast<OMPClause *>(this)->children();
146 }
147
148 /// Get the iterator range for the expressions used in the clauses. Used
149 /// expressions include only the children that must be evaluated at the
150 /// runtime before entering the construct.
153 return const_cast<OMPClause *>(this)->children();
154 }
155
156 static bool classof(const OMPClause *) { return true; }
157};
158
159template <OpenMPClauseKind ClauseKind>
161 /// Build '\p ClauseKind' clause.
162 ///
163 /// \param StartLoc Starting location of the clause.
164 /// \param EndLoc Ending location of the clause.
166 : OMPClause(ClauseKind, StartLoc, EndLoc) {}
167
168 /// Build an empty clause.
171
175
179
186
187 static bool classof(const OMPClause *T) {
188 return T->getClauseKind() == ClauseKind;
189 }
190};
191
192template <OpenMPClauseKind ClauseKind, class Base>
193class OMPOneStmtClause : public Base {
194
195 /// Location of '('.
196 SourceLocation LParenLoc;
197
198 /// Sub-expression.
199 Stmt *S = nullptr;
200
201protected:
202 void setStmt(Stmt *S) { this->S = S; }
203
204public:
206 SourceLocation EndLoc)
207 : Base(ClauseKind, StartLoc, EndLoc), LParenLoc(LParenLoc), S(S) {}
208
210
211 /// Return the associated statement, potentially casted to \p T.
212 template <typename T> T *getStmtAs() const { return cast_or_null<T>(S); }
213
214 /// Sets the location of '('.
215 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
216
217 /// Returns the location of '('.
218 SourceLocation getLParenLoc() const { return LParenLoc; }
219
222 using child_range = llvm::iterator_range<child_iterator>;
223 using const_child_range = llvm::iterator_range<const_child_iterator>;
224
225 child_range children() { return child_range(&S, &S + 1); }
226
227 const_child_range children() const { return const_child_range(&S, &S + 1); }
228
229 // TODO: Consider making the getAddrOfExprAsWritten version the default.
236
237 static bool classof(const OMPClause *T) {
238 return T->getClauseKind() == ClauseKind;
239 }
240};
241
242/// Class that handles pre-initialization statement for some clauses, like
243/// 'schedule', 'firstprivate' etc.
245 friend class OMPClauseReader;
246
247 /// Pre-initialization statement for the clause.
248 Stmt *PreInit = nullptr;
249
250 /// Region that captures the associated stmt.
251 OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
252
253protected:
255 assert(get(This) && "get is not tuned for pre-init.");
256 }
257
258 /// Set pre-initialization statement for the clause.
259 void
261 OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
262 PreInit = S;
263 CaptureRegion = ThisRegion;
264 }
265
266public:
267 /// Get pre-initialization statement for the clause.
268 const Stmt *getPreInitStmt() const { return PreInit; }
269
270 /// Get pre-initialization statement for the clause.
271 Stmt *getPreInitStmt() { return PreInit; }
272
273 /// Get capture region for the stmt in the clause.
274 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
275
277 static const OMPClauseWithPreInit *get(const OMPClause *C);
278};
279
280/// Class that handles post-update expression for some clauses, like
281/// 'lastprivate', 'reduction' etc.
283 friend class OMPClauseReader;
284
285 /// Post-update expression for the clause.
286 Expr *PostUpdate = nullptr;
287
288protected:
290 assert(get(This) && "get is not tuned for post-update.");
291 }
292
293 /// Set pre-initialization statement for the clause.
294 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
295
296public:
297 /// Get post-update expression for the clause.
298 const Expr *getPostUpdateExpr() const { return PostUpdate; }
299
300 /// Get post-update expression for the clause.
301 Expr *getPostUpdateExpr() { return PostUpdate; }
302
304 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
305};
306
307/// This structure contains most locations needed for by an OMPVarListClause.
309 /// Starting location of the clause (the clause keyword).
311 /// Location of '('.
313 /// Ending location of the clause.
315 OMPVarListLocTy() = default;
319};
320
321/// This represents clauses with the list of variables like 'private',
322/// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
323/// '#pragma omp ...' directives.
324template <class T> class OMPVarListClause : public OMPClause {
325 friend class OMPClauseReader;
326
327 /// Location of '('.
328 SourceLocation LParenLoc;
329
330 /// Number of variables in the list.
331 unsigned NumVars;
332
333protected:
334 /// Build a clause with \a N variables
335 ///
336 /// \param K Kind of the clause.
337 /// \param StartLoc Starting location of the clause (the clause keyword).
338 /// \param LParenLoc Location of '('.
339 /// \param EndLoc Ending location of the clause.
340 /// \param N Number of the variables in the clause.
342 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
343 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
344
345 /// Fetches list of variables associated with this clause.
347 return static_cast<T *>(this)->template getTrailingObjectsNonStrict<Expr *>(
348 NumVars);
349 }
350
351 /// Sets the list of variables for this clause.
353 assert(VL.size() == NumVars &&
354 "Number of variables is not the same as the preallocated buffer");
355 llvm::copy(VL, getVarRefs().begin());
356 }
357
358public:
361 using varlist_range = llvm::iterator_range<varlist_iterator>;
362 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
363
364 unsigned varlist_size() const { return NumVars; }
365 bool varlist_empty() const { return NumVars == 0; }
366
369
372 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
374
375 /// Sets the location of '('.
376 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
377
378 /// Returns the location of '('.
379 SourceLocation getLParenLoc() const { return LParenLoc; }
380
381 /// Fetches list of all variables in the clause.
383 return static_cast<const T *>(this)
384 ->template getTrailingObjectsNonStrict<Expr *>(NumVars);
385 }
386};
387
388/// Class that represents a list of directive kinds (parallel, target, etc.)
389/// as used in \c absent, \c contains clauses.
390template <class T> class OMPDirectiveListClause : public OMPClause {
391 /// Location of '('.
392 SourceLocation LParenLoc;
393
394protected:
395 /// Number of directive kinds listed in the clause
396 unsigned NumKinds;
397
398public:
399 /// Build a clause with \a NumKinds directive kinds.
400 ///
401 /// \param K The clause kind.
402 /// \param StartLoc Starting location of the clause (the clause keyword).
403 /// \param LParenLoc Location of '('.
404 /// \param EndLoc Ending location of the clause.
405 /// \param NumKinds Number of directive kinds listed in the clause.
407 SourceLocation LParenLoc, SourceLocation EndLoc,
408 unsigned NumKinds)
409 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc),
411
415
419
426
428 return static_cast<T *>(this)
429 ->template getTrailingObjectsNonStrict<OpenMPDirectiveKind>(NumKinds);
430 }
431
433 assert(
434 DK.size() == NumKinds &&
435 "Number of directive kinds is not the same as the preallocated buffer");
436 llvm::copy(DK, getDirectiveKinds().begin());
437 }
438
439 SourceLocation getLParenLoc() { return LParenLoc; }
440
441 void setLParenLoc(SourceLocation S) { LParenLoc = S; }
442};
443
444/// This represents 'allocator' clause in the '#pragma omp ...'
445/// directive.
446///
447/// \code
448/// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
449/// \endcode
450/// In this example directive '#pragma omp allocate' has simple 'allocator'
451/// clause with the allocator 'omp_default_mem_alloc'.
453 : public OMPOneStmtClause<llvm::omp::OMPC_allocator, OMPClause> {
454 friend class OMPClauseReader;
455
456 /// Set allocator.
457 void setAllocator(Expr *A) { setStmt(A); }
458
459public:
460 /// Build 'allocator' clause with the given allocator.
461 ///
462 /// \param A Allocator.
463 /// \param StartLoc Starting location of the clause.
464 /// \param LParenLoc Location of '('.
465 /// \param EndLoc Ending location of the clause.
467 SourceLocation EndLoc)
468 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
469
470 /// Build an empty clause.
472
473 /// Returns allocator.
474 Expr *getAllocator() const { return getStmtAs<Expr>(); }
475};
476
477/// This represents the 'align' clause in the '#pragma omp allocate'
478/// directive.
479///
480/// \code
481/// #pragma omp allocate(a) allocator(omp_default_mem_alloc) align(8)
482/// \endcode
483/// In this example directive '#pragma omp allocate' has simple 'allocator'
484/// clause with the allocator 'omp_default_mem_alloc' and align clause with
485/// value of 8.
486class OMPAlignClause final
487 : public OMPOneStmtClause<llvm::omp::OMPC_align, OMPClause> {
488 friend class OMPClauseReader;
489
490 /// Set alignment value.
491 void setAlignment(Expr *A) { setStmt(A); }
492
493public:
494 /// Build 'align' clause with the given alignment
495 ///
496 /// \param A Alignment value.
497 /// \param StartLoc Starting location of the clause.
498 /// \param LParenLoc Location of '('.
499 /// \param EndLoc Ending location of the clause.
501 SourceLocation EndLoc)
502 : OMPOneStmtClause(A, StartLoc, LParenLoc, EndLoc) {}
503
504 /// Build an empty clause.
506
507 /// Returns alignment
508 Expr *getAlignment() const { return getStmtAs<Expr>(); }
509};
510
511/// This represents clause 'allocate' in the '#pragma omp ...' directives.
512///
513/// \code
514/// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
515/// \endcode
516/// In this example directive '#pragma omp parallel' has clause 'private'
517/// and clause 'allocate' for the variable 'a', which specifies an explicit
518/// memory allocator.
519class OMPAllocateClause final
520 : public OMPVarListClause<OMPAllocateClause>,
521 private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
522 friend class OMPClauseReader;
523 friend OMPVarListClause;
524 friend TrailingObjects;
525
526 /// Allocator specified in the clause, or 'nullptr' if the default one is
527 /// used.
528 Expr *Allocator = nullptr;
529 /// Alignment specified in the clause, or 'nullptr' if the default one is
530 /// used.
531 Expr *Alignment = nullptr;
532 /// Position of the ':' delimiter in the clause;
533 SourceLocation ColonLoc;
534 /// Modifier of 'allocate' clause.
536 /// Location of allocator modifier if any.
537 SourceLocation AllocatorModifierLoc;
538
539 // ----------------------------------------------------------------------------
540
541 /// Modifiers for 'allocate' clause.
542 enum { FIRST, SECOND, NUM_MODIFIERS };
543 OpenMPAllocateClauseModifier Modifiers[NUM_MODIFIERS];
544
545 /// Locations of modifiers.
546 SourceLocation ModifiersLoc[NUM_MODIFIERS];
547
548 /// Set the first allocate modifier.
549 ///
550 /// \param M Allocate modifier.
551 void setFirstAllocateModifier(OpenMPAllocateClauseModifier M) {
552 Modifiers[FIRST] = M;
553 }
554
555 /// Set the second allocate modifier.
556 ///
557 /// \param M Allocate modifier.
558 void setSecondAllocateModifier(OpenMPAllocateClauseModifier M) {
559 Modifiers[SECOND] = M;
560 }
561
562 /// Set location of the first allocate modifier.
563 void setFirstAllocateModifierLoc(SourceLocation Loc) {
564 ModifiersLoc[FIRST] = Loc;
565 }
566
567 /// Set location of the second allocate modifier.
568 void setSecondAllocateModifierLoc(SourceLocation Loc) {
569 ModifiersLoc[SECOND] = Loc;
570 }
571
572 // ----------------------------------------------------------------------------
573
574 /// Build clause with number of variables \a N.
575 ///
576 /// \param StartLoc Starting location of the clause.
577 /// \param LParenLoc Location of '('.
578 /// \param Allocator Allocator expression.
579 /// \param ColonLoc Location of ':' delimiter.
580 /// \param EndLoc Ending location of the clause.
581 /// \param N Number of the variables in the clause.
582 OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
583 Expr *Allocator, Expr *Alignment, SourceLocation ColonLoc,
585 SourceLocation Modifier1Loc,
587 SourceLocation Modifier2Loc, SourceLocation EndLoc,
588 unsigned N)
589 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
590 LParenLoc, EndLoc, N),
591 Allocator(Allocator), Alignment(Alignment), ColonLoc(ColonLoc) {
592 Modifiers[FIRST] = Modifier1;
593 Modifiers[SECOND] = Modifier2;
594 ModifiersLoc[FIRST] = Modifier1Loc;
595 ModifiersLoc[SECOND] = Modifier2Loc;
596 }
597
598 /// Build an empty clause.
599 ///
600 /// \param N Number of variables.
601 explicit OMPAllocateClause(unsigned N)
602 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
603 SourceLocation(), SourceLocation(),
604 SourceLocation(), N) {
605 Modifiers[FIRST] = OMPC_ALLOCATE_unknown;
606 Modifiers[SECOND] = OMPC_ALLOCATE_unknown;
607 }
608
609 /// Sets location of ':' symbol in clause.
610 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
611
612 void setAllocator(Expr *A) { Allocator = A; }
613 void setAllocatorModifier(OpenMPAllocateClauseModifier AM) {
614 AllocatorModifier = AM;
615 }
616 void setAlignment(Expr *A) { Alignment = A; }
617
618public:
619 /// Creates clause with a list of variables \a VL.
620 ///
621 /// \param C AST context.
622 /// \param StartLoc Starting location of the clause.
623 /// \param LParenLoc Location of '('.
624 /// \param Allocator Allocator expression.
625 /// \param ColonLoc Location of ':' delimiter.
626 /// \param AllocatorModifier Allocator modifier.
627 /// \param SourceLocation Allocator modifier location.
628 /// \param EndLoc Ending location of the clause.
629 /// \param VL List of references to the variables.
630 static OMPAllocateClause *
631 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
632 Expr *Allocator, Expr *Alignment, SourceLocation ColonLoc,
633 OpenMPAllocateClauseModifier Modifier1, SourceLocation Modifier1Loc,
634 OpenMPAllocateClauseModifier Modifier2, SourceLocation Modifier2Loc,
635 SourceLocation EndLoc, ArrayRef<Expr *> VL);
636
637 /// Returns the allocator expression or nullptr, if no allocator is specified.
638 Expr *getAllocator() const { return Allocator; }
639
640 /// Returns the alignment expression or nullptr, if no alignment specified.
641 Expr *getAlignment() const { return Alignment; }
642
643 /// Return 'allocate' modifier.
645 return AllocatorModifier;
646 }
647
648 /// Get the first modifier of the clause.
650 return Modifiers[FIRST];
651 }
652
653 /// Get location of first modifier of the clause.
655 return ModifiersLoc[FIRST];
656 }
657
658 /// Get the second modifier of the clause.
660 return Modifiers[SECOND];
661 }
662
663 /// Get location of second modifier of the clause.
665 return ModifiersLoc[SECOND];
666 }
667
668 /// Returns the location of the ':' delimiter.
669 SourceLocation getColonLoc() const { return ColonLoc; }
670 /// Return the location of the modifier.
672 return AllocatorModifierLoc;
673 }
674
675 /// Creates an empty clause with the place for \a N variables.
676 ///
677 /// \param C AST context.
678 /// \param N The number of variables.
679 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
680
682 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
683 reinterpret_cast<Stmt **>(varlist_end()));
684 }
685
687 return const_cast<OMPAllocateClause *>(this)->children();
688 }
689
696
697 static bool classof(const OMPClause *T) {
698 return T->getClauseKind() == llvm::omp::OMPC_allocate;
699 }
700};
701
702/// This represents 'if' clause in the '#pragma omp ...' directive.
703///
704/// \code
705/// #pragma omp parallel if(parallel:a > 5)
706/// \endcode
707/// In this example directive '#pragma omp parallel' has simple 'if' clause with
708/// condition 'a > 5' and directive name modifier 'parallel'.
710 friend class OMPClauseReader;
711
712 /// Location of '('.
713 SourceLocation LParenLoc;
714
715 /// Condition of the 'if' clause.
716 Stmt *Condition = nullptr;
717
718 /// Location of ':' (if any).
719 SourceLocation ColonLoc;
720
721 /// Directive name modifier for the clause.
722 OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
723
724 /// Name modifier location.
725 SourceLocation NameModifierLoc;
726
727 /// Set condition.
728 void setCondition(Expr *Cond) { Condition = Cond; }
729
730 /// Set directive name modifier for the clause.
731 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
732
733 /// Set location of directive name modifier for the clause.
734 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
735
736 /// Set location of ':'.
737 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
738
739public:
740 /// Build 'if' clause with condition \a Cond.
741 ///
742 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
743 /// \param Cond Condition of the clause.
744 /// \param HelperCond Helper condition for the clause.
745 /// \param CaptureRegion Innermost OpenMP region where expressions in this
746 /// clause must be captured.
747 /// \param StartLoc Starting location of the clause.
748 /// \param LParenLoc Location of '('.
749 /// \param NameModifierLoc Location of directive name modifier.
750 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
751 /// \param EndLoc Ending location of the clause.
752 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
753 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
754 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
755 SourceLocation ColonLoc, SourceLocation EndLoc)
756 : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
757 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
758 ColonLoc(ColonLoc), NameModifier(NameModifier),
759 NameModifierLoc(NameModifierLoc) {
760 setPreInitStmt(HelperCond, CaptureRegion);
761 }
762
763 /// Build an empty clause.
767
768 /// Sets the location of '('.
769 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
770
771 /// Returns the location of '('.
772 SourceLocation getLParenLoc() const { return LParenLoc; }
773
774 /// Return the location of ':'.
775 SourceLocation getColonLoc() const { return ColonLoc; }
776
777 /// Returns condition.
778 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
779
780 /// Return directive name modifier associated with the clause.
781 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
782
783 /// Return the location of directive name modifier.
784 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
785
786 child_range children() { return child_range(&Condition, &Condition + 1); }
787
789 return const_child_range(&Condition, &Condition + 1);
790 }
791
794 return const_cast<OMPIfClause *>(this)->used_children();
795 }
796
797 static bool classof(const OMPClause *T) {
798 return T->getClauseKind() == llvm::omp::OMPC_if;
799 }
800};
801
802/// This represents 'final' clause in the '#pragma omp ...' directive.
803///
804/// \code
805/// #pragma omp task final(a > 5)
806/// \endcode
807/// In this example directive '#pragma omp task' has simple 'final'
808/// clause with condition 'a > 5'.
809class OMPFinalClause final
810 : public OMPOneStmtClause<llvm::omp::OMPC_final, OMPClause>,
811 public OMPClauseWithPreInit {
812 friend class OMPClauseReader;
813
814 /// Set condition.
815 void setCondition(Expr *Cond) { setStmt(Cond); }
816
817public:
818 /// Build 'final' clause with condition \a Cond.
819 ///
820 /// \param Cond Condition of the clause.
821 /// \param HelperCond Helper condition for the construct.
822 /// \param CaptureRegion Innermost OpenMP region where expressions in this
823 /// clause must be captured.
824 /// \param StartLoc Starting location of the clause.
825 /// \param LParenLoc Location of '('.
826 /// \param EndLoc Ending location of the clause.
827 OMPFinalClause(Expr *Cond, Stmt *HelperCond,
828 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
829 SourceLocation LParenLoc, SourceLocation EndLoc)
830 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
832 setPreInitStmt(HelperCond, CaptureRegion);
833 }
834
835 /// Build an empty clause.
837
838 /// Returns condition.
839 Expr *getCondition() const { return getStmtAs<Expr>(); }
840
843 return const_cast<OMPFinalClause *>(this)->used_children();
844 }
845};
846
847/// This represents 'num_threads' clause in the '#pragma omp ...'
848/// directive.
849///
850/// \code
851/// #pragma omp parallel num_threads(n)
852/// \endcode
853/// In this example directive '#pragma omp parallel' has 'num_threads' clause
854/// requesting 'n' threads.
855///
856/// \code
857/// #pragma omp parallel num_threads(strict: n)
858/// \endcode
859/// In this example directive '#pragma omp parallel' has 'num_threads' clause
860/// requesting 'n' threads strictly with the 'strict' modifier.
861///
862/// \code
863/// #pragma omp parallel num_threads(dims(2): x, y)
864/// \endcode
865/// In this example directive '#pragma omp parallel' has clause 'num_threads'
866/// with the 'dims' modifier specifying two dimensions. The list specifies the
867/// number of threads in each dimension.
868class OMPNumThreadsClause final
869 : public OMPVarListClause<OMPNumThreadsClause>,
871 private llvm::TrailingObjects<OMPNumThreadsClause, Expr *> {
872 friend class OMPVarListClause<OMPNumThreadsClause>;
873 friend TrailingObjects;
874 friend class OMPClauseReader;
875
876private:
877 /// Categories of modifiers for the 'num_threads' clause.
878 enum { PRESCRIPTIVENESS, DIMS, NUM_MODIFIERS };
879
880 /// Modifiers for the clause, indexed by category.
881 OpenMPNumThreadsClauseModifier Modifiers[NUM_MODIFIERS] = {
883
884 /// Locations of the modifiers, indexed by category.
885 SourceLocation ModifiersLoc[NUM_MODIFIERS];
886
887 /// Build clause with number of expressions \a N.
888 ///
889 /// \param C AST context.
890 /// \param StartLoc Starting location of the clause.
891 /// \param LParenLoc Location of '('.
892 /// \param EndLoc Ending location of the clause.
893 /// \param N Number of expressions.
894 OMPNumThreadsClause(const ASTContext &C, SourceLocation StartLoc,
895 SourceLocation LParenLoc, SourceLocation EndLoc,
896 unsigned N)
897 : OMPVarListClause<OMPNumThreadsClause>(llvm::omp::OMPC_num_threads,
898 StartLoc, LParenLoc, EndLoc, N),
899 OMPClauseWithPreInit(this) {}
900
901 /// Build an empty clause.
902 ///
903 /// \param N Number of expressions.
904 explicit OMPNumThreadsClause(unsigned N)
905 : OMPVarListClause<OMPNumThreadsClause>(
906 llvm::omp::OMPC_num_threads, SourceLocation(), SourceLocation(),
907 SourceLocation(), N),
908 OMPClauseWithPreInit(this) {}
909
910 /// Sets the dims modifier.
911 void setDimsModifier(OpenMPNumThreadsClauseModifier M) {
912 Modifiers[DIMS] = M;
913 }
914
915 /// Sets the prescriptiveness modifier.
916 void setPrescriptivenessModifier(OpenMPNumThreadsClauseModifier M) {
917 Modifiers[PRESCRIPTIVENESS] = M;
918 }
919
920 /// Sets the location of the prescriptiveness modifier.
921 void setPrescriptivenessModifierLoc(SourceLocation Loc) {
922 ModifiersLoc[PRESCRIPTIVENESS] = Loc;
923 }
924
925 /// Sets the location of the dims modifier.
926 void setDimsModifierLoc(SourceLocation Loc) { ModifiersLoc[DIMS] = Loc; }
927
928 /// Sets the dims modifier expression.
929 void setDimsModifierExpr(Expr *E) { *varlist_end() = E; }
930
931public:
932 /// Creates clause with a list of variables/expressions.
933 ///
934 /// \param C AST context.
935 /// \param CaptureRegion The captured region for the pre-init statements.
936 /// \param StartLoc Starting location of the clause.
937 /// \param LParenLoc Location of '('.
938 /// \param EndLoc Ending location of the clause.
939 /// \param VL List of references to the expressions.
940 /// \param PrescriptivenessModifier The prescriptiveness modifier.
941 /// \param DimsModifier The dims modifier.
942 /// \param PrescriptivenessModifierLoc Location of the prescriptiveness
943 /// modifier.
944 /// \param DimsModifierLoc Location of the dims modifier.
945 /// \param DimsModifierExpr The expression of the number of dimensions.
946 /// \param PreInit
947 static OMPNumThreadsClause *
948 Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
949 SourceLocation StartLoc, SourceLocation LParenLoc,
950 SourceLocation EndLoc, ArrayRef<Expr *> VL,
951 OpenMPNumThreadsClauseModifier PrescriptivenessModifier,
953 SourceLocation PrescriptivenessModifierLoc,
954 SourceLocation DimsModifierLoc, Expr *DimsModifierExpr, Stmt *PreInit);
955
956 /// Creates an empty clause with the place for \a N expressions.
957 ///
958 /// \param C AST context.
959 /// \param N The number of expressions.
960 static OMPNumThreadsClause *CreateEmpty(const ASTContext &C, unsigned N);
961
962 /// Return NumThreads expressions.
965 return const_cast<OMPNumThreadsClause *>(this)->getNumThreads();
966 }
967
968 /// Returns the prescriptiveness modifier.
970 return Modifiers[PRESCRIPTIVENESS];
971 }
972 /// Returns the location of the prescriptiveness modifier.
974 return ModifiersLoc[PRESCRIPTIVENESS];
975 }
976
977 /// Returns the dims modifier.
979 return Modifiers[DIMS];
980 }
981 /// Returns the location of the dims modifier.
982 SourceLocation getDimsModifierLoc() const { return ModifiersLoc[DIMS]; }
983
984 /// Checks if the clause has the dims modifier.
985 bool hasDimsModifier() const {
986 return Modifiers[DIMS] == OMPC_NUMTHREADS_dims;
987 }
988
989 /// Returns the dims modifier expression if present.
991 return hasDimsModifier() ? *varlist_end() : nullptr;
992 }
993 /// Returns the dims modifier expression if present.
994 const Expr *getDimsModifierExpr() const {
995 return const_cast<OMPNumThreadsClause *>(this)->getDimsModifierExpr();
996 }
997
999 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1000 reinterpret_cast<Stmt **>(varlist_end()) + 1);
1001 }
1003 return const_cast<OMPNumThreadsClause *>(this)->children();
1004 }
1005
1012
1013 static bool classof(const OMPClause *T) {
1014 return T->getClauseKind() == llvm::omp::OMPC_num_threads;
1015 }
1016};
1017
1018/// This represents 'safelen' clause in the '#pragma omp ...'
1019/// directive.
1020///
1021/// \code
1022/// #pragma omp simd safelen(4)
1023/// \endcode
1024/// In this example directive '#pragma omp simd' has clause 'safelen'
1025/// with single expression '4'.
1026/// If the safelen clause is used then no two iterations executed
1027/// concurrently with SIMD instructions can have a greater distance
1028/// in the logical iteration space than its value. The parameter of
1029/// the safelen clause must be a constant positive integer expression.
1031 : public OMPOneStmtClause<llvm::omp::OMPC_safelen, OMPClause> {
1032 friend class OMPClauseReader;
1033
1034 /// Set safelen.
1035 void setSafelen(Expr *Len) { setStmt(Len); }
1036
1037public:
1038 /// Build 'safelen' clause.
1039 ///
1040 /// \param Len Expression associated with this clause.
1041 /// \param StartLoc Starting location of the clause.
1042 /// \param EndLoc Ending location of the clause.
1044 SourceLocation EndLoc)
1045 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
1046
1047 /// Build an empty clause.
1049
1050 /// Return safe iteration space distance.
1051 Expr *getSafelen() const { return getStmtAs<Expr>(); }
1052};
1053
1054/// This represents 'simdlen' clause in the '#pragma omp ...'
1055/// directive.
1056///
1057/// \code
1058/// #pragma omp simd simdlen(4)
1059/// \endcode
1060/// In this example directive '#pragma omp simd' has clause 'simdlen'
1061/// with single expression '4'.
1062/// If the 'simdlen' clause is used then it specifies the preferred number of
1063/// iterations to be executed concurrently. The parameter of the 'simdlen'
1064/// clause must be a constant positive integer expression.
1066 : public OMPOneStmtClause<llvm::omp::OMPC_simdlen, OMPClause> {
1067 friend class OMPClauseReader;
1068
1069 /// Set simdlen.
1070 void setSimdlen(Expr *Len) { setStmt(Len); }
1071
1072public:
1073 /// Build 'simdlen' clause.
1074 ///
1075 /// \param Len Expression associated with this clause.
1076 /// \param StartLoc Starting location of the clause.
1077 /// \param EndLoc Ending location of the clause.
1079 SourceLocation EndLoc)
1080 : OMPOneStmtClause(Len, StartLoc, LParenLoc, EndLoc) {}
1081
1082 /// Build an empty clause.
1084
1085 /// Return safe iteration space distance.
1086 Expr *getSimdlen() const { return getStmtAs<Expr>(); }
1087};
1088
1089/// This represents the 'sizes' clause in the '#pragma omp tile' directive.
1090///
1091/// \code
1092/// #pragma omp tile sizes(5,5)
1093/// for (int i = 0; i < 64; ++i)
1094/// for (int j = 0; j < 64; ++j)
1095/// \endcode
1096class OMPSizesClause final
1097 : public OMPClause,
1098 private llvm::TrailingObjects<OMPSizesClause, Expr *> {
1099 friend class OMPClauseReader;
1100 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
1101
1102 /// Location of '('.
1103 SourceLocation LParenLoc;
1104
1105 /// Number of tile sizes in the clause.
1106 unsigned NumSizes;
1107
1108 /// Build an empty clause.
1109 explicit OMPSizesClause(int NumSizes)
1110 : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()),
1111 NumSizes(NumSizes) {}
1112
1113public:
1114 /// Build a 'sizes' AST node.
1115 ///
1116 /// \param C Context of the AST.
1117 /// \param StartLoc Location of the 'sizes' identifier.
1118 /// \param LParenLoc Location of '('.
1119 /// \param EndLoc Location of ')'.
1120 /// \param Sizes Content of the clause.
1121 static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc,
1122 SourceLocation LParenLoc, SourceLocation EndLoc,
1123 ArrayRef<Expr *> Sizes);
1124
1125 /// Build an empty 'sizes' AST node for deserialization.
1126 ///
1127 /// \param C Context of the AST.
1128 /// \param NumSizes Number of items in the clause.
1129 static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes);
1130
1131 /// Sets the location of '('.
1132 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1133
1134 /// Returns the location of '('.
1135 SourceLocation getLParenLoc() const { return LParenLoc; }
1136
1137 /// Returns the number of list items.
1138 unsigned getNumSizes() const { return NumSizes; }
1139
1140 /// Returns the tile size expressions.
1142 return getTrailingObjects(NumSizes);
1143 }
1144 ArrayRef<Expr *> getSizesRefs() const { return getTrailingObjects(NumSizes); }
1145
1146 /// Sets the tile size expressions.
1148 assert(VL.size() == NumSizes);
1149 llvm::copy(VL, getSizesRefs().begin());
1150 }
1151
1154 return child_range(reinterpret_cast<Stmt **>(Sizes.begin()),
1155 reinterpret_cast<Stmt **>(Sizes.end()));
1156 }
1159 return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()),
1160 reinterpret_cast<Stmt *const *>(Sizes.end()));
1161 }
1162
1169
1170 static bool classof(const OMPClause *T) {
1171 return T->getClauseKind() == llvm::omp::OMPC_sizes;
1172 }
1173};
1174
1175/// This represents the 'counts' clause in the '#pragma omp split' directive.
1176///
1177/// \code
1178/// #pragma omp split counts(3, omp_fill, 2)
1179/// for (int i = 0; i < n; ++i) { ... }
1180/// \endcode
1181class OMPCountsClause final
1182 : public OMPClause,
1183 private llvm::TrailingObjects<OMPCountsClause, Expr *> {
1184 friend class OMPClauseReader;
1185 friend class llvm::TrailingObjects<OMPCountsClause, Expr *>;
1186
1187 /// Location of '('.
1188 SourceLocation LParenLoc;
1189
1190 /// Number of count expressions in the clause.
1191 unsigned NumCounts = 0;
1192
1193 /// 0-based index of the omp_fill list item.
1194 std::optional<unsigned> OmpFillIndex;
1195
1196 /// Source location of the omp_fill keyword.
1197 SourceLocation OmpFillLoc;
1198
1199 /// Build an empty clause.
1200 explicit OMPCountsClause(int NumCounts)
1201 : OMPClause(llvm::omp::OMPC_counts, SourceLocation(), SourceLocation()),
1202 NumCounts(NumCounts) {}
1203
1204 /// Sets the location of '('.
1205 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1206 void setOmpFillIndex(std::optional<unsigned> Idx) { OmpFillIndex = Idx; }
1207 void setOmpFillLoc(SourceLocation Loc) { OmpFillLoc = Loc; }
1208
1209 /// Sets the count expressions.
1210 void setCountsRefs(ArrayRef<Expr *> VL) {
1211 assert(VL.size() == NumCounts);
1212 llvm::copy(VL, getCountsRefs().begin());
1213 }
1214
1215public:
1216 /// Build a 'counts' AST node.
1217 ///
1218 /// \param C Context of the AST.
1219 /// \param StartLoc Location of the 'counts' identifier.
1220 /// \param LParenLoc Location of '('.
1221 /// \param EndLoc Location of ')'.
1222 /// \param Counts Content of the clause.
1223 static OMPCountsClause *Create(const ASTContext &C, SourceLocation StartLoc,
1224 SourceLocation LParenLoc,
1225 SourceLocation EndLoc, ArrayRef<Expr *> Counts,
1226 std::optional<unsigned> FillIdx,
1227 SourceLocation FillLoc);
1228
1229 /// Build an empty 'counts' AST node for deserialization.
1230 ///
1231 /// \param C Context of the AST.
1232 /// \param NumCounts Number of items in the clause.
1233 static OMPCountsClause *CreateEmpty(const ASTContext &C, unsigned NumCounts);
1234
1235 /// Returns the location of '('.
1236 SourceLocation getLParenLoc() const { return LParenLoc; }
1237
1238 /// Returns the number of list items.
1239 unsigned getNumCounts() const { return NumCounts; }
1240
1241 std::optional<unsigned> getOmpFillIndex() const { return OmpFillIndex; }
1242 SourceLocation getOmpFillLoc() const { return OmpFillLoc; }
1243 bool hasOmpFill() const { return OmpFillIndex.has_value(); }
1244
1245 /// Returns the count expressions.
1247 return getTrailingObjects(NumCounts);
1248 }
1250 return getTrailingObjects(NumCounts);
1251 }
1252
1255 return child_range(reinterpret_cast<Stmt **>(Counts.begin()),
1256 reinterpret_cast<Stmt **>(Counts.end()));
1257 }
1260 return const_child_range(reinterpret_cast<Stmt *const *>(Counts.begin()),
1261 reinterpret_cast<Stmt *const *>(Counts.end()));
1262 }
1269
1270 static bool classof(const OMPClause *T) {
1271 return T->getClauseKind() == llvm::omp::OMPC_counts;
1272 }
1273};
1274
1275/// This class represents the 'permutation' clause in the
1276/// '#pragma omp interchange' directive.
1277///
1278/// \code{.c}
1279/// #pragma omp interchange permutation(2,1)
1280/// for (int i = 0; i < 64; ++i)
1281/// for (int j = 0; j < 64; ++j)
1282/// \endcode
1283class OMPPermutationClause final
1284 : public OMPClause,
1285 private llvm::TrailingObjects<OMPSizesClause, Expr *> {
1286 friend class OMPClauseReader;
1287 friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
1288
1289 /// Location of '('.
1290 SourceLocation LParenLoc;
1291
1292 /// Number of arguments in the clause, and hence also the number of loops to
1293 /// be permuted.
1294 unsigned NumLoops;
1295
1296 /// Sets the permutation index expressions.
1297 void setArgRefs(ArrayRef<Expr *> VL) {
1298 assert(VL.size() == NumLoops && "Expecting one expression per loop");
1299 llvm::copy(VL, getTrailingObjects());
1300 }
1301
1302 /// Build an empty clause.
1303 explicit OMPPermutationClause(int NumLoops)
1304 : OMPClause(llvm::omp::OMPC_permutation, SourceLocation(),
1305 SourceLocation()),
1306 NumLoops(NumLoops) {}
1307
1308public:
1309 /// Build a 'permutation' clause AST node.
1310 ///
1311 /// \param C Context of the AST.
1312 /// \param StartLoc Location of the 'permutation' identifier.
1313 /// \param LParenLoc Location of '('.
1314 /// \param EndLoc Location of ')'.
1315 /// \param Args Content of the clause.
1316 static OMPPermutationClause *
1317 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1318 SourceLocation EndLoc, ArrayRef<Expr *> Args);
1319
1320 /// Build an empty 'permutation' AST node for deserialization.
1321 ///
1322 /// \param C Context of the AST.
1323 /// \param NumLoops Number of arguments in the clause.
1324 static OMPPermutationClause *CreateEmpty(const ASTContext &C,
1325 unsigned NumLoops);
1326
1327 /// Sets the location of '('.
1328 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1329
1330 /// Returns the location of '('.
1331 SourceLocation getLParenLoc() const { return LParenLoc; }
1332
1333 /// Returns the number of list items.
1334 unsigned getNumLoops() const { return NumLoops; }
1335
1336 /// Returns the permutation index expressions.
1337 ///@{
1338 MutableArrayRef<Expr *> getArgsRefs() { return getTrailingObjects(NumLoops); }
1339 ArrayRef<Expr *> getArgsRefs() const { return getTrailingObjects(NumLoops); }
1340 ///@}
1341
1344 return child_range(reinterpret_cast<Stmt **>(Args.begin()),
1345 reinterpret_cast<Stmt **>(Args.end()));
1346 }
1349 return const_child_range(reinterpret_cast<Stmt *const *>(Args.begin()),
1350 reinterpret_cast<Stmt *const *>(Args.end()));
1351 }
1352
1359
1360 static bool classof(const OMPClause *T) {
1361 return T->getClauseKind() == llvm::omp::OMPC_permutation;
1362 }
1363};
1364
1365/// Representation of the 'full' clause of the '#pragma omp unroll' directive.
1366///
1367/// \code
1368/// #pragma omp unroll full
1369/// for (int i = 0; i < 64; ++i)
1370/// \endcode
1371class OMPFullClause final : public OMPNoChildClause<llvm::omp::OMPC_full> {
1372public:
1373 /// Build an AST node for a 'full' clause.
1374 ///
1375 /// \param StartLoc Starting location of the clause.
1376 /// \param EndLoc Ending location of the clause.
1378 : OMPNoChildClause(StartLoc, EndLoc) {}
1379
1380 /// Build an empty clause.
1382};
1383
1384/// This class represents the 'looprange' clause in the
1385/// '#pragma omp fuse' directive
1386///
1387/// \code {c}
1388/// #pragma omp fuse looprange(1,2)
1389/// {
1390/// for(int i = 0; i < 64; ++i)
1391/// for(int j = 0; j < 256; j+=2)
1392/// for(int k = 127; k >= 0; --k)
1393/// \endcode
1394class OMPLoopRangeClause final : public OMPClause {
1395 friend class OMPClauseReader;
1396 /// Location of '('
1397 SourceLocation LParenLoc;
1398
1399 /// Location of first and count expressions
1400 SourceLocation FirstLoc, CountLoc;
1401
1402 /// Number of looprange arguments (always 2: first, count)
1403 enum { FirstExpr, CountExpr, NumArgs };
1404 Stmt *Args[NumArgs] = {nullptr, nullptr};
1405
1406 /// Set looprange 'first' expression
1407 void setFirst(Expr *E) { Args[FirstExpr] = E; }
1408
1409 /// Set looprange 'count' expression
1410 void setCount(Expr *E) { Args[CountExpr] = E; }
1411
1412public:
1413 /// Build a 'looprange' clause.
1415 SourceLocation FirstLoc, SourceLocation CountLoc,
1416 SourceLocation EndLoc, Expr *First, Expr *Count)
1417 : OMPClause(llvm::omp::OMPC_looprange, StartLoc, EndLoc),
1418 LParenLoc(LParenLoc), FirstLoc(FirstLoc), CountLoc(CountLoc) {
1419 setFirst(First);
1420 setCount(Count);
1421 }
1422
1423 /// Build an empty clause for deserialization.
1425 : OMPClause(llvm::omp::OMPC_looprange, {}, {}) {}
1426
1427 // Location getters/setters
1428 SourceLocation getLParenLoc() const { return LParenLoc; }
1429 SourceLocation getFirstLoc() const { return FirstLoc; }
1430 SourceLocation getCountLoc() const { return CountLoc; }
1431
1432 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1433 void setFirstLoc(SourceLocation Loc) { FirstLoc = Loc; }
1434 void setCountLoc(SourceLocation Loc) { CountLoc = Loc; }
1435
1436 /// Get looprange 'first' expression
1437 Expr *getFirst() const { return cast_or_null<Expr>(Args[FirstExpr]); }
1438
1439 /// Get looprange 'count' expression
1440 Expr *getCount() const { return cast_or_null<Expr>(Args[CountExpr]); }
1441
1442 child_range children() { return child_range(Args, Args + NumArgs); }
1444 return const_child_range(Args, Args + NumArgs);
1445 }
1446
1453
1454 static bool classof(const OMPClause *T) {
1455 return T->getClauseKind() == llvm::omp::OMPC_looprange;
1456 }
1457};
1458
1459/// Representation of the 'partial' clause of the '#pragma omp unroll'
1460/// directive.
1461///
1462/// \code
1463/// #pragma omp unroll partial(4)
1464/// for (int i = start; i < end; ++i)
1465/// \endcode
1466class OMPPartialClause final : public OMPClause {
1467 friend class OMPClauseReader;
1468
1469 /// Location of '('.
1470 SourceLocation LParenLoc;
1471
1472 /// Optional argument to the clause (unroll factor).
1473 Stmt *Factor = nullptr;
1474
1475 /// Set the unroll factor.
1476 void setFactor(Expr *E) { Factor = E; }
1477
1478 /// Sets the location of '('.
1479 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1480
1481public:
1482 /// Build an AST node for a 'partial' clause.
1483 ///
1484 /// \param StartLoc Location of the 'partial' identifier.
1485 /// \param LParenLoc Location of '('.
1486 /// \param EndLoc Location of ')'.
1487 /// \param Factor Clause argument.
1489 SourceLocation EndLoc, Expr *Factor)
1490 : OMPClause(llvm::omp::OMPC_partial, StartLoc, EndLoc),
1491 LParenLoc(LParenLoc), Factor(Factor) {}
1492
1493 /// Build an empty clause.
1494 explicit OMPPartialClause() : OMPClause(llvm::omp::OMPC_partial, {}, {}) {}
1495
1496 /// Returns the location of '('.
1497 SourceLocation getLParenLoc() const { return LParenLoc; }
1498
1499 /// Returns the argument of the clause or nullptr if not set.
1500 Expr *getFactor() const { return cast_or_null<Expr>(Factor); }
1501
1502 child_range children() { return child_range(&Factor, &Factor + 1); }
1504 return const_child_range(&Factor, &Factor + 1);
1505 }
1506
1513
1514 static bool classof(const OMPClause *T) {
1515 return T->getClauseKind() == llvm::omp::OMPC_partial;
1516 }
1517};
1518
1519/// This represents the 'depth' clause on the '#pragma omp flatten' (and
1520/// '#pragma omp fuse') loop-transformation directives.
1521///
1522/// \code
1523/// #pragma omp flatten depth(3)
1524/// \endcode
1525/// In this example the 'flatten' directive has a 'depth' clause whose argument
1526/// '3' specifies how many perfectly nested loops are combined into one.
1527/// The argument must be a positive integer constant expression that evaluates
1528/// to at most the loop nest depth of the associated loop nest.
1529class OMPDepthClause final : public OMPClause {
1530 friend class OMPClauseReader;
1531
1532 /// Location of '('.
1533 SourceLocation LParenLoc;
1534
1535 /// The depth expression (e.g. number of loops to flatten or nest-levels to
1536 /// fuse).
1537 Stmt *Depth = nullptr;
1538
1539 /// Build an empty clause.
1540 explicit OMPDepthClause() : OMPClause(llvm::omp::OMPC_depth, {}, {}) {}
1541
1542 /// Set the depth expression.
1543 void setDepth(Expr *E) { Depth = E; }
1544
1545 /// Sets the location of '('.
1546 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1547
1548public:
1549 /// Build an AST node for a 'depth' clause.
1550 ///
1551 /// \param StartLoc Location of the 'depth' identifier.
1552 /// \param LParenLoc Location of '('.
1553 /// \param EndLoc Location of ')'.
1554 /// \param Depth The depth expression.
1556 SourceLocation EndLoc, Expr *Depth)
1557 : OMPClause(llvm::omp::OMPC_depth, StartLoc, EndLoc),
1558 LParenLoc(LParenLoc), Depth(Depth) {}
1559
1560 /// Returns the location of '('.
1561 SourceLocation getLParenLoc() const { return LParenLoc; }
1562
1563 /// Returns the depth expression or nullptr if not set.
1564 Expr *getDepth() const { return cast_or_null<Expr>(Depth); }
1565
1566 child_range children() { return child_range(&Depth, &Depth + 1); }
1568 return const_child_range(&Depth, &Depth + 1);
1569 }
1570
1577
1578 static bool classof(const OMPClause *T) {
1579 return T->getClauseKind() == llvm::omp::OMPC_depth;
1580 }
1581};
1582
1583/// This represents 'collapse' clause in the '#pragma omp ...'
1584/// directive.
1585///
1586/// \code
1587/// #pragma omp simd collapse(3)
1588/// \endcode
1589/// In this example directive '#pragma omp simd' has clause 'collapse'
1590/// with single expression '3'.
1591/// The parameter must be a constant positive integer expression, it specifies
1592/// the number of nested loops that should be collapsed into a single iteration
1593/// space.
1595 : public OMPOneStmtClause<llvm::omp::OMPC_collapse, OMPClause> {
1596 friend class OMPClauseReader;
1597
1598 /// Set the number of associated for-loops.
1599 void setNumForLoops(Expr *Num) { setStmt(Num); }
1600
1601public:
1602 /// Build 'collapse' clause.
1603 ///
1604 /// \param Num Expression associated with this clause.
1605 /// \param StartLoc Starting location of the clause.
1606 /// \param LParenLoc Location of '('.
1607 /// \param EndLoc Ending location of the clause.
1609 SourceLocation LParenLoc, SourceLocation EndLoc)
1610 : OMPOneStmtClause(Num, StartLoc, LParenLoc, EndLoc) {}
1611
1612 /// Build an empty clause.
1614
1615 /// Return the number of associated for-loops.
1616 Expr *getNumForLoops() const { return getStmtAs<Expr>(); }
1617};
1618
1619/// This represents 'default' clause in the '#pragma omp ...' directive.
1620///
1621/// \code
1622/// #pragma omp parallel default(shared)
1623/// \endcode
1624/// In this example directive '#pragma omp parallel' has simple 'default'
1625/// clause with kind 'shared'.
1627 friend class OMPClauseReader;
1628
1629 /// Location of '('.
1630 SourceLocation LParenLoc;
1631
1632 /// A kind of the 'default' clause.
1633 llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
1634
1635 /// Start location of the kind in source code.
1636 SourceLocation KindKwLoc;
1637
1638 /// Variable-Category to indicate where Kind is applied
1639 OpenMPDefaultClauseVariableCategory VC = OMPC_DEFAULT_VC_all;
1640
1641 /// Start location of Variable-Category
1642 SourceLocation VCLoc;
1643
1644 /// Set kind of the clauses.
1645 ///
1646 /// \param K Argument of clause.
1647 void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
1648
1649 /// Set argument location.
1650 ///
1651 /// \param KLoc Argument location.
1652 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1653
1654 /// Set Variable Category used with the Kind Clause (Default Modifier)
1655 void setDefaultVariableCategory(OpenMPDefaultClauseVariableCategory VC) {
1656 this->VC = VC;
1657 }
1658
1659 void setDefaultVariableCategoryLocation(SourceLocation VCLoc) {
1660 this->VCLoc = VCLoc;
1661 }
1662
1663public:
1664 /// Build 'default' clause with argument \a A ('none' or 'shared').
1665 ///
1666 /// \param A Argument of the clause ('none' or 'shared').
1667 /// \param ALoc Starting location of the argument.
1668 /// \param StartLoc Starting location of the clause.
1669 /// \param LParenLoc Location of '('.
1670 /// \param EndLoc Ending location of the clause.
1671 OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
1673 SourceLocation StartLoc, SourceLocation LParenLoc,
1674 SourceLocation EndLoc)
1675 : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
1676 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), VC(VC), VCLoc(VCLoc) {}
1677
1678 /// Build an empty clause.
1680 : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
1681 }
1682
1683 /// Sets the location of '('.
1684 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1685
1686 /// Returns the location of '('.
1687 SourceLocation getLParenLoc() const { return LParenLoc; }
1688
1689 /// Returns kind of the clause.
1690 llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
1691
1692 /// Returns location of clause kind.
1693 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
1694
1696
1697 SourceLocation getDefaultVCLoc() const { return VCLoc; }
1698
1702
1706
1713
1714 static bool classof(const OMPClause *T) {
1715 return T->getClauseKind() == llvm::omp::OMPC_default;
1716 }
1717};
1718
1719/// This represents 'threadset' clause in the '#pragma omp task ...' directive.
1720///
1721/// \code
1722/// #pragma omp task threadset(omp_pool)
1723/// \endcode
1724/// In this example directive '#pragma omp task' has simple 'threadset'
1725/// clause with kind 'omp_pool'.
1726class OMPThreadsetClause final : public OMPClause {
1727 friend class OMPClauseReader;
1728
1729 /// Location of '('.
1730 SourceLocation LParenLoc;
1731
1732 /// A kind of the 'threadset' clause.
1734
1735 /// Start location of the kind in source code.
1736 SourceLocation KindLoc;
1737
1738 /// Set kind of the clauses.
1739 ///
1740 /// \param K Argument of clause.
1741 void setThreadsetKind(OpenMPThreadsetKind K) { Kind = K; }
1742
1743 /// Set argument location.
1744 ///
1745 /// \param KLoc Argument location.
1746 void setThreadsetKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1747
1748public:
1749 /// Build 'threadset' clause with argument \a A ('omp_team' or 'omp_pool').
1750 ///
1751 /// \param A Argument of the clause ('omp_team' or 'omp_pool').
1752 /// \param ALoc Starting location of the argument.
1753 /// \param StartLoc Starting location of the clause.
1754 /// \param LParenLoc Location of '('.
1755 /// \param EndLoc Ending location of the clause.
1757 SourceLocation StartLoc, SourceLocation LParenLoc,
1758 SourceLocation EndLoc)
1759 : OMPClause(llvm::omp::OMPC_threadset, StartLoc, EndLoc),
1760 LParenLoc(LParenLoc), Kind(A), KindLoc(ALoc) {}
1761
1762 /// Build an empty clause.
1764 : OMPClause(llvm::omp::OMPC_threadset, SourceLocation(),
1765 SourceLocation()) {}
1766
1767 /// Sets the location of '('.
1768 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1769
1770 /// Returns the location of '('.
1771 SourceLocation getLParenLoc() const { return LParenLoc; }
1772
1773 /// Returns kind of the clause.
1774 OpenMPThreadsetKind getThreadsetKind() const { return Kind; }
1775
1776 /// Returns location of clause kind.
1777 SourceLocation getThreadsetKindLoc() const { return KindLoc; }
1778
1782
1786
1793
1794 static bool classof(const OMPClause *T) {
1795 return T->getClauseKind() == llvm::omp::OMPC_threadset;
1796 }
1797};
1798
1799/// This class represents the 'transparent' clause in the '#pragma omp task'
1800/// directive.
1801///
1802/// \code
1803/// #pragma omp task transparent(omp_not_impex)
1804/// \endcode
1805///
1806/// In this example, the directive '#pragma omp task' has a 'transparent'
1807/// clause with OpenMP keyword 'omp_not_impex`. Other valid keywords that may
1808/// appear in this clause are 'omp_import', 'omp_export' and 'omp_impex'.
1809///
1810class OMPTransparentClause final
1811 : public OMPOneStmtClause<llvm::omp::OMPC_transparent, OMPClause>,
1812 public OMPClauseWithPreInit {
1813 friend class OMPClauseReader;
1814
1815 /// Location of '('.
1816 SourceLocation LParenLoc;
1817
1818 /// Argument of the 'transparent' clause.
1819 Expr *ImpexType = nullptr;
1820
1821 /// Sets the location of '('.
1822 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1823
1824 void setImpexTypeKind(Expr *E) { ImpexType = E; }
1825
1826public:
1827 /// Build 'transparent' clause with argument \a A ('omp_not_impex',
1828 /// 'omp_import', 'omp_export' or 'omp_impex')
1829 ///
1830 /// \param A Argument of the clause ('omp_not_impex', 'omp_import',
1831 /// 'omp_export' or 'omp_impex')
1832 /// \param ALoc Starting location of the argument.
1833 /// \param StartLoc Starting location of the clause.
1834 /// \param LParenLoc Location of '('.
1835 /// \param EndLoc Ending location of the clause.
1836 OMPTransparentClause(Expr *ImpexTypeKind, Stmt *HelperValStmt,
1837 OpenMPDirectiveKind CaptureRegion,
1838 SourceLocation StartLoc, SourceLocation LParenLoc,
1839 SourceLocation EndLoc)
1840 : OMPOneStmtClause(ImpexTypeKind, StartLoc, LParenLoc, EndLoc),
1841 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
1842 ImpexType(ImpexTypeKind) {
1843 setPreInitStmt(HelperValStmt, CaptureRegion);
1844 }
1845
1846 /// Build an empty clause.
1847 OMPTransparentClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
1848
1849 /// Returns the location of '('.
1850 SourceLocation getLParenLoc() const { return LParenLoc; }
1851
1852 /// Returns argument of the clause.
1853 Expr *getImpexType() const { return ImpexType; }
1854
1855 child_range children() {
1856 return child_range(reinterpret_cast<Stmt **>(&ImpexType),
1857 reinterpret_cast<Stmt **>(&ImpexType) + 1);
1858 }
1859
1860 const_child_range children() const {
1861 return const_cast<OMPTransparentClause *>(this)->children();
1862 }
1863
1864 child_range used_children() {
1865 return child_range(child_iterator(), child_iterator());
1866 }
1867 const_child_range used_children() const {
1868 return const_child_range(const_child_iterator(), const_child_iterator());
1869 }
1870
1871 static bool classof(const OMPClause *T) {
1872 return T->getClauseKind() == llvm::omp::OMPC_transparent;
1873 }
1874};
1875
1876/// This represents 'proc_bind' clause in the '#pragma omp ...'
1877/// directive.
1878///
1879/// \code
1880/// #pragma omp parallel proc_bind(master)
1881/// \endcode
1882/// In this example directive '#pragma omp parallel' has simple 'proc_bind'
1883/// clause with kind 'master'.
1884class OMPProcBindClause : public OMPClause {
1885 friend class OMPClauseReader;
1886
1887 /// Location of '('.
1888 SourceLocation LParenLoc;
1889
1890 /// A kind of the 'proc_bind' clause.
1891 llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
1892
1893 /// Start location of the kind in source code.
1894 SourceLocation KindKwLoc;
1895
1896 /// Set kind of the clause.
1897 ///
1898 /// \param K Kind of clause.
1899 void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
1900
1901 /// Set clause kind location.
1902 ///
1903 /// \param KLoc Kind location.
1904 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1905
1906public:
1907 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
1908 /// 'spread').
1909 ///
1910 /// \param A Argument of the clause ('master', 'close' or 'spread').
1911 /// \param ALoc Starting location of the argument.
1912 /// \param StartLoc Starting location of the clause.
1913 /// \param LParenLoc Location of '('.
1914 /// \param EndLoc Ending location of the clause.
1915 OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
1916 SourceLocation StartLoc, SourceLocation LParenLoc,
1917 SourceLocation EndLoc)
1918 : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
1919 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1920
1921 /// Build an empty clause.
1922 OMPProcBindClause()
1923 : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
1924 SourceLocation()) {}
1925
1926 /// Sets the location of '('.
1927 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1928
1929 /// Returns the location of '('.
1930 SourceLocation getLParenLoc() const { return LParenLoc; }
1931
1932 /// Returns kind of the clause.
1933 llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
1934
1935 /// Returns location of clause kind.
1936 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
1937
1938 child_range children() {
1939 return child_range(child_iterator(), child_iterator());
1940 }
1941
1942 const_child_range children() const {
1943 return const_child_range(const_child_iterator(), const_child_iterator());
1944 }
1945
1946 child_range used_children() {
1947 return child_range(child_iterator(), child_iterator());
1948 }
1949 const_child_range used_children() const {
1950 return const_child_range(const_child_iterator(), const_child_iterator());
1951 }
1952
1953 static bool classof(const OMPClause *T) {
1954 return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
1955 }
1956};
1957
1958/// This represents 'unified_address' clause in the '#pragma omp requires'
1959/// directive.
1960///
1961/// \code
1962/// #pragma omp requires unified_address
1963/// \endcode
1964/// In this example directive '#pragma omp requires' has 'unified_address'
1965/// clause.
1966class OMPUnifiedAddressClause final
1967 : public OMPNoChildClause<llvm::omp::OMPC_unified_address> {
1968public:
1969 friend class OMPClauseReader;
1970 /// Build 'unified_address' clause.
1971 ///
1972 /// \param StartLoc Starting location of the clause.
1973 /// \param EndLoc Ending location of the clause.
1974 OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
1975 : OMPNoChildClause(StartLoc, EndLoc) {}
1976
1977 /// Build an empty clause.
1978 OMPUnifiedAddressClause() : OMPNoChildClause() {}
1979};
1980
1981/// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1982/// directive.
1983///
1984/// \code
1985/// #pragma omp requires unified_shared_memory
1986/// \endcode
1987/// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1988/// clause.
1989class OMPUnifiedSharedMemoryClause final : public OMPClause {
1990public:
1991 friend class OMPClauseReader;
1992 /// Build 'unified_shared_memory' clause.
1993 ///
1994 /// \param StartLoc Starting location of the clause.
1995 /// \param EndLoc Ending location of the clause.
1996 OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
1997 : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1998
1999 /// Build an empty clause.
2000 OMPUnifiedSharedMemoryClause()
2001 : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
2002 SourceLocation()) {}
2003
2004 child_range children() {
2005 return child_range(child_iterator(), child_iterator());
2006 }
2007
2008 const_child_range children() const {
2009 return const_child_range(const_child_iterator(), const_child_iterator());
2010 }
2011
2012 child_range used_children() {
2013 return child_range(child_iterator(), child_iterator());
2014 }
2015 const_child_range used_children() const {
2016 return const_child_range(const_child_iterator(), const_child_iterator());
2017 }
2018
2019 static bool classof(const OMPClause *T) {
2020 return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
2021 }
2022};
2023
2024/// This represents 'reverse_offload' clause in the '#pragma omp requires'
2025/// directive.
2026///
2027/// \code
2028/// #pragma omp requires reverse_offload
2029/// \endcode
2030/// In this example directive '#pragma omp requires' has 'reverse_offload'
2031/// clause.
2032class OMPReverseOffloadClause final : public OMPClause {
2033public:
2034 friend class OMPClauseReader;
2035 /// Build 'reverse_offload' clause.
2036 ///
2037 /// \param StartLoc Starting location of the clause.
2038 /// \param EndLoc Ending location of the clause.
2039 OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
2040 : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
2041
2042 /// Build an empty clause.
2043 OMPReverseOffloadClause()
2044 : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
2045 SourceLocation()) {}
2046
2047 child_range children() {
2048 return child_range(child_iterator(), child_iterator());
2049 }
2050
2051 const_child_range children() const {
2052 return const_child_range(const_child_iterator(), const_child_iterator());
2053 }
2054
2055 child_range used_children() {
2056 return child_range(child_iterator(), child_iterator());
2057 }
2058 const_child_range used_children() const {
2059 return const_child_range(const_child_iterator(), const_child_iterator());
2060 }
2061
2062 static bool classof(const OMPClause *T) {
2063 return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
2064 }
2065};
2066
2067/// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
2068/// directive.
2069///
2070/// \code
2071/// #pragma omp requires dynamic_allocators
2072/// \endcode
2073/// In this example directive '#pragma omp requires' has 'dynamic_allocators'
2074/// clause.
2075class OMPDynamicAllocatorsClause final : public OMPClause {
2076public:
2077 friend class OMPClauseReader;
2078 /// Build 'dynamic_allocators' clause.
2079 ///
2080 /// \param StartLoc Starting location of the clause.
2081 /// \param EndLoc Ending location of the clause.
2082 OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
2083 : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
2084
2085 /// Build an empty clause.
2086 OMPDynamicAllocatorsClause()
2087 : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
2088 SourceLocation()) {}
2089
2090 child_range children() {
2091 return child_range(child_iterator(), child_iterator());
2092 }
2093
2094 const_child_range children() const {
2095 return const_child_range(const_child_iterator(), const_child_iterator());
2096 }
2097
2098 child_range used_children() {
2099 return child_range(child_iterator(), child_iterator());
2100 }
2101 const_child_range used_children() const {
2102 return const_child_range(const_child_iterator(), const_child_iterator());
2103 }
2104
2105 static bool classof(const OMPClause *T) {
2106 return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
2107 }
2108};
2109
2110/// This represents 'atomic_default_mem_order' clause in the '#pragma omp
2111/// requires' directive.
2112///
2113/// \code
2114/// #pragma omp requires atomic_default_mem_order(seq_cst)
2115/// \endcode
2116/// In this example directive '#pragma omp requires' has simple
2117/// atomic_default_mem_order' clause with kind 'seq_cst'.
2118class OMPAtomicDefaultMemOrderClause final : public OMPClause {
2119 friend class OMPClauseReader;
2120
2121 /// Location of '('
2122 SourceLocation LParenLoc;
2123
2124 /// A kind of the 'atomic_default_mem_order' clause.
2127
2128 /// Start location of the kind in source code.
2129 SourceLocation KindKwLoc;
2130
2131 /// Set kind of the clause.
2132 ///
2133 /// \param K Kind of clause.
2134 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
2135 Kind = K;
2136 }
2137
2138 /// Set clause kind location.
2139 ///
2140 /// \param KLoc Kind location.
2141 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
2142 KindKwLoc = KLoc;
2143 }
2144
2145public:
2146 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
2147 /// 'acq_rel' or 'relaxed').
2148 ///
2149 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
2150 /// \param ALoc Starting location of the argument.
2151 /// \param StartLoc Starting location of the clause.
2152 /// \param LParenLoc Location of '('.
2153 /// \param EndLoc Ending location of the clause.
2154 OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
2155 SourceLocation ALoc, SourceLocation StartLoc,
2156 SourceLocation LParenLoc,
2157 SourceLocation EndLoc)
2158 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
2159 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
2160
2161 /// Build an empty clause.
2162 OMPAtomicDefaultMemOrderClause()
2163 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
2164 SourceLocation()) {}
2165
2166 /// Sets the location of '('.
2167 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2168
2169 /// Returns the locaiton of '('.
2170 SourceLocation getLParenLoc() const { return LParenLoc; }
2171
2172 /// Returns kind of the clause.
2173 OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
2174 return Kind;
2175 }
2176
2177 /// Returns location of clause kind.
2178 SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
2179
2180 child_range children() {
2181 return child_range(child_iterator(), child_iterator());
2182 }
2183
2184 const_child_range children() const {
2185 return const_child_range(const_child_iterator(), const_child_iterator());
2186 }
2187
2188 child_range used_children() {
2189 return child_range(child_iterator(), child_iterator());
2190 }
2191 const_child_range used_children() const {
2192 return const_child_range(const_child_iterator(), const_child_iterator());
2193 }
2194
2195 static bool classof(const OMPClause *T) {
2196 return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
2197 }
2198};
2199
2200/// This represents 'self_maps' clause in the '#pragma omp requires'
2201/// directive.
2202///
2203/// \code
2204/// #pragma omp requires self_maps
2205/// \endcode
2206/// In this example directive '#pragma omp requires' has 'self_maps'
2207/// clause.
2208class OMPSelfMapsClause final : public OMPClause {
2209public:
2210 friend class OMPClauseReader;
2211 /// Build 'self_maps' clause.
2212 ///
2213 /// \param StartLoc Starting location of the clause.
2214 /// \param EndLoc Ending location of the clause.
2215 OMPSelfMapsClause(SourceLocation StartLoc, SourceLocation EndLoc)
2216 : OMPClause(llvm::omp::OMPC_self_maps, StartLoc, EndLoc) {}
2217
2218 /// Build an empty clause.
2219 OMPSelfMapsClause()
2220 : OMPClause(llvm::omp::OMPC_self_maps, SourceLocation(),
2221 SourceLocation()) {}
2222
2223 child_range children() {
2224 return child_range(child_iterator(), child_iterator());
2225 }
2226
2227 const_child_range children() const {
2228 return const_child_range(const_child_iterator(), const_child_iterator());
2229 }
2230
2231 child_range used_children() {
2232 return child_range(child_iterator(), child_iterator());
2233 }
2234 const_child_range used_children() const {
2235 return const_child_range(const_child_iterator(), const_child_iterator());
2236 }
2237
2238 static bool classof(const OMPClause *T) {
2239 return T->getClauseKind() == llvm::omp::OMPC_self_maps;
2240 }
2241};
2242
2243/// This represents 'at' clause in the '#pragma omp error' directive
2244///
2245/// \code
2246/// #pragma omp error at(compilation)
2247/// \endcode
2248/// In this example directive '#pragma omp error' has simple
2249/// 'at' clause with kind 'complilation'.
2250class OMPAtClause final : public OMPClause {
2251 friend class OMPClauseReader;
2252
2253 /// Location of '('
2254 SourceLocation LParenLoc;
2255
2256 /// A kind of the 'at' clause.
2258
2259 /// Start location of the kind in source code.
2260 SourceLocation KindKwLoc;
2261
2262 /// Set kind of the clause.
2263 ///
2264 /// \param K Kind of clause.
2265 void setAtKind(OpenMPAtClauseKind K) { Kind = K; }
2266
2267 /// Set clause kind location.
2268 ///
2269 /// \param KLoc Kind location.
2270 void setAtKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
2271
2272 /// Sets the location of '('.
2273 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2274
2275public:
2276 /// Build 'at' clause with argument \a A ('compilation' or 'execution').
2277 ///
2278 /// \param A Argument of the clause ('compilation' or 'execution').
2279 /// \param ALoc Starting location of the argument.
2280 /// \param StartLoc Starting location of the clause.
2281 /// \param LParenLoc Location of '('.
2282 /// \param EndLoc Ending location of the clause.
2283 OMPAtClause(OpenMPAtClauseKind A, SourceLocation ALoc,
2284 SourceLocation StartLoc, SourceLocation LParenLoc,
2285 SourceLocation EndLoc)
2286 : OMPClause(llvm::omp::OMPC_at, StartLoc, EndLoc), LParenLoc(LParenLoc),
2287 Kind(A), KindKwLoc(ALoc) {}
2288
2289 /// Build an empty clause.
2290 OMPAtClause()
2291 : OMPClause(llvm::omp::OMPC_at, SourceLocation(), SourceLocation()) {}
2292
2293 /// Returns the locaiton of '('.
2294 SourceLocation getLParenLoc() const { return LParenLoc; }
2295
2296 /// Returns kind of the clause.
2297 OpenMPAtClauseKind getAtKind() const { return Kind; }
2298
2299 /// Returns location of clause kind.
2300 SourceLocation getAtKindKwLoc() const { return KindKwLoc; }
2301
2302 child_range children() {
2303 return child_range(child_iterator(), child_iterator());
2304 }
2305
2306 const_child_range children() const {
2307 return const_child_range(const_child_iterator(), const_child_iterator());
2308 }
2309
2310 child_range used_children() {
2311 return child_range(child_iterator(), child_iterator());
2312 }
2313 const_child_range used_children() const {
2314 return const_child_range(const_child_iterator(), const_child_iterator());
2315 }
2316
2317 static bool classof(const OMPClause *T) {
2318 return T->getClauseKind() == llvm::omp::OMPC_at;
2319 }
2320};
2321
2322/// This represents the 'severity' clause in the '#pragma omp error' and the
2323/// '#pragma omp parallel' directives.
2324///
2325/// \code
2326/// #pragma omp error severity(fatal)
2327/// \endcode
2328/// In this example directive '#pragma omp error' has simple
2329/// 'severity' clause with kind 'fatal'.
2330class OMPSeverityClause final : public OMPClause {
2331 friend class OMPClauseReader;
2332
2333 /// Location of '('
2334 SourceLocation LParenLoc;
2335
2336 /// A kind of the 'severity' clause.
2338
2339 /// Start location of the kind in source code.
2340 SourceLocation KindKwLoc;
2341
2342 /// Set kind of the clause.
2343 ///
2344 /// \param K Kind of clause.
2345 void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; }
2346
2347 /// Set clause kind location.
2348 ///
2349 /// \param KLoc Kind location.
2350 void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
2351
2352 /// Sets the location of '('.
2353 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2354
2355public:
2356 /// Build 'severity' clause with argument \a A ('fatal' or 'warning').
2357 ///
2358 /// \param A Argument of the clause ('fatal' or 'warning').
2359 /// \param ALoc Starting location of the argument.
2360 /// \param StartLoc Starting location of the clause.
2361 /// \param LParenLoc Location of '('.
2362 /// \param EndLoc Ending location of the clause.
2363 OMPSeverityClause(OpenMPSeverityClauseKind A, SourceLocation ALoc,
2364 SourceLocation StartLoc, SourceLocation LParenLoc,
2365 SourceLocation EndLoc)
2366 : OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc),
2367 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
2368
2369 /// Build an empty clause.
2370 OMPSeverityClause()
2371 : OMPClause(llvm::omp::OMPC_severity, SourceLocation(),
2372 SourceLocation()) {}
2373
2374 /// Returns the locaiton of '('.
2375 SourceLocation getLParenLoc() const { return LParenLoc; }
2376
2377 /// Returns kind of the clause.
2378 OpenMPSeverityClauseKind getSeverityKind() const { return Kind; }
2379
2380 /// Returns location of clause kind.
2381 SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; }
2382
2383 child_range children() {
2384 return child_range(child_iterator(), child_iterator());
2385 }
2386
2387 const_child_range children() const {
2388 return const_child_range(const_child_iterator(), const_child_iterator());
2389 }
2390
2391 child_range used_children() {
2392 return child_range(child_iterator(), child_iterator());
2393 }
2394 const_child_range used_children() const {
2395 return const_child_range(const_child_iterator(), const_child_iterator());
2396 }
2397
2398 static bool classof(const OMPClause *T) {
2399 return T->getClauseKind() == llvm::omp::OMPC_severity;
2400 }
2401};
2402
2403/// This represents the 'message' clause in the '#pragma omp error' and the
2404/// '#pragma omp parallel' directives.
2405///
2406/// \code
2407/// #pragma omp error message("GNU compiler required.")
2408/// \endcode
2409/// In this example directive '#pragma omp error' has simple
2410/// 'message' clause with user error message of "GNU compiler required.".
2411class OMPMessageClause final
2412 : public OMPOneStmtClause<llvm::omp::OMPC_message, OMPClause>,
2413 public OMPClauseWithPreInit {
2414 friend class OMPClauseReader;
2415
2416 /// Set message string of the clause.
2417 void setMessageString(Expr *MS) { setStmt(MS); }
2418
2419public:
2420 /// Build 'message' clause with message string argument
2421 ///
2422 /// \param MS Argument of the clause (message string).
2423 /// \param HelperMS Helper statement for the construct.
2424 /// \param CaptureRegion Innermost OpenMP region where expressions in this
2425 /// clause must be captured.
2426 /// \param StartLoc Starting location of the clause.
2427 /// \param LParenLoc Location of '('.
2428 /// \param EndLoc Ending location of the clause.
2429 OMPMessageClause(Expr *MS, Stmt *HelperMS, OpenMPDirectiveKind CaptureRegion,
2430 SourceLocation StartLoc, SourceLocation LParenLoc,
2431 SourceLocation EndLoc)
2432 : OMPOneStmtClause(MS, StartLoc, LParenLoc, EndLoc),
2433 OMPClauseWithPreInit(this) {
2434 setPreInitStmt(HelperMS, CaptureRegion);
2435 }
2436
2437 /// Build an empty clause.
2438 OMPMessageClause() : OMPOneStmtClause(), OMPClauseWithPreInit(this) {}
2439
2440 /// Returns message string of the clause.
2441 Expr *getMessageString() const { return getStmtAs<Expr>(); }
2442
2443 /// Try to evaluate the message string at compile time.
2444 std::optional<std::string> tryEvaluateString(ASTContext &Ctx) const {
2445 if (Expr *MessageExpr = getMessageString())
2446 return MessageExpr->tryEvaluateString(Ctx);
2447 return std::nullopt;
2448 }
2449};
2450
2451/// This represents 'schedule' clause in the '#pragma omp ...' directive.
2452///
2453/// \code
2454/// #pragma omp for schedule(static, 3)
2455/// \endcode
2456/// In this example directive '#pragma omp for' has 'schedule' clause with
2457/// arguments 'static' and '3'.
2458class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
2459 friend class OMPClauseReader;
2460
2461 /// Location of '('.
2462 SourceLocation LParenLoc;
2463
2464 /// A kind of the 'schedule' clause.
2466
2467 /// Modifiers for 'schedule' clause.
2468 enum {FIRST, SECOND, NUM_MODIFIERS};
2469 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
2470
2471 /// Locations of modifiers.
2472 SourceLocation ModifiersLoc[NUM_MODIFIERS];
2473
2474 /// Start location of the schedule ind in source code.
2475 SourceLocation KindLoc;
2476
2477 /// Location of ',' (if any).
2478 SourceLocation CommaLoc;
2479
2480 /// Chunk size.
2481 Expr *ChunkSize = nullptr;
2482
2483 /// Set schedule kind.
2484 ///
2485 /// \param K Schedule kind.
2486 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
2487
2488 /// Set the first schedule modifier.
2489 ///
2490 /// \param M Schedule modifier.
2491 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
2492 Modifiers[FIRST] = M;
2493 }
2494
2495 /// Set the second schedule modifier.
2496 ///
2497 /// \param M Schedule modifier.
2498 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
2499 Modifiers[SECOND] = M;
2500 }
2501
2502 /// Set location of the first schedule modifier.
2503 void setFirstScheduleModifierLoc(SourceLocation Loc) {
2504 ModifiersLoc[FIRST] = Loc;
2505 }
2506
2507 /// Set location of the second schedule modifier.
2508 void setSecondScheduleModifierLoc(SourceLocation Loc) {
2509 ModifiersLoc[SECOND] = Loc;
2510 }
2511
2512 /// Set schedule modifier location.
2513 ///
2514 /// \param M Schedule modifier location.
2515 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
2516 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
2517 Modifiers[FIRST] = M;
2518 else {
2519 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
2520 Modifiers[SECOND] = M;
2521 }
2522 }
2523
2524 /// Sets the location of '('.
2525 ///
2526 /// \param Loc Location of '('.
2527 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2528
2529 /// Set schedule kind start location.
2530 ///
2531 /// \param KLoc Schedule kind location.
2532 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
2533
2534 /// Set location of ','.
2535 ///
2536 /// \param Loc Location of ','.
2537 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
2538
2539 /// Set chunk size.
2540 ///
2541 /// \param E Chunk size.
2542 void setChunkSize(Expr *E) { ChunkSize = E; }
2543
2544public:
2545 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
2546 /// expression \a ChunkSize.
2547 ///
2548 /// \param StartLoc Starting location of the clause.
2549 /// \param LParenLoc Location of '('.
2550 /// \param KLoc Starting location of the argument.
2551 /// \param CommaLoc Location of ','.
2552 /// \param EndLoc Ending location of the clause.
2553 /// \param Kind Schedule kind.
2554 /// \param ChunkSize Chunk size.
2555 /// \param HelperChunkSize Helper chunk size for combined directives.
2556 /// \param M1 The first modifier applied to 'schedule' clause.
2557 /// \param M1Loc Location of the first modifier
2558 /// \param M2 The second modifier applied to 'schedule' clause.
2559 /// \param M2Loc Location of the second modifier
2560 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2561 SourceLocation KLoc, SourceLocation CommaLoc,
2562 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
2563 Expr *ChunkSize, Stmt *HelperChunkSize,
2564 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
2565 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
2566 : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
2567 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
2568 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
2569 setPreInitStmt(HelperChunkSize);
2570 Modifiers[FIRST] = M1;
2571 Modifiers[SECOND] = M2;
2572 ModifiersLoc[FIRST] = M1Loc;
2573 ModifiersLoc[SECOND] = M2Loc;
2574 }
2575
2576 /// Build an empty clause.
2577 explicit OMPScheduleClause()
2578 : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
2579 OMPClauseWithPreInit(this) {
2580 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
2581 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
2582 }
2583
2584 /// Get kind of the clause.
2585 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
2586
2587 /// Get the first modifier of the clause.
2588 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
2589 return Modifiers[FIRST];
2590 }
2591
2592 /// Get the second modifier of the clause.
2593 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
2594 return Modifiers[SECOND];
2595 }
2596
2597 /// Get location of '('.
2598 SourceLocation getLParenLoc() { return LParenLoc; }
2599
2600 /// Get kind location.
2601 SourceLocation getScheduleKindLoc() { return KindLoc; }
2602
2603 /// Get the first modifier location.
2604 SourceLocation getFirstScheduleModifierLoc() const {
2605 return ModifiersLoc[FIRST];
2606 }
2607
2608 /// Get the second modifier location.
2609 SourceLocation getSecondScheduleModifierLoc() const {
2610 return ModifiersLoc[SECOND];
2611 }
2612
2613 /// Get location of ','.
2614 SourceLocation getCommaLoc() { return CommaLoc; }
2615
2616 /// Get chunk size.
2617 Expr *getChunkSize() { return ChunkSize; }
2618
2619 /// Get chunk size.
2620 const Expr *getChunkSize() const { return ChunkSize; }
2621
2622 child_range children() {
2623 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
2624 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
2625 }
2626
2627 const_child_range children() const {
2628 return const_cast<OMPScheduleClause *>(this)->children();
2629 }
2630
2631 child_range used_children() {
2632 return child_range(child_iterator(), child_iterator());
2633 }
2634 const_child_range used_children() const {
2635 return const_child_range(const_child_iterator(), const_child_iterator());
2636 }
2637
2638 static bool classof(const OMPClause *T) {
2639 return T->getClauseKind() == llvm::omp::OMPC_schedule;
2640 }
2641};
2642
2643/// This represents 'ordered' clause in the '#pragma omp ...' directive.
2644///
2645/// \code
2646/// #pragma omp for ordered (2)
2647/// \endcode
2648/// In this example directive '#pragma omp for' has 'ordered' clause with
2649/// parameter 2.
2650class OMPOrderedClause final
2651 : public OMPClause,
2652 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
2653 friend class OMPClauseReader;
2654 friend TrailingObjects;
2655
2656 /// Location of '('.
2657 SourceLocation LParenLoc;
2658
2659 /// Number of for-loops.
2660 Stmt *NumForLoops = nullptr;
2661
2662 /// Real number of loops.
2663 unsigned NumberOfLoops = 0;
2664
2665 /// Build 'ordered' clause.
2666 ///
2667 /// \param Num Expression, possibly associated with this clause.
2668 /// \param NumLoops Number of loops, associated with this clause.
2669 /// \param StartLoc Starting location of the clause.
2670 /// \param LParenLoc Location of '('.
2671 /// \param EndLoc Ending location of the clause.
2672 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
2673 SourceLocation LParenLoc, SourceLocation EndLoc)
2674 : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
2675 LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
2676
2677 /// Build an empty clause.
2678 explicit OMPOrderedClause(unsigned NumLoops)
2679 : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
2680 NumberOfLoops(NumLoops) {}
2681
2682 /// Set the number of associated for-loops.
2683 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
2684
2685public:
2686 /// Build 'ordered' clause.
2687 ///
2688 /// \param Num Expression, possibly associated with this clause.
2689 /// \param NumLoops Number of loops, associated with this clause.
2690 /// \param StartLoc Starting location of the clause.
2691 /// \param LParenLoc Location of '('.
2692 /// \param EndLoc Ending location of the clause.
2693 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
2694 unsigned NumLoops, SourceLocation StartLoc,
2695 SourceLocation LParenLoc,
2696 SourceLocation EndLoc);
2697
2698 /// Build an empty clause.
2699 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
2700
2701 /// Sets the location of '('.
2702 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2703
2704 /// Returns the location of '('.
2705 SourceLocation getLParenLoc() const { return LParenLoc; }
2706
2707 /// Return the number of associated for-loops.
2708 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
2709
2710 /// Set number of iterations for the specified loop.
2711 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
2712 /// Get number of iterations for all the loops.
2713 ArrayRef<Expr *> getLoopNumIterations() const;
2714
2715 /// Set loop counter for the specified loop.
2716 void setLoopCounter(unsigned NumLoop, Expr *Counter);
2717 /// Get loops counter for the specified loop.
2718 Expr *getLoopCounter(unsigned NumLoop);
2719 const Expr *getLoopCounter(unsigned NumLoop) const;
2720
2721 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
2722
2723 const_child_range children() const {
2724 return const_child_range(&NumForLoops, &NumForLoops + 1);
2725 }
2726
2727 child_range used_children() {
2728 return child_range(child_iterator(), child_iterator());
2729 }
2730 const_child_range used_children() const {
2731 return const_child_range(const_child_iterator(), const_child_iterator());
2732 }
2733
2734 static bool classof(const OMPClause *T) {
2735 return T->getClauseKind() == llvm::omp::OMPC_ordered;
2736 }
2737};
2738
2739/// This represents 'nowait' clause in the '#pragma omp ...' directive.
2740///
2741/// \code
2742/// #pragma omp for nowait (cond)
2743/// \endcode
2744/// In this example directive '#pragma omp for' has simple 'nowait' clause with
2745/// condition 'cond'.
2746class OMPNowaitClause final : public OMPClause {
2747 friend class OMPClauseReader;
2748
2749 /// Location of '('.
2750 SourceLocation LParenLoc;
2751
2752 /// Condition of the 'nowait' clause.
2753 Stmt *Condition = nullptr;
2754
2755 /// Set condition.
2756 void setCondition(Expr *Cond) { Condition = Cond; }
2757
2758public:
2759 /// Build 'nowait' clause with condition \a Cond.
2760 ///
2761 /// \param Cond Condition of the clause.
2762 /// \param StartLoc Starting location of the clause.
2763 /// \param LParenLoc Location of '('.
2764 /// \param EndLoc Ending location of the clause.
2765 OMPNowaitClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
2766 SourceLocation EndLoc)
2767 : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc),
2768 LParenLoc(LParenLoc), Condition(Cond) {}
2769
2770 /// Build an empty clause.
2771 OMPNowaitClause()
2772 : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {}
2773
2774 /// Sets the location of '('.
2775 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2776
2777 /// Returns the location of '('.
2778 SourceLocation getLParenLoc() const { return LParenLoc; }
2779
2780 /// Returns condition.
2781 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
2782
2783 child_range children() {
2784 if (Condition)
2785 return child_range(&Condition, &Condition + 1);
2786 return child_range(child_iterator(), child_iterator());
2787 }
2788
2789 const_child_range children() const {
2790 if (Condition)
2791 return const_child_range(&Condition, &Condition + 1);
2792 return const_child_range(const_child_iterator(), const_child_iterator());
2793 }
2794
2795 child_range used_children();
2796 const_child_range used_children() const {
2797 return const_cast<OMPNowaitClause *>(this)->used_children();
2798 }
2799
2800 static bool classof(const OMPClause *T) {
2801 return T->getClauseKind() == llvm::omp::OMPC_nowait;
2802 }
2803};
2804
2805/// This represents 'untied' clause in the '#pragma omp ...' directive.
2806///
2807/// \code
2808/// #pragma omp task untied
2809/// \endcode
2810/// In this example directive '#pragma omp task' has 'untied' clause.
2811class OMPUntiedClause : public OMPClause {
2812public:
2813 /// Build 'untied' clause.
2814 ///
2815 /// \param StartLoc Starting location of the clause.
2816 /// \param EndLoc Ending location of the clause.
2817 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
2818 : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
2819
2820 /// Build an empty clause.
2821 OMPUntiedClause()
2822 : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
2823
2824 child_range children() {
2825 return child_range(child_iterator(), child_iterator());
2826 }
2827
2828 const_child_range children() const {
2829 return const_child_range(const_child_iterator(), const_child_iterator());
2830 }
2831
2832 child_range used_children() {
2833 return child_range(child_iterator(), child_iterator());
2834 }
2835 const_child_range used_children() const {
2836 return const_child_range(const_child_iterator(), const_child_iterator());
2837 }
2838
2839 static bool classof(const OMPClause *T) {
2840 return T->getClauseKind() == llvm::omp::OMPC_untied;
2841 }
2842};
2843
2844/// This represents 'mergeable' clause in the '#pragma omp ...'
2845/// directive.
2846///
2847/// \code
2848/// #pragma omp task mergeable
2849/// \endcode
2850/// In this example directive '#pragma omp task' has 'mergeable' clause.
2851class OMPMergeableClause : public OMPClause {
2852public:
2853 /// Build 'mergeable' clause.
2854 ///
2855 /// \param StartLoc Starting location of the clause.
2856 /// \param EndLoc Ending location of the clause.
2857 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
2858 : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
2859
2860 /// Build an empty clause.
2861 OMPMergeableClause()
2862 : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
2863 SourceLocation()) {}
2864
2865 child_range children() {
2866 return child_range(child_iterator(), child_iterator());
2867 }
2868
2869 const_child_range children() const {
2870 return const_child_range(const_child_iterator(), const_child_iterator());
2871 }
2872
2873 child_range used_children() {
2874 return child_range(child_iterator(), child_iterator());
2875 }
2876 const_child_range used_children() const {
2877 return const_child_range(const_child_iterator(), const_child_iterator());
2878 }
2879
2880 static bool classof(const OMPClause *T) {
2881 return T->getClauseKind() == llvm::omp::OMPC_mergeable;
2882 }
2883};
2884
2885/// This represents the 'absent' clause in the '#pragma omp assume'
2886/// directive.
2887///
2888/// \code
2889/// #pragma omp assume absent(<directive-name list>)
2890/// \endcode
2891/// In this example directive '#pragma omp assume' has an 'absent' clause.
2892class OMPAbsentClause final
2893 : public OMPDirectiveListClause<OMPAbsentClause>,
2894 private llvm::TrailingObjects<OMPAbsentClause, OpenMPDirectiveKind> {
2895 friend OMPDirectiveListClause;
2896 friend TrailingObjects;
2897
2898 /// Build 'absent' clause.
2899 ///
2900 /// \param StartLoc Starting location of the clause.
2901 /// \param LParenLoc Location of '('.
2902 /// \param EndLoc Ending location of the clause.
2903 /// \param NumKinds Number of directive kinds listed in the clause.
2904 OMPAbsentClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2905 SourceLocation EndLoc, unsigned NumKinds)
2906 : OMPDirectiveListClause<OMPAbsentClause>(
2907 llvm::omp::OMPC_absent, StartLoc, LParenLoc, EndLoc, NumKinds) {}
2908
2909 /// Build an empty clause.
2910 OMPAbsentClause(unsigned NumKinds)
2911 : OMPDirectiveListClause<OMPAbsentClause>(
2912 llvm::omp::OMPC_absent, SourceLocation(), SourceLocation(),
2913 SourceLocation(), NumKinds) {}
2914
2915public:
2916 static OMPAbsentClause *Create(const ASTContext &C,
2917 ArrayRef<OpenMPDirectiveKind> DKVec,
2918 SourceLocation Loc, SourceLocation LLoc,
2919 SourceLocation RLoc);
2920
2921 static OMPAbsentClause *CreateEmpty(const ASTContext &C, unsigned NumKinds);
2922
2923 static bool classof(const OMPClause *C) {
2924 return C->getClauseKind() == llvm::omp::OMPC_absent;
2925 }
2926};
2927
2928/// This represents the 'contains' clause in the '#pragma omp assume'
2929/// directive.
2930///
2931/// \code
2932/// #pragma omp assume contains(<directive-name list>)
2933/// \endcode
2934/// In this example directive '#pragma omp assume' has a 'contains' clause.
2935class OMPContainsClause final
2936 : public OMPDirectiveListClause<OMPContainsClause>,
2937 private llvm::TrailingObjects<OMPContainsClause, OpenMPDirectiveKind> {
2938 friend OMPDirectiveListClause;
2939 friend TrailingObjects;
2940
2941 /// Build 'contains' clause.
2942 ///
2943 /// \param StartLoc Starting location of the clause.
2944 /// \param LParenLoc Location of '('.
2945 /// \param EndLoc Ending location of the clause.
2946 /// \param NumKinds Number of directive kinds listed in the clause.
2947 OMPContainsClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2948 SourceLocation EndLoc, unsigned NumKinds)
2949 : OMPDirectiveListClause<OMPContainsClause>(
2950 llvm::omp::OMPC_contains, StartLoc, LParenLoc, EndLoc, NumKinds) {}
2951
2952 /// Build an empty clause.
2953 OMPContainsClause(unsigned NumKinds)
2954 : OMPDirectiveListClause<OMPContainsClause>(
2955 llvm::omp::OMPC_contains, SourceLocation(), SourceLocation(),
2956 SourceLocation(), NumKinds) {}
2957
2958public:
2959 static OMPContainsClause *Create(const ASTContext &C,
2960 ArrayRef<OpenMPDirectiveKind> DKVec,
2961 SourceLocation Loc, SourceLocation LLoc,
2962 SourceLocation RLoc);
2963
2964 static OMPContainsClause *CreateEmpty(const ASTContext &C, unsigned NumKinds);
2965
2966 static bool classof(const OMPClause *C) {
2967 return C->getClauseKind() == llvm::omp::OMPC_contains;
2968 }
2969};
2970
2971/// This represents the 'holds' clause in the '#pragma omp assume'
2972/// directive.
2973///
2974/// \code
2975/// #pragma omp assume holds(<expr>)
2976/// \endcode
2977/// In this example directive '#pragma omp assume' has a 'holds' clause.
2978class OMPHoldsClause final
2979 : public OMPOneStmtClause<llvm::omp::OMPC_holds, OMPClause> {
2980 friend class OMPClauseReader;
2981
2982public:
2983 /// Build 'holds' clause.
2984 ///
2985 /// \param StartLoc Starting location of the clause.
2986 /// \param EndLoc Ending location of the clause.
2987 OMPHoldsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2988 SourceLocation EndLoc)
2989 : OMPOneStmtClause(E, StartLoc, LParenLoc, EndLoc) {}
2990
2991 /// Build an empty clause.
2992 OMPHoldsClause() : OMPOneStmtClause() {}
2993
2994 Expr *getExpr() const { return getStmtAs<Expr>(); }
2995 void setExpr(Expr *E) { setStmt(E); }
2996};
2997
2998/// This represents the 'no_openmp' clause in the '#pragma omp assume'
2999/// directive.
3000///
3001/// \code
3002/// #pragma omp assume no_openmp
3003/// \endcode
3004/// In this example directive '#pragma omp assume' has a 'no_openmp' clause.
3005class OMPNoOpenMPClause final
3006 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp> {
3007public:
3008 /// Build 'no_openmp' clause.
3009 ///
3010 /// \param StartLoc Starting location of the clause.
3011 /// \param EndLoc Ending location of the clause.
3012 OMPNoOpenMPClause(SourceLocation StartLoc, SourceLocation EndLoc)
3013 : OMPNoChildClause(StartLoc, EndLoc) {}
3014
3015 /// Build an empty clause.
3016 OMPNoOpenMPClause() : OMPNoChildClause() {}
3017};
3018
3019/// This represents the 'no_openmp_routines' clause in the '#pragma omp assume'
3020/// directive.
3021///
3022/// \code
3023/// #pragma omp assume no_openmp_routines
3024/// \endcode
3025/// In this example directive '#pragma omp assume' has a 'no_openmp_routines'
3026/// clause.
3027class OMPNoOpenMPRoutinesClause final
3028 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp_routines> {
3029public:
3030 /// Build 'no_openmp_routines' clause.
3031 ///
3032 /// \param StartLoc Starting location of the clause.
3033 /// \param EndLoc Ending location of the clause.
3034 OMPNoOpenMPRoutinesClause(SourceLocation StartLoc, SourceLocation EndLoc)
3035 : OMPNoChildClause(StartLoc, EndLoc) {}
3036
3037 /// Build an empty clause.
3038 OMPNoOpenMPRoutinesClause() : OMPNoChildClause() {}
3039};
3040
3041/// This represents the 'no_openmp_constructs' clause in the
3042//// '#pragma omp assume' directive.
3043///
3044/// \code
3045/// #pragma omp assume no_openmp_constructs
3046/// \endcode
3047/// In this example directive '#pragma omp assume' has a 'no_openmp_constructs'
3048/// clause.
3049class OMPNoOpenMPConstructsClause final
3050 : public OMPNoChildClause<llvm::omp::OMPC_no_openmp_constructs> {
3051public:
3052 /// Build 'no_openmp_constructs' clause.
3053 ///
3054 /// \param StartLoc Starting location of the clause.
3055 /// \param EndLoc Ending location of the clause.
3056 OMPNoOpenMPConstructsClause(SourceLocation StartLoc, SourceLocation EndLoc)
3057 : OMPNoChildClause(StartLoc, EndLoc) {}
3058
3059 /// Build an empty clause.
3060 OMPNoOpenMPConstructsClause() : OMPNoChildClause() {}
3061};
3062
3063/// This represents the 'no_parallelism' clause in the '#pragma omp assume'
3064/// directive.
3065///
3066/// \code
3067/// #pragma omp assume no_parallelism
3068/// \endcode
3069/// In this example directive '#pragma omp assume' has a 'no_parallelism'
3070/// clause.
3071class OMPNoParallelismClause final
3072 : public OMPNoChildClause<llvm::omp::OMPC_no_parallelism> {
3073public:
3074 /// Build 'no_parallelism' clause.
3075 ///
3076 /// \param StartLoc Starting location of the clause.
3077 /// \param EndLoc Ending location of the clause.
3078 OMPNoParallelismClause(SourceLocation StartLoc, SourceLocation EndLoc)
3079 : OMPNoChildClause(StartLoc, EndLoc) {}
3080
3081 /// Build an empty clause.
3082 OMPNoParallelismClause() : OMPNoChildClause() {}
3083};
3084
3085/// This represents 'read' clause in the '#pragma omp atomic' directive.
3086///
3087/// \code
3088/// #pragma omp atomic read
3089/// \endcode
3090/// In this example directive '#pragma omp atomic' has 'read' clause.
3091class OMPReadClause : public OMPClause {
3092public:
3093 /// Build 'read' clause.
3094 ///
3095 /// \param StartLoc Starting location of the clause.
3096 /// \param EndLoc Ending location of the clause.
3097 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
3098 : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
3099
3100 /// Build an empty clause.
3101 OMPReadClause()
3102 : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
3103
3104 child_range children() {
3105 return child_range(child_iterator(), child_iterator());
3106 }
3107
3108 const_child_range children() const {
3109 return const_child_range(const_child_iterator(), const_child_iterator());
3110 }
3111
3112 child_range used_children() {
3113 return child_range(child_iterator(), child_iterator());
3114 }
3115 const_child_range used_children() const {
3116 return const_child_range(const_child_iterator(), const_child_iterator());
3117 }
3118
3119 static bool classof(const OMPClause *T) {
3120 return T->getClauseKind() == llvm::omp::OMPC_read;
3121 }
3122};
3123
3124/// This represents 'write' clause in the '#pragma omp atomic' directive.
3125///
3126/// \code
3127/// #pragma omp atomic write
3128/// \endcode
3129/// In this example directive '#pragma omp atomic' has 'write' clause.
3130class OMPWriteClause : public OMPClause {
3131public:
3132 /// Build 'write' clause.
3133 ///
3134 /// \param StartLoc Starting location of the clause.
3135 /// \param EndLoc Ending location of the clause.
3136 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
3137 : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
3138
3139 /// Build an empty clause.
3140 OMPWriteClause()
3141 : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
3142
3143 child_range children() {
3144 return child_range(child_iterator(), child_iterator());
3145 }
3146
3147 const_child_range children() const {
3148 return const_child_range(const_child_iterator(), const_child_iterator());
3149 }
3150
3151 child_range used_children() {
3152 return child_range(child_iterator(), child_iterator());
3153 }
3154 const_child_range used_children() const {
3155 return const_child_range(const_child_iterator(), const_child_iterator());
3156 }
3157
3158 static bool classof(const OMPClause *T) {
3159 return T->getClauseKind() == llvm::omp::OMPC_write;
3160 }
3161};
3162
3163/// This represents 'update' clause in the '#pragma omp atomic'
3164/// directive.
3165///
3166/// \code
3167/// #pragma omp atomic update
3168/// \endcode
3169/// In this example directive '#pragma omp atomic' has 'update' clause.
3170class OMPUpdateClause : public OMPClause {
3171public:
3172 /// Build 'update' clause.
3173 ///
3174 /// \param StartLoc Starting location of the clause.
3175 /// \param EndLoc Ending location of the clause.
3176 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
3177 : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc) {}
3178
3179 /// Build an empty clause.
3180 OMPUpdateClause()
3181 : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()) {}
3182
3183 child_range children() {
3184 return child_range(child_iterator(), child_iterator());
3185 }
3186
3187 const_child_range children() const {
3188 return const_child_range(const_child_iterator(), const_child_iterator());
3189 }
3190
3191 child_range used_children() {
3192 return child_range(child_iterator(), child_iterator());
3193 }
3194 const_child_range used_children() const {
3195 return const_child_range(const_child_iterator(), const_child_iterator());
3196 }
3197
3198 static bool classof(const OMPClause *T) {
3199 return T->getClauseKind() == llvm::omp::OMPC_update;
3200 }
3201};
3202
3203/// This class represents 'update' clause in '#pragma omp depobj'
3204/// directive.
3205///
3206/// \code
3207/// #pragma omp depobj(a) update(in)
3208/// \endcode
3209/// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
3210/// dependence kind.
3211class OMPUpdateDependObjectsClause final
3212 : public OMPClause,
3213 private llvm::TrailingObjects<OMPUpdateDependObjectsClause,
3214 SourceLocation, OpenMPDependClauseKind> {
3215 friend class OMPClauseReader;
3216 friend TrailingObjects;
3217
3218 /// Define the sizes of each trailing object array except the last one. This
3219 /// is required for TrailingObjects to work properly.
3220 size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
3221 // 2 locations: for '(' and argument location.
3222 return 2;
3223 }
3224
3225 /// Sets the location of '(' in clause for 'depobj' directive.
3226 void setLParenLoc(SourceLocation Loc) {
3227 *getTrailingObjects<SourceLocation>() = Loc;
3228 }
3229
3230 /// Sets the location of '(' in clause for 'depobj' directive.
3231 void setArgumentLoc(SourceLocation Loc) {
3232 *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
3233 }
3234
3235 /// Sets the dependence kind for the clause for 'depobj' directive.
3236 void setDependencyKind(OpenMPDependClauseKind DK) {
3237 *getTrailingObjects<OpenMPDependClauseKind>() = DK;
3238 }
3239
3240 /// Build 'update' clause.
3241 ///
3242 /// \param StartLoc Starting location of the clause.
3243 /// \param EndLoc Ending location of the clause.
3244 OMPUpdateDependObjectsClause(SourceLocation StartLoc, SourceLocation EndLoc)
3245 : OMPClause(llvm::omp::OMPC_update_depend_objects, StartLoc, EndLoc) {}
3246
3247 /// Build an empty clause.
3248 OMPUpdateDependObjectsClause()
3249 : OMPClause(llvm::omp::OMPC_update_depend_objects, SourceLocation(),
3250 SourceLocation()) {}
3251
3252public:
3253 /// Creates clause for 'depobj' directive.
3254 ///
3255 /// \param C AST context.
3256 /// \param StartLoc Starting location of the clause.
3257 /// \param LParenLoc Location of '('.
3258 /// \param ArgumentLoc Location of the argument.
3259 /// \param DK Dependence kind.
3260 /// \param EndLoc Ending location of the clause.
3261 static OMPUpdateDependObjectsClause *
3262 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3263 SourceLocation ArgumentLoc, OpenMPDependClauseKind DK,
3264 SourceLocation EndLoc);
3265
3266 /// Creates an empty clause with the place for \a N variables.
3267 ///
3268 /// \param C AST context.
3269 static OMPUpdateDependObjectsClause *CreateEmpty(const ASTContext &C);
3270
3271 child_range children() {
3272 return child_range(child_iterator(), child_iterator());
3273 }
3274
3275 const_child_range children() const {
3276 return const_child_range(const_child_iterator(), const_child_iterator());
3277 }
3278
3279 child_range used_children() {
3280 return child_range(child_iterator(), child_iterator());
3281 }
3282 const_child_range used_children() const {
3283 return const_child_range(const_child_iterator(), const_child_iterator());
3284 }
3285
3286 /// Gets the location of '(' in clause for 'depobj' directive.
3287 SourceLocation getLParenLoc() const {
3288 return *getTrailingObjects<SourceLocation>();
3289 }
3290
3291 /// Gets the location of argument in clause for 'depobj' directive.
3292 SourceLocation getArgumentLoc() const {
3293 return *std::next(getTrailingObjects<SourceLocation>(), 1);
3294 }
3295
3296 /// Gets the dependence kind in clause for 'depobj' directive.
3297 OpenMPDependClauseKind getDependencyKind() const {
3298 return *getTrailingObjects<OpenMPDependClauseKind>();
3299 }
3300
3301 static bool classof(const OMPClause *T) {
3302 return T->getClauseKind() == llvm::omp::OMPC_update_depend_objects;
3303 }
3304};
3305
3306/// This represents 'capture' clause in the '#pragma omp atomic'
3307/// directive.
3308///
3309/// \code
3310/// #pragma omp atomic capture
3311/// \endcode
3312/// In this example directive '#pragma omp atomic' has 'capture' clause.
3313class OMPCaptureClause : public OMPClause {
3314public:
3315 /// Build 'capture' clause.
3316 ///
3317 /// \param StartLoc Starting location of the clause.
3318 /// \param EndLoc Ending location of the clause.
3319 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
3320 : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
3321
3322 /// Build an empty clause.
3323 OMPCaptureClause()
3324 : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
3325 }
3326
3327 child_range children() {
3328 return child_range(child_iterator(), child_iterator());
3329 }
3330
3331 const_child_range children() const {
3332 return const_child_range(const_child_iterator(), const_child_iterator());
3333 }
3334
3335 child_range used_children() {
3336 return child_range(child_iterator(), child_iterator());
3337 }
3338 const_child_range used_children() const {
3339 return const_child_range(const_child_iterator(), const_child_iterator());
3340 }
3341
3342 static bool classof(const OMPClause *T) {
3343 return T->getClauseKind() == llvm::omp::OMPC_capture;
3344 }
3345};
3346
3347/// This represents 'compare' clause in the '#pragma omp atomic'
3348/// directive.
3349///
3350/// \code
3351/// #pragma omp atomic compare
3352/// \endcode
3353/// In this example directive '#pragma omp atomic' has 'compare' clause.
3354class OMPCompareClause final : public OMPClause {
3355public:
3356 /// Build 'compare' clause.
3357 ///
3358 /// \param StartLoc Starting location of the clause.
3359 /// \param EndLoc Ending location of the clause.
3360 OMPCompareClause(SourceLocation StartLoc, SourceLocation EndLoc)
3361 : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {}
3362
3363 /// Build an empty clause.
3364 OMPCompareClause()
3365 : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) {
3366 }
3367
3368 child_range children() {
3369 return child_range(child_iterator(), child_iterator());
3370 }
3371
3372 const_child_range children() const {
3373 return const_child_range(const_child_iterator(), const_child_iterator());
3374 }
3375
3376 child_range used_children() {
3377 return child_range(child_iterator(), child_iterator());
3378 }
3379 const_child_range used_children() const {
3380 return const_child_range(const_child_iterator(), const_child_iterator());
3381 }
3382
3383 static bool classof(const OMPClause *T) {
3384 return T->getClauseKind() == llvm::omp::OMPC_compare;
3385 }
3386};
3387
3388/// This represents 'seq_cst' clause in the '#pragma omp atomic|flush'
3389/// directives.
3390///
3391/// \code
3392/// #pragma omp atomic seq_cst
3393/// \endcode
3394/// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
3395class OMPSeqCstClause : public OMPClause {
3396public:
3397 /// Build 'seq_cst' clause.
3398 ///
3399 /// \param StartLoc Starting location of the clause.
3400 /// \param EndLoc Ending location of the clause.
3401 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
3402 : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
3403
3404 /// Build an empty clause.
3405 OMPSeqCstClause()
3406 : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
3407 }
3408
3409 child_range children() {
3410 return child_range(child_iterator(), child_iterator());
3411 }
3412
3413 const_child_range children() const {
3414 return const_child_range(const_child_iterator(), const_child_iterator());
3415 }
3416
3417 child_range used_children() {
3418 return child_range(child_iterator(), child_iterator());
3419 }
3420 const_child_range used_children() const {
3421 return const_child_range(const_child_iterator(), const_child_iterator());
3422 }
3423
3424 static bool classof(const OMPClause *T) {
3425 return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
3426 }
3427};
3428
3429/// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
3430/// directives.
3431///
3432/// \code
3433/// #pragma omp flush acq_rel
3434/// \endcode
3435/// In this example directive '#pragma omp flush' has 'acq_rel' clause.
3436class OMPAcqRelClause final : public OMPClause {
3437public:
3438 /// Build 'ack_rel' clause.
3439 ///
3440 /// \param StartLoc Starting location of the clause.
3441 /// \param EndLoc Ending location of the clause.
3442 OMPAcqRelClause(SourceLocation StartLoc, SourceLocation EndLoc)
3443 : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
3444
3445 /// Build an empty clause.
3446 OMPAcqRelClause()
3447 : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
3448 }
3449
3450 child_range children() {
3451 return child_range(child_iterator(), child_iterator());
3452 }
3453
3454 const_child_range children() const {
3455 return const_child_range(const_child_iterator(), const_child_iterator());
3456 }
3457
3458 child_range used_children() {
3459 return child_range(child_iterator(), child_iterator());
3460 }
3461 const_child_range used_children() const {
3462 return const_child_range(const_child_iterator(), const_child_iterator());
3463 }
3464
3465 static bool classof(const OMPClause *T) {
3466 return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
3467 }
3468};
3469
3470/// This represents 'acquire' clause in the '#pragma omp atomic|flush'
3471/// directives.
3472///
3473/// \code
3474/// #pragma omp flush acquire
3475/// \endcode
3476/// In this example directive '#pragma omp flush' has 'acquire' clause.
3477class OMPAcquireClause final : public OMPClause {
3478public:
3479 /// Build 'acquire' clause.
3480 ///
3481 /// \param StartLoc Starting location of the clause.
3482 /// \param EndLoc Ending location of the clause.
3483 OMPAcquireClause(SourceLocation StartLoc, SourceLocation EndLoc)
3484 : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
3485
3486 /// Build an empty clause.
3487 OMPAcquireClause()
3488 : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
3489 }
3490
3491 child_range children() {
3492 return child_range(child_iterator(), child_iterator());
3493 }
3494
3495 const_child_range children() const {
3496 return const_child_range(const_child_iterator(), const_child_iterator());
3497 }
3498
3499 child_range used_children() {
3500 return child_range(child_iterator(), child_iterator());
3501 }
3502 const_child_range used_children() const {
3503 return const_child_range(const_child_iterator(), const_child_iterator());
3504 }
3505
3506 static bool classof(const OMPClause *T) {
3507 return T->getClauseKind() == llvm::omp::OMPC_acquire;
3508 }
3509};
3510
3511/// This represents 'release' clause in the '#pragma omp atomic|flush'
3512/// directives.
3513///
3514/// \code
3515/// #pragma omp flush release
3516/// \endcode
3517/// In this example directive '#pragma omp flush' has 'release' clause.
3518class OMPReleaseClause final : public OMPClause {
3519public:
3520 /// Build 'release' clause.
3521 ///
3522 /// \param StartLoc Starting location of the clause.
3523 /// \param EndLoc Ending location of the clause.
3524 OMPReleaseClause(SourceLocation StartLoc, SourceLocation EndLoc)
3525 : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
3526
3527 /// Build an empty clause.
3528 OMPReleaseClause()
3529 : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
3530 }
3531
3532 child_range children() {
3533 return child_range(child_iterator(), child_iterator());
3534 }
3535
3536 const_child_range children() const {
3537 return const_child_range(const_child_iterator(), const_child_iterator());
3538 }
3539
3540 child_range used_children() {
3541 return child_range(child_iterator(), child_iterator());
3542 }
3543 const_child_range used_children() const {
3544 return const_child_range(const_child_iterator(), const_child_iterator());
3545 }
3546
3547 static bool classof(const OMPClause *T) {
3548 return T->getClauseKind() == llvm::omp::OMPC_release;
3549 }
3550};
3551
3552/// This represents 'relaxed' clause in the '#pragma omp atomic'
3553/// directives.
3554///
3555/// \code
3556/// #pragma omp atomic relaxed
3557/// \endcode
3558/// In this example directive '#pragma omp atomic' has 'relaxed' clause.
3559class OMPRelaxedClause final : public OMPClause {
3560public:
3561 /// Build 'relaxed' clause.
3562 ///
3563 /// \param StartLoc Starting location of the clause.
3564 /// \param EndLoc Ending location of the clause.
3565 OMPRelaxedClause(SourceLocation StartLoc, SourceLocation EndLoc)
3566 : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
3567
3568 /// Build an empty clause.
3569 OMPRelaxedClause()
3570 : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
3571 }
3572
3573 child_range children() {
3574 return child_range(child_iterator(), child_iterator());
3575 }
3576
3577 const_child_range children() const {
3578 return const_child_range(const_child_iterator(), const_child_iterator());
3579 }
3580
3581 child_range used_children() {
3582 return child_range(child_iterator(), child_iterator());
3583 }
3584 const_child_range used_children() const {
3585 return const_child_range(const_child_iterator(), const_child_iterator());
3586 }
3587
3588 static bool classof(const OMPClause *T) {
3589 return T->getClauseKind() == llvm::omp::OMPC_relaxed;
3590 }
3591};
3592
3593/// This represents 'weak' clause in the '#pragma omp atomic'
3594/// directives.
3595///
3596/// \code
3597/// #pragma omp atomic compare weak
3598/// \endcode
3599/// In this example directive '#pragma omp atomic' has 'weak' clause.
3600class OMPWeakClause final : public OMPClause {
3601public:
3602 /// Build 'weak' clause.
3603 ///
3604 /// \param StartLoc Starting location of the clause.
3605 /// \param EndLoc Ending location of the clause.
3606 OMPWeakClause(SourceLocation StartLoc, SourceLocation EndLoc)
3607 : OMPClause(llvm::omp::OMPC_weak, StartLoc, EndLoc) {}
3608
3609 /// Build an empty clause.
3610 OMPWeakClause()
3611 : OMPClause(llvm::omp::OMPC_weak, SourceLocation(), SourceLocation()) {}
3612
3613 child_range children() {
3614 return child_range(child_iterator(), child_iterator());
3615 }
3616
3617 const_child_range children() const {
3618 return const_child_range(const_child_iterator(), const_child_iterator());
3619 }
3620
3621 child_range used_children() {
3622 return child_range(child_iterator(), child_iterator());
3623 }
3624 const_child_range used_children() const {
3625 return const_child_range(const_child_iterator(), const_child_iterator());
3626 }
3627
3628 static bool classof(const OMPClause *T) {
3629 return T->getClauseKind() == llvm::omp::OMPC_weak;
3630 }
3631};
3632
3633/// This represents 'fail' clause in the '#pragma omp atomic'
3634/// directive.
3635///
3636/// \code
3637/// #pragma omp atomic compare fail
3638/// \endcode
3639/// In this example directive '#pragma omp atomic compare' has 'fail' clause.
3640class OMPFailClause final : public OMPClause {
3641
3642 // FailParameter is a memory-order-clause. Storing the ClauseKind is
3643 // sufficient for our purpose.
3644 OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown;
3645 SourceLocation FailParameterLoc;
3646 SourceLocation LParenLoc;
3647
3648 friend class OMPClauseReader;
3649
3650 /// Sets the location of '(' in fail clause.
3651 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3652
3653 /// Sets the location of memoryOrder clause argument in fail clause.
3654 void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; }
3655
3656 /// Sets the mem_order clause for 'atomic compare fail' directive.
3657 void setFailParameter(OpenMPClauseKind FailParameter) {
3658 this->FailParameter = FailParameter;
3659 assert(checkFailClauseParameter(FailParameter) &&
3660 "Invalid fail clause parameter");
3661 }
3662
3663public:
3664 /// Build 'fail' clause.
3665 ///
3666 /// \param StartLoc Starting location of the clause.
3667 /// \param EndLoc Ending location of the clause.
3668 OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc)
3669 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {}
3670
3671 OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation FailParameterLoc,
3672 SourceLocation StartLoc, SourceLocation LParenLoc,
3673 SourceLocation EndLoc)
3674 : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc),
3675 FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) {
3676
3677 setFailParameter(FailParameter);
3678 }
3679
3680 /// Build an empty clause.
3681 OMPFailClause()
3682 : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {}
3683
3684 child_range children() {
3685 return child_range(child_iterator(), child_iterator());
3686 }
3687
3688 const_child_range children() const {
3689 return const_child_range(const_child_iterator(), const_child_iterator());
3690 }
3691
3692 child_range used_children() {
3693 return child_range(child_iterator(), child_iterator());
3694 }
3695 const_child_range used_children() const {
3696 return const_child_range(const_child_iterator(), const_child_iterator());
3697 }
3698
3699 static bool classof(const OMPClause *T) {
3700 return T->getClauseKind() == llvm::omp::OMPC_fail;
3701 }
3702
3703 /// Gets the location of '(' (for the parameter) in fail clause.
3704 SourceLocation getLParenLoc() const {
3705 return LParenLoc;
3706 }
3707
3708 /// Gets the location of Fail Parameter (type memory-order-clause) in
3709 /// fail clause.
3710 SourceLocation getFailParameterLoc() const { return FailParameterLoc; }
3711
3712 /// Gets the parameter (type memory-order-clause) in Fail clause.
3713 OpenMPClauseKind getFailParameter() const { return FailParameter; }
3714};
3715
3716/// This represents clause 'private' in the '#pragma omp ...' directives.
3717///
3718/// \code
3719/// #pragma omp parallel private(a,b)
3720/// \endcode
3721/// In this example directive '#pragma omp parallel' has clause 'private'
3722/// with the variables 'a' and 'b'.
3723class OMPPrivateClause final
3724 : public OMPVarListClause<OMPPrivateClause>,
3725 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
3726 friend class OMPClauseReader;
3727 friend OMPVarListClause;
3728 friend TrailingObjects;
3729
3730 /// Build clause with number of variables \a N.
3731 ///
3732 /// \param StartLoc Starting location of the clause.
3733 /// \param LParenLoc Location of '('.
3734 /// \param EndLoc Ending location of the clause.
3735 /// \param N Number of the variables in the clause.
3736 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3737 SourceLocation EndLoc, unsigned N)
3738 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
3739 LParenLoc, EndLoc, N) {}
3740
3741 /// Build an empty clause.
3742 ///
3743 /// \param N Number of variables.
3744 explicit OMPPrivateClause(unsigned N)
3745 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
3746 SourceLocation(), SourceLocation(),
3747 SourceLocation(), N) {}
3748
3749 /// Sets the list of references to private copies with initializers for
3750 /// new private variables.
3751 /// \param VL List of references.
3752 void setPrivateCopies(ArrayRef<Expr *> VL);
3753
3754 /// Gets the list of references to private copies with initializers for
3755 /// new private variables.
3756 MutableArrayRef<Expr *> getPrivateCopies() {
3757 return {varlist_end(), varlist_size()};
3758 }
3759 ArrayRef<const Expr *> getPrivateCopies() const {
3760 return {varlist_end(), varlist_size()};
3761 }
3762
3763public:
3764 /// Creates clause with a list of variables \a VL.
3765 ///
3766 /// \param C AST context.
3767 /// \param StartLoc Starting location of the clause.
3768 /// \param LParenLoc Location of '('.
3769 /// \param EndLoc Ending location of the clause.
3770 /// \param VL List of references to the variables.
3771 /// \param PrivateVL List of references to private copies with initializers.
3772 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
3773 SourceLocation LParenLoc,
3774 SourceLocation EndLoc, ArrayRef<Expr *> VL,
3775 ArrayRef<Expr *> PrivateVL);
3776
3777 /// Creates an empty clause with the place for \a N variables.
3778 ///
3779 /// \param C AST context.
3780 /// \param N The number of variables.
3781 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3782
3783 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
3784 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
3785 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
3786 using private_copies_const_range =
3787 llvm::iterator_range<private_copies_const_iterator>;
3788
3789 private_copies_range private_copies() { return getPrivateCopies(); }
3790
3791 private_copies_const_range private_copies() const {
3792 return getPrivateCopies();
3793 }
3794
3795 child_range children() {
3796 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3797 reinterpret_cast<Stmt **>(varlist_end()));
3798 }
3799
3800 const_child_range children() const {
3801 return const_cast<OMPPrivateClause *>(this)->children();
3802 }
3803
3804 child_range used_children() {
3805 return child_range(child_iterator(), child_iterator());
3806 }
3807 const_child_range used_children() const {
3808 return const_child_range(const_child_iterator(), const_child_iterator());
3809 }
3810
3811 static bool classof(const OMPClause *T) {
3812 return T->getClauseKind() == llvm::omp::OMPC_private;
3813 }
3814};
3815
3816/// This represents clause 'firstprivate' in the '#pragma omp ...'
3817/// directives.
3818///
3819/// \code
3820/// #pragma omp parallel firstprivate(a,b)
3821/// \endcode
3822/// In this example directive '#pragma omp parallel' has clause 'firstprivate'
3823/// with the variables 'a' and 'b'.
3824class OMPFirstprivateClause final
3825 : public OMPVarListClause<OMPFirstprivateClause>,
3826 public OMPClauseWithPreInit,
3827 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
3828 friend class OMPClauseReader;
3829 friend OMPVarListClause;
3830 friend TrailingObjects;
3831
3832 /// Build clause with number of variables \a N.
3833 ///
3834 /// \param StartLoc Starting location of the clause.
3835 /// \param LParenLoc Location of '('.
3836 /// \param EndLoc Ending location of the clause.
3837 /// \param N Number of the variables in the clause.
3838 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3839 SourceLocation EndLoc, unsigned N)
3840 : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
3841 StartLoc, LParenLoc, EndLoc, N),
3842 OMPClauseWithPreInit(this) {}
3843
3844 /// Build an empty clause.
3845 ///
3846 /// \param N Number of variables.
3847 explicit OMPFirstprivateClause(unsigned N)
3848 : OMPVarListClause<OMPFirstprivateClause>(
3849 llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
3850 SourceLocation(), N),
3851 OMPClauseWithPreInit(this) {}
3852
3853 /// Sets the list of references to private copies with initializers for
3854 /// new private variables.
3855 /// \param VL List of references.
3856 void setPrivateCopies(ArrayRef<Expr *> VL);
3857
3858 /// Gets the list of references to private copies with initializers for
3859 /// new private variables.
3860 MutableArrayRef<Expr *> getPrivateCopies() {
3861 return {varlist_end(), varlist_size()};
3862 }
3863 ArrayRef<const Expr *> getPrivateCopies() const {
3864 return {varlist_end(), varlist_size()};
3865 }
3866
3867 /// Sets the list of references to initializer variables for new
3868 /// private variables.
3869 /// \param VL List of references.
3870 void setInits(ArrayRef<Expr *> VL);
3871
3872 /// Gets the list of references to initializer variables for new
3873 /// private variables.
3874 MutableArrayRef<Expr *> getInits() {
3875 return {getPrivateCopies().end(), varlist_size()};
3876 }
3877 ArrayRef<const Expr *> getInits() const {
3878 return {getPrivateCopies().end(), varlist_size()};
3879 }
3880
3881public:
3882 /// Creates clause with a list of variables \a VL.
3883 ///
3884 /// \param C AST context.
3885 /// \param StartLoc Starting location of the clause.
3886 /// \param LParenLoc Location of '('.
3887 /// \param EndLoc Ending location of the clause.
3888 /// \param VL List of references to the original variables.
3889 /// \param PrivateVL List of references to private copies with initializers.
3890 /// \param InitVL List of references to auto generated variables used for
3891 /// initialization of a single array element. Used if firstprivate variable is
3892 /// of array type.
3893 /// \param PreInit Statement that must be executed before entering the OpenMP
3894 /// region with this clause.
3895 static OMPFirstprivateClause *
3896 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3897 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
3898 ArrayRef<Expr *> InitVL, Stmt *PreInit);
3899
3900 /// Creates an empty clause with the place for \a N variables.
3901 ///
3902 /// \param C AST context.
3903 /// \param N The number of variables.
3904 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3905
3906 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
3907 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
3908 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
3909 using private_copies_const_range =
3910 llvm::iterator_range<private_copies_const_iterator>;
3911
3912 private_copies_range private_copies() { return getPrivateCopies(); }
3913 private_copies_const_range private_copies() const {
3914 return getPrivateCopies();
3915 }
3916
3917 using inits_iterator = MutableArrayRef<Expr *>::iterator;
3918 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
3919 using inits_range = llvm::iterator_range<inits_iterator>;
3920 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3921
3922 inits_range inits() { return getInits(); }
3923 inits_const_range inits() const { return getInits(); }
3924
3925 child_range children() {
3926 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3927 reinterpret_cast<Stmt **>(varlist_end()));
3928 }
3929
3930 const_child_range children() const {
3931 return const_cast<OMPFirstprivateClause *>(this)->children();
3932 }
3933
3934 child_range used_children() {
3935 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3936 reinterpret_cast<Stmt **>(varlist_end()));
3937 }
3938 const_child_range used_children() const {
3939 return const_cast<OMPFirstprivateClause *>(this)->used_children();
3940 }
3941
3942 static bool classof(const OMPClause *T) {
3943 return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
3944 }
3945};
3946
3947/// This represents clause 'lastprivate' in the '#pragma omp ...'
3948/// directives.
3949///
3950/// \code
3951/// #pragma omp simd lastprivate(a,b)
3952/// \endcode
3953/// In this example directive '#pragma omp simd' has clause 'lastprivate'
3954/// with the variables 'a' and 'b'.
3955class OMPLastprivateClause final
3956 : public OMPVarListClause<OMPLastprivateClause>,
3958 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
3959 // There are 4 additional tail-allocated arrays at the end of the class:
3960 // 1. Contains list of pseudo variables with the default initialization for
3961 // each non-firstprivate variables. Used in codegen for initialization of
3962 // lastprivate copies.
3963 // 2. List of helper expressions for proper generation of assignment operation
3964 // required for lastprivate clause. This list represents private variables
3965 // (for arrays, single array element).
3966 // 3. List of helper expressions for proper generation of assignment operation
3967 // required for lastprivate clause. This list represents original variables
3968 // (for arrays, single array element).
3969 // 4. List of helper expressions that represents assignment operation:
3970 // \code
3971 // DstExprs = SrcExprs;
3972 // \endcode
3973 // Required for proper codegen of final assignment performed by the
3974 // lastprivate clause.
3975 friend class OMPClauseReader;
3976 friend OMPVarListClause;
3977 friend TrailingObjects;
3978
3979 /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
3981 /// Optional location of the lasptrivate kind, if specified by user.
3982 SourceLocation LPKindLoc;
3983 /// Optional colon location, if specified by user.
3984 SourceLocation ColonLoc;
3985
3986 /// Build clause with number of variables \a N.
3987 ///
3988 /// \param StartLoc Starting location of the clause.
3989 /// \param LParenLoc Location of '('.
3990 /// \param EndLoc Ending location of the clause.
3991 /// \param N Number of the variables in the clause.
3992 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3993 SourceLocation EndLoc, OpenMPLastprivateModifier LPKind,
3994 SourceLocation LPKindLoc, SourceLocation ColonLoc,
3995 unsigned N)
3996 : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
3997 StartLoc, LParenLoc, EndLoc, N),
3998 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
3999 ColonLoc(ColonLoc) {}
4000
4001 /// Build an empty clause.
4002 ///
4003 /// \param N Number of variables.
4004 explicit OMPLastprivateClause(unsigned N)
4005 : OMPVarListClause<OMPLastprivateClause>(
4006 llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
4007 SourceLocation(), N),
4008 OMPClauseWithPostUpdate(this) {}
4009
4010 /// Get the list of helper expressions for initialization of private
4011 /// copies for lastprivate variables.
4012 MutableArrayRef<Expr *> getPrivateCopies() {
4013 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4014 }
4015 ArrayRef<const Expr *> getPrivateCopies() const {
4016 return {varlist_end(), varlist_size()};
4017 }
4018
4019 /// Set list of helper expressions, required for proper codegen of the
4020 /// clause. These expressions represent private variables (for arrays, single
4021 /// array element) in the final assignment statement performed by the
4022 /// lastprivate clause.
4023 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4024
4025 /// Get the list of helper source expressions.
4026 MutableArrayRef<Expr *> getSourceExprs() {
4027 return {getPrivateCopies().end(), varlist_size()};
4028 }
4029 ArrayRef<const Expr *> getSourceExprs() const {
4030 return {getPrivateCopies().end(), varlist_size()};
4031 }
4032
4033 /// Set list of helper expressions, required for proper codegen of the
4034 /// clause. These expressions represent original variables (for arrays, single
4035 /// array element) in the final assignment statement performed by the
4036 /// lastprivate clause.
4037 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4038
4039 /// Get the list of helper destination expressions.
4040 MutableArrayRef<Expr *> getDestinationExprs() {
4041 return {getSourceExprs().end(), varlist_size()};
4042 }
4043 ArrayRef<const Expr *> getDestinationExprs() const {
4044 return {getSourceExprs().end(), varlist_size()};
4045 }
4046
4047 /// Set list of helper assignment expressions, required for proper
4048 /// codegen of the clause. These expressions are assignment expressions that
4049 /// assign private copy of the variable to original variable.
4050 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4051
4052 /// Get the list of helper assignment expressions.
4053 MutableArrayRef<Expr *> getAssignmentOps() {
4054 return {getDestinationExprs().end(), varlist_size()};
4055 }
4056 ArrayRef<const Expr *> getAssignmentOps() const {
4057 return {getDestinationExprs().end(), varlist_size()};
4058 }
4059
4060 /// Sets lastprivate kind.
4061 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
4062 /// Sets location of the lastprivate kind.
4063 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
4064 /// Sets colon symbol location.
4065 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4066
4067public:
4068 /// Creates clause with a list of variables \a VL.
4069 ///
4070 /// \param C AST context.
4071 /// \param StartLoc Starting location of the clause.
4072 /// \param LParenLoc Location of '('.
4073 /// \param EndLoc Ending location of the clause.
4074 /// \param VL List of references to the variables.
4075 /// \param SrcExprs List of helper expressions for proper generation of
4076 /// assignment operation required for lastprivate clause. This list represents
4077 /// private variables (for arrays, single array element).
4078 /// \param DstExprs List of helper expressions for proper generation of
4079 /// assignment operation required for lastprivate clause. This list represents
4080 /// original variables (for arrays, single array element).
4081 /// \param AssignmentOps List of helper expressions that represents assignment
4082 /// operation:
4083 /// \code
4084 /// DstExprs = SrcExprs;
4085 /// \endcode
4086 /// Required for proper codegen of final assignment performed by the
4087 /// lastprivate clause.
4088 /// \param LPKind Lastprivate kind, e.g. 'conditional'.
4089 /// \param LPKindLoc Location of the lastprivate kind.
4090 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
4091 /// \param PreInit Statement that must be executed before entering the OpenMP
4092 /// region with this clause.
4093 /// \param PostUpdate Expression that must be executed after exit from the
4094 /// OpenMP region with this clause.
4095 static OMPLastprivateClause *
4096 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4097 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4098 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
4099 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
4100 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
4101
4102 /// Creates an empty clause with the place for \a N variables.
4103 ///
4104 /// \param C AST context.
4105 /// \param N The number of variables.
4106 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
4107
4108 /// Lastprivate kind.
4109 OpenMPLastprivateModifier getKind() const { return LPKind; }
4110 /// Returns the location of the lastprivate kind.
4111 SourceLocation getKindLoc() const { return LPKindLoc; }
4112 /// Returns the location of the ':' symbol, if any.
4113 SourceLocation getColonLoc() const { return ColonLoc; }
4114
4115 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4116 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4117 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4118 using helper_expr_const_range =
4119 llvm::iterator_range<helper_expr_const_iterator>;
4120
4121 /// Set list of helper expressions, required for generation of private
4122 /// copies of original lastprivate variables.
4123 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
4124
4125 helper_expr_const_range private_copies() const { return getPrivateCopies(); }
4126
4127 helper_expr_range private_copies() { return getPrivateCopies(); }
4128
4129 helper_expr_const_range source_exprs() const { return getSourceExprs(); }
4130
4131 helper_expr_range source_exprs() { return getSourceExprs(); }
4132
4133 helper_expr_const_range destination_exprs() const {
4134 return getDestinationExprs();
4135 }
4136
4137 helper_expr_range destination_exprs() { return getDestinationExprs(); }
4138
4139 helper_expr_const_range assignment_ops() const { return getAssignmentOps(); }
4140
4141 helper_expr_range assignment_ops() { return getAssignmentOps(); }
4142
4143 child_range children() {
4144 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4145 reinterpret_cast<Stmt **>(varlist_end()));
4146 }
4147
4148 const_child_range children() const {
4149 return const_cast<OMPLastprivateClause *>(this)->children();
4150 }
4151
4152 child_range used_children() {
4153 return child_range(child_iterator(), child_iterator());
4154 }
4155 const_child_range used_children() const {
4156 return const_child_range(const_child_iterator(), const_child_iterator());
4157 }
4158
4159 static bool classof(const OMPClause *T) {
4160 return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
4161 }
4162};
4163
4164/// This represents clause 'shared' in the '#pragma omp ...' directives.
4165///
4166/// \code
4167/// #pragma omp parallel shared(a,b)
4168/// \endcode
4169/// In this example directive '#pragma omp parallel' has clause 'shared'
4170/// with the variables 'a' and 'b'.
4171class OMPSharedClause final
4172 : public OMPVarListClause<OMPSharedClause>,
4173 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
4174 friend OMPVarListClause;
4175 friend TrailingObjects;
4176
4177 /// Build clause with number of variables \a N.
4178 ///
4179 /// \param StartLoc Starting location of the clause.
4180 /// \param LParenLoc Location of '('.
4181 /// \param EndLoc Ending location of the clause.
4182 /// \param N Number of the variables in the clause.
4183 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4184 SourceLocation EndLoc, unsigned N)
4185 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
4186 LParenLoc, EndLoc, N) {}
4187
4188 /// Build an empty clause.
4189 ///
4190 /// \param N Number of variables.
4191 explicit OMPSharedClause(unsigned N)
4192 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
4193 SourceLocation(), SourceLocation(),
4194 SourceLocation(), N) {}
4195
4196public:
4197 /// Creates clause with a list of variables \a VL.
4198 ///
4199 /// \param C AST context.
4200 /// \param StartLoc Starting location of the clause.
4201 /// \param LParenLoc Location of '('.
4202 /// \param EndLoc Ending location of the clause.
4203 /// \param VL List of references to the variables.
4204 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
4205 SourceLocation LParenLoc,
4206 SourceLocation EndLoc, ArrayRef<Expr *> VL);
4207
4208 /// Creates an empty clause with \a N variables.
4209 ///
4210 /// \param C AST context.
4211 /// \param N The number of variables.
4212 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
4213
4214 child_range children() {
4215 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4216 reinterpret_cast<Stmt **>(varlist_end()));
4217 }
4218
4219 const_child_range children() const {
4220 return const_cast<OMPSharedClause *>(this)->children();
4221 }
4222
4223 child_range used_children() {
4224 return child_range(child_iterator(), child_iterator());
4225 }
4226 const_child_range used_children() const {
4227 return const_child_range(const_child_iterator(), const_child_iterator());
4228 }
4229
4230 static bool classof(const OMPClause *T) {
4231 return T->getClauseKind() == llvm::omp::OMPC_shared;
4232 }
4233};
4234
4235/// This represents clause 'reduction' in the '#pragma omp ...'
4236/// directives.
4237///
4238/// \code
4239/// #pragma omp parallel reduction(+:a,b)
4240/// \endcode
4241/// In this example directive '#pragma omp parallel' has clause 'reduction'
4242/// with operator '+' and the variables 'a' and 'b'.
4243class OMPReductionClause final
4244 : public OMPVarListClause<OMPReductionClause>,
4246 private llvm::TrailingObjects<OMPReductionClause, Expr *, bool> {
4247 friend class OMPClauseReader;
4248 friend OMPVarListClause;
4249 friend TrailingObjects;
4250
4251 /// Reduction modifier.
4253
4254 /// Original Sharing modifier.
4255 OpenMPOriginalSharingModifier OriginalSharingModifier =
4256 OMPC_ORIGINAL_SHARING_default;
4257
4258 /// Reduction modifier location.
4259 SourceLocation ModifierLoc;
4260
4261 /// Location of ':'.
4262 SourceLocation ColonLoc;
4263
4264 /// Nested name specifier for C++.
4265 NestedNameSpecifierLoc QualifierLoc;
4266
4267 /// Name of custom operator.
4268 DeclarationNameInfo NameInfo;
4269
4270 /// Build clause with number of variables \a N.
4271 ///
4272 /// \param StartLoc Starting location of the clause.
4273 /// \param LParenLoc Location of '('.
4274 /// \param ModifierLoc Modifier location.
4275 /// \param ColonLoc Location of ':'.
4276 /// \param EndLoc Ending location of the clause.
4277 /// \param N Number of the variables in the clause.
4278 /// \param QualifierLoc The nested-name qualifier with location information
4279 /// \param NameInfo The full name info for reduction identifier.
4280 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4281 SourceLocation ModifierLoc, SourceLocation ColonLoc,
4282 SourceLocation EndLoc,
4283 OpenMPReductionClauseModifier Modifier,
4284 OpenMPOriginalSharingModifier OriginalSharingModifier,
4285 unsigned N, NestedNameSpecifierLoc QualifierLoc,
4286 const DeclarationNameInfo &NameInfo)
4287 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
4288 StartLoc, LParenLoc, EndLoc, N),
4289 OMPClauseWithPostUpdate(this), Modifier(Modifier),
4290 OriginalSharingModifier(OriginalSharingModifier),
4291 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
4292 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
4293
4294 /// Build an empty clause.
4295 ///
4296 /// \param N Number of variables.
4297 explicit OMPReductionClause(unsigned N)
4298 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
4299 SourceLocation(), SourceLocation(),
4300 SourceLocation(), N),
4301 OMPClauseWithPostUpdate(this) {}
4302
4303 /// Sets reduction modifier.
4304 void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
4305
4306 /// Sets Original Sharing modifier.
4307 void setOriginalSharingModifier(OpenMPOriginalSharingModifier M) {
4308 OriginalSharingModifier = M;
4309 }
4310
4311 /// Sets location of the modifier.
4312 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4313
4314 /// Sets location of ':' symbol in clause.
4315 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
4316
4317 /// Sets the name info for specified reduction identifier.
4318 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
4319
4320 /// Sets the nested name specifier.
4321 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
4322
4323 /// Set list of helper expressions, required for proper codegen of the
4324 /// clause. These expressions represent private copy of the reduction
4325 /// variable.
4326 void setPrivates(ArrayRef<Expr *> Privates);
4327
4328 /// Get the list of helper privates.
4329 MutableArrayRef<Expr *> getPrivates() {
4330 return {varlist_end(), varlist_size()};
4331 }
4332 ArrayRef<const Expr *> getPrivates() const {
4333 return {varlist_end(), varlist_size()};
4334 }
4335
4336 /// Set list of helper expressions, required for proper codegen of the
4337 /// clause. These expressions represent LHS expression in the final
4338 /// reduction expression performed by the reduction clause.
4339 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
4340
4341 /// Get the list of helper LHS expressions.
4342 MutableArrayRef<Expr *> getLHSExprs() {
4343 return {getPrivates().end(), varlist_size()};
4344 }
4345 ArrayRef<const Expr *> getLHSExprs() const {
4346 return {getPrivates().end(), varlist_size()};
4347 }
4348
4349 /// Set list of helper expressions, required for proper codegen of the
4350 /// clause. These expressions represent RHS expression in the final
4351 /// reduction expression performed by the reduction clause.
4352 /// Also, variables in these expressions are used for proper initialization of
4353 /// reduction copies.
4354 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
4355
4356 /// Set the list private reduction flags
4357 void setPrivateVariableReductionFlags(ArrayRef<bool> Flags) {
4358 assert(Flags.size() == varlist_size() &&
4359 "Number of private flags does not match vars");
4360 llvm::copy(Flags, getTrailingObjects<bool>());
4361 }
4362
4363 /// Get the list of help private variable reduction flags
4364 MutableArrayRef<bool> getPrivateVariableReductionFlags() {
4365 return getTrailingObjects<bool>(varlist_size());
4366 }
4367 ArrayRef<bool> getPrivateVariableReductionFlags() const {
4368 return getTrailingObjects<bool>(varlist_size());
4369 }
4370
4371 /// Returns the number of Expr* objects in trailing storage
4372 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4373 return varlist_size() * (Modifier == OMPC_REDUCTION_inscan ? 8 : 5);
4374 }
4375
4376 /// Returns the number of bool flags in trailing storage
4377 size_t numTrailingObjects(OverloadToken<bool>) const {
4378 return varlist_size();
4379 }
4380
4381 /// Get the list of helper destination expressions.
4382 MutableArrayRef<Expr *> getRHSExprs() {
4383 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
4384 }
4385 ArrayRef<const Expr *> getRHSExprs() const {
4386 return {getLHSExprs().end(), varlist_size()};
4387 }
4388
4389 /// Set list of helper reduction expressions, required for proper
4390 /// codegen of the clause. These expressions are binary expressions or
4391 /// operator/custom reduction call that calculates new value from source
4392 /// helper expressions to destination helper expressions.
4393 void setReductionOps(ArrayRef<Expr *> ReductionOps);
4394
4395 /// Get the list of helper reduction expressions.
4396 MutableArrayRef<Expr *> getReductionOps() {
4397 return {getRHSExprs().end(), varlist_size()};
4398 }
4399 ArrayRef<const Expr *> getReductionOps() const {
4400 return {getRHSExprs().end(), varlist_size()};
4401 }
4402
4403 /// Set list of helper copy operations for inscan reductions.
4404 /// The form is: Temps[i] = LHS[i];
4405 void setInscanCopyOps(ArrayRef<Expr *> Ops);
4406
4407 /// Get the list of helper inscan copy operations.
4408 MutableArrayRef<Expr *> getInscanCopyOps() {
4409 return {getReductionOps().end(), varlist_size()};
4410 }
4411 ArrayRef<const Expr *> getInscanCopyOps() const {
4412 return {getReductionOps().end(), varlist_size()};
4413 }
4414
4415 /// Set list of helper temp vars for inscan copy array operations.
4416 void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
4417
4418 /// Get the list of helper inscan copy temps.
4419 MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
4420 return {getInscanCopyOps().end(), varlist_size()};
4421 }
4422 ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
4423 return {getInscanCopyOps().end(), varlist_size()};
4424 }
4425
4426 /// Set list of helper temp elements vars for inscan copy array operations.
4427 void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
4428
4429 /// Get the list of helper inscan copy temps.
4430 MutableArrayRef<Expr *> getInscanCopyArrayElems() {
4431 return {getInscanCopyArrayTemps().end(), varlist_size()};
4432 }
4433 ArrayRef<const Expr *> getInscanCopyArrayElems() const {
4434 return {getInscanCopyArrayTemps().end(), varlist_size()};
4435 }
4436
4437public:
4438 /// Creates clause with a list of variables \a VL.
4439 ///
4440 /// \param StartLoc Starting location of the clause.
4441 /// \param LParenLoc Location of '('.
4442 /// \param ModifierLoc Modifier location.
4443 /// \param ColonLoc Location of ':'.
4444 /// \param EndLoc Ending location of the clause.
4445 /// \param VL The variables in the clause.
4446 /// \param QualifierLoc The nested-name qualifier with location information
4447 /// \param NameInfo The full name info for reduction identifier.
4448 /// \param Privates List of helper expressions for proper generation of
4449 /// private copies.
4450 /// \param LHSExprs List of helper expressions for proper generation of
4451 /// assignment operation required for copyprivate clause. This list represents
4452 /// LHSs of the reduction expressions.
4453 /// \param RHSExprs List of helper expressions for proper generation of
4454 /// assignment operation required for copyprivate clause. This list represents
4455 /// RHSs of the reduction expressions.
4456 /// Also, variables in these expressions are used for proper initialization of
4457 /// reduction copies.
4458 /// \param ReductionOps List of helper expressions that represents reduction
4459 /// expressions:
4460 /// \code
4461 /// LHSExprs binop RHSExprs;
4462 /// operator binop(LHSExpr, RHSExpr);
4463 /// <CutomReduction>(LHSExpr, RHSExpr);
4464 /// \endcode
4465 /// Required for proper codegen of final reduction operation performed by the
4466 /// reduction clause.
4467 /// \param CopyOps List of copy operations for inscan reductions:
4468 /// \code
4469 /// TempExprs = LHSExprs;
4470 /// \endcode
4471 /// \param CopyArrayTemps Temp arrays for prefix sums.
4472 /// \param CopyArrayElems Temp arrays for prefix sums.
4473 /// \param PreInit Statement that must be executed before entering the OpenMP
4474 /// region with this clause.
4475 /// \param PostUpdate Expression that must be executed after exit from the
4476 /// OpenMP region with this clause.
4477 /// \param IsPrivateVarReduction array for private variable reduction flags
4478 static OMPReductionClause *
4479 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4480 SourceLocation ModifierLoc, SourceLocation ColonLoc,
4481 SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
4482 ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
4483 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
4484 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
4485 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
4486 ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
4487 Stmt *PreInit, Expr *PostUpdate, ArrayRef<bool> IsPrivateVarReduction,
4488 OpenMPOriginalSharingModifier OriginalSharingModifier);
4489
4490 /// Creates an empty clause with the place for \a N variables.
4491 ///
4492 /// \param C AST context.
4493 /// \param N The number of variables.
4494 /// \param Modifier Reduction modifier.
4495 static OMPReductionClause *
4496 CreateEmpty(const ASTContext &C, unsigned N,
4497 OpenMPReductionClauseModifier Modifier);
4498
4499 /// Returns modifier.
4500 OpenMPReductionClauseModifier getModifier() const { return Modifier; }
4501
4502 /// Returns Original Sharing Modifier.
4503 OpenMPOriginalSharingModifier getOriginalSharingModifier() const {
4504 return OriginalSharingModifier;
4505 }
4506
4507 /// Returns modifier location.
4508 SourceLocation getModifierLoc() const { return ModifierLoc; }
4509
4510 /// Gets location of ':' symbol in clause.
4511 SourceLocation getColonLoc() const { return ColonLoc; }
4512
4513 /// Gets the name info for specified reduction identifier.
4514 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
4515
4516 /// Gets the nested name specifier.
4517 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4518
4519 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4520 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4521 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4522 using helper_expr_const_range =
4523 llvm::iterator_range<helper_expr_const_iterator>;
4524 using helper_flag_iterator = MutableArrayRef<bool>::iterator;
4525 using helper_flag_const_iterator = ArrayRef<bool>::iterator;
4526 using helper_flag_range = llvm::iterator_range<helper_flag_iterator>;
4527 using helper_flag_const_range =
4528 llvm::iterator_range<helper_flag_const_iterator>;
4529
4530 helper_expr_const_range privates() const { return getPrivates(); }
4531
4532 helper_expr_range privates() { return getPrivates(); }
4533
4534 helper_expr_const_range lhs_exprs() const { return getLHSExprs(); }
4535
4536 helper_expr_range lhs_exprs() { return getLHSExprs(); }
4537
4538 helper_expr_const_range rhs_exprs() const { return getRHSExprs(); }
4539
4540 helper_expr_range rhs_exprs() { return getRHSExprs(); }
4541
4542 helper_flag_const_range private_var_reduction_flags() const {
4543 return getPrivateVariableReductionFlags();
4544 }
4545
4546 helper_flag_range private_var_reduction_flags() {
4547 return getPrivateVariableReductionFlags();
4548 }
4549
4550 helper_expr_const_range reduction_ops() const { return getReductionOps(); }
4551
4552 helper_expr_range reduction_ops() { return getReductionOps(); }
4553
4554 helper_expr_const_range copy_ops() const { return getInscanCopyOps(); }
4555
4556 helper_expr_range copy_ops() { return getInscanCopyOps(); }
4557
4558 helper_expr_const_range copy_array_temps() const {
4559 return getInscanCopyArrayTemps();
4560 }
4561
4562 helper_expr_range copy_array_temps() { return getInscanCopyArrayTemps(); }
4563
4564 helper_expr_const_range copy_array_elems() const {
4565 return getInscanCopyArrayElems();
4566 }
4567
4568 helper_expr_range copy_array_elems() { return getInscanCopyArrayElems(); }
4569
4570 child_range children() {
4571 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4572 reinterpret_cast<Stmt **>(varlist_end()));
4573 }
4574
4575 const_child_range children() const {
4576 return const_cast<OMPReductionClause *>(this)->children();
4577 }
4578
4579 child_range used_children() {
4580 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4581 reinterpret_cast<Stmt **>(varlist_end()));
4582 }
4583 const_child_range used_children() const {
4584 return const_cast<OMPReductionClause *>(this)->used_children();
4585 }
4586
4587 static bool classof(const OMPClause *T) {
4588 return T->getClauseKind() == llvm::omp::OMPC_reduction;
4589 }
4590};
4591
4592/// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
4593/// directives.
4594///
4595/// \code
4596/// #pragma omp taskgroup task_reduction(+:a,b)
4597/// \endcode
4598/// In this example directive '#pragma omp taskgroup' has clause
4599/// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
4600class OMPTaskReductionClause final
4601 : public OMPVarListClause<OMPTaskReductionClause>,
4603 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
4604 friend class OMPClauseReader;
4605 friend OMPVarListClause;
4606 friend TrailingObjects;
4607
4608 /// Location of ':'.
4609 SourceLocation ColonLoc;
4610
4611 /// Nested name specifier for C++.
4612 NestedNameSpecifierLoc QualifierLoc;
4613
4614 /// Name of custom operator.
4615 DeclarationNameInfo NameInfo;
4616
4617 /// Build clause with number of variables \a N.
4618 ///
4619 /// \param StartLoc Starting location of the clause.
4620 /// \param LParenLoc Location of '('.
4621 /// \param EndLoc Ending location of the clause.
4622 /// \param ColonLoc Location of ':'.
4623 /// \param N Number of the variables in the clause.
4624 /// \param QualifierLoc The nested-name qualifier with location information
4625 /// \param NameInfo The full name info for reduction identifier.
4626 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4627 SourceLocation ColonLoc, SourceLocation EndLoc,
4628 unsigned N, NestedNameSpecifierLoc QualifierLoc,
4629 const DeclarationNameInfo &NameInfo)
4630 : OMPVarListClause<OMPTaskReductionClause>(
4631 llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
4632 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
4633 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
4634
4635 /// Build an empty clause.
4636 ///
4637 /// \param N Number of variables.
4638 explicit OMPTaskReductionClause(unsigned N)
4639 : OMPVarListClause<OMPTaskReductionClause>(
4640 llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
4641 SourceLocation(), N),
4642 OMPClauseWithPostUpdate(this) {}
4643
4644 /// Sets location of ':' symbol in clause.
4645 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
4646
4647 /// Sets the name info for specified reduction identifier.
4648 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
4649
4650 /// Sets the nested name specifier.
4651 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
4652
4653 /// Set list of helper expressions, required for proper codegen of the clause.
4654 /// These expressions represent private copy of the reduction variable.
4655 void setPrivates(ArrayRef<Expr *> Privates);
4656
4657 /// Get the list of helper privates.
4658 MutableArrayRef<Expr *> getPrivates() {
4659 return {varlist_end(), varlist_size()};
4660 }
4661 ArrayRef<const Expr *> getPrivates() const {
4662 return {varlist_end(), varlist_size()};
4663 }
4664
4665 /// Set list of helper expressions, required for proper codegen of the clause.
4666 /// These expressions represent LHS expression in the final reduction
4667 /// expression performed by the reduction clause.
4668 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
4669
4670 /// Get the list of helper LHS expressions.
4671 MutableArrayRef<Expr *> getLHSExprs() {
4672 return {getPrivates().end(), varlist_size()};
4673 }
4674 ArrayRef<const Expr *> getLHSExprs() const {
4675 return {getPrivates().end(), varlist_size()};
4676 }
4677
4678 /// Set list of helper expressions, required for proper codegen of the clause.
4679 /// These expressions represent RHS expression in the final reduction
4680 /// expression performed by the reduction clause. Also, variables in these
4681 /// expressions are used for proper initialization of reduction copies.
4682 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
4683
4684 /// Get the list of helper destination expressions.
4685 MutableArrayRef<Expr *> getRHSExprs() {
4686 return {getLHSExprs().end(), varlist_size()};
4687 }
4688 ArrayRef<const Expr *> getRHSExprs() const {
4689 return {getLHSExprs().end(), varlist_size()};
4690 }
4691
4692 /// Set list of helper reduction expressions, required for proper
4693 /// codegen of the clause. These expressions are binary expressions or
4694 /// operator/custom reduction call that calculates new value from source
4695 /// helper expressions to destination helper expressions.
4696 void setReductionOps(ArrayRef<Expr *> ReductionOps);
4697
4698 /// Get the list of helper reduction expressions.
4699 MutableArrayRef<Expr *> getReductionOps() {
4700 return {getRHSExprs().end(), varlist_size()};
4701 }
4702 ArrayRef<const Expr *> getReductionOps() const {
4703 return {getRHSExprs().end(), varlist_size()};
4704 }
4705
4706public:
4707 /// Creates clause with a list of variables \a VL.
4708 ///
4709 /// \param StartLoc Starting location of the clause.
4710 /// \param LParenLoc Location of '('.
4711 /// \param ColonLoc Location of ':'.
4712 /// \param EndLoc Ending location of the clause.
4713 /// \param VL The variables in the clause.
4714 /// \param QualifierLoc The nested-name qualifier with location information
4715 /// \param NameInfo The full name info for reduction identifier.
4716 /// \param Privates List of helper expressions for proper generation of
4717 /// private copies.
4718 /// \param LHSExprs List of helper expressions for proper generation of
4719 /// assignment operation required for copyprivate clause. This list represents
4720 /// LHSs of the reduction expressions.
4721 /// \param RHSExprs List of helper expressions for proper generation of
4722 /// assignment operation required for copyprivate clause. This list represents
4723 /// RHSs of the reduction expressions.
4724 /// Also, variables in these expressions are used for proper initialization of
4725 /// reduction copies.
4726 /// \param ReductionOps List of helper expressions that represents reduction
4727 /// expressions:
4728 /// \code
4729 /// LHSExprs binop RHSExprs;
4730 /// operator binop(LHSExpr, RHSExpr);
4731 /// <CutomReduction>(LHSExpr, RHSExpr);
4732 /// \endcode
4733 /// Required for proper codegen of final reduction operation performed by the
4734 /// reduction clause.
4735 /// \param PreInit Statement that must be executed before entering the OpenMP
4736 /// region with this clause.
4737 /// \param PostUpdate Expression that must be executed after exit from the
4738 /// OpenMP region with this clause.
4739 static OMPTaskReductionClause *
4740 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4741 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
4742 NestedNameSpecifierLoc QualifierLoc,
4743 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
4744 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
4745 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
4746
4747 /// Creates an empty clause with the place for \a N variables.
4748 ///
4749 /// \param C AST context.
4750 /// \param N The number of variables.
4751 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
4752
4753 /// Gets location of ':' symbol in clause.
4754 SourceLocation getColonLoc() const { return ColonLoc; }
4755
4756 /// Gets the name info for specified reduction identifier.
4757 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
4758
4759 /// Gets the nested name specifier.
4760 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4761
4762 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4763 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4764 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4765 using helper_expr_const_range =
4766 llvm::iterator_range<helper_expr_const_iterator>;
4767
4768 helper_expr_const_range privates() const { return getPrivates(); }
4769
4770 helper_expr_range privates() { return getPrivates(); }
4771
4772 helper_expr_const_range lhs_exprs() const { return getLHSExprs(); }
4773
4774 helper_expr_range lhs_exprs() { return getLHSExprs(); }
4775
4776 helper_expr_const_range rhs_exprs() const { return getRHSExprs(); }
4777
4778 helper_expr_range rhs_exprs() { return getRHSExprs(); }
4779
4780 helper_expr_const_range reduction_ops() const { return getReductionOps(); }
4781
4782 helper_expr_range reduction_ops() { return getReductionOps(); }
4783
4784 child_range children() {
4785 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4786 reinterpret_cast<Stmt **>(varlist_end()));
4787 }
4788
4789 const_child_range children() const {
4790 return const_cast<OMPTaskReductionClause *>(this)->children();
4791 }
4792
4793 child_range used_children() {
4794 return child_range(child_iterator(), child_iterator());
4795 }
4796 const_child_range used_children() const {
4797 return const_child_range(const_child_iterator(), const_child_iterator());
4798 }
4799
4800 static bool classof(const OMPClause *T) {
4801 return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
4802 }
4803};
4804
4805/// This represents clause 'in_reduction' in the '#pragma omp task' directives.
4806///
4807/// \code
4808/// #pragma omp task in_reduction(+:a,b)
4809/// \endcode
4810/// In this example directive '#pragma omp task' has clause 'in_reduction' with
4811/// operator '+' and the variables 'a' and 'b'.
4812class OMPInReductionClause final
4813 : public OMPVarListClause<OMPInReductionClause>,
4815 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
4816 friend class OMPClauseReader;
4817 friend OMPVarListClause;
4818 friend TrailingObjects;
4819
4820 /// Location of ':'.
4821 SourceLocation ColonLoc;
4822
4823 /// Nested name specifier for C++.
4824 NestedNameSpecifierLoc QualifierLoc;
4825
4826 /// Name of custom operator.
4827 DeclarationNameInfo NameInfo;
4828
4829 /// Build clause with number of variables \a N.
4830 ///
4831 /// \param StartLoc Starting location of the clause.
4832 /// \param LParenLoc Location of '('.
4833 /// \param EndLoc Ending location of the clause.
4834 /// \param ColonLoc Location of ':'.
4835 /// \param N Number of the variables in the clause.
4836 /// \param QualifierLoc The nested-name qualifier with location information
4837 /// \param NameInfo The full name info for reduction identifier.
4838 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4839 SourceLocation ColonLoc, SourceLocation EndLoc,
4840 unsigned N, NestedNameSpecifierLoc QualifierLoc,
4841 const DeclarationNameInfo &NameInfo)
4842 : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
4843 StartLoc, LParenLoc, EndLoc, N),
4844 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
4845 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
4846
4847 /// Build an empty clause.
4848 ///
4849 /// \param N Number of variables.
4850 explicit OMPInReductionClause(unsigned N)
4851 : OMPVarListClause<OMPInReductionClause>(
4852 llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
4853 SourceLocation(), N),
4854 OMPClauseWithPostUpdate(this) {}
4855
4856 /// Sets location of ':' symbol in clause.
4857 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
4858
4859 /// Sets the name info for specified reduction identifier.
4860 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
4861
4862 /// Sets the nested name specifier.
4863 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
4864
4865 /// Set list of helper expressions, required for proper codegen of the clause.
4866 /// These expressions represent private copy of the reduction variable.
4867 void setPrivates(ArrayRef<Expr *> Privates);
4868
4869 /// Get the list of helper privates.
4870 MutableArrayRef<Expr *> getPrivates() {
4871 return {varlist_end(), varlist_size()};
4872 }
4873 ArrayRef<const Expr *> getPrivates() const {
4874 return {varlist_end(), varlist_size()};
4875 }
4876
4877 /// Set list of helper expressions, required for proper codegen of the clause.
4878 /// These expressions represent LHS expression in the final reduction
4879 /// expression performed by the reduction clause.
4880 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
4881
4882 /// Get the list of helper LHS expressions.
4883 MutableArrayRef<Expr *> getLHSExprs() {
4884 return {getPrivates().end(), varlist_size()};
4885 }
4886 ArrayRef<const Expr *> getLHSExprs() const {
4887 return {getPrivates().end(), varlist_size()};
4888 }
4889
4890 /// Set list of helper expressions, required for proper codegen of the clause.
4891 /// These expressions represent RHS expression in the final reduction
4892 /// expression performed by the reduction clause. Also, variables in these
4893 /// expressions are used for proper initialization of reduction copies.
4894 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
4895
4896 /// Get the list of helper destination expressions.
4897 MutableArrayRef<Expr *> getRHSExprs() {
4898 return {getLHSExprs().end(), varlist_size()};
4899 }
4900 ArrayRef<const Expr *> getRHSExprs() const {
4901 return {getLHSExprs().end(), varlist_size()};
4902 }
4903
4904 /// Set list of helper reduction expressions, required for proper
4905 /// codegen of the clause. These expressions are binary expressions or
4906 /// operator/custom reduction call that calculates new value from source
4907 /// helper expressions to destination helper expressions.
4908 void setReductionOps(ArrayRef<Expr *> ReductionOps);
4909
4910 /// Get the list of helper reduction expressions.
4911 MutableArrayRef<Expr *> getReductionOps() {
4912 return {getRHSExprs().end(), varlist_size()};
4913 }
4914 ArrayRef<const Expr *> getReductionOps() const {
4915 return {getRHSExprs().end(), varlist_size()};
4916 }
4917
4918 /// Set list of helper reduction taskgroup descriptors.
4919 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
4920
4921 /// Get the list of helper reduction taskgroup descriptors.
4922 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
4923 return {getReductionOps().end(), varlist_size()};
4924 }
4925 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
4926 return {getReductionOps().end(), varlist_size()};
4927 }
4928
4929public:
4930 /// Creates clause with a list of variables \a VL.
4931 ///
4932 /// \param StartLoc Starting location of the clause.
4933 /// \param LParenLoc Location of '('.
4934 /// \param ColonLoc Location of ':'.
4935 /// \param EndLoc Ending location of the clause.
4936 /// \param VL The variables in the clause.
4937 /// \param QualifierLoc The nested-name qualifier with location information
4938 /// \param NameInfo The full name info for reduction identifier.
4939 /// \param Privates List of helper expressions for proper generation of
4940 /// private copies.
4941 /// \param LHSExprs List of helper expressions for proper generation of
4942 /// assignment operation required for copyprivate clause. This list represents
4943 /// LHSs of the reduction expressions.
4944 /// \param RHSExprs List of helper expressions for proper generation of
4945 /// assignment operation required for copyprivate clause. This list represents
4946 /// RHSs of the reduction expressions.
4947 /// Also, variables in these expressions are used for proper initialization of
4948 /// reduction copies.
4949 /// \param ReductionOps List of helper expressions that represents reduction
4950 /// expressions:
4951 /// \code
4952 /// LHSExprs binop RHSExprs;
4953 /// operator binop(LHSExpr, RHSExpr);
4954 /// <CutomReduction>(LHSExpr, RHSExpr);
4955 /// \endcode
4956 /// Required for proper codegen of final reduction operation performed by the
4957 /// reduction clause.
4958 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
4959 /// corresponding items in parent taskgroup task_reduction clause.
4960 /// \param PreInit Statement that must be executed before entering the OpenMP
4961 /// region with this clause.
4962 /// \param PostUpdate Expression that must be executed after exit from the
4963 /// OpenMP region with this clause.
4964 static OMPInReductionClause *
4965 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4966 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
4967 NestedNameSpecifierLoc QualifierLoc,
4968 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
4969 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
4970 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
4971 Stmt *PreInit, Expr *PostUpdate);
4972
4973 /// Creates an empty clause with the place for \a N variables.
4974 ///
4975 /// \param C AST context.
4976 /// \param N The number of variables.
4977 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
4978
4979 /// Gets location of ':' symbol in clause.
4980 SourceLocation getColonLoc() const { return ColonLoc; }
4981
4982 /// Gets the name info for specified reduction identifier.
4983 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
4984
4985 /// Gets the nested name specifier.
4986 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4987
4988 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4989 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4990 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4991 using helper_expr_const_range =
4992 llvm::iterator_range<helper_expr_const_iterator>;
4993
4994 helper_expr_const_range privates() const { return getPrivates(); }
4995
4996 helper_expr_range privates() { return getPrivates(); }
4997
4998 helper_expr_const_range lhs_exprs() const { return getLHSExprs(); }
4999
5000 helper_expr_range lhs_exprs() { return getLHSExprs(); }
5001
5002 helper_expr_const_range rhs_exprs() const { return getRHSExprs(); }
5003
5004 helper_expr_range rhs_exprs() { return getRHSExprs(); }
5005
5006 helper_expr_const_range reduction_ops() const { return getReductionOps(); }
5007
5008 helper_expr_range reduction_ops() { return getReductionOps(); }
5009
5010 helper_expr_const_range taskgroup_descriptors() const {
5011 return getTaskgroupDescriptors();
5012 }
5013
5014 helper_expr_range taskgroup_descriptors() {
5015 return getTaskgroupDescriptors();
5016 }
5017
5018 child_range children() {
5019 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5020 reinterpret_cast<Stmt **>(varlist_end()));
5021 }
5022
5023 const_child_range children() const {
5024 return const_cast<OMPInReductionClause *>(this)->children();
5025 }
5026
5027 child_range used_children() {
5028 return child_range(child_iterator(), child_iterator());
5029 }
5030 const_child_range used_children() const {
5031 return const_child_range(const_child_iterator(), const_child_iterator());
5032 }
5033
5034 static bool classof(const OMPClause *T) {
5035 return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
5036 }
5037};
5038
5039/// This represents clause 'linear' in the '#pragma omp ...'
5040/// directives.
5041///
5042/// \code
5043/// #pragma omp simd linear(a,b : 2)
5044/// \endcode
5045/// In this example directive '#pragma omp simd' has clause 'linear'
5046/// with variables 'a', 'b' and linear step '2'.
5047class OMPLinearClause final
5048 : public OMPVarListClause<OMPLinearClause>,
5050 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
5051 friend class OMPClauseReader;
5052 friend OMPVarListClause;
5053 friend TrailingObjects;
5054
5055 /// Modifier of 'linear' clause.
5056 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
5057
5058 /// Location of linear modifier if any.
5059 SourceLocation ModifierLoc;
5060
5061 /// Location of ':'.
5062 SourceLocation ColonLoc;
5063
5064 /// Location of 'step' modifier.
5065 SourceLocation StepModifierLoc;
5066
5067 /// Sets the linear step for clause.
5068 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
5069
5070 /// Sets the expression to calculate linear step for clause.
5071 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
5072
5073 /// Build 'linear' clause with given number of variables \a NumVars.
5074 ///
5075 /// \param StartLoc Starting location of the clause.
5076 /// \param LParenLoc Location of '('.
5077 /// \param ColonLoc Location of ':'.
5078 /// \param StepModifierLoc Location of 'step' modifier.
5079 /// \param EndLoc Ending location of the clause.
5080 /// \param NumVars Number of variables.
5081 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5082 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
5083 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
5084 SourceLocation EndLoc, unsigned NumVars)
5085 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
5086 LParenLoc, EndLoc, NumVars),
5087 OMPClauseWithPostUpdate(this), Modifier(Modifier),
5088 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
5089 StepModifierLoc(StepModifierLoc) {}
5090
5091 /// Build an empty clause.
5092 ///
5093 /// \param NumVars Number of variables.
5094 explicit OMPLinearClause(unsigned NumVars)
5095 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
5096 SourceLocation(), SourceLocation(),
5097 SourceLocation(), NumVars),
5098 OMPClauseWithPostUpdate(this) {}
5099
5100 /// Gets the list of initial values for linear variables.
5101 ///
5102 /// There are NumVars expressions with initial values allocated after the
5103 /// varlist, they are followed by NumVars update expressions (used to update
5104 /// the linear variable's value on current iteration) and they are followed by
5105 /// NumVars final expressions (used to calculate the linear variable's
5106 /// value after the loop body). After these lists, there are 2 helper
5107 /// expressions - linear step and a helper to calculate it before the
5108 /// loop body (used when the linear step is not constant):
5109 ///
5110 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
5111 /// Finals[]; Step; CalcStep; }
5113 return {varlist_end(), varlist_size()};
5114 }
5115 ArrayRef<const Expr *> getPrivates() const {
5116 return {varlist_end(), varlist_size()};
5117 }
5118
5120 return {getPrivates().end(), varlist_size()};
5121 }
5122 ArrayRef<const Expr *> getInits() const {
5123 return {getPrivates().end(), varlist_size()};
5124 }
5125
5126 /// Sets the list of update expressions for linear variables.
5128 return {getInits().end(), varlist_size()};
5129 }
5130 ArrayRef<const Expr *> getUpdates() const {
5131 return {getInits().end(), varlist_size()};
5132 }
5133
5134 /// Sets the list of final update expressions for linear variables.
5136 return {getUpdates().end(), varlist_size()};
5137 }
5138 ArrayRef<const Expr *> getFinals() const {
5139 return {getUpdates().end(), varlist_size()};
5140 }
5141
5142 /// Gets the list of used expressions for linear variables.
5144 return {getFinals().end() + 2, varlist_size() + 1};
5145 }
5146 ArrayRef<const Expr *> getUsedExprs() const {
5147 return {getFinals().end() + 2, varlist_size() + 1};
5148 }
5149
5150 /// Sets the list of the copies of original linear variables.
5151 /// \param PL List of expressions.
5152 void setPrivates(ArrayRef<Expr *> PL);
5153
5154 /// Sets the list of the initial values for linear variables.
5155 /// \param IL List of expressions.
5157
5158public:
5159 /// Creates clause with a list of variables \a VL and a linear step
5160 /// \a Step.
5161 ///
5162 /// \param C AST Context.
5163 /// \param StartLoc Starting location of the clause.
5164 /// \param LParenLoc Location of '('.
5165 /// \param Modifier Modifier of 'linear' clause.
5166 /// \param ModifierLoc Modifier location.
5167 /// \param ColonLoc Location of ':'.
5168 /// \param StepModifierLoc Location of 'step' modifier.
5169 /// \param EndLoc Ending location of the clause.
5170 /// \param VL List of references to the variables.
5171 /// \param PL List of private copies of original variables.
5172 /// \param IL List of initial values for the variables.
5173 /// \param Step Linear step.
5174 /// \param CalcStep Calculation of the linear step.
5175 /// \param PreInit Statement that must be executed before entering the OpenMP
5176 /// region with this clause.
5177 /// \param PostUpdate Expression that must be executed after exit from the
5178 /// OpenMP region with this clause.
5179 static OMPLinearClause *
5180 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
5181 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
5182 SourceLocation ColonLoc, SourceLocation StepModifierLoc,
5184 ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit,
5185 Expr *PostUpdate);
5186
5187 /// Creates an empty clause with the place for \a NumVars variables.
5188 ///
5189 /// \param C AST context.
5190 /// \param NumVars Number of variables.
5191 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
5192
5193 /// Set modifier.
5194 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
5195
5196 /// Return modifier.
5197 OpenMPLinearClauseKind getModifier() const { return Modifier; }
5198
5199 /// Set modifier location.
5200 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
5201
5202 /// Return modifier location.
5203 SourceLocation getModifierLoc() const { return ModifierLoc; }
5204
5205 /// Sets the location of ':'.
5206 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
5207
5208 /// Sets the location of 'step' modifier.
5209 void setStepModifierLoc(SourceLocation Loc) { StepModifierLoc = Loc; }
5210
5211 /// Returns the location of ':'.
5212 SourceLocation getColonLoc() const { return ColonLoc; }
5213
5214 /// Returns the location of 'step' modifier.
5215 SourceLocation getStepModifierLoc() const { return StepModifierLoc; }
5216
5217 /// Returns linear step.
5218 Expr *getStep() { return *(getFinals().end()); }
5219
5220 /// Returns linear step.
5221 const Expr *getStep() const { return *(getFinals().end()); }
5222
5223 /// Returns expression to calculate linear step.
5224 Expr *getCalcStep() { return *(getFinals().end() + 1); }
5225
5226 /// Returns expression to calculate linear step.
5227 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
5228
5229 /// Sets the list of update expressions for linear variables.
5230 /// \param UL List of expressions.
5232
5233 /// Sets the list of final update expressions for linear variables.
5234 /// \param FL List of expressions.
5236
5237 /// Sets the list of used expressions for the linear clause.
5239
5242 using privates_range = llvm::iterator_range<privates_iterator>;
5243 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
5244
5246
5247 privates_const_range privates() const { return getPrivates(); }
5248
5251 using inits_range = llvm::iterator_range<inits_iterator>;
5252 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
5253
5255
5256 inits_const_range inits() const { return getInits(); }
5257
5260 using updates_range = llvm::iterator_range<updates_iterator>;
5261 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
5262
5264
5265 updates_const_range updates() const { return getUpdates(); }
5266
5269 using finals_range = llvm::iterator_range<finals_iterator>;
5270 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
5271
5273
5274 finals_const_range finals() const { return getFinals(); }
5275
5279 llvm::iterator_range<used_expressions_iterator>;
5281 llvm::iterator_range<used_expressions_const_iterator>;
5282
5286
5287 used_expressions_const_range used_expressions() const {
5288 return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
5289 }
5290
5291 child_range children() {
5292 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5293 reinterpret_cast<Stmt **>(varlist_end()));
5294 }
5295
5296 const_child_range children() const {
5297 return const_cast<OMPLinearClause *>(this)->children();
5298 }
5299
5300 child_range used_children();
5301
5302 const_child_range used_children() const {
5303 return const_cast<OMPLinearClause *>(this)->used_children();
5304 }
5305
5306 static bool classof(const OMPClause *T) {
5307 return T->getClauseKind() == llvm::omp::OMPC_linear;
5308 }
5309};
5310
5311/// This represents clause 'aligned' in the '#pragma omp ...'
5312/// directives.
5313///
5314/// \code
5315/// #pragma omp simd aligned(a,b : 8)
5316/// \endcode
5317/// In this example directive '#pragma omp simd' has clause 'aligned'
5318/// with variables 'a', 'b' and alignment '8'.
5319class OMPAlignedClause final
5320 : public OMPVarListClause<OMPAlignedClause>,
5321 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
5322 friend class OMPClauseReader;
5323 friend OMPVarListClause;
5324 friend TrailingObjects;
5325
5326 /// Location of ':'.
5327 SourceLocation ColonLoc;
5328
5329 /// Sets the alignment for clause.
5330 void setAlignment(Expr *A) { *varlist_end() = A; }
5331
5332 /// Build 'aligned' clause with given number of variables \a NumVars.
5333 ///
5334 /// \param StartLoc Starting location of the clause.
5335 /// \param LParenLoc Location of '('.
5336 /// \param ColonLoc Location of ':'.
5337 /// \param EndLoc Ending location of the clause.
5338 /// \param NumVars Number of variables.
5339 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5340 SourceLocation ColonLoc, SourceLocation EndLoc,
5341 unsigned NumVars)
5342 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
5343 LParenLoc, EndLoc, NumVars),
5344 ColonLoc(ColonLoc) {}
5345
5346 /// Build an empty clause.
5347 ///
5348 /// \param NumVars Number of variables.
5349 explicit OMPAlignedClause(unsigned NumVars)
5350 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
5351 SourceLocation(), SourceLocation(),
5352 SourceLocation(), NumVars) {}
5353
5354public:
5355 /// Creates clause with a list of variables \a VL and alignment \a A.
5356 ///
5357 /// \param C AST Context.
5358 /// \param StartLoc Starting location of the clause.
5359 /// \param LParenLoc Location of '('.
5360 /// \param ColonLoc Location of ':'.
5361 /// \param EndLoc Ending location of the clause.
5362 /// \param VL List of references to the variables.
5363 /// \param A Alignment.
5364 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
5365 SourceLocation LParenLoc,
5366 SourceLocation ColonLoc,
5367 SourceLocation EndLoc, ArrayRef<Expr *> VL,
5368 Expr *A);
5369
5370 /// Creates an empty clause with the place for \a NumVars variables.
5371 ///
5372 /// \param C AST context.
5373 /// \param NumVars Number of variables.
5374 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
5375
5376 /// Sets the location of ':'.
5377 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
5378
5379 /// Returns the location of ':'.
5380 SourceLocation getColonLoc() const { return ColonLoc; }
5381
5382 /// Returns alignment.
5383 Expr *getAlignment() { return *varlist_end(); }
5384
5385 /// Returns alignment.
5386 const Expr *getAlignment() const { return *varlist_end(); }
5387
5388 child_range children() {
5389 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5390 reinterpret_cast<Stmt **>(varlist_end()));
5391 }
5392
5393 const_child_range children() const {
5394 return const_cast<OMPAlignedClause *>(this)->children();
5395 }
5396
5397 child_range used_children() {
5398 return child_range(child_iterator(), child_iterator());
5399 }
5400 const_child_range used_children() const {
5401 return const_child_range(const_child_iterator(), const_child_iterator());
5402 }
5403
5404 static bool classof(const OMPClause *T) {
5405 return T->getClauseKind() == llvm::omp::OMPC_aligned;
5406 }
5407};
5408
5409/// This represents clause 'copyin' in the '#pragma omp ...' directives.
5410///
5411/// \code
5412/// #pragma omp parallel copyin(a,b)
5413/// \endcode
5414/// In this example directive '#pragma omp parallel' has clause 'copyin'
5415/// with the variables 'a' and 'b'.
5416class OMPCopyinClause final
5417 : public OMPVarListClause<OMPCopyinClause>,
5418 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
5419 // Class has 3 additional tail allocated arrays:
5420 // 1. List of helper expressions for proper generation of assignment operation
5421 // required for copyin clause. This list represents sources.
5422 // 2. List of helper expressions for proper generation of assignment operation
5423 // required for copyin clause. This list represents destinations.
5424 // 3. List of helper expressions that represents assignment operation:
5425 // \code
5426 // DstExprs = SrcExprs;
5427 // \endcode
5428 // Required for proper codegen of propagation of master's thread values of
5429 // threadprivate variables to local instances of that variables in other
5430 // implicit threads.
5431
5432 friend class OMPClauseReader;
5433 friend OMPVarListClause;
5434 friend TrailingObjects;
5435
5436 /// Build clause with number of variables \a N.
5437 ///
5438 /// \param StartLoc Starting location of the clause.
5439 /// \param LParenLoc Location of '('.
5440 /// \param EndLoc Ending location of the clause.
5441 /// \param N Number of the variables in the clause.
5442 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5443 SourceLocation EndLoc, unsigned N)
5444 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
5445 LParenLoc, EndLoc, N) {}
5446
5447 /// Build an empty clause.
5448 ///
5449 /// \param N Number of variables.
5450 explicit OMPCopyinClause(unsigned N)
5451 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
5452 SourceLocation(), SourceLocation(),
5453 SourceLocation(), N) {}
5454
5455 /// Set list of helper expressions, required for proper codegen of the
5456 /// clause. These expressions represent source expression in the final
5457 /// assignment statement performed by the copyin clause.
5458 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
5459
5460 /// Get the list of helper source expressions.
5461 MutableArrayRef<Expr *> getSourceExprs() {
5462 return {varlist_end(), varlist_size()};
5463 }
5464 ArrayRef<const Expr *> getSourceExprs() const {
5465 return {varlist_end(), varlist_size()};
5466 }
5467
5468 /// Set list of helper expressions, required for proper codegen of the
5469 /// clause. These expressions represent destination expression in the final
5470 /// assignment statement performed by the copyin clause.
5471 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
5472
5473 /// Get the list of helper destination expressions.
5474 MutableArrayRef<Expr *> getDestinationExprs() {
5475 return {getSourceExprs().end(), varlist_size()};
5476 }
5477 ArrayRef<const Expr *> getDestinationExprs() const {
5478 return {getSourceExprs().end(), varlist_size()};
5479 }
5480
5481 /// Set list of helper assignment expressions, required for proper
5482 /// codegen of the clause. These expressions are assignment expressions that
5483 /// assign source helper expressions to destination helper expressions
5484 /// correspondingly.
5485 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
5486
5487 /// Get the list of helper assignment expressions.
5488 MutableArrayRef<Expr *> getAssignmentOps() {
5489 return {getDestinationExprs().end(), varlist_size()};
5490 }
5491 ArrayRef<const Expr *> getAssignmentOps() const {
5492 return {getDestinationExprs().end(), varlist_size()};
5493 }
5494
5495public:
5496 /// Creates clause with a list of variables \a VL.
5497 ///
5498 /// \param C AST context.
5499 /// \param StartLoc Starting location of the clause.
5500 /// \param LParenLoc Location of '('.
5501 /// \param EndLoc Ending location of the clause.
5502 /// \param VL List of references to the variables.
5503 /// \param SrcExprs List of helper expressions for proper generation of
5504 /// assignment operation required for copyin clause. This list represents
5505 /// sources.
5506 /// \param DstExprs List of helper expressions for proper generation of
5507 /// assignment operation required for copyin clause. This list represents
5508 /// destinations.
5509 /// \param AssignmentOps List of helper expressions that represents assignment
5510 /// operation:
5511 /// \code
5512 /// DstExprs = SrcExprs;
5513 /// \endcode
5514 /// Required for proper codegen of propagation of master's thread values of
5515 /// threadprivate variables to local instances of that variables in other
5516 /// implicit threads.
5517 static OMPCopyinClause *
5518 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
5519 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
5520 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
5521
5522 /// Creates an empty clause with \a N variables.
5523 ///
5524 /// \param C AST context.
5525 /// \param N The number of variables.
5526 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
5527
5528 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
5530 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
5532 llvm::iterator_range<helper_expr_const_iterator>;
5533
5534 helper_expr_const_range source_exprs() const { return getSourceExprs(); }
5535
5536 helper_expr_range source_exprs() { return getSourceExprs(); }
5537
5539 return getDestinationExprs();
5540 }
5541
5542 helper_expr_range destination_exprs() { return getDestinationExprs(); }
5543
5544 helper_expr_const_range assignment_ops() const { return getAssignmentOps(); }
5545
5546 helper_expr_range assignment_ops() { return getAssignmentOps(); }
5547
5548 child_range children() {
5549 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5550 reinterpret_cast<Stmt **>(varlist_end()));
5551 }
5552
5553 const_child_range children() const {
5554 return const_cast<OMPCopyinClause *>(this)->children();
5555 }
5556
5557 child_range used_children() {
5558 return child_range(child_iterator(), child_iterator());
5559 }
5560 const_child_range used_children() const {
5561 return const_child_range(const_child_iterator(), const_child_iterator());
5562 }
5563
5564 static bool classof(const OMPClause *T) {
5565 return T->getClauseKind() == llvm::omp::OMPC_copyin;
5566 }
5567};
5568
5569/// This represents clause 'copyprivate' in the '#pragma omp ...'
5570/// directives.
5571///
5572/// \code
5573/// #pragma omp single copyprivate(a,b)
5574/// \endcode
5575/// In this example directive '#pragma omp single' has clause 'copyprivate'
5576/// with the variables 'a' and 'b'.
5577class OMPCopyprivateClause final
5578 : public OMPVarListClause<OMPCopyprivateClause>,
5579 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
5580 friend class OMPClauseReader;
5581 friend OMPVarListClause;
5582 friend TrailingObjects;
5583
5584 /// Build clause with number of variables \a N.
5585 ///
5586 /// \param StartLoc Starting location of the clause.
5587 /// \param LParenLoc Location of '('.
5588 /// \param EndLoc Ending location of the clause.
5589 /// \param N Number of the variables in the clause.
5590 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5591 SourceLocation EndLoc, unsigned N)
5592 : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
5593 StartLoc, LParenLoc, EndLoc, N) {
5594 }
5595
5596 /// Build an empty clause.
5597 ///
5598 /// \param N Number of variables.
5599 explicit OMPCopyprivateClause(unsigned N)
5600 : OMPVarListClause<OMPCopyprivateClause>(
5601 llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
5602 SourceLocation(), N) {}
5603
5604 /// Set list of helper expressions, required for proper codegen of the
5605 /// clause. These expressions represent source expression in the final
5606 /// assignment statement performed by the copyprivate clause.
5607 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
5608
5609 /// Get the list of helper source expressions.
5610 MutableArrayRef<Expr *> getSourceExprs() {
5611 return {varlist_end(), varlist_size()};
5612 }
5613 ArrayRef<const Expr *> getSourceExprs() const {
5614 return {varlist_end(), varlist_size()};
5615 }
5616
5617 /// Set list of helper expressions, required for proper codegen of the
5618 /// clause. These expressions represent destination expression in the final
5619 /// assignment statement performed by the copyprivate clause.
5620 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
5621
5622 /// Get the list of helper destination expressions.
5623 MutableArrayRef<Expr *> getDestinationExprs() {
5624 return {getSourceExprs().end(), varlist_size()};
5625 }
5626 ArrayRef<const Expr *> getDestinationExprs() const {
5627 return {getSourceExprs().end(), varlist_size()};
5628 }
5629
5630 /// Set list of helper assignment expressions, required for proper
5631 /// codegen of the clause. These expressions are assignment expressions that
5632 /// assign source helper expressions to destination helper expressions
5633 /// correspondingly.
5634 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
5635
5636 /// Get the list of helper assignment expressions.
5637 MutableArrayRef<Expr *> getAssignmentOps() {
5638 return {getDestinationExprs().end(), varlist_size()};
5639 }
5640 ArrayRef<const Expr *> getAssignmentOps() const {
5641 return {getDestinationExprs().end(), varlist_size()};
5642 }
5643
5644public:
5645 /// Creates clause with a list of variables \a VL.
5646 ///
5647 /// \param C AST context.
5648 /// \param StartLoc Starting location of the clause.
5649 /// \param LParenLoc Location of '('.
5650 /// \param EndLoc Ending location of the clause.
5651 /// \param VL List of references to the variables.
5652 /// \param SrcExprs List of helper expressions for proper generation of
5653 /// assignment operation required for copyprivate clause. This list represents
5654 /// sources.
5655 /// \param DstExprs List of helper expressions for proper generation of
5656 /// assignment operation required for copyprivate clause. This list represents
5657 /// destinations.
5658 /// \param AssignmentOps List of helper expressions that represents assignment
5659 /// operation:
5660 /// \code
5661 /// DstExprs = SrcExprs;
5662 /// \endcode
5663 /// Required for proper codegen of final assignment performed by the
5664 /// copyprivate clause.
5665 static OMPCopyprivateClause *
5666 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
5667 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
5668 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
5669
5670 /// Creates an empty clause with \a N variables.
5671 ///
5672 /// \param C AST context.
5673 /// \param N The number of variables.
5674 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
5675
5676 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
5678 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
5680 llvm::iterator_range<helper_expr_const_iterator>;
5681
5682 helper_expr_const_range source_exprs() const { return getSourceExprs(); }
5683
5684 helper_expr_range source_exprs() { return getSourceExprs(); }
5685
5687 return getDestinationExprs();
5688 }
5689
5690 helper_expr_range destination_exprs() { return getDestinationExprs(); }
5691
5692 helper_expr_const_range assignment_ops() const { return getAssignmentOps(); }
5693
5694 helper_expr_range assignment_ops() { return getAssignmentOps(); }
5695
5696 child_range children() {
5697 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5698 reinterpret_cast<Stmt **>(varlist_end()));
5699 }
5700
5701 const_child_range children() const {
5702 return const_cast<OMPCopyprivateClause *>(this)->children();
5703 }
5704
5705 child_range used_children() {
5706 return child_range(child_iterator(), child_iterator());
5707 }
5708 const_child_range used_children() const {
5709 return const_child_range(const_child_iterator(), const_child_iterator());
5710 }
5711
5712 static bool classof(const OMPClause *T) {
5713 return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
5714 }
5715};
5716
5717/// This represents implicit clause 'flush' for the '#pragma omp flush'
5718/// directive.
5719/// This clause does not exist by itself, it can be only as a part of 'omp
5720/// flush' directive. This clause is introduced to keep the original structure
5721/// of \a OMPExecutableDirective class and its derivatives and to use the
5722/// existing infrastructure of clauses with the list of variables.
5723///
5724/// \code
5725/// #pragma omp flush(a,b)
5726/// \endcode
5727/// In this example directive '#pragma omp flush' has implicit clause 'flush'
5728/// with the variables 'a' and 'b'.
5729class OMPFlushClause final
5730 : public OMPVarListClause<OMPFlushClause>,
5731 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
5732 friend OMPVarListClause;
5733 friend TrailingObjects;
5734
5735 /// Build clause with number of variables \a N.
5736 ///
5737 /// \param StartLoc Starting location of the clause.
5738 /// \param LParenLoc Location of '('.
5739 /// \param EndLoc Ending location of the clause.
5740 /// \param N Number of the variables in the clause.
5741 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5742 SourceLocation EndLoc, unsigned N)
5743 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
5744 LParenLoc, EndLoc, N) {}
5745
5746 /// Build an empty clause.
5747 ///
5748 /// \param N Number of variables.
5749 explicit OMPFlushClause(unsigned N)
5750 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
5751 SourceLocation(), SourceLocation(),
5752 SourceLocation(), N) {}
5753
5754public:
5755 /// Creates clause with a list of variables \a VL.
5756 ///
5757 /// \param C AST context.
5758 /// \param StartLoc Starting location of the clause.
5759 /// \param LParenLoc Location of '('.
5760 /// \param EndLoc Ending location of the clause.
5761 /// \param VL List of references to the variables.
5762 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
5763 SourceLocation LParenLoc, SourceLocation EndLoc,
5764 ArrayRef<Expr *> VL);
5765
5766 /// Creates an empty clause with \a N variables.
5767 ///
5768 /// \param C AST context.
5769 /// \param N The number of variables.
5770 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
5771
5772 child_range children() {
5773 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5774 reinterpret_cast<Stmt **>(varlist_end()));
5775 }
5776
5777 const_child_range children() const {
5778 return const_cast<OMPFlushClause *>(this)->children();
5779 }
5780
5781 child_range used_children() {
5782 return child_range(child_iterator(), child_iterator());
5783 }
5784 const_child_range used_children() const {
5785 return const_child_range(const_child_iterator(), const_child_iterator());
5786 }
5787
5788 static bool classof(const OMPClause *T) {
5789 return T->getClauseKind() == llvm::omp::OMPC_flush;
5790 }
5791};
5792
5793/// This represents implicit clause 'depobj' for the '#pragma omp depobj'
5794/// directive.
5795/// This clause does not exist by itself, it can be only as a part of 'omp
5796/// depobj' directive. This clause is introduced to keep the original structure
5797/// of \a OMPExecutableDirective class and its derivatives and to use the
5798/// existing infrastructure of clauses with the list of variables.
5799///
5800/// \code
5801/// #pragma omp depobj(a) destroy
5802/// \endcode
5803/// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
5804/// with the depobj 'a'.
5805class OMPDepobjClause final : public OMPClause {
5806 friend class OMPClauseReader;
5807
5808 /// Location of '('.
5809 SourceLocation LParenLoc;
5810
5811 /// Chunk size.
5812 Expr *Depobj = nullptr;
5813
5814 void setDepobj(Expr *E) { Depobj = E; }
5815
5816 /// Sets the location of '('.
5817 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5818
5819public:
5820 /// Build a 'depobj' clause.
5821 ///
5822 /// \param StartLoc Starting location of the clause.
5823 /// \param LParenLoc Location of '('.
5824 /// \param EndLoc Ending location of the clause.
5825 /// \param Depobj depobj expression associated with the 'depobj' directive.
5826 OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5827 SourceLocation EndLoc, Expr *Depobj)
5828 : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
5829 LParenLoc(LParenLoc), Depobj(Depobj) {}
5830
5831 /// Build an empty clause.
5833 : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
5834
5835 /// Returns depobj expression associated with the clause.
5836 Expr *getDepobj() { return Depobj; }
5837 const Expr *getDepobj() const { return Depobj; }
5838
5839 /// Returns the location of '('.
5840 SourceLocation getLParenLoc() const { return LParenLoc; }
5841
5842 child_range children() {
5843 return child_range(reinterpret_cast<Stmt **>(&Depobj),
5844 reinterpret_cast<Stmt **>(&Depobj) + 1);
5845 }
5846
5847 const_child_range children() const {
5848 return const_cast<OMPDepobjClause *>(this)->children();
5849 }
5850
5851 child_range used_children() {
5852 return child_range(child_iterator(), child_iterator());
5853 }
5854 const_child_range used_children() const {
5855 return const_child_range(const_child_iterator(), const_child_iterator());
5856 }
5857
5858 static bool classof(const OMPClause *T) {
5859 return T->getClauseKind() == llvm::omp::OMPC_depobj;
5860 }
5861};
5862
5863/// This represents implicit clause 'depend' for the '#pragma omp task'
5864/// directive.
5865///
5866/// \code
5867/// #pragma omp task depend(in:a,b)
5868/// \endcode
5869/// In this example directive '#pragma omp task' with clause 'depend' with the
5870/// variables 'a' and 'b' with dependency 'in'.
5871class OMPDependClause final
5872 : public OMPVarListClause<OMPDependClause>,
5873 private llvm::TrailingObjects<OMPDependClause, Expr *> {
5874 friend class OMPClauseReader;
5875 friend OMPVarListClause;
5876 friend TrailingObjects;
5877
5878public:
5879 struct DependDataTy final {
5880 /// Dependency type (one of in, out, inout).
5881 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
5882
5883 /// Dependency type location.
5884 SourceLocation DepLoc;
5885
5886 /// Colon location.
5887 SourceLocation ColonLoc;
5888
5889 /// Location of 'omp_all_memory'.
5890 SourceLocation OmpAllMemoryLoc;
5891 };
5892
5893private:
5894 /// Dependency type and source locations.
5895 DependDataTy Data;
5896
5897 /// Number of loops, associated with the depend clause.
5898 unsigned NumLoops = 0;
5899
5900 /// Build clause with number of variables \a N.
5901 ///
5902 /// \param StartLoc Starting location of the clause.
5903 /// \param LParenLoc Location of '('.
5904 /// \param EndLoc Ending location of the clause.
5905 /// \param N Number of the variables in the clause.
5906 /// \param NumLoops Number of loops that is associated with this depend
5907 /// clause.
5908 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5909 SourceLocation EndLoc, unsigned N, unsigned NumLoops)
5910 : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, StartLoc,
5911 LParenLoc, EndLoc, N),
5912 NumLoops(NumLoops) {}
5913
5914 /// Build an empty clause.
5915 ///
5916 /// \param N Number of variables.
5917 /// \param NumLoops Number of loops that is associated with this depend
5918 /// clause.
5919 explicit OMPDependClause(unsigned N, unsigned NumLoops)
5920 : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend,
5921 SourceLocation(), SourceLocation(),
5922 SourceLocation(), N),
5923 NumLoops(NumLoops) {}
5924
5925 /// Set dependency kind.
5926 void setDependencyKind(OpenMPDependClauseKind K) { Data.DepKind = K; }
5927
5928 /// Set dependency kind and its location.
5929 void setDependencyLoc(SourceLocation Loc) { Data.DepLoc = Loc; }
5930
5931 /// Set colon location.
5932 void setColonLoc(SourceLocation Loc) { Data.ColonLoc = Loc; }
5933
5934 /// Set the 'omp_all_memory' location.
5935 void setOmpAllMemoryLoc(SourceLocation Loc) { Data.OmpAllMemoryLoc = Loc; }
5936
5937 /// Sets optional dependency modifier.
5938 void setModifier(Expr *DepModifier);
5939
5940public:
5941 /// Creates clause with a list of variables \a VL.
5942 ///
5943 /// \param C AST context.
5944 /// \param StartLoc Starting location of the clause.
5945 /// \param LParenLoc Location of '('.
5946 /// \param EndLoc Ending location of the clause.
5947 /// \param Data Dependency type and source locations.
5948 /// \param VL List of references to the variables.
5949 /// \param NumLoops Number of loops that is associated with this depend
5950 /// clause.
5951 static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
5952 SourceLocation LParenLoc,
5953 SourceLocation EndLoc, DependDataTy Data,
5954 Expr *DepModifier, ArrayRef<Expr *> VL,
5955 unsigned NumLoops);
5956
5957 /// Creates an empty clause with \a N variables.
5958 ///
5959 /// \param C AST context.
5960 /// \param N The number of variables.
5961 /// \param NumLoops Number of loops that is associated with this depend
5962 /// clause.
5963 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
5964 unsigned NumLoops);
5965
5966 /// Get dependency type.
5967 OpenMPDependClauseKind getDependencyKind() const { return Data.DepKind; }
5968
5969 /// Get dependency type location.
5970 SourceLocation getDependencyLoc() const { return Data.DepLoc; }
5971
5972 /// Get colon location.
5973 SourceLocation getColonLoc() const { return Data.ColonLoc; }
5974
5975 /// Get 'omp_all_memory' location.
5976 SourceLocation getOmpAllMemoryLoc() const { return Data.OmpAllMemoryLoc; }
5977
5978 /// Return optional depend modifier.
5979 Expr *getModifier();
5980 const Expr *getModifier() const {
5981 return const_cast<OMPDependClause *>(this)->getModifier();
5982 }
5983
5984 /// Get number of loops associated with the clause.
5985 unsigned getNumLoops() const { return NumLoops; }
5986
5987 /// Set the loop data for the depend clauses with 'sink|source' kind of
5988 /// dependency.
5989 void setLoopData(unsigned NumLoop, Expr *Cnt);
5990
5991 /// Get the loop data.
5992 Expr *getLoopData(unsigned NumLoop);
5993 const Expr *getLoopData(unsigned NumLoop) const;
5994
5995 child_range children() {
5996 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5997 reinterpret_cast<Stmt **>(varlist_end()));
5998 }
5999
6000 const_child_range children() const {
6001 return const_cast<OMPDependClause *>(this)->children();
6002 }
6003
6004 child_range used_children() {
6005 return child_range(child_iterator(), child_iterator());
6006 }
6007 const_child_range used_children() const {
6008 return const_child_range(const_child_iterator(), const_child_iterator());
6009 }
6010
6011 static bool classof(const OMPClause *T) {
6012 return T->getClauseKind() == llvm::omp::OMPC_depend;
6013 }
6014};
6015
6016/// This represents 'device' clause in the '#pragma omp ...'
6017/// directive.
6018///
6019/// \code
6020/// #pragma omp target device(a)
6021/// \endcode
6022/// In this example directive '#pragma omp target' has clause 'device'
6023/// with single expression 'a'.
6025 friend class OMPClauseReader;
6026
6027 /// Location of '('.
6028 SourceLocation LParenLoc;
6029
6030 /// Device clause modifier.
6031 OpenMPDeviceClauseModifier Modifier = OMPC_DEVICE_unknown;
6032
6033 /// Location of the modifier.
6034 SourceLocation ModifierLoc;
6035
6036 /// Device number.
6037 Stmt *Device = nullptr;
6038
6039 /// Set the device number.
6040 ///
6041 /// \param E Device number.
6042 void setDevice(Expr *E) { Device = E; }
6043
6044 /// Sets modifier.
6045 void setModifier(OpenMPDeviceClauseModifier M) { Modifier = M; }
6046
6047 /// Setst modifier location.
6048 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
6049
6050public:
6051 /// Build 'device' clause.
6052 ///
6053 /// \param Modifier Clause modifier.
6054 /// \param E Expression associated with this clause.
6055 /// \param CaptureRegion Innermost OpenMP region where expressions in this
6056 /// clause must be captured.
6057 /// \param StartLoc Starting location of the clause.
6058 /// \param ModifierLoc Modifier location.
6059 /// \param LParenLoc Location of '('.
6060 /// \param EndLoc Ending location of the clause.
6061 OMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *E, Stmt *HelperE,
6062 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
6063 SourceLocation LParenLoc, SourceLocation ModifierLoc,
6064 SourceLocation EndLoc)
6065 : OMPClause(llvm::omp::OMPC_device, StartLoc, EndLoc),
6066 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
6067 ModifierLoc(ModifierLoc), Device(E) {
6068 setPreInitStmt(HelperE, CaptureRegion);
6069 }
6070
6071 /// Build an empty clause.
6073 : OMPClause(llvm::omp::OMPC_device, SourceLocation(), SourceLocation()),
6074 OMPClauseWithPreInit(this) {}
6075
6076 /// Sets the location of '('.
6077 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
6078
6079 /// Returns the location of '('.
6080 SourceLocation getLParenLoc() const { return LParenLoc; }
6081
6082 /// Return device number.
6083 Expr *getDevice() { return cast<Expr>(Device); }
6084
6085 /// Return device number.
6086 Expr *getDevice() const { return cast<Expr>(Device); }
6087
6088 /// Gets modifier.
6089 OpenMPDeviceClauseModifier getModifier() const { return Modifier; }
6090
6091 /// Gets modifier location.
6092 SourceLocation getModifierLoc() const { return ModifierLoc; }
6093
6094 child_range children() { return child_range(&Device, &Device + 1); }
6095
6096 const_child_range children() const {
6097 return const_child_range(&Device, &Device + 1);
6098 }
6099
6100 child_range used_children() {
6101 return child_range(child_iterator(), child_iterator());
6102 }
6103 const_child_range used_children() const {
6104 return const_child_range(const_child_iterator(), const_child_iterator());
6105 }
6106
6107 static bool classof(const OMPClause *T) {
6108 return T->getClauseKind() == llvm::omp::OMPC_device;
6109 }
6110};
6111
6112/// This represents 'threads' clause in the '#pragma omp ...' directive.
6113///
6114/// \code
6115/// #pragma omp ordered threads
6116/// \endcode
6117/// In this example directive '#pragma omp ordered' has simple 'threads' clause.
6119 : public OMPNoChildClause<llvm::omp::OMPC_threads> {
6120public:
6121 /// Build 'threads' clause.
6122 ///
6123 /// \param StartLoc Starting location of the clause.
6124 /// \param EndLoc Ending location of the clause.
6125 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
6126 : OMPNoChildClause(StartLoc, EndLoc) {}
6127
6128 /// Build an empty clause.
6130};
6131
6132/// This represents 'simd' clause in the '#pragma omp ...' directive.
6133///
6134/// \code
6135/// #pragma omp ordered simd
6136/// \endcode
6137/// In this example directive '#pragma omp ordered' has simple 'simd' clause.
6138class OMPSIMDClause : public OMPClause {
6139public:
6140 /// Build 'simd' clause.
6141 ///
6142 /// \param StartLoc Starting location of the clause.
6143 /// \param EndLoc Ending location of the clause.
6144 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
6145 : OMPClause(llvm::omp::OMPC_simd, StartLoc, EndLoc) {}
6146
6147 /// Build an empty clause.
6149 : OMPClause(llvm::omp::OMPC_simd, SourceLocation(), SourceLocation()) {}
6150
6151 child_range children() {
6152 return child_range(child_iterator(), child_iterator());
6153 }
6154
6155 const_child_range children() const {
6156 return const_child_range(const_child_iterator(), const_child_iterator());
6157 }
6158
6159 child_range used_children() {
6160 return child_range(child_iterator(), child_iterator());
6161 }
6162 const_child_range used_children() const {
6163 return const_child_range(const_child_iterator(), const_child_iterator());
6164 }
6165
6166 static bool classof(const OMPClause *T) {
6167 return T->getClauseKind() == llvm::omp::OMPC_simd;
6168 }
6169};
6170
6171/// Struct that defines common infrastructure to handle mappable
6172/// expressions used in OpenMP clauses.
6174public:
6175 /// Class that represents a component of a mappable expression. E.g.
6176 /// for an expression S.a, the first component is a declaration reference
6177 /// expression associated with 'S' and the second is a member expression
6178 /// associated with the field declaration 'a'. If the expression is an array
6179 /// subscript it may not have any associated declaration. In that case the
6180 /// associated declaration is set to nullptr.
6182 /// Pair of Expression and Non-contiguous pair associated with the
6183 /// component.
6184 llvm::PointerIntPair<Expr *, 1, bool> AssociatedExpressionNonContiguousPr;
6185
6186 /// Declaration associated with the declaration. If the component does
6187 /// not have a declaration (e.g. array subscripts or section), this is set
6188 /// to nullptr.
6189 ValueDecl *AssociatedDeclaration = nullptr;
6190
6191 public:
6192 explicit MappableComponent() = default;
6193 explicit MappableComponent(Expr *AssociatedExpression,
6194 ValueDecl *AssociatedDeclaration,
6195 bool IsNonContiguous)
6196 : AssociatedExpressionNonContiguousPr(AssociatedExpression,
6197 IsNonContiguous),
6198 AssociatedDeclaration(
6199 AssociatedDeclaration
6200 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
6201 : nullptr) {}
6202
6204 return AssociatedExpressionNonContiguousPr.getPointer();
6205 }
6206
6207 bool isNonContiguous() const {
6208 return AssociatedExpressionNonContiguousPr.getInt();
6209 }
6210
6211 ValueDecl *getAssociatedDeclaration() const {
6212 return AssociatedDeclaration;
6213 }
6214
6215 bool operator==(const MappableComponent &Other) const {
6216 return AssociatedExpressionNonContiguousPr ==
6217 Other.AssociatedExpressionNonContiguousPr &&
6218 AssociatedDeclaration == Other.AssociatedDeclaration;
6219 }
6220 };
6221
6222 // List of components of an expression. This first one is the whole
6223 // expression and the last one is the base expression.
6226
6227 // List of all component lists associated to the same base declaration.
6228 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
6229 // their component list but the same base declaration 'S'.
6232
6233 // Hash function to allow usage as DenseMap keys.
6234 friend llvm::hash_code hash_value(const MappableComponent &MC) {
6235 return llvm::hash_combine(MC.getAssociatedExpression(),
6237 MC.isNonContiguous());
6238 }
6239
6240public:
6241 /// Get the type of an element of a ComponentList Expr \p Exp.
6242 ///
6243 /// For something like the following:
6244 /// ```c
6245 /// int *p, **p;
6246 /// ```
6247 /// The types for the following Exprs would be:
6248 /// Expr | Type
6249 /// ---------|-----------
6250 /// p | int *
6251 /// *p | int
6252 /// p[0] | int
6253 /// p[0:1] | int
6254 /// pp | int **
6255 /// pp[0] | int *
6256 /// pp[0:1] | int *
6257 /// Note: this assumes that if \p Exp is an array-section, it is contiguous.
6258 static QualType getComponentExprElementType(const Expr *Exp);
6259
6260 /// Find the attach pointer expression from a list of mappable expression
6261 /// components.
6262 ///
6263 /// This function traverses the component list to find the first
6264 /// expression that has a pointer type, which represents the attach
6265 /// base pointer expr for the current component-list.
6266 ///
6267 /// For example, given the following:
6268 ///
6269 /// ```c
6270 /// struct S {
6271 /// int a;
6272 /// int b[10];
6273 /// int c[10][10];
6274 /// int *p;
6275 /// int **pp;
6276 /// }
6277 /// S s, *ps, **pps, *(pas[10]), ***ppps;
6278 /// int i;
6279 /// ```
6280 ///
6281 /// The base-pointers for the following map operands would be:
6282 /// map list-item | attach base-pointer | attach base-pointer
6283 /// | for directives except | target_update (if
6284 /// | target_update | different)
6285 /// ----------------|-----------------------|---------------------
6286 /// s | N/A |
6287 /// s.a | N/A |
6288 /// s.p | N/A |
6289 /// ps | N/A |
6290 /// ps->p | ps |
6291 /// ps[1] | ps |
6292 /// *(ps + 1) | ps |
6293 /// (ps + 1)[1] | ps |
6294 /// ps[1:10] | ps |
6295 /// ps->b[10] | ps |
6296 /// ps->p[10] | ps->p |
6297 /// ps->c[1][2] | ps |
6298 /// ps->c[1:2][2] | (error diagnostic) | N/A, TODO: ps
6299 /// ps->c[1:1][2] | ps | N/A, TODO: ps
6300 /// pps[1][2] | pps[1] |
6301 /// pps[1:1][2] | pps[1:1] | N/A, TODO: pps[1:1]
6302 /// pps[1:i][2] | pps[1:i] | N/A, TODO: pps[1:i]
6303 /// pps[1:2][2] | (error diagnostic) | N/A
6304 /// pps[1]->p | pps[1] |
6305 /// pps[1]->p[10] | pps[1] |
6306 /// pas[1] | N/A |
6307 /// pas[1][2] | pas[1] |
6308 /// ppps[1][2] | ppps[1] |
6309 /// ppps[1][2][3] | ppps[1][2] |
6310 /// ppps[1][2:1][3] | ppps[1][2:1] | N/A, TODO: ppps[1][2:1]
6311 /// ppps[1][2:2][3] | (error diagnostic) | N/A
6312 /// Returns a pair of the attach pointer expression and its depth in the
6313 /// component list.
6314 /// TODO: This may need to be updated to handle ref_ptr/ptee cases for byref
6315 /// map operands.
6316 /// TODO: Handle cases for target-update, where the list-item is a
6317 /// non-contiguous array-section that still has a base-pointer.
6318 static std::pair<const Expr *, std::optional<size_t>>
6319 findAttachPtrExpr(MappableExprComponentListRef Components,
6320 OpenMPDirectiveKind CurDirKind);
6321
6322protected:
6323 // Return the total number of elements in a list of component lists.
6324 static unsigned
6325 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
6326
6327 // Return the total number of elements in a list of declarations. All
6328 // declarations are expected to be canonical.
6329 static unsigned
6330 getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
6331};
6332
6333/// This structure contains all sizes needed for by an
6334/// OMPMappableExprListClause.
6336 /// Number of expressions listed.
6337 unsigned NumVars;
6338 /// Number of unique base declarations.
6340 /// Number of component lists.
6342 /// Total number of expression components.
6349};
6350
6351/// This represents clauses with a list of expressions that are mappable.
6352/// Examples of these clauses are 'map' in
6353/// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
6354/// in '#pragma omp target update...' directives.
6355template <class T>
6356class OMPMappableExprListClause : public OMPVarListClause<T>,
6358 friend class OMPClauseReader;
6359
6360 /// Number of unique declarations in this clause.
6361 unsigned NumUniqueDeclarations;
6362
6363 /// Number of component lists in this clause.
6364 unsigned NumComponentLists;
6365
6366 /// Total number of components in this clause.
6367 unsigned NumComponents;
6368
6369 /// Whether this clause is possible to have user-defined mappers associated.
6370 /// It should be true for map, to, and from clauses, and false for
6371 /// use_device_ptr and is_device_ptr.
6372 const bool SupportsMapper;
6373
6374 /// C++ nested name specifier for the associated user-defined mapper.
6375 NestedNameSpecifierLoc MapperQualifierLoc;
6376
6377 /// The associated user-defined mapper identifier information.
6378 DeclarationNameInfo MapperIdInfo;
6379
6380protected:
6381 /// Build a clause for \a NumUniqueDeclarations declarations, \a
6382 /// NumComponentLists total component lists, and \a NumComponents total
6383 /// components.
6384 ///
6385 /// \param K Kind of the clause.
6386 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6387 /// StartLoc: starting location of the clause (the clause keyword); 2)
6388 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6389 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6390 /// NumVars: number of expressions listed in this clause; 2)
6391 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6392 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6393 /// NumComponents: total number of expression components in the clause.
6394 /// \param SupportsMapper Indicates whether this clause is possible to have
6395 /// user-defined mappers associated.
6396 /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
6397 /// user-defined mapper.
6398 /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
6400 OpenMPClauseKind K, const OMPVarListLocTy &Locs,
6401 const OMPMappableExprListSizeTy &Sizes, bool SupportsMapper = false,
6402 NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
6403 DeclarationNameInfo *MapperIdInfoPtr = nullptr)
6404 : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
6405 Sizes.NumVars),
6406 NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
6407 NumComponentLists(Sizes.NumComponentLists),
6408 NumComponents(Sizes.NumComponents), SupportsMapper(SupportsMapper) {
6409 if (MapperQualifierLocPtr)
6410 MapperQualifierLoc = *MapperQualifierLocPtr;
6411 if (MapperIdInfoPtr)
6412 MapperIdInfo = *MapperIdInfoPtr;
6413 }
6414
6415 /// Get the unique declarations that are in the trailing objects of the
6416 /// class.
6417 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
6418 return static_cast<T *>(this)
6419 ->template getTrailingObjectsNonStrict<ValueDecl *>(
6420 NumUniqueDeclarations);
6421 }
6422
6423 /// Get the unique declarations that are in the trailing objects of the
6424 /// class.
6426 return static_cast<const T *>(this)
6427 ->template getTrailingObjectsNonStrict<ValueDecl *>(
6428 NumUniqueDeclarations);
6429 }
6430
6431 /// Set the unique declarations that are in the trailing objects of the
6432 /// class.
6434 assert(UDs.size() == NumUniqueDeclarations &&
6435 "Unexpected amount of unique declarations.");
6436 llvm::copy(UDs, getUniqueDeclsRef().begin());
6437 }
6438
6439 /// Get the number of lists per declaration that are in the trailing
6440 /// objects of the class.
6441 MutableArrayRef<unsigned> getDeclNumListsRef() {
6442 return static_cast<T *>(this)
6443 ->template getTrailingObjectsNonStrict<unsigned>(NumUniqueDeclarations);
6444 }
6445
6446 /// Get the number of lists per declaration that are in the trailing
6447 /// objects of the class.
6449 return static_cast<const T *>(this)
6450 ->template getTrailingObjectsNonStrict<unsigned>(NumUniqueDeclarations);
6451 }
6452
6453 /// Set the number of lists per declaration that are in the trailing
6454 /// objects of the class.
6456 assert(DNLs.size() == NumUniqueDeclarations &&
6457 "Unexpected amount of list numbers.");
6458 llvm::copy(DNLs, getDeclNumListsRef().begin());
6459 }
6460
6461 /// Get the cumulative component lists sizes that are in the trailing
6462 /// objects of the class. They are appended after the number of lists.
6463 MutableArrayRef<unsigned> getComponentListSizesRef() {
6464 return MutableArrayRef<unsigned>(
6465 static_cast<T *>(this)
6466 ->template getTrailingObjectsNonStrict<unsigned>() +
6467 NumUniqueDeclarations,
6468 NumComponentLists);
6469 }
6470
6471 /// Get the cumulative component lists sizes that are in the trailing
6472 /// objects of the class. They are appended after the number of lists.
6474 return ArrayRef<unsigned>(
6475 static_cast<const T *>(this)
6476 ->template getTrailingObjectsNonStrict<unsigned>() +
6477 NumUniqueDeclarations,
6478 NumComponentLists);
6479 }
6480
6481 /// Set the cumulative component lists sizes that are in the trailing
6482 /// objects of the class.
6484 assert(CLSs.size() == NumComponentLists &&
6485 "Unexpected amount of component lists.");
6486 llvm::copy(CLSs, getComponentListSizesRef().begin());
6487 }
6488
6489 /// Get the components that are in the trailing objects of the class.
6490 MutableArrayRef<MappableComponent> getComponentsRef() {
6491 return static_cast<T *>(this)
6492 ->template getTrailingObjectsNonStrict<MappableComponent>(
6493 NumComponents);
6494 }
6495
6496 /// Get the components that are in the trailing objects of the class.
6498 return static_cast<const T *>(this)
6499 ->template getTrailingObjectsNonStrict<MappableComponent>(
6500 NumComponents);
6501 }
6502
6503 /// Set the components that are in the trailing objects of the class.
6504 /// This requires the list sizes so that it can also fill the original
6505 /// expressions, which are the first component of each list.
6507 ArrayRef<unsigned> CLSs) {
6508 assert(Components.size() == NumComponents &&
6509 "Unexpected amount of component lists.");
6510 assert(CLSs.size() == NumComponentLists &&
6511 "Unexpected amount of list sizes.");
6512 llvm::copy(Components, getComponentsRef().begin());
6513 }
6514
6515 /// Fill the clause information from the list of declarations and
6516 /// associated component lists.
6518 MappableExprComponentListsRef ComponentLists) {
6519 // Perform some checks to make sure the data sizes are consistent with the
6520 // information available when the clause was created.
6521 assert(getUniqueDeclarationsTotalNumber(Declarations) ==
6522 NumUniqueDeclarations &&
6523 "Unexpected number of mappable expression info entries!");
6524 assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
6525 "Unexpected total number of components!");
6526 assert(Declarations.size() == ComponentLists.size() &&
6527 "Declaration and component lists size is not consistent!");
6528 assert(Declarations.size() == NumComponentLists &&
6529 "Unexpected declaration and component lists size!");
6530
6531 // Organize the components by declaration and retrieve the original
6532 // expression. Original expressions are always the first component of the
6533 // mappable component list.
6534 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
6535 ComponentListMap;
6536 {
6537 auto CI = ComponentLists.begin();
6538 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
6539 ++DI, ++CI) {
6540 assert(!CI->empty() && "Invalid component list!");
6541 ComponentListMap[*DI].push_back(*CI);
6542 }
6543 }
6544
6545 // Iterators of the target storage.
6546 auto UniqueDeclarations = getUniqueDeclsRef();
6547 auto UDI = UniqueDeclarations.begin();
6548
6549 auto DeclNumLists = getDeclNumListsRef();
6550 auto DNLI = DeclNumLists.begin();
6551
6552 auto ComponentListSizes = getComponentListSizesRef();
6553 auto CLSI = ComponentListSizes.begin();
6554
6555 auto Components = getComponentsRef();
6556 auto CI = Components.begin();
6557
6558 // Variable to compute the accumulation of the number of components.
6559 unsigned PrevSize = 0u;
6560
6561 // Scan all the declarations and associated component lists.
6562 for (auto &M : ComponentListMap) {
6563 // The declaration.
6564 auto *D = M.first;
6565 // The component lists.
6566 auto CL = M.second;
6567
6568 // Initialize the entry.
6569 *UDI = D;
6570 ++UDI;
6571
6572 *DNLI = CL.size();
6573 ++DNLI;
6574
6575 // Obtain the cumulative sizes and concatenate all the components in the
6576 // reserved storage.
6577 for (auto C : CL) {
6578 // Accumulate with the previous size.
6579 PrevSize += C.size();
6580
6581 // Save the size.
6582 *CLSI = PrevSize;
6583 ++CLSI;
6584
6585 // Append components after the current components iterator.
6586 CI = llvm::copy(C, CI);
6587 }
6588 }
6589 }
6590
6591 /// Set the nested name specifier of associated user-defined mapper.
6592 void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) {
6593 MapperQualifierLoc = NNSL;
6594 }
6595
6596 /// Set the name of associated user-defined mapper.
6597 void setMapperIdInfo(DeclarationNameInfo MapperId) {
6598 MapperIdInfo = MapperId;
6599 }
6600
6601 /// Get the user-defined mapper references that are in the trailing objects of
6602 /// the class.
6603 MutableArrayRef<Expr *> getUDMapperRefs() {
6604 assert(SupportsMapper &&
6605 "Must be a clause that is possible to have user-defined mappers");
6606 return MutableArrayRef<Expr *>(
6607 static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
6608 OMPVarListClause<T>::varlist_size(),
6609 OMPVarListClause<T>::varlist_size());
6610 }
6611
6612 /// Get the user-defined mappers references that are in the trailing objects
6613 /// of the class.
6615 assert(SupportsMapper &&
6616 "Must be a clause that is possible to have user-defined mappers");
6617 return ArrayRef<Expr *>(
6618 static_cast<const T *>(this)->template getTrailingObjects<Expr *>() +
6619 OMPVarListClause<T>::varlist_size(),
6620 OMPVarListClause<T>::varlist_size());
6621 }
6622
6623 /// Set the user-defined mappers that are in the trailing objects of the
6624 /// class.
6626 assert(DMDs.size() == OMPVarListClause<T>::varlist_size() &&
6627 "Unexpected number of user-defined mappers.");
6628 assert(SupportsMapper &&
6629 "Must be a clause that is possible to have user-defined mappers");
6630 llvm::copy(DMDs, getUDMapperRefs().begin());
6631 }
6632
6633public:
6634 /// Return the number of unique base declarations in this clause.
6635 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
6636
6637 /// Return the number of lists derived from the clause expressions.
6638 unsigned getTotalComponentListNum() const { return NumComponentLists; }
6639
6640 /// Return the total number of components in all lists derived from the
6641 /// clause.
6642 unsigned getTotalComponentsNum() const { return NumComponents; }
6643
6644 /// Gets the nested name specifier for associated user-defined mapper.
6645 NestedNameSpecifierLoc getMapperQualifierLoc() const {
6646 return MapperQualifierLoc;
6647 }
6648
6649 /// Gets the name info for associated user-defined mapper.
6650 const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; }
6651
6652 /// Iterator that browse the components by lists. It also allows
6653 /// browsing components of a single declaration.
6655 : public llvm::iterator_adaptor_base<
6656 const_component_lists_iterator,
6657 MappableExprComponentListRef::const_iterator,
6658 std::forward_iterator_tag, MappableComponent, ptrdiff_t,
6659 MappableComponent, MappableComponent> {
6660 // The declaration the iterator currently refers to.
6662
6663 // The list number associated with the current declaration.
6664 ArrayRef<unsigned>::iterator NumListsCur;
6665
6666 // Whether this clause is possible to have user-defined mappers associated.
6667 const bool SupportsMapper;
6668
6669 // The user-defined mapper associated with the current declaration.
6671
6672 // Remaining lists for the current declaration.
6673 unsigned RemainingLists = 0;
6674
6675 // The cumulative size of the previous list, or zero if there is no previous
6676 // list.
6677 unsigned PrevListSize = 0;
6678
6679 // The cumulative sizes of the current list - it will delimit the remaining
6680 // range of interest.
6683
6684 // Iterator to the end of the components storage.
6685 MappableExprComponentListRef::const_iterator End;
6686
6687 public:
6688 /// Construct an iterator that scans all lists.
6690 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
6691 ArrayRef<unsigned> CumulativeListSizes,
6692 MappableExprComponentListRef Components, bool SupportsMapper,
6693 ArrayRef<Expr *> Mappers)
6694 : const_component_lists_iterator::iterator_adaptor_base(
6695 Components.begin()),
6696 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
6697 SupportsMapper(SupportsMapper),
6698 ListSizeCur(CumulativeListSizes.begin()),
6699 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
6700 assert(UniqueDecls.size() == DeclsListNum.size() &&
6701 "Inconsistent number of declarations and list sizes!");
6702 if (!DeclsListNum.empty())
6703 RemainingLists = *NumListsCur;
6704 if (SupportsMapper)
6705 MapperCur = Mappers.begin();
6706 }
6707
6708 /// Construct an iterator that scan lists for a given declaration \a
6709 /// Declaration.
6711 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
6712 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
6713 MappableExprComponentListRef Components, bool SupportsMapper,
6714 ArrayRef<Expr *> Mappers)
6715 : const_component_lists_iterator(UniqueDecls, DeclsListNum,
6716 CumulativeListSizes, Components,
6717 SupportsMapper, Mappers) {
6718 // Look for the desired declaration. While we are looking for it, we
6719 // update the state so that we know the component where a given list
6720 // starts.
6721 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
6722 if (*DeclCur == Declaration)
6723 break;
6724
6725 assert(*NumListsCur > 0 && "No lists associated with declaration??");
6726
6727 // Skip the lists associated with the current declaration, but save the
6728 // last list size that was skipped.
6729 std::advance(ListSizeCur, *NumListsCur - 1);
6730 PrevListSize = *ListSizeCur;
6731 ++ListSizeCur;
6732
6733 if (SupportsMapper)
6734 ++MapperCur;
6735 }
6736
6737 // If we didn't find any declaration, advance the iterator to after the
6738 // last component and set remaining lists to zero.
6739 if (ListSizeCur == CumulativeListSizes.end()) {
6740 this->I = End;
6741 RemainingLists = 0u;
6742 return;
6743 }
6744
6745 // Set the remaining lists with the total number of lists of the current
6746 // declaration.
6747 RemainingLists = *NumListsCur;
6748
6749 // Adjust the list size end iterator to the end of the relevant range.
6750 ListSizeEnd = ListSizeCur;
6751 std::advance(ListSizeEnd, RemainingLists);
6752
6753 // Given that the list sizes are cumulative, the index of the component
6754 // that start the list is the size of the previous list.
6755 std::advance(this->I, PrevListSize);
6756 }
6757
6758 // Return the array with the current list. The sizes are cumulative, so the
6759 // array size is the difference between the current size and previous one.
6760 std::tuple<const ValueDecl *, MappableExprComponentListRef,
6761 const ValueDecl *>
6762 operator*() const {
6763 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
6764 const ValueDecl *Mapper = nullptr;
6765 if (SupportsMapper && *MapperCur)
6766 Mapper = cast<ValueDecl>(cast<DeclRefExpr>(*MapperCur)->getDecl());
6767 return std::make_tuple(
6768 *DeclCur,
6769 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize),
6770 Mapper);
6771 }
6772 std::tuple<const ValueDecl *, MappableExprComponentListRef,
6773 const ValueDecl *>
6774 operator->() const {
6775 return **this;
6776 }
6777
6778 // Skip the components of the current list.
6780 assert(ListSizeCur != ListSizeEnd && RemainingLists &&
6781 "Invalid iterator!");
6782
6783 // If we don't have more lists just skip all the components. Otherwise,
6784 // advance the iterator by the number of components in the current list.
6785 if (std::next(ListSizeCur) == ListSizeEnd) {
6786 this->I = End;
6787 RemainingLists = 0;
6788 } else {
6789 std::advance(this->I, *ListSizeCur - PrevListSize);
6790 PrevListSize = *ListSizeCur;
6791
6792 // We are done with a declaration, move to the next one.
6793 if (!(--RemainingLists)) {
6794 ++DeclCur;
6795 ++NumListsCur;
6796 RemainingLists = *NumListsCur;
6797 assert(RemainingLists && "No lists in the following declaration??");
6798 }
6799 }
6800
6801 ++ListSizeCur;
6802 if (SupportsMapper)
6803 ++MapperCur;
6804 return *this;
6805 }
6806 };
6807
6809 llvm::iterator_range<const_component_lists_iterator>;
6810
6811 /// Iterators for all component lists.
6828
6829 /// Iterators for component lists associated with the provided
6830 /// declaration.
6831 const_component_lists_iterator
6832 decl_component_lists_begin(const ValueDecl *VD) const {
6835 getComponentListSizesRef(), getComponentsRef(), SupportsMapper,
6836 SupportsMapper ? getUDMapperRefs() : ArrayRef<Expr *>());
6837 }
6844
6845 /// Iterators to access all the declarations, number of lists, list sizes, and
6846 /// components.
6848 using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
6849
6851
6854 llvm::iterator_range<const_all_num_lists_iterator>;
6855
6859
6862 llvm::iterator_range<const_all_lists_sizes_iterator>;
6863
6867
6870 llvm::iterator_range<const_all_components_iterator>;
6871
6875
6876 using mapperlist_iterator = MutableArrayRef<Expr *>::iterator;
6878 using mapperlist_range = llvm::iterator_range<mapperlist_iterator>;
6880 llvm::iterator_range<mapperlist_const_iterator>;
6881
6885 return getUDMapperRefs().begin();
6886 }
6888 return getUDMapperRefs().end();
6889 }
6896};
6897
6898/// This represents clause 'map' in the '#pragma omp ...'
6899/// directives.
6900///
6901/// \code
6902/// #pragma omp target map(a,b)
6903/// \endcode
6904/// In this example directive '#pragma omp target' has clause 'map'
6905/// with the variables 'a' and 'b'.
6906class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
6907 private llvm::TrailingObjects<
6908 OMPMapClause, Expr *, ValueDecl *, unsigned,
6909 OMPClauseMappableExprCommon::MappableComponent> {
6910 friend class OMPClauseReader;
6911 friend OMPMappableExprListClause;
6912 friend OMPVarListClause;
6913 friend TrailingObjects;
6914
6915 /// Define the sizes of each trailing object array except the last one. This
6916 /// is required for TrailingObjects to work properly.
6917 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6918 // There are varlist_size() of expressions, and varlist_size() of
6919 // user-defined mappers.
6920 return 2 * varlist_size() + 1;
6921 }
6922 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6923 return getUniqueDeclarationsNum();
6924 }
6925 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6926 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6927 }
6928
6929private:
6930 /// Map-type-modifiers for the 'map' clause.
6931 OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = {
6936
6937 /// Location of map-type-modifiers for the 'map' clause.
6938 SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers];
6939
6940 /// Map type for the 'map' clause.
6942
6943 /// Is this an implicit map type or not.
6944 bool MapTypeIsImplicit = false;
6945
6946 /// Location of the map type.
6947 SourceLocation MapLoc;
6948
6949 /// Colon location.
6950 SourceLocation ColonLoc;
6951
6952 /// Build a clause for \a NumVars listed expressions, \a
6953 /// NumUniqueDeclarations declarations, \a NumComponentLists total component
6954 /// lists, and \a NumComponents total expression components.
6955 ///
6956 /// \param MapModifiers Map-type-modifiers.
6957 /// \param MapModifiersLoc Locations of map-type-modifiers.
6958 /// \param MapperQualifierLoc C++ nested name specifier for the associated
6959 /// user-defined mapper.
6960 /// \param MapperIdInfo The identifier of associated user-defined mapper.
6961 /// \param MapType Map type.
6962 /// \param MapTypeIsImplicit Map type is inferred implicitly.
6963 /// \param MapLoc Location of the map type.
6964 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6965 /// StartLoc: starting location of the clause (the clause keyword); 2)
6966 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6967 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6968 /// NumVars: number of expressions listed in this clause; 2)
6969 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6970 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6971 /// NumComponents: total number of expression components in the clause.
6972 explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,
6973 ArrayRef<SourceLocation> MapModifiersLoc,
6974 NestedNameSpecifierLoc MapperQualifierLoc,
6975 DeclarationNameInfo MapperIdInfo,
6976 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
6977 SourceLocation MapLoc, const OMPVarListLocTy &Locs,
6978 const OMPMappableExprListSizeTy &Sizes)
6979 : OMPMappableExprListClause(llvm::omp::OMPC_map, Locs, Sizes,
6980 /*SupportsMapper=*/true, &MapperQualifierLoc,
6981 &MapperIdInfo),
6982 MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
6983 assert(std::size(MapTypeModifiers) == MapModifiers.size() &&
6984 "Unexpected number of map type modifiers.");
6985 llvm::copy(MapModifiers, std::begin(MapTypeModifiers));
6986
6987 assert(std::size(MapTypeModifiersLoc) == MapModifiersLoc.size() &&
6988 "Unexpected number of map type modifier locations.");
6989 llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
6990 }
6991
6992 /// Build an empty clause.
6993 ///
6994 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6995 /// NumVars: number of expressions listed in this clause; 2)
6996 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6997 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6998 /// NumComponents: total number of expression components in the clause.
6999 explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes)
7000 : OMPMappableExprListClause(llvm::omp::OMPC_map, OMPVarListLocTy(), Sizes,
7001 /*SupportsMapper=*/true) {}
7002
7003 /// Set map-type-modifier for the clause.
7004 ///
7005 /// \param I index for map-type-modifier.
7006 /// \param T map-type-modifier for the clause.
7007 void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
7008 assert(I < NumberOfOMPMapClauseModifiers &&
7009 "Unexpected index to store map type modifier, exceeds array size.");
7010 MapTypeModifiers[I] = T;
7011 }
7012
7013 /// Set location for the map-type-modifier.
7014 ///
7015 /// \param I index for map-type-modifier location.
7016 /// \param TLoc map-type-modifier location.
7017 void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
7018 assert(I < NumberOfOMPMapClauseModifiers &&
7019 "Index to store map type modifier location exceeds array size.");
7020 MapTypeModifiersLoc[I] = TLoc;
7021 }
7022
7023 /// Set type for the clause.
7024 ///
7025 /// \param T Type for the clause.
7026 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
7027
7028 /// Set type location.
7029 ///
7030 /// \param TLoc Type location.
7031 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
7032
7033 /// Set colon location.
7034 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
7035
7036 /// Set iterator modifier.
7037 void setIteratorModifier(Expr *IteratorModifier) {
7038 getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
7039 }
7040
7041public:
7042 /// Creates clause with a list of variables \a VL.
7043 ///
7044 /// \param C AST context.
7045 /// \param Locs Locations needed to build a mappable clause. It includes 1)
7046 /// StartLoc: starting location of the clause (the clause keyword); 2)
7047 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
7048 /// \param Vars The original expression used in the clause.
7049 /// \param Declarations Declarations used in the clause.
7050 /// \param ComponentLists Component lists used in the clause.
7051 /// \param UDMapperRefs References to user-defined mappers associated with
7052 /// expressions used in the clause.
7053 /// \param IteratorModifier Iterator modifier.
7054 /// \param MapModifiers Map-type-modifiers.
7055 /// \param MapModifiersLoc Location of map-type-modifiers.
7056 /// \param UDMQualifierLoc C++ nested name specifier for the associated
7057 /// user-defined mapper.
7058 /// \param MapperId The identifier of associated user-defined mapper.
7059 /// \param Type Map type.
7060 /// \param TypeIsImplicit Map type is inferred implicitly.
7061 /// \param TypeLoc Location of the map type.
7062 static OMPMapClause *
7063 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
7064 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
7065 MappableExprComponentListsRef ComponentLists,
7066 ArrayRef<Expr *> UDMapperRefs, Expr *IteratorModifier,
7067 ArrayRef<OpenMPMapModifierKind> MapModifiers,
7068 ArrayRef<SourceLocation> MapModifiersLoc,
7069 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
7070 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc);
7071
7072 /// Creates an empty clause with the place for \a NumVars original
7073 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
7074 /// lists, and \a NumComponents expression components.
7075 ///
7076 /// \param C AST context.
7077 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
7078 /// NumVars: number of expressions listed in this clause; 2)
7079 /// NumUniqueDeclarations: number of unique base declarations in this clause;
7080 /// 3) NumComponentLists: number of component lists in this clause; and 4)
7081 /// NumComponents: total number of expression components in the clause.
7082 static OMPMapClause *CreateEmpty(const ASTContext &C,
7083 const OMPMappableExprListSizeTy &Sizes);
7084
7085 /// Fetches Expr * of iterator modifier.
7087 return getTrailingObjects<Expr *>()[2 * varlist_size()];
7088 }
7089
7090 /// Fetches mapping kind for the clause.
7091 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
7092
7093 /// Is this an implicit map type?
7094 /// We have to capture 'IsMapTypeImplicit' from the parser for more
7095 /// informative error messages. It helps distinguish map(r) from
7096 /// map(tofrom: r), which is important to print more helpful error
7097 /// messages for some target directives.
7098 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
7099
7100 /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
7101 ///
7102 /// \param Cnt index for map-type-modifier.
7103 OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
7104 assert(Cnt < NumberOfOMPMapClauseModifiers &&
7105 "Requested modifier exceeds the total number of modifiers.");
7106 return MapTypeModifiers[Cnt];
7107 }
7108
7109 /// Fetches the map-type-modifier location at 'Cnt' index of array of
7110 /// modifiers' locations.
7111 ///
7112 /// \param Cnt index for map-type-modifier location.
7113 SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
7114 assert(Cnt < NumberOfOMPMapClauseModifiers &&
7115 "Requested modifier location exceeds total number of modifiers.");
7116 return MapTypeModifiersLoc[Cnt];
7117 }
7118
7119 /// Fetches ArrayRef of map-type-modifiers.
7121 return MapTypeModifiers;
7122 }
7123
7124 /// Fetches ArrayRef of location of map-type-modifiers.
7126 return MapTypeModifiersLoc;
7127 }
7128
7129 /// Fetches location of clause mapping kind.
7130 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
7131
7132 /// Get colon location.
7133 SourceLocation getColonLoc() const { return ColonLoc; }
7134
7135 child_range children() {
7136 return child_range(
7137 reinterpret_cast<Stmt **>(varlist_begin()),
7138 reinterpret_cast<Stmt **>(varlist_end()));
7139 }
7140
7141 const_child_range children() const {
7142 return const_cast<OMPMapClause *>(this)->children();
7143 }
7144
7145 child_range used_children() {
7146 if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_tofrom)
7147 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7148 reinterpret_cast<Stmt **>(varlist_end()));
7149 return child_range(child_iterator(), child_iterator());
7150 }
7151 const_child_range used_children() const {
7152 return const_cast<OMPMapClause *>(this)->used_children();
7153 }
7154
7155
7156 static bool classof(const OMPClause *T) {
7157 return T->getClauseKind() == llvm::omp::OMPC_map;
7158 }
7159};
7160
7161/// This represents 'num_teams' clause in the '#pragma omp ...'
7162/// directive.
7163///
7164/// \code
7165/// #pragma omp teams num_teams(n)
7166/// \endcode
7167/// In this example directive '#pragma omp teams' has clause 'num_teams'
7168/// with single expression 'n'.
7169///
7170/// \code
7171/// #pragma omp teams num_teams(m:n)
7172/// \endcode
7173/// In this example directive '#pragma omp teams' has clause 'num_teams' with
7174/// single expression 'n' as upper-bound and modifier expression 'm' as
7175/// lower-bound.
7176///
7177/// \code
7178/// #pragma omp teams num_teams(dims(2): x, y)
7179/// \endcode
7180/// In this example directive '#pragma omp teams' has clause 'num_teams' with
7181/// the 'dims' modifier specifying two dimensions. The list specifies the number
7182/// of teams in each dimension.
7183///
7184/// When 'ompx_bare' clause exists on a 'target' directive, 'num_teams' clause
7185/// can accept up to three expressions.
7186///
7187/// \code
7188/// #pragma omp target teams ompx_bare num_teams(x, y, z)
7189/// \endcode
7190class OMPNumTeamsClause final
7191 : public OMPVarListClause<OMPNumTeamsClause>,
7192 public OMPClauseWithPreInit,
7193 private llvm::TrailingObjects<OMPNumTeamsClause, Expr *> {
7194 friend class OMPClauseReader;
7195 friend OMPVarListClause;
7196 friend TrailingObjects;
7197
7198 /// Modifier that was specified.
7199 OpenMPNumTeamsClauseModifier Modifier = OMPC_NUMTEAMS_unknown;
7200
7201 /// Location of the modifier.
7202 SourceLocation ModifierLoc;
7203
7204 OMPNumTeamsClause(const ASTContext &C, SourceLocation StartLoc,
7205 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
7206 : OMPVarListClause(llvm::omp::OMPC_num_teams, StartLoc, LParenLoc, EndLoc,
7207 N),
7208 OMPClauseWithPreInit(this) {}
7209
7210 /// Build an empty clause.
7211 OMPNumTeamsClause(unsigned N)
7212 : OMPVarListClause(llvm::omp::OMPC_num_teams, SourceLocation(),
7213 SourceLocation(), SourceLocation(), N),
7214 OMPClauseWithPreInit(this) {}
7215
7216 /// Set the modifier.
7217 void setModifier(OpenMPNumTeamsClauseModifier M) { Modifier = M; }
7218
7219 /// Set the expression of the modifier.
7220 void setModifierExpr(Expr *E) { *varlist_end() = E; }
7221
7222 /// Set the location of the modifier.
7223 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
7224
7225public:
7226 /// Creates clause with a list of variables \a VL.
7227 ///
7228 /// \param C AST context.
7229 /// \param StartLoc Starting location of the clause.
7230 /// \param LParenLoc Location of '('.
7231 /// \param EndLoc Ending location of the clause.
7232 /// \param VL List of references to the variables.
7233 /// \param Modifier The modifier specified in the clause.
7234 /// \param ModifierExpr The expression of the modifier.
7235 /// \param ModifierLoc Location of the modifier.
7236 /// \param PreInit
7237 static OMPNumTeamsClause *
7238 Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
7239 SourceLocation StartLoc, SourceLocation LParenLoc,
7240 SourceLocation EndLoc, ArrayRef<Expr *> VL,
7241 OpenMPNumTeamsClauseModifier Modifier, Expr *ModifierExpr,
7242 SourceLocation ModifierLoc, Stmt *PreInit);
7243
7244 /// Creates an empty clause with \a N variables.
7245 ///
7246 /// \param C AST context.
7247 /// \param N The number of variables.
7248 static OMPNumTeamsClause *CreateEmpty(const ASTContext &C, unsigned N);
7249
7250 /// Return NumTeams expressions.
7251 ArrayRef<Expr *> getNumTeams() { return getVarRefs(); }
7252
7253 /// Return NumTeams expressions.
7255 return const_cast<OMPNumTeamsClause *>(this)->getNumTeams();
7256 }
7257
7258 /// Get the modifier.
7259 OpenMPNumTeamsClauseModifier getModifier() const { return Modifier; }
7260
7261 /// Get the expression of the modifier.
7262 const Expr *getModifierExpr() const { return *varlist_end(); }
7263
7264 /// Get the expression of the modifier.
7265 Expr *getModifierExpr() { return *varlist_end(); }
7266
7267 /// Get the expression of the modifier if it is the dims modifier.
7268 const Expr *getDimsModifierExpr() const {
7269 if (Modifier == OMPC_NUMTEAMS_dims)
7270 return getModifierExpr();
7271 return nullptr;
7272 }
7273
7274 /// Get the location of the modifier.
7275 SourceLocation getModifierLoc() const { return ModifierLoc; }
7276
7277 child_range children() {
7278 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7279 reinterpret_cast<Stmt **>(varlist_end()) + 1);
7280 }
7281
7282 const_child_range children() const {
7283 return const_cast<OMPNumTeamsClause *>(this)->children();
7284 }
7285
7286 child_range used_children() {
7287 return child_range(child_iterator(), child_iterator());
7288 }
7289 const_child_range used_children() const {
7290 return const_child_range(const_child_iterator(), const_child_iterator());
7291 }
7292
7293 static bool classof(const OMPClause *T) {
7294 return T->getClauseKind() == llvm::omp::OMPC_num_teams;
7295 }
7296};
7297
7298/// This represents 'thread_limit' clause in the '#pragma omp ...'
7299/// directive.
7300///
7301/// \code
7302/// #pragma omp teams thread_limit(n)
7303/// \endcode
7304/// In this example directive '#pragma omp teams' has clause 'thread_limit'
7305/// with single expression 'n'.
7306///
7307/// \code
7308/// #pragma omp teams thread_limit(dims(2): x, y)
7309/// \endcode
7310/// In this example directive '#pragma omp teams' has clause 'thread_limit' with
7311/// the 'dims' modifier specifying two dimensions. The list specifies the limit
7312/// on the number of threads in each dimension.
7313///
7314/// When 'ompx_bare' clause exists on a 'target' directive, 'thread_limit'
7315/// clause can accept up to three expressions.
7316///
7317/// \code
7318/// #pragma omp target teams ompx_bare thread_limit(x, y, z)
7319/// \endcode
7320class OMPThreadLimitClause final
7321 : public OMPVarListClause<OMPThreadLimitClause>,
7322 public OMPClauseWithPreInit,
7323 private llvm::TrailingObjects<OMPThreadLimitClause, Expr *> {
7324 friend class OMPClauseReader;
7325 friend OMPVarListClause;
7326 friend TrailingObjects;
7327
7328 /// Modifier that was specified.
7329 OpenMPThreadLimitClauseModifier Modifier = OMPC_THREADLIMIT_unknown;
7330
7331 /// Location of the modifier.
7332 SourceLocation ModifierLoc;
7333
7334 OMPThreadLimitClause(const ASTContext &C, SourceLocation StartLoc,
7335 SourceLocation LParenLoc, SourceLocation EndLoc,
7336 unsigned N)
7337 : OMPVarListClause(llvm::omp::OMPC_thread_limit, StartLoc, LParenLoc,
7338 EndLoc, N),
7339 OMPClauseWithPreInit(this) {}
7340
7341 /// Build an empty clause.
7342 OMPThreadLimitClause(unsigned N)
7343 : OMPVarListClause(llvm::omp::OMPC_thread_limit, SourceLocation(),
7344 SourceLocation(), SourceLocation(), N),
7345 OMPClauseWithPreInit(this) {}
7346
7347 /// Set the modifier.
7348 void setModifier(OpenMPThreadLimitClauseModifier M) { Modifier = M; }
7349
7350 /// Set the location of the modifier.
7351 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
7352
7353 /// Set the expression of the modifier.
7354 void setModifierExpr(Expr *E) { *varlist_end() = E; }
7355
7356public:
7357 /// Creates clause with a list of variables \a VL.
7358 ///
7359 /// \param C AST context.
7360 /// \param StartLoc Starting location of the clause.
7361 /// \param LParenLoc Location of '('.
7362 /// \param EndLoc Ending location of the clause.
7363 /// \param VL List of references to the variables.
7364 /// \param Modifier The modifier specified in the clause.
7365 /// \param ModifierExpr The expression of the modifier.
7366 /// \param ModifierLoc Location of the modifier.
7367 /// \param PreInit
7368 static OMPThreadLimitClause *
7369 Create(const ASTContext &C, OpenMPDirectiveKind CaptureRegion,
7370 SourceLocation StartLoc, SourceLocation LParenLoc,
7371 SourceLocation EndLoc, ArrayRef<Expr *> VL,
7372 OpenMPThreadLimitClauseModifier Modifier, Expr *ModifierExpr,
7373 SourceLocation ModifierLoc, Stmt *PreInit);
7374
7375 /// Creates an empty clause with \a N variables.
7376 ///
7377 /// \param C AST context.
7378 /// \param N The number of variables.
7379 static OMPThreadLimitClause *CreateEmpty(const ASTContext &C, unsigned N);
7380
7381 /// Return ThreadLimit expressions.
7382 ArrayRef<Expr *> getThreadLimit() { return getVarRefs(); }
7383
7384 /// Return ThreadLimit expressions.
7386 return const_cast<OMPThreadLimitClause *>(this)->getThreadLimit();
7387 }
7388
7389 /// Get the modifier.
7390 OpenMPThreadLimitClauseModifier getModifier() const { return Modifier; }
7391
7392 /// Get the expression of the modifier.
7393 const Expr *getModifierExpr() const { return *varlist_end(); }
7394
7395 /// Get the expression of the modifier.
7396 Expr *getModifierExpr() { return *varlist_end(); }
7397
7398 /// Get the expression of the modifier if it is the dims modifier.
7399 const Expr *getDimsModifierExpr() const {
7400 if (Modifier == OMPC_THREADLIMIT_dims)
7401 return getModifierExpr();
7402 return nullptr;
7403 }
7404
7405 /// Get the location of the modifier.
7406 SourceLocation getModifierLoc() const { return ModifierLoc; }
7407
7408 child_range children() {
7409 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7410 reinterpret_cast<Stmt **>(varlist_end()) + 1);
7411 }
7412
7413 const_child_range children() const {
7414 return const_cast<OMPThreadLimitClause *>(this)->children();
7415 }
7416
7417 child_range used_children() {
7418 return child_range(child_iterator(), child_iterator());
7419 }
7420 const_child_range used_children() const {
7421 return const_child_range(const_child_iterator(), const_child_iterator());
7422 }
7423
7424 static bool classof(const OMPClause *T) {
7425 return T->getClauseKind() == llvm::omp::OMPC_thread_limit;
7426 }
7427};
7428
7429/// This represents 'priority' clause in the '#pragma omp ...'
7430/// directive.
7431///
7432/// \code
7433/// #pragma omp task priority(n)
7434/// \endcode
7435/// In this example directive '#pragma omp teams' has clause 'priority' with
7436/// single expression 'n'.
7438 friend class OMPClauseReader;
7439
7440 /// Location of '('.
7441 SourceLocation LParenLoc;
7442
7443 /// Priority number.
7444 Stmt *Priority = nullptr;
7445
7446 /// Set the Priority number.
7447 ///
7448 /// \param E Priority number.
7449 void setPriority(Expr *E) { Priority = E; }
7450
7451public:
7452 /// Build 'priority' clause.
7453 ///
7454 /// \param Priority Expression associated with this clause.
7455 /// \param HelperPriority Helper priority for the construct.
7456 /// \param CaptureRegion Innermost OpenMP region where expressions in this
7457 /// clause must be captured.
7458 /// \param StartLoc Starting location of the clause.
7459 /// \param LParenLoc Location of '('.
7460 /// \param EndLoc Ending location of the clause.
7461 OMPPriorityClause(Expr *Priority, Stmt *HelperPriority,
7462 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
7463 SourceLocation LParenLoc, SourceLocation EndLoc)
7464 : OMPClause(llvm::omp::OMPC_priority, StartLoc, EndLoc),
7465 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Priority(Priority) {
7466 setPreInitStmt(HelperPriority, CaptureRegion);
7467 }
7468
7469 /// Build an empty clause.
7471 : OMPClause(llvm::omp::OMPC_priority, SourceLocation(), SourceLocation()),
7472 OMPClauseWithPreInit(this) {}
7473
7474 /// Sets the location of '('.
7475 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7476
7477 /// Returns the location of '('.
7478 SourceLocation getLParenLoc() const { return LParenLoc; }
7479
7480 /// Return Priority number.
7481 Expr *getPriority() { return cast<Expr>(Priority); }
7482
7483 /// Return Priority number.
7484 Expr *getPriority() const { return cast<Expr>(Priority); }
7485
7486 child_range children() { return child_range(&Priority, &Priority + 1); }
7487
7488 const_child_range children() const {
7489 return const_child_range(&Priority, &Priority + 1);
7490 }
7491
7492 child_range used_children();
7493 const_child_range used_children() const {
7494 return const_cast<OMPPriorityClause *>(this)->used_children();
7495 }
7496
7497 static bool classof(const OMPClause *T) {
7498 return T->getClauseKind() == llvm::omp::OMPC_priority;
7499 }
7500};
7501
7502/// This represents 'grainsize' clause in the '#pragma omp ...'
7503/// directive.
7504///
7505/// \code
7506/// #pragma omp taskloop grainsize(4)
7507/// \endcode
7508/// In this example directive '#pragma omp taskloop' has clause 'grainsize'
7509/// with single expression '4'.
7511 friend class OMPClauseReader;
7512
7513 /// Location of '('.
7514 SourceLocation LParenLoc;
7515
7516 /// Modifiers for 'grainsize' clause.
7517 OpenMPGrainsizeClauseModifier Modifier = OMPC_GRAINSIZE_unknown;
7518
7519 /// Location of the modifier.
7520 SourceLocation ModifierLoc;
7521
7522 /// Safe iteration space distance.
7523 Stmt *Grainsize = nullptr;
7524
7525 /// Set safelen.
7526 void setGrainsize(Expr *Size) { Grainsize = Size; }
7527
7528 /// Sets modifier.
7529 void setModifier(OpenMPGrainsizeClauseModifier M) { Modifier = M; }
7530
7531 /// Sets modifier location.
7532 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
7533
7534public:
7535 /// Build 'grainsize' clause.
7536 ///
7537 /// \param Modifier Clause modifier.
7538 /// \param Size Expression associated with this clause.
7539 /// \param HelperSize Helper grainsize for the construct.
7540 /// \param CaptureRegion Innermost OpenMP region where expressions in this
7541 /// clause must be captured.
7542 /// \param StartLoc Starting location of the clause.
7543 /// \param ModifierLoc Modifier location.
7544 /// \param LParenLoc Location of '('.
7545 /// \param EndLoc Ending location of the clause.
7546 OMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size,
7547 Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion,
7548 SourceLocation StartLoc, SourceLocation LParenLoc,
7549 SourceLocation ModifierLoc, SourceLocation EndLoc)
7550 : OMPClause(llvm::omp::OMPC_grainsize, StartLoc, EndLoc),
7551 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
7552 ModifierLoc(ModifierLoc), Grainsize(Size) {
7553 setPreInitStmt(HelperSize, CaptureRegion);
7554 }
7555
7556 /// Build an empty clause.
7558 : OMPClause(llvm::omp::OMPC_grainsize, SourceLocation(),
7559 SourceLocation()),
7560 OMPClauseWithPreInit(this) {}
7561
7562 /// Sets the location of '('.
7563 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7564
7565 /// Returns the location of '('.
7566 SourceLocation getLParenLoc() const { return LParenLoc; }
7567
7568 /// Return safe iteration space distance.
7569 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
7570
7571 /// Gets modifier.
7572 OpenMPGrainsizeClauseModifier getModifier() const { return Modifier; }
7573
7574 /// Gets modifier location.
7575 SourceLocation getModifierLoc() const { return ModifierLoc; }
7576
7577 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
7578
7579 const_child_range children() const {
7580 return const_child_range(&Grainsize, &Grainsize + 1);
7581 }
7582
7583 child_range used_children();
7584 const_child_range used_children() const {
7585 return const_cast<OMPGrainsizeClause *>(this)->used_children();
7586 }
7587
7588 static bool classof(const OMPClause *T) {
7589 return T->getClauseKind() == llvm::omp::OMPC_grainsize;
7590 }
7591};
7592
7593/// This represents 'nogroup' clause in the '#pragma omp ...' directive.
7594///
7595/// \code
7596/// #pragma omp taskloop nogroup
7597/// \endcode
7598/// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
7600public:
7601 /// Build 'nogroup' clause.
7602 ///
7603 /// \param StartLoc Starting location of the clause.
7604 /// \param EndLoc Ending location of the clause.
7605 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
7606 : OMPClause(llvm::omp::OMPC_nogroup, StartLoc, EndLoc) {}
7607
7608 /// Build an empty clause.
7610 : OMPClause(llvm::omp::OMPC_nogroup, SourceLocation(), SourceLocation()) {
7611 }
7612
7613 child_range children() {
7614 return child_range(child_iterator(), child_iterator());
7615 }
7616
7617 const_child_range children() const {
7618 return const_child_range(const_child_iterator(), const_child_iterator());
7619 }
7620
7621 child_range used_children() {
7622 return child_range(child_iterator(), child_iterator());
7623 }
7624 const_child_range used_children() const {
7625 return const_child_range(const_child_iterator(), const_child_iterator());
7626 }
7627
7628 static bool classof(const OMPClause *T) {
7629 return T->getClauseKind() == llvm::omp::OMPC_nogroup;
7630 }
7631};
7632
7633/// This represents 'num_tasks' clause in the '#pragma omp ...'
7634/// directive.
7635///
7636/// \code
7637/// #pragma omp taskloop num_tasks(4)
7638/// \endcode
7639/// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
7640/// with single expression '4'.
7642 friend class OMPClauseReader;
7643
7644 /// Location of '('.
7645 SourceLocation LParenLoc;
7646
7647 /// Modifiers for 'num_tasks' clause.
7648 OpenMPNumTasksClauseModifier Modifier = OMPC_NUMTASKS_unknown;
7649
7650 /// Location of the modifier.
7651 SourceLocation ModifierLoc;
7652
7653 /// Safe iteration space distance.
7654 Stmt *NumTasks = nullptr;
7655
7656 /// Set safelen.
7657 void setNumTasks(Expr *Size) { NumTasks = Size; }
7658
7659 /// Sets modifier.
7660 void setModifier(OpenMPNumTasksClauseModifier M) { Modifier = M; }
7661
7662 /// Sets modifier location.
7663 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
7664
7665public:
7666 /// Build 'num_tasks' clause.
7667 ///
7668 /// \param Modifier Clause modifier.
7669 /// \param Size Expression associated with this clause.
7670 /// \param HelperSize Helper grainsize for the construct.
7671 /// \param CaptureRegion Innermost OpenMP region where expressions in this
7672 /// clause must be captured.
7673 /// \param StartLoc Starting location of the clause.
7674 /// \param EndLoc Ending location of the clause.
7675 /// \param ModifierLoc Modifier location.
7676 /// \param LParenLoc Location of '('.
7677 OMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *Size,
7678 Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion,
7679 SourceLocation StartLoc, SourceLocation LParenLoc,
7680 SourceLocation ModifierLoc, SourceLocation EndLoc)
7681 : OMPClause(llvm::omp::OMPC_num_tasks, StartLoc, EndLoc),
7682 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
7683 ModifierLoc(ModifierLoc), NumTasks(Size) {
7684 setPreInitStmt(HelperSize, CaptureRegion);
7685 }
7686
7687 /// Build an empty clause.
7689 : OMPClause(llvm::omp::OMPC_num_tasks, SourceLocation(),
7690 SourceLocation()),
7691 OMPClauseWithPreInit(this) {}
7692
7693 /// Sets the location of '('.
7694 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7695
7696 /// Returns the location of '('.
7697 SourceLocation getLParenLoc() const { return LParenLoc; }
7698
7699 /// Return safe iteration space distance.
7700 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
7701
7702 /// Gets modifier.
7703 OpenMPNumTasksClauseModifier getModifier() const { return Modifier; }
7704
7705 /// Gets modifier location.
7706 SourceLocation getModifierLoc() const { return ModifierLoc; }
7707
7708 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
7709
7710 const_child_range children() const {
7711 return const_child_range(&NumTasks, &NumTasks + 1);
7712 }
7713
7714 child_range used_children();
7715 const_child_range used_children() const {
7716 return const_cast<OMPNumTasksClause *>(this)->used_children();
7717 }
7718
7719 static bool classof(const OMPClause *T) {
7720 return T->getClauseKind() == llvm::omp::OMPC_num_tasks;
7721 }
7722};
7723
7724/// This represents 'hint' clause in the '#pragma omp ...' directive.
7725///
7726/// \code
7727/// #pragma omp critical (name) hint(6)
7728/// \endcode
7729/// In this example directive '#pragma omp critical' has name 'name' and clause
7730/// 'hint' with argument '6'.
7731class OMPHintClause : public OMPClause {
7732 friend class OMPClauseReader;
7733
7734 /// Location of '('.
7735 SourceLocation LParenLoc;
7736
7737 /// Hint expression of the 'hint' clause.
7738 Stmt *Hint = nullptr;
7739
7740 /// Set hint expression.
7741 void setHint(Expr *H) { Hint = H; }
7742
7743public:
7744 /// Build 'hint' clause with expression \a Hint.
7745 ///
7746 /// \param Hint Hint expression.
7747 /// \param StartLoc Starting location of the clause.
7748 /// \param LParenLoc Location of '('.
7749 /// \param EndLoc Ending location of the clause.
7750 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
7751 SourceLocation EndLoc)
7752 : OMPClause(llvm::omp::OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
7753 Hint(Hint) {}
7754
7755 /// Build an empty clause.
7757 : OMPClause(llvm::omp::OMPC_hint, SourceLocation(), SourceLocation()) {}
7758
7759 /// Sets the location of '('.
7760 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7761
7762 /// Returns the location of '('.
7763 SourceLocation getLParenLoc() const { return LParenLoc; }
7764
7765 /// Returns number of threads.
7766 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
7767
7768 child_range children() { return child_range(&Hint, &Hint + 1); }
7769
7770 const_child_range children() const {
7771 return const_child_range(&Hint, &Hint + 1);
7772 }
7773
7774 child_range used_children() {
7775 return child_range(child_iterator(), child_iterator());
7776 }
7777 const_child_range used_children() const {
7778 return const_child_range(const_child_iterator(), const_child_iterator());
7779 }
7780
7781 static bool classof(const OMPClause *T) {
7782 return T->getClauseKind() == llvm::omp::OMPC_hint;
7783 }
7784};
7785
7786/// This represents 'dist_schedule' clause in the '#pragma omp ...'
7787/// directive.
7788///
7789/// \code
7790/// #pragma omp distribute dist_schedule(static, 3)
7791/// \endcode
7792/// In this example directive '#pragma omp distribute' has 'dist_schedule'
7793/// clause with arguments 'static' and '3'.
7795 friend class OMPClauseReader;
7796
7797 /// Location of '('.
7798 SourceLocation LParenLoc;
7799
7800 /// A kind of the 'schedule' clause.
7801 OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
7802
7803 /// Start location of the schedule kind in source code.
7804 SourceLocation KindLoc;
7805
7806 /// Location of ',' (if any).
7807 SourceLocation CommaLoc;
7808
7809 /// Chunk size.
7810 Expr *ChunkSize = nullptr;
7811
7812 /// Set schedule kind.
7813 ///
7814 /// \param K Schedule kind.
7815 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
7816
7817 /// Sets the location of '('.
7818 ///
7819 /// \param Loc Location of '('.
7820 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7821
7822 /// Set schedule kind start location.
7823 ///
7824 /// \param KLoc Schedule kind location.
7825 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
7826
7827 /// Set location of ','.
7828 ///
7829 /// \param Loc Location of ','.
7830 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
7831
7832 /// Set chunk size.
7833 ///
7834 /// \param E Chunk size.
7835 void setChunkSize(Expr *E) { ChunkSize = E; }
7836
7837public:
7838 /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
7839 /// size expression \a ChunkSize.
7840 ///
7841 /// \param StartLoc Starting location of the clause.
7842 /// \param LParenLoc Location of '('.
7843 /// \param KLoc Starting location of the argument.
7844 /// \param CommaLoc Location of ','.
7845 /// \param EndLoc Ending location of the clause.
7846 /// \param Kind DistSchedule kind.
7847 /// \param ChunkSize Chunk size.
7848 /// \param HelperChunkSize Helper chunk size for combined directives.
7849 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7850 SourceLocation KLoc, SourceLocation CommaLoc,
7851 SourceLocation EndLoc,
7852 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
7853 Stmt *HelperChunkSize)
7854 : OMPClause(llvm::omp::OMPC_dist_schedule, StartLoc, EndLoc),
7855 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
7856 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
7857 setPreInitStmt(HelperChunkSize);
7858 }
7859
7860 /// Build an empty clause.
7862 : OMPClause(llvm::omp::OMPC_dist_schedule, SourceLocation(),
7863 SourceLocation()),
7864 OMPClauseWithPreInit(this) {}
7865
7866 /// Get kind of the clause.
7867 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
7868
7869 /// Get location of '('.
7870 SourceLocation getLParenLoc() { return LParenLoc; }
7871
7872 /// Get kind location.
7873 SourceLocation getDistScheduleKindLoc() { return KindLoc; }
7874
7875 /// Get location of ','.
7876 SourceLocation getCommaLoc() { return CommaLoc; }
7877
7878 /// Get chunk size.
7879 Expr *getChunkSize() { return ChunkSize; }
7880
7881 /// Get chunk size.
7882 const Expr *getChunkSize() const { return ChunkSize; }
7883
7884 child_range children() {
7885 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
7886 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
7887 }
7888
7889 const_child_range children() const {
7890 return const_cast<OMPDistScheduleClause *>(this)->children();
7891 }
7892
7893 child_range used_children() {
7894 return child_range(child_iterator(), child_iterator());
7895 }
7896 const_child_range used_children() const {
7897 return const_child_range(const_child_iterator(), const_child_iterator());
7898 }
7899
7900 static bool classof(const OMPClause *T) {
7901 return T->getClauseKind() == llvm::omp::OMPC_dist_schedule;
7902 }
7903};
7904
7905/// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
7906///
7907/// \code
7908/// #pragma omp target defaultmap(tofrom: scalar)
7909/// \endcode
7910/// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
7911/// 'scalar' with modifier 'tofrom'.
7913 friend class OMPClauseReader;
7914
7915 /// Location of '('.
7916 SourceLocation LParenLoc;
7917
7918 /// Modifiers for 'defaultmap' clause.
7919 OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
7920
7921 /// Locations of modifiers.
7922 SourceLocation ModifierLoc;
7923
7924 /// A kind of the 'defaultmap' clause.
7925 OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
7926
7927 /// Start location of the defaultmap kind in source code.
7928 SourceLocation KindLoc;
7929
7930 /// Set defaultmap kind.
7931 ///
7932 /// \param K Defaultmap kind.
7933 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
7934
7935 /// Set the defaultmap modifier.
7936 ///
7937 /// \param M Defaultmap modifier.
7938 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
7939 Modifier = M;
7940 }
7941
7942 /// Set location of the defaultmap modifier.
7943 void setDefaultmapModifierLoc(SourceLocation Loc) {
7944 ModifierLoc = Loc;
7945 }
7946
7947 /// Sets the location of '('.
7948 ///
7949 /// \param Loc Location of '('.
7950 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7951
7952 /// Set defaultmap kind start location.
7953 ///
7954 /// \param KLoc Defaultmap kind location.
7955 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
7956
7957public:
7958 /// Build 'defaultmap' clause with defaultmap kind \a Kind
7959 ///
7960 /// \param StartLoc Starting location of the clause.
7961 /// \param LParenLoc Location of '('.
7962 /// \param KLoc Starting location of the argument.
7963 /// \param EndLoc Ending location of the clause.
7964 /// \param Kind Defaultmap kind.
7965 /// \param M The modifier applied to 'defaultmap' clause.
7966 /// \param MLoc Location of the modifier
7967 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7968 SourceLocation MLoc, SourceLocation KLoc,
7969 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
7970 OpenMPDefaultmapClauseModifier M)
7971 : OMPClause(llvm::omp::OMPC_defaultmap, StartLoc, EndLoc),
7972 LParenLoc(LParenLoc), Modifier(M), ModifierLoc(MLoc), Kind(Kind),
7973 KindLoc(KLoc) {}
7974
7975 /// Build an empty clause.
7977 : OMPClause(llvm::omp::OMPC_defaultmap, SourceLocation(),
7978 SourceLocation()) {}
7979
7980 /// Get kind of the clause.
7981 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
7982
7983 /// Get the modifier of the clause.
7984 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
7985 return Modifier;
7986 }
7987
7988 /// Get location of '('.
7989 SourceLocation getLParenLoc() { return LParenLoc; }
7990
7991 /// Get kind location.
7992 SourceLocation getDefaultmapKindLoc() { return KindLoc; }
7993
7994 /// Get the modifier location.
7995 SourceLocation getDefaultmapModifierLoc() const {
7996 return ModifierLoc;
7997 }
7998
7999 child_range children() {
8000 return child_range(child_iterator(), child_iterator());
8001 }
8002
8003 const_child_range children() const {
8004 return const_child_range(const_child_iterator(), const_child_iterator());
8005 }
8006
8007 child_range used_children() {
8008 return child_range(child_iterator(), child_iterator());
8009 }
8010 const_child_range used_children() const {
8011 return const_child_range(const_child_iterator(), const_child_iterator());
8012 }
8013
8014 static bool classof(const OMPClause *T) {
8015 return T->getClauseKind() == llvm::omp::OMPC_defaultmap;
8016 }
8017};
8018
8019/// This represents clause 'to' in the '#pragma omp ...'
8020/// directives.
8021///
8022/// \code
8023/// #pragma omp target update to(a,b)
8024/// \endcode
8025/// In this example directive '#pragma omp target update' has clause 'to'
8026/// with the variables 'a' and 'b'.
8027class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
8028 private llvm::TrailingObjects<
8029 OMPToClause, Expr *, ValueDecl *, unsigned,
8030 OMPClauseMappableExprCommon::MappableComponent> {
8031 friend class OMPClauseReader;
8032 friend OMPMappableExprListClause;
8033 friend OMPVarListClause;
8034 friend TrailingObjects;
8035
8036 /// Motion-modifiers for the 'to' clause.
8037 OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
8038 OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown,
8039 OMPC_MOTION_MODIFIER_unknown};
8040
8041 /// Location of motion-modifiers for the 'to' clause.
8042 SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
8043
8044 /// Colon location.
8045 SourceLocation ColonLoc;
8046
8047 /// Build clause with number of variables \a NumVars.
8048 ///
8049 /// \param TheMotionModifiers Motion-modifiers.
8050 /// \param TheMotionModifiersLoc Locations of motion-modifiers.
8051 /// \param MapperQualifierLoc C++ nested name specifier for the associated
8052 /// user-defined mapper.
8053 /// \param MapperIdInfo The identifier of associated user-defined mapper.
8054 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8055 /// StartLoc: starting location of the clause (the clause keyword); 2)
8056 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8057 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8058 /// NumVars: number of expressions listed in this clause; 2)
8059 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8060 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8061 /// NumComponents: total number of expression components in the clause.
8062 explicit OMPToClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
8063 ArrayRef<SourceLocation> TheMotionModifiersLoc,
8064 NestedNameSpecifierLoc MapperQualifierLoc,
8065 DeclarationNameInfo MapperIdInfo,
8066 const OMPVarListLocTy &Locs,
8067 const OMPMappableExprListSizeTy &Sizes)
8068 : OMPMappableExprListClause(llvm::omp::OMPC_to, Locs, Sizes,
8069 /*SupportsMapper=*/true, &MapperQualifierLoc,
8070 &MapperIdInfo) {
8071 assert(std::size(MotionModifiers) == TheMotionModifiers.size() &&
8072 "Unexpected number of motion modifiers.");
8073 llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
8074
8075 assert(std::size(MotionModifiersLoc) == TheMotionModifiersLoc.size() &&
8076 "Unexpected number of motion modifier locations.");
8077 llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
8078 }
8079
8080 /// Build an empty clause.
8081 ///
8082 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8083 /// NumVars: number of expressions listed in this clause; 2)
8084 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8085 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8086 /// NumComponents: total number of expression components in the clause.
8087 explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes)
8088 : OMPMappableExprListClause(llvm::omp::OMPC_to, OMPVarListLocTy(), Sizes,
8089 /*SupportsMapper=*/true) {}
8090
8091 /// Set motion-modifier for the clause.
8092 ///
8093 /// \param I index for motion-modifier.
8094 /// \param T motion-modifier for the clause.
8095 void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
8096 assert(I < NumberOfOMPMotionModifiers &&
8097 "Unexpected index to store motion modifier, exceeds array size.");
8098 MotionModifiers[I] = T;
8099 }
8100
8101 /// Set location for the motion-modifier.
8102 ///
8103 /// \param I index for motion-modifier location.
8104 /// \param TLoc motion-modifier location.
8105 void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
8106 assert(I < NumberOfOMPMotionModifiers &&
8107 "Index to store motion modifier location exceeds array size.");
8108 MotionModifiersLoc[I] = TLoc;
8109 }
8110
8111 void setIteratorModifier(Expr *IteratorModifier) {
8112 getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
8113 }
8114 /// Set colon location.
8115 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
8116
8117 /// Define the sizes of each trailing object array except the last one. This
8118 /// is required for TrailingObjects to work properly.
8119 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8120 // There are varlist_size() of expressions, and varlist_size() of
8121 // user-defined mappers.
8122 return 2 * varlist_size() + 1;
8123 }
8124 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8125 return getUniqueDeclarationsNum();
8126 }
8127 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8128 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8129 }
8130
8131public:
8132 /// Creates clause with a list of variables \a Vars.
8133 ///
8134 /// \param C AST context.
8135 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8136 /// StartLoc: starting location of the clause (the clause keyword); 2)
8137 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8138 /// \param Vars The original expression used in the clause.
8139 /// \param Declarations Declarations used in the clause.
8140 /// \param ComponentLists Component lists used in the clause.
8141 /// \param MotionModifiers Motion-modifiers.
8142 /// \param MotionModifiersLoc Location of motion-modifiers.
8143 /// \param UDMapperRefs References to user-defined mappers associated with
8144 /// expressions used in the clause.
8145 /// \param UDMQualifierLoc C++ nested name specifier for the associated
8146 /// user-defined mapper.
8147 /// \param MapperId The identifier of associated user-defined mapper.
8148 static OMPToClause *
8149 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8150 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8151 MappableExprComponentListsRef ComponentLists,
8152 ArrayRef<Expr *> UDMapperRefs, Expr *IteratorModifier,
8153 ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
8154 ArrayRef<SourceLocation> MotionModifiersLoc,
8155 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
8156
8157 /// Creates an empty clause with the place for \a NumVars variables.
8158 ///
8159 /// \param C AST context.
8160 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8161 /// NumVars: number of expressions listed in this clause; 2)
8162 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8163 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8164 /// NumComponents: total number of expression components in the clause.
8165 static OMPToClause *CreateEmpty(const ASTContext &C,
8166 const OMPMappableExprListSizeTy &Sizes);
8167
8168 /// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
8169 ///
8170 /// \param Cnt index for motion-modifier.
8171 OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
8172 assert(Cnt < NumberOfOMPMotionModifiers &&
8173 "Requested modifier exceeds the total number of modifiers.");
8174 return MotionModifiers[Cnt];
8175 }
8176 Expr *getIteratorModifier() const {
8177 return getTrailingObjects<Expr *>()[2 * varlist_size()];
8178 }
8179 /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
8180 /// locations.
8181 ///
8182 /// \param Cnt index for motion-modifier location.
8183 SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
8184 assert(Cnt < NumberOfOMPMotionModifiers &&
8185 "Requested modifier location exceeds total number of modifiers.");
8186 return MotionModifiersLoc[Cnt];
8187 }
8188
8189 /// Fetches ArrayRef of motion-modifiers.
8191 return MotionModifiers;
8192 }
8193
8194 /// Fetches ArrayRef of location of motion-modifiers.
8196 return MotionModifiersLoc;
8197 }
8198
8199 /// Get colon location.
8200 SourceLocation getColonLoc() const { return ColonLoc; }
8201
8202 child_range children() {
8203 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8204 reinterpret_cast<Stmt **>(varlist_end()));
8205 }
8206
8207 const_child_range children() const {
8208 return const_cast<OMPToClause *>(this)->children();
8209 }
8210
8211 child_range used_children() {
8212 return child_range(child_iterator(), child_iterator());
8213 }
8214 const_child_range used_children() const {
8215 return const_child_range(const_child_iterator(), const_child_iterator());
8216 }
8217
8218 static bool classof(const OMPClause *T) {
8219 return T->getClauseKind() == llvm::omp::OMPC_to;
8220 }
8221};
8222
8223/// This represents clause 'from' in the '#pragma omp ...'
8224/// directives.
8225///
8226/// \code
8227/// #pragma omp target update from(a,b)
8228/// \endcode
8229/// In this example directive '#pragma omp target update' has clause 'from'
8230/// with the variables 'a' and 'b'.
8231class OMPFromClause final
8232 : public OMPMappableExprListClause<OMPFromClause>,
8233 private llvm::TrailingObjects<
8234 OMPFromClause, Expr *, ValueDecl *, unsigned,
8235 OMPClauseMappableExprCommon::MappableComponent> {
8236 friend class OMPClauseReader;
8237 friend OMPMappableExprListClause;
8238 friend OMPVarListClause;
8239 friend TrailingObjects;
8240
8241 /// Motion-modifiers for the 'from' clause.
8242 OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
8243 OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown,
8244 OMPC_MOTION_MODIFIER_unknown};
8245
8246 /// Location of motion-modifiers for the 'from' clause.
8247 SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
8248
8249 /// Colon location.
8250 SourceLocation ColonLoc;
8251
8252 /// Build clause with number of variables \a NumVars.
8253 ///
8254 /// \param TheMotionModifiers Motion-modifiers.
8255 /// \param TheMotionModifiersLoc Locations of motion-modifiers.
8256 /// \param MapperQualifierLoc C++ nested name specifier for the associated
8257 /// user-defined mapper.
8258 /// \param MapperIdInfo The identifier of associated user-defined mapper.
8259 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8260 /// StartLoc: starting location of the clause (the clause keyword); 2)
8261 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8262 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8263 /// NumVars: number of expressions listed in this clause; 2)
8264 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8265 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8266 /// NumComponents: total number of expression components in the clause.
8267 explicit OMPFromClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
8268 ArrayRef<SourceLocation> TheMotionModifiersLoc,
8269 NestedNameSpecifierLoc MapperQualifierLoc,
8270 DeclarationNameInfo MapperIdInfo,
8271 const OMPVarListLocTy &Locs,
8272 const OMPMappableExprListSizeTy &Sizes)
8273 : OMPMappableExprListClause(llvm::omp::OMPC_from, Locs, Sizes,
8274 /*SupportsMapper=*/true, &MapperQualifierLoc,
8275 &MapperIdInfo) {
8276 assert(std::size(MotionModifiers) == TheMotionModifiers.size() &&
8277 "Unexpected number of motion modifiers.");
8278 llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
8279
8280 assert(std::size(MotionModifiersLoc) == TheMotionModifiersLoc.size() &&
8281 "Unexpected number of motion modifier locations.");
8282 llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
8283 }
8284
8285 /// Build an empty clause.
8286 ///
8287 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8288 /// NumVars: number of expressions listed in this clause; 2)
8289 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8290 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8291 /// NumComponents: total number of expression components in the clause.
8292 explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes)
8293 : OMPMappableExprListClause(llvm::omp::OMPC_from, OMPVarListLocTy(),
8294 Sizes, /*SupportsMapper=*/true) {}
8295
8296 /// Set motion-modifier for the clause.
8297 ///
8298 /// \param I index for motion-modifier.
8299 /// \param T motion-modifier for the clause.
8300 void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
8301 assert(I < NumberOfOMPMotionModifiers &&
8302 "Unexpected index to store motion modifier, exceeds array size.");
8303 MotionModifiers[I] = T;
8304 }
8305 void setIteratorModifier(Expr *IteratorModifier) {
8306 getTrailingObjects<Expr *>()[2 * varlist_size()] = IteratorModifier;
8307 }
8308 /// Set location for the motion-modifier.
8309 ///
8310 /// \param I index for motion-modifier location.
8311 /// \param TLoc motion-modifier location.
8312 void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
8313 assert(I < NumberOfOMPMotionModifiers &&
8314 "Index to store motion modifier location exceeds array size.");
8315 MotionModifiersLoc[I] = TLoc;
8316 }
8317
8318 /// Set colon location.
8319 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
8320
8321 /// Define the sizes of each trailing object array except the last one. This
8322 /// is required for TrailingObjects to work properly.
8323 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8324 // There are varlist_size() of expressions, and varlist_size() of
8325 // user-defined mappers.
8326 return 2 * varlist_size() + 1;
8327 }
8328 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8329 return getUniqueDeclarationsNum();
8330 }
8331 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8332 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8333 }
8334
8335public:
8336 /// Creates clause with a list of variables \a Vars.
8337 ///
8338 /// \param C AST context.
8339 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8340 /// StartLoc: starting location of the clause (the clause keyword); 2)
8341 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8342 /// \param Vars The original expression used in the clause.
8343 /// \param Declarations Declarations used in the clause.
8344 /// \param ComponentLists Component lists used in the clause.
8345 /// \param MotionModifiers Motion-modifiers.
8346 /// \param MotionModifiersLoc Location of motion-modifiers.
8347 /// \param UDMapperRefs References to user-defined mappers associated with
8348 /// expressions used in the clause.
8349 /// \param UDMQualifierLoc C++ nested name specifier for the associated
8350 /// user-defined mapper.
8351 /// \param MapperId The identifier of associated user-defined mapper.
8352 static OMPFromClause *
8353 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8354 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8355 MappableExprComponentListsRef ComponentLists,
8356 ArrayRef<Expr *> UDMapperRefs, Expr *IteratorExpr,
8357 ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
8358 ArrayRef<SourceLocation> MotionModifiersLoc,
8359 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
8360
8361 /// Creates an empty clause with the place for \a NumVars variables.
8362 ///
8363 /// \param C AST context.
8364 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8365 /// NumVars: number of expressions listed in this clause; 2)
8366 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8367 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8368 /// NumComponents: total number of expression components in the clause.
8369 static OMPFromClause *CreateEmpty(const ASTContext &C,
8370 const OMPMappableExprListSizeTy &Sizes);
8371
8372 /// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
8373 ///
8374 /// \param Cnt index for motion-modifier.
8375 OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
8376 assert(Cnt < NumberOfOMPMotionModifiers &&
8377 "Requested modifier exceeds the total number of modifiers.");
8378 return MotionModifiers[Cnt];
8379 }
8380 Expr *getIteratorModifier() const {
8381 return getTrailingObjects<Expr *>()[2 * varlist_size()];
8382 }
8383 /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
8384 /// locations.
8385 ///
8386 /// \param Cnt index for motion-modifier location.
8387 SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
8388 assert(Cnt < NumberOfOMPMotionModifiers &&
8389 "Requested modifier location exceeds total number of modifiers.");
8390 return MotionModifiersLoc[Cnt];
8391 }
8392
8393 /// Fetches ArrayRef of motion-modifiers.
8395 return MotionModifiers;
8396 }
8397
8398 /// Fetches ArrayRef of location of motion-modifiers.
8400 return MotionModifiersLoc;
8401 }
8402
8403 /// Get colon location.
8404 SourceLocation getColonLoc() const { return ColonLoc; }
8405
8406 child_range children() {
8407 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8408 reinterpret_cast<Stmt **>(varlist_end()));
8409 }
8410
8411 const_child_range children() const {
8412 return const_cast<OMPFromClause *>(this)->children();
8413 }
8414
8415 child_range used_children() {
8416 return child_range(child_iterator(), child_iterator());
8417 }
8418 const_child_range used_children() const {
8419 return const_child_range(const_child_iterator(), const_child_iterator());
8420 }
8421
8422 static bool classof(const OMPClause *T) {
8423 return T->getClauseKind() == llvm::omp::OMPC_from;
8424 }
8425};
8426
8427/// This represents clause 'use_device_ptr' in the '#pragma omp ...'
8428/// directives.
8429///
8430/// \code
8431/// #pragma omp target data use_device_ptr(a,b)
8432/// \endcode
8433/// In this example directive '#pragma omp target data' has clause
8434/// 'use_device_ptr' with the variables 'a' and 'b'.
8435class OMPUseDevicePtrClause final
8436 : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
8437 private llvm::TrailingObjects<
8438 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
8439 OMPClauseMappableExprCommon::MappableComponent> {
8440 friend class OMPClauseReader;
8441 friend OMPMappableExprListClause;
8442 friend OMPVarListClause;
8443 friend TrailingObjects;
8444
8445 /// Fallback modifier for the clause.
8446 OpenMPUseDevicePtrFallbackModifier FallbackModifier =
8447 OMPC_USE_DEVICE_PTR_FALLBACK_unknown;
8448
8449 /// Location of the fallback modifier.
8450 SourceLocation FallbackModifierLoc;
8451
8452 /// Build clause with number of variables \a NumVars.
8453 ///
8454 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8455 /// StartLoc: starting location of the clause (the clause keyword); 2)
8456 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8457 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8458 /// NumVars: number of expressions listed in this clause; 2)
8459 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8460 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8461 /// NumComponents: total number of expression components in the clause.
8462 /// \param FallbackModifier The fallback modifier for the clause.
8463 /// \param FallbackModifierLoc Location of the fallback modifier.
8464 explicit OMPUseDevicePtrClause(
8465 const OMPVarListLocTy &Locs, const OMPMappableExprListSizeTy &Sizes,
8466 OpenMPUseDevicePtrFallbackModifier FallbackModifier,
8467 SourceLocation FallbackModifierLoc)
8468 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr, Locs, Sizes),
8469 FallbackModifier(FallbackModifier),
8470 FallbackModifierLoc(FallbackModifierLoc) {}
8471
8472 /// Build an empty clause.
8473 ///
8474 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8475 /// NumVars: number of expressions listed in this clause; 2)
8476 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8477 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8478 /// NumComponents: total number of expression components in the clause.
8480 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr,
8481 OMPVarListLocTy(), Sizes) {}
8482
8483 /// Define the sizes of each trailing object array except the last one. This
8484 /// is required for TrailingObjects to work properly.
8485 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8486 return 3 * varlist_size();
8487 }
8488 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8489 return getUniqueDeclarationsNum();
8490 }
8491 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8492 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8493 }
8494
8495 /// Sets the list of references to private copies with initializers for new
8496 /// private variables.
8497 /// \param VL List of references.
8498 void setPrivateCopies(ArrayRef<Expr *> VL);
8499
8500 /// Gets the list of references to private copies with initializers for new
8501 /// private variables.
8502 MutableArrayRef<Expr *> getPrivateCopies() {
8503 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
8504 }
8505 ArrayRef<const Expr *> getPrivateCopies() const {
8506 return {varlist_end(), varlist_size()};
8507 }
8508
8509 /// Sets the list of references to initializer variables for new private
8510 /// variables.
8511 /// \param VL List of references.
8512 void setInits(ArrayRef<Expr *> VL);
8513
8514 /// Gets the list of references to initializer variables for new private
8515 /// variables.
8516 MutableArrayRef<Expr *> getInits() {
8517 return {getPrivateCopies().end(), varlist_size()};
8518 }
8519 ArrayRef<const Expr *> getInits() const {
8520 return {getPrivateCopies().end(), varlist_size()};
8521 }
8522
8523 /// Set the fallback modifier for the clause.
8524 void setFallbackModifier(OpenMPUseDevicePtrFallbackModifier M) {
8525 FallbackModifier = M;
8526 }
8527
8528 /// Set the location of the fallback modifier.
8529 void setFallbackModifierLoc(SourceLocation Loc) { FallbackModifierLoc = Loc; }
8530
8531public:
8532 /// Creates clause with a list of variables \a Vars.
8533 ///
8534 /// \param C AST context.
8535 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8536 /// StartLoc: starting location of the clause (the clause keyword); 2)
8537 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8538 /// \param Vars The original expression used in the clause.
8539 /// \param PrivateVars Expressions referring to private copies.
8540 /// \param Inits Expressions referring to private copy initializers.
8541 /// \param Declarations Declarations used in the clause.
8542 /// \param ComponentLists Component lists used in the clause.
8543 /// \param FallbackModifier The fallback modifier for the clause.
8544 /// \param FallbackModifierLoc Location of the fallback modifier.
8545 static OMPUseDevicePtrClause *
8546 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8547 ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
8548 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
8549 MappableExprComponentListsRef ComponentLists,
8550 OpenMPUseDevicePtrFallbackModifier FallbackModifier,
8551 SourceLocation FallbackModifierLoc);
8552
8553 /// Creates an empty clause with the place for \a NumVars variables.
8554 ///
8555 /// \param C AST context.
8556 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8557 /// NumVars: number of expressions listed in this clause; 2)
8558 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8559 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8560 /// NumComponents: total number of expression components in the clause.
8561 static OMPUseDevicePtrClause *
8562 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
8563
8564 /// Get the fallback modifier for the clause.
8565 OpenMPUseDevicePtrFallbackModifier getFallbackModifier() const {
8566 return FallbackModifier;
8567 }
8568
8569 /// Get the location of the fallback modifier.
8570 SourceLocation getFallbackModifierLoc() const { return FallbackModifierLoc; }
8571
8572 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
8574 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
8576 llvm::iterator_range<private_copies_const_iterator>;
8577
8578 private_copies_range private_copies() { return getPrivateCopies(); }
8579
8581 return getPrivateCopies();
8582 }
8583
8584 using inits_iterator = MutableArrayRef<Expr *>::iterator;
8586 using inits_range = llvm::iterator_range<inits_iterator>;
8587 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
8588
8589 inits_range inits() { return getInits(); }
8590
8591 inits_const_range inits() const { return getInits(); }
8592
8593 child_range children() {
8594 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8595 reinterpret_cast<Stmt **>(varlist_end()));
8596 }
8597
8598 const_child_range children() const {
8599 return const_cast<OMPUseDevicePtrClause *>(this)->children();
8600 }
8601
8602 child_range used_children() {
8603 return child_range(child_iterator(), child_iterator());
8604 }
8605 const_child_range used_children() const {
8606 return const_child_range(const_child_iterator(), const_child_iterator());
8607 }
8608
8609 static bool classof(const OMPClause *T) {
8610 return T->getClauseKind() == llvm::omp::OMPC_use_device_ptr;
8611 }
8612};
8613
8614/// This represents clause 'use_device_addr' in the '#pragma omp ...'
8615/// directives.
8616///
8617/// \code
8618/// #pragma omp target data use_device_addr(a,b)
8619/// \endcode
8620/// In this example directive '#pragma omp target data' has clause
8621/// 'use_device_addr' with the variables 'a' and 'b'.
8622class OMPUseDeviceAddrClause final
8623 : public OMPMappableExprListClause<OMPUseDeviceAddrClause>,
8624 private llvm::TrailingObjects<
8625 OMPUseDeviceAddrClause, Expr *, ValueDecl *, unsigned,
8626 OMPClauseMappableExprCommon::MappableComponent> {
8627 friend class OMPClauseReader;
8628 friend OMPMappableExprListClause;
8629 friend OMPVarListClause;
8630 friend TrailingObjects;
8631
8632 /// Build clause with number of variables \a NumVars.
8633 ///
8634 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8635 /// StartLoc: starting location of the clause (the clause keyword); 2)
8636 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8637 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8638 /// NumVars: number of expressions listed in this clause; 2)
8639 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8640 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8641 /// NumComponents: total number of expression components in the clause.
8642 explicit OMPUseDeviceAddrClause(const OMPVarListLocTy &Locs,
8643 const OMPMappableExprListSizeTy &Sizes)
8644 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr, Locs,
8645 Sizes) {}
8646
8647 /// Build an empty clause.
8648 ///
8649 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8650 /// NumVars: number of expressions listed in this clause; 2)
8651 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8652 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8653 /// NumComponents: total number of expression components in the clause.
8655 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr,
8656 OMPVarListLocTy(), Sizes) {}
8657
8658 /// Define the sizes of each trailing object array except the last one. This
8659 /// is required for TrailingObjects to work properly.
8660 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8661 return varlist_size();
8662 }
8663 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8664 return getUniqueDeclarationsNum();
8665 }
8666 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8667 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8668 }
8669
8670public:
8671 /// Creates clause with a list of variables \a Vars.
8672 ///
8673 /// \param C AST context.
8674 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8675 /// StartLoc: starting location of the clause (the clause keyword); 2)
8676 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8677 /// \param Vars The original expression used in the clause.
8678 /// \param Declarations Declarations used in the clause.
8679 /// \param ComponentLists Component lists used in the clause.
8680 static OMPUseDeviceAddrClause *
8681 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8682 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8683 MappableExprComponentListsRef ComponentLists);
8684
8685 /// Creates an empty clause with the place for \a NumVars variables.
8686 ///
8687 /// \param C AST context.
8688 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8689 /// NumVars: number of expressions listed in this clause; 2)
8690 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8691 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8692 /// NumComponents: total number of expression components in the clause.
8693 static OMPUseDeviceAddrClause *
8694 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
8695
8696 child_range children() {
8697 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8698 reinterpret_cast<Stmt **>(varlist_end()));
8699 }
8700
8701 const_child_range children() const {
8702 return const_cast<OMPUseDeviceAddrClause *>(this)->children();
8703 }
8704
8705 child_range used_children() {
8706 return child_range(child_iterator(), child_iterator());
8707 }
8708 const_child_range used_children() const {
8709 return const_child_range(const_child_iterator(), const_child_iterator());
8710 }
8711
8712 static bool classof(const OMPClause *T) {
8713 return T->getClauseKind() == llvm::omp::OMPC_use_device_addr;
8714 }
8715};
8716
8717/// This represents clause 'is_device_ptr' in the '#pragma omp ...'
8718/// directives.
8719///
8720/// \code
8721/// #pragma omp target is_device_ptr(a,b)
8722/// \endcode
8723/// In this example directive '#pragma omp target' has clause
8724/// 'is_device_ptr' with the variables 'a' and 'b'.
8725class OMPIsDevicePtrClause final
8726 : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
8727 private llvm::TrailingObjects<
8728 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
8729 OMPClauseMappableExprCommon::MappableComponent> {
8730 friend class OMPClauseReader;
8731 friend OMPMappableExprListClause;
8732 friend OMPVarListClause;
8733 friend TrailingObjects;
8734
8735 /// Build clause with number of variables \a NumVars.
8736 ///
8737 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8738 /// StartLoc: starting location of the clause (the clause keyword); 2)
8739 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8740 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8741 /// NumVars: number of expressions listed in this clause; 2)
8742 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8743 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8744 /// NumComponents: total number of expression components in the clause.
8745 explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs,
8746 const OMPMappableExprListSizeTy &Sizes)
8747 : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr, Locs, Sizes) {}
8748
8749 /// Build an empty clause.
8750 ///
8751 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8752 /// NumVars: number of expressions listed in this clause; 2)
8753 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8754 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8755 /// NumComponents: total number of expression components in the clause.
8756 explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
8757 : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr,
8758 OMPVarListLocTy(), Sizes) {}
8759
8760 /// Define the sizes of each trailing object array except the last one. This
8761 /// is required for TrailingObjects to work properly.
8762 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8763 return varlist_size();
8764 }
8765 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8766 return getUniqueDeclarationsNum();
8767 }
8768 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8769 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8770 }
8771
8772public:
8773 /// Creates clause with a list of variables \a Vars.
8774 ///
8775 /// \param C AST context.
8776 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8777 /// StartLoc: starting location of the clause (the clause keyword); 2)
8778 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8779 /// \param Vars The original expression used in the clause.
8780 /// \param Declarations Declarations used in the clause.
8781 /// \param ComponentLists Component lists used in the clause.
8782 static OMPIsDevicePtrClause *
8783 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8784 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8785 MappableExprComponentListsRef ComponentLists);
8786
8787 /// Creates an empty clause with the place for \a NumVars variables.
8788 ///
8789 /// \param C AST context.
8790 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8791 /// NumVars: number of expressions listed in this clause; 2)
8792 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8793 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8794 /// NumComponents: total number of expression components in the clause.
8795 static OMPIsDevicePtrClause *
8796 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
8797
8798 child_range children() {
8799 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8800 reinterpret_cast<Stmt **>(varlist_end()));
8801 }
8802
8803 const_child_range children() const {
8804 return const_cast<OMPIsDevicePtrClause *>(this)->children();
8805 }
8806
8807 child_range used_children() {
8808 return child_range(child_iterator(), child_iterator());
8809 }
8810 const_child_range used_children() const {
8811 return const_child_range(const_child_iterator(), const_child_iterator());
8812 }
8813
8814 static bool classof(const OMPClause *T) {
8815 return T->getClauseKind() == llvm::omp::OMPC_is_device_ptr;
8816 }
8817};
8818
8819/// This represents clause 'has_device_ptr' in the '#pragma omp ...'
8820/// directives.
8821///
8822/// \code
8823/// #pragma omp target has_device_addr(a,b)
8824/// \endcode
8825/// In this example directive '#pragma omp target' has clause
8826/// 'has_device_ptr' with the variables 'a' and 'b'.
8827class OMPHasDeviceAddrClause final
8828 : public OMPMappableExprListClause<OMPHasDeviceAddrClause>,
8829 private llvm::TrailingObjects<
8830 OMPHasDeviceAddrClause, Expr *, ValueDecl *, unsigned,
8831 OMPClauseMappableExprCommon::MappableComponent> {
8832 friend class OMPClauseReader;
8833 friend OMPMappableExprListClause;
8834 friend OMPVarListClause;
8835 friend TrailingObjects;
8836
8837 /// Build clause with number of variables \a NumVars.
8838 ///
8839 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8840 /// StartLoc: starting location of the clause (the clause keyword); 2)
8841 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8842 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8843 /// NumVars: number of expressions listed in this clause; 2)
8844 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8845 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8846 /// NumComponents: total number of expression components in the clause.
8847 explicit OMPHasDeviceAddrClause(const OMPVarListLocTy &Locs,
8848 const OMPMappableExprListSizeTy &Sizes)
8849 : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr, Locs,
8850 Sizes) {}
8851
8852 /// Build an empty clause.
8853 ///
8854 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8855 /// NumVars: number of expressions listed in this clause; 2)
8856 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8857 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8858 /// NumComponents: total number of expression components in the clause.
8860 : OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr,
8861 OMPVarListLocTy(), Sizes) {}
8862
8863 /// Define the sizes of each trailing object array except the last one. This
8864 /// is required for TrailingObjects to work properly.
8865 size_t numTrailingObjects(OverloadToken<Expr *>) const {
8866 return varlist_size();
8867 }
8868 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
8869 return getUniqueDeclarationsNum();
8870 }
8871 size_t numTrailingObjects(OverloadToken<unsigned>) const {
8872 return getUniqueDeclarationsNum() + getTotalComponentListNum();
8873 }
8874
8875public:
8876 /// Creates clause with a list of variables \a Vars.
8877 ///
8878 /// \param C AST context.
8879 /// \param Locs Locations needed to build a mappable clause. It includes 1)
8880 /// StartLoc: starting location of the clause (the clause keyword); 2)
8881 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
8882 /// \param Vars The original expression used in the clause.
8883 /// \param Declarations Declarations used in the clause.
8884 /// \param ComponentLists Component lists used in the clause.
8885 static OMPHasDeviceAddrClause *
8886 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
8887 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
8888 MappableExprComponentListsRef ComponentLists);
8889
8890 /// Creates an empty clause with the place for \a NumVars variables.
8891 ///
8892 /// \param C AST context.
8893 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
8894 /// NumVars: number of expressions listed in this clause; 2)
8895 /// NumUniqueDeclarations: number of unique base declarations in this clause;
8896 /// 3) NumComponentLists: number of component lists in this clause; and 4)
8897 /// NumComponents: total number of expression components in the clause.
8898 static OMPHasDeviceAddrClause *
8899 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
8900
8901 child_range children() {
8902 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8903 reinterpret_cast<Stmt **>(varlist_end()));
8904 }
8905
8906 const_child_range children() const {
8907 return const_cast<OMPHasDeviceAddrClause *>(this)->children();
8908 }
8909
8910 child_range used_children() {
8911 return child_range(child_iterator(), child_iterator());
8912 }
8913 const_child_range used_children() const {
8914 return const_child_range(const_child_iterator(), const_child_iterator());
8915 }
8916
8917 static bool classof(const OMPClause *T) {
8918 return T->getClauseKind() == llvm::omp::OMPC_has_device_addr;
8919 }
8920};
8921
8922/// This represents clause 'nontemporal' in the '#pragma omp ...' directives.
8923///
8924/// \code
8925/// #pragma omp simd nontemporal(a)
8926/// \endcode
8927/// In this example directive '#pragma omp simd' has clause 'nontemporal' for
8928/// the variable 'a'.
8929class OMPNontemporalClause final
8930 : public OMPVarListClause<OMPNontemporalClause>,
8931 private llvm::TrailingObjects<OMPNontemporalClause, Expr *> {
8932 friend class OMPClauseReader;
8933 friend OMPVarListClause;
8934 friend TrailingObjects;
8935
8936 /// Build clause with number of variables \a N.
8937 ///
8938 /// \param StartLoc Starting location of the clause.
8939 /// \param LParenLoc Location of '('.
8940 /// \param EndLoc Ending location of the clause.
8941 /// \param N Number of the variables in the clause.
8942 OMPNontemporalClause(SourceLocation StartLoc, SourceLocation LParenLoc,
8943 SourceLocation EndLoc, unsigned N)
8944 : OMPVarListClause<OMPNontemporalClause>(llvm::omp::OMPC_nontemporal,
8945 StartLoc, LParenLoc, EndLoc, N) {
8946 }
8947
8948 /// Build an empty clause.
8949 ///
8950 /// \param N Number of variables.
8951 explicit OMPNontemporalClause(unsigned N)
8952 : OMPVarListClause<OMPNontemporalClause>(
8953 llvm::omp::OMPC_nontemporal, SourceLocation(), SourceLocation(),
8954 SourceLocation(), N) {}
8955
8956 /// Get the list of privatied copies if the member expression was captured by
8957 /// one of the privatization clauses.
8958 MutableArrayRef<Expr *> getPrivateRefs() {
8959 return {varlist_end(), varlist_size()};
8960 }
8961 ArrayRef<const Expr *> getPrivateRefs() const {
8962 return {varlist_end(), varlist_size()};
8963 }
8964
8965public:
8966 /// Creates clause with a list of variables \a VL.
8967 ///
8968 /// \param C AST context.
8969 /// \param StartLoc Starting location of the clause.
8970 /// \param LParenLoc Location of '('.
8971 /// \param EndLoc Ending location of the clause.
8972 /// \param VL List of references to the variables.
8973 static OMPNontemporalClause *
8974 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
8975 SourceLocation EndLoc, ArrayRef<Expr *> VL);
8976
8977 /// Creates an empty clause with the place for \a N variables.
8978 ///
8979 /// \param C AST context.
8980 /// \param N The number of variables.
8981 static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N);
8982
8983 /// Sets the list of references to private copies created in private clauses.
8984 /// \param VL List of references.
8985 void setPrivateRefs(ArrayRef<Expr *> VL);
8986
8987 child_range children() {
8988 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
8989 reinterpret_cast<Stmt **>(varlist_end()));
8990 }
8991
8992 const_child_range children() const {
8993 return const_cast<OMPNontemporalClause *>(this)->children();
8994 }
8995
8996 child_range private_refs() {
8997 return child_range(reinterpret_cast<Stmt **>(getPrivateRefs().begin()),
8998 reinterpret_cast<Stmt **>(getPrivateRefs().end()));
8999 }
9000
9001 const_child_range private_refs() const {
9002 return const_cast<OMPNontemporalClause *>(this)->private_refs();
9003 }
9004
9005 child_range used_children() {
9006 return child_range(child_iterator(), child_iterator());
9007 }
9008 const_child_range used_children() const {
9009 return const_child_range(const_child_iterator(), const_child_iterator());
9010 }
9011
9012 static bool classof(const OMPClause *T) {
9013 return T->getClauseKind() == llvm::omp::OMPC_nontemporal;
9014 }
9015};
9016
9017/// This represents 'order' clause in the '#pragma omp ...' directive.
9018///
9019/// \code
9020/// #pragma omp simd order(concurrent)
9021/// \endcode
9022/// In this example directive '#pragma omp parallel' has simple 'order'
9023/// clause with kind 'concurrent'.
9024class OMPOrderClause final : public OMPClause {
9025 friend class OMPClauseReader;
9026
9027 /// Location of '('.
9028 SourceLocation LParenLoc;
9029
9030 /// A kind of the 'order' clause.
9031 OpenMPOrderClauseKind Kind = OMPC_ORDER_unknown;
9032
9033 /// Start location of the kind in source code.
9034 SourceLocation KindKwLoc;
9035
9036 /// A modifier for order clause
9037 OpenMPOrderClauseModifier Modifier = OMPC_ORDER_MODIFIER_unknown;
9038
9039 /// Start location of the modifier in source code.
9040 SourceLocation ModifierKwLoc;
9041
9042 /// Set kind of the clause.
9043 ///
9044 /// \param K Argument of clause.
9045 void setKind(OpenMPOrderClauseKind K) { Kind = K; }
9046
9047 /// Set argument location.
9048 ///
9049 /// \param KLoc Argument location.
9050 void setKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
9051
9052 /// Set modifier of the clause.
9053 ///
9054 /// \param M Argument of clause.
9055 void setModifier(OpenMPOrderClauseModifier M) { Modifier = M; }
9056
9057 /// Set modifier location.
9058 ///
9059 /// \param MLoc Modifier keyword location.
9060 void setModifierKwLoc(SourceLocation MLoc) { ModifierKwLoc = MLoc; }
9061
9062public:
9063 /// Build 'order' clause with argument \p A ('concurrent').
9064 ///
9065 /// \param A Argument of the clause ('concurrent').
9066 /// \param ALoc Starting location of the argument.
9067 /// \param StartLoc Starting location of the clause.
9068 /// \param LParenLoc Location of '('.
9069 /// \param EndLoc Ending location of the clause.
9070 /// \param Modifier The modifier applied to 'order' clause.
9071 /// \param MLoc Location of the modifier
9072 OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc,
9073 SourceLocation StartLoc, SourceLocation LParenLoc,
9074 SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier,
9075 SourceLocation MLoc)
9076 : OMPClause(llvm::omp::OMPC_order, StartLoc, EndLoc),
9077 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc), Modifier(Modifier),
9078 ModifierKwLoc(MLoc) {}
9079
9080 /// Build an empty clause.
9082 : OMPClause(llvm::omp::OMPC_order, SourceLocation(), SourceLocation()) {}
9083
9084 /// Sets the location of '('.
9085 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9086
9087 /// Returns the location of '('.
9088 SourceLocation getLParenLoc() const { return LParenLoc; }
9089
9090 /// Returns kind of the clause.
9091 OpenMPOrderClauseKind getKind() const { return Kind; }
9092
9093 /// Returns location of clause kind.
9094 SourceLocation getKindKwLoc() const { return KindKwLoc; }
9095
9096 /// Returns Modifier of the clause.
9097 OpenMPOrderClauseModifier getModifier() const { return Modifier; }
9098
9099 /// Returns location of clause modifier.
9100 SourceLocation getModifierKwLoc() const { return ModifierKwLoc; }
9101
9102 child_range children() {
9103 return child_range(child_iterator(), child_iterator());
9104 }
9105
9106 const_child_range children() const {
9107 return const_child_range(const_child_iterator(), const_child_iterator());
9108 }
9109
9110 child_range used_children() {
9111 return child_range(child_iterator(), child_iterator());
9112 }
9113 const_child_range used_children() const {
9114 return const_child_range(const_child_iterator(), const_child_iterator());
9115 }
9116
9117 static bool classof(const OMPClause *T) {
9118 return T->getClauseKind() == llvm::omp::OMPC_order;
9119 }
9120};
9121
9122/// This represents the 'init' clause in '#pragma omp ...' directives.
9123///
9124/// \code
9125/// #pragma omp interop init(target:obj)
9126/// \endcode
9127class OMPInitClause final
9128 : public OMPVarListClause<OMPInitClause>,
9129 private llvm::TrailingObjects<OMPInitClause, Expr *, unsigned> {
9130 friend class OMPClauseReader;
9131 friend OMPVarListClause;
9132 friend TrailingObjects;
9133
9134 /// Location of interop variable.
9135 SourceLocation VarLoc;
9136
9137 bool IsTarget = false;
9138 bool IsTargetSync = false;
9139 bool HasPreferAttrs = false;
9140
9141 /// Total number of attr() exprs across all pref-specs; equals the last entry
9142 /// of the trailing unsigned[] of cumulative end offsets (or 0 if no prefs).
9143 unsigned NumAttrs = 0;
9144
9145 /// Trailing-objects layout (single contiguous Expr* array):
9146 /// Expr*[ varlist_size() + NumAttrs ]:
9147 /// [0] = InteropVar
9148 /// [1 .. NumPrefs] = Fr expr per pref-spec (null if attr-only)
9149 /// [varlist_size() ..] = flat list of attr exprs, concatenated in
9150 /// pref-spec order
9151 /// unsigned[ NumPrefs ]:
9152 /// [i] = end offset of pref-spec i's attrs in the flat
9153 /// attr block (inclusive cumulative attr count);
9154 /// spec i's attrs are [ends[i-1], ends[i]), with
9155 /// an implicit 0 before ends[0]
9156 ///
9157 /// varlist_size() = 1 + NumPrefs, so OMPVarListClause iteration covers
9158 /// InteropVar + the Fr block.
9159
9160 size_t numTrailingObjects(OverloadToken<Expr *>) const {
9161 return varlist_size() + NumAttrs;
9162 }
9163 size_t numTrailingObjects(OverloadToken<unsigned>) const {
9164 return getNumPrefs();
9165 }
9166
9167 void setInteropVar(Expr *E) { varlist_begin()[0] = E; }
9168
9169 void setIsTarget(bool V) { IsTarget = V; }
9170
9171 void setIsTargetSync(bool V) { IsTargetSync = V; }
9172
9173 void setHasPreferAttrs(bool V) { HasPreferAttrs = V; }
9174
9175 void setAttrs(ArrayRef<unsigned> Counts, ArrayRef<Expr *> Attrs);
9176
9177 /// Number of pref-specs in prefer_type(...).
9178 unsigned getNumPrefs() const { return varlist_size() - 1; }
9179
9180 /// Per-pref-spec attr end offsets: entry i is the inclusive cumulative attr
9181 /// count through pref-spec i (one past its last attr in the flat attr block).
9182 ArrayRef<unsigned> getAttrEnds() const {
9183 return getTrailingObjects<unsigned>(getNumPrefs());
9184 }
9185
9186 /// Sets the location of the interop variable.
9187 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
9188
9189 /// Build 'init' clause.
9190 ///
9191 /// \param IsTarget Uses the 'target' interop-type.
9192 /// \param IsTargetSync Uses the 'targetsync' interop-type.
9193 /// \param StartLoc Starting location of the clause.
9194 /// \param LParenLoc Location of '('.
9195 /// \param VarLoc Location of the interop variable.
9196 /// \param EndLoc Ending location of the clause.
9197 /// \param N Number of varlist entries (1 + NumPrefs).
9198 OMPInitClause(bool IsTarget, bool IsTargetSync, SourceLocation StartLoc,
9199 SourceLocation LParenLoc, SourceLocation VarLoc,
9200 SourceLocation EndLoc, unsigned N)
9201 : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, StartLoc,
9202 LParenLoc, EndLoc, N),
9203 VarLoc(VarLoc), IsTarget(IsTarget), IsTargetSync(IsTargetSync) {}
9204
9205 /// Build an empty clause.
9206 OMPInitClause(unsigned N)
9207 : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, SourceLocation(),
9208 SourceLocation(), SourceLocation(), N) {
9209 }
9210
9211public:
9212 struct PrefView {
9213 /// Foreign-runtime-id expression. Null for attr-only specs.
9214 Expr *Fr;
9215 /// attr() string-literal expressions. Empty for fr-only or OMP 5.1
9216 /// flat specs.
9218 };
9219
9220 /// Creates a fully specified clause.
9221 ///
9222 /// \param C AST context.
9223 /// \param InteropVar The interop variable.
9224 /// \param InteropInfo The interop-type and prefer_type list.
9225 /// \param StartLoc Starting location of the clause.
9226 /// \param LParenLoc Location of '('.
9227 /// \param VarLoc Location of the interop variable.
9228 /// \param EndLoc Ending location of the clause.
9229 static OMPInitClause *Create(const ASTContext &C, Expr *InteropVar,
9230 OMPInteropInfo &InteropInfo,
9231 SourceLocation StartLoc,
9232 SourceLocation LParenLoc, SourceLocation VarLoc,
9233 SourceLocation EndLoc);
9234
9235 /// Creates an empty clause sized for \a NumPrefs pref-specs and \a NumAttrs
9236 /// total attr() exprs across them.
9237 ///
9238 /// \param C AST context.
9239 /// \param NumPrefs Number of pref-specs (length of the Fr block).
9240 /// \param NumAttrs Total attr() exprs across all pref-specs.
9241 static OMPInitClause *CreateEmpty(const ASTContext &C, unsigned NumPrefs,
9242 unsigned NumAttrs);
9243
9244 /// Returns the location of the interop variable.
9245 SourceLocation getVarLoc() const { return VarLoc; }
9246
9247 /// Returns the interop variable.
9248 Expr *getInteropVar() { return varlist_begin()[0]; }
9249 const Expr *getInteropVar() const { return varlist_begin()[0]; }
9250
9251 /// Returns true is interop-type 'target' is used.
9252 bool getIsTarget() const { return IsTarget; }
9253
9254 /// Returns true is interop-type 'targetsync' is used.
9255 bool getIsTargetSync() const { return IsTargetSync; }
9256
9257 /// Returns true if OMP 6.0 {fr/attr} syntax is used.
9258 bool hasPreferAttrs() const { return HasPreferAttrs; }
9259
9260 /// All attr() exprs across every pref-spec, in pref-spec order (flat block).
9262 return ArrayRef<Expr *>(getTrailingObjects<Expr *>() + varlist_size(),
9263 NumAttrs);
9264 }
9265
9266 child_range children() {
9267 return child_range(
9268 reinterpret_cast<Stmt **>(varlist_begin()),
9269 reinterpret_cast<Stmt **>(varlist_begin() + varlist_size() + NumAttrs));
9270 }
9271
9272 const_child_range children() const {
9273 return const_cast<OMPInitClause *>(this)->children();
9274 }
9275
9276 child_range used_children() {
9277 return child_range(child_iterator(), child_iterator());
9278 }
9279 const_child_range used_children() const {
9280 return const_child_range(const_child_iterator(), const_child_iterator());
9281 }
9282
9283 /// Returns a range of PrefView objects, one per preference-specification,
9284 /// each carrying the fr() expression (or null) and the attr() exprs.
9285 auto prefs() const {
9286 unsigned N = getNumPrefs();
9287 Expr *const *E = getTrailingObjects<Expr *>();
9288 ArrayRef<unsigned> Ends = getAttrEnds();
9289 return llvm::map_range(llvm::seq<unsigned>(0, N), [this, E,
9290 Ends](unsigned I) {
9291 unsigned Start = (I == 0) ? 0 : Ends[I - 1];
9292 return PrefView{
9293 const_cast<Expr *>(E[1 + I]),
9294 ArrayRef<Expr *>(const_cast<Expr **>(E) + varlist_size() + Start,
9295 Ends[I] - Start)};
9296 });
9297 }
9298
9299 static bool classof(const OMPClause *T) {
9300 return T->getClauseKind() == llvm::omp::OMPC_init;
9301 }
9302};
9303
9304/// This represents the 'use' clause in '#pragma omp ...' directives.
9305///
9306/// \code
9307/// #pragma omp interop use(obj)
9308/// \endcode
9309class OMPUseClause final : public OMPClause {
9310 friend class OMPClauseReader;
9311
9312 /// Location of '('.
9313 SourceLocation LParenLoc;
9314
9315 /// Location of interop variable.
9316 SourceLocation VarLoc;
9317
9318 /// The interop variable.
9319 Stmt *InteropVar = nullptr;
9320
9321 /// Set the interop variable.
9322 void setInteropVar(Expr *E) { InteropVar = E; }
9323
9324 /// Sets the location of '('.
9325 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9326
9327 /// Sets the location of the interop variable.
9328 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
9329
9330public:
9331 /// Build 'use' clause with and interop variable expression \a InteropVar.
9332 ///
9333 /// \param InteropVar The interop variable.
9334 /// \param StartLoc Starting location of the clause.
9335 /// \param LParenLoc Location of '('.
9336 /// \param VarLoc Location of the interop variable.
9337 /// \param EndLoc Ending location of the clause.
9338 OMPUseClause(Expr *InteropVar, SourceLocation StartLoc,
9339 SourceLocation LParenLoc, SourceLocation VarLoc,
9340 SourceLocation EndLoc)
9341 : OMPClause(llvm::omp::OMPC_use, StartLoc, EndLoc), LParenLoc(LParenLoc),
9342 VarLoc(VarLoc), InteropVar(InteropVar) {}
9343
9344 /// Build an empty clause.
9346 : OMPClause(llvm::omp::OMPC_use, SourceLocation(), SourceLocation()) {}
9347
9348 /// Returns the location of '('.
9349 SourceLocation getLParenLoc() const { return LParenLoc; }
9350
9351 /// Returns the location of the interop variable.
9352 SourceLocation getVarLoc() const { return VarLoc; }
9353
9354 /// Returns the interop variable.
9355 Expr *getInteropVar() const { return cast<Expr>(InteropVar); }
9356
9357 child_range children() { return child_range(&InteropVar, &InteropVar + 1); }
9358
9359 const_child_range children() const {
9360 return const_child_range(&InteropVar, &InteropVar + 1);
9361 }
9362
9363 child_range used_children() {
9364 return child_range(child_iterator(), child_iterator());
9365 }
9366 const_child_range used_children() const {
9367 return const_child_range(const_child_iterator(), const_child_iterator());
9368 }
9369
9370 static bool classof(const OMPClause *T) {
9371 return T->getClauseKind() == llvm::omp::OMPC_use;
9372 }
9373};
9374
9375/// This represents 'destroy' clause in the '#pragma omp depobj'
9376/// directive or the '#pragma omp interop' directive..
9377///
9378/// \code
9379/// #pragma omp depobj(a) destroy
9380/// #pragma omp interop destroy(obj)
9381/// \endcode
9382/// In these examples directive '#pragma omp depobj' and '#pragma omp interop'
9383/// have a 'destroy' clause. The 'interop' directive includes an object.
9384class OMPDestroyClause final : public OMPClause {
9385 friend class OMPClauseReader;
9386
9387 /// Location of '('.
9388 SourceLocation LParenLoc;
9389
9390 /// Location of interop variable.
9391 SourceLocation VarLoc;
9392
9393 /// The interop variable.
9394 Stmt *InteropVar = nullptr;
9395
9396 /// Set the interop variable.
9397 void setInteropVar(Expr *E) { InteropVar = E; }
9398
9399 /// Sets the location of '('.
9400 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9401
9402 /// Sets the location of the interop variable.
9403 void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
9404
9405public:
9406 /// Build 'destroy' clause with an interop variable expression \a InteropVar.
9407 ///
9408 /// \param InteropVar The interop variable.
9409 /// \param StartLoc Starting location of the clause.
9410 /// \param LParenLoc Location of '('.
9411 /// \param VarLoc Location of the interop variable.
9412 /// \param EndLoc Ending location of the clause.
9413 OMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc,
9414 SourceLocation LParenLoc, SourceLocation VarLoc,
9415 SourceLocation EndLoc)
9416 : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc),
9417 LParenLoc(LParenLoc), VarLoc(VarLoc), InteropVar(InteropVar) {}
9418
9419 /// Build 'destroy' clause.
9420 ///
9421 /// \param StartLoc Starting location of the clause.
9422 /// \param EndLoc Ending location of the clause.
9423 OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
9424 : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc) {}
9425
9426 /// Build an empty clause.
9428 : OMPClause(llvm::omp::OMPC_destroy, SourceLocation(), SourceLocation()) {
9429 }
9430
9431 /// Returns the location of '('.
9432 SourceLocation getLParenLoc() const { return LParenLoc; }
9433
9434 /// Returns the location of the interop variable.
9435 SourceLocation getVarLoc() const { return VarLoc; }
9436
9437 /// Returns the interop variable.
9438 Expr *getInteropVar() const { return cast_or_null<Expr>(InteropVar); }
9439
9440 child_range children() {
9441 if (InteropVar)
9442 return child_range(&InteropVar, &InteropVar + 1);
9443 return child_range(child_iterator(), child_iterator());
9444 }
9445
9446 const_child_range children() const {
9447 if (InteropVar)
9448 return const_child_range(&InteropVar, &InteropVar + 1);
9449 return const_child_range(const_child_iterator(), const_child_iterator());
9450 }
9451
9452 child_range used_children() {
9453 return child_range(child_iterator(), child_iterator());
9454 }
9455 const_child_range used_children() const {
9456 return const_child_range(const_child_iterator(), const_child_iterator());
9457 }
9458
9459 static bool classof(const OMPClause *T) {
9460 return T->getClauseKind() == llvm::omp::OMPC_destroy;
9461 }
9462};
9463
9464/// This represents 'novariants' clause in the '#pragma omp ...' directive.
9465///
9466/// \code
9467/// #pragma omp dispatch novariants(a > 5)
9468/// \endcode
9469/// In this example directive '#pragma omp dispatch' has simple 'novariants'
9470/// clause with condition 'a > 5'.
9472 : public OMPOneStmtClause<llvm::omp::OMPC_novariants, OMPClause>,
9473 public OMPClauseWithPreInit {
9474 friend class OMPClauseReader;
9475
9476 /// Set condition.
9477 void setCondition(Expr *Cond) { setStmt(Cond); }
9478
9479public:
9480 /// Build 'novariants' clause with condition \a Cond.
9481 ///
9482 /// \param Cond Condition of the clause.
9483 /// \param HelperCond Helper condition for the construct.
9484 /// \param CaptureRegion Innermost OpenMP region where expressions in this
9485 /// clause must be captured.
9486 /// \param StartLoc Starting location of the clause.
9487 /// \param LParenLoc Location of '('.
9488 /// \param EndLoc Ending location of the clause.
9489 OMPNovariantsClause(Expr *Cond, Stmt *HelperCond,
9490 OpenMPDirectiveKind CaptureRegion,
9491 SourceLocation StartLoc, SourceLocation LParenLoc,
9492 SourceLocation EndLoc)
9493 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
9494 OMPClauseWithPreInit(this) {
9495 setPreInitStmt(HelperCond, CaptureRegion);
9496 }
9497
9498 /// Build an empty clause.
9500
9501 /// Returns condition.
9502 Expr *getCondition() const { return getStmtAs<Expr>(); }
9503
9504 child_range used_children();
9505 const_child_range used_children() const {
9506 return const_cast<OMPNovariantsClause *>(this)->used_children();
9507 }
9508};
9509
9510/// This represents 'nocontext' clause in the '#pragma omp ...' directive.
9511///
9512/// \code
9513/// #pragma omp dispatch nocontext(a > 5)
9514/// \endcode
9515/// In this example directive '#pragma omp dispatch' has simple 'nocontext'
9516/// clause with condition 'a > 5'.
9518 : public OMPOneStmtClause<llvm::omp::OMPC_nocontext, OMPClause>,
9519 public OMPClauseWithPreInit {
9520 friend class OMPClauseReader;
9521
9522 /// Set condition.
9523 void setCondition(Expr *Cond) { setStmt(Cond); }
9524
9525public:
9526 /// Build 'nocontext' clause with condition \a Cond.
9527 ///
9528 /// \param Cond Condition of the clause.
9529 /// \param HelperCond Helper condition for the construct.
9530 /// \param CaptureRegion Innermost OpenMP region where expressions in this
9531 /// clause must be captured.
9532 /// \param StartLoc Starting location of the clause.
9533 /// \param LParenLoc Location of '('.
9534 /// \param EndLoc Ending location of the clause.
9535 OMPNocontextClause(Expr *Cond, Stmt *HelperCond,
9536 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
9537 SourceLocation LParenLoc, SourceLocation EndLoc)
9538 : OMPOneStmtClause(Cond, StartLoc, LParenLoc, EndLoc),
9539 OMPClauseWithPreInit(this) {
9540 setPreInitStmt(HelperCond, CaptureRegion);
9541 }
9542
9543 /// Build an empty clause.
9545
9546 /// Returns condition.
9547 Expr *getCondition() const { return getStmtAs<Expr>(); }
9548
9549 child_range used_children();
9550 const_child_range used_children() const {
9551 return const_cast<OMPNocontextClause *>(this)->used_children();
9552 }
9553};
9554
9555/// This represents 'detach' clause in the '#pragma omp task' directive.
9556///
9557/// \code
9558/// #pragma omp task detach(evt)
9559/// \endcode
9560/// In this example directive '#pragma omp detach' has simple 'detach' clause
9561/// with the variable 'evt'.
9563 : public OMPOneStmtClause<llvm::omp::OMPC_detach, OMPClause> {
9564 friend class OMPClauseReader;
9565
9566 /// Set condition.
9567 void setEventHandler(Expr *E) { setStmt(E); }
9568
9569public:
9570 /// Build 'detach' clause with event-handler \a Evt.
9571 ///
9572 /// \param Evt Event handler expression.
9573 /// \param StartLoc Starting location of the clause.
9574 /// \param LParenLoc Location of '('.
9575 /// \param EndLoc Ending location of the clause.
9576 OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc,
9577 SourceLocation EndLoc)
9578 : OMPOneStmtClause(Evt, StartLoc, LParenLoc, EndLoc) {}
9579
9580 /// Build an empty clause.
9582
9583 /// Returns event-handler expression.
9584 Expr *getEventHandler() const { return getStmtAs<Expr>(); }
9585};
9586
9587/// This represents clause 'inclusive' in the '#pragma omp scan' directive.
9588///
9589/// \code
9590/// #pragma omp scan inclusive(a,b)
9591/// \endcode
9592/// In this example directive '#pragma omp scan' has clause 'inclusive'
9593/// with the variables 'a' and 'b'.
9594class OMPInclusiveClause final
9595 : public OMPVarListClause<OMPInclusiveClause>,
9596 private llvm::TrailingObjects<OMPInclusiveClause, Expr *> {
9597 friend class OMPClauseReader;
9598 friend OMPVarListClause;
9599 friend TrailingObjects;
9600
9601 /// Build clause with number of variables \a N.
9602 ///
9603 /// \param StartLoc Starting location of the clause.
9604 /// \param LParenLoc Location of '('.
9605 /// \param EndLoc Ending location of the clause.
9606 /// \param N Number of the variables in the clause.
9607 OMPInclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9608 SourceLocation EndLoc, unsigned N)
9609 : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
9610 StartLoc, LParenLoc, EndLoc, N) {}
9611
9612 /// Build an empty clause.
9613 ///
9614 /// \param N Number of variables.
9615 explicit OMPInclusiveClause(unsigned N)
9616 : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
9617 SourceLocation(), SourceLocation(),
9618 SourceLocation(), N) {}
9619
9620public:
9621 /// Creates clause with a list of variables \a VL.
9622 ///
9623 /// \param C AST context.
9624 /// \param StartLoc Starting location of the clause.
9625 /// \param LParenLoc Location of '('.
9626 /// \param EndLoc Ending location of the clause.
9627 /// \param VL List of references to the original variables.
9628 static OMPInclusiveClause *Create(const ASTContext &C,
9629 SourceLocation StartLoc,
9630 SourceLocation LParenLoc,
9631 SourceLocation EndLoc, ArrayRef<Expr *> VL);
9632
9633 /// Creates an empty clause with the place for \a N variables.
9634 ///
9635 /// \param C AST context.
9636 /// \param N The number of variables.
9637 static OMPInclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
9638
9639 child_range children() {
9640 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
9641 reinterpret_cast<Stmt **>(varlist_end()));
9642 }
9643
9644 const_child_range children() const {
9645 return const_cast<OMPInclusiveClause *>(this)->children();
9646 }
9647
9648 child_range used_children() {
9649 return child_range(child_iterator(), child_iterator());
9650 }
9651 const_child_range used_children() const {
9652 return const_child_range(const_child_iterator(), const_child_iterator());
9653 }
9654
9655 static bool classof(const OMPClause *T) {
9656 return T->getClauseKind() == llvm::omp::OMPC_inclusive;
9657 }
9658};
9659
9660/// This represents clause 'exclusive' in the '#pragma omp scan' directive.
9661///
9662/// \code
9663/// #pragma omp scan exclusive(a,b)
9664/// \endcode
9665/// In this example directive '#pragma omp scan' has clause 'exclusive'
9666/// with the variables 'a' and 'b'.
9667class OMPExclusiveClause final
9668 : public OMPVarListClause<OMPExclusiveClause>,
9669 private llvm::TrailingObjects<OMPExclusiveClause, Expr *> {
9670 friend class OMPClauseReader;
9671 friend OMPVarListClause;
9672 friend TrailingObjects;
9673
9674 /// Build clause with number of variables \a N.
9675 ///
9676 /// \param StartLoc Starting location of the clause.
9677 /// \param LParenLoc Location of '('.
9678 /// \param EndLoc Ending location of the clause.
9679 /// \param N Number of the variables in the clause.
9680 OMPExclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9681 SourceLocation EndLoc, unsigned N)
9682 : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
9683 StartLoc, LParenLoc, EndLoc, N) {}
9684
9685 /// Build an empty clause.
9686 ///
9687 /// \param N Number of variables.
9688 explicit OMPExclusiveClause(unsigned N)
9689 : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
9690 SourceLocation(), SourceLocation(),
9691 SourceLocation(), N) {}
9692
9693public:
9694 /// Creates clause with a list of variables \a VL.
9695 ///
9696 /// \param C AST context.
9697 /// \param StartLoc Starting location of the clause.
9698 /// \param LParenLoc Location of '('.
9699 /// \param EndLoc Ending location of the clause.
9700 /// \param VL List of references to the original variables.
9701 static OMPExclusiveClause *Create(const ASTContext &C,
9702 SourceLocation StartLoc,
9703 SourceLocation LParenLoc,
9704 SourceLocation EndLoc, ArrayRef<Expr *> VL);
9705
9706 /// Creates an empty clause with the place for \a N variables.
9707 ///
9708 /// \param C AST context.
9709 /// \param N The number of variables.
9710 static OMPExclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
9711
9712 child_range children() {
9713 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
9714 reinterpret_cast<Stmt **>(varlist_end()));
9715 }
9716
9717 const_child_range children() const {
9718 return const_cast<OMPExclusiveClause *>(this)->children();
9719 }
9720
9721 child_range used_children() {
9722 return child_range(child_iterator(), child_iterator());
9723 }
9724 const_child_range used_children() const {
9725 return const_child_range(const_child_iterator(), const_child_iterator());
9726 }
9727
9728 static bool classof(const OMPClause *T) {
9729 return T->getClauseKind() == llvm::omp::OMPC_exclusive;
9730 }
9731};
9732
9733/// This represents clause 'uses_allocators' in the '#pragma omp target'-based
9734/// directives.
9735///
9736/// \code
9737/// #pragma omp target uses_allocators(default_allocator, my_allocator(traits))
9738/// \endcode
9739/// In this example directive '#pragma omp target' has clause 'uses_allocators'
9740/// with the allocators 'default_allocator' and user-defined 'my_allocator'.
9741class OMPUsesAllocatorsClause final
9742 : public OMPClause,
9743 private llvm::TrailingObjects<OMPUsesAllocatorsClause, Expr *,
9744 SourceLocation> {
9745public:
9746 /// Data for list of allocators.
9747 struct Data {
9748 /// Allocator.
9749 Expr *Allocator = nullptr;
9750 /// Allocator traits.
9751 Expr *AllocatorTraits = nullptr;
9752 /// Locations of '(' and ')' symbols.
9753 SourceLocation LParenLoc, RParenLoc;
9754 };
9755
9756private:
9757 friend class OMPClauseReader;
9758 friend TrailingObjects;
9759
9760 enum class ExprOffsets {
9761 Allocator,
9762 AllocatorTraits,
9763 Total,
9764 };
9765
9766 enum class ParenLocsOffsets {
9767 LParen,
9768 RParen,
9769 Total,
9770 };
9771
9772 /// Location of '('.
9773 SourceLocation LParenLoc;
9774 /// Total number of allocators in the clause.
9775 unsigned NumOfAllocators = 0;
9776
9777 /// Build clause.
9778 ///
9779 /// \param StartLoc Starting location of the clause.
9780 /// \param LParenLoc Location of '('.
9781 /// \param EndLoc Ending location of the clause.
9782 /// \param N Number of allocators associated with the clause.
9783 OMPUsesAllocatorsClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9784 SourceLocation EndLoc, unsigned N)
9785 : OMPClause(llvm::omp::OMPC_uses_allocators, StartLoc, EndLoc),
9786 LParenLoc(LParenLoc), NumOfAllocators(N) {}
9787
9788 /// Build an empty clause.
9789 /// \param N Number of allocators associated with the clause.
9790 ///
9791 explicit OMPUsesAllocatorsClause(unsigned N)
9792 : OMPClause(llvm::omp::OMPC_uses_allocators, SourceLocation(),
9793 SourceLocation()),
9794 NumOfAllocators(N) {}
9795
9796 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
9797 return NumOfAllocators * static_cast<int>(ExprOffsets::Total);
9798 }
9799
9800 /// Sets the location of '('.
9801 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
9802
9803 /// Sets the allocators data for the clause.
9804 void setAllocatorsData(ArrayRef<OMPUsesAllocatorsClause::Data> Data);
9805
9806public:
9807 /// Creates clause with a list of allocators \p Data.
9808 ///
9809 /// \param C AST context.
9810 /// \param StartLoc Starting location of the clause.
9811 /// \param LParenLoc Location of '('.
9812 /// \param EndLoc Ending location of the clause.
9813 /// \param Data List of allocators.
9814 static OMPUsesAllocatorsClause *
9815 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
9816 SourceLocation EndLoc, ArrayRef<OMPUsesAllocatorsClause::Data> Data);
9817
9818 /// Creates an empty clause with the place for \p N allocators.
9819 ///
9820 /// \param C AST context.
9821 /// \param N The number of allocators.
9822 static OMPUsesAllocatorsClause *CreateEmpty(const ASTContext &C, unsigned N);
9823
9824 /// Returns the location of '('.
9825 SourceLocation getLParenLoc() const { return LParenLoc; }
9826
9827 /// Returns number of allocators associated with the clause.
9828 unsigned getNumberOfAllocators() const { return NumOfAllocators; }
9829
9830 /// Returns data for the specified allocator.
9831 OMPUsesAllocatorsClause::Data getAllocatorData(unsigned I) const;
9832
9833 // Iterators
9834 child_range children() {
9835 Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
9836 return child_range(Begin, Begin + NumOfAllocators *
9837 static_cast<int>(ExprOffsets::Total));
9838 }
9839 const_child_range children() const {
9840 Stmt *const *Begin =
9841 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
9842 return const_child_range(
9843 Begin, Begin + NumOfAllocators * static_cast<int>(ExprOffsets::Total));
9844 }
9845
9846 child_range used_children() {
9847 return child_range(child_iterator(), child_iterator());
9848 }
9849 const_child_range used_children() const {
9850 return const_child_range(const_child_iterator(), const_child_iterator());
9851 }
9852
9853 static bool classof(const OMPClause *T) {
9854 return T->getClauseKind() == llvm::omp::OMPC_uses_allocators;
9855 }
9856};
9857
9858/// This represents clause 'affinity' in the '#pragma omp task'-based
9859/// directives.
9860///
9861/// \code
9862/// #pragma omp task affinity(iterator(i = 0:n) : ([3][n])a, b[:n], c[i])
9863/// \endcode
9864/// In this example directive '#pragma omp task' has clause 'affinity' with the
9865/// affinity modifer 'iterator(i = 0:n)' and locator items '([3][n])a', 'b[:n]'
9866/// and 'c[i]'.
9867class OMPAffinityClause final
9868 : public OMPVarListClause<OMPAffinityClause>,
9869 private llvm::TrailingObjects<OMPAffinityClause, Expr *> {
9870 friend class OMPClauseReader;
9871 friend OMPVarListClause;
9872 friend TrailingObjects;
9873
9874 /// Location of ':' symbol.
9875 SourceLocation ColonLoc;
9876
9877 /// Build clause.
9878 ///
9879 /// \param StartLoc Starting location of the clause.
9880 /// \param LParenLoc Location of '('.
9881 /// \param ColonLoc Location of ':'.
9882 /// \param EndLoc Ending location of the clause.
9883 /// \param N Number of locators associated with the clause.
9884 OMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc,
9885 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N)
9886 : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity, StartLoc,
9887 LParenLoc, EndLoc, N) {}
9888
9889 /// Build an empty clause.
9890 /// \param N Number of locators associated with the clause.
9891 ///
9892 explicit OMPAffinityClause(unsigned N)
9893 : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity,
9894 SourceLocation(), SourceLocation(),
9895 SourceLocation(), N) {}
9896
9897 /// Sets the affinity modifier for the clause, if any.
9898 void setModifier(Expr *E) { getTrailingObjects()[varlist_size()] = E; }
9899
9900 /// Sets the location of ':' symbol.
9901 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
9902
9903public:
9904 /// Creates clause with a modifier a list of locator items.
9905 ///
9906 /// \param C AST context.
9907 /// \param StartLoc Starting location of the clause.
9908 /// \param LParenLoc Location of '('.
9909 /// \param ColonLoc Location of ':'.
9910 /// \param EndLoc Ending location of the clause.
9911 /// \param Locators List of locator items.
9912 static OMPAffinityClause *Create(const ASTContext &C, SourceLocation StartLoc,
9913 SourceLocation LParenLoc,
9914 SourceLocation ColonLoc,
9915 SourceLocation EndLoc, Expr *Modifier,
9916 ArrayRef<Expr *> Locators);
9917
9918 /// Creates an empty clause with the place for \p N locator items.
9919 ///
9920 /// \param C AST context.
9921 /// \param N The number of locator items.
9922 static OMPAffinityClause *CreateEmpty(const ASTContext &C, unsigned N);
9923
9924 /// Gets affinity modifier.
9925 Expr *getModifier() { return getTrailingObjects()[varlist_size()]; }
9926 Expr *getModifier() const { return getTrailingObjects()[varlist_size()]; }
9927
9928 /// Gets the location of ':' symbol.
9929 SourceLocation getColonLoc() const { return ColonLoc; }
9930
9931 // Iterators
9932 child_range children() {
9933 int Offset = getModifier() ? 1 : 0;
9934 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
9935 reinterpret_cast<Stmt **>(varlist_end() + Offset));
9936 }
9937
9938 const_child_range children() const {
9939 return const_cast<OMPAffinityClause *>(this)->children();
9940 }
9941
9942 child_range used_children() {
9943 return child_range(child_iterator(), child_iterator());
9944 }
9945 const_child_range used_children() const {
9946 return const_child_range(const_child_iterator(), const_child_iterator());
9947 }
9948
9949 static bool classof(const OMPClause *T) {
9950 return T->getClauseKind() == llvm::omp::OMPC_affinity;
9951 }
9952};
9953
9954/// This represents 'filter' clause in the '#pragma omp ...' directive.
9955///
9956/// \code
9957/// #pragma omp masked filter(tid)
9958/// \endcode
9959/// In this example directive '#pragma omp masked' has 'filter' clause with
9960/// thread id.
9962 : public OMPOneStmtClause<llvm::omp::OMPC_filter, OMPClause>,
9963 public OMPClauseWithPreInit {
9964 friend class OMPClauseReader;
9965
9966 /// Sets the thread identifier.
9967 void setThreadID(Expr *TID) { setStmt(TID); }
9968
9969public:
9970 /// Build 'filter' clause with thread-id \a ThreadID.
9971 ///
9972 /// \param ThreadID Thread identifier.
9973 /// \param HelperE Helper expression associated with this clause.
9974 /// \param CaptureRegion Innermost OpenMP region where expressions in this
9975 /// clause must be captured.
9976 /// \param StartLoc Starting location of the clause.
9977 /// \param LParenLoc Location of '('.
9978 /// \param EndLoc Ending location of the clause.
9979 OMPFilterClause(Expr *ThreadID, Stmt *HelperE,
9980 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
9981 SourceLocation LParenLoc, SourceLocation EndLoc)
9982 : OMPOneStmtClause(ThreadID, StartLoc, LParenLoc, EndLoc),
9983 OMPClauseWithPreInit(this) {
9984 setPreInitStmt(HelperE, CaptureRegion);
9985 }
9986
9987 /// Build an empty clause.
9989
9990 /// Return thread identifier.
9991 Expr *getThreadID() const { return getStmtAs<Expr>(); }
9992
9993 /// Return thread identifier.
9994 Expr *getThreadID() { return getStmtAs<Expr>(); }
9995};
9996
9997/// This represents 'bind' clause in the '#pragma omp ...' directives.
9998///
9999/// \code
10000/// #pragma omp loop bind(parallel)
10001/// \endcode
10002class OMPBindClause final : public OMPNoChildClause<llvm::omp::OMPC_bind> {
10003 friend class OMPClauseReader;
10004
10005 /// Location of '('.
10006 SourceLocation LParenLoc;
10007
10008 /// The binding kind of 'bind' clause.
10009 OpenMPBindClauseKind Kind = OMPC_BIND_unknown;
10010
10011 /// Start location of the kind in source code.
10012 SourceLocation KindLoc;
10013
10014 /// Sets the location of '('.
10015 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
10016
10017 /// Set the binding kind.
10018 void setBindKind(OpenMPBindClauseKind K) { Kind = K; }
10019
10020 /// Set the binding kind location.
10021 void setBindKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
10022
10023public:
10024 /// Build 'bind' clause with kind \a K ('teams', 'parallel', or 'thread').
10025 ///
10026 /// \param K Binding kind of the clause ('teams', 'parallel' or 'thread').
10027 /// \param KLoc Starting location of the binding kind.
10028 /// \param StartLoc Starting location of the clause.
10029 /// \param LParenLoc Location of '('.
10030 /// \param EndLoc Ending location of the clause.
10031 OMPBindClause(OpenMPBindClauseKind K, SourceLocation KLoc,
10032 SourceLocation StartLoc, SourceLocation LParenLoc,
10033 SourceLocation EndLoc)
10034 : OMPNoChildClause(StartLoc, EndLoc), LParenLoc(LParenLoc), Kind(K),
10035 KindLoc(KLoc) {}
10036
10037 /// Build an empty clause.
10039
10040 /// Returns the location of '('.
10041 SourceLocation getLParenLoc() const { return LParenLoc; }
10042
10043 /// Returns kind of the clause.
10044 OpenMPBindClauseKind getBindKind() const { return Kind; }
10045
10046 /// Returns location of clause kind.
10047 SourceLocation getBindKindLoc() const { return KindLoc; }
10048};
10049
10050/// This class implements a simple visitor for OMPClause
10051/// subclasses.
10052template<class ImplClass, template <typename> class Ptr, typename RetTy>
10054public:
10055#define PTR(CLASS) Ptr<CLASS>
10056#define DISPATCH(CLASS) \
10057 return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
10058
10059#define GEN_CLANG_CLAUSE_CLASS
10060#define CLAUSE_CLASS(Enum, Str, Class) \
10061 RetTy Visit##Class(PTR(Class) S) { \
10062 return static_cast<ImplClass *>(this)->VisitOMPClause(S); \
10063 }
10064#include "llvm/Frontend/OpenMP/OMP.inc"
10065
10066 RetTy Visit(PTR(OMPClause) S) {
10067 // Top switch clause: visit each OMPClause.
10068 switch (S->getClauseKind()) {
10069#define GEN_CLANG_CLAUSE_CLASS
10070#define CLAUSE_CLASS(Enum, Str, Class) \
10071 case llvm::omp::Clause::Enum: \
10072 DISPATCH(Class);
10073#define CLAUSE_NO_CLASS(Enum, Str) \
10074 case llvm::omp::Clause::Enum: \
10075 break;
10076#include "llvm/Frontend/OpenMP/OMP.inc"
10077 }
10078 }
10079 // Base case, ignore it. :)
10080 RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); }
10081#undef PTR
10082#undef DISPATCH
10083};
10084
10085template <typename T> using const_ptr = std::add_pointer_t<std::add_const_t<T>>;
10086
10087template <class ImplClass, typename RetTy = void>
10089 : public OMPClauseVisitorBase<ImplClass, std::add_pointer_t, RetTy> {};
10090template<class ImplClass, typename RetTy = void>
10092 public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {};
10093
10094class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
10095 raw_ostream &OS;
10096 const PrintingPolicy &Policy;
10097 llvm::omp::Version Version;
10098
10099 /// Process clauses with list of variables.
10100 template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
10101 /// Process motion clauses.
10102 template <typename T> void VisitOMPMotionClause(T *Node);
10103
10104public:
10105 OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy,
10106 llvm::omp::Version OpenMPVersion)
10107 : OS(OS), Policy(Policy), Version(OpenMPVersion) {}
10108
10109#define GEN_CLANG_CLAUSE_CLASS
10110#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);
10111#include "llvm/Frontend/OpenMP/OMP.inc"
10112};
10113
10115 llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
10116
10117 /// The raw string as we parsed it. This is needed for the `isa` trait set
10118 /// (which accepts anything) and (later) extensions.
10119 StringRef RawString;
10120};
10121
10123 Expr *ScoreOrCondition = nullptr;
10124 llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
10126};
10127
10129 llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
10131};
10132
10133/// Helper data structure representing the traits in a match clause of an
10134/// `declare variant` or `metadirective`. The outer level is an ordered
10135/// collection of selector sets, each with an associated kind and an ordered
10136/// collection of selectors. A selector has a kind, an optional score/condition,
10137/// and an ordered collection of properties.
10138class OMPTraitInfo {
10139 /// Private constructor accesible only by ASTContext.
10140 OMPTraitInfo() {}
10141 friend class ASTContext;
10142
10143public:
10144 /// Reconstruct a (partial) OMPTraitInfo object from a mangled name.
10145 OMPTraitInfo(StringRef MangledName);
10146
10147 /// The outermost level of selector sets.
10149
10151 llvm::function_ref<bool(Expr *&, bool /* IsScore */)> Cond) {
10152 return llvm::any_of(Sets, [&](OMPTraitSet &Set) {
10153 return llvm::any_of(
10154 Set.Selectors, [&](OMPTraitSelector &Selector) {
10155 return Cond(Selector.ScoreOrCondition,
10156 /* IsScore */ Selector.Kind !=
10157 llvm::omp::TraitSelector::user_condition);
10158 });
10159 });
10160 }
10161
10162 /// Create a variant match info object from this trait info object. While the
10163 /// former is a flat representation the actual main difference is that the
10164 /// latter uses clang::Expr to store the score/condition while the former is
10165 /// independent of clang. Thus, expressions and conditions are evaluated in
10166 /// this method.
10167 void getAsVariantMatchInfo(ASTContext &ASTCtx,
10168 llvm::omp::VariantMatchInfo &VMI) const;
10169
10170 /// Return a string representation identifying this context selector.
10171 std::string getMangledName() const;
10172
10173 /// Check the extension trait \p TP is active.
10174 bool isExtensionActive(llvm::omp::TraitProperty TP) {
10175 for (const OMPTraitSet &Set : Sets) {
10176 if (Set.Kind != llvm::omp::TraitSet::implementation)
10177 continue;
10178 for (const OMPTraitSelector &Selector : Set.Selectors) {
10179 if (Selector.Kind != llvm::omp::TraitSelector::implementation_extension)
10180 continue;
10181 for (const OMPTraitProperty &Property : Selector.Properties) {
10182 if (Property.Kind == TP)
10183 return true;
10184 }
10185 }
10186 }
10187 return false;
10188 }
10189
10190 /// Print a human readable representation into \p OS.
10191 void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
10192};
10193llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
10194llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
10195
10196/// Clang specific specialization of the OMPContext to lookup target features.
10199 std::function<void(StringRef)> &&DiagUnknownTrait,
10200 const FunctionDecl *CurrentFunctionDecl,
10201 ArrayRef<llvm::omp::TraitProperty> ConstructTraits,
10202 int DeviceNum);
10203
10204 virtual ~TargetOMPContext() = default;
10205
10206 /// See llvm::omp::OMPContext::matchesISATrait
10207 bool matchesISATrait(StringRef RawString) const override;
10208
10209private:
10210 std::function<bool(StringRef)> FeatureValidityCheck;
10211 std::function<void(StringRef)> DiagUnknownTrait;
10212 llvm::StringMap<bool> FeatureMap;
10213};
10214
10215/// Contains data for OpenMP directives: clauses, children
10216/// expressions/statements (helpers for codegen) and associated statement, if
10217/// any.
10218class OMPChildren final
10219 : private llvm::TrailingObjects<OMPChildren, OMPClause *, Stmt *> {
10220 friend TrailingObjects;
10221 friend class OMPClauseReader;
10223 friend class OMPMetaDirective;
10224 template <typename T> friend class OMPDeclarativeDirective;
10225
10226 /// Numbers of clauses.
10227 unsigned NumClauses = 0;
10228 /// Number of child expressions/stmts.
10229 unsigned NumChildren = 0;
10230 /// true if the directive has associated statement.
10231 bool HasAssociatedStmt = false;
10232
10233 /// Define the sizes of each trailing object array except the last one. This
10234 /// is required for TrailingObjects to work properly.
10235 size_t numTrailingObjects(OverloadToken<OMPClause *>) const {
10236 return NumClauses;
10237 }
10238
10239 OMPChildren() = delete;
10240
10241 OMPChildren(unsigned NumClauses, unsigned NumChildren, bool HasAssociatedStmt)
10242 : NumClauses(NumClauses), NumChildren(NumChildren),
10243 HasAssociatedStmt(HasAssociatedStmt) {}
10244
10245 static size_t size(unsigned NumClauses, bool HasAssociatedStmt,
10246 unsigned NumChildren);
10247
10248 static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses);
10249 static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses, Stmt *S,
10250 unsigned NumChildren = 0);
10251 static OMPChildren *CreateEmpty(void *Mem, unsigned NumClauses,
10252 bool HasAssociatedStmt = false,
10253 unsigned NumChildren = 0);
10254
10255public:
10256 unsigned getNumClauses() const { return NumClauses; }
10257 unsigned getNumChildren() const { return NumChildren; }
10258 bool hasAssociatedStmt() const { return HasAssociatedStmt; }
10259
10260 /// Set associated statement.
10261 void setAssociatedStmt(Stmt *S) {
10262 getTrailingObjects<Stmt *>()[NumChildren] = S;
10263 }
10264
10266
10267 /// Sets the list of variables for this clause.
10268 ///
10269 /// \param Clauses The list of clauses for the directive.
10270 ///
10271 void setClauses(ArrayRef<OMPClause *> Clauses);
10272
10273 /// Returns statement associated with the directive.
10274 const Stmt *getAssociatedStmt() const {
10275 return const_cast<OMPChildren *>(this)->getAssociatedStmt();
10276 }
10278 assert(HasAssociatedStmt &&
10279 "Expected directive with the associated statement.");
10280 return getTrailingObjects<Stmt *>()[NumChildren];
10281 }
10282
10283 /// Get the clauses storage.
10284 MutableArrayRef<OMPClause *> getClauses() {
10285 return getTrailingObjects<OMPClause *>(NumClauses);
10286 }
10288 return const_cast<OMPChildren *>(this)->getClauses();
10289 }
10290
10291 /// Returns the captured statement associated with the
10292 /// component region within the (combined) directive.
10293 ///
10294 /// \param RegionKind Component region kind.
10295 const CapturedStmt *
10296 getCapturedStmt(OpenMPDirectiveKind RegionKind,
10297 ArrayRef<OpenMPDirectiveKind> CaptureRegions) const {
10298 assert(llvm::is_contained(CaptureRegions, RegionKind) &&
10299 "RegionKind not found in OpenMP CaptureRegions.");
10300 auto *CS = cast<CapturedStmt>(getAssociatedStmt());
10301 for (auto ThisCaptureRegion : CaptureRegions) {
10302 if (ThisCaptureRegion == RegionKind)
10303 return CS;
10304 CS = cast<CapturedStmt>(CS->getCapturedStmt());
10305 }
10306 llvm_unreachable("Incorrect RegionKind specified for directive.");
10307 }
10308
10309 /// Get innermost captured statement for the construct.
10310 CapturedStmt *
10312 assert(hasAssociatedStmt() && "Must have associated captured statement.");
10313 assert(!CaptureRegions.empty() &&
10314 "At least one captured statement must be provided.");
10315 auto *CS = cast<CapturedStmt>(getAssociatedStmt());
10316 for (unsigned Level = CaptureRegions.size(); Level > 1; --Level)
10317 CS = cast<CapturedStmt>(CS->getCapturedStmt());
10318 return CS;
10319 }
10320
10321 const CapturedStmt *
10323 return const_cast<OMPChildren *>(this)->getInnermostCapturedStmt(
10324 CaptureRegions);
10325 }
10326
10327 MutableArrayRef<Stmt *> getChildren();
10329 return const_cast<OMPChildren *>(this)->getChildren();
10330 }
10331
10332 Stmt *getRawStmt() {
10333 assert(HasAssociatedStmt &&
10334 "Expected directive with the associated statement.");
10335 if (auto *CS = dyn_cast<CapturedStmt>(getAssociatedStmt())) {
10336 Stmt *S = nullptr;
10337 do {
10338 S = CS->getCapturedStmt();
10339 CS = dyn_cast<CapturedStmt>(S);
10340 } while (CS);
10341 return S;
10342 }
10343 return getAssociatedStmt();
10344 }
10345 const Stmt *getRawStmt() const {
10346 return const_cast<OMPChildren *>(this)->getRawStmt();
10347 }
10348
10349 Stmt::child_range getAssociatedStmtAsRange() {
10350 if (!HasAssociatedStmt)
10351 return Stmt::child_range(Stmt::child_iterator(), Stmt::child_iterator());
10352 return Stmt::child_range(&getTrailingObjects<Stmt *>()[NumChildren],
10353 &getTrailingObjects<Stmt *>()[NumChildren + 1]);
10354 }
10355};
10356
10357/// This represents 'ompx_dyn_cgroup_mem' clause in the '#pragma omp target ...'
10358/// directive.
10359///
10360/// \code
10361/// #pragma omp target [...] ompx_dyn_cgroup_mem(N)
10362/// \endcode
10364 : public OMPOneStmtClause<llvm::omp::OMPC_ompx_dyn_cgroup_mem, OMPClause>,
10365 public OMPClauseWithPreInit {
10366 friend class OMPClauseReader;
10367
10368 /// Set size.
10369 void setSize(Expr *E) { setStmt(E); }
10370
10371public:
10372 /// Build 'ompx_dyn_cgroup_mem' clause.
10373 ///
10374 /// \param Size Size expression.
10375 /// \param HelperSize Helper Size expression
10376 /// \param CaptureRegion Innermost OpenMP region where expressions in this
10377 /// \param StartLoc Starting location of the clause.
10378 /// \param LParenLoc Location of '('.
10379 /// \param EndLoc Ending location of the clause.
10380 OMPXDynCGroupMemClause(Expr *Size, Stmt *HelperSize,
10381 OpenMPDirectiveKind CaptureRegion,
10382 SourceLocation StartLoc, SourceLocation LParenLoc,
10383 SourceLocation EndLoc)
10384 : OMPOneStmtClause(Size, StartLoc, LParenLoc, EndLoc),
10385 OMPClauseWithPreInit(this) {
10386 setPreInitStmt(HelperSize, CaptureRegion);
10387 }
10388
10389 /// Build an empty clause.
10391
10392 /// Return the size expression.
10393 Expr *getSize() { return getStmtAs<Expr>(); }
10394
10395 /// Return the size expression.
10396 Expr *getSize() const { return getStmtAs<Expr>(); }
10397};
10398
10399/// This represents 'dyn_groupprivate' clause in '#pragma omp target ...'
10400/// and '#pragma omp teams ...' directives.
10401///
10402/// \code
10403/// #pragma omp target [...] dyn_groupprivate(a,b: N)
10404/// \endcode
10406 friend class OMPClauseReader;
10407
10408 /// Location of '('.
10409 SourceLocation LParenLoc;
10410
10411 /// Modifiers for 'dyn_groupprivate' clause.
10412 enum { SIMPLE, FALLBACK, NUM_MODIFIERS };
10413 unsigned Modifiers[NUM_MODIFIERS];
10414
10415 /// Locations of modifiers.
10416 SourceLocation ModifiersLoc[NUM_MODIFIERS];
10417
10418 /// The size of the dyn_groupprivate.
10419 Expr *Size = nullptr;
10420
10421 /// Set the first dyn_groupprivate modifier.
10422 ///
10423 /// \param M The modifier.
10424 void setDynGroupprivateModifier(OpenMPDynGroupprivateClauseModifier M) {
10425 Modifiers[SIMPLE] = M;
10426 }
10427
10428 /// Set the second dyn_groupprivate modifier.
10429 ///
10430 /// \param M The modifier.
10431 void setDynGroupprivateFallbackModifier(
10432 OpenMPDynGroupprivateClauseFallbackModifier M) {
10433 Modifiers[FALLBACK] = M;
10434 }
10435
10436 /// Set location of the first dyn_groupprivate modifier.
10437 void setDynGroupprivateModifierLoc(SourceLocation Loc) {
10438 ModifiersLoc[SIMPLE] = Loc;
10439 }
10440
10441 /// Set location of the second dyn_groupprivate modifier.
10442 void setDynGroupprivateFallbackModifierLoc(SourceLocation Loc) {
10443 ModifiersLoc[FALLBACK] = Loc;
10444 }
10445
10446 /// Sets the location of '('.
10447 ///
10448 /// \param Loc Location of '('.
10449 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
10450
10451 /// Set size.
10452 ///
10453 /// \param E Size.
10454 void setSize(Expr *E) { Size = E; }
10455
10456public:
10457 /// Build 'dyn_groupprivate' clause with a size expression \a Size.
10458 ///
10459 /// \param StartLoc Starting location of the clause.
10460 /// \param LParenLoc Location of '('.
10461 /// \param EndLoc Ending location of the clause.
10462 /// \param Size Size.
10463 /// \param M1 The first modifier applied to 'dyn_groupprivate' clause.
10464 /// \param M1Loc Location of the first modifier.
10465 /// \param M2 The second modifier applied to 'dyn_groupprivate' clause.
10466 /// \param M2Loc Location of the second modifier.
10467 OMPDynGroupprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
10468 SourceLocation EndLoc, Expr *Size, Stmt *HelperSize,
10469 OpenMPDirectiveKind CaptureRegion,
10470 OpenMPDynGroupprivateClauseModifier M1,
10471 SourceLocation M1Loc,
10472 OpenMPDynGroupprivateClauseFallbackModifier M2,
10473 SourceLocation M2Loc)
10474 : OMPClause(llvm::omp::OMPC_dyn_groupprivate, StartLoc, EndLoc),
10475 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Size(Size) {
10476 setPreInitStmt(HelperSize, CaptureRegion);
10477 Modifiers[SIMPLE] = M1;
10478 Modifiers[FALLBACK] = M2;
10479 ModifiersLoc[SIMPLE] = M1Loc;
10480 ModifiersLoc[FALLBACK] = M2Loc;
10481 }
10482
10483 /// Build an empty clause.
10485 : OMPClause(llvm::omp::OMPC_dyn_groupprivate, SourceLocation(),
10486 SourceLocation()),
10487 OMPClauseWithPreInit(this) {
10488 Modifiers[SIMPLE] = OMPC_DYN_GROUPPRIVATE_unknown;
10489 Modifiers[FALLBACK] = OMPC_DYN_GROUPPRIVATE_FALLBACK_unknown;
10490 }
10491
10492 /// Get the first modifier of the clause.
10493 OpenMPDynGroupprivateClauseModifier getDynGroupprivateModifier() const {
10494 return static_cast<OpenMPDynGroupprivateClauseModifier>(Modifiers[SIMPLE]);
10495 }
10496
10497 /// Get the second modifier of the clause.
10498 OpenMPDynGroupprivateClauseFallbackModifier
10500 return static_cast<OpenMPDynGroupprivateClauseFallbackModifier>(
10501 Modifiers[FALLBACK]);
10502 }
10503
10504 /// Get location of '('.
10505 SourceLocation getLParenLoc() { return LParenLoc; }
10506
10507 /// Get the first modifier location.
10508 SourceLocation getDynGroupprivateModifierLoc() const {
10509 return ModifiersLoc[SIMPLE];
10510 }
10511
10512 /// Get the second modifier location.
10514 return ModifiersLoc[FALLBACK];
10515 }
10516
10517 /// Get size.
10518 Expr *getSize() { return Size; }
10519
10520 /// Get size.
10521 const Expr *getSize() const { return Size; }
10522
10523 child_range children() {
10524 return child_range(reinterpret_cast<Stmt **>(&Size),
10525 reinterpret_cast<Stmt **>(&Size) + 1);
10526 }
10527
10528 const_child_range children() const {
10529 return const_cast<OMPDynGroupprivateClause *>(this)->children();
10530 }
10531
10532 child_range used_children() {
10533 return child_range(child_iterator(), child_iterator());
10534 }
10535 const_child_range used_children() const {
10536 return const_child_range(const_child_iterator(), const_child_iterator());
10537 }
10538
10539 static bool classof(const OMPClause *T) {
10540 return T->getClauseKind() == llvm::omp::OMPC_dyn_groupprivate;
10541 }
10542};
10543
10544/// This represents the 'doacross' clause for the '#pragma omp ordered'
10545/// directive.
10546///
10547/// \code
10548/// #pragma omp ordered doacross(sink: i-1, j-1)
10549/// \endcode
10550/// In this example directive '#pragma omp ordered' with clause 'doacross' with
10551/// a dependence-type 'sink' and loop-iteration vector expressions i-1 and j-1.
10552class OMPDoacrossClause final
10553 : public OMPVarListClause<OMPDoacrossClause>,
10554 private llvm::TrailingObjects<OMPDoacrossClause, Expr *> {
10555 friend class OMPClauseReader;
10556 friend OMPVarListClause;
10557 friend TrailingObjects;
10558
10559 /// Dependence type (sink or source).
10560 OpenMPDoacrossClauseModifier DepType = OMPC_DOACROSS_unknown;
10561
10562 /// Dependence type location.
10563 SourceLocation DepLoc;
10564
10565 /// Colon location.
10566 SourceLocation ColonLoc;
10567
10568 /// Number of loops, associated with the doacross clause.
10569 unsigned NumLoops = 0;
10570
10571 /// Build clause with number of expressions \a N.
10572 ///
10573 /// \param StartLoc Starting location of the clause.
10574 /// \param LParenLoc Location of '('.
10575 /// \param EndLoc Ending location of the clause.
10576 /// \param N Number of expressions in the clause.
10577 /// \param NumLoops Number of loops associated with the clause.
10578 OMPDoacrossClause(SourceLocation StartLoc, SourceLocation LParenLoc,
10579 SourceLocation EndLoc, unsigned N, unsigned NumLoops)
10580 : OMPVarListClause<OMPDoacrossClause>(llvm::omp::OMPC_doacross, StartLoc,
10581 LParenLoc, EndLoc, N),
10582 NumLoops(NumLoops) {}
10583
10584 /// Build an empty clause.
10585 ///
10586 /// \param N Number of expressions in the clause.
10587 /// \param NumLoops Number of loops associated with the clause.
10588 explicit OMPDoacrossClause(unsigned N, unsigned NumLoops)
10589 : OMPVarListClause<OMPDoacrossClause>(llvm::omp::OMPC_doacross,
10590 SourceLocation(), SourceLocation(),
10591 SourceLocation(), N),
10592 NumLoops(NumLoops) {}
10593
10594 /// Set dependence type.
10595 void setDependenceType(OpenMPDoacrossClauseModifier M) { DepType = M; }
10596
10597 /// Set dependence type location.
10598 void setDependenceLoc(SourceLocation Loc) { DepLoc = Loc; }
10599
10600 /// Set colon location.
10601 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
10602
10603public:
10604 /// Creates clause with a list of expressions \a VL.
10605 ///
10606 /// \param C AST context.
10607 /// \param StartLoc Starting location of the clause.
10608 /// \param LParenLoc Location of '('.
10609 /// \param EndLoc Ending location of the clause.
10610 /// \param DepType The dependence type.
10611 /// \param DepLoc Location of the dependence type.
10612 /// \param ColonLoc Location of ':'.
10613 /// \param VL List of references to the expressions.
10614 /// \param NumLoops Number of loops that associated with the clause.
10615 static OMPDoacrossClause *
10616 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
10617 SourceLocation EndLoc, OpenMPDoacrossClauseModifier DepType,
10618 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
10619 unsigned NumLoops);
10620
10621 /// Creates an empty clause with \a N expressions.
10622 ///
10623 /// \param C AST context.
10624 /// \param N The number of expressions.
10625 /// \param NumLoops Number of loops that is associated with this clause.
10626 static OMPDoacrossClause *CreateEmpty(const ASTContext &C, unsigned N,
10627 unsigned NumLoops);
10628
10629 /// Get dependence type.
10630 OpenMPDoacrossClauseModifier getDependenceType() const { return DepType; }
10631
10632 /// Get dependence type location.
10633 SourceLocation getDependenceLoc() const { return DepLoc; }
10634
10635 /// Get colon location.
10636 SourceLocation getColonLoc() const { return ColonLoc; }
10637
10638 /// Get number of loops associated with the clause.
10639 unsigned getNumLoops() const { return NumLoops; }
10640
10641 /// Set the loop data.
10642 void setLoopData(unsigned NumLoop, Expr *Cnt);
10643
10644 /// Get the loop data.
10645 Expr *getLoopData(unsigned NumLoop);
10646 const Expr *getLoopData(unsigned NumLoop) const;
10647
10648 child_range children() {
10649 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
10650 reinterpret_cast<Stmt **>(varlist_end()));
10651 }
10652
10653 const_child_range children() const {
10654 return const_cast<OMPDoacrossClause *>(this)->children();
10655 }
10656
10657 child_range used_children() {
10658 return child_range(child_iterator(), child_iterator());
10659 }
10660 const_child_range used_children() const {
10661 return const_child_range(const_child_iterator(), const_child_iterator());
10662 }
10663
10664 static bool classof(const OMPClause *T) {
10665 return T->getClauseKind() == llvm::omp::OMPC_doacross;
10666 }
10667};
10668
10669/// This represents 'ompx_attribute' clause in a directive that might generate
10670/// an outlined function. An example is given below.
10671///
10672/// \code
10673/// #pragma omp target [...] ompx_attribute(flatten)
10674/// \endcode
10676 : public OMPNoChildClause<llvm::omp::OMPC_ompx_attribute> {
10677 friend class OMPClauseReader;
10678
10679 /// Location of '('.
10680 SourceLocation LParenLoc;
10681
10682 /// The parsed attributes (clause arguments)
10684
10685public:
10686 /// Build 'ompx_attribute' clause.
10687 ///
10688 /// \param Attrs The parsed attributes (clause arguments)
10689 /// \param StartLoc Starting location of the clause.
10690 /// \param LParenLoc Location of '('.
10691 /// \param EndLoc Ending location of the clause.
10692 OMPXAttributeClause(ArrayRef<const Attr *> Attrs, SourceLocation StartLoc,
10693 SourceLocation LParenLoc, SourceLocation EndLoc)
10694 : OMPNoChildClause(StartLoc, EndLoc), LParenLoc(LParenLoc), Attrs(Attrs) {
10695 }
10696
10697 /// Build an empty clause.
10699
10700 /// Sets the location of '('.
10701 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
10702
10703 /// Returns the location of '('.
10704 SourceLocation getLParenLoc() const { return LParenLoc; }
10705
10706 /// Returned the attributes parsed from this clause.
10707 ArrayRef<const Attr *> getAttrs() const { return Attrs; }
10708
10709private:
10710 /// Replace the attributes with \p NewAttrs.
10711 void setAttrs(ArrayRef<Attr *> NewAttrs) {
10712 Attrs.clear();
10713 Attrs.append(NewAttrs.begin(), NewAttrs.end());
10714 }
10715};
10716
10717/// This represents 'ompx_bare' clause in the '#pragma omp target teams ...'
10718/// directive.
10719///
10720/// \code
10721/// #pragma omp target teams ompx_bare
10722/// \endcode
10723/// In this example directive '#pragma omp target teams' has a 'ompx_bare'
10724/// clause.
10725class OMPXBareClause : public OMPNoChildClause<llvm::omp::OMPC_ompx_bare> {
10726public:
10727 /// Build 'ompx_bare' clause.
10728 ///
10729 /// \param StartLoc Starting location of the clause.
10730 /// \param EndLoc Ending location of the clause.
10731 OMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
10732 : OMPNoChildClause(StartLoc, EndLoc) {}
10733
10734 /// Build an empty clause.
10735 OMPXBareClause() = default;
10736};
10737
10738/// Resolve one 'adjust_args' parameter-list item to the 1-based argument
10739/// positions it identifies (OpenMP 6.0 [5.2.1]).
10740///
10741/// \param Item A named item, positional item, or parameter range.
10742/// \param FD The base function the OMPDeclareVariantAttr is attached to.
10743/// \param NumArgs The value of 'omp_num_args' at the point of resolution:
10744/// \c max(FD->getNumParams(), Call->getNumArgs()) at a call
10745/// site, or \c FD->getNumParams() with no call site available
10746/// (OpenMP 6.0 [20.1]).
10747/// \param Positions Resolved positions are appended here, ascending. Positions
10748/// outside [1, NumArgs] are silently dropped
10749/// (OpenMP 6.0 [9.6.2]).
10750/// \returns false if \p Item is not a resolvable item shape, or if a bound is
10751/// dependent or not a constant expression.
10752///
10753/// Emits no diagnostics; callers are responsible for diagnosing invalid items
10754/// before calling this function.
10755bool resolveOMPAdjustArgsItem(const OMPAdjustArgsItem &Item,
10756 const FunctionDecl *FD, unsigned NumArgs,
10757 const ASTContext &Ctx,
10758 SmallVectorImpl<unsigned> &Positions);
10759
10760} // namespace clang
10761
10762#endif // LLVM_CLANG_AST_OPENMPCLAUSE_H
#define V(N, I)
Forward declaration of all AST node types.
#define PTR(CLASS)
Definition AttrVisitor.h:27
static Decl::Kind getKind(const Decl *D)
SmallVector< AnnotatedLine *, 1 > Children
If this token starts a block, this contains all the unwrapped lines in it.
static const Decl * getCanonicalDecl(const Decl *D)
static void print(llvm::raw_ostream &OS, const T &V, const Context &Ctx, QualType Ty)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
bool resolveOMPAdjustArgsItem(const OMPAdjustArgsItem &Item, const FunctionDecl *FD, unsigned NumArgs, const ASTContext &Ctx, SmallVectorImpl< unsigned > &Positions)
Resolve one 'adjust_args' parameter-list item to the 1-based argument positions it identifies (OpenMP...
std::add_pointer_t< std::add_const_t< T > > const_ptr
Defines some OpenMP-specific enums and functions.
Defines the clang::SourceLocation class and associated facilities.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
This represents clause 'affinity' in the 'pragma omp task'-based directives.
friend class OMPClauseReader
Expr * getModifier()
Gets affinity modifier.
child_range used_children()
SourceLocation getColonLoc() const
Gets the location of ':' symbol.
const_child_range children() const
child_range children()
Expr * getModifier() const
static bool classof(const OMPClause *T)
const_child_range used_children() const
This represents clause 'aligned' in the 'pragma omp ...' directives.
friend class OMPClauseReader
void setColonLoc(SourceLocation Loc)
Sets the location of ':'.
SourceLocation getColonLoc() const
Returns the location of ':'.
const Expr * getAlignment() const
Returns alignment.
const_child_range children() const
child_range children()
static bool classof(const OMPClause *T)
Expr * getAlignment()
Returns alignment.
child_range used_children()
const_child_range used_children() const
friend class OMPClauseReader
SourceLocation getBindKindLoc() const
Returns location of clause kind.
OMPBindClause(OpenMPBindClauseKind K, SourceLocation KLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'bind' clause with kind K ('teams', 'parallel', or 'thread').
OMPBindClause()
Build an empty clause.
SourceLocation getLParenLoc() const
Returns the location of '('.
OpenMPBindClauseKind getBindKind() const
Returns kind of the clause.
Contains data for OpenMP directives: clauses, children expressions/statements (helpers for codegen) a...
friend class OMPClauseReader
void setChildren(ArrayRef< Stmt * > Children)
Stmt::child_range getAssociatedStmtAsRange()
MutableArrayRef< OMPClause * > getClauses()
Get the clauses storage.
void setClauses(ArrayRef< OMPClause * > Clauses)
Sets the list of variables for this clause.
friend class OMPMetaDirective
friend class OMPDeclarativeDirective
bool hasAssociatedStmt() const
const CapturedStmt * getInnermostCapturedStmt(ArrayRef< OpenMPDirectiveKind > CaptureRegions) const
Stmt * getRawStmt()
ArrayRef< Stmt * > getChildren() const
void setAssociatedStmt(Stmt *S)
Set associated statement.
const Stmt * getRawStmt() const
unsigned getNumChildren() const
CapturedStmt * getInnermostCapturedStmt(ArrayRef< OpenMPDirectiveKind > CaptureRegions)
Get innermost captured statement for the construct.
friend class OMPExecutableDirective
const Stmt * getAssociatedStmt() const
Returns statement associated with the directive.
ArrayRef< OMPClause * > getClauses() const
MutableArrayRef< Stmt * > getChildren()
const CapturedStmt * getCapturedStmt(OpenMPDirectiveKind RegionKind, ArrayRef< OpenMPDirectiveKind > CaptureRegions) const
Returns the captured statement associated with the component region within the (combined) directive.
Stmt * getAssociatedStmt()
unsigned getNumClauses() const
Class that represents a component of a mappable expression. E.g. for an expression S....
bool operator==(const MappableComponent &Other) const
MappableComponent(Expr *AssociatedExpression, ValueDecl *AssociatedDeclaration, bool IsNonContiguous)
Struct that defines common infrastructure to handle mappable expressions used in OpenMP clauses.
static unsigned getUniqueDeclarationsTotalNumber(ArrayRef< const ValueDecl * > Declarations)
static unsigned getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists)
friend llvm::hash_code hash_value(const MappableComponent &MC)
ArrayRef< MappableExprComponentList > MappableExprComponentListsRef
SmallVector< MappableComponent, 8 > MappableExprComponentList
ArrayRef< MappableComponent > MappableExprComponentListRef
SmallVector< MappableExprComponentList, 8 > MappableExprComponentLists
OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy, llvm::omp::Version OpenMPVersion)
This class implements a simple visitor for OMPClause subclasses.
RetTy VisitOMPClause(PTR(OMPClause) Node)
RetTy Visit(PTR(OMPClause) S)
This represents clause 'copyin' in the 'pragma omp ...' directives.
friend class OMPClauseReader
llvm::iterator_range< helper_expr_iterator > helper_expr_range
helper_expr_const_range assignment_ops() const
ArrayRef< const Expr * >::iterator helper_expr_const_iterator
helper_expr_range assignment_ops()
child_range children()
helper_expr_range source_exprs()
helper_expr_const_range source_exprs() const
MutableArrayRef< Expr * >::iterator helper_expr_iterator
const_child_range children() const
static bool classof(const OMPClause *T)
helper_expr_range destination_exprs()
child_range used_children()
llvm::iterator_range< helper_expr_const_iterator > helper_expr_const_range
const_child_range used_children() const
helper_expr_const_range destination_exprs() const
This represents clause 'copyprivate' in the 'pragma omp ...' directives.
llvm::iterator_range< helper_expr_iterator > helper_expr_range
child_range children()
friend class OMPClauseReader
const_child_range used_children() const
helper_expr_range destination_exprs()
helper_expr_range source_exprs()
const_child_range children() const
llvm::iterator_range< helper_expr_const_iterator > helper_expr_const_range
child_range used_children()
static bool classof(const OMPClause *T)
helper_expr_const_range destination_exprs() const
ArrayRef< const Expr * >::iterator helper_expr_const_iterator
MutableArrayRef< Expr * >::iterator helper_expr_iterator
helper_expr_const_range source_exprs() const
helper_expr_range assignment_ops()
helper_expr_const_range assignment_ops() const
friend class OMPClauseReader
const_child_range children() const
OMPDefaultmapClause()
Build an empty clause.
child_range children()
OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KLoc, SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind, OpenMPDefaultmapClauseModifier M)
Build 'defaultmap' clause with defaultmap kind Kind.
static bool classof(const OMPClause *T)
child_range used_children()
SourceLocation getDefaultmapModifierLoc() const
Get the modifier location.
OpenMPDefaultmapClauseKind getDefaultmapKind() const
Get kind of the clause.
const_child_range used_children() const
SourceLocation getDefaultmapKindLoc()
Get kind location.
OpenMPDefaultmapClauseModifier getDefaultmapModifier() const
Get the modifier of the clause.
SourceLocation getLParenLoc()
Get location of '('.
This represents implicit clause 'depend' for the 'pragma omp task' directive.
const_child_range children() const
friend class OMPClauseReader
SourceLocation getDependencyLoc() const
Get dependency type location.
Expr * getModifier()
Return optional depend modifier.
unsigned getNumLoops() const
Get number of loops associated with the clause.
const Expr * getModifier() const
SourceLocation getColonLoc() const
Get colon location.
SourceLocation getOmpAllMemoryLoc() const
Get 'omp_all_memory' location.
const_child_range used_children() const
static bool classof(const OMPClause *T)
child_range children()
OpenMPDependClauseKind getDependencyKind() const
Get dependency type.
child_range used_children()
const Expr * getDepobj() const
friend class OMPClauseReader
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range children() const
OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, Expr *Depobj)
Build a 'depobj' clause.
child_range children()
Expr * getDepobj()
Returns depobj expression associated with the clause.
static bool classof(const OMPClause *T)
const_child_range used_children() const
child_range used_children()
OMPDepobjClause()
Build an empty clause.
SourceLocation getLParenLoc() const
Returns the location of '('.
OMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build 'destroy' clause with an interop variable expression InteropVar.
friend class OMPClauseReader
const_child_range children() const
const_child_range used_children() const
static bool classof(const OMPClause *T)
SourceLocation getVarLoc() const
Returns the location of the interop variable.
Expr * getInteropVar() const
Returns the interop variable.
child_range used_children()
OMPDestroyClause()
Build an empty clause.
child_range children()
OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'destroy' clause.
friend class OMPClauseReader
Expr * getEventHandler() const
Returns event-handler expression.
OMPDetachClause()
Build an empty clause.
OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'detach' clause with event-handler Evt.
OpenMPDeviceClauseModifier getModifier() const
Gets modifier.
friend class OMPClauseReader
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
child_range used_children()
Expr * getDevice()
Return device number.
OMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build 'device' clause.
OMPDeviceClause()
Build an empty clause.
SourceLocation getModifierLoc() const
Gets modifier location.
Expr * getDevice() const
Return device number.
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range used_children() const
const_child_range children() const
child_range children()
static bool classof(const OMPClause *T)
SourceLocation getDistScheduleKindLoc()
Get kind location.
friend class OMPClauseReader
OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KLoc, SourceLocation CommaLoc, SourceLocation EndLoc, OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, Stmt *HelperChunkSize)
Build 'dist_schedule' clause with schedule kind Kind and chunk size expression ChunkSize.
SourceLocation getLParenLoc()
Get location of '('.
child_range used_children()
const_child_range used_children() const
SourceLocation getCommaLoc()
Get location of ','.
static bool classof(const OMPClause *T)
const_child_range children() const
Expr * getChunkSize()
Get chunk size.
OpenMPDistScheduleClauseKind getDistScheduleKind() const
Get kind of the clause.
OMPDistScheduleClause()
Build an empty clause.
const Expr * getChunkSize() const
Get chunk size.
This represents the 'doacross' clause for the 'pragma omp ordered' directive.
const_child_range children() const
friend class OMPClauseReader
SourceLocation getDependenceLoc() const
Get dependence type location.
SourceLocation getColonLoc() const
Get colon location.
OpenMPDoacrossClauseModifier getDependenceType() const
Get dependence type.
static bool classof(const OMPClause *T)
const_child_range used_children() const
child_range children()
child_range used_children()
unsigned getNumLoops() const
Get number of loops associated with the clause.
OMPDynGroupprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, Expr *Size, Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, OpenMPDynGroupprivateClauseModifier M1, SourceLocation M1Loc, OpenMPDynGroupprivateClauseFallbackModifier M2, SourceLocation M2Loc)
Build 'dyn_groupprivate' clause with a size expression Size.
static bool classof(const OMPClause *T)
const Expr * getSize() const
Get size.
Expr * getSize()
Get size.
SourceLocation getLParenLoc()
Get location of '('.
OpenMPDynGroupprivateClauseFallbackModifier getDynGroupprivateFallbackModifier() const
Get the second modifier of the clause.
OMPDynGroupprivateClause()
Build an empty clause.
SourceLocation getDynGroupprivateFallbackModifierLoc() const
Get the second modifier location.
SourceLocation getDynGroupprivateModifierLoc() const
Get the first modifier location.
OpenMPDynGroupprivateClauseModifier getDynGroupprivateModifier() const
Get the first modifier of the clause.
const_child_range children() const
const_child_range used_children() const
This represents clause 'exclusive' in the 'pragma omp scan' directive.
const_child_range children() const
friend class OMPClauseReader
child_range children()
static bool classof(const OMPClause *T)
child_range used_children()
const_child_range used_children() const
OMPFilterClause()
Build an empty clause.
friend class OMPClauseReader
Expr * getThreadID() const
Return thread identifier.
Expr * getThreadID()
Return thread identifier.
OMPFilterClause(Expr *ThreadID, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'filter' clause with thread-id ThreadID.
static OMPFlushClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with N variables.
static bool classof(const OMPClause *T)
child_range used_children()
const_child_range used_children() const
child_range children()
const_child_range children() const
static OMPFlushClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL)
Creates clause with a list of variables VL.
This represents clause 'from' in the 'pragma omp ...' directives.
const_child_range children() const
friend class OMPClauseReader
const_child_range used_children() const
child_range used_children()
ArrayRef< SourceLocation > getMotionModifiersLoc() const LLVM_READONLY
Fetches ArrayRef of location of motion-modifiers.
static bool classof(const OMPClause *T)
child_range children()
ArrayRef< OpenMPMotionModifierKind > getMotionModifiers() const LLVM_READONLY
Fetches ArrayRef of motion-modifiers.
SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY
Fetches the motion-modifier location at 'Cnt' index of array of modifiers' locations.
SourceLocation getColonLoc() const
Get colon location.
Expr * getIteratorModifier() const
OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY
Fetches the motion-modifier at 'Cnt' index of array of modifiers.
const_child_range children() const
OpenMPGrainsizeClauseModifier getModifier() const
Gets modifier.
friend class OMPClauseReader
OMPGrainsizeClause()
Build an empty clause.
SourceLocation getModifierLoc() const
Gets modifier location.
const_child_range used_children() const
Expr * getGrainsize() const
Return safe iteration space distance.
child_range used_children()
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
static bool classof(const OMPClause *T)
child_range children()
SourceLocation getLParenLoc() const
Returns the location of '('.
OMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build 'grainsize' clause.
This represents clause 'has_device_ptr' in the 'pragma omp ...' directives.
static bool classof(const OMPClause *T)
friend class OMPClauseReader
const_child_range used_children() const
const_child_range children() const
child_range used_children()
SourceLocation getLParenLoc() const
Returns the location of '('.
friend class OMPClauseReader
child_range used_children()
OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'hint' clause with expression Hint.
Expr * getHint() const
Returns number of threads.
const_child_range used_children() const
const_child_range children() const
static bool classof(const OMPClause *T)
child_range children()
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
OMPHintClause()
Build an empty clause.
This represents clause 'inclusive' in the 'pragma omp scan' directive.
const_child_range children() const
friend class OMPClauseReader
child_range children()
static bool classof(const OMPClause *T)
const_child_range used_children() const
child_range used_children()
bool getIsTarget() const
Returns true is interop-type 'target' is used.
friend class OMPClauseReader
ArrayRef< Expr * > attrs() const
All attr() exprs across every pref-spec, in pref-spec order (flat block).
static OMPInitClause * CreateEmpty(const ASTContext &C, unsigned NumPrefs, unsigned NumAttrs)
Creates an empty clause sized for NumPrefs pref-specs and NumAttrs total attr() exprs across them.
const_child_range children() const
bool hasPreferAttrs() const
Returns true if OMP 6.0 {fr/attr} syntax is used.
child_range children()
child_range used_children()
Expr * getInteropVar()
Returns the interop variable.
const_child_range used_children() const
static OMPInitClause * Create(const ASTContext &C, Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Creates a fully specified clause.
SourceLocation getVarLoc() const
Returns the location of the interop variable.
bool getIsTargetSync() const
Returns true is interop-type 'targetsync' is used.
const Expr * getInteropVar() const
static bool classof(const OMPClause *T)
auto prefs() const
Returns a range of PrefView objects, one per preference-specification, each carrying the fr() express...
This represents clause 'is_device_ptr' in the 'pragma omp ...' directives.
friend class OMPClauseReader
child_range children()
static bool classof(const OMPClause *T)
child_range used_children()
const_child_range children() const
const_child_range used_children() const
OpenMPMapClauseKind getMapType() const LLVM_READONLY
Fetches mapping kind for the clause.
child_range children()
friend class OMPClauseReader
const_child_range children() const
OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY
Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY
Fetches the map-type-modifier location at 'Cnt' index of array of modifiers' locations.
SourceLocation getMapLoc() const LLVM_READONLY
Fetches location of clause mapping kind.
child_range used_children()
ArrayRef< SourceLocation > getMapTypeModifiersLoc() const LLVM_READONLY
Fetches ArrayRef of location of map-type-modifiers.
static bool classof(const OMPClause *T)
SourceLocation getColonLoc() const
Get colon location.
ArrayRef< OpenMPMapModifierKind > getMapTypeModifiers() const LLVM_READONLY
Fetches ArrayRef of map-type-modifiers.
const_child_range used_children() const
bool isImplicitMapType() const LLVM_READONLY
Is this an implicit map type? We have to capture 'IsMapTypeImplicit' from the parser for more informa...
Expr * getIteratorModifier()
Fetches Expr * of iterator modifier.
Iterator that browse the components by lists. It also allows browsing components of a single declarat...
std::tuple< const ValueDecl *, MappableExprComponentListRef, const ValueDecl * > operator->() const
std::tuple< const ValueDecl *, MappableExprComponentListRef, const ValueDecl * > operator*() const
const_component_lists_iterator(const ValueDecl *Declaration, ArrayRef< ValueDecl * > UniqueDecls, ArrayRef< unsigned > DeclsListNum, ArrayRef< unsigned > CumulativeListSizes, MappableExprComponentListRef Components, bool SupportsMapper, ArrayRef< Expr * > Mappers)
Construct an iterator that scan lists for a given declaration Declaration.
const_component_lists_iterator(ArrayRef< ValueDecl * > UniqueDecls, ArrayRef< unsigned > DeclsListNum, ArrayRef< unsigned > CumulativeListSizes, MappableExprComponentListRef Components, bool SupportsMapper, ArrayRef< Expr * > Mappers)
Construct an iterator that scans all lists.
This represents clauses with a list of expressions that are mappable. Examples of these clauses are '...
MutableArrayRef< ValueDecl * > getUniqueDeclsRef()
Get the unique declarations that are in the trailing objects of the class.
const DeclarationNameInfo & getMapperIdInfo() const
Gets the name info for associated user-defined mapper.
const_all_lists_sizes_range all_lists_sizes() const
const_component_lists_range decl_component_lists(const ValueDecl *VD) const
llvm::iterator_range< const_all_components_iterator > const_all_components_range
unsigned getTotalComponentsNum() const
Return the total number of components in all lists derived from the clause.
void setComponents(ArrayRef< MappableComponent > Components, ArrayRef< unsigned > CLSs)
Set the components that are in the trailing objects of the class. This requires the list sizes so tha...
mapperlist_const_iterator mapperlist_end() const
const_component_lists_iterator component_lists_end() const
llvm::iterator_range< const_all_lists_sizes_iterator > const_all_lists_sizes_range
mapperlist_iterator mapperlist_begin()
ArrayRef< ValueDecl * > getUniqueDeclsRef() const
Get the unique declarations that are in the trailing objects of the class.
mapperlist_iterator mapperlist_end()
ArrayRef< ValueDecl * >::iterator const_all_decls_iterator
Iterators to access all the declarations, number of lists, list sizes, and components.
MutableArrayRef< Expr * >::iterator mapperlist_iterator
ArrayRef< unsigned > getComponentListSizesRef() const
Get the cumulative component lists sizes that are in the trailing objects of the class....
MutableArrayRef< unsigned > getDeclNumListsRef()
Get the number of lists per declaration that are in the trailing objects of the class.
ArrayRef< Expr * > getUDMapperRefs() const
Get the user-defined mappers references that are in the trailing objects of the class.
const_component_lists_range component_lists() const
void setDeclNumLists(ArrayRef< unsigned > DNLs)
Set the number of lists per declaration that are in the trailing objects of the class.
const_all_components_range all_components() const
ArrayRef< unsigned >::iterator const_all_num_lists_iterator
mapperlist_const_range mapperlists() const
OMPMappableExprListClause(OpenMPClauseKind K, const OMPVarListLocTy &Locs, const OMPMappableExprListSizeTy &Sizes, bool SupportsMapper=false, NestedNameSpecifierLoc *MapperQualifierLocPtr=nullptr, DeclarationNameInfo *MapperIdInfoPtr=nullptr)
Build a clause for NumUniqueDeclarations declarations, NumComponentLists total component lists,...
ArrayRef< const Expr * >::iterator mapperlist_const_iterator
mapperlist_const_iterator mapperlist_begin() const
void setMapperIdInfo(DeclarationNameInfo MapperId)
Set the name of associated user-defined mapper.
void setUDMapperRefs(ArrayRef< Expr * > DMDs)
Set the user-defined mappers that are in the trailing objects of the class.
void setComponentListSizes(ArrayRef< unsigned > CLSs)
Set the cumulative component lists sizes that are in the trailing objects of the class.
const_all_num_lists_range all_num_lists() const
ArrayRef< unsigned >::iterator const_all_lists_sizes_iterator
unsigned getTotalComponentListNum() const
Return the number of lists derived from the clause expressions.
void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL)
Set the nested name specifier of associated user-defined mapper.
MutableArrayRef< Expr * > getUDMapperRefs()
Get the user-defined mapper references that are in the trailing objects of the class.
unsigned getUniqueDeclarationsNum() const
Return the number of unique base declarations in this clause.
const_component_lists_iterator decl_component_lists_end() const
ArrayRef< unsigned > getDeclNumListsRef() const
Get the number of lists per declaration that are in the trailing objects of the class.
NestedNameSpecifierLoc getMapperQualifierLoc() const
Gets the nested name specifier for associated user-defined mapper.
llvm::iterator_range< const_all_num_lists_iterator > const_all_num_lists_range
mapperlist_range mapperlists()
MutableArrayRef< unsigned > getComponentListSizesRef()
Get the cumulative component lists sizes that are in the trailing objects of the class....
void setClauseInfo(ArrayRef< ValueDecl * > Declarations, MappableExprComponentListsRef ComponentLists)
Fill the clause information from the list of declarations and associated component lists.
MutableArrayRef< MappableComponent > getComponentsRef()
Get the components that are in the trailing objects of the class.
const_component_lists_iterator component_lists_begin() const
Iterators for all component lists.
llvm::iterator_range< const_component_lists_iterator > const_component_lists_range
llvm::iterator_range< mapperlist_const_iterator > mapperlist_const_range
const_component_lists_iterator decl_component_lists_begin(const ValueDecl *VD) const
Iterators for component lists associated with the provided declaration.
ArrayRef< MappableComponent > getComponentsRef() const
Get the components that are in the trailing objects of the class.
llvm::iterator_range< mapperlist_iterator > mapperlist_range
llvm::iterator_range< const_all_decls_iterator > const_all_decls_range
ArrayRef< MappableComponent >::iterator const_all_components_iterator
void setUniqueDecls(ArrayRef< ValueDecl * > UDs)
Set the unique declarations that are in the trailing objects of the class.
const_all_decls_range all_decls() const
friend class OMPClauseReader
OMPNocontextClause()
Build an empty clause.
const_child_range used_children() const
Expr * getCondition() const
Returns condition.
OMPNocontextClause(Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'nocontext' clause with condition Cond.
child_range used_children()
static bool classof(const OMPClause *T)
const_child_range children() const
child_range children()
const_child_range used_children() const
OMPNogroupClause()
Build an empty clause.
OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'nogroup' clause.
child_range used_children()
This represents clause 'nontemporal' in the 'pragma omp ...' directives.
friend class OMPClauseReader
child_range used_children()
static bool classof(const OMPClause *T)
const_child_range used_children() const
child_range children()
const_child_range children() const
const_child_range private_refs() const
child_range private_refs()
Expr * getCondition() const
Returns condition.
friend class OMPClauseReader
const_child_range used_children() const
child_range used_children()
OMPNovariantsClause()
Build an empty clause.
OMPNovariantsClause(Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'novariants' clause with condition Cond.
friend class OMPClauseReader
const_child_range children() const
SourceLocation getModifierLoc() const
Gets modifier location.
OMPNumTasksClause()
Build an empty clause.
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range used_children() const
OpenMPNumTasksClauseModifier getModifier() const
Gets modifier.
OMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *Size, Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build 'num_tasks' clause.
child_range children()
static bool classof(const OMPClause *T)
child_range used_children()
Expr * getNumTasks() const
Return safe iteration space distance.
This represents 'num_teams' clause in the 'pragma omp ...' directive.
child_range used_children()
friend class OMPClauseReader
const Expr * getDimsModifierExpr() const
Get the expression of the modifier if it is the dims modifier.
ArrayRef< Expr * > getNumTeams()
Return NumTeams expressions.
Expr * getModifierExpr()
Get the expression of the modifier.
static bool classof(const OMPClause *T)
const_child_range children() const
SourceLocation getModifierLoc() const
Get the location of the modifier.
OpenMPNumTeamsClauseModifier getModifier() const
Get the modifier.
const Expr * getModifierExpr() const
Get the expression of the modifier.
ArrayRef< Expr * > getNumTeams() const
Return NumTeams expressions.
child_range children()
const_child_range used_children() const
friend class OMPClauseReader
SourceLocation getLParenLoc() const
Returns the location of '('.
SourceLocation getModifierKwLoc() const
Returns location of clause modifier.
OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier, SourceLocation MLoc)
Build 'order' clause with argument A ('concurrent').
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
SourceLocation getKindKwLoc() const
Returns location of clause kind.
const_child_range used_children() const
static bool classof(const OMPClause *T)
OMPOrderClause()
Build an empty clause.
const_child_range children() const
child_range used_children()
child_range children()
OpenMPOrderClauseKind getKind() const
Returns kind of the clause.
OpenMPOrderClauseModifier getModifier() const
Returns Modifier of the clause.
friend class OMPClauseReader
child_range children()
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
Expr * getPriority() const
Return Priority number.
child_range used_children()
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range used_children() const
OMPPriorityClause(Expr *Priority, Stmt *HelperPriority, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'priority' clause.
OMPPriorityClause()
Build an empty clause.
static bool classof(const OMPClause *T)
const_child_range children() const
Expr * getPriority()
Return Priority number.
OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'simd' clause.
const_child_range used_children() const
const_child_range children() const
OMPSIMDClause()
Build an empty clause.
child_range used_children()
static bool classof(const OMPClause *T)
child_range children()
This represents 'thread_limit' clause in the 'pragma omp ...' directive.
const_child_range children() const
friend class OMPClauseReader
SourceLocation getModifierLoc() const
Get the location of the modifier.
Expr * getModifierExpr()
Get the expression of the modifier.
child_range used_children()
const_child_range used_children() const
ArrayRef< Expr * > getThreadLimit() const
Return ThreadLimit expressions.
const Expr * getDimsModifierExpr() const
Get the expression of the modifier if it is the dims modifier.
child_range children()
ArrayRef< Expr * > getThreadLimit()
Return ThreadLimit expressions.
const Expr * getModifierExpr() const
Get the expression of the modifier.
OpenMPThreadLimitClauseModifier getModifier() const
Get the modifier.
static bool classof(const OMPClause *T)
OMPThreadsClause()
Build an empty clause.
OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'threads' clause.
This represents clause 'to' in the 'pragma omp ...' directives.
ArrayRef< SourceLocation > getMotionModifiersLoc() const LLVM_READONLY
Fetches ArrayRef of location of motion-modifiers.
friend class OMPClauseReader
Expr * getIteratorModifier() const
SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY
Fetches the motion-modifier location at 'Cnt' index of array of modifiers' locations.
ArrayRef< OpenMPMotionModifierKind > getMotionModifiers() const LLVM_READONLY
Fetches ArrayRef of motion-modifiers.
static bool classof(const OMPClause *T)
child_range used_children()
OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY
Fetches the motion-modifier at 'Cnt' index of array of modifiers.
const_child_range used_children() const
const_child_range children() const
child_range children()
SourceLocation getColonLoc() const
Get colon location.
bool isExtensionActive(llvm::omp::TraitProperty TP)
Check the extension trait TP is active.
friend class ASTContext
llvm::SmallVector< OMPTraitSet, 2 > Sets
The outermost level of selector sets.
bool anyScoreOrCondition(llvm::function_ref< bool(Expr *&, bool)> Cond)
friend class OMPClauseReader
static bool classof(const OMPClause *T)
child_range used_children()
SourceLocation getVarLoc() const
Returns the location of the interop variable.
Expr * getInteropVar() const
Returns the interop variable.
OMPUseClause()
Build an empty clause.
const_child_range children() const
const_child_range used_children() const
OMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build 'use' clause with and interop variable expression InteropVar.
child_range children()
SourceLocation getLParenLoc() const
Returns the location of '('.
This represents clause 'use_device_addr' in the 'pragma omp ...' directives.
friend class OMPClauseReader
const_child_range used_children() const
child_range used_children()
static bool classof(const OMPClause *T)
const_child_range children() const
This represents clause 'use_device_ptr' in the 'pragma omp ...' directives.
SourceLocation getFallbackModifierLoc() const
Get the location of the fallback modifier.
friend class OMPClauseReader
ArrayRef< const Expr * >::iterator inits_const_iterator
static bool classof(const OMPClause *T)
MutableArrayRef< Expr * >::iterator private_copies_iterator
llvm::iterator_range< private_copies_iterator > private_copies_range
llvm::iterator_range< inits_iterator > inits_range
const_child_range used_children() const
child_range used_children()
OpenMPUseDevicePtrFallbackModifier getFallbackModifier() const
Get the fallback modifier for the clause.
const_child_range children() const
private_copies_const_range private_copies() const
private_copies_range private_copies()
MutableArrayRef< Expr * >::iterator inits_iterator
ArrayRef< const Expr * >::iterator private_copies_const_iterator
llvm::iterator_range< inits_const_iterator > inits_const_range
inits_const_range inits() const
llvm::iterator_range< private_copies_const_iterator > private_copies_const_range
const_child_range used_children() const
child_range used_children()
const_child_range children() const
SourceLocation getLParenLoc() const
Returns the location of '('.
static bool classof(const OMPClause *T)
unsigned getNumberOfAllocators() const
Returns number of allocators associated with the clause.
ArrayRef< const Attr * > getAttrs() const
Returned the attributes parsed from this clause.
friend class OMPClauseReader
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
OMPXAttributeClause()
Build an empty clause.
SourceLocation getLParenLoc() const
Returns the location of '('.
OMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'ompx_attribute' clause.
OMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'ompx_bare' clause.
OMPXBareClause()=default
Build an empty clause.
Expr * getSize()
Return the size expression.
Expr * getSize() const
Return the size expression.
OMPXDynCGroupMemClause(Expr *Size, Stmt *HelperSize, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'ompx_dyn_cgroup_mem' clause.
OMPXDynCGroupMemClause()
Build an empty clause.
a trap message and trap category.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
This represents one expression.
Definition Expr.h:114
ArrayRef< OMPAdjustArgsItem > items() const
OpenMPNeedDevicePtrModifier NeedDevicePtrModifier
OpenMPAdjustArgsOpKind AdjustOp
friend class OMPClauseReader
OMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'align' clause with the given alignment.
Expr * getAlignment() const
Returns alignment.
OMPAlignClause()
Build an empty clause.
This represents clause 'allocate' in the 'pragma omp ...' directives.
const_child_range children() const
SourceLocation getAllocatorModifierLoc() const
Return the location of the modifier.
const_child_range used_children() const
OpenMPAllocateClauseModifier getAllocatorModifier() const
Return 'allocate' modifier.
OpenMPAllocateClauseModifier getSecondAllocateModifier() const
Get the second modifier of the clause.
SourceLocation getColonLoc() const
Returns the location of the ':' delimiter.
Expr * getAlignment() const
Returns the alignment expression or nullptr, if no alignment specified.
OpenMPAllocateClauseModifier getFirstAllocateModifier() const
Get the first modifier of the clause.
Expr * getAllocator() const
Returns the allocator expression or nullptr, if no allocator is specified.
SourceLocation getSecondAllocateModifierLoc() const
Get location of second modifier of the clause.
child_range used_children()
SourceLocation getFirstAllocateModifierLoc() const
Get location of first modifier of the clause.
static OMPAllocateClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N variables.
static bool classof(const OMPClause *T)
OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'allocator' clause with the given allocator.
OMPAllocatorClause()
Build an empty clause.
Expr * getAllocator() const
Returns allocator.
Class that handles post-update expression for some clauses, like 'lastprivate', 'reduction' etc.
void setPostUpdateExpr(Expr *S)
Set pre-initialization statement for the clause.
static OMPClauseWithPostUpdate * get(OMPClause *C)
Expr * getPostUpdateExpr()
Get post-update expression for the clause.
OMPClauseWithPostUpdate(const OMPClause *This)
const Expr * getPostUpdateExpr() const
Get post-update expression for the clause.
Class that handles pre-initialization statement for some clauses, like 'schedule',...
const Stmt * getPreInitStmt() const
Get pre-initialization statement for the clause.
OMPClauseWithPreInit(const OMPClause *This)
OpenMPDirectiveKind getCaptureRegion() const
Get capture region for the stmt in the clause.
Stmt * getPreInitStmt()
Get pre-initialization statement for the clause.
static OMPClauseWithPreInit * get(OMPClause *C)
void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion=llvm::omp::OMPD_unknown)
Set pre-initialization statement for the clause.
This is a basic class for representing single OpenMP clause.
const_child_range children() const
void setLocStart(SourceLocation Loc)
Sets the starting location of the clause.
static bool classof(const OMPClause *)
SourceLocation getBeginLoc() const
Returns the starting location of the clause.
llvm::iterator_range< const_child_iterator > const_child_range
ConstStmtIterator const_child_iterator
child_range used_children()
Get the iterator range for the expressions used in the clauses.
llvm::iterator_range< child_iterator > child_range
OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
void setLocEnd(SourceLocation Loc)
Sets the ending location of the clause.
bool isImplicit() const
StmtIterator child_iterator
SourceLocation getEndLoc() const
Returns the ending location of the clause.
child_range children()
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
const_child_range used_children() const
OMPCollapseClause()
Build an empty clause.
Expr * getNumForLoops() const
Return the number of associated for-loops.
OMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'collapse' clause.
static bool classof(const OMPClause *T)
std::optional< unsigned > getOmpFillIndex() const
friend class OMPClauseReader
child_range used_children()
SourceLocation getOmpFillLoc() const
ArrayRef< Expr * > getCountsRefs() const
const_child_range used_children() const
const_child_range children() const
unsigned getNumCounts() const
Returns the number of list items.
static OMPCountsClause * CreateEmpty(const ASTContext &C, unsigned NumCounts)
Build an empty 'counts' AST node for deserialization.
SourceLocation getLParenLoc() const
Returns the location of '('.
MutableArrayRef< Expr * > getCountsRefs()
Returns the count expressions.
const_child_range used_children() const
OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc, OpenMPDefaultClauseVariableCategory VC, SourceLocation VCLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'default' clause with argument A ('none' or 'shared').
SourceLocation getLParenLoc() const
Returns the location of '('.
llvm::omp::DefaultKind getDefaultKind() const
Returns kind of the clause.
SourceLocation getDefaultKindKwLoc() const
Returns location of clause kind.
OpenMPDefaultClauseVariableCategory getDefaultVC() const
static bool classof(const OMPClause *T)
child_range used_children()
const_child_range children() const
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
OMPDefaultClause()
Build an empty clause.
SourceLocation getDefaultVCLoc() const
friend class OMPClauseReader
const_child_range children() const
Expr * getDepth() const
Returns the depth expression or nullptr if not set.
const_child_range used_children() const
OMPDepthClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, Expr *Depth)
Build an AST node for a 'depth' clause.
static bool classof(const OMPClause *T)
child_range used_children()
SourceLocation getLParenLoc() const
Returns the location of '('.
Class that represents a list of directive kinds (parallel, target, etc.) as used in absent,...
MutableArrayRef< OpenMPDirectiveKind > getDirectiveKinds()
void setDirectiveKinds(ArrayRef< OpenMPDirectiveKind > DK)
const_child_range children() const
unsigned NumKinds
Number of directive kinds listed in the clause.
void setLParenLoc(SourceLocation S)
const_child_range used_children() const
OMPDirectiveListClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, unsigned NumKinds)
Build a clause with NumKinds directive kinds.
This represents 'final' clause in the 'pragma omp ...' directive.
child_range used_children()
friend class OMPClauseReader
Expr * getCondition() const
Returns condition.
OMPFinalClause(Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'final' clause with condition Cond.
OMPFinalClause()
Build an empty clause.
OMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build an AST node for a 'full' clause.
OMPFullClause()
Build an empty clause.
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
friend class OMPClauseReader
const_child_range used_children() const
SourceLocation getLParenLoc() const
Returns the location of '('.
SourceLocation getColonLoc() const
Return the location of ':'.
static bool classof(const OMPClause *T)
child_range used_children()
Expr * getCondition() const
Returns condition.
OpenMPDirectiveKind getNameModifier() const
Return directive name modifier associated with the clause.
OMPIfClause()
Build an empty clause.
child_range children()
const_child_range children() const
OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond, OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build 'if' clause with condition Cond.
SourceLocation getNameModifierLoc() const
Return the location of directive name modifier.
OMPLoopRangeClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation FirstLoc, SourceLocation CountLoc, SourceLocation EndLoc, Expr *First, Expr *Count)
Build a 'looprange' clause.
Expr * getFirst() const
Get looprange 'first' expression.
const_child_range used_children() const
OMPLoopRangeClause()
Build an empty clause for deserialization.
void setFirstLoc(SourceLocation Loc)
void setCountLoc(SourceLocation Loc)
SourceLocation getFirstLoc() const
SourceLocation getLParenLoc() const
static bool classof(const OMPClause *T)
SourceLocation getCountLoc() const
const_child_range children() const
Expr * getCount() const
Get looprange 'count' expression.
void setLParenLoc(SourceLocation Loc)
SourceLocation getPrescriptivenessModifierLoc() const
Returns the location of the prescriptiveness modifier.
Expr * getDimsModifierExpr()
Returns the dims modifier expression if present.
bool hasDimsModifier() const
Checks if the clause has the dims modifier.
const_child_range used_children() const
const Expr * getDimsModifierExpr() const
Returns the dims modifier expression if present.
OpenMPNumThreadsClauseModifier getDimsModifier() const
Returns the dims modifier.
OpenMPNumThreadsClauseModifier getPrescriptivenessModifier() const
Returns the prescriptiveness modifier.
const_child_range children() const
static bool classof(const OMPClause *T)
ArrayRef< Expr * > getNumThreads()
Return NumThreads expressions.
static OMPNumThreadsClause * CreateEmpty(const ASTContext &C, unsigned N)
Creates an empty clause with the place for N expressions.
SourceLocation getDimsModifierLoc() const
Returns the location of the dims modifier.
ArrayRef< Expr * > getNumThreads() const
const_child_range used_children() const
child_range used_children()
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
OMPOneStmtClause(Stmt *S, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static bool classof(const OMPClause *T)
ConstStmtIterator const_child_iterator
const_child_range children() const
StmtIterator child_iterator
llvm::iterator_range< child_iterator > child_range
SourceLocation getLParenLoc() const
Returns the location of '('.
llvm::iterator_range< const_child_iterator > const_child_range
T * getStmtAs() const
Return the associated statement, potentially casted to T.
child_range used_children()
const_child_range used_children() const
OMPPartialClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, Expr *Factor)
Build an AST node for a 'partial' clause.
SourceLocation getLParenLoc() const
Returns the location of '('.
const_child_range children() const
static bool classof(const OMPClause *T)
OMPPartialClause()
Build an empty clause.
Expr * getFactor() const
Returns the argument of the clause or nullptr if not set.
This class represents the 'permutation' clause in the 'pragma omp interchange' directive.
static bool classof(const OMPClause *T)
ArrayRef< Expr * > getArgsRefs() const
unsigned getNumLoops() const
Returns the number of list items.
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
SourceLocation getLParenLoc() const
Returns the location of '('.
MutableArrayRef< Expr * > getArgsRefs()
Returns the permutation index expressions.
static OMPPermutationClause * CreateEmpty(const ASTContext &C, unsigned NumLoops)
Build an empty 'permutation' AST node for deserialization.
const_child_range used_children() const
const_child_range children() const
OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'safelen' clause.
Expr * getSafelen() const
Return safe iteration space distance.
OMPSafelenClause()
Build an empty clause.
OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'simdlen' clause.
Expr * getSimdlen() const
Return safe iteration space distance.
OMPSimdlenClause()
Build an empty clause.
This represents the 'sizes' clause in the 'pragma omp tile' directive.
SourceLocation getLParenLoc() const
Returns the location of '('.
friend class OMPClauseReader
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
static bool classof(const OMPClause *T)
const_child_range used_children() const
void setSizesRefs(ArrayRef< Expr * > VL)
Sets the tile size expressions.
unsigned getNumSizes() const
Returns the number of list items.
child_range used_children()
MutableArrayRef< Expr * > getSizesRefs()
Returns the tile size expressions.
ArrayRef< Expr * > getSizesRefs() const
const_child_range children() const
static OMPSizesClause * CreateEmpty(const ASTContext &C, unsigned NumSizes)
Build an empty 'sizes' AST node for deserialization.
static bool classof(const OMPClause *T)
OpenMPThreadsetKind getThreadsetKind() const
Returns kind of the clause.
const_child_range children() const
OMPThreadsetClause(OpenMPThreadsetKind A, SourceLocation ALoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build 'threadset' clause with argument A ('omp_team' or 'omp_pool').
const_child_range used_children() const
SourceLocation getThreadsetKindLoc() const
Returns location of clause kind.
SourceLocation getLParenLoc() const
Returns the location of '('.
OMPThreadsetClause()
Build an empty clause.
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
This represents clauses with the list of variables like 'private', 'firstprivate',...
varlist_const_range varlist() const
friend class OMPClauseReader
void setLParenLoc(SourceLocation Loc)
Sets the location of '('.
ArrayRef< const Expr * > getVarRefs() const
Fetches list of all variables in the clause.
OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
Build a clause with N variables.
MutableArrayRef< Expr * > getVarRefs()
Fetches list of variables associated with this clause.
varlist_range varlist()
varlist_const_iterator varlist_end() const
varlist_iterator varlist_end()
llvm::iterator_range< varlist_const_iterator > varlist_const_range
MutableArrayRef< Expr * >::iterator varlist_iterator
varlist_iterator varlist_begin()
ArrayRef< const Expr * >::iterator varlist_const_iterator
SourceLocation getLParenLoc() const
Returns the location of '('.
unsigned varlist_size() const
varlist_const_iterator varlist_begin() const
llvm::iterator_range< varlist_iterator > varlist_range
void setVarRefs(ArrayRef< Expr * > VL)
Sets the list of variables for this clause.
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:85
Definition SPIR.cpp:35
Top level wrappers for InstallAPI frontend operations.
static OMPLinearClause * CreateEmpty(const ASTContext &C, unsigned NumVars)
Creates an empty clause with the place for NumVars variables.
OpenMPOriginalSharingModifier
OpenMP 6.0 original sharing modifiers.
ArrayRef< const Expr * >::iterator used_expressions_const_iterator
bool checkFailClauseParameter(OpenMPClauseKind FailClauseParameter)
Checks if the parameter to the fail clause in "#pragma atomic compare fail" is restricted only to mem...
MutableArrayRef< Expr * > getFinals()
Sets the list of final update expressions for linear variables.
llvm::iterator_range< inits_iterator > inits_range
privates_range privates()
OpenMPDefaultClauseVariableCategory
OpenMP variable-category for 'default' clause.
MutableArrayRef< Expr * >::iterator privates_iterator
static bool classof(const OMPClause *T)
llvm::iterator_range< finals_const_iterator > finals_const_range
MutableArrayRef< Expr * > getPrivates()
Finals[]; Step; CalcStep; }.
OpenMPNeedDevicePtrModifier
OpenMP 6.1 need_device modifier.
void setFinals(ArrayRef< Expr * > FL)
Sets the list of final update expressions for linear variables.
void setColonLoc(SourceLocation Loc)
Sets the location of ':'.
MutableArrayRef< Expr * >::iterator inits_iterator
OpenMPAdjustArgsOpKind
OpenMP adjust-op kinds for 'adjust_args' clause.
OpenMPLinearClauseKind getModifier() const
Return modifier.
llvm::iterator_range< privates_const_iterator > privates_const_range
void setUsedExprs(ArrayRef< Expr * > UE)
Sets the list of used expressions for the linear clause.
OpenMPAtClauseKind
OpenMP attributes for 'at' clause.
@ OMPC_AT_unknown
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
@ OMPC_REDUCTION_unknown
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition OpenMPKinds.h:39
@ OMPC_SCHEDULE_MODIFIER_unknown
Definition OpenMPKinds.h:40
llvm::iterator_range< inits_const_iterator > inits_const_range
llvm::iterator_range< updates_iterator > updates_range
llvm::iterator_range< used_expressions_iterator > used_expressions_range
MutableArrayRef< Expr * >::iterator updates_iterator
SourceLocation getStepModifierLoc() const
Returns the location of 'step' modifier.
const FunctionProtoType * T
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
OpenMPDependClauseKind
OpenMP attributes for 'depend' clause.
Definition OpenMPKinds.h:55
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > PL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
Expr * getStep()
Returns linear step.
ArrayRef< const Expr * >::iterator updates_const_iterator
child_range used_children()
llvm::iterator_range< privates_iterator > privates_range
void setUpdates(ArrayRef< Expr * > UL)
Sets the list of update expressions for linear variables.
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
@ OMPC_SEVERITY_unknown
void setPrivates(ArrayRef< Expr * > PL)
Sets the list of the copies of original linear variables.
MutableArrayRef< Expr * > getUsedExprs()
Gets the list of used expressions for linear variables.
MutableArrayRef< Expr * >::iterator used_expressions_iterator
void setInits(ArrayRef< Expr * > IL)
Sets the list of the initial values for linear variables.
OpenMPAllocateClauseModifier
OpenMP modifiers for 'allocate' clause.
@ OMPC_ALLOCATE_unknown
inits_range inits()
void setModifierLoc(SourceLocation Loc)
Set modifier location.
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition OpenMPKinds.h:63
void setStepModifierLoc(SourceLocation Loc)
Sets the location of 'step' modifier.
SourceLocation getColonLoc() const
Returns the location of ':'.
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition OpenMPKinds.h:25
MutableArrayRef< Expr * > getUpdates()
Sets the list of update expressions for linear variables.
updates_range updates()
void setModifier(OpenMPLinearClauseKind Kind)
Set modifier.
SourceLocation getModifierLoc() const
Return modifier location.
finals_range finals()
llvm::iterator_range< used_expressions_const_iterator > used_expressions_const_range
MutableArrayRef< Expr * > getInits()
OpenMPNumThreadsClauseModifier
@ OMPC_NUMTHREADS_unknown
ArrayRef< const Expr * >::iterator privates_const_iterator
OpenMPAtomicDefaultMemOrderClauseKind
OpenMP attributes for 'atomic_default_mem_order' clause.
@ OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown
child_range children()
ArrayRef< const Expr * >::iterator finals_const_iterator
MutableArrayRef< Expr * >::iterator finals_iterator
ArrayRef< const Expr * >::iterator inits_const_iterator
used_expressions_range used_expressions()
Expr * getCalcStep()
Returns expression to calculate linear step.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
OpenMPMapModifierKind
OpenMP modifier kind for 'map' clause.
Definition OpenMPKinds.h:79
@ OMPC_MAP_MODIFIER_unknown
Definition OpenMPKinds.h:80
llvm::omp::Clause OpenMPClauseKind
OpenMP clauses.
Definition OpenMPKinds.h:28
llvm::iterator_range< updates_const_iterator > updates_const_range
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition OpenMPKinds.h:31
@ OMPC_SCHEDULE_unknown
Definition OpenMPKinds.h:35
llvm::iterator_range< finals_iterator > finals_range
OpenMPThreadsetKind
OpenMP modifiers for 'threadset' clause.
@ OMPC_THREADSET_unknown
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition OpenMPKinds.h:71
@ OMPC_MAP_unknown
Definition OpenMPKinds.h:75
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
int const char * function
Definition c++config.h:31
__builtin_bitreverse32 uint32_t __builtin_riscv_aaddu_u32 __builtin_riscv_asubu_u32 __builtin_elementwise_add_sat __builtin_elementwise_sub_sat int32_t uint32_t uint32_t __builtin_riscv_mhacc_i32 __builtin_riscv_mhaccu_u32 __builtin_riscv_mhaccsu_i32 __builtin_riscv_mulq_i32 __builtin_riscv_mqwacc_i64 uint8_t
#define true
Definition stdbool.h:25
OpenMPDependClauseKind DepKind
Dependency type (one of in, out, inout).
SourceLocation DepLoc
Dependency type location.
SourceLocation ColonLoc
Colon location.
SourceLocation OmpAllMemoryLoc
Location of 'omp_all_memory'.
ArrayRef< Expr * > Attrs
attr() string-literal expressions. Empty for fr-only or OMP 5.1 flat specs.
Expr * Fr
Foreign-runtime-id expression. Null for attr-only specs.
This structure contains all sizes needed for by an OMPMappableExprListClause.
OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations, unsigned NumComponentLists, unsigned NumComponents)
OMPMappableExprListSizeTy()=default
unsigned NumComponents
Total number of expression components.
unsigned NumUniqueDeclarations
Number of unique base declarations.
unsigned NumVars
Number of expressions listed.
unsigned NumComponentLists
Number of component lists.
llvm::omp::TraitProperty Kind
StringRef RawString
The raw string as we parsed it. This is needed for the isa trait set (which accepts anything) and (la...
llvm::omp::TraitSelector Kind
SmallVector< OMPTraitProperty, 1 > Properties
SmallVector< OMPTraitSelector, 2 > Selectors
llvm::omp::TraitSet Kind
Data for list of allocators.
Expr * AllocatorTraits
Allocator traits.
SourceLocation LParenLoc
Locations of '(' and ')' symbols.
TargetOMPContext(ASTContext &ASTCtx, std::function< void(StringRef)> &&DiagUnknownTrait, const FunctionDecl *CurrentFunctionDecl, ArrayRef< llvm::omp::TraitProperty > ConstructTraits, int DeviceNum)
bool matchesISATrait(StringRef RawString) const override
See llvm::omp::OMPContext::matchesISATrait.
virtual ~TargetOMPContext()=default
One bound of a parameter range.
Expr * E
The bound expression, or the logical offset for a NumArgs bound.
One item in an OpenMP 'adjust_args' parameter list.
Expr * E
A named parameter or positional expression for a Single item.
const_child_range used_children() const
static bool classof(const OMPClause *T)
OMPNoChildClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build 'ClauseKind' clause.
child_range used_children()
OMPNoChildClause()
Build an empty clause.
const_child_range children() const
SourceLocation StartLoc
Starting location of the clause (the clause keyword).
SourceLocation LParenLoc
Location of '('.
SourceLocation EndLoc
Ending location of the clause.
OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)