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