1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// This file defines OpenMP AST classes for clauses.
11 /// There are clauses for executable directives, clauses for declarative
12 /// directives and clauses which can be used in both kinds of directives.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
18 
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/DeclarationName.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/NestedNameSpecifier.h"
23 #include "clang/AST/Stmt.h"
24 #include "clang/AST/StmtIterator.h"
25 #include "clang/Basic/LLVM.h"
26 #include "clang/Basic/OpenMPKinds.h"
27 #include "clang/Basic/SourceLocation.h"
28 #include "llvm/ADT/ArrayRef.h"
29 #include "llvm/ADT/MapVector.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/ADT/iterator.h"
32 #include "llvm/ADT/iterator_range.h"
33 #include "llvm/Frontend/OpenMP/OMPConstants.h"
34 #include "llvm/Support/Casting.h"
35 #include "llvm/Support/Compiler.h"
36 #include "llvm/Support/TrailingObjects.h"
37 #include <cassert>
38 #include <cstddef>
39 #include <iterator>
40 #include <utility>
41 
42 namespace clang {
43 
44 class ASTContext;
45 
46 //===----------------------------------------------------------------------===//
47 // AST classes for clauses.
48 //===----------------------------------------------------------------------===//
49 
50 /// This is a basic class for representing single OpenMP clause.
51 class OMPClause {
52   /// Starting location of the clause (the clause keyword).
53   SourceLocation StartLoc;
54 
55   /// Ending location of the clause.
56   SourceLocation EndLoc;
57 
58   /// Kind of the clause.
59   OpenMPClauseKind Kind;
60 
61 protected:
OMPClause(OpenMPClauseKind K,SourceLocation StartLoc,SourceLocation EndLoc)62   OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
63       : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
64 
65 public:
66   /// Returns the starting location of the clause.
getBeginLoc()67   SourceLocation getBeginLoc() const { return StartLoc; }
68 
69   /// Returns the ending location of the clause.
getEndLoc()70   SourceLocation getEndLoc() const { return EndLoc; }
71 
72   /// Sets the starting location of the clause.
setLocStart(SourceLocation Loc)73   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
74 
75   /// Sets the ending location of the clause.
setLocEnd(SourceLocation Loc)76   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
77 
78   /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
getClauseKind()79   OpenMPClauseKind getClauseKind() const { return Kind; }
80 
isImplicit()81   bool isImplicit() const { return StartLoc.isInvalid(); }
82 
83   using child_iterator = StmtIterator;
84   using const_child_iterator = ConstStmtIterator;
85   using child_range = llvm::iterator_range<child_iterator>;
86   using const_child_range = llvm::iterator_range<const_child_iterator>;
87 
88   child_range children();
children()89   const_child_range children() const {
90     auto Children = const_cast<OMPClause *>(this)->children();
91     return const_child_range(Children.begin(), Children.end());
92   }
93 
94   /// Get the iterator range for the expressions used in the clauses. Used
95   /// expressions include only the children that must be evaluated at the
96   /// runtime before entering the construct.
97   child_range used_children();
used_children()98   const_child_range used_children() const {
99     auto Children = const_cast<OMPClause *>(this)->children();
100     return const_child_range(Children.begin(), Children.end());
101   }
102 
classof(const OMPClause *)103   static bool classof(const OMPClause *) { return true; }
104 };
105 
106 /// Class that handles pre-initialization statement for some clauses, like
107 /// 'shedule', 'firstprivate' etc.
108 class OMPClauseWithPreInit {
109   friend class OMPClauseReader;
110 
111   /// Pre-initialization statement for the clause.
112   Stmt *PreInit = nullptr;
113 
114   /// Region that captures the associated stmt.
115   OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
116 
117 protected:
OMPClauseWithPreInit(const OMPClause * This)118   OMPClauseWithPreInit(const OMPClause *This) {
119     assert(get(This) && "get is not tuned for pre-init.");
120   }
121 
122   /// Set pre-initialization statement for the clause.
123   void
124   setPreInitStmt(Stmt *S,
125                  OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
126     PreInit = S;
127     CaptureRegion = ThisRegion;
128   }
129 
130 public:
131   /// Get pre-initialization statement for the clause.
getPreInitStmt()132   const Stmt *getPreInitStmt() const { return PreInit; }
133 
134   /// Get pre-initialization statement for the clause.
getPreInitStmt()135   Stmt *getPreInitStmt() { return PreInit; }
136 
137   /// Get capture region for the stmt in the clause.
getCaptureRegion()138   OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
139 
140   static OMPClauseWithPreInit *get(OMPClause *C);
141   static const OMPClauseWithPreInit *get(const OMPClause *C);
142 };
143 
144 /// Class that handles post-update expression for some clauses, like
145 /// 'lastprivate', 'reduction' etc.
146 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
147   friend class OMPClauseReader;
148 
149   /// Post-update expression for the clause.
150   Expr *PostUpdate = nullptr;
151 
152 protected:
OMPClauseWithPostUpdate(const OMPClause * This)153   OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
154     assert(get(This) && "get is not tuned for post-update.");
155   }
156 
157   /// Set pre-initialization statement for the clause.
setPostUpdateExpr(Expr * S)158   void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
159 
160 public:
161   /// Get post-update expression for the clause.
getPostUpdateExpr()162   const Expr *getPostUpdateExpr() const { return PostUpdate; }
163 
164   /// Get post-update expression for the clause.
getPostUpdateExpr()165   Expr *getPostUpdateExpr() { return PostUpdate; }
166 
167   static OMPClauseWithPostUpdate *get(OMPClause *C);
168   static const OMPClauseWithPostUpdate *get(const OMPClause *C);
169 };
170 
171 /// This structure contains most locations needed for by an OMPVarListClause.
172 struct OMPVarListLocTy {
173   /// Starting location of the clause (the clause keyword).
174   SourceLocation StartLoc;
175   /// Location of '('.
176   SourceLocation LParenLoc;
177   /// Ending location of the clause.
178   SourceLocation EndLoc;
179   OMPVarListLocTy() = default;
OMPVarListLocTyOMPVarListLocTy180   OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc,
181                   SourceLocation EndLoc)
182       : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {}
183 };
184 
185 /// This represents clauses with the list of variables like 'private',
186 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
187 /// '#pragma omp ...' directives.
188 template <class T> class OMPVarListClause : public OMPClause {
189   friend class OMPClauseReader;
190 
191   /// Location of '('.
192   SourceLocation LParenLoc;
193 
194   /// Number of variables in the list.
195   unsigned NumVars;
196 
197 protected:
198   /// Build a clause with \a N variables
199   ///
200   /// \param K Kind of the clause.
201   /// \param StartLoc Starting location of the clause (the clause keyword).
202   /// \param LParenLoc Location of '('.
203   /// \param EndLoc Ending location of the clause.
204   /// \param N Number of the variables in the clause.
OMPVarListClause(OpenMPClauseKind K,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)205   OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
206                    SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
207       : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
208 
209   /// Fetches list of variables associated with this clause.
getVarRefs()210   MutableArrayRef<Expr *> getVarRefs() {
211     return MutableArrayRef<Expr *>(
212         static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
213   }
214 
215   /// Sets the list of variables for this clause.
setVarRefs(ArrayRef<Expr * > VL)216   void setVarRefs(ArrayRef<Expr *> VL) {
217     assert(VL.size() == NumVars &&
218            "Number of variables is not the same as the preallocated buffer");
219     std::copy(VL.begin(), VL.end(),
220               static_cast<T *>(this)->template getTrailingObjects<Expr *>());
221   }
222 
223 public:
224   using varlist_iterator = MutableArrayRef<Expr *>::iterator;
225   using varlist_const_iterator = ArrayRef<const Expr *>::iterator;
226   using varlist_range = llvm::iterator_range<varlist_iterator>;
227   using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
228 
varlist_size()229   unsigned varlist_size() const { return NumVars; }
varlist_empty()230   bool varlist_empty() const { return NumVars == 0; }
231 
varlists()232   varlist_range varlists() {
233     return varlist_range(varlist_begin(), varlist_end());
234   }
varlists()235   varlist_const_range varlists() const {
236     return varlist_const_range(varlist_begin(), varlist_end());
237   }
238 
varlist_begin()239   varlist_iterator varlist_begin() { return getVarRefs().begin(); }
varlist_end()240   varlist_iterator varlist_end() { return getVarRefs().end(); }
varlist_begin()241   varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
varlist_end()242   varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
243 
244   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)245   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
246 
247   /// Returns the location of '('.
getLParenLoc()248   SourceLocation getLParenLoc() const { return LParenLoc; }
249 
250   /// Fetches list of all variables in the clause.
getVarRefs()251   ArrayRef<const Expr *> getVarRefs() const {
252     return llvm::makeArrayRef(
253         static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
254         NumVars);
255   }
256 };
257 
258 /// This represents 'allocator' clause in the '#pragma omp ...'
259 /// directive.
260 ///
261 /// \code
262 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
263 /// \endcode
264 /// In this example directive '#pragma omp allocate' has simple 'allocator'
265 /// clause with the allocator 'omp_default_mem_alloc'.
266 class OMPAllocatorClause : public OMPClause {
267   friend class OMPClauseReader;
268 
269   /// Location of '('.
270   SourceLocation LParenLoc;
271 
272   /// Expression with the allocator.
273   Stmt *Allocator = nullptr;
274 
275   /// Set allocator.
setAllocator(Expr * A)276   void setAllocator(Expr *A) { Allocator = A; }
277 
278 public:
279   /// Build 'allocator' clause with the given allocator.
280   ///
281   /// \param A Allocator.
282   /// \param StartLoc Starting location of the clause.
283   /// \param LParenLoc Location of '('.
284   /// \param EndLoc Ending location of the clause.
OMPAllocatorClause(Expr * A,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)285   OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
286                      SourceLocation EndLoc)
287       : OMPClause(OMPC_allocator, StartLoc, EndLoc), LParenLoc(LParenLoc),
288         Allocator(A) {}
289 
290   /// Build an empty clause.
OMPAllocatorClause()291   OMPAllocatorClause()
292       : OMPClause(OMPC_allocator, SourceLocation(), SourceLocation()) {}
293 
294   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)295   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
296 
297   /// Returns the location of '('.
getLParenLoc()298   SourceLocation getLParenLoc() const { return LParenLoc; }
299 
300   /// Returns allocator.
getAllocator()301   Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); }
302 
children()303   child_range children() { return child_range(&Allocator, &Allocator + 1); }
304 
children()305   const_child_range children() const {
306     return const_child_range(&Allocator, &Allocator + 1);
307   }
308 
used_children()309   child_range used_children() {
310     return child_range(child_iterator(), child_iterator());
311   }
used_children()312   const_child_range used_children() const {
313     return const_child_range(const_child_iterator(), const_child_iterator());
314   }
315 
classof(const OMPClause * T)316   static bool classof(const OMPClause *T) {
317     return T->getClauseKind() == OMPC_allocator;
318   }
319 };
320 
321 /// This represents clause 'allocate' in the '#pragma omp ...' directives.
322 ///
323 /// \code
324 /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
325 /// \endcode
326 /// In this example directive '#pragma omp parallel' has clause 'private'
327 /// and clause 'allocate' for the variable 'a'.
328 class OMPAllocateClause final
329     : public OMPVarListClause<OMPAllocateClause>,
330       private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
331   friend class OMPClauseReader;
332   friend OMPVarListClause;
333   friend TrailingObjects;
334 
335   /// Allocator specified in the clause, or 'nullptr' if the default one is
336   /// used.
337   Expr *Allocator = nullptr;
338   /// Position of the ':' delimiter in the clause;
339   SourceLocation ColonLoc;
340 
341   /// Build clause with number of variables \a N.
342   ///
343   /// \param StartLoc Starting location of the clause.
344   /// \param LParenLoc Location of '('.
345   /// \param Allocator Allocator expression.
346   /// \param ColonLoc Location of ':' delimiter.
347   /// \param EndLoc Ending location of the clause.
348   /// \param N Number of the variables in the clause.
OMPAllocateClause(SourceLocation StartLoc,SourceLocation LParenLoc,Expr * Allocator,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned N)349   OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
350                     Expr *Allocator, SourceLocation ColonLoc,
351                     SourceLocation EndLoc, unsigned N)
352       : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, StartLoc, LParenLoc,
353                                             EndLoc, N),
354         Allocator(Allocator), ColonLoc(ColonLoc) {}
355 
356   /// Build an empty clause.
357   ///
358   /// \param N Number of variables.
OMPAllocateClause(unsigned N)359   explicit OMPAllocateClause(unsigned N)
360       : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, SourceLocation(),
361                                             SourceLocation(), SourceLocation(),
362                                             N) {}
363 
364   /// Sets location of ':' symbol in clause.
setColonLoc(SourceLocation CL)365   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
366 
setAllocator(Expr * A)367   void setAllocator(Expr *A) { Allocator = A; }
368 
369 public:
370   /// Creates clause with a list of variables \a VL.
371   ///
372   /// \param C AST context.
373   /// \param StartLoc Starting location of the clause.
374   /// \param LParenLoc Location of '('.
375   /// \param Allocator Allocator expression.
376   /// \param ColonLoc Location of ':' delimiter.
377   /// \param EndLoc Ending location of the clause.
378   /// \param VL List of references to the variables.
379   static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
380                                    SourceLocation LParenLoc, Expr *Allocator,
381                                    SourceLocation ColonLoc,
382                                    SourceLocation EndLoc, ArrayRef<Expr *> VL);
383 
384   /// Returns the allocator expression or nullptr, if no allocator is specified.
getAllocator()385   Expr *getAllocator() const { return Allocator; }
386 
387   /// Returns the location of the ':' delimiter.
getColonLoc()388   SourceLocation getColonLoc() const { return ColonLoc; }
389 
390   /// Creates an empty clause with the place for \a N variables.
391   ///
392   /// \param C AST context.
393   /// \param N The number of variables.
394   static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
395 
children()396   child_range children() {
397     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
398                        reinterpret_cast<Stmt **>(varlist_end()));
399   }
400 
children()401   const_child_range children() const {
402     auto Children = const_cast<OMPAllocateClause *>(this)->children();
403     return const_child_range(Children.begin(), Children.end());
404   }
405 
used_children()406   child_range used_children() {
407     return child_range(child_iterator(), child_iterator());
408   }
used_children()409   const_child_range used_children() const {
410     return const_child_range(const_child_iterator(), const_child_iterator());
411   }
412 
classof(const OMPClause * T)413   static bool classof(const OMPClause *T) {
414     return T->getClauseKind() == OMPC_allocate;
415   }
416 };
417 
418 /// This represents 'if' clause in the '#pragma omp ...' directive.
419 ///
420 /// \code
421 /// #pragma omp parallel if(parallel:a > 5)
422 /// \endcode
423 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
424 /// condition 'a > 5' and directive name modifier 'parallel'.
425 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
426   friend class OMPClauseReader;
427 
428   /// Location of '('.
429   SourceLocation LParenLoc;
430 
431   /// Condition of the 'if' clause.
432   Stmt *Condition = nullptr;
433 
434   /// Location of ':' (if any).
435   SourceLocation ColonLoc;
436 
437   /// Directive name modifier for the clause.
438   OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
439 
440   /// Name modifier location.
441   SourceLocation NameModifierLoc;
442 
443   /// Set condition.
setCondition(Expr * Cond)444   void setCondition(Expr *Cond) { Condition = Cond; }
445 
446   /// Set directive name modifier for the clause.
setNameModifier(OpenMPDirectiveKind NM)447   void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
448 
449   /// Set location of directive name modifier for the clause.
setNameModifierLoc(SourceLocation Loc)450   void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
451 
452   /// Set location of ':'.
setColonLoc(SourceLocation Loc)453   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
454 
455 public:
456   /// Build 'if' clause with condition \a Cond.
457   ///
458   /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
459   /// \param Cond Condition of the clause.
460   /// \param HelperCond Helper condition for the clause.
461   /// \param CaptureRegion Innermost OpenMP region where expressions in this
462   /// clause must be captured.
463   /// \param StartLoc Starting location of the clause.
464   /// \param LParenLoc Location of '('.
465   /// \param NameModifierLoc Location of directive name modifier.
466   /// \param ColonLoc [OpenMP 4.1] Location of ':'.
467   /// \param EndLoc Ending location of the clause.
OMPIfClause(OpenMPDirectiveKind NameModifier,Expr * Cond,Stmt * HelperCond,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation NameModifierLoc,SourceLocation ColonLoc,SourceLocation EndLoc)468   OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
469               OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
470               SourceLocation LParenLoc, SourceLocation NameModifierLoc,
471               SourceLocation ColonLoc, SourceLocation EndLoc)
472       : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this),
473         LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
474         NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) {
475     setPreInitStmt(HelperCond, CaptureRegion);
476   }
477 
478   /// Build an empty clause.
OMPIfClause()479   OMPIfClause()
480       : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
481         OMPClauseWithPreInit(this) {}
482 
483   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)484   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
485 
486   /// Returns the location of '('.
getLParenLoc()487   SourceLocation getLParenLoc() const { return LParenLoc; }
488 
489   /// Return the location of ':'.
getColonLoc()490   SourceLocation getColonLoc() const { return ColonLoc; }
491 
492   /// Returns condition.
getCondition()493   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
494 
495   /// Return directive name modifier associated with the clause.
getNameModifier()496   OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
497 
498   /// Return the location of directive name modifier.
getNameModifierLoc()499   SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
500 
children()501   child_range children() { return child_range(&Condition, &Condition + 1); }
502 
children()503   const_child_range children() const {
504     return const_child_range(&Condition, &Condition + 1);
505   }
506 
507   child_range used_children();
used_children()508   const_child_range used_children() const {
509     auto Children = const_cast<OMPIfClause *>(this)->used_children();
510     return const_child_range(Children.begin(), Children.end());
511   }
512 
classof(const OMPClause * T)513   static bool classof(const OMPClause *T) {
514     return T->getClauseKind() == OMPC_if;
515   }
516 };
517 
518 /// This represents 'final' clause in the '#pragma omp ...' directive.
519 ///
520 /// \code
521 /// #pragma omp task final(a > 5)
522 /// \endcode
523 /// In this example directive '#pragma omp task' has simple 'final'
524 /// clause with condition 'a > 5'.
525 class OMPFinalClause : public OMPClause, public OMPClauseWithPreInit {
526   friend class OMPClauseReader;
527 
528   /// Location of '('.
529   SourceLocation LParenLoc;
530 
531   /// Condition of the 'if' clause.
532   Stmt *Condition = nullptr;
533 
534   /// Set condition.
setCondition(Expr * Cond)535   void setCondition(Expr *Cond) { Condition = Cond; }
536 
537 public:
538   /// Build 'final' clause with condition \a Cond.
539   ///
540   /// \param Cond Condition of the clause.
541   /// \param HelperCond Helper condition for the construct.
542   /// \param CaptureRegion Innermost OpenMP region where expressions in this
543   /// clause must be captured.
544   /// \param StartLoc Starting location of the clause.
545   /// \param LParenLoc Location of '('.
546   /// \param EndLoc Ending location of the clause.
OMPFinalClause(Expr * Cond,Stmt * HelperCond,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)547   OMPFinalClause(Expr *Cond, Stmt *HelperCond,
548                  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
549                  SourceLocation LParenLoc, SourceLocation EndLoc)
550       : OMPClause(OMPC_final, StartLoc, EndLoc), OMPClauseWithPreInit(this),
551         LParenLoc(LParenLoc), Condition(Cond) {
552     setPreInitStmt(HelperCond, CaptureRegion);
553   }
554 
555   /// Build an empty clause.
OMPFinalClause()556   OMPFinalClause()
557       : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
558         OMPClauseWithPreInit(this) {}
559 
560   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)561   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
562 
563   /// Returns the location of '('.
getLParenLoc()564   SourceLocation getLParenLoc() const { return LParenLoc; }
565 
566   /// Returns condition.
getCondition()567   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
568 
children()569   child_range children() { return child_range(&Condition, &Condition + 1); }
570 
children()571   const_child_range children() const {
572     return const_child_range(&Condition, &Condition + 1);
573   }
574 
575   child_range used_children();
used_children()576   const_child_range used_children() const {
577     auto Children = const_cast<OMPFinalClause *>(this)->used_children();
578     return const_child_range(Children.begin(), Children.end());
579   }
580 
classof(const OMPClause * T)581   static bool classof(const OMPClause *T) {
582     return T->getClauseKind() == OMPC_final;
583   }
584 };
585 
586 /// This represents 'num_threads' clause in the '#pragma omp ...'
587 /// directive.
588 ///
589 /// \code
590 /// #pragma omp parallel num_threads(6)
591 /// \endcode
592 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
593 /// clause with number of threads '6'.
594 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
595   friend class OMPClauseReader;
596 
597   /// Location of '('.
598   SourceLocation LParenLoc;
599 
600   /// Condition of the 'num_threads' clause.
601   Stmt *NumThreads = nullptr;
602 
603   /// Set condition.
setNumThreads(Expr * NThreads)604   void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
605 
606 public:
607   /// Build 'num_threads' clause with condition \a NumThreads.
608   ///
609   /// \param NumThreads Number of threads for the construct.
610   /// \param HelperNumThreads Helper Number of threads for the construct.
611   /// \param CaptureRegion Innermost OpenMP region where expressions in this
612   /// clause must be captured.
613   /// \param StartLoc Starting location of the clause.
614   /// \param LParenLoc Location of '('.
615   /// \param EndLoc Ending location of the clause.
OMPNumThreadsClause(Expr * NumThreads,Stmt * HelperNumThreads,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)616   OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
617                       OpenMPDirectiveKind CaptureRegion,
618                       SourceLocation StartLoc, SourceLocation LParenLoc,
619                       SourceLocation EndLoc)
620       : OMPClause(OMPC_num_threads, StartLoc, EndLoc),
621         OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
622         NumThreads(NumThreads) {
623     setPreInitStmt(HelperNumThreads, CaptureRegion);
624   }
625 
626   /// Build an empty clause.
OMPNumThreadsClause()627   OMPNumThreadsClause()
628       : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
629         OMPClauseWithPreInit(this) {}
630 
631   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)632   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
633 
634   /// Returns the location of '('.
getLParenLoc()635   SourceLocation getLParenLoc() const { return LParenLoc; }
636 
637   /// Returns number of threads.
getNumThreads()638   Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
639 
children()640   child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
641 
children()642   const_child_range children() const {
643     return const_child_range(&NumThreads, &NumThreads + 1);
644   }
645 
used_children()646   child_range used_children() {
647     return child_range(child_iterator(), child_iterator());
648   }
used_children()649   const_child_range used_children() const {
650     return const_child_range(const_child_iterator(), const_child_iterator());
651   }
652 
classof(const OMPClause * T)653   static bool classof(const OMPClause *T) {
654     return T->getClauseKind() == OMPC_num_threads;
655   }
656 };
657 
658 /// This represents 'safelen' clause in the '#pragma omp ...'
659 /// directive.
660 ///
661 /// \code
662 /// #pragma omp simd safelen(4)
663 /// \endcode
664 /// In this example directive '#pragma omp simd' has clause 'safelen'
665 /// with single expression '4'.
666 /// If the safelen clause is used then no two iterations executed
667 /// concurrently with SIMD instructions can have a greater distance
668 /// in the logical iteration space than its value. The parameter of
669 /// the safelen clause must be a constant positive integer expression.
670 class OMPSafelenClause : public OMPClause {
671   friend class OMPClauseReader;
672 
673   /// Location of '('.
674   SourceLocation LParenLoc;
675 
676   /// Safe iteration space distance.
677   Stmt *Safelen = nullptr;
678 
679   /// Set safelen.
setSafelen(Expr * Len)680   void setSafelen(Expr *Len) { Safelen = Len; }
681 
682 public:
683   /// Build 'safelen' clause.
684   ///
685   /// \param Len Expression associated with this clause.
686   /// \param StartLoc Starting location of the clause.
687   /// \param EndLoc Ending location of the clause.
OMPSafelenClause(Expr * Len,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)688   OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
689                    SourceLocation EndLoc)
690       : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
691         Safelen(Len) {}
692 
693   /// Build an empty clause.
OMPSafelenClause()694   explicit OMPSafelenClause()
695       : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()) {}
696 
697   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)698   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
699 
700   /// Returns the location of '('.
getLParenLoc()701   SourceLocation getLParenLoc() const { return LParenLoc; }
702 
703   /// Return safe iteration space distance.
getSafelen()704   Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
705 
children()706   child_range children() { return child_range(&Safelen, &Safelen + 1); }
707 
children()708   const_child_range children() const {
709     return const_child_range(&Safelen, &Safelen + 1);
710   }
711 
used_children()712   child_range used_children() {
713     return child_range(child_iterator(), child_iterator());
714   }
used_children()715   const_child_range used_children() const {
716     return const_child_range(const_child_iterator(), const_child_iterator());
717   }
718 
classof(const OMPClause * T)719   static bool classof(const OMPClause *T) {
720     return T->getClauseKind() == OMPC_safelen;
721   }
722 };
723 
724 /// This represents 'simdlen' clause in the '#pragma omp ...'
725 /// directive.
726 ///
727 /// \code
728 /// #pragma omp simd simdlen(4)
729 /// \endcode
730 /// In this example directive '#pragma omp simd' has clause 'simdlen'
731 /// with single expression '4'.
732 /// If the 'simdlen' clause is used then it specifies the preferred number of
733 /// iterations to be executed concurrently. The parameter of the 'simdlen'
734 /// clause must be a constant positive integer expression.
735 class OMPSimdlenClause : public OMPClause {
736   friend class OMPClauseReader;
737 
738   /// Location of '('.
739   SourceLocation LParenLoc;
740 
741   /// Safe iteration space distance.
742   Stmt *Simdlen = nullptr;
743 
744   /// Set simdlen.
setSimdlen(Expr * Len)745   void setSimdlen(Expr *Len) { Simdlen = Len; }
746 
747 public:
748   /// Build 'simdlen' clause.
749   ///
750   /// \param Len Expression associated with this clause.
751   /// \param StartLoc Starting location of the clause.
752   /// \param EndLoc Ending location of the clause.
OMPSimdlenClause(Expr * Len,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)753   OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
754                    SourceLocation EndLoc)
755       : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
756         Simdlen(Len) {}
757 
758   /// Build an empty clause.
OMPSimdlenClause()759   explicit OMPSimdlenClause()
760       : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()) {}
761 
762   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)763   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
764 
765   /// Returns the location of '('.
getLParenLoc()766   SourceLocation getLParenLoc() const { return LParenLoc; }
767 
768   /// Return safe iteration space distance.
getSimdlen()769   Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
770 
children()771   child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
772 
children()773   const_child_range children() const {
774     return const_child_range(&Simdlen, &Simdlen + 1);
775   }
776 
used_children()777   child_range used_children() {
778     return child_range(child_iterator(), child_iterator());
779   }
used_children()780   const_child_range used_children() const {
781     return const_child_range(const_child_iterator(), const_child_iterator());
782   }
783 
classof(const OMPClause * T)784   static bool classof(const OMPClause *T) {
785     return T->getClauseKind() == OMPC_simdlen;
786   }
787 };
788 
789 /// This represents 'collapse' clause in the '#pragma omp ...'
790 /// directive.
791 ///
792 /// \code
793 /// #pragma omp simd collapse(3)
794 /// \endcode
795 /// In this example directive '#pragma omp simd' has clause 'collapse'
796 /// with single expression '3'.
797 /// The parameter must be a constant positive integer expression, it specifies
798 /// the number of nested loops that should be collapsed into a single iteration
799 /// space.
800 class OMPCollapseClause : public OMPClause {
801   friend class OMPClauseReader;
802 
803   /// Location of '('.
804   SourceLocation LParenLoc;
805 
806   /// Number of for-loops.
807   Stmt *NumForLoops = nullptr;
808 
809   /// Set the number of associated for-loops.
setNumForLoops(Expr * Num)810   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
811 
812 public:
813   /// Build 'collapse' clause.
814   ///
815   /// \param Num Expression associated with this clause.
816   /// \param StartLoc Starting location of the clause.
817   /// \param LParenLoc Location of '('.
818   /// \param EndLoc Ending location of the clause.
OMPCollapseClause(Expr * Num,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)819   OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
820                     SourceLocation LParenLoc, SourceLocation EndLoc)
821       : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
822         NumForLoops(Num) {}
823 
824   /// Build an empty clause.
OMPCollapseClause()825   explicit OMPCollapseClause()
826       : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()) {}
827 
828   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)829   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
830 
831   /// Returns the location of '('.
getLParenLoc()832   SourceLocation getLParenLoc() const { return LParenLoc; }
833 
834   /// Return the number of associated for-loops.
getNumForLoops()835   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
836 
children()837   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
838 
children()839   const_child_range children() const {
840     return const_child_range(&NumForLoops, &NumForLoops + 1);
841   }
842 
used_children()843   child_range used_children() {
844     return child_range(child_iterator(), child_iterator());
845   }
used_children()846   const_child_range used_children() const {
847     return const_child_range(const_child_iterator(), const_child_iterator());
848   }
849 
classof(const OMPClause * T)850   static bool classof(const OMPClause *T) {
851     return T->getClauseKind() == OMPC_collapse;
852   }
853 };
854 
855 /// This represents 'default' clause in the '#pragma omp ...' directive.
856 ///
857 /// \code
858 /// #pragma omp parallel default(shared)
859 /// \endcode
860 /// In this example directive '#pragma omp parallel' has simple 'default'
861 /// clause with kind 'shared'.
862 class OMPDefaultClause : public OMPClause {
863   friend class OMPClauseReader;
864 
865   /// Location of '('.
866   SourceLocation LParenLoc;
867 
868   /// A kind of the 'default' clause.
869   OpenMPDefaultClauseKind Kind = OMPC_DEFAULT_unknown;
870 
871   /// Start location of the kind in source code.
872   SourceLocation KindKwLoc;
873 
874   /// Set kind of the clauses.
875   ///
876   /// \param K Argument of clause.
setDefaultKind(OpenMPDefaultClauseKind K)877   void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
878 
879   /// Set argument location.
880   ///
881   /// \param KLoc Argument location.
setDefaultKindKwLoc(SourceLocation KLoc)882   void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
883 
884 public:
885   /// Build 'default' clause with argument \a A ('none' or 'shared').
886   ///
887   /// \param A Argument of the clause ('none' or 'shared').
888   /// \param ALoc Starting location of the argument.
889   /// \param StartLoc Starting location of the clause.
890   /// \param LParenLoc Location of '('.
891   /// \param EndLoc Ending location of the clause.
OMPDefaultClause(OpenMPDefaultClauseKind A,SourceLocation ALoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)892   OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
893                    SourceLocation StartLoc, SourceLocation LParenLoc,
894                    SourceLocation EndLoc)
895       : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
896         Kind(A), KindKwLoc(ALoc) {}
897 
898   /// Build an empty clause.
OMPDefaultClause()899   OMPDefaultClause()
900       : OMPClause(OMPC_default, SourceLocation(), SourceLocation()) {}
901 
902   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)903   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
904 
905   /// Returns the location of '('.
getLParenLoc()906   SourceLocation getLParenLoc() const { return LParenLoc; }
907 
908   /// Returns kind of the clause.
getDefaultKind()909   OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
910 
911   /// Returns location of clause kind.
getDefaultKindKwLoc()912   SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
913 
children()914   child_range children() {
915     return child_range(child_iterator(), child_iterator());
916   }
917 
children()918   const_child_range children() const {
919     return const_child_range(const_child_iterator(), const_child_iterator());
920   }
921 
used_children()922   child_range used_children() {
923     return child_range(child_iterator(), child_iterator());
924   }
used_children()925   const_child_range used_children() const {
926     return const_child_range(const_child_iterator(), const_child_iterator());
927   }
928 
classof(const OMPClause * T)929   static bool classof(const OMPClause *T) {
930     return T->getClauseKind() == OMPC_default;
931   }
932 };
933 
934 /// This represents 'proc_bind' clause in the '#pragma omp ...'
935 /// directive.
936 ///
937 /// \code
938 /// #pragma omp parallel proc_bind(master)
939 /// \endcode
940 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
941 /// clause with kind 'master'.
942 class OMPProcBindClause : public OMPClause {
943   friend class OMPClauseReader;
944 
945   /// Location of '('.
946   SourceLocation LParenLoc;
947 
948   /// A kind of the 'proc_bind' clause.
949   llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
950 
951   /// Start location of the kind in source code.
952   SourceLocation KindKwLoc;
953 
954   /// Set kind of the clause.
955   ///
956   /// \param K Kind of clause.
setProcBindKind(llvm::omp::ProcBindKind K)957   void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
958 
959   /// Set clause kind location.
960   ///
961   /// \param KLoc Kind location.
setProcBindKindKwLoc(SourceLocation KLoc)962   void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
963 
964 public:
965   /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
966   ///        'spread').
967   ///
968   /// \param A Argument of the clause ('master', 'close' or 'spread').
969   /// \param ALoc Starting location of the argument.
970   /// \param StartLoc Starting location of the clause.
971   /// \param LParenLoc Location of '('.
972   /// \param EndLoc Ending location of the clause.
OMPProcBindClause(llvm::omp::ProcBindKind A,SourceLocation ALoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)973   OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
974                     SourceLocation StartLoc, SourceLocation LParenLoc,
975                     SourceLocation EndLoc)
976       : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
977         Kind(A), KindKwLoc(ALoc) {}
978 
979   /// Build an empty clause.
OMPProcBindClause()980   OMPProcBindClause()
981       : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()) {}
982 
983   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)984   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
985 
986   /// Returns the location of '('.
getLParenLoc()987   SourceLocation getLParenLoc() const { return LParenLoc; }
988 
989   /// Returns kind of the clause.
getProcBindKind()990   llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
991 
992   /// Returns location of clause kind.
getProcBindKindKwLoc()993   SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
994 
children()995   child_range children() {
996     return child_range(child_iterator(), child_iterator());
997   }
998 
children()999   const_child_range children() const {
1000     return const_child_range(const_child_iterator(), const_child_iterator());
1001   }
1002 
used_children()1003   child_range used_children() {
1004     return child_range(child_iterator(), child_iterator());
1005   }
used_children()1006   const_child_range used_children() const {
1007     return const_child_range(const_child_iterator(), const_child_iterator());
1008   }
1009 
classof(const OMPClause * T)1010   static bool classof(const OMPClause *T) {
1011     return T->getClauseKind() == OMPC_proc_bind;
1012   }
1013 };
1014 
1015 /// This represents 'unified_address' clause in the '#pragma omp requires'
1016 /// directive.
1017 ///
1018 /// \code
1019 /// #pragma omp requires unified_address
1020 /// \endcode
1021 /// In this example directive '#pragma omp requires' has 'unified_address'
1022 /// clause.
1023 class OMPUnifiedAddressClause final : public OMPClause {
1024 public:
1025   friend class OMPClauseReader;
1026   /// Build 'unified_address' clause.
1027   ///
1028   /// \param StartLoc Starting location of the clause.
1029   /// \param EndLoc Ending location of the clause.
OMPUnifiedAddressClause(SourceLocation StartLoc,SourceLocation EndLoc)1030   OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
1031       : OMPClause(OMPC_unified_address, StartLoc, EndLoc) {}
1032 
1033   /// Build an empty clause.
OMPUnifiedAddressClause()1034   OMPUnifiedAddressClause()
1035       : OMPClause(OMPC_unified_address, SourceLocation(), SourceLocation()) {}
1036 
children()1037   child_range children() {
1038     return child_range(child_iterator(), child_iterator());
1039   }
1040 
children()1041   const_child_range children() const {
1042     return const_child_range(const_child_iterator(), const_child_iterator());
1043   }
1044 
used_children()1045   child_range used_children() {
1046     return child_range(child_iterator(), child_iterator());
1047   }
used_children()1048   const_child_range used_children() const {
1049     return const_child_range(const_child_iterator(), const_child_iterator());
1050   }
1051 
classof(const OMPClause * T)1052   static bool classof(const OMPClause *T) {
1053     return T->getClauseKind() == OMPC_unified_address;
1054   }
1055 };
1056 
1057 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1058 /// directive.
1059 ///
1060 /// \code
1061 /// #pragma omp requires unified_shared_memory
1062 /// \endcode
1063 /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1064 /// clause.
1065 class OMPUnifiedSharedMemoryClause final : public OMPClause {
1066 public:
1067   friend class OMPClauseReader;
1068   /// Build 'unified_shared_memory' clause.
1069   ///
1070   /// \param StartLoc Starting location of the clause.
1071   /// \param EndLoc Ending location of the clause.
OMPUnifiedSharedMemoryClause(SourceLocation StartLoc,SourceLocation EndLoc)1072   OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
1073       : OMPClause(OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1074 
1075   /// Build an empty clause.
OMPUnifiedSharedMemoryClause()1076   OMPUnifiedSharedMemoryClause()
1077       : OMPClause(OMPC_unified_shared_memory, SourceLocation(), SourceLocation()) {}
1078 
children()1079   child_range children() {
1080     return child_range(child_iterator(), child_iterator());
1081   }
1082 
children()1083   const_child_range children() const {
1084     return const_child_range(const_child_iterator(), const_child_iterator());
1085   }
1086 
used_children()1087   child_range used_children() {
1088     return child_range(child_iterator(), child_iterator());
1089   }
used_children()1090   const_child_range used_children() const {
1091     return const_child_range(const_child_iterator(), const_child_iterator());
1092   }
1093 
classof(const OMPClause * T)1094   static bool classof(const OMPClause *T) {
1095     return T->getClauseKind() == OMPC_unified_shared_memory;
1096   }
1097 };
1098 
1099 /// This represents 'reverse_offload' clause in the '#pragma omp requires'
1100 /// directive.
1101 ///
1102 /// \code
1103 /// #pragma omp requires reverse_offload
1104 /// \endcode
1105 /// In this example directive '#pragma omp requires' has 'reverse_offload'
1106 /// clause.
1107 class OMPReverseOffloadClause final : public OMPClause {
1108 public:
1109   friend class OMPClauseReader;
1110   /// Build 'reverse_offload' clause.
1111   ///
1112   /// \param StartLoc Starting location of the clause.
1113   /// \param EndLoc Ending location of the clause.
OMPReverseOffloadClause(SourceLocation StartLoc,SourceLocation EndLoc)1114   OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1115       : OMPClause(OMPC_reverse_offload, StartLoc, EndLoc) {}
1116 
1117   /// Build an empty clause.
OMPReverseOffloadClause()1118   OMPReverseOffloadClause()
1119       : OMPClause(OMPC_reverse_offload, SourceLocation(), SourceLocation()) {}
1120 
children()1121   child_range children() {
1122     return child_range(child_iterator(), child_iterator());
1123   }
1124 
children()1125   const_child_range children() const {
1126     return const_child_range(const_child_iterator(), const_child_iterator());
1127   }
1128 
used_children()1129   child_range used_children() {
1130     return child_range(child_iterator(), child_iterator());
1131   }
used_children()1132   const_child_range used_children() const {
1133     return const_child_range(const_child_iterator(), const_child_iterator());
1134   }
1135 
classof(const OMPClause * T)1136   static bool classof(const OMPClause *T) {
1137     return T->getClauseKind() == OMPC_reverse_offload;
1138   }
1139 };
1140 
1141 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1142 /// directive.
1143 ///
1144 /// \code
1145 /// #pragma omp requires dynamic_allocators
1146 /// \endcode
1147 /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1148 /// clause.
1149 class OMPDynamicAllocatorsClause final : public OMPClause {
1150 public:
1151   friend class OMPClauseReader;
1152   /// Build 'dynamic_allocators' clause.
1153   ///
1154   /// \param StartLoc Starting location of the clause.
1155   /// \param EndLoc Ending location of the clause.
OMPDynamicAllocatorsClause(SourceLocation StartLoc,SourceLocation EndLoc)1156   OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
1157       : OMPClause(OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1158 
1159   /// Build an empty clause.
OMPDynamicAllocatorsClause()1160   OMPDynamicAllocatorsClause()
1161       : OMPClause(OMPC_dynamic_allocators, SourceLocation(), SourceLocation()) {
1162   }
1163 
children()1164   child_range children() {
1165     return child_range(child_iterator(), child_iterator());
1166   }
1167 
children()1168   const_child_range children() const {
1169     return const_child_range(const_child_iterator(), const_child_iterator());
1170   }
1171 
used_children()1172   child_range used_children() {
1173     return child_range(child_iterator(), child_iterator());
1174   }
used_children()1175   const_child_range used_children() const {
1176     return const_child_range(const_child_iterator(), const_child_iterator());
1177   }
1178 
classof(const OMPClause * T)1179   static bool classof(const OMPClause *T) {
1180     return T->getClauseKind() == OMPC_dynamic_allocators;
1181   }
1182 };
1183 
1184 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1185 /// requires'  directive.
1186 ///
1187 /// \code
1188 /// #pragma omp requires atomic_default_mem_order(seq_cst)
1189 /// \endcode
1190 /// In this example directive '#pragma omp requires' has simple
1191 /// atomic_default_mem_order' clause with kind 'seq_cst'.
1192 class OMPAtomicDefaultMemOrderClause final : public OMPClause {
1193   friend class OMPClauseReader;
1194 
1195   /// Location of '('
1196   SourceLocation LParenLoc;
1197 
1198   /// A kind of the 'atomic_default_mem_order' clause.
1199   OpenMPAtomicDefaultMemOrderClauseKind Kind =
1200       OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown;
1201 
1202   /// Start location of the kind in source code.
1203   SourceLocation KindKwLoc;
1204 
1205   /// Set kind of the clause.
1206   ///
1207   /// \param K Kind of clause.
setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K)1208   void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1209     Kind = K;
1210   }
1211 
1212   /// Set clause kind location.
1213   ///
1214   /// \param KLoc Kind location.
setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc)1215   void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1216     KindKwLoc = KLoc;
1217   }
1218 
1219 public:
1220   /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1221   /// 'acq_rel' or 'relaxed').
1222   ///
1223   /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1224   /// \param ALoc Starting location of the argument.
1225   /// \param StartLoc Starting location of the clause.
1226   /// \param LParenLoc Location of '('.
1227   /// \param EndLoc Ending location of the clause.
OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,SourceLocation ALoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1228   OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
1229                                  SourceLocation ALoc, SourceLocation StartLoc,
1230                                  SourceLocation LParenLoc,
1231                                  SourceLocation EndLoc)
1232       : OMPClause(OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1233         LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1234 
1235   /// Build an empty clause.
OMPAtomicDefaultMemOrderClause()1236   OMPAtomicDefaultMemOrderClause()
1237       : OMPClause(OMPC_atomic_default_mem_order, SourceLocation(),
1238                   SourceLocation()) {}
1239 
1240   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)1241   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1242 
1243   /// Returns the locaiton of '('.
getLParenLoc()1244   SourceLocation getLParenLoc() const { return LParenLoc; }
1245 
1246   /// Returns kind of the clause.
getAtomicDefaultMemOrderKind()1247   OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
1248     return Kind;
1249   }
1250 
1251   /// Returns location of clause kind.
getAtomicDefaultMemOrderKindKwLoc()1252   SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
1253 
children()1254   child_range children() {
1255     return child_range(child_iterator(), child_iterator());
1256   }
1257 
children()1258   const_child_range children() const {
1259     return const_child_range(const_child_iterator(), const_child_iterator());
1260   }
1261 
used_children()1262   child_range used_children() {
1263     return child_range(child_iterator(), child_iterator());
1264   }
used_children()1265   const_child_range used_children() const {
1266     return const_child_range(const_child_iterator(), const_child_iterator());
1267   }
1268 
classof(const OMPClause * T)1269   static bool classof(const OMPClause *T) {
1270     return T->getClauseKind() == OMPC_atomic_default_mem_order;
1271   }
1272 };
1273 
1274 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
1275 ///
1276 /// \code
1277 /// #pragma omp for schedule(static, 3)
1278 /// \endcode
1279 /// In this example directive '#pragma omp for' has 'schedule' clause with
1280 /// arguments 'static' and '3'.
1281 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
1282   friend class OMPClauseReader;
1283 
1284   /// Location of '('.
1285   SourceLocation LParenLoc;
1286 
1287   /// A kind of the 'schedule' clause.
1288   OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
1289 
1290   /// Modifiers for 'schedule' clause.
1291   enum {FIRST, SECOND, NUM_MODIFIERS};
1292   OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1293 
1294   /// Locations of modifiers.
1295   SourceLocation ModifiersLoc[NUM_MODIFIERS];
1296 
1297   /// Start location of the schedule ind in source code.
1298   SourceLocation KindLoc;
1299 
1300   /// Location of ',' (if any).
1301   SourceLocation CommaLoc;
1302 
1303   /// Chunk size.
1304   Expr *ChunkSize = nullptr;
1305 
1306   /// Set schedule kind.
1307   ///
1308   /// \param K Schedule kind.
setScheduleKind(OpenMPScheduleClauseKind K)1309   void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1310 
1311   /// Set the first schedule modifier.
1312   ///
1313   /// \param M Schedule modifier.
setFirstScheduleModifier(OpenMPScheduleClauseModifier M)1314   void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1315     Modifiers[FIRST] = M;
1316   }
1317 
1318   /// Set the second schedule modifier.
1319   ///
1320   /// \param M Schedule modifier.
setSecondScheduleModifier(OpenMPScheduleClauseModifier M)1321   void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1322     Modifiers[SECOND] = M;
1323   }
1324 
1325   /// Set location of the first schedule modifier.
setFirstScheduleModifierLoc(SourceLocation Loc)1326   void setFirstScheduleModifierLoc(SourceLocation Loc) {
1327     ModifiersLoc[FIRST] = Loc;
1328   }
1329 
1330   /// Set location of the second schedule modifier.
setSecondScheduleModifierLoc(SourceLocation Loc)1331   void setSecondScheduleModifierLoc(SourceLocation Loc) {
1332     ModifiersLoc[SECOND] = Loc;
1333   }
1334 
1335   /// Set schedule modifier location.
1336   ///
1337   /// \param M Schedule modifier location.
setScheduleModifer(OpenMPScheduleClauseModifier M)1338   void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1339     if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1340       Modifiers[FIRST] = M;
1341     else {
1342       assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1343       Modifiers[SECOND] = M;
1344     }
1345   }
1346 
1347   /// Sets the location of '('.
1348   ///
1349   /// \param Loc Location of '('.
setLParenLoc(SourceLocation Loc)1350   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1351 
1352   /// Set schedule kind start location.
1353   ///
1354   /// \param KLoc Schedule kind location.
setScheduleKindLoc(SourceLocation KLoc)1355   void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1356 
1357   /// Set location of ','.
1358   ///
1359   /// \param Loc Location of ','.
setCommaLoc(SourceLocation Loc)1360   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1361 
1362   /// Set chunk size.
1363   ///
1364   /// \param E Chunk size.
setChunkSize(Expr * E)1365   void setChunkSize(Expr *E) { ChunkSize = E; }
1366 
1367 public:
1368   /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1369   /// expression \a ChunkSize.
1370   ///
1371   /// \param StartLoc Starting location of the clause.
1372   /// \param LParenLoc Location of '('.
1373   /// \param KLoc Starting location of the argument.
1374   /// \param CommaLoc Location of ','.
1375   /// \param EndLoc Ending location of the clause.
1376   /// \param Kind Schedule kind.
1377   /// \param ChunkSize Chunk size.
1378   /// \param HelperChunkSize Helper chunk size for combined directives.
1379   /// \param M1 The first modifier applied to 'schedule' clause.
1380   /// \param M1Loc Location of the first modifier
1381   /// \param M2 The second modifier applied to 'schedule' clause.
1382   /// \param M2Loc Location of the second modifier
OMPScheduleClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation KLoc,SourceLocation CommaLoc,SourceLocation EndLoc,OpenMPScheduleClauseKind Kind,Expr * ChunkSize,Stmt * HelperChunkSize,OpenMPScheduleClauseModifier M1,SourceLocation M1Loc,OpenMPScheduleClauseModifier M2,SourceLocation M2Loc)1383   OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1384                     SourceLocation KLoc, SourceLocation CommaLoc,
1385                     SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
1386                     Expr *ChunkSize, Stmt *HelperChunkSize,
1387                     OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
1388                     OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
1389       : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this),
1390         LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc),
1391         ChunkSize(ChunkSize) {
1392     setPreInitStmt(HelperChunkSize);
1393     Modifiers[FIRST] = M1;
1394     Modifiers[SECOND] = M2;
1395     ModifiersLoc[FIRST] = M1Loc;
1396     ModifiersLoc[SECOND] = M2Loc;
1397   }
1398 
1399   /// Build an empty clause.
OMPScheduleClause()1400   explicit OMPScheduleClause()
1401       : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
1402         OMPClauseWithPreInit(this) {
1403     Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1404     Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1405   }
1406 
1407   /// Get kind of the clause.
getScheduleKind()1408   OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
1409 
1410   /// Get the first modifier of the clause.
getFirstScheduleModifier()1411   OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
1412     return Modifiers[FIRST];
1413   }
1414 
1415   /// Get the second modifier of the clause.
getSecondScheduleModifier()1416   OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
1417     return Modifiers[SECOND];
1418   }
1419 
1420   /// Get location of '('.
getLParenLoc()1421   SourceLocation getLParenLoc() { return LParenLoc; }
1422 
1423   /// Get kind location.
getScheduleKindLoc()1424   SourceLocation getScheduleKindLoc() { return KindLoc; }
1425 
1426   /// Get the first modifier location.
getFirstScheduleModifierLoc()1427   SourceLocation getFirstScheduleModifierLoc() const {
1428     return ModifiersLoc[FIRST];
1429   }
1430 
1431   /// Get the second modifier location.
getSecondScheduleModifierLoc()1432   SourceLocation getSecondScheduleModifierLoc() const {
1433     return ModifiersLoc[SECOND];
1434   }
1435 
1436   /// Get location of ','.
getCommaLoc()1437   SourceLocation getCommaLoc() { return CommaLoc; }
1438 
1439   /// Get chunk size.
getChunkSize()1440   Expr *getChunkSize() { return ChunkSize; }
1441 
1442   /// Get chunk size.
getChunkSize()1443   const Expr *getChunkSize() const { return ChunkSize; }
1444 
children()1445   child_range children() {
1446     return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1447                        reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1448   }
1449 
children()1450   const_child_range children() const {
1451     auto Children = const_cast<OMPScheduleClause *>(this)->children();
1452     return const_child_range(Children.begin(), Children.end());
1453   }
1454 
used_children()1455   child_range used_children() {
1456     return child_range(child_iterator(), child_iterator());
1457   }
used_children()1458   const_child_range used_children() const {
1459     return const_child_range(const_child_iterator(), const_child_iterator());
1460   }
1461 
classof(const OMPClause * T)1462   static bool classof(const OMPClause *T) {
1463     return T->getClauseKind() == OMPC_schedule;
1464   }
1465 };
1466 
1467 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1468 ///
1469 /// \code
1470 /// #pragma omp for ordered (2)
1471 /// \endcode
1472 /// In this example directive '#pragma omp for' has 'ordered' clause with
1473 /// parameter 2.
1474 class OMPOrderedClause final
1475     : public OMPClause,
1476       private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1477   friend class OMPClauseReader;
1478   friend TrailingObjects;
1479 
1480   /// Location of '('.
1481   SourceLocation LParenLoc;
1482 
1483   /// Number of for-loops.
1484   Stmt *NumForLoops = nullptr;
1485 
1486   /// Real number of loops.
1487   unsigned NumberOfLoops = 0;
1488 
1489   /// Build 'ordered' clause.
1490   ///
1491   /// \param Num Expression, possibly associated with this clause.
1492   /// \param NumLoops Number of loops, associated with this clause.
1493   /// \param StartLoc Starting location of the clause.
1494   /// \param LParenLoc Location of '('.
1495   /// \param EndLoc Ending location of the clause.
OMPOrderedClause(Expr * Num,unsigned NumLoops,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)1496   OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1497                    SourceLocation LParenLoc, SourceLocation EndLoc)
1498       : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
1499         NumForLoops(Num), NumberOfLoops(NumLoops) {}
1500 
1501   /// Build an empty clause.
OMPOrderedClause(unsigned NumLoops)1502   explicit OMPOrderedClause(unsigned NumLoops)
1503       : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
1504         NumberOfLoops(NumLoops) {}
1505 
1506   /// Set the number of associated for-loops.
setNumForLoops(Expr * Num)1507   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1508 
1509 public:
1510   /// Build 'ordered' clause.
1511   ///
1512   /// \param Num Expression, possibly associated with this clause.
1513   /// \param NumLoops Number of loops, associated with this clause.
1514   /// \param StartLoc Starting location of the clause.
1515   /// \param LParenLoc Location of '('.
1516   /// \param EndLoc Ending location of the clause.
1517   static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1518                                   unsigned NumLoops, SourceLocation StartLoc,
1519                                   SourceLocation LParenLoc,
1520                                   SourceLocation EndLoc);
1521 
1522   /// Build an empty clause.
1523   static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1524 
1525   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)1526   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1527 
1528   /// Returns the location of '('.
getLParenLoc()1529   SourceLocation getLParenLoc() const { return LParenLoc; }
1530 
1531   /// Return the number of associated for-loops.
getNumForLoops()1532   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1533 
1534   /// Set number of iterations for the specified loop.
1535   void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1536   /// Get number of iterations for all the loops.
1537   ArrayRef<Expr *> getLoopNumIterations() const;
1538 
1539   /// Set loop counter for the specified loop.
1540   void setLoopCounter(unsigned NumLoop, Expr *Counter);
1541   /// Get loops counter for the specified loop.
1542   Expr *getLoopCounter(unsigned NumLoop);
1543   const Expr *getLoopCounter(unsigned NumLoop) const;
1544 
children()1545   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1546 
children()1547   const_child_range children() const {
1548     return const_child_range(&NumForLoops, &NumForLoops + 1);
1549   }
1550 
used_children()1551   child_range used_children() {
1552     return child_range(child_iterator(), child_iterator());
1553   }
used_children()1554   const_child_range used_children() const {
1555     return const_child_range(const_child_iterator(), const_child_iterator());
1556   }
1557 
classof(const OMPClause * T)1558   static bool classof(const OMPClause *T) {
1559     return T->getClauseKind() == OMPC_ordered;
1560   }
1561 };
1562 
1563 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1564 ///
1565 /// \code
1566 /// #pragma omp for nowait
1567 /// \endcode
1568 /// In this example directive '#pragma omp for' has 'nowait' clause.
1569 class OMPNowaitClause : public OMPClause {
1570 public:
1571   /// Build 'nowait' clause.
1572   ///
1573   /// \param StartLoc Starting location of the clause.
1574   /// \param EndLoc Ending location of the clause.
OMPNowaitClause(SourceLocation StartLoc,SourceLocation EndLoc)1575   OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
1576       : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
1577 
1578   /// Build an empty clause.
OMPNowaitClause()1579   OMPNowaitClause()
1580       : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
1581 
children()1582   child_range children() {
1583     return child_range(child_iterator(), child_iterator());
1584   }
1585 
children()1586   const_child_range children() const {
1587     return const_child_range(const_child_iterator(), const_child_iterator());
1588   }
1589 
used_children()1590   child_range used_children() {
1591     return child_range(child_iterator(), child_iterator());
1592   }
used_children()1593   const_child_range used_children() const {
1594     return const_child_range(const_child_iterator(), const_child_iterator());
1595   }
1596 
classof(const OMPClause * T)1597   static bool classof(const OMPClause *T) {
1598     return T->getClauseKind() == OMPC_nowait;
1599   }
1600 };
1601 
1602 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1603 ///
1604 /// \code
1605 /// #pragma omp task untied
1606 /// \endcode
1607 /// In this example directive '#pragma omp task' has 'untied' clause.
1608 class OMPUntiedClause : public OMPClause {
1609 public:
1610   /// Build 'untied' clause.
1611   ///
1612   /// \param StartLoc Starting location of the clause.
1613   /// \param EndLoc Ending location of the clause.
OMPUntiedClause(SourceLocation StartLoc,SourceLocation EndLoc)1614   OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
1615       : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
1616 
1617   /// Build an empty clause.
OMPUntiedClause()1618   OMPUntiedClause()
1619       : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
1620 
children()1621   child_range children() {
1622     return child_range(child_iterator(), child_iterator());
1623   }
1624 
children()1625   const_child_range children() const {
1626     return const_child_range(const_child_iterator(), const_child_iterator());
1627   }
1628 
used_children()1629   child_range used_children() {
1630     return child_range(child_iterator(), child_iterator());
1631   }
used_children()1632   const_child_range used_children() const {
1633     return const_child_range(const_child_iterator(), const_child_iterator());
1634   }
1635 
classof(const OMPClause * T)1636   static bool classof(const OMPClause *T) {
1637     return T->getClauseKind() == OMPC_untied;
1638   }
1639 };
1640 
1641 /// This represents 'mergeable' clause in the '#pragma omp ...'
1642 /// directive.
1643 ///
1644 /// \code
1645 /// #pragma omp task mergeable
1646 /// \endcode
1647 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1648 class OMPMergeableClause : public OMPClause {
1649 public:
1650   /// Build 'mergeable' clause.
1651   ///
1652   /// \param StartLoc Starting location of the clause.
1653   /// \param EndLoc Ending location of the clause.
OMPMergeableClause(SourceLocation StartLoc,SourceLocation EndLoc)1654   OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
1655       : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
1656 
1657   /// Build an empty clause.
OMPMergeableClause()1658   OMPMergeableClause()
1659       : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
1660 
children()1661   child_range children() {
1662     return child_range(child_iterator(), child_iterator());
1663   }
1664 
children()1665   const_child_range children() const {
1666     return const_child_range(const_child_iterator(), const_child_iterator());
1667   }
1668 
used_children()1669   child_range used_children() {
1670     return child_range(child_iterator(), child_iterator());
1671   }
used_children()1672   const_child_range used_children() const {
1673     return const_child_range(const_child_iterator(), const_child_iterator());
1674   }
1675 
classof(const OMPClause * T)1676   static bool classof(const OMPClause *T) {
1677     return T->getClauseKind() == OMPC_mergeable;
1678   }
1679 };
1680 
1681 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1682 ///
1683 /// \code
1684 /// #pragma omp atomic read
1685 /// \endcode
1686 /// In this example directive '#pragma omp atomic' has 'read' clause.
1687 class OMPReadClause : public OMPClause {
1688 public:
1689   /// Build 'read' clause.
1690   ///
1691   /// \param StartLoc Starting location of the clause.
1692   /// \param EndLoc Ending location of the clause.
OMPReadClause(SourceLocation StartLoc,SourceLocation EndLoc)1693   OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1694       : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1695 
1696   /// Build an empty clause.
OMPReadClause()1697   OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1698 
children()1699   child_range children() {
1700     return child_range(child_iterator(), child_iterator());
1701   }
1702 
children()1703   const_child_range children() const {
1704     return const_child_range(const_child_iterator(), const_child_iterator());
1705   }
1706 
used_children()1707   child_range used_children() {
1708     return child_range(child_iterator(), child_iterator());
1709   }
used_children()1710   const_child_range used_children() const {
1711     return const_child_range(const_child_iterator(), const_child_iterator());
1712   }
1713 
classof(const OMPClause * T)1714   static bool classof(const OMPClause *T) {
1715     return T->getClauseKind() == OMPC_read;
1716   }
1717 };
1718 
1719 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1720 ///
1721 /// \code
1722 /// #pragma omp atomic write
1723 /// \endcode
1724 /// In this example directive '#pragma omp atomic' has 'write' clause.
1725 class OMPWriteClause : public OMPClause {
1726 public:
1727   /// Build 'write' clause.
1728   ///
1729   /// \param StartLoc Starting location of the clause.
1730   /// \param EndLoc Ending location of the clause.
OMPWriteClause(SourceLocation StartLoc,SourceLocation EndLoc)1731   OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1732       : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1733 
1734   /// Build an empty clause.
OMPWriteClause()1735   OMPWriteClause()
1736       : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1737 
children()1738   child_range children() {
1739     return child_range(child_iterator(), child_iterator());
1740   }
1741 
children()1742   const_child_range children() const {
1743     return const_child_range(const_child_iterator(), const_child_iterator());
1744   }
1745 
used_children()1746   child_range used_children() {
1747     return child_range(child_iterator(), child_iterator());
1748   }
used_children()1749   const_child_range used_children() const {
1750     return const_child_range(const_child_iterator(), const_child_iterator());
1751   }
1752 
classof(const OMPClause * T)1753   static bool classof(const OMPClause *T) {
1754     return T->getClauseKind() == OMPC_write;
1755   }
1756 };
1757 
1758 /// This represents 'update' clause in the '#pragma omp atomic'
1759 /// directive.
1760 ///
1761 /// \code
1762 /// #pragma omp atomic update
1763 /// \endcode
1764 /// In this example directive '#pragma omp atomic' has 'update' clause.
1765 class OMPUpdateClause : public OMPClause {
1766 public:
1767   /// Build 'update' clause.
1768   ///
1769   /// \param StartLoc Starting location of the clause.
1770   /// \param EndLoc Ending location of the clause.
OMPUpdateClause(SourceLocation StartLoc,SourceLocation EndLoc)1771   OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
1772       : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1773 
1774   /// Build an empty clause.
OMPUpdateClause()1775   OMPUpdateClause()
1776       : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1777 
children()1778   child_range children() {
1779     return child_range(child_iterator(), child_iterator());
1780   }
1781 
children()1782   const_child_range children() const {
1783     return const_child_range(const_child_iterator(), const_child_iterator());
1784   }
1785 
used_children()1786   child_range used_children() {
1787     return child_range(child_iterator(), child_iterator());
1788   }
used_children()1789   const_child_range used_children() const {
1790     return const_child_range(const_child_iterator(), const_child_iterator());
1791   }
1792 
classof(const OMPClause * T)1793   static bool classof(const OMPClause *T) {
1794     return T->getClauseKind() == OMPC_update;
1795   }
1796 };
1797 
1798 /// This represents 'capture' clause in the '#pragma omp atomic'
1799 /// directive.
1800 ///
1801 /// \code
1802 /// #pragma omp atomic capture
1803 /// \endcode
1804 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1805 class OMPCaptureClause : public OMPClause {
1806 public:
1807   /// Build 'capture' clause.
1808   ///
1809   /// \param StartLoc Starting location of the clause.
1810   /// \param EndLoc Ending location of the clause.
OMPCaptureClause(SourceLocation StartLoc,SourceLocation EndLoc)1811   OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1812       : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1813 
1814   /// Build an empty clause.
OMPCaptureClause()1815   OMPCaptureClause()
1816       : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1817 
children()1818   child_range children() {
1819     return child_range(child_iterator(), child_iterator());
1820   }
1821 
children()1822   const_child_range children() const {
1823     return const_child_range(const_child_iterator(), const_child_iterator());
1824   }
1825 
used_children()1826   child_range used_children() {
1827     return child_range(child_iterator(), child_iterator());
1828   }
used_children()1829   const_child_range used_children() const {
1830     return const_child_range(const_child_iterator(), const_child_iterator());
1831   }
1832 
classof(const OMPClause * T)1833   static bool classof(const OMPClause *T) {
1834     return T->getClauseKind() == OMPC_capture;
1835   }
1836 };
1837 
1838 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
1839 /// directive.
1840 ///
1841 /// \code
1842 /// #pragma omp atomic seq_cst
1843 /// \endcode
1844 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1845 class OMPSeqCstClause : public OMPClause {
1846 public:
1847   /// Build 'seq_cst' clause.
1848   ///
1849   /// \param StartLoc Starting location of the clause.
1850   /// \param EndLoc Ending location of the clause.
OMPSeqCstClause(SourceLocation StartLoc,SourceLocation EndLoc)1851   OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1852       : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1853 
1854   /// Build an empty clause.
OMPSeqCstClause()1855   OMPSeqCstClause()
1856       : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1857 
children()1858   child_range children() {
1859     return child_range(child_iterator(), child_iterator());
1860   }
1861 
children()1862   const_child_range children() const {
1863     return const_child_range(const_child_iterator(), const_child_iterator());
1864   }
1865 
used_children()1866   child_range used_children() {
1867     return child_range(child_iterator(), child_iterator());
1868   }
used_children()1869   const_child_range used_children() const {
1870     return const_child_range(const_child_iterator(), const_child_iterator());
1871   }
1872 
classof(const OMPClause * T)1873   static bool classof(const OMPClause *T) {
1874     return T->getClauseKind() == OMPC_seq_cst;
1875   }
1876 };
1877 
1878 /// This represents clause 'private' in the '#pragma omp ...' directives.
1879 ///
1880 /// \code
1881 /// #pragma omp parallel private(a,b)
1882 /// \endcode
1883 /// In this example directive '#pragma omp parallel' has clause 'private'
1884 /// with the variables 'a' and 'b'.
1885 class OMPPrivateClause final
1886     : public OMPVarListClause<OMPPrivateClause>,
1887       private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1888   friend class OMPClauseReader;
1889   friend OMPVarListClause;
1890   friend TrailingObjects;
1891 
1892   /// Build clause with number of variables \a N.
1893   ///
1894   /// \param StartLoc Starting location of the clause.
1895   /// \param LParenLoc Location of '('.
1896   /// \param EndLoc Ending location of the clause.
1897   /// \param N Number of the variables in the clause.
OMPPrivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)1898   OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1899                    SourceLocation EndLoc, unsigned N)
1900       : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1901                                            EndLoc, N) {}
1902 
1903   /// Build an empty clause.
1904   ///
1905   /// \param N Number of variables.
OMPPrivateClause(unsigned N)1906   explicit OMPPrivateClause(unsigned N)
1907       : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
1908                                            SourceLocation(), SourceLocation(),
1909                                            N) {}
1910 
1911   /// Sets the list of references to private copies with initializers for
1912   /// new private variables.
1913   /// \param VL List of references.
1914   void setPrivateCopies(ArrayRef<Expr *> VL);
1915 
1916   /// Gets the list of references to private copies with initializers for
1917   /// new private variables.
getPrivateCopies()1918   MutableArrayRef<Expr *> getPrivateCopies() {
1919     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1920   }
getPrivateCopies()1921   ArrayRef<const Expr *> getPrivateCopies() const {
1922     return llvm::makeArrayRef(varlist_end(), varlist_size());
1923   }
1924 
1925 public:
1926   /// Creates clause with a list of variables \a VL.
1927   ///
1928   /// \param C AST context.
1929   /// \param StartLoc Starting location of the clause.
1930   /// \param LParenLoc Location of '('.
1931   /// \param EndLoc Ending location of the clause.
1932   /// \param VL List of references to the variables.
1933   /// \param PrivateVL List of references to private copies with initializers.
1934   static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1935                                   SourceLocation LParenLoc,
1936                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
1937                                   ArrayRef<Expr *> PrivateVL);
1938 
1939   /// Creates an empty clause with the place for \a N variables.
1940   ///
1941   /// \param C AST context.
1942   /// \param N The number of variables.
1943   static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1944 
1945   using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
1946   using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
1947   using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1948   using private_copies_const_range =
1949       llvm::iterator_range<private_copies_const_iterator>;
1950 
private_copies()1951   private_copies_range private_copies() {
1952     return private_copies_range(getPrivateCopies().begin(),
1953                                 getPrivateCopies().end());
1954   }
1955 
private_copies()1956   private_copies_const_range private_copies() const {
1957     return private_copies_const_range(getPrivateCopies().begin(),
1958                                       getPrivateCopies().end());
1959   }
1960 
children()1961   child_range children() {
1962     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1963                        reinterpret_cast<Stmt **>(varlist_end()));
1964   }
1965 
children()1966   const_child_range children() const {
1967     auto Children = const_cast<OMPPrivateClause *>(this)->children();
1968     return const_child_range(Children.begin(), Children.end());
1969   }
1970 
used_children()1971   child_range used_children() {
1972     return child_range(child_iterator(), child_iterator());
1973   }
used_children()1974   const_child_range used_children() const {
1975     return const_child_range(const_child_iterator(), const_child_iterator());
1976   }
1977 
classof(const OMPClause * T)1978   static bool classof(const OMPClause *T) {
1979     return T->getClauseKind() == OMPC_private;
1980   }
1981 };
1982 
1983 /// This represents clause 'firstprivate' in the '#pragma omp ...'
1984 /// directives.
1985 ///
1986 /// \code
1987 /// #pragma omp parallel firstprivate(a,b)
1988 /// \endcode
1989 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1990 /// with the variables 'a' and 'b'.
1991 class OMPFirstprivateClause final
1992     : public OMPVarListClause<OMPFirstprivateClause>,
1993       public OMPClauseWithPreInit,
1994       private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1995   friend class OMPClauseReader;
1996   friend OMPVarListClause;
1997   friend TrailingObjects;
1998 
1999   /// Build clause with number of variables \a N.
2000   ///
2001   /// \param StartLoc Starting location of the clause.
2002   /// \param LParenLoc Location of '('.
2003   /// \param EndLoc Ending location of the clause.
2004   /// \param N Number of the variables in the clause.
OMPFirstprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)2005   OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2006                         SourceLocation EndLoc, unsigned N)
2007       : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
2008                                                 LParenLoc, EndLoc, N),
2009         OMPClauseWithPreInit(this) {}
2010 
2011   /// Build an empty clause.
2012   ///
2013   /// \param N Number of variables.
OMPFirstprivateClause(unsigned N)2014   explicit OMPFirstprivateClause(unsigned N)
2015       : OMPVarListClause<OMPFirstprivateClause>(
2016             OMPC_firstprivate, SourceLocation(), SourceLocation(),
2017             SourceLocation(), N),
2018         OMPClauseWithPreInit(this) {}
2019 
2020   /// Sets the list of references to private copies with initializers for
2021   /// new private variables.
2022   /// \param VL List of references.
2023   void setPrivateCopies(ArrayRef<Expr *> VL);
2024 
2025   /// Gets the list of references to private copies with initializers for
2026   /// new private variables.
getPrivateCopies()2027   MutableArrayRef<Expr *> getPrivateCopies() {
2028     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2029   }
getPrivateCopies()2030   ArrayRef<const Expr *> getPrivateCopies() const {
2031     return llvm::makeArrayRef(varlist_end(), varlist_size());
2032   }
2033 
2034   /// Sets the list of references to initializer variables for new
2035   /// private variables.
2036   /// \param VL List of references.
2037   void setInits(ArrayRef<Expr *> VL);
2038 
2039   /// Gets the list of references to initializer variables for new
2040   /// private variables.
getInits()2041   MutableArrayRef<Expr *> getInits() {
2042     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2043   }
getInits()2044   ArrayRef<const Expr *> getInits() const {
2045     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2046   }
2047 
2048 public:
2049   /// Creates clause with a list of variables \a VL.
2050   ///
2051   /// \param C AST context.
2052   /// \param StartLoc Starting location of the clause.
2053   /// \param LParenLoc Location of '('.
2054   /// \param EndLoc Ending location of the clause.
2055   /// \param VL List of references to the original variables.
2056   /// \param PrivateVL List of references to private copies with initializers.
2057   /// \param InitVL List of references to auto generated variables used for
2058   /// initialization of a single array element. Used if firstprivate variable is
2059   /// of array type.
2060   /// \param PreInit Statement that must be executed before entering the OpenMP
2061   /// region with this clause.
2062   static OMPFirstprivateClause *
2063   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2064          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2065          ArrayRef<Expr *> InitVL, Stmt *PreInit);
2066 
2067   /// Creates an empty clause with the place for \a N variables.
2068   ///
2069   /// \param C AST context.
2070   /// \param N The number of variables.
2071   static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2072 
2073   using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
2074   using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
2075   using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2076   using private_copies_const_range =
2077       llvm::iterator_range<private_copies_const_iterator>;
2078 
private_copies()2079   private_copies_range private_copies() {
2080     return private_copies_range(getPrivateCopies().begin(),
2081                                 getPrivateCopies().end());
2082   }
private_copies()2083   private_copies_const_range private_copies() const {
2084     return private_copies_const_range(getPrivateCopies().begin(),
2085                                       getPrivateCopies().end());
2086   }
2087 
2088   using inits_iterator = MutableArrayRef<Expr *>::iterator;
2089   using inits_const_iterator = ArrayRef<const Expr *>::iterator;
2090   using inits_range = llvm::iterator_range<inits_iterator>;
2091   using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2092 
inits()2093   inits_range inits() {
2094     return inits_range(getInits().begin(), getInits().end());
2095   }
inits()2096   inits_const_range inits() const {
2097     return inits_const_range(getInits().begin(), getInits().end());
2098   }
2099 
children()2100   child_range children() {
2101     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2102                        reinterpret_cast<Stmt **>(varlist_end()));
2103   }
2104 
children()2105   const_child_range children() const {
2106     auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2107     return const_child_range(Children.begin(), Children.end());
2108   }
2109 
used_children()2110   child_range used_children() {
2111     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2112                        reinterpret_cast<Stmt **>(varlist_end()));
2113   }
used_children()2114   const_child_range used_children() const {
2115     auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2116     return const_child_range(Children.begin(), Children.end());
2117   }
2118 
classof(const OMPClause * T)2119   static bool classof(const OMPClause *T) {
2120     return T->getClauseKind() == OMPC_firstprivate;
2121   }
2122 };
2123 
2124 /// This represents clause 'lastprivate' in the '#pragma omp ...'
2125 /// directives.
2126 ///
2127 /// \code
2128 /// #pragma omp simd lastprivate(a,b)
2129 /// \endcode
2130 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
2131 /// with the variables 'a' and 'b'.
2132 class OMPLastprivateClause final
2133     : public OMPVarListClause<OMPLastprivateClause>,
2134       public OMPClauseWithPostUpdate,
2135       private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2136   // There are 4 additional tail-allocated arrays at the end of the class:
2137   // 1. Contains list of pseudo variables with the default initialization for
2138   // each non-firstprivate variables. Used in codegen for initialization of
2139   // lastprivate copies.
2140   // 2. List of helper expressions for proper generation of assignment operation
2141   // required for lastprivate clause. This list represents private variables
2142   // (for arrays, single array element).
2143   // 3. List of helper expressions for proper generation of assignment operation
2144   // required for lastprivate clause. This list represents original variables
2145   // (for arrays, single array element).
2146   // 4. List of helper expressions that represents assignment operation:
2147   // \code
2148   // DstExprs = SrcExprs;
2149   // \endcode
2150   // Required for proper codegen of final assignment performed by the
2151   // lastprivate clause.
2152   friend class OMPClauseReader;
2153   friend OMPVarListClause;
2154   friend TrailingObjects;
2155 
2156   /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2157   OpenMPLastprivateModifier LPKind;
2158   /// Optional location of the lasptrivate kind, if specified by user.
2159   SourceLocation LPKindLoc;
2160   /// Optional colon location, if specified by user.
2161   SourceLocation ColonLoc;
2162 
2163   /// Build clause with number of variables \a N.
2164   ///
2165   /// \param StartLoc Starting location of the clause.
2166   /// \param LParenLoc Location of '('.
2167   /// \param EndLoc Ending location of the clause.
2168   /// \param N Number of the variables in the clause.
OMPLastprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,OpenMPLastprivateModifier LPKind,SourceLocation LPKindLoc,SourceLocation ColonLoc,unsigned N)2169   OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2170                        SourceLocation EndLoc, OpenMPLastprivateModifier LPKind,
2171                        SourceLocation LPKindLoc, SourceLocation ColonLoc,
2172                        unsigned N)
2173       : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
2174                                                LParenLoc, EndLoc, N),
2175         OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2176         ColonLoc(ColonLoc) {}
2177 
2178   /// Build an empty clause.
2179   ///
2180   /// \param N Number of variables.
OMPLastprivateClause(unsigned N)2181   explicit OMPLastprivateClause(unsigned N)
2182       : OMPVarListClause<OMPLastprivateClause>(
2183             OMPC_lastprivate, SourceLocation(), SourceLocation(),
2184             SourceLocation(), N),
2185         OMPClauseWithPostUpdate(this) {}
2186 
2187   /// Get the list of helper expressions for initialization of private
2188   /// copies for lastprivate variables.
getPrivateCopies()2189   MutableArrayRef<Expr *> getPrivateCopies() {
2190     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2191   }
getPrivateCopies()2192   ArrayRef<const Expr *> getPrivateCopies() const {
2193     return llvm::makeArrayRef(varlist_end(), varlist_size());
2194   }
2195 
2196   /// Set list of helper expressions, required for proper codegen of the
2197   /// clause. These expressions represent private variables (for arrays, single
2198   /// array element) in the final assignment statement performed by the
2199   /// lastprivate clause.
2200   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2201 
2202   /// Get the list of helper source expressions.
getSourceExprs()2203   MutableArrayRef<Expr *> getSourceExprs() {
2204     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2205   }
getSourceExprs()2206   ArrayRef<const Expr *> getSourceExprs() const {
2207     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2208   }
2209 
2210   /// Set list of helper expressions, required for proper codegen of the
2211   /// clause. These expressions represent original variables (for arrays, single
2212   /// array element) in the final assignment statement performed by the
2213   /// lastprivate clause.
2214   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2215 
2216   /// Get the list of helper destination expressions.
getDestinationExprs()2217   MutableArrayRef<Expr *> getDestinationExprs() {
2218     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2219   }
getDestinationExprs()2220   ArrayRef<const Expr *> getDestinationExprs() const {
2221     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2222   }
2223 
2224   /// Set list of helper assignment expressions, required for proper
2225   /// codegen of the clause. These expressions are assignment expressions that
2226   /// assign private copy of the variable to original variable.
2227   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2228 
2229   /// Get the list of helper assignment expressions.
getAssignmentOps()2230   MutableArrayRef<Expr *> getAssignmentOps() {
2231     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2232   }
getAssignmentOps()2233   ArrayRef<const Expr *> getAssignmentOps() const {
2234     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2235   }
2236 
2237   /// Sets lastprivate kind.
setKind(OpenMPLastprivateModifier Kind)2238   void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
2239   /// Sets location of the lastprivate kind.
setKindLoc(SourceLocation Loc)2240   void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
2241   /// Sets colon symbol location.
setColonLoc(SourceLocation Loc)2242   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2243 
2244 public:
2245   /// Creates clause with a list of variables \a VL.
2246   ///
2247   /// \param C AST context.
2248   /// \param StartLoc Starting location of the clause.
2249   /// \param LParenLoc Location of '('.
2250   /// \param EndLoc Ending location of the clause.
2251   /// \param VL List of references to the variables.
2252   /// \param SrcExprs List of helper expressions for proper generation of
2253   /// assignment operation required for lastprivate clause. This list represents
2254   /// private variables (for arrays, single array element).
2255   /// \param DstExprs List of helper expressions for proper generation of
2256   /// assignment operation required for lastprivate clause. This list represents
2257   /// original variables (for arrays, single array element).
2258   /// \param AssignmentOps List of helper expressions that represents assignment
2259   /// operation:
2260   /// \code
2261   /// DstExprs = SrcExprs;
2262   /// \endcode
2263   /// Required for proper codegen of final assignment performed by the
2264   /// lastprivate clause.
2265   /// \param LPKind Lastprivate kind, e.g. 'conditional'.
2266   /// \param LPKindLoc Location of the lastprivate kind.
2267   /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
2268   /// \param PreInit Statement that must be executed before entering the OpenMP
2269   /// region with this clause.
2270   /// \param PostUpdate Expression that must be executed after exit from the
2271   /// OpenMP region with this clause.
2272   static OMPLastprivateClause *
2273   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2274          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2275          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2276          OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
2277          SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
2278 
2279   /// Creates an empty clause with the place for \a N variables.
2280   ///
2281   /// \param C AST context.
2282   /// \param N The number of variables.
2283   static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2284 
2285   /// Lastprivate kind.
getKind()2286   OpenMPLastprivateModifier getKind() const { return LPKind; }
2287   /// Returns the location of the lastprivate kind.
getKindLoc()2288   SourceLocation getKindLoc() const { return LPKindLoc; }
2289   /// Returns the location of the ':' symbol, if any.
getColonLoc()2290   SourceLocation getColonLoc() const { return ColonLoc; }
2291 
2292   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2293   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2294   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2295   using helper_expr_const_range =
2296       llvm::iterator_range<helper_expr_const_iterator>;
2297 
2298   /// Set list of helper expressions, required for generation of private
2299   /// copies of original lastprivate variables.
2300   void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2301 
private_copies()2302   helper_expr_const_range private_copies() const {
2303     return helper_expr_const_range(getPrivateCopies().begin(),
2304                                    getPrivateCopies().end());
2305   }
2306 
private_copies()2307   helper_expr_range private_copies() {
2308     return helper_expr_range(getPrivateCopies().begin(),
2309                              getPrivateCopies().end());
2310   }
2311 
source_exprs()2312   helper_expr_const_range source_exprs() const {
2313     return helper_expr_const_range(getSourceExprs().begin(),
2314                                    getSourceExprs().end());
2315   }
2316 
source_exprs()2317   helper_expr_range source_exprs() {
2318     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2319   }
2320 
destination_exprs()2321   helper_expr_const_range destination_exprs() const {
2322     return helper_expr_const_range(getDestinationExprs().begin(),
2323                                    getDestinationExprs().end());
2324   }
2325 
destination_exprs()2326   helper_expr_range destination_exprs() {
2327     return helper_expr_range(getDestinationExprs().begin(),
2328                              getDestinationExprs().end());
2329   }
2330 
assignment_ops()2331   helper_expr_const_range assignment_ops() const {
2332     return helper_expr_const_range(getAssignmentOps().begin(),
2333                                    getAssignmentOps().end());
2334   }
2335 
assignment_ops()2336   helper_expr_range assignment_ops() {
2337     return helper_expr_range(getAssignmentOps().begin(),
2338                              getAssignmentOps().end());
2339   }
2340 
children()2341   child_range children() {
2342     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2343                        reinterpret_cast<Stmt **>(varlist_end()));
2344   }
2345 
children()2346   const_child_range children() const {
2347     auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2348     return const_child_range(Children.begin(), Children.end());
2349   }
2350 
used_children()2351   child_range used_children() {
2352     return child_range(child_iterator(), child_iterator());
2353   }
used_children()2354   const_child_range used_children() const {
2355     return const_child_range(const_child_iterator(), const_child_iterator());
2356   }
2357 
classof(const OMPClause * T)2358   static bool classof(const OMPClause *T) {
2359     return T->getClauseKind() == OMPC_lastprivate;
2360   }
2361 };
2362 
2363 /// This represents clause 'shared' in the '#pragma omp ...' directives.
2364 ///
2365 /// \code
2366 /// #pragma omp parallel shared(a,b)
2367 /// \endcode
2368 /// In this example directive '#pragma omp parallel' has clause 'shared'
2369 /// with the variables 'a' and 'b'.
2370 class OMPSharedClause final
2371     : public OMPVarListClause<OMPSharedClause>,
2372       private llvm::TrailingObjects<OMPSharedClause, Expr *> {
2373   friend OMPVarListClause;
2374   friend TrailingObjects;
2375 
2376   /// Build clause with number of variables \a N.
2377   ///
2378   /// \param StartLoc Starting location of the clause.
2379   /// \param LParenLoc Location of '('.
2380   /// \param EndLoc Ending location of the clause.
2381   /// \param N Number of the variables in the clause.
OMPSharedClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)2382   OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2383                   SourceLocation EndLoc, unsigned N)
2384       : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
2385                                           EndLoc, N) {}
2386 
2387   /// Build an empty clause.
2388   ///
2389   /// \param N Number of variables.
OMPSharedClause(unsigned N)2390   explicit OMPSharedClause(unsigned N)
2391       : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
2392                                           SourceLocation(), SourceLocation(),
2393                                           N) {}
2394 
2395 public:
2396   /// Creates clause with a list of variables \a VL.
2397   ///
2398   /// \param C AST context.
2399   /// \param StartLoc Starting location of the clause.
2400   /// \param LParenLoc Location of '('.
2401   /// \param EndLoc Ending location of the clause.
2402   /// \param VL List of references to the variables.
2403   static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2404                                  SourceLocation LParenLoc,
2405                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
2406 
2407   /// Creates an empty clause with \a N variables.
2408   ///
2409   /// \param C AST context.
2410   /// \param N The number of variables.
2411   static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
2412 
children()2413   child_range children() {
2414     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2415                        reinterpret_cast<Stmt **>(varlist_end()));
2416   }
2417 
children()2418   const_child_range children() const {
2419     auto Children = const_cast<OMPSharedClause *>(this)->children();
2420     return const_child_range(Children.begin(), Children.end());
2421   }
2422 
used_children()2423   child_range used_children() {
2424     return child_range(child_iterator(), child_iterator());
2425   }
used_children()2426   const_child_range used_children() const {
2427     return const_child_range(const_child_iterator(), const_child_iterator());
2428   }
2429 
classof(const OMPClause * T)2430   static bool classof(const OMPClause *T) {
2431     return T->getClauseKind() == OMPC_shared;
2432   }
2433 };
2434 
2435 /// This represents clause 'reduction' in the '#pragma omp ...'
2436 /// directives.
2437 ///
2438 /// \code
2439 /// #pragma omp parallel reduction(+:a,b)
2440 /// \endcode
2441 /// In this example directive '#pragma omp parallel' has clause 'reduction'
2442 /// with operator '+' and the variables 'a' and 'b'.
2443 class OMPReductionClause final
2444     : public OMPVarListClause<OMPReductionClause>,
2445       public OMPClauseWithPostUpdate,
2446       private llvm::TrailingObjects<OMPReductionClause, Expr *> {
2447   friend class OMPClauseReader;
2448   friend OMPVarListClause;
2449   friend TrailingObjects;
2450 
2451   /// Location of ':'.
2452   SourceLocation ColonLoc;
2453 
2454   /// Nested name specifier for C++.
2455   NestedNameSpecifierLoc QualifierLoc;
2456 
2457   /// Name of custom operator.
2458   DeclarationNameInfo NameInfo;
2459 
2460   /// Build clause with number of variables \a N.
2461   ///
2462   /// \param StartLoc Starting location of the clause.
2463   /// \param LParenLoc Location of '('.
2464   /// \param EndLoc Ending location of the clause.
2465   /// \param ColonLoc Location of ':'.
2466   /// \param N Number of the variables in the clause.
2467   /// \param QualifierLoc The nested-name qualifier with location information
2468   /// \param NameInfo The full name info for reduction identifier.
OMPReductionClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned N,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo)2469   OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2470                      SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
2471                      NestedNameSpecifierLoc QualifierLoc,
2472                      const DeclarationNameInfo &NameInfo)
2473       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
2474                                              LParenLoc, EndLoc, N),
2475         OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2476         QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2477 
2478   /// Build an empty clause.
2479   ///
2480   /// \param N Number of variables.
OMPReductionClause(unsigned N)2481   explicit OMPReductionClause(unsigned N)
2482       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
2483                                              SourceLocation(), SourceLocation(),
2484                                              N),
2485         OMPClauseWithPostUpdate(this) {}
2486 
2487   /// Sets location of ':' symbol in clause.
setColonLoc(SourceLocation CL)2488   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2489 
2490   /// Sets the name info for specified reduction identifier.
setNameInfo(DeclarationNameInfo DNI)2491   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2492 
2493   /// Sets the nested name specifier.
setQualifierLoc(NestedNameSpecifierLoc NSL)2494   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2495 
2496   /// Set list of helper expressions, required for proper codegen of the
2497   /// clause. These expressions represent private copy of the reduction
2498   /// variable.
2499   void setPrivates(ArrayRef<Expr *> Privates);
2500 
2501   /// Get the list of helper privates.
getPrivates()2502   MutableArrayRef<Expr *> getPrivates() {
2503     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2504   }
getPrivates()2505   ArrayRef<const Expr *> getPrivates() const {
2506     return llvm::makeArrayRef(varlist_end(), varlist_size());
2507   }
2508 
2509   /// Set list of helper expressions, required for proper codegen of the
2510   /// clause. These expressions represent LHS expression in the final
2511   /// reduction expression performed by the reduction clause.
2512   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2513 
2514   /// Get the list of helper LHS expressions.
getLHSExprs()2515   MutableArrayRef<Expr *> getLHSExprs() {
2516     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2517   }
getLHSExprs()2518   ArrayRef<const Expr *> getLHSExprs() const {
2519     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2520   }
2521 
2522   /// Set list of helper expressions, required for proper codegen of the
2523   /// clause. These expressions represent RHS expression in the final
2524   /// reduction expression performed by the reduction clause.
2525   /// Also, variables in these expressions are used for proper initialization of
2526   /// reduction copies.
2527   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2528 
2529   /// Get the list of helper destination expressions.
getRHSExprs()2530   MutableArrayRef<Expr *> getRHSExprs() {
2531     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2532   }
getRHSExprs()2533   ArrayRef<const Expr *> getRHSExprs() const {
2534     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2535   }
2536 
2537   /// Set list of helper reduction expressions, required for proper
2538   /// codegen of the clause. These expressions are binary expressions or
2539   /// operator/custom reduction call that calculates new value from source
2540   /// helper expressions to destination helper expressions.
2541   void setReductionOps(ArrayRef<Expr *> ReductionOps);
2542 
2543   /// Get the list of helper reduction expressions.
getReductionOps()2544   MutableArrayRef<Expr *> getReductionOps() {
2545     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2546   }
getReductionOps()2547   ArrayRef<const Expr *> getReductionOps() const {
2548     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2549   }
2550 
2551 public:
2552   /// Creates clause with a list of variables \a VL.
2553   ///
2554   /// \param StartLoc Starting location of the clause.
2555   /// \param LParenLoc Location of '('.
2556   /// \param ColonLoc Location of ':'.
2557   /// \param EndLoc Ending location of the clause.
2558   /// \param VL The variables in the clause.
2559   /// \param QualifierLoc The nested-name qualifier with location information
2560   /// \param NameInfo The full name info for reduction identifier.
2561   /// \param Privates List of helper expressions for proper generation of
2562   /// private copies.
2563   /// \param LHSExprs List of helper expressions for proper generation of
2564   /// assignment operation required for copyprivate clause. This list represents
2565   /// LHSs of the reduction expressions.
2566   /// \param RHSExprs List of helper expressions for proper generation of
2567   /// assignment operation required for copyprivate clause. This list represents
2568   /// RHSs of the reduction expressions.
2569   /// Also, variables in these expressions are used for proper initialization of
2570   /// reduction copies.
2571   /// \param ReductionOps List of helper expressions that represents reduction
2572   /// expressions:
2573   /// \code
2574   /// LHSExprs binop RHSExprs;
2575   /// operator binop(LHSExpr, RHSExpr);
2576   /// <CutomReduction>(LHSExpr, RHSExpr);
2577   /// \endcode
2578   /// Required for proper codegen of final reduction operation performed by the
2579   /// reduction clause.
2580   /// \param PreInit Statement that must be executed before entering the OpenMP
2581   /// region with this clause.
2582   /// \param PostUpdate Expression that must be executed after exit from the
2583   /// OpenMP region with this clause.
2584   static OMPReductionClause *
2585   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2586          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2587          NestedNameSpecifierLoc QualifierLoc,
2588          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2589          ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2590          ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2591 
2592   /// Creates an empty clause with the place for \a N variables.
2593   ///
2594   /// \param C AST context.
2595   /// \param N The number of variables.
2596   static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2597 
2598   /// Gets location of ':' symbol in clause.
getColonLoc()2599   SourceLocation getColonLoc() const { return ColonLoc; }
2600 
2601   /// Gets the name info for specified reduction identifier.
getNameInfo()2602   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2603 
2604   /// Gets the nested name specifier.
getQualifierLoc()2605   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2606 
2607   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2608   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2609   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2610   using helper_expr_const_range =
2611       llvm::iterator_range<helper_expr_const_iterator>;
2612 
privates()2613   helper_expr_const_range privates() const {
2614     return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2615   }
2616 
privates()2617   helper_expr_range privates() {
2618     return helper_expr_range(getPrivates().begin(), getPrivates().end());
2619   }
2620 
lhs_exprs()2621   helper_expr_const_range lhs_exprs() const {
2622     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2623   }
2624 
lhs_exprs()2625   helper_expr_range lhs_exprs() {
2626     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2627   }
2628 
rhs_exprs()2629   helper_expr_const_range rhs_exprs() const {
2630     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2631   }
2632 
rhs_exprs()2633   helper_expr_range rhs_exprs() {
2634     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2635   }
2636 
reduction_ops()2637   helper_expr_const_range reduction_ops() const {
2638     return helper_expr_const_range(getReductionOps().begin(),
2639                                    getReductionOps().end());
2640   }
2641 
reduction_ops()2642   helper_expr_range reduction_ops() {
2643     return helper_expr_range(getReductionOps().begin(),
2644                              getReductionOps().end());
2645   }
2646 
children()2647   child_range children() {
2648     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2649                        reinterpret_cast<Stmt **>(varlist_end()));
2650   }
2651 
children()2652   const_child_range children() const {
2653     auto Children = const_cast<OMPReductionClause *>(this)->children();
2654     return const_child_range(Children.begin(), Children.end());
2655   }
2656 
used_children()2657   child_range used_children() {
2658     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2659                        reinterpret_cast<Stmt **>(varlist_end()));
2660   }
used_children()2661   const_child_range used_children() const {
2662     auto Children = const_cast<OMPReductionClause *>(this)->used_children();
2663     return const_child_range(Children.begin(), Children.end());
2664   }
2665 
classof(const OMPClause * T)2666   static bool classof(const OMPClause *T) {
2667     return T->getClauseKind() == OMPC_reduction;
2668   }
2669 };
2670 
2671 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
2672 /// directives.
2673 ///
2674 /// \code
2675 /// #pragma omp taskgroup task_reduction(+:a,b)
2676 /// \endcode
2677 /// In this example directive '#pragma omp taskgroup' has clause
2678 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
2679 class OMPTaskReductionClause final
2680     : public OMPVarListClause<OMPTaskReductionClause>,
2681       public OMPClauseWithPostUpdate,
2682       private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
2683   friend class OMPClauseReader;
2684   friend OMPVarListClause;
2685   friend TrailingObjects;
2686 
2687   /// Location of ':'.
2688   SourceLocation ColonLoc;
2689 
2690   /// Nested name specifier for C++.
2691   NestedNameSpecifierLoc QualifierLoc;
2692 
2693   /// Name of custom operator.
2694   DeclarationNameInfo NameInfo;
2695 
2696   /// Build clause with number of variables \a N.
2697   ///
2698   /// \param StartLoc Starting location of the clause.
2699   /// \param LParenLoc Location of '('.
2700   /// \param EndLoc Ending location of the clause.
2701   /// \param ColonLoc Location of ':'.
2702   /// \param N Number of the variables in the clause.
2703   /// \param QualifierLoc The nested-name qualifier with location information
2704   /// \param NameInfo The full name info for reduction identifier.
OMPTaskReductionClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned N,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo)2705   OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2706                          SourceLocation ColonLoc, SourceLocation EndLoc,
2707                          unsigned N, NestedNameSpecifierLoc QualifierLoc,
2708                          const DeclarationNameInfo &NameInfo)
2709       : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
2710                                                  LParenLoc, EndLoc, N),
2711         OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2712         QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2713 
2714   /// Build an empty clause.
2715   ///
2716   /// \param N Number of variables.
OMPTaskReductionClause(unsigned N)2717   explicit OMPTaskReductionClause(unsigned N)
2718       : OMPVarListClause<OMPTaskReductionClause>(
2719             OMPC_task_reduction, SourceLocation(), SourceLocation(),
2720             SourceLocation(), N),
2721         OMPClauseWithPostUpdate(this) {}
2722 
2723   /// Sets location of ':' symbol in clause.
setColonLoc(SourceLocation CL)2724   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2725 
2726   /// Sets the name info for specified reduction identifier.
setNameInfo(DeclarationNameInfo DNI)2727   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2728 
2729   /// Sets the nested name specifier.
setQualifierLoc(NestedNameSpecifierLoc NSL)2730   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2731 
2732   /// Set list of helper expressions, required for proper codegen of the clause.
2733   /// These expressions represent private copy of the reduction variable.
2734   void setPrivates(ArrayRef<Expr *> Privates);
2735 
2736   /// Get the list of helper privates.
getPrivates()2737   MutableArrayRef<Expr *> getPrivates() {
2738     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2739   }
getPrivates()2740   ArrayRef<const Expr *> getPrivates() const {
2741     return llvm::makeArrayRef(varlist_end(), varlist_size());
2742   }
2743 
2744   /// Set list of helper expressions, required for proper codegen of the clause.
2745   /// These expressions represent LHS expression in the final reduction
2746   /// expression performed by the reduction clause.
2747   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2748 
2749   /// Get the list of helper LHS expressions.
getLHSExprs()2750   MutableArrayRef<Expr *> getLHSExprs() {
2751     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2752   }
getLHSExprs()2753   ArrayRef<const Expr *> getLHSExprs() const {
2754     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2755   }
2756 
2757   /// Set list of helper expressions, required for proper codegen of the clause.
2758   /// These expressions represent RHS expression in the final reduction
2759   /// expression performed by the reduction clause. Also, variables in these
2760   /// expressions are used for proper initialization of reduction copies.
2761   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2762 
2763   ///  Get the list of helper destination expressions.
getRHSExprs()2764   MutableArrayRef<Expr *> getRHSExprs() {
2765     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2766   }
getRHSExprs()2767   ArrayRef<const Expr *> getRHSExprs() const {
2768     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2769   }
2770 
2771   /// Set list of helper reduction expressions, required for proper
2772   /// codegen of the clause. These expressions are binary expressions or
2773   /// operator/custom reduction call that calculates new value from source
2774   /// helper expressions to destination helper expressions.
2775   void setReductionOps(ArrayRef<Expr *> ReductionOps);
2776 
2777   ///  Get the list of helper reduction expressions.
getReductionOps()2778   MutableArrayRef<Expr *> getReductionOps() {
2779     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2780   }
getReductionOps()2781   ArrayRef<const Expr *> getReductionOps() const {
2782     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2783   }
2784 
2785 public:
2786   /// Creates clause with a list of variables \a VL.
2787   ///
2788   /// \param StartLoc Starting location of the clause.
2789   /// \param LParenLoc Location of '('.
2790   /// \param ColonLoc Location of ':'.
2791   /// \param EndLoc Ending location of the clause.
2792   /// \param VL The variables in the clause.
2793   /// \param QualifierLoc The nested-name qualifier with location information
2794   /// \param NameInfo The full name info for reduction identifier.
2795   /// \param Privates List of helper expressions for proper generation of
2796   /// private copies.
2797   /// \param LHSExprs List of helper expressions for proper generation of
2798   /// assignment operation required for copyprivate clause. This list represents
2799   /// LHSs of the reduction expressions.
2800   /// \param RHSExprs List of helper expressions for proper generation of
2801   /// assignment operation required for copyprivate clause. This list represents
2802   /// RHSs of the reduction expressions.
2803   /// Also, variables in these expressions are used for proper initialization of
2804   /// reduction copies.
2805   /// \param ReductionOps List of helper expressions that represents reduction
2806   /// expressions:
2807   /// \code
2808   /// LHSExprs binop RHSExprs;
2809   /// operator binop(LHSExpr, RHSExpr);
2810   /// <CutomReduction>(LHSExpr, RHSExpr);
2811   /// \endcode
2812   /// Required for proper codegen of final reduction operation performed by the
2813   /// reduction clause.
2814   /// \param PreInit Statement that must be executed before entering the OpenMP
2815   /// region with this clause.
2816   /// \param PostUpdate Expression that must be executed after exit from the
2817   /// OpenMP region with this clause.
2818   static OMPTaskReductionClause *
2819   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2820          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2821          NestedNameSpecifierLoc QualifierLoc,
2822          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2823          ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2824          ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2825 
2826   /// Creates an empty clause with the place for \a N variables.
2827   ///
2828   /// \param C AST context.
2829   /// \param N The number of variables.
2830   static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2831 
2832   /// Gets location of ':' symbol in clause.
getColonLoc()2833   SourceLocation getColonLoc() const { return ColonLoc; }
2834 
2835   /// Gets the name info for specified reduction identifier.
getNameInfo()2836   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2837 
2838   /// Gets the nested name specifier.
getQualifierLoc()2839   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2840 
2841   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2842   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2843   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2844   using helper_expr_const_range =
2845       llvm::iterator_range<helper_expr_const_iterator>;
2846 
privates()2847   helper_expr_const_range privates() const {
2848     return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2849   }
2850 
privates()2851   helper_expr_range privates() {
2852     return helper_expr_range(getPrivates().begin(), getPrivates().end());
2853   }
2854 
lhs_exprs()2855   helper_expr_const_range lhs_exprs() const {
2856     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2857   }
2858 
lhs_exprs()2859   helper_expr_range lhs_exprs() {
2860     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2861   }
2862 
rhs_exprs()2863   helper_expr_const_range rhs_exprs() const {
2864     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2865   }
2866 
rhs_exprs()2867   helper_expr_range rhs_exprs() {
2868     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2869   }
2870 
reduction_ops()2871   helper_expr_const_range reduction_ops() const {
2872     return helper_expr_const_range(getReductionOps().begin(),
2873                                    getReductionOps().end());
2874   }
2875 
reduction_ops()2876   helper_expr_range reduction_ops() {
2877     return helper_expr_range(getReductionOps().begin(),
2878                              getReductionOps().end());
2879   }
2880 
children()2881   child_range children() {
2882     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2883                        reinterpret_cast<Stmt **>(varlist_end()));
2884   }
2885 
children()2886   const_child_range children() const {
2887     auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
2888     return const_child_range(Children.begin(), Children.end());
2889   }
2890 
used_children()2891   child_range used_children() {
2892     return child_range(child_iterator(), child_iterator());
2893   }
used_children()2894   const_child_range used_children() const {
2895     return const_child_range(const_child_iterator(), const_child_iterator());
2896   }
2897 
classof(const OMPClause * T)2898   static bool classof(const OMPClause *T) {
2899     return T->getClauseKind() == OMPC_task_reduction;
2900   }
2901 };
2902 
2903 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
2904 ///
2905 /// \code
2906 /// #pragma omp task in_reduction(+:a,b)
2907 /// \endcode
2908 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
2909 /// operator '+' and the variables 'a' and 'b'.
2910 class OMPInReductionClause final
2911     : public OMPVarListClause<OMPInReductionClause>,
2912       public OMPClauseWithPostUpdate,
2913       private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
2914   friend class OMPClauseReader;
2915   friend OMPVarListClause;
2916   friend TrailingObjects;
2917 
2918   /// Location of ':'.
2919   SourceLocation ColonLoc;
2920 
2921   /// Nested name specifier for C++.
2922   NestedNameSpecifierLoc QualifierLoc;
2923 
2924   /// Name of custom operator.
2925   DeclarationNameInfo NameInfo;
2926 
2927   /// Build clause with number of variables \a N.
2928   ///
2929   /// \param StartLoc Starting location of the clause.
2930   /// \param LParenLoc Location of '('.
2931   /// \param EndLoc Ending location of the clause.
2932   /// \param ColonLoc Location of ':'.
2933   /// \param N Number of the variables in the clause.
2934   /// \param QualifierLoc The nested-name qualifier with location information
2935   /// \param NameInfo The full name info for reduction identifier.
OMPInReductionClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned N,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo)2936   OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2937                        SourceLocation ColonLoc, SourceLocation EndLoc,
2938                        unsigned N, NestedNameSpecifierLoc QualifierLoc,
2939                        const DeclarationNameInfo &NameInfo)
2940       : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc,
2941                                                LParenLoc, EndLoc, N),
2942         OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2943         QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2944 
2945   /// Build an empty clause.
2946   ///
2947   /// \param N Number of variables.
OMPInReductionClause(unsigned N)2948   explicit OMPInReductionClause(unsigned N)
2949       : OMPVarListClause<OMPInReductionClause>(
2950             OMPC_in_reduction, SourceLocation(), SourceLocation(),
2951             SourceLocation(), N),
2952         OMPClauseWithPostUpdate(this) {}
2953 
2954   /// Sets location of ':' symbol in clause.
setColonLoc(SourceLocation CL)2955   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2956 
2957   /// Sets the name info for specified reduction identifier.
setNameInfo(DeclarationNameInfo DNI)2958   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2959 
2960   /// Sets the nested name specifier.
setQualifierLoc(NestedNameSpecifierLoc NSL)2961   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2962 
2963   /// Set list of helper expressions, required for proper codegen of the clause.
2964   /// These expressions represent private copy of the reduction variable.
2965   void setPrivates(ArrayRef<Expr *> Privates);
2966 
2967   /// Get the list of helper privates.
getPrivates()2968   MutableArrayRef<Expr *> getPrivates() {
2969     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2970   }
getPrivates()2971   ArrayRef<const Expr *> getPrivates() const {
2972     return llvm::makeArrayRef(varlist_end(), varlist_size());
2973   }
2974 
2975   /// Set list of helper expressions, required for proper codegen of the clause.
2976   /// These expressions represent LHS expression in the final reduction
2977   /// expression performed by the reduction clause.
2978   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2979 
2980   /// Get the list of helper LHS expressions.
getLHSExprs()2981   MutableArrayRef<Expr *> getLHSExprs() {
2982     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2983   }
getLHSExprs()2984   ArrayRef<const Expr *> getLHSExprs() const {
2985     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2986   }
2987 
2988   /// Set list of helper expressions, required for proper codegen of the clause.
2989   /// These expressions represent RHS expression in the final reduction
2990   /// expression performed by the reduction clause. Also, variables in these
2991   /// expressions are used for proper initialization of reduction copies.
2992   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2993 
2994   ///  Get the list of helper destination expressions.
getRHSExprs()2995   MutableArrayRef<Expr *> getRHSExprs() {
2996     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2997   }
getRHSExprs()2998   ArrayRef<const Expr *> getRHSExprs() const {
2999     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3000   }
3001 
3002   /// Set list of helper reduction expressions, required for proper
3003   /// codegen of the clause. These expressions are binary expressions or
3004   /// operator/custom reduction call that calculates new value from source
3005   /// helper expressions to destination helper expressions.
3006   void setReductionOps(ArrayRef<Expr *> ReductionOps);
3007 
3008   ///  Get the list of helper reduction expressions.
getReductionOps()3009   MutableArrayRef<Expr *> getReductionOps() {
3010     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3011   }
getReductionOps()3012   ArrayRef<const Expr *> getReductionOps() const {
3013     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3014   }
3015 
3016   /// Set list of helper reduction taskgroup descriptors.
3017   void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3018 
3019   ///  Get the list of helper reduction taskgroup descriptors.
getTaskgroupDescriptors()3020   MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3021     return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3022   }
getTaskgroupDescriptors()3023   ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3024     return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3025   }
3026 
3027 public:
3028   /// Creates clause with a list of variables \a VL.
3029   ///
3030   /// \param StartLoc Starting location of the clause.
3031   /// \param LParenLoc Location of '('.
3032   /// \param ColonLoc Location of ':'.
3033   /// \param EndLoc Ending location of the clause.
3034   /// \param VL The variables in the clause.
3035   /// \param QualifierLoc The nested-name qualifier with location information
3036   /// \param NameInfo The full name info for reduction identifier.
3037   /// \param Privates List of helper expressions for proper generation of
3038   /// private copies.
3039   /// \param LHSExprs List of helper expressions for proper generation of
3040   /// assignment operation required for copyprivate clause. This list represents
3041   /// LHSs of the reduction expressions.
3042   /// \param RHSExprs List of helper expressions for proper generation of
3043   /// assignment operation required for copyprivate clause. This list represents
3044   /// RHSs of the reduction expressions.
3045   /// Also, variables in these expressions are used for proper initialization of
3046   /// reduction copies.
3047   /// \param ReductionOps List of helper expressions that represents reduction
3048   /// expressions:
3049   /// \code
3050   /// LHSExprs binop RHSExprs;
3051   /// operator binop(LHSExpr, RHSExpr);
3052   /// <CutomReduction>(LHSExpr, RHSExpr);
3053   /// \endcode
3054   /// Required for proper codegen of final reduction operation performed by the
3055   /// reduction clause.
3056   /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3057   /// corresponding items in parent taskgroup task_reduction clause.
3058   /// \param PreInit Statement that must be executed before entering the OpenMP
3059   /// region with this clause.
3060   /// \param PostUpdate Expression that must be executed after exit from the
3061   /// OpenMP region with this clause.
3062   static OMPInReductionClause *
3063   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3064          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3065          NestedNameSpecifierLoc QualifierLoc,
3066          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3067          ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3068          ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3069          Stmt *PreInit, Expr *PostUpdate);
3070 
3071   /// Creates an empty clause with the place for \a N variables.
3072   ///
3073   /// \param C AST context.
3074   /// \param N The number of variables.
3075   static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3076 
3077   /// Gets location of ':' symbol in clause.
getColonLoc()3078   SourceLocation getColonLoc() const { return ColonLoc; }
3079 
3080   /// Gets the name info for specified reduction identifier.
getNameInfo()3081   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3082 
3083   /// Gets the nested name specifier.
getQualifierLoc()3084   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3085 
3086   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3087   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3088   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3089   using helper_expr_const_range =
3090       llvm::iterator_range<helper_expr_const_iterator>;
3091 
privates()3092   helper_expr_const_range privates() const {
3093     return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3094   }
3095 
privates()3096   helper_expr_range privates() {
3097     return helper_expr_range(getPrivates().begin(), getPrivates().end());
3098   }
3099 
lhs_exprs()3100   helper_expr_const_range lhs_exprs() const {
3101     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3102   }
3103 
lhs_exprs()3104   helper_expr_range lhs_exprs() {
3105     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3106   }
3107 
rhs_exprs()3108   helper_expr_const_range rhs_exprs() const {
3109     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3110   }
3111 
rhs_exprs()3112   helper_expr_range rhs_exprs() {
3113     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3114   }
3115 
reduction_ops()3116   helper_expr_const_range reduction_ops() const {
3117     return helper_expr_const_range(getReductionOps().begin(),
3118                                    getReductionOps().end());
3119   }
3120 
reduction_ops()3121   helper_expr_range reduction_ops() {
3122     return helper_expr_range(getReductionOps().begin(),
3123                              getReductionOps().end());
3124   }
3125 
taskgroup_descriptors()3126   helper_expr_const_range taskgroup_descriptors() const {
3127     return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3128                                    getTaskgroupDescriptors().end());
3129   }
3130 
taskgroup_descriptors()3131   helper_expr_range taskgroup_descriptors() {
3132     return helper_expr_range(getTaskgroupDescriptors().begin(),
3133                              getTaskgroupDescriptors().end());
3134   }
3135 
children()3136   child_range children() {
3137     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3138                        reinterpret_cast<Stmt **>(varlist_end()));
3139   }
3140 
children()3141   const_child_range children() const {
3142     auto Children = const_cast<OMPInReductionClause *>(this)->children();
3143     return const_child_range(Children.begin(), Children.end());
3144   }
3145 
used_children()3146   child_range used_children() {
3147     return child_range(child_iterator(), child_iterator());
3148   }
used_children()3149   const_child_range used_children() const {
3150     return const_child_range(const_child_iterator(), const_child_iterator());
3151   }
3152 
classof(const OMPClause * T)3153   static bool classof(const OMPClause *T) {
3154     return T->getClauseKind() == OMPC_in_reduction;
3155   }
3156 };
3157 
3158 /// This represents clause 'linear' in the '#pragma omp ...'
3159 /// directives.
3160 ///
3161 /// \code
3162 /// #pragma omp simd linear(a,b : 2)
3163 /// \endcode
3164 /// In this example directive '#pragma omp simd' has clause 'linear'
3165 /// with variables 'a', 'b' and linear step '2'.
3166 class OMPLinearClause final
3167     : public OMPVarListClause<OMPLinearClause>,
3168       public OMPClauseWithPostUpdate,
3169       private llvm::TrailingObjects<OMPLinearClause, Expr *> {
3170   friend class OMPClauseReader;
3171   friend OMPVarListClause;
3172   friend TrailingObjects;
3173 
3174   /// Modifier of 'linear' clause.
3175   OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
3176 
3177   /// Location of linear modifier if any.
3178   SourceLocation ModifierLoc;
3179 
3180   /// Location of ':'.
3181   SourceLocation ColonLoc;
3182 
3183   /// Sets the linear step for clause.
setStep(Expr * Step)3184   void setStep(Expr *Step) { *(getFinals().end()) = Step; }
3185 
3186   /// Sets the expression to calculate linear step for clause.
setCalcStep(Expr * CalcStep)3187   void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
3188 
3189   /// Build 'linear' clause with given number of variables \a NumVars.
3190   ///
3191   /// \param StartLoc Starting location of the clause.
3192   /// \param LParenLoc Location of '('.
3193   /// \param ColonLoc Location of ':'.
3194   /// \param EndLoc Ending location of the clause.
3195   /// \param NumVars Number of variables.
OMPLinearClause(SourceLocation StartLoc,SourceLocation LParenLoc,OpenMPLinearClauseKind Modifier,SourceLocation ModifierLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned NumVars)3196   OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3197                   OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3198                   SourceLocation ColonLoc, SourceLocation EndLoc,
3199                   unsigned NumVars)
3200       : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
3201                                           EndLoc, NumVars),
3202         OMPClauseWithPostUpdate(this), Modifier(Modifier),
3203         ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
3204 
3205   /// Build an empty clause.
3206   ///
3207   /// \param NumVars Number of variables.
OMPLinearClause(unsigned NumVars)3208   explicit OMPLinearClause(unsigned NumVars)
3209       : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
3210                                           SourceLocation(), SourceLocation(),
3211                                           NumVars),
3212         OMPClauseWithPostUpdate(this) {}
3213 
3214   /// Gets the list of initial values for linear variables.
3215   ///
3216   /// There are NumVars expressions with initial values allocated after the
3217   /// varlist, they are followed by NumVars update expressions (used to update
3218   /// the linear variable's value on current iteration) and they are followed by
3219   /// NumVars final expressions (used to calculate the linear variable's
3220   /// value after the loop body). After these lists, there are 2 helper
3221   /// expressions - linear step and a helper to calculate it before the
3222   /// loop body (used when the linear step is not constant):
3223   ///
3224   /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
3225   /// Finals[]; Step; CalcStep; }
getPrivates()3226   MutableArrayRef<Expr *> getPrivates() {
3227     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3228   }
getPrivates()3229   ArrayRef<const Expr *> getPrivates() const {
3230     return llvm::makeArrayRef(varlist_end(), varlist_size());
3231   }
3232 
getInits()3233   MutableArrayRef<Expr *> getInits() {
3234     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3235   }
getInits()3236   ArrayRef<const Expr *> getInits() const {
3237     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3238   }
3239 
3240   /// Sets the list of update expressions for linear variables.
getUpdates()3241   MutableArrayRef<Expr *> getUpdates() {
3242     return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
3243   }
getUpdates()3244   ArrayRef<const Expr *> getUpdates() const {
3245     return llvm::makeArrayRef(getInits().end(), varlist_size());
3246   }
3247 
3248   /// Sets the list of final update expressions for linear variables.
getFinals()3249   MutableArrayRef<Expr *> getFinals() {
3250     return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
3251   }
getFinals()3252   ArrayRef<const Expr *> getFinals() const {
3253     return llvm::makeArrayRef(getUpdates().end(), varlist_size());
3254   }
3255 
3256   /// Gets the list of used expressions for linear variables.
getUsedExprs()3257   MutableArrayRef<Expr *> getUsedExprs() {
3258     return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
3259   }
getUsedExprs()3260   ArrayRef<const Expr *> getUsedExprs() const {
3261     return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
3262   }
3263 
3264   /// Sets the list of the copies of original linear variables.
3265   /// \param PL List of expressions.
3266   void setPrivates(ArrayRef<Expr *> PL);
3267 
3268   /// Sets the list of the initial values for linear variables.
3269   /// \param IL List of expressions.
3270   void setInits(ArrayRef<Expr *> IL);
3271 
3272 public:
3273   /// Creates clause with a list of variables \a VL and a linear step
3274   /// \a Step.
3275   ///
3276   /// \param C AST Context.
3277   /// \param StartLoc Starting location of the clause.
3278   /// \param LParenLoc Location of '('.
3279   /// \param Modifier Modifier of 'linear' clause.
3280   /// \param ModifierLoc Modifier location.
3281   /// \param ColonLoc Location of ':'.
3282   /// \param EndLoc Ending location of the clause.
3283   /// \param VL List of references to the variables.
3284   /// \param PL List of private copies of original variables.
3285   /// \param IL List of initial values for the variables.
3286   /// \param Step Linear step.
3287   /// \param CalcStep Calculation of the linear step.
3288   /// \param PreInit Statement that must be executed before entering the OpenMP
3289   /// region with this clause.
3290   /// \param PostUpdate Expression that must be executed after exit from the
3291   /// OpenMP region with this clause.
3292   static OMPLinearClause *
3293   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3294          OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3295          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3296          ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
3297          Stmt *PreInit, Expr *PostUpdate);
3298 
3299   /// Creates an empty clause with the place for \a NumVars variables.
3300   ///
3301   /// \param C AST context.
3302   /// \param NumVars Number of variables.
3303   static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3304 
3305   /// Set modifier.
setModifier(OpenMPLinearClauseKind Kind)3306   void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
3307 
3308   /// Return modifier.
getModifier()3309   OpenMPLinearClauseKind getModifier() const { return Modifier; }
3310 
3311   /// Set modifier location.
setModifierLoc(SourceLocation Loc)3312   void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3313 
3314   /// Return modifier location.
getModifierLoc()3315   SourceLocation getModifierLoc() const { return ModifierLoc; }
3316 
3317   /// Sets the location of ':'.
setColonLoc(SourceLocation Loc)3318   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3319 
3320   /// Returns the location of ':'.
getColonLoc()3321   SourceLocation getColonLoc() const { return ColonLoc; }
3322 
3323   /// Returns linear step.
getStep()3324   Expr *getStep() { return *(getFinals().end()); }
3325 
3326   /// Returns linear step.
getStep()3327   const Expr *getStep() const { return *(getFinals().end()); }
3328 
3329   /// Returns expression to calculate linear step.
getCalcStep()3330   Expr *getCalcStep() { return *(getFinals().end() + 1); }
3331 
3332   /// Returns expression to calculate linear step.
getCalcStep()3333   const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
3334 
3335   /// Sets the list of update expressions for linear variables.
3336   /// \param UL List of expressions.
3337   void setUpdates(ArrayRef<Expr *> UL);
3338 
3339   /// Sets the list of final update expressions for linear variables.
3340   /// \param FL List of expressions.
3341   void setFinals(ArrayRef<Expr *> FL);
3342 
3343   /// Sets the list of used expressions for the linear clause.
3344   void setUsedExprs(ArrayRef<Expr *> UE);
3345 
3346   using privates_iterator = MutableArrayRef<Expr *>::iterator;
3347   using privates_const_iterator = ArrayRef<const Expr *>::iterator;
3348   using privates_range = llvm::iterator_range<privates_iterator>;
3349   using privates_const_range = llvm::iterator_range<privates_const_iterator>;
3350 
privates()3351   privates_range privates() {
3352     return privates_range(getPrivates().begin(), getPrivates().end());
3353   }
3354 
privates()3355   privates_const_range privates() const {
3356     return privates_const_range(getPrivates().begin(), getPrivates().end());
3357   }
3358 
3359   using inits_iterator = MutableArrayRef<Expr *>::iterator;
3360   using inits_const_iterator = ArrayRef<const Expr *>::iterator;
3361   using inits_range = llvm::iterator_range<inits_iterator>;
3362   using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3363 
inits()3364   inits_range inits() {
3365     return inits_range(getInits().begin(), getInits().end());
3366   }
3367 
inits()3368   inits_const_range inits() const {
3369     return inits_const_range(getInits().begin(), getInits().end());
3370   }
3371 
3372   using updates_iterator = MutableArrayRef<Expr *>::iterator;
3373   using updates_const_iterator = ArrayRef<const Expr *>::iterator;
3374   using updates_range = llvm::iterator_range<updates_iterator>;
3375   using updates_const_range = llvm::iterator_range<updates_const_iterator>;
3376 
updates()3377   updates_range updates() {
3378     return updates_range(getUpdates().begin(), getUpdates().end());
3379   }
3380 
updates()3381   updates_const_range updates() const {
3382     return updates_const_range(getUpdates().begin(), getUpdates().end());
3383   }
3384 
3385   using finals_iterator = MutableArrayRef<Expr *>::iterator;
3386   using finals_const_iterator = ArrayRef<const Expr *>::iterator;
3387   using finals_range = llvm::iterator_range<finals_iterator>;
3388   using finals_const_range = llvm::iterator_range<finals_const_iterator>;
3389 
finals()3390   finals_range finals() {
3391     return finals_range(getFinals().begin(), getFinals().end());
3392   }
3393 
finals()3394   finals_const_range finals() const {
3395     return finals_const_range(getFinals().begin(), getFinals().end());
3396   }
3397 
3398   using used_expressions_iterator = MutableArrayRef<Expr *>::iterator;
3399   using used_expressions_const_iterator = ArrayRef<const Expr *>::iterator;
3400   using used_expressions_range =
3401       llvm::iterator_range<used_expressions_iterator>;
3402   using used_expressions_const_range =
3403       llvm::iterator_range<used_expressions_const_iterator>;
3404 
used_expressions()3405   used_expressions_range used_expressions() {
3406     return finals_range(getUsedExprs().begin(), getUsedExprs().end());
3407   }
3408 
used_expressions()3409   used_expressions_const_range used_expressions() const {
3410     return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
3411   }
3412 
children()3413   child_range children() {
3414     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3415                        reinterpret_cast<Stmt **>(varlist_end()));
3416   }
3417 
children()3418   const_child_range children() const {
3419     auto Children = const_cast<OMPLinearClause *>(this)->children();
3420     return const_child_range(Children.begin(), Children.end());
3421   }
3422 
3423   child_range used_children();
3424 
used_children()3425   const_child_range used_children() const {
3426     auto Children = const_cast<OMPLinearClause *>(this)->used_children();
3427     return const_child_range(Children.begin(), Children.end());
3428   }
3429 
classof(const OMPClause * T)3430   static bool classof(const OMPClause *T) {
3431     return T->getClauseKind() == OMPC_linear;
3432   }
3433 };
3434 
3435 /// This represents clause 'aligned' in the '#pragma omp ...'
3436 /// directives.
3437 ///
3438 /// \code
3439 /// #pragma omp simd aligned(a,b : 8)
3440 /// \endcode
3441 /// In this example directive '#pragma omp simd' has clause 'aligned'
3442 /// with variables 'a', 'b' and alignment '8'.
3443 class OMPAlignedClause final
3444     : public OMPVarListClause<OMPAlignedClause>,
3445       private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
3446   friend class OMPClauseReader;
3447   friend OMPVarListClause;
3448   friend TrailingObjects;
3449 
3450   /// Location of ':'.
3451   SourceLocation ColonLoc;
3452 
3453   /// Sets the alignment for clause.
setAlignment(Expr * A)3454   void setAlignment(Expr *A) { *varlist_end() = A; }
3455 
3456   /// Build 'aligned' clause with given number of variables \a NumVars.
3457   ///
3458   /// \param StartLoc Starting location of the clause.
3459   /// \param LParenLoc Location of '('.
3460   /// \param ColonLoc Location of ':'.
3461   /// \param EndLoc Ending location of the clause.
3462   /// \param NumVars Number of variables.
OMPAlignedClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned NumVars)3463   OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3464                    SourceLocation ColonLoc, SourceLocation EndLoc,
3465                    unsigned NumVars)
3466       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
3467                                            EndLoc, NumVars),
3468         ColonLoc(ColonLoc) {}
3469 
3470   /// Build an empty clause.
3471   ///
3472   /// \param NumVars Number of variables.
OMPAlignedClause(unsigned NumVars)3473   explicit OMPAlignedClause(unsigned NumVars)
3474       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
3475                                            SourceLocation(), SourceLocation(),
3476                                            NumVars) {}
3477 
3478 public:
3479   /// Creates clause with a list of variables \a VL and alignment \a A.
3480   ///
3481   /// \param C AST Context.
3482   /// \param StartLoc Starting location of the clause.
3483   /// \param LParenLoc Location of '('.
3484   /// \param ColonLoc Location of ':'.
3485   /// \param EndLoc Ending location of the clause.
3486   /// \param VL List of references to the variables.
3487   /// \param A Alignment.
3488   static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3489                                   SourceLocation LParenLoc,
3490                                   SourceLocation ColonLoc,
3491                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
3492                                   Expr *A);
3493 
3494   /// Creates an empty clause with the place for \a NumVars variables.
3495   ///
3496   /// \param C AST context.
3497   /// \param NumVars Number of variables.
3498   static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3499 
3500   /// Sets the location of ':'.
setColonLoc(SourceLocation Loc)3501   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3502 
3503   /// Returns the location of ':'.
getColonLoc()3504   SourceLocation getColonLoc() const { return ColonLoc; }
3505 
3506   /// Returns alignment.
getAlignment()3507   Expr *getAlignment() { return *varlist_end(); }
3508 
3509   /// Returns alignment.
getAlignment()3510   const Expr *getAlignment() const { return *varlist_end(); }
3511 
children()3512   child_range children() {
3513     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3514                        reinterpret_cast<Stmt **>(varlist_end()));
3515   }
3516 
children()3517   const_child_range children() const {
3518     auto Children = const_cast<OMPAlignedClause *>(this)->children();
3519     return const_child_range(Children.begin(), Children.end());
3520   }
3521 
used_children()3522   child_range used_children() {
3523     return child_range(child_iterator(), child_iterator());
3524   }
used_children()3525   const_child_range used_children() const {
3526     return const_child_range(const_child_iterator(), const_child_iterator());
3527   }
3528 
classof(const OMPClause * T)3529   static bool classof(const OMPClause *T) {
3530     return T->getClauseKind() == OMPC_aligned;
3531   }
3532 };
3533 
3534 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
3535 ///
3536 /// \code
3537 /// #pragma omp parallel copyin(a,b)
3538 /// \endcode
3539 /// In this example directive '#pragma omp parallel' has clause 'copyin'
3540 /// with the variables 'a' and 'b'.
3541 class OMPCopyinClause final
3542     : public OMPVarListClause<OMPCopyinClause>,
3543       private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
3544   // Class has 3 additional tail allocated arrays:
3545   // 1. List of helper expressions for proper generation of assignment operation
3546   // required for copyin clause. This list represents sources.
3547   // 2. List of helper expressions for proper generation of assignment operation
3548   // required for copyin clause. This list represents destinations.
3549   // 3. List of helper expressions that represents assignment operation:
3550   // \code
3551   // DstExprs = SrcExprs;
3552   // \endcode
3553   // Required for proper codegen of propagation of master's thread values of
3554   // threadprivate variables to local instances of that variables in other
3555   // implicit threads.
3556 
3557   friend class OMPClauseReader;
3558   friend OMPVarListClause;
3559   friend TrailingObjects;
3560 
3561   /// Build clause with number of variables \a N.
3562   ///
3563   /// \param StartLoc Starting location of the clause.
3564   /// \param LParenLoc Location of '('.
3565   /// \param EndLoc Ending location of the clause.
3566   /// \param N Number of the variables in the clause.
OMPCopyinClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)3567   OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3568                   SourceLocation EndLoc, unsigned N)
3569       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
3570                                           EndLoc, N) {}
3571 
3572   /// Build an empty clause.
3573   ///
3574   /// \param N Number of variables.
OMPCopyinClause(unsigned N)3575   explicit OMPCopyinClause(unsigned N)
3576       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
3577                                           SourceLocation(), SourceLocation(),
3578                                           N) {}
3579 
3580   /// Set list of helper expressions, required for proper codegen of the
3581   /// clause. These expressions represent source expression in the final
3582   /// assignment statement performed by the copyin clause.
3583   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3584 
3585   /// Get the list of helper source expressions.
getSourceExprs()3586   MutableArrayRef<Expr *> getSourceExprs() {
3587     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3588   }
getSourceExprs()3589   ArrayRef<const Expr *> getSourceExprs() const {
3590     return llvm::makeArrayRef(varlist_end(), varlist_size());
3591   }
3592 
3593   /// Set list of helper expressions, required for proper codegen of the
3594   /// clause. These expressions represent destination expression in the final
3595   /// assignment statement performed by the copyin clause.
3596   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3597 
3598   /// Get the list of helper destination expressions.
getDestinationExprs()3599   MutableArrayRef<Expr *> getDestinationExprs() {
3600     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3601   }
getDestinationExprs()3602   ArrayRef<const Expr *> getDestinationExprs() const {
3603     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3604   }
3605 
3606   /// Set list of helper assignment expressions, required for proper
3607   /// codegen of the clause. These expressions are assignment expressions that
3608   /// assign source helper expressions to destination helper expressions
3609   /// correspondingly.
3610   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3611 
3612   /// Get the list of helper assignment expressions.
getAssignmentOps()3613   MutableArrayRef<Expr *> getAssignmentOps() {
3614     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3615   }
getAssignmentOps()3616   ArrayRef<const Expr *> getAssignmentOps() const {
3617     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3618   }
3619 
3620 public:
3621   /// Creates clause with a list of variables \a VL.
3622   ///
3623   /// \param C AST context.
3624   /// \param StartLoc Starting location of the clause.
3625   /// \param LParenLoc Location of '('.
3626   /// \param EndLoc Ending location of the clause.
3627   /// \param VL List of references to the variables.
3628   /// \param SrcExprs List of helper expressions for proper generation of
3629   /// assignment operation required for copyin clause. This list represents
3630   /// sources.
3631   /// \param DstExprs List of helper expressions for proper generation of
3632   /// assignment operation required for copyin clause. This list represents
3633   /// destinations.
3634   /// \param AssignmentOps List of helper expressions that represents assignment
3635   /// operation:
3636   /// \code
3637   /// DstExprs = SrcExprs;
3638   /// \endcode
3639   /// Required for proper codegen of propagation of master's thread values of
3640   /// threadprivate variables to local instances of that variables in other
3641   /// implicit threads.
3642   static OMPCopyinClause *
3643   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3644          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3645          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
3646 
3647   /// Creates an empty clause with \a N variables.
3648   ///
3649   /// \param C AST context.
3650   /// \param N The number of variables.
3651   static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
3652 
3653   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3654   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3655   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3656   using helper_expr_const_range =
3657       llvm::iterator_range<helper_expr_const_iterator>;
3658 
source_exprs()3659   helper_expr_const_range source_exprs() const {
3660     return helper_expr_const_range(getSourceExprs().begin(),
3661                                    getSourceExprs().end());
3662   }
3663 
source_exprs()3664   helper_expr_range source_exprs() {
3665     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3666   }
3667 
destination_exprs()3668   helper_expr_const_range destination_exprs() const {
3669     return helper_expr_const_range(getDestinationExprs().begin(),
3670                                    getDestinationExprs().end());
3671   }
3672 
destination_exprs()3673   helper_expr_range destination_exprs() {
3674     return helper_expr_range(getDestinationExprs().begin(),
3675                              getDestinationExprs().end());
3676   }
3677 
assignment_ops()3678   helper_expr_const_range assignment_ops() const {
3679     return helper_expr_const_range(getAssignmentOps().begin(),
3680                                    getAssignmentOps().end());
3681   }
3682 
assignment_ops()3683   helper_expr_range assignment_ops() {
3684     return helper_expr_range(getAssignmentOps().begin(),
3685                              getAssignmentOps().end());
3686   }
3687 
children()3688   child_range children() {
3689     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3690                        reinterpret_cast<Stmt **>(varlist_end()));
3691   }
3692 
children()3693   const_child_range children() const {
3694     auto Children = const_cast<OMPCopyinClause *>(this)->children();
3695     return const_child_range(Children.begin(), Children.end());
3696   }
3697 
used_children()3698   child_range used_children() {
3699     return child_range(child_iterator(), child_iterator());
3700   }
used_children()3701   const_child_range used_children() const {
3702     return const_child_range(const_child_iterator(), const_child_iterator());
3703   }
3704 
classof(const OMPClause * T)3705   static bool classof(const OMPClause *T) {
3706     return T->getClauseKind() == OMPC_copyin;
3707   }
3708 };
3709 
3710 /// This represents clause 'copyprivate' in the '#pragma omp ...'
3711 /// directives.
3712 ///
3713 /// \code
3714 /// #pragma omp single copyprivate(a,b)
3715 /// \endcode
3716 /// In this example directive '#pragma omp single' has clause 'copyprivate'
3717 /// with the variables 'a' and 'b'.
3718 class OMPCopyprivateClause final
3719     : public OMPVarListClause<OMPCopyprivateClause>,
3720       private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
3721   friend class OMPClauseReader;
3722   friend OMPVarListClause;
3723   friend TrailingObjects;
3724 
3725   /// Build clause with number of variables \a N.
3726   ///
3727   /// \param StartLoc Starting location of the clause.
3728   /// \param LParenLoc Location of '('.
3729   /// \param EndLoc Ending location of the clause.
3730   /// \param N Number of the variables in the clause.
OMPCopyprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)3731   OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3732                        SourceLocation EndLoc, unsigned N)
3733       : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
3734                                                LParenLoc, EndLoc, N) {}
3735 
3736   /// Build an empty clause.
3737   ///
3738   /// \param N Number of variables.
OMPCopyprivateClause(unsigned N)3739   explicit OMPCopyprivateClause(unsigned N)
3740       : OMPVarListClause<OMPCopyprivateClause>(
3741             OMPC_copyprivate, SourceLocation(), SourceLocation(),
3742             SourceLocation(), N) {}
3743 
3744   /// Set list of helper expressions, required for proper codegen of the
3745   /// clause. These expressions represent source expression in the final
3746   /// assignment statement performed by the copyprivate clause.
3747   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3748 
3749   /// Get the list of helper source expressions.
getSourceExprs()3750   MutableArrayRef<Expr *> getSourceExprs() {
3751     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3752   }
getSourceExprs()3753   ArrayRef<const Expr *> getSourceExprs() const {
3754     return llvm::makeArrayRef(varlist_end(), varlist_size());
3755   }
3756 
3757   /// Set list of helper expressions, required for proper codegen of the
3758   /// clause. These expressions represent destination expression in the final
3759   /// assignment statement performed by the copyprivate clause.
3760   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3761 
3762   /// Get the list of helper destination expressions.
getDestinationExprs()3763   MutableArrayRef<Expr *> getDestinationExprs() {
3764     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3765   }
getDestinationExprs()3766   ArrayRef<const Expr *> getDestinationExprs() const {
3767     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3768   }
3769 
3770   /// Set list of helper assignment expressions, required for proper
3771   /// codegen of the clause. These expressions are assignment expressions that
3772   /// assign source helper expressions to destination helper expressions
3773   /// correspondingly.
3774   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3775 
3776   /// Get the list of helper assignment expressions.
getAssignmentOps()3777   MutableArrayRef<Expr *> getAssignmentOps() {
3778     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3779   }
getAssignmentOps()3780   ArrayRef<const Expr *> getAssignmentOps() const {
3781     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3782   }
3783 
3784 public:
3785   /// Creates clause with a list of variables \a VL.
3786   ///
3787   /// \param C AST context.
3788   /// \param StartLoc Starting location of the clause.
3789   /// \param LParenLoc Location of '('.
3790   /// \param EndLoc Ending location of the clause.
3791   /// \param VL List of references to the variables.
3792   /// \param SrcExprs List of helper expressions for proper generation of
3793   /// assignment operation required for copyprivate clause. This list represents
3794   /// sources.
3795   /// \param DstExprs List of helper expressions for proper generation of
3796   /// assignment operation required for copyprivate clause. This list represents
3797   /// destinations.
3798   /// \param AssignmentOps List of helper expressions that represents assignment
3799   /// operation:
3800   /// \code
3801   /// DstExprs = SrcExprs;
3802   /// \endcode
3803   /// Required for proper codegen of final assignment performed by the
3804   /// copyprivate clause.
3805   static OMPCopyprivateClause *
3806   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3807          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3808          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
3809 
3810   /// Creates an empty clause with \a N variables.
3811   ///
3812   /// \param C AST context.
3813   /// \param N The number of variables.
3814   static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3815 
3816   using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3817   using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3818   using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3819   using helper_expr_const_range =
3820       llvm::iterator_range<helper_expr_const_iterator>;
3821 
source_exprs()3822   helper_expr_const_range source_exprs() const {
3823     return helper_expr_const_range(getSourceExprs().begin(),
3824                                    getSourceExprs().end());
3825   }
3826 
source_exprs()3827   helper_expr_range source_exprs() {
3828     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3829   }
3830 
destination_exprs()3831   helper_expr_const_range destination_exprs() const {
3832     return helper_expr_const_range(getDestinationExprs().begin(),
3833                                    getDestinationExprs().end());
3834   }
3835 
destination_exprs()3836   helper_expr_range destination_exprs() {
3837     return helper_expr_range(getDestinationExprs().begin(),
3838                              getDestinationExprs().end());
3839   }
3840 
assignment_ops()3841   helper_expr_const_range assignment_ops() const {
3842     return helper_expr_const_range(getAssignmentOps().begin(),
3843                                    getAssignmentOps().end());
3844   }
3845 
assignment_ops()3846   helper_expr_range assignment_ops() {
3847     return helper_expr_range(getAssignmentOps().begin(),
3848                              getAssignmentOps().end());
3849   }
3850 
children()3851   child_range children() {
3852     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3853                        reinterpret_cast<Stmt **>(varlist_end()));
3854   }
3855 
children()3856   const_child_range children() const {
3857     auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
3858     return const_child_range(Children.begin(), Children.end());
3859   }
3860 
used_children()3861   child_range used_children() {
3862     return child_range(child_iterator(), child_iterator());
3863   }
used_children()3864   const_child_range used_children() const {
3865     return const_child_range(const_child_iterator(), const_child_iterator());
3866   }
3867 
classof(const OMPClause * T)3868   static bool classof(const OMPClause *T) {
3869     return T->getClauseKind() == OMPC_copyprivate;
3870   }
3871 };
3872 
3873 /// This represents implicit clause 'flush' for the '#pragma omp flush'
3874 /// directive.
3875 /// This clause does not exist by itself, it can be only as a part of 'omp
3876 /// flush' directive. This clause is introduced to keep the original structure
3877 /// of \a OMPExecutableDirective class and its derivatives and to use the
3878 /// existing infrastructure of clauses with the list of variables.
3879 ///
3880 /// \code
3881 /// #pragma omp flush(a,b)
3882 /// \endcode
3883 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
3884 /// with the variables 'a' and 'b'.
3885 class OMPFlushClause final
3886     : public OMPVarListClause<OMPFlushClause>,
3887       private llvm::TrailingObjects<OMPFlushClause, Expr *> {
3888   friend OMPVarListClause;
3889   friend TrailingObjects;
3890 
3891   /// Build clause with number of variables \a N.
3892   ///
3893   /// \param StartLoc Starting location of the clause.
3894   /// \param LParenLoc Location of '('.
3895   /// \param EndLoc Ending location of the clause.
3896   /// \param N Number of the variables in the clause.
OMPFlushClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)3897   OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3898                  SourceLocation EndLoc, unsigned N)
3899       : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
3900                                          EndLoc, N) {}
3901 
3902   /// Build an empty clause.
3903   ///
3904   /// \param N Number of variables.
OMPFlushClause(unsigned N)3905   explicit OMPFlushClause(unsigned N)
3906       : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
3907                                          SourceLocation(), SourceLocation(),
3908                                          N) {}
3909 
3910 public:
3911   /// Creates clause with a list of variables \a VL.
3912   ///
3913   /// \param C AST context.
3914   /// \param StartLoc Starting location of the clause.
3915   /// \param LParenLoc Location of '('.
3916   /// \param EndLoc Ending location of the clause.
3917   /// \param VL List of references to the variables.
3918   static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
3919                                 SourceLocation LParenLoc, SourceLocation EndLoc,
3920                                 ArrayRef<Expr *> VL);
3921 
3922   /// Creates an empty clause with \a N variables.
3923   ///
3924   /// \param C AST context.
3925   /// \param N The number of variables.
3926   static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
3927 
children()3928   child_range children() {
3929     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3930                        reinterpret_cast<Stmt **>(varlist_end()));
3931   }
3932 
children()3933   const_child_range children() const {
3934     auto Children = const_cast<OMPFlushClause *>(this)->children();
3935     return const_child_range(Children.begin(), Children.end());
3936   }
3937 
used_children()3938   child_range used_children() {
3939     return child_range(child_iterator(), child_iterator());
3940   }
used_children()3941   const_child_range used_children() const {
3942     return const_child_range(const_child_iterator(), const_child_iterator());
3943   }
3944 
classof(const OMPClause * T)3945   static bool classof(const OMPClause *T) {
3946     return T->getClauseKind() == OMPC_flush;
3947   }
3948 };
3949 
3950 /// This represents implicit clause 'depend' for the '#pragma omp task'
3951 /// directive.
3952 ///
3953 /// \code
3954 /// #pragma omp task depend(in:a,b)
3955 /// \endcode
3956 /// In this example directive '#pragma omp task' with clause 'depend' with the
3957 /// variables 'a' and 'b' with dependency 'in'.
3958 class OMPDependClause final
3959     : public OMPVarListClause<OMPDependClause>,
3960       private llvm::TrailingObjects<OMPDependClause, Expr *> {
3961   friend class OMPClauseReader;
3962   friend OMPVarListClause;
3963   friend TrailingObjects;
3964 
3965   /// Dependency type (one of in, out, inout).
3966   OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
3967 
3968   /// Dependency type location.
3969   SourceLocation DepLoc;
3970 
3971   /// Colon location.
3972   SourceLocation ColonLoc;
3973 
3974   /// Number of loops, associated with the depend clause.
3975   unsigned NumLoops = 0;
3976 
3977   /// Build clause with number of variables \a N.
3978   ///
3979   /// \param StartLoc Starting location of the clause.
3980   /// \param LParenLoc Location of '('.
3981   /// \param EndLoc Ending location of the clause.
3982   /// \param N Number of the variables in the clause.
3983   /// \param NumLoops Number of loops that is associated with this depend
3984   /// clause.
OMPDependClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N,unsigned NumLoops)3985   OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3986                   SourceLocation EndLoc, unsigned N, unsigned NumLoops)
3987       : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
3988                                           EndLoc, N), NumLoops(NumLoops) {}
3989 
3990   /// Build an empty clause.
3991   ///
3992   /// \param N Number of variables.
3993   /// \param NumLoops Number of loops that is associated with this depend
3994   /// clause.
OMPDependClause(unsigned N,unsigned NumLoops)3995   explicit OMPDependClause(unsigned N, unsigned NumLoops)
3996       : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
3997                                           SourceLocation(), SourceLocation(),
3998                                           N),
3999         NumLoops(NumLoops) {}
4000 
4001   /// Set dependency kind.
setDependencyKind(OpenMPDependClauseKind K)4002   void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
4003 
4004   /// Set dependency kind and its location.
setDependencyLoc(SourceLocation Loc)4005   void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
4006 
4007   /// Set colon location.
setColonLoc(SourceLocation Loc)4008   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4009 
4010 public:
4011   /// Creates clause with a list of variables \a VL.
4012   ///
4013   /// \param C AST context.
4014   /// \param StartLoc Starting location of the clause.
4015   /// \param LParenLoc Location of '('.
4016   /// \param EndLoc Ending location of the clause.
4017   /// \param DepKind Dependency type.
4018   /// \param DepLoc Location of the dependency type.
4019   /// \param ColonLoc Colon location.
4020   /// \param VL List of references to the variables.
4021   /// \param NumLoops Number of loops that is associated with this depend
4022   /// clause.
4023   static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
4024                                  SourceLocation LParenLoc,
4025                                  SourceLocation EndLoc,
4026                                  OpenMPDependClauseKind DepKind,
4027                                  SourceLocation DepLoc, SourceLocation ColonLoc,
4028                                  ArrayRef<Expr *> VL, unsigned NumLoops);
4029 
4030   /// Creates an empty clause with \a N variables.
4031   ///
4032   /// \param C AST context.
4033   /// \param N The number of variables.
4034   /// \param NumLoops Number of loops that is associated with this depend
4035   /// clause.
4036   static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
4037                                       unsigned NumLoops);
4038 
4039   /// Get dependency type.
getDependencyKind()4040   OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
4041 
4042   /// Get dependency type location.
getDependencyLoc()4043   SourceLocation getDependencyLoc() const { return DepLoc; }
4044 
4045   /// Get colon location.
getColonLoc()4046   SourceLocation getColonLoc() const { return ColonLoc; }
4047 
4048   /// Get number of loops associated with the clause.
getNumLoops()4049   unsigned getNumLoops() const { return NumLoops; }
4050 
4051   /// Set the loop data for the depend clauses with 'sink|source' kind of
4052   /// dependency.
4053   void setLoopData(unsigned NumLoop, Expr *Cnt);
4054 
4055   /// Get the loop data.
4056   Expr *getLoopData(unsigned NumLoop);
4057   const Expr *getLoopData(unsigned NumLoop) const;
4058 
children()4059   child_range children() {
4060     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4061                        reinterpret_cast<Stmt **>(varlist_end()));
4062   }
4063 
children()4064   const_child_range children() const {
4065     auto Children = const_cast<OMPDependClause *>(this)->children();
4066     return const_child_range(Children.begin(), Children.end());
4067   }
4068 
used_children()4069   child_range used_children() {
4070     return child_range(child_iterator(), child_iterator());
4071   }
used_children()4072   const_child_range used_children() const {
4073     return const_child_range(const_child_iterator(), const_child_iterator());
4074   }
4075 
classof(const OMPClause * T)4076   static bool classof(const OMPClause *T) {
4077     return T->getClauseKind() == OMPC_depend;
4078   }
4079 };
4080 
4081 /// This represents 'device' clause in the '#pragma omp ...'
4082 /// directive.
4083 ///
4084 /// \code
4085 /// #pragma omp target device(a)
4086 /// \endcode
4087 /// In this example directive '#pragma omp target' has clause 'device'
4088 /// with single expression 'a'.
4089 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
4090   friend class OMPClauseReader;
4091 
4092   /// Location of '('.
4093   SourceLocation LParenLoc;
4094 
4095   /// Device number.
4096   Stmt *Device = nullptr;
4097 
4098   /// Set the device number.
4099   ///
4100   /// \param E Device number.
setDevice(Expr * E)4101   void setDevice(Expr *E) { Device = E; }
4102 
4103 public:
4104   /// Build 'device' clause.
4105   ///
4106   /// \param E Expression associated with this clause.
4107   /// \param CaptureRegion Innermost OpenMP region where expressions in this
4108   /// clause must be captured.
4109   /// \param StartLoc Starting location of the clause.
4110   /// \param LParenLoc Location of '('.
4111   /// \param EndLoc Ending location of the clause.
OMPDeviceClause(Expr * E,Stmt * HelperE,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)4112   OMPDeviceClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
4113                   SourceLocation StartLoc, SourceLocation LParenLoc,
4114                   SourceLocation EndLoc)
4115       : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this),
4116         LParenLoc(LParenLoc), Device(E) {
4117     setPreInitStmt(HelperE, CaptureRegion);
4118   }
4119 
4120   /// Build an empty clause.
OMPDeviceClause()4121   OMPDeviceClause()
4122       : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
4123         OMPClauseWithPreInit(this) {}
4124 
4125   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)4126   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4127 
4128   /// Returns the location of '('.
getLParenLoc()4129   SourceLocation getLParenLoc() const { return LParenLoc; }
4130 
4131   /// Return device number.
getDevice()4132   Expr *getDevice() { return cast<Expr>(Device); }
4133 
4134   /// Return device number.
getDevice()4135   Expr *getDevice() const { return cast<Expr>(Device); }
4136 
children()4137   child_range children() { return child_range(&Device, &Device + 1); }
4138 
children()4139   const_child_range children() const {
4140     return const_child_range(&Device, &Device + 1);
4141   }
4142 
used_children()4143   child_range used_children() {
4144     return child_range(child_iterator(), child_iterator());
4145   }
used_children()4146   const_child_range used_children() const {
4147     return const_child_range(const_child_iterator(), const_child_iterator());
4148   }
4149 
classof(const OMPClause * T)4150   static bool classof(const OMPClause *T) {
4151     return T->getClauseKind() == OMPC_device;
4152   }
4153 };
4154 
4155 /// This represents 'threads' clause in the '#pragma omp ...' directive.
4156 ///
4157 /// \code
4158 /// #pragma omp ordered threads
4159 /// \endcode
4160 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
4161 class OMPThreadsClause : public OMPClause {
4162 public:
4163   /// Build 'threads' clause.
4164   ///
4165   /// \param StartLoc Starting location of the clause.
4166   /// \param EndLoc Ending location of the clause.
OMPThreadsClause(SourceLocation StartLoc,SourceLocation EndLoc)4167   OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
4168       : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
4169 
4170   /// Build an empty clause.
OMPThreadsClause()4171   OMPThreadsClause()
4172       : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
4173 
children()4174   child_range children() {
4175     return child_range(child_iterator(), child_iterator());
4176   }
4177 
children()4178   const_child_range children() const {
4179     return const_child_range(const_child_iterator(), const_child_iterator());
4180   }
4181 
used_children()4182   child_range used_children() {
4183     return child_range(child_iterator(), child_iterator());
4184   }
used_children()4185   const_child_range used_children() const {
4186     return const_child_range(const_child_iterator(), const_child_iterator());
4187   }
4188 
classof(const OMPClause * T)4189   static bool classof(const OMPClause *T) {
4190     return T->getClauseKind() == OMPC_threads;
4191   }
4192 };
4193 
4194 /// This represents 'simd' clause in the '#pragma omp ...' directive.
4195 ///
4196 /// \code
4197 /// #pragma omp ordered simd
4198 /// \endcode
4199 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
4200 class OMPSIMDClause : public OMPClause {
4201 public:
4202   /// Build 'simd' clause.
4203   ///
4204   /// \param StartLoc Starting location of the clause.
4205   /// \param EndLoc Ending location of the clause.
OMPSIMDClause(SourceLocation StartLoc,SourceLocation EndLoc)4206   OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
4207       : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
4208 
4209   /// Build an empty clause.
OMPSIMDClause()4210   OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
4211 
children()4212   child_range children() {
4213     return child_range(child_iterator(), child_iterator());
4214   }
4215 
children()4216   const_child_range children() const {
4217     return const_child_range(const_child_iterator(), const_child_iterator());
4218   }
4219 
used_children()4220   child_range used_children() {
4221     return child_range(child_iterator(), child_iterator());
4222   }
used_children()4223   const_child_range used_children() const {
4224     return const_child_range(const_child_iterator(), const_child_iterator());
4225   }
4226 
classof(const OMPClause * T)4227   static bool classof(const OMPClause *T) {
4228     return T->getClauseKind() == OMPC_simd;
4229   }
4230 };
4231 
4232 /// Struct that defines common infrastructure to handle mappable
4233 /// expressions used in OpenMP clauses.
4234 class OMPClauseMappableExprCommon {
4235 public:
4236   /// Class that represents a component of a mappable expression. E.g.
4237   /// for an expression S.a, the first component is a declaration reference
4238   /// expression associated with 'S' and the second is a member expression
4239   /// associated with the field declaration 'a'. If the expression is an array
4240   /// subscript it may not have any associated declaration. In that case the
4241   /// associated declaration is set to nullptr.
4242   class MappableComponent {
4243     /// Expression associated with the component.
4244     Expr *AssociatedExpression = nullptr;
4245 
4246     /// Declaration associated with the declaration. If the component does
4247     /// not have a declaration (e.g. array subscripts or section), this is set
4248     /// to nullptr.
4249     ValueDecl *AssociatedDeclaration = nullptr;
4250 
4251   public:
4252     explicit MappableComponent() = default;
MappableComponent(Expr * AssociatedExpression,ValueDecl * AssociatedDeclaration)4253     explicit MappableComponent(Expr *AssociatedExpression,
4254                                ValueDecl *AssociatedDeclaration)
4255         : AssociatedExpression(AssociatedExpression),
4256           AssociatedDeclaration(
4257               AssociatedDeclaration
4258                   ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
4259                   : nullptr) {}
4260 
getAssociatedExpression()4261     Expr *getAssociatedExpression() const { return AssociatedExpression; }
4262 
getAssociatedDeclaration()4263     ValueDecl *getAssociatedDeclaration() const {
4264       return AssociatedDeclaration;
4265     }
4266   };
4267 
4268   // List of components of an expression. This first one is the whole
4269   // expression and the last one is the base expression.
4270   using MappableExprComponentList = SmallVector<MappableComponent, 8>;
4271   using MappableExprComponentListRef = ArrayRef<MappableComponent>;
4272 
4273   // List of all component lists associated to the same base declaration.
4274   // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
4275   // their component list but the same base declaration 'S'.
4276   using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
4277   using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
4278 
4279 protected:
4280   // Return the total number of elements in a list of component lists.
4281   static unsigned
4282   getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
4283 
4284   // Return the total number of elements in a list of declarations. All
4285   // declarations are expected to be canonical.
4286   static unsigned
4287   getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
4288 };
4289 
4290 /// This structure contains all sizes needed for by an
4291 /// OMPMappableExprListClause.
4292 struct OMPMappableExprListSizeTy {
4293   /// Number of expressions listed.
4294   unsigned NumVars;
4295   /// Number of unique base declarations.
4296   unsigned NumUniqueDeclarations;
4297   /// Number of component lists.
4298   unsigned NumComponentLists;
4299   /// Total number of expression components.
4300   unsigned NumComponents;
4301   OMPMappableExprListSizeTy() = default;
OMPMappableExprListSizeTyOMPMappableExprListSizeTy4302   OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations,
4303                             unsigned NumComponentLists, unsigned NumComponents)
4304       : NumVars(NumVars), NumUniqueDeclarations(NumUniqueDeclarations),
4305         NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
4306 };
4307 
4308 /// This represents clauses with a list of expressions that are mappable.
4309 /// Examples of these clauses are 'map' in
4310 /// '#pragma omp target [enter|exit] [data]...' directives, and  'to' and 'from
4311 /// in '#pragma omp target update...' directives.
4312 template <class T>
4313 class OMPMappableExprListClause : public OMPVarListClause<T>,
4314                                   public OMPClauseMappableExprCommon {
4315   friend class OMPClauseReader;
4316 
4317   /// Number of unique declarations in this clause.
4318   unsigned NumUniqueDeclarations;
4319 
4320   /// Number of component lists in this clause.
4321   unsigned NumComponentLists;
4322 
4323   /// Total number of components in this clause.
4324   unsigned NumComponents;
4325 
4326   /// C++ nested name specifier for the associated user-defined mapper.
4327   NestedNameSpecifierLoc MapperQualifierLoc;
4328 
4329   /// The associated user-defined mapper identifier information.
4330   DeclarationNameInfo MapperIdInfo;
4331 
4332 protected:
4333   /// Build a clause for \a NumUniqueDeclarations declarations, \a
4334   /// NumComponentLists total component lists, and \a NumComponents total
4335   /// components.
4336   ///
4337   /// \param K Kind of the clause.
4338   /// \param Locs Locations needed to build a mappable clause. It includes 1)
4339   /// StartLoc: starting location of the clause (the clause keyword); 2)
4340   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4341   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4342   /// NumVars: number of expressions listed in this clause; 2)
4343   /// NumUniqueDeclarations: number of unique base declarations in this clause;
4344   /// 3) NumComponentLists: number of component lists in this clause; and 4)
4345   /// NumComponents: total number of expression components in the clause.
4346   /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
4347   /// user-defined mapper.
4348   /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
4349   OMPMappableExprListClause(
4350       OpenMPClauseKind K, const OMPVarListLocTy &Locs,
4351       const OMPMappableExprListSizeTy &Sizes,
4352       NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
4353       DeclarationNameInfo *MapperIdInfoPtr = nullptr)
4354       : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
4355                             Sizes.NumVars),
4356         NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
4357         NumComponentLists(Sizes.NumComponentLists),
4358         NumComponents(Sizes.NumComponents) {
4359     if (MapperQualifierLocPtr)
4360       MapperQualifierLoc = *MapperQualifierLocPtr;
4361     if (MapperIdInfoPtr)
4362       MapperIdInfo = *MapperIdInfoPtr;
4363   }
4364 
4365   /// Get the unique declarations that are in the trailing objects of the
4366   /// class.
getUniqueDeclsRef()4367   MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
4368     return MutableArrayRef<ValueDecl *>(
4369         static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
4370         NumUniqueDeclarations);
4371   }
4372 
4373   /// Get the unique declarations that are in the trailing objects of the
4374   /// class.
getUniqueDeclsRef()4375   ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
4376     return ArrayRef<ValueDecl *>(
4377         static_cast<const T *>(this)
4378             ->template getTrailingObjects<ValueDecl *>(),
4379         NumUniqueDeclarations);
4380   }
4381 
4382   /// Set the unique declarations that are in the trailing objects of the
4383   /// class.
setUniqueDecls(ArrayRef<ValueDecl * > UDs)4384   void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
4385     assert(UDs.size() == NumUniqueDeclarations &&
4386            "Unexpected amount of unique declarations.");
4387     std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
4388   }
4389 
4390   /// Get the number of lists per declaration that are in the trailing
4391   /// objects of the class.
getDeclNumListsRef()4392   MutableArrayRef<unsigned> getDeclNumListsRef() {
4393     return MutableArrayRef<unsigned>(
4394         static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
4395         NumUniqueDeclarations);
4396   }
4397 
4398   /// Get the number of lists per declaration that are in the trailing
4399   /// objects of the class.
getDeclNumListsRef()4400   ArrayRef<unsigned> getDeclNumListsRef() const {
4401     return ArrayRef<unsigned>(
4402         static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
4403         NumUniqueDeclarations);
4404   }
4405 
4406   /// Set the number of lists per declaration that are in the trailing
4407   /// objects of the class.
setDeclNumLists(ArrayRef<unsigned> DNLs)4408   void setDeclNumLists(ArrayRef<unsigned> DNLs) {
4409     assert(DNLs.size() == NumUniqueDeclarations &&
4410            "Unexpected amount of list numbers.");
4411     std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
4412   }
4413 
4414   /// Get the cumulative component lists sizes that are in the trailing
4415   /// objects of the class. They are appended after the number of lists.
getComponentListSizesRef()4416   MutableArrayRef<unsigned> getComponentListSizesRef() {
4417     return MutableArrayRef<unsigned>(
4418         static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
4419             NumUniqueDeclarations,
4420         NumComponentLists);
4421   }
4422 
4423   /// Get the cumulative component lists sizes that are in the trailing
4424   /// objects of the class. They are appended after the number of lists.
getComponentListSizesRef()4425   ArrayRef<unsigned> getComponentListSizesRef() const {
4426     return ArrayRef<unsigned>(
4427         static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
4428             NumUniqueDeclarations,
4429         NumComponentLists);
4430   }
4431 
4432   /// Set the cumulative component lists sizes that are in the trailing
4433   /// objects of the class.
setComponentListSizes(ArrayRef<unsigned> CLSs)4434   void setComponentListSizes(ArrayRef<unsigned> CLSs) {
4435     assert(CLSs.size() == NumComponentLists &&
4436            "Unexpected amount of component lists.");
4437     std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
4438   }
4439 
4440   /// Get the components that are in the trailing objects of the class.
getComponentsRef()4441   MutableArrayRef<MappableComponent> getComponentsRef() {
4442     return MutableArrayRef<MappableComponent>(
4443         static_cast<T *>(this)
4444             ->template getTrailingObjects<MappableComponent>(),
4445         NumComponents);
4446   }
4447 
4448   /// Get the components that are in the trailing objects of the class.
getComponentsRef()4449   ArrayRef<MappableComponent> getComponentsRef() const {
4450     return ArrayRef<MappableComponent>(
4451         static_cast<const T *>(this)
4452             ->template getTrailingObjects<MappableComponent>(),
4453         NumComponents);
4454   }
4455 
4456   /// Set the components that are in the trailing objects of the class.
4457   /// This requires the list sizes so that it can also fill the original
4458   /// expressions, which are the first component of each list.
setComponents(ArrayRef<MappableComponent> Components,ArrayRef<unsigned> CLSs)4459   void setComponents(ArrayRef<MappableComponent> Components,
4460                      ArrayRef<unsigned> CLSs) {
4461     assert(Components.size() == NumComponents &&
4462            "Unexpected amount of component lists.");
4463     assert(CLSs.size() == NumComponentLists &&
4464            "Unexpected amount of list sizes.");
4465     std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
4466   }
4467 
4468   /// Fill the clause information from the list of declarations and
4469   /// associated component lists.
setClauseInfo(ArrayRef<ValueDecl * > Declarations,MappableExprComponentListsRef ComponentLists)4470   void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
4471                      MappableExprComponentListsRef ComponentLists) {
4472     // Perform some checks to make sure the data sizes are consistent with the
4473     // information available when the clause was created.
4474     assert(getUniqueDeclarationsTotalNumber(Declarations) ==
4475                NumUniqueDeclarations &&
4476            "Unexpected number of mappable expression info entries!");
4477     assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
4478            "Unexpected total number of components!");
4479     assert(Declarations.size() == ComponentLists.size() &&
4480            "Declaration and component lists size is not consistent!");
4481     assert(Declarations.size() == NumComponentLists &&
4482            "Unexpected declaration and component lists size!");
4483 
4484     // Organize the components by declaration and retrieve the original
4485     // expression. Original expressions are always the first component of the
4486     // mappable component list.
4487     llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
4488         ComponentListMap;
4489     {
4490       auto CI = ComponentLists.begin();
4491       for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
4492            ++DI, ++CI) {
4493         assert(!CI->empty() && "Invalid component list!");
4494         ComponentListMap[*DI].push_back(*CI);
4495       }
4496     }
4497 
4498     // Iterators of the target storage.
4499     auto UniqueDeclarations = getUniqueDeclsRef();
4500     auto UDI = UniqueDeclarations.begin();
4501 
4502     auto DeclNumLists = getDeclNumListsRef();
4503     auto DNLI = DeclNumLists.begin();
4504 
4505     auto ComponentListSizes = getComponentListSizesRef();
4506     auto CLSI = ComponentListSizes.begin();
4507 
4508     auto Components = getComponentsRef();
4509     auto CI = Components.begin();
4510 
4511     // Variable to compute the accumulation of the number of components.
4512     unsigned PrevSize = 0u;
4513 
4514     // Scan all the declarations and associated component lists.
4515     for (auto &M : ComponentListMap) {
4516       // The declaration.
4517       auto *D = M.first;
4518       // The component lists.
4519       auto CL = M.second;
4520 
4521       // Initialize the entry.
4522       *UDI = D;
4523       ++UDI;
4524 
4525       *DNLI = CL.size();
4526       ++DNLI;
4527 
4528       // Obtain the cumulative sizes and concatenate all the components in the
4529       // reserved storage.
4530       for (auto C : CL) {
4531         // Accumulate with the previous size.
4532         PrevSize += C.size();
4533 
4534         // Save the size.
4535         *CLSI = PrevSize;
4536         ++CLSI;
4537 
4538         // Append components after the current components iterator.
4539         CI = std::copy(C.begin(), C.end(), CI);
4540       }
4541     }
4542   }
4543 
4544   /// Set the nested name specifier of associated user-defined mapper.
setMapperQualifierLoc(NestedNameSpecifierLoc NNSL)4545   void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) {
4546     MapperQualifierLoc = NNSL;
4547   }
4548 
4549   /// Set the name of associated user-defined mapper.
setMapperIdInfo(DeclarationNameInfo MapperId)4550   void setMapperIdInfo(DeclarationNameInfo MapperId) {
4551     MapperIdInfo = MapperId;
4552   }
4553 
4554   /// Get the user-defined mapper references that are in the trailing objects of
4555   /// the class.
getUDMapperRefs()4556   MutableArrayRef<Expr *> getUDMapperRefs() {
4557     return llvm::makeMutableArrayRef<Expr *>(
4558         static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
4559             OMPVarListClause<T>::varlist_size(),
4560         OMPVarListClause<T>::varlist_size());
4561   }
4562 
4563   /// Get the user-defined mappers references that are in the trailing objects
4564   /// of the class.
getUDMapperRefs()4565   ArrayRef<Expr *> getUDMapperRefs() const {
4566     return llvm::makeArrayRef<Expr *>(
4567         static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
4568             OMPVarListClause<T>::varlist_size(),
4569         OMPVarListClause<T>::varlist_size());
4570   }
4571 
4572   /// Set the user-defined mappers that are in the trailing objects of the
4573   /// class.
setUDMapperRefs(ArrayRef<Expr * > DMDs)4574   void setUDMapperRefs(ArrayRef<Expr *> DMDs) {
4575     assert(DMDs.size() == OMPVarListClause<T>::varlist_size() &&
4576            "Unexpected number of user-defined mappers.");
4577     std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin());
4578   }
4579 
4580 public:
4581   /// Return the number of unique base declarations in this clause.
getUniqueDeclarationsNum()4582   unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
4583 
4584   /// Return the number of lists derived from the clause expressions.
getTotalComponentListNum()4585   unsigned getTotalComponentListNum() const { return NumComponentLists; }
4586 
4587   /// Return the total number of components in all lists derived from the
4588   /// clause.
getTotalComponentsNum()4589   unsigned getTotalComponentsNum() const { return NumComponents; }
4590 
4591   /// Gets the nested name specifier for associated user-defined mapper.
getMapperQualifierLoc()4592   NestedNameSpecifierLoc getMapperQualifierLoc() const {
4593     return MapperQualifierLoc;
4594   }
4595 
4596   /// Gets the name info for associated user-defined mapper.
getMapperIdInfo()4597   const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; }
4598 
4599   /// Iterator that browse the components by lists. It also allows
4600   /// browsing components of a single declaration.
4601   class const_component_lists_iterator
4602       : public llvm::iterator_adaptor_base<
4603             const_component_lists_iterator,
4604             MappableExprComponentListRef::const_iterator,
4605             std::forward_iterator_tag, MappableComponent, ptrdiff_t,
4606             MappableComponent, MappableComponent> {
4607     // The declaration the iterator currently refers to.
4608     ArrayRef<ValueDecl *>::iterator DeclCur;
4609 
4610     // The list number associated with the current declaration.
4611     ArrayRef<unsigned>::iterator NumListsCur;
4612 
4613     // Remaining lists for the current declaration.
4614     unsigned RemainingLists = 0;
4615 
4616     // The cumulative size of the previous list, or zero if there is no previous
4617     // list.
4618     unsigned PrevListSize = 0;
4619 
4620     // The cumulative sizes of the current list - it will delimit the remaining
4621     // range of interest.
4622     ArrayRef<unsigned>::const_iterator ListSizeCur;
4623     ArrayRef<unsigned>::const_iterator ListSizeEnd;
4624 
4625     // Iterator to the end of the components storage.
4626     MappableExprComponentListRef::const_iterator End;
4627 
4628   public:
4629     /// Construct an iterator that scans all lists.
const_component_lists_iterator(ArrayRef<ValueDecl * > UniqueDecls,ArrayRef<unsigned> DeclsListNum,ArrayRef<unsigned> CumulativeListSizes,MappableExprComponentListRef Components)4630     explicit const_component_lists_iterator(
4631         ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
4632         ArrayRef<unsigned> CumulativeListSizes,
4633         MappableExprComponentListRef Components)
4634         : const_component_lists_iterator::iterator_adaptor_base(
4635               Components.begin()),
4636           DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
4637           ListSizeCur(CumulativeListSizes.begin()),
4638           ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
4639       assert(UniqueDecls.size() == DeclsListNum.size() &&
4640              "Inconsistent number of declarations and list sizes!");
4641       if (!DeclsListNum.empty())
4642         RemainingLists = *NumListsCur;
4643     }
4644 
4645     /// Construct an iterator that scan lists for a given declaration \a
4646     /// Declaration.
const_component_lists_iterator(const ValueDecl * Declaration,ArrayRef<ValueDecl * > UniqueDecls,ArrayRef<unsigned> DeclsListNum,ArrayRef<unsigned> CumulativeListSizes,MappableExprComponentListRef Components)4647     explicit const_component_lists_iterator(
4648         const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
4649         ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
4650         MappableExprComponentListRef Components)
4651         : const_component_lists_iterator(UniqueDecls, DeclsListNum,
4652                                          CumulativeListSizes, Components) {
4653       // Look for the desired declaration. While we are looking for it, we
4654       // update the state so that we know the component where a given list
4655       // starts.
4656       for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
4657         if (*DeclCur == Declaration)
4658           break;
4659 
4660         assert(*NumListsCur > 0 && "No lists associated with declaration??");
4661 
4662         // Skip the lists associated with the current declaration, but save the
4663         // last list size that was skipped.
4664         std::advance(ListSizeCur, *NumListsCur - 1);
4665         PrevListSize = *ListSizeCur;
4666         ++ListSizeCur;
4667       }
4668 
4669       // If we didn't find any declaration, advance the iterator to after the
4670       // last component and set remaining lists to zero.
4671       if (ListSizeCur == CumulativeListSizes.end()) {
4672         this->I = End;
4673         RemainingLists = 0u;
4674         return;
4675       }
4676 
4677       // Set the remaining lists with the total number of lists of the current
4678       // declaration.
4679       RemainingLists = *NumListsCur;
4680 
4681       // Adjust the list size end iterator to the end of the relevant range.
4682       ListSizeEnd = ListSizeCur;
4683       std::advance(ListSizeEnd, RemainingLists);
4684 
4685       // Given that the list sizes are cumulative, the index of the component
4686       // that start the list is the size of the previous list.
4687       std::advance(this->I, PrevListSize);
4688     }
4689 
4690     // Return the array with the current list. The sizes are cumulative, so the
4691     // array size is the difference between the current size and previous one.
4692     std::pair<const ValueDecl *, MappableExprComponentListRef>
4693     operator*() const {
4694       assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
4695       return std::make_pair(
4696           *DeclCur,
4697           MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize));
4698     }
4699     std::pair<const ValueDecl *, MappableExprComponentListRef>
4700     operator->() const {
4701       return **this;
4702     }
4703 
4704     // Skip the components of the current list.
4705     const_component_lists_iterator &operator++() {
4706       assert(ListSizeCur != ListSizeEnd && RemainingLists &&
4707              "Invalid iterator!");
4708 
4709       // If we don't have more lists just skip all the components. Otherwise,
4710       // advance the iterator by the number of components in the current list.
4711       if (std::next(ListSizeCur) == ListSizeEnd) {
4712         this->I = End;
4713         RemainingLists = 0;
4714       } else {
4715         std::advance(this->I, *ListSizeCur - PrevListSize);
4716         PrevListSize = *ListSizeCur;
4717 
4718         // We are done with a declaration, move to the next one.
4719         if (!(--RemainingLists)) {
4720           ++DeclCur;
4721           ++NumListsCur;
4722           RemainingLists = *NumListsCur;
4723           assert(RemainingLists && "No lists in the following declaration??");
4724         }
4725       }
4726 
4727       ++ListSizeCur;
4728       return *this;
4729     }
4730   };
4731 
4732   using const_component_lists_range =
4733       llvm::iterator_range<const_component_lists_iterator>;
4734 
4735   /// Iterators for all component lists.
component_lists_begin()4736   const_component_lists_iterator component_lists_begin() const {
4737     return const_component_lists_iterator(
4738         getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
4739         getComponentsRef());
4740   }
component_lists_end()4741   const_component_lists_iterator component_lists_end() const {
4742     return const_component_lists_iterator(
4743         ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
4744         MappableExprComponentListRef(getComponentsRef().end(),
4745                                      getComponentsRef().end()));
4746   }
component_lists()4747   const_component_lists_range component_lists() const {
4748     return {component_lists_begin(), component_lists_end()};
4749   }
4750 
4751   /// Iterators for component lists associated with the provided
4752   /// declaration.
4753   const_component_lists_iterator
decl_component_lists_begin(const ValueDecl * VD)4754   decl_component_lists_begin(const ValueDecl *VD) const {
4755     return const_component_lists_iterator(
4756         VD, getUniqueDeclsRef(), getDeclNumListsRef(),
4757         getComponentListSizesRef(), getComponentsRef());
4758   }
decl_component_lists_end()4759   const_component_lists_iterator decl_component_lists_end() const {
4760     return component_lists_end();
4761   }
decl_component_lists(const ValueDecl * VD)4762   const_component_lists_range decl_component_lists(const ValueDecl *VD) const {
4763     return {decl_component_lists_begin(VD), decl_component_lists_end()};
4764   }
4765 
4766   /// Iterators to access all the declarations, number of lists, list sizes, and
4767   /// components.
4768   using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
4769   using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
4770 
all_decls()4771   const_all_decls_range all_decls() const {
4772     auto A = getUniqueDeclsRef();
4773     return const_all_decls_range(A.begin(), A.end());
4774   }
4775 
4776   using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
4777   using const_all_num_lists_range =
4778       llvm::iterator_range<const_all_num_lists_iterator>;
4779 
all_num_lists()4780   const_all_num_lists_range all_num_lists() const {
4781     auto A = getDeclNumListsRef();
4782     return const_all_num_lists_range(A.begin(), A.end());
4783   }
4784 
4785   using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
4786   using const_all_lists_sizes_range =
4787       llvm::iterator_range<const_all_lists_sizes_iterator>;
4788 
all_lists_sizes()4789   const_all_lists_sizes_range all_lists_sizes() const {
4790     auto A = getComponentListSizesRef();
4791     return const_all_lists_sizes_range(A.begin(), A.end());
4792   }
4793 
4794   using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
4795   using const_all_components_range =
4796       llvm::iterator_range<const_all_components_iterator>;
4797 
all_components()4798   const_all_components_range all_components() const {
4799     auto A = getComponentsRef();
4800     return const_all_components_range(A.begin(), A.end());
4801   }
4802 
4803   using mapperlist_iterator = MutableArrayRef<Expr *>::iterator;
4804   using mapperlist_const_iterator = ArrayRef<const Expr *>::iterator;
4805   using mapperlist_range = llvm::iterator_range<mapperlist_iterator>;
4806   using mapperlist_const_range =
4807       llvm::iterator_range<mapperlist_const_iterator>;
4808 
mapperlist_begin()4809   mapperlist_iterator mapperlist_begin() { return getUDMapperRefs().begin(); }
mapperlist_end()4810   mapperlist_iterator mapperlist_end() { return getUDMapperRefs().end(); }
mapperlist_begin()4811   mapperlist_const_iterator mapperlist_begin() const {
4812     return getUDMapperRefs().begin();
4813   }
mapperlist_end()4814   mapperlist_const_iterator mapperlist_end() const {
4815     return getUDMapperRefs().end();
4816   }
mapperlists()4817   mapperlist_range mapperlists() {
4818     return mapperlist_range(mapperlist_begin(), mapperlist_end());
4819   }
mapperlists()4820   mapperlist_const_range mapperlists() const {
4821     return mapperlist_const_range(mapperlist_begin(), mapperlist_end());
4822   }
4823 };
4824 
4825 /// This represents clause 'map' in the '#pragma omp ...'
4826 /// directives.
4827 ///
4828 /// \code
4829 /// #pragma omp target map(a,b)
4830 /// \endcode
4831 /// In this example directive '#pragma omp target' has clause 'map'
4832 /// with the variables 'a' and 'b'.
4833 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
4834                            private llvm::TrailingObjects<
4835                                OMPMapClause, Expr *, ValueDecl *, unsigned,
4836                                OMPClauseMappableExprCommon::MappableComponent> {
4837   friend class OMPClauseReader;
4838   friend OMPMappableExprListClause;
4839   friend OMPVarListClause;
4840   friend TrailingObjects;
4841 
4842   /// Define the sizes of each trailing object array except the last one. This
4843   /// is required for TrailingObjects to work properly.
numTrailingObjects(OverloadToken<Expr * >)4844   size_t numTrailingObjects(OverloadToken<Expr *>) const {
4845     // There are varlist_size() of expressions, and varlist_size() of
4846     // user-defined mappers.
4847     return 2 * varlist_size();
4848   }
numTrailingObjects(OverloadToken<ValueDecl * >)4849   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4850     return getUniqueDeclarationsNum();
4851   }
numTrailingObjects(OverloadToken<unsigned>)4852   size_t numTrailingObjects(OverloadToken<unsigned>) const {
4853     return getUniqueDeclarationsNum() + getTotalComponentListNum();
4854   }
4855 
4856 public:
4857   /// Number of allowed map-type-modifiers.
4858   static constexpr unsigned NumberOfModifiers =
4859       OMPC_MAP_MODIFIER_last - OMPC_MAP_MODIFIER_unknown - 1;
4860 
4861 private:
4862   /// Map-type-modifiers for the 'map' clause.
4863   OpenMPMapModifierKind MapTypeModifiers[NumberOfModifiers] = {
4864       OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
4865       OMPC_MAP_MODIFIER_unknown};
4866 
4867   /// Location of map-type-modifiers for the 'map' clause.
4868   SourceLocation MapTypeModifiersLoc[NumberOfModifiers];
4869 
4870   /// Map type for the 'map' clause.
4871   OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
4872 
4873   /// Is this an implicit map type or not.
4874   bool MapTypeIsImplicit = false;
4875 
4876   /// Location of the map type.
4877   SourceLocation MapLoc;
4878 
4879   /// Colon location.
4880   SourceLocation ColonLoc;
4881 
4882   /// Build a clause for \a NumVars listed expressions, \a
4883   /// NumUniqueDeclarations declarations, \a NumComponentLists total component
4884   /// lists, and \a NumComponents total expression components.
4885   ///
4886   /// \param MapModifiers Map-type-modifiers.
4887   /// \param MapModifiersLoc Locations of map-type-modifiers.
4888   /// \param MapperQualifierLoc C++ nested name specifier for the associated
4889   /// user-defined mapper.
4890   /// \param MapperIdInfo The identifier of associated user-defined mapper.
4891   /// \param MapType Map type.
4892   /// \param MapTypeIsImplicit Map type is inferred implicitly.
4893   /// \param MapLoc Location of the map type.
4894   /// \param Locs Locations needed to build a mappable clause. It includes 1)
4895   /// StartLoc: starting location of the clause (the clause keyword); 2)
4896   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4897   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4898   /// NumVars: number of expressions listed in this clause; 2)
4899   /// NumUniqueDeclarations: number of unique base declarations in this clause;
4900   /// 3) NumComponentLists: number of component lists in this clause; and 4)
4901   /// NumComponents: total number of expression components in the clause.
OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,ArrayRef<SourceLocation> MapModifiersLoc,NestedNameSpecifierLoc MapperQualifierLoc,DeclarationNameInfo MapperIdInfo,OpenMPMapClauseKind MapType,bool MapTypeIsImplicit,SourceLocation MapLoc,const OMPVarListLocTy & Locs,const OMPMappableExprListSizeTy & Sizes)4902   explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,
4903                         ArrayRef<SourceLocation> MapModifiersLoc,
4904                         NestedNameSpecifierLoc MapperQualifierLoc,
4905                         DeclarationNameInfo MapperIdInfo,
4906                         OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
4907                         SourceLocation MapLoc, const OMPVarListLocTy &Locs,
4908                         const OMPMappableExprListSizeTy &Sizes)
4909       : OMPMappableExprListClause(OMPC_map, Locs, Sizes, &MapperQualifierLoc,
4910                                   &MapperIdInfo),
4911         MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
4912     assert(llvm::array_lengthof(MapTypeModifiers) == MapModifiers.size() &&
4913            "Unexpected number of map type modifiers.");
4914     llvm::copy(MapModifiers, std::begin(MapTypeModifiers));
4915 
4916     assert(llvm::array_lengthof(MapTypeModifiersLoc) ==
4917                MapModifiersLoc.size() &&
4918            "Unexpected number of map type modifier locations.");
4919     llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
4920   }
4921 
4922   /// Build an empty clause.
4923   ///
4924   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4925   /// NumVars: number of expressions listed in this clause; 2)
4926   /// NumUniqueDeclarations: number of unique base declarations in this clause;
4927   /// 3) NumComponentLists: number of component lists in this clause; and 4)
4928   /// NumComponents: total number of expression components in the clause.
OMPMapClause(const OMPMappableExprListSizeTy & Sizes)4929   explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes)
4930       : OMPMappableExprListClause(OMPC_map, OMPVarListLocTy(), Sizes) {}
4931 
4932   /// Set map-type-modifier for the clause.
4933   ///
4934   /// \param I index for map-type-modifier.
4935   /// \param T map-type-modifier for the clause.
setMapTypeModifier(unsigned I,OpenMPMapModifierKind T)4936   void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
4937     assert(I < NumberOfModifiers &&
4938            "Unexpected index to store map type modifier, exceeds array size.");
4939     MapTypeModifiers[I] = T;
4940   }
4941 
4942   /// Set location for the map-type-modifier.
4943   ///
4944   /// \param I index for map-type-modifier location.
4945   /// \param TLoc map-type-modifier location.
setMapTypeModifierLoc(unsigned I,SourceLocation TLoc)4946   void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
4947     assert(I < NumberOfModifiers &&
4948            "Index to store map type modifier location exceeds array size.");
4949     MapTypeModifiersLoc[I] = TLoc;
4950   }
4951 
4952   /// Set type for the clause.
4953   ///
4954   /// \param T Type for the clause.
setMapType(OpenMPMapClauseKind T)4955   void setMapType(OpenMPMapClauseKind T) { MapType = T; }
4956 
4957   /// Set type location.
4958   ///
4959   /// \param TLoc Type location.
setMapLoc(SourceLocation TLoc)4960   void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
4961 
4962   /// Set colon location.
setColonLoc(SourceLocation Loc)4963   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4964 
4965 public:
4966   /// Creates clause with a list of variables \a VL.
4967   ///
4968   /// \param C AST context.
4969   /// \param Locs Locations needed to build a mappable clause. It includes 1)
4970   /// StartLoc: starting location of the clause (the clause keyword); 2)
4971   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4972   /// \param Vars The original expression used in the clause.
4973   /// \param Declarations Declarations used in the clause.
4974   /// \param ComponentLists Component lists used in the clause.
4975   /// \param UDMapperRefs References to user-defined mappers associated with
4976   /// expressions used in the clause.
4977   /// \param MapModifiers Map-type-modifiers.
4978   /// \param MapModifiersLoc Location of map-type-modifiers.
4979   /// \param UDMQualifierLoc C++ nested name specifier for the associated
4980   /// user-defined mapper.
4981   /// \param MapperId The identifier of associated user-defined mapper.
4982   /// \param Type Map type.
4983   /// \param TypeIsImplicit Map type is inferred implicitly.
4984   /// \param TypeLoc Location of the map type.
4985   static OMPMapClause *
4986   Create(const ASTContext &C, const OMPVarListLocTy &Locs,
4987          ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
4988          MappableExprComponentListsRef ComponentLists,
4989          ArrayRef<Expr *> UDMapperRefs,
4990          ArrayRef<OpenMPMapModifierKind> MapModifiers,
4991          ArrayRef<SourceLocation> MapModifiersLoc,
4992          NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
4993          OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc);
4994 
4995   /// Creates an empty clause with the place for \a NumVars original
4996   /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
4997   /// lists, and \a NumComponents expression components.
4998   ///
4999   /// \param C AST context.
5000   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5001   /// NumVars: number of expressions listed in this clause; 2)
5002   /// NumUniqueDeclarations: number of unique base declarations in this clause;
5003   /// 3) NumComponentLists: number of component lists in this clause; and 4)
5004   /// NumComponents: total number of expression components in the clause.
5005   static OMPMapClause *CreateEmpty(const ASTContext &C,
5006                                    const OMPMappableExprListSizeTy &Sizes);
5007 
5008   /// Fetches mapping kind for the clause.
getMapType()5009   OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
5010 
5011   /// Is this an implicit map type?
5012   /// We have to capture 'IsMapTypeImplicit' from the parser for more
5013   /// informative error messages.  It helps distinguish map(r) from
5014   /// map(tofrom: r), which is important to print more helpful error
5015   /// messages for some target directives.
isImplicitMapType()5016   bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
5017 
5018   /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
5019   ///
5020   /// \param Cnt index for map-type-modifier.
getMapTypeModifier(unsigned Cnt)5021   OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
5022     assert(Cnt < NumberOfModifiers &&
5023            "Requested modifier exceeds the total number of modifiers.");
5024     return MapTypeModifiers[Cnt];
5025   }
5026 
5027   /// Fetches the map-type-modifier location at 'Cnt' index of array of
5028   /// modifiers' locations.
5029   ///
5030   /// \param Cnt index for map-type-modifier location.
getMapTypeModifierLoc(unsigned Cnt)5031   SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
5032     assert(Cnt < NumberOfModifiers &&
5033            "Requested modifier location exceeds total number of modifiers.");
5034     return MapTypeModifiersLoc[Cnt];
5035   }
5036 
5037   /// Fetches ArrayRef of map-type-modifiers.
getMapTypeModifiers()5038   ArrayRef<OpenMPMapModifierKind> getMapTypeModifiers() const LLVM_READONLY {
5039     return llvm::makeArrayRef(MapTypeModifiers);
5040   }
5041 
5042   /// Fetches ArrayRef of location of map-type-modifiers.
getMapTypeModifiersLoc()5043   ArrayRef<SourceLocation> getMapTypeModifiersLoc() const LLVM_READONLY {
5044     return llvm::makeArrayRef(MapTypeModifiersLoc);
5045   }
5046 
5047   /// Fetches location of clause mapping kind.
getMapLoc()5048   SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
5049 
5050   /// Get colon location.
getColonLoc()5051   SourceLocation getColonLoc() const { return ColonLoc; }
5052 
children()5053   child_range children() {
5054     return child_range(
5055         reinterpret_cast<Stmt **>(varlist_begin()),
5056         reinterpret_cast<Stmt **>(varlist_end()));
5057   }
5058 
children()5059   const_child_range children() const {
5060     auto Children = const_cast<OMPMapClause *>(this)->children();
5061     return const_child_range(Children.begin(), Children.end());
5062   }
5063 
used_children()5064   child_range used_children() {
5065     if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_tofrom)
5066       return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5067                          reinterpret_cast<Stmt **>(varlist_end()));
5068     return child_range(child_iterator(), child_iterator());
5069   }
used_children()5070   const_child_range used_children() const {
5071     auto Children = const_cast<OMPMapClause *>(this)->used_children();
5072     return const_child_range(Children.begin(), Children.end());
5073   }
5074 
5075 
classof(const OMPClause * T)5076   static bool classof(const OMPClause *T) {
5077     return T->getClauseKind() == OMPC_map;
5078   }
5079 };
5080 
5081 /// This represents 'num_teams' clause in the '#pragma omp ...'
5082 /// directive.
5083 ///
5084 /// \code
5085 /// #pragma omp teams num_teams(n)
5086 /// \endcode
5087 /// In this example directive '#pragma omp teams' has clause 'num_teams'
5088 /// with single expression 'n'.
5089 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
5090   friend class OMPClauseReader;
5091 
5092   /// Location of '('.
5093   SourceLocation LParenLoc;
5094 
5095   /// NumTeams number.
5096   Stmt *NumTeams = nullptr;
5097 
5098   /// Set the NumTeams number.
5099   ///
5100   /// \param E NumTeams number.
setNumTeams(Expr * E)5101   void setNumTeams(Expr *E) { NumTeams = E; }
5102 
5103 public:
5104   /// Build 'num_teams' clause.
5105   ///
5106   /// \param E Expression associated with this clause.
5107   /// \param HelperE Helper Expression associated with this clause.
5108   /// \param CaptureRegion Innermost OpenMP region where expressions in this
5109   /// clause must be captured.
5110   /// \param StartLoc Starting location of the clause.
5111   /// \param LParenLoc Location of '('.
5112   /// \param EndLoc Ending location of the clause.
OMPNumTeamsClause(Expr * E,Stmt * HelperE,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)5113   OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
5114                     SourceLocation StartLoc, SourceLocation LParenLoc,
5115                     SourceLocation EndLoc)
5116       : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this),
5117         LParenLoc(LParenLoc), NumTeams(E) {
5118     setPreInitStmt(HelperE, CaptureRegion);
5119   }
5120 
5121   /// Build an empty clause.
OMPNumTeamsClause()5122   OMPNumTeamsClause()
5123       : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
5124         OMPClauseWithPreInit(this) {}
5125 
5126   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)5127   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5128 
5129   /// Returns the location of '('.
getLParenLoc()5130   SourceLocation getLParenLoc() const { return LParenLoc; }
5131 
5132   /// Return NumTeams number.
getNumTeams()5133   Expr *getNumTeams() { return cast<Expr>(NumTeams); }
5134 
5135   /// Return NumTeams number.
getNumTeams()5136   Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
5137 
children()5138   child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
5139 
children()5140   const_child_range children() const {
5141     return const_child_range(&NumTeams, &NumTeams + 1);
5142   }
5143 
used_children()5144   child_range used_children() {
5145     return child_range(child_iterator(), child_iterator());
5146   }
used_children()5147   const_child_range used_children() const {
5148     return const_child_range(const_child_iterator(), const_child_iterator());
5149   }
5150 
classof(const OMPClause * T)5151   static bool classof(const OMPClause *T) {
5152     return T->getClauseKind() == OMPC_num_teams;
5153   }
5154 };
5155 
5156 /// This represents 'thread_limit' clause in the '#pragma omp ...'
5157 /// directive.
5158 ///
5159 /// \code
5160 /// #pragma omp teams thread_limit(n)
5161 /// \endcode
5162 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
5163 /// with single expression 'n'.
5164 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
5165   friend class OMPClauseReader;
5166 
5167   /// Location of '('.
5168   SourceLocation LParenLoc;
5169 
5170   /// ThreadLimit number.
5171   Stmt *ThreadLimit = nullptr;
5172 
5173   /// Set the ThreadLimit number.
5174   ///
5175   /// \param E ThreadLimit number.
setThreadLimit(Expr * E)5176   void setThreadLimit(Expr *E) { ThreadLimit = E; }
5177 
5178 public:
5179   /// Build 'thread_limit' clause.
5180   ///
5181   /// \param E Expression associated with this clause.
5182   /// \param HelperE Helper Expression associated with this clause.
5183   /// \param CaptureRegion Innermost OpenMP region where expressions in this
5184   /// clause must be captured.
5185   /// \param StartLoc Starting location of the clause.
5186   /// \param LParenLoc Location of '('.
5187   /// \param EndLoc Ending location of the clause.
OMPThreadLimitClause(Expr * E,Stmt * HelperE,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)5188   OMPThreadLimitClause(Expr *E, Stmt *HelperE,
5189                        OpenMPDirectiveKind CaptureRegion,
5190                        SourceLocation StartLoc, SourceLocation LParenLoc,
5191                        SourceLocation EndLoc)
5192       : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
5193         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
5194     setPreInitStmt(HelperE, CaptureRegion);
5195   }
5196 
5197   /// Build an empty clause.
OMPThreadLimitClause()5198   OMPThreadLimitClause()
5199       : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
5200         OMPClauseWithPreInit(this) {}
5201 
5202   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)5203   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5204 
5205   /// Returns the location of '('.
getLParenLoc()5206   SourceLocation getLParenLoc() const { return LParenLoc; }
5207 
5208   /// Return ThreadLimit number.
getThreadLimit()5209   Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
5210 
5211   /// Return ThreadLimit number.
getThreadLimit()5212   Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
5213 
children()5214   child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
5215 
children()5216   const_child_range children() const {
5217     return const_child_range(&ThreadLimit, &ThreadLimit + 1);
5218   }
5219 
used_children()5220   child_range used_children() {
5221     return child_range(child_iterator(), child_iterator());
5222   }
used_children()5223   const_child_range used_children() const {
5224     return const_child_range(const_child_iterator(), const_child_iterator());
5225   }
5226 
classof(const OMPClause * T)5227   static bool classof(const OMPClause *T) {
5228     return T->getClauseKind() == OMPC_thread_limit;
5229   }
5230 };
5231 
5232 /// This represents 'priority' clause in the '#pragma omp ...'
5233 /// directive.
5234 ///
5235 /// \code
5236 /// #pragma omp task priority(n)
5237 /// \endcode
5238 /// In this example directive '#pragma omp teams' has clause 'priority' with
5239 /// single expression 'n'.
5240 class OMPPriorityClause : public OMPClause, public OMPClauseWithPreInit {
5241   friend class OMPClauseReader;
5242 
5243   /// Location of '('.
5244   SourceLocation LParenLoc;
5245 
5246   /// Priority number.
5247   Stmt *Priority = nullptr;
5248 
5249   /// Set the Priority number.
5250   ///
5251   /// \param E Priority number.
setPriority(Expr * E)5252   void setPriority(Expr *E) { Priority = E; }
5253 
5254 public:
5255   /// Build 'priority' clause.
5256   ///
5257   /// \param Priority Expression associated with this clause.
5258   /// \param HelperPriority Helper priority for the construct.
5259   /// \param CaptureRegion Innermost OpenMP region where expressions in this
5260   /// clause must be captured.
5261   /// \param StartLoc Starting location of the clause.
5262   /// \param LParenLoc Location of '('.
5263   /// \param EndLoc Ending location of the clause.
OMPPriorityClause(Expr * Priority,Stmt * HelperPriority,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)5264   OMPPriorityClause(Expr *Priority, Stmt *HelperPriority,
5265                     OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5266                     SourceLocation LParenLoc, SourceLocation EndLoc)
5267       : OMPClause(OMPC_priority, StartLoc, EndLoc), OMPClauseWithPreInit(this),
5268         LParenLoc(LParenLoc), Priority(Priority) {
5269     setPreInitStmt(HelperPriority, CaptureRegion);
5270   }
5271 
5272   /// Build an empty clause.
OMPPriorityClause()5273   OMPPriorityClause()
5274       : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()),
5275         OMPClauseWithPreInit(this) {}
5276 
5277   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)5278   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5279 
5280   /// Returns the location of '('.
getLParenLoc()5281   SourceLocation getLParenLoc() const { return LParenLoc; }
5282 
5283   /// Return Priority number.
getPriority()5284   Expr *getPriority() { return cast<Expr>(Priority); }
5285 
5286   /// Return Priority number.
getPriority()5287   Expr *getPriority() const { return cast<Expr>(Priority); }
5288 
children()5289   child_range children() { return child_range(&Priority, &Priority + 1); }
5290 
children()5291   const_child_range children() const {
5292     return const_child_range(&Priority, &Priority + 1);
5293   }
5294 
5295   child_range used_children();
used_children()5296   const_child_range used_children() const {
5297     auto Children = const_cast<OMPPriorityClause *>(this)->used_children();
5298     return const_child_range(Children.begin(), Children.end());
5299   }
5300 
classof(const OMPClause * T)5301   static bool classof(const OMPClause *T) {
5302     return T->getClauseKind() == OMPC_priority;
5303   }
5304 };
5305 
5306 /// This represents 'grainsize' clause in the '#pragma omp ...'
5307 /// directive.
5308 ///
5309 /// \code
5310 /// #pragma omp taskloop grainsize(4)
5311 /// \endcode
5312 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
5313 /// with single expression '4'.
5314 class OMPGrainsizeClause : public OMPClause, public OMPClauseWithPreInit {
5315   friend class OMPClauseReader;
5316 
5317   /// Location of '('.
5318   SourceLocation LParenLoc;
5319 
5320   /// Safe iteration space distance.
5321   Stmt *Grainsize = nullptr;
5322 
5323   /// Set safelen.
setGrainsize(Expr * Size)5324   void setGrainsize(Expr *Size) { Grainsize = Size; }
5325 
5326 public:
5327   /// Build 'grainsize' clause.
5328   ///
5329   /// \param Size Expression associated with this clause.
5330   /// \param HelperSize Helper grainsize for the construct.
5331   /// \param CaptureRegion Innermost OpenMP region where expressions in this
5332   /// clause must be captured.
5333   /// \param StartLoc Starting location of the clause.
5334   /// \param EndLoc Ending location of the clause.
OMPGrainsizeClause(Expr * Size,Stmt * HelperSize,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)5335   OMPGrainsizeClause(Expr *Size, Stmt *HelperSize,
5336                      OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5337                      SourceLocation LParenLoc, SourceLocation EndLoc)
5338       : OMPClause(OMPC_grainsize, StartLoc, EndLoc), OMPClauseWithPreInit(this),
5339         LParenLoc(LParenLoc), Grainsize(Size) {
5340     setPreInitStmt(HelperSize, CaptureRegion);
5341   }
5342 
5343   /// Build an empty clause.
OMPGrainsizeClause()5344   explicit OMPGrainsizeClause()
5345       : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()),
5346         OMPClauseWithPreInit(this) {}
5347 
5348   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)5349   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5350 
5351   /// Returns the location of '('.
getLParenLoc()5352   SourceLocation getLParenLoc() const { return LParenLoc; }
5353 
5354   /// Return safe iteration space distance.
getGrainsize()5355   Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
5356 
children()5357   child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
5358 
children()5359   const_child_range children() const {
5360     return const_child_range(&Grainsize, &Grainsize + 1);
5361   }
5362 
5363   child_range used_children();
used_children()5364   const_child_range used_children() const {
5365     auto Children = const_cast<OMPGrainsizeClause *>(this)->used_children();
5366     return const_child_range(Children.begin(), Children.end());
5367   }
5368 
classof(const OMPClause * T)5369   static bool classof(const OMPClause *T) {
5370     return T->getClauseKind() == OMPC_grainsize;
5371   }
5372 };
5373 
5374 /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
5375 ///
5376 /// \code
5377 /// #pragma omp taskloop nogroup
5378 /// \endcode
5379 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
5380 class OMPNogroupClause : public OMPClause {
5381 public:
5382   /// Build 'nogroup' clause.
5383   ///
5384   /// \param StartLoc Starting location of the clause.
5385   /// \param EndLoc Ending location of the clause.
OMPNogroupClause(SourceLocation StartLoc,SourceLocation EndLoc)5386   OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
5387       : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
5388 
5389   /// Build an empty clause.
OMPNogroupClause()5390   OMPNogroupClause()
5391       : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
5392 
children()5393   child_range children() {
5394     return child_range(child_iterator(), child_iterator());
5395   }
5396 
children()5397   const_child_range children() const {
5398     return const_child_range(const_child_iterator(), const_child_iterator());
5399   }
5400 
used_children()5401   child_range used_children() {
5402     return child_range(child_iterator(), child_iterator());
5403   }
used_children()5404   const_child_range used_children() const {
5405     return const_child_range(const_child_iterator(), const_child_iterator());
5406   }
5407 
classof(const OMPClause * T)5408   static bool classof(const OMPClause *T) {
5409     return T->getClauseKind() == OMPC_nogroup;
5410   }
5411 };
5412 
5413 /// This represents 'num_tasks' clause in the '#pragma omp ...'
5414 /// directive.
5415 ///
5416 /// \code
5417 /// #pragma omp taskloop num_tasks(4)
5418 /// \endcode
5419 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
5420 /// with single expression '4'.
5421 class OMPNumTasksClause : public OMPClause, public OMPClauseWithPreInit {
5422   friend class OMPClauseReader;
5423 
5424   /// Location of '('.
5425   SourceLocation LParenLoc;
5426 
5427   /// Safe iteration space distance.
5428   Stmt *NumTasks = nullptr;
5429 
5430   /// Set safelen.
setNumTasks(Expr * Size)5431   void setNumTasks(Expr *Size) { NumTasks = Size; }
5432 
5433 public:
5434   /// Build 'num_tasks' clause.
5435   ///
5436   /// \param Size Expression associated with this clause.
5437   /// \param HelperSize Helper grainsize for the construct.
5438   /// \param CaptureRegion Innermost OpenMP region where expressions in this
5439   /// clause must be captured.
5440   /// \param StartLoc Starting location of the clause.
5441   /// \param EndLoc Ending location of the clause.
OMPNumTasksClause(Expr * Size,Stmt * HelperSize,OpenMPDirectiveKind CaptureRegion,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)5442   OMPNumTasksClause(Expr *Size, Stmt *HelperSize,
5443                     OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5444                     SourceLocation LParenLoc, SourceLocation EndLoc)
5445       : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), OMPClauseWithPreInit(this),
5446         LParenLoc(LParenLoc), NumTasks(Size) {
5447     setPreInitStmt(HelperSize, CaptureRegion);
5448   }
5449 
5450   /// Build an empty clause.
OMPNumTasksClause()5451   explicit OMPNumTasksClause()
5452       : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()),
5453         OMPClauseWithPreInit(this) {}
5454 
5455   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)5456   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5457 
5458   /// Returns the location of '('.
getLParenLoc()5459   SourceLocation getLParenLoc() const { return LParenLoc; }
5460 
5461   /// Return safe iteration space distance.
getNumTasks()5462   Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
5463 
children()5464   child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
5465 
children()5466   const_child_range children() const {
5467     return const_child_range(&NumTasks, &NumTasks + 1);
5468   }
5469 
5470   child_range used_children();
used_children()5471   const_child_range used_children() const {
5472     auto Children = const_cast<OMPNumTasksClause *>(this)->used_children();
5473     return const_child_range(Children.begin(), Children.end());
5474   }
5475 
classof(const OMPClause * T)5476   static bool classof(const OMPClause *T) {
5477     return T->getClauseKind() == OMPC_num_tasks;
5478   }
5479 };
5480 
5481 /// This represents 'hint' clause in the '#pragma omp ...' directive.
5482 ///
5483 /// \code
5484 /// #pragma omp critical (name) hint(6)
5485 /// \endcode
5486 /// In this example directive '#pragma omp critical' has name 'name' and clause
5487 /// 'hint' with argument '6'.
5488 class OMPHintClause : public OMPClause {
5489   friend class OMPClauseReader;
5490 
5491   /// Location of '('.
5492   SourceLocation LParenLoc;
5493 
5494   /// Hint expression of the 'hint' clause.
5495   Stmt *Hint = nullptr;
5496 
5497   /// Set hint expression.
setHint(Expr * H)5498   void setHint(Expr *H) { Hint = H; }
5499 
5500 public:
5501   /// Build 'hint' clause with expression \a Hint.
5502   ///
5503   /// \param Hint Hint expression.
5504   /// \param StartLoc Starting location of the clause.
5505   /// \param LParenLoc Location of '('.
5506   /// \param EndLoc Ending location of the clause.
OMPHintClause(Expr * Hint,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)5507   OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
5508                 SourceLocation EndLoc)
5509       : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
5510         Hint(Hint) {}
5511 
5512   /// Build an empty clause.
OMPHintClause()5513   OMPHintClause() : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()) {}
5514 
5515   /// Sets the location of '('.
setLParenLoc(SourceLocation Loc)5516   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5517 
5518   /// Returns the location of '('.
getLParenLoc()5519   SourceLocation getLParenLoc() const { return LParenLoc; }
5520 
5521   /// Returns number of threads.
getHint()5522   Expr *getHint() const { return cast_or_null<Expr>(Hint); }
5523 
children()5524   child_range children() { return child_range(&Hint, &Hint + 1); }
5525 
children()5526   const_child_range children() const {
5527     return const_child_range(&Hint, &Hint + 1);
5528   }
5529 
used_children()5530   child_range used_children() {
5531     return child_range(child_iterator(), child_iterator());
5532   }
used_children()5533   const_child_range used_children() const {
5534     return const_child_range(const_child_iterator(), const_child_iterator());
5535   }
5536 
classof(const OMPClause * T)5537   static bool classof(const OMPClause *T) {
5538     return T->getClauseKind() == OMPC_hint;
5539   }
5540 };
5541 
5542 /// This represents 'dist_schedule' clause in the '#pragma omp ...'
5543 /// directive.
5544 ///
5545 /// \code
5546 /// #pragma omp distribute dist_schedule(static, 3)
5547 /// \endcode
5548 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
5549 /// clause with arguments 'static' and '3'.
5550 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
5551   friend class OMPClauseReader;
5552 
5553   /// Location of '('.
5554   SourceLocation LParenLoc;
5555 
5556   /// A kind of the 'schedule' clause.
5557   OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
5558 
5559   /// Start location of the schedule kind in source code.
5560   SourceLocation KindLoc;
5561 
5562   /// Location of ',' (if any).
5563   SourceLocation CommaLoc;
5564 
5565   /// Chunk size.
5566   Expr *ChunkSize = nullptr;
5567 
5568   /// Set schedule kind.
5569   ///
5570   /// \param K Schedule kind.
setDistScheduleKind(OpenMPDistScheduleClauseKind K)5571   void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
5572 
5573   /// Sets the location of '('.
5574   ///
5575   /// \param Loc Location of '('.
setLParenLoc(SourceLocation Loc)5576   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5577 
5578   /// Set schedule kind start location.
5579   ///
5580   /// \param KLoc Schedule kind location.
setDistScheduleKindLoc(SourceLocation KLoc)5581   void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
5582 
5583   /// Set location of ','.
5584   ///
5585   /// \param Loc Location of ','.
setCommaLoc(SourceLocation Loc)5586   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
5587 
5588   /// Set chunk size.
5589   ///
5590   /// \param E Chunk size.
setChunkSize(Expr * E)5591   void setChunkSize(Expr *E) { ChunkSize = E; }
5592 
5593 public:
5594   /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
5595   /// size expression \a ChunkSize.
5596   ///
5597   /// \param StartLoc Starting location of the clause.
5598   /// \param LParenLoc Location of '('.
5599   /// \param KLoc Starting location of the argument.
5600   /// \param CommaLoc Location of ','.
5601   /// \param EndLoc Ending location of the clause.
5602   /// \param Kind DistSchedule kind.
5603   /// \param ChunkSize Chunk size.
5604   /// \param HelperChunkSize Helper chunk size for combined directives.
OMPDistScheduleClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation KLoc,SourceLocation CommaLoc,SourceLocation EndLoc,OpenMPDistScheduleClauseKind Kind,Expr * ChunkSize,Stmt * HelperChunkSize)5605   OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5606                         SourceLocation KLoc, SourceLocation CommaLoc,
5607                         SourceLocation EndLoc,
5608                         OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
5609                         Stmt *HelperChunkSize)
5610       : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc),
5611         OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
5612         KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
5613     setPreInitStmt(HelperChunkSize);
5614   }
5615 
5616   /// Build an empty clause.
OMPDistScheduleClause()5617   explicit OMPDistScheduleClause()
5618       : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()),
5619         OMPClauseWithPreInit(this) {}
5620 
5621   /// Get kind of the clause.
getDistScheduleKind()5622   OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
5623 
5624   /// Get location of '('.
getLParenLoc()5625   SourceLocation getLParenLoc() { return LParenLoc; }
5626 
5627   /// Get kind location.
getDistScheduleKindLoc()5628   SourceLocation getDistScheduleKindLoc() { return KindLoc; }
5629 
5630   /// Get location of ','.
getCommaLoc()5631   SourceLocation getCommaLoc() { return CommaLoc; }
5632 
5633   /// Get chunk size.
getChunkSize()5634   Expr *getChunkSize() { return ChunkSize; }
5635 
5636   /// Get chunk size.
getChunkSize()5637   const Expr *getChunkSize() const { return ChunkSize; }
5638 
children()5639   child_range children() {
5640     return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
5641                        reinterpret_cast<Stmt **>(&ChunkSize) + 1);
5642   }
5643 
children()5644   const_child_range children() const {
5645     auto Children = const_cast<OMPDistScheduleClause *>(this)->children();
5646     return const_child_range(Children.begin(), Children.end());
5647   }
5648 
used_children()5649   child_range used_children() {
5650     return child_range(child_iterator(), child_iterator());
5651   }
used_children()5652   const_child_range used_children() const {
5653     return const_child_range(const_child_iterator(), const_child_iterator());
5654   }
5655 
classof(const OMPClause * T)5656   static bool classof(const OMPClause *T) {
5657     return T->getClauseKind() == OMPC_dist_schedule;
5658   }
5659 };
5660 
5661 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
5662 ///
5663 /// \code
5664 /// #pragma omp target defaultmap(tofrom: scalar)
5665 /// \endcode
5666 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
5667 /// 'scalar' with modifier 'tofrom'.
5668 class OMPDefaultmapClause : public OMPClause {
5669   friend class OMPClauseReader;
5670 
5671   /// Location of '('.
5672   SourceLocation LParenLoc;
5673 
5674   /// Modifiers for 'defaultmap' clause.
5675   OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
5676 
5677   /// Locations of modifiers.
5678   SourceLocation ModifierLoc;
5679 
5680   /// A kind of the 'defaultmap' clause.
5681   OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
5682 
5683   /// Start location of the defaultmap kind in source code.
5684   SourceLocation KindLoc;
5685 
5686   /// Set defaultmap kind.
5687   ///
5688   /// \param K Defaultmap kind.
setDefaultmapKind(OpenMPDefaultmapClauseKind K)5689   void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
5690 
5691   /// Set the defaultmap modifier.
5692   ///
5693   /// \param M Defaultmap modifier.
setDefaultmapModifier(OpenMPDefaultmapClauseModifier M)5694   void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
5695     Modifier = M;
5696   }
5697 
5698   /// Set location of the defaultmap modifier.
setDefaultmapModifierLoc(SourceLocation Loc)5699   void setDefaultmapModifierLoc(SourceLocation Loc) {
5700     ModifierLoc = Loc;
5701   }
5702 
5703   /// Sets the location of '('.
5704   ///
5705   /// \param Loc Location of '('.
setLParenLoc(SourceLocation Loc)5706   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5707 
5708   /// Set defaultmap kind start location.
5709   ///
5710   /// \param KLoc Defaultmap kind location.
setDefaultmapKindLoc(SourceLocation KLoc)5711   void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
5712 
5713 public:
5714   /// Build 'defaultmap' clause with defaultmap kind \a Kind
5715   ///
5716   /// \param StartLoc Starting location of the clause.
5717   /// \param LParenLoc Location of '('.
5718   /// \param KLoc Starting location of the argument.
5719   /// \param EndLoc Ending location of the clause.
5720   /// \param Kind Defaultmap kind.
5721   /// \param M The modifier applied to 'defaultmap' clause.
5722   /// \param MLoc Location of the modifier
OMPDefaultmapClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation MLoc,SourceLocation KLoc,SourceLocation EndLoc,OpenMPDefaultmapClauseKind Kind,OpenMPDefaultmapClauseModifier M)5723   OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5724                       SourceLocation MLoc, SourceLocation KLoc,
5725                       SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
5726                       OpenMPDefaultmapClauseModifier M)
5727       : OMPClause(OMPC_defaultmap, StartLoc, EndLoc), LParenLoc(LParenLoc),
5728         Modifier(M), ModifierLoc(MLoc), Kind(Kind), KindLoc(KLoc) {}
5729 
5730   /// Build an empty clause.
OMPDefaultmapClause()5731   explicit OMPDefaultmapClause()
5732       : OMPClause(OMPC_defaultmap, SourceLocation(), SourceLocation()) {}
5733 
5734   /// Get kind of the clause.
getDefaultmapKind()5735   OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
5736 
5737   /// Get the modifier of the clause.
getDefaultmapModifier()5738   OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
5739     return Modifier;
5740   }
5741 
5742   /// Get location of '('.
getLParenLoc()5743   SourceLocation getLParenLoc() { return LParenLoc; }
5744 
5745   /// Get kind location.
getDefaultmapKindLoc()5746   SourceLocation getDefaultmapKindLoc() { return KindLoc; }
5747 
5748   /// Get the modifier location.
getDefaultmapModifierLoc()5749   SourceLocation getDefaultmapModifierLoc() const {
5750     return ModifierLoc;
5751   }
5752 
children()5753   child_range children() {
5754     return child_range(child_iterator(), child_iterator());
5755   }
5756 
children()5757   const_child_range children() const {
5758     return const_child_range(const_child_iterator(), const_child_iterator());
5759   }
5760 
used_children()5761   child_range used_children() {
5762     return child_range(child_iterator(), child_iterator());
5763   }
used_children()5764   const_child_range used_children() const {
5765     return const_child_range(const_child_iterator(), const_child_iterator());
5766   }
5767 
classof(const OMPClause * T)5768   static bool classof(const OMPClause *T) {
5769     return T->getClauseKind() == OMPC_defaultmap;
5770   }
5771 };
5772 
5773 /// This represents clause 'to' in the '#pragma omp ...'
5774 /// directives.
5775 ///
5776 /// \code
5777 /// #pragma omp target update to(a,b)
5778 /// \endcode
5779 /// In this example directive '#pragma omp target update' has clause 'to'
5780 /// with the variables 'a' and 'b'.
5781 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
5782                           private llvm::TrailingObjects<
5783                               OMPToClause, Expr *, ValueDecl *, unsigned,
5784                               OMPClauseMappableExprCommon::MappableComponent> {
5785   friend class OMPClauseReader;
5786   friend OMPMappableExprListClause;
5787   friend OMPVarListClause;
5788   friend TrailingObjects;
5789 
5790   /// Build clause with number of variables \a NumVars.
5791   ///
5792   /// \param MapperQualifierLoc C++ nested name specifier for the associated
5793   /// user-defined mapper.
5794   /// \param MapperIdInfo The identifier of associated user-defined mapper.
5795   /// \param Locs Locations needed to build a mappable clause. It includes 1)
5796   /// StartLoc: starting location of the clause (the clause keyword); 2)
5797   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5798   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5799   /// NumVars: number of expressions listed in this clause; 2)
5800   /// NumUniqueDeclarations: number of unique base declarations in this clause;
5801   /// 3) NumComponentLists: number of component lists in this clause; and 4)
5802   /// NumComponents: total number of expression components in the clause.
OMPToClause(NestedNameSpecifierLoc MapperQualifierLoc,DeclarationNameInfo MapperIdInfo,const OMPVarListLocTy & Locs,const OMPMappableExprListSizeTy & Sizes)5803   explicit OMPToClause(NestedNameSpecifierLoc MapperQualifierLoc,
5804                        DeclarationNameInfo MapperIdInfo,
5805                        const OMPVarListLocTy &Locs,
5806                        const OMPMappableExprListSizeTy &Sizes)
5807       : OMPMappableExprListClause(OMPC_to, Locs, Sizes, &MapperQualifierLoc,
5808                                   &MapperIdInfo) {}
5809 
5810   /// Build an empty clause.
5811   ///
5812   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5813   /// NumVars: number of expressions listed in this clause; 2)
5814   /// NumUniqueDeclarations: number of unique base declarations in this clause;
5815   /// 3) NumComponentLists: number of component lists in this clause; and 4)
5816   /// NumComponents: total number of expression components in the clause.
OMPToClause(const OMPMappableExprListSizeTy & Sizes)5817   explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes)
5818       : OMPMappableExprListClause(OMPC_to, OMPVarListLocTy(), Sizes) {}
5819 
5820   /// Define the sizes of each trailing object array except the last one. This
5821   /// is required for TrailingObjects to work properly.
numTrailingObjects(OverloadToken<Expr * >)5822   size_t numTrailingObjects(OverloadToken<Expr *>) const {
5823     // There are varlist_size() of expressions, and varlist_size() of
5824     // user-defined mappers.
5825     return 2 * varlist_size();
5826   }
numTrailingObjects(OverloadToken<ValueDecl * >)5827   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
5828     return getUniqueDeclarationsNum();
5829   }
numTrailingObjects(OverloadToken<unsigned>)5830   size_t numTrailingObjects(OverloadToken<unsigned>) const {
5831     return getUniqueDeclarationsNum() + getTotalComponentListNum();
5832   }
5833 
5834 public:
5835   /// Creates clause with a list of variables \a Vars.
5836   ///
5837   /// \param C AST context.
5838   /// \param Locs Locations needed to build a mappable clause. It includes 1)
5839   /// StartLoc: starting location of the clause (the clause keyword); 2)
5840   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5841   /// \param Vars The original expression used in the clause.
5842   /// \param Declarations Declarations used in the clause.
5843   /// \param ComponentLists Component lists used in the clause.
5844   /// \param UDMapperRefs References to user-defined mappers associated with
5845   /// expressions used in the clause.
5846   /// \param UDMQualifierLoc C++ nested name specifier for the associated
5847   /// user-defined mapper.
5848   /// \param MapperId The identifier of associated user-defined mapper.
5849   static OMPToClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
5850                              ArrayRef<Expr *> Vars,
5851                              ArrayRef<ValueDecl *> Declarations,
5852                              MappableExprComponentListsRef ComponentLists,
5853                              ArrayRef<Expr *> UDMapperRefs,
5854                              NestedNameSpecifierLoc UDMQualifierLoc,
5855                              DeclarationNameInfo MapperId);
5856 
5857   /// Creates an empty clause with the place for \a NumVars variables.
5858   ///
5859   /// \param C AST context.
5860   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5861   /// NumVars: number of expressions listed in this clause; 2)
5862   /// NumUniqueDeclarations: number of unique base declarations in this clause;
5863   /// 3) NumComponentLists: number of component lists in this clause; and 4)
5864   /// NumComponents: total number of expression components in the clause.
5865   static OMPToClause *CreateEmpty(const ASTContext &C,
5866                                   const OMPMappableExprListSizeTy &Sizes);
5867 
children()5868   child_range children() {
5869     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5870                        reinterpret_cast<Stmt **>(varlist_end()));
5871   }
5872 
children()5873   const_child_range children() const {
5874     auto Children = const_cast<OMPToClause *>(this)->children();
5875     return const_child_range(Children.begin(), Children.end());
5876   }
5877 
used_children()5878   child_range used_children() {
5879     return child_range(child_iterator(), child_iterator());
5880   }
used_children()5881   const_child_range used_children() const {
5882     return const_child_range(const_child_iterator(), const_child_iterator());
5883   }
5884 
classof(const OMPClause * T)5885   static bool classof(const OMPClause *T) {
5886     return T->getClauseKind() == OMPC_to;
5887   }
5888 };
5889 
5890 /// This represents clause 'from' in the '#pragma omp ...'
5891 /// directives.
5892 ///
5893 /// \code
5894 /// #pragma omp target update from(a,b)
5895 /// \endcode
5896 /// In this example directive '#pragma omp target update' has clause 'from'
5897 /// with the variables 'a' and 'b'.
5898 class OMPFromClause final
5899     : public OMPMappableExprListClause<OMPFromClause>,
5900       private llvm::TrailingObjects<
5901           OMPFromClause, Expr *, ValueDecl *, unsigned,
5902           OMPClauseMappableExprCommon::MappableComponent> {
5903   friend class OMPClauseReader;
5904   friend OMPMappableExprListClause;
5905   friend OMPVarListClause;
5906   friend TrailingObjects;
5907 
5908   /// Build clause with number of variables \a NumVars.
5909   ///
5910   /// \param MapperQualifierLoc C++ nested name specifier for the associated
5911   /// user-defined mapper.
5912   /// \param MapperIdInfo The identifier of associated user-defined mapper.
5913   /// \param Locs Locations needed to build a mappable clause. It includes 1)
5914   /// StartLoc: starting location of the clause (the clause keyword); 2)
5915   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5916   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5917   /// NumVars: number of expressions listed in this clause; 2)
5918   /// NumUniqueDeclarations: number of unique base declarations in this clause;
5919   /// 3) NumComponentLists: number of component lists in this clause; and 4)
5920   /// NumComponents: total number of expression components in the clause.
OMPFromClause(NestedNameSpecifierLoc MapperQualifierLoc,DeclarationNameInfo MapperIdInfo,const OMPVarListLocTy & Locs,const OMPMappableExprListSizeTy & Sizes)5921   explicit OMPFromClause(NestedNameSpecifierLoc MapperQualifierLoc,
5922                          DeclarationNameInfo MapperIdInfo,
5923                          const OMPVarListLocTy &Locs,
5924                          const OMPMappableExprListSizeTy &Sizes)
5925       : OMPMappableExprListClause(OMPC_from, Locs, Sizes, &MapperQualifierLoc,
5926                                   &MapperIdInfo) {}
5927 
5928   /// Build an empty clause.
5929   ///
5930   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5931   /// NumVars: number of expressions listed in this clause; 2)
5932   /// NumUniqueDeclarations: number of unique base declarations in this clause;
5933   /// 3) NumComponentLists: number of component lists in this clause; and 4)
5934   /// NumComponents: total number of expression components in the clause.
OMPFromClause(const OMPMappableExprListSizeTy & Sizes)5935   explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes)
5936       : OMPMappableExprListClause(OMPC_from, OMPVarListLocTy(), Sizes) {}
5937 
5938   /// Define the sizes of each trailing object array except the last one. This
5939   /// is required for TrailingObjects to work properly.
numTrailingObjects(OverloadToken<Expr * >)5940   size_t numTrailingObjects(OverloadToken<Expr *>) const {
5941     // There are varlist_size() of expressions, and varlist_size() of
5942     // user-defined mappers.
5943     return 2 * varlist_size();
5944   }
numTrailingObjects(OverloadToken<ValueDecl * >)5945   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
5946     return getUniqueDeclarationsNum();
5947   }
numTrailingObjects(OverloadToken<unsigned>)5948   size_t numTrailingObjects(OverloadToken<unsigned>) const {
5949     return getUniqueDeclarationsNum() + getTotalComponentListNum();
5950   }
5951 
5952 public:
5953   /// Creates clause with a list of variables \a Vars.
5954   ///
5955   /// \param C AST context.
5956   /// \param Locs Locations needed to build a mappable clause. It includes 1)
5957   /// StartLoc: starting location of the clause (the clause keyword); 2)
5958   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5959   /// \param Vars The original expression used in the clause.
5960   /// \param Declarations Declarations used in the clause.
5961   /// \param ComponentLists Component lists used in the clause.
5962   /// \param UDMapperRefs References to user-defined mappers associated with
5963   /// expressions used in the clause.
5964   /// \param UDMQualifierLoc C++ nested name specifier for the associated
5965   /// user-defined mapper.
5966   /// \param MapperId The identifier of associated user-defined mapper.
5967   static OMPFromClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
5968                                ArrayRef<Expr *> Vars,
5969                                ArrayRef<ValueDecl *> Declarations,
5970                                MappableExprComponentListsRef ComponentLists,
5971                                ArrayRef<Expr *> UDMapperRefs,
5972                                NestedNameSpecifierLoc UDMQualifierLoc,
5973                                DeclarationNameInfo MapperId);
5974 
5975   /// Creates an empty clause with the place for \a NumVars variables.
5976   ///
5977   /// \param C AST context.
5978   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5979   /// NumVars: number of expressions listed in this clause; 2)
5980   /// NumUniqueDeclarations: number of unique base declarations in this clause;
5981   /// 3) NumComponentLists: number of component lists in this clause; and 4)
5982   /// NumComponents: total number of expression components in the clause.
5983   static OMPFromClause *CreateEmpty(const ASTContext &C,
5984                                     const OMPMappableExprListSizeTy &Sizes);
5985 
children()5986   child_range children() {
5987     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5988                        reinterpret_cast<Stmt **>(varlist_end()));
5989   }
5990 
children()5991   const_child_range children() const {
5992     auto Children = const_cast<OMPFromClause *>(this)->children();
5993     return const_child_range(Children.begin(), Children.end());
5994   }
5995 
used_children()5996   child_range used_children() {
5997     return child_range(child_iterator(), child_iterator());
5998   }
used_children()5999   const_child_range used_children() const {
6000     return const_child_range(const_child_iterator(), const_child_iterator());
6001   }
6002 
classof(const OMPClause * T)6003   static bool classof(const OMPClause *T) {
6004     return T->getClauseKind() == OMPC_from;
6005   }
6006 };
6007 
6008 /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
6009 /// directives.
6010 ///
6011 /// \code
6012 /// #pragma omp target data use_device_ptr(a,b)
6013 /// \endcode
6014 /// In this example directive '#pragma omp target data' has clause
6015 /// 'use_device_ptr' with the variables 'a' and 'b'.
6016 class OMPUseDevicePtrClause final
6017     : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
6018       private llvm::TrailingObjects<
6019           OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
6020           OMPClauseMappableExprCommon::MappableComponent> {
6021   friend class OMPClauseReader;
6022   friend OMPMappableExprListClause;
6023   friend OMPVarListClause;
6024   friend TrailingObjects;
6025 
6026   /// Build clause with number of variables \a NumVars.
6027   ///
6028   /// \param Locs Locations needed to build a mappable clause. It includes 1)
6029   /// StartLoc: starting location of the clause (the clause keyword); 2)
6030   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6031   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6032   /// NumVars: number of expressions listed in this clause; 2)
6033   /// NumUniqueDeclarations: number of unique base declarations in this clause;
6034   /// 3) NumComponentLists: number of component lists in this clause; and 4)
6035   /// NumComponents: total number of expression components in the clause.
OMPUseDevicePtrClause(const OMPVarListLocTy & Locs,const OMPMappableExprListSizeTy & Sizes)6036   explicit OMPUseDevicePtrClause(const OMPVarListLocTy &Locs,
6037                                  const OMPMappableExprListSizeTy &Sizes)
6038       : OMPMappableExprListClause(OMPC_use_device_ptr, Locs, Sizes) {}
6039 
6040   /// Build an empty clause.
6041   ///
6042   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6043   /// NumVars: number of expressions listed in this clause; 2)
6044   /// NumUniqueDeclarations: number of unique base declarations in this clause;
6045   /// 3) NumComponentLists: number of component lists in this clause; and 4)
6046   /// NumComponents: total number of expression components in the clause.
OMPUseDevicePtrClause(const OMPMappableExprListSizeTy & Sizes)6047   explicit OMPUseDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
6048       : OMPMappableExprListClause(OMPC_use_device_ptr, OMPVarListLocTy(),
6049                                   Sizes) {}
6050 
6051   /// Define the sizes of each trailing object array except the last one. This
6052   /// is required for TrailingObjects to work properly.
numTrailingObjects(OverloadToken<Expr * >)6053   size_t numTrailingObjects(OverloadToken<Expr *>) const {
6054     return 3 * varlist_size();
6055   }
numTrailingObjects(OverloadToken<ValueDecl * >)6056   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6057     return getUniqueDeclarationsNum();
6058   }
numTrailingObjects(OverloadToken<unsigned>)6059   size_t numTrailingObjects(OverloadToken<unsigned>) const {
6060     return getUniqueDeclarationsNum() + getTotalComponentListNum();
6061   }
6062 
6063   /// Sets the list of references to private copies with initializers for new
6064   /// private variables.
6065   /// \param VL List of references.
6066   void setPrivateCopies(ArrayRef<Expr *> VL);
6067 
6068   /// Gets the list of references to private copies with initializers for new
6069   /// private variables.
getPrivateCopies()6070   MutableArrayRef<Expr *> getPrivateCopies() {
6071     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
6072   }
getPrivateCopies()6073   ArrayRef<const Expr *> getPrivateCopies() const {
6074     return llvm::makeArrayRef(varlist_end(), varlist_size());
6075   }
6076 
6077   /// Sets the list of references to initializer variables for new private
6078   /// variables.
6079   /// \param VL List of references.
6080   void setInits(ArrayRef<Expr *> VL);
6081 
6082   /// Gets the list of references to initializer variables for new private
6083   /// variables.
getInits()6084   MutableArrayRef<Expr *> getInits() {
6085     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
6086   }
getInits()6087   ArrayRef<const Expr *> getInits() const {
6088     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
6089   }
6090 
6091 public:
6092   /// Creates clause with a list of variables \a Vars.
6093   ///
6094   /// \param C AST context.
6095   /// \param Locs Locations needed to build a mappable clause. It includes 1)
6096   /// StartLoc: starting location of the clause (the clause keyword); 2)
6097   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6098   /// \param Vars The original expression used in the clause.
6099   /// \param PrivateVars Expressions referring to private copies.
6100   /// \param Inits Expressions referring to private copy initializers.
6101   /// \param Declarations Declarations used in the clause.
6102   /// \param ComponentLists Component lists used in the clause.
6103   static OMPUseDevicePtrClause *
6104   Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6105          ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
6106          ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
6107          MappableExprComponentListsRef ComponentLists);
6108 
6109   /// Creates an empty clause with the place for \a NumVars variables.
6110   ///
6111   /// \param C AST context.
6112   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6113   /// NumVars: number of expressions listed in this clause; 2)
6114   /// NumUniqueDeclarations: number of unique base declarations in this clause;
6115   /// 3) NumComponentLists: number of component lists in this clause; and 4)
6116   /// NumComponents: total number of expression components in the clause.
6117   static OMPUseDevicePtrClause *
6118   CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
6119 
6120   using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
6121   using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
6122   using private_copies_range = llvm::iterator_range<private_copies_iterator>;
6123   using private_copies_const_range =
6124       llvm::iterator_range<private_copies_const_iterator>;
6125 
private_copies()6126   private_copies_range private_copies() {
6127     return private_copies_range(getPrivateCopies().begin(),
6128                                 getPrivateCopies().end());
6129   }
6130 
private_copies()6131   private_copies_const_range private_copies() const {
6132     return private_copies_const_range(getPrivateCopies().begin(),
6133                                       getPrivateCopies().end());
6134   }
6135 
6136   using inits_iterator = MutableArrayRef<Expr *>::iterator;
6137   using inits_const_iterator = ArrayRef<const Expr *>::iterator;
6138   using inits_range = llvm::iterator_range<inits_iterator>;
6139   using inits_const_range = llvm::iterator_range<inits_const_iterator>;
6140 
inits()6141   inits_range inits() {
6142     return inits_range(getInits().begin(), getInits().end());
6143   }
6144 
inits()6145   inits_const_range inits() const {
6146     return inits_const_range(getInits().begin(), getInits().end());
6147   }
6148 
children()6149   child_range children() {
6150     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6151                        reinterpret_cast<Stmt **>(varlist_end()));
6152   }
6153 
children()6154   const_child_range children() const {
6155     auto Children = const_cast<OMPUseDevicePtrClause *>(this)->children();
6156     return const_child_range(Children.begin(), Children.end());
6157   }
6158 
used_children()6159   child_range used_children() {
6160     return child_range(child_iterator(), child_iterator());
6161   }
used_children()6162   const_child_range used_children() const {
6163     return const_child_range(const_child_iterator(), const_child_iterator());
6164   }
6165 
classof(const OMPClause * T)6166   static bool classof(const OMPClause *T) {
6167     return T->getClauseKind() == OMPC_use_device_ptr;
6168   }
6169 };
6170 
6171 /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
6172 /// directives.
6173 ///
6174 /// \code
6175 /// #pragma omp target is_device_ptr(a,b)
6176 /// \endcode
6177 /// In this example directive '#pragma omp target' has clause
6178 /// 'is_device_ptr' with the variables 'a' and 'b'.
6179 class OMPIsDevicePtrClause final
6180     : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
6181       private llvm::TrailingObjects<
6182           OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
6183           OMPClauseMappableExprCommon::MappableComponent> {
6184   friend class OMPClauseReader;
6185   friend OMPMappableExprListClause;
6186   friend OMPVarListClause;
6187   friend TrailingObjects;
6188 
6189   /// Build clause with number of variables \a NumVars.
6190   ///
6191   /// \param Locs Locations needed to build a mappable clause. It includes 1)
6192   /// StartLoc: starting location of the clause (the clause keyword); 2)
6193   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6194   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6195   /// NumVars: number of expressions listed in this clause; 2)
6196   /// NumUniqueDeclarations: number of unique base declarations in this clause;
6197   /// 3) NumComponentLists: number of component lists in this clause; and 4)
6198   /// NumComponents: total number of expression components in the clause.
OMPIsDevicePtrClause(const OMPVarListLocTy & Locs,const OMPMappableExprListSizeTy & Sizes)6199   explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs,
6200                                 const OMPMappableExprListSizeTy &Sizes)
6201       : OMPMappableExprListClause(OMPC_is_device_ptr, Locs, Sizes) {}
6202 
6203   /// Build an empty clause.
6204   ///
6205   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6206   /// NumVars: number of expressions listed in this clause; 2)
6207   /// NumUniqueDeclarations: number of unique base declarations in this clause;
6208   /// 3) NumComponentLists: number of component lists in this clause; and 4)
6209   /// NumComponents: total number of expression components in the clause.
OMPIsDevicePtrClause(const OMPMappableExprListSizeTy & Sizes)6210   explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
6211       : OMPMappableExprListClause(OMPC_is_device_ptr, OMPVarListLocTy(),
6212                                   Sizes) {}
6213 
6214   /// Define the sizes of each trailing object array except the last one. This
6215   /// is required for TrailingObjects to work properly.
numTrailingObjects(OverloadToken<Expr * >)6216   size_t numTrailingObjects(OverloadToken<Expr *>) const {
6217     return varlist_size();
6218   }
numTrailingObjects(OverloadToken<ValueDecl * >)6219   size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6220     return getUniqueDeclarationsNum();
6221   }
numTrailingObjects(OverloadToken<unsigned>)6222   size_t numTrailingObjects(OverloadToken<unsigned>) const {
6223     return getUniqueDeclarationsNum() + getTotalComponentListNum();
6224   }
6225 
6226 public:
6227   /// Creates clause with a list of variables \a Vars.
6228   ///
6229   /// \param C AST context.
6230   /// \param Locs Locations needed to build a mappable clause. It includes 1)
6231   /// StartLoc: starting location of the clause (the clause keyword); 2)
6232   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6233   /// \param Vars The original expression used in the clause.
6234   /// \param Declarations Declarations used in the clause.
6235   /// \param ComponentLists Component lists used in the clause.
6236   static OMPIsDevicePtrClause *
6237   Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6238          ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
6239          MappableExprComponentListsRef ComponentLists);
6240 
6241   /// Creates an empty clause with the place for \a NumVars variables.
6242   ///
6243   /// \param C AST context.
6244   /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6245   /// NumVars: number of expressions listed in this clause; 2)
6246   /// NumUniqueDeclarations: number of unique base declarations in this clause;
6247   /// 3) NumComponentLists: number of component lists in this clause; and 4)
6248   /// NumComponents: total number of expression components in the clause.
6249   static OMPIsDevicePtrClause *
6250   CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
6251 
children()6252   child_range children() {
6253     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6254                        reinterpret_cast<Stmt **>(varlist_end()));
6255   }
6256 
children()6257   const_child_range children() const {
6258     auto Children = const_cast<OMPIsDevicePtrClause *>(this)->children();
6259     return const_child_range(Children.begin(), Children.end());
6260   }
6261 
used_children()6262   child_range used_children() {
6263     return child_range(child_iterator(), child_iterator());
6264   }
used_children()6265   const_child_range used_children() const {
6266     return const_child_range(const_child_iterator(), const_child_iterator());
6267   }
6268 
classof(const OMPClause * T)6269   static bool classof(const OMPClause *T) {
6270     return T->getClauseKind() == OMPC_is_device_ptr;
6271   }
6272 };
6273 
6274 /// This represents clause 'nontemporal' in the '#pragma omp ...' directives.
6275 ///
6276 /// \code
6277 /// #pragma omp simd nontemporal(a)
6278 /// \endcode
6279 /// In this example directive '#pragma omp simd' has clause 'nontemporal' for
6280 /// the variable 'a'.
6281 class OMPNontemporalClause final
6282     : public OMPVarListClause<OMPNontemporalClause>,
6283       private llvm::TrailingObjects<OMPNontemporalClause, Expr *> {
6284   friend class OMPClauseReader;
6285   friend OMPVarListClause;
6286   friend TrailingObjects;
6287 
6288   /// Build clause with number of variables \a N.
6289   ///
6290   /// \param StartLoc Starting location of the clause.
6291   /// \param LParenLoc Location of '('.
6292   /// \param EndLoc Ending location of the clause.
6293   /// \param N Number of the variables in the clause.
OMPNontemporalClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)6294   OMPNontemporalClause(SourceLocation StartLoc, SourceLocation LParenLoc,
6295                        SourceLocation EndLoc, unsigned N)
6296       : OMPVarListClause<OMPNontemporalClause>(OMPC_nontemporal, StartLoc,
6297                                                LParenLoc, EndLoc, N) {}
6298 
6299   /// Build an empty clause.
6300   ///
6301   /// \param N Number of variables.
OMPNontemporalClause(unsigned N)6302   explicit OMPNontemporalClause(unsigned N)
6303       : OMPVarListClause<OMPNontemporalClause>(
6304             OMPC_nontemporal, SourceLocation(), SourceLocation(),
6305             SourceLocation(), N) {}
6306 
6307   /// Get the list of privatied copies if the member expression was captured by
6308   /// one of the privatization clauses.
getPrivateRefs()6309   MutableArrayRef<Expr *> getPrivateRefs() {
6310     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
6311   }
getPrivateRefs()6312   ArrayRef<const Expr *> getPrivateRefs() const {
6313     return llvm::makeArrayRef(varlist_end(), varlist_size());
6314   }
6315 
6316 public:
6317   /// Creates clause with a list of variables \a VL.
6318   ///
6319   /// \param C AST context.
6320   /// \param StartLoc Starting location of the clause.
6321   /// \param LParenLoc Location of '('.
6322   /// \param EndLoc Ending location of the clause.
6323   /// \param VL List of references to the variables.
6324   static OMPNontemporalClause *
6325   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
6326          SourceLocation EndLoc, ArrayRef<Expr *> VL);
6327 
6328   /// Creates an empty clause with the place for \a N variables.
6329   ///
6330   /// \param C AST context.
6331   /// \param N The number of variables.
6332   static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N);
6333 
6334   /// Sets the list of references to private copies created in private clauses.
6335   /// \param VL List of references.
6336   void setPrivateRefs(ArrayRef<Expr *> VL);
6337 
children()6338   child_range children() {
6339     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6340                        reinterpret_cast<Stmt **>(varlist_end()));
6341   }
6342 
children()6343   const_child_range children() const {
6344     auto Children = const_cast<OMPNontemporalClause *>(this)->children();
6345     return const_child_range(Children.begin(), Children.end());
6346   }
6347 
private_refs()6348   child_range private_refs() {
6349     return child_range(reinterpret_cast<Stmt **>(getPrivateRefs().begin()),
6350                        reinterpret_cast<Stmt **>(getPrivateRefs().end()));
6351   }
6352 
private_refs()6353   const_child_range private_refs() const {
6354     auto Children = const_cast<OMPNontemporalClause *>(this)->private_refs();
6355     return const_child_range(Children.begin(), Children.end());
6356   }
6357 
used_children()6358   child_range used_children() {
6359     return child_range(child_iterator(), child_iterator());
6360   }
used_children()6361   const_child_range used_children() const {
6362     return const_child_range(const_child_iterator(), const_child_iterator());
6363   }
6364 
classof(const OMPClause * T)6365   static bool classof(const OMPClause *T) {
6366     return T->getClauseKind() == OMPC_nontemporal;
6367   }
6368 };
6369 
6370 /// This class implements a simple visitor for OMPClause
6371 /// subclasses.
6372 template<class ImplClass, template <typename> class Ptr, typename RetTy>
6373 class OMPClauseVisitorBase {
6374 public:
6375 #define PTR(CLASS) typename Ptr<CLASS>::type
6376 #define DISPATCH(CLASS) \
6377   return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
6378 
6379 #define OPENMP_CLAUSE(Name, Class)                              \
6380   RetTy Visit ## Class (PTR(Class) S) { DISPATCH(Class); }
6381 #include "clang/Basic/OpenMPKinds.def"
6382 
Visit(PTR (OMPClause)S)6383   RetTy Visit(PTR(OMPClause) S) {
6384     // Top switch clause: visit each OMPClause.
6385     switch (S->getClauseKind()) {
6386     default: llvm_unreachable("Unknown clause kind!");
6387 #define OPENMP_CLAUSE(Name, Class)                              \
6388     case OMPC_ ## Name : return Visit ## Class(static_cast<PTR(Class)>(S));
6389 #include "clang/Basic/OpenMPKinds.def"
6390     }
6391   }
6392   // Base case, ignore it. :)
VisitOMPClause(PTR (OMPClause)Node)6393   RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); }
6394 #undef PTR
6395 #undef DISPATCH
6396 };
6397 
6398 template <typename T>
6399 using const_ptr = typename std::add_pointer<typename std::add_const<T>::type>;
6400 
6401 template<class ImplClass, typename RetTy = void>
6402 class OMPClauseVisitor :
6403       public OMPClauseVisitorBase <ImplClass, std::add_pointer, RetTy> {};
6404 template<class ImplClass, typename RetTy = void>
6405 class ConstOMPClauseVisitor :
6406       public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {};
6407 
6408 class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
6409   raw_ostream &OS;
6410   const PrintingPolicy &Policy;
6411 
6412   /// Process clauses with list of variables.
6413   template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
6414 
6415 public:
OMPClausePrinter(raw_ostream & OS,const PrintingPolicy & Policy)6416   OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
6417       : OS(OS), Policy(Policy) {}
6418 
6419 #define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *S);
6420 #include "clang/Basic/OpenMPKinds.def"
6421 };
6422 
6423 } // namespace clang
6424 
6425 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H
6426