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