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