Home | History | Annotate | Line # | Download | only in AST
      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"
     21 #include "clang/AST/DeclarationName.h"
     22 #include "clang/AST/Expr.h"
     23 #include "clang/AST/NestedNameSpecifier.h"
     24 #include "clang/AST/Stmt.h"
     25 #include "clang/AST/StmtIterator.h"
     26 #include "clang/Basic/LLVM.h"
     27 #include "clang/Basic/OpenMPKinds.h"
     28 #include "clang/Basic/SourceLocation.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/OMPConstants.h"
     36 #include "llvm/Frontend/OpenMP/OMPContext.h"
     37 #include "llvm/Support/Casting.h"
     38 #include "llvm/Support/Compiler.h"
     39 #include "llvm/Support/TrailingObjects.h"
     40 #include <cassert>
     41 #include <cstddef>
     42 #include <iterator>
     43 #include <utility>
     44 
     45 namespace clang {
     46 
     47 class ASTContext;
     48 
     49 //===----------------------------------------------------------------------===//
     50 // AST classes for clauses.
     51 //===----------------------------------------------------------------------===//
     52 
     53 /// This is a basic class for representing single OpenMP clause.
     54 class OMPClause {
     55   /// Starting location of the clause (the clause keyword).
     56   SourceLocation StartLoc;
     57 
     58   /// Ending location of the clause.
     59   SourceLocation EndLoc;
     60 
     61   /// Kind of the clause.
     62   OpenMPClauseKind Kind;
     63 
     64 protected:
     65   OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
     66       : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
     67 
     68 public:
     69   /// Returns the starting location of the clause.
     70   SourceLocation getBeginLoc() const { return StartLoc; }
     71 
     72   /// Returns the ending location of the clause.
     73   SourceLocation getEndLoc() const { return EndLoc; }
     74 
     75   /// Sets the starting location of the clause.
     76   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
     77 
     78   /// Sets the ending location of the clause.
     79   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
     80 
     81   /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
     82   OpenMPClauseKind getClauseKind() const { return Kind; }
     83 
     84   bool isImplicit() const { return StartLoc.isInvalid(); }
     85 
     86   using child_iterator = StmtIterator;
     87   using const_child_iterator = ConstStmtIterator;
     88   using child_range = llvm::iterator_range<child_iterator>;
     89   using const_child_range = llvm::iterator_range<const_child_iterator>;
     90 
     91   child_range children();
     92   const_child_range children() const {
     93     auto Children = const_cast<OMPClause *>(this)->children();
     94     return const_child_range(Children.begin(), Children.end());
     95   }
     96 
     97   /// Get the iterator range for the expressions used in the clauses. Used
     98   /// expressions include only the children that must be evaluated at the
     99   /// runtime before entering the construct.
    100   child_range used_children();
    101   const_child_range used_children() const {
    102     auto Children = const_cast<OMPClause *>(this)->children();
    103     return const_child_range(Children.begin(), Children.end());
    104   }
    105 
    106   static bool classof(const OMPClause *) { return true; }
    107 };
    108 
    109 /// Class that handles pre-initialization statement for some clauses, like
    110 /// 'shedule', 'firstprivate' etc.
    111 class OMPClauseWithPreInit {
    112   friend class OMPClauseReader;
    113 
    114   /// Pre-initialization statement for the clause.
    115   Stmt *PreInit = nullptr;
    116 
    117   /// Region that captures the associated stmt.
    118   OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
    119 
    120 protected:
    121   OMPClauseWithPreInit(const OMPClause *This) {
    122     assert(get(This) && "get is not tuned for pre-init.");
    123   }
    124 
    125   /// Set pre-initialization statement for the clause.
    126   void
    127   setPreInitStmt(Stmt *S,
    128                  OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
    129     PreInit = S;
    130     CaptureRegion = ThisRegion;
    131   }
    132 
    133 public:
    134   /// Get pre-initialization statement for the clause.
    135   const Stmt *getPreInitStmt() const { return PreInit; }
    136 
    137   /// Get pre-initialization statement for the clause.
    138   Stmt *getPreInitStmt() { return PreInit; }
    139 
    140   /// Get capture region for the stmt in the clause.
    141   OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
    142 
    143   static OMPClauseWithPreInit *get(OMPClause *C);
    144   static const OMPClauseWithPreInit *get(const OMPClause *C);
    145 };
    146 
    147 /// Class that handles post-update expression for some clauses, like
    148 /// 'lastprivate', 'reduction' etc.
    149 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
    150   friend class OMPClauseReader;
    151 
    152   /// Post-update expression for the clause.
    153   Expr *PostUpdate = nullptr;
    154 
    155 protected:
    156   OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
    157     assert(get(This) && "get is not tuned for post-update.");
    158   }
    159 
    160   /// Set pre-initialization statement for the clause.
    161   void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
    162 
    163 public:
    164   /// Get post-update expression for the clause.
    165   const Expr *getPostUpdateExpr() const { return PostUpdate; }
    166 
    167   /// Get post-update expression for the clause.
    168   Expr *getPostUpdateExpr() { return PostUpdate; }
    169 
    170   static OMPClauseWithPostUpdate *get(OMPClause *C);
    171   static const OMPClauseWithPostUpdate *get(const OMPClause *C);
    172 };
    173 
    174 /// This structure contains most locations needed for by an OMPVarListClause.
    175 struct OMPVarListLocTy {
    176   /// Starting location of the clause (the clause keyword).
    177   SourceLocation StartLoc;
    178   /// Location of '('.
    179   SourceLocation LParenLoc;
    180   /// Ending location of the clause.
    181   SourceLocation EndLoc;
    182   OMPVarListLocTy() = default;
    183   OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc,
    184                   SourceLocation EndLoc)
    185       : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {}
    186 };
    187 
    188 /// This represents clauses with the list of variables like 'private',
    189 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
    190 /// '#pragma omp ...' directives.
    191 template <class T> class OMPVarListClause : public OMPClause {
    192   friend class OMPClauseReader;
    193 
    194   /// Location of '('.
    195   SourceLocation LParenLoc;
    196 
    197   /// Number of variables in the list.
    198   unsigned NumVars;
    199 
    200 protected:
    201   /// Build a clause with \a N variables
    202   ///
    203   /// \param K Kind of the clause.
    204   /// \param StartLoc Starting location of the clause (the clause keyword).
    205   /// \param LParenLoc Location of '('.
    206   /// \param EndLoc Ending location of the clause.
    207   /// \param N Number of the variables in the clause.
    208   OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
    209                    SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
    210       : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
    211 
    212   /// Fetches list of variables associated with this clause.
    213   MutableArrayRef<Expr *> getVarRefs() {
    214     return MutableArrayRef<Expr *>(
    215         static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
    216   }
    217 
    218   /// Sets the list of variables for this clause.
    219   void setVarRefs(ArrayRef<Expr *> VL) {
    220     assert(VL.size() == NumVars &&
    221            "Number of variables is not the same as the preallocated buffer");
    222     std::copy(VL.begin(), VL.end(),
    223               static_cast<T *>(this)->template getTrailingObjects<Expr *>());
    224   }
    225 
    226 public:
    227   using varlist_iterator = MutableArrayRef<Expr *>::iterator;
    228   using varlist_const_iterator = ArrayRef<const Expr *>::iterator;
    229   using varlist_range = llvm::iterator_range<varlist_iterator>;
    230   using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
    231 
    232   unsigned varlist_size() const { return NumVars; }
    233   bool varlist_empty() const { return NumVars == 0; }
    234 
    235   varlist_range varlists() {
    236     return varlist_range(varlist_begin(), varlist_end());
    237   }
    238   varlist_const_range varlists() const {
    239     return varlist_const_range(varlist_begin(), varlist_end());
    240   }
    241 
    242   varlist_iterator varlist_begin() { return getVarRefs().begin(); }
    243   varlist_iterator varlist_end() { return getVarRefs().end(); }
    244   varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
    245   varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
    246 
    247   /// Sets the location of '('.
    248   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    249 
    250   /// Returns the location of '('.
    251   SourceLocation getLParenLoc() const { return LParenLoc; }
    252 
    253   /// Fetches list of all variables in the clause.
    254   ArrayRef<const Expr *> getVarRefs() const {
    255     return llvm::makeArrayRef(
    256         static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
    257         NumVars);
    258   }
    259 };
    260 
    261 /// This represents 'allocator' clause in the '#pragma omp ...'
    262 /// directive.
    263 ///
    264 /// \code
    265 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
    266 /// \endcode
    267 /// In this example directive '#pragma omp allocate' has simple 'allocator'
    268 /// clause with the allocator 'omp_default_mem_alloc'.
    269 class OMPAllocatorClause : public OMPClause {
    270   friend class OMPClauseReader;
    271 
    272   /// Location of '('.
    273   SourceLocation LParenLoc;
    274 
    275   /// Expression with the allocator.
    276   Stmt *Allocator = nullptr;
    277 
    278   /// Set allocator.
    279   void setAllocator(Expr *A) { Allocator = A; }
    280 
    281 public:
    282   /// Build 'allocator' clause with the given allocator.
    283   ///
    284   /// \param A Allocator.
    285   /// \param StartLoc Starting location of the clause.
    286   /// \param LParenLoc Location of '('.
    287   /// \param EndLoc Ending location of the clause.
    288   OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
    289                      SourceLocation EndLoc)
    290       : OMPClause(llvm::omp::OMPC_allocator, StartLoc, EndLoc),
    291         LParenLoc(LParenLoc), Allocator(A) {}
    292 
    293   /// Build an empty clause.
    294   OMPAllocatorClause()
    295       : OMPClause(llvm::omp::OMPC_allocator, SourceLocation(),
    296                   SourceLocation()) {}
    297 
    298   /// Sets the location of '('.
    299   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    300 
    301   /// Returns the location of '('.
    302   SourceLocation getLParenLoc() const { return LParenLoc; }
    303 
    304   /// Returns allocator.
    305   Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); }
    306 
    307   child_range children() { return child_range(&Allocator, &Allocator + 1); }
    308 
    309   const_child_range children() const {
    310     return const_child_range(&Allocator, &Allocator + 1);
    311   }
    312 
    313   child_range used_children() {
    314     return child_range(child_iterator(), child_iterator());
    315   }
    316   const_child_range used_children() const {
    317     return const_child_range(const_child_iterator(), const_child_iterator());
    318   }
    319 
    320   static bool classof(const OMPClause *T) {
    321     return T->getClauseKind() == llvm::omp::OMPC_allocator;
    322   }
    323 };
    324 
    325 /// This represents clause 'allocate' in the '#pragma omp ...' directives.
    326 ///
    327 /// \code
    328 /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
    329 /// \endcode
    330 /// In this example directive '#pragma omp parallel' has clause 'private'
    331 /// and clause 'allocate' for the variable 'a'.
    332 class OMPAllocateClause final
    333     : public OMPVarListClause<OMPAllocateClause>,
    334       private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
    335   friend class OMPClauseReader;
    336   friend OMPVarListClause;
    337   friend TrailingObjects;
    338 
    339   /// Allocator specified in the clause, or 'nullptr' if the default one is
    340   /// used.
    341   Expr *Allocator = nullptr;
    342   /// Position of the ':' delimiter in the clause;
    343   SourceLocation ColonLoc;
    344 
    345   /// Build clause with number of variables \a N.
    346   ///
    347   /// \param StartLoc Starting location of the clause.
    348   /// \param LParenLoc Location of '('.
    349   /// \param Allocator Allocator expression.
    350   /// \param ColonLoc Location of ':' delimiter.
    351   /// \param EndLoc Ending location of the clause.
    352   /// \param N Number of the variables in the clause.
    353   OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
    354                     Expr *Allocator, SourceLocation ColonLoc,
    355                     SourceLocation EndLoc, unsigned N)
    356       : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
    357                                             LParenLoc, EndLoc, N),
    358         Allocator(Allocator), ColonLoc(ColonLoc) {}
    359 
    360   /// Build an empty clause.
    361   ///
    362   /// \param N Number of variables.
    363   explicit OMPAllocateClause(unsigned N)
    364       : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
    365                                             SourceLocation(), SourceLocation(),
    366                                             SourceLocation(), N) {}
    367 
    368   /// Sets location of ':' symbol in clause.
    369   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
    370 
    371   void setAllocator(Expr *A) { Allocator = A; }
    372 
    373 public:
    374   /// Creates clause with a list of variables \a VL.
    375   ///
    376   /// \param C AST context.
    377   /// \param StartLoc Starting location of the clause.
    378   /// \param LParenLoc Location of '('.
    379   /// \param Allocator Allocator expression.
    380   /// \param ColonLoc Location of ':' delimiter.
    381   /// \param EndLoc Ending location of the clause.
    382   /// \param VL List of references to the variables.
    383   static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
    384                                    SourceLocation LParenLoc, Expr *Allocator,
    385                                    SourceLocation ColonLoc,
    386                                    SourceLocation EndLoc, ArrayRef<Expr *> VL);
    387 
    388   /// Returns the allocator expression or nullptr, if no allocator is specified.
    389   Expr *getAllocator() const { return Allocator; }
    390 
    391   /// Returns the location of the ':' delimiter.
    392   SourceLocation getColonLoc() const { return ColonLoc; }
    393 
    394   /// Creates an empty clause with the place for \a N variables.
    395   ///
    396   /// \param C AST context.
    397   /// \param N The number of variables.
    398   static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
    399 
    400   child_range children() {
    401     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
    402                        reinterpret_cast<Stmt **>(varlist_end()));
    403   }
    404 
    405   const_child_range children() const {
    406     auto Children = const_cast<OMPAllocateClause *>(this)->children();
    407     return const_child_range(Children.begin(), Children.end());
    408   }
    409 
    410   child_range used_children() {
    411     return child_range(child_iterator(), child_iterator());
    412   }
    413   const_child_range used_children() const {
    414     return const_child_range(const_child_iterator(), const_child_iterator());
    415   }
    416 
    417   static bool classof(const OMPClause *T) {
    418     return T->getClauseKind() == llvm::omp::OMPC_allocate;
    419   }
    420 };
    421 
    422 /// This represents 'if' clause in the '#pragma omp ...' directive.
    423 ///
    424 /// \code
    425 /// #pragma omp parallel if(parallel:a > 5)
    426 /// \endcode
    427 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
    428 /// condition 'a > 5' and directive name modifier 'parallel'.
    429 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
    430   friend class OMPClauseReader;
    431 
    432   /// Location of '('.
    433   SourceLocation LParenLoc;
    434 
    435   /// Condition of the 'if' clause.
    436   Stmt *Condition = nullptr;
    437 
    438   /// Location of ':' (if any).
    439   SourceLocation ColonLoc;
    440 
    441   /// Directive name modifier for the clause.
    442   OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
    443 
    444   /// Name modifier location.
    445   SourceLocation NameModifierLoc;
    446 
    447   /// Set condition.
    448   void setCondition(Expr *Cond) { Condition = Cond; }
    449 
    450   /// Set directive name modifier for the clause.
    451   void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
    452 
    453   /// Set location of directive name modifier for the clause.
    454   void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
    455 
    456   /// Set location of ':'.
    457   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
    458 
    459 public:
    460   /// Build 'if' clause with condition \a Cond.
    461   ///
    462   /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
    463   /// \param Cond Condition of the clause.
    464   /// \param HelperCond Helper condition for the clause.
    465   /// \param CaptureRegion Innermost OpenMP region where expressions in this
    466   /// clause must be captured.
    467   /// \param StartLoc Starting location of the clause.
    468   /// \param LParenLoc Location of '('.
    469   /// \param NameModifierLoc Location of directive name modifier.
    470   /// \param ColonLoc [OpenMP 4.1] Location of ':'.
    471   /// \param EndLoc Ending location of the clause.
    472   OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
    473               OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
    474               SourceLocation LParenLoc, SourceLocation NameModifierLoc,
    475               SourceLocation ColonLoc, SourceLocation EndLoc)
    476       : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
    477         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
    478         ColonLoc(ColonLoc), NameModifier(NameModifier),
    479         NameModifierLoc(NameModifierLoc) {
    480     setPreInitStmt(HelperCond, CaptureRegion);
    481   }
    482 
    483   /// Build an empty clause.
    484   OMPIfClause()
    485       : OMPClause(llvm::omp::OMPC_if, SourceLocation(), SourceLocation()),
    486         OMPClauseWithPreInit(this) {}
    487 
    488   /// Sets the location of '('.
    489   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    490 
    491   /// Returns the location of '('.
    492   SourceLocation getLParenLoc() const { return LParenLoc; }
    493 
    494   /// Return the location of ':'.
    495   SourceLocation getColonLoc() const { return ColonLoc; }
    496 
    497   /// Returns condition.
    498   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
    499 
    500   /// Return directive name modifier associated with the clause.
    501   OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
    502 
    503   /// Return the location of directive name modifier.
    504   SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
    505 
    506   child_range children() { return child_range(&Condition, &Condition + 1); }
    507 
    508   const_child_range children() const {
    509     return const_child_range(&Condition, &Condition + 1);
    510   }
    511 
    512   child_range used_children();
    513   const_child_range used_children() const {
    514     auto Children = const_cast<OMPIfClause *>(this)->used_children();
    515     return const_child_range(Children.begin(), Children.end());
    516   }
    517 
    518   static bool classof(const OMPClause *T) {
    519     return T->getClauseKind() == llvm::omp::OMPC_if;
    520   }
    521 };
    522 
    523 /// This represents 'final' clause in the '#pragma omp ...' directive.
    524 ///
    525 /// \code
    526 /// #pragma omp task final(a > 5)
    527 /// \endcode
    528 /// In this example directive '#pragma omp task' has simple 'final'
    529 /// clause with condition 'a > 5'.
    530 class OMPFinalClause : public OMPClause, public OMPClauseWithPreInit {
    531   friend class OMPClauseReader;
    532 
    533   /// Location of '('.
    534   SourceLocation LParenLoc;
    535 
    536   /// Condition of the 'if' clause.
    537   Stmt *Condition = nullptr;
    538 
    539   /// Set condition.
    540   void setCondition(Expr *Cond) { Condition = Cond; }
    541 
    542 public:
    543   /// Build 'final' clause with condition \a Cond.
    544   ///
    545   /// \param Cond Condition of the clause.
    546   /// \param HelperCond Helper condition for the construct.
    547   /// \param CaptureRegion Innermost OpenMP region where expressions in this
    548   /// clause must be captured.
    549   /// \param StartLoc Starting location of the clause.
    550   /// \param LParenLoc Location of '('.
    551   /// \param EndLoc Ending location of the clause.
    552   OMPFinalClause(Expr *Cond, Stmt *HelperCond,
    553                  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
    554                  SourceLocation LParenLoc, SourceLocation EndLoc)
    555       : OMPClause(llvm::omp::OMPC_final, StartLoc, EndLoc),
    556         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
    557     setPreInitStmt(HelperCond, CaptureRegion);
    558   }
    559 
    560   /// Build an empty clause.
    561   OMPFinalClause()
    562       : OMPClause(llvm::omp::OMPC_final, SourceLocation(), SourceLocation()),
    563         OMPClauseWithPreInit(this) {}
    564 
    565   /// Sets the location of '('.
    566   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    567 
    568   /// Returns the location of '('.
    569   SourceLocation getLParenLoc() const { return LParenLoc; }
    570 
    571   /// Returns condition.
    572   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
    573 
    574   child_range children() { return child_range(&Condition, &Condition + 1); }
    575 
    576   const_child_range children() const {
    577     return const_child_range(&Condition, &Condition + 1);
    578   }
    579 
    580   child_range used_children();
    581   const_child_range used_children() const {
    582     auto Children = const_cast<OMPFinalClause *>(this)->used_children();
    583     return const_child_range(Children.begin(), Children.end());
    584   }
    585 
    586   static bool classof(const OMPClause *T) {
    587     return T->getClauseKind() == llvm::omp::OMPC_final;
    588   }
    589 };
    590 
    591 /// This represents 'num_threads' clause in the '#pragma omp ...'
    592 /// directive.
    593 ///
    594 /// \code
    595 /// #pragma omp parallel num_threads(6)
    596 /// \endcode
    597 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
    598 /// clause with number of threads '6'.
    599 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
    600   friend class OMPClauseReader;
    601 
    602   /// Location of '('.
    603   SourceLocation LParenLoc;
    604 
    605   /// Condition of the 'num_threads' clause.
    606   Stmt *NumThreads = nullptr;
    607 
    608   /// Set condition.
    609   void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
    610 
    611 public:
    612   /// Build 'num_threads' clause with condition \a NumThreads.
    613   ///
    614   /// \param NumThreads Number of threads for the construct.
    615   /// \param HelperNumThreads Helper Number of threads for the construct.
    616   /// \param CaptureRegion Innermost OpenMP region where expressions in this
    617   /// clause must be captured.
    618   /// \param StartLoc Starting location of the clause.
    619   /// \param LParenLoc Location of '('.
    620   /// \param EndLoc Ending location of the clause.
    621   OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
    622                       OpenMPDirectiveKind CaptureRegion,
    623                       SourceLocation StartLoc, SourceLocation LParenLoc,
    624                       SourceLocation EndLoc)
    625       : OMPClause(llvm::omp::OMPC_num_threads, StartLoc, EndLoc),
    626         OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
    627         NumThreads(NumThreads) {
    628     setPreInitStmt(HelperNumThreads, CaptureRegion);
    629   }
    630 
    631   /// Build an empty clause.
    632   OMPNumThreadsClause()
    633       : OMPClause(llvm::omp::OMPC_num_threads, SourceLocation(),
    634                   SourceLocation()),
    635         OMPClauseWithPreInit(this) {}
    636 
    637   /// Sets the location of '('.
    638   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    639 
    640   /// Returns the location of '('.
    641   SourceLocation getLParenLoc() const { return LParenLoc; }
    642 
    643   /// Returns number of threads.
    644   Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
    645 
    646   child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
    647 
    648   const_child_range children() const {
    649     return const_child_range(&NumThreads, &NumThreads + 1);
    650   }
    651 
    652   child_range used_children() {
    653     return child_range(child_iterator(), child_iterator());
    654   }
    655   const_child_range used_children() const {
    656     return const_child_range(const_child_iterator(), const_child_iterator());
    657   }
    658 
    659   static bool classof(const OMPClause *T) {
    660     return T->getClauseKind() == llvm::omp::OMPC_num_threads;
    661   }
    662 };
    663 
    664 /// This represents 'safelen' clause in the '#pragma omp ...'
    665 /// directive.
    666 ///
    667 /// \code
    668 /// #pragma omp simd safelen(4)
    669 /// \endcode
    670 /// In this example directive '#pragma omp simd' has clause 'safelen'
    671 /// with single expression '4'.
    672 /// If the safelen clause is used then no two iterations executed
    673 /// concurrently with SIMD instructions can have a greater distance
    674 /// in the logical iteration space than its value. The parameter of
    675 /// the safelen clause must be a constant positive integer expression.
    676 class OMPSafelenClause : public OMPClause {
    677   friend class OMPClauseReader;
    678 
    679   /// Location of '('.
    680   SourceLocation LParenLoc;
    681 
    682   /// Safe iteration space distance.
    683   Stmt *Safelen = nullptr;
    684 
    685   /// Set safelen.
    686   void setSafelen(Expr *Len) { Safelen = Len; }
    687 
    688 public:
    689   /// Build 'safelen' clause.
    690   ///
    691   /// \param Len Expression associated with this clause.
    692   /// \param StartLoc Starting location of the clause.
    693   /// \param EndLoc Ending location of the clause.
    694   OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
    695                    SourceLocation EndLoc)
    696       : OMPClause(llvm::omp::OMPC_safelen, StartLoc, EndLoc),
    697         LParenLoc(LParenLoc), Safelen(Len) {}
    698 
    699   /// Build an empty clause.
    700   explicit OMPSafelenClause()
    701       : OMPClause(llvm::omp::OMPC_safelen, SourceLocation(), SourceLocation()) {
    702   }
    703 
    704   /// Sets the location of '('.
    705   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    706 
    707   /// Returns the location of '('.
    708   SourceLocation getLParenLoc() const { return LParenLoc; }
    709 
    710   /// Return safe iteration space distance.
    711   Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
    712 
    713   child_range children() { return child_range(&Safelen, &Safelen + 1); }
    714 
    715   const_child_range children() const {
    716     return const_child_range(&Safelen, &Safelen + 1);
    717   }
    718 
    719   child_range used_children() {
    720     return child_range(child_iterator(), child_iterator());
    721   }
    722   const_child_range used_children() const {
    723     return const_child_range(const_child_iterator(), const_child_iterator());
    724   }
    725 
    726   static bool classof(const OMPClause *T) {
    727     return T->getClauseKind() == llvm::omp::OMPC_safelen;
    728   }
    729 };
    730 
    731 /// This represents 'simdlen' clause in the '#pragma omp ...'
    732 /// directive.
    733 ///
    734 /// \code
    735 /// #pragma omp simd simdlen(4)
    736 /// \endcode
    737 /// In this example directive '#pragma omp simd' has clause 'simdlen'
    738 /// with single expression '4'.
    739 /// If the 'simdlen' clause is used then it specifies the preferred number of
    740 /// iterations to be executed concurrently. The parameter of the 'simdlen'
    741 /// clause must be a constant positive integer expression.
    742 class OMPSimdlenClause : public OMPClause {
    743   friend class OMPClauseReader;
    744 
    745   /// Location of '('.
    746   SourceLocation LParenLoc;
    747 
    748   /// Safe iteration space distance.
    749   Stmt *Simdlen = nullptr;
    750 
    751   /// Set simdlen.
    752   void setSimdlen(Expr *Len) { Simdlen = Len; }
    753 
    754 public:
    755   /// Build 'simdlen' clause.
    756   ///
    757   /// \param Len Expression associated with this clause.
    758   /// \param StartLoc Starting location of the clause.
    759   /// \param EndLoc Ending location of the clause.
    760   OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
    761                    SourceLocation EndLoc)
    762       : OMPClause(llvm::omp::OMPC_simdlen, StartLoc, EndLoc),
    763         LParenLoc(LParenLoc), Simdlen(Len) {}
    764 
    765   /// Build an empty clause.
    766   explicit OMPSimdlenClause()
    767       : OMPClause(llvm::omp::OMPC_simdlen, SourceLocation(), SourceLocation()) {
    768   }
    769 
    770   /// Sets the location of '('.
    771   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    772 
    773   /// Returns the location of '('.
    774   SourceLocation getLParenLoc() const { return LParenLoc; }
    775 
    776   /// Return safe iteration space distance.
    777   Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
    778 
    779   child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
    780 
    781   const_child_range children() const {
    782     return const_child_range(&Simdlen, &Simdlen + 1);
    783   }
    784 
    785   child_range used_children() {
    786     return child_range(child_iterator(), child_iterator());
    787   }
    788   const_child_range used_children() const {
    789     return const_child_range(const_child_iterator(), const_child_iterator());
    790   }
    791 
    792   static bool classof(const OMPClause *T) {
    793     return T->getClauseKind() == llvm::omp::OMPC_simdlen;
    794   }
    795 };
    796 
    797 /// This represents the 'sizes' clause in the '#pragma omp tile' directive.
    798 ///
    799 /// \code
    800 /// #pragma omp tile sizes(5,5)
    801 /// for (int i = 0; i < 64; ++i)
    802 ///   for (int j = 0; j < 64; ++j)
    803 /// \endcode
    804 class OMPSizesClause final
    805     : public OMPClause,
    806       private llvm::TrailingObjects<OMPSizesClause, Expr *> {
    807   friend class OMPClauseReader;
    808   friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
    809 
    810   /// Location of '('.
    811   SourceLocation LParenLoc;
    812 
    813   /// Number of tile sizes in the clause.
    814   unsigned NumSizes;
    815 
    816   /// Build an empty clause.
    817   explicit OMPSizesClause(int NumSizes)
    818       : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()),
    819         NumSizes(NumSizes) {}
    820 
    821 public:
    822   /// Build a 'sizes' AST node.
    823   ///
    824   /// \param C         Context of the AST.
    825   /// \param StartLoc  Location of the 'sizes' identifier.
    826   /// \param LParenLoc Location of '('.
    827   /// \param EndLoc    Location of ')'.
    828   /// \param Sizes     Content of the clause.
    829   static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc,
    830                                 SourceLocation LParenLoc, SourceLocation EndLoc,
    831                                 ArrayRef<Expr *> Sizes);
    832 
    833   /// Build an empty 'sizes' AST node for deserialization.
    834   ///
    835   /// \param C     Context of the AST.
    836   /// \param NumSizes Number of items in the clause.
    837   static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes);
    838 
    839   /// Sets the location of '('.
    840   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    841 
    842   /// Returns the location of '('.
    843   SourceLocation getLParenLoc() const { return LParenLoc; }
    844 
    845   /// Returns the number of list items.
    846   unsigned getNumSizes() const { return NumSizes; }
    847 
    848   /// Returns the tile size expressions.
    849   MutableArrayRef<Expr *> getSizesRefs() {
    850     return MutableArrayRef<Expr *>(static_cast<OMPSizesClause *>(this)
    851                                        ->template getTrailingObjects<Expr *>(),
    852                                    NumSizes);
    853   }
    854   ArrayRef<Expr *> getSizesRefs() const {
    855     return ArrayRef<Expr *>(static_cast<const OMPSizesClause *>(this)
    856                                 ->template getTrailingObjects<Expr *>(),
    857                             NumSizes);
    858   }
    859 
    860   /// Sets the tile size expressions.
    861   void setSizesRefs(ArrayRef<Expr *> VL) {
    862     assert(VL.size() == NumSizes);
    863     std::copy(VL.begin(), VL.end(),
    864               static_cast<OMPSizesClause *>(this)
    865                   ->template getTrailingObjects<Expr *>());
    866   }
    867 
    868   child_range children() {
    869     MutableArrayRef<Expr *> Sizes = getSizesRefs();
    870     return child_range(reinterpret_cast<Stmt **>(Sizes.begin()),
    871                        reinterpret_cast<Stmt **>(Sizes.end()));
    872   }
    873   const_child_range children() const {
    874     ArrayRef<Expr *> Sizes = getSizesRefs();
    875     return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()),
    876                              reinterpret_cast<Stmt *const *>(Sizes.end()));
    877   }
    878 
    879   child_range used_children() {
    880     return child_range(child_iterator(), child_iterator());
    881   }
    882   const_child_range used_children() const {
    883     return const_child_range(const_child_iterator(), const_child_iterator());
    884   }
    885 
    886   static bool classof(const OMPClause *T) {
    887     return T->getClauseKind() == llvm::omp::OMPC_sizes;
    888   }
    889 };
    890 
    891 /// This represents 'collapse' clause in the '#pragma omp ...'
    892 /// directive.
    893 ///
    894 /// \code
    895 /// #pragma omp simd collapse(3)
    896 /// \endcode
    897 /// In this example directive '#pragma omp simd' has clause 'collapse'
    898 /// with single expression '3'.
    899 /// The parameter must be a constant positive integer expression, it specifies
    900 /// the number of nested loops that should be collapsed into a single iteration
    901 /// space.
    902 class OMPCollapseClause : public OMPClause {
    903   friend class OMPClauseReader;
    904 
    905   /// Location of '('.
    906   SourceLocation LParenLoc;
    907 
    908   /// Number of for-loops.
    909   Stmt *NumForLoops = nullptr;
    910 
    911   /// Set the number of associated for-loops.
    912   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
    913 
    914 public:
    915   /// Build 'collapse' clause.
    916   ///
    917   /// \param Num Expression associated with this clause.
    918   /// \param StartLoc Starting location of the clause.
    919   /// \param LParenLoc Location of '('.
    920   /// \param EndLoc Ending location of the clause.
    921   OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
    922                     SourceLocation LParenLoc, SourceLocation EndLoc)
    923       : OMPClause(llvm::omp::OMPC_collapse, StartLoc, EndLoc),
    924         LParenLoc(LParenLoc), NumForLoops(Num) {}
    925 
    926   /// Build an empty clause.
    927   explicit OMPCollapseClause()
    928       : OMPClause(llvm::omp::OMPC_collapse, SourceLocation(),
    929                   SourceLocation()) {}
    930 
    931   /// Sets the location of '('.
    932   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    933 
    934   /// Returns the location of '('.
    935   SourceLocation getLParenLoc() const { return LParenLoc; }
    936 
    937   /// Return the number of associated for-loops.
    938   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
    939 
    940   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
    941 
    942   const_child_range children() const {
    943     return const_child_range(&NumForLoops, &NumForLoops + 1);
    944   }
    945 
    946   child_range used_children() {
    947     return child_range(child_iterator(), child_iterator());
    948   }
    949   const_child_range used_children() const {
    950     return const_child_range(const_child_iterator(), const_child_iterator());
    951   }
    952 
    953   static bool classof(const OMPClause *T) {
    954     return T->getClauseKind() == llvm::omp::OMPC_collapse;
    955   }
    956 };
    957 
    958 /// This represents 'default' clause in the '#pragma omp ...' directive.
    959 ///
    960 /// \code
    961 /// #pragma omp parallel default(shared)
    962 /// \endcode
    963 /// In this example directive '#pragma omp parallel' has simple 'default'
    964 /// clause with kind 'shared'.
    965 class OMPDefaultClause : public OMPClause {
    966   friend class OMPClauseReader;
    967 
    968   /// Location of '('.
    969   SourceLocation LParenLoc;
    970 
    971   /// A kind of the 'default' clause.
    972   llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
    973 
    974   /// Start location of the kind in source code.
    975   SourceLocation KindKwLoc;
    976 
    977   /// Set kind of the clauses.
    978   ///
    979   /// \param K Argument of clause.
    980   void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
    981 
    982   /// Set argument location.
    983   ///
    984   /// \param KLoc Argument location.
    985   void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
    986 
    987 public:
    988   /// Build 'default' clause with argument \a A ('none' or 'shared').
    989   ///
    990   /// \param A Argument of the clause ('none' or 'shared').
    991   /// \param ALoc Starting location of the argument.
    992   /// \param StartLoc Starting location of the clause.
    993   /// \param LParenLoc Location of '('.
    994   /// \param EndLoc Ending location of the clause.
    995   OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
    996                    SourceLocation StartLoc, SourceLocation LParenLoc,
    997                    SourceLocation EndLoc)
    998       : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
    999         LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
   1000 
   1001   /// Build an empty clause.
   1002   OMPDefaultClause()
   1003       : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
   1004   }
   1005 
   1006   /// Sets the location of '('.
   1007   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   1008 
   1009   /// Returns the location of '('.
   1010   SourceLocation getLParenLoc() const { return LParenLoc; }
   1011 
   1012   /// Returns kind of the clause.
   1013   llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
   1014 
   1015   /// Returns location of clause kind.
   1016   SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
   1017 
   1018   child_range children() {
   1019     return child_range(child_iterator(), child_iterator());
   1020   }
   1021 
   1022   const_child_range children() const {
   1023     return const_child_range(const_child_iterator(), const_child_iterator());
   1024   }
   1025 
   1026   child_range used_children() {
   1027     return child_range(child_iterator(), child_iterator());
   1028   }
   1029   const_child_range used_children() const {
   1030     return const_child_range(const_child_iterator(), const_child_iterator());
   1031   }
   1032 
   1033   static bool classof(const OMPClause *T) {
   1034     return T->getClauseKind() == llvm::omp::OMPC_default;
   1035   }
   1036 };
   1037 
   1038 /// This represents 'proc_bind' clause in the '#pragma omp ...'
   1039 /// directive.
   1040 ///
   1041 /// \code
   1042 /// #pragma omp parallel proc_bind(master)
   1043 /// \endcode
   1044 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
   1045 /// clause with kind 'master'.
   1046 class OMPProcBindClause : public OMPClause {
   1047   friend class OMPClauseReader;
   1048 
   1049   /// Location of '('.
   1050   SourceLocation LParenLoc;
   1051 
   1052   /// A kind of the 'proc_bind' clause.
   1053   llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
   1054 
   1055   /// Start location of the kind in source code.
   1056   SourceLocation KindKwLoc;
   1057 
   1058   /// Set kind of the clause.
   1059   ///
   1060   /// \param K Kind of clause.
   1061   void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
   1062 
   1063   /// Set clause kind location.
   1064   ///
   1065   /// \param KLoc Kind location.
   1066   void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
   1067 
   1068 public:
   1069   /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
   1070   ///        'spread').
   1071   ///
   1072   /// \param A Argument of the clause ('master', 'close' or 'spread').
   1073   /// \param ALoc Starting location of the argument.
   1074   /// \param StartLoc Starting location of the clause.
   1075   /// \param LParenLoc Location of '('.
   1076   /// \param EndLoc Ending location of the clause.
   1077   OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
   1078                     SourceLocation StartLoc, SourceLocation LParenLoc,
   1079                     SourceLocation EndLoc)
   1080       : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
   1081         LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
   1082 
   1083   /// Build an empty clause.
   1084   OMPProcBindClause()
   1085       : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
   1086                   SourceLocation()) {}
   1087 
   1088   /// Sets the location of '('.
   1089   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   1090 
   1091   /// Returns the location of '('.
   1092   SourceLocation getLParenLoc() const { return LParenLoc; }
   1093 
   1094   /// Returns kind of the clause.
   1095   llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
   1096 
   1097   /// Returns location of clause kind.
   1098   SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
   1099 
   1100   child_range children() {
   1101     return child_range(child_iterator(), child_iterator());
   1102   }
   1103 
   1104   const_child_range children() const {
   1105     return const_child_range(const_child_iterator(), const_child_iterator());
   1106   }
   1107 
   1108   child_range used_children() {
   1109     return child_range(child_iterator(), child_iterator());
   1110   }
   1111   const_child_range used_children() const {
   1112     return const_child_range(const_child_iterator(), const_child_iterator());
   1113   }
   1114 
   1115   static bool classof(const OMPClause *T) {
   1116     return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
   1117   }
   1118 };
   1119 
   1120 /// This represents 'unified_address' clause in the '#pragma omp requires'
   1121 /// directive.
   1122 ///
   1123 /// \code
   1124 /// #pragma omp requires unified_address
   1125 /// \endcode
   1126 /// In this example directive '#pragma omp requires' has 'unified_address'
   1127 /// clause.
   1128 class OMPUnifiedAddressClause final : public OMPClause {
   1129 public:
   1130   friend class OMPClauseReader;
   1131   /// Build 'unified_address' clause.
   1132   ///
   1133   /// \param StartLoc Starting location of the clause.
   1134   /// \param EndLoc Ending location of the clause.
   1135   OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1136       : OMPClause(llvm::omp::OMPC_unified_address, StartLoc, EndLoc) {}
   1137 
   1138   /// Build an empty clause.
   1139   OMPUnifiedAddressClause()
   1140       : OMPClause(llvm::omp::OMPC_unified_address, SourceLocation(),
   1141                   SourceLocation()) {}
   1142 
   1143   child_range children() {
   1144     return child_range(child_iterator(), child_iterator());
   1145   }
   1146 
   1147   const_child_range children() const {
   1148     return const_child_range(const_child_iterator(), const_child_iterator());
   1149   }
   1150 
   1151   child_range used_children() {
   1152     return child_range(child_iterator(), child_iterator());
   1153   }
   1154   const_child_range used_children() const {
   1155     return const_child_range(const_child_iterator(), const_child_iterator());
   1156   }
   1157 
   1158   static bool classof(const OMPClause *T) {
   1159     return T->getClauseKind() == llvm::omp::OMPC_unified_address;
   1160   }
   1161 };
   1162 
   1163 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
   1164 /// directive.
   1165 ///
   1166 /// \code
   1167 /// #pragma omp requires unified_shared_memory
   1168 /// \endcode
   1169 /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
   1170 /// clause.
   1171 class OMPUnifiedSharedMemoryClause final : public OMPClause {
   1172 public:
   1173   friend class OMPClauseReader;
   1174   /// Build 'unified_shared_memory' clause.
   1175   ///
   1176   /// \param StartLoc Starting location of the clause.
   1177   /// \param EndLoc Ending location of the clause.
   1178   OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1179       : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
   1180 
   1181   /// Build an empty clause.
   1182   OMPUnifiedSharedMemoryClause()
   1183       : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
   1184                   SourceLocation()) {}
   1185 
   1186   child_range children() {
   1187     return child_range(child_iterator(), child_iterator());
   1188   }
   1189 
   1190   const_child_range children() const {
   1191     return const_child_range(const_child_iterator(), const_child_iterator());
   1192   }
   1193 
   1194   child_range used_children() {
   1195     return child_range(child_iterator(), child_iterator());
   1196   }
   1197   const_child_range used_children() const {
   1198     return const_child_range(const_child_iterator(), const_child_iterator());
   1199   }
   1200 
   1201   static bool classof(const OMPClause *T) {
   1202     return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
   1203   }
   1204 };
   1205 
   1206 /// This represents 'reverse_offload' clause in the '#pragma omp requires'
   1207 /// directive.
   1208 ///
   1209 /// \code
   1210 /// #pragma omp requires reverse_offload
   1211 /// \endcode
   1212 /// In this example directive '#pragma omp requires' has 'reverse_offload'
   1213 /// clause.
   1214 class OMPReverseOffloadClause final : public OMPClause {
   1215 public:
   1216   friend class OMPClauseReader;
   1217   /// Build 'reverse_offload' clause.
   1218   ///
   1219   /// \param StartLoc Starting location of the clause.
   1220   /// \param EndLoc Ending location of the clause.
   1221   OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1222       : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
   1223 
   1224   /// Build an empty clause.
   1225   OMPReverseOffloadClause()
   1226       : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
   1227                   SourceLocation()) {}
   1228 
   1229   child_range children() {
   1230     return child_range(child_iterator(), child_iterator());
   1231   }
   1232 
   1233   const_child_range children() const {
   1234     return const_child_range(const_child_iterator(), const_child_iterator());
   1235   }
   1236 
   1237   child_range used_children() {
   1238     return child_range(child_iterator(), child_iterator());
   1239   }
   1240   const_child_range used_children() const {
   1241     return const_child_range(const_child_iterator(), const_child_iterator());
   1242   }
   1243 
   1244   static bool classof(const OMPClause *T) {
   1245     return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
   1246   }
   1247 };
   1248 
   1249 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
   1250 /// directive.
   1251 ///
   1252 /// \code
   1253 /// #pragma omp requires dynamic_allocators
   1254 /// \endcode
   1255 /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
   1256 /// clause.
   1257 class OMPDynamicAllocatorsClause final : public OMPClause {
   1258 public:
   1259   friend class OMPClauseReader;
   1260   /// Build 'dynamic_allocators' clause.
   1261   ///
   1262   /// \param StartLoc Starting location of the clause.
   1263   /// \param EndLoc Ending location of the clause.
   1264   OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1265       : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
   1266 
   1267   /// Build an empty clause.
   1268   OMPDynamicAllocatorsClause()
   1269       : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
   1270                   SourceLocation()) {}
   1271 
   1272   child_range children() {
   1273     return child_range(child_iterator(), child_iterator());
   1274   }
   1275 
   1276   const_child_range children() const {
   1277     return const_child_range(const_child_iterator(), const_child_iterator());
   1278   }
   1279 
   1280   child_range used_children() {
   1281     return child_range(child_iterator(), child_iterator());
   1282   }
   1283   const_child_range used_children() const {
   1284     return const_child_range(const_child_iterator(), const_child_iterator());
   1285   }
   1286 
   1287   static bool classof(const OMPClause *T) {
   1288     return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
   1289   }
   1290 };
   1291 
   1292 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
   1293 /// requires'  directive.
   1294 ///
   1295 /// \code
   1296 /// #pragma omp requires atomic_default_mem_order(seq_cst)
   1297 /// \endcode
   1298 /// In this example directive '#pragma omp requires' has simple
   1299 /// atomic_default_mem_order' clause with kind 'seq_cst'.
   1300 class OMPAtomicDefaultMemOrderClause final : public OMPClause {
   1301   friend class OMPClauseReader;
   1302 
   1303   /// Location of '('
   1304   SourceLocation LParenLoc;
   1305 
   1306   /// A kind of the 'atomic_default_mem_order' clause.
   1307   OpenMPAtomicDefaultMemOrderClauseKind Kind =
   1308       OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown;
   1309 
   1310   /// Start location of the kind in source code.
   1311   SourceLocation KindKwLoc;
   1312 
   1313   /// Set kind of the clause.
   1314   ///
   1315   /// \param K Kind of clause.
   1316   void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
   1317     Kind = K;
   1318   }
   1319 
   1320   /// Set clause kind location.
   1321   ///
   1322   /// \param KLoc Kind location.
   1323   void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
   1324     KindKwLoc = KLoc;
   1325   }
   1326 
   1327 public:
   1328   /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
   1329   /// 'acq_rel' or 'relaxed').
   1330   ///
   1331   /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
   1332   /// \param ALoc Starting location of the argument.
   1333   /// \param StartLoc Starting location of the clause.
   1334   /// \param LParenLoc Location of '('.
   1335   /// \param EndLoc Ending location of the clause.
   1336   OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
   1337                                  SourceLocation ALoc, SourceLocation StartLoc,
   1338                                  SourceLocation LParenLoc,
   1339                                  SourceLocation EndLoc)
   1340       : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
   1341         LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
   1342 
   1343   /// Build an empty clause.
   1344   OMPAtomicDefaultMemOrderClause()
   1345       : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
   1346                   SourceLocation()) {}
   1347 
   1348   /// Sets the location of '('.
   1349   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   1350 
   1351   /// Returns the locaiton of '('.
   1352   SourceLocation getLParenLoc() const { return LParenLoc; }
   1353 
   1354   /// Returns kind of the clause.
   1355   OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
   1356     return Kind;
   1357   }
   1358 
   1359   /// Returns location of clause kind.
   1360   SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
   1361 
   1362   child_range children() {
   1363     return child_range(child_iterator(), child_iterator());
   1364   }
   1365 
   1366   const_child_range children() const {
   1367     return const_child_range(const_child_iterator(), const_child_iterator());
   1368   }
   1369 
   1370   child_range used_children() {
   1371     return child_range(child_iterator(), child_iterator());
   1372   }
   1373   const_child_range used_children() const {
   1374     return const_child_range(const_child_iterator(), const_child_iterator());
   1375   }
   1376 
   1377   static bool classof(const OMPClause *T) {
   1378     return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
   1379   }
   1380 };
   1381 
   1382 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
   1383 ///
   1384 /// \code
   1385 /// #pragma omp for schedule(static, 3)
   1386 /// \endcode
   1387 /// In this example directive '#pragma omp for' has 'schedule' clause with
   1388 /// arguments 'static' and '3'.
   1389 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
   1390   friend class OMPClauseReader;
   1391 
   1392   /// Location of '('.
   1393   SourceLocation LParenLoc;
   1394 
   1395   /// A kind of the 'schedule' clause.
   1396   OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
   1397 
   1398   /// Modifiers for 'schedule' clause.
   1399   enum {FIRST, SECOND, NUM_MODIFIERS};
   1400   OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
   1401 
   1402   /// Locations of modifiers.
   1403   SourceLocation ModifiersLoc[NUM_MODIFIERS];
   1404 
   1405   /// Start location of the schedule ind in source code.
   1406   SourceLocation KindLoc;
   1407 
   1408   /// Location of ',' (if any).
   1409   SourceLocation CommaLoc;
   1410 
   1411   /// Chunk size.
   1412   Expr *ChunkSize = nullptr;
   1413 
   1414   /// Set schedule kind.
   1415   ///
   1416   /// \param K Schedule kind.
   1417   void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
   1418 
   1419   /// Set the first schedule modifier.
   1420   ///
   1421   /// \param M Schedule modifier.
   1422   void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
   1423     Modifiers[FIRST] = M;
   1424   }
   1425 
   1426   /// Set the second schedule modifier.
   1427   ///
   1428   /// \param M Schedule modifier.
   1429   void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
   1430     Modifiers[SECOND] = M;
   1431   }
   1432 
   1433   /// Set location of the first schedule modifier.
   1434   void setFirstScheduleModifierLoc(SourceLocation Loc) {
   1435     ModifiersLoc[FIRST] = Loc;
   1436   }
   1437 
   1438   /// Set location of the second schedule modifier.
   1439   void setSecondScheduleModifierLoc(SourceLocation Loc) {
   1440     ModifiersLoc[SECOND] = Loc;
   1441   }
   1442 
   1443   /// Set schedule modifier location.
   1444   ///
   1445   /// \param M Schedule modifier location.
   1446   void setScheduleModifer(OpenMPScheduleClauseModifier M) {
   1447     if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
   1448       Modifiers[FIRST] = M;
   1449     else {
   1450       assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
   1451       Modifiers[SECOND] = M;
   1452     }
   1453   }
   1454 
   1455   /// Sets the location of '('.
   1456   ///
   1457   /// \param Loc Location of '('.
   1458   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   1459 
   1460   /// Set schedule kind start location.
   1461   ///
   1462   /// \param KLoc Schedule kind location.
   1463   void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
   1464 
   1465   /// Set location of ','.
   1466   ///
   1467   /// \param Loc Location of ','.
   1468   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
   1469 
   1470   /// Set chunk size.
   1471   ///
   1472   /// \param E Chunk size.
   1473   void setChunkSize(Expr *E) { ChunkSize = E; }
   1474 
   1475 public:
   1476   /// Build 'schedule' clause with schedule kind \a Kind and chunk size
   1477   /// expression \a ChunkSize.
   1478   ///
   1479   /// \param StartLoc Starting location of the clause.
   1480   /// \param LParenLoc Location of '('.
   1481   /// \param KLoc Starting location of the argument.
   1482   /// \param CommaLoc Location of ','.
   1483   /// \param EndLoc Ending location of the clause.
   1484   /// \param Kind Schedule kind.
   1485   /// \param ChunkSize Chunk size.
   1486   /// \param HelperChunkSize Helper chunk size for combined directives.
   1487   /// \param M1 The first modifier applied to 'schedule' clause.
   1488   /// \param M1Loc Location of the first modifier
   1489   /// \param M2 The second modifier applied to 'schedule' clause.
   1490   /// \param M2Loc Location of the second modifier
   1491   OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   1492                     SourceLocation KLoc, SourceLocation CommaLoc,
   1493                     SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
   1494                     Expr *ChunkSize, Stmt *HelperChunkSize,
   1495                     OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
   1496                     OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
   1497       : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
   1498         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
   1499         KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
   1500     setPreInitStmt(HelperChunkSize);
   1501     Modifiers[FIRST] = M1;
   1502     Modifiers[SECOND] = M2;
   1503     ModifiersLoc[FIRST] = M1Loc;
   1504     ModifiersLoc[SECOND] = M2Loc;
   1505   }
   1506 
   1507   /// Build an empty clause.
   1508   explicit OMPScheduleClause()
   1509       : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
   1510         OMPClauseWithPreInit(this) {
   1511     Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
   1512     Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
   1513   }
   1514 
   1515   /// Get kind of the clause.
   1516   OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
   1517 
   1518   /// Get the first modifier of the clause.
   1519   OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
   1520     return Modifiers[FIRST];
   1521   }
   1522 
   1523   /// Get the second modifier of the clause.
   1524   OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
   1525     return Modifiers[SECOND];
   1526   }
   1527 
   1528   /// Get location of '('.
   1529   SourceLocation getLParenLoc() { return LParenLoc; }
   1530 
   1531   /// Get kind location.
   1532   SourceLocation getScheduleKindLoc() { return KindLoc; }
   1533 
   1534   /// Get the first modifier location.
   1535   SourceLocation getFirstScheduleModifierLoc() const {
   1536     return ModifiersLoc[FIRST];
   1537   }
   1538 
   1539   /// Get the second modifier location.
   1540   SourceLocation getSecondScheduleModifierLoc() const {
   1541     return ModifiersLoc[SECOND];
   1542   }
   1543 
   1544   /// Get location of ','.
   1545   SourceLocation getCommaLoc() { return CommaLoc; }
   1546 
   1547   /// Get chunk size.
   1548   Expr *getChunkSize() { return ChunkSize; }
   1549 
   1550   /// Get chunk size.
   1551   const Expr *getChunkSize() const { return ChunkSize; }
   1552 
   1553   child_range children() {
   1554     return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
   1555                        reinterpret_cast<Stmt **>(&ChunkSize) + 1);
   1556   }
   1557 
   1558   const_child_range children() const {
   1559     auto Children = const_cast<OMPScheduleClause *>(this)->children();
   1560     return const_child_range(Children.begin(), Children.end());
   1561   }
   1562 
   1563   child_range used_children() {
   1564     return child_range(child_iterator(), child_iterator());
   1565   }
   1566   const_child_range used_children() const {
   1567     return const_child_range(const_child_iterator(), const_child_iterator());
   1568   }
   1569 
   1570   static bool classof(const OMPClause *T) {
   1571     return T->getClauseKind() == llvm::omp::OMPC_schedule;
   1572   }
   1573 };
   1574 
   1575 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
   1576 ///
   1577 /// \code
   1578 /// #pragma omp for ordered (2)
   1579 /// \endcode
   1580 /// In this example directive '#pragma omp for' has 'ordered' clause with
   1581 /// parameter 2.
   1582 class OMPOrderedClause final
   1583     : public OMPClause,
   1584       private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
   1585   friend class OMPClauseReader;
   1586   friend TrailingObjects;
   1587 
   1588   /// Location of '('.
   1589   SourceLocation LParenLoc;
   1590 
   1591   /// Number of for-loops.
   1592   Stmt *NumForLoops = nullptr;
   1593 
   1594   /// Real number of loops.
   1595   unsigned NumberOfLoops = 0;
   1596 
   1597   /// Build 'ordered' clause.
   1598   ///
   1599   /// \param Num Expression, possibly associated with this clause.
   1600   /// \param NumLoops Number of loops, associated with this clause.
   1601   /// \param StartLoc Starting location of the clause.
   1602   /// \param LParenLoc Location of '('.
   1603   /// \param EndLoc Ending location of the clause.
   1604   OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
   1605                    SourceLocation LParenLoc, SourceLocation EndLoc)
   1606       : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
   1607         LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
   1608 
   1609   /// Build an empty clause.
   1610   explicit OMPOrderedClause(unsigned NumLoops)
   1611       : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
   1612         NumberOfLoops(NumLoops) {}
   1613 
   1614   /// Set the number of associated for-loops.
   1615   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
   1616 
   1617 public:
   1618   /// Build 'ordered' clause.
   1619   ///
   1620   /// \param Num Expression, possibly associated with this clause.
   1621   /// \param NumLoops Number of loops, associated with this clause.
   1622   /// \param StartLoc Starting location of the clause.
   1623   /// \param LParenLoc Location of '('.
   1624   /// \param EndLoc Ending location of the clause.
   1625   static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
   1626                                   unsigned NumLoops, SourceLocation StartLoc,
   1627                                   SourceLocation LParenLoc,
   1628                                   SourceLocation EndLoc);
   1629 
   1630   /// Build an empty clause.
   1631   static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
   1632 
   1633   /// Sets the location of '('.
   1634   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   1635 
   1636   /// Returns the location of '('.
   1637   SourceLocation getLParenLoc() const { return LParenLoc; }
   1638 
   1639   /// Return the number of associated for-loops.
   1640   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
   1641 
   1642   /// Set number of iterations for the specified loop.
   1643   void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
   1644   /// Get number of iterations for all the loops.
   1645   ArrayRef<Expr *> getLoopNumIterations() const;
   1646 
   1647   /// Set loop counter for the specified loop.
   1648   void setLoopCounter(unsigned NumLoop, Expr *Counter);
   1649   /// Get loops counter for the specified loop.
   1650   Expr *getLoopCounter(unsigned NumLoop);
   1651   const Expr *getLoopCounter(unsigned NumLoop) const;
   1652 
   1653   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
   1654 
   1655   const_child_range children() const {
   1656     return const_child_range(&NumForLoops, &NumForLoops + 1);
   1657   }
   1658 
   1659   child_range used_children() {
   1660     return child_range(child_iterator(), child_iterator());
   1661   }
   1662   const_child_range used_children() const {
   1663     return const_child_range(const_child_iterator(), const_child_iterator());
   1664   }
   1665 
   1666   static bool classof(const OMPClause *T) {
   1667     return T->getClauseKind() == llvm::omp::OMPC_ordered;
   1668   }
   1669 };
   1670 
   1671 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
   1672 ///
   1673 /// \code
   1674 /// #pragma omp for nowait
   1675 /// \endcode
   1676 /// In this example directive '#pragma omp for' has 'nowait' clause.
   1677 class OMPNowaitClause : public OMPClause {
   1678 public:
   1679   /// Build 'nowait' clause.
   1680   ///
   1681   /// \param StartLoc Starting location of the clause.
   1682   /// \param EndLoc Ending location of the clause.
   1683   OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1684       : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc) {}
   1685 
   1686   /// Build an empty clause.
   1687   OMPNowaitClause()
   1688       : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {}
   1689 
   1690   child_range children() {
   1691     return child_range(child_iterator(), child_iterator());
   1692   }
   1693 
   1694   const_child_range children() const {
   1695     return const_child_range(const_child_iterator(), const_child_iterator());
   1696   }
   1697 
   1698   child_range used_children() {
   1699     return child_range(child_iterator(), child_iterator());
   1700   }
   1701   const_child_range used_children() const {
   1702     return const_child_range(const_child_iterator(), const_child_iterator());
   1703   }
   1704 
   1705   static bool classof(const OMPClause *T) {
   1706     return T->getClauseKind() == llvm::omp::OMPC_nowait;
   1707   }
   1708 };
   1709 
   1710 /// This represents 'untied' clause in the '#pragma omp ...' directive.
   1711 ///
   1712 /// \code
   1713 /// #pragma omp task untied
   1714 /// \endcode
   1715 /// In this example directive '#pragma omp task' has 'untied' clause.
   1716 class OMPUntiedClause : public OMPClause {
   1717 public:
   1718   /// Build 'untied' clause.
   1719   ///
   1720   /// \param StartLoc Starting location of the clause.
   1721   /// \param EndLoc Ending location of the clause.
   1722   OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1723       : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
   1724 
   1725   /// Build an empty clause.
   1726   OMPUntiedClause()
   1727       : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
   1728 
   1729   child_range children() {
   1730     return child_range(child_iterator(), child_iterator());
   1731   }
   1732 
   1733   const_child_range children() const {
   1734     return const_child_range(const_child_iterator(), const_child_iterator());
   1735   }
   1736 
   1737   child_range used_children() {
   1738     return child_range(child_iterator(), child_iterator());
   1739   }
   1740   const_child_range used_children() const {
   1741     return const_child_range(const_child_iterator(), const_child_iterator());
   1742   }
   1743 
   1744   static bool classof(const OMPClause *T) {
   1745     return T->getClauseKind() == llvm::omp::OMPC_untied;
   1746   }
   1747 };
   1748 
   1749 /// This represents 'mergeable' clause in the '#pragma omp ...'
   1750 /// directive.
   1751 ///
   1752 /// \code
   1753 /// #pragma omp task mergeable
   1754 /// \endcode
   1755 /// In this example directive '#pragma omp task' has 'mergeable' clause.
   1756 class OMPMergeableClause : public OMPClause {
   1757 public:
   1758   /// Build 'mergeable' clause.
   1759   ///
   1760   /// \param StartLoc Starting location of the clause.
   1761   /// \param EndLoc Ending location of the clause.
   1762   OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1763       : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
   1764 
   1765   /// Build an empty clause.
   1766   OMPMergeableClause()
   1767       : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
   1768                   SourceLocation()) {}
   1769 
   1770   child_range children() {
   1771     return child_range(child_iterator(), child_iterator());
   1772   }
   1773 
   1774   const_child_range children() const {
   1775     return const_child_range(const_child_iterator(), const_child_iterator());
   1776   }
   1777 
   1778   child_range used_children() {
   1779     return child_range(child_iterator(), child_iterator());
   1780   }
   1781   const_child_range used_children() const {
   1782     return const_child_range(const_child_iterator(), const_child_iterator());
   1783   }
   1784 
   1785   static bool classof(const OMPClause *T) {
   1786     return T->getClauseKind() == llvm::omp::OMPC_mergeable;
   1787   }
   1788 };
   1789 
   1790 /// This represents 'read' clause in the '#pragma omp atomic' directive.
   1791 ///
   1792 /// \code
   1793 /// #pragma omp atomic read
   1794 /// \endcode
   1795 /// In this example directive '#pragma omp atomic' has 'read' clause.
   1796 class OMPReadClause : public OMPClause {
   1797 public:
   1798   /// Build 'read' clause.
   1799   ///
   1800   /// \param StartLoc Starting location of the clause.
   1801   /// \param EndLoc Ending location of the clause.
   1802   OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1803       : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
   1804 
   1805   /// Build an empty clause.
   1806   OMPReadClause()
   1807       : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
   1808 
   1809   child_range children() {
   1810     return child_range(child_iterator(), child_iterator());
   1811   }
   1812 
   1813   const_child_range children() const {
   1814     return const_child_range(const_child_iterator(), const_child_iterator());
   1815   }
   1816 
   1817   child_range used_children() {
   1818     return child_range(child_iterator(), child_iterator());
   1819   }
   1820   const_child_range used_children() const {
   1821     return const_child_range(const_child_iterator(), const_child_iterator());
   1822   }
   1823 
   1824   static bool classof(const OMPClause *T) {
   1825     return T->getClauseKind() == llvm::omp::OMPC_read;
   1826   }
   1827 };
   1828 
   1829 /// This represents 'write' clause in the '#pragma omp atomic' directive.
   1830 ///
   1831 /// \code
   1832 /// #pragma omp atomic write
   1833 /// \endcode
   1834 /// In this example directive '#pragma omp atomic' has 'write' clause.
   1835 class OMPWriteClause : public OMPClause {
   1836 public:
   1837   /// Build 'write' clause.
   1838   ///
   1839   /// \param StartLoc Starting location of the clause.
   1840   /// \param EndLoc Ending location of the clause.
   1841   OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1842       : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
   1843 
   1844   /// Build an empty clause.
   1845   OMPWriteClause()
   1846       : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
   1847 
   1848   child_range children() {
   1849     return child_range(child_iterator(), child_iterator());
   1850   }
   1851 
   1852   const_child_range children() const {
   1853     return const_child_range(const_child_iterator(), const_child_iterator());
   1854   }
   1855 
   1856   child_range used_children() {
   1857     return child_range(child_iterator(), child_iterator());
   1858   }
   1859   const_child_range used_children() const {
   1860     return const_child_range(const_child_iterator(), const_child_iterator());
   1861   }
   1862 
   1863   static bool classof(const OMPClause *T) {
   1864     return T->getClauseKind() == llvm::omp::OMPC_write;
   1865   }
   1866 };
   1867 
   1868 /// This represents 'update' clause in the '#pragma omp atomic'
   1869 /// directive.
   1870 ///
   1871 /// \code
   1872 /// #pragma omp atomic update
   1873 /// \endcode
   1874 /// In this example directive '#pragma omp atomic' has 'update' clause.
   1875 /// Also, this class represents 'update' clause in  '#pragma omp depobj'
   1876 /// directive.
   1877 ///
   1878 /// \code
   1879 /// #pragma omp depobj(a) update(in)
   1880 /// \endcode
   1881 /// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
   1882 /// dependence kind.
   1883 class OMPUpdateClause final
   1884     : public OMPClause,
   1885       private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
   1886                                     OpenMPDependClauseKind> {
   1887   friend class OMPClauseReader;
   1888   friend TrailingObjects;
   1889 
   1890   /// true if extended version of the clause for 'depobj' directive.
   1891   bool IsExtended = false;
   1892 
   1893   /// Define the sizes of each trailing object array except the last one. This
   1894   /// is required for TrailingObjects to work properly.
   1895   size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
   1896     // 2 locations: for '(' and argument location.
   1897     return IsExtended ? 2 : 0;
   1898   }
   1899 
   1900   /// Sets the the location of '(' in clause for 'depobj' directive.
   1901   void setLParenLoc(SourceLocation Loc) {
   1902     assert(IsExtended && "Expected extended clause.");
   1903     *getTrailingObjects<SourceLocation>() = Loc;
   1904   }
   1905 
   1906   /// Sets the the location of '(' in clause for 'depobj' directive.
   1907   void setArgumentLoc(SourceLocation Loc) {
   1908     assert(IsExtended && "Expected extended clause.");
   1909     *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
   1910   }
   1911 
   1912   /// Sets the dependence kind for the clause for 'depobj' directive.
   1913   void setDependencyKind(OpenMPDependClauseKind DK) {
   1914     assert(IsExtended && "Expected extended clause.");
   1915     *getTrailingObjects<OpenMPDependClauseKind>() = DK;
   1916   }
   1917 
   1918   /// Build 'update' clause.
   1919   ///
   1920   /// \param StartLoc Starting location of the clause.
   1921   /// \param EndLoc Ending location of the clause.
   1922   OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
   1923                   bool IsExtended)
   1924       : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
   1925         IsExtended(IsExtended) {}
   1926 
   1927   /// Build an empty clause.
   1928   OMPUpdateClause(bool IsExtended)
   1929       : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
   1930         IsExtended(IsExtended) {}
   1931 
   1932 public:
   1933   /// Creates clause for 'atomic' directive.
   1934   ///
   1935   /// \param C AST context.
   1936   /// \param StartLoc Starting location of the clause.
   1937   /// \param EndLoc Ending location of the clause.
   1938   static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
   1939                                  SourceLocation EndLoc);
   1940 
   1941   /// Creates clause for 'depobj' directive.
   1942   ///
   1943   /// \param C AST context.
   1944   /// \param StartLoc Starting location of the clause.
   1945   /// \param LParenLoc Location of '('.
   1946   /// \param ArgumentLoc Location of the argument.
   1947   /// \param DK Dependence kind.
   1948   /// \param EndLoc Ending location of the clause.
   1949   static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
   1950                                  SourceLocation LParenLoc,
   1951                                  SourceLocation ArgumentLoc,
   1952                                  OpenMPDependClauseKind DK,
   1953                                  SourceLocation EndLoc);
   1954 
   1955   /// Creates an empty clause with the place for \a N variables.
   1956   ///
   1957   /// \param C AST context.
   1958   /// \param IsExtended true if extended clause for 'depobj' directive must be
   1959   /// created.
   1960   static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
   1961 
   1962   /// Checks if the clause is the extended clauses for 'depobj' directive.
   1963   bool isExtended() const { return IsExtended; }
   1964 
   1965   child_range children() {
   1966     return child_range(child_iterator(), child_iterator());
   1967   }
   1968 
   1969   const_child_range children() const {
   1970     return const_child_range(const_child_iterator(), const_child_iterator());
   1971   }
   1972 
   1973   child_range used_children() {
   1974     return child_range(child_iterator(), child_iterator());
   1975   }
   1976   const_child_range used_children() const {
   1977     return const_child_range(const_child_iterator(), const_child_iterator());
   1978   }
   1979 
   1980   /// Gets the the location of '(' in clause for 'depobj' directive.
   1981   SourceLocation getLParenLoc() const {
   1982     assert(IsExtended && "Expected extended clause.");
   1983     return *getTrailingObjects<SourceLocation>();
   1984   }
   1985 
   1986   /// Gets the the location of argument in clause for 'depobj' directive.
   1987   SourceLocation getArgumentLoc() const {
   1988     assert(IsExtended && "Expected extended clause.");
   1989     return *std::next(getTrailingObjects<SourceLocation>(), 1);
   1990   }
   1991 
   1992   /// Gets the dependence kind in clause for 'depobj' directive.
   1993   OpenMPDependClauseKind getDependencyKind() const {
   1994     assert(IsExtended && "Expected extended clause.");
   1995     return *getTrailingObjects<OpenMPDependClauseKind>();
   1996   }
   1997 
   1998   static bool classof(const OMPClause *T) {
   1999     return T->getClauseKind() == llvm::omp::OMPC_update;
   2000   }
   2001 };
   2002 
   2003 /// This represents 'capture' clause in the '#pragma omp atomic'
   2004 /// directive.
   2005 ///
   2006 /// \code
   2007 /// #pragma omp atomic capture
   2008 /// \endcode
   2009 /// In this example directive '#pragma omp atomic' has 'capture' clause.
   2010 class OMPCaptureClause : public OMPClause {
   2011 public:
   2012   /// Build 'capture' clause.
   2013   ///
   2014   /// \param StartLoc Starting location of the clause.
   2015   /// \param EndLoc Ending location of the clause.
   2016   OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2017       : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
   2018 
   2019   /// Build an empty clause.
   2020   OMPCaptureClause()
   2021       : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
   2022   }
   2023 
   2024   child_range children() {
   2025     return child_range(child_iterator(), child_iterator());
   2026   }
   2027 
   2028   const_child_range children() const {
   2029     return const_child_range(const_child_iterator(), const_child_iterator());
   2030   }
   2031 
   2032   child_range used_children() {
   2033     return child_range(child_iterator(), child_iterator());
   2034   }
   2035   const_child_range used_children() const {
   2036     return const_child_range(const_child_iterator(), const_child_iterator());
   2037   }
   2038 
   2039   static bool classof(const OMPClause *T) {
   2040     return T->getClauseKind() == llvm::omp::OMPC_capture;
   2041   }
   2042 };
   2043 
   2044 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
   2045 /// directive.
   2046 ///
   2047 /// \code
   2048 /// #pragma omp atomic seq_cst
   2049 /// \endcode
   2050 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
   2051 class OMPSeqCstClause : public OMPClause {
   2052 public:
   2053   /// Build 'seq_cst' clause.
   2054   ///
   2055   /// \param StartLoc Starting location of the clause.
   2056   /// \param EndLoc Ending location of the clause.
   2057   OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2058       : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
   2059 
   2060   /// Build an empty clause.
   2061   OMPSeqCstClause()
   2062       : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
   2063   }
   2064 
   2065   child_range children() {
   2066     return child_range(child_iterator(), child_iterator());
   2067   }
   2068 
   2069   const_child_range children() const {
   2070     return const_child_range(const_child_iterator(), const_child_iterator());
   2071   }
   2072 
   2073   child_range used_children() {
   2074     return child_range(child_iterator(), child_iterator());
   2075   }
   2076   const_child_range used_children() const {
   2077     return const_child_range(const_child_iterator(), const_child_iterator());
   2078   }
   2079 
   2080   static bool classof(const OMPClause *T) {
   2081     return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
   2082   }
   2083 };
   2084 
   2085 /// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
   2086 /// directives.
   2087 ///
   2088 /// \code
   2089 /// #pragma omp flush acq_rel
   2090 /// \endcode
   2091 /// In this example directive '#pragma omp flush' has 'acq_rel' clause.
   2092 class OMPAcqRelClause final : public OMPClause {
   2093 public:
   2094   /// Build 'ack_rel' clause.
   2095   ///
   2096   /// \param StartLoc Starting location of the clause.
   2097   /// \param EndLoc Ending location of the clause.
   2098   OMPAcqRelClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2099       : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
   2100 
   2101   /// Build an empty clause.
   2102   OMPAcqRelClause()
   2103       : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
   2104   }
   2105 
   2106   child_range children() {
   2107     return child_range(child_iterator(), child_iterator());
   2108   }
   2109 
   2110   const_child_range children() const {
   2111     return const_child_range(const_child_iterator(), const_child_iterator());
   2112   }
   2113 
   2114   child_range used_children() {
   2115     return child_range(child_iterator(), child_iterator());
   2116   }
   2117   const_child_range used_children() const {
   2118     return const_child_range(const_child_iterator(), const_child_iterator());
   2119   }
   2120 
   2121   static bool classof(const OMPClause *T) {
   2122     return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
   2123   }
   2124 };
   2125 
   2126 /// This represents 'acquire' clause in the '#pragma omp atomic|flush'
   2127 /// directives.
   2128 ///
   2129 /// \code
   2130 /// #pragma omp flush acquire
   2131 /// \endcode
   2132 /// In this example directive '#pragma omp flush' has 'acquire' clause.
   2133 class OMPAcquireClause final : public OMPClause {
   2134 public:
   2135   /// Build 'acquire' clause.
   2136   ///
   2137   /// \param StartLoc Starting location of the clause.
   2138   /// \param EndLoc Ending location of the clause.
   2139   OMPAcquireClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2140       : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
   2141 
   2142   /// Build an empty clause.
   2143   OMPAcquireClause()
   2144       : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
   2145   }
   2146 
   2147   child_range children() {
   2148     return child_range(child_iterator(), child_iterator());
   2149   }
   2150 
   2151   const_child_range children() const {
   2152     return const_child_range(const_child_iterator(), const_child_iterator());
   2153   }
   2154 
   2155   child_range used_children() {
   2156     return child_range(child_iterator(), child_iterator());
   2157   }
   2158   const_child_range used_children() const {
   2159     return const_child_range(const_child_iterator(), const_child_iterator());
   2160   }
   2161 
   2162   static bool classof(const OMPClause *T) {
   2163     return T->getClauseKind() == llvm::omp::OMPC_acquire;
   2164   }
   2165 };
   2166 
   2167 /// This represents 'release' clause in the '#pragma omp atomic|flush'
   2168 /// directives.
   2169 ///
   2170 /// \code
   2171 /// #pragma omp flush release
   2172 /// \endcode
   2173 /// In this example directive '#pragma omp flush' has 'release' clause.
   2174 class OMPReleaseClause final : public OMPClause {
   2175 public:
   2176   /// Build 'release' clause.
   2177   ///
   2178   /// \param StartLoc Starting location of the clause.
   2179   /// \param EndLoc Ending location of the clause.
   2180   OMPReleaseClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2181       : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
   2182 
   2183   /// Build an empty clause.
   2184   OMPReleaseClause()
   2185       : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
   2186   }
   2187 
   2188   child_range children() {
   2189     return child_range(child_iterator(), child_iterator());
   2190   }
   2191 
   2192   const_child_range children() const {
   2193     return const_child_range(const_child_iterator(), const_child_iterator());
   2194   }
   2195 
   2196   child_range used_children() {
   2197     return child_range(child_iterator(), child_iterator());
   2198   }
   2199   const_child_range used_children() const {
   2200     return const_child_range(const_child_iterator(), const_child_iterator());
   2201   }
   2202 
   2203   static bool classof(const OMPClause *T) {
   2204     return T->getClauseKind() == llvm::omp::OMPC_release;
   2205   }
   2206 };
   2207 
   2208 /// This represents 'relaxed' clause in the '#pragma omp atomic'
   2209 /// directives.
   2210 ///
   2211 /// \code
   2212 /// #pragma omp atomic relaxed
   2213 /// \endcode
   2214 /// In this example directive '#pragma omp atomic' has 'relaxed' clause.
   2215 class OMPRelaxedClause final : public OMPClause {
   2216 public:
   2217   /// Build 'relaxed' clause.
   2218   ///
   2219   /// \param StartLoc Starting location of the clause.
   2220   /// \param EndLoc Ending location of the clause.
   2221   OMPRelaxedClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2222       : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
   2223 
   2224   /// Build an empty clause.
   2225   OMPRelaxedClause()
   2226       : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
   2227   }
   2228 
   2229   child_range children() {
   2230     return child_range(child_iterator(), child_iterator());
   2231   }
   2232 
   2233   const_child_range children() const {
   2234     return const_child_range(const_child_iterator(), const_child_iterator());
   2235   }
   2236 
   2237   child_range used_children() {
   2238     return child_range(child_iterator(), child_iterator());
   2239   }
   2240   const_child_range used_children() const {
   2241     return const_child_range(const_child_iterator(), const_child_iterator());
   2242   }
   2243 
   2244   static bool classof(const OMPClause *T) {
   2245     return T->getClauseKind() == llvm::omp::OMPC_relaxed;
   2246   }
   2247 };
   2248 
   2249 /// This represents clause 'private' in the '#pragma omp ...' directives.
   2250 ///
   2251 /// \code
   2252 /// #pragma omp parallel private(a,b)
   2253 /// \endcode
   2254 /// In this example directive '#pragma omp parallel' has clause 'private'
   2255 /// with the variables 'a' and 'b'.
   2256 class OMPPrivateClause final
   2257     : public OMPVarListClause<OMPPrivateClause>,
   2258       private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
   2259   friend class OMPClauseReader;
   2260   friend OMPVarListClause;
   2261   friend TrailingObjects;
   2262 
   2263   /// Build clause with number of variables \a N.
   2264   ///
   2265   /// \param StartLoc Starting location of the clause.
   2266   /// \param LParenLoc Location of '('.
   2267   /// \param EndLoc Ending location of the clause.
   2268   /// \param N Number of the variables in the clause.
   2269   OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2270                    SourceLocation EndLoc, unsigned N)
   2271       : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
   2272                                            LParenLoc, EndLoc, N) {}
   2273 
   2274   /// Build an empty clause.
   2275   ///
   2276   /// \param N Number of variables.
   2277   explicit OMPPrivateClause(unsigned N)
   2278       : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
   2279                                            SourceLocation(), SourceLocation(),
   2280                                            SourceLocation(), N) {}
   2281 
   2282   /// Sets the list of references to private copies with initializers for
   2283   /// new private variables.
   2284   /// \param VL List of references.
   2285   void setPrivateCopies(ArrayRef<Expr *> VL);
   2286 
   2287   /// Gets the list of references to private copies with initializers for
   2288   /// new private variables.
   2289   MutableArrayRef<Expr *> getPrivateCopies() {
   2290     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   2291   }
   2292   ArrayRef<const Expr *> getPrivateCopies() const {
   2293     return llvm::makeArrayRef(varlist_end(), varlist_size());
   2294   }
   2295 
   2296 public:
   2297   /// Creates clause with a list of variables \a VL.
   2298   ///
   2299   /// \param C AST context.
   2300   /// \param StartLoc Starting location of the clause.
   2301   /// \param LParenLoc Location of '('.
   2302   /// \param EndLoc Ending location of the clause.
   2303   /// \param VL List of references to the variables.
   2304   /// \param PrivateVL List of references to private copies with initializers.
   2305   static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
   2306                                   SourceLocation LParenLoc,
   2307                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
   2308                                   ArrayRef<Expr *> PrivateVL);
   2309 
   2310   /// Creates an empty clause with the place for \a N variables.
   2311   ///
   2312   /// \param C AST context.
   2313   /// \param N The number of variables.
   2314   static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
   2315 
   2316   using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
   2317   using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
   2318   using private_copies_range = llvm::iterator_range<private_copies_iterator>;
   2319   using private_copies_const_range =
   2320       llvm::iterator_range<private_copies_const_iterator>;
   2321 
   2322   private_copies_range private_copies() {
   2323     return private_copies_range(getPrivateCopies().begin(),
   2324                                 getPrivateCopies().end());
   2325   }
   2326 
   2327   private_copies_const_range private_copies() const {
   2328     return private_copies_const_range(getPrivateCopies().begin(),
   2329                                       getPrivateCopies().end());
   2330   }
   2331 
   2332   child_range children() {
   2333     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2334                        reinterpret_cast<Stmt **>(varlist_end()));
   2335   }
   2336 
   2337   const_child_range children() const {
   2338     auto Children = const_cast<OMPPrivateClause *>(this)->children();
   2339     return const_child_range(Children.begin(), Children.end());
   2340   }
   2341 
   2342   child_range used_children() {
   2343     return child_range(child_iterator(), child_iterator());
   2344   }
   2345   const_child_range used_children() const {
   2346     return const_child_range(const_child_iterator(), const_child_iterator());
   2347   }
   2348 
   2349   static bool classof(const OMPClause *T) {
   2350     return T->getClauseKind() == llvm::omp::OMPC_private;
   2351   }
   2352 };
   2353 
   2354 /// This represents clause 'firstprivate' in the '#pragma omp ...'
   2355 /// directives.
   2356 ///
   2357 /// \code
   2358 /// #pragma omp parallel firstprivate(a,b)
   2359 /// \endcode
   2360 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
   2361 /// with the variables 'a' and 'b'.
   2362 class OMPFirstprivateClause final
   2363     : public OMPVarListClause<OMPFirstprivateClause>,
   2364       public OMPClauseWithPreInit,
   2365       private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
   2366   friend class OMPClauseReader;
   2367   friend OMPVarListClause;
   2368   friend TrailingObjects;
   2369 
   2370   /// Build clause with number of variables \a N.
   2371   ///
   2372   /// \param StartLoc Starting location of the clause.
   2373   /// \param LParenLoc Location of '('.
   2374   /// \param EndLoc Ending location of the clause.
   2375   /// \param N Number of the variables in the clause.
   2376   OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2377                         SourceLocation EndLoc, unsigned N)
   2378       : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
   2379                                                 StartLoc, LParenLoc, EndLoc, N),
   2380         OMPClauseWithPreInit(this) {}
   2381 
   2382   /// Build an empty clause.
   2383   ///
   2384   /// \param N Number of variables.
   2385   explicit OMPFirstprivateClause(unsigned N)
   2386       : OMPVarListClause<OMPFirstprivateClause>(
   2387             llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
   2388             SourceLocation(), N),
   2389         OMPClauseWithPreInit(this) {}
   2390 
   2391   /// Sets the list of references to private copies with initializers for
   2392   /// new private variables.
   2393   /// \param VL List of references.
   2394   void setPrivateCopies(ArrayRef<Expr *> VL);
   2395 
   2396   /// Gets the list of references to private copies with initializers for
   2397   /// new private variables.
   2398   MutableArrayRef<Expr *> getPrivateCopies() {
   2399     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   2400   }
   2401   ArrayRef<const Expr *> getPrivateCopies() const {
   2402     return llvm::makeArrayRef(varlist_end(), varlist_size());
   2403   }
   2404 
   2405   /// Sets the list of references to initializer variables for new
   2406   /// private variables.
   2407   /// \param VL List of references.
   2408   void setInits(ArrayRef<Expr *> VL);
   2409 
   2410   /// Gets the list of references to initializer variables for new
   2411   /// private variables.
   2412   MutableArrayRef<Expr *> getInits() {
   2413     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
   2414   }
   2415   ArrayRef<const Expr *> getInits() const {
   2416     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
   2417   }
   2418 
   2419 public:
   2420   /// Creates clause with a list of variables \a VL.
   2421   ///
   2422   /// \param C AST context.
   2423   /// \param StartLoc Starting location of the clause.
   2424   /// \param LParenLoc Location of '('.
   2425   /// \param EndLoc Ending location of the clause.
   2426   /// \param VL List of references to the original variables.
   2427   /// \param PrivateVL List of references to private copies with initializers.
   2428   /// \param InitVL List of references to auto generated variables used for
   2429   /// initialization of a single array element. Used if firstprivate variable is
   2430   /// of array type.
   2431   /// \param PreInit Statement that must be executed before entering the OpenMP
   2432   /// region with this clause.
   2433   static OMPFirstprivateClause *
   2434   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   2435          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
   2436          ArrayRef<Expr *> InitVL, Stmt *PreInit);
   2437 
   2438   /// Creates an empty clause with the place for \a N variables.
   2439   ///
   2440   /// \param C AST context.
   2441   /// \param N The number of variables.
   2442   static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
   2443 
   2444   using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
   2445   using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
   2446   using private_copies_range = llvm::iterator_range<private_copies_iterator>;
   2447   using private_copies_const_range =
   2448       llvm::iterator_range<private_copies_const_iterator>;
   2449 
   2450   private_copies_range private_copies() {
   2451     return private_copies_range(getPrivateCopies().begin(),
   2452                                 getPrivateCopies().end());
   2453   }
   2454   private_copies_const_range private_copies() const {
   2455     return private_copies_const_range(getPrivateCopies().begin(),
   2456                                       getPrivateCopies().end());
   2457   }
   2458 
   2459   using inits_iterator = MutableArrayRef<Expr *>::iterator;
   2460   using inits_const_iterator = ArrayRef<const Expr *>::iterator;
   2461   using inits_range = llvm::iterator_range<inits_iterator>;
   2462   using inits_const_range = llvm::iterator_range<inits_const_iterator>;
   2463 
   2464   inits_range inits() {
   2465     return inits_range(getInits().begin(), getInits().end());
   2466   }
   2467   inits_const_range inits() const {
   2468     return inits_const_range(getInits().begin(), getInits().end());
   2469   }
   2470 
   2471   child_range children() {
   2472     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2473                        reinterpret_cast<Stmt **>(varlist_end()));
   2474   }
   2475 
   2476   const_child_range children() const {
   2477     auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
   2478     return const_child_range(Children.begin(), Children.end());
   2479   }
   2480 
   2481   child_range used_children() {
   2482     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2483                        reinterpret_cast<Stmt **>(varlist_end()));
   2484   }
   2485   const_child_range used_children() const {
   2486     auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
   2487     return const_child_range(Children.begin(), Children.end());
   2488   }
   2489 
   2490   static bool classof(const OMPClause *T) {
   2491     return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
   2492   }
   2493 };
   2494 
   2495 /// This represents clause 'lastprivate' in the '#pragma omp ...'
   2496 /// directives.
   2497 ///
   2498 /// \code
   2499 /// #pragma omp simd lastprivate(a,b)
   2500 /// \endcode
   2501 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
   2502 /// with the variables 'a' and 'b'.
   2503 class OMPLastprivateClause final
   2504     : public OMPVarListClause<OMPLastprivateClause>,
   2505       public OMPClauseWithPostUpdate,
   2506       private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
   2507   // There are 4 additional tail-allocated arrays at the end of the class:
   2508   // 1. Contains list of pseudo variables with the default initialization for
   2509   // each non-firstprivate variables. Used in codegen for initialization of
   2510   // lastprivate copies.
   2511   // 2. List of helper expressions for proper generation of assignment operation
   2512   // required for lastprivate clause. This list represents private variables
   2513   // (for arrays, single array element).
   2514   // 3. List of helper expressions for proper generation of assignment operation
   2515   // required for lastprivate clause. This list represents original variables
   2516   // (for arrays, single array element).
   2517   // 4. List of helper expressions that represents assignment operation:
   2518   // \code
   2519   // DstExprs = SrcExprs;
   2520   // \endcode
   2521   // Required for proper codegen of final assignment performed by the
   2522   // lastprivate clause.
   2523   friend class OMPClauseReader;
   2524   friend OMPVarListClause;
   2525   friend TrailingObjects;
   2526 
   2527   /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
   2528   OpenMPLastprivateModifier LPKind;
   2529   /// Optional location of the lasptrivate kind, if specified by user.
   2530   SourceLocation LPKindLoc;
   2531   /// Optional colon location, if specified by user.
   2532   SourceLocation ColonLoc;
   2533 
   2534   /// Build clause with number of variables \a N.
   2535   ///
   2536   /// \param StartLoc Starting location of the clause.
   2537   /// \param LParenLoc Location of '('.
   2538   /// \param EndLoc Ending location of the clause.
   2539   /// \param N Number of the variables in the clause.
   2540   OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2541                        SourceLocation EndLoc, OpenMPLastprivateModifier LPKind,
   2542                        SourceLocation LPKindLoc, SourceLocation ColonLoc,
   2543                        unsigned N)
   2544       : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
   2545                                                StartLoc, LParenLoc, EndLoc, N),
   2546         OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
   2547         ColonLoc(ColonLoc) {}
   2548 
   2549   /// Build an empty clause.
   2550   ///
   2551   /// \param N Number of variables.
   2552   explicit OMPLastprivateClause(unsigned N)
   2553       : OMPVarListClause<OMPLastprivateClause>(
   2554             llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
   2555             SourceLocation(), N),
   2556         OMPClauseWithPostUpdate(this) {}
   2557 
   2558   /// Get the list of helper expressions for initialization of private
   2559   /// copies for lastprivate variables.
   2560   MutableArrayRef<Expr *> getPrivateCopies() {
   2561     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   2562   }
   2563   ArrayRef<const Expr *> getPrivateCopies() const {
   2564     return llvm::makeArrayRef(varlist_end(), varlist_size());
   2565   }
   2566 
   2567   /// Set list of helper expressions, required for proper codegen of the
   2568   /// clause. These expressions represent private variables (for arrays, single
   2569   /// array element) in the final assignment statement performed by the
   2570   /// lastprivate clause.
   2571   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
   2572 
   2573   /// Get the list of helper source expressions.
   2574   MutableArrayRef<Expr *> getSourceExprs() {
   2575     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
   2576   }
   2577   ArrayRef<const Expr *> getSourceExprs() const {
   2578     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
   2579   }
   2580 
   2581   /// Set list of helper expressions, required for proper codegen of the
   2582   /// clause. These expressions represent original variables (for arrays, single
   2583   /// array element) in the final assignment statement performed by the
   2584   /// lastprivate clause.
   2585   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
   2586 
   2587   /// Get the list of helper destination expressions.
   2588   MutableArrayRef<Expr *> getDestinationExprs() {
   2589     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
   2590   }
   2591   ArrayRef<const Expr *> getDestinationExprs() const {
   2592     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
   2593   }
   2594 
   2595   /// Set list of helper assignment expressions, required for proper
   2596   /// codegen of the clause. These expressions are assignment expressions that
   2597   /// assign private copy of the variable to original variable.
   2598   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
   2599 
   2600   /// Get the list of helper assignment expressions.
   2601   MutableArrayRef<Expr *> getAssignmentOps() {
   2602     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
   2603   }
   2604   ArrayRef<const Expr *> getAssignmentOps() const {
   2605     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
   2606   }
   2607 
   2608   /// Sets lastprivate kind.
   2609   void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
   2610   /// Sets location of the lastprivate kind.
   2611   void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
   2612   /// Sets colon symbol location.
   2613   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   2614 
   2615 public:
   2616   /// Creates clause with a list of variables \a VL.
   2617   ///
   2618   /// \param C AST context.
   2619   /// \param StartLoc Starting location of the clause.
   2620   /// \param LParenLoc Location of '('.
   2621   /// \param EndLoc Ending location of the clause.
   2622   /// \param VL List of references to the variables.
   2623   /// \param SrcExprs List of helper expressions for proper generation of
   2624   /// assignment operation required for lastprivate clause. This list represents
   2625   /// private variables (for arrays, single array element).
   2626   /// \param DstExprs List of helper expressions for proper generation of
   2627   /// assignment operation required for lastprivate clause. This list represents
   2628   /// original variables (for arrays, single array element).
   2629   /// \param AssignmentOps List of helper expressions that represents assignment
   2630   /// operation:
   2631   /// \code
   2632   /// DstExprs = SrcExprs;
   2633   /// \endcode
   2634   /// Required for proper codegen of final assignment performed by the
   2635   /// lastprivate clause.
   2636   /// \param LPKind Lastprivate kind, e.g. 'conditional'.
   2637   /// \param LPKindLoc Location of the lastprivate kind.
   2638   /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
   2639   /// \param PreInit Statement that must be executed before entering the OpenMP
   2640   /// region with this clause.
   2641   /// \param PostUpdate Expression that must be executed after exit from the
   2642   /// OpenMP region with this clause.
   2643   static OMPLastprivateClause *
   2644   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   2645          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
   2646          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
   2647          OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
   2648          SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
   2649 
   2650   /// Creates an empty clause with the place for \a N variables.
   2651   ///
   2652   /// \param C AST context.
   2653   /// \param N The number of variables.
   2654   static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
   2655 
   2656   /// Lastprivate kind.
   2657   OpenMPLastprivateModifier getKind() const { return LPKind; }
   2658   /// Returns the location of the lastprivate kind.
   2659   SourceLocation getKindLoc() const { return LPKindLoc; }
   2660   /// Returns the location of the ':' symbol, if any.
   2661   SourceLocation getColonLoc() const { return ColonLoc; }
   2662 
   2663   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
   2664   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
   2665   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
   2666   using helper_expr_const_range =
   2667       llvm::iterator_range<helper_expr_const_iterator>;
   2668 
   2669   /// Set list of helper expressions, required for generation of private
   2670   /// copies of original lastprivate variables.
   2671   void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
   2672 
   2673   helper_expr_const_range private_copies() const {
   2674     return helper_expr_const_range(getPrivateCopies().begin(),
   2675                                    getPrivateCopies().end());
   2676   }
   2677 
   2678   helper_expr_range private_copies() {
   2679     return helper_expr_range(getPrivateCopies().begin(),
   2680                              getPrivateCopies().end());
   2681   }
   2682 
   2683   helper_expr_const_range source_exprs() const {
   2684     return helper_expr_const_range(getSourceExprs().begin(),
   2685                                    getSourceExprs().end());
   2686   }
   2687 
   2688   helper_expr_range source_exprs() {
   2689     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
   2690   }
   2691 
   2692   helper_expr_const_range destination_exprs() const {
   2693     return helper_expr_const_range(getDestinationExprs().begin(),
   2694                                    getDestinationExprs().end());
   2695   }
   2696 
   2697   helper_expr_range destination_exprs() {
   2698     return helper_expr_range(getDestinationExprs().begin(),
   2699                              getDestinationExprs().end());
   2700   }
   2701 
   2702   helper_expr_const_range assignment_ops() const {
   2703     return helper_expr_const_range(getAssignmentOps().begin(),
   2704                                    getAssignmentOps().end());
   2705   }
   2706 
   2707   helper_expr_range assignment_ops() {
   2708     return helper_expr_range(getAssignmentOps().begin(),
   2709                              getAssignmentOps().end());
   2710   }
   2711 
   2712   child_range children() {
   2713     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2714                        reinterpret_cast<Stmt **>(varlist_end()));
   2715   }
   2716 
   2717   const_child_range children() const {
   2718     auto Children = const_cast<OMPLastprivateClause *>(this)->children();
   2719     return const_child_range(Children.begin(), Children.end());
   2720   }
   2721 
   2722   child_range used_children() {
   2723     return child_range(child_iterator(), child_iterator());
   2724   }
   2725   const_child_range used_children() const {
   2726     return const_child_range(const_child_iterator(), const_child_iterator());
   2727   }
   2728 
   2729   static bool classof(const OMPClause *T) {
   2730     return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
   2731   }
   2732 };
   2733 
   2734 /// This represents clause 'shared' in the '#pragma omp ...' directives.
   2735 ///
   2736 /// \code
   2737 /// #pragma omp parallel shared(a,b)
   2738 /// \endcode
   2739 /// In this example directive '#pragma omp parallel' has clause 'shared'
   2740 /// with the variables 'a' and 'b'.
   2741 class OMPSharedClause final
   2742     : public OMPVarListClause<OMPSharedClause>,
   2743       private llvm::TrailingObjects<OMPSharedClause, Expr *> {
   2744   friend OMPVarListClause;
   2745   friend TrailingObjects;
   2746 
   2747   /// Build clause with number of variables \a N.
   2748   ///
   2749   /// \param StartLoc Starting location of the clause.
   2750   /// \param LParenLoc Location of '('.
   2751   /// \param EndLoc Ending location of the clause.
   2752   /// \param N Number of the variables in the clause.
   2753   OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2754                   SourceLocation EndLoc, unsigned N)
   2755       : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
   2756                                           LParenLoc, EndLoc, N) {}
   2757 
   2758   /// Build an empty clause.
   2759   ///
   2760   /// \param N Number of variables.
   2761   explicit OMPSharedClause(unsigned N)
   2762       : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
   2763                                           SourceLocation(), SourceLocation(),
   2764                                           SourceLocation(), N) {}
   2765 
   2766 public:
   2767   /// Creates clause with a list of variables \a VL.
   2768   ///
   2769   /// \param C AST context.
   2770   /// \param StartLoc Starting location of the clause.
   2771   /// \param LParenLoc Location of '('.
   2772   /// \param EndLoc Ending location of the clause.
   2773   /// \param VL List of references to the variables.
   2774   static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
   2775                                  SourceLocation LParenLoc,
   2776                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
   2777 
   2778   /// Creates an empty clause with \a N variables.
   2779   ///
   2780   /// \param C AST context.
   2781   /// \param N The number of variables.
   2782   static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
   2783 
   2784   child_range children() {
   2785     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2786                        reinterpret_cast<Stmt **>(varlist_end()));
   2787   }
   2788 
   2789   const_child_range children() const {
   2790     auto Children = const_cast<OMPSharedClause *>(this)->children();
   2791     return const_child_range(Children.begin(), Children.end());
   2792   }
   2793 
   2794   child_range used_children() {
   2795     return child_range(child_iterator(), child_iterator());
   2796   }
   2797   const_child_range used_children() const {
   2798     return const_child_range(const_child_iterator(), const_child_iterator());
   2799   }
   2800 
   2801   static bool classof(const OMPClause *T) {
   2802     return T->getClauseKind() == llvm::omp::OMPC_shared;
   2803   }
   2804 };
   2805 
   2806 /// This represents clause 'reduction' in the '#pragma omp ...'
   2807 /// directives.
   2808 ///
   2809 /// \code
   2810 /// #pragma omp parallel reduction(+:a,b)
   2811 /// \endcode
   2812 /// In this example directive '#pragma omp parallel' has clause 'reduction'
   2813 /// with operator '+' and the variables 'a' and 'b'.
   2814 class OMPReductionClause final
   2815     : public OMPVarListClause<OMPReductionClause>,
   2816       public OMPClauseWithPostUpdate,
   2817       private llvm::TrailingObjects<OMPReductionClause, Expr *> {
   2818   friend class OMPClauseReader;
   2819   friend OMPVarListClause;
   2820   friend TrailingObjects;
   2821 
   2822   /// Reduction modifier.
   2823   OpenMPReductionClauseModifier Modifier = OMPC_REDUCTION_unknown;
   2824 
   2825   /// Reduction modifier location.
   2826   SourceLocation ModifierLoc;
   2827 
   2828   /// Location of ':'.
   2829   SourceLocation ColonLoc;
   2830 
   2831   /// Nested name specifier for C++.
   2832   NestedNameSpecifierLoc QualifierLoc;
   2833 
   2834   /// Name of custom operator.
   2835   DeclarationNameInfo NameInfo;
   2836 
   2837   /// Build clause with number of variables \a N.
   2838   ///
   2839   /// \param StartLoc Starting location of the clause.
   2840   /// \param LParenLoc Location of '('.
   2841   /// \param ModifierLoc Modifier location.
   2842   /// \param ColonLoc Location of ':'.
   2843   /// \param EndLoc Ending location of the clause.
   2844   /// \param N Number of the variables in the clause.
   2845   /// \param QualifierLoc The nested-name qualifier with location information
   2846   /// \param NameInfo The full name info for reduction identifier.
   2847   OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2848                      SourceLocation ModifierLoc, SourceLocation ColonLoc,
   2849                      SourceLocation EndLoc,
   2850                      OpenMPReductionClauseModifier Modifier, unsigned N,
   2851                      NestedNameSpecifierLoc QualifierLoc,
   2852                      const DeclarationNameInfo &NameInfo)
   2853       : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
   2854                                              StartLoc, LParenLoc, EndLoc, N),
   2855         OMPClauseWithPostUpdate(this), Modifier(Modifier),
   2856         ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
   2857         QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
   2858 
   2859   /// Build an empty clause.
   2860   ///
   2861   /// \param N Number of variables.
   2862   explicit OMPReductionClause(unsigned N)
   2863       : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
   2864                                              SourceLocation(), SourceLocation(),
   2865                                              SourceLocation(), N),
   2866         OMPClauseWithPostUpdate(this) {}
   2867 
   2868   /// Sets reduction modifier.
   2869   void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
   2870 
   2871   /// Sets location of the modifier.
   2872   void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
   2873 
   2874   /// Sets location of ':' symbol in clause.
   2875   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
   2876 
   2877   /// Sets the name info for specified reduction identifier.
   2878   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
   2879 
   2880   /// Sets the nested name specifier.
   2881   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
   2882 
   2883   /// Set list of helper expressions, required for proper codegen of the
   2884   /// clause. These expressions represent private copy of the reduction
   2885   /// variable.
   2886   void setPrivates(ArrayRef<Expr *> Privates);
   2887 
   2888   /// Get the list of helper privates.
   2889   MutableArrayRef<Expr *> getPrivates() {
   2890     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   2891   }
   2892   ArrayRef<const Expr *> getPrivates() const {
   2893     return llvm::makeArrayRef(varlist_end(), varlist_size());
   2894   }
   2895 
   2896   /// Set list of helper expressions, required for proper codegen of the
   2897   /// clause. These expressions represent LHS expression in the final
   2898   /// reduction expression performed by the reduction clause.
   2899   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
   2900 
   2901   /// Get the list of helper LHS expressions.
   2902   MutableArrayRef<Expr *> getLHSExprs() {
   2903     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
   2904   }
   2905   ArrayRef<const Expr *> getLHSExprs() const {
   2906     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
   2907   }
   2908 
   2909   /// Set list of helper expressions, required for proper codegen of the
   2910   /// clause. These expressions represent RHS expression in the final
   2911   /// reduction expression performed by the reduction clause.
   2912   /// Also, variables in these expressions are used for proper initialization of
   2913   /// reduction copies.
   2914   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
   2915 
   2916   /// Get the list of helper destination expressions.
   2917   MutableArrayRef<Expr *> getRHSExprs() {
   2918     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
   2919   }
   2920   ArrayRef<const Expr *> getRHSExprs() const {
   2921     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
   2922   }
   2923 
   2924   /// Set list of helper reduction expressions, required for proper
   2925   /// codegen of the clause. These expressions are binary expressions or
   2926   /// operator/custom reduction call that calculates new value from source
   2927   /// helper expressions to destination helper expressions.
   2928   void setReductionOps(ArrayRef<Expr *> ReductionOps);
   2929 
   2930   /// Get the list of helper reduction expressions.
   2931   MutableArrayRef<Expr *> getReductionOps() {
   2932     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
   2933   }
   2934   ArrayRef<const Expr *> getReductionOps() const {
   2935     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
   2936   }
   2937 
   2938   /// Set list of helper copy operations for inscan reductions.
   2939   /// The form is: Temps[i] = LHS[i];
   2940   void setInscanCopyOps(ArrayRef<Expr *> Ops);
   2941 
   2942   /// Get the list of helper inscan copy operations.
   2943   MutableArrayRef<Expr *> getInscanCopyOps() {
   2944     return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
   2945   }
   2946   ArrayRef<const Expr *> getInscanCopyOps() const {
   2947     return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
   2948   }
   2949 
   2950   /// Set list of helper temp vars for inscan copy array operations.
   2951   void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
   2952 
   2953   /// Get the list of helper inscan copy temps.
   2954   MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
   2955     return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
   2956   }
   2957   ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
   2958     return llvm::makeArrayRef(getInscanCopyOps().end(), varlist_size());
   2959   }
   2960 
   2961   /// Set list of helper temp elements vars for inscan copy array operations.
   2962   void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
   2963 
   2964   /// Get the list of helper inscan copy temps.
   2965   MutableArrayRef<Expr *> getInscanCopyArrayElems() {
   2966     return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
   2967                                    varlist_size());
   2968   }
   2969   ArrayRef<const Expr *> getInscanCopyArrayElems() const {
   2970     return llvm::makeArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
   2971   }
   2972 
   2973 public:
   2974   /// Creates clause with a list of variables \a VL.
   2975   ///
   2976   /// \param StartLoc Starting location of the clause.
   2977   /// \param LParenLoc Location of '('.
   2978   /// \param ModifierLoc Modifier location.
   2979   /// \param ColonLoc Location of ':'.
   2980   /// \param EndLoc Ending location of the clause.
   2981   /// \param VL The variables in the clause.
   2982   /// \param QualifierLoc The nested-name qualifier with location information
   2983   /// \param NameInfo The full name info for reduction identifier.
   2984   /// \param Privates List of helper expressions for proper generation of
   2985   /// private copies.
   2986   /// \param LHSExprs List of helper expressions for proper generation of
   2987   /// assignment operation required for copyprivate clause. This list represents
   2988   /// LHSs of the reduction expressions.
   2989   /// \param RHSExprs List of helper expressions for proper generation of
   2990   /// assignment operation required for copyprivate clause. This list represents
   2991   /// RHSs of the reduction expressions.
   2992   /// Also, variables in these expressions are used for proper initialization of
   2993   /// reduction copies.
   2994   /// \param ReductionOps List of helper expressions that represents reduction
   2995   /// expressions:
   2996   /// \code
   2997   /// LHSExprs binop RHSExprs;
   2998   /// operator binop(LHSExpr, RHSExpr);
   2999   /// <CutomReduction>(LHSExpr, RHSExpr);
   3000   /// \endcode
   3001   /// Required for proper codegen of final reduction operation performed by the
   3002   /// reduction clause.
   3003   /// \param CopyOps List of copy operations for inscan reductions:
   3004   /// \code
   3005   /// TempExprs = LHSExprs;
   3006   /// \endcode
   3007   /// \param CopyArrayTemps Temp arrays for prefix sums.
   3008   /// \param CopyArrayElems Temp arrays for prefix sums.
   3009   /// \param PreInit Statement that must be executed before entering the OpenMP
   3010   /// region with this clause.
   3011   /// \param PostUpdate Expression that must be executed after exit from the
   3012   /// OpenMP region with this clause.
   3013   static OMPReductionClause *
   3014   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   3015          SourceLocation ModifierLoc, SourceLocation ColonLoc,
   3016          SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
   3017          ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
   3018          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
   3019          ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
   3020          ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
   3021          ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
   3022          Stmt *PreInit, Expr *PostUpdate);
   3023 
   3024   /// Creates an empty clause with the place for \a N variables.
   3025   ///
   3026   /// \param C AST context.
   3027   /// \param N The number of variables.
   3028   /// \param Modifier Reduction modifier.
   3029   static OMPReductionClause *
   3030   CreateEmpty(const ASTContext &C, unsigned N,
   3031               OpenMPReductionClauseModifier Modifier);
   3032 
   3033   /// Returns modifier.
   3034   OpenMPReductionClauseModifier getModifier() const { return Modifier; }
   3035 
   3036   /// Returns modifier location.
   3037   SourceLocation getModifierLoc() const { return ModifierLoc; }
   3038 
   3039   /// Gets location of ':' symbol in clause.
   3040   SourceLocation getColonLoc() const { return ColonLoc; }
   3041 
   3042   /// Gets the name info for specified reduction identifier.
   3043   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
   3044 
   3045   /// Gets the nested name specifier.
   3046   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   3047 
   3048   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
   3049   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
   3050   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
   3051   using helper_expr_const_range =
   3052       llvm::iterator_range<helper_expr_const_iterator>;
   3053 
   3054   helper_expr_const_range privates() const {
   3055     return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
   3056   }
   3057 
   3058   helper_expr_range privates() {
   3059     return helper_expr_range(getPrivates().begin(), getPrivates().end());
   3060   }
   3061 
   3062   helper_expr_const_range lhs_exprs() const {
   3063     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
   3064   }
   3065 
   3066   helper_expr_range lhs_exprs() {
   3067     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
   3068   }
   3069 
   3070   helper_expr_const_range rhs_exprs() const {
   3071     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
   3072   }
   3073 
   3074   helper_expr_range rhs_exprs() {
   3075     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
   3076   }
   3077 
   3078   helper_expr_const_range reduction_ops() const {
   3079     return helper_expr_const_range(getReductionOps().begin(),
   3080                                    getReductionOps().end());
   3081   }
   3082 
   3083   helper_expr_range reduction_ops() {
   3084     return helper_expr_range(getReductionOps().begin(),
   3085                              getReductionOps().end());
   3086   }
   3087 
   3088   helper_expr_const_range copy_ops() const {
   3089     return helper_expr_const_range(getInscanCopyOps().begin(),
   3090                                    getInscanCopyOps().end());
   3091   }
   3092 
   3093   helper_expr_range copy_ops() {
   3094     return helper_expr_range(getInscanCopyOps().begin(),
   3095                              getInscanCopyOps().end());
   3096   }
   3097 
   3098   helper_expr_const_range copy_array_temps() const {
   3099     return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
   3100                                    getInscanCopyArrayTemps().end());
   3101   }
   3102 
   3103   helper_expr_range copy_array_temps() {
   3104     return helper_expr_range(getInscanCopyArrayTemps().begin(),
   3105                              getInscanCopyArrayTemps().end());
   3106   }
   3107 
   3108   helper_expr_const_range copy_array_elems() const {
   3109     return helper_expr_const_range(getInscanCopyArrayElems().begin(),
   3110                                    getInscanCopyArrayElems().end());
   3111   }
   3112 
   3113   helper_expr_range copy_array_elems() {
   3114     return helper_expr_range(getInscanCopyArrayElems().begin(),
   3115                              getInscanCopyArrayElems().end());
   3116   }
   3117 
   3118   child_range children() {
   3119     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   3120                        reinterpret_cast<Stmt **>(varlist_end()));
   3121   }
   3122 
   3123   const_child_range children() const {
   3124     auto Children = const_cast<OMPReductionClause *>(this)->children();
   3125     return const_child_range(Children.begin(), Children.end());
   3126   }
   3127 
   3128   child_range used_children() {
   3129     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   3130                        reinterpret_cast<Stmt **>(varlist_end()));
   3131   }
   3132   const_child_range used_children() const {
   3133     auto Children = const_cast<OMPReductionClause *>(this)->used_children();
   3134     return const_child_range(Children.begin(), Children.end());
   3135   }
   3136 
   3137   static bool classof(const OMPClause *T) {
   3138     return T->getClauseKind() == llvm::omp::OMPC_reduction;
   3139   }
   3140 };
   3141 
   3142 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
   3143 /// directives.
   3144 ///
   3145 /// \code
   3146 /// #pragma omp taskgroup task_reduction(+:a,b)
   3147 /// \endcode
   3148 /// In this example directive '#pragma omp taskgroup' has clause
   3149 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
   3150 class OMPTaskReductionClause final
   3151     : public OMPVarListClause<OMPTaskReductionClause>,
   3152       public OMPClauseWithPostUpdate,
   3153       private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
   3154   friend class OMPClauseReader;
   3155   friend OMPVarListClause;
   3156   friend TrailingObjects;
   3157 
   3158   /// Location of ':'.
   3159   SourceLocation ColonLoc;
   3160 
   3161   /// Nested name specifier for C++.
   3162   NestedNameSpecifierLoc QualifierLoc;
   3163 
   3164   /// Name of custom operator.
   3165   DeclarationNameInfo NameInfo;
   3166 
   3167   /// Build clause with number of variables \a N.
   3168   ///
   3169   /// \param StartLoc Starting location of the clause.
   3170   /// \param LParenLoc Location of '('.
   3171   /// \param EndLoc Ending location of the clause.
   3172   /// \param ColonLoc Location of ':'.
   3173   /// \param N Number of the variables in the clause.
   3174   /// \param QualifierLoc The nested-name qualifier with location information
   3175   /// \param NameInfo The full name info for reduction identifier.
   3176   OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   3177                          SourceLocation ColonLoc, SourceLocation EndLoc,
   3178                          unsigned N, NestedNameSpecifierLoc QualifierLoc,
   3179                          const DeclarationNameInfo &NameInfo)
   3180       : OMPVarListClause<OMPTaskReductionClause>(
   3181             llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
   3182         OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
   3183         QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
   3184 
   3185   /// Build an empty clause.
   3186   ///
   3187   /// \param N Number of variables.
   3188   explicit OMPTaskReductionClause(unsigned N)
   3189       : OMPVarListClause<OMPTaskReductionClause>(
   3190             llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
   3191             SourceLocation(), N),
   3192         OMPClauseWithPostUpdate(this) {}
   3193 
   3194   /// Sets location of ':' symbol in clause.
   3195   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
   3196 
   3197   /// Sets the name info for specified reduction identifier.
   3198   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
   3199 
   3200   /// Sets the nested name specifier.
   3201   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
   3202 
   3203   /// Set list of helper expressions, required for proper codegen of the clause.
   3204   /// These expressions represent private copy of the reduction variable.
   3205   void setPrivates(ArrayRef<Expr *> Privates);
   3206 
   3207   /// Get the list of helper privates.
   3208   MutableArrayRef<Expr *> getPrivates() {
   3209     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   3210   }
   3211   ArrayRef<const Expr *> getPrivates() const {
   3212     return llvm::makeArrayRef(varlist_end(), varlist_size());
   3213   }
   3214 
   3215   /// Set list of helper expressions, required for proper codegen of the clause.
   3216   /// These expressions represent LHS expression in the final reduction
   3217   /// expression performed by the reduction clause.
   3218   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
   3219 
   3220   /// Get the list of helper LHS expressions.
   3221   MutableArrayRef<Expr *> getLHSExprs() {
   3222     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
   3223   }
   3224   ArrayRef<const Expr *> getLHSExprs() const {
   3225     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
   3226   }
   3227 
   3228   /// Set list of helper expressions, required for proper codegen of the clause.
   3229   /// These expressions represent RHS expression in the final reduction
   3230   /// expression performed by the reduction clause. Also, variables in these
   3231   /// expressions are used for proper initialization of reduction copies.
   3232   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
   3233 
   3234   ///  Get the list of helper destination expressions.
   3235   MutableArrayRef<Expr *> getRHSExprs() {
   3236     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
   3237   }
   3238   ArrayRef<const Expr *> getRHSExprs() const {
   3239     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
   3240   }
   3241 
   3242   /// Set list of helper reduction expressions, required for proper
   3243   /// codegen of the clause. These expressions are binary expressions or
   3244   /// operator/custom reduction call that calculates new value from source
   3245   /// helper expressions to destination helper expressions.
   3246   void setReductionOps(ArrayRef<Expr *> ReductionOps);
   3247 
   3248   ///  Get the list of helper reduction expressions.
   3249   MutableArrayRef<Expr *> getReductionOps() {
   3250     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
   3251   }
   3252   ArrayRef<const Expr *> getReductionOps() const {
   3253     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
   3254   }
   3255 
   3256 public:
   3257   /// Creates clause with a list of variables \a VL.
   3258   ///
   3259   /// \param StartLoc Starting location of the clause.
   3260   /// \param LParenLoc Location of '('.
   3261   /// \param ColonLoc Location of ':'.
   3262   /// \param EndLoc Ending location of the clause.
   3263   /// \param VL The variables in the clause.
   3264   /// \param QualifierLoc The nested-name qualifier with location information
   3265   /// \param NameInfo The full name info for reduction identifier.
   3266   /// \param Privates List of helper expressions for proper generation of
   3267   /// private copies.
   3268   /// \param LHSExprs List of helper expressions for proper generation of
   3269   /// assignment operation required for copyprivate clause. This list represents
   3270   /// LHSs of the reduction expressions.
   3271   /// \param RHSExprs List of helper expressions for proper generation of
   3272   /// assignment operation required for copyprivate clause. This list represents
   3273   /// RHSs of the reduction expressions.
   3274   /// Also, variables in these expressions are used for proper initialization of
   3275   /// reduction copies.
   3276   /// \param ReductionOps List of helper expressions that represents reduction
   3277   /// expressions:
   3278   /// \code
   3279   /// LHSExprs binop RHSExprs;
   3280   /// operator binop(LHSExpr, RHSExpr);
   3281   /// <CutomReduction>(LHSExpr, RHSExpr);
   3282   /// \endcode
   3283   /// Required for proper codegen of final reduction operation performed by the
   3284   /// reduction clause.
   3285   /// \param PreInit Statement that must be executed before entering the OpenMP
   3286   /// region with this clause.
   3287   /// \param PostUpdate Expression that must be executed after exit from the
   3288   /// OpenMP region with this clause.
   3289   static OMPTaskReductionClause *
   3290   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   3291          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
   3292          NestedNameSpecifierLoc QualifierLoc,
   3293          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
   3294          ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
   3295          ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
   3296 
   3297   /// Creates an empty clause with the place for \a N variables.
   3298   ///
   3299   /// \param C AST context.
   3300   /// \param N The number of variables.
   3301   static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
   3302 
   3303   /// Gets location of ':' symbol in clause.
   3304   SourceLocation getColonLoc() const { return ColonLoc; }
   3305 
   3306   /// Gets the name info for specified reduction identifier.
   3307   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
   3308 
   3309   /// Gets the nested name specifier.
   3310   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   3311 
   3312   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
   3313   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
   3314   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
   3315   using helper_expr_const_range =
   3316       llvm::iterator_range<helper_expr_const_iterator>;
   3317 
   3318   helper_expr_const_range privates() const {
   3319     return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
   3320   }
   3321 
   3322   helper_expr_range privates() {
   3323     return helper_expr_range(getPrivates().begin(), getPrivates().end());
   3324   }
   3325 
   3326   helper_expr_const_range lhs_exprs() const {
   3327     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
   3328   }
   3329 
   3330   helper_expr_range lhs_exprs() {
   3331     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
   3332   }
   3333 
   3334   helper_expr_const_range rhs_exprs() const {
   3335     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
   3336   }
   3337 
   3338   helper_expr_range rhs_exprs() {
   3339     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
   3340   }
   3341 
   3342   helper_expr_const_range reduction_ops() const {
   3343     return helper_expr_const_range(getReductionOps().begin(),
   3344                                    getReductionOps().end());
   3345   }
   3346 
   3347   helper_expr_range reduction_ops() {
   3348     return helper_expr_range(getReductionOps().begin(),
   3349                              getReductionOps().end());
   3350   }
   3351 
   3352   child_range children() {
   3353     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   3354                        reinterpret_cast<Stmt **>(varlist_end()));
   3355   }
   3356 
   3357   const_child_range children() const {
   3358     auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
   3359     return const_child_range(Children.begin(), Children.end());
   3360   }
   3361 
   3362   child_range used_children() {
   3363     return child_range(child_iterator(), child_iterator());
   3364   }
   3365   const_child_range used_children() const {
   3366     return const_child_range(const_child_iterator(), const_child_iterator());
   3367   }
   3368 
   3369   static bool classof(const OMPClause *T) {
   3370     return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
   3371   }
   3372 };
   3373 
   3374 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
   3375 ///
   3376 /// \code
   3377 /// #pragma omp task in_reduction(+:a,b)
   3378 /// \endcode
   3379 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
   3380 /// operator '+' and the variables 'a' and 'b'.
   3381 class OMPInReductionClause final
   3382     : public OMPVarListClause<OMPInReductionClause>,
   3383       public OMPClauseWithPostUpdate,
   3384       private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
   3385   friend class OMPClauseReader;
   3386   friend OMPVarListClause;
   3387   friend TrailingObjects;
   3388 
   3389   /// Location of ':'.
   3390   SourceLocation ColonLoc;
   3391 
   3392   /// Nested name specifier for C++.
   3393   NestedNameSpecifierLoc QualifierLoc;
   3394 
   3395   /// Name of custom operator.
   3396   DeclarationNameInfo NameInfo;
   3397 
   3398   /// Build clause with number of variables \a N.
   3399   ///
   3400   /// \param StartLoc Starting location of the clause.
   3401   /// \param LParenLoc Location of '('.
   3402   /// \param EndLoc Ending location of the clause.
   3403   /// \param ColonLoc Location of ':'.
   3404   /// \param N Number of the variables in the clause.
   3405   /// \param QualifierLoc The nested-name qualifier with location information
   3406   /// \param NameInfo The full name info for reduction identifier.
   3407   OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   3408                        SourceLocation ColonLoc, SourceLocation EndLoc,
   3409                        unsigned N, NestedNameSpecifierLoc QualifierLoc,
   3410                        const DeclarationNameInfo &NameInfo)
   3411       : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
   3412                                                StartLoc, LParenLoc, EndLoc, N),
   3413         OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
   3414         QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
   3415 
   3416   /// Build an empty clause.
   3417   ///
   3418   /// \param N Number of variables.
   3419   explicit OMPInReductionClause(unsigned N)
   3420       : OMPVarListClause<OMPInReductionClause>(
   3421             llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
   3422             SourceLocation(), N),
   3423         OMPClauseWithPostUpdate(this) {}
   3424 
   3425   /// Sets location of ':' symbol in clause.
   3426   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
   3427 
   3428   /// Sets the name info for specified reduction identifier.
   3429   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
   3430 
   3431   /// Sets the nested name specifier.
   3432   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
   3433 
   3434   /// Set list of helper expressions, required for proper codegen of the clause.
   3435   /// These expressions represent private copy of the reduction variable.
   3436   void setPrivates(ArrayRef<Expr *> Privates);
   3437 
   3438   /// Get the list of helper privates.
   3439   MutableArrayRef<Expr *> getPrivates() {
   3440     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   3441   }
   3442   ArrayRef<const Expr *> getPrivates() const {
   3443     return llvm::makeArrayRef(varlist_end(), varlist_size());
   3444   }
   3445 
   3446   /// Set list of helper expressions, required for proper codegen of the clause.
   3447   /// These expressions represent LHS expression in the final reduction
   3448   /// expression performed by the reduction clause.
   3449   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
   3450 
   3451   /// Get the list of helper LHS expressions.
   3452   MutableArrayRef<Expr *> getLHSExprs() {
   3453     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
   3454   }
   3455   ArrayRef<const Expr *> getLHSExprs() const {
   3456     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
   3457   }
   3458 
   3459   /// Set list of helper expressions, required for proper codegen of the clause.
   3460   /// These expressions represent RHS expression in the final reduction
   3461   /// expression performed by the reduction clause. Also, variables in these
   3462   /// expressions are used for proper initialization of reduction copies.
   3463   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
   3464 
   3465   ///  Get the list of helper destination expressions.
   3466   MutableArrayRef<Expr *> getRHSExprs() {
   3467     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
   3468   }
   3469   ArrayRef<const Expr *> getRHSExprs() const {
   3470     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
   3471   }
   3472 
   3473   /// Set list of helper reduction expressions, required for proper
   3474   /// codegen of the clause. These expressions are binary expressions or
   3475   /// operator/custom reduction call that calculates new value from source
   3476   /// helper expressions to destination helper expressions.
   3477   void setReductionOps(ArrayRef<Expr *> ReductionOps);
   3478 
   3479   ///  Get the list of helper reduction expressions.
   3480   MutableArrayRef<Expr *> getReductionOps() {
   3481     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
   3482   }
   3483   ArrayRef<const Expr *> getReductionOps() const {
   3484     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
   3485   }
   3486 
   3487   /// Set list of helper reduction taskgroup descriptors.
   3488   void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
   3489 
   3490   ///  Get the list of helper reduction taskgroup descriptors.
   3491   MutableArrayRef<Expr *> getTaskgroupDescriptors() {
   3492     return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
   3493   }
   3494   ArrayRef<const Expr *> getTaskgroupDescriptors() const {
   3495     return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
   3496   }
   3497 
   3498 public:
   3499   /// Creates clause with a list of variables \a VL.
   3500   ///
   3501   /// \param StartLoc Starting location of the clause.
   3502   /// \param LParenLoc Location of '('.
   3503   /// \param ColonLoc Location of ':'.
   3504   /// \param EndLoc Ending location of the clause.
   3505   /// \param VL The variables in the clause.
   3506   /// \param QualifierLoc The nested-name qualifier with location information
   3507   /// \param NameInfo The full name info for reduction identifier.
   3508   /// \param Privates List of helper expressions for proper generation of
   3509   /// private copies.
   3510   /// \param LHSExprs List of helper expressions for proper generation of
   3511   /// assignment operation required for copyprivate clause. This list represents
   3512   /// LHSs of the reduction expressions.
   3513   /// \param RHSExprs List of helper expressions for proper generation of
   3514   /// assignment operation required for copyprivate clause. This list represents
   3515   /// RHSs of the reduction expressions.
   3516   /// Also, variables in these expressions are used for proper initialization of
   3517   /// reduction copies.
   3518   /// \param ReductionOps List of helper expressions that represents reduction
   3519   /// expressions:
   3520   /// \code
   3521   /// LHSExprs binop RHSExprs;
   3522   /// operator binop(LHSExpr, RHSExpr);
   3523   /// <CutomReduction>(LHSExpr, RHSExpr);
   3524   /// \endcode
   3525   /// Required for proper codegen of final reduction operation performed by the
   3526   /// reduction clause.
   3527   /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
   3528   /// corresponding items in parent taskgroup task_reduction clause.
   3529   /// \param PreInit Statement that must be executed before entering the OpenMP
   3530   /// region with this clause.
   3531   /// \param PostUpdate Expression that must be executed after exit from the
   3532   /// OpenMP region with this clause.
   3533   static OMPInReductionClause *
   3534   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   3535          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
   3536          NestedNameSpecifierLoc QualifierLoc,
   3537          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
   3538          ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
   3539          ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
   3540          Stmt *PreInit, Expr *PostUpdate);
   3541 
   3542   /// Creates an empty clause with the place for \a N variables.
   3543   ///
   3544   /// \param C AST context.
   3545   /// \param N The number of variables.
   3546   static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
   3547 
   3548   /// Gets location of ':' symbol in clause.
   3549   SourceLocation getColonLoc() const { return ColonLoc; }
   3550 
   3551   /// Gets the name info for specified reduction identifier.
   3552   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
   3553 
   3554   /// Gets the nested name specifier.
   3555   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   3556 
   3557   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
   3558   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
   3559   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
   3560   using helper_expr_const_range =
   3561       llvm::iterator_range<helper_expr_const_iterator>;
   3562 
   3563   helper_expr_const_range privates() const {
   3564     return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
   3565   }
   3566 
   3567   helper_expr_range privates() {
   3568     return helper_expr_range(getPrivates().begin(), getPrivates().end());
   3569   }
   3570 
   3571   helper_expr_const_range lhs_exprs() const {
   3572     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
   3573   }
   3574 
   3575   helper_expr_range lhs_exprs() {
   3576     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
   3577   }
   3578 
   3579   helper_expr_const_range rhs_exprs() const {
   3580     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
   3581   }
   3582 
   3583   helper_expr_range rhs_exprs() {
   3584     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
   3585   }
   3586 
   3587   helper_expr_const_range reduction_ops() const {
   3588     return helper_expr_const_range(getReductionOps().begin(),
   3589                                    getReductionOps().end());
   3590   }
   3591 
   3592   helper_expr_range reduction_ops() {
   3593     return helper_expr_range(getReductionOps().begin(),
   3594                              getReductionOps().end());
   3595   }
   3596 
   3597   helper_expr_const_range taskgroup_descriptors() const {
   3598     return helper_expr_const_range(getTaskgroupDescriptors().begin(),
   3599                                    getTaskgroupDescriptors().end());
   3600   }
   3601 
   3602   helper_expr_range taskgroup_descriptors() {
   3603     return helper_expr_range(getTaskgroupDescriptors().begin(),
   3604                              getTaskgroupDescriptors().end());
   3605   }
   3606 
   3607   child_range children() {
   3608     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   3609                        reinterpret_cast<Stmt **>(varlist_end()));
   3610   }
   3611 
   3612   const_child_range children() const {
   3613     auto Children = const_cast<OMPInReductionClause *>(this)->children();
   3614     return const_child_range(Children.begin(), Children.end());
   3615   }
   3616 
   3617   child_range used_children() {
   3618     return child_range(child_iterator(), child_iterator());
   3619   }
   3620   const_child_range used_children() const {
   3621     return const_child_range(const_child_iterator(), const_child_iterator());
   3622   }
   3623 
   3624   static bool classof(const OMPClause *T) {
   3625     return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
   3626   }
   3627 };
   3628 
   3629 /// This represents clause 'linear' in the '#pragma omp ...'
   3630 /// directives.
   3631 ///
   3632 /// \code
   3633 /// #pragma omp simd linear(a,b : 2)
   3634 /// \endcode
   3635 /// In this example directive '#pragma omp simd' has clause 'linear'
   3636 /// with variables 'a', 'b' and linear step '2'.
   3637 class OMPLinearClause final
   3638     : public OMPVarListClause<OMPLinearClause>,
   3639       public OMPClauseWithPostUpdate,
   3640       private llvm::TrailingObjects<OMPLinearClause, Expr *> {
   3641   friend class OMPClauseReader;
   3642   friend OMPVarListClause;
   3643   friend TrailingObjects;
   3644 
   3645   /// Modifier of 'linear' clause.
   3646   OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
   3647 
   3648   /// Location of linear modifier if any.
   3649   SourceLocation ModifierLoc;
   3650 
   3651   /// Location of ':'.
   3652   SourceLocation ColonLoc;
   3653 
   3654   /// Sets the linear step for clause.
   3655   void setStep(Expr *Step) { *(getFinals().end()) = Step; }
   3656 
   3657   /// Sets the expression to calculate linear step for clause.
   3658   void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
   3659 
   3660   /// Build 'linear' clause with given number of variables \a NumVars.
   3661   ///
   3662   /// \param StartLoc Starting location of the clause.
   3663   /// \param LParenLoc Location of '('.
   3664   /// \param ColonLoc Location of ':'.
   3665   /// \param EndLoc Ending location of the clause.
   3666   /// \param NumVars Number of variables.
   3667   OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   3668                   OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
   3669                   SourceLocation ColonLoc, SourceLocation EndLoc,
   3670                   unsigned NumVars)
   3671       : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
   3672                                           LParenLoc, EndLoc, NumVars),
   3673         OMPClauseWithPostUpdate(this), Modifier(Modifier),
   3674         ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
   3675 
   3676   /// Build an empty clause.
   3677   ///
   3678   /// \param NumVars Number of variables.
   3679   explicit OMPLinearClause(unsigned NumVars)
   3680       : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
   3681                                           SourceLocation(), SourceLocation(),
   3682                                           SourceLocation(), NumVars),
   3683         OMPClauseWithPostUpdate(this) {}
   3684 
   3685   /// Gets the list of initial values for linear variables.
   3686   ///
   3687   /// There are NumVars expressions with initial values allocated after the
   3688   /// varlist, they are followed by NumVars update expressions (used to update
   3689   /// the linear variable's value on current iteration) and they are followed by
   3690   /// NumVars final expressions (used to calculate the linear variable's
   3691   /// value after the loop body). After these lists, there are 2 helper
   3692   /// expressions - linear step and a helper to calculate it before the
   3693   /// loop body (used when the linear step is not constant):
   3694   ///
   3695   /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
   3696   /// Finals[]; Step; CalcStep; }
   3697   MutableArrayRef<Expr *> getPrivates() {
   3698     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   3699   }
   3700   ArrayRef<const Expr *> getPrivates() const {
   3701     return llvm::makeArrayRef(varlist_end(), varlist_size());
   3702   }
   3703 
   3704   MutableArrayRef<Expr *> getInits() {
   3705     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
   3706   }
   3707   ArrayRef<const Expr *> getInits() const {
   3708     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
   3709   }
   3710 
   3711   /// Sets the list of update expressions for linear variables.
   3712   MutableArrayRef<Expr *> getUpdates() {
   3713     return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
   3714   }
   3715   ArrayRef<const Expr *> getUpdates() const {
   3716     return llvm::makeArrayRef(getInits().end(), varlist_size());
   3717   }
   3718 
   3719   /// Sets the list of final update expressions for linear variables.
   3720   MutableArrayRef<Expr *> getFinals() {
   3721     return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
   3722   }
   3723   ArrayRef<const Expr *> getFinals() const {
   3724     return llvm::makeArrayRef(getUpdates().end(), varlist_size());
   3725   }
   3726 
   3727   /// Gets the list of used expressions for linear variables.
   3728   MutableArrayRef<Expr *> getUsedExprs() {
   3729     return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
   3730   }
   3731   ArrayRef<const Expr *> getUsedExprs() const {
   3732     return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
   3733   }
   3734 
   3735   /// Sets the list of the copies of original linear variables.
   3736   /// \param PL List of expressions.
   3737   void setPrivates(ArrayRef<Expr *> PL);
   3738 
   3739   /// Sets the list of the initial values for linear variables.
   3740   /// \param IL List of expressions.
   3741   void setInits(ArrayRef<Expr *> IL);
   3742 
   3743 public:
   3744   /// Creates clause with a list of variables \a VL and a linear step
   3745   /// \a Step.
   3746   ///
   3747   /// \param C AST Context.
   3748   /// \param StartLoc Starting location of the clause.
   3749   /// \param LParenLoc Location of '('.
   3750   /// \param Modifier Modifier of 'linear' clause.
   3751   /// \param ModifierLoc Modifier location.
   3752   /// \param ColonLoc Location of ':'.
   3753   /// \param EndLoc Ending location of the clause.
   3754   /// \param VL List of references to the variables.
   3755   /// \param PL List of private copies of original variables.
   3756   /// \param IL List of initial values for the variables.
   3757   /// \param Step Linear step.
   3758   /// \param CalcStep Calculation of the linear step.
   3759   /// \param PreInit Statement that must be executed before entering the OpenMP
   3760   /// region with this clause.
   3761   /// \param PostUpdate Expression that must be executed after exit from the
   3762   /// OpenMP region with this clause.
   3763   static OMPLinearClause *
   3764   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   3765          OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
   3766          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
   3767          ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
   3768          Stmt *PreInit, Expr *PostUpdate);
   3769 
   3770   /// Creates an empty clause with the place for \a NumVars variables.
   3771   ///
   3772   /// \param C AST context.
   3773   /// \param NumVars Number of variables.
   3774   static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
   3775 
   3776   /// Set modifier.
   3777   void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
   3778 
   3779   /// Return modifier.
   3780   OpenMPLinearClauseKind getModifier() const { return Modifier; }
   3781 
   3782   /// Set modifier location.
   3783   void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
   3784 
   3785   /// Return modifier location.
   3786   SourceLocation getModifierLoc() const { return ModifierLoc; }
   3787 
   3788   /// Sets the location of ':'.
   3789   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   3790 
   3791   /// Returns the location of ':'.
   3792   SourceLocation getColonLoc() const { return ColonLoc; }
   3793 
   3794   /// Returns linear step.
   3795   Expr *getStep() { return *(getFinals().end()); }
   3796 
   3797   /// Returns linear step.
   3798   const Expr *getStep() const { return *(getFinals().end()); }
   3799 
   3800   /// Returns expression to calculate linear step.
   3801   Expr *getCalcStep() { return *(getFinals().end() + 1); }
   3802 
   3803   /// Returns expression to calculate linear step.
   3804   const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
   3805 
   3806   /// Sets the list of update expressions for linear variables.
   3807   /// \param UL List of expressions.
   3808   void setUpdates(ArrayRef<Expr *> UL);
   3809 
   3810   /// Sets the list of final update expressions for linear variables.
   3811   /// \param FL List of expressions.
   3812   void setFinals(ArrayRef<Expr *> FL);
   3813 
   3814   /// Sets the list of used expressions for the linear clause.
   3815   void setUsedExprs(ArrayRef<Expr *> UE);
   3816 
   3817   using privates_iterator = MutableArrayRef<Expr *>::iterator;
   3818   using privates_const_iterator = ArrayRef<const Expr *>::iterator;
   3819   using privates_range = llvm::iterator_range<privates_iterator>;
   3820   using privates_const_range = llvm::iterator_range<privates_const_iterator>;
   3821 
   3822   privates_range privates() {
   3823     return privates_range(getPrivates().begin(), getPrivates().end());
   3824   }
   3825 
   3826   privates_const_range privates() const {
   3827     return privates_const_range(getPrivates().begin(), getPrivates().end());
   3828   }
   3829 
   3830   using inits_iterator = MutableArrayRef<Expr *>::iterator;
   3831   using inits_const_iterator = ArrayRef<const Expr *>::iterator;
   3832   using inits_range = llvm::iterator_range<inits_iterator>;
   3833   using inits_const_range = llvm::iterator_range<inits_const_iterator>;
   3834 
   3835   inits_range inits() {
   3836     return inits_range(getInits().begin(), getInits().end());
   3837   }
   3838 
   3839   inits_const_range inits() const {
   3840     return inits_const_range(getInits().begin(), getInits().end());
   3841   }
   3842 
   3843   using updates_iterator = MutableArrayRef<Expr *>::iterator;
   3844   using updates_const_iterator = ArrayRef<const Expr *>::iterator;
   3845   using updates_range = llvm::iterator_range<updates_iterator>;
   3846   using updates_const_range = llvm::iterator_range<updates_const_iterator>;
   3847 
   3848   updates_range updates() {
   3849     return updates_range(getUpdates().begin(), getUpdates().end());
   3850   }
   3851 
   3852   updates_const_range updates() const {
   3853     return updates_const_range(getUpdates().begin(), getUpdates().end());
   3854   }
   3855 
   3856   using finals_iterator = MutableArrayRef<Expr *>::iterator;
   3857   using finals_const_iterator = ArrayRef<const Expr *>::iterator;
   3858   using finals_range = llvm::iterator_range<finals_iterator>;
   3859   using finals_const_range = llvm::iterator_range<finals_const_iterator>;
   3860 
   3861   finals_range finals() {
   3862     return finals_range(getFinals().begin(), getFinals().end());
   3863   }
   3864 
   3865   finals_const_range finals() const {
   3866     return finals_const_range(getFinals().begin(), getFinals().end());
   3867   }
   3868 
   3869   using used_expressions_iterator = MutableArrayRef<Expr *>::iterator;
   3870   using used_expressions_const_iterator = ArrayRef<const Expr *>::iterator;
   3871   using used_expressions_range =
   3872       llvm::iterator_range<used_expressions_iterator>;
   3873   using used_expressions_const_range =
   3874       llvm::iterator_range<used_expressions_const_iterator>;
   3875 
   3876   used_expressions_range used_expressions() {
   3877     return finals_range(getUsedExprs().begin(), getUsedExprs().end());
   3878   }
   3879 
   3880   used_expressions_const_range used_expressions() const {
   3881     return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
   3882   }
   3883 
   3884   child_range children() {
   3885     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   3886                        reinterpret_cast<Stmt **>(varlist_end()));
   3887   }
   3888 
   3889   const_child_range children() const {
   3890     auto Children = const_cast<OMPLinearClause *>(this)->children();
   3891     return const_child_range(Children.begin(), Children.end());
   3892   }
   3893 
   3894   child_range used_children();
   3895 
   3896   const_child_range used_children() const {
   3897     auto Children = const_cast<OMPLinearClause *>(this)->used_children();
   3898     return const_child_range(Children.begin(), Children.end());
   3899   }
   3900 
   3901   static bool classof(const OMPClause *T) {
   3902     return T->getClauseKind() == llvm::omp::OMPC_linear;
   3903   }
   3904 };
   3905 
   3906 /// This represents clause 'aligned' in the '#pragma omp ...'
   3907 /// directives.
   3908 ///
   3909 /// \code
   3910 /// #pragma omp simd aligned(a,b : 8)
   3911 /// \endcode
   3912 /// In this example directive '#pragma omp simd' has clause 'aligned'
   3913 /// with variables 'a', 'b' and alignment '8'.
   3914 class OMPAlignedClause final
   3915     : public OMPVarListClause<OMPAlignedClause>,
   3916       private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
   3917   friend class OMPClauseReader;
   3918   friend OMPVarListClause;
   3919   friend TrailingObjects;
   3920 
   3921   /// Location of ':'.
   3922   SourceLocation ColonLoc;
   3923 
   3924   /// Sets the alignment for clause.
   3925   void setAlignment(Expr *A) { *varlist_end() = A; }
   3926 
   3927   /// Build 'aligned' clause with given number of variables \a NumVars.
   3928   ///
   3929   /// \param StartLoc Starting location of the clause.
   3930   /// \param LParenLoc Location of '('.
   3931   /// \param ColonLoc Location of ':'.
   3932   /// \param EndLoc Ending location of the clause.
   3933   /// \param NumVars Number of variables.
   3934   OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   3935                    SourceLocation ColonLoc, SourceLocation EndLoc,
   3936                    unsigned NumVars)
   3937       : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
   3938                                            LParenLoc, EndLoc, NumVars),
   3939         ColonLoc(ColonLoc) {}
   3940 
   3941   /// Build an empty clause.
   3942   ///
   3943   /// \param NumVars Number of variables.
   3944   explicit OMPAlignedClause(unsigned NumVars)
   3945       : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
   3946                                            SourceLocation(), SourceLocation(),
   3947                                            SourceLocation(), NumVars) {}
   3948 
   3949 public:
   3950   /// Creates clause with a list of variables \a VL and alignment \a A.
   3951   ///
   3952   /// \param C AST Context.
   3953   /// \param StartLoc Starting location of the clause.
   3954   /// \param LParenLoc Location of '('.
   3955   /// \param ColonLoc Location of ':'.
   3956   /// \param EndLoc Ending location of the clause.
   3957   /// \param VL List of references to the variables.
   3958   /// \param A Alignment.
   3959   static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
   3960                                   SourceLocation LParenLoc,
   3961                                   SourceLocation ColonLoc,
   3962                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
   3963                                   Expr *A);
   3964 
   3965   /// Creates an empty clause with the place for \a NumVars variables.
   3966   ///
   3967   /// \param C AST context.
   3968   /// \param NumVars Number of variables.
   3969   static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
   3970 
   3971   /// Sets the location of ':'.
   3972   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   3973 
   3974   /// Returns the location of ':'.
   3975   SourceLocation getColonLoc() const { return ColonLoc; }
   3976 
   3977   /// Returns alignment.
   3978   Expr *getAlignment() { return *varlist_end(); }
   3979 
   3980   /// Returns alignment.
   3981   const Expr *getAlignment() const { return *varlist_end(); }
   3982 
   3983   child_range children() {
   3984     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   3985                        reinterpret_cast<Stmt **>(varlist_end()));
   3986   }
   3987 
   3988   const_child_range children() const {
   3989     auto Children = const_cast<OMPAlignedClause *>(this)->children();
   3990     return const_child_range(Children.begin(), Children.end());
   3991   }
   3992 
   3993   child_range used_children() {
   3994     return child_range(child_iterator(), child_iterator());
   3995   }
   3996   const_child_range used_children() const {
   3997     return const_child_range(const_child_iterator(), const_child_iterator());
   3998   }
   3999 
   4000   static bool classof(const OMPClause *T) {
   4001     return T->getClauseKind() == llvm::omp::OMPC_aligned;
   4002   }
   4003 };
   4004 
   4005 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
   4006 ///
   4007 /// \code
   4008 /// #pragma omp parallel copyin(a,b)
   4009 /// \endcode
   4010 /// In this example directive '#pragma omp parallel' has clause 'copyin'
   4011 /// with the variables 'a' and 'b'.
   4012 class OMPCopyinClause final
   4013     : public OMPVarListClause<OMPCopyinClause>,
   4014       private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
   4015   // Class has 3 additional tail allocated arrays:
   4016   // 1. List of helper expressions for proper generation of assignment operation
   4017   // required for copyin clause. This list represents sources.
   4018   // 2. List of helper expressions for proper generation of assignment operation
   4019   // required for copyin clause. This list represents destinations.
   4020   // 3. List of helper expressions that represents assignment operation:
   4021   // \code
   4022   // DstExprs = SrcExprs;
   4023   // \endcode
   4024   // Required for proper codegen of propagation of master's thread values of
   4025   // threadprivate variables to local instances of that variables in other
   4026   // implicit threads.
   4027 
   4028   friend class OMPClauseReader;
   4029   friend OMPVarListClause;
   4030   friend TrailingObjects;
   4031 
   4032   /// Build clause with number of variables \a N.
   4033   ///
   4034   /// \param StartLoc Starting location of the clause.
   4035   /// \param LParenLoc Location of '('.
   4036   /// \param EndLoc Ending location of the clause.
   4037   /// \param N Number of the variables in the clause.
   4038   OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   4039                   SourceLocation EndLoc, unsigned N)
   4040       : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
   4041                                           LParenLoc, EndLoc, N) {}
   4042 
   4043   /// Build an empty clause.
   4044   ///
   4045   /// \param N Number of variables.
   4046   explicit OMPCopyinClause(unsigned N)
   4047       : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
   4048                                           SourceLocation(), SourceLocation(),
   4049                                           SourceLocation(), N) {}
   4050 
   4051   /// Set list of helper expressions, required for proper codegen of the
   4052   /// clause. These expressions represent source expression in the final
   4053   /// assignment statement performed by the copyin clause.
   4054   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
   4055 
   4056   /// Get the list of helper source expressions.
   4057   MutableArrayRef<Expr *> getSourceExprs() {
   4058     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   4059   }
   4060   ArrayRef<const Expr *> getSourceExprs() const {
   4061     return llvm::makeArrayRef(varlist_end(), varlist_size());
   4062   }
   4063 
   4064   /// Set list of helper expressions, required for proper codegen of the
   4065   /// clause. These expressions represent destination expression in the final
   4066   /// assignment statement performed by the copyin clause.
   4067   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
   4068 
   4069   /// Get the list of helper destination expressions.
   4070   MutableArrayRef<Expr *> getDestinationExprs() {
   4071     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
   4072   }
   4073   ArrayRef<const Expr *> getDestinationExprs() const {
   4074     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
   4075   }
   4076 
   4077   /// Set list of helper assignment expressions, required for proper
   4078   /// codegen of the clause. These expressions are assignment expressions that
   4079   /// assign source helper expressions to destination helper expressions
   4080   /// correspondingly.
   4081   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
   4082 
   4083   /// Get the list of helper assignment expressions.
   4084   MutableArrayRef<Expr *> getAssignmentOps() {
   4085     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
   4086   }
   4087   ArrayRef<const Expr *> getAssignmentOps() const {
   4088     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
   4089   }
   4090 
   4091 public:
   4092   /// Creates clause with a list of variables \a VL.
   4093   ///
   4094   /// \param C AST context.
   4095   /// \param StartLoc Starting location of the clause.
   4096   /// \param LParenLoc Location of '('.
   4097   /// \param EndLoc Ending location of the clause.
   4098   /// \param VL List of references to the variables.
   4099   /// \param SrcExprs List of helper expressions for proper generation of
   4100   /// assignment operation required for copyin clause. This list represents
   4101   /// sources.
   4102   /// \param DstExprs List of helper expressions for proper generation of
   4103   /// assignment operation required for copyin clause. This list represents
   4104   /// destinations.
   4105   /// \param AssignmentOps List of helper expressions that represents assignment
   4106   /// operation:
   4107   /// \code
   4108   /// DstExprs = SrcExprs;
   4109   /// \endcode
   4110   /// Required for proper codegen of propagation of master's thread values of
   4111   /// threadprivate variables to local instances of that variables in other
   4112   /// implicit threads.
   4113   static OMPCopyinClause *
   4114   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   4115          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
   4116          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
   4117 
   4118   /// Creates an empty clause with \a N variables.
   4119   ///
   4120   /// \param C AST context.
   4121   /// \param N The number of variables.
   4122   static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
   4123 
   4124   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
   4125   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
   4126   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
   4127   using helper_expr_const_range =
   4128       llvm::iterator_range<helper_expr_const_iterator>;
   4129 
   4130   helper_expr_const_range source_exprs() const {
   4131     return helper_expr_const_range(getSourceExprs().begin(),
   4132                                    getSourceExprs().end());
   4133   }
   4134 
   4135   helper_expr_range source_exprs() {
   4136     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
   4137   }
   4138 
   4139   helper_expr_const_range destination_exprs() const {
   4140     return helper_expr_const_range(getDestinationExprs().begin(),
   4141                                    getDestinationExprs().end());
   4142   }
   4143 
   4144   helper_expr_range destination_exprs() {
   4145     return helper_expr_range(getDestinationExprs().begin(),
   4146                              getDestinationExprs().end());
   4147   }
   4148 
   4149   helper_expr_const_range assignment_ops() const {
   4150     return helper_expr_const_range(getAssignmentOps().begin(),
   4151                                    getAssignmentOps().end());
   4152   }
   4153 
   4154   helper_expr_range assignment_ops() {
   4155     return helper_expr_range(getAssignmentOps().begin(),
   4156                              getAssignmentOps().end());
   4157   }
   4158 
   4159   child_range children() {
   4160     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   4161                        reinterpret_cast<Stmt **>(varlist_end()));
   4162   }
   4163 
   4164   const_child_range children() const {
   4165     auto Children = const_cast<OMPCopyinClause *>(this)->children();
   4166     return const_child_range(Children.begin(), Children.end());
   4167   }
   4168 
   4169   child_range used_children() {
   4170     return child_range(child_iterator(), child_iterator());
   4171   }
   4172   const_child_range used_children() const {
   4173     return const_child_range(const_child_iterator(), const_child_iterator());
   4174   }
   4175 
   4176   static bool classof(const OMPClause *T) {
   4177     return T->getClauseKind() == llvm::omp::OMPC_copyin;
   4178   }
   4179 };
   4180 
   4181 /// This represents clause 'copyprivate' in the '#pragma omp ...'
   4182 /// directives.
   4183 ///
   4184 /// \code
   4185 /// #pragma omp single copyprivate(a,b)
   4186 /// \endcode
   4187 /// In this example directive '#pragma omp single' has clause 'copyprivate'
   4188 /// with the variables 'a' and 'b'.
   4189 class OMPCopyprivateClause final
   4190     : public OMPVarListClause<OMPCopyprivateClause>,
   4191       private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
   4192   friend class OMPClauseReader;
   4193   friend OMPVarListClause;
   4194   friend TrailingObjects;
   4195 
   4196   /// Build clause with number of variables \a N.
   4197   ///
   4198   /// \param StartLoc Starting location of the clause.
   4199   /// \param LParenLoc Location of '('.
   4200   /// \param EndLoc Ending location of the clause.
   4201   /// \param N Number of the variables in the clause.
   4202   OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   4203                        SourceLocation EndLoc, unsigned N)
   4204       : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
   4205                                                StartLoc, LParenLoc, EndLoc, N) {
   4206   }
   4207 
   4208   /// Build an empty clause.
   4209   ///
   4210   /// \param N Number of variables.
   4211   explicit OMPCopyprivateClause(unsigned N)
   4212       : OMPVarListClause<OMPCopyprivateClause>(
   4213             llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
   4214             SourceLocation(), N) {}
   4215 
   4216   /// Set list of helper expressions, required for proper codegen of the
   4217   /// clause. These expressions represent source expression in the final
   4218   /// assignment statement performed by the copyprivate clause.
   4219   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
   4220 
   4221   /// Get the list of helper source expressions.
   4222   MutableArrayRef<Expr *> getSourceExprs() {
   4223     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   4224   }
   4225   ArrayRef<const Expr *> getSourceExprs() const {
   4226     return llvm::makeArrayRef(varlist_end(), varlist_size());
   4227   }
   4228 
   4229   /// Set list of helper expressions, required for proper codegen of the
   4230   /// clause. These expressions represent destination expression in the final
   4231   /// assignment statement performed by the copyprivate clause.
   4232   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
   4233 
   4234   /// Get the list of helper destination expressions.
   4235   MutableArrayRef<Expr *> getDestinationExprs() {
   4236     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
   4237   }
   4238   ArrayRef<const Expr *> getDestinationExprs() const {
   4239     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
   4240   }
   4241 
   4242   /// Set list of helper assignment expressions, required for proper
   4243   /// codegen of the clause. These expressions are assignment expressions that
   4244   /// assign source helper expressions to destination helper expressions
   4245   /// correspondingly.
   4246   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
   4247 
   4248   /// Get the list of helper assignment expressions.
   4249   MutableArrayRef<Expr *> getAssignmentOps() {
   4250     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
   4251   }
   4252   ArrayRef<const Expr *> getAssignmentOps() const {
   4253     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
   4254   }
   4255 
   4256 public:
   4257   /// Creates clause with a list of variables \a VL.
   4258   ///
   4259   /// \param C AST context.
   4260   /// \param StartLoc Starting location of the clause.
   4261   /// \param LParenLoc Location of '('.
   4262   /// \param EndLoc Ending location of the clause.
   4263   /// \param VL List of references to the variables.
   4264   /// \param SrcExprs List of helper expressions for proper generation of
   4265   /// assignment operation required for copyprivate clause. This list represents
   4266   /// sources.
   4267   /// \param DstExprs List of helper expressions for proper generation of
   4268   /// assignment operation required for copyprivate clause. This list represents
   4269   /// destinations.
   4270   /// \param AssignmentOps List of helper expressions that represents assignment
   4271   /// operation:
   4272   /// \code
   4273   /// DstExprs = SrcExprs;
   4274   /// \endcode
   4275   /// Required for proper codegen of final assignment performed by the
   4276   /// copyprivate clause.
   4277   static OMPCopyprivateClause *
   4278   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   4279          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
   4280          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
   4281 
   4282   /// Creates an empty clause with \a N variables.
   4283   ///
   4284   /// \param C AST context.
   4285   /// \param N The number of variables.
   4286   static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
   4287 
   4288   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
   4289   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
   4290   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
   4291   using helper_expr_const_range =
   4292       llvm::iterator_range<helper_expr_const_iterator>;
   4293 
   4294   helper_expr_const_range source_exprs() const {
   4295     return helper_expr_const_range(getSourceExprs().begin(),
   4296                                    getSourceExprs().end());
   4297   }
   4298 
   4299   helper_expr_range source_exprs() {
   4300     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
   4301   }
   4302 
   4303   helper_expr_const_range destination_exprs() const {
   4304     return helper_expr_const_range(getDestinationExprs().begin(),
   4305                                    getDestinationExprs().end());
   4306   }
   4307 
   4308   helper_expr_range destination_exprs() {
   4309     return helper_expr_range(getDestinationExprs().begin(),
   4310                              getDestinationExprs().end());
   4311   }
   4312 
   4313   helper_expr_const_range assignment_ops() const {
   4314     return helper_expr_const_range(getAssignmentOps().begin(),
   4315                                    getAssignmentOps().end());
   4316   }
   4317 
   4318   helper_expr_range assignment_ops() {
   4319     return helper_expr_range(getAssignmentOps().begin(),
   4320                              getAssignmentOps().end());
   4321   }
   4322 
   4323   child_range children() {
   4324     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   4325                        reinterpret_cast<Stmt **>(varlist_end()));
   4326   }
   4327 
   4328   const_child_range children() const {
   4329     auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
   4330     return const_child_range(Children.begin(), Children.end());
   4331   }
   4332 
   4333   child_range used_children() {
   4334     return child_range(child_iterator(), child_iterator());
   4335   }
   4336   const_child_range used_children() const {
   4337     return const_child_range(const_child_iterator(), const_child_iterator());
   4338   }
   4339 
   4340   static bool classof(const OMPClause *T) {
   4341     return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
   4342   }
   4343 };
   4344 
   4345 /// This represents implicit clause 'flush' for the '#pragma omp flush'
   4346 /// directive.
   4347 /// This clause does not exist by itself, it can be only as a part of 'omp
   4348 /// flush' directive. This clause is introduced to keep the original structure
   4349 /// of \a OMPExecutableDirective class and its derivatives and to use the
   4350 /// existing infrastructure of clauses with the list of variables.
   4351 ///
   4352 /// \code
   4353 /// #pragma omp flush(a,b)
   4354 /// \endcode
   4355 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
   4356 /// with the variables 'a' and 'b'.
   4357 class OMPFlushClause final
   4358     : public OMPVarListClause<OMPFlushClause>,
   4359       private llvm::TrailingObjects<OMPFlushClause, Expr *> {
   4360   friend OMPVarListClause;
   4361   friend TrailingObjects;
   4362 
   4363   /// Build clause with number of variables \a N.
   4364   ///
   4365   /// \param StartLoc Starting location of the clause.
   4366   /// \param LParenLoc Location of '('.
   4367   /// \param EndLoc Ending location of the clause.
   4368   /// \param N Number of the variables in the clause.
   4369   OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   4370                  SourceLocation EndLoc, unsigned N)
   4371       : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
   4372                                          LParenLoc, EndLoc, N) {}
   4373 
   4374   /// Build an empty clause.
   4375   ///
   4376   /// \param N Number of variables.
   4377   explicit OMPFlushClause(unsigned N)
   4378       : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
   4379                                          SourceLocation(), SourceLocation(),
   4380                                          SourceLocation(), N) {}
   4381 
   4382 public:
   4383   /// Creates clause with a list of variables \a VL.
   4384   ///
   4385   /// \param C AST context.
   4386   /// \param StartLoc Starting location of the clause.
   4387   /// \param LParenLoc Location of '('.
   4388   /// \param EndLoc Ending location of the clause.
   4389   /// \param VL List of references to the variables.
   4390   static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
   4391                                 SourceLocation LParenLoc, SourceLocation EndLoc,
   4392                                 ArrayRef<Expr *> VL);
   4393 
   4394   /// Creates an empty clause with \a N variables.
   4395   ///
   4396   /// \param C AST context.
   4397   /// \param N The number of variables.
   4398   static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
   4399 
   4400   child_range children() {
   4401     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   4402                        reinterpret_cast<Stmt **>(varlist_end()));
   4403   }
   4404 
   4405   const_child_range children() const {
   4406     auto Children = const_cast<OMPFlushClause *>(this)->children();
   4407     return const_child_range(Children.begin(), Children.end());
   4408   }
   4409 
   4410   child_range used_children() {
   4411     return child_range(child_iterator(), child_iterator());
   4412   }
   4413   const_child_range used_children() const {
   4414     return const_child_range(const_child_iterator(), const_child_iterator());
   4415   }
   4416 
   4417   static bool classof(const OMPClause *T) {
   4418     return T->getClauseKind() == llvm::omp::OMPC_flush;
   4419   }
   4420 };
   4421 
   4422 /// This represents implicit clause 'depobj' for the '#pragma omp depobj'
   4423 /// directive.
   4424 /// This clause does not exist by itself, it can be only as a part of 'omp
   4425 /// depobj' directive. This clause is introduced to keep the original structure
   4426 /// of \a OMPExecutableDirective class and its derivatives and to use the
   4427 /// existing infrastructure of clauses with the list of variables.
   4428 ///
   4429 /// \code
   4430 /// #pragma omp depobj(a) destroy
   4431 /// \endcode
   4432 /// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
   4433 /// with the depobj 'a'.
   4434 class OMPDepobjClause final : public OMPClause {
   4435   friend class OMPClauseReader;
   4436 
   4437   /// Location of '('.
   4438   SourceLocation LParenLoc;
   4439 
   4440   /// Chunk size.
   4441   Expr *Depobj = nullptr;
   4442 
   4443   /// Build clause with number of variables \a N.
   4444   ///
   4445   /// \param StartLoc Starting location of the clause.
   4446   /// \param LParenLoc Location of '('.
   4447   /// \param EndLoc Ending location of the clause.
   4448   OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   4449                   SourceLocation EndLoc)
   4450       : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
   4451         LParenLoc(LParenLoc) {}
   4452 
   4453   /// Build an empty clause.
   4454   ///
   4455   explicit OMPDepobjClause()
   4456       : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
   4457 
   4458   void setDepobj(Expr *E) { Depobj = E; }
   4459 
   4460   /// Sets the location of '('.
   4461   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   4462 
   4463 public:
   4464   /// Creates clause.
   4465   ///
   4466   /// \param C AST context.
   4467   /// \param StartLoc Starting location of the clause.
   4468   /// \param LParenLoc Location of '('.
   4469   /// \param EndLoc Ending location of the clause.
   4470   /// \param Depobj depobj expression associated with the 'depobj' directive.
   4471   static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc,
   4472                                  SourceLocation LParenLoc,
   4473                                  SourceLocation EndLoc, Expr *Depobj);
   4474 
   4475   /// Creates an empty clause.
   4476   ///
   4477   /// \param C AST context.
   4478   static OMPDepobjClause *CreateEmpty(const ASTContext &C);
   4479 
   4480   /// Returns depobj expression associated with the clause.
   4481   Expr *getDepobj() { return Depobj; }
   4482   const Expr *getDepobj() const { return Depobj; }
   4483 
   4484   /// Returns the location of '('.
   4485   SourceLocation getLParenLoc() const { return LParenLoc; }
   4486 
   4487   child_range children() {
   4488     return child_range(reinterpret_cast<Stmt **>(&Depobj),
   4489                        reinterpret_cast<Stmt **>(&Depobj) + 1);
   4490   }
   4491 
   4492   const_child_range children() const {
   4493     auto Children = const_cast<OMPDepobjClause *>(this)->children();
   4494     return const_child_range(Children.begin(), Children.end());
   4495   }
   4496 
   4497   child_range used_children() {
   4498     return child_range(child_iterator(), child_iterator());
   4499   }
   4500   const_child_range used_children() const {
   4501     return const_child_range(const_child_iterator(), const_child_iterator());
   4502   }
   4503 
   4504   static bool classof(const OMPClause *T) {
   4505     return T->getClauseKind() == llvm::omp::OMPC_depobj;
   4506   }
   4507 };
   4508 
   4509 /// This represents implicit clause 'depend' for the '#pragma omp task'
   4510 /// directive.
   4511 ///
   4512 /// \code
   4513 /// #pragma omp task depend(in:a,b)
   4514 /// \endcode
   4515 /// In this example directive '#pragma omp task' with clause 'depend' with the
   4516 /// variables 'a' and 'b' with dependency 'in'.
   4517 class OMPDependClause final
   4518     : public OMPVarListClause<OMPDependClause>,
   4519       private llvm::TrailingObjects<OMPDependClause, Expr *> {
   4520   friend class OMPClauseReader;
   4521   friend OMPVarListClause;
   4522   friend TrailingObjects;
   4523 
   4524   /// Dependency type (one of in, out, inout).
   4525   OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
   4526 
   4527   /// Dependency type location.
   4528   SourceLocation DepLoc;
   4529 
   4530   /// Colon location.
   4531   SourceLocation ColonLoc;
   4532 
   4533   /// Number of loops, associated with the depend clause.
   4534   unsigned NumLoops = 0;
   4535 
   4536   /// Build clause with number of variables \a N.
   4537   ///
   4538   /// \param StartLoc Starting location of the clause.
   4539   /// \param LParenLoc Location of '('.
   4540   /// \param EndLoc Ending location of the clause.
   4541   /// \param N Number of the variables in the clause.
   4542   /// \param NumLoops Number of loops that is associated with this depend
   4543   /// clause.
   4544   OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   4545                   SourceLocation EndLoc, unsigned N, unsigned NumLoops)
   4546       : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, StartLoc,
   4547                                           LParenLoc, EndLoc, N),
   4548         NumLoops(NumLoops) {}
   4549 
   4550   /// Build an empty clause.
   4551   ///
   4552   /// \param N Number of variables.
   4553   /// \param NumLoops Number of loops that is associated with this depend
   4554   /// clause.
   4555   explicit OMPDependClause(unsigned N, unsigned NumLoops)
   4556       : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend,
   4557                                           SourceLocation(), SourceLocation(),
   4558                                           SourceLocation(), N),
   4559         NumLoops(NumLoops) {}
   4560 
   4561   /// Set dependency kind.
   4562   void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
   4563 
   4564   /// Set dependency kind and its location.
   4565   void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
   4566 
   4567   /// Set colon location.
   4568   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   4569 
   4570   /// Sets optional dependency modifier.
   4571   void setModifier(Expr *DepModifier);
   4572 
   4573 public:
   4574   /// Creates clause with a list of variables \a VL.
   4575   ///
   4576   /// \param C AST context.
   4577   /// \param StartLoc Starting location of the clause.
   4578   /// \param LParenLoc Location of '('.
   4579   /// \param EndLoc Ending location of the clause.
   4580   /// \param DepKind Dependency type.
   4581   /// \param DepLoc Location of the dependency type.
   4582   /// \param ColonLoc Colon location.
   4583   /// \param VL List of references to the variables.
   4584   /// \param NumLoops Number of loops that is associated with this depend
   4585   /// clause.
   4586   static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
   4587                                  SourceLocation LParenLoc,
   4588                                  SourceLocation EndLoc, Expr *DepModifier,
   4589                                  OpenMPDependClauseKind DepKind,
   4590                                  SourceLocation DepLoc, SourceLocation ColonLoc,
   4591                                  ArrayRef<Expr *> VL, unsigned NumLoops);
   4592 
   4593   /// Creates an empty clause with \a N variables.
   4594   ///
   4595   /// \param C AST context.
   4596   /// \param N The number of variables.
   4597   /// \param NumLoops Number of loops that is associated with this depend
   4598   /// clause.
   4599   static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
   4600                                       unsigned NumLoops);
   4601 
   4602   /// Get dependency type.
   4603   OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
   4604 
   4605   /// Return optional depend modifier.
   4606   Expr *getModifier();
   4607   const Expr *getModifier() const {
   4608     return const_cast<OMPDependClause *>(this)->getModifier();
   4609   }
   4610 
   4611   /// Get dependency type location.
   4612   SourceLocation getDependencyLoc() const { return DepLoc; }
   4613 
   4614   /// Get colon location.
   4615   SourceLocation getColonLoc() const { return ColonLoc; }
   4616 
   4617   /// Get number of loops associated with the clause.
   4618   unsigned getNumLoops() const { return NumLoops; }
   4619 
   4620   /// Set the loop data for the depend clauses with 'sink|source' kind of
   4621   /// dependency.
   4622   void setLoopData(unsigned NumLoop, Expr *Cnt);
   4623 
   4624   /// Get the loop data.
   4625   Expr *getLoopData(unsigned NumLoop);
   4626   const Expr *getLoopData(unsigned NumLoop) const;
   4627 
   4628   child_range children() {
   4629     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   4630                        reinterpret_cast<Stmt **>(varlist_end()));
   4631   }
   4632 
   4633   const_child_range children() const {
   4634     auto Children = const_cast<OMPDependClause *>(this)->children();
   4635     return const_child_range(Children.begin(), Children.end());
   4636   }
   4637 
   4638   child_range used_children() {
   4639     return child_range(child_iterator(), child_iterator());
   4640   }
   4641   const_child_range used_children() const {
   4642     return const_child_range(const_child_iterator(), const_child_iterator());
   4643   }
   4644 
   4645   static bool classof(const OMPClause *T) {
   4646     return T->getClauseKind() == llvm::omp::OMPC_depend;
   4647   }
   4648 };
   4649 
   4650 /// This represents 'device' clause in the '#pragma omp ...'
   4651 /// directive.
   4652 ///
   4653 /// \code
   4654 /// #pragma omp target device(a)
   4655 /// \endcode
   4656 /// In this example directive '#pragma omp target' has clause 'device'
   4657 /// with single expression 'a'.
   4658 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
   4659   friend class OMPClauseReader;
   4660 
   4661   /// Location of '('.
   4662   SourceLocation LParenLoc;
   4663 
   4664   /// Device clause modifier.
   4665   OpenMPDeviceClauseModifier Modifier = OMPC_DEVICE_unknown;
   4666 
   4667   /// Location of the modifier.
   4668   SourceLocation ModifierLoc;
   4669 
   4670   /// Device number.
   4671   Stmt *Device = nullptr;
   4672 
   4673   /// Set the device number.
   4674   ///
   4675   /// \param E Device number.
   4676   void setDevice(Expr *E) { Device = E; }
   4677 
   4678   /// Sets modifier.
   4679   void setModifier(OpenMPDeviceClauseModifier M) { Modifier = M; }
   4680 
   4681   /// Setst modifier location.
   4682   void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
   4683 
   4684 public:
   4685   /// Build 'device' clause.
   4686   ///
   4687   /// \param Modifier Clause modifier.
   4688   /// \param E Expression associated with this clause.
   4689   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   4690   /// clause must be captured.
   4691   /// \param StartLoc Starting location of the clause.
   4692   /// \param ModifierLoc Modifier location.
   4693   /// \param LParenLoc Location of '('.
   4694   /// \param EndLoc Ending location of the clause.
   4695   OMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *E, Stmt *HelperE,
   4696                   OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
   4697                   SourceLocation LParenLoc, SourceLocation ModifierLoc,
   4698                   SourceLocation EndLoc)
   4699       : OMPClause(llvm::omp::OMPC_device, StartLoc, EndLoc),
   4700         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
   4701         ModifierLoc(ModifierLoc), Device(E) {
   4702     setPreInitStmt(HelperE, CaptureRegion);
   4703   }
   4704 
   4705   /// Build an empty clause.
   4706   OMPDeviceClause()
   4707       : OMPClause(llvm::omp::OMPC_device, SourceLocation(), SourceLocation()),
   4708         OMPClauseWithPreInit(this) {}
   4709 
   4710   /// Sets the location of '('.
   4711   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   4712 
   4713   /// Returns the location of '('.
   4714   SourceLocation getLParenLoc() const { return LParenLoc; }
   4715 
   4716   /// Return device number.
   4717   Expr *getDevice() { return cast<Expr>(Device); }
   4718 
   4719   /// Return device number.
   4720   Expr *getDevice() const { return cast<Expr>(Device); }
   4721 
   4722   /// Gets modifier.
   4723   OpenMPDeviceClauseModifier getModifier() const { return Modifier; }
   4724 
   4725   /// Gets modifier location.
   4726   SourceLocation getModifierLoc() const { return ModifierLoc; }
   4727 
   4728   child_range children() { return child_range(&Device, &Device + 1); }
   4729 
   4730   const_child_range children() const {
   4731     return const_child_range(&Device, &Device + 1);
   4732   }
   4733 
   4734   child_range used_children() {
   4735     return child_range(child_iterator(), child_iterator());
   4736   }
   4737   const_child_range used_children() const {
   4738     return const_child_range(const_child_iterator(), const_child_iterator());
   4739   }
   4740 
   4741   static bool classof(const OMPClause *T) {
   4742     return T->getClauseKind() == llvm::omp::OMPC_device;
   4743   }
   4744 };
   4745 
   4746 /// This represents 'threads' clause in the '#pragma omp ...' directive.
   4747 ///
   4748 /// \code
   4749 /// #pragma omp ordered threads
   4750 /// \endcode
   4751 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
   4752 class OMPThreadsClause : public OMPClause {
   4753 public:
   4754   /// Build 'threads' clause.
   4755   ///
   4756   /// \param StartLoc Starting location of the clause.
   4757   /// \param EndLoc Ending location of the clause.
   4758   OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
   4759       : OMPClause(llvm::omp::OMPC_threads, StartLoc, EndLoc) {}
   4760 
   4761   /// Build an empty clause.
   4762   OMPThreadsClause()
   4763       : OMPClause(llvm::omp::OMPC_threads, SourceLocation(), SourceLocation()) {
   4764   }
   4765 
   4766   child_range children() {
   4767     return child_range(child_iterator(), child_iterator());
   4768   }
   4769 
   4770   const_child_range children() const {
   4771     return const_child_range(const_child_iterator(), const_child_iterator());
   4772   }
   4773 
   4774   child_range used_children() {
   4775     return child_range(child_iterator(), child_iterator());
   4776   }
   4777   const_child_range used_children() const {
   4778     return const_child_range(const_child_iterator(), const_child_iterator());
   4779   }
   4780 
   4781   static bool classof(const OMPClause *T) {
   4782     return T->getClauseKind() == llvm::omp::OMPC_threads;
   4783   }
   4784 };
   4785 
   4786 /// This represents 'simd' clause in the '#pragma omp ...' directive.
   4787 ///
   4788 /// \code
   4789 /// #pragma omp ordered simd
   4790 /// \endcode
   4791 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
   4792 class OMPSIMDClause : public OMPClause {
   4793 public:
   4794   /// Build 'simd' clause.
   4795   ///
   4796   /// \param StartLoc Starting location of the clause.
   4797   /// \param EndLoc Ending location of the clause.
   4798   OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
   4799       : OMPClause(llvm::omp::OMPC_simd, StartLoc, EndLoc) {}
   4800 
   4801   /// Build an empty clause.
   4802   OMPSIMDClause()
   4803       : OMPClause(llvm::omp::OMPC_simd, SourceLocation(), SourceLocation()) {}
   4804 
   4805   child_range children() {
   4806     return child_range(child_iterator(), child_iterator());
   4807   }
   4808 
   4809   const_child_range children() const {
   4810     return const_child_range(const_child_iterator(), const_child_iterator());
   4811   }
   4812 
   4813   child_range used_children() {
   4814     return child_range(child_iterator(), child_iterator());
   4815   }
   4816   const_child_range used_children() const {
   4817     return const_child_range(const_child_iterator(), const_child_iterator());
   4818   }
   4819 
   4820   static bool classof(const OMPClause *T) {
   4821     return T->getClauseKind() == llvm::omp::OMPC_simd;
   4822   }
   4823 };
   4824 
   4825 /// Struct that defines common infrastructure to handle mappable
   4826 /// expressions used in OpenMP clauses.
   4827 class OMPClauseMappableExprCommon {
   4828 public:
   4829   /// Class that represents a component of a mappable expression. E.g.
   4830   /// for an expression S.a, the first component is a declaration reference
   4831   /// expression associated with 'S' and the second is a member expression
   4832   /// associated with the field declaration 'a'. If the expression is an array
   4833   /// subscript it may not have any associated declaration. In that case the
   4834   /// associated declaration is set to nullptr.
   4835   class MappableComponent {
   4836     /// Pair of Expression and Non-contiguous pair  associated with the
   4837     /// component.
   4838     llvm::PointerIntPair<Expr *, 1, bool> AssociatedExpressionNonContiguousPr;
   4839 
   4840     /// Declaration associated with the declaration. If the component does
   4841     /// not have a declaration (e.g. array subscripts or section), this is set
   4842     /// to nullptr.
   4843     ValueDecl *AssociatedDeclaration = nullptr;
   4844 
   4845   public:
   4846     explicit MappableComponent() = default;
   4847     explicit MappableComponent(Expr *AssociatedExpression,
   4848                                ValueDecl *AssociatedDeclaration,
   4849                                bool IsNonContiguous)
   4850         : AssociatedExpressionNonContiguousPr(AssociatedExpression,
   4851                                               IsNonContiguous),
   4852           AssociatedDeclaration(
   4853               AssociatedDeclaration
   4854                   ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
   4855                   : nullptr) {}
   4856 
   4857     Expr *getAssociatedExpression() const {
   4858       return AssociatedExpressionNonContiguousPr.getPointer();
   4859     }
   4860 
   4861     bool isNonContiguous() const {
   4862       return AssociatedExpressionNonContiguousPr.getInt();
   4863     }
   4864 
   4865     ValueDecl *getAssociatedDeclaration() const {
   4866       return AssociatedDeclaration;
   4867     }
   4868   };
   4869 
   4870   // List of components of an expression. This first one is the whole
   4871   // expression and the last one is the base expression.
   4872   using MappableExprComponentList = SmallVector<MappableComponent, 8>;
   4873   using MappableExprComponentListRef = ArrayRef<MappableComponent>;
   4874 
   4875   // List of all component lists associated to the same base declaration.
   4876   // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
   4877   // their component list but the same base declaration 'S'.
   4878   using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
   4879   using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
   4880 
   4881 protected:
   4882   // Return the total number of elements in a list of component lists.
   4883   static unsigned
   4884   getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
   4885 
   4886   // Return the total number of elements in a list of declarations. All
   4887   // declarations are expected to be canonical.
   4888   static unsigned
   4889   getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
   4890 };
   4891 
   4892 /// This structure contains all sizes needed for by an
   4893 /// OMPMappableExprListClause.
   4894 struct OMPMappableExprListSizeTy {
   4895   /// Number of expressions listed.
   4896   unsigned NumVars;
   4897   /// Number of unique base declarations.
   4898   unsigned NumUniqueDeclarations;
   4899   /// Number of component lists.
   4900   unsigned NumComponentLists;
   4901   /// Total number of expression components.
   4902   unsigned NumComponents;
   4903   OMPMappableExprListSizeTy() = default;
   4904   OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations,
   4905                             unsigned NumComponentLists, unsigned NumComponents)
   4906       : NumVars(NumVars), NumUniqueDeclarations(NumUniqueDeclarations),
   4907         NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
   4908 };
   4909 
   4910 /// This represents clauses with a list of expressions that are mappable.
   4911 /// Examples of these clauses are 'map' in
   4912 /// '#pragma omp target [enter|exit] [data]...' directives, and  'to' and 'from
   4913 /// in '#pragma omp target update...' directives.
   4914 template <class T>
   4915 class OMPMappableExprListClause : public OMPVarListClause<T>,
   4916                                   public OMPClauseMappableExprCommon {
   4917   friend class OMPClauseReader;
   4918 
   4919   /// Number of unique declarations in this clause.
   4920   unsigned NumUniqueDeclarations;
   4921 
   4922   /// Number of component lists in this clause.
   4923   unsigned NumComponentLists;
   4924 
   4925   /// Total number of components in this clause.
   4926   unsigned NumComponents;
   4927 
   4928   /// Whether this clause is possible to have user-defined mappers associated.
   4929   /// It should be true for map, to, and from clauses, and false for
   4930   /// use_device_ptr and is_device_ptr.
   4931   const bool SupportsMapper;
   4932 
   4933   /// C++ nested name specifier for the associated user-defined mapper.
   4934   NestedNameSpecifierLoc MapperQualifierLoc;
   4935 
   4936   /// The associated user-defined mapper identifier information.
   4937   DeclarationNameInfo MapperIdInfo;
   4938 
   4939 protected:
   4940   /// Build a clause for \a NumUniqueDeclarations declarations, \a
   4941   /// NumComponentLists total component lists, and \a NumComponents total
   4942   /// components.
   4943   ///
   4944   /// \param K Kind of the clause.
   4945   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   4946   /// StartLoc: starting location of the clause (the clause keyword); 2)
   4947   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   4948   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   4949   /// NumVars: number of expressions listed in this clause; 2)
   4950   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   4951   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   4952   /// NumComponents: total number of expression components in the clause.
   4953   /// \param SupportsMapper Indicates whether this clause is possible to have
   4954   /// user-defined mappers associated.
   4955   /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
   4956   /// user-defined mapper.
   4957   /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
   4958   OMPMappableExprListClause(
   4959       OpenMPClauseKind K, const OMPVarListLocTy &Locs,
   4960       const OMPMappableExprListSizeTy &Sizes, bool SupportsMapper = false,
   4961       NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
   4962       DeclarationNameInfo *MapperIdInfoPtr = nullptr)
   4963       : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
   4964                             Sizes.NumVars),
   4965         NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
   4966         NumComponentLists(Sizes.NumComponentLists),
   4967         NumComponents(Sizes.NumComponents), SupportsMapper(SupportsMapper) {
   4968     if (MapperQualifierLocPtr)
   4969       MapperQualifierLoc = *MapperQualifierLocPtr;
   4970     if (MapperIdInfoPtr)
   4971       MapperIdInfo = *MapperIdInfoPtr;
   4972   }
   4973 
   4974   /// Get the unique declarations that are in the trailing objects of the
   4975   /// class.
   4976   MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
   4977     return MutableArrayRef<ValueDecl *>(
   4978         static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
   4979         NumUniqueDeclarations);
   4980   }
   4981 
   4982   /// Get the unique declarations that are in the trailing objects of the
   4983   /// class.
   4984   ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
   4985     return ArrayRef<ValueDecl *>(
   4986         static_cast<const T *>(this)
   4987             ->template getTrailingObjects<ValueDecl *>(),
   4988         NumUniqueDeclarations);
   4989   }
   4990 
   4991   /// Set the unique declarations that are in the trailing objects of the
   4992   /// class.
   4993   void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
   4994     assert(UDs.size() == NumUniqueDeclarations &&
   4995            "Unexpected amount of unique declarations.");
   4996     std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
   4997   }
   4998 
   4999   /// Get the number of lists per declaration that are in the trailing
   5000   /// objects of the class.
   5001   MutableArrayRef<unsigned> getDeclNumListsRef() {
   5002     return MutableArrayRef<unsigned>(
   5003         static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
   5004         NumUniqueDeclarations);
   5005   }
   5006 
   5007   /// Get the number of lists per declaration that are in the trailing
   5008   /// objects of the class.
   5009   ArrayRef<unsigned> getDeclNumListsRef() const {
   5010     return ArrayRef<unsigned>(
   5011         static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
   5012         NumUniqueDeclarations);
   5013   }
   5014 
   5015   /// Set the number of lists per declaration that are in the trailing
   5016   /// objects of the class.
   5017   void setDeclNumLists(ArrayRef<unsigned> DNLs) {
   5018     assert(DNLs.size() == NumUniqueDeclarations &&
   5019            "Unexpected amount of list numbers.");
   5020     std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
   5021   }
   5022 
   5023   /// Get the cumulative component lists sizes that are in the trailing
   5024   /// objects of the class. They are appended after the number of lists.
   5025   MutableArrayRef<unsigned> getComponentListSizesRef() {
   5026     return MutableArrayRef<unsigned>(
   5027         static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
   5028             NumUniqueDeclarations,
   5029         NumComponentLists);
   5030   }
   5031 
   5032   /// Get the cumulative component lists sizes that are in the trailing
   5033   /// objects of the class. They are appended after the number of lists.
   5034   ArrayRef<unsigned> getComponentListSizesRef() const {
   5035     return ArrayRef<unsigned>(
   5036         static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
   5037             NumUniqueDeclarations,
   5038         NumComponentLists);
   5039   }
   5040 
   5041   /// Set the cumulative component lists sizes that are in the trailing
   5042   /// objects of the class.
   5043   void setComponentListSizes(ArrayRef<unsigned> CLSs) {
   5044     assert(CLSs.size() == NumComponentLists &&
   5045            "Unexpected amount of component lists.");
   5046     std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
   5047   }
   5048 
   5049   /// Get the components that are in the trailing objects of the class.
   5050   MutableArrayRef<MappableComponent> getComponentsRef() {
   5051     return MutableArrayRef<MappableComponent>(
   5052         static_cast<T *>(this)
   5053             ->template getTrailingObjects<MappableComponent>(),
   5054         NumComponents);
   5055   }
   5056 
   5057   /// Get the components that are in the trailing objects of the class.
   5058   ArrayRef<MappableComponent> getComponentsRef() const {
   5059     return ArrayRef<MappableComponent>(
   5060         static_cast<const T *>(this)
   5061             ->template getTrailingObjects<MappableComponent>(),
   5062         NumComponents);
   5063   }
   5064 
   5065   /// Set the components that are in the trailing objects of the class.
   5066   /// This requires the list sizes so that it can also fill the original
   5067   /// expressions, which are the first component of each list.
   5068   void setComponents(ArrayRef<MappableComponent> Components,
   5069                      ArrayRef<unsigned> CLSs) {
   5070     assert(Components.size() == NumComponents &&
   5071            "Unexpected amount of component lists.");
   5072     assert(CLSs.size() == NumComponentLists &&
   5073            "Unexpected amount of list sizes.");
   5074     std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
   5075   }
   5076 
   5077   /// Fill the clause information from the list of declarations and
   5078   /// associated component lists.
   5079   void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
   5080                      MappableExprComponentListsRef ComponentLists) {
   5081     // Perform some checks to make sure the data sizes are consistent with the
   5082     // information available when the clause was created.
   5083     assert(getUniqueDeclarationsTotalNumber(Declarations) ==
   5084                NumUniqueDeclarations &&
   5085            "Unexpected number of mappable expression info entries!");
   5086     assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
   5087            "Unexpected total number of components!");
   5088     assert(Declarations.size() == ComponentLists.size() &&
   5089            "Declaration and component lists size is not consistent!");
   5090     assert(Declarations.size() == NumComponentLists &&
   5091            "Unexpected declaration and component lists size!");
   5092 
   5093     // Organize the components by declaration and retrieve the original
   5094     // expression. Original expressions are always the first component of the
   5095     // mappable component list.
   5096     llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
   5097         ComponentListMap;
   5098     {
   5099       auto CI = ComponentLists.begin();
   5100       for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
   5101            ++DI, ++CI) {
   5102         assert(!CI->empty() && "Invalid component list!");
   5103         ComponentListMap[*DI].push_back(*CI);
   5104       }
   5105     }
   5106 
   5107     // Iterators of the target storage.
   5108     auto UniqueDeclarations = getUniqueDeclsRef();
   5109     auto UDI = UniqueDeclarations.begin();
   5110 
   5111     auto DeclNumLists = getDeclNumListsRef();
   5112     auto DNLI = DeclNumLists.begin();
   5113 
   5114     auto ComponentListSizes = getComponentListSizesRef();
   5115     auto CLSI = ComponentListSizes.begin();
   5116 
   5117     auto Components = getComponentsRef();
   5118     auto CI = Components.begin();
   5119 
   5120     // Variable to compute the accumulation of the number of components.
   5121     unsigned PrevSize = 0u;
   5122 
   5123     // Scan all the declarations and associated component lists.
   5124     for (auto &M : ComponentListMap) {
   5125       // The declaration.
   5126       auto *D = M.first;
   5127       // The component lists.
   5128       auto CL = M.second;
   5129 
   5130       // Initialize the entry.
   5131       *UDI = D;
   5132       ++UDI;
   5133 
   5134       *DNLI = CL.size();
   5135       ++DNLI;
   5136 
   5137       // Obtain the cumulative sizes and concatenate all the components in the
   5138       // reserved storage.
   5139       for (auto C : CL) {
   5140         // Accumulate with the previous size.
   5141         PrevSize += C.size();
   5142 
   5143         // Save the size.
   5144         *CLSI = PrevSize;
   5145         ++CLSI;
   5146 
   5147         // Append components after the current components iterator.
   5148         CI = std::copy(C.begin(), C.end(), CI);
   5149       }
   5150     }
   5151   }
   5152 
   5153   /// Set the nested name specifier of associated user-defined mapper.
   5154   void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) {
   5155     MapperQualifierLoc = NNSL;
   5156   }
   5157 
   5158   /// Set the name of associated user-defined mapper.
   5159   void setMapperIdInfo(DeclarationNameInfo MapperId) {
   5160     MapperIdInfo = MapperId;
   5161   }
   5162 
   5163   /// Get the user-defined mapper references that are in the trailing objects of
   5164   /// the class.
   5165   MutableArrayRef<Expr *> getUDMapperRefs() {
   5166     assert(SupportsMapper &&
   5167            "Must be a clause that is possible to have user-defined mappers");
   5168     return llvm::makeMutableArrayRef<Expr *>(
   5169         static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
   5170             OMPVarListClause<T>::varlist_size(),
   5171         OMPVarListClause<T>::varlist_size());
   5172   }
   5173 
   5174   /// Get the user-defined mappers references that are in the trailing objects
   5175   /// of the class.
   5176   ArrayRef<Expr *> getUDMapperRefs() const {
   5177     assert(SupportsMapper &&
   5178            "Must be a clause that is possible to have user-defined mappers");
   5179     return llvm::makeArrayRef<Expr *>(
   5180         static_cast<const T *>(this)->template getTrailingObjects<Expr *>() +
   5181             OMPVarListClause<T>::varlist_size(),
   5182         OMPVarListClause<T>::varlist_size());
   5183   }
   5184 
   5185   /// Set the user-defined mappers that are in the trailing objects of the
   5186   /// class.
   5187   void setUDMapperRefs(ArrayRef<Expr *> DMDs) {
   5188     assert(DMDs.size() == OMPVarListClause<T>::varlist_size() &&
   5189            "Unexpected number of user-defined mappers.");
   5190     assert(SupportsMapper &&
   5191            "Must be a clause that is possible to have user-defined mappers");
   5192     std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin());
   5193   }
   5194 
   5195 public:
   5196   /// Return the number of unique base declarations in this clause.
   5197   unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
   5198 
   5199   /// Return the number of lists derived from the clause expressions.
   5200   unsigned getTotalComponentListNum() const { return NumComponentLists; }
   5201 
   5202   /// Return the total number of components in all lists derived from the
   5203   /// clause.
   5204   unsigned getTotalComponentsNum() const { return NumComponents; }
   5205 
   5206   /// Gets the nested name specifier for associated user-defined mapper.
   5207   NestedNameSpecifierLoc getMapperQualifierLoc() const {
   5208     return MapperQualifierLoc;
   5209   }
   5210 
   5211   /// Gets the name info for associated user-defined mapper.
   5212   const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; }
   5213 
   5214   /// Iterator that browse the components by lists. It also allows
   5215   /// browsing components of a single declaration.
   5216   class const_component_lists_iterator
   5217       : public llvm::iterator_adaptor_base<
   5218             const_component_lists_iterator,
   5219             MappableExprComponentListRef::const_iterator,
   5220             std::forward_iterator_tag, MappableComponent, ptrdiff_t,
   5221             MappableComponent, MappableComponent> {
   5222     // The declaration the iterator currently refers to.
   5223     ArrayRef<ValueDecl *>::iterator DeclCur;
   5224 
   5225     // The list number associated with the current declaration.
   5226     ArrayRef<unsigned>::iterator NumListsCur;
   5227 
   5228     // Whether this clause is possible to have user-defined mappers associated.
   5229     const bool SupportsMapper;
   5230 
   5231     // The user-defined mapper associated with the current declaration.
   5232     ArrayRef<Expr *>::iterator MapperCur;
   5233 
   5234     // Remaining lists for the current declaration.
   5235     unsigned RemainingLists = 0;
   5236 
   5237     // The cumulative size of the previous list, or zero if there is no previous
   5238     // list.
   5239     unsigned PrevListSize = 0;
   5240 
   5241     // The cumulative sizes of the current list - it will delimit the remaining
   5242     // range of interest.
   5243     ArrayRef<unsigned>::const_iterator ListSizeCur;
   5244     ArrayRef<unsigned>::const_iterator ListSizeEnd;
   5245 
   5246     // Iterator to the end of the components storage.
   5247     MappableExprComponentListRef::const_iterator End;
   5248 
   5249   public:
   5250     /// Construct an iterator that scans all lists.
   5251     explicit const_component_lists_iterator(
   5252         ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
   5253         ArrayRef<unsigned> CumulativeListSizes,
   5254         MappableExprComponentListRef Components, bool SupportsMapper,
   5255         ArrayRef<Expr *> Mappers)
   5256         : const_component_lists_iterator::iterator_adaptor_base(
   5257               Components.begin()),
   5258           DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
   5259           SupportsMapper(SupportsMapper),
   5260           ListSizeCur(CumulativeListSizes.begin()),
   5261           ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
   5262       assert(UniqueDecls.size() == DeclsListNum.size() &&
   5263              "Inconsistent number of declarations and list sizes!");
   5264       if (!DeclsListNum.empty())
   5265         RemainingLists = *NumListsCur;
   5266       if (SupportsMapper)
   5267         MapperCur = Mappers.begin();
   5268     }
   5269 
   5270     /// Construct an iterator that scan lists for a given declaration \a
   5271     /// Declaration.
   5272     explicit const_component_lists_iterator(
   5273         const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
   5274         ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
   5275         MappableExprComponentListRef Components, bool SupportsMapper,
   5276         ArrayRef<Expr *> Mappers)
   5277         : const_component_lists_iterator(UniqueDecls, DeclsListNum,
   5278                                          CumulativeListSizes, Components,
   5279                                          SupportsMapper, Mappers) {
   5280       // Look for the desired declaration. While we are looking for it, we
   5281       // update the state so that we know the component where a given list
   5282       // starts.
   5283       for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
   5284         if (*DeclCur == Declaration)
   5285           break;
   5286 
   5287         assert(*NumListsCur > 0 && "No lists associated with declaration??");
   5288 
   5289         // Skip the lists associated with the current declaration, but save the
   5290         // last list size that was skipped.
   5291         std::advance(ListSizeCur, *NumListsCur - 1);
   5292         PrevListSize = *ListSizeCur;
   5293         ++ListSizeCur;
   5294 
   5295         if (SupportsMapper)
   5296           ++MapperCur;
   5297       }
   5298 
   5299       // If we didn't find any declaration, advance the iterator to after the
   5300       // last component and set remaining lists to zero.
   5301       if (ListSizeCur == CumulativeListSizes.end()) {
   5302         this->I = End;
   5303         RemainingLists = 0u;
   5304         return;
   5305       }
   5306 
   5307       // Set the remaining lists with the total number of lists of the current
   5308       // declaration.
   5309       RemainingLists = *NumListsCur;
   5310 
   5311       // Adjust the list size end iterator to the end of the relevant range.
   5312       ListSizeEnd = ListSizeCur;
   5313       std::advance(ListSizeEnd, RemainingLists);
   5314 
   5315       // Given that the list sizes are cumulative, the index of the component
   5316       // that start the list is the size of the previous list.
   5317       std::advance(this->I, PrevListSize);
   5318     }
   5319 
   5320     // Return the array with the current list. The sizes are cumulative, so the
   5321     // array size is the difference between the current size and previous one.
   5322     std::tuple<const ValueDecl *, MappableExprComponentListRef,
   5323                const ValueDecl *>
   5324     operator*() const {
   5325       assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
   5326       const ValueDecl *Mapper = nullptr;
   5327       if (SupportsMapper && *MapperCur)
   5328         Mapper = cast<ValueDecl>(cast<DeclRefExpr>(*MapperCur)->getDecl());
   5329       return std::make_tuple(
   5330           *DeclCur,
   5331           MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize),
   5332           Mapper);
   5333     }
   5334     std::tuple<const ValueDecl *, MappableExprComponentListRef,
   5335                const ValueDecl *>
   5336     operator->() const {
   5337       return **this;
   5338     }
   5339 
   5340     // Skip the components of the current list.
   5341     const_component_lists_iterator &operator++() {
   5342       assert(ListSizeCur != ListSizeEnd && RemainingLists &&
   5343              "Invalid iterator!");
   5344 
   5345       // If we don't have more lists just skip all the components. Otherwise,
   5346       // advance the iterator by the number of components in the current list.
   5347       if (std::next(ListSizeCur) == ListSizeEnd) {
   5348         this->I = End;
   5349         RemainingLists = 0;
   5350       } else {
   5351         std::advance(this->I, *ListSizeCur - PrevListSize);
   5352         PrevListSize = *ListSizeCur;
   5353 
   5354         // We are done with a declaration, move to the next one.
   5355         if (!(--RemainingLists)) {
   5356           ++DeclCur;
   5357           ++NumListsCur;
   5358           RemainingLists = *NumListsCur;
   5359           assert(RemainingLists && "No lists in the following declaration??");
   5360         }
   5361       }
   5362 
   5363       ++ListSizeCur;
   5364       if (SupportsMapper)
   5365         ++MapperCur;
   5366       return *this;
   5367     }
   5368   };
   5369 
   5370   using const_component_lists_range =
   5371       llvm::iterator_range<const_component_lists_iterator>;
   5372 
   5373   /// Iterators for all component lists.
   5374   const_component_lists_iterator component_lists_begin() const {
   5375     return const_component_lists_iterator(
   5376         getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
   5377         getComponentsRef(), SupportsMapper,
   5378         SupportsMapper ? getUDMapperRefs() : llvm::None);
   5379   }
   5380   const_component_lists_iterator component_lists_end() const {
   5381     return const_component_lists_iterator(
   5382         ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
   5383         MappableExprComponentListRef(getComponentsRef().end(),
   5384                                      getComponentsRef().end()),
   5385         SupportsMapper, llvm::None);
   5386   }
   5387   const_component_lists_range component_lists() const {
   5388     return {component_lists_begin(), component_lists_end()};
   5389   }
   5390 
   5391   /// Iterators for component lists associated with the provided
   5392   /// declaration.
   5393   const_component_lists_iterator
   5394   decl_component_lists_begin(const ValueDecl *VD) const {
   5395     return const_component_lists_iterator(
   5396         VD, getUniqueDeclsRef(), getDeclNumListsRef(),
   5397         getComponentListSizesRef(), getComponentsRef(), SupportsMapper,
   5398         SupportsMapper ? getUDMapperRefs() : llvm::None);
   5399   }
   5400   const_component_lists_iterator decl_component_lists_end() const {
   5401     return component_lists_end();
   5402   }
   5403   const_component_lists_range decl_component_lists(const ValueDecl *VD) const {
   5404     return {decl_component_lists_begin(VD), decl_component_lists_end()};
   5405   }
   5406 
   5407   /// Iterators to access all the declarations, number of lists, list sizes, and
   5408   /// components.
   5409   using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
   5410   using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
   5411 
   5412   const_all_decls_range all_decls() const {
   5413     auto A = getUniqueDeclsRef();
   5414     return const_all_decls_range(A.begin(), A.end());
   5415   }
   5416 
   5417   using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
   5418   using const_all_num_lists_range =
   5419       llvm::iterator_range<const_all_num_lists_iterator>;
   5420 
   5421   const_all_num_lists_range all_num_lists() const {
   5422     auto A = getDeclNumListsRef();
   5423     return const_all_num_lists_range(A.begin(), A.end());
   5424   }
   5425 
   5426   using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
   5427   using const_all_lists_sizes_range =
   5428       llvm::iterator_range<const_all_lists_sizes_iterator>;
   5429 
   5430   const_all_lists_sizes_range all_lists_sizes() const {
   5431     auto A = getComponentListSizesRef();
   5432     return const_all_lists_sizes_range(A.begin(), A.end());
   5433   }
   5434 
   5435   using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
   5436   using const_all_components_range =
   5437       llvm::iterator_range<const_all_components_iterator>;
   5438 
   5439   const_all_components_range all_components() const {
   5440     auto A = getComponentsRef();
   5441     return const_all_components_range(A.begin(), A.end());
   5442   }
   5443 
   5444   using mapperlist_iterator = MutableArrayRef<Expr *>::iterator;
   5445   using mapperlist_const_iterator = ArrayRef<const Expr *>::iterator;
   5446   using mapperlist_range = llvm::iterator_range<mapperlist_iterator>;
   5447   using mapperlist_const_range =
   5448       llvm::iterator_range<mapperlist_const_iterator>;
   5449 
   5450   mapperlist_iterator mapperlist_begin() { return getUDMapperRefs().begin(); }
   5451   mapperlist_iterator mapperlist_end() { return getUDMapperRefs().end(); }
   5452   mapperlist_const_iterator mapperlist_begin() const {
   5453     return getUDMapperRefs().begin();
   5454   }
   5455   mapperlist_const_iterator mapperlist_end() const {
   5456     return getUDMapperRefs().end();
   5457   }
   5458   mapperlist_range mapperlists() {
   5459     return mapperlist_range(mapperlist_begin(), mapperlist_end());
   5460   }
   5461   mapperlist_const_range mapperlists() const {
   5462     return mapperlist_const_range(mapperlist_begin(), mapperlist_end());
   5463   }
   5464 };
   5465 
   5466 /// This represents clause 'map' in the '#pragma omp ...'
   5467 /// directives.
   5468 ///
   5469 /// \code
   5470 /// #pragma omp target map(a,b)
   5471 /// \endcode
   5472 /// In this example directive '#pragma omp target' has clause 'map'
   5473 /// with the variables 'a' and 'b'.
   5474 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
   5475                            private llvm::TrailingObjects<
   5476                                OMPMapClause, Expr *, ValueDecl *, unsigned,
   5477                                OMPClauseMappableExprCommon::MappableComponent> {
   5478   friend class OMPClauseReader;
   5479   friend OMPMappableExprListClause;
   5480   friend OMPVarListClause;
   5481   friend TrailingObjects;
   5482 
   5483   /// Define the sizes of each trailing object array except the last one. This
   5484   /// is required for TrailingObjects to work properly.
   5485   size_t numTrailingObjects(OverloadToken<Expr *>) const {
   5486     // There are varlist_size() of expressions, and varlist_size() of
   5487     // user-defined mappers.
   5488     return 2 * varlist_size();
   5489   }
   5490   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
   5491     return getUniqueDeclarationsNum();
   5492   }
   5493   size_t numTrailingObjects(OverloadToken<unsigned>) const {
   5494     return getUniqueDeclarationsNum() + getTotalComponentListNum();
   5495   }
   5496 
   5497 private:
   5498   /// Map-type-modifiers for the 'map' clause.
   5499   OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = {
   5500       OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
   5501       OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown};
   5502 
   5503   /// Location of map-type-modifiers for the 'map' clause.
   5504   SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers];
   5505 
   5506   /// Map type for the 'map' clause.
   5507   OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
   5508 
   5509   /// Is this an implicit map type or not.
   5510   bool MapTypeIsImplicit = false;
   5511 
   5512   /// Location of the map type.
   5513   SourceLocation MapLoc;
   5514 
   5515   /// Colon location.
   5516   SourceLocation ColonLoc;
   5517 
   5518   /// Build a clause for \a NumVars listed expressions, \a
   5519   /// NumUniqueDeclarations declarations, \a NumComponentLists total component
   5520   /// lists, and \a NumComponents total expression components.
   5521   ///
   5522   /// \param MapModifiers Map-type-modifiers.
   5523   /// \param MapModifiersLoc Locations of map-type-modifiers.
   5524   /// \param MapperQualifierLoc C++ nested name specifier for the associated
   5525   /// user-defined mapper.
   5526   /// \param MapperIdInfo The identifier of associated user-defined mapper.
   5527   /// \param MapType Map type.
   5528   /// \param MapTypeIsImplicit Map type is inferred implicitly.
   5529   /// \param MapLoc Location of the map type.
   5530   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   5531   /// StartLoc: starting location of the clause (the clause keyword); 2)
   5532   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   5533   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   5534   /// NumVars: number of expressions listed in this clause; 2)
   5535   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   5536   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   5537   /// NumComponents: total number of expression components in the clause.
   5538   explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,
   5539                         ArrayRef<SourceLocation> MapModifiersLoc,
   5540                         NestedNameSpecifierLoc MapperQualifierLoc,
   5541                         DeclarationNameInfo MapperIdInfo,
   5542                         OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
   5543                         SourceLocation MapLoc, const OMPVarListLocTy &Locs,
   5544                         const OMPMappableExprListSizeTy &Sizes)
   5545       : OMPMappableExprListClause(llvm::omp::OMPC_map, Locs, Sizes,
   5546                                   /*SupportsMapper=*/true, &MapperQualifierLoc,
   5547                                   &MapperIdInfo),
   5548         MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
   5549     assert(llvm::array_lengthof(MapTypeModifiers) == MapModifiers.size() &&
   5550            "Unexpected number of map type modifiers.");
   5551     llvm::copy(MapModifiers, std::begin(MapTypeModifiers));
   5552 
   5553     assert(llvm::array_lengthof(MapTypeModifiersLoc) ==
   5554                MapModifiersLoc.size() &&
   5555            "Unexpected number of map type modifier locations.");
   5556     llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
   5557   }
   5558 
   5559   /// Build an empty clause.
   5560   ///
   5561   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   5562   /// NumVars: number of expressions listed in this clause; 2)
   5563   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   5564   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   5565   /// NumComponents: total number of expression components in the clause.
   5566   explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes)
   5567       : OMPMappableExprListClause(llvm::omp::OMPC_map, OMPVarListLocTy(), Sizes,
   5568                                   /*SupportsMapper=*/true) {}
   5569 
   5570   /// Set map-type-modifier for the clause.
   5571   ///
   5572   /// \param I index for map-type-modifier.
   5573   /// \param T map-type-modifier for the clause.
   5574   void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
   5575     assert(I < NumberOfOMPMapClauseModifiers &&
   5576            "Unexpected index to store map type modifier, exceeds array size.");
   5577     MapTypeModifiers[I] = T;
   5578   }
   5579 
   5580   /// Set location for the map-type-modifier.
   5581   ///
   5582   /// \param I index for map-type-modifier location.
   5583   /// \param TLoc map-type-modifier location.
   5584   void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
   5585     assert(I < NumberOfOMPMapClauseModifiers &&
   5586            "Index to store map type modifier location exceeds array size.");
   5587     MapTypeModifiersLoc[I] = TLoc;
   5588   }
   5589 
   5590   /// Set type for the clause.
   5591   ///
   5592   /// \param T Type for the clause.
   5593   void setMapType(OpenMPMapClauseKind T) { MapType = T; }
   5594 
   5595   /// Set type location.
   5596   ///
   5597   /// \param TLoc Type location.
   5598   void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
   5599 
   5600   /// Set colon location.
   5601   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   5602 
   5603 public:
   5604   /// Creates clause with a list of variables \a VL.
   5605   ///
   5606   /// \param C AST context.
   5607   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   5608   /// StartLoc: starting location of the clause (the clause keyword); 2)
   5609   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   5610   /// \param Vars The original expression used in the clause.
   5611   /// \param Declarations Declarations used in the clause.
   5612   /// \param ComponentLists Component lists used in the clause.
   5613   /// \param UDMapperRefs References to user-defined mappers associated with
   5614   /// expressions used in the clause.
   5615   /// \param MapModifiers Map-type-modifiers.
   5616   /// \param MapModifiersLoc Location of map-type-modifiers.
   5617   /// \param UDMQualifierLoc C++ nested name specifier for the associated
   5618   /// user-defined mapper.
   5619   /// \param MapperId The identifier of associated user-defined mapper.
   5620   /// \param Type Map type.
   5621   /// \param TypeIsImplicit Map type is inferred implicitly.
   5622   /// \param TypeLoc Location of the map type.
   5623   static OMPMapClause *
   5624   Create(const ASTContext &C, const OMPVarListLocTy &Locs,
   5625          ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
   5626          MappableExprComponentListsRef ComponentLists,
   5627          ArrayRef<Expr *> UDMapperRefs,
   5628          ArrayRef<OpenMPMapModifierKind> MapModifiers,
   5629          ArrayRef<SourceLocation> MapModifiersLoc,
   5630          NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
   5631          OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc);
   5632 
   5633   /// Creates an empty clause with the place for \a NumVars original
   5634   /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
   5635   /// lists, and \a NumComponents expression components.
   5636   ///
   5637   /// \param C AST context.
   5638   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   5639   /// NumVars: number of expressions listed in this clause; 2)
   5640   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   5641   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   5642   /// NumComponents: total number of expression components in the clause.
   5643   static OMPMapClause *CreateEmpty(const ASTContext &C,
   5644                                    const OMPMappableExprListSizeTy &Sizes);
   5645 
   5646   /// Fetches mapping kind for the clause.
   5647   OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
   5648 
   5649   /// Is this an implicit map type?
   5650   /// We have to capture 'IsMapTypeImplicit' from the parser for more
   5651   /// informative error messages.  It helps distinguish map(r) from
   5652   /// map(tofrom: r), which is important to print more helpful error
   5653   /// messages for some target directives.
   5654   bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
   5655 
   5656   /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
   5657   ///
   5658   /// \param Cnt index for map-type-modifier.
   5659   OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
   5660     assert(Cnt < NumberOfOMPMapClauseModifiers &&
   5661            "Requested modifier exceeds the total number of modifiers.");
   5662     return MapTypeModifiers[Cnt];
   5663   }
   5664 
   5665   /// Fetches the map-type-modifier location at 'Cnt' index of array of
   5666   /// modifiers' locations.
   5667   ///
   5668   /// \param Cnt index for map-type-modifier location.
   5669   SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
   5670     assert(Cnt < NumberOfOMPMapClauseModifiers &&
   5671            "Requested modifier location exceeds total number of modifiers.");
   5672     return MapTypeModifiersLoc[Cnt];
   5673   }
   5674 
   5675   /// Fetches ArrayRef of map-type-modifiers.
   5676   ArrayRef<OpenMPMapModifierKind> getMapTypeModifiers() const LLVM_READONLY {
   5677     return llvm::makeArrayRef(MapTypeModifiers);
   5678   }
   5679 
   5680   /// Fetches ArrayRef of location of map-type-modifiers.
   5681   ArrayRef<SourceLocation> getMapTypeModifiersLoc() const LLVM_READONLY {
   5682     return llvm::makeArrayRef(MapTypeModifiersLoc);
   5683   }
   5684 
   5685   /// Fetches location of clause mapping kind.
   5686   SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
   5687 
   5688   /// Get colon location.
   5689   SourceLocation getColonLoc() const { return ColonLoc; }
   5690 
   5691   child_range children() {
   5692     return child_range(
   5693         reinterpret_cast<Stmt **>(varlist_begin()),
   5694         reinterpret_cast<Stmt **>(varlist_end()));
   5695   }
   5696 
   5697   const_child_range children() const {
   5698     auto Children = const_cast<OMPMapClause *>(this)->children();
   5699     return const_child_range(Children.begin(), Children.end());
   5700   }
   5701 
   5702   child_range used_children() {
   5703     if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_tofrom)
   5704       return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   5705                          reinterpret_cast<Stmt **>(varlist_end()));
   5706     return child_range(child_iterator(), child_iterator());
   5707   }
   5708   const_child_range used_children() const {
   5709     auto Children = const_cast<OMPMapClause *>(this)->used_children();
   5710     return const_child_range(Children.begin(), Children.end());
   5711   }
   5712 
   5713 
   5714   static bool classof(const OMPClause *T) {
   5715     return T->getClauseKind() == llvm::omp::OMPC_map;
   5716   }
   5717 };
   5718 
   5719 /// This represents 'num_teams' clause in the '#pragma omp ...'
   5720 /// directive.
   5721 ///
   5722 /// \code
   5723 /// #pragma omp teams num_teams(n)
   5724 /// \endcode
   5725 /// In this example directive '#pragma omp teams' has clause 'num_teams'
   5726 /// with single expression 'n'.
   5727 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
   5728   friend class OMPClauseReader;
   5729 
   5730   /// Location of '('.
   5731   SourceLocation LParenLoc;
   5732 
   5733   /// NumTeams number.
   5734   Stmt *NumTeams = nullptr;
   5735 
   5736   /// Set the NumTeams number.
   5737   ///
   5738   /// \param E NumTeams number.
   5739   void setNumTeams(Expr *E) { NumTeams = E; }
   5740 
   5741 public:
   5742   /// Build 'num_teams' clause.
   5743   ///
   5744   /// \param E Expression associated with this clause.
   5745   /// \param HelperE Helper Expression associated with this clause.
   5746   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   5747   /// clause must be captured.
   5748   /// \param StartLoc Starting location of the clause.
   5749   /// \param LParenLoc Location of '('.
   5750   /// \param EndLoc Ending location of the clause.
   5751   OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
   5752                     SourceLocation StartLoc, SourceLocation LParenLoc,
   5753                     SourceLocation EndLoc)
   5754       : OMPClause(llvm::omp::OMPC_num_teams, StartLoc, EndLoc),
   5755         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), NumTeams(E) {
   5756     setPreInitStmt(HelperE, CaptureRegion);
   5757   }
   5758 
   5759   /// Build an empty clause.
   5760   OMPNumTeamsClause()
   5761       : OMPClause(llvm::omp::OMPC_num_teams, SourceLocation(),
   5762                   SourceLocation()),
   5763         OMPClauseWithPreInit(this) {}
   5764 
   5765   /// Sets the location of '('.
   5766   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   5767 
   5768   /// Returns the location of '('.
   5769   SourceLocation getLParenLoc() const { return LParenLoc; }
   5770 
   5771   /// Return NumTeams number.
   5772   Expr *getNumTeams() { return cast<Expr>(NumTeams); }
   5773 
   5774   /// Return NumTeams number.
   5775   Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
   5776 
   5777   child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
   5778 
   5779   const_child_range children() const {
   5780     return const_child_range(&NumTeams, &NumTeams + 1);
   5781   }
   5782 
   5783   child_range used_children() {
   5784     return child_range(child_iterator(), child_iterator());
   5785   }
   5786   const_child_range used_children() const {
   5787     return const_child_range(const_child_iterator(), const_child_iterator());
   5788   }
   5789 
   5790   static bool classof(const OMPClause *T) {
   5791     return T->getClauseKind() == llvm::omp::OMPC_num_teams;
   5792   }
   5793 };
   5794 
   5795 /// This represents 'thread_limit' clause in the '#pragma omp ...'
   5796 /// directive.
   5797 ///
   5798 /// \code
   5799 /// #pragma omp teams thread_limit(n)
   5800 /// \endcode
   5801 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
   5802 /// with single expression 'n'.
   5803 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
   5804   friend class OMPClauseReader;
   5805 
   5806   /// Location of '('.
   5807   SourceLocation LParenLoc;
   5808 
   5809   /// ThreadLimit number.
   5810   Stmt *ThreadLimit = nullptr;
   5811 
   5812   /// Set the ThreadLimit number.
   5813   ///
   5814   /// \param E ThreadLimit number.
   5815   void setThreadLimit(Expr *E) { ThreadLimit = E; }
   5816 
   5817 public:
   5818   /// Build 'thread_limit' clause.
   5819   ///
   5820   /// \param E Expression associated with this clause.
   5821   /// \param HelperE Helper Expression associated with this clause.
   5822   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   5823   /// clause must be captured.
   5824   /// \param StartLoc Starting location of the clause.
   5825   /// \param LParenLoc Location of '('.
   5826   /// \param EndLoc Ending location of the clause.
   5827   OMPThreadLimitClause(Expr *E, Stmt *HelperE,
   5828                        OpenMPDirectiveKind CaptureRegion,
   5829                        SourceLocation StartLoc, SourceLocation LParenLoc,
   5830                        SourceLocation EndLoc)
   5831       : OMPClause(llvm::omp::OMPC_thread_limit, StartLoc, EndLoc),
   5832         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
   5833     setPreInitStmt(HelperE, CaptureRegion);
   5834   }
   5835 
   5836   /// Build an empty clause.
   5837   OMPThreadLimitClause()
   5838       : OMPClause(llvm::omp::OMPC_thread_limit, SourceLocation(),
   5839                   SourceLocation()),
   5840         OMPClauseWithPreInit(this) {}
   5841 
   5842   /// Sets the location of '('.
   5843   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   5844 
   5845   /// Returns the location of '('.
   5846   SourceLocation getLParenLoc() const { return LParenLoc; }
   5847 
   5848   /// Return ThreadLimit number.
   5849   Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
   5850 
   5851   /// Return ThreadLimit number.
   5852   Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
   5853 
   5854   child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
   5855 
   5856   const_child_range children() const {
   5857     return const_child_range(&ThreadLimit, &ThreadLimit + 1);
   5858   }
   5859 
   5860   child_range used_children() {
   5861     return child_range(child_iterator(), child_iterator());
   5862   }
   5863   const_child_range used_children() const {
   5864     return const_child_range(const_child_iterator(), const_child_iterator());
   5865   }
   5866 
   5867   static bool classof(const OMPClause *T) {
   5868     return T->getClauseKind() == llvm::omp::OMPC_thread_limit;
   5869   }
   5870 };
   5871 
   5872 /// This represents 'priority' clause in the '#pragma omp ...'
   5873 /// directive.
   5874 ///
   5875 /// \code
   5876 /// #pragma omp task priority(n)
   5877 /// \endcode
   5878 /// In this example directive '#pragma omp teams' has clause 'priority' with
   5879 /// single expression 'n'.
   5880 class OMPPriorityClause : public OMPClause, public OMPClauseWithPreInit {
   5881   friend class OMPClauseReader;
   5882 
   5883   /// Location of '('.
   5884   SourceLocation LParenLoc;
   5885 
   5886   /// Priority number.
   5887   Stmt *Priority = nullptr;
   5888 
   5889   /// Set the Priority number.
   5890   ///
   5891   /// \param E Priority number.
   5892   void setPriority(Expr *E) { Priority = E; }
   5893 
   5894 public:
   5895   /// Build 'priority' clause.
   5896   ///
   5897   /// \param Priority Expression associated with this clause.
   5898   /// \param HelperPriority Helper priority for the construct.
   5899   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   5900   /// clause must be captured.
   5901   /// \param StartLoc Starting location of the clause.
   5902   /// \param LParenLoc Location of '('.
   5903   /// \param EndLoc Ending location of the clause.
   5904   OMPPriorityClause(Expr *Priority, Stmt *HelperPriority,
   5905                     OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
   5906                     SourceLocation LParenLoc, SourceLocation EndLoc)
   5907       : OMPClause(llvm::omp::OMPC_priority, StartLoc, EndLoc),
   5908         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Priority(Priority) {
   5909     setPreInitStmt(HelperPriority, CaptureRegion);
   5910   }
   5911 
   5912   /// Build an empty clause.
   5913   OMPPriorityClause()
   5914       : OMPClause(llvm::omp::OMPC_priority, SourceLocation(), SourceLocation()),
   5915         OMPClauseWithPreInit(this) {}
   5916 
   5917   /// Sets the location of '('.
   5918   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   5919 
   5920   /// Returns the location of '('.
   5921   SourceLocation getLParenLoc() const { return LParenLoc; }
   5922 
   5923   /// Return Priority number.
   5924   Expr *getPriority() { return cast<Expr>(Priority); }
   5925 
   5926   /// Return Priority number.
   5927   Expr *getPriority() const { return cast<Expr>(Priority); }
   5928 
   5929   child_range children() { return child_range(&Priority, &Priority + 1); }
   5930 
   5931   const_child_range children() const {
   5932     return const_child_range(&Priority, &Priority + 1);
   5933   }
   5934 
   5935   child_range used_children();
   5936   const_child_range used_children() const {
   5937     auto Children = const_cast<OMPPriorityClause *>(this)->used_children();
   5938     return const_child_range(Children.begin(), Children.end());
   5939   }
   5940 
   5941   static bool classof(const OMPClause *T) {
   5942     return T->getClauseKind() == llvm::omp::OMPC_priority;
   5943   }
   5944 };
   5945 
   5946 /// This represents 'grainsize' clause in the '#pragma omp ...'
   5947 /// directive.
   5948 ///
   5949 /// \code
   5950 /// #pragma omp taskloop grainsize(4)
   5951 /// \endcode
   5952 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
   5953 /// with single expression '4'.
   5954 class OMPGrainsizeClause : public OMPClause, public OMPClauseWithPreInit {
   5955   friend class OMPClauseReader;
   5956 
   5957   /// Location of '('.
   5958   SourceLocation LParenLoc;
   5959 
   5960   /// Safe iteration space distance.
   5961   Stmt *Grainsize = nullptr;
   5962 
   5963   /// Set safelen.
   5964   void setGrainsize(Expr *Size) { Grainsize = Size; }
   5965 
   5966 public:
   5967   /// Build 'grainsize' clause.
   5968   ///
   5969   /// \param Size Expression associated with this clause.
   5970   /// \param HelperSize Helper grainsize for the construct.
   5971   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   5972   /// clause must be captured.
   5973   /// \param StartLoc Starting location of the clause.
   5974   /// \param EndLoc Ending location of the clause.
   5975   OMPGrainsizeClause(Expr *Size, Stmt *HelperSize,
   5976                      OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
   5977                      SourceLocation LParenLoc, SourceLocation EndLoc)
   5978       : OMPClause(llvm::omp::OMPC_grainsize, StartLoc, EndLoc),
   5979         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Grainsize(Size) {
   5980     setPreInitStmt(HelperSize, CaptureRegion);
   5981   }
   5982 
   5983   /// Build an empty clause.
   5984   explicit OMPGrainsizeClause()
   5985       : OMPClause(llvm::omp::OMPC_grainsize, SourceLocation(),
   5986                   SourceLocation()),
   5987         OMPClauseWithPreInit(this) {}
   5988 
   5989   /// Sets the location of '('.
   5990   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   5991 
   5992   /// Returns the location of '('.
   5993   SourceLocation getLParenLoc() const { return LParenLoc; }
   5994 
   5995   /// Return safe iteration space distance.
   5996   Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
   5997 
   5998   child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
   5999 
   6000   const_child_range children() const {
   6001     return const_child_range(&Grainsize, &Grainsize + 1);
   6002   }
   6003 
   6004   child_range used_children();
   6005   const_child_range used_children() const {
   6006     auto Children = const_cast<OMPGrainsizeClause *>(this)->used_children();
   6007     return const_child_range(Children.begin(), Children.end());
   6008   }
   6009 
   6010   static bool classof(const OMPClause *T) {
   6011     return T->getClauseKind() == llvm::omp::OMPC_grainsize;
   6012   }
   6013 };
   6014 
   6015 /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
   6016 ///
   6017 /// \code
   6018 /// #pragma omp taskloop nogroup
   6019 /// \endcode
   6020 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
   6021 class OMPNogroupClause : public OMPClause {
   6022 public:
   6023   /// Build 'nogroup' clause.
   6024   ///
   6025   /// \param StartLoc Starting location of the clause.
   6026   /// \param EndLoc Ending location of the clause.
   6027   OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
   6028       : OMPClause(llvm::omp::OMPC_nogroup, StartLoc, EndLoc) {}
   6029 
   6030   /// Build an empty clause.
   6031   OMPNogroupClause()
   6032       : OMPClause(llvm::omp::OMPC_nogroup, SourceLocation(), SourceLocation()) {
   6033   }
   6034 
   6035   child_range children() {
   6036     return child_range(child_iterator(), child_iterator());
   6037   }
   6038 
   6039   const_child_range children() const {
   6040     return const_child_range(const_child_iterator(), const_child_iterator());
   6041   }
   6042 
   6043   child_range used_children() {
   6044     return child_range(child_iterator(), child_iterator());
   6045   }
   6046   const_child_range used_children() const {
   6047     return const_child_range(const_child_iterator(), const_child_iterator());
   6048   }
   6049 
   6050   static bool classof(const OMPClause *T) {
   6051     return T->getClauseKind() == llvm::omp::OMPC_nogroup;
   6052   }
   6053 };
   6054 
   6055 /// This represents 'num_tasks' clause in the '#pragma omp ...'
   6056 /// directive.
   6057 ///
   6058 /// \code
   6059 /// #pragma omp taskloop num_tasks(4)
   6060 /// \endcode
   6061 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
   6062 /// with single expression '4'.
   6063 class OMPNumTasksClause : public OMPClause, public OMPClauseWithPreInit {
   6064   friend class OMPClauseReader;
   6065 
   6066   /// Location of '('.
   6067   SourceLocation LParenLoc;
   6068 
   6069   /// Safe iteration space distance.
   6070   Stmt *NumTasks = nullptr;
   6071 
   6072   /// Set safelen.
   6073   void setNumTasks(Expr *Size) { NumTasks = Size; }
   6074 
   6075 public:
   6076   /// Build 'num_tasks' clause.
   6077   ///
   6078   /// \param Size Expression associated with this clause.
   6079   /// \param HelperSize Helper grainsize for the construct.
   6080   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   6081   /// clause must be captured.
   6082   /// \param StartLoc Starting location of the clause.
   6083   /// \param EndLoc Ending location of the clause.
   6084   OMPNumTasksClause(Expr *Size, Stmt *HelperSize,
   6085                     OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
   6086                     SourceLocation LParenLoc, SourceLocation EndLoc)
   6087       : OMPClause(llvm::omp::OMPC_num_tasks, StartLoc, EndLoc),
   6088         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), NumTasks(Size) {
   6089     setPreInitStmt(HelperSize, CaptureRegion);
   6090   }
   6091 
   6092   /// Build an empty clause.
   6093   explicit OMPNumTasksClause()
   6094       : OMPClause(llvm::omp::OMPC_num_tasks, SourceLocation(),
   6095                   SourceLocation()),
   6096         OMPClauseWithPreInit(this) {}
   6097 
   6098   /// Sets the location of '('.
   6099   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   6100 
   6101   /// Returns the location of '('.
   6102   SourceLocation getLParenLoc() const { return LParenLoc; }
   6103 
   6104   /// Return safe iteration space distance.
   6105   Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
   6106 
   6107   child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
   6108 
   6109   const_child_range children() const {
   6110     return const_child_range(&NumTasks, &NumTasks + 1);
   6111   }
   6112 
   6113   child_range used_children();
   6114   const_child_range used_children() const {
   6115     auto Children = const_cast<OMPNumTasksClause *>(this)->used_children();
   6116     return const_child_range(Children.begin(), Children.end());
   6117   }
   6118 
   6119   static bool classof(const OMPClause *T) {
   6120     return T->getClauseKind() == llvm::omp::OMPC_num_tasks;
   6121   }
   6122 };
   6123 
   6124 /// This represents 'hint' clause in the '#pragma omp ...' directive.
   6125 ///
   6126 /// \code
   6127 /// #pragma omp critical (name) hint(6)
   6128 /// \endcode
   6129 /// In this example directive '#pragma omp critical' has name 'name' and clause
   6130 /// 'hint' with argument '6'.
   6131 class OMPHintClause : public OMPClause {
   6132   friend class OMPClauseReader;
   6133 
   6134   /// Location of '('.
   6135   SourceLocation LParenLoc;
   6136 
   6137   /// Hint expression of the 'hint' clause.
   6138   Stmt *Hint = nullptr;
   6139 
   6140   /// Set hint expression.
   6141   void setHint(Expr *H) { Hint = H; }
   6142 
   6143 public:
   6144   /// Build 'hint' clause with expression \a Hint.
   6145   ///
   6146   /// \param Hint Hint expression.
   6147   /// \param StartLoc Starting location of the clause.
   6148   /// \param LParenLoc Location of '('.
   6149   /// \param EndLoc Ending location of the clause.
   6150   OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
   6151                 SourceLocation EndLoc)
   6152       : OMPClause(llvm::omp::OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
   6153         Hint(Hint) {}
   6154 
   6155   /// Build an empty clause.
   6156   OMPHintClause()
   6157       : OMPClause(llvm::omp::OMPC_hint, SourceLocation(), SourceLocation()) {}
   6158 
   6159   /// Sets the location of '('.
   6160   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   6161 
   6162   /// Returns the location of '('.
   6163   SourceLocation getLParenLoc() const { return LParenLoc; }
   6164 
   6165   /// Returns number of threads.
   6166   Expr *getHint() const { return cast_or_null<Expr>(Hint); }
   6167 
   6168   child_range children() { return child_range(&Hint, &Hint + 1); }
   6169 
   6170   const_child_range children() const {
   6171     return const_child_range(&Hint, &Hint + 1);
   6172   }
   6173 
   6174   child_range used_children() {
   6175     return child_range(child_iterator(), child_iterator());
   6176   }
   6177   const_child_range used_children() const {
   6178     return const_child_range(const_child_iterator(), const_child_iterator());
   6179   }
   6180 
   6181   static bool classof(const OMPClause *T) {
   6182     return T->getClauseKind() == llvm::omp::OMPC_hint;
   6183   }
   6184 };
   6185 
   6186 /// This represents 'dist_schedule' clause in the '#pragma omp ...'
   6187 /// directive.
   6188 ///
   6189 /// \code
   6190 /// #pragma omp distribute dist_schedule(static, 3)
   6191 /// \endcode
   6192 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
   6193 /// clause with arguments 'static' and '3'.
   6194 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
   6195   friend class OMPClauseReader;
   6196 
   6197   /// Location of '('.
   6198   SourceLocation LParenLoc;
   6199 
   6200   /// A kind of the 'schedule' clause.
   6201   OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
   6202 
   6203   /// Start location of the schedule kind in source code.
   6204   SourceLocation KindLoc;
   6205 
   6206   /// Location of ',' (if any).
   6207   SourceLocation CommaLoc;
   6208 
   6209   /// Chunk size.
   6210   Expr *ChunkSize = nullptr;
   6211 
   6212   /// Set schedule kind.
   6213   ///
   6214   /// \param K Schedule kind.
   6215   void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
   6216 
   6217   /// Sets the location of '('.
   6218   ///
   6219   /// \param Loc Location of '('.
   6220   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   6221 
   6222   /// Set schedule kind start location.
   6223   ///
   6224   /// \param KLoc Schedule kind location.
   6225   void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
   6226 
   6227   /// Set location of ','.
   6228   ///
   6229   /// \param Loc Location of ','.
   6230   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
   6231 
   6232   /// Set chunk size.
   6233   ///
   6234   /// \param E Chunk size.
   6235   void setChunkSize(Expr *E) { ChunkSize = E; }
   6236 
   6237 public:
   6238   /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
   6239   /// size expression \a ChunkSize.
   6240   ///
   6241   /// \param StartLoc Starting location of the clause.
   6242   /// \param LParenLoc Location of '('.
   6243   /// \param KLoc Starting location of the argument.
   6244   /// \param CommaLoc Location of ','.
   6245   /// \param EndLoc Ending location of the clause.
   6246   /// \param Kind DistSchedule kind.
   6247   /// \param ChunkSize Chunk size.
   6248   /// \param HelperChunkSize Helper chunk size for combined directives.
   6249   OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   6250                         SourceLocation KLoc, SourceLocation CommaLoc,
   6251                         SourceLocation EndLoc,
   6252                         OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
   6253                         Stmt *HelperChunkSize)
   6254       : OMPClause(llvm::omp::OMPC_dist_schedule, StartLoc, EndLoc),
   6255         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
   6256         KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
   6257     setPreInitStmt(HelperChunkSize);
   6258   }
   6259 
   6260   /// Build an empty clause.
   6261   explicit OMPDistScheduleClause()
   6262       : OMPClause(llvm::omp::OMPC_dist_schedule, SourceLocation(),
   6263                   SourceLocation()),
   6264         OMPClauseWithPreInit(this) {}
   6265 
   6266   /// Get kind of the clause.
   6267   OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
   6268 
   6269   /// Get location of '('.
   6270   SourceLocation getLParenLoc() { return LParenLoc; }
   6271 
   6272   /// Get kind location.
   6273   SourceLocation getDistScheduleKindLoc() { return KindLoc; }
   6274 
   6275   /// Get location of ','.
   6276   SourceLocation getCommaLoc() { return CommaLoc; }
   6277 
   6278   /// Get chunk size.
   6279   Expr *getChunkSize() { return ChunkSize; }
   6280 
   6281   /// Get chunk size.
   6282   const Expr *getChunkSize() const { return ChunkSize; }
   6283 
   6284   child_range children() {
   6285     return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
   6286                        reinterpret_cast<Stmt **>(&ChunkSize) + 1);
   6287   }
   6288 
   6289   const_child_range children() const {
   6290     auto Children = const_cast<OMPDistScheduleClause *>(this)->children();
   6291     return const_child_range(Children.begin(), Children.end());
   6292   }
   6293 
   6294   child_range used_children() {
   6295     return child_range(child_iterator(), child_iterator());
   6296   }
   6297   const_child_range used_children() const {
   6298     return const_child_range(const_child_iterator(), const_child_iterator());
   6299   }
   6300 
   6301   static bool classof(const OMPClause *T) {
   6302     return T->getClauseKind() == llvm::omp::OMPC_dist_schedule;
   6303   }
   6304 };
   6305 
   6306 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
   6307 ///
   6308 /// \code
   6309 /// #pragma omp target defaultmap(tofrom: scalar)
   6310 /// \endcode
   6311 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
   6312 /// 'scalar' with modifier 'tofrom'.
   6313 class OMPDefaultmapClause : public OMPClause {
   6314   friend class OMPClauseReader;
   6315 
   6316   /// Location of '('.
   6317   SourceLocation LParenLoc;
   6318 
   6319   /// Modifiers for 'defaultmap' clause.
   6320   OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
   6321 
   6322   /// Locations of modifiers.
   6323   SourceLocation ModifierLoc;
   6324 
   6325   /// A kind of the 'defaultmap' clause.
   6326   OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
   6327 
   6328   /// Start location of the defaultmap kind in source code.
   6329   SourceLocation KindLoc;
   6330 
   6331   /// Set defaultmap kind.
   6332   ///
   6333   /// \param K Defaultmap kind.
   6334   void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
   6335 
   6336   /// Set the defaultmap modifier.
   6337   ///
   6338   /// \param M Defaultmap modifier.
   6339   void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
   6340     Modifier = M;
   6341   }
   6342 
   6343   /// Set location of the defaultmap modifier.
   6344   void setDefaultmapModifierLoc(SourceLocation Loc) {
   6345     ModifierLoc = Loc;
   6346   }
   6347 
   6348   /// Sets the location of '('.
   6349   ///
   6350   /// \param Loc Location of '('.
   6351   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   6352 
   6353   /// Set defaultmap kind start location.
   6354   ///
   6355   /// \param KLoc Defaultmap kind location.
   6356   void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
   6357 
   6358 public:
   6359   /// Build 'defaultmap' clause with defaultmap kind \a Kind
   6360   ///
   6361   /// \param StartLoc Starting location of the clause.
   6362   /// \param LParenLoc Location of '('.
   6363   /// \param KLoc Starting location of the argument.
   6364   /// \param EndLoc Ending location of the clause.
   6365   /// \param Kind Defaultmap kind.
   6366   /// \param M The modifier applied to 'defaultmap' clause.
   6367   /// \param MLoc Location of the modifier
   6368   OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   6369                       SourceLocation MLoc, SourceLocation KLoc,
   6370                       SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
   6371                       OpenMPDefaultmapClauseModifier M)
   6372       : OMPClause(llvm::omp::OMPC_defaultmap, StartLoc, EndLoc),
   6373         LParenLoc(LParenLoc), Modifier(M), ModifierLoc(MLoc), Kind(Kind),
   6374         KindLoc(KLoc) {}
   6375 
   6376   /// Build an empty clause.
   6377   explicit OMPDefaultmapClause()
   6378       : OMPClause(llvm::omp::OMPC_defaultmap, SourceLocation(),
   6379                   SourceLocation()) {}
   6380 
   6381   /// Get kind of the clause.
   6382   OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
   6383 
   6384   /// Get the modifier of the clause.
   6385   OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
   6386     return Modifier;
   6387   }
   6388 
   6389   /// Get location of '('.
   6390   SourceLocation getLParenLoc() { return LParenLoc; }
   6391 
   6392   /// Get kind location.
   6393   SourceLocation getDefaultmapKindLoc() { return KindLoc; }
   6394 
   6395   /// Get the modifier location.
   6396   SourceLocation getDefaultmapModifierLoc() const {
   6397     return ModifierLoc;
   6398   }
   6399 
   6400   child_range children() {
   6401     return child_range(child_iterator(), child_iterator());
   6402   }
   6403 
   6404   const_child_range children() const {
   6405     return const_child_range(const_child_iterator(), const_child_iterator());
   6406   }
   6407 
   6408   child_range used_children() {
   6409     return child_range(child_iterator(), child_iterator());
   6410   }
   6411   const_child_range used_children() const {
   6412     return const_child_range(const_child_iterator(), const_child_iterator());
   6413   }
   6414 
   6415   static bool classof(const OMPClause *T) {
   6416     return T->getClauseKind() == llvm::omp::OMPC_defaultmap;
   6417   }
   6418 };
   6419 
   6420 /// This represents clause 'to' in the '#pragma omp ...'
   6421 /// directives.
   6422 ///
   6423 /// \code
   6424 /// #pragma omp target update to(a,b)
   6425 /// \endcode
   6426 /// In this example directive '#pragma omp target update' has clause 'to'
   6427 /// with the variables 'a' and 'b'.
   6428 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
   6429                           private llvm::TrailingObjects<
   6430                               OMPToClause, Expr *, ValueDecl *, unsigned,
   6431                               OMPClauseMappableExprCommon::MappableComponent> {
   6432   friend class OMPClauseReader;
   6433   friend OMPMappableExprListClause;
   6434   friend OMPVarListClause;
   6435   friend TrailingObjects;
   6436 
   6437   /// Motion-modifiers for the 'to' clause.
   6438   OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
   6439       OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
   6440 
   6441   /// Location of motion-modifiers for the 'to' clause.
   6442   SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
   6443 
   6444   /// Colon location.
   6445   SourceLocation ColonLoc;
   6446 
   6447   /// Build clause with number of variables \a NumVars.
   6448   ///
   6449   /// \param TheMotionModifiers Motion-modifiers.
   6450   /// \param TheMotionModifiersLoc Locations of motion-modifiers.
   6451   /// \param MapperQualifierLoc C++ nested name specifier for the associated
   6452   /// user-defined mapper.
   6453   /// \param MapperIdInfo The identifier of associated user-defined mapper.
   6454   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   6455   /// StartLoc: starting location of the clause (the clause keyword); 2)
   6456   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   6457   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6458   /// NumVars: number of expressions listed in this clause; 2)
   6459   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6460   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6461   /// NumComponents: total number of expression components in the clause.
   6462   explicit OMPToClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
   6463                        ArrayRef<SourceLocation> TheMotionModifiersLoc,
   6464                        NestedNameSpecifierLoc MapperQualifierLoc,
   6465                        DeclarationNameInfo MapperIdInfo,
   6466                        const OMPVarListLocTy &Locs,
   6467                        const OMPMappableExprListSizeTy &Sizes)
   6468       : OMPMappableExprListClause(llvm::omp::OMPC_to, Locs, Sizes,
   6469                                   /*SupportsMapper=*/true, &MapperQualifierLoc,
   6470                                   &MapperIdInfo) {
   6471     assert(llvm::array_lengthof(MotionModifiers) == TheMotionModifiers.size() &&
   6472            "Unexpected number of motion modifiers.");
   6473     llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
   6474 
   6475     assert(llvm::array_lengthof(MotionModifiersLoc) ==
   6476                TheMotionModifiersLoc.size() &&
   6477            "Unexpected number of motion modifier locations.");
   6478     llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
   6479   }
   6480 
   6481   /// Build an empty clause.
   6482   ///
   6483   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6484   /// NumVars: number of expressions listed in this clause; 2)
   6485   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6486   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6487   /// NumComponents: total number of expression components in the clause.
   6488   explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes)
   6489       : OMPMappableExprListClause(llvm::omp::OMPC_to, OMPVarListLocTy(), Sizes,
   6490                                   /*SupportsMapper=*/true) {}
   6491 
   6492   /// Set motion-modifier for the clause.
   6493   ///
   6494   /// \param I index for motion-modifier.
   6495   /// \param T motion-modifier for the clause.
   6496   void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
   6497     assert(I < NumberOfOMPMotionModifiers &&
   6498            "Unexpected index to store motion modifier, exceeds array size.");
   6499     MotionModifiers[I] = T;
   6500   }
   6501 
   6502   /// Set location for the motion-modifier.
   6503   ///
   6504   /// \param I index for motion-modifier location.
   6505   /// \param TLoc motion-modifier location.
   6506   void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
   6507     assert(I < NumberOfOMPMotionModifiers &&
   6508            "Index to store motion modifier location exceeds array size.");
   6509     MotionModifiersLoc[I] = TLoc;
   6510   }
   6511 
   6512   /// Set colon location.
   6513   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   6514 
   6515   /// Define the sizes of each trailing object array except the last one. This
   6516   /// is required for TrailingObjects to work properly.
   6517   size_t numTrailingObjects(OverloadToken<Expr *>) const {
   6518     // There are varlist_size() of expressions, and varlist_size() of
   6519     // user-defined mappers.
   6520     return 2 * varlist_size();
   6521   }
   6522   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
   6523     return getUniqueDeclarationsNum();
   6524   }
   6525   size_t numTrailingObjects(OverloadToken<unsigned>) const {
   6526     return getUniqueDeclarationsNum() + getTotalComponentListNum();
   6527   }
   6528 
   6529 public:
   6530   /// Creates clause with a list of variables \a Vars.
   6531   ///
   6532   /// \param C AST context.
   6533   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   6534   /// StartLoc: starting location of the clause (the clause keyword); 2)
   6535   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   6536   /// \param Vars The original expression used in the clause.
   6537   /// \param Declarations Declarations used in the clause.
   6538   /// \param ComponentLists Component lists used in the clause.
   6539   /// \param MotionModifiers Motion-modifiers.
   6540   /// \param MotionModifiersLoc Location of motion-modifiers.
   6541   /// \param UDMapperRefs References to user-defined mappers associated with
   6542   /// expressions used in the clause.
   6543   /// \param UDMQualifierLoc C++ nested name specifier for the associated
   6544   /// user-defined mapper.
   6545   /// \param MapperId The identifier of associated user-defined mapper.
   6546   static OMPToClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
   6547                              ArrayRef<Expr *> Vars,
   6548                              ArrayRef<ValueDecl *> Declarations,
   6549                              MappableExprComponentListsRef ComponentLists,
   6550                              ArrayRef<Expr *> UDMapperRefs,
   6551                              ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
   6552                              ArrayRef<SourceLocation> MotionModifiersLoc,
   6553                              NestedNameSpecifierLoc UDMQualifierLoc,
   6554                              DeclarationNameInfo MapperId);
   6555 
   6556   /// Creates an empty clause with the place for \a NumVars variables.
   6557   ///
   6558   /// \param C AST context.
   6559   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6560   /// NumVars: number of expressions listed in this clause; 2)
   6561   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6562   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6563   /// NumComponents: total number of expression components in the clause.
   6564   static OMPToClause *CreateEmpty(const ASTContext &C,
   6565                                   const OMPMappableExprListSizeTy &Sizes);
   6566 
   6567   /// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
   6568   ///
   6569   /// \param Cnt index for motion-modifier.
   6570   OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
   6571     assert(Cnt < NumberOfOMPMotionModifiers &&
   6572            "Requested modifier exceeds the total number of modifiers.");
   6573     return MotionModifiers[Cnt];
   6574   }
   6575 
   6576   /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
   6577   /// locations.
   6578   ///
   6579   /// \param Cnt index for motion-modifier location.
   6580   SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
   6581     assert(Cnt < NumberOfOMPMotionModifiers &&
   6582            "Requested modifier location exceeds total number of modifiers.");
   6583     return MotionModifiersLoc[Cnt];
   6584   }
   6585 
   6586   /// Fetches ArrayRef of motion-modifiers.
   6587   ArrayRef<OpenMPMotionModifierKind> getMotionModifiers() const LLVM_READONLY {
   6588     return llvm::makeArrayRef(MotionModifiers);
   6589   }
   6590 
   6591   /// Fetches ArrayRef of location of motion-modifiers.
   6592   ArrayRef<SourceLocation> getMotionModifiersLoc() const LLVM_READONLY {
   6593     return llvm::makeArrayRef(MotionModifiersLoc);
   6594   }
   6595 
   6596   /// Get colon location.
   6597   SourceLocation getColonLoc() const { return ColonLoc; }
   6598 
   6599   child_range children() {
   6600     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   6601                        reinterpret_cast<Stmt **>(varlist_end()));
   6602   }
   6603 
   6604   const_child_range children() const {
   6605     auto Children = const_cast<OMPToClause *>(this)->children();
   6606     return const_child_range(Children.begin(), Children.end());
   6607   }
   6608 
   6609   child_range used_children() {
   6610     return child_range(child_iterator(), child_iterator());
   6611   }
   6612   const_child_range used_children() const {
   6613     return const_child_range(const_child_iterator(), const_child_iterator());
   6614   }
   6615 
   6616   static bool classof(const OMPClause *T) {
   6617     return T->getClauseKind() == llvm::omp::OMPC_to;
   6618   }
   6619 };
   6620 
   6621 /// This represents clause 'from' in the '#pragma omp ...'
   6622 /// directives.
   6623 ///
   6624 /// \code
   6625 /// #pragma omp target update from(a,b)
   6626 /// \endcode
   6627 /// In this example directive '#pragma omp target update' has clause 'from'
   6628 /// with the variables 'a' and 'b'.
   6629 class OMPFromClause final
   6630     : public OMPMappableExprListClause<OMPFromClause>,
   6631       private llvm::TrailingObjects<
   6632           OMPFromClause, Expr *, ValueDecl *, unsigned,
   6633           OMPClauseMappableExprCommon::MappableComponent> {
   6634   friend class OMPClauseReader;
   6635   friend OMPMappableExprListClause;
   6636   friend OMPVarListClause;
   6637   friend TrailingObjects;
   6638 
   6639   /// Motion-modifiers for the 'from' clause.
   6640   OpenMPMotionModifierKind MotionModifiers[NumberOfOMPMotionModifiers] = {
   6641       OMPC_MOTION_MODIFIER_unknown, OMPC_MOTION_MODIFIER_unknown};
   6642 
   6643   /// Location of motion-modifiers for the 'from' clause.
   6644   SourceLocation MotionModifiersLoc[NumberOfOMPMotionModifiers];
   6645 
   6646   /// Colon location.
   6647   SourceLocation ColonLoc;
   6648 
   6649   /// Build clause with number of variables \a NumVars.
   6650   ///
   6651   /// \param TheMotionModifiers Motion-modifiers.
   6652   /// \param TheMotionModifiersLoc Locations of motion-modifiers.
   6653   /// \param MapperQualifierLoc C++ nested name specifier for the associated
   6654   /// user-defined mapper.
   6655   /// \param MapperIdInfo The identifier of associated user-defined mapper.
   6656   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   6657   /// StartLoc: starting location of the clause (the clause keyword); 2)
   6658   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   6659   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6660   /// NumVars: number of expressions listed in this clause; 2)
   6661   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6662   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6663   /// NumComponents: total number of expression components in the clause.
   6664   explicit OMPFromClause(ArrayRef<OpenMPMotionModifierKind> TheMotionModifiers,
   6665                          ArrayRef<SourceLocation> TheMotionModifiersLoc,
   6666                          NestedNameSpecifierLoc MapperQualifierLoc,
   6667                          DeclarationNameInfo MapperIdInfo,
   6668                          const OMPVarListLocTy &Locs,
   6669                          const OMPMappableExprListSizeTy &Sizes)
   6670       : OMPMappableExprListClause(llvm::omp::OMPC_from, Locs, Sizes,
   6671                                   /*SupportsMapper=*/true, &MapperQualifierLoc,
   6672                                   &MapperIdInfo) {
   6673     assert(llvm::array_lengthof(MotionModifiers) == TheMotionModifiers.size() &&
   6674            "Unexpected number of motion modifiers.");
   6675     llvm::copy(TheMotionModifiers, std::begin(MotionModifiers));
   6676 
   6677     assert(llvm::array_lengthof(MotionModifiersLoc) ==
   6678                TheMotionModifiersLoc.size() &&
   6679            "Unexpected number of motion modifier locations.");
   6680     llvm::copy(TheMotionModifiersLoc, std::begin(MotionModifiersLoc));
   6681   }
   6682 
   6683   /// Build an empty clause.
   6684   ///
   6685   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6686   /// NumVars: number of expressions listed in this clause; 2)
   6687   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6688   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6689   /// NumComponents: total number of expression components in the clause.
   6690   explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes)
   6691       : OMPMappableExprListClause(llvm::omp::OMPC_from, OMPVarListLocTy(),
   6692                                   Sizes, /*SupportsMapper=*/true) {}
   6693 
   6694   /// Set motion-modifier for the clause.
   6695   ///
   6696   /// \param I index for motion-modifier.
   6697   /// \param T motion-modifier for the clause.
   6698   void setMotionModifier(unsigned I, OpenMPMotionModifierKind T) {
   6699     assert(I < NumberOfOMPMotionModifiers &&
   6700            "Unexpected index to store motion modifier, exceeds array size.");
   6701     MotionModifiers[I] = T;
   6702   }
   6703 
   6704   /// Set location for the motion-modifier.
   6705   ///
   6706   /// \param I index for motion-modifier location.
   6707   /// \param TLoc motion-modifier location.
   6708   void setMotionModifierLoc(unsigned I, SourceLocation TLoc) {
   6709     assert(I < NumberOfOMPMotionModifiers &&
   6710            "Index to store motion modifier location exceeds array size.");
   6711     MotionModifiersLoc[I] = TLoc;
   6712   }
   6713 
   6714   /// Set colon location.
   6715   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   6716 
   6717   /// Define the sizes of each trailing object array except the last one. This
   6718   /// is required for TrailingObjects to work properly.
   6719   size_t numTrailingObjects(OverloadToken<Expr *>) const {
   6720     // There are varlist_size() of expressions, and varlist_size() of
   6721     // user-defined mappers.
   6722     return 2 * varlist_size();
   6723   }
   6724   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
   6725     return getUniqueDeclarationsNum();
   6726   }
   6727   size_t numTrailingObjects(OverloadToken<unsigned>) const {
   6728     return getUniqueDeclarationsNum() + getTotalComponentListNum();
   6729   }
   6730 
   6731 public:
   6732   /// Creates clause with a list of variables \a Vars.
   6733   ///
   6734   /// \param C AST context.
   6735   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   6736   /// StartLoc: starting location of the clause (the clause keyword); 2)
   6737   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   6738   /// \param Vars The original expression used in the clause.
   6739   /// \param Declarations Declarations used in the clause.
   6740   /// \param ComponentLists Component lists used in the clause.
   6741   /// \param MotionModifiers Motion-modifiers.
   6742   /// \param MotionModifiersLoc Location of motion-modifiers.
   6743   /// \param UDMapperRefs References to user-defined mappers associated with
   6744   /// expressions used in the clause.
   6745   /// \param UDMQualifierLoc C++ nested name specifier for the associated
   6746   /// user-defined mapper.
   6747   /// \param MapperId The identifier of associated user-defined mapper.
   6748   static OMPFromClause *
   6749   Create(const ASTContext &C, const OMPVarListLocTy &Locs,
   6750          ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
   6751          MappableExprComponentListsRef ComponentLists,
   6752          ArrayRef<Expr *> UDMapperRefs,
   6753          ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
   6754          ArrayRef<SourceLocation> MotionModifiersLoc,
   6755          NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId);
   6756 
   6757   /// Creates an empty clause with the place for \a NumVars variables.
   6758   ///
   6759   /// \param C AST context.
   6760   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6761   /// NumVars: number of expressions listed in this clause; 2)
   6762   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6763   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6764   /// NumComponents: total number of expression components in the clause.
   6765   static OMPFromClause *CreateEmpty(const ASTContext &C,
   6766                                     const OMPMappableExprListSizeTy &Sizes);
   6767 
   6768   /// Fetches the motion-modifier at 'Cnt' index of array of modifiers.
   6769   ///
   6770   /// \param Cnt index for motion-modifier.
   6771   OpenMPMotionModifierKind getMotionModifier(unsigned Cnt) const LLVM_READONLY {
   6772     assert(Cnt < NumberOfOMPMotionModifiers &&
   6773            "Requested modifier exceeds the total number of modifiers.");
   6774     return MotionModifiers[Cnt];
   6775   }
   6776 
   6777   /// Fetches the motion-modifier location at 'Cnt' index of array of modifiers'
   6778   /// locations.
   6779   ///
   6780   /// \param Cnt index for motion-modifier location.
   6781   SourceLocation getMotionModifierLoc(unsigned Cnt) const LLVM_READONLY {
   6782     assert(Cnt < NumberOfOMPMotionModifiers &&
   6783            "Requested modifier location exceeds total number of modifiers.");
   6784     return MotionModifiersLoc[Cnt];
   6785   }
   6786 
   6787   /// Fetches ArrayRef of motion-modifiers.
   6788   ArrayRef<OpenMPMotionModifierKind> getMotionModifiers() const LLVM_READONLY {
   6789     return llvm::makeArrayRef(MotionModifiers);
   6790   }
   6791 
   6792   /// Fetches ArrayRef of location of motion-modifiers.
   6793   ArrayRef<SourceLocation> getMotionModifiersLoc() const LLVM_READONLY {
   6794     return llvm::makeArrayRef(MotionModifiersLoc);
   6795   }
   6796 
   6797   /// Get colon location.
   6798   SourceLocation getColonLoc() const { return ColonLoc; }
   6799 
   6800   child_range children() {
   6801     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   6802                        reinterpret_cast<Stmt **>(varlist_end()));
   6803   }
   6804 
   6805   const_child_range children() const {
   6806     auto Children = const_cast<OMPFromClause *>(this)->children();
   6807     return const_child_range(Children.begin(), Children.end());
   6808   }
   6809 
   6810   child_range used_children() {
   6811     return child_range(child_iterator(), child_iterator());
   6812   }
   6813   const_child_range used_children() const {
   6814     return const_child_range(const_child_iterator(), const_child_iterator());
   6815   }
   6816 
   6817   static bool classof(const OMPClause *T) {
   6818     return T->getClauseKind() == llvm::omp::OMPC_from;
   6819   }
   6820 };
   6821 
   6822 /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
   6823 /// directives.
   6824 ///
   6825 /// \code
   6826 /// #pragma omp target data use_device_ptr(a,b)
   6827 /// \endcode
   6828 /// In this example directive '#pragma omp target data' has clause
   6829 /// 'use_device_ptr' with the variables 'a' and 'b'.
   6830 class OMPUseDevicePtrClause final
   6831     : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
   6832       private llvm::TrailingObjects<
   6833           OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
   6834           OMPClauseMappableExprCommon::MappableComponent> {
   6835   friend class OMPClauseReader;
   6836   friend OMPMappableExprListClause;
   6837   friend OMPVarListClause;
   6838   friend TrailingObjects;
   6839 
   6840   /// Build clause with number of variables \a NumVars.
   6841   ///
   6842   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   6843   /// StartLoc: starting location of the clause (the clause keyword); 2)
   6844   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   6845   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6846   /// NumVars: number of expressions listed in this clause; 2)
   6847   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6848   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6849   /// NumComponents: total number of expression components in the clause.
   6850   explicit OMPUseDevicePtrClause(const OMPVarListLocTy &Locs,
   6851                                  const OMPMappableExprListSizeTy &Sizes)
   6852       : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr, Locs, Sizes) {
   6853   }
   6854 
   6855   /// Build an empty clause.
   6856   ///
   6857   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6858   /// NumVars: number of expressions listed in this clause; 2)
   6859   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6860   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6861   /// NumComponents: total number of expression components in the clause.
   6862   explicit OMPUseDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
   6863       : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr,
   6864                                   OMPVarListLocTy(), Sizes) {}
   6865 
   6866   /// Define the sizes of each trailing object array except the last one. This
   6867   /// is required for TrailingObjects to work properly.
   6868   size_t numTrailingObjects(OverloadToken<Expr *>) const {
   6869     return 3 * varlist_size();
   6870   }
   6871   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
   6872     return getUniqueDeclarationsNum();
   6873   }
   6874   size_t numTrailingObjects(OverloadToken<unsigned>) const {
   6875     return getUniqueDeclarationsNum() + getTotalComponentListNum();
   6876   }
   6877 
   6878   /// Sets the list of references to private copies with initializers for new
   6879   /// private variables.
   6880   /// \param VL List of references.
   6881   void setPrivateCopies(ArrayRef<Expr *> VL);
   6882 
   6883   /// Gets the list of references to private copies with initializers for new
   6884   /// private variables.
   6885   MutableArrayRef<Expr *> getPrivateCopies() {
   6886     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   6887   }
   6888   ArrayRef<const Expr *> getPrivateCopies() const {
   6889     return llvm::makeArrayRef(varlist_end(), varlist_size());
   6890   }
   6891 
   6892   /// Sets the list of references to initializer variables for new private
   6893   /// variables.
   6894   /// \param VL List of references.
   6895   void setInits(ArrayRef<Expr *> VL);
   6896 
   6897   /// Gets the list of references to initializer variables for new private
   6898   /// variables.
   6899   MutableArrayRef<Expr *> getInits() {
   6900     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
   6901   }
   6902   ArrayRef<const Expr *> getInits() const {
   6903     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
   6904   }
   6905 
   6906 public:
   6907   /// Creates clause with a list of variables \a Vars.
   6908   ///
   6909   /// \param C AST context.
   6910   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   6911   /// StartLoc: starting location of the clause (the clause keyword); 2)
   6912   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   6913   /// \param Vars The original expression used in the clause.
   6914   /// \param PrivateVars Expressions referring to private copies.
   6915   /// \param Inits Expressions referring to private copy initializers.
   6916   /// \param Declarations Declarations used in the clause.
   6917   /// \param ComponentLists Component lists used in the clause.
   6918   static OMPUseDevicePtrClause *
   6919   Create(const ASTContext &C, const OMPVarListLocTy &Locs,
   6920          ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
   6921          ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
   6922          MappableExprComponentListsRef ComponentLists);
   6923 
   6924   /// Creates an empty clause with the place for \a NumVars variables.
   6925   ///
   6926   /// \param C AST context.
   6927   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   6928   /// NumVars: number of expressions listed in this clause; 2)
   6929   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   6930   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   6931   /// NumComponents: total number of expression components in the clause.
   6932   static OMPUseDevicePtrClause *
   6933   CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
   6934 
   6935   using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
   6936   using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
   6937   using private_copies_range = llvm::iterator_range<private_copies_iterator>;
   6938   using private_copies_const_range =
   6939       llvm::iterator_range<private_copies_const_iterator>;
   6940 
   6941   private_copies_range private_copies() {
   6942     return private_copies_range(getPrivateCopies().begin(),
   6943                                 getPrivateCopies().end());
   6944   }
   6945 
   6946   private_copies_const_range private_copies() const {
   6947     return private_copies_const_range(getPrivateCopies().begin(),
   6948                                       getPrivateCopies().end());
   6949   }
   6950 
   6951   using inits_iterator = MutableArrayRef<Expr *>::iterator;
   6952   using inits_const_iterator = ArrayRef<const Expr *>::iterator;
   6953   using inits_range = llvm::iterator_range<inits_iterator>;
   6954   using inits_const_range = llvm::iterator_range<inits_const_iterator>;
   6955 
   6956   inits_range inits() {
   6957     return inits_range(getInits().begin(), getInits().end());
   6958   }
   6959 
   6960   inits_const_range inits() const {
   6961     return inits_const_range(getInits().begin(), getInits().end());
   6962   }
   6963 
   6964   child_range children() {
   6965     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   6966                        reinterpret_cast<Stmt **>(varlist_end()));
   6967   }
   6968 
   6969   const_child_range children() const {
   6970     auto Children = const_cast<OMPUseDevicePtrClause *>(this)->children();
   6971     return const_child_range(Children.begin(), Children.end());
   6972   }
   6973 
   6974   child_range used_children() {
   6975     return child_range(child_iterator(), child_iterator());
   6976   }
   6977   const_child_range used_children() const {
   6978     return const_child_range(const_child_iterator(), const_child_iterator());
   6979   }
   6980 
   6981   static bool classof(const OMPClause *T) {
   6982     return T->getClauseKind() == llvm::omp::OMPC_use_device_ptr;
   6983   }
   6984 };
   6985 
   6986 /// This represents clause 'use_device_addr' in the '#pragma omp ...'
   6987 /// directives.
   6988 ///
   6989 /// \code
   6990 /// #pragma omp target data use_device_addr(a,b)
   6991 /// \endcode
   6992 /// In this example directive '#pragma omp target data' has clause
   6993 /// 'use_device_addr' with the variables 'a' and 'b'.
   6994 class OMPUseDeviceAddrClause final
   6995     : public OMPMappableExprListClause<OMPUseDeviceAddrClause>,
   6996       private llvm::TrailingObjects<
   6997           OMPUseDeviceAddrClause, Expr *, ValueDecl *, unsigned,
   6998           OMPClauseMappableExprCommon::MappableComponent> {
   6999   friend class OMPClauseReader;
   7000   friend OMPMappableExprListClause;
   7001   friend OMPVarListClause;
   7002   friend TrailingObjects;
   7003 
   7004   /// Build clause with number of variables \a NumVars.
   7005   ///
   7006   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   7007   /// StartLoc: starting location of the clause (the clause keyword); 2)
   7008   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   7009   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   7010   /// NumVars: number of expressions listed in this clause; 2)
   7011   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   7012   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   7013   /// NumComponents: total number of expression components in the clause.
   7014   explicit OMPUseDeviceAddrClause(const OMPVarListLocTy &Locs,
   7015                                   const OMPMappableExprListSizeTy &Sizes)
   7016       : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr, Locs,
   7017                                   Sizes) {}
   7018 
   7019   /// Build an empty clause.
   7020   ///
   7021   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   7022   /// NumVars: number of expressions listed in this clause; 2)
   7023   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   7024   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   7025   /// NumComponents: total number of expression components in the clause.
   7026   explicit OMPUseDeviceAddrClause(const OMPMappableExprListSizeTy &Sizes)
   7027       : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr,
   7028                                   OMPVarListLocTy(), Sizes) {}
   7029 
   7030   /// Define the sizes of each trailing object array except the last one. This
   7031   /// is required for TrailingObjects to work properly.
   7032   size_t numTrailingObjects(OverloadToken<Expr *>) const {
   7033     return varlist_size();
   7034   }
   7035   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
   7036     return getUniqueDeclarationsNum();
   7037   }
   7038   size_t numTrailingObjects(OverloadToken<unsigned>) const {
   7039     return getUniqueDeclarationsNum() + getTotalComponentListNum();
   7040   }
   7041 
   7042 public:
   7043   /// Creates clause with a list of variables \a Vars.
   7044   ///
   7045   /// \param C AST context.
   7046   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   7047   /// StartLoc: starting location of the clause (the clause keyword); 2)
   7048   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   7049   /// \param Vars The original expression used in the clause.
   7050   /// \param Declarations Declarations used in the clause.
   7051   /// \param ComponentLists Component lists used in the clause.
   7052   static OMPUseDeviceAddrClause *
   7053   Create(const ASTContext &C, const OMPVarListLocTy &Locs,
   7054          ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
   7055          MappableExprComponentListsRef ComponentLists);
   7056 
   7057   /// Creates an empty clause with the place for \a NumVars variables.
   7058   ///
   7059   /// \param C AST context.
   7060   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   7061   /// NumVars: number of expressions listed in this clause; 2)
   7062   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   7063   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   7064   /// NumComponents: total number of expression components in the clause.
   7065   static OMPUseDeviceAddrClause *
   7066   CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
   7067 
   7068   child_range children() {
   7069     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   7070                        reinterpret_cast<Stmt **>(varlist_end()));
   7071   }
   7072 
   7073   const_child_range children() const {
   7074     auto Children = const_cast<OMPUseDeviceAddrClause *>(this)->children();
   7075     return const_child_range(Children.begin(), Children.end());
   7076   }
   7077 
   7078   child_range used_children() {
   7079     return child_range(child_iterator(), child_iterator());
   7080   }
   7081   const_child_range used_children() const {
   7082     return const_child_range(const_child_iterator(), const_child_iterator());
   7083   }
   7084 
   7085   static bool classof(const OMPClause *T) {
   7086     return T->getClauseKind() == llvm::omp::OMPC_use_device_addr;
   7087   }
   7088 };
   7089 
   7090 /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
   7091 /// directives.
   7092 ///
   7093 /// \code
   7094 /// #pragma omp target is_device_ptr(a,b)
   7095 /// \endcode
   7096 /// In this example directive '#pragma omp target' has clause
   7097 /// 'is_device_ptr' with the variables 'a' and 'b'.
   7098 class OMPIsDevicePtrClause final
   7099     : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
   7100       private llvm::TrailingObjects<
   7101           OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
   7102           OMPClauseMappableExprCommon::MappableComponent> {
   7103   friend class OMPClauseReader;
   7104   friend OMPMappableExprListClause;
   7105   friend OMPVarListClause;
   7106   friend TrailingObjects;
   7107 
   7108   /// Build clause with number of variables \a NumVars.
   7109   ///
   7110   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   7111   /// StartLoc: starting location of the clause (the clause keyword); 2)
   7112   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   7113   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   7114   /// NumVars: number of expressions listed in this clause; 2)
   7115   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   7116   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   7117   /// NumComponents: total number of expression components in the clause.
   7118   explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs,
   7119                                 const OMPMappableExprListSizeTy &Sizes)
   7120       : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr, Locs, Sizes) {}
   7121 
   7122   /// Build an empty clause.
   7123   ///
   7124   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   7125   /// NumVars: number of expressions listed in this clause; 2)
   7126   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   7127   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   7128   /// NumComponents: total number of expression components in the clause.
   7129   explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
   7130       : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr,
   7131                                   OMPVarListLocTy(), Sizes) {}
   7132 
   7133   /// Define the sizes of each trailing object array except the last one. This
   7134   /// is required for TrailingObjects to work properly.
   7135   size_t numTrailingObjects(OverloadToken<Expr *>) const {
   7136     return varlist_size();
   7137   }
   7138   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
   7139     return getUniqueDeclarationsNum();
   7140   }
   7141   size_t numTrailingObjects(OverloadToken<unsigned>) const {
   7142     return getUniqueDeclarationsNum() + getTotalComponentListNum();
   7143   }
   7144 
   7145 public:
   7146   /// Creates clause with a list of variables \a Vars.
   7147   ///
   7148   /// \param C AST context.
   7149   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   7150   /// StartLoc: starting location of the clause (the clause keyword); 2)
   7151   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
   7152   /// \param Vars The original expression used in the clause.
   7153   /// \param Declarations Declarations used in the clause.
   7154   /// \param ComponentLists Component lists used in the clause.
   7155   static OMPIsDevicePtrClause *
   7156   Create(const ASTContext &C, const OMPVarListLocTy &Locs,
   7157          ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
   7158          MappableExprComponentListsRef ComponentLists);
   7159 
   7160   /// Creates an empty clause with the place for \a NumVars variables.
   7161   ///
   7162   /// \param C AST context.
   7163   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
   7164   /// NumVars: number of expressions listed in this clause; 2)
   7165   /// NumUniqueDeclarations: number of unique base declarations in this clause;
   7166   /// 3) NumComponentLists: number of component lists in this clause; and 4)
   7167   /// NumComponents: total number of expression components in the clause.
   7168   static OMPIsDevicePtrClause *
   7169   CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
   7170 
   7171   child_range children() {
   7172     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   7173                        reinterpret_cast<Stmt **>(varlist_end()));
   7174   }
   7175 
   7176   const_child_range children() const {
   7177     auto Children = const_cast<OMPIsDevicePtrClause *>(this)->children();
   7178     return const_child_range(Children.begin(), Children.end());
   7179   }
   7180 
   7181   child_range used_children() {
   7182     return child_range(child_iterator(), child_iterator());
   7183   }
   7184   const_child_range used_children() const {
   7185     return const_child_range(const_child_iterator(), const_child_iterator());
   7186   }
   7187 
   7188   static bool classof(const OMPClause *T) {
   7189     return T->getClauseKind() == llvm::omp::OMPC_is_device_ptr;
   7190   }
   7191 };
   7192 
   7193 /// This represents clause 'nontemporal' in the '#pragma omp ...' directives.
   7194 ///
   7195 /// \code
   7196 /// #pragma omp simd nontemporal(a)
   7197 /// \endcode
   7198 /// In this example directive '#pragma omp simd' has clause 'nontemporal' for
   7199 /// the variable 'a'.
   7200 class OMPNontemporalClause final
   7201     : public OMPVarListClause<OMPNontemporalClause>,
   7202       private llvm::TrailingObjects<OMPNontemporalClause, Expr *> {
   7203   friend class OMPClauseReader;
   7204   friend OMPVarListClause;
   7205   friend TrailingObjects;
   7206 
   7207   /// Build clause with number of variables \a N.
   7208   ///
   7209   /// \param StartLoc Starting location of the clause.
   7210   /// \param LParenLoc Location of '('.
   7211   /// \param EndLoc Ending location of the clause.
   7212   /// \param N Number of the variables in the clause.
   7213   OMPNontemporalClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   7214                        SourceLocation EndLoc, unsigned N)
   7215       : OMPVarListClause<OMPNontemporalClause>(llvm::omp::OMPC_nontemporal,
   7216                                                StartLoc, LParenLoc, EndLoc, N) {
   7217   }
   7218 
   7219   /// Build an empty clause.
   7220   ///
   7221   /// \param N Number of variables.
   7222   explicit OMPNontemporalClause(unsigned N)
   7223       : OMPVarListClause<OMPNontemporalClause>(
   7224             llvm::omp::OMPC_nontemporal, SourceLocation(), SourceLocation(),
   7225             SourceLocation(), N) {}
   7226 
   7227   /// Get the list of privatied copies if the member expression was captured by
   7228   /// one of the privatization clauses.
   7229   MutableArrayRef<Expr *> getPrivateRefs() {
   7230     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   7231   }
   7232   ArrayRef<const Expr *> getPrivateRefs() const {
   7233     return llvm::makeArrayRef(varlist_end(), varlist_size());
   7234   }
   7235 
   7236 public:
   7237   /// Creates clause with a list of variables \a VL.
   7238   ///
   7239   /// \param C AST context.
   7240   /// \param StartLoc Starting location of the clause.
   7241   /// \param LParenLoc Location of '('.
   7242   /// \param EndLoc Ending location of the clause.
   7243   /// \param VL List of references to the variables.
   7244   static OMPNontemporalClause *
   7245   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   7246          SourceLocation EndLoc, ArrayRef<Expr *> VL);
   7247 
   7248   /// Creates an empty clause with the place for \a N variables.
   7249   ///
   7250   /// \param C AST context.
   7251   /// \param N The number of variables.
   7252   static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N);
   7253 
   7254   /// Sets the list of references to private copies created in private clauses.
   7255   /// \param VL List of references.
   7256   void setPrivateRefs(ArrayRef<Expr *> VL);
   7257 
   7258   child_range children() {
   7259     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   7260                        reinterpret_cast<Stmt **>(varlist_end()));
   7261   }
   7262 
   7263   const_child_range children() const {
   7264     auto Children = const_cast<OMPNontemporalClause *>(this)->children();
   7265     return const_child_range(Children.begin(), Children.end());
   7266   }
   7267 
   7268   child_range private_refs() {
   7269     return child_range(reinterpret_cast<Stmt **>(getPrivateRefs().begin()),
   7270                        reinterpret_cast<Stmt **>(getPrivateRefs().end()));
   7271   }
   7272 
   7273   const_child_range private_refs() const {
   7274     auto Children = const_cast<OMPNontemporalClause *>(this)->private_refs();
   7275     return const_child_range(Children.begin(), Children.end());
   7276   }
   7277 
   7278   child_range used_children() {
   7279     return child_range(child_iterator(), child_iterator());
   7280   }
   7281   const_child_range used_children() const {
   7282     return const_child_range(const_child_iterator(), const_child_iterator());
   7283   }
   7284 
   7285   static bool classof(const OMPClause *T) {
   7286     return T->getClauseKind() == llvm::omp::OMPC_nontemporal;
   7287   }
   7288 };
   7289 
   7290 /// This represents 'order' clause in the '#pragma omp ...' directive.
   7291 ///
   7292 /// \code
   7293 /// #pragma omp simd order(concurrent)
   7294 /// \endcode
   7295 /// In this example directive '#pragma omp parallel' has simple 'order'
   7296 /// clause with kind 'concurrent'.
   7297 class OMPOrderClause final : public OMPClause {
   7298   friend class OMPClauseReader;
   7299 
   7300   /// Location of '('.
   7301   SourceLocation LParenLoc;
   7302 
   7303   /// A kind of the 'default' clause.
   7304   OpenMPOrderClauseKind Kind = OMPC_ORDER_unknown;
   7305 
   7306   /// Start location of the kind in source code.
   7307   SourceLocation KindKwLoc;
   7308 
   7309   /// Set kind of the clause.
   7310   ///
   7311   /// \param K Argument of clause.
   7312   void setKind(OpenMPOrderClauseKind K) { Kind = K; }
   7313 
   7314   /// Set argument location.
   7315   ///
   7316   /// \param KLoc Argument location.
   7317   void setKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
   7318 
   7319 public:
   7320   /// Build 'order' clause with argument \p A ('concurrent').
   7321   ///
   7322   /// \param A Argument of the clause ('concurrent').
   7323   /// \param ALoc Starting location of the argument.
   7324   /// \param StartLoc Starting location of the clause.
   7325   /// \param LParenLoc Location of '('.
   7326   /// \param EndLoc Ending location of the clause.
   7327   OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc,
   7328                  SourceLocation StartLoc, SourceLocation LParenLoc,
   7329                  SourceLocation EndLoc)
   7330       : OMPClause(llvm::omp::OMPC_order, StartLoc, EndLoc),
   7331         LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
   7332 
   7333   /// Build an empty clause.
   7334   OMPOrderClause()
   7335       : OMPClause(llvm::omp::OMPC_order, SourceLocation(), SourceLocation()) {}
   7336 
   7337   /// Sets the location of '('.
   7338   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   7339 
   7340   /// Returns the location of '('.
   7341   SourceLocation getLParenLoc() const { return LParenLoc; }
   7342 
   7343   /// Returns kind of the clause.
   7344   OpenMPOrderClauseKind getKind() const { return Kind; }
   7345 
   7346   /// Returns location of clause kind.
   7347   SourceLocation getKindKwLoc() const { return KindKwLoc; }
   7348 
   7349   child_range children() {
   7350     return child_range(child_iterator(), child_iterator());
   7351   }
   7352 
   7353   const_child_range children() const {
   7354     return const_child_range(const_child_iterator(), const_child_iterator());
   7355   }
   7356 
   7357   child_range used_children() {
   7358     return child_range(child_iterator(), child_iterator());
   7359   }
   7360   const_child_range used_children() const {
   7361     return const_child_range(const_child_iterator(), const_child_iterator());
   7362   }
   7363 
   7364   static bool classof(const OMPClause *T) {
   7365     return T->getClauseKind() == llvm::omp::OMPC_order;
   7366   }
   7367 };
   7368 
   7369 /// This represents the 'init' clause in '#pragma omp ...' directives.
   7370 ///
   7371 /// \code
   7372 /// #pragma omp interop init(target:obj)
   7373 /// \endcode
   7374 class OMPInitClause final
   7375     : public OMPVarListClause<OMPInitClause>,
   7376       private llvm::TrailingObjects<OMPInitClause, Expr *> {
   7377   friend class OMPClauseReader;
   7378   friend OMPVarListClause;
   7379   friend TrailingObjects;
   7380 
   7381   /// Location of interop variable.
   7382   SourceLocation VarLoc;
   7383 
   7384   bool IsTarget = false;
   7385   bool IsTargetSync = false;
   7386 
   7387   void setInteropVar(Expr *E) { varlist_begin()[0] = E; }
   7388 
   7389   void setIsTarget(bool V) { IsTarget = V; }
   7390 
   7391   void setIsTargetSync(bool V) { IsTargetSync = V; }
   7392 
   7393   /// Sets the location of the interop variable.
   7394   void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
   7395 
   7396   /// Build 'init' clause.
   7397   ///
   7398   /// \param IsTarget Uses the 'target' interop-type.
   7399   /// \param IsTargetSync Uses the 'targetsync' interop-type.
   7400   /// \param StartLoc Starting location of the clause.
   7401   /// \param LParenLoc Location of '('.
   7402   /// \param VarLoc Location of the interop variable.
   7403   /// \param EndLoc Ending location of the clause.
   7404   /// \param N Number of expressions.
   7405   OMPInitClause(bool IsTarget, bool IsTargetSync, SourceLocation StartLoc,
   7406                 SourceLocation LParenLoc, SourceLocation VarLoc,
   7407                 SourceLocation EndLoc, unsigned N)
   7408       : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, StartLoc,
   7409                                         LParenLoc, EndLoc, N),
   7410         VarLoc(VarLoc), IsTarget(IsTarget), IsTargetSync(IsTargetSync) {}
   7411 
   7412   /// Build an empty clause.
   7413   OMPInitClause(unsigned N)
   7414       : OMPVarListClause<OMPInitClause>(llvm::omp::OMPC_init, SourceLocation(),
   7415                                         SourceLocation(), SourceLocation(), N) {
   7416   }
   7417 
   7418 public:
   7419   /// Creates a fully specified clause.
   7420   ///
   7421   /// \param C AST context.
   7422   /// \param InteropVar The interop variable.
   7423   /// \param PrefExprs The list of preference expressions.
   7424   /// \param IsTarget Uses the 'target' interop-type.
   7425   /// \param IsTargetSync Uses the 'targetsync' interop-type.
   7426   /// \param StartLoc Starting location of the clause.
   7427   /// \param LParenLoc Location of '('.
   7428   /// \param VarLoc Location of the interop variable.
   7429   /// \param EndLoc Ending location of the clause.
   7430   static OMPInitClause *Create(const ASTContext &C, Expr *InteropVar,
   7431                                ArrayRef<Expr *> PrefExprs, bool IsTarget,
   7432                                bool IsTargetSync, SourceLocation StartLoc,
   7433                                SourceLocation LParenLoc, SourceLocation VarLoc,
   7434                                SourceLocation EndLoc);
   7435 
   7436   /// Creates an empty clause with \a N expressions.
   7437   ///
   7438   /// \param C AST context.
   7439   /// \param N Number of expression items.
   7440   static OMPInitClause *CreateEmpty(const ASTContext &C, unsigned N);
   7441 
   7442   /// Returns the location of the interop variable.
   7443   SourceLocation getVarLoc() const { return VarLoc; }
   7444 
   7445   /// Returns the interop variable.
   7446   Expr *getInteropVar() { return varlist_begin()[0]; }
   7447   const Expr *getInteropVar() const { return varlist_begin()[0]; }
   7448 
   7449   /// Returns true is interop-type 'target' is used.
   7450   bool getIsTarget() const { return IsTarget; }
   7451 
   7452   /// Returns true is interop-type 'targetsync' is used.
   7453   bool getIsTargetSync() const { return IsTargetSync; }
   7454 
   7455   child_range children() {
   7456     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   7457                        reinterpret_cast<Stmt **>(varlist_end()));
   7458   }
   7459 
   7460   const_child_range children() const {
   7461     auto Children = const_cast<OMPInitClause *>(this)->children();
   7462     return const_child_range(Children.begin(), Children.end());
   7463   }
   7464 
   7465   child_range used_children() {
   7466     return child_range(child_iterator(), child_iterator());
   7467   }
   7468   const_child_range used_children() const {
   7469     return const_child_range(const_child_iterator(), const_child_iterator());
   7470   }
   7471 
   7472   using prefs_iterator = MutableArrayRef<Expr *>::iterator;
   7473   using const_prefs_iterator = ArrayRef<const Expr *>::iterator;
   7474   using prefs_range = llvm::iterator_range<prefs_iterator>;
   7475   using const_prefs_range = llvm::iterator_range<const_prefs_iterator>;
   7476 
   7477   prefs_range prefs() {
   7478     return prefs_range(reinterpret_cast<Expr **>(std::next(varlist_begin())),
   7479                        reinterpret_cast<Expr **>(varlist_end()));
   7480   }
   7481 
   7482   const_prefs_range prefs() const {
   7483     auto Prefs = const_cast<OMPInitClause *>(this)->prefs();
   7484     return const_prefs_range(Prefs.begin(), Prefs.end());
   7485   }
   7486 
   7487   static bool classof(const OMPClause *T) {
   7488     return T->getClauseKind() == llvm::omp::OMPC_init;
   7489   }
   7490 };
   7491 
   7492 /// This represents the 'use' clause in '#pragma omp ...' directives.
   7493 ///
   7494 /// \code
   7495 /// #pragma omp interop use(obj)
   7496 /// \endcode
   7497 class OMPUseClause final : public OMPClause {
   7498   friend class OMPClauseReader;
   7499 
   7500   /// Location of '('.
   7501   SourceLocation LParenLoc;
   7502 
   7503   /// Location of interop variable.
   7504   SourceLocation VarLoc;
   7505 
   7506   /// The interop variable.
   7507   Stmt *InteropVar = nullptr;
   7508 
   7509   /// Set the interop variable.
   7510   void setInteropVar(Expr *E) { InteropVar = E; }
   7511 
   7512   /// Sets the location of '('.
   7513   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   7514 
   7515   /// Sets the location of the interop variable.
   7516   void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
   7517 
   7518 public:
   7519   /// Build 'use' clause with and interop variable expression \a InteropVar.
   7520   ///
   7521   /// \param InteropVar The interop variable.
   7522   /// \param StartLoc Starting location of the clause.
   7523   /// \param LParenLoc Location of '('.
   7524   /// \param VarLoc Location of the interop variable.
   7525   /// \param EndLoc Ending location of the clause.
   7526   OMPUseClause(Expr *InteropVar, SourceLocation StartLoc,
   7527                SourceLocation LParenLoc, SourceLocation VarLoc,
   7528                SourceLocation EndLoc)
   7529       : OMPClause(llvm::omp::OMPC_use, StartLoc, EndLoc), LParenLoc(LParenLoc),
   7530         VarLoc(VarLoc), InteropVar(InteropVar) {}
   7531 
   7532   /// Build an empty clause.
   7533   OMPUseClause()
   7534       : OMPClause(llvm::omp::OMPC_use, SourceLocation(), SourceLocation()) {}
   7535 
   7536   /// Returns the location of '('.
   7537   SourceLocation getLParenLoc() const { return LParenLoc; }
   7538 
   7539   /// Returns the location of the interop variable.
   7540   SourceLocation getVarLoc() const { return VarLoc; }
   7541 
   7542   /// Returns the interop variable.
   7543   Expr *getInteropVar() const { return cast<Expr>(InteropVar); }
   7544 
   7545   child_range children() { return child_range(&InteropVar, &InteropVar + 1); }
   7546 
   7547   const_child_range children() const {
   7548     return const_child_range(&InteropVar, &InteropVar + 1);
   7549   }
   7550 
   7551   child_range used_children() {
   7552     return child_range(child_iterator(), child_iterator());
   7553   }
   7554   const_child_range used_children() const {
   7555     return const_child_range(const_child_iterator(), const_child_iterator());
   7556   }
   7557 
   7558   static bool classof(const OMPClause *T) {
   7559     return T->getClauseKind() == llvm::omp::OMPC_use;
   7560   }
   7561 };
   7562 
   7563 /// This represents 'destroy' clause in the '#pragma omp depobj'
   7564 /// directive or the '#pragma omp interop' directive..
   7565 ///
   7566 /// \code
   7567 /// #pragma omp depobj(a) destroy
   7568 /// #pragma omp interop destroy(obj)
   7569 /// \endcode
   7570 /// In these examples directive '#pragma omp depobj' and '#pragma omp interop'
   7571 /// have a 'destroy' clause. The 'interop' directive includes an object.
   7572 class OMPDestroyClause final : public OMPClause {
   7573   friend class OMPClauseReader;
   7574 
   7575   /// Location of '('.
   7576   SourceLocation LParenLoc;
   7577 
   7578   /// Location of interop variable.
   7579   SourceLocation VarLoc;
   7580 
   7581   /// The interop variable.
   7582   Stmt *InteropVar = nullptr;
   7583 
   7584   /// Set the interop variable.
   7585   void setInteropVar(Expr *E) { InteropVar = E; }
   7586 
   7587   /// Sets the location of '('.
   7588   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   7589 
   7590   /// Sets the location of the interop variable.
   7591   void setVarLoc(SourceLocation Loc) { VarLoc = Loc; }
   7592 
   7593 public:
   7594   /// Build 'destroy' clause with an interop variable expression \a InteropVar.
   7595   ///
   7596   /// \param InteropVar The interop variable.
   7597   /// \param StartLoc Starting location of the clause.
   7598   /// \param LParenLoc Location of '('.
   7599   /// \param VarLoc Location of the interop variable.
   7600   /// \param EndLoc Ending location of the clause.
   7601   OMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc,
   7602                    SourceLocation LParenLoc, SourceLocation VarLoc,
   7603                    SourceLocation EndLoc)
   7604       : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc),
   7605         LParenLoc(LParenLoc), VarLoc(VarLoc), InteropVar(InteropVar) {}
   7606 
   7607   /// Build 'destroy' clause.
   7608   ///
   7609   /// \param StartLoc Starting location of the clause.
   7610   /// \param EndLoc Ending location of the clause.
   7611   OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
   7612       : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc) {}
   7613 
   7614   /// Build an empty clause.
   7615   OMPDestroyClause()
   7616       : OMPClause(llvm::omp::OMPC_destroy, SourceLocation(), SourceLocation()) {
   7617   }
   7618 
   7619   /// Returns the location of '('.
   7620   SourceLocation getLParenLoc() const { return LParenLoc; }
   7621 
   7622   /// Returns the location of the interop variable.
   7623   SourceLocation getVarLoc() const { return VarLoc; }
   7624 
   7625   /// Returns the interop variable.
   7626   Expr *getInteropVar() const { return cast_or_null<Expr>(InteropVar); }
   7627 
   7628   child_range children() {
   7629     if (InteropVar)
   7630       return child_range(&InteropVar, &InteropVar + 1);
   7631     return child_range(child_iterator(), child_iterator());
   7632   }
   7633 
   7634   const_child_range children() const {
   7635     if (InteropVar)
   7636       return const_child_range(&InteropVar, &InteropVar + 1);
   7637     return const_child_range(const_child_iterator(), const_child_iterator());
   7638   }
   7639 
   7640   child_range used_children() {
   7641     return child_range(child_iterator(), child_iterator());
   7642   }
   7643   const_child_range used_children() const {
   7644     return const_child_range(const_child_iterator(), const_child_iterator());
   7645   }
   7646 
   7647   static bool classof(const OMPClause *T) {
   7648     return T->getClauseKind() == llvm::omp::OMPC_destroy;
   7649   }
   7650 };
   7651 
   7652 /// This represents 'novariants' clause in the '#pragma omp ...' directive.
   7653 ///
   7654 /// \code
   7655 /// #pragma omp dispatch novariants(a > 5)
   7656 /// \endcode
   7657 /// In this example directive '#pragma omp dispatch' has simple 'novariants'
   7658 /// clause with condition 'a > 5'.
   7659 class OMPNovariantsClause final : public OMPClause,
   7660                                   public OMPClauseWithPreInit {
   7661   friend class OMPClauseReader;
   7662 
   7663   /// Location of '('.
   7664   SourceLocation LParenLoc;
   7665 
   7666   /// Condition of the 'if' clause.
   7667   Stmt *Condition = nullptr;
   7668 
   7669   /// Set condition.
   7670   void setCondition(Expr *Cond) { Condition = Cond; }
   7671 
   7672   /// Sets the location of '('.
   7673   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   7674 
   7675 public:
   7676   /// Build 'novariants' clause with condition \a Cond.
   7677   ///
   7678   /// \param Cond Condition of the clause.
   7679   /// \param HelperCond Helper condition for the construct.
   7680   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   7681   /// clause must be captured.
   7682   /// \param StartLoc Starting location of the clause.
   7683   /// \param LParenLoc Location of '('.
   7684   /// \param EndLoc Ending location of the clause.
   7685   OMPNovariantsClause(Expr *Cond, Stmt *HelperCond,
   7686                       OpenMPDirectiveKind CaptureRegion,
   7687                       SourceLocation StartLoc, SourceLocation LParenLoc,
   7688                       SourceLocation EndLoc)
   7689       : OMPClause(llvm::omp::OMPC_novariants, StartLoc, EndLoc),
   7690         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
   7691     setPreInitStmt(HelperCond, CaptureRegion);
   7692   }
   7693 
   7694   /// Build an empty clause.
   7695   OMPNovariantsClause()
   7696       : OMPClause(llvm::omp::OMPC_novariants, SourceLocation(),
   7697                   SourceLocation()),
   7698         OMPClauseWithPreInit(this) {}
   7699 
   7700   /// Returns the location of '('.
   7701   SourceLocation getLParenLoc() const { return LParenLoc; }
   7702 
   7703   /// Returns condition.
   7704   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
   7705 
   7706   child_range children() { return child_range(&Condition, &Condition + 1); }
   7707 
   7708   const_child_range children() const {
   7709     return const_child_range(&Condition, &Condition + 1);
   7710   }
   7711 
   7712   child_range used_children();
   7713   const_child_range used_children() const {
   7714     auto Children = const_cast<OMPNovariantsClause *>(this)->used_children();
   7715     return const_child_range(Children.begin(), Children.end());
   7716   }
   7717 
   7718   static bool classof(const OMPClause *T) {
   7719     return T->getClauseKind() == llvm::omp::OMPC_novariants;
   7720   }
   7721 };
   7722 
   7723 /// This represents 'nocontext' clause in the '#pragma omp ...' directive.
   7724 ///
   7725 /// \code
   7726 /// #pragma omp dispatch nocontext(a > 5)
   7727 /// \endcode
   7728 /// In this example directive '#pragma omp dispatch' has simple 'nocontext'
   7729 /// clause with condition 'a > 5'.
   7730 class OMPNocontextClause final : public OMPClause, public OMPClauseWithPreInit {
   7731   friend class OMPClauseReader;
   7732 
   7733   /// Location of '('.
   7734   SourceLocation LParenLoc;
   7735 
   7736   /// Condition of the 'if' clause.
   7737   Stmt *Condition = nullptr;
   7738 
   7739   /// Set condition.
   7740   void setCondition(Expr *Cond) { Condition = Cond; }
   7741 
   7742   /// Sets the location of '('.
   7743   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   7744 
   7745 public:
   7746   /// Build 'nocontext' clause with condition \a Cond.
   7747   ///
   7748   /// \param Cond Condition of the clause.
   7749   /// \param HelperCond Helper condition for the construct.
   7750   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   7751   /// clause must be captured.
   7752   /// \param StartLoc Starting location of the clause.
   7753   /// \param LParenLoc Location of '('.
   7754   /// \param EndLoc Ending location of the clause.
   7755   OMPNocontextClause(Expr *Cond, Stmt *HelperCond,
   7756                      OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
   7757                      SourceLocation LParenLoc, SourceLocation EndLoc)
   7758       : OMPClause(llvm::omp::OMPC_nocontext, StartLoc, EndLoc),
   7759         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
   7760     setPreInitStmt(HelperCond, CaptureRegion);
   7761   }
   7762 
   7763   /// Build an empty clause.
   7764   OMPNocontextClause()
   7765       : OMPClause(llvm::omp::OMPC_nocontext, SourceLocation(),
   7766                   SourceLocation()),
   7767         OMPClauseWithPreInit(this) {}
   7768 
   7769   /// Returns the location of '('.
   7770   SourceLocation getLParenLoc() const { return LParenLoc; }
   7771 
   7772   /// Returns condition.
   7773   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
   7774 
   7775   child_range children() { return child_range(&Condition, &Condition + 1); }
   7776 
   7777   const_child_range children() const {
   7778     return const_child_range(&Condition, &Condition + 1);
   7779   }
   7780 
   7781   child_range used_children();
   7782   const_child_range used_children() const {
   7783     auto Children = const_cast<OMPNocontextClause *>(this)->used_children();
   7784     return const_child_range(Children.begin(), Children.end());
   7785   }
   7786 
   7787   static bool classof(const OMPClause *T) {
   7788     return T->getClauseKind() == llvm::omp::OMPC_nocontext;
   7789   }
   7790 };
   7791 
   7792 /// This represents 'detach' clause in the '#pragma omp task' directive.
   7793 ///
   7794 /// \code
   7795 /// #pragma omp task detach(evt)
   7796 /// \endcode
   7797 /// In this example directive '#pragma omp detach' has simple 'detach' clause
   7798 /// with the variable 'evt'.
   7799 class OMPDetachClause final : public OMPClause {
   7800   friend class OMPClauseReader;
   7801 
   7802   /// Location of '('.
   7803   SourceLocation LParenLoc;
   7804 
   7805   /// Expression of the 'detach' clause.
   7806   Stmt *Evt = nullptr;
   7807 
   7808   /// Set condition.
   7809   void setEventHandler(Expr *E) { Evt = E; }
   7810 
   7811   /// Sets the location of '('.
   7812   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   7813 
   7814 public:
   7815   /// Build 'detach' clause with event-handler \a Evt.
   7816   ///
   7817   /// \param Evt Event handler expression.
   7818   /// \param StartLoc Starting location of the clause.
   7819   /// \param LParenLoc Location of '('.
   7820   /// \param EndLoc Ending location of the clause.
   7821   OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc,
   7822                   SourceLocation EndLoc)
   7823       : OMPClause(llvm::omp::OMPC_detach, StartLoc, EndLoc),
   7824         LParenLoc(LParenLoc), Evt(Evt) {}
   7825 
   7826   /// Build an empty clause.
   7827   OMPDetachClause()
   7828       : OMPClause(llvm::omp::OMPC_detach, SourceLocation(), SourceLocation()) {}
   7829 
   7830   /// Returns the location of '('.
   7831   SourceLocation getLParenLoc() const { return LParenLoc; }
   7832 
   7833   /// Returns event-handler expression.
   7834   Expr *getEventHandler() const { return cast_or_null<Expr>(Evt); }
   7835 
   7836   child_range children() { return child_range(&Evt, &Evt + 1); }
   7837 
   7838   const_child_range children() const {
   7839     return const_child_range(&Evt, &Evt + 1);
   7840   }
   7841 
   7842   child_range used_children() {
   7843     return child_range(child_iterator(), child_iterator());
   7844   }
   7845   const_child_range used_children() const {
   7846     return const_child_range(const_child_iterator(), const_child_iterator());
   7847   }
   7848 
   7849   static bool classof(const OMPClause *T) {
   7850     return T->getClauseKind() == llvm::omp::OMPC_detach;
   7851   }
   7852 };
   7853 
   7854 /// This represents clause 'inclusive' in the '#pragma omp scan' directive.
   7855 ///
   7856 /// \code
   7857 /// #pragma omp scan inclusive(a,b)
   7858 /// \endcode
   7859 /// In this example directive '#pragma omp scan' has clause 'inclusive'
   7860 /// with the variables 'a' and 'b'.
   7861 class OMPInclusiveClause final
   7862     : public OMPVarListClause<OMPInclusiveClause>,
   7863       private llvm::TrailingObjects<OMPInclusiveClause, Expr *> {
   7864   friend class OMPClauseReader;
   7865   friend OMPVarListClause;
   7866   friend TrailingObjects;
   7867 
   7868   /// Build clause with number of variables \a N.
   7869   ///
   7870   /// \param StartLoc Starting location of the clause.
   7871   /// \param LParenLoc Location of '('.
   7872   /// \param EndLoc Ending location of the clause.
   7873   /// \param N Number of the variables in the clause.
   7874   OMPInclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   7875                      SourceLocation EndLoc, unsigned N)
   7876       : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
   7877                                              StartLoc, LParenLoc, EndLoc, N) {}
   7878 
   7879   /// Build an empty clause.
   7880   ///
   7881   /// \param N Number of variables.
   7882   explicit OMPInclusiveClause(unsigned N)
   7883       : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
   7884                                              SourceLocation(), SourceLocation(),
   7885                                              SourceLocation(), N) {}
   7886 
   7887 public:
   7888   /// Creates clause with a list of variables \a VL.
   7889   ///
   7890   /// \param C AST context.
   7891   /// \param StartLoc Starting location of the clause.
   7892   /// \param LParenLoc Location of '('.
   7893   /// \param EndLoc Ending location of the clause.
   7894   /// \param VL List of references to the original variables.
   7895   static OMPInclusiveClause *Create(const ASTContext &C,
   7896                                     SourceLocation StartLoc,
   7897                                     SourceLocation LParenLoc,
   7898                                     SourceLocation EndLoc, ArrayRef<Expr *> VL);
   7899 
   7900   /// Creates an empty clause with the place for \a N variables.
   7901   ///
   7902   /// \param C AST context.
   7903   /// \param N The number of variables.
   7904   static OMPInclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
   7905 
   7906   child_range children() {
   7907     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   7908                        reinterpret_cast<Stmt **>(varlist_end()));
   7909   }
   7910 
   7911   const_child_range children() const {
   7912     auto Children = const_cast<OMPInclusiveClause *>(this)->children();
   7913     return const_child_range(Children.begin(), Children.end());
   7914   }
   7915 
   7916   child_range used_children() {
   7917     return child_range(child_iterator(), child_iterator());
   7918   }
   7919   const_child_range used_children() const {
   7920     return const_child_range(const_child_iterator(), const_child_iterator());
   7921   }
   7922 
   7923   static bool classof(const OMPClause *T) {
   7924     return T->getClauseKind() == llvm::omp::OMPC_inclusive;
   7925   }
   7926 };
   7927 
   7928 /// This represents clause 'exclusive' in the '#pragma omp scan' directive.
   7929 ///
   7930 /// \code
   7931 /// #pragma omp scan exclusive(a,b)
   7932 /// \endcode
   7933 /// In this example directive '#pragma omp scan' has clause 'exclusive'
   7934 /// with the variables 'a' and 'b'.
   7935 class OMPExclusiveClause final
   7936     : public OMPVarListClause<OMPExclusiveClause>,
   7937       private llvm::TrailingObjects<OMPExclusiveClause, Expr *> {
   7938   friend class OMPClauseReader;
   7939   friend OMPVarListClause;
   7940   friend TrailingObjects;
   7941 
   7942   /// Build clause with number of variables \a N.
   7943   ///
   7944   /// \param StartLoc Starting location of the clause.
   7945   /// \param LParenLoc Location of '('.
   7946   /// \param EndLoc Ending location of the clause.
   7947   /// \param N Number of the variables in the clause.
   7948   OMPExclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   7949                      SourceLocation EndLoc, unsigned N)
   7950       : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
   7951                                              StartLoc, LParenLoc, EndLoc, N) {}
   7952 
   7953   /// Build an empty clause.
   7954   ///
   7955   /// \param N Number of variables.
   7956   explicit OMPExclusiveClause(unsigned N)
   7957       : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
   7958                                              SourceLocation(), SourceLocation(),
   7959                                              SourceLocation(), N) {}
   7960 
   7961 public:
   7962   /// Creates clause with a list of variables \a VL.
   7963   ///
   7964   /// \param C AST context.
   7965   /// \param StartLoc Starting location of the clause.
   7966   /// \param LParenLoc Location of '('.
   7967   /// \param EndLoc Ending location of the clause.
   7968   /// \param VL List of references to the original variables.
   7969   static OMPExclusiveClause *Create(const ASTContext &C,
   7970                                     SourceLocation StartLoc,
   7971                                     SourceLocation LParenLoc,
   7972                                     SourceLocation EndLoc, ArrayRef<Expr *> VL);
   7973 
   7974   /// Creates an empty clause with the place for \a N variables.
   7975   ///
   7976   /// \param C AST context.
   7977   /// \param N The number of variables.
   7978   static OMPExclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
   7979 
   7980   child_range children() {
   7981     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   7982                        reinterpret_cast<Stmt **>(varlist_end()));
   7983   }
   7984 
   7985   const_child_range children() const {
   7986     auto Children = const_cast<OMPExclusiveClause *>(this)->children();
   7987     return const_child_range(Children.begin(), Children.end());
   7988   }
   7989 
   7990   child_range used_children() {
   7991     return child_range(child_iterator(), child_iterator());
   7992   }
   7993   const_child_range used_children() const {
   7994     return const_child_range(const_child_iterator(), const_child_iterator());
   7995   }
   7996 
   7997   static bool classof(const OMPClause *T) {
   7998     return T->getClauseKind() == llvm::omp::OMPC_exclusive;
   7999   }
   8000 };
   8001 
   8002 /// This represents clause 'uses_allocators' in the '#pragma omp target'-based
   8003 /// directives.
   8004 ///
   8005 /// \code
   8006 /// #pragma omp target uses_allocators(default_allocator, my_allocator(traits))
   8007 /// \endcode
   8008 /// In this example directive '#pragma omp target' has clause 'uses_allocators'
   8009 /// with the allocators 'default_allocator' and user-defined 'my_allocator'.
   8010 class OMPUsesAllocatorsClause final
   8011     : public OMPClause,
   8012       private llvm::TrailingObjects<OMPUsesAllocatorsClause, Expr *,
   8013                                     SourceLocation> {
   8014 public:
   8015   /// Data for list of allocators.
   8016   struct Data {
   8017     /// Allocator.
   8018     Expr *Allocator = nullptr;
   8019     /// Allocator traits.
   8020     Expr *AllocatorTraits = nullptr;
   8021     /// Locations of '(' and ')' symbols.
   8022     SourceLocation LParenLoc, RParenLoc;
   8023   };
   8024 
   8025 private:
   8026   friend class OMPClauseReader;
   8027   friend TrailingObjects;
   8028 
   8029   enum class ExprOffsets {
   8030     Allocator,
   8031     AllocatorTraits,
   8032     Total,
   8033   };
   8034 
   8035   enum class ParenLocsOffsets {
   8036     LParen,
   8037     RParen,
   8038     Total,
   8039   };
   8040 
   8041   /// Location of '('.
   8042   SourceLocation LParenLoc;
   8043   /// Total number of allocators in the clause.
   8044   unsigned NumOfAllocators = 0;
   8045 
   8046   /// Build clause.
   8047   ///
   8048   /// \param StartLoc Starting location of the clause.
   8049   /// \param LParenLoc Location of '('.
   8050   /// \param EndLoc Ending location of the clause.
   8051   /// \param N Number of allocators asssociated with the clause.
   8052   OMPUsesAllocatorsClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   8053                           SourceLocation EndLoc, unsigned N)
   8054       : OMPClause(llvm::omp::OMPC_uses_allocators, StartLoc, EndLoc),
   8055         LParenLoc(LParenLoc), NumOfAllocators(N) {}
   8056 
   8057   /// Build an empty clause.
   8058   /// \param N Number of allocators asssociated with the clause.
   8059   ///
   8060   explicit OMPUsesAllocatorsClause(unsigned N)
   8061       : OMPClause(llvm::omp::OMPC_uses_allocators, SourceLocation(),
   8062                   SourceLocation()),
   8063         NumOfAllocators(N) {}
   8064 
   8065   unsigned numTrailingObjects(OverloadToken<Expr *>) const {
   8066     return NumOfAllocators * static_cast<int>(ExprOffsets::Total);
   8067   }
   8068 
   8069   /// Sets the location of '('.
   8070   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   8071 
   8072   /// Sets the allocators data for the clause.
   8073   void setAllocatorsData(ArrayRef<OMPUsesAllocatorsClause::Data> Data);
   8074 
   8075 public:
   8076   /// Creates clause with a list of allocators \p Data.
   8077   ///
   8078   /// \param C AST context.
   8079   /// \param StartLoc Starting location of the clause.
   8080   /// \param LParenLoc Location of '('.
   8081   /// \param EndLoc Ending location of the clause.
   8082   /// \param Data List of allocators.
   8083   static OMPUsesAllocatorsClause *
   8084   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   8085          SourceLocation EndLoc, ArrayRef<OMPUsesAllocatorsClause::Data> Data);
   8086 
   8087   /// Creates an empty clause with the place for \p N allocators.
   8088   ///
   8089   /// \param C AST context.
   8090   /// \param N The number of allocators.
   8091   static OMPUsesAllocatorsClause *CreateEmpty(const ASTContext &C, unsigned N);
   8092 
   8093   /// Returns the location of '('.
   8094   SourceLocation getLParenLoc() const { return LParenLoc; }
   8095 
   8096   /// Returns number of allocators associated with the clause.
   8097   unsigned getNumberOfAllocators() const { return NumOfAllocators; }
   8098 
   8099   /// Returns data for the specified allocator.
   8100   OMPUsesAllocatorsClause::Data getAllocatorData(unsigned I) const;
   8101 
   8102   // Iterators
   8103   child_range children() {
   8104     Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
   8105     return child_range(Begin, Begin + NumOfAllocators *
   8106                                           static_cast<int>(ExprOffsets::Total));
   8107   }
   8108   const_child_range children() const {
   8109     Stmt *const *Begin =
   8110         reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
   8111     return const_child_range(
   8112         Begin, Begin + NumOfAllocators * static_cast<int>(ExprOffsets::Total));
   8113   }
   8114 
   8115   child_range used_children() {
   8116     return child_range(child_iterator(), child_iterator());
   8117   }
   8118   const_child_range used_children() const {
   8119     return const_child_range(const_child_iterator(), const_child_iterator());
   8120   }
   8121 
   8122   static bool classof(const OMPClause *T) {
   8123     return T->getClauseKind() == llvm::omp::OMPC_uses_allocators;
   8124   }
   8125 };
   8126 
   8127 /// This represents clause 'affinity' in the '#pragma omp task'-based
   8128 /// directives.
   8129 ///
   8130 /// \code
   8131 /// #pragma omp task affinity(iterator(i = 0:n) : ([3][n])a, b[:n], c[i])
   8132 /// \endcode
   8133 /// In this example directive '#pragma omp task' has clause 'affinity' with the
   8134 /// affinity modifer 'iterator(i = 0:n)' and locator items '([3][n])a', 'b[:n]'
   8135 /// and 'c[i]'.
   8136 class OMPAffinityClause final
   8137     : public OMPVarListClause<OMPAffinityClause>,
   8138       private llvm::TrailingObjects<OMPAffinityClause, Expr *> {
   8139   friend class OMPClauseReader;
   8140   friend OMPVarListClause;
   8141   friend TrailingObjects;
   8142 
   8143   /// Location of ':' symbol.
   8144   SourceLocation ColonLoc;
   8145 
   8146   /// Build clause.
   8147   ///
   8148   /// \param StartLoc Starting location of the clause.
   8149   /// \param LParenLoc Location of '('.
   8150   /// \param ColonLoc Location of ':'.
   8151   /// \param EndLoc Ending location of the clause.
   8152   /// \param N Number of locators asssociated with the clause.
   8153   OMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   8154                     SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N)
   8155       : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity, StartLoc,
   8156                                             LParenLoc, EndLoc, N) {}
   8157 
   8158   /// Build an empty clause.
   8159   /// \param N Number of locators asssociated with the clause.
   8160   ///
   8161   explicit OMPAffinityClause(unsigned N)
   8162       : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity,
   8163                                             SourceLocation(), SourceLocation(),
   8164                                             SourceLocation(), N) {}
   8165 
   8166   /// Sets the affinity modifier for the clause, if any.
   8167   void setModifier(Expr *E) {
   8168     getTrailingObjects<Expr *>()[varlist_size()] = E;
   8169   }
   8170 
   8171   /// Sets the location of ':' symbol.
   8172   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   8173 
   8174 public:
   8175   /// Creates clause with a modifier a list of locator items.
   8176   ///
   8177   /// \param C AST context.
   8178   /// \param StartLoc Starting location of the clause.
   8179   /// \param LParenLoc Location of '('.
   8180   /// \param ColonLoc Location of ':'.
   8181   /// \param EndLoc Ending location of the clause.
   8182   /// \param Locators List of locator items.
   8183   static OMPAffinityClause *Create(const ASTContext &C, SourceLocation StartLoc,
   8184                                    SourceLocation LParenLoc,
   8185                                    SourceLocation ColonLoc,
   8186                                    SourceLocation EndLoc, Expr *Modifier,
   8187                                    ArrayRef<Expr *> Locators);
   8188 
   8189   /// Creates an empty clause with the place for \p N locator items.
   8190   ///
   8191   /// \param C AST context.
   8192   /// \param N The number of locator items.
   8193   static OMPAffinityClause *CreateEmpty(const ASTContext &C, unsigned N);
   8194 
   8195   /// Gets affinity modifier.
   8196   Expr *getModifier() { return getTrailingObjects<Expr *>()[varlist_size()]; }
   8197   Expr *getModifier() const {
   8198     return getTrailingObjects<Expr *>()[varlist_size()];
   8199   }
   8200 
   8201   /// Gets the location of ':' symbol.
   8202   SourceLocation getColonLoc() const { return ColonLoc; }
   8203 
   8204   // Iterators
   8205   child_range children() {
   8206     int Offset = getModifier() ? 1 : 0;
   8207     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   8208                        reinterpret_cast<Stmt **>(varlist_end() + Offset));
   8209   }
   8210 
   8211   const_child_range children() const {
   8212     auto Children = const_cast<OMPAffinityClause *>(this)->children();
   8213     return const_child_range(Children.begin(), Children.end());
   8214   }
   8215 
   8216   child_range used_children() {
   8217     return child_range(child_iterator(), child_iterator());
   8218   }
   8219   const_child_range used_children() const {
   8220     return const_child_range(const_child_iterator(), const_child_iterator());
   8221   }
   8222 
   8223   static bool classof(const OMPClause *T) {
   8224     return T->getClauseKind() == llvm::omp::OMPC_affinity;
   8225   }
   8226 };
   8227 
   8228 /// This represents 'filter' clause in the '#pragma omp ...' directive.
   8229 ///
   8230 /// \code
   8231 /// #pragma omp masked filter(tid)
   8232 /// \endcode
   8233 /// In this example directive '#pragma omp masked' has 'filter' clause with
   8234 /// thread id.
   8235 class OMPFilterClause final : public OMPClause, public OMPClauseWithPreInit {
   8236   friend class OMPClauseReader;
   8237 
   8238   /// Location of '('.
   8239   SourceLocation LParenLoc;
   8240 
   8241   /// Express of the 'filter' clause.
   8242   Stmt *ThreadID = nullptr;
   8243 
   8244   /// Sets the thread identifier.
   8245   void setThreadID(Expr *TID) { ThreadID = TID; }
   8246 
   8247   /// Sets the location of '('.
   8248   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   8249 
   8250 public:
   8251   /// Build 'filter' clause with thread-id \a ThreadID.
   8252   ///
   8253   /// \param ThreadID Thread identifier.
   8254   /// \param HelperE Helper expression associated with this clause.
   8255   /// \param CaptureRegion Innermost OpenMP region where expressions in this
   8256   /// clause must be captured.
   8257   /// \param StartLoc Starting location of the clause.
   8258   /// \param LParenLoc Location of '('.
   8259   /// \param EndLoc Ending location of the clause.
   8260   OMPFilterClause(Expr *ThreadID, Stmt *HelperE,
   8261                   OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
   8262                   SourceLocation LParenLoc, SourceLocation EndLoc)
   8263       : OMPClause(llvm::omp::OMPC_filter, StartLoc, EndLoc),
   8264         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadID(ThreadID) {
   8265     setPreInitStmt(HelperE, CaptureRegion);
   8266   }
   8267 
   8268   /// Build an empty clause.
   8269   OMPFilterClause()
   8270       : OMPClause(llvm::omp::OMPC_filter, SourceLocation(), SourceLocation()),
   8271         OMPClauseWithPreInit(this) {}
   8272   /// Returns the location of '('.
   8273   SourceLocation getLParenLoc() const { return LParenLoc; }
   8274 
   8275   /// Return thread identifier.
   8276   Expr *getThreadID() { return cast<Expr>(ThreadID); }
   8277 
   8278   /// Return thread identifier.
   8279   Expr *getThreadID() const { return cast<Expr>(ThreadID); }
   8280 
   8281   child_range children() { return child_range(&ThreadID, &ThreadID + 1); }
   8282 
   8283   const_child_range children() const {
   8284     return const_child_range(&ThreadID, &ThreadID + 1);
   8285   }
   8286 
   8287   child_range used_children() {
   8288     return child_range(child_iterator(), child_iterator());
   8289   }
   8290   const_child_range used_children() const {
   8291     return const_child_range(const_child_iterator(), const_child_iterator());
   8292   }
   8293 
   8294   static bool classof(const OMPClause *T) {
   8295     return T->getClauseKind() == llvm::omp::OMPC_filter;
   8296   }
   8297 };
   8298 
   8299 /// This class implements a simple visitor for OMPClause
   8300 /// subclasses.
   8301 template<class ImplClass, template <typename> class Ptr, typename RetTy>
   8302 class OMPClauseVisitorBase {
   8303 public:
   8304 #define PTR(CLASS) Ptr<CLASS>
   8305 #define DISPATCH(CLASS) \
   8306   return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
   8307 
   8308 #define GEN_CLANG_CLAUSE_CLASS
   8309 #define CLAUSE_CLASS(Enum, Str, Class)                                         \
   8310   RetTy Visit##Class(PTR(Class) S) { DISPATCH(Class); }
   8311 #include "llvm/Frontend/OpenMP/OMP.inc"
   8312 
   8313   RetTy Visit(PTR(OMPClause) S) {
   8314     // Top switch clause: visit each OMPClause.
   8315     switch (S->getClauseKind()) {
   8316 #define GEN_CLANG_CLAUSE_CLASS
   8317 #define CLAUSE_CLASS(Enum, Str, Class)                                         \
   8318   case llvm::omp::Clause::Enum:                                                \
   8319     return Visit##Class(static_cast<PTR(Class)>(S));
   8320 #define CLAUSE_NO_CLASS(Enum, Str)                                             \
   8321   case llvm::omp::Clause::Enum:                                                \
   8322     break;
   8323 #include "llvm/Frontend/OpenMP/OMP.inc"
   8324     }
   8325   }
   8326   // Base case, ignore it. :)
   8327   RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); }
   8328 #undef PTR
   8329 #undef DISPATCH
   8330 };
   8331 
   8332 template <typename T> using const_ptr = std::add_pointer_t<std::add_const_t<T>>;
   8333 
   8334 template <class ImplClass, typename RetTy = void>
   8335 class OMPClauseVisitor
   8336     : public OMPClauseVisitorBase<ImplClass, std::add_pointer_t, RetTy> {};
   8337 template<class ImplClass, typename RetTy = void>
   8338 class ConstOMPClauseVisitor :
   8339       public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {};
   8340 
   8341 class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
   8342   raw_ostream &OS;
   8343   const PrintingPolicy &Policy;
   8344 
   8345   /// Process clauses with list of variables.
   8346   template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
   8347   /// Process motion clauses.
   8348   template <typename T> void VisitOMPMotionClause(T *Node);
   8349 
   8350 public:
   8351   OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
   8352       : OS(OS), Policy(Policy) {}
   8353 
   8354 #define GEN_CLANG_CLAUSE_CLASS
   8355 #define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S);
   8356 #include "llvm/Frontend/OpenMP/OMP.inc"
   8357 };
   8358 
   8359 struct OMPTraitProperty {
   8360   llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
   8361 
   8362   /// The raw string as we parsed it. This is needed for the `isa` trait set
   8363   /// (which accepts anything) and (later) extensions.
   8364   StringRef RawString;
   8365 };
   8366 struct OMPTraitSelector {
   8367   Expr *ScoreOrCondition = nullptr;
   8368   llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
   8369   llvm::SmallVector<OMPTraitProperty, 1> Properties;
   8370 };
   8371 struct OMPTraitSet {
   8372   llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
   8373   llvm::SmallVector<OMPTraitSelector, 2> Selectors;
   8374 };
   8375 
   8376 /// Helper data structure representing the traits in a match clause of an
   8377 /// `declare variant` or `metadirective`. The outer level is an ordered
   8378 /// collection of selector sets, each with an associated kind and an ordered
   8379 /// collection of selectors. A selector has a kind, an optional score/condition,
   8380 /// and an ordered collection of properties.
   8381 class OMPTraitInfo {
   8382   /// Private constructor accesible only by ASTContext.
   8383   OMPTraitInfo() {}
   8384   friend class ASTContext;
   8385 
   8386 public:
   8387   /// Reconstruct a (partial) OMPTraitInfo object from a mangled name.
   8388   OMPTraitInfo(StringRef MangledName);
   8389 
   8390   /// The outermost level of selector sets.
   8391   llvm::SmallVector<OMPTraitSet, 2> Sets;
   8392 
   8393   bool anyScoreOrCondition(
   8394       llvm::function_ref<bool(Expr *&, bool /* IsScore */)> Cond) {
   8395     return llvm::any_of(Sets, [&](OMPTraitSet &Set) {
   8396       return llvm::any_of(
   8397           Set.Selectors, [&](OMPTraitSelector &Selector) {
   8398             return Cond(Selector.ScoreOrCondition,
   8399                         /* IsScore */ Selector.Kind !=
   8400                             llvm::omp::TraitSelector::user_condition);
   8401           });
   8402     });
   8403   }
   8404 
   8405   /// Create a variant match info object from this trait info object. While the
   8406   /// former is a flat representation the actual main difference is that the
   8407   /// latter uses clang::Expr to store the score/condition while the former is
   8408   /// independent of clang. Thus, expressions and conditions are evaluated in
   8409   /// this method.
   8410   void getAsVariantMatchInfo(ASTContext &ASTCtx,
   8411                              llvm::omp::VariantMatchInfo &VMI) const;
   8412 
   8413   /// Return a string representation identifying this context selector.
   8414   std::string getMangledName() const;
   8415 
   8416   /// Check the extension trait \p TP is active.
   8417   bool isExtensionActive(llvm::omp::TraitProperty TP) {
   8418     for (const OMPTraitSet &Set : Sets) {
   8419       if (Set.Kind != llvm::omp::TraitSet::implementation)
   8420         continue;
   8421       for (const OMPTraitSelector &Selector : Set.Selectors) {
   8422         if (Selector.Kind != llvm::omp::TraitSelector::implementation_extension)
   8423           continue;
   8424         for (const OMPTraitProperty &Property : Selector.Properties) {
   8425           if (Property.Kind == TP)
   8426             return true;
   8427         }
   8428       }
   8429     }
   8430     return false;
   8431   }
   8432 
   8433   /// Print a human readable representation into \p OS.
   8434   void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
   8435 };
   8436 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
   8437 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
   8438 
   8439 /// Clang specific specialization of the OMPContext to lookup target features.
   8440 struct TargetOMPContext final : public llvm::omp::OMPContext {
   8441 
   8442   TargetOMPContext(ASTContext &ASTCtx,
   8443                    std::function<void(StringRef)> &&DiagUnknownTrait,
   8444                    const FunctionDecl *CurrentFunctionDecl);
   8445   virtual ~TargetOMPContext() = default;
   8446 
   8447   /// See llvm::omp::OMPContext::matchesISATrait
   8448   bool matchesISATrait(StringRef RawString) const override;
   8449 
   8450 private:
   8451   std::function<bool(StringRef)> FeatureValidityCheck;
   8452   std::function<void(StringRef)> DiagUnknownTrait;
   8453   llvm::StringMap<bool> FeatureMap;
   8454 };
   8455 
   8456 /// Contains data for OpenMP directives: clauses, children
   8457 /// expressions/statements (helpers for codegen) and associated statement, if
   8458 /// any.
   8459 class OMPChildren final
   8460     : private llvm::TrailingObjects<OMPChildren, OMPClause *, Stmt *> {
   8461   friend TrailingObjects;
   8462   friend class OMPClauseReader;
   8463   friend class OMPExecutableDirective;
   8464   template <typename T> friend class OMPDeclarativeDirective;
   8465 
   8466   /// Numbers of clauses.
   8467   unsigned NumClauses = 0;
   8468   /// Number of child expressions/stmts.
   8469   unsigned NumChildren = 0;
   8470   /// true if the directive has associated statement.
   8471   bool HasAssociatedStmt = false;
   8472 
   8473   /// Define the sizes of each trailing object array except the last one. This
   8474   /// is required for TrailingObjects to work properly.
   8475   size_t numTrailingObjects(OverloadToken<OMPClause *>) const {
   8476     return NumClauses;
   8477   }
   8478 
   8479   OMPChildren() = delete;
   8480 
   8481   OMPChildren(unsigned NumClauses, unsigned NumChildren, bool HasAssociatedStmt)
   8482       : NumClauses(NumClauses), NumChildren(NumChildren),
   8483         HasAssociatedStmt(HasAssociatedStmt) {}
   8484 
   8485   static size_t size(unsigned NumClauses, bool HasAssociatedStmt,
   8486                      unsigned NumChildren);
   8487 
   8488   static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses);
   8489   static OMPChildren *Create(void *Mem, ArrayRef<OMPClause *> Clauses, Stmt *S,
   8490                              unsigned NumChildren = 0);
   8491   static OMPChildren *CreateEmpty(void *Mem, unsigned NumClauses,
   8492                                   bool HasAssociatedStmt = false,
   8493                                   unsigned NumChildren = 0);
   8494 
   8495 public:
   8496   unsigned getNumClauses() const { return NumClauses; }
   8497   unsigned getNumChildren() const { return NumChildren; }
   8498   bool hasAssociatedStmt() const { return HasAssociatedStmt; }
   8499 
   8500   /// Set associated statement.
   8501   void setAssociatedStmt(Stmt *S) {
   8502     getTrailingObjects<Stmt *>()[NumChildren] = S;
   8503   }
   8504 
   8505   void setChildren(ArrayRef<Stmt *> Children);
   8506 
   8507   /// Sets the list of variables for this clause.
   8508   ///
   8509   /// \param Clauses The list of clauses for the directive.
   8510   ///
   8511   void setClauses(ArrayRef<OMPClause *> Clauses);
   8512 
   8513   /// Returns statement associated with the directive.
   8514   const Stmt *getAssociatedStmt() const {
   8515     return const_cast<OMPChildren *>(this)->getAssociatedStmt();
   8516   }
   8517   Stmt *getAssociatedStmt() {
   8518     assert(HasAssociatedStmt &&
   8519            "Expected directive with the associated statement.");
   8520     return getTrailingObjects<Stmt *>()[NumChildren];
   8521   }
   8522 
   8523   /// Get the clauses storage.
   8524   MutableArrayRef<OMPClause *> getClauses() {
   8525     return llvm::makeMutableArrayRef(getTrailingObjects<OMPClause *>(),
   8526                                      NumClauses);
   8527   }
   8528   ArrayRef<OMPClause *> getClauses() const {
   8529     return const_cast<OMPChildren *>(this)->getClauses();
   8530   }
   8531 
   8532   /// Returns the captured statement associated with the
   8533   /// component region within the (combined) directive.
   8534   ///
   8535   /// \param RegionKind Component region kind.
   8536   const CapturedStmt *
   8537   getCapturedStmt(OpenMPDirectiveKind RegionKind,
   8538                   ArrayRef<OpenMPDirectiveKind> CaptureRegions) const {
   8539     assert(llvm::any_of(
   8540                CaptureRegions,
   8541                [=](const OpenMPDirectiveKind K) { return K == RegionKind; }) &&
   8542            "RegionKind not found in OpenMP CaptureRegions.");
   8543     auto *CS = cast<CapturedStmt>(getAssociatedStmt());
   8544     for (auto ThisCaptureRegion : CaptureRegions) {
   8545       if (ThisCaptureRegion == RegionKind)
   8546         return CS;
   8547       CS = cast<CapturedStmt>(CS->getCapturedStmt());
   8548     }
   8549     llvm_unreachable("Incorrect RegionKind specified for directive.");
   8550   }
   8551 
   8552   /// Get innermost captured statement for the construct.
   8553   CapturedStmt *
   8554   getInnermostCapturedStmt(ArrayRef<OpenMPDirectiveKind> CaptureRegions) {
   8555     assert(hasAssociatedStmt() && "Must have associated captured statement.");
   8556     assert(!CaptureRegions.empty() &&
   8557            "At least one captured statement must be provided.");
   8558     auto *CS = cast<CapturedStmt>(getAssociatedStmt());
   8559     for (unsigned Level = CaptureRegions.size(); Level > 1; --Level)
   8560       CS = cast<CapturedStmt>(CS->getCapturedStmt());
   8561     return CS;
   8562   }
   8563 
   8564   const CapturedStmt *
   8565   getInnermostCapturedStmt(ArrayRef<OpenMPDirectiveKind> CaptureRegions) const {
   8566     return const_cast<OMPChildren *>(this)->getInnermostCapturedStmt(
   8567         CaptureRegions);
   8568   }
   8569 
   8570   MutableArrayRef<Stmt *> getChildren();
   8571   ArrayRef<Stmt *> getChildren() const {
   8572     return const_cast<OMPChildren *>(this)->getChildren();
   8573   }
   8574 
   8575   Stmt *getRawStmt() {
   8576     assert(HasAssociatedStmt &&
   8577            "Expected directive with the associated statement.");
   8578     if (auto *CS = dyn_cast<CapturedStmt>(getAssociatedStmt())) {
   8579       Stmt *S = nullptr;
   8580       do {
   8581         S = CS->getCapturedStmt();
   8582         CS = dyn_cast<CapturedStmt>(S);
   8583       } while (CS);
   8584       return S;
   8585     }
   8586     return getAssociatedStmt();
   8587   }
   8588   const Stmt *getRawStmt() const {
   8589     return const_cast<OMPChildren *>(this)->getRawStmt();
   8590   }
   8591 
   8592   Stmt::child_range getAssociatedStmtAsRange() {
   8593     if (!HasAssociatedStmt)
   8594       return Stmt::child_range(Stmt::child_iterator(), Stmt::child_iterator());
   8595     return Stmt::child_range(&getTrailingObjects<Stmt *>()[NumChildren],
   8596                              &getTrailingObjects<Stmt *>()[NumChildren + 1]);
   8597   }
   8598 };
   8599 
   8600 } // namespace clang
   8601 
   8602 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H
   8603