Home | History | Annotate | Download | only in AST
      1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 /// \file
     10 /// \brief 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/Expr.h"
     20 #include "clang/AST/Stmt.h"
     21 #include "clang/Basic/OpenMPKinds.h"
     22 #include "clang/Basic/SourceLocation.h"
     23 
     24 namespace clang {
     25 
     26 //===----------------------------------------------------------------------===//
     27 // AST classes for clauses.
     28 //===----------------------------------------------------------------------===//
     29 
     30 /// \brief This is a basic class for representing single OpenMP clause.
     31 ///
     32 class OMPClause {
     33   /// \brief Starting location of the clause (the clause keyword).
     34   SourceLocation StartLoc;
     35   /// \brief Ending location of the clause.
     36   SourceLocation EndLoc;
     37   /// \brief Kind of the clause.
     38   OpenMPClauseKind Kind;
     39 
     40 protected:
     41   OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
     42       : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
     43 
     44 public:
     45   /// \brief Returns the starting location of the clause.
     46   SourceLocation getLocStart() const { return StartLoc; }
     47   /// \brief Returns the ending location of the clause.
     48   SourceLocation getLocEnd() const { return EndLoc; }
     49 
     50   /// \brief Sets the starting location of the clause.
     51   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
     52   /// \brief Sets the ending location of the clause.
     53   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
     54 
     55   /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
     56   OpenMPClauseKind getClauseKind() const { return Kind; }
     57 
     58   bool isImplicit() const { return StartLoc.isInvalid(); }
     59 
     60   typedef StmtIterator child_iterator;
     61   typedef ConstStmtIterator const_child_iterator;
     62   typedef llvm::iterator_range<child_iterator> child_range;
     63   typedef llvm::iterator_range<const_child_iterator> const_child_range;
     64 
     65   child_range children();
     66   const_child_range children() const {
     67     auto Children = const_cast<OMPClause *>(this)->children();
     68     return const_child_range(Children.begin(), Children.end());
     69   }
     70   static bool classof(const OMPClause *) { return true; }
     71 };
     72 
     73 /// \brief This represents clauses with the list of variables like 'private',
     74 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
     75 /// '#pragma omp ...' directives.
     76 template <class T> class OMPVarListClause : public OMPClause {
     77   friend class OMPClauseReader;
     78   /// \brief Location of '('.
     79   SourceLocation LParenLoc;
     80   /// \brief Number of variables in the list.
     81   unsigned NumVars;
     82 
     83 protected:
     84   /// \brief Fetches list of variables associated with this clause.
     85   MutableArrayRef<Expr *> getVarRefs() {
     86     return MutableArrayRef<Expr *>(
     87         reinterpret_cast<Expr **>(
     88             reinterpret_cast<char *>(this) +
     89             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
     90         NumVars);
     91   }
     92 
     93   /// \brief Sets the list of variables for this clause.
     94   void setVarRefs(ArrayRef<Expr *> VL) {
     95     assert(VL.size() == NumVars &&
     96            "Number of variables is not the same as the preallocated buffer");
     97     std::copy(
     98         VL.begin(), VL.end(),
     99         reinterpret_cast<Expr **>(
    100             reinterpret_cast<char *>(this) +
    101             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())));
    102   }
    103 
    104   /// \brief Build a clause with \a N variables
    105   ///
    106   /// \param K Kind of the clause.
    107   /// \param StartLoc Starting location of the clause (the clause keyword).
    108   /// \param LParenLoc Location of '('.
    109   /// \param EndLoc Ending location of the clause.
    110   /// \param N Number of the variables in the clause.
    111   ///
    112   OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
    113                    SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
    114       : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
    115 
    116 public:
    117   typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
    118   typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
    119   typedef llvm::iterator_range<varlist_iterator> varlist_range;
    120   typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
    121 
    122   unsigned varlist_size() const { return NumVars; }
    123   bool varlist_empty() const { return NumVars == 0; }
    124 
    125   varlist_range varlists() {
    126     return varlist_range(varlist_begin(), varlist_end());
    127   }
    128   varlist_const_range varlists() const {
    129     return varlist_const_range(varlist_begin(), varlist_end());
    130   }
    131 
    132   varlist_iterator varlist_begin() { return getVarRefs().begin(); }
    133   varlist_iterator varlist_end() { return getVarRefs().end(); }
    134   varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
    135   varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
    136 
    137   /// \brief Sets the location of '('.
    138   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    139   /// \brief Returns the location of '('.
    140   SourceLocation getLParenLoc() const { return LParenLoc; }
    141 
    142   /// \brief Fetches list of all variables in the clause.
    143   ArrayRef<const Expr *> getVarRefs() const {
    144     return llvm::makeArrayRef(
    145         reinterpret_cast<const Expr *const *>(
    146             reinterpret_cast<const char *>(this) +
    147             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<const Expr *>())),
    148         NumVars);
    149   }
    150 };
    151 
    152 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
    153 ///
    154 /// \code
    155 /// #pragma omp parallel if(parallel:a > 5)
    156 /// \endcode
    157 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
    158 /// condition 'a > 5' and directive name modifier 'parallel'.
    159 ///
    160 class OMPIfClause : public OMPClause {
    161   friend class OMPClauseReader;
    162   /// \brief Location of '('.
    163   SourceLocation LParenLoc;
    164   /// \brief Condition of the 'if' clause.
    165   Stmt *Condition;
    166   /// \brief Location of ':' (if any).
    167   SourceLocation ColonLoc;
    168   /// \brief Directive name modifier for the clause.
    169   OpenMPDirectiveKind NameModifier;
    170   /// \brief Name modifier location.
    171   SourceLocation NameModifierLoc;
    172 
    173   /// \brief Set condition.
    174   ///
    175   void setCondition(Expr *Cond) { Condition = Cond; }
    176   /// \brief Set directive name modifier for the clause.
    177   ///
    178   void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
    179   /// \brief Set location of directive name modifier for the clause.
    180   ///
    181   void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
    182   /// \brief Set location of ':'.
    183   ///
    184   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
    185 
    186 public:
    187   /// \brief Build 'if' clause with condition \a Cond.
    188   ///
    189   /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
    190   /// \param Cond Condition of the clause.
    191   /// \param StartLoc Starting location of the clause.
    192   /// \param LParenLoc Location of '('.
    193   /// \param NameModifierLoc Location of directive name modifier.
    194   /// \param ColonLoc [OpenMP 4.1] Location of ':'.
    195   /// \param EndLoc Ending location of the clause.
    196   ///
    197   OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond,
    198               SourceLocation StartLoc, SourceLocation LParenLoc,
    199               SourceLocation NameModifierLoc, SourceLocation ColonLoc,
    200               SourceLocation EndLoc)
    201       : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
    202         Condition(Cond), ColonLoc(ColonLoc), NameModifier(NameModifier),
    203         NameModifierLoc(NameModifierLoc) {}
    204 
    205   /// \brief Build an empty clause.
    206   ///
    207   OMPIfClause()
    208       : OMPClause(OMPC_if, SourceLocation(), SourceLocation()), LParenLoc(),
    209         Condition(nullptr), ColonLoc(), NameModifier(OMPD_unknown),
    210         NameModifierLoc() {}
    211 
    212   /// \brief Sets the location of '('.
    213   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    214   /// \brief Returns the location of '('.
    215   SourceLocation getLParenLoc() const { return LParenLoc; }
    216 
    217   /// \brief Return the location of ':'.
    218   SourceLocation getColonLoc() const { return ColonLoc; }
    219 
    220   /// \brief Returns condition.
    221   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
    222   /// \brief Return directive name modifier associated with the clause.
    223   OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
    224 
    225   /// \brief Return the location of directive name modifier.
    226   SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
    227 
    228   static bool classof(const OMPClause *T) {
    229     return T->getClauseKind() == OMPC_if;
    230   }
    231 
    232   child_range children() { return child_range(&Condition, &Condition + 1); }
    233 };
    234 
    235 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
    236 ///
    237 /// \code
    238 /// #pragma omp task final(a > 5)
    239 /// \endcode
    240 /// In this example directive '#pragma omp task' has simple 'final'
    241 /// clause with condition 'a > 5'.
    242 ///
    243 class OMPFinalClause : public OMPClause {
    244   friend class OMPClauseReader;
    245   /// \brief Location of '('.
    246   SourceLocation LParenLoc;
    247   /// \brief Condition of the 'if' clause.
    248   Stmt *Condition;
    249 
    250   /// \brief Set condition.
    251   ///
    252   void setCondition(Expr *Cond) { Condition = Cond; }
    253 
    254 public:
    255   /// \brief Build 'final' clause with condition \a Cond.
    256   ///
    257   /// \param StartLoc Starting location of the clause.
    258   /// \param LParenLoc Location of '('.
    259   /// \param Cond Condition of the clause.
    260   /// \param EndLoc Ending location of the clause.
    261   ///
    262   OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
    263                  SourceLocation EndLoc)
    264       : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
    265         Condition(Cond) {}
    266 
    267   /// \brief Build an empty clause.
    268   ///
    269   OMPFinalClause()
    270       : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
    271         LParenLoc(SourceLocation()), Condition(nullptr) {}
    272 
    273   /// \brief Sets the location of '('.
    274   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    275   /// \brief Returns the location of '('.
    276   SourceLocation getLParenLoc() const { return LParenLoc; }
    277 
    278   /// \brief Returns condition.
    279   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
    280 
    281   static bool classof(const OMPClause *T) {
    282     return T->getClauseKind() == OMPC_final;
    283   }
    284 
    285   child_range children() { return child_range(&Condition, &Condition + 1); }
    286 };
    287 
    288 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
    289 /// directive.
    290 ///
    291 /// \code
    292 /// #pragma omp parallel num_threads(6)
    293 /// \endcode
    294 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
    295 /// clause with number of threads '6'.
    296 ///
    297 class OMPNumThreadsClause : public OMPClause {
    298   friend class OMPClauseReader;
    299   /// \brief Location of '('.
    300   SourceLocation LParenLoc;
    301   /// \brief Condition of the 'num_threads' clause.
    302   Stmt *NumThreads;
    303 
    304   /// \brief Set condition.
    305   ///
    306   void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
    307 
    308 public:
    309   /// \brief Build 'num_threads' clause with condition \a NumThreads.
    310   ///
    311   /// \param NumThreads Number of threads for the construct.
    312   /// \param StartLoc Starting location of the clause.
    313   /// \param LParenLoc Location of '('.
    314   /// \param EndLoc Ending location of the clause.
    315   ///
    316   OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
    317                       SourceLocation LParenLoc, SourceLocation EndLoc)
    318       : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
    319         NumThreads(NumThreads) {}
    320 
    321   /// \brief Build an empty clause.
    322   ///
    323   OMPNumThreadsClause()
    324       : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
    325         LParenLoc(SourceLocation()), NumThreads(nullptr) {}
    326 
    327   /// \brief Sets the location of '('.
    328   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    329   /// \brief Returns the location of '('.
    330   SourceLocation getLParenLoc() const { return LParenLoc; }
    331 
    332   /// \brief Returns number of threads.
    333   Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
    334 
    335   static bool classof(const OMPClause *T) {
    336     return T->getClauseKind() == OMPC_num_threads;
    337   }
    338 
    339   child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
    340 };
    341 
    342 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
    343 /// directive.
    344 ///
    345 /// \code
    346 /// #pragma omp simd safelen(4)
    347 /// \endcode
    348 /// In this example directive '#pragma omp simd' has clause 'safelen'
    349 /// with single expression '4'.
    350 /// If the safelen clause is used then no two iterations executed
    351 /// concurrently with SIMD instructions can have a greater distance
    352 /// in the logical iteration space than its value. The parameter of
    353 /// the safelen clause must be a constant positive integer expression.
    354 ///
    355 class OMPSafelenClause : public OMPClause {
    356   friend class OMPClauseReader;
    357   /// \brief Location of '('.
    358   SourceLocation LParenLoc;
    359   /// \brief Safe iteration space distance.
    360   Stmt *Safelen;
    361 
    362   /// \brief Set safelen.
    363   void setSafelen(Expr *Len) { Safelen = Len; }
    364 
    365 public:
    366   /// \brief Build 'safelen' clause.
    367   ///
    368   /// \param Len Expression associated with this clause.
    369   /// \param StartLoc Starting location of the clause.
    370   /// \param EndLoc Ending location of the clause.
    371   ///
    372   OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
    373                    SourceLocation EndLoc)
    374       : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
    375         Safelen(Len) {}
    376 
    377   /// \brief Build an empty clause.
    378   ///
    379   explicit OMPSafelenClause()
    380       : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
    381         LParenLoc(SourceLocation()), Safelen(nullptr) {}
    382 
    383   /// \brief Sets the location of '('.
    384   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    385   /// \brief Returns the location of '('.
    386   SourceLocation getLParenLoc() const { return LParenLoc; }
    387 
    388   /// \brief Return safe iteration space distance.
    389   Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
    390 
    391   static bool classof(const OMPClause *T) {
    392     return T->getClauseKind() == OMPC_safelen;
    393   }
    394 
    395   child_range children() { return child_range(&Safelen, &Safelen + 1); }
    396 };
    397 
    398 /// \brief This represents 'simdlen' clause in the '#pragma omp ...'
    399 /// directive.
    400 ///
    401 /// \code
    402 /// #pragma omp simd simdlen(4)
    403 /// \endcode
    404 /// In this example directive '#pragma omp simd' has clause 'simdlen'
    405 /// with single expression '4'.
    406 /// If the 'simdlen' clause is used then it specifies the preferred number of
    407 /// iterations to be executed concurrently. The parameter of the 'simdlen'
    408 /// clause must be a constant positive integer expression.
    409 ///
    410 class OMPSimdlenClause : public OMPClause {
    411   friend class OMPClauseReader;
    412   /// \brief Location of '('.
    413   SourceLocation LParenLoc;
    414   /// \brief Safe iteration space distance.
    415   Stmt *Simdlen;
    416 
    417   /// \brief Set simdlen.
    418   void setSimdlen(Expr *Len) { Simdlen = Len; }
    419 
    420 public:
    421   /// \brief Build 'simdlen' clause.
    422   ///
    423   /// \param Len Expression associated with this clause.
    424   /// \param StartLoc Starting location of the clause.
    425   /// \param EndLoc Ending location of the clause.
    426   ///
    427   OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
    428                    SourceLocation EndLoc)
    429       : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
    430         Simdlen(Len) {}
    431 
    432   /// \brief Build an empty clause.
    433   ///
    434   explicit OMPSimdlenClause()
    435       : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()),
    436         LParenLoc(SourceLocation()), Simdlen(nullptr) {}
    437 
    438   /// \brief Sets the location of '('.
    439   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    440   /// \brief Returns the location of '('.
    441   SourceLocation getLParenLoc() const { return LParenLoc; }
    442 
    443   /// \brief Return safe iteration space distance.
    444   Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
    445 
    446   static bool classof(const OMPClause *T) {
    447     return T->getClauseKind() == OMPC_simdlen;
    448   }
    449 
    450   child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
    451 };
    452 
    453 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
    454 /// directive.
    455 ///
    456 /// \code
    457 /// #pragma omp simd collapse(3)
    458 /// \endcode
    459 /// In this example directive '#pragma omp simd' has clause 'collapse'
    460 /// with single expression '3'.
    461 /// The parameter must be a constant positive integer expression, it specifies
    462 /// the number of nested loops that should be collapsed into a single iteration
    463 /// space.
    464 ///
    465 class OMPCollapseClause : public OMPClause {
    466   friend class OMPClauseReader;
    467   /// \brief Location of '('.
    468   SourceLocation LParenLoc;
    469   /// \brief Number of for-loops.
    470   Stmt *NumForLoops;
    471 
    472   /// \brief Set the number of associated for-loops.
    473   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
    474 
    475 public:
    476   /// \brief Build 'collapse' clause.
    477   ///
    478   /// \param Num Expression associated with this clause.
    479   /// \param StartLoc Starting location of the clause.
    480   /// \param LParenLoc Location of '('.
    481   /// \param EndLoc Ending location of the clause.
    482   ///
    483   OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
    484                     SourceLocation LParenLoc, SourceLocation EndLoc)
    485       : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
    486         NumForLoops(Num) {}
    487 
    488   /// \brief Build an empty clause.
    489   ///
    490   explicit OMPCollapseClause()
    491       : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
    492         LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
    493 
    494   /// \brief Sets the location of '('.
    495   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    496   /// \brief Returns the location of '('.
    497   SourceLocation getLParenLoc() const { return LParenLoc; }
    498 
    499   /// \brief Return the number of associated for-loops.
    500   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
    501 
    502   static bool classof(const OMPClause *T) {
    503     return T->getClauseKind() == OMPC_collapse;
    504   }
    505 
    506   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
    507 };
    508 
    509 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
    510 ///
    511 /// \code
    512 /// #pragma omp parallel default(shared)
    513 /// \endcode
    514 /// In this example directive '#pragma omp parallel' has simple 'default'
    515 /// clause with kind 'shared'.
    516 ///
    517 class OMPDefaultClause : public OMPClause {
    518   friend class OMPClauseReader;
    519   /// \brief Location of '('.
    520   SourceLocation LParenLoc;
    521   /// \brief A kind of the 'default' clause.
    522   OpenMPDefaultClauseKind Kind;
    523   /// \brief Start location of the kind in source code.
    524   SourceLocation KindKwLoc;
    525 
    526   /// \brief Set kind of the clauses.
    527   ///
    528   /// \param K Argument of clause.
    529   ///
    530   void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
    531 
    532   /// \brief Set argument location.
    533   ///
    534   /// \param KLoc Argument location.
    535   ///
    536   void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
    537 
    538 public:
    539   /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
    540   ///
    541   /// \param A Argument of the clause ('none' or 'shared').
    542   /// \param ALoc Starting location of the argument.
    543   /// \param StartLoc Starting location of the clause.
    544   /// \param LParenLoc Location of '('.
    545   /// \param EndLoc Ending location of the clause.
    546   ///
    547   OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
    548                    SourceLocation StartLoc, SourceLocation LParenLoc,
    549                    SourceLocation EndLoc)
    550       : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
    551         Kind(A), KindKwLoc(ALoc) {}
    552 
    553   /// \brief Build an empty clause.
    554   ///
    555   OMPDefaultClause()
    556       : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
    557         LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
    558         KindKwLoc(SourceLocation()) {}
    559 
    560   /// \brief Sets the location of '('.
    561   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    562   /// \brief Returns the location of '('.
    563   SourceLocation getLParenLoc() const { return LParenLoc; }
    564 
    565   /// \brief Returns kind of the clause.
    566   OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
    567 
    568   /// \brief Returns location of clause kind.
    569   SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
    570 
    571   static bool classof(const OMPClause *T) {
    572     return T->getClauseKind() == OMPC_default;
    573   }
    574 
    575   child_range children() {
    576     return child_range(child_iterator(), child_iterator());
    577   }
    578 };
    579 
    580 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
    581 /// directive.
    582 ///
    583 /// \code
    584 /// #pragma omp parallel proc_bind(master)
    585 /// \endcode
    586 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
    587 /// clause with kind 'master'.
    588 ///
    589 class OMPProcBindClause : public OMPClause {
    590   friend class OMPClauseReader;
    591   /// \brief Location of '('.
    592   SourceLocation LParenLoc;
    593   /// \brief A kind of the 'proc_bind' clause.
    594   OpenMPProcBindClauseKind Kind;
    595   /// \brief Start location of the kind in source code.
    596   SourceLocation KindKwLoc;
    597 
    598   /// \brief Set kind of the clause.
    599   ///
    600   /// \param K Kind of clause.
    601   ///
    602   void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
    603 
    604   /// \brief Set clause kind location.
    605   ///
    606   /// \param KLoc Kind location.
    607   ///
    608   void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
    609 
    610 public:
    611   /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
    612   ///        'spread').
    613   ///
    614   /// \param A Argument of the clause ('master', 'close' or 'spread').
    615   /// \param ALoc Starting location of the argument.
    616   /// \param StartLoc Starting location of the clause.
    617   /// \param LParenLoc Location of '('.
    618   /// \param EndLoc Ending location of the clause.
    619   ///
    620   OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
    621                     SourceLocation StartLoc, SourceLocation LParenLoc,
    622                     SourceLocation EndLoc)
    623       : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
    624         Kind(A), KindKwLoc(ALoc) {}
    625 
    626   /// \brief Build an empty clause.
    627   ///
    628   OMPProcBindClause()
    629       : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
    630         LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
    631         KindKwLoc(SourceLocation()) {}
    632 
    633   /// \brief Sets the location of '('.
    634   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    635   /// \brief Returns the location of '('.
    636   SourceLocation getLParenLoc() const { return LParenLoc; }
    637 
    638   /// \brief Returns kind of the clause.
    639   OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
    640 
    641   /// \brief Returns location of clause kind.
    642   SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
    643 
    644   static bool classof(const OMPClause *T) {
    645     return T->getClauseKind() == OMPC_proc_bind;
    646   }
    647 
    648   child_range children() {
    649     return child_range(child_iterator(), child_iterator());
    650   }
    651 };
    652 
    653 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
    654 ///
    655 /// \code
    656 /// #pragma omp for schedule(static, 3)
    657 /// \endcode
    658 /// In this example directive '#pragma omp for' has 'schedule' clause with
    659 /// arguments 'static' and '3'.
    660 ///
    661 class OMPScheduleClause : public OMPClause {
    662   friend class OMPClauseReader;
    663   /// \brief Location of '('.
    664   SourceLocation LParenLoc;
    665   /// \brief A kind of the 'schedule' clause.
    666   OpenMPScheduleClauseKind Kind;
    667   /// \brief Start location of the schedule ind in source code.
    668   SourceLocation KindLoc;
    669   /// \brief Location of ',' (if any).
    670   SourceLocation CommaLoc;
    671   /// \brief Chunk size and a reference to pseudo variable for combined
    672   /// directives.
    673   enum { CHUNK_SIZE, HELPER_CHUNK_SIZE, NUM_EXPRS };
    674   Stmt *ChunkSizes[NUM_EXPRS];
    675 
    676   /// \brief Set schedule kind.
    677   ///
    678   /// \param K Schedule kind.
    679   ///
    680   void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
    681   /// \brief Sets the location of '('.
    682   ///
    683   /// \param Loc Location of '('.
    684   ///
    685   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    686   /// \brief Set schedule kind start location.
    687   ///
    688   /// \param KLoc Schedule kind location.
    689   ///
    690   void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
    691   /// \brief Set location of ','.
    692   ///
    693   /// \param Loc Location of ','.
    694   ///
    695   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
    696   /// \brief Set chunk size.
    697   ///
    698   /// \param E Chunk size.
    699   ///
    700   void setChunkSize(Expr *E) { ChunkSizes[CHUNK_SIZE] = E; }
    701   /// \brief Set helper chunk size.
    702   ///
    703   /// \param E Helper chunk size.
    704   ///
    705   void setHelperChunkSize(Expr *E) { ChunkSizes[HELPER_CHUNK_SIZE] = E; }
    706 
    707 public:
    708   /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
    709   /// expression \a ChunkSize.
    710   ///
    711   /// \param StartLoc Starting location of the clause.
    712   /// \param LParenLoc Location of '('.
    713   /// \param KLoc Starting location of the argument.
    714   /// \param CommaLoc Location of ','.
    715   /// \param EndLoc Ending location of the clause.
    716   /// \param Kind Schedule kind.
    717   /// \param ChunkSize Chunk size.
    718   /// \param HelperChunkSize Helper chunk size for combined directives.
    719   ///
    720   OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
    721                     SourceLocation KLoc, SourceLocation CommaLoc,
    722                     SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
    723                     Expr *ChunkSize, Expr *HelperChunkSize)
    724       : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
    725         Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc) {
    726     ChunkSizes[CHUNK_SIZE] = ChunkSize;
    727     ChunkSizes[HELPER_CHUNK_SIZE] = HelperChunkSize;
    728   }
    729 
    730   /// \brief Build an empty clause.
    731   ///
    732   explicit OMPScheduleClause()
    733       : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
    734         Kind(OMPC_SCHEDULE_unknown) {
    735     ChunkSizes[CHUNK_SIZE] = nullptr;
    736     ChunkSizes[HELPER_CHUNK_SIZE] = nullptr;
    737   }
    738 
    739   /// \brief Get kind of the clause.
    740   ///
    741   OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
    742   /// \brief Get location of '('.
    743   ///
    744   SourceLocation getLParenLoc() { return LParenLoc; }
    745   /// \brief Get kind location.
    746   ///
    747   SourceLocation getScheduleKindLoc() { return KindLoc; }
    748   /// \brief Get location of ','.
    749   ///
    750   SourceLocation getCommaLoc() { return CommaLoc; }
    751   /// \brief Get chunk size.
    752   ///
    753   Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]); }
    754   /// \brief Get chunk size.
    755   ///
    756   Expr *getChunkSize() const {
    757     return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]);
    758   }
    759   /// \brief Get helper chunk size.
    760   ///
    761   Expr *getHelperChunkSize() {
    762     return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
    763   }
    764   /// \brief Get helper chunk size.
    765   ///
    766   Expr *getHelperChunkSize() const {
    767     return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
    768   }
    769 
    770   static bool classof(const OMPClause *T) {
    771     return T->getClauseKind() == OMPC_schedule;
    772   }
    773 
    774   child_range children() {
    775     return child_range(&ChunkSizes[CHUNK_SIZE], &ChunkSizes[CHUNK_SIZE] + 1);
    776   }
    777 };
    778 
    779 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
    780 ///
    781 /// \code
    782 /// #pragma omp for ordered (2)
    783 /// \endcode
    784 /// In this example directive '#pragma omp for' has 'ordered' clause with
    785 /// parameter 2.
    786 ///
    787 class OMPOrderedClause : public OMPClause {
    788   friend class OMPClauseReader;
    789   /// \brief Location of '('.
    790   SourceLocation LParenLoc;
    791   /// \brief Number of for-loops.
    792   Stmt *NumForLoops;
    793 
    794   /// \brief Set the number of associated for-loops.
    795   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
    796 
    797 public:
    798   /// \brief Build 'ordered' clause.
    799   ///
    800   /// \param Num Expression, possibly associated with this clause.
    801   /// \param StartLoc Starting location of the clause.
    802   /// \param LParenLoc Location of '('.
    803   /// \param EndLoc Ending location of the clause.
    804   ///
    805   OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
    806                     SourceLocation LParenLoc, SourceLocation EndLoc)
    807       : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
    808         NumForLoops(Num) {}
    809 
    810   /// \brief Build an empty clause.
    811   ///
    812   explicit OMPOrderedClause()
    813       : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
    814         LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
    815 
    816   /// \brief Sets the location of '('.
    817   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
    818   /// \brief Returns the location of '('.
    819   SourceLocation getLParenLoc() const { return LParenLoc; }
    820 
    821   /// \brief Return the number of associated for-loops.
    822   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
    823 
    824   static bool classof(const OMPClause *T) {
    825     return T->getClauseKind() == OMPC_ordered;
    826   }
    827 
    828   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
    829 };
    830 
    831 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
    832 ///
    833 /// \code
    834 /// #pragma omp for nowait
    835 /// \endcode
    836 /// In this example directive '#pragma omp for' has 'nowait' clause.
    837 ///
    838 class OMPNowaitClause : public OMPClause {
    839 public:
    840   /// \brief Build 'nowait' clause.
    841   ///
    842   /// \param StartLoc Starting location of the clause.
    843   /// \param EndLoc Ending location of the clause.
    844   ///
    845   OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
    846       : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
    847 
    848   /// \brief Build an empty clause.
    849   ///
    850   OMPNowaitClause()
    851       : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
    852 
    853   static bool classof(const OMPClause *T) {
    854     return T->getClauseKind() == OMPC_nowait;
    855   }
    856 
    857   child_range children() {
    858     return child_range(child_iterator(), child_iterator());
    859   }
    860 };
    861 
    862 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
    863 ///
    864 /// \code
    865 /// #pragma omp task untied
    866 /// \endcode
    867 /// In this example directive '#pragma omp task' has 'untied' clause.
    868 ///
    869 class OMPUntiedClause : public OMPClause {
    870 public:
    871   /// \brief Build 'untied' clause.
    872   ///
    873   /// \param StartLoc Starting location of the clause.
    874   /// \param EndLoc Ending location of the clause.
    875   ///
    876   OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
    877       : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
    878 
    879   /// \brief Build an empty clause.
    880   ///
    881   OMPUntiedClause()
    882       : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
    883 
    884   static bool classof(const OMPClause *T) {
    885     return T->getClauseKind() == OMPC_untied;
    886   }
    887 
    888   child_range children() {
    889     return child_range(child_iterator(), child_iterator());
    890   }
    891 };
    892 
    893 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
    894 /// directive.
    895 ///
    896 /// \code
    897 /// #pragma omp task mergeable
    898 /// \endcode
    899 /// In this example directive '#pragma omp task' has 'mergeable' clause.
    900 ///
    901 class OMPMergeableClause : public OMPClause {
    902 public:
    903   /// \brief Build 'mergeable' clause.
    904   ///
    905   /// \param StartLoc Starting location of the clause.
    906   /// \param EndLoc Ending location of the clause.
    907   ///
    908   OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
    909       : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
    910 
    911   /// \brief Build an empty clause.
    912   ///
    913   OMPMergeableClause()
    914       : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
    915 
    916   static bool classof(const OMPClause *T) {
    917     return T->getClauseKind() == OMPC_mergeable;
    918   }
    919 
    920   child_range children() {
    921     return child_range(child_iterator(), child_iterator());
    922   }
    923 };
    924 
    925 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
    926 ///
    927 /// \code
    928 /// #pragma omp atomic read
    929 /// \endcode
    930 /// In this example directive '#pragma omp atomic' has 'read' clause.
    931 ///
    932 class OMPReadClause : public OMPClause {
    933 public:
    934   /// \brief Build 'read' clause.
    935   ///
    936   /// \param StartLoc Starting location of the clause.
    937   /// \param EndLoc Ending location of the clause.
    938   ///
    939   OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
    940       : OMPClause(OMPC_read, StartLoc, EndLoc) {}
    941 
    942   /// \brief Build an empty clause.
    943   ///
    944   OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
    945 
    946   static bool classof(const OMPClause *T) {
    947     return T->getClauseKind() == OMPC_read;
    948   }
    949 
    950   child_range children() {
    951     return child_range(child_iterator(), child_iterator());
    952   }
    953 };
    954 
    955 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
    956 ///
    957 /// \code
    958 /// #pragma omp atomic write
    959 /// \endcode
    960 /// In this example directive '#pragma omp atomic' has 'write' clause.
    961 ///
    962 class OMPWriteClause : public OMPClause {
    963 public:
    964   /// \brief Build 'write' clause.
    965   ///
    966   /// \param StartLoc Starting location of the clause.
    967   /// \param EndLoc Ending location of the clause.
    968   ///
    969   OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
    970       : OMPClause(OMPC_write, StartLoc, EndLoc) {}
    971 
    972   /// \brief Build an empty clause.
    973   ///
    974   OMPWriteClause()
    975       : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
    976 
    977   static bool classof(const OMPClause *T) {
    978     return T->getClauseKind() == OMPC_write;
    979   }
    980 
    981   child_range children() {
    982     return child_range(child_iterator(), child_iterator());
    983   }
    984 };
    985 
    986 /// \brief This represents 'update' clause in the '#pragma omp atomic'
    987 /// directive.
    988 ///
    989 /// \code
    990 /// #pragma omp atomic update
    991 /// \endcode
    992 /// In this example directive '#pragma omp atomic' has 'update' clause.
    993 ///
    994 class OMPUpdateClause : public OMPClause {
    995 public:
    996   /// \brief Build 'update' clause.
    997   ///
    998   /// \param StartLoc Starting location of the clause.
    999   /// \param EndLoc Ending location of the clause.
   1000   ///
   1001   OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1002       : OMPClause(OMPC_update, StartLoc, EndLoc) {}
   1003 
   1004   /// \brief Build an empty clause.
   1005   ///
   1006   OMPUpdateClause()
   1007       : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
   1008 
   1009   static bool classof(const OMPClause *T) {
   1010     return T->getClauseKind() == OMPC_update;
   1011   }
   1012 
   1013   child_range children() {
   1014     return child_range(child_iterator(), child_iterator());
   1015   }
   1016 };
   1017 
   1018 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
   1019 /// directive.
   1020 ///
   1021 /// \code
   1022 /// #pragma omp atomic capture
   1023 /// \endcode
   1024 /// In this example directive '#pragma omp atomic' has 'capture' clause.
   1025 ///
   1026 class OMPCaptureClause : public OMPClause {
   1027 public:
   1028   /// \brief Build 'capture' clause.
   1029   ///
   1030   /// \param StartLoc Starting location of the clause.
   1031   /// \param EndLoc Ending location of the clause.
   1032   ///
   1033   OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1034       : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
   1035 
   1036   /// \brief Build an empty clause.
   1037   ///
   1038   OMPCaptureClause()
   1039       : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
   1040 
   1041   static bool classof(const OMPClause *T) {
   1042     return T->getClauseKind() == OMPC_capture;
   1043   }
   1044 
   1045   child_range children() {
   1046     return child_range(child_iterator(), child_iterator());
   1047   }
   1048 };
   1049 
   1050 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
   1051 /// directive.
   1052 ///
   1053 /// \code
   1054 /// #pragma omp atomic seq_cst
   1055 /// \endcode
   1056 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
   1057 ///
   1058 class OMPSeqCstClause : public OMPClause {
   1059 public:
   1060   /// \brief Build 'seq_cst' clause.
   1061   ///
   1062   /// \param StartLoc Starting location of the clause.
   1063   /// \param EndLoc Ending location of the clause.
   1064   ///
   1065   OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
   1066       : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
   1067 
   1068   /// \brief Build an empty clause.
   1069   ///
   1070   OMPSeqCstClause()
   1071       : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
   1072 
   1073   static bool classof(const OMPClause *T) {
   1074     return T->getClauseKind() == OMPC_seq_cst;
   1075   }
   1076 
   1077   child_range children() {
   1078     return child_range(child_iterator(), child_iterator());
   1079   }
   1080 };
   1081 
   1082 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
   1083 ///
   1084 /// \code
   1085 /// #pragma omp parallel private(a,b)
   1086 /// \endcode
   1087 /// In this example directive '#pragma omp parallel' has clause 'private'
   1088 /// with the variables 'a' and 'b'.
   1089 ///
   1090 class OMPPrivateClause : public OMPVarListClause<OMPPrivateClause> {
   1091   friend class OMPClauseReader;
   1092   /// \brief Build clause with number of variables \a N.
   1093   ///
   1094   /// \param StartLoc Starting location of the clause.
   1095   /// \param LParenLoc Location of '('.
   1096   /// \param EndLoc Ending location of the clause.
   1097   /// \param N Number of the variables in the clause.
   1098   ///
   1099   OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   1100                    SourceLocation EndLoc, unsigned N)
   1101       : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
   1102                                            EndLoc, N) {}
   1103 
   1104   /// \brief Build an empty clause.
   1105   ///
   1106   /// \param N Number of variables.
   1107   ///
   1108   explicit OMPPrivateClause(unsigned N)
   1109       : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
   1110                                            SourceLocation(), SourceLocation(),
   1111                                            N) {}
   1112 
   1113   /// \brief Sets the list of references to private copies with initializers for
   1114   /// new private variables.
   1115   /// \param VL List of references.
   1116   void setPrivateCopies(ArrayRef<Expr *> VL);
   1117 
   1118   /// \brief Gets the list of references to private copies with initializers for
   1119   /// new private variables.
   1120   MutableArrayRef<Expr *> getPrivateCopies() {
   1121     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   1122   }
   1123   ArrayRef<const Expr *> getPrivateCopies() const {
   1124     return llvm::makeArrayRef(varlist_end(), varlist_size());
   1125   }
   1126 
   1127 public:
   1128   /// \brief Creates clause with a list of variables \a VL.
   1129   ///
   1130   /// \param C AST context.
   1131   /// \param StartLoc Starting location of the clause.
   1132   /// \param LParenLoc Location of '('.
   1133   /// \param EndLoc Ending location of the clause.
   1134   /// \param VL List of references to the variables.
   1135   /// \param PrivateVL List of references to private copies with initializers.
   1136   ///
   1137   static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
   1138                                   SourceLocation LParenLoc,
   1139                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
   1140                                   ArrayRef<Expr *> PrivateVL);
   1141   /// \brief Creates an empty clause with the place for \a N variables.
   1142   ///
   1143   /// \param C AST context.
   1144   /// \param N The number of variables.
   1145   ///
   1146   static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
   1147 
   1148   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
   1149   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
   1150   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
   1151   typedef llvm::iterator_range<private_copies_const_iterator>
   1152       private_copies_const_range;
   1153 
   1154   private_copies_range private_copies() {
   1155     return private_copies_range(getPrivateCopies().begin(),
   1156                                 getPrivateCopies().end());
   1157   }
   1158   private_copies_const_range private_copies() const {
   1159     return private_copies_const_range(getPrivateCopies().begin(),
   1160                                       getPrivateCopies().end());
   1161   }
   1162 
   1163   child_range children() {
   1164     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   1165                        reinterpret_cast<Stmt **>(varlist_end()));
   1166   }
   1167 
   1168   static bool classof(const OMPClause *T) {
   1169     return T->getClauseKind() == OMPC_private;
   1170   }
   1171 };
   1172 
   1173 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
   1174 /// directives.
   1175 ///
   1176 /// \code
   1177 /// #pragma omp parallel firstprivate(a,b)
   1178 /// \endcode
   1179 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
   1180 /// with the variables 'a' and 'b'.
   1181 ///
   1182 class OMPFirstprivateClause : public OMPVarListClause<OMPFirstprivateClause> {
   1183   friend class OMPClauseReader;
   1184 
   1185   /// \brief Build clause with number of variables \a N.
   1186   ///
   1187   /// \param StartLoc Starting location of the clause.
   1188   /// \param LParenLoc Location of '('.
   1189   /// \param EndLoc Ending location of the clause.
   1190   /// \param N Number of the variables in the clause.
   1191   ///
   1192   OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   1193                         SourceLocation EndLoc, unsigned N)
   1194       : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
   1195                                                 LParenLoc, EndLoc, N) {}
   1196 
   1197   /// \brief Build an empty clause.
   1198   ///
   1199   /// \param N Number of variables.
   1200   ///
   1201   explicit OMPFirstprivateClause(unsigned N)
   1202       : OMPVarListClause<OMPFirstprivateClause>(
   1203             OMPC_firstprivate, SourceLocation(), SourceLocation(),
   1204             SourceLocation(), N) {}
   1205   /// \brief Sets the list of references to private copies with initializers for
   1206   /// new private variables.
   1207   /// \param VL List of references.
   1208   void setPrivateCopies(ArrayRef<Expr *> VL);
   1209 
   1210   /// \brief Gets the list of references to private copies with initializers for
   1211   /// new private variables.
   1212   MutableArrayRef<Expr *> getPrivateCopies() {
   1213     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   1214   }
   1215   ArrayRef<const Expr *> getPrivateCopies() const {
   1216     return llvm::makeArrayRef(varlist_end(), varlist_size());
   1217   }
   1218 
   1219   /// \brief Sets the list of references to initializer variables for new
   1220   /// private variables.
   1221   /// \param VL List of references.
   1222   void setInits(ArrayRef<Expr *> VL);
   1223 
   1224   /// \brief Gets the list of references to initializer variables for new
   1225   /// private variables.
   1226   MutableArrayRef<Expr *> getInits() {
   1227     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
   1228   }
   1229   ArrayRef<const Expr *> getInits() const {
   1230     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
   1231   }
   1232 
   1233 public:
   1234   /// \brief Creates clause with a list of variables \a VL.
   1235   ///
   1236   /// \param C AST context.
   1237   /// \param StartLoc Starting location of the clause.
   1238   /// \param LParenLoc Location of '('.
   1239   /// \param EndLoc Ending location of the clause.
   1240   /// \param VL List of references to the original variables.
   1241   /// \param PrivateVL List of references to private copies with initializers.
   1242   /// \param InitVL List of references to auto generated variables used for
   1243   /// initialization of a single array element. Used if firstprivate variable is
   1244   /// of array type.
   1245   ///
   1246   static OMPFirstprivateClause *
   1247   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   1248          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
   1249          ArrayRef<Expr *> InitVL);
   1250   /// \brief Creates an empty clause with the place for \a N variables.
   1251   ///
   1252   /// \param C AST context.
   1253   /// \param N The number of variables.
   1254   ///
   1255   static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
   1256 
   1257   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
   1258   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
   1259   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
   1260   typedef llvm::iterator_range<private_copies_const_iterator>
   1261       private_copies_const_range;
   1262 
   1263   private_copies_range private_copies() {
   1264     return private_copies_range(getPrivateCopies().begin(),
   1265                                 getPrivateCopies().end());
   1266   }
   1267   private_copies_const_range private_copies() const {
   1268     return private_copies_const_range(getPrivateCopies().begin(),
   1269                                       getPrivateCopies().end());
   1270   }
   1271 
   1272   typedef MutableArrayRef<Expr *>::iterator inits_iterator;
   1273   typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
   1274   typedef llvm::iterator_range<inits_iterator> inits_range;
   1275   typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
   1276 
   1277   inits_range inits() {
   1278     return inits_range(getInits().begin(), getInits().end());
   1279   }
   1280   inits_const_range inits() const {
   1281     return inits_const_range(getInits().begin(), getInits().end());
   1282   }
   1283 
   1284   child_range children() {
   1285     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   1286                        reinterpret_cast<Stmt **>(varlist_end()));
   1287   }
   1288 
   1289   static bool classof(const OMPClause *T) {
   1290     return T->getClauseKind() == OMPC_firstprivate;
   1291   }
   1292 };
   1293 
   1294 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
   1295 /// directives.
   1296 ///
   1297 /// \code
   1298 /// #pragma omp simd lastprivate(a,b)
   1299 /// \endcode
   1300 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
   1301 /// with the variables 'a' and 'b'.
   1302 class OMPLastprivateClause : public OMPVarListClause<OMPLastprivateClause> {
   1303   // There are 4 additional tail-allocated arrays at the end of the class:
   1304   // 1. Contains list of pseudo variables with the default initialization for
   1305   // each non-firstprivate variables. Used in codegen for initialization of
   1306   // lastprivate copies.
   1307   // 2. List of helper expressions for proper generation of assignment operation
   1308   // required for lastprivate clause. This list represents private variables
   1309   // (for arrays, single array element).
   1310   // 3. List of helper expressions for proper generation of assignment operation
   1311   // required for lastprivate clause. This list represents original variables
   1312   // (for arrays, single array element).
   1313   // 4. List of helper expressions that represents assignment operation:
   1314   // \code
   1315   // DstExprs = SrcExprs;
   1316   // \endcode
   1317   // Required for proper codegen of final assignment performed by the
   1318   // lastprivate clause.
   1319   //
   1320   friend class OMPClauseReader;
   1321 
   1322   /// \brief Build clause with number of variables \a N.
   1323   ///
   1324   /// \param StartLoc Starting location of the clause.
   1325   /// \param LParenLoc Location of '('.
   1326   /// \param EndLoc Ending location of the clause.
   1327   /// \param N Number of the variables in the clause.
   1328   ///
   1329   OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   1330                        SourceLocation EndLoc, unsigned N)
   1331       : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
   1332                                                LParenLoc, EndLoc, N) {}
   1333 
   1334   /// \brief Build an empty clause.
   1335   ///
   1336   /// \param N Number of variables.
   1337   ///
   1338   explicit OMPLastprivateClause(unsigned N)
   1339       : OMPVarListClause<OMPLastprivateClause>(
   1340             OMPC_lastprivate, SourceLocation(), SourceLocation(),
   1341             SourceLocation(), N) {}
   1342 
   1343   /// \brief Get the list of helper expressions for initialization of private
   1344   /// copies for lastprivate variables.
   1345   MutableArrayRef<Expr *> getPrivateCopies() {
   1346     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   1347   }
   1348   ArrayRef<const Expr *> getPrivateCopies() const {
   1349     return llvm::makeArrayRef(varlist_end(), varlist_size());
   1350   }
   1351 
   1352   /// \brief Set list of helper expressions, required for proper codegen of the
   1353   /// clause. These expressions represent private variables (for arrays, single
   1354   /// array element) in the final assignment statement performed by the
   1355   /// lastprivate clause.
   1356   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
   1357 
   1358   /// \brief Get the list of helper source expressions.
   1359   MutableArrayRef<Expr *> getSourceExprs() {
   1360     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
   1361   }
   1362   ArrayRef<const Expr *> getSourceExprs() const {
   1363     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
   1364   }
   1365 
   1366   /// \brief Set list of helper expressions, required for proper codegen of the
   1367   /// clause. These expressions represent original variables (for arrays, single
   1368   /// array element) in the final assignment statement performed by the
   1369   /// lastprivate clause.
   1370   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
   1371 
   1372   /// \brief Get the list of helper destination expressions.
   1373   MutableArrayRef<Expr *> getDestinationExprs() {
   1374     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
   1375   }
   1376   ArrayRef<const Expr *> getDestinationExprs() const {
   1377     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
   1378   }
   1379 
   1380   /// \brief Set list of helper assignment expressions, required for proper
   1381   /// codegen of the clause. These expressions are assignment expressions that
   1382   /// assign private copy of the variable to original variable.
   1383   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
   1384 
   1385   /// \brief Get the list of helper assignment expressions.
   1386   MutableArrayRef<Expr *> getAssignmentOps() {
   1387     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
   1388   }
   1389   ArrayRef<const Expr *> getAssignmentOps() const {
   1390     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
   1391   }
   1392 
   1393 public:
   1394   /// \brief Creates clause with a list of variables \a VL.
   1395   ///
   1396   /// \param C AST context.
   1397   /// \param StartLoc Starting location of the clause.
   1398   /// \param LParenLoc Location of '('.
   1399   /// \param EndLoc Ending location of the clause.
   1400   /// \param VL List of references to the variables.
   1401   /// \param SrcExprs List of helper expressions for proper generation of
   1402   /// assignment operation required for lastprivate clause. This list represents
   1403   /// private variables (for arrays, single array element).
   1404   /// \param DstExprs List of helper expressions for proper generation of
   1405   /// assignment operation required for lastprivate clause. This list represents
   1406   /// original variables (for arrays, single array element).
   1407   /// \param AssignmentOps List of helper expressions that represents assignment
   1408   /// operation:
   1409   /// \code
   1410   /// DstExprs = SrcExprs;
   1411   /// \endcode
   1412   /// Required for proper codegen of final assignment performed by the
   1413   /// lastprivate clause.
   1414   ///
   1415   ///
   1416   static OMPLastprivateClause *
   1417   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   1418          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
   1419          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
   1420   /// \brief Creates an empty clause with the place for \a N variables.
   1421   ///
   1422   /// \param C AST context.
   1423   /// \param N The number of variables.
   1424   ///
   1425   static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
   1426 
   1427   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
   1428   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
   1429   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
   1430   typedef llvm::iterator_range<helper_expr_const_iterator>
   1431       helper_expr_const_range;
   1432 
   1433   /// \brief Set list of helper expressions, required for generation of private
   1434   /// copies of original lastprivate variables.
   1435   void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
   1436 
   1437   helper_expr_const_range private_copies() const {
   1438     return helper_expr_const_range(getPrivateCopies().begin(),
   1439                                    getPrivateCopies().end());
   1440   }
   1441   helper_expr_range private_copies() {
   1442     return helper_expr_range(getPrivateCopies().begin(),
   1443                              getPrivateCopies().end());
   1444   }
   1445   helper_expr_const_range source_exprs() const {
   1446     return helper_expr_const_range(getSourceExprs().begin(),
   1447                                    getSourceExprs().end());
   1448   }
   1449   helper_expr_range source_exprs() {
   1450     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
   1451   }
   1452   helper_expr_const_range destination_exprs() const {
   1453     return helper_expr_const_range(getDestinationExprs().begin(),
   1454                                    getDestinationExprs().end());
   1455   }
   1456   helper_expr_range destination_exprs() {
   1457     return helper_expr_range(getDestinationExprs().begin(),
   1458                              getDestinationExprs().end());
   1459   }
   1460   helper_expr_const_range assignment_ops() const {
   1461     return helper_expr_const_range(getAssignmentOps().begin(),
   1462                                    getAssignmentOps().end());
   1463   }
   1464   helper_expr_range assignment_ops() {
   1465     return helper_expr_range(getAssignmentOps().begin(),
   1466                              getAssignmentOps().end());
   1467   }
   1468 
   1469   child_range children() {
   1470     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   1471                        reinterpret_cast<Stmt **>(varlist_end()));
   1472   }
   1473 
   1474   static bool classof(const OMPClause *T) {
   1475     return T->getClauseKind() == OMPC_lastprivate;
   1476   }
   1477 };
   1478 
   1479 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
   1480 ///
   1481 /// \code
   1482 /// #pragma omp parallel shared(a,b)
   1483 /// \endcode
   1484 /// In this example directive '#pragma omp parallel' has clause 'shared'
   1485 /// with the variables 'a' and 'b'.
   1486 ///
   1487 class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
   1488   /// \brief Build clause with number of variables \a N.
   1489   ///
   1490   /// \param StartLoc Starting location of the clause.
   1491   /// \param LParenLoc Location of '('.
   1492   /// \param EndLoc Ending location of the clause.
   1493   /// \param N Number of the variables in the clause.
   1494   ///
   1495   OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   1496                   SourceLocation EndLoc, unsigned N)
   1497       : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
   1498                                           EndLoc, N) {}
   1499 
   1500   /// \brief Build an empty clause.
   1501   ///
   1502   /// \param N Number of variables.
   1503   ///
   1504   explicit OMPSharedClause(unsigned N)
   1505       : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
   1506                                           SourceLocation(), SourceLocation(),
   1507                                           N) {}
   1508 
   1509 public:
   1510   /// \brief Creates clause with a list of variables \a VL.
   1511   ///
   1512   /// \param C AST context.
   1513   /// \param StartLoc Starting location of the clause.
   1514   /// \param LParenLoc Location of '('.
   1515   /// \param EndLoc Ending location of the clause.
   1516   /// \param VL List of references to the variables.
   1517   ///
   1518   static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
   1519                                  SourceLocation LParenLoc,
   1520                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
   1521   /// \brief Creates an empty clause with \a N variables.
   1522   ///
   1523   /// \param C AST context.
   1524   /// \param N The number of variables.
   1525   ///
   1526   static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
   1527 
   1528   child_range children() {
   1529     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   1530                        reinterpret_cast<Stmt **>(varlist_end()));
   1531   }
   1532 
   1533   static bool classof(const OMPClause *T) {
   1534     return T->getClauseKind() == OMPC_shared;
   1535   }
   1536 };
   1537 
   1538 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
   1539 /// directives.
   1540 ///
   1541 /// \code
   1542 /// #pragma omp parallel reduction(+:a,b)
   1543 /// \endcode
   1544 /// In this example directive '#pragma omp parallel' has clause 'reduction'
   1545 /// with operator '+' and the variables 'a' and 'b'.
   1546 ///
   1547 class OMPReductionClause : public OMPVarListClause<OMPReductionClause> {
   1548   friend class OMPClauseReader;
   1549   /// \brief Location of ':'.
   1550   SourceLocation ColonLoc;
   1551   /// \brief Nested name specifier for C++.
   1552   NestedNameSpecifierLoc QualifierLoc;
   1553   /// \brief Name of custom operator.
   1554   DeclarationNameInfo NameInfo;
   1555 
   1556   /// \brief Build clause with number of variables \a N.
   1557   ///
   1558   /// \param StartLoc Starting location of the clause.
   1559   /// \param LParenLoc Location of '('.
   1560   /// \param EndLoc Ending location of the clause.
   1561   /// \param ColonLoc Location of ':'.
   1562   /// \param N Number of the variables in the clause.
   1563   /// \param QualifierLoc The nested-name qualifier with location information
   1564   /// \param NameInfo The full name info for reduction identifier.
   1565   ///
   1566   OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   1567                      SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
   1568                      NestedNameSpecifierLoc QualifierLoc,
   1569                      const DeclarationNameInfo &NameInfo)
   1570       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
   1571                                              LParenLoc, EndLoc, N),
   1572         ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
   1573 
   1574   /// \brief Build an empty clause.
   1575   ///
   1576   /// \param N Number of variables.
   1577   ///
   1578   explicit OMPReductionClause(unsigned N)
   1579       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
   1580                                              SourceLocation(), SourceLocation(),
   1581                                              N),
   1582         ColonLoc(), QualifierLoc(), NameInfo() {}
   1583 
   1584   /// \brief Sets location of ':' symbol in clause.
   1585   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
   1586   /// \brief Sets the name info for specified reduction identifier.
   1587   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
   1588   /// \brief Sets the nested name specifier.
   1589   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
   1590 
   1591   /// \brief Set list of helper expressions, required for proper codegen of the
   1592   /// clause. These expressions represent private copy of the reduction
   1593   /// variable.
   1594   void setPrivates(ArrayRef<Expr *> Privates);
   1595 
   1596   /// \brief Get the list of helper privates.
   1597   MutableArrayRef<Expr *> getPrivates() {
   1598     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   1599   }
   1600   ArrayRef<const Expr *> getPrivates() const {
   1601     return llvm::makeArrayRef(varlist_end(), varlist_size());
   1602   }
   1603 
   1604   /// \brief Set list of helper expressions, required for proper codegen of the
   1605   /// clause. These expressions represent LHS expression in the final
   1606   /// reduction expression performed by the reduction clause.
   1607   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
   1608 
   1609   /// \brief Get the list of helper LHS expressions.
   1610   MutableArrayRef<Expr *> getLHSExprs() {
   1611     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
   1612   }
   1613   ArrayRef<const Expr *> getLHSExprs() const {
   1614     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
   1615   }
   1616 
   1617   /// \brief Set list of helper expressions, required for proper codegen of the
   1618   /// clause. These expressions represent RHS expression in the final
   1619   /// reduction expression performed by the reduction clause.
   1620   /// Also, variables in these expressions are used for proper initialization of
   1621   /// reduction copies.
   1622   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
   1623 
   1624   /// \brief Get the list of helper destination expressions.
   1625   MutableArrayRef<Expr *> getRHSExprs() {
   1626     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
   1627   }
   1628   ArrayRef<const Expr *> getRHSExprs() const {
   1629     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
   1630   }
   1631 
   1632   /// \brief Set list of helper reduction expressions, required for proper
   1633   /// codegen of the clause. These expressions are binary expressions or
   1634   /// operator/custom reduction call that calculates new value from source
   1635   /// helper expressions to destination helper expressions.
   1636   void setReductionOps(ArrayRef<Expr *> ReductionOps);
   1637 
   1638   /// \brief Get the list of helper reduction expressions.
   1639   MutableArrayRef<Expr *> getReductionOps() {
   1640     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
   1641   }
   1642   ArrayRef<const Expr *> getReductionOps() const {
   1643     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
   1644   }
   1645 
   1646 public:
   1647   /// \brief Creates clause with a list of variables \a VL.
   1648   ///
   1649   /// \param StartLoc Starting location of the clause.
   1650   /// \param LParenLoc Location of '('.
   1651   /// \param ColonLoc Location of ':'.
   1652   /// \param EndLoc Ending location of the clause.
   1653   /// \param VL The variables in the clause.
   1654   /// \param QualifierLoc The nested-name qualifier with location information
   1655   /// \param NameInfo The full name info for reduction identifier.
   1656   /// \param Privates List of helper expressions for proper generation of
   1657   /// private copies.
   1658   /// \param LHSExprs List of helper expressions for proper generation of
   1659   /// assignment operation required for copyprivate clause. This list represents
   1660   /// LHSs of the reduction expressions.
   1661   /// \param RHSExprs List of helper expressions for proper generation of
   1662   /// assignment operation required for copyprivate clause. This list represents
   1663   /// RHSs of the reduction expressions.
   1664   /// Also, variables in these expressions are used for proper initialization of
   1665   /// reduction copies.
   1666   /// \param ReductionOps List of helper expressions that represents reduction
   1667   /// expressions:
   1668   /// \code
   1669   /// LHSExprs binop RHSExprs;
   1670   /// operator binop(LHSExpr, RHSExpr);
   1671   /// <CutomReduction>(LHSExpr, RHSExpr);
   1672   /// \endcode
   1673   /// Required for proper codegen of final reduction operation performed by the
   1674   /// reduction clause.
   1675   ///
   1676   static OMPReductionClause *
   1677   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   1678          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
   1679          NestedNameSpecifierLoc QualifierLoc,
   1680          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
   1681          ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
   1682          ArrayRef<Expr *> ReductionOps);
   1683   /// \brief Creates an empty clause with the place for \a N variables.
   1684   ///
   1685   /// \param C AST context.
   1686   /// \param N The number of variables.
   1687   ///
   1688   static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
   1689 
   1690   /// \brief Gets location of ':' symbol in clause.
   1691   SourceLocation getColonLoc() const { return ColonLoc; }
   1692   /// \brief Gets the name info for specified reduction identifier.
   1693   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
   1694   /// \brief Gets the nested name specifier.
   1695   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
   1696 
   1697   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
   1698   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
   1699   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
   1700   typedef llvm::iterator_range<helper_expr_const_iterator>
   1701       helper_expr_const_range;
   1702 
   1703   helper_expr_const_range privates() const {
   1704     return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
   1705   }
   1706   helper_expr_range privates() {
   1707     return helper_expr_range(getPrivates().begin(), getPrivates().end());
   1708   }
   1709   helper_expr_const_range lhs_exprs() const {
   1710     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
   1711   }
   1712   helper_expr_range lhs_exprs() {
   1713     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
   1714   }
   1715   helper_expr_const_range rhs_exprs() const {
   1716     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
   1717   }
   1718   helper_expr_range rhs_exprs() {
   1719     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
   1720   }
   1721   helper_expr_const_range reduction_ops() const {
   1722     return helper_expr_const_range(getReductionOps().begin(),
   1723                                    getReductionOps().end());
   1724   }
   1725   helper_expr_range reduction_ops() {
   1726     return helper_expr_range(getReductionOps().begin(),
   1727                              getReductionOps().end());
   1728   }
   1729 
   1730   child_range children() {
   1731     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   1732                        reinterpret_cast<Stmt **>(varlist_end()));
   1733   }
   1734 
   1735   static bool classof(const OMPClause *T) {
   1736     return T->getClauseKind() == OMPC_reduction;
   1737   }
   1738 };
   1739 
   1740 /// \brief This represents clause 'linear' in the '#pragma omp ...'
   1741 /// directives.
   1742 ///
   1743 /// \code
   1744 /// #pragma omp simd linear(a,b : 2)
   1745 /// \endcode
   1746 /// In this example directive '#pragma omp simd' has clause 'linear'
   1747 /// with variables 'a', 'b' and linear step '2'.
   1748 ///
   1749 class OMPLinearClause : public OMPVarListClause<OMPLinearClause> {
   1750   friend class OMPClauseReader;
   1751   /// \brief Modifier of 'linear' clause.
   1752   OpenMPLinearClauseKind Modifier;
   1753   /// \brief Location of linear modifier if any.
   1754   SourceLocation ModifierLoc;
   1755   /// \brief Location of ':'.
   1756   SourceLocation ColonLoc;
   1757 
   1758   /// \brief Sets the linear step for clause.
   1759   void setStep(Expr *Step) { *(getFinals().end()) = Step; }
   1760 
   1761   /// \brief Sets the expression to calculate linear step for clause.
   1762   void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
   1763 
   1764   /// \brief Build 'linear' clause with given number of variables \a NumVars.
   1765   ///
   1766   /// \param StartLoc Starting location of the clause.
   1767   /// \param LParenLoc Location of '('.
   1768   /// \param ColonLoc Location of ':'.
   1769   /// \param EndLoc Ending location of the clause.
   1770   /// \param NumVars Number of variables.
   1771   ///
   1772   OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   1773                   OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
   1774                   SourceLocation ColonLoc, SourceLocation EndLoc,
   1775                   unsigned NumVars)
   1776       : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
   1777                                           EndLoc, NumVars),
   1778         Modifier(Modifier), ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
   1779 
   1780   /// \brief Build an empty clause.
   1781   ///
   1782   /// \param NumVars Number of variables.
   1783   ///
   1784   explicit OMPLinearClause(unsigned NumVars)
   1785       : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
   1786                                           SourceLocation(), SourceLocation(),
   1787                                           NumVars),
   1788         Modifier(OMPC_LINEAR_val), ModifierLoc(), ColonLoc() {}
   1789 
   1790   /// \brief Gets the list of initial values for linear variables.
   1791   ///
   1792   /// There are NumVars expressions with initial values allocated after the
   1793   /// varlist, they are followed by NumVars update expressions (used to update
   1794   /// the linear variable's value on current iteration) and they are followed by
   1795   /// NumVars final expressions (used to calculate the linear variable's
   1796   /// value after the loop body). After these lists, there are 2 helper
   1797   /// expressions - linear step and a helper to calculate it before the
   1798   /// loop body (used when the linear step is not constant):
   1799   ///
   1800   /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
   1801   /// Finals[]; Step; CalcStep; }
   1802   ///
   1803   MutableArrayRef<Expr *> getPrivates() {
   1804     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   1805   }
   1806   ArrayRef<const Expr *> getPrivates() const {
   1807     return llvm::makeArrayRef(varlist_end(), varlist_size());
   1808   }
   1809 
   1810   MutableArrayRef<Expr *> getInits() {
   1811     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
   1812   }
   1813   ArrayRef<const Expr *> getInits() const {
   1814     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
   1815   }
   1816 
   1817   /// \brief Sets the list of update expressions for linear variables.
   1818   MutableArrayRef<Expr *> getUpdates() {
   1819     return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
   1820   }
   1821   ArrayRef<const Expr *> getUpdates() const {
   1822     return llvm::makeArrayRef(getInits().end(), varlist_size());
   1823   }
   1824 
   1825   /// \brief Sets the list of final update expressions for linear variables.
   1826   MutableArrayRef<Expr *> getFinals() {
   1827     return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
   1828   }
   1829   ArrayRef<const Expr *> getFinals() const {
   1830     return llvm::makeArrayRef(getUpdates().end(), varlist_size());
   1831   }
   1832 
   1833   /// \brief Sets the list of the copies of original linear variables.
   1834   /// \param PL List of expressions.
   1835   void setPrivates(ArrayRef<Expr *> PL);
   1836 
   1837   /// \brief Sets the list of the initial values for linear variables.
   1838   /// \param IL List of expressions.
   1839   void setInits(ArrayRef<Expr *> IL);
   1840 
   1841 public:
   1842   /// \brief Creates clause with a list of variables \a VL and a linear step
   1843   /// \a Step.
   1844   ///
   1845   /// \param C AST Context.
   1846   /// \param StartLoc Starting location of the clause.
   1847   /// \param LParenLoc Location of '('.
   1848   /// \param Modifier Modifier of 'linear' clause.
   1849   /// \param ModifierLoc Modifier location.
   1850   /// \param ColonLoc Location of ':'.
   1851   /// \param EndLoc Ending location of the clause.
   1852   /// \param VL List of references to the variables.
   1853   /// \param PL List of private copies of original variables.
   1854   /// \param IL List of initial values for the variables.
   1855   /// \param Step Linear step.
   1856   /// \param CalcStep Calculation of the linear step.
   1857   static OMPLinearClause *
   1858   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   1859          OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
   1860          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
   1861          ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep);
   1862 
   1863   /// \brief Creates an empty clause with the place for \a NumVars variables.
   1864   ///
   1865   /// \param C AST context.
   1866   /// \param NumVars Number of variables.
   1867   ///
   1868   static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
   1869 
   1870   /// \brief Set modifier.
   1871   void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
   1872   /// \brief Return modifier.
   1873   OpenMPLinearClauseKind getModifier() const { return Modifier; }
   1874 
   1875   /// \brief Set modifier location.
   1876   void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
   1877   /// \brief Return modifier location.
   1878   SourceLocation getModifierLoc() const { return ModifierLoc; }
   1879 
   1880   /// \brief Sets the location of ':'.
   1881   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   1882   /// \brief Returns the location of ':'.
   1883   SourceLocation getColonLoc() const { return ColonLoc; }
   1884 
   1885   /// \brief Returns linear step.
   1886   Expr *getStep() { return *(getFinals().end()); }
   1887   /// \brief Returns linear step.
   1888   const Expr *getStep() const { return *(getFinals().end()); }
   1889   /// \brief Returns expression to calculate linear step.
   1890   Expr *getCalcStep() { return *(getFinals().end() + 1); }
   1891   /// \brief Returns expression to calculate linear step.
   1892   const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
   1893 
   1894   /// \brief Sets the list of update expressions for linear variables.
   1895   /// \param UL List of expressions.
   1896   void setUpdates(ArrayRef<Expr *> UL);
   1897 
   1898   /// \brief Sets the list of final update expressions for linear variables.
   1899   /// \param FL List of expressions.
   1900   void setFinals(ArrayRef<Expr *> FL);
   1901 
   1902   typedef MutableArrayRef<Expr *>::iterator privates_iterator;
   1903   typedef ArrayRef<const Expr *>::iterator privates_const_iterator;
   1904   typedef llvm::iterator_range<privates_iterator> privates_range;
   1905   typedef llvm::iterator_range<privates_const_iterator> privates_const_range;
   1906 
   1907   privates_range privates() {
   1908     return privates_range(getPrivates().begin(), getPrivates().end());
   1909   }
   1910   privates_const_range privates() const {
   1911     return privates_const_range(getPrivates().begin(), getPrivates().end());
   1912   }
   1913 
   1914   typedef MutableArrayRef<Expr *>::iterator inits_iterator;
   1915   typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
   1916   typedef llvm::iterator_range<inits_iterator> inits_range;
   1917   typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
   1918 
   1919   inits_range inits() {
   1920     return inits_range(getInits().begin(), getInits().end());
   1921   }
   1922   inits_const_range inits() const {
   1923     return inits_const_range(getInits().begin(), getInits().end());
   1924   }
   1925 
   1926   typedef MutableArrayRef<Expr *>::iterator updates_iterator;
   1927   typedef ArrayRef<const Expr *>::iterator updates_const_iterator;
   1928   typedef llvm::iterator_range<updates_iterator> updates_range;
   1929   typedef llvm::iterator_range<updates_const_iterator> updates_const_range;
   1930 
   1931   updates_range updates() {
   1932     return updates_range(getUpdates().begin(), getUpdates().end());
   1933   }
   1934   updates_const_range updates() const {
   1935     return updates_const_range(getUpdates().begin(), getUpdates().end());
   1936   }
   1937 
   1938   typedef MutableArrayRef<Expr *>::iterator finals_iterator;
   1939   typedef ArrayRef<const Expr *>::iterator finals_const_iterator;
   1940   typedef llvm::iterator_range<finals_iterator> finals_range;
   1941   typedef llvm::iterator_range<finals_const_iterator> finals_const_range;
   1942 
   1943   finals_range finals() {
   1944     return finals_range(getFinals().begin(), getFinals().end());
   1945   }
   1946   finals_const_range finals() const {
   1947     return finals_const_range(getFinals().begin(), getFinals().end());
   1948   }
   1949 
   1950   child_range children() {
   1951     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   1952                        reinterpret_cast<Stmt **>(varlist_end()));
   1953   }
   1954 
   1955   static bool classof(const OMPClause *T) {
   1956     return T->getClauseKind() == OMPC_linear;
   1957   }
   1958 };
   1959 
   1960 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
   1961 /// directives.
   1962 ///
   1963 /// \code
   1964 /// #pragma omp simd aligned(a,b : 8)
   1965 /// \endcode
   1966 /// In this example directive '#pragma omp simd' has clause 'aligned'
   1967 /// with variables 'a', 'b' and alignment '8'.
   1968 ///
   1969 class OMPAlignedClause : public OMPVarListClause<OMPAlignedClause> {
   1970   friend class OMPClauseReader;
   1971   /// \brief Location of ':'.
   1972   SourceLocation ColonLoc;
   1973 
   1974   /// \brief Sets the alignment for clause.
   1975   void setAlignment(Expr *A) { *varlist_end() = A; }
   1976 
   1977   /// \brief Build 'aligned' clause with given number of variables \a NumVars.
   1978   ///
   1979   /// \param StartLoc Starting location of the clause.
   1980   /// \param LParenLoc Location of '('.
   1981   /// \param ColonLoc Location of ':'.
   1982   /// \param EndLoc Ending location of the clause.
   1983   /// \param NumVars Number of variables.
   1984   ///
   1985   OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   1986                    SourceLocation ColonLoc, SourceLocation EndLoc,
   1987                    unsigned NumVars)
   1988       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
   1989                                            EndLoc, NumVars),
   1990         ColonLoc(ColonLoc) {}
   1991 
   1992   /// \brief Build an empty clause.
   1993   ///
   1994   /// \param NumVars Number of variables.
   1995   ///
   1996   explicit OMPAlignedClause(unsigned NumVars)
   1997       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
   1998                                            SourceLocation(), SourceLocation(),
   1999                                            NumVars),
   2000         ColonLoc(SourceLocation()) {}
   2001 
   2002 public:
   2003   /// \brief Creates clause with a list of variables \a VL and alignment \a A.
   2004   ///
   2005   /// \param C AST Context.
   2006   /// \param StartLoc Starting location of the clause.
   2007   /// \param LParenLoc Location of '('.
   2008   /// \param ColonLoc Location of ':'.
   2009   /// \param EndLoc Ending location of the clause.
   2010   /// \param VL List of references to the variables.
   2011   /// \param A Alignment.
   2012   static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
   2013                                   SourceLocation LParenLoc,
   2014                                   SourceLocation ColonLoc,
   2015                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
   2016                                   Expr *A);
   2017 
   2018   /// \brief Creates an empty clause with the place for \a NumVars variables.
   2019   ///
   2020   /// \param C AST context.
   2021   /// \param NumVars Number of variables.
   2022   ///
   2023   static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
   2024 
   2025   /// \brief Sets the location of ':'.
   2026   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   2027   /// \brief Returns the location of ':'.
   2028   SourceLocation getColonLoc() const { return ColonLoc; }
   2029 
   2030   /// \brief Returns alignment.
   2031   Expr *getAlignment() { return *varlist_end(); }
   2032   /// \brief Returns alignment.
   2033   const Expr *getAlignment() const { return *varlist_end(); }
   2034 
   2035   child_range children() {
   2036     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2037                        reinterpret_cast<Stmt **>(varlist_end()));
   2038   }
   2039 
   2040   static bool classof(const OMPClause *T) {
   2041     return T->getClauseKind() == OMPC_aligned;
   2042   }
   2043 };
   2044 
   2045 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
   2046 ///
   2047 /// \code
   2048 /// #pragma omp parallel copyin(a,b)
   2049 /// \endcode
   2050 /// In this example directive '#pragma omp parallel' has clause 'copyin'
   2051 /// with the variables 'a' and 'b'.
   2052 ///
   2053 class OMPCopyinClause : public OMPVarListClause<OMPCopyinClause> {
   2054   // Class has 3 additional tail allocated arrays:
   2055   // 1. List of helper expressions for proper generation of assignment operation
   2056   // required for copyin clause. This list represents sources.
   2057   // 2. List of helper expressions for proper generation of assignment operation
   2058   // required for copyin clause. This list represents destinations.
   2059   // 3. List of helper expressions that represents assignment operation:
   2060   // \code
   2061   // DstExprs = SrcExprs;
   2062   // \endcode
   2063   // Required for proper codegen of propagation of master's thread values of
   2064   // threadprivate variables to local instances of that variables in other
   2065   // implicit threads.
   2066 
   2067   friend class OMPClauseReader;
   2068   /// \brief Build clause with number of variables \a N.
   2069   ///
   2070   /// \param StartLoc Starting location of the clause.
   2071   /// \param LParenLoc Location of '('.
   2072   /// \param EndLoc Ending location of the clause.
   2073   /// \param N Number of the variables in the clause.
   2074   ///
   2075   OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2076                   SourceLocation EndLoc, unsigned N)
   2077       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
   2078                                           EndLoc, N) {}
   2079 
   2080   /// \brief Build an empty clause.
   2081   ///
   2082   /// \param N Number of variables.
   2083   ///
   2084   explicit OMPCopyinClause(unsigned N)
   2085       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
   2086                                           SourceLocation(), SourceLocation(),
   2087                                           N) {}
   2088 
   2089   /// \brief Set list of helper expressions, required for proper codegen of the
   2090   /// clause. These expressions represent source expression in the final
   2091   /// assignment statement performed by the copyin clause.
   2092   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
   2093 
   2094   /// \brief Get the list of helper source expressions.
   2095   MutableArrayRef<Expr *> getSourceExprs() {
   2096     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   2097   }
   2098   ArrayRef<const Expr *> getSourceExprs() const {
   2099     return llvm::makeArrayRef(varlist_end(), varlist_size());
   2100   }
   2101 
   2102   /// \brief Set list of helper expressions, required for proper codegen of the
   2103   /// clause. These expressions represent destination expression in the final
   2104   /// assignment statement performed by the copyin clause.
   2105   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
   2106 
   2107   /// \brief Get the list of helper destination expressions.
   2108   MutableArrayRef<Expr *> getDestinationExprs() {
   2109     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
   2110   }
   2111   ArrayRef<const Expr *> getDestinationExprs() const {
   2112     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
   2113   }
   2114 
   2115   /// \brief Set list of helper assignment expressions, required for proper
   2116   /// codegen of the clause. These expressions are assignment expressions that
   2117   /// assign source helper expressions to destination helper expressions
   2118   /// correspondingly.
   2119   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
   2120 
   2121   /// \brief Get the list of helper assignment expressions.
   2122   MutableArrayRef<Expr *> getAssignmentOps() {
   2123     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
   2124   }
   2125   ArrayRef<const Expr *> getAssignmentOps() const {
   2126     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
   2127   }
   2128 
   2129 public:
   2130   /// \brief Creates clause with a list of variables \a VL.
   2131   ///
   2132   /// \param C AST context.
   2133   /// \param StartLoc Starting location of the clause.
   2134   /// \param LParenLoc Location of '('.
   2135   /// \param EndLoc Ending location of the clause.
   2136   /// \param VL List of references to the variables.
   2137   /// \param SrcExprs List of helper expressions for proper generation of
   2138   /// assignment operation required for copyin clause. This list represents
   2139   /// sources.
   2140   /// \param DstExprs List of helper expressions for proper generation of
   2141   /// assignment operation required for copyin clause. This list represents
   2142   /// destinations.
   2143   /// \param AssignmentOps List of helper expressions that represents assignment
   2144   /// operation:
   2145   /// \code
   2146   /// DstExprs = SrcExprs;
   2147   /// \endcode
   2148   /// Required for proper codegen of propagation of master's thread values of
   2149   /// threadprivate variables to local instances of that variables in other
   2150   /// implicit threads.
   2151   ///
   2152   static OMPCopyinClause *
   2153   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   2154          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
   2155          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
   2156   /// \brief Creates an empty clause with \a N variables.
   2157   ///
   2158   /// \param C AST context.
   2159   /// \param N The number of variables.
   2160   ///
   2161   static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
   2162 
   2163   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
   2164   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
   2165   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
   2166   typedef llvm::iterator_range<helper_expr_const_iterator>
   2167       helper_expr_const_range;
   2168 
   2169   helper_expr_const_range source_exprs() const {
   2170     return helper_expr_const_range(getSourceExprs().begin(),
   2171                                    getSourceExprs().end());
   2172   }
   2173   helper_expr_range source_exprs() {
   2174     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
   2175   }
   2176   helper_expr_const_range destination_exprs() const {
   2177     return helper_expr_const_range(getDestinationExprs().begin(),
   2178                                    getDestinationExprs().end());
   2179   }
   2180   helper_expr_range destination_exprs() {
   2181     return helper_expr_range(getDestinationExprs().begin(),
   2182                              getDestinationExprs().end());
   2183   }
   2184   helper_expr_const_range assignment_ops() const {
   2185     return helper_expr_const_range(getAssignmentOps().begin(),
   2186                                    getAssignmentOps().end());
   2187   }
   2188   helper_expr_range assignment_ops() {
   2189     return helper_expr_range(getAssignmentOps().begin(),
   2190                              getAssignmentOps().end());
   2191   }
   2192 
   2193   child_range children() {
   2194     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2195                        reinterpret_cast<Stmt **>(varlist_end()));
   2196   }
   2197 
   2198   static bool classof(const OMPClause *T) {
   2199     return T->getClauseKind() == OMPC_copyin;
   2200   }
   2201 };
   2202 
   2203 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
   2204 /// directives.
   2205 ///
   2206 /// \code
   2207 /// #pragma omp single copyprivate(a,b)
   2208 /// \endcode
   2209 /// In this example directive '#pragma omp single' has clause 'copyprivate'
   2210 /// with the variables 'a' and 'b'.
   2211 ///
   2212 class OMPCopyprivateClause : public OMPVarListClause<OMPCopyprivateClause> {
   2213   friend class OMPClauseReader;
   2214   /// \brief Build clause with number of variables \a N.
   2215   ///
   2216   /// \param StartLoc Starting location of the clause.
   2217   /// \param LParenLoc Location of '('.
   2218   /// \param EndLoc Ending location of the clause.
   2219   /// \param N Number of the variables in the clause.
   2220   ///
   2221   OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2222                        SourceLocation EndLoc, unsigned N)
   2223       : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
   2224                                                LParenLoc, EndLoc, N) {}
   2225 
   2226   /// \brief Build an empty clause.
   2227   ///
   2228   /// \param N Number of variables.
   2229   ///
   2230   explicit OMPCopyprivateClause(unsigned N)
   2231       : OMPVarListClause<OMPCopyprivateClause>(
   2232             OMPC_copyprivate, SourceLocation(), SourceLocation(),
   2233             SourceLocation(), N) {}
   2234 
   2235   /// \brief Set list of helper expressions, required for proper codegen of the
   2236   /// clause. These expressions represent source expression in the final
   2237   /// assignment statement performed by the copyprivate clause.
   2238   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
   2239 
   2240   /// \brief Get the list of helper source expressions.
   2241   MutableArrayRef<Expr *> getSourceExprs() {
   2242     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
   2243   }
   2244   ArrayRef<const Expr *> getSourceExprs() const {
   2245     return llvm::makeArrayRef(varlist_end(), varlist_size());
   2246   }
   2247 
   2248   /// \brief Set list of helper expressions, required for proper codegen of the
   2249   /// clause. These expressions represent destination expression in the final
   2250   /// assignment statement performed by the copyprivate clause.
   2251   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
   2252 
   2253   /// \brief Get the list of helper destination expressions.
   2254   MutableArrayRef<Expr *> getDestinationExprs() {
   2255     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
   2256   }
   2257   ArrayRef<const Expr *> getDestinationExprs() const {
   2258     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
   2259   }
   2260 
   2261   /// \brief Set list of helper assignment expressions, required for proper
   2262   /// codegen of the clause. These expressions are assignment expressions that
   2263   /// assign source helper expressions to destination helper expressions
   2264   /// correspondingly.
   2265   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
   2266 
   2267   /// \brief Get the list of helper assignment expressions.
   2268   MutableArrayRef<Expr *> getAssignmentOps() {
   2269     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
   2270   }
   2271   ArrayRef<const Expr *> getAssignmentOps() const {
   2272     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
   2273   }
   2274 
   2275 public:
   2276   /// \brief Creates clause with a list of variables \a VL.
   2277   ///
   2278   /// \param C AST context.
   2279   /// \param StartLoc Starting location of the clause.
   2280   /// \param LParenLoc Location of '('.
   2281   /// \param EndLoc Ending location of the clause.
   2282   /// \param VL List of references to the variables.
   2283   /// \param SrcExprs List of helper expressions for proper generation of
   2284   /// assignment operation required for copyprivate clause. This list represents
   2285   /// sources.
   2286   /// \param DstExprs List of helper expressions for proper generation of
   2287   /// assignment operation required for copyprivate clause. This list represents
   2288   /// destinations.
   2289   /// \param AssignmentOps List of helper expressions that represents assignment
   2290   /// operation:
   2291   /// \code
   2292   /// DstExprs = SrcExprs;
   2293   /// \endcode
   2294   /// Required for proper codegen of final assignment performed by the
   2295   /// copyprivate clause.
   2296   ///
   2297   static OMPCopyprivateClause *
   2298   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   2299          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
   2300          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
   2301   /// \brief Creates an empty clause with \a N variables.
   2302   ///
   2303   /// \param C AST context.
   2304   /// \param N The number of variables.
   2305   ///
   2306   static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
   2307 
   2308   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
   2309   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
   2310   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
   2311   typedef llvm::iterator_range<helper_expr_const_iterator>
   2312       helper_expr_const_range;
   2313 
   2314   helper_expr_const_range source_exprs() const {
   2315     return helper_expr_const_range(getSourceExprs().begin(),
   2316                                    getSourceExprs().end());
   2317   }
   2318   helper_expr_range source_exprs() {
   2319     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
   2320   }
   2321   helper_expr_const_range destination_exprs() const {
   2322     return helper_expr_const_range(getDestinationExprs().begin(),
   2323                                    getDestinationExprs().end());
   2324   }
   2325   helper_expr_range destination_exprs() {
   2326     return helper_expr_range(getDestinationExprs().begin(),
   2327                              getDestinationExprs().end());
   2328   }
   2329   helper_expr_const_range assignment_ops() const {
   2330     return helper_expr_const_range(getAssignmentOps().begin(),
   2331                                    getAssignmentOps().end());
   2332   }
   2333   helper_expr_range assignment_ops() {
   2334     return helper_expr_range(getAssignmentOps().begin(),
   2335                              getAssignmentOps().end());
   2336   }
   2337 
   2338   child_range children() {
   2339     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2340                        reinterpret_cast<Stmt **>(varlist_end()));
   2341   }
   2342 
   2343   static bool classof(const OMPClause *T) {
   2344     return T->getClauseKind() == OMPC_copyprivate;
   2345   }
   2346 };
   2347 
   2348 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
   2349 /// directive.
   2350 /// This clause does not exist by itself, it can be only as a part of 'omp
   2351 /// flush' directive. This clause is introduced to keep the original structure
   2352 /// of \a OMPExecutableDirective class and its derivatives and to use the
   2353 /// existing infrastructure of clauses with the list of variables.
   2354 ///
   2355 /// \code
   2356 /// #pragma omp flush(a,b)
   2357 /// \endcode
   2358 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
   2359 /// with the variables 'a' and 'b'.
   2360 ///
   2361 class OMPFlushClause : public OMPVarListClause<OMPFlushClause> {
   2362   /// \brief Build clause with number of variables \a N.
   2363   ///
   2364   /// \param StartLoc Starting location of the clause.
   2365   /// \param LParenLoc Location of '('.
   2366   /// \param EndLoc Ending location of the clause.
   2367   /// \param N Number of the variables in the clause.
   2368   ///
   2369   OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2370                  SourceLocation EndLoc, unsigned N)
   2371       : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
   2372                                          EndLoc, N) {}
   2373 
   2374   /// \brief Build an empty clause.
   2375   ///
   2376   /// \param N Number of variables.
   2377   ///
   2378   explicit OMPFlushClause(unsigned N)
   2379       : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
   2380                                          SourceLocation(), SourceLocation(),
   2381                                          N) {}
   2382 
   2383 public:
   2384   /// \brief Creates clause with a list of variables \a VL.
   2385   ///
   2386   /// \param C AST context.
   2387   /// \param StartLoc Starting location of the clause.
   2388   /// \param LParenLoc Location of '('.
   2389   /// \param EndLoc Ending location of the clause.
   2390   /// \param VL List of references to the variables.
   2391   ///
   2392   static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
   2393                                 SourceLocation LParenLoc, SourceLocation EndLoc,
   2394                                 ArrayRef<Expr *> VL);
   2395   /// \brief Creates an empty clause with \a N variables.
   2396   ///
   2397   /// \param C AST context.
   2398   /// \param N The number of variables.
   2399   ///
   2400   static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
   2401 
   2402   child_range children() {
   2403     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2404                        reinterpret_cast<Stmt **>(varlist_end()));
   2405   }
   2406 
   2407   static bool classof(const OMPClause *T) {
   2408     return T->getClauseKind() == OMPC_flush;
   2409   }
   2410 };
   2411 
   2412 /// \brief This represents implicit clause 'depend' for the '#pragma omp task'
   2413 /// directive.
   2414 ///
   2415 /// \code
   2416 /// #pragma omp task depend(in:a,b)
   2417 /// \endcode
   2418 /// In this example directive '#pragma omp task' with clause 'depend' with the
   2419 /// variables 'a' and 'b' with dependency 'in'.
   2420 ///
   2421 class OMPDependClause : public OMPVarListClause<OMPDependClause> {
   2422   friend class OMPClauseReader;
   2423   /// \brief Dependency type (one of in, out, inout).
   2424   OpenMPDependClauseKind DepKind;
   2425   /// \brief Dependency type location.
   2426   SourceLocation DepLoc;
   2427   /// \brief Colon location.
   2428   SourceLocation ColonLoc;
   2429   /// \brief Build clause with number of variables \a N.
   2430   ///
   2431   /// \param StartLoc Starting location of the clause.
   2432   /// \param LParenLoc Location of '('.
   2433   /// \param EndLoc Ending location of the clause.
   2434   /// \param N Number of the variables in the clause.
   2435   ///
   2436   OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
   2437                   SourceLocation EndLoc, unsigned N)
   2438       : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
   2439                                           EndLoc, N),
   2440         DepKind(OMPC_DEPEND_unknown) {}
   2441 
   2442   /// \brief Build an empty clause.
   2443   ///
   2444   /// \param N Number of variables.
   2445   ///
   2446   explicit OMPDependClause(unsigned N)
   2447       : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
   2448                                           SourceLocation(), SourceLocation(),
   2449                                           N),
   2450         DepKind(OMPC_DEPEND_unknown) {}
   2451   /// \brief Set dependency kind.
   2452   void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
   2453 
   2454   /// \brief Set dependency kind and its location.
   2455   void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
   2456 
   2457   /// \brief Set colon location.
   2458   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   2459 
   2460 public:
   2461   /// \brief Creates clause with a list of variables \a VL.
   2462   ///
   2463   /// \param C AST context.
   2464   /// \param StartLoc Starting location of the clause.
   2465   /// \param LParenLoc Location of '('.
   2466   /// \param EndLoc Ending location of the clause.
   2467   /// \param DepKind Dependency type.
   2468   /// \param DepLoc Location of the dependency type.
   2469   /// \param ColonLoc Colon location.
   2470   /// \param VL List of references to the variables.
   2471   ///
   2472   static OMPDependClause *
   2473   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
   2474          SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
   2475          SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL);
   2476   /// \brief Creates an empty clause with \a N variables.
   2477   ///
   2478   /// \param C AST context.
   2479   /// \param N The number of variables.
   2480   ///
   2481   static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N);
   2482 
   2483   /// \brief Get dependency type.
   2484   OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
   2485   /// \brief Get dependency type location.
   2486   SourceLocation getDependencyLoc() const { return DepLoc; }
   2487   /// \brief Get colon location.
   2488   SourceLocation getColonLoc() const { return ColonLoc; }
   2489 
   2490   child_range children() {
   2491     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
   2492                        reinterpret_cast<Stmt **>(varlist_end()));
   2493   }
   2494 
   2495   static bool classof(const OMPClause *T) {
   2496     return T->getClauseKind() == OMPC_depend;
   2497   }
   2498 };
   2499 
   2500 /// \brief This represents 'device' clause in the '#pragma omp ...'
   2501 /// directive.
   2502 ///
   2503 /// \code
   2504 /// #pragma omp target device(a)
   2505 /// \endcode
   2506 /// In this example directive '#pragma omp target' has clause 'device'
   2507 /// with single expression 'a'.
   2508 ///
   2509 class OMPDeviceClause : public OMPClause {
   2510   friend class OMPClauseReader;
   2511   /// \brief Location of '('.
   2512   SourceLocation LParenLoc;
   2513   /// \brief Device number.
   2514   Stmt *Device;
   2515   /// \brief Set the device number.
   2516   ///
   2517   /// \param E Device number.
   2518   ///
   2519   void setDevice(Expr *E) { Device = E; }
   2520 
   2521 public:
   2522   /// \brief Build 'device' clause.
   2523   ///
   2524   /// \param E Expression associated with this clause.
   2525   /// \param StartLoc Starting location of the clause.
   2526   /// \param LParenLoc Location of '('.
   2527   /// \param EndLoc Ending location of the clause.
   2528   ///
   2529   OMPDeviceClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
   2530                   SourceLocation EndLoc)
   2531       : OMPClause(OMPC_device, StartLoc, EndLoc), LParenLoc(LParenLoc),
   2532         Device(E) {}
   2533 
   2534   /// \brief Build an empty clause.
   2535   ///
   2536   OMPDeviceClause()
   2537       : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
   2538         LParenLoc(SourceLocation()), Device(nullptr) {}
   2539   /// \brief Sets the location of '('.
   2540   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   2541   /// \brief Returns the location of '('.
   2542   SourceLocation getLParenLoc() const { return LParenLoc; }
   2543   /// \brief Return device number.
   2544   Expr *getDevice() { return cast<Expr>(Device); }
   2545   /// \brief Return device number.
   2546   Expr *getDevice() const { return cast<Expr>(Device); }
   2547 
   2548   static bool classof(const OMPClause *T) {
   2549     return T->getClauseKind() == OMPC_device;
   2550   }
   2551 
   2552   child_range children() { return child_range(&Device, &Device + 1); }
   2553 };
   2554 
   2555 /// \brief This represents 'threads' clause in the '#pragma omp ...' directive.
   2556 ///
   2557 /// \code
   2558 /// #pragma omp ordered threads
   2559 /// \endcode
   2560 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
   2561 ///
   2562 class OMPThreadsClause : public OMPClause {
   2563 public:
   2564   /// \brief Build 'threads' clause.
   2565   ///
   2566   /// \param StartLoc Starting location of the clause.
   2567   /// \param EndLoc Ending location of the clause.
   2568   ///
   2569   OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2570       : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
   2571 
   2572   /// \brief Build an empty clause.
   2573   ///
   2574   OMPThreadsClause()
   2575       : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
   2576 
   2577   static bool classof(const OMPClause *T) {
   2578     return T->getClauseKind() == OMPC_threads;
   2579   }
   2580 
   2581   child_range children() {
   2582     return child_range(child_iterator(), child_iterator());
   2583   }
   2584 };
   2585 
   2586 /// \brief This represents 'simd' clause in the '#pragma omp ...' directive.
   2587 ///
   2588 /// \code
   2589 /// #pragma omp ordered simd
   2590 /// \endcode
   2591 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
   2592 ///
   2593 class OMPSIMDClause : public OMPClause {
   2594 public:
   2595   /// \brief Build 'simd' clause.
   2596   ///
   2597   /// \param StartLoc Starting location of the clause.
   2598   /// \param EndLoc Ending location of the clause.
   2599   ///
   2600   OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2601       : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
   2602 
   2603   /// \brief Build an empty clause.
   2604   ///
   2605   OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
   2606 
   2607   static bool classof(const OMPClause *T) {
   2608     return T->getClauseKind() == OMPC_simd;
   2609   }
   2610 
   2611   child_range children() {
   2612     return child_range(child_iterator(), child_iterator());
   2613   }
   2614 };
   2615 
   2616 /// \brief This represents clause 'map' in the '#pragma omp ...'
   2617 /// directives.
   2618 ///
   2619 /// \code
   2620 /// #pragma omp target map(a,b)
   2621 /// \endcode
   2622 /// In this example directive '#pragma omp target' has clause 'map'
   2623 /// with the variables 'a' and 'b'.
   2624 ///
   2625 class OMPMapClause : public OMPVarListClause<OMPMapClause> {
   2626   friend class OMPClauseReader;
   2627 
   2628   /// \brief Map type modifier for the 'map' clause.
   2629   OpenMPMapClauseKind MapTypeModifier;
   2630   /// \brief Map type for the 'map' clause.
   2631   OpenMPMapClauseKind MapType;
   2632   /// \brief Location of the map type.
   2633   SourceLocation MapLoc;
   2634   /// \brief Colon location.
   2635   SourceLocation ColonLoc;
   2636 
   2637   /// \brief Set type modifier for the clause.
   2638   ///
   2639   /// \param T Type Modifier for the clause.
   2640   ///
   2641   void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; }
   2642 
   2643   /// \brief Set type for the clause.
   2644   ///
   2645   /// \param T Type for the clause.
   2646   ///
   2647   void setMapType(OpenMPMapClauseKind T) { MapType = T; }
   2648 
   2649   /// \brief Set type location.
   2650   ///
   2651   /// \param TLoc Type location.
   2652   ///
   2653   void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
   2654 
   2655   /// \brief Set colon location.
   2656   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
   2657 
   2658   /// \brief Build clause with number of variables \a N.
   2659   ///
   2660   /// \param MapTypeModifier Map type modifier.
   2661   /// \param MapType Map type.
   2662   /// \param MapLoc Location of the map type.
   2663   /// \param StartLoc Starting location of the clause.
   2664   /// \param EndLoc Ending location of the clause.
   2665   /// \param N Number of the variables in the clause.
   2666   ///
   2667   explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier,
   2668                         OpenMPMapClauseKind MapType, SourceLocation MapLoc,
   2669                         SourceLocation StartLoc, SourceLocation LParenLoc,
   2670                         SourceLocation EndLoc, unsigned N)
   2671     : OMPVarListClause<OMPMapClause>(OMPC_map, StartLoc, LParenLoc, EndLoc, N),
   2672       MapTypeModifier(MapTypeModifier), MapType(MapType), MapLoc(MapLoc) {}
   2673 
   2674   /// \brief Build an empty clause.
   2675   ///
   2676   /// \param N Number of variables.
   2677   ///
   2678   explicit OMPMapClause(unsigned N)
   2679       : OMPVarListClause<OMPMapClause>(OMPC_map, SourceLocation(),
   2680                                        SourceLocation(), SourceLocation(), N),
   2681         MapTypeModifier(OMPC_MAP_unknown), MapType(OMPC_MAP_unknown), MapLoc() {}
   2682 
   2683 public:
   2684   /// \brief Creates clause with a list of variables \a VL.
   2685   ///
   2686   /// \param C AST context.
   2687   /// \param StartLoc Starting location of the clause.
   2688   /// \param EndLoc Ending location of the clause.
   2689   /// \param VL List of references to the variables.
   2690   /// \param TypeModifier Map type modifier.
   2691   /// \param Type Map type.
   2692   /// \param TypeLoc Location of the map type.
   2693   ///
   2694   static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc,
   2695                               SourceLocation LParenLoc,
   2696                               SourceLocation EndLoc, ArrayRef<Expr *> VL,
   2697                               OpenMPMapClauseKind TypeModifier,
   2698                               OpenMPMapClauseKind Type, SourceLocation TypeLoc);
   2699   /// \brief Creates an empty clause with the place for \a N variables.
   2700   ///
   2701   /// \param C AST context.
   2702   /// \param N The number of variables.
   2703   ///
   2704   static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned N);
   2705 
   2706   /// \brief Fetches mapping kind for the clause.
   2707   OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
   2708 
   2709   /// \brief Fetches the map type modifier for the clause.
   2710   OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY {
   2711     return MapTypeModifier;
   2712   }
   2713 
   2714   /// \brief Fetches location of clause mapping kind.
   2715   SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
   2716 
   2717   /// \brief Get colon location.
   2718   SourceLocation getColonLoc() const { return ColonLoc; }
   2719 
   2720   static bool classof(const OMPClause *T) {
   2721     return T->getClauseKind() == OMPC_map;
   2722   }
   2723 
   2724   child_range children() {
   2725     return child_range(
   2726         reinterpret_cast<Stmt **>(varlist_begin()),
   2727         reinterpret_cast<Stmt **>(varlist_end()));
   2728   }
   2729 };
   2730 
   2731 /// \brief This represents 'num_teams' clause in the '#pragma omp ...'
   2732 /// directive.
   2733 ///
   2734 /// \code
   2735 /// #pragma omp teams num_teams(n)
   2736 /// \endcode
   2737 /// In this example directive '#pragma omp teams' has clause 'num_teams'
   2738 /// with single expression 'n'.
   2739 ///
   2740 class OMPNumTeamsClause : public OMPClause {
   2741   friend class OMPClauseReader;
   2742   /// \brief Location of '('.
   2743   SourceLocation LParenLoc;
   2744   /// \brief NumTeams number.
   2745   Stmt *NumTeams;
   2746   /// \brief Set the NumTeams number.
   2747   ///
   2748   /// \param E NumTeams number.
   2749   ///
   2750   void setNumTeams(Expr *E) { NumTeams = E; }
   2751 
   2752 public:
   2753   /// \brief Build 'num_teams' clause.
   2754   ///
   2755   /// \param E Expression associated with this clause.
   2756   /// \param StartLoc Starting location of the clause.
   2757   /// \param LParenLoc Location of '('.
   2758   /// \param EndLoc Ending location of the clause.
   2759   ///
   2760   OMPNumTeamsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
   2761                     SourceLocation EndLoc)
   2762       : OMPClause(OMPC_num_teams, StartLoc, EndLoc), LParenLoc(LParenLoc),
   2763         NumTeams(E) {}
   2764 
   2765   /// \brief Build an empty clause.
   2766   ///
   2767   OMPNumTeamsClause()
   2768       : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
   2769         LParenLoc(SourceLocation()), NumTeams(nullptr) {}
   2770   /// \brief Sets the location of '('.
   2771   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   2772   /// \brief Returns the location of '('.
   2773   SourceLocation getLParenLoc() const { return LParenLoc; }
   2774   /// \brief Return NumTeams number.
   2775   Expr *getNumTeams() { return cast<Expr>(NumTeams); }
   2776   /// \brief Return NumTeams number.
   2777   Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
   2778 
   2779   static bool classof(const OMPClause *T) {
   2780     return T->getClauseKind() == OMPC_num_teams;
   2781   }
   2782 
   2783   child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
   2784 };
   2785 
   2786 /// \brief This represents 'thread_limit' clause in the '#pragma omp ...'
   2787 /// directive.
   2788 ///
   2789 /// \code
   2790 /// #pragma omp teams thread_limit(n)
   2791 /// \endcode
   2792 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
   2793 /// with single expression 'n'.
   2794 ///
   2795 class OMPThreadLimitClause : public OMPClause {
   2796   friend class OMPClauseReader;
   2797   /// \brief Location of '('.
   2798   SourceLocation LParenLoc;
   2799   /// \brief ThreadLimit number.
   2800   Stmt *ThreadLimit;
   2801   /// \brief Set the ThreadLimit number.
   2802   ///
   2803   /// \param E ThreadLimit number.
   2804   ///
   2805   void setThreadLimit(Expr *E) { ThreadLimit = E; }
   2806 
   2807 public:
   2808   /// \brief Build 'thread_limit' clause.
   2809   ///
   2810   /// \param E Expression associated with this clause.
   2811   /// \param StartLoc Starting location of the clause.
   2812   /// \param LParenLoc Location of '('.
   2813   /// \param EndLoc Ending location of the clause.
   2814   ///
   2815   OMPThreadLimitClause(Expr *E, SourceLocation StartLoc,
   2816                        SourceLocation LParenLoc, SourceLocation EndLoc)
   2817       : OMPClause(OMPC_thread_limit, StartLoc, EndLoc), LParenLoc(LParenLoc),
   2818         ThreadLimit(E) {}
   2819 
   2820   /// \brief Build an empty clause.
   2821   ///
   2822   OMPThreadLimitClause()
   2823       : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
   2824         LParenLoc(SourceLocation()), ThreadLimit(nullptr) {}
   2825   /// \brief Sets the location of '('.
   2826   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   2827   /// \brief Returns the location of '('.
   2828   SourceLocation getLParenLoc() const { return LParenLoc; }
   2829   /// \brief Return ThreadLimit number.
   2830   Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
   2831   /// \brief Return ThreadLimit number.
   2832   Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
   2833 
   2834   static bool classof(const OMPClause *T) {
   2835     return T->getClauseKind() == OMPC_thread_limit;
   2836   }
   2837 
   2838   child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
   2839 };
   2840 
   2841 /// \brief This represents 'priority' clause in the '#pragma omp ...'
   2842 /// directive.
   2843 ///
   2844 /// \code
   2845 /// #pragma omp task priority(n)
   2846 /// \endcode
   2847 /// In this example directive '#pragma omp teams' has clause 'priority' with
   2848 /// single expression 'n'.
   2849 ///
   2850 class OMPPriorityClause : public OMPClause {
   2851   friend class OMPClauseReader;
   2852   /// \brief Location of '('.
   2853   SourceLocation LParenLoc;
   2854   /// \brief Priority number.
   2855   Stmt *Priority;
   2856   /// \brief Set the Priority number.
   2857   ///
   2858   /// \param E Priority number.
   2859   ///
   2860   void setPriority(Expr *E) { Priority = E; }
   2861 
   2862 public:
   2863   /// \brief Build 'priority' clause.
   2864   ///
   2865   /// \param E Expression associated with this clause.
   2866   /// \param StartLoc Starting location of the clause.
   2867   /// \param LParenLoc Location of '('.
   2868   /// \param EndLoc Ending location of the clause.
   2869   ///
   2870   OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
   2871                     SourceLocation EndLoc)
   2872       : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
   2873         Priority(E) {}
   2874 
   2875   /// \brief Build an empty clause.
   2876   ///
   2877   OMPPriorityClause()
   2878       : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()),
   2879         LParenLoc(SourceLocation()), Priority(nullptr) {}
   2880   /// \brief Sets the location of '('.
   2881   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   2882   /// \brief Returns the location of '('.
   2883   SourceLocation getLParenLoc() const { return LParenLoc; }
   2884   /// \brief Return Priority number.
   2885   Expr *getPriority() { return cast<Expr>(Priority); }
   2886   /// \brief Return Priority number.
   2887   Expr *getPriority() const { return cast<Expr>(Priority); }
   2888 
   2889   static bool classof(const OMPClause *T) {
   2890     return T->getClauseKind() == OMPC_priority;
   2891   }
   2892 
   2893   child_range children() { return child_range(&Priority, &Priority + 1); }
   2894 };
   2895 
   2896 /// \brief This represents 'grainsize' clause in the '#pragma omp ...'
   2897 /// directive.
   2898 ///
   2899 /// \code
   2900 /// #pragma omp taskloop grainsize(4)
   2901 /// \endcode
   2902 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
   2903 /// with single expression '4'.
   2904 ///
   2905 class OMPGrainsizeClause : public OMPClause {
   2906   friend class OMPClauseReader;
   2907   /// \brief Location of '('.
   2908   SourceLocation LParenLoc;
   2909   /// \brief Safe iteration space distance.
   2910   Stmt *Grainsize;
   2911 
   2912   /// \brief Set safelen.
   2913   void setGrainsize(Expr *Size) { Grainsize = Size; }
   2914 
   2915 public:
   2916   /// \brief Build 'grainsize' clause.
   2917   ///
   2918   /// \param Size Expression associated with this clause.
   2919   /// \param StartLoc Starting location of the clause.
   2920   /// \param EndLoc Ending location of the clause.
   2921   ///
   2922   OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
   2923                      SourceLocation LParenLoc, SourceLocation EndLoc)
   2924       : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
   2925         Grainsize(Size) {}
   2926 
   2927   /// \brief Build an empty clause.
   2928   ///
   2929   explicit OMPGrainsizeClause()
   2930       : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()),
   2931         LParenLoc(SourceLocation()), Grainsize(nullptr) {}
   2932 
   2933   /// \brief Sets the location of '('.
   2934   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   2935   /// \brief Returns the location of '('.
   2936   SourceLocation getLParenLoc() const { return LParenLoc; }
   2937 
   2938   /// \brief Return safe iteration space distance.
   2939   Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
   2940 
   2941   static bool classof(const OMPClause *T) {
   2942     return T->getClauseKind() == OMPC_grainsize;
   2943   }
   2944 
   2945   child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
   2946 };
   2947 
   2948 /// \brief This represents 'nogroup' clause in the '#pragma omp ...' directive.
   2949 ///
   2950 /// \code
   2951 /// #pragma omp taskloop nogroup
   2952 /// \endcode
   2953 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
   2954 ///
   2955 class OMPNogroupClause : public OMPClause {
   2956 public:
   2957   /// \brief Build 'nogroup' clause.
   2958   ///
   2959   /// \param StartLoc Starting location of the clause.
   2960   /// \param EndLoc Ending location of the clause.
   2961   ///
   2962   OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
   2963       : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
   2964 
   2965   /// \brief Build an empty clause.
   2966   ///
   2967   OMPNogroupClause()
   2968       : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
   2969 
   2970   static bool classof(const OMPClause *T) {
   2971     return T->getClauseKind() == OMPC_nogroup;
   2972   }
   2973 
   2974   child_range children() {
   2975     return child_range(child_iterator(), child_iterator());
   2976   }
   2977 };
   2978 
   2979 /// \brief This represents 'num_tasks' clause in the '#pragma omp ...'
   2980 /// directive.
   2981 ///
   2982 /// \code
   2983 /// #pragma omp taskloop num_tasks(4)
   2984 /// \endcode
   2985 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
   2986 /// with single expression '4'.
   2987 ///
   2988 class OMPNumTasksClause : public OMPClause {
   2989   friend class OMPClauseReader;
   2990   /// \brief Location of '('.
   2991   SourceLocation LParenLoc;
   2992   /// \brief Safe iteration space distance.
   2993   Stmt *NumTasks;
   2994 
   2995   /// \brief Set safelen.
   2996   void setNumTasks(Expr *Size) { NumTasks = Size; }
   2997 
   2998 public:
   2999   /// \brief Build 'num_tasks' clause.
   3000   ///
   3001   /// \param Size Expression associated with this clause.
   3002   /// \param StartLoc Starting location of the clause.
   3003   /// \param EndLoc Ending location of the clause.
   3004   ///
   3005   OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
   3006                     SourceLocation LParenLoc, SourceLocation EndLoc)
   3007       : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
   3008         NumTasks(Size) {}
   3009 
   3010   /// \brief Build an empty clause.
   3011   ///
   3012   explicit OMPNumTasksClause()
   3013       : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()),
   3014         LParenLoc(SourceLocation()), NumTasks(nullptr) {}
   3015 
   3016   /// \brief Sets the location of '('.
   3017   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   3018   /// \brief Returns the location of '('.
   3019   SourceLocation getLParenLoc() const { return LParenLoc; }
   3020 
   3021   /// \brief Return safe iteration space distance.
   3022   Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
   3023 
   3024   static bool classof(const OMPClause *T) {
   3025     return T->getClauseKind() == OMPC_num_tasks;
   3026   }
   3027 
   3028   child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
   3029 };
   3030 
   3031 /// \brief This represents 'hint' clause in the '#pragma omp ...' directive.
   3032 ///
   3033 /// \code
   3034 /// #pragma omp critical (name) hint(6)
   3035 /// \endcode
   3036 /// In this example directive '#pragma omp critical' has name 'name' and clause
   3037 /// 'hint' with argument '6'.
   3038 ///
   3039 class OMPHintClause : public OMPClause {
   3040   friend class OMPClauseReader;
   3041   /// \brief Location of '('.
   3042   SourceLocation LParenLoc;
   3043   /// \brief Hint expression of the 'hint' clause.
   3044   Stmt *Hint;
   3045 
   3046   /// \brief Set hint expression.
   3047   ///
   3048   void setHint(Expr *H) { Hint = H; }
   3049 
   3050 public:
   3051   /// \brief Build 'hint' clause with expression \a Hint.
   3052   ///
   3053   /// \param Hint Hint expression.
   3054   /// \param StartLoc Starting location of the clause.
   3055   /// \param LParenLoc Location of '('.
   3056   /// \param EndLoc Ending location of the clause.
   3057   ///
   3058   OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
   3059                 SourceLocation EndLoc)
   3060       : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
   3061         Hint(Hint) {}
   3062 
   3063   /// \brief Build an empty clause.
   3064   ///
   3065   OMPHintClause()
   3066       : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()),
   3067         LParenLoc(SourceLocation()), Hint(nullptr) {}
   3068 
   3069   /// \brief Sets the location of '('.
   3070   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
   3071   /// \brief Returns the location of '('.
   3072   SourceLocation getLParenLoc() const { return LParenLoc; }
   3073 
   3074   /// \brief Returns number of threads.
   3075   Expr *getHint() const { return cast_or_null<Expr>(Hint); }
   3076 
   3077   static bool classof(const OMPClause *T) {
   3078     return T->getClauseKind() == OMPC_hint;
   3079   }
   3080 
   3081   child_range children() { return child_range(&Hint, &Hint + 1); }
   3082 };
   3083 
   3084 } // end namespace clang
   3085 
   3086 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H
   3087