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