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