]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/OpenMPClause.h
Import ClangFormat.cpp from ^/vendor/clang/clang-release_380-r262564
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / OpenMPClause.h
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:
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.
46   SourceLocation getLocStart() const { return StartLoc; }
47   /// \brief Returns the ending location of the clause.
48   SourceLocation getLocEnd() const { return EndLoc; }
49
50   /// \brief Sets the starting location of the clause.
51   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
52   /// \brief Sets the ending location of the clause.
53   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
54
55   /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
56   OpenMPClauseKind getClauseKind() const { return Kind; }
57
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();
66   const_child_range children() const {
67     auto Children = const_cast<OMPClause *>(this)->children();
68     return const_child_range(Children.begin(), Children.end());
69   }
70   static bool classof(const OMPClause *) { return true; }
71 };
72
73 /// \brief This represents clauses with the list of variables like 'private',
74 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
75 /// '#pragma omp ...' directives.
76 template <class T> class OMPVarListClause : public OMPClause {
77   friend class OMPClauseReader;
78   /// \brief Location of '('.
79   SourceLocation LParenLoc;
80   /// \brief Number of variables in the list.
81   unsigned NumVars;
82
83 protected:
84   /// \brief Fetches list of variables associated with this clause.
85   MutableArrayRef<Expr *> getVarRefs() {
86     return MutableArrayRef<Expr *>(
87         static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
88   }
89
90   /// \brief Sets the list of variables for this clause.
91   void setVarRefs(ArrayRef<Expr *> VL) {
92     assert(VL.size() == NumVars &&
93            "Number of variables is not the same as the preallocated buffer");
94     std::copy(VL.begin(), VL.end(),
95               static_cast<T *>(this)->template getTrailingObjects<Expr *>());
96   }
97
98   /// \brief Build a clause with \a N variables
99   ///
100   /// \param K Kind of the clause.
101   /// \param StartLoc Starting location of the clause (the clause keyword).
102   /// \param LParenLoc Location of '('.
103   /// \param EndLoc Ending location of the clause.
104   /// \param N Number of the variables in the clause.
105   ///
106   OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
107                    SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
108       : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
109
110 public:
111   typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
112   typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
113   typedef llvm::iterator_range<varlist_iterator> varlist_range;
114   typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
115
116   unsigned varlist_size() const { return NumVars; }
117   bool varlist_empty() const { return NumVars == 0; }
118
119   varlist_range varlists() {
120     return varlist_range(varlist_begin(), varlist_end());
121   }
122   varlist_const_range varlists() const {
123     return varlist_const_range(varlist_begin(), varlist_end());
124   }
125
126   varlist_iterator varlist_begin() { return getVarRefs().begin(); }
127   varlist_iterator varlist_end() { return getVarRefs().end(); }
128   varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
129   varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
130
131   /// \brief Sets the location of '('.
132   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
133   /// \brief Returns the location of '('.
134   SourceLocation getLParenLoc() const { return LParenLoc; }
135
136   /// \brief Fetches list of all variables in the clause.
137   ArrayRef<const Expr *> getVarRefs() const {
138     return llvm::makeArrayRef(
139         static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
140         NumVars);
141   }
142 };
143
144 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
145 ///
146 /// \code
147 /// #pragma omp parallel if(parallel:a > 5)
148 /// \endcode
149 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
150 /// condition 'a > 5' and directive name modifier 'parallel'.
151 ///
152 class OMPIfClause : public OMPClause {
153   friend class OMPClauseReader;
154   /// \brief Location of '('.
155   SourceLocation LParenLoc;
156   /// \brief Condition of the 'if' clause.
157   Stmt *Condition;
158   /// \brief Location of ':' (if any).
159   SourceLocation ColonLoc;
160   /// \brief Directive name modifier for the clause.
161   OpenMPDirectiveKind NameModifier;
162   /// \brief Name modifier location.
163   SourceLocation NameModifierLoc;
164
165   /// \brief Set condition.
166   ///
167   void setCondition(Expr *Cond) { Condition = Cond; }
168   /// \brief Set directive name modifier for the clause.
169   ///
170   void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
171   /// \brief Set location of directive name modifier for the clause.
172   ///
173   void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
174   /// \brief Set location of ':'.
175   ///
176   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
177
178 public:
179   /// \brief Build 'if' clause with condition \a Cond.
180   ///
181   /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
182   /// \param Cond Condition of the clause.
183   /// \param StartLoc Starting location of the clause.
184   /// \param LParenLoc Location of '('.
185   /// \param NameModifierLoc Location of directive name modifier.
186   /// \param ColonLoc [OpenMP 4.1] Location of ':'.
187   /// \param EndLoc Ending location of the clause.
188   ///
189   OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond,
190               SourceLocation StartLoc, SourceLocation LParenLoc,
191               SourceLocation NameModifierLoc, SourceLocation ColonLoc,
192               SourceLocation EndLoc)
193       : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
194         Condition(Cond), ColonLoc(ColonLoc), NameModifier(NameModifier),
195         NameModifierLoc(NameModifierLoc) {}
196
197   /// \brief Build an empty clause.
198   ///
199   OMPIfClause()
200       : OMPClause(OMPC_if, SourceLocation(), SourceLocation()), LParenLoc(),
201         Condition(nullptr), ColonLoc(), NameModifier(OMPD_unknown),
202         NameModifierLoc() {}
203
204   /// \brief Sets the location of '('.
205   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
206   /// \brief Returns the location of '('.
207   SourceLocation getLParenLoc() const { return LParenLoc; }
208
209   /// \brief Return the location of ':'.
210   SourceLocation getColonLoc() const { return ColonLoc; }
211
212   /// \brief Returns condition.
213   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
214   /// \brief Return directive name modifier associated with the clause.
215   OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
216
217   /// \brief Return the location of directive name modifier.
218   SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
219
220   static bool classof(const OMPClause *T) {
221     return T->getClauseKind() == OMPC_if;
222   }
223
224   child_range children() { return child_range(&Condition, &Condition + 1); }
225 };
226
227 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
228 ///
229 /// \code
230 /// #pragma omp task final(a > 5)
231 /// \endcode
232 /// In this example directive '#pragma omp task' has simple 'final'
233 /// clause with condition 'a > 5'.
234 ///
235 class OMPFinalClause : public OMPClause {
236   friend class OMPClauseReader;
237   /// \brief Location of '('.
238   SourceLocation LParenLoc;
239   /// \brief Condition of the 'if' clause.
240   Stmt *Condition;
241
242   /// \brief Set condition.
243   ///
244   void setCondition(Expr *Cond) { Condition = Cond; }
245
246 public:
247   /// \brief Build 'final' clause with condition \a Cond.
248   ///
249   /// \param StartLoc Starting location of the clause.
250   /// \param LParenLoc Location of '('.
251   /// \param Cond Condition of the clause.
252   /// \param EndLoc Ending location of the clause.
253   ///
254   OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
255                  SourceLocation EndLoc)
256       : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
257         Condition(Cond) {}
258
259   /// \brief Build an empty clause.
260   ///
261   OMPFinalClause()
262       : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
263         LParenLoc(SourceLocation()), Condition(nullptr) {}
264
265   /// \brief Sets the location of '('.
266   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
267   /// \brief Returns the location of '('.
268   SourceLocation getLParenLoc() const { return LParenLoc; }
269
270   /// \brief Returns condition.
271   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
272
273   static bool classof(const OMPClause *T) {
274     return T->getClauseKind() == OMPC_final;
275   }
276
277   child_range children() { return child_range(&Condition, &Condition + 1); }
278 };
279
280 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
281 /// directive.
282 ///
283 /// \code
284 /// #pragma omp parallel num_threads(6)
285 /// \endcode
286 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
287 /// clause with number of threads '6'.
288 ///
289 class OMPNumThreadsClause : public OMPClause {
290   friend class OMPClauseReader;
291   /// \brief Location of '('.
292   SourceLocation LParenLoc;
293   /// \brief Condition of the 'num_threads' clause.
294   Stmt *NumThreads;
295
296   /// \brief Set condition.
297   ///
298   void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
299
300 public:
301   /// \brief Build 'num_threads' clause with condition \a NumThreads.
302   ///
303   /// \param NumThreads Number of threads for the construct.
304   /// \param StartLoc Starting location of the clause.
305   /// \param LParenLoc Location of '('.
306   /// \param EndLoc Ending location of the clause.
307   ///
308   OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
309                       SourceLocation LParenLoc, SourceLocation EndLoc)
310       : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
311         NumThreads(NumThreads) {}
312
313   /// \brief Build an empty clause.
314   ///
315   OMPNumThreadsClause()
316       : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
317         LParenLoc(SourceLocation()), NumThreads(nullptr) {}
318
319   /// \brief Sets the location of '('.
320   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
321   /// \brief Returns the location of '('.
322   SourceLocation getLParenLoc() const { return LParenLoc; }
323
324   /// \brief Returns number of threads.
325   Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
326
327   static bool classof(const OMPClause *T) {
328     return T->getClauseKind() == OMPC_num_threads;
329   }
330
331   child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
332 };
333
334 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
335 /// directive.
336 ///
337 /// \code
338 /// #pragma omp simd safelen(4)
339 /// \endcode
340 /// In this example directive '#pragma omp simd' has clause 'safelen'
341 /// with single expression '4'.
342 /// If the safelen clause is used then no two iterations executed
343 /// concurrently with SIMD instructions can have a greater distance
344 /// in the logical iteration space than its value. The parameter of
345 /// the safelen clause must be a constant positive integer expression.
346 ///
347 class OMPSafelenClause : public OMPClause {
348   friend class OMPClauseReader;
349   /// \brief Location of '('.
350   SourceLocation LParenLoc;
351   /// \brief Safe iteration space distance.
352   Stmt *Safelen;
353
354   /// \brief Set safelen.
355   void setSafelen(Expr *Len) { Safelen = Len; }
356
357 public:
358   /// \brief Build 'safelen' clause.
359   ///
360   /// \param Len Expression associated with this clause.
361   /// \param StartLoc Starting location of the clause.
362   /// \param EndLoc Ending location of the clause.
363   ///
364   OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
365                    SourceLocation EndLoc)
366       : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
367         Safelen(Len) {}
368
369   /// \brief Build an empty clause.
370   ///
371   explicit OMPSafelenClause()
372       : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
373         LParenLoc(SourceLocation()), Safelen(nullptr) {}
374
375   /// \brief Sets the location of '('.
376   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
377   /// \brief Returns the location of '('.
378   SourceLocation getLParenLoc() const { return LParenLoc; }
379
380   /// \brief Return safe iteration space distance.
381   Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
382
383   static bool classof(const OMPClause *T) {
384     return T->getClauseKind() == OMPC_safelen;
385   }
386
387   child_range children() { return child_range(&Safelen, &Safelen + 1); }
388 };
389
390 /// \brief This represents 'simdlen' clause in the '#pragma omp ...'
391 /// directive.
392 ///
393 /// \code
394 /// #pragma omp simd simdlen(4)
395 /// \endcode
396 /// In this example directive '#pragma omp simd' has clause 'simdlen'
397 /// with single expression '4'.
398 /// If the 'simdlen' clause is used then it specifies the preferred number of
399 /// iterations to be executed concurrently. The parameter of the 'simdlen'
400 /// clause must be a constant positive integer expression.
401 ///
402 class OMPSimdlenClause : public OMPClause {
403   friend class OMPClauseReader;
404   /// \brief Location of '('.
405   SourceLocation LParenLoc;
406   /// \brief Safe iteration space distance.
407   Stmt *Simdlen;
408
409   /// \brief Set simdlen.
410   void setSimdlen(Expr *Len) { Simdlen = Len; }
411
412 public:
413   /// \brief Build 'simdlen' clause.
414   ///
415   /// \param Len Expression associated with this clause.
416   /// \param StartLoc Starting location of the clause.
417   /// \param EndLoc Ending location of the clause.
418   ///
419   OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
420                    SourceLocation EndLoc)
421       : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
422         Simdlen(Len) {}
423
424   /// \brief Build an empty clause.
425   ///
426   explicit OMPSimdlenClause()
427       : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()),
428         LParenLoc(SourceLocation()), Simdlen(nullptr) {}
429
430   /// \brief Sets the location of '('.
431   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
432   /// \brief Returns the location of '('.
433   SourceLocation getLParenLoc() const { return LParenLoc; }
434
435   /// \brief Return safe iteration space distance.
436   Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
437
438   static bool classof(const OMPClause *T) {
439     return T->getClauseKind() == OMPC_simdlen;
440   }
441
442   child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
443 };
444
445 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
446 /// directive.
447 ///
448 /// \code
449 /// #pragma omp simd collapse(3)
450 /// \endcode
451 /// In this example directive '#pragma omp simd' has clause 'collapse'
452 /// with single expression '3'.
453 /// The parameter must be a constant positive integer expression, it specifies
454 /// the number of nested loops that should be collapsed into a single iteration
455 /// space.
456 ///
457 class OMPCollapseClause : public OMPClause {
458   friend class OMPClauseReader;
459   /// \brief Location of '('.
460   SourceLocation LParenLoc;
461   /// \brief Number of for-loops.
462   Stmt *NumForLoops;
463
464   /// \brief Set the number of associated for-loops.
465   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
466
467 public:
468   /// \brief Build 'collapse' clause.
469   ///
470   /// \param Num Expression associated with this clause.
471   /// \param StartLoc Starting location of the clause.
472   /// \param LParenLoc Location of '('.
473   /// \param EndLoc Ending location of the clause.
474   ///
475   OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
476                     SourceLocation LParenLoc, SourceLocation EndLoc)
477       : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
478         NumForLoops(Num) {}
479
480   /// \brief Build an empty clause.
481   ///
482   explicit OMPCollapseClause()
483       : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
484         LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
485
486   /// \brief Sets the location of '('.
487   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
488   /// \brief Returns the location of '('.
489   SourceLocation getLParenLoc() const { return LParenLoc; }
490
491   /// \brief Return the number of associated for-loops.
492   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
493
494   static bool classof(const OMPClause *T) {
495     return T->getClauseKind() == OMPC_collapse;
496   }
497
498   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
499 };
500
501 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
502 ///
503 /// \code
504 /// #pragma omp parallel default(shared)
505 /// \endcode
506 /// In this example directive '#pragma omp parallel' has simple 'default'
507 /// clause with kind 'shared'.
508 ///
509 class OMPDefaultClause : public OMPClause {
510   friend class OMPClauseReader;
511   /// \brief Location of '('.
512   SourceLocation LParenLoc;
513   /// \brief A kind of the 'default' clause.
514   OpenMPDefaultClauseKind Kind;
515   /// \brief Start location of the kind in source code.
516   SourceLocation KindKwLoc;
517
518   /// \brief Set kind of the clauses.
519   ///
520   /// \param K Argument of clause.
521   ///
522   void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
523
524   /// \brief Set argument location.
525   ///
526   /// \param KLoc Argument location.
527   ///
528   void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
529
530 public:
531   /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
532   ///
533   /// \param A Argument of the clause ('none' or 'shared').
534   /// \param ALoc Starting location of the argument.
535   /// \param StartLoc Starting location of the clause.
536   /// \param LParenLoc Location of '('.
537   /// \param EndLoc Ending location of the clause.
538   ///
539   OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
540                    SourceLocation StartLoc, SourceLocation LParenLoc,
541                    SourceLocation EndLoc)
542       : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
543         Kind(A), KindKwLoc(ALoc) {}
544
545   /// \brief Build an empty clause.
546   ///
547   OMPDefaultClause()
548       : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
549         LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
550         KindKwLoc(SourceLocation()) {}
551
552   /// \brief Sets the location of '('.
553   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
554   /// \brief Returns the location of '('.
555   SourceLocation getLParenLoc() const { return LParenLoc; }
556
557   /// \brief Returns kind of the clause.
558   OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
559
560   /// \brief Returns location of clause kind.
561   SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
562
563   static bool classof(const OMPClause *T) {
564     return T->getClauseKind() == OMPC_default;
565   }
566
567   child_range children() {
568     return child_range(child_iterator(), child_iterator());
569   }
570 };
571
572 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
573 /// directive.
574 ///
575 /// \code
576 /// #pragma omp parallel proc_bind(master)
577 /// \endcode
578 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
579 /// clause with kind 'master'.
580 ///
581 class OMPProcBindClause : public OMPClause {
582   friend class OMPClauseReader;
583   /// \brief Location of '('.
584   SourceLocation LParenLoc;
585   /// \brief A kind of the 'proc_bind' clause.
586   OpenMPProcBindClauseKind Kind;
587   /// \brief Start location of the kind in source code.
588   SourceLocation KindKwLoc;
589
590   /// \brief Set kind of the clause.
591   ///
592   /// \param K Kind of clause.
593   ///
594   void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
595
596   /// \brief Set clause kind location.
597   ///
598   /// \param KLoc Kind location.
599   ///
600   void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
601
602 public:
603   /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
604   ///        'spread').
605   ///
606   /// \param A Argument of the clause ('master', 'close' or 'spread').
607   /// \param ALoc Starting location of the argument.
608   /// \param StartLoc Starting location of the clause.
609   /// \param LParenLoc Location of '('.
610   /// \param EndLoc Ending location of the clause.
611   ///
612   OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
613                     SourceLocation StartLoc, SourceLocation LParenLoc,
614                     SourceLocation EndLoc)
615       : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
616         Kind(A), KindKwLoc(ALoc) {}
617
618   /// \brief Build an empty clause.
619   ///
620   OMPProcBindClause()
621       : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
622         LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
623         KindKwLoc(SourceLocation()) {}
624
625   /// \brief Sets the location of '('.
626   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
627   /// \brief Returns the location of '('.
628   SourceLocation getLParenLoc() const { return LParenLoc; }
629
630   /// \brief Returns kind of the clause.
631   OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
632
633   /// \brief Returns location of clause kind.
634   SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
635
636   static bool classof(const OMPClause *T) {
637     return T->getClauseKind() == OMPC_proc_bind;
638   }
639
640   child_range children() {
641     return child_range(child_iterator(), child_iterator());
642   }
643 };
644
645 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
646 ///
647 /// \code
648 /// #pragma omp for schedule(static, 3)
649 /// \endcode
650 /// In this example directive '#pragma omp for' has 'schedule' clause with
651 /// arguments 'static' and '3'.
652 ///
653 class OMPScheduleClause : public OMPClause {
654   friend class OMPClauseReader;
655   /// \brief Location of '('.
656   SourceLocation LParenLoc;
657   /// \brief A kind of the 'schedule' clause.
658   OpenMPScheduleClauseKind Kind;
659   /// \brief Modifiers for 'schedule' clause.
660   enum {FIRST, SECOND, NUM_MODIFIERS};
661   OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
662   /// \brief Locations of modifiers.
663   SourceLocation ModifiersLoc[NUM_MODIFIERS];
664   /// \brief Start location of the schedule ind in source code.
665   SourceLocation KindLoc;
666   /// \brief Location of ',' (if any).
667   SourceLocation CommaLoc;
668   /// \brief Chunk size and a reference to pseudo variable for combined
669   /// directives.
670   enum { CHUNK_SIZE, HELPER_CHUNK_SIZE, NUM_EXPRS };
671   Stmt *ChunkSizes[NUM_EXPRS];
672
673   /// \brief Set schedule kind.
674   ///
675   /// \param K Schedule kind.
676   ///
677   void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
678   /// \brief Set the first schedule modifier.
679   ///
680   /// \param M Schedule modifier.
681   ///
682   void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
683     Modifiers[FIRST] = M;
684   }
685   /// \brief Set the second schedule modifier.
686   ///
687   /// \param M Schedule modifier.
688   ///
689   void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
690     Modifiers[SECOND] = M;
691   }
692   /// \brief Set location of the first schedule modifier.
693   ///
694   void setFirstScheduleModifierLoc(SourceLocation Loc) {
695     ModifiersLoc[FIRST] = Loc;
696   }
697   /// \brief Set location of the second schedule modifier.
698   ///
699   void setSecondScheduleModifierLoc(SourceLocation Loc) {
700     ModifiersLoc[SECOND] = Loc;
701   }
702   /// \brief Set schedule modifier location.
703   ///
704   /// \param M Schedule modifier location.
705   ///
706   void setScheduleModifer(OpenMPScheduleClauseModifier M) {
707     if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
708       Modifiers[FIRST] = M;
709     else {
710       assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
711       Modifiers[SECOND] = M;
712     }
713   }
714   /// \brief Sets the location of '('.
715   ///
716   /// \param Loc Location of '('.
717   ///
718   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
719   /// \brief Set schedule kind start location.
720   ///
721   /// \param KLoc Schedule kind location.
722   ///
723   void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
724   /// \brief Set location of ','.
725   ///
726   /// \param Loc Location of ','.
727   ///
728   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
729   /// \brief Set chunk size.
730   ///
731   /// \param E Chunk size.
732   ///
733   void setChunkSize(Expr *E) { ChunkSizes[CHUNK_SIZE] = E; }
734   /// \brief Set helper chunk size.
735   ///
736   /// \param E Helper chunk size.
737   ///
738   void setHelperChunkSize(Expr *E) { ChunkSizes[HELPER_CHUNK_SIZE] = E; }
739
740 public:
741   /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
742   /// expression \a ChunkSize.
743   ///
744   /// \param StartLoc Starting location of the clause.
745   /// \param LParenLoc Location of '('.
746   /// \param KLoc Starting location of the argument.
747   /// \param CommaLoc Location of ','.
748   /// \param EndLoc Ending location of the clause.
749   /// \param Kind Schedule kind.
750   /// \param ChunkSize Chunk size.
751   /// \param HelperChunkSize Helper chunk size for combined directives.
752   /// \param M1 The first modifier applied to 'schedule' clause.
753   /// \param M1Loc Location of the first modifier
754   /// \param M2 The second modifier applied to 'schedule' clause.
755   /// \param M2Loc Location of the second modifier
756   ///
757   OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
758                     SourceLocation KLoc, SourceLocation CommaLoc,
759                     SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
760                     Expr *ChunkSize, Expr *HelperChunkSize,
761                     OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
762                     OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
763       : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
764         Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc) {
765     ChunkSizes[CHUNK_SIZE] = ChunkSize;
766     ChunkSizes[HELPER_CHUNK_SIZE] = HelperChunkSize;
767     Modifiers[FIRST] = M1;
768     Modifiers[SECOND] = M2;
769     ModifiersLoc[FIRST] = M1Loc;
770     ModifiersLoc[SECOND] = M2Loc;
771   }
772
773   /// \brief Build an empty clause.
774   ///
775   explicit OMPScheduleClause()
776       : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
777         Kind(OMPC_SCHEDULE_unknown) {
778     ChunkSizes[CHUNK_SIZE] = nullptr;
779     ChunkSizes[HELPER_CHUNK_SIZE] = nullptr;
780     Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
781     Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
782   }
783
784   /// \brief Get kind of the clause.
785   ///
786   OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
787   /// \brief Get the first modifier of the clause.
788   ///
789   OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
790     return Modifiers[FIRST];
791   }
792   /// \brief Get the second modifier of the clause.
793   ///
794   OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
795     return Modifiers[SECOND];
796   }
797   /// \brief Get location of '('.
798   ///
799   SourceLocation getLParenLoc() { return LParenLoc; }
800   /// \brief Get kind location.
801   ///
802   SourceLocation getScheduleKindLoc() { return KindLoc; }
803   /// \brief Get the first modifier location.
804   ///
805   SourceLocation getFirstScheduleModifierLoc() const {
806     return ModifiersLoc[FIRST];
807   }
808   /// \brief Get the second modifier location.
809   ///
810   SourceLocation getSecondScheduleModifierLoc() const {
811     return ModifiersLoc[SECOND];
812   }
813   /// \brief Get location of ','.
814   ///
815   SourceLocation getCommaLoc() { return CommaLoc; }
816   /// \brief Get chunk size.
817   ///
818   Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]); }
819   /// \brief Get chunk size.
820   ///
821   Expr *getChunkSize() const {
822     return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]);
823   }
824   /// \brief Get helper chunk size.
825   ///
826   Expr *getHelperChunkSize() {
827     return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
828   }
829   /// \brief Get helper chunk size.
830   ///
831   Expr *getHelperChunkSize() const {
832     return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
833   }
834
835   static bool classof(const OMPClause *T) {
836     return T->getClauseKind() == OMPC_schedule;
837   }
838
839   child_range children() {
840     return child_range(&ChunkSizes[CHUNK_SIZE], &ChunkSizes[CHUNK_SIZE] + 1);
841   }
842 };
843
844 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
845 ///
846 /// \code
847 /// #pragma omp for ordered (2)
848 /// \endcode
849 /// In this example directive '#pragma omp for' has 'ordered' clause with
850 /// parameter 2.
851 ///
852 class OMPOrderedClause : public OMPClause {
853   friend class OMPClauseReader;
854   /// \brief Location of '('.
855   SourceLocation LParenLoc;
856   /// \brief Number of for-loops.
857   Stmt *NumForLoops;
858
859   /// \brief Set the number of associated for-loops.
860   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
861
862 public:
863   /// \brief Build 'ordered' clause.
864   ///
865   /// \param Num Expression, possibly associated with this clause.
866   /// \param StartLoc Starting location of the clause.
867   /// \param LParenLoc Location of '('.
868   /// \param EndLoc Ending location of the clause.
869   ///
870   OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
871                     SourceLocation LParenLoc, SourceLocation EndLoc)
872       : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
873         NumForLoops(Num) {}
874
875   /// \brief Build an empty clause.
876   ///
877   explicit OMPOrderedClause()
878       : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
879         LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
880
881   /// \brief Sets the location of '('.
882   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
883   /// \brief Returns the location of '('.
884   SourceLocation getLParenLoc() const { return LParenLoc; }
885
886   /// \brief Return the number of associated for-loops.
887   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
888
889   static bool classof(const OMPClause *T) {
890     return T->getClauseKind() == OMPC_ordered;
891   }
892
893   child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
894 };
895
896 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
897 ///
898 /// \code
899 /// #pragma omp for nowait
900 /// \endcode
901 /// In this example directive '#pragma omp for' has 'nowait' clause.
902 ///
903 class OMPNowaitClause : public OMPClause {
904 public:
905   /// \brief Build 'nowait' clause.
906   ///
907   /// \param StartLoc Starting location of the clause.
908   /// \param EndLoc Ending location of the clause.
909   ///
910   OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
911       : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
912
913   /// \brief Build an empty clause.
914   ///
915   OMPNowaitClause()
916       : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
917
918   static bool classof(const OMPClause *T) {
919     return T->getClauseKind() == OMPC_nowait;
920   }
921
922   child_range children() {
923     return child_range(child_iterator(), child_iterator());
924   }
925 };
926
927 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
928 ///
929 /// \code
930 /// #pragma omp task untied
931 /// \endcode
932 /// In this example directive '#pragma omp task' has 'untied' clause.
933 ///
934 class OMPUntiedClause : public OMPClause {
935 public:
936   /// \brief Build 'untied' clause.
937   ///
938   /// \param StartLoc Starting location of the clause.
939   /// \param EndLoc Ending location of the clause.
940   ///
941   OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
942       : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
943
944   /// \brief Build an empty clause.
945   ///
946   OMPUntiedClause()
947       : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
948
949   static bool classof(const OMPClause *T) {
950     return T->getClauseKind() == OMPC_untied;
951   }
952
953   child_range children() {
954     return child_range(child_iterator(), child_iterator());
955   }
956 };
957
958 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
959 /// directive.
960 ///
961 /// \code
962 /// #pragma omp task mergeable
963 /// \endcode
964 /// In this example directive '#pragma omp task' has 'mergeable' clause.
965 ///
966 class OMPMergeableClause : public OMPClause {
967 public:
968   /// \brief Build 'mergeable' clause.
969   ///
970   /// \param StartLoc Starting location of the clause.
971   /// \param EndLoc Ending location of the clause.
972   ///
973   OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
974       : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
975
976   /// \brief Build an empty clause.
977   ///
978   OMPMergeableClause()
979       : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
980
981   static bool classof(const OMPClause *T) {
982     return T->getClauseKind() == OMPC_mergeable;
983   }
984
985   child_range children() {
986     return child_range(child_iterator(), child_iterator());
987   }
988 };
989
990 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
991 ///
992 /// \code
993 /// #pragma omp atomic read
994 /// \endcode
995 /// In this example directive '#pragma omp atomic' has 'read' clause.
996 ///
997 class OMPReadClause : public OMPClause {
998 public:
999   /// \brief Build 'read' clause.
1000   ///
1001   /// \param StartLoc Starting location of the clause.
1002   /// \param EndLoc Ending location of the clause.
1003   ///
1004   OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1005       : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1006
1007   /// \brief Build an empty clause.
1008   ///
1009   OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1010
1011   static bool classof(const OMPClause *T) {
1012     return T->getClauseKind() == OMPC_read;
1013   }
1014
1015   child_range children() {
1016     return child_range(child_iterator(), child_iterator());
1017   }
1018 };
1019
1020 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
1021 ///
1022 /// \code
1023 /// #pragma omp atomic write
1024 /// \endcode
1025 /// In this example directive '#pragma omp atomic' has 'write' clause.
1026 ///
1027 class OMPWriteClause : public OMPClause {
1028 public:
1029   /// \brief Build 'write' clause.
1030   ///
1031   /// \param StartLoc Starting location of the clause.
1032   /// \param EndLoc Ending location of the clause.
1033   ///
1034   OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1035       : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1036
1037   /// \brief Build an empty clause.
1038   ///
1039   OMPWriteClause()
1040       : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1041
1042   static bool classof(const OMPClause *T) {
1043     return T->getClauseKind() == OMPC_write;
1044   }
1045
1046   child_range children() {
1047     return child_range(child_iterator(), child_iterator());
1048   }
1049 };
1050
1051 /// \brief This represents 'update' clause in the '#pragma omp atomic'
1052 /// directive.
1053 ///
1054 /// \code
1055 /// #pragma omp atomic update
1056 /// \endcode
1057 /// In this example directive '#pragma omp atomic' has 'update' clause.
1058 ///
1059 class OMPUpdateClause : public OMPClause {
1060 public:
1061   /// \brief Build 'update' clause.
1062   ///
1063   /// \param StartLoc Starting location of the clause.
1064   /// \param EndLoc Ending location of the clause.
1065   ///
1066   OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
1067       : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1068
1069   /// \brief Build an empty clause.
1070   ///
1071   OMPUpdateClause()
1072       : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1073
1074   static bool classof(const OMPClause *T) {
1075     return T->getClauseKind() == OMPC_update;
1076   }
1077
1078   child_range children() {
1079     return child_range(child_iterator(), child_iterator());
1080   }
1081 };
1082
1083 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
1084 /// directive.
1085 ///
1086 /// \code
1087 /// #pragma omp atomic capture
1088 /// \endcode
1089 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1090 ///
1091 class OMPCaptureClause : public OMPClause {
1092 public:
1093   /// \brief Build 'capture' clause.
1094   ///
1095   /// \param StartLoc Starting location of the clause.
1096   /// \param EndLoc Ending location of the clause.
1097   ///
1098   OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1099       : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1100
1101   /// \brief Build an empty clause.
1102   ///
1103   OMPCaptureClause()
1104       : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1105
1106   static bool classof(const OMPClause *T) {
1107     return T->getClauseKind() == OMPC_capture;
1108   }
1109
1110   child_range children() {
1111     return child_range(child_iterator(), child_iterator());
1112   }
1113 };
1114
1115 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
1116 /// directive.
1117 ///
1118 /// \code
1119 /// #pragma omp atomic seq_cst
1120 /// \endcode
1121 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1122 ///
1123 class OMPSeqCstClause : public OMPClause {
1124 public:
1125   /// \brief Build 'seq_cst' clause.
1126   ///
1127   /// \param StartLoc Starting location of the clause.
1128   /// \param EndLoc Ending location of the clause.
1129   ///
1130   OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1131       : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1132
1133   /// \brief Build an empty clause.
1134   ///
1135   OMPSeqCstClause()
1136       : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1137
1138   static bool classof(const OMPClause *T) {
1139     return T->getClauseKind() == OMPC_seq_cst;
1140   }
1141
1142   child_range children() {
1143     return child_range(child_iterator(), child_iterator());
1144   }
1145 };
1146
1147 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
1148 ///
1149 /// \code
1150 /// #pragma omp parallel private(a,b)
1151 /// \endcode
1152 /// In this example directive '#pragma omp parallel' has clause 'private'
1153 /// with the variables 'a' and 'b'.
1154 ///
1155 class OMPPrivateClause final
1156     : public OMPVarListClause<OMPPrivateClause>,
1157       private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1158   friend TrailingObjects;
1159   friend OMPVarListClause;
1160   friend class OMPClauseReader;
1161   /// \brief Build clause with number of variables \a N.
1162   ///
1163   /// \param StartLoc Starting location of the clause.
1164   /// \param LParenLoc Location of '('.
1165   /// \param EndLoc Ending location of the clause.
1166   /// \param N Number of the variables in the clause.
1167   ///
1168   OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1169                    SourceLocation EndLoc, unsigned N)
1170       : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1171                                            EndLoc, N) {}
1172
1173   /// \brief Build an empty clause.
1174   ///
1175   /// \param N Number of variables.
1176   ///
1177   explicit OMPPrivateClause(unsigned N)
1178       : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
1179                                            SourceLocation(), SourceLocation(),
1180                                            N) {}
1181
1182   /// \brief Sets the list of references to private copies with initializers for
1183   /// new private variables.
1184   /// \param VL List of references.
1185   void setPrivateCopies(ArrayRef<Expr *> VL);
1186
1187   /// \brief Gets the list of references to private copies with initializers for
1188   /// new private variables.
1189   MutableArrayRef<Expr *> getPrivateCopies() {
1190     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1191   }
1192   ArrayRef<const Expr *> getPrivateCopies() const {
1193     return llvm::makeArrayRef(varlist_end(), varlist_size());
1194   }
1195
1196 public:
1197   /// \brief Creates clause with a list of variables \a VL.
1198   ///
1199   /// \param C AST context.
1200   /// \param StartLoc Starting location of the clause.
1201   /// \param LParenLoc Location of '('.
1202   /// \param EndLoc Ending location of the clause.
1203   /// \param VL List of references to the variables.
1204   /// \param PrivateVL List of references to private copies with initializers.
1205   ///
1206   static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1207                                   SourceLocation LParenLoc,
1208                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
1209                                   ArrayRef<Expr *> PrivateVL);
1210   /// \brief Creates an empty clause with the place for \a N variables.
1211   ///
1212   /// \param C AST context.
1213   /// \param N The number of variables.
1214   ///
1215   static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1216
1217   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1218   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1219   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1220   typedef llvm::iterator_range<private_copies_const_iterator>
1221       private_copies_const_range;
1222
1223   private_copies_range private_copies() {
1224     return private_copies_range(getPrivateCopies().begin(),
1225                                 getPrivateCopies().end());
1226   }
1227   private_copies_const_range private_copies() const {
1228     return private_copies_const_range(getPrivateCopies().begin(),
1229                                       getPrivateCopies().end());
1230   }
1231
1232   child_range children() {
1233     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1234                        reinterpret_cast<Stmt **>(varlist_end()));
1235   }
1236
1237   static bool classof(const OMPClause *T) {
1238     return T->getClauseKind() == OMPC_private;
1239   }
1240 };
1241
1242 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
1243 /// directives.
1244 ///
1245 /// \code
1246 /// #pragma omp parallel firstprivate(a,b)
1247 /// \endcode
1248 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1249 /// with the variables 'a' and 'b'.
1250 ///
1251 class OMPFirstprivateClause final
1252     : public OMPVarListClause<OMPFirstprivateClause>,
1253       private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1254   friend TrailingObjects;
1255   friend OMPVarListClause;
1256   friend class OMPClauseReader;
1257
1258   /// \brief Build clause with number of variables \a N.
1259   ///
1260   /// \param StartLoc Starting location of the clause.
1261   /// \param LParenLoc Location of '('.
1262   /// \param EndLoc Ending location of the clause.
1263   /// \param N Number of the variables in the clause.
1264   ///
1265   OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1266                         SourceLocation EndLoc, unsigned N)
1267       : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1268                                                 LParenLoc, EndLoc, N) {}
1269
1270   /// \brief Build an empty clause.
1271   ///
1272   /// \param N Number of variables.
1273   ///
1274   explicit OMPFirstprivateClause(unsigned N)
1275       : OMPVarListClause<OMPFirstprivateClause>(
1276             OMPC_firstprivate, SourceLocation(), SourceLocation(),
1277             SourceLocation(), N) {}
1278   /// \brief Sets the list of references to private copies with initializers for
1279   /// new private variables.
1280   /// \param VL List of references.
1281   void setPrivateCopies(ArrayRef<Expr *> VL);
1282
1283   /// \brief Gets the list of references to private copies with initializers for
1284   /// new private variables.
1285   MutableArrayRef<Expr *> getPrivateCopies() {
1286     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1287   }
1288   ArrayRef<const Expr *> getPrivateCopies() const {
1289     return llvm::makeArrayRef(varlist_end(), varlist_size());
1290   }
1291
1292   /// \brief Sets the list of references to initializer variables for new
1293   /// private variables.
1294   /// \param VL List of references.
1295   void setInits(ArrayRef<Expr *> VL);
1296
1297   /// \brief Gets the list of references to initializer variables for new
1298   /// private variables.
1299   MutableArrayRef<Expr *> getInits() {
1300     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1301   }
1302   ArrayRef<const Expr *> getInits() const {
1303     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1304   }
1305
1306 public:
1307   /// \brief Creates clause with a list of variables \a VL.
1308   ///
1309   /// \param C AST context.
1310   /// \param StartLoc Starting location of the clause.
1311   /// \param LParenLoc Location of '('.
1312   /// \param EndLoc Ending location of the clause.
1313   /// \param VL List of references to the original variables.
1314   /// \param PrivateVL List of references to private copies with initializers.
1315   /// \param InitVL List of references to auto generated variables used for
1316   /// initialization of a single array element. Used if firstprivate variable is
1317   /// of array type.
1318   ///
1319   static OMPFirstprivateClause *
1320   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1321          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1322          ArrayRef<Expr *> InitVL);
1323   /// \brief Creates an empty clause with the place for \a N variables.
1324   ///
1325   /// \param C AST context.
1326   /// \param N The number of variables.
1327   ///
1328   static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1329
1330   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1331   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1332   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1333   typedef llvm::iterator_range<private_copies_const_iterator>
1334       private_copies_const_range;
1335
1336   private_copies_range private_copies() {
1337     return private_copies_range(getPrivateCopies().begin(),
1338                                 getPrivateCopies().end());
1339   }
1340   private_copies_const_range private_copies() const {
1341     return private_copies_const_range(getPrivateCopies().begin(),
1342                                       getPrivateCopies().end());
1343   }
1344
1345   typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1346   typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1347   typedef llvm::iterator_range<inits_iterator> inits_range;
1348   typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1349
1350   inits_range inits() {
1351     return inits_range(getInits().begin(), getInits().end());
1352   }
1353   inits_const_range inits() const {
1354     return inits_const_range(getInits().begin(), getInits().end());
1355   }
1356
1357   child_range children() {
1358     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1359                        reinterpret_cast<Stmt **>(varlist_end()));
1360   }
1361
1362   static bool classof(const OMPClause *T) {
1363     return T->getClauseKind() == OMPC_firstprivate;
1364   }
1365 };
1366
1367 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
1368 /// directives.
1369 ///
1370 /// \code
1371 /// #pragma omp simd lastprivate(a,b)
1372 /// \endcode
1373 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1374 /// with the variables 'a' and 'b'.
1375 class OMPLastprivateClause final
1376     : public OMPVarListClause<OMPLastprivateClause>,
1377       private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
1378   // There are 4 additional tail-allocated arrays at the end of the class:
1379   // 1. Contains list of pseudo variables with the default initialization for
1380   // each non-firstprivate variables. Used in codegen for initialization of
1381   // lastprivate copies.
1382   // 2. List of helper expressions for proper generation of assignment operation
1383   // required for lastprivate clause. This list represents private variables
1384   // (for arrays, single array element).
1385   // 3. List of helper expressions for proper generation of assignment operation
1386   // required for lastprivate clause. This list represents original variables
1387   // (for arrays, single array element).
1388   // 4. List of helper expressions that represents assignment operation:
1389   // \code
1390   // DstExprs = SrcExprs;
1391   // \endcode
1392   // Required for proper codegen of final assignment performed by the
1393   // lastprivate clause.
1394   //
1395   friend TrailingObjects;
1396   friend OMPVarListClause;
1397   friend class OMPClauseReader;
1398
1399   /// \brief Build clause with number of variables \a N.
1400   ///
1401   /// \param StartLoc Starting location of the clause.
1402   /// \param LParenLoc Location of '('.
1403   /// \param EndLoc Ending location of the clause.
1404   /// \param N Number of the variables in the clause.
1405   ///
1406   OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1407                        SourceLocation EndLoc, unsigned N)
1408       : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1409                                                LParenLoc, EndLoc, N) {}
1410
1411   /// \brief Build an empty clause.
1412   ///
1413   /// \param N Number of variables.
1414   ///
1415   explicit OMPLastprivateClause(unsigned N)
1416       : OMPVarListClause<OMPLastprivateClause>(
1417             OMPC_lastprivate, SourceLocation(), SourceLocation(),
1418             SourceLocation(), N) {}
1419
1420   /// \brief Get the list of helper expressions for initialization of private
1421   /// copies for lastprivate variables.
1422   MutableArrayRef<Expr *> getPrivateCopies() {
1423     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1424   }
1425   ArrayRef<const Expr *> getPrivateCopies() const {
1426     return llvm::makeArrayRef(varlist_end(), varlist_size());
1427   }
1428
1429   /// \brief Set list of helper expressions, required for proper codegen of the
1430   /// clause. These expressions represent private variables (for arrays, single
1431   /// array element) in the final assignment statement performed by the
1432   /// lastprivate clause.
1433   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1434
1435   /// \brief Get the list of helper source expressions.
1436   MutableArrayRef<Expr *> getSourceExprs() {
1437     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1438   }
1439   ArrayRef<const Expr *> getSourceExprs() const {
1440     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1441   }
1442
1443   /// \brief Set list of helper expressions, required for proper codegen of the
1444   /// clause. These expressions represent original variables (for arrays, single
1445   /// array element) in the final assignment statement performed by the
1446   /// lastprivate clause.
1447   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1448
1449   /// \brief Get the list of helper destination expressions.
1450   MutableArrayRef<Expr *> getDestinationExprs() {
1451     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1452   }
1453   ArrayRef<const Expr *> getDestinationExprs() const {
1454     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1455   }
1456
1457   /// \brief Set list of helper assignment expressions, required for proper
1458   /// codegen of the clause. These expressions are assignment expressions that
1459   /// assign private copy of the variable to original variable.
1460   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1461
1462   /// \brief Get the list of helper assignment expressions.
1463   MutableArrayRef<Expr *> getAssignmentOps() {
1464     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1465   }
1466   ArrayRef<const Expr *> getAssignmentOps() const {
1467     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1468   }
1469
1470 public:
1471   /// \brief Creates clause with a list of variables \a VL.
1472   ///
1473   /// \param C AST context.
1474   /// \param StartLoc Starting location of the clause.
1475   /// \param LParenLoc Location of '('.
1476   /// \param EndLoc Ending location of the clause.
1477   /// \param VL List of references to the variables.
1478   /// \param SrcExprs List of helper expressions for proper generation of
1479   /// assignment operation required for lastprivate clause. This list represents
1480   /// private variables (for arrays, single array element).
1481   /// \param DstExprs List of helper expressions for proper generation of
1482   /// assignment operation required for lastprivate clause. This list represents
1483   /// original variables (for arrays, single array element).
1484   /// \param AssignmentOps List of helper expressions that represents assignment
1485   /// operation:
1486   /// \code
1487   /// DstExprs = SrcExprs;
1488   /// \endcode
1489   /// Required for proper codegen of final assignment performed by the
1490   /// lastprivate clause.
1491   ///
1492   ///
1493   static OMPLastprivateClause *
1494   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1495          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1496          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
1497   /// \brief Creates an empty clause with the place for \a N variables.
1498   ///
1499   /// \param C AST context.
1500   /// \param N The number of variables.
1501   ///
1502   static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1503
1504   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1505   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1506   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1507   typedef llvm::iterator_range<helper_expr_const_iterator>
1508       helper_expr_const_range;
1509
1510   /// \brief Set list of helper expressions, required for generation of private
1511   /// copies of original lastprivate variables.
1512   void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1513
1514   helper_expr_const_range private_copies() const {
1515     return helper_expr_const_range(getPrivateCopies().begin(),
1516                                    getPrivateCopies().end());
1517   }
1518   helper_expr_range private_copies() {
1519     return helper_expr_range(getPrivateCopies().begin(),
1520                              getPrivateCopies().end());
1521   }
1522   helper_expr_const_range source_exprs() const {
1523     return helper_expr_const_range(getSourceExprs().begin(),
1524                                    getSourceExprs().end());
1525   }
1526   helper_expr_range source_exprs() {
1527     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1528   }
1529   helper_expr_const_range destination_exprs() const {
1530     return helper_expr_const_range(getDestinationExprs().begin(),
1531                                    getDestinationExprs().end());
1532   }
1533   helper_expr_range destination_exprs() {
1534     return helper_expr_range(getDestinationExprs().begin(),
1535                              getDestinationExprs().end());
1536   }
1537   helper_expr_const_range assignment_ops() const {
1538     return helper_expr_const_range(getAssignmentOps().begin(),
1539                                    getAssignmentOps().end());
1540   }
1541   helper_expr_range assignment_ops() {
1542     return helper_expr_range(getAssignmentOps().begin(),
1543                              getAssignmentOps().end());
1544   }
1545
1546   child_range children() {
1547     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1548                        reinterpret_cast<Stmt **>(varlist_end()));
1549   }
1550
1551   static bool classof(const OMPClause *T) {
1552     return T->getClauseKind() == OMPC_lastprivate;
1553   }
1554 };
1555
1556 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
1557 ///
1558 /// \code
1559 /// #pragma omp parallel shared(a,b)
1560 /// \endcode
1561 /// In this example directive '#pragma omp parallel' has clause 'shared'
1562 /// with the variables 'a' and 'b'.
1563 ///
1564 class OMPSharedClause final
1565     : public OMPVarListClause<OMPSharedClause>,
1566       private llvm::TrailingObjects<OMPSharedClause, Expr *> {
1567   friend TrailingObjects;
1568   friend OMPVarListClause;
1569   /// \brief Build clause with number of variables \a N.
1570   ///
1571   /// \param StartLoc Starting location of the clause.
1572   /// \param LParenLoc Location of '('.
1573   /// \param EndLoc Ending location of the clause.
1574   /// \param N Number of the variables in the clause.
1575   ///
1576   OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1577                   SourceLocation EndLoc, unsigned N)
1578       : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1579                                           EndLoc, N) {}
1580
1581   /// \brief Build an empty clause.
1582   ///
1583   /// \param N Number of variables.
1584   ///
1585   explicit OMPSharedClause(unsigned N)
1586       : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1587                                           SourceLocation(), SourceLocation(),
1588                                           N) {}
1589
1590 public:
1591   /// \brief Creates clause with a list of variables \a VL.
1592   ///
1593   /// \param C AST context.
1594   /// \param StartLoc Starting location of the clause.
1595   /// \param LParenLoc Location of '('.
1596   /// \param EndLoc Ending location of the clause.
1597   /// \param VL List of references to the variables.
1598   ///
1599   static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1600                                  SourceLocation LParenLoc,
1601                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
1602   /// \brief Creates an empty clause with \a N variables.
1603   ///
1604   /// \param C AST context.
1605   /// \param N The number of variables.
1606   ///
1607   static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1608
1609   child_range children() {
1610     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1611                        reinterpret_cast<Stmt **>(varlist_end()));
1612   }
1613
1614   static bool classof(const OMPClause *T) {
1615     return T->getClauseKind() == OMPC_shared;
1616   }
1617 };
1618
1619 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
1620 /// directives.
1621 ///
1622 /// \code
1623 /// #pragma omp parallel reduction(+:a,b)
1624 /// \endcode
1625 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1626 /// with operator '+' and the variables 'a' and 'b'.
1627 ///
1628 class OMPReductionClause final
1629     : public OMPVarListClause<OMPReductionClause>,
1630       private llvm::TrailingObjects<OMPReductionClause, Expr *> {
1631   friend TrailingObjects;
1632   friend OMPVarListClause;
1633   friend class OMPClauseReader;
1634   /// \brief Location of ':'.
1635   SourceLocation ColonLoc;
1636   /// \brief Nested name specifier for C++.
1637   NestedNameSpecifierLoc QualifierLoc;
1638   /// \brief Name of custom operator.
1639   DeclarationNameInfo NameInfo;
1640
1641   /// \brief Build clause with number of variables \a N.
1642   ///
1643   /// \param StartLoc Starting location of the clause.
1644   /// \param LParenLoc Location of '('.
1645   /// \param EndLoc Ending location of the clause.
1646   /// \param ColonLoc Location of ':'.
1647   /// \param N Number of the variables in the clause.
1648   /// \param QualifierLoc The nested-name qualifier with location information
1649   /// \param NameInfo The full name info for reduction identifier.
1650   ///
1651   OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1652                      SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1653                      NestedNameSpecifierLoc QualifierLoc,
1654                      const DeclarationNameInfo &NameInfo)
1655       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1656                                              LParenLoc, EndLoc, N),
1657         ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1658
1659   /// \brief Build an empty clause.
1660   ///
1661   /// \param N Number of variables.
1662   ///
1663   explicit OMPReductionClause(unsigned N)
1664       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1665                                              SourceLocation(), SourceLocation(),
1666                                              N),
1667         ColonLoc(), QualifierLoc(), NameInfo() {}
1668
1669   /// \brief Sets location of ':' symbol in clause.
1670   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1671   /// \brief Sets the name info for specified reduction identifier.
1672   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1673   /// \brief Sets the nested name specifier.
1674   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1675
1676   /// \brief Set list of helper expressions, required for proper codegen of the
1677   /// clause. These expressions represent private copy of the reduction
1678   /// variable.
1679   void setPrivates(ArrayRef<Expr *> Privates);
1680
1681   /// \brief Get the list of helper privates.
1682   MutableArrayRef<Expr *> getPrivates() {
1683     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1684   }
1685   ArrayRef<const Expr *> getPrivates() const {
1686     return llvm::makeArrayRef(varlist_end(), varlist_size());
1687   }
1688
1689   /// \brief Set list of helper expressions, required for proper codegen of the
1690   /// clause. These expressions represent LHS expression in the final
1691   /// reduction expression performed by the reduction clause.
1692   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1693
1694   /// \brief Get the list of helper LHS expressions.
1695   MutableArrayRef<Expr *> getLHSExprs() {
1696     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1697   }
1698   ArrayRef<const Expr *> getLHSExprs() const {
1699     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1700   }
1701
1702   /// \brief Set list of helper expressions, required for proper codegen of the
1703   /// clause. These expressions represent RHS expression in the final
1704   /// reduction expression performed by the reduction clause.
1705   /// Also, variables in these expressions are used for proper initialization of
1706   /// reduction copies.
1707   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1708
1709   /// \brief Get the list of helper destination expressions.
1710   MutableArrayRef<Expr *> getRHSExprs() {
1711     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1712   }
1713   ArrayRef<const Expr *> getRHSExprs() const {
1714     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1715   }
1716
1717   /// \brief Set list of helper reduction expressions, required for proper
1718   /// codegen of the clause. These expressions are binary expressions or
1719   /// operator/custom reduction call that calculates new value from source
1720   /// helper expressions to destination helper expressions.
1721   void setReductionOps(ArrayRef<Expr *> ReductionOps);
1722
1723   /// \brief Get the list of helper reduction expressions.
1724   MutableArrayRef<Expr *> getReductionOps() {
1725     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1726   }
1727   ArrayRef<const Expr *> getReductionOps() const {
1728     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1729   }
1730
1731 public:
1732   /// \brief Creates clause with a list of variables \a VL.
1733   ///
1734   /// \param StartLoc Starting location of the clause.
1735   /// \param LParenLoc Location of '('.
1736   /// \param ColonLoc Location of ':'.
1737   /// \param EndLoc Ending location of the clause.
1738   /// \param VL The variables in the clause.
1739   /// \param QualifierLoc The nested-name qualifier with location information
1740   /// \param NameInfo The full name info for reduction identifier.
1741   /// \param Privates List of helper expressions for proper generation of
1742   /// private copies.
1743   /// \param LHSExprs List of helper expressions for proper generation of
1744   /// assignment operation required for copyprivate clause. This list represents
1745   /// LHSs of the reduction expressions.
1746   /// \param RHSExprs List of helper expressions for proper generation of
1747   /// assignment operation required for copyprivate clause. This list represents
1748   /// RHSs of the reduction expressions.
1749   /// Also, variables in these expressions are used for proper initialization of
1750   /// reduction copies.
1751   /// \param ReductionOps List of helper expressions that represents reduction
1752   /// expressions:
1753   /// \code
1754   /// LHSExprs binop RHSExprs;
1755   /// operator binop(LHSExpr, RHSExpr);
1756   /// <CutomReduction>(LHSExpr, RHSExpr);
1757   /// \endcode
1758   /// Required for proper codegen of final reduction operation performed by the
1759   /// reduction clause.
1760   ///
1761   static OMPReductionClause *
1762   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1763          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1764          NestedNameSpecifierLoc QualifierLoc,
1765          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
1766          ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1767          ArrayRef<Expr *> ReductionOps);
1768   /// \brief Creates an empty clause with the place for \a N variables.
1769   ///
1770   /// \param C AST context.
1771   /// \param N The number of variables.
1772   ///
1773   static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1774
1775   /// \brief Gets location of ':' symbol in clause.
1776   SourceLocation getColonLoc() const { return ColonLoc; }
1777   /// \brief Gets the name info for specified reduction identifier.
1778   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1779   /// \brief Gets the nested name specifier.
1780   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1781
1782   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1783   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1784   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1785   typedef llvm::iterator_range<helper_expr_const_iterator>
1786       helper_expr_const_range;
1787
1788   helper_expr_const_range privates() const {
1789     return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
1790   }
1791   helper_expr_range privates() {
1792     return helper_expr_range(getPrivates().begin(), getPrivates().end());
1793   }
1794   helper_expr_const_range lhs_exprs() const {
1795     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
1796   }
1797   helper_expr_range lhs_exprs() {
1798     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
1799   }
1800   helper_expr_const_range rhs_exprs() const {
1801     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
1802   }
1803   helper_expr_range rhs_exprs() {
1804     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
1805   }
1806   helper_expr_const_range reduction_ops() const {
1807     return helper_expr_const_range(getReductionOps().begin(),
1808                                    getReductionOps().end());
1809   }
1810   helper_expr_range reduction_ops() {
1811     return helper_expr_range(getReductionOps().begin(),
1812                              getReductionOps().end());
1813   }
1814
1815   child_range children() {
1816     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1817                        reinterpret_cast<Stmt **>(varlist_end()));
1818   }
1819
1820   static bool classof(const OMPClause *T) {
1821     return T->getClauseKind() == OMPC_reduction;
1822   }
1823 };
1824
1825 /// \brief This represents clause 'linear' in the '#pragma omp ...'
1826 /// directives.
1827 ///
1828 /// \code
1829 /// #pragma omp simd linear(a,b : 2)
1830 /// \endcode
1831 /// In this example directive '#pragma omp simd' has clause 'linear'
1832 /// with variables 'a', 'b' and linear step '2'.
1833 ///
1834 class OMPLinearClause final
1835     : public OMPVarListClause<OMPLinearClause>,
1836       private llvm::TrailingObjects<OMPLinearClause, Expr *> {
1837   friend TrailingObjects;
1838   friend OMPVarListClause;
1839   friend class OMPClauseReader;
1840   /// \brief Modifier of 'linear' clause.
1841   OpenMPLinearClauseKind Modifier;
1842   /// \brief Location of linear modifier if any.
1843   SourceLocation ModifierLoc;
1844   /// \brief Location of ':'.
1845   SourceLocation ColonLoc;
1846
1847   /// \brief Sets the linear step for clause.
1848   void setStep(Expr *Step) { *(getFinals().end()) = Step; }
1849
1850   /// \brief Sets the expression to calculate linear step for clause.
1851   void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
1852
1853   /// \brief Build 'linear' clause with given number of variables \a NumVars.
1854   ///
1855   /// \param StartLoc Starting location of the clause.
1856   /// \param LParenLoc Location of '('.
1857   /// \param ColonLoc Location of ':'.
1858   /// \param EndLoc Ending location of the clause.
1859   /// \param NumVars Number of variables.
1860   ///
1861   OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1862                   OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
1863                   SourceLocation ColonLoc, SourceLocation EndLoc,
1864                   unsigned NumVars)
1865       : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
1866                                           EndLoc, NumVars),
1867         Modifier(Modifier), ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
1868
1869   /// \brief Build an empty clause.
1870   ///
1871   /// \param NumVars Number of variables.
1872   ///
1873   explicit OMPLinearClause(unsigned NumVars)
1874       : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
1875                                           SourceLocation(), SourceLocation(),
1876                                           NumVars),
1877         Modifier(OMPC_LINEAR_val), ModifierLoc(), ColonLoc() {}
1878
1879   /// \brief Gets the list of initial values for linear variables.
1880   ///
1881   /// There are NumVars expressions with initial values allocated after the
1882   /// varlist, they are followed by NumVars update expressions (used to update
1883   /// the linear variable's value on current iteration) and they are followed by
1884   /// NumVars final expressions (used to calculate the linear variable's
1885   /// value after the loop body). After these lists, there are 2 helper
1886   /// expressions - linear step and a helper to calculate it before the
1887   /// loop body (used when the linear step is not constant):
1888   ///
1889   /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
1890   /// Finals[]; Step; CalcStep; }
1891   ///
1892   MutableArrayRef<Expr *> getPrivates() {
1893     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1894   }
1895   ArrayRef<const Expr *> getPrivates() const {
1896     return llvm::makeArrayRef(varlist_end(), varlist_size());
1897   }
1898
1899   MutableArrayRef<Expr *> getInits() {
1900     return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1901   }
1902   ArrayRef<const Expr *> getInits() const {
1903     return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1904   }
1905
1906   /// \brief Sets the list of update expressions for linear variables.
1907   MutableArrayRef<Expr *> getUpdates() {
1908     return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
1909   }
1910   ArrayRef<const Expr *> getUpdates() const {
1911     return llvm::makeArrayRef(getInits().end(), varlist_size());
1912   }
1913
1914   /// \brief Sets the list of final update expressions for linear variables.
1915   MutableArrayRef<Expr *> getFinals() {
1916     return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
1917   }
1918   ArrayRef<const Expr *> getFinals() const {
1919     return llvm::makeArrayRef(getUpdates().end(), varlist_size());
1920   }
1921
1922   /// \brief Sets the list of the copies of original linear variables.
1923   /// \param PL List of expressions.
1924   void setPrivates(ArrayRef<Expr *> PL);
1925
1926   /// \brief Sets the list of the initial values for linear variables.
1927   /// \param IL List of expressions.
1928   void setInits(ArrayRef<Expr *> IL);
1929
1930 public:
1931   /// \brief Creates clause with a list of variables \a VL and a linear step
1932   /// \a Step.
1933   ///
1934   /// \param C AST Context.
1935   /// \param StartLoc Starting location of the clause.
1936   /// \param LParenLoc Location of '('.
1937   /// \param Modifier Modifier of 'linear' clause.
1938   /// \param ModifierLoc Modifier location.
1939   /// \param ColonLoc Location of ':'.
1940   /// \param EndLoc Ending location of the clause.
1941   /// \param VL List of references to the variables.
1942   /// \param PL List of private copies of original variables.
1943   /// \param IL List of initial values for the variables.
1944   /// \param Step Linear step.
1945   /// \param CalcStep Calculation of the linear step.
1946   static OMPLinearClause *
1947   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1948          OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
1949          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1950          ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep);
1951
1952   /// \brief Creates an empty clause with the place for \a NumVars variables.
1953   ///
1954   /// \param C AST context.
1955   /// \param NumVars Number of variables.
1956   ///
1957   static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1958
1959   /// \brief Set modifier.
1960   void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
1961   /// \brief Return modifier.
1962   OpenMPLinearClauseKind getModifier() const { return Modifier; }
1963
1964   /// \brief Set modifier location.
1965   void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
1966   /// \brief Return modifier location.
1967   SourceLocation getModifierLoc() const { return ModifierLoc; }
1968
1969   /// \brief Sets the location of ':'.
1970   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1971   /// \brief Returns the location of ':'.
1972   SourceLocation getColonLoc() const { return ColonLoc; }
1973
1974   /// \brief Returns linear step.
1975   Expr *getStep() { return *(getFinals().end()); }
1976   /// \brief Returns linear step.
1977   const Expr *getStep() const { return *(getFinals().end()); }
1978   /// \brief Returns expression to calculate linear step.
1979   Expr *getCalcStep() { return *(getFinals().end() + 1); }
1980   /// \brief Returns expression to calculate linear step.
1981   const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
1982
1983   /// \brief Sets the list of update expressions for linear variables.
1984   /// \param UL List of expressions.
1985   void setUpdates(ArrayRef<Expr *> UL);
1986
1987   /// \brief Sets the list of final update expressions for linear variables.
1988   /// \param FL List of expressions.
1989   void setFinals(ArrayRef<Expr *> FL);
1990
1991   typedef MutableArrayRef<Expr *>::iterator privates_iterator;
1992   typedef ArrayRef<const Expr *>::iterator privates_const_iterator;
1993   typedef llvm::iterator_range<privates_iterator> privates_range;
1994   typedef llvm::iterator_range<privates_const_iterator> privates_const_range;
1995
1996   privates_range privates() {
1997     return privates_range(getPrivates().begin(), getPrivates().end());
1998   }
1999   privates_const_range privates() const {
2000     return privates_const_range(getPrivates().begin(), getPrivates().end());
2001   }
2002
2003   typedef MutableArrayRef<Expr *>::iterator inits_iterator;
2004   typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
2005   typedef llvm::iterator_range<inits_iterator> inits_range;
2006   typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
2007
2008   inits_range inits() {
2009     return inits_range(getInits().begin(), getInits().end());
2010   }
2011   inits_const_range inits() const {
2012     return inits_const_range(getInits().begin(), getInits().end());
2013   }
2014
2015   typedef MutableArrayRef<Expr *>::iterator updates_iterator;
2016   typedef ArrayRef<const Expr *>::iterator updates_const_iterator;
2017   typedef llvm::iterator_range<updates_iterator> updates_range;
2018   typedef llvm::iterator_range<updates_const_iterator> updates_const_range;
2019
2020   updates_range updates() {
2021     return updates_range(getUpdates().begin(), getUpdates().end());
2022   }
2023   updates_const_range updates() const {
2024     return updates_const_range(getUpdates().begin(), getUpdates().end());
2025   }
2026
2027   typedef MutableArrayRef<Expr *>::iterator finals_iterator;
2028   typedef ArrayRef<const Expr *>::iterator finals_const_iterator;
2029   typedef llvm::iterator_range<finals_iterator> finals_range;
2030   typedef llvm::iterator_range<finals_const_iterator> finals_const_range;
2031
2032   finals_range finals() {
2033     return finals_range(getFinals().begin(), getFinals().end());
2034   }
2035   finals_const_range finals() const {
2036     return finals_const_range(getFinals().begin(), getFinals().end());
2037   }
2038
2039   child_range children() {
2040     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2041                        reinterpret_cast<Stmt **>(varlist_end()));
2042   }
2043
2044   static bool classof(const OMPClause *T) {
2045     return T->getClauseKind() == OMPC_linear;
2046   }
2047 };
2048
2049 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
2050 /// directives.
2051 ///
2052 /// \code
2053 /// #pragma omp simd aligned(a,b : 8)
2054 /// \endcode
2055 /// In this example directive '#pragma omp simd' has clause 'aligned'
2056 /// with variables 'a', 'b' and alignment '8'.
2057 ///
2058 class OMPAlignedClause final
2059     : public OMPVarListClause<OMPAlignedClause>,
2060       private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
2061   friend TrailingObjects;
2062   friend OMPVarListClause;
2063   friend class OMPClauseReader;
2064   /// \brief Location of ':'.
2065   SourceLocation ColonLoc;
2066
2067   /// \brief Sets the alignment for clause.
2068   void setAlignment(Expr *A) { *varlist_end() = A; }
2069
2070   /// \brief Build 'aligned' clause with given number of variables \a NumVars.
2071   ///
2072   /// \param StartLoc Starting location of the clause.
2073   /// \param LParenLoc Location of '('.
2074   /// \param ColonLoc Location of ':'.
2075   /// \param EndLoc Ending location of the clause.
2076   /// \param NumVars Number of variables.
2077   ///
2078   OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2079                    SourceLocation ColonLoc, SourceLocation EndLoc,
2080                    unsigned NumVars)
2081       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
2082                                            EndLoc, NumVars),
2083         ColonLoc(ColonLoc) {}
2084
2085   /// \brief Build an empty clause.
2086   ///
2087   /// \param NumVars Number of variables.
2088   ///
2089   explicit OMPAlignedClause(unsigned NumVars)
2090       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
2091                                            SourceLocation(), SourceLocation(),
2092                                            NumVars),
2093         ColonLoc(SourceLocation()) {}
2094
2095 public:
2096   /// \brief Creates clause with a list of variables \a VL and alignment \a A.
2097   ///
2098   /// \param C AST Context.
2099   /// \param StartLoc Starting location of the clause.
2100   /// \param LParenLoc Location of '('.
2101   /// \param ColonLoc Location of ':'.
2102   /// \param EndLoc Ending location of the clause.
2103   /// \param VL List of references to the variables.
2104   /// \param A Alignment.
2105   static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2106                                   SourceLocation LParenLoc,
2107                                   SourceLocation ColonLoc,
2108                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
2109                                   Expr *A);
2110
2111   /// \brief Creates an empty clause with the place for \a NumVars variables.
2112   ///
2113   /// \param C AST context.
2114   /// \param NumVars Number of variables.
2115   ///
2116   static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2117
2118   /// \brief Sets the location of ':'.
2119   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2120   /// \brief Returns the location of ':'.
2121   SourceLocation getColonLoc() const { return ColonLoc; }
2122
2123   /// \brief Returns alignment.
2124   Expr *getAlignment() { return *varlist_end(); }
2125   /// \brief Returns alignment.
2126   const Expr *getAlignment() const { return *varlist_end(); }
2127
2128   child_range children() {
2129     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2130                        reinterpret_cast<Stmt **>(varlist_end()));
2131   }
2132
2133   static bool classof(const OMPClause *T) {
2134     return T->getClauseKind() == OMPC_aligned;
2135   }
2136 };
2137
2138 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
2139 ///
2140 /// \code
2141 /// #pragma omp parallel copyin(a,b)
2142 /// \endcode
2143 /// In this example directive '#pragma omp parallel' has clause 'copyin'
2144 /// with the variables 'a' and 'b'.
2145 ///
2146 class OMPCopyinClause final
2147     : public OMPVarListClause<OMPCopyinClause>,
2148       private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
2149   // Class has 3 additional tail allocated arrays:
2150   // 1. List of helper expressions for proper generation of assignment operation
2151   // required for copyin clause. This list represents sources.
2152   // 2. List of helper expressions for proper generation of assignment operation
2153   // required for copyin clause. This list represents destinations.
2154   // 3. List of helper expressions that represents assignment operation:
2155   // \code
2156   // DstExprs = SrcExprs;
2157   // \endcode
2158   // Required for proper codegen of propagation of master's thread values of
2159   // threadprivate variables to local instances of that variables in other
2160   // implicit threads.
2161
2162   friend TrailingObjects;
2163   friend OMPVarListClause;
2164   friend class OMPClauseReader;
2165   /// \brief Build clause with number of variables \a N.
2166   ///
2167   /// \param StartLoc Starting location of the clause.
2168   /// \param LParenLoc Location of '('.
2169   /// \param EndLoc Ending location of the clause.
2170   /// \param N Number of the variables in the clause.
2171   ///
2172   OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2173                   SourceLocation EndLoc, unsigned N)
2174       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
2175                                           EndLoc, N) {}
2176
2177   /// \brief Build an empty clause.
2178   ///
2179   /// \param N Number of variables.
2180   ///
2181   explicit OMPCopyinClause(unsigned N)
2182       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
2183                                           SourceLocation(), SourceLocation(),
2184                                           N) {}
2185
2186   /// \brief Set list of helper expressions, required for proper codegen of the
2187   /// clause. These expressions represent source expression in the final
2188   /// assignment statement performed by the copyin clause.
2189   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2190
2191   /// \brief Get the list of helper source expressions.
2192   MutableArrayRef<Expr *> getSourceExprs() {
2193     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2194   }
2195   ArrayRef<const Expr *> getSourceExprs() const {
2196     return llvm::makeArrayRef(varlist_end(), varlist_size());
2197   }
2198
2199   /// \brief Set list of helper expressions, required for proper codegen of the
2200   /// clause. These expressions represent destination expression in the final
2201   /// assignment statement performed by the copyin clause.
2202   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2203
2204   /// \brief Get the list of helper destination expressions.
2205   MutableArrayRef<Expr *> getDestinationExprs() {
2206     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2207   }
2208   ArrayRef<const Expr *> getDestinationExprs() const {
2209     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2210   }
2211
2212   /// \brief Set list of helper assignment expressions, required for proper
2213   /// codegen of the clause. These expressions are assignment expressions that
2214   /// assign source helper expressions to destination helper expressions
2215   /// correspondingly.
2216   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2217
2218   /// \brief Get the list of helper assignment expressions.
2219   MutableArrayRef<Expr *> getAssignmentOps() {
2220     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2221   }
2222   ArrayRef<const Expr *> getAssignmentOps() const {
2223     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2224   }
2225
2226 public:
2227   /// \brief Creates clause with a list of variables \a VL.
2228   ///
2229   /// \param C AST context.
2230   /// \param StartLoc Starting location of the clause.
2231   /// \param LParenLoc Location of '('.
2232   /// \param EndLoc Ending location of the clause.
2233   /// \param VL List of references to the variables.
2234   /// \param SrcExprs List of helper expressions for proper generation of
2235   /// assignment operation required for copyin clause. This list represents
2236   /// sources.
2237   /// \param DstExprs List of helper expressions for proper generation of
2238   /// assignment operation required for copyin clause. This list represents
2239   /// destinations.
2240   /// \param AssignmentOps List of helper expressions that represents assignment
2241   /// operation:
2242   /// \code
2243   /// DstExprs = SrcExprs;
2244   /// \endcode
2245   /// Required for proper codegen of propagation of master's thread values of
2246   /// threadprivate variables to local instances of that variables in other
2247   /// implicit threads.
2248   ///
2249   static OMPCopyinClause *
2250   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2251          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2252          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2253   /// \brief Creates an empty clause with \a N variables.
2254   ///
2255   /// \param C AST context.
2256   /// \param N The number of variables.
2257   ///
2258   static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
2259
2260   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2261   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2262   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2263   typedef llvm::iterator_range<helper_expr_const_iterator>
2264       helper_expr_const_range;
2265
2266   helper_expr_const_range source_exprs() const {
2267     return helper_expr_const_range(getSourceExprs().begin(),
2268                                    getSourceExprs().end());
2269   }
2270   helper_expr_range source_exprs() {
2271     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2272   }
2273   helper_expr_const_range destination_exprs() const {
2274     return helper_expr_const_range(getDestinationExprs().begin(),
2275                                    getDestinationExprs().end());
2276   }
2277   helper_expr_range destination_exprs() {
2278     return helper_expr_range(getDestinationExprs().begin(),
2279                              getDestinationExprs().end());
2280   }
2281   helper_expr_const_range assignment_ops() const {
2282     return helper_expr_const_range(getAssignmentOps().begin(),
2283                                    getAssignmentOps().end());
2284   }
2285   helper_expr_range assignment_ops() {
2286     return helper_expr_range(getAssignmentOps().begin(),
2287                              getAssignmentOps().end());
2288   }
2289
2290   child_range children() {
2291     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2292                        reinterpret_cast<Stmt **>(varlist_end()));
2293   }
2294
2295   static bool classof(const OMPClause *T) {
2296     return T->getClauseKind() == OMPC_copyin;
2297   }
2298 };
2299
2300 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
2301 /// directives.
2302 ///
2303 /// \code
2304 /// #pragma omp single copyprivate(a,b)
2305 /// \endcode
2306 /// In this example directive '#pragma omp single' has clause 'copyprivate'
2307 /// with the variables 'a' and 'b'.
2308 ///
2309 class OMPCopyprivateClause final
2310     : public OMPVarListClause<OMPCopyprivateClause>,
2311       private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
2312   friend TrailingObjects;
2313   friend OMPVarListClause;
2314   friend class OMPClauseReader;
2315   /// \brief Build clause with number of variables \a N.
2316   ///
2317   /// \param StartLoc Starting location of the clause.
2318   /// \param LParenLoc Location of '('.
2319   /// \param EndLoc Ending location of the clause.
2320   /// \param N Number of the variables in the clause.
2321   ///
2322   OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2323                        SourceLocation EndLoc, unsigned N)
2324       : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
2325                                                LParenLoc, EndLoc, N) {}
2326
2327   /// \brief Build an empty clause.
2328   ///
2329   /// \param N Number of variables.
2330   ///
2331   explicit OMPCopyprivateClause(unsigned N)
2332       : OMPVarListClause<OMPCopyprivateClause>(
2333             OMPC_copyprivate, SourceLocation(), SourceLocation(),
2334             SourceLocation(), N) {}
2335
2336   /// \brief Set list of helper expressions, required for proper codegen of the
2337   /// clause. These expressions represent source expression in the final
2338   /// assignment statement performed by the copyprivate clause.
2339   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2340
2341   /// \brief Get the list of helper source expressions.
2342   MutableArrayRef<Expr *> getSourceExprs() {
2343     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2344   }
2345   ArrayRef<const Expr *> getSourceExprs() const {
2346     return llvm::makeArrayRef(varlist_end(), varlist_size());
2347   }
2348
2349   /// \brief Set list of helper expressions, required for proper codegen of the
2350   /// clause. These expressions represent destination expression in the final
2351   /// assignment statement performed by the copyprivate clause.
2352   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2353
2354   /// \brief Get the list of helper destination expressions.
2355   MutableArrayRef<Expr *> getDestinationExprs() {
2356     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2357   }
2358   ArrayRef<const Expr *> getDestinationExprs() const {
2359     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2360   }
2361
2362   /// \brief Set list of helper assignment expressions, required for proper
2363   /// codegen of the clause. These expressions are assignment expressions that
2364   /// assign source helper expressions to destination helper expressions
2365   /// correspondingly.
2366   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2367
2368   /// \brief Get the list of helper assignment expressions.
2369   MutableArrayRef<Expr *> getAssignmentOps() {
2370     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2371   }
2372   ArrayRef<const Expr *> getAssignmentOps() const {
2373     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2374   }
2375
2376 public:
2377   /// \brief Creates clause with a list of variables \a VL.
2378   ///
2379   /// \param C AST context.
2380   /// \param StartLoc Starting location of the clause.
2381   /// \param LParenLoc Location of '('.
2382   /// \param EndLoc Ending location of the clause.
2383   /// \param VL List of references to the variables.
2384   /// \param SrcExprs List of helper expressions for proper generation of
2385   /// assignment operation required for copyprivate clause. This list represents
2386   /// sources.
2387   /// \param DstExprs List of helper expressions for proper generation of
2388   /// assignment operation required for copyprivate clause. This list represents
2389   /// destinations.
2390   /// \param AssignmentOps List of helper expressions that represents assignment
2391   /// operation:
2392   /// \code
2393   /// DstExprs = SrcExprs;
2394   /// \endcode
2395   /// Required for proper codegen of final assignment performed by the
2396   /// copyprivate clause.
2397   ///
2398   static OMPCopyprivateClause *
2399   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2400          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2401          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2402   /// \brief Creates an empty clause with \a N variables.
2403   ///
2404   /// \param C AST context.
2405   /// \param N The number of variables.
2406   ///
2407   static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2408
2409   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2410   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2411   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2412   typedef llvm::iterator_range<helper_expr_const_iterator>
2413       helper_expr_const_range;
2414
2415   helper_expr_const_range source_exprs() const {
2416     return helper_expr_const_range(getSourceExprs().begin(),
2417                                    getSourceExprs().end());
2418   }
2419   helper_expr_range source_exprs() {
2420     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2421   }
2422   helper_expr_const_range destination_exprs() const {
2423     return helper_expr_const_range(getDestinationExprs().begin(),
2424                                    getDestinationExprs().end());
2425   }
2426   helper_expr_range destination_exprs() {
2427     return helper_expr_range(getDestinationExprs().begin(),
2428                              getDestinationExprs().end());
2429   }
2430   helper_expr_const_range assignment_ops() const {
2431     return helper_expr_const_range(getAssignmentOps().begin(),
2432                                    getAssignmentOps().end());
2433   }
2434   helper_expr_range assignment_ops() {
2435     return helper_expr_range(getAssignmentOps().begin(),
2436                              getAssignmentOps().end());
2437   }
2438
2439   child_range children() {
2440     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2441                        reinterpret_cast<Stmt **>(varlist_end()));
2442   }
2443
2444   static bool classof(const OMPClause *T) {
2445     return T->getClauseKind() == OMPC_copyprivate;
2446   }
2447 };
2448
2449 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
2450 /// directive.
2451 /// This clause does not exist by itself, it can be only as a part of 'omp
2452 /// flush' directive. This clause is introduced to keep the original structure
2453 /// of \a OMPExecutableDirective class and its derivatives and to use the
2454 /// existing infrastructure of clauses with the list of variables.
2455 ///
2456 /// \code
2457 /// #pragma omp flush(a,b)
2458 /// \endcode
2459 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
2460 /// with the variables 'a' and 'b'.
2461 ///
2462 class OMPFlushClause final
2463     : public OMPVarListClause<OMPFlushClause>,
2464       private llvm::TrailingObjects<OMPFlushClause, Expr *> {
2465   friend TrailingObjects;
2466   friend OMPVarListClause;
2467   /// \brief Build clause with number of variables \a N.
2468   ///
2469   /// \param StartLoc Starting location of the clause.
2470   /// \param LParenLoc Location of '('.
2471   /// \param EndLoc Ending location of the clause.
2472   /// \param N Number of the variables in the clause.
2473   ///
2474   OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2475                  SourceLocation EndLoc, unsigned N)
2476       : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
2477                                          EndLoc, N) {}
2478
2479   /// \brief Build an empty clause.
2480   ///
2481   /// \param N Number of variables.
2482   ///
2483   explicit OMPFlushClause(unsigned N)
2484       : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
2485                                          SourceLocation(), SourceLocation(),
2486                                          N) {}
2487
2488 public:
2489   /// \brief Creates clause with a list of variables \a VL.
2490   ///
2491   /// \param C AST context.
2492   /// \param StartLoc Starting location of the clause.
2493   /// \param LParenLoc Location of '('.
2494   /// \param EndLoc Ending location of the clause.
2495   /// \param VL List of references to the variables.
2496   ///
2497   static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
2498                                 SourceLocation LParenLoc, SourceLocation EndLoc,
2499                                 ArrayRef<Expr *> VL);
2500   /// \brief Creates an empty clause with \a N variables.
2501   ///
2502   /// \param C AST context.
2503   /// \param N The number of variables.
2504   ///
2505   static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
2506
2507   child_range children() {
2508     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2509                        reinterpret_cast<Stmt **>(varlist_end()));
2510   }
2511
2512   static bool classof(const OMPClause *T) {
2513     return T->getClauseKind() == OMPC_flush;
2514   }
2515 };
2516
2517 /// \brief This represents implicit clause 'depend' for the '#pragma omp task'
2518 /// directive.
2519 ///
2520 /// \code
2521 /// #pragma omp task depend(in:a,b)
2522 /// \endcode
2523 /// In this example directive '#pragma omp task' with clause 'depend' with the
2524 /// variables 'a' and 'b' with dependency 'in'.
2525 ///
2526 class OMPDependClause final
2527     : public OMPVarListClause<OMPDependClause>,
2528       private llvm::TrailingObjects<OMPDependClause, Expr *> {
2529   friend TrailingObjects;
2530   friend OMPVarListClause;
2531   friend class OMPClauseReader;
2532   /// \brief Dependency type (one of in, out, inout).
2533   OpenMPDependClauseKind DepKind;
2534   /// \brief Dependency type location.
2535   SourceLocation DepLoc;
2536   /// \brief Colon location.
2537   SourceLocation ColonLoc;
2538   /// \brief Build clause with number of variables \a N.
2539   ///
2540   /// \param StartLoc Starting location of the clause.
2541   /// \param LParenLoc Location of '('.
2542   /// \param EndLoc Ending location of the clause.
2543   /// \param N Number of the variables in the clause.
2544   ///
2545   OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2546                   SourceLocation EndLoc, unsigned N)
2547       : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
2548                                           EndLoc, N),
2549         DepKind(OMPC_DEPEND_unknown) {}
2550
2551   /// \brief Build an empty clause.
2552   ///
2553   /// \param N Number of variables.
2554   ///
2555   explicit OMPDependClause(unsigned N)
2556       : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
2557                                           SourceLocation(), SourceLocation(),
2558                                           N),
2559         DepKind(OMPC_DEPEND_unknown) {}
2560   /// \brief Set dependency kind.
2561   void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
2562
2563   /// \brief Set dependency kind and its location.
2564   void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
2565
2566   /// \brief Set colon location.
2567   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2568
2569 public:
2570   /// \brief Creates clause with a list of variables \a VL.
2571   ///
2572   /// \param C AST context.
2573   /// \param StartLoc Starting location of the clause.
2574   /// \param LParenLoc Location of '('.
2575   /// \param EndLoc Ending location of the clause.
2576   /// \param DepKind Dependency type.
2577   /// \param DepLoc Location of the dependency type.
2578   /// \param ColonLoc Colon location.
2579   /// \param VL List of references to the variables.
2580   ///
2581   static OMPDependClause *
2582   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2583          SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
2584          SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL);
2585   /// \brief Creates an empty clause with \a N variables.
2586   ///
2587   /// \param C AST context.
2588   /// \param N The number of variables.
2589   ///
2590   static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N);
2591
2592   /// \brief Get dependency type.
2593   OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
2594   /// \brief Get dependency type location.
2595   SourceLocation getDependencyLoc() const { return DepLoc; }
2596   /// \brief Get colon location.
2597   SourceLocation getColonLoc() const { return ColonLoc; }
2598
2599   child_range children() {
2600     return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2601                        reinterpret_cast<Stmt **>(varlist_end()));
2602   }
2603
2604   static bool classof(const OMPClause *T) {
2605     return T->getClauseKind() == OMPC_depend;
2606   }
2607 };
2608
2609 /// \brief This represents 'device' clause in the '#pragma omp ...'
2610 /// directive.
2611 ///
2612 /// \code
2613 /// #pragma omp target device(a)
2614 /// \endcode
2615 /// In this example directive '#pragma omp target' has clause 'device'
2616 /// with single expression 'a'.
2617 ///
2618 class OMPDeviceClause : public OMPClause {
2619   friend class OMPClauseReader;
2620   /// \brief Location of '('.
2621   SourceLocation LParenLoc;
2622   /// \brief Device number.
2623   Stmt *Device;
2624   /// \brief Set the device number.
2625   ///
2626   /// \param E Device number.
2627   ///
2628   void setDevice(Expr *E) { Device = E; }
2629
2630 public:
2631   /// \brief Build 'device' clause.
2632   ///
2633   /// \param E Expression associated with this clause.
2634   /// \param StartLoc Starting location of the clause.
2635   /// \param LParenLoc Location of '('.
2636   /// \param EndLoc Ending location of the clause.
2637   ///
2638   OMPDeviceClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc, 
2639                   SourceLocation EndLoc)
2640       : OMPClause(OMPC_device, StartLoc, EndLoc), LParenLoc(LParenLoc), 
2641         Device(E) {}
2642
2643   /// \brief Build an empty clause.
2644   ///
2645   OMPDeviceClause()
2646       : OMPClause(OMPC_device, SourceLocation(), SourceLocation()), 
2647         LParenLoc(SourceLocation()), Device(nullptr) {}
2648   /// \brief Sets the location of '('.
2649   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2650   /// \brief Returns the location of '('.
2651   SourceLocation getLParenLoc() const { return LParenLoc; }
2652   /// \brief Return device number.
2653   Expr *getDevice() { return cast<Expr>(Device); }
2654   /// \brief Return device number.
2655   Expr *getDevice() const { return cast<Expr>(Device); }
2656
2657   static bool classof(const OMPClause *T) {
2658     return T->getClauseKind() == OMPC_device;
2659   }
2660
2661   child_range children() { return child_range(&Device, &Device + 1); }
2662 };
2663
2664 /// \brief This represents 'threads' clause in the '#pragma omp ...' directive.
2665 ///
2666 /// \code
2667 /// #pragma omp ordered threads
2668 /// \endcode
2669 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
2670 ///
2671 class OMPThreadsClause : public OMPClause {
2672 public:
2673   /// \brief Build 'threads' clause.
2674   ///
2675   /// \param StartLoc Starting location of the clause.
2676   /// \param EndLoc Ending location of the clause.
2677   ///
2678   OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
2679       : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
2680
2681   /// \brief Build an empty clause.
2682   ///
2683   OMPThreadsClause()
2684       : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
2685
2686   static bool classof(const OMPClause *T) {
2687     return T->getClauseKind() == OMPC_threads;
2688   }
2689
2690   child_range children() {
2691     return child_range(child_iterator(), child_iterator());
2692   }
2693 };
2694
2695 /// \brief This represents 'simd' clause in the '#pragma omp ...' directive.
2696 ///
2697 /// \code
2698 /// #pragma omp ordered simd
2699 /// \endcode
2700 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
2701 ///
2702 class OMPSIMDClause : public OMPClause {
2703 public:
2704   /// \brief Build 'simd' clause.
2705   ///
2706   /// \param StartLoc Starting location of the clause.
2707   /// \param EndLoc Ending location of the clause.
2708   ///
2709   OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
2710       : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
2711
2712   /// \brief Build an empty clause.
2713   ///
2714   OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
2715
2716   static bool classof(const OMPClause *T) {
2717     return T->getClauseKind() == OMPC_simd;
2718   }
2719
2720   child_range children() {
2721     return child_range(child_iterator(), child_iterator());
2722   }
2723 };
2724
2725 /// \brief This represents clause 'map' in the '#pragma omp ...'
2726 /// directives.
2727 ///
2728 /// \code
2729 /// #pragma omp target map(a,b)
2730 /// \endcode
2731 /// In this example directive '#pragma omp target' has clause 'map'
2732 /// with the variables 'a' and 'b'.
2733 ///
2734 class OMPMapClause final : public OMPVarListClause<OMPMapClause>,
2735                            private llvm::TrailingObjects<OMPMapClause, Expr *> {
2736   friend TrailingObjects;
2737   friend OMPVarListClause;
2738   friend class OMPClauseReader;
2739
2740   /// \brief Map type modifier for the 'map' clause.
2741   OpenMPMapClauseKind MapTypeModifier;
2742   /// \brief Map type for the 'map' clause.
2743   OpenMPMapClauseKind MapType;
2744   /// \brief Location of the map type.
2745   SourceLocation MapLoc;
2746   /// \brief Colon location.
2747   SourceLocation ColonLoc;
2748
2749   /// \brief Set type modifier for the clause.
2750   ///
2751   /// \param T Type Modifier for the clause.
2752   ///
2753   void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; }
2754
2755   /// \brief Set type for the clause.
2756   ///
2757   /// \param T Type for the clause.
2758   ///
2759   void setMapType(OpenMPMapClauseKind T) { MapType = T; }
2760
2761   /// \brief Set type location.
2762   ///
2763   /// \param TLoc Type location.
2764   ///
2765   void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
2766
2767   /// \brief Set colon location.
2768   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2769
2770   /// \brief Build clause with number of variables \a N.
2771   ///
2772   /// \param MapTypeModifier Map type modifier.
2773   /// \param MapType Map type.
2774   /// \param MapLoc Location of the map type.
2775   /// \param StartLoc Starting location of the clause.
2776   /// \param EndLoc Ending location of the clause.
2777   /// \param N Number of the variables in the clause.
2778   ///
2779   explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier,
2780                         OpenMPMapClauseKind MapType, SourceLocation MapLoc,
2781                         SourceLocation StartLoc, SourceLocation LParenLoc,
2782                         SourceLocation EndLoc, unsigned N)
2783     : OMPVarListClause<OMPMapClause>(OMPC_map, StartLoc, LParenLoc, EndLoc, N),
2784       MapTypeModifier(MapTypeModifier), MapType(MapType), MapLoc(MapLoc) {}
2785
2786   /// \brief Build an empty clause.
2787   ///
2788   /// \param N Number of variables.
2789   ///
2790   explicit OMPMapClause(unsigned N)
2791       : OMPVarListClause<OMPMapClause>(OMPC_map, SourceLocation(),
2792                                        SourceLocation(), SourceLocation(), N),
2793         MapTypeModifier(OMPC_MAP_unknown), MapType(OMPC_MAP_unknown), MapLoc() {}
2794
2795 public:
2796   /// \brief Creates clause with a list of variables \a VL.
2797   ///
2798   /// \param C AST context.
2799   /// \param StartLoc Starting location of the clause.
2800   /// \param EndLoc Ending location of the clause.
2801   /// \param VL List of references to the variables.
2802   /// \param TypeModifier Map type modifier.
2803   /// \param Type Map type.
2804   /// \param TypeLoc Location of the map type.
2805   ///
2806   static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc,
2807                               SourceLocation LParenLoc,
2808                               SourceLocation EndLoc, ArrayRef<Expr *> VL,
2809                               OpenMPMapClauseKind TypeModifier,
2810                               OpenMPMapClauseKind Type, SourceLocation TypeLoc);
2811   /// \brief Creates an empty clause with the place for \a N variables.
2812   ///
2813   /// \param C AST context.
2814   /// \param N The number of variables.
2815   ///
2816   static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned N);
2817
2818   /// \brief Fetches mapping kind for the clause.
2819   OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
2820
2821   /// \brief Fetches the map type modifier for the clause.
2822   OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY {
2823     return MapTypeModifier;
2824   }
2825
2826   /// \brief Fetches location of clause mapping kind.
2827   SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
2828
2829   /// \brief Get colon location.
2830   SourceLocation getColonLoc() const { return ColonLoc; }
2831
2832   static bool classof(const OMPClause *T) {
2833     return T->getClauseKind() == OMPC_map;
2834   }
2835
2836   child_range children() {
2837     return child_range(
2838         reinterpret_cast<Stmt **>(varlist_begin()),
2839         reinterpret_cast<Stmt **>(varlist_end()));
2840   }
2841 };
2842
2843 /// \brief This represents 'num_teams' clause in the '#pragma omp ...'
2844 /// directive.
2845 ///
2846 /// \code
2847 /// #pragma omp teams num_teams(n)
2848 /// \endcode
2849 /// In this example directive '#pragma omp teams' has clause 'num_teams'
2850 /// with single expression 'n'.
2851 ///
2852 class OMPNumTeamsClause : public OMPClause {
2853   friend class OMPClauseReader;
2854   /// \brief Location of '('.
2855   SourceLocation LParenLoc;
2856   /// \brief NumTeams number.
2857   Stmt *NumTeams;
2858   /// \brief Set the NumTeams number.
2859   ///
2860   /// \param E NumTeams number.
2861   ///
2862   void setNumTeams(Expr *E) { NumTeams = E; }
2863
2864 public:
2865   /// \brief Build 'num_teams' clause.
2866   ///
2867   /// \param E Expression associated with this clause.
2868   /// \param StartLoc Starting location of the clause.
2869   /// \param LParenLoc Location of '('.
2870   /// \param EndLoc Ending location of the clause.
2871   ///
2872   OMPNumTeamsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2873                     SourceLocation EndLoc)
2874       : OMPClause(OMPC_num_teams, StartLoc, EndLoc), LParenLoc(LParenLoc), 
2875         NumTeams(E) {}
2876
2877   /// \brief Build an empty clause.
2878   ///
2879   OMPNumTeamsClause()
2880       : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()), 
2881         LParenLoc(SourceLocation()), NumTeams(nullptr) {}
2882   /// \brief Sets the location of '('.
2883   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2884   /// \brief Returns the location of '('.
2885   SourceLocation getLParenLoc() const { return LParenLoc; }
2886   /// \brief Return NumTeams number.
2887   Expr *getNumTeams() { return cast<Expr>(NumTeams); }
2888   /// \brief Return NumTeams number.
2889   Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
2890
2891   static bool classof(const OMPClause *T) {
2892     return T->getClauseKind() == OMPC_num_teams;
2893   }
2894
2895   child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
2896 };
2897
2898 /// \brief This represents 'thread_limit' clause in the '#pragma omp ...'
2899 /// directive.
2900 ///
2901 /// \code
2902 /// #pragma omp teams thread_limit(n)
2903 /// \endcode
2904 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
2905 /// with single expression 'n'.
2906 ///
2907 class OMPThreadLimitClause : public OMPClause {
2908   friend class OMPClauseReader;
2909   /// \brief Location of '('.
2910   SourceLocation LParenLoc;
2911   /// \brief ThreadLimit number.
2912   Stmt *ThreadLimit;
2913   /// \brief Set the ThreadLimit number.
2914   ///
2915   /// \param E ThreadLimit number.
2916   ///
2917   void setThreadLimit(Expr *E) { ThreadLimit = E; }
2918
2919 public:
2920   /// \brief Build 'thread_limit' clause.
2921   ///
2922   /// \param E Expression associated with this clause.
2923   /// \param StartLoc Starting location of the clause.
2924   /// \param LParenLoc Location of '('.
2925   /// \param EndLoc Ending location of the clause.
2926   ///
2927   OMPThreadLimitClause(Expr *E, SourceLocation StartLoc,
2928                        SourceLocation LParenLoc, SourceLocation EndLoc)
2929       : OMPClause(OMPC_thread_limit, StartLoc, EndLoc), LParenLoc(LParenLoc),
2930         ThreadLimit(E) {}
2931
2932   /// \brief Build an empty clause.
2933   ///
2934   OMPThreadLimitClause()
2935       : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
2936         LParenLoc(SourceLocation()), ThreadLimit(nullptr) {}
2937   /// \brief Sets the location of '('.
2938   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2939   /// \brief Returns the location of '('.
2940   SourceLocation getLParenLoc() const { return LParenLoc; }
2941   /// \brief Return ThreadLimit number.
2942   Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
2943   /// \brief Return ThreadLimit number.
2944   Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
2945
2946   static bool classof(const OMPClause *T) {
2947     return T->getClauseKind() == OMPC_thread_limit;
2948   }
2949
2950   child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
2951 };
2952
2953 /// \brief This represents 'priority' clause in the '#pragma omp ...'
2954 /// directive.
2955 ///
2956 /// \code
2957 /// #pragma omp task priority(n)
2958 /// \endcode
2959 /// In this example directive '#pragma omp teams' has clause 'priority' with
2960 /// single expression 'n'.
2961 ///
2962 class OMPPriorityClause : public OMPClause {
2963   friend class OMPClauseReader;
2964   /// \brief Location of '('.
2965   SourceLocation LParenLoc;
2966   /// \brief Priority number.
2967   Stmt *Priority;
2968   /// \brief Set the Priority number.
2969   ///
2970   /// \param E Priority number.
2971   ///
2972   void setPriority(Expr *E) { Priority = E; }
2973
2974 public:
2975   /// \brief Build 'priority' clause.
2976   ///
2977   /// \param E Expression associated with this clause.
2978   /// \param StartLoc Starting location of the clause.
2979   /// \param LParenLoc Location of '('.
2980   /// \param EndLoc Ending location of the clause.
2981   ///
2982   OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2983                     SourceLocation EndLoc)
2984       : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
2985         Priority(E) {}
2986
2987   /// \brief Build an empty clause.
2988   ///
2989   OMPPriorityClause()
2990       : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()),
2991         LParenLoc(SourceLocation()), Priority(nullptr) {}
2992   /// \brief Sets the location of '('.
2993   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2994   /// \brief Returns the location of '('.
2995   SourceLocation getLParenLoc() const { return LParenLoc; }
2996   /// \brief Return Priority number.
2997   Expr *getPriority() { return cast<Expr>(Priority); }
2998   /// \brief Return Priority number.
2999   Expr *getPriority() const { return cast<Expr>(Priority); }
3000
3001   static bool classof(const OMPClause *T) {
3002     return T->getClauseKind() == OMPC_priority;
3003   }
3004
3005   child_range children() { return child_range(&Priority, &Priority + 1); }
3006 };
3007
3008 /// \brief This represents 'grainsize' clause in the '#pragma omp ...'
3009 /// directive.
3010 ///
3011 /// \code
3012 /// #pragma omp taskloop grainsize(4)
3013 /// \endcode
3014 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
3015 /// with single expression '4'.
3016 ///
3017 class OMPGrainsizeClause : public OMPClause {
3018   friend class OMPClauseReader;
3019   /// \brief Location of '('.
3020   SourceLocation LParenLoc;
3021   /// \brief Safe iteration space distance.
3022   Stmt *Grainsize;
3023
3024   /// \brief Set safelen.
3025   void setGrainsize(Expr *Size) { Grainsize = Size; }
3026
3027 public:
3028   /// \brief Build 'grainsize' clause.
3029   ///
3030   /// \param Size Expression associated with this clause.
3031   /// \param StartLoc Starting location of the clause.
3032   /// \param EndLoc Ending location of the clause.
3033   ///
3034   OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
3035                      SourceLocation LParenLoc, SourceLocation EndLoc)
3036       : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
3037         Grainsize(Size) {}
3038
3039   /// \brief Build an empty clause.
3040   ///
3041   explicit OMPGrainsizeClause()
3042       : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()),
3043         LParenLoc(SourceLocation()), Grainsize(nullptr) {}
3044
3045   /// \brief Sets the location of '('.
3046   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3047   /// \brief Returns the location of '('.
3048   SourceLocation getLParenLoc() const { return LParenLoc; }
3049
3050   /// \brief Return safe iteration space distance.
3051   Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
3052
3053   static bool classof(const OMPClause *T) {
3054     return T->getClauseKind() == OMPC_grainsize;
3055   }
3056
3057   child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
3058 };
3059
3060 /// \brief This represents 'nogroup' clause in the '#pragma omp ...' directive.
3061 ///
3062 /// \code
3063 /// #pragma omp taskloop nogroup
3064 /// \endcode
3065 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
3066 ///
3067 class OMPNogroupClause : public OMPClause {
3068 public:
3069   /// \brief Build 'nogroup' clause.
3070   ///
3071   /// \param StartLoc Starting location of the clause.
3072   /// \param EndLoc Ending location of the clause.
3073   ///
3074   OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
3075       : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
3076
3077   /// \brief Build an empty clause.
3078   ///
3079   OMPNogroupClause()
3080       : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
3081
3082   static bool classof(const OMPClause *T) {
3083     return T->getClauseKind() == OMPC_nogroup;
3084   }
3085
3086   child_range children() {
3087     return child_range(child_iterator(), child_iterator());
3088   }
3089 };
3090
3091 /// \brief This represents 'num_tasks' clause in the '#pragma omp ...'
3092 /// directive.
3093 ///
3094 /// \code
3095 /// #pragma omp taskloop num_tasks(4)
3096 /// \endcode
3097 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
3098 /// with single expression '4'.
3099 ///
3100 class OMPNumTasksClause : public OMPClause {
3101   friend class OMPClauseReader;
3102   /// \brief Location of '('.
3103   SourceLocation LParenLoc;
3104   /// \brief Safe iteration space distance.
3105   Stmt *NumTasks;
3106
3107   /// \brief Set safelen.
3108   void setNumTasks(Expr *Size) { NumTasks = Size; }
3109
3110 public:
3111   /// \brief Build 'num_tasks' clause.
3112   ///
3113   /// \param Size Expression associated with this clause.
3114   /// \param StartLoc Starting location of the clause.
3115   /// \param EndLoc Ending location of the clause.
3116   ///
3117   OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
3118                     SourceLocation LParenLoc, SourceLocation EndLoc)
3119       : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
3120         NumTasks(Size) {}
3121
3122   /// \brief Build an empty clause.
3123   ///
3124   explicit OMPNumTasksClause()
3125       : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()),
3126         LParenLoc(SourceLocation()), NumTasks(nullptr) {}
3127
3128   /// \brief Sets the location of '('.
3129   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3130   /// \brief Returns the location of '('.
3131   SourceLocation getLParenLoc() const { return LParenLoc; }
3132
3133   /// \brief Return safe iteration space distance.
3134   Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
3135
3136   static bool classof(const OMPClause *T) {
3137     return T->getClauseKind() == OMPC_num_tasks;
3138   }
3139
3140   child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
3141 };
3142
3143 /// \brief This represents 'hint' clause in the '#pragma omp ...' directive.
3144 ///
3145 /// \code
3146 /// #pragma omp critical (name) hint(6)
3147 /// \endcode
3148 /// In this example directive '#pragma omp critical' has name 'name' and clause
3149 /// 'hint' with argument '6'.
3150 ///
3151 class OMPHintClause : public OMPClause {
3152   friend class OMPClauseReader;
3153   /// \brief Location of '('.
3154   SourceLocation LParenLoc;
3155   /// \brief Hint expression of the 'hint' clause.
3156   Stmt *Hint;
3157
3158   /// \brief Set hint expression.
3159   ///
3160   void setHint(Expr *H) { Hint = H; }
3161
3162 public:
3163   /// \brief Build 'hint' clause with expression \a Hint.
3164   ///
3165   /// \param Hint Hint expression.
3166   /// \param StartLoc Starting location of the clause.
3167   /// \param LParenLoc Location of '('.
3168   /// \param EndLoc Ending location of the clause.
3169   ///
3170   OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
3171                 SourceLocation EndLoc)
3172       : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
3173         Hint(Hint) {}
3174
3175   /// \brief Build an empty clause.
3176   ///
3177   OMPHintClause()
3178       : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()),
3179         LParenLoc(SourceLocation()), Hint(nullptr) {}
3180
3181   /// \brief Sets the location of '('.
3182   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3183   /// \brief Returns the location of '('.
3184   SourceLocation getLParenLoc() const { return LParenLoc; }
3185
3186   /// \brief Returns number of threads.
3187   Expr *getHint() const { return cast_or_null<Expr>(Hint); }
3188
3189   static bool classof(const OMPClause *T) {
3190     return T->getClauseKind() == OMPC_hint;
3191   }
3192
3193   child_range children() { return child_range(&Hint, &Hint + 1); }
3194 };
3195
3196 } // end namespace clang
3197
3198 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H