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