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