1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// \brief This file defines OpenMP AST classes for clauses.
11 /// There are clauses for executable directives, clauses for declarative
12 /// directives and clauses which can be used in both kinds of directives.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
18 
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/Stmt.h"
21 #include "clang/Basic/OpenMPKinds.h"
22 #include "clang/Basic/SourceLocation.h"
23 
24 namespace clang {
25 
26 //===----------------------------------------------------------------------===//
27 // AST classes for clauses.
28 //===----------------------------------------------------------------------===//
29 
30 /// \brief This is a basic class for representing single OpenMP clause.
31 ///
32 class OMPClause {
33   /// \brief Starting location of the clause (the clause keyword).
34   SourceLocation StartLoc;
35   /// \brief Ending location of the clause.
36   SourceLocation EndLoc;
37   /// \brief Kind of the clause.
38   OpenMPClauseKind Kind;
39 
40 protected:
OMPClause(OpenMPClauseKind K,SourceLocation StartLoc,SourceLocation EndLoc)41   OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
42       : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
43 
44 public:
45   /// \brief Returns the starting location of the clause.
getLocStart()46   SourceLocation getLocStart() const { return StartLoc; }
47   /// \brief Returns the ending location of the clause.
getLocEnd()48   SourceLocation getLocEnd() const { return EndLoc; }
49 
50   /// \brief Sets the starting location of the clause.
setLocStart(SourceLocation Loc)51   void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
52   /// \brief Sets the ending location of the clause.
setLocEnd(SourceLocation Loc)53   void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
54 
55   /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
getClauseKind()56   OpenMPClauseKind getClauseKind() const { return Kind; }
57 
isImplicit()58   bool isImplicit() const { return StartLoc.isInvalid(); }
59 
60   StmtRange children();
children()61   ConstStmtRange children() const {
62     return const_cast<OMPClause *>(this)->children();
63   }
classof(const OMPClause *)64   static bool classof(const OMPClause *) { return true; }
65 };
66 
67 /// \brief This represents clauses with the list of variables like 'private',
68 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
69 /// '#pragma omp ...' directives.
70 template <class T> class OMPVarListClause : public OMPClause {
71   friend class OMPClauseReader;
72   /// \brief Location of '('.
73   SourceLocation LParenLoc;
74   /// \brief Number of variables in the list.
75   unsigned NumVars;
76 
77 protected:
78   /// \brief Fetches list of variables associated with this clause.
getVarRefs()79   MutableArrayRef<Expr *> getVarRefs() {
80     return MutableArrayRef<Expr *>(
81         reinterpret_cast<Expr **>(
82             reinterpret_cast<char *>(this) +
83             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
84         NumVars);
85   }
86 
87   /// \brief Sets the list of variables for this clause.
setVarRefs(ArrayRef<Expr * > VL)88   void setVarRefs(ArrayRef<Expr *> VL) {
89     assert(VL.size() == NumVars &&
90            "Number of variables is not the same as the preallocated buffer");
91     std::copy(
92         VL.begin(), VL.end(),
93         reinterpret_cast<Expr **>(
94             reinterpret_cast<char *>(this) +
95             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())));
96   }
97 
98   /// \brief Build a clause with \a N variables
99   ///
100   /// \param K Kind of the clause.
101   /// \param StartLoc Starting location of the clause (the clause keyword).
102   /// \param LParenLoc Location of '('.
103   /// \param EndLoc Ending location of the clause.
104   /// \param N Number of the variables in the clause.
105   ///
OMPVarListClause(OpenMPClauseKind K,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)106   OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
107                    SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
108       : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
109 
110 public:
111   typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
112   typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
113   typedef llvm::iterator_range<varlist_iterator> varlist_range;
114   typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
115 
varlist_size()116   unsigned varlist_size() const { return NumVars; }
varlist_empty()117   bool varlist_empty() const { return NumVars == 0; }
118 
varlists()119   varlist_range varlists() {
120     return varlist_range(varlist_begin(), varlist_end());
121   }
varlists()122   varlist_const_range varlists() const {
123     return varlist_const_range(varlist_begin(), varlist_end());
124   }
125 
varlist_begin()126   varlist_iterator varlist_begin() { return getVarRefs().begin(); }
varlist_end()127   varlist_iterator varlist_end() { return getVarRefs().end(); }
varlist_begin()128   varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
varlist_end()129   varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
130 
131   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)132   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
133   /// \brief Returns the location of '('.
getLParenLoc()134   SourceLocation getLParenLoc() const { return LParenLoc; }
135 
136   /// \brief Fetches list of all variables in the clause.
getVarRefs()137   ArrayRef<const Expr *> getVarRefs() const {
138     return llvm::makeArrayRef(
139         reinterpret_cast<const Expr *const *>(
140             reinterpret_cast<const char *>(this) +
141             llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<const Expr *>())),
142         NumVars);
143   }
144 };
145 
146 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
147 ///
148 /// \code
149 /// #pragma omp parallel if(a > 5)
150 /// \endcode
151 /// In this example directive '#pragma omp parallel' has simple 'if'
152 /// clause with condition 'a > 5'.
153 ///
154 class OMPIfClause : public OMPClause {
155   friend class OMPClauseReader;
156   /// \brief Location of '('.
157   SourceLocation LParenLoc;
158   /// \brief Condition of the 'if' clause.
159   Stmt *Condition;
160 
161   /// \brief Set condition.
162   ///
setCondition(Expr * Cond)163   void setCondition(Expr *Cond) { Condition = Cond; }
164 
165 public:
166   /// \brief Build 'if' clause with condition \a Cond.
167   ///
168   /// \param StartLoc Starting location of the clause.
169   /// \param LParenLoc Location of '('.
170   /// \param Cond Condition of the clause.
171   /// \param EndLoc Ending location of the clause.
172   ///
OMPIfClause(Expr * Cond,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)173   OMPIfClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
174               SourceLocation EndLoc)
175       : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
176         Condition(Cond) {}
177 
178   /// \brief Build an empty clause.
179   ///
OMPIfClause()180   OMPIfClause()
181       : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
182         LParenLoc(SourceLocation()), Condition(nullptr) {}
183 
184   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)185   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
186   /// \brief Returns the location of '('.
getLParenLoc()187   SourceLocation getLParenLoc() const { return LParenLoc; }
188 
189   /// \brief Returns condition.
getCondition()190   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
191 
classof(const OMPClause * T)192   static bool classof(const OMPClause *T) {
193     return T->getClauseKind() == OMPC_if;
194   }
195 
children()196   StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
197 };
198 
199 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
200 ///
201 /// \code
202 /// #pragma omp task final(a > 5)
203 /// \endcode
204 /// In this example directive '#pragma omp task' has simple 'final'
205 /// clause with condition 'a > 5'.
206 ///
207 class OMPFinalClause : public OMPClause {
208   friend class OMPClauseReader;
209   /// \brief Location of '('.
210   SourceLocation LParenLoc;
211   /// \brief Condition of the 'if' clause.
212   Stmt *Condition;
213 
214   /// \brief Set condition.
215   ///
setCondition(Expr * Cond)216   void setCondition(Expr *Cond) { Condition = Cond; }
217 
218 public:
219   /// \brief Build 'final' clause with condition \a Cond.
220   ///
221   /// \param StartLoc Starting location of the clause.
222   /// \param LParenLoc Location of '('.
223   /// \param Cond Condition of the clause.
224   /// \param EndLoc Ending location of the clause.
225   ///
OMPFinalClause(Expr * Cond,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)226   OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
227                  SourceLocation EndLoc)
228       : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
229         Condition(Cond) {}
230 
231   /// \brief Build an empty clause.
232   ///
OMPFinalClause()233   OMPFinalClause()
234       : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
235         LParenLoc(SourceLocation()), Condition(nullptr) {}
236 
237   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)238   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
239   /// \brief Returns the location of '('.
getLParenLoc()240   SourceLocation getLParenLoc() const { return LParenLoc; }
241 
242   /// \brief Returns condition.
getCondition()243   Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
244 
classof(const OMPClause * T)245   static bool classof(const OMPClause *T) {
246     return T->getClauseKind() == OMPC_final;
247   }
248 
children()249   StmtRange children() { return StmtRange(&Condition, &Condition + 1); }
250 };
251 
252 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
253 /// directive.
254 ///
255 /// \code
256 /// #pragma omp parallel num_threads(6)
257 /// \endcode
258 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
259 /// clause with number of threads '6'.
260 ///
261 class OMPNumThreadsClause : public OMPClause {
262   friend class OMPClauseReader;
263   /// \brief Location of '('.
264   SourceLocation LParenLoc;
265   /// \brief Condition of the 'num_threads' clause.
266   Stmt *NumThreads;
267 
268   /// \brief Set condition.
269   ///
setNumThreads(Expr * NThreads)270   void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
271 
272 public:
273   /// \brief Build 'num_threads' clause with condition \a NumThreads.
274   ///
275   /// \param NumThreads Number of threads for the construct.
276   /// \param StartLoc Starting location of the clause.
277   /// \param LParenLoc Location of '('.
278   /// \param EndLoc Ending location of the clause.
279   ///
OMPNumThreadsClause(Expr * NumThreads,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)280   OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
281                       SourceLocation LParenLoc, SourceLocation EndLoc)
282       : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
283         NumThreads(NumThreads) {}
284 
285   /// \brief Build an empty clause.
286   ///
OMPNumThreadsClause()287   OMPNumThreadsClause()
288       : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
289         LParenLoc(SourceLocation()), NumThreads(nullptr) {}
290 
291   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)292   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
293   /// \brief Returns the location of '('.
getLParenLoc()294   SourceLocation getLParenLoc() const { return LParenLoc; }
295 
296   /// \brief Returns number of threads.
getNumThreads()297   Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
298 
classof(const OMPClause * T)299   static bool classof(const OMPClause *T) {
300     return T->getClauseKind() == OMPC_num_threads;
301   }
302 
children()303   StmtRange children() { return StmtRange(&NumThreads, &NumThreads + 1); }
304 };
305 
306 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
307 /// directive.
308 ///
309 /// \code
310 /// #pragma omp simd safelen(4)
311 /// \endcode
312 /// In this example directive '#pragma omp simd' has clause 'safelen'
313 /// with single expression '4'.
314 /// If the safelen clause is used then no two iterations executed
315 /// concurrently with SIMD instructions can have a greater distance
316 /// in the logical iteration space than its value. The parameter of
317 /// the safelen clause must be a constant positive integer expression.
318 ///
319 class OMPSafelenClause : public OMPClause {
320   friend class OMPClauseReader;
321   /// \brief Location of '('.
322   SourceLocation LParenLoc;
323   /// \brief Safe iteration space distance.
324   Stmt *Safelen;
325 
326   /// \brief Set safelen.
setSafelen(Expr * Len)327   void setSafelen(Expr *Len) { Safelen = Len; }
328 
329 public:
330   /// \brief Build 'safelen' clause.
331   ///
332   /// \param Len Expression associated with this clause.
333   /// \param StartLoc Starting location of the clause.
334   /// \param EndLoc Ending location of the clause.
335   ///
OMPSafelenClause(Expr * Len,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)336   OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
337                    SourceLocation EndLoc)
338       : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
339         Safelen(Len) {}
340 
341   /// \brief Build an empty clause.
342   ///
OMPSafelenClause()343   explicit OMPSafelenClause()
344       : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
345         LParenLoc(SourceLocation()), Safelen(nullptr) {}
346 
347   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)348   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
349   /// \brief Returns the location of '('.
getLParenLoc()350   SourceLocation getLParenLoc() const { return LParenLoc; }
351 
352   /// \brief Return safe iteration space distance.
getSafelen()353   Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
354 
classof(const OMPClause * T)355   static bool classof(const OMPClause *T) {
356     return T->getClauseKind() == OMPC_safelen;
357   }
358 
children()359   StmtRange children() { return StmtRange(&Safelen, &Safelen + 1); }
360 };
361 
362 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
363 /// directive.
364 ///
365 /// \code
366 /// #pragma omp simd collapse(3)
367 /// \endcode
368 /// In this example directive '#pragma omp simd' has clause 'collapse'
369 /// with single expression '3'.
370 /// The parameter must be a constant positive integer expression, it specifies
371 /// the number of nested loops that should be collapsed into a single iteration
372 /// space.
373 ///
374 class OMPCollapseClause : public OMPClause {
375   friend class OMPClauseReader;
376   /// \brief Location of '('.
377   SourceLocation LParenLoc;
378   /// \brief Number of for-loops.
379   Stmt *NumForLoops;
380 
381   /// \brief Set the number of associated for-loops.
setNumForLoops(Expr * Num)382   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
383 
384 public:
385   /// \brief Build 'collapse' clause.
386   ///
387   /// \param Num Expression associated with this clause.
388   /// \param StartLoc Starting location of the clause.
389   /// \param LParenLoc Location of '('.
390   /// \param EndLoc Ending location of the clause.
391   ///
OMPCollapseClause(Expr * Num,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)392   OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
393                     SourceLocation LParenLoc, SourceLocation EndLoc)
394       : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
395         NumForLoops(Num) {}
396 
397   /// \brief Build an empty clause.
398   ///
OMPCollapseClause()399   explicit OMPCollapseClause()
400       : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
401         LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
402 
403   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)404   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
405   /// \brief Returns the location of '('.
getLParenLoc()406   SourceLocation getLParenLoc() const { return LParenLoc; }
407 
408   /// \brief Return the number of associated for-loops.
getNumForLoops()409   Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
410 
classof(const OMPClause * T)411   static bool classof(const OMPClause *T) {
412     return T->getClauseKind() == OMPC_collapse;
413   }
414 
children()415   StmtRange children() { return StmtRange(&NumForLoops, &NumForLoops + 1); }
416 };
417 
418 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
419 ///
420 /// \code
421 /// #pragma omp parallel default(shared)
422 /// \endcode
423 /// In this example directive '#pragma omp parallel' has simple 'default'
424 /// clause with kind 'shared'.
425 ///
426 class OMPDefaultClause : public OMPClause {
427   friend class OMPClauseReader;
428   /// \brief Location of '('.
429   SourceLocation LParenLoc;
430   /// \brief A kind of the 'default' clause.
431   OpenMPDefaultClauseKind Kind;
432   /// \brief Start location of the kind in source code.
433   SourceLocation KindKwLoc;
434 
435   /// \brief Set kind of the clauses.
436   ///
437   /// \param K Argument of clause.
438   ///
setDefaultKind(OpenMPDefaultClauseKind K)439   void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
440 
441   /// \brief Set argument location.
442   ///
443   /// \param KLoc Argument location.
444   ///
setDefaultKindKwLoc(SourceLocation KLoc)445   void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
446 
447 public:
448   /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
449   ///
450   /// \param A Argument of the clause ('none' or 'shared').
451   /// \param ALoc Starting location of the argument.
452   /// \param StartLoc Starting location of the clause.
453   /// \param LParenLoc Location of '('.
454   /// \param EndLoc Ending location of the clause.
455   ///
OMPDefaultClause(OpenMPDefaultClauseKind A,SourceLocation ALoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)456   OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
457                    SourceLocation StartLoc, SourceLocation LParenLoc,
458                    SourceLocation EndLoc)
459       : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
460         Kind(A), KindKwLoc(ALoc) {}
461 
462   /// \brief Build an empty clause.
463   ///
OMPDefaultClause()464   OMPDefaultClause()
465       : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
466         LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
467         KindKwLoc(SourceLocation()) {}
468 
469   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)470   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
471   /// \brief Returns the location of '('.
getLParenLoc()472   SourceLocation getLParenLoc() const { return LParenLoc; }
473 
474   /// \brief Returns kind of the clause.
getDefaultKind()475   OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
476 
477   /// \brief Returns location of clause kind.
getDefaultKindKwLoc()478   SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
479 
classof(const OMPClause * T)480   static bool classof(const OMPClause *T) {
481     return T->getClauseKind() == OMPC_default;
482   }
483 
children()484   StmtRange children() { return StmtRange(); }
485 };
486 
487 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
488 /// directive.
489 ///
490 /// \code
491 /// #pragma omp parallel proc_bind(master)
492 /// \endcode
493 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
494 /// clause with kind 'master'.
495 ///
496 class OMPProcBindClause : public OMPClause {
497   friend class OMPClauseReader;
498   /// \brief Location of '('.
499   SourceLocation LParenLoc;
500   /// \brief A kind of the 'proc_bind' clause.
501   OpenMPProcBindClauseKind Kind;
502   /// \brief Start location of the kind in source code.
503   SourceLocation KindKwLoc;
504 
505   /// \brief Set kind of the clause.
506   ///
507   /// \param K Kind of clause.
508   ///
setProcBindKind(OpenMPProcBindClauseKind K)509   void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
510 
511   /// \brief Set clause kind location.
512   ///
513   /// \param KLoc Kind location.
514   ///
setProcBindKindKwLoc(SourceLocation KLoc)515   void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
516 
517 public:
518   /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
519   ///        'spread').
520   ///
521   /// \param A Argument of the clause ('master', 'close' or 'spread').
522   /// \param ALoc Starting location of the argument.
523   /// \param StartLoc Starting location of the clause.
524   /// \param LParenLoc Location of '('.
525   /// \param EndLoc Ending location of the clause.
526   ///
OMPProcBindClause(OpenMPProcBindClauseKind A,SourceLocation ALoc,SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc)527   OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
528                     SourceLocation StartLoc, SourceLocation LParenLoc,
529                     SourceLocation EndLoc)
530       : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
531         Kind(A), KindKwLoc(ALoc) {}
532 
533   /// \brief Build an empty clause.
534   ///
OMPProcBindClause()535   OMPProcBindClause()
536       : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
537         LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
538         KindKwLoc(SourceLocation()) {}
539 
540   /// \brief Sets the location of '('.
setLParenLoc(SourceLocation Loc)541   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
542   /// \brief Returns the location of '('.
getLParenLoc()543   SourceLocation getLParenLoc() const { return LParenLoc; }
544 
545   /// \brief Returns kind of the clause.
getProcBindKind()546   OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
547 
548   /// \brief Returns location of clause kind.
getProcBindKindKwLoc()549   SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
550 
classof(const OMPClause * T)551   static bool classof(const OMPClause *T) {
552     return T->getClauseKind() == OMPC_proc_bind;
553   }
554 
children()555   StmtRange children() { return StmtRange(); }
556 };
557 
558 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
559 ///
560 /// \code
561 /// #pragma omp for schedule(static, 3)
562 /// \endcode
563 /// In this example directive '#pragma omp for' has 'schedule' clause with
564 /// arguments 'static' and '3'.
565 ///
566 class OMPScheduleClause : public OMPClause {
567   friend class OMPClauseReader;
568   /// \brief Location of '('.
569   SourceLocation LParenLoc;
570   /// \brief A kind of the 'schedule' clause.
571   OpenMPScheduleClauseKind Kind;
572   /// \brief Start location of the schedule ind in source code.
573   SourceLocation KindLoc;
574   /// \brief Location of ',' (if any).
575   SourceLocation CommaLoc;
576   /// \brief Chunk size.
577   Stmt *ChunkSize;
578 
579   /// \brief Set schedule kind.
580   ///
581   /// \param K Schedule kind.
582   ///
setScheduleKind(OpenMPScheduleClauseKind K)583   void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
584   /// \brief Sets the location of '('.
585   ///
586   /// \param Loc Location of '('.
587   ///
setLParenLoc(SourceLocation Loc)588   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
589   /// \brief Set schedule kind start location.
590   ///
591   /// \param KLoc Schedule kind location.
592   ///
setScheduleKindLoc(SourceLocation KLoc)593   void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
594   /// \brief Set location of ','.
595   ///
596   /// \param Loc Location of ','.
597   ///
setCommaLoc(SourceLocation Loc)598   void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
599   /// \brief Set chunk size.
600   ///
601   /// \param E Chunk size.
602   ///
setChunkSize(Expr * E)603   void setChunkSize(Expr *E) { ChunkSize = E; }
604 
605 public:
606   /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
607   /// expression \a ChunkSize.
608   ///
609   /// \param StartLoc Starting location of the clause.
610   /// \param LParenLoc Location of '('.
611   /// \param KLoc Starting location of the argument.
612   /// \param CommaLoc Location of ','.
613   /// \param EndLoc Ending location of the clause.
614   /// \param Kind Schedule kind.
615   /// \param ChunkSize Chunk size.
616   ///
OMPScheduleClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation KLoc,SourceLocation CommaLoc,SourceLocation EndLoc,OpenMPScheduleClauseKind Kind,Expr * ChunkSize)617   OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
618                     SourceLocation KLoc, SourceLocation CommaLoc,
619                     SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
620                     Expr *ChunkSize)
621       : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
622         Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {}
623 
624   /// \brief Build an empty clause.
625   ///
OMPScheduleClause()626   explicit OMPScheduleClause()
627       : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
628         Kind(OMPC_SCHEDULE_unknown), ChunkSize(nullptr) {}
629 
630   /// \brief Get kind of the clause.
631   ///
getScheduleKind()632   OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
633   /// \brief Get location of '('.
634   ///
getLParenLoc()635   SourceLocation getLParenLoc() { return LParenLoc; }
636   /// \brief Get kind location.
637   ///
getScheduleKindLoc()638   SourceLocation getScheduleKindLoc() { return KindLoc; }
639   /// \brief Get location of ','.
640   ///
getCommaLoc()641   SourceLocation getCommaLoc() { return CommaLoc; }
642   /// \brief Get chunk size.
643   ///
getChunkSize()644   Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSize); }
645   /// \brief Get chunk size.
646   ///
getChunkSize()647   Expr *getChunkSize() const { return dyn_cast_or_null<Expr>(ChunkSize); }
648 
classof(const OMPClause * T)649   static bool classof(const OMPClause *T) {
650     return T->getClauseKind() == OMPC_schedule;
651   }
652 
children()653   StmtRange children() { return StmtRange(&ChunkSize, &ChunkSize + 1); }
654 };
655 
656 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
657 ///
658 /// \code
659 /// #pragma omp for ordered
660 /// \endcode
661 /// In this example directive '#pragma omp for' has 'ordered' clause.
662 ///
663 class OMPOrderedClause : public OMPClause {
664 public:
665   /// \brief Build 'ordered' clause.
666   ///
667   /// \param StartLoc Starting location of the clause.
668   /// \param EndLoc Ending location of the clause.
669   ///
OMPOrderedClause(SourceLocation StartLoc,SourceLocation EndLoc)670   OMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc)
671       : OMPClause(OMPC_ordered, StartLoc, EndLoc) {}
672 
673   /// \brief Build an empty clause.
674   ///
OMPOrderedClause()675   OMPOrderedClause()
676       : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
677 
classof(const OMPClause * T)678   static bool classof(const OMPClause *T) {
679     return T->getClauseKind() == OMPC_ordered;
680   }
681 
children()682   StmtRange children() { return StmtRange(); }
683 };
684 
685 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
686 ///
687 /// \code
688 /// #pragma omp for nowait
689 /// \endcode
690 /// In this example directive '#pragma omp for' has 'nowait' clause.
691 ///
692 class OMPNowaitClause : public OMPClause {
693 public:
694   /// \brief Build 'nowait' clause.
695   ///
696   /// \param StartLoc Starting location of the clause.
697   /// \param EndLoc Ending location of the clause.
698   ///
OMPNowaitClause(SourceLocation StartLoc,SourceLocation EndLoc)699   OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
700       : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
701 
702   /// \brief Build an empty clause.
703   ///
OMPNowaitClause()704   OMPNowaitClause()
705       : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
706 
classof(const OMPClause * T)707   static bool classof(const OMPClause *T) {
708     return T->getClauseKind() == OMPC_nowait;
709   }
710 
children()711   StmtRange children() { return StmtRange(); }
712 };
713 
714 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
715 ///
716 /// \code
717 /// #pragma omp task untied
718 /// \endcode
719 /// In this example directive '#pragma omp task' has 'untied' clause.
720 ///
721 class OMPUntiedClause : public OMPClause {
722 public:
723   /// \brief Build 'untied' clause.
724   ///
725   /// \param StartLoc Starting location of the clause.
726   /// \param EndLoc Ending location of the clause.
727   ///
OMPUntiedClause(SourceLocation StartLoc,SourceLocation EndLoc)728   OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
729       : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
730 
731   /// \brief Build an empty clause.
732   ///
OMPUntiedClause()733   OMPUntiedClause()
734       : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
735 
classof(const OMPClause * T)736   static bool classof(const OMPClause *T) {
737     return T->getClauseKind() == OMPC_untied;
738   }
739 
children()740   StmtRange children() { return StmtRange(); }
741 };
742 
743 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
744 /// directive.
745 ///
746 /// \code
747 /// #pragma omp task mergeable
748 /// \endcode
749 /// In this example directive '#pragma omp task' has 'mergeable' clause.
750 ///
751 class OMPMergeableClause : public OMPClause {
752 public:
753   /// \brief Build 'mergeable' clause.
754   ///
755   /// \param StartLoc Starting location of the clause.
756   /// \param EndLoc Ending location of the clause.
757   ///
OMPMergeableClause(SourceLocation StartLoc,SourceLocation EndLoc)758   OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
759       : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
760 
761   /// \brief Build an empty clause.
762   ///
OMPMergeableClause()763   OMPMergeableClause()
764       : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
765 
classof(const OMPClause * T)766   static bool classof(const OMPClause *T) {
767     return T->getClauseKind() == OMPC_mergeable;
768   }
769 
children()770   StmtRange children() { return StmtRange(); }
771 };
772 
773 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
774 ///
775 /// \code
776 /// #pragma omp atomic read
777 /// \endcode
778 /// In this example directive '#pragma omp atomic' has 'read' clause.
779 ///
780 class OMPReadClause : public OMPClause {
781 public:
782   /// \brief Build 'read' clause.
783   ///
784   /// \param StartLoc Starting location of the clause.
785   /// \param EndLoc Ending location of the clause.
786   ///
OMPReadClause(SourceLocation StartLoc,SourceLocation EndLoc)787   OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
788       : OMPClause(OMPC_read, StartLoc, EndLoc) {}
789 
790   /// \brief Build an empty clause.
791   ///
OMPReadClause()792   OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
793 
classof(const OMPClause * T)794   static bool classof(const OMPClause *T) {
795     return T->getClauseKind() == OMPC_read;
796   }
797 
children()798   StmtRange children() { return StmtRange(); }
799 };
800 
801 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
802 ///
803 /// \code
804 /// #pragma omp atomic write
805 /// \endcode
806 /// In this example directive '#pragma omp atomic' has 'write' clause.
807 ///
808 class OMPWriteClause : public OMPClause {
809 public:
810   /// \brief Build 'write' clause.
811   ///
812   /// \param StartLoc Starting location of the clause.
813   /// \param EndLoc Ending location of the clause.
814   ///
OMPWriteClause(SourceLocation StartLoc,SourceLocation EndLoc)815   OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
816       : OMPClause(OMPC_write, StartLoc, EndLoc) {}
817 
818   /// \brief Build an empty clause.
819   ///
OMPWriteClause()820   OMPWriteClause()
821       : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
822 
classof(const OMPClause * T)823   static bool classof(const OMPClause *T) {
824     return T->getClauseKind() == OMPC_write;
825   }
826 
children()827   StmtRange children() { return StmtRange(); }
828 };
829 
830 /// \brief This represents 'update' clause in the '#pragma omp atomic'
831 /// directive.
832 ///
833 /// \code
834 /// #pragma omp atomic update
835 /// \endcode
836 /// In this example directive '#pragma omp atomic' has 'update' clause.
837 ///
838 class OMPUpdateClause : public OMPClause {
839 public:
840   /// \brief Build 'update' clause.
841   ///
842   /// \param StartLoc Starting location of the clause.
843   /// \param EndLoc Ending location of the clause.
844   ///
OMPUpdateClause(SourceLocation StartLoc,SourceLocation EndLoc)845   OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
846       : OMPClause(OMPC_update, StartLoc, EndLoc) {}
847 
848   /// \brief Build an empty clause.
849   ///
OMPUpdateClause()850   OMPUpdateClause()
851       : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
852 
classof(const OMPClause * T)853   static bool classof(const OMPClause *T) {
854     return T->getClauseKind() == OMPC_update;
855   }
856 
children()857   StmtRange children() { return StmtRange(); }
858 };
859 
860 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
861 /// directive.
862 ///
863 /// \code
864 /// #pragma omp atomic capture
865 /// \endcode
866 /// In this example directive '#pragma omp atomic' has 'capture' clause.
867 ///
868 class OMPCaptureClause : public OMPClause {
869 public:
870   /// \brief Build 'capture' clause.
871   ///
872   /// \param StartLoc Starting location of the clause.
873   /// \param EndLoc Ending location of the clause.
874   ///
OMPCaptureClause(SourceLocation StartLoc,SourceLocation EndLoc)875   OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
876       : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
877 
878   /// \brief Build an empty clause.
879   ///
OMPCaptureClause()880   OMPCaptureClause()
881       : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
882 
classof(const OMPClause * T)883   static bool classof(const OMPClause *T) {
884     return T->getClauseKind() == OMPC_capture;
885   }
886 
children()887   StmtRange children() { return StmtRange(); }
888 };
889 
890 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
891 /// directive.
892 ///
893 /// \code
894 /// #pragma omp atomic seq_cst
895 /// \endcode
896 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
897 ///
898 class OMPSeqCstClause : public OMPClause {
899 public:
900   /// \brief Build 'seq_cst' clause.
901   ///
902   /// \param StartLoc Starting location of the clause.
903   /// \param EndLoc Ending location of the clause.
904   ///
OMPSeqCstClause(SourceLocation StartLoc,SourceLocation EndLoc)905   OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
906       : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
907 
908   /// \brief Build an empty clause.
909   ///
OMPSeqCstClause()910   OMPSeqCstClause()
911       : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
912 
classof(const OMPClause * T)913   static bool classof(const OMPClause *T) {
914     return T->getClauseKind() == OMPC_seq_cst;
915   }
916 
children()917   StmtRange children() { return StmtRange(); }
918 };
919 
920 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
921 ///
922 /// \code
923 /// #pragma omp parallel private(a,b)
924 /// \endcode
925 /// In this example directive '#pragma omp parallel' has clause 'private'
926 /// with the variables 'a' and 'b'.
927 ///
928 class OMPPrivateClause : public OMPVarListClause<OMPPrivateClause> {
929   friend class OMPClauseReader;
930   /// \brief Build clause with number of variables \a N.
931   ///
932   /// \param StartLoc Starting location of the clause.
933   /// \param LParenLoc Location of '('.
934   /// \param EndLoc Ending location of the clause.
935   /// \param N Number of the variables in the clause.
936   ///
OMPPrivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)937   OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
938                    SourceLocation EndLoc, unsigned N)
939       : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
940                                            EndLoc, N) {}
941 
942   /// \brief Build an empty clause.
943   ///
944   /// \param N Number of variables.
945   ///
OMPPrivateClause(unsigned N)946   explicit OMPPrivateClause(unsigned N)
947       : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
948                                            SourceLocation(), SourceLocation(),
949                                            N) {}
950 
951   /// \brief Sets the list of references to private copies with initializers for
952   /// new private variables.
953   /// \param VL List of references.
954   void setPrivateCopies(ArrayRef<Expr *> VL);
955 
956   /// \brief Gets the list of references to private copies with initializers for
957   /// new private variables.
getPrivateCopies()958   MutableArrayRef<Expr *> getPrivateCopies() {
959     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
960   }
getPrivateCopies()961   ArrayRef<const Expr *> getPrivateCopies() const {
962     return llvm::makeArrayRef(varlist_end(), varlist_size());
963   }
964 
965 public:
966   /// \brief Creates clause with a list of variables \a VL.
967   ///
968   /// \param C AST context.
969   /// \param StartLoc Starting location of the clause.
970   /// \param LParenLoc Location of '('.
971   /// \param EndLoc Ending location of the clause.
972   /// \param VL List of references to the variables.
973   /// \param PrivateVL List of references to private copies with initializers.
974   ///
975   static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
976                                   SourceLocation LParenLoc,
977                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
978                                   ArrayRef<Expr *> PrivateVL);
979   /// \brief Creates an empty clause with the place for \a N variables.
980   ///
981   /// \param C AST context.
982   /// \param N The number of variables.
983   ///
984   static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
985 
986   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
987   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
988   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
989   typedef llvm::iterator_range<private_copies_const_iterator>
990       private_copies_const_range;
991 
private_copies()992   private_copies_range private_copies() {
993     return private_copies_range(getPrivateCopies().begin(),
994                                 getPrivateCopies().end());
995   }
private_copies()996   private_copies_const_range private_copies() const {
997     return private_copies_const_range(getPrivateCopies().begin(),
998                                       getPrivateCopies().end());
999   }
1000 
children()1001   StmtRange children() {
1002     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1003                      reinterpret_cast<Stmt **>(varlist_end()));
1004   }
1005 
classof(const OMPClause * T)1006   static bool classof(const OMPClause *T) {
1007     return T->getClauseKind() == OMPC_private;
1008   }
1009 };
1010 
1011 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
1012 /// directives.
1013 ///
1014 /// \code
1015 /// #pragma omp parallel firstprivate(a,b)
1016 /// \endcode
1017 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1018 /// with the variables 'a' and 'b'.
1019 ///
1020 class OMPFirstprivateClause : public OMPVarListClause<OMPFirstprivateClause> {
1021   friend class OMPClauseReader;
1022 
1023   /// \brief Build clause with number of variables \a N.
1024   ///
1025   /// \param StartLoc Starting location of the clause.
1026   /// \param LParenLoc Location of '('.
1027   /// \param EndLoc Ending location of the clause.
1028   /// \param N Number of the variables in the clause.
1029   ///
OMPFirstprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)1030   OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1031                         SourceLocation EndLoc, unsigned N)
1032       : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1033                                                 LParenLoc, EndLoc, N) {}
1034 
1035   /// \brief Build an empty clause.
1036   ///
1037   /// \param N Number of variables.
1038   ///
OMPFirstprivateClause(unsigned N)1039   explicit OMPFirstprivateClause(unsigned N)
1040       : OMPVarListClause<OMPFirstprivateClause>(
1041             OMPC_firstprivate, SourceLocation(), SourceLocation(),
1042             SourceLocation(), N) {}
1043   /// \brief Sets the list of references to private copies with initializers for
1044   /// new private variables.
1045   /// \param VL List of references.
1046   void setPrivateCopies(ArrayRef<Expr *> VL);
1047 
1048   /// \brief Gets the list of references to private copies with initializers for
1049   /// new private variables.
getPrivateCopies()1050   MutableArrayRef<Expr *> getPrivateCopies() {
1051     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1052   }
getPrivateCopies()1053   ArrayRef<const Expr *> getPrivateCopies() const {
1054     return llvm::makeArrayRef(varlist_end(), varlist_size());
1055   }
1056 
1057   /// \brief Sets the list of references to initializer variables for new
1058   /// private variables.
1059   /// \param VL List of references.
1060   void setInits(ArrayRef<Expr *> VL);
1061 
1062   /// \brief Gets the list of references to initializer variables for new
1063   /// private variables.
getInits()1064   MutableArrayRef<Expr *> getInits() {
1065     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1066   }
getInits()1067   ArrayRef<const Expr *> getInits() const {
1068     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1069   }
1070 
1071 public:
1072   /// \brief Creates clause with a list of variables \a VL.
1073   ///
1074   /// \param C AST context.
1075   /// \param StartLoc Starting location of the clause.
1076   /// \param LParenLoc Location of '('.
1077   /// \param EndLoc Ending location of the clause.
1078   /// \param VL List of references to the original variables.
1079   /// \param PrivateVL List of references to private copies with initializers.
1080   /// \param InitVL List of references to auto generated variables used for
1081   /// initialization of a single array element. Used if firstprivate variable is
1082   /// of array type.
1083   ///
1084   static OMPFirstprivateClause *
1085   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1086          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1087          ArrayRef<Expr *> InitVL);
1088   /// \brief Creates an empty clause with the place for \a N variables.
1089   ///
1090   /// \param C AST context.
1091   /// \param N The number of variables.
1092   ///
1093   static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1094 
1095   typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1096   typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1097   typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1098   typedef llvm::iterator_range<private_copies_const_iterator>
1099       private_copies_const_range;
1100 
private_copies()1101   private_copies_range private_copies() {
1102     return private_copies_range(getPrivateCopies().begin(),
1103                                 getPrivateCopies().end());
1104   }
private_copies()1105   private_copies_const_range private_copies() const {
1106     return private_copies_const_range(getPrivateCopies().begin(),
1107                                       getPrivateCopies().end());
1108   }
1109 
1110   typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1111   typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1112   typedef llvm::iterator_range<inits_iterator> inits_range;
1113   typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1114 
inits()1115   inits_range inits() {
1116     return inits_range(getInits().begin(), getInits().end());
1117   }
inits()1118   inits_const_range inits() const {
1119     return inits_const_range(getInits().begin(), getInits().end());
1120   }
1121 
children()1122   StmtRange children() {
1123     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1124                      reinterpret_cast<Stmt **>(varlist_end()));
1125   }
1126 
classof(const OMPClause * T)1127   static bool classof(const OMPClause *T) {
1128     return T->getClauseKind() == OMPC_firstprivate;
1129   }
1130 };
1131 
1132 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
1133 /// directives.
1134 ///
1135 /// \code
1136 /// #pragma omp simd lastprivate(a,b)
1137 /// \endcode
1138 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1139 /// with the variables 'a' and 'b'.
1140 class OMPLastprivateClause : public OMPVarListClause<OMPLastprivateClause> {
1141   // There are 4 additional tail-allocated arrays at the end of the class:
1142   // 1. Contains list of pseudo variables with the default initialization for
1143   // each non-firstprivate variables. Used in codegen for initialization of
1144   // lastprivate copies.
1145   // 2. List of helper expressions for proper generation of assignment operation
1146   // required for lastprivate clause. This list represents private variables
1147   // (for arrays, single array element).
1148   // 3. List of helper expressions for proper generation of assignment operation
1149   // required for lastprivate clause. This list represents original variables
1150   // (for arrays, single array element).
1151   // 4. List of helper expressions that represents assignment operation:
1152   // \code
1153   // DstExprs = SrcExprs;
1154   // \endcode
1155   // Required for proper codegen of final assignment performed by the
1156   // lastprivate clause.
1157   //
1158   friend class OMPClauseReader;
1159 
1160   /// \brief Build clause with number of variables \a N.
1161   ///
1162   /// \param StartLoc Starting location of the clause.
1163   /// \param LParenLoc Location of '('.
1164   /// \param EndLoc Ending location of the clause.
1165   /// \param N Number of the variables in the clause.
1166   ///
OMPLastprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)1167   OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1168                        SourceLocation EndLoc, unsigned N)
1169       : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1170                                                LParenLoc, EndLoc, N) {}
1171 
1172   /// \brief Build an empty clause.
1173   ///
1174   /// \param N Number of variables.
1175   ///
OMPLastprivateClause(unsigned N)1176   explicit OMPLastprivateClause(unsigned N)
1177       : OMPVarListClause<OMPLastprivateClause>(
1178             OMPC_lastprivate, SourceLocation(), SourceLocation(),
1179             SourceLocation(), N) {}
1180 
1181   /// \brief Get the list of helper expressions for initialization of private
1182   /// copies for lastprivate variables.
getPrivateCopies()1183   MutableArrayRef<Expr *> getPrivateCopies() {
1184     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1185   }
getPrivateCopies()1186   ArrayRef<const Expr *> getPrivateCopies() const {
1187     return llvm::makeArrayRef(varlist_end(), varlist_size());
1188   }
1189 
1190   /// \brief Set list of helper expressions, required for proper codegen of the
1191   /// clause. These expressions represent private variables (for arrays, single
1192   /// array element) in the final assignment statement performed by the
1193   /// lastprivate clause.
1194   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1195 
1196   /// \brief Get the list of helper source expressions.
getSourceExprs()1197   MutableArrayRef<Expr *> getSourceExprs() {
1198     return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1199   }
getSourceExprs()1200   ArrayRef<const Expr *> getSourceExprs() const {
1201     return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1202   }
1203 
1204   /// \brief Set list of helper expressions, required for proper codegen of the
1205   /// clause. These expressions represent original variables (for arrays, single
1206   /// array element) in the final assignment statement performed by the
1207   /// lastprivate clause.
1208   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1209 
1210   /// \brief Get the list of helper destination expressions.
getDestinationExprs()1211   MutableArrayRef<Expr *> getDestinationExprs() {
1212     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1213   }
getDestinationExprs()1214   ArrayRef<const Expr *> getDestinationExprs() const {
1215     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1216   }
1217 
1218   /// \brief Set list of helper assignment expressions, required for proper
1219   /// codegen of the clause. These expressions are assignment expressions that
1220   /// assign private copy of the variable to original variable.
1221   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1222 
1223   /// \brief Get the list of helper assignment expressions.
getAssignmentOps()1224   MutableArrayRef<Expr *> getAssignmentOps() {
1225     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1226   }
getAssignmentOps()1227   ArrayRef<const Expr *> getAssignmentOps() const {
1228     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1229   }
1230 
1231 public:
1232   /// \brief Creates clause with a list of variables \a VL.
1233   ///
1234   /// \param C AST context.
1235   /// \param StartLoc Starting location of the clause.
1236   /// \param LParenLoc Location of '('.
1237   /// \param EndLoc Ending location of the clause.
1238   /// \param VL List of references to the variables.
1239   /// \param SrcExprs List of helper expressions for proper generation of
1240   /// assignment operation required for lastprivate clause. This list represents
1241   /// private variables (for arrays, single array element).
1242   /// \param DstExprs List of helper expressions for proper generation of
1243   /// assignment operation required for lastprivate clause. This list represents
1244   /// original variables (for arrays, single array element).
1245   /// \param AssignmentOps List of helper expressions that represents assignment
1246   /// operation:
1247   /// \code
1248   /// DstExprs = SrcExprs;
1249   /// \endcode
1250   /// Required for proper codegen of final assignment performed by the
1251   /// lastprivate clause.
1252   ///
1253   ///
1254   static OMPLastprivateClause *
1255   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1256          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1257          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
1258   /// \brief Creates an empty clause with the place for \a N variables.
1259   ///
1260   /// \param C AST context.
1261   /// \param N The number of variables.
1262   ///
1263   static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1264 
1265   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1266   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1267   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1268   typedef llvm::iterator_range<helper_expr_const_iterator>
1269       helper_expr_const_range;
1270 
1271   /// \brief Set list of helper expressions, required for generation of private
1272   /// copies of original lastprivate variables.
1273   void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1274 
private_copies()1275   helper_expr_const_range private_copies() const {
1276     return helper_expr_const_range(getPrivateCopies().begin(),
1277                                    getPrivateCopies().end());
1278   }
private_copies()1279   helper_expr_range private_copies() {
1280     return helper_expr_range(getPrivateCopies().begin(),
1281                              getPrivateCopies().end());
1282   }
source_exprs()1283   helper_expr_const_range source_exprs() const {
1284     return helper_expr_const_range(getSourceExprs().begin(),
1285                                    getSourceExprs().end());
1286   }
source_exprs()1287   helper_expr_range source_exprs() {
1288     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1289   }
destination_exprs()1290   helper_expr_const_range destination_exprs() const {
1291     return helper_expr_const_range(getDestinationExprs().begin(),
1292                                    getDestinationExprs().end());
1293   }
destination_exprs()1294   helper_expr_range destination_exprs() {
1295     return helper_expr_range(getDestinationExprs().begin(),
1296                              getDestinationExprs().end());
1297   }
assignment_ops()1298   helper_expr_const_range assignment_ops() const {
1299     return helper_expr_const_range(getAssignmentOps().begin(),
1300                                    getAssignmentOps().end());
1301   }
assignment_ops()1302   helper_expr_range assignment_ops() {
1303     return helper_expr_range(getAssignmentOps().begin(),
1304                              getAssignmentOps().end());
1305   }
1306 
children()1307   StmtRange children() {
1308     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1309                      reinterpret_cast<Stmt **>(varlist_end()));
1310   }
1311 
classof(const OMPClause * T)1312   static bool classof(const OMPClause *T) {
1313     return T->getClauseKind() == OMPC_lastprivate;
1314   }
1315 };
1316 
1317 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
1318 ///
1319 /// \code
1320 /// #pragma omp parallel shared(a,b)
1321 /// \endcode
1322 /// In this example directive '#pragma omp parallel' has clause 'shared'
1323 /// with the variables 'a' and 'b'.
1324 ///
1325 class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
1326   /// \brief Build clause with number of variables \a N.
1327   ///
1328   /// \param StartLoc Starting location of the clause.
1329   /// \param LParenLoc Location of '('.
1330   /// \param EndLoc Ending location of the clause.
1331   /// \param N Number of the variables in the clause.
1332   ///
OMPSharedClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)1333   OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1334                   SourceLocation EndLoc, unsigned N)
1335       : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1336                                           EndLoc, N) {}
1337 
1338   /// \brief Build an empty clause.
1339   ///
1340   /// \param N Number of variables.
1341   ///
OMPSharedClause(unsigned N)1342   explicit OMPSharedClause(unsigned N)
1343       : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1344                                           SourceLocation(), SourceLocation(),
1345                                           N) {}
1346 
1347 public:
1348   /// \brief Creates clause with a list of variables \a VL.
1349   ///
1350   /// \param C AST context.
1351   /// \param StartLoc Starting location of the clause.
1352   /// \param LParenLoc Location of '('.
1353   /// \param EndLoc Ending location of the clause.
1354   /// \param VL List of references to the variables.
1355   ///
1356   static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1357                                  SourceLocation LParenLoc,
1358                                  SourceLocation EndLoc, ArrayRef<Expr *> VL);
1359   /// \brief Creates an empty clause with \a N variables.
1360   ///
1361   /// \param C AST context.
1362   /// \param N The number of variables.
1363   ///
1364   static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1365 
children()1366   StmtRange children() {
1367     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1368                      reinterpret_cast<Stmt **>(varlist_end()));
1369   }
1370 
classof(const OMPClause * T)1371   static bool classof(const OMPClause *T) {
1372     return T->getClauseKind() == OMPC_shared;
1373   }
1374 };
1375 
1376 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
1377 /// directives.
1378 ///
1379 /// \code
1380 /// #pragma omp parallel reduction(+:a,b)
1381 /// \endcode
1382 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1383 /// with operator '+' and the variables 'a' and 'b'.
1384 ///
1385 class OMPReductionClause : public OMPVarListClause<OMPReductionClause> {
1386   friend class OMPClauseReader;
1387   /// \brief Location of ':'.
1388   SourceLocation ColonLoc;
1389   /// \brief Nested name specifier for C++.
1390   NestedNameSpecifierLoc QualifierLoc;
1391   /// \brief Name of custom operator.
1392   DeclarationNameInfo NameInfo;
1393 
1394   /// \brief Build clause with number of variables \a N.
1395   ///
1396   /// \param StartLoc Starting location of the clause.
1397   /// \param LParenLoc Location of '('.
1398   /// \param EndLoc Ending location of the clause.
1399   /// \param ColonLoc Location of ':'.
1400   /// \param N Number of the variables in the clause.
1401   /// \param QualifierLoc The nested-name qualifier with location information
1402   /// \param NameInfo The full name info for reduction identifier.
1403   ///
OMPReductionClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned N,NestedNameSpecifierLoc QualifierLoc,const DeclarationNameInfo & NameInfo)1404   OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1405                      SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1406                      NestedNameSpecifierLoc QualifierLoc,
1407                      const DeclarationNameInfo &NameInfo)
1408       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1409                                              LParenLoc, EndLoc, N),
1410         ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1411 
1412   /// \brief Build an empty clause.
1413   ///
1414   /// \param N Number of variables.
1415   ///
OMPReductionClause(unsigned N)1416   explicit OMPReductionClause(unsigned N)
1417       : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1418                                              SourceLocation(), SourceLocation(),
1419                                              N),
1420         ColonLoc(), QualifierLoc(), NameInfo() {}
1421 
1422   /// \brief Sets location of ':' symbol in clause.
setColonLoc(SourceLocation CL)1423   void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1424   /// \brief Sets the name info for specified reduction identifier.
setNameInfo(DeclarationNameInfo DNI)1425   void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1426   /// \brief Sets the nested name specifier.
setQualifierLoc(NestedNameSpecifierLoc NSL)1427   void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1428 
1429   /// \brief Set list of helper expressions, required for proper codegen of the
1430   /// clause. These expressions represent LHS expression in the final
1431   /// reduction expression performed by the reduction clause.
1432   void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1433 
1434   /// \brief Get the list of helper LHS expressions.
getLHSExprs()1435   MutableArrayRef<Expr *> getLHSExprs() {
1436     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1437   }
getLHSExprs()1438   ArrayRef<const Expr *> getLHSExprs() const {
1439     return llvm::makeArrayRef(varlist_end(), varlist_size());
1440   }
1441 
1442   /// \brief Set list of helper expressions, required for proper codegen of the
1443   /// clause. These expressions represent RHS expression in the final
1444   /// reduction expression performed by the reduction clause.
1445   /// Also, variables in these expressions are used for proper initialization of
1446   /// reduction copies.
1447   void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1448 
1449   /// \brief Get the list of helper destination expressions.
getRHSExprs()1450   MutableArrayRef<Expr *> getRHSExprs() {
1451     return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1452   }
getRHSExprs()1453   ArrayRef<const Expr *> getRHSExprs() const {
1454     return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1455   }
1456 
1457   /// \brief Set list of helper reduction expressions, required for proper
1458   /// codegen of the clause. These expressions are binary expressions or
1459   /// operator/custom reduction call that calculates new value from source
1460   /// helper expressions to destination helper expressions.
1461   void setReductionOps(ArrayRef<Expr *> ReductionOps);
1462 
1463   /// \brief Get the list of helper reduction expressions.
getReductionOps()1464   MutableArrayRef<Expr *> getReductionOps() {
1465     return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1466   }
getReductionOps()1467   ArrayRef<const Expr *> getReductionOps() const {
1468     return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1469   }
1470 
1471 public:
1472   /// \brief Creates clause with a list of variables \a VL.
1473   ///
1474   /// \param StartLoc Starting location of the clause.
1475   /// \param LParenLoc Location of '('.
1476   /// \param ColonLoc Location of ':'.
1477   /// \param EndLoc Ending location of the clause.
1478   /// \param VL The variables in the clause.
1479   /// \param QualifierLoc The nested-name qualifier with location information
1480   /// \param NameInfo The full name info for reduction identifier.
1481   /// \param LHSExprs List of helper expressions for proper generation of
1482   /// assignment operation required for copyprivate clause. This list represents
1483   /// LHSs of the reduction expressions.
1484   /// \param RHSExprs List of helper expressions for proper generation of
1485   /// assignment operation required for copyprivate clause. This list represents
1486   /// RHSs of the reduction expressions.
1487   /// Also, variables in these expressions are used for proper initialization of
1488   /// reduction copies.
1489   /// \param ReductionOps List of helper expressions that represents reduction
1490   /// expressions:
1491   /// \code
1492   /// LHSExprs binop RHSExprs;
1493   /// operator binop(LHSExpr, RHSExpr);
1494   /// <CutomReduction>(LHSExpr, RHSExpr);
1495   /// \endcode
1496   /// Required for proper codegen of final reduction operation performed by the
1497   /// reduction clause.
1498   ///
1499   static OMPReductionClause *
1500   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1501          SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1502          NestedNameSpecifierLoc QualifierLoc,
1503          const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> LHSExprs,
1504          ArrayRef<Expr *> RHSExprs, ArrayRef<Expr *> ReductionOps);
1505   /// \brief Creates an empty clause with the place for \a N variables.
1506   ///
1507   /// \param C AST context.
1508   /// \param N The number of variables.
1509   ///
1510   static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1511 
1512   /// \brief Gets location of ':' symbol in clause.
getColonLoc()1513   SourceLocation getColonLoc() const { return ColonLoc; }
1514   /// \brief Gets the name info for specified reduction identifier.
getNameInfo()1515   const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1516   /// \brief Gets the nested name specifier.
getQualifierLoc()1517   NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1518 
1519   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1520   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1521   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1522   typedef llvm::iterator_range<helper_expr_const_iterator>
1523       helper_expr_const_range;
1524 
lhs_exprs()1525   helper_expr_const_range lhs_exprs() const {
1526     return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
1527   }
lhs_exprs()1528   helper_expr_range lhs_exprs() {
1529     return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
1530   }
rhs_exprs()1531   helper_expr_const_range rhs_exprs() const {
1532     return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
1533   }
rhs_exprs()1534   helper_expr_range rhs_exprs() {
1535     return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
1536   }
reduction_ops()1537   helper_expr_const_range reduction_ops() const {
1538     return helper_expr_const_range(getReductionOps().begin(),
1539                                    getReductionOps().end());
1540   }
reduction_ops()1541   helper_expr_range reduction_ops() {
1542     return helper_expr_range(getReductionOps().begin(),
1543                              getReductionOps().end());
1544   }
1545 
children()1546   StmtRange children() {
1547     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1548                      reinterpret_cast<Stmt **>(varlist_end()));
1549   }
1550 
classof(const OMPClause * T)1551   static bool classof(const OMPClause *T) {
1552     return T->getClauseKind() == OMPC_reduction;
1553   }
1554 };
1555 
1556 /// \brief This represents clause 'linear' in the '#pragma omp ...'
1557 /// directives.
1558 ///
1559 /// \code
1560 /// #pragma omp simd linear(a,b : 2)
1561 /// \endcode
1562 /// In this example directive '#pragma omp simd' has clause 'linear'
1563 /// with variables 'a', 'b' and linear step '2'.
1564 ///
1565 class OMPLinearClause : public OMPVarListClause<OMPLinearClause> {
1566   friend class OMPClauseReader;
1567   /// \brief Location of ':'.
1568   SourceLocation ColonLoc;
1569 
1570   /// \brief Sets the linear step for clause.
setStep(Expr * Step)1571   void setStep(Expr *Step) { *(getFinals().end()) = Step; }
1572 
1573   /// \brief Sets the expression to calculate linear step for clause.
setCalcStep(Expr * CalcStep)1574   void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
1575 
1576   /// \brief Build 'linear' clause with given number of variables \a NumVars.
1577   ///
1578   /// \param StartLoc Starting location of the clause.
1579   /// \param LParenLoc Location of '('.
1580   /// \param ColonLoc Location of ':'.
1581   /// \param EndLoc Ending location of the clause.
1582   /// \param NumVars Number of variables.
1583   ///
OMPLinearClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned NumVars)1584   OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1585                   SourceLocation ColonLoc, SourceLocation EndLoc,
1586                   unsigned NumVars)
1587       : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
1588                                           EndLoc, NumVars),
1589         ColonLoc(ColonLoc) {}
1590 
1591   /// \brief Build an empty clause.
1592   ///
1593   /// \param NumVars Number of variables.
1594   ///
OMPLinearClause(unsigned NumVars)1595   explicit OMPLinearClause(unsigned NumVars)
1596       : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
1597                                           SourceLocation(), SourceLocation(),
1598                                           NumVars),
1599         ColonLoc(SourceLocation()) {}
1600 
1601   /// \brief Gets the list of initial values for linear variables.
1602   ///
1603   /// There are NumVars expressions with initial values allocated after the
1604   /// varlist, they are followed by NumVars update expressions (used to update
1605   /// the linear variable's value on current iteration) and they are followed by
1606   /// NumVars final expressions (used to calculate the linear variable's
1607   /// value after the loop body). After these lists, there are 2 helper
1608   /// expressions - linear step and a helper to calculate it before the
1609   /// loop body (used when the linear step is not constant):
1610   ///
1611   /// { Vars[] /* in OMPVarListClause */; Inits[]; Updates[]; Finals[];
1612   ///   Step; CalcStep; }
1613   ///
getInits()1614   MutableArrayRef<Expr *> getInits() {
1615     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1616   }
getInits()1617   ArrayRef<const Expr *> getInits() const {
1618     return llvm::makeArrayRef(varlist_end(), varlist_size());
1619   }
1620 
1621   /// \brief Sets the list of update expressions for linear variables.
getUpdates()1622   MutableArrayRef<Expr *> getUpdates() {
1623     return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
1624   }
getUpdates()1625   ArrayRef<const Expr *> getUpdates() const {
1626     return llvm::makeArrayRef(getInits().end(), varlist_size());
1627   }
1628 
1629   /// \brief Sets the list of final update expressions for linear variables.
getFinals()1630   MutableArrayRef<Expr *> getFinals() {
1631     return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
1632   }
getFinals()1633   ArrayRef<const Expr *> getFinals() const {
1634     return llvm::makeArrayRef(getUpdates().end(), varlist_size());
1635   }
1636 
1637   /// \brief Sets the list of the initial values for linear variables.
1638   /// \param IL List of expressions.
1639   void setInits(ArrayRef<Expr *> IL);
1640 
1641 public:
1642   /// \brief Creates clause with a list of variables \a VL and a linear step
1643   /// \a Step.
1644   ///
1645   /// \param C AST Context.
1646   /// \param StartLoc Starting location of the clause.
1647   /// \param LParenLoc Location of '('.
1648   /// \param ColonLoc Location of ':'.
1649   /// \param EndLoc Ending location of the clause.
1650   /// \param VL List of references to the variables.
1651   /// \param IL List of initial values for the variables.
1652   /// \param Step Linear step.
1653   /// \param CalcStep Calculation of the linear step.
1654   static OMPLinearClause *Create(const ASTContext &C, SourceLocation StartLoc,
1655                                  SourceLocation LParenLoc,
1656                                  SourceLocation ColonLoc, SourceLocation EndLoc,
1657                                  ArrayRef<Expr *> VL, ArrayRef<Expr *> IL,
1658                                  Expr *Step, Expr *CalcStep);
1659 
1660   /// \brief Creates an empty clause with the place for \a NumVars variables.
1661   ///
1662   /// \param C AST context.
1663   /// \param NumVars Number of variables.
1664   ///
1665   static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1666 
1667   /// \brief Sets the location of ':'.
setColonLoc(SourceLocation Loc)1668   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1669   /// \brief Returns the location of '('.
getColonLoc()1670   SourceLocation getColonLoc() const { return ColonLoc; }
1671 
1672   /// \brief Returns linear step.
getStep()1673   Expr *getStep() { return *(getFinals().end()); }
1674   /// \brief Returns linear step.
getStep()1675   const Expr *getStep() const { return *(getFinals().end()); }
1676   /// \brief Returns expression to calculate linear step.
getCalcStep()1677   Expr *getCalcStep() { return *(getFinals().end() + 1); }
1678   /// \brief Returns expression to calculate linear step.
getCalcStep()1679   const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
1680 
1681   /// \brief Sets the list of update expressions for linear variables.
1682   /// \param UL List of expressions.
1683   void setUpdates(ArrayRef<Expr *> UL);
1684 
1685   /// \brief Sets the list of final update expressions for linear variables.
1686   /// \param FL List of expressions.
1687   void setFinals(ArrayRef<Expr *> FL);
1688 
1689   typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1690   typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1691   typedef llvm::iterator_range<inits_iterator> inits_range;
1692   typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1693 
inits()1694   inits_range inits() {
1695     return inits_range(getInits().begin(), getInits().end());
1696   }
inits()1697   inits_const_range inits() const {
1698     return inits_const_range(getInits().begin(), getInits().end());
1699   }
1700 
1701   typedef MutableArrayRef<Expr *>::iterator updates_iterator;
1702   typedef ArrayRef<const Expr *>::iterator updates_const_iterator;
1703   typedef llvm::iterator_range<updates_iterator> updates_range;
1704   typedef llvm::iterator_range<updates_const_iterator> updates_const_range;
1705 
updates()1706   updates_range updates() {
1707     return updates_range(getUpdates().begin(), getUpdates().end());
1708   }
updates()1709   updates_const_range updates() const {
1710     return updates_const_range(getUpdates().begin(), getUpdates().end());
1711   }
1712 
1713   typedef MutableArrayRef<Expr *>::iterator finals_iterator;
1714   typedef ArrayRef<const Expr *>::iterator finals_const_iterator;
1715   typedef llvm::iterator_range<finals_iterator> finals_range;
1716   typedef llvm::iterator_range<finals_const_iterator> finals_const_range;
1717 
finals()1718   finals_range finals() {
1719     return finals_range(getFinals().begin(), getFinals().end());
1720   }
finals()1721   finals_const_range finals() const {
1722     return finals_const_range(getFinals().begin(), getFinals().end());
1723   }
1724 
children()1725   StmtRange children() {
1726     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1727                      reinterpret_cast<Stmt **>(getFinals().end() + 2));
1728   }
1729 
classof(const OMPClause * T)1730   static bool classof(const OMPClause *T) {
1731     return T->getClauseKind() == OMPC_linear;
1732   }
1733 };
1734 
1735 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
1736 /// directives.
1737 ///
1738 /// \code
1739 /// #pragma omp simd aligned(a,b : 8)
1740 /// \endcode
1741 /// In this example directive '#pragma omp simd' has clause 'aligned'
1742 /// with variables 'a', 'b' and alignment '8'.
1743 ///
1744 class OMPAlignedClause : public OMPVarListClause<OMPAlignedClause> {
1745   friend class OMPClauseReader;
1746   /// \brief Location of ':'.
1747   SourceLocation ColonLoc;
1748 
1749   /// \brief Sets the alignment for clause.
setAlignment(Expr * A)1750   void setAlignment(Expr *A) { *varlist_end() = A; }
1751 
1752   /// \brief Build 'aligned' clause with given number of variables \a NumVars.
1753   ///
1754   /// \param StartLoc Starting location of the clause.
1755   /// \param LParenLoc Location of '('.
1756   /// \param ColonLoc Location of ':'.
1757   /// \param EndLoc Ending location of the clause.
1758   /// \param NumVars Number of variables.
1759   ///
OMPAlignedClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation ColonLoc,SourceLocation EndLoc,unsigned NumVars)1760   OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1761                    SourceLocation ColonLoc, SourceLocation EndLoc,
1762                    unsigned NumVars)
1763       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
1764                                            EndLoc, NumVars),
1765         ColonLoc(ColonLoc) {}
1766 
1767   /// \brief Build an empty clause.
1768   ///
1769   /// \param NumVars Number of variables.
1770   ///
OMPAlignedClause(unsigned NumVars)1771   explicit OMPAlignedClause(unsigned NumVars)
1772       : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
1773                                            SourceLocation(), SourceLocation(),
1774                                            NumVars),
1775         ColonLoc(SourceLocation()) {}
1776 
1777 public:
1778   /// \brief Creates clause with a list of variables \a VL and alignment \a A.
1779   ///
1780   /// \param C AST Context.
1781   /// \param StartLoc Starting location of the clause.
1782   /// \param LParenLoc Location of '('.
1783   /// \param ColonLoc Location of ':'.
1784   /// \param EndLoc Ending location of the clause.
1785   /// \param VL List of references to the variables.
1786   /// \param A Alignment.
1787   static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1788                                   SourceLocation LParenLoc,
1789                                   SourceLocation ColonLoc,
1790                                   SourceLocation EndLoc, ArrayRef<Expr *> VL,
1791                                   Expr *A);
1792 
1793   /// \brief Creates an empty clause with the place for \a NumVars variables.
1794   ///
1795   /// \param C AST context.
1796   /// \param NumVars Number of variables.
1797   ///
1798   static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1799 
1800   /// \brief Sets the location of ':'.
setColonLoc(SourceLocation Loc)1801   void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1802   /// \brief Returns the location of ':'.
getColonLoc()1803   SourceLocation getColonLoc() const { return ColonLoc; }
1804 
1805   /// \brief Returns alignment.
getAlignment()1806   Expr *getAlignment() { return *varlist_end(); }
1807   /// \brief Returns alignment.
getAlignment()1808   const Expr *getAlignment() const { return *varlist_end(); }
1809 
children()1810   StmtRange children() {
1811     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1812                      reinterpret_cast<Stmt **>(varlist_end() + 1));
1813   }
1814 
classof(const OMPClause * T)1815   static bool classof(const OMPClause *T) {
1816     return T->getClauseKind() == OMPC_aligned;
1817   }
1818 };
1819 
1820 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
1821 ///
1822 /// \code
1823 /// #pragma omp parallel copyin(a,b)
1824 /// \endcode
1825 /// In this example directive '#pragma omp parallel' has clause 'copyin'
1826 /// with the variables 'a' and 'b'.
1827 ///
1828 class OMPCopyinClause : public OMPVarListClause<OMPCopyinClause> {
1829   // Class has 3 additional tail allocated arrays:
1830   // 1. List of helper expressions for proper generation of assignment operation
1831   // required for copyin clause. This list represents sources.
1832   // 2. List of helper expressions for proper generation of assignment operation
1833   // required for copyin clause. This list represents destinations.
1834   // 3. List of helper expressions that represents assignment operation:
1835   // \code
1836   // DstExprs = SrcExprs;
1837   // \endcode
1838   // Required for proper codegen of propagation of master's thread values of
1839   // threadprivate variables to local instances of that variables in other
1840   // implicit threads.
1841 
1842   friend class OMPClauseReader;
1843   /// \brief Build clause with number of variables \a N.
1844   ///
1845   /// \param StartLoc Starting location of the clause.
1846   /// \param LParenLoc Location of '('.
1847   /// \param EndLoc Ending location of the clause.
1848   /// \param N Number of the variables in the clause.
1849   ///
OMPCopyinClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)1850   OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1851                   SourceLocation EndLoc, unsigned N)
1852       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
1853                                           EndLoc, N) {}
1854 
1855   /// \brief Build an empty clause.
1856   ///
1857   /// \param N Number of variables.
1858   ///
OMPCopyinClause(unsigned N)1859   explicit OMPCopyinClause(unsigned N)
1860       : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
1861                                           SourceLocation(), SourceLocation(),
1862                                           N) {}
1863 
1864   /// \brief Set list of helper expressions, required for proper codegen of the
1865   /// clause. These expressions represent source expression in the final
1866   /// assignment statement performed by the copyin clause.
1867   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1868 
1869   /// \brief Get the list of helper source expressions.
getSourceExprs()1870   MutableArrayRef<Expr *> getSourceExprs() {
1871     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1872   }
getSourceExprs()1873   ArrayRef<const Expr *> getSourceExprs() const {
1874     return llvm::makeArrayRef(varlist_end(), varlist_size());
1875   }
1876 
1877   /// \brief Set list of helper expressions, required for proper codegen of the
1878   /// clause. These expressions represent destination expression in the final
1879   /// assignment statement performed by the copyin clause.
1880   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1881 
1882   /// \brief Get the list of helper destination expressions.
getDestinationExprs()1883   MutableArrayRef<Expr *> getDestinationExprs() {
1884     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1885   }
getDestinationExprs()1886   ArrayRef<const Expr *> getDestinationExprs() const {
1887     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1888   }
1889 
1890   /// \brief Set list of helper assignment expressions, required for proper
1891   /// codegen of the clause. These expressions are assignment expressions that
1892   /// assign source helper expressions to destination helper expressions
1893   /// correspondingly.
1894   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1895 
1896   /// \brief Get the list of helper assignment expressions.
getAssignmentOps()1897   MutableArrayRef<Expr *> getAssignmentOps() {
1898     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1899   }
getAssignmentOps()1900   ArrayRef<const Expr *> getAssignmentOps() const {
1901     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1902   }
1903 
1904 public:
1905   /// \brief Creates clause with a list of variables \a VL.
1906   ///
1907   /// \param C AST context.
1908   /// \param StartLoc Starting location of the clause.
1909   /// \param LParenLoc Location of '('.
1910   /// \param EndLoc Ending location of the clause.
1911   /// \param VL List of references to the variables.
1912   /// \param SrcExprs List of helper expressions for proper generation of
1913   /// assignment operation required for copyin clause. This list represents
1914   /// sources.
1915   /// \param DstExprs List of helper expressions for proper generation of
1916   /// assignment operation required for copyin clause. This list represents
1917   /// destinations.
1918   /// \param AssignmentOps List of helper expressions that represents assignment
1919   /// operation:
1920   /// \code
1921   /// DstExprs = SrcExprs;
1922   /// \endcode
1923   /// Required for proper codegen of propagation of master's thread values of
1924   /// threadprivate variables to local instances of that variables in other
1925   /// implicit threads.
1926   ///
1927   static OMPCopyinClause *
1928   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1929          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1930          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
1931   /// \brief Creates an empty clause with \a N variables.
1932   ///
1933   /// \param C AST context.
1934   /// \param N The number of variables.
1935   ///
1936   static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
1937 
1938   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1939   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1940   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1941   typedef llvm::iterator_range<helper_expr_const_iterator>
1942       helper_expr_const_range;
1943 
source_exprs()1944   helper_expr_const_range source_exprs() const {
1945     return helper_expr_const_range(getSourceExprs().begin(),
1946                                    getSourceExprs().end());
1947   }
source_exprs()1948   helper_expr_range source_exprs() {
1949     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1950   }
destination_exprs()1951   helper_expr_const_range destination_exprs() const {
1952     return helper_expr_const_range(getDestinationExprs().begin(),
1953                                    getDestinationExprs().end());
1954   }
destination_exprs()1955   helper_expr_range destination_exprs() {
1956     return helper_expr_range(getDestinationExprs().begin(),
1957                              getDestinationExprs().end());
1958   }
assignment_ops()1959   helper_expr_const_range assignment_ops() const {
1960     return helper_expr_const_range(getAssignmentOps().begin(),
1961                                    getAssignmentOps().end());
1962   }
assignment_ops()1963   helper_expr_range assignment_ops() {
1964     return helper_expr_range(getAssignmentOps().begin(),
1965                              getAssignmentOps().end());
1966   }
1967 
children()1968   StmtRange children() {
1969     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
1970                      reinterpret_cast<Stmt **>(varlist_end()));
1971   }
1972 
classof(const OMPClause * T)1973   static bool classof(const OMPClause *T) {
1974     return T->getClauseKind() == OMPC_copyin;
1975   }
1976 };
1977 
1978 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
1979 /// directives.
1980 ///
1981 /// \code
1982 /// #pragma omp single copyprivate(a,b)
1983 /// \endcode
1984 /// In this example directive '#pragma omp single' has clause 'copyprivate'
1985 /// with the variables 'a' and 'b'.
1986 ///
1987 class OMPCopyprivateClause : public OMPVarListClause<OMPCopyprivateClause> {
1988   friend class OMPClauseReader;
1989   /// \brief Build clause with number of variables \a N.
1990   ///
1991   /// \param StartLoc Starting location of the clause.
1992   /// \param LParenLoc Location of '('.
1993   /// \param EndLoc Ending location of the clause.
1994   /// \param N Number of the variables in the clause.
1995   ///
OMPCopyprivateClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)1996   OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1997                        SourceLocation EndLoc, unsigned N)
1998       : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
1999                                                LParenLoc, EndLoc, N) {}
2000 
2001   /// \brief Build an empty clause.
2002   ///
2003   /// \param N Number of variables.
2004   ///
OMPCopyprivateClause(unsigned N)2005   explicit OMPCopyprivateClause(unsigned N)
2006       : OMPVarListClause<OMPCopyprivateClause>(
2007             OMPC_copyprivate, SourceLocation(), SourceLocation(),
2008             SourceLocation(), N) {}
2009 
2010   /// \brief Set list of helper expressions, required for proper codegen of the
2011   /// clause. These expressions represent source expression in the final
2012   /// assignment statement performed by the copyprivate clause.
2013   void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2014 
2015   /// \brief Get the list of helper source expressions.
getSourceExprs()2016   MutableArrayRef<Expr *> getSourceExprs() {
2017     return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2018   }
getSourceExprs()2019   ArrayRef<const Expr *> getSourceExprs() const {
2020     return llvm::makeArrayRef(varlist_end(), varlist_size());
2021   }
2022 
2023   /// \brief Set list of helper expressions, required for proper codegen of the
2024   /// clause. These expressions represent destination expression in the final
2025   /// assignment statement performed by the copyprivate clause.
2026   void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2027 
2028   /// \brief Get the list of helper destination expressions.
getDestinationExprs()2029   MutableArrayRef<Expr *> getDestinationExprs() {
2030     return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2031   }
getDestinationExprs()2032   ArrayRef<const Expr *> getDestinationExprs() const {
2033     return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2034   }
2035 
2036   /// \brief Set list of helper assignment expressions, required for proper
2037   /// codegen of the clause. These expressions are assignment expressions that
2038   /// assign source helper expressions to destination helper expressions
2039   /// correspondingly.
2040   void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2041 
2042   /// \brief Get the list of helper assignment expressions.
getAssignmentOps()2043   MutableArrayRef<Expr *> getAssignmentOps() {
2044     return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2045   }
getAssignmentOps()2046   ArrayRef<const Expr *> getAssignmentOps() const {
2047     return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2048   }
2049 
2050 public:
2051   /// \brief Creates clause with a list of variables \a VL.
2052   ///
2053   /// \param C AST context.
2054   /// \param StartLoc Starting location of the clause.
2055   /// \param LParenLoc Location of '('.
2056   /// \param EndLoc Ending location of the clause.
2057   /// \param VL List of references to the variables.
2058   /// \param SrcExprs List of helper expressions for proper generation of
2059   /// assignment operation required for copyprivate clause. This list represents
2060   /// sources.
2061   /// \param DstExprs List of helper expressions for proper generation of
2062   /// assignment operation required for copyprivate clause. This list represents
2063   /// destinations.
2064   /// \param AssignmentOps List of helper expressions that represents assignment
2065   /// operation:
2066   /// \code
2067   /// DstExprs = SrcExprs;
2068   /// \endcode
2069   /// Required for proper codegen of final assignment performed by the
2070   /// copyprivate clause.
2071   ///
2072   static OMPCopyprivateClause *
2073   Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2074          SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2075          ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2076   /// \brief Creates an empty clause with \a N variables.
2077   ///
2078   /// \param C AST context.
2079   /// \param N The number of variables.
2080   ///
2081   static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2082 
2083   typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2084   typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2085   typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2086   typedef llvm::iterator_range<helper_expr_const_iterator>
2087       helper_expr_const_range;
2088 
source_exprs()2089   helper_expr_const_range source_exprs() const {
2090     return helper_expr_const_range(getSourceExprs().begin(),
2091                                    getSourceExprs().end());
2092   }
source_exprs()2093   helper_expr_range source_exprs() {
2094     return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2095   }
destination_exprs()2096   helper_expr_const_range destination_exprs() const {
2097     return helper_expr_const_range(getDestinationExprs().begin(),
2098                                    getDestinationExprs().end());
2099   }
destination_exprs()2100   helper_expr_range destination_exprs() {
2101     return helper_expr_range(getDestinationExprs().begin(),
2102                              getDestinationExprs().end());
2103   }
assignment_ops()2104   helper_expr_const_range assignment_ops() const {
2105     return helper_expr_const_range(getAssignmentOps().begin(),
2106                                    getAssignmentOps().end());
2107   }
assignment_ops()2108   helper_expr_range assignment_ops() {
2109     return helper_expr_range(getAssignmentOps().begin(),
2110                              getAssignmentOps().end());
2111   }
2112 
children()2113   StmtRange children() {
2114     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
2115                      reinterpret_cast<Stmt **>(varlist_end()));
2116   }
2117 
classof(const OMPClause * T)2118   static bool classof(const OMPClause *T) {
2119     return T->getClauseKind() == OMPC_copyprivate;
2120   }
2121 };
2122 
2123 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
2124 /// directive.
2125 /// This clause does not exist by itself, it can be only as a part of 'omp
2126 /// flush' directive. This clause is introduced to keep the original structure
2127 /// of \a OMPExecutableDirective class and its derivatives and to use the
2128 /// existing infrastructure of clauses with the list of variables.
2129 ///
2130 /// \code
2131 /// #pragma omp flush(a,b)
2132 /// \endcode
2133 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
2134 /// with the variables 'a' and 'b'.
2135 ///
2136 class OMPFlushClause : public OMPVarListClause<OMPFlushClause> {
2137   /// \brief Build clause with number of variables \a N.
2138   ///
2139   /// \param StartLoc Starting location of the clause.
2140   /// \param LParenLoc Location of '('.
2141   /// \param EndLoc Ending location of the clause.
2142   /// \param N Number of the variables in the clause.
2143   ///
OMPFlushClause(SourceLocation StartLoc,SourceLocation LParenLoc,SourceLocation EndLoc,unsigned N)2144   OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2145                  SourceLocation EndLoc, unsigned N)
2146       : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
2147                                          EndLoc, N) {}
2148 
2149   /// \brief Build an empty clause.
2150   ///
2151   /// \param N Number of variables.
2152   ///
OMPFlushClause(unsigned N)2153   explicit OMPFlushClause(unsigned N)
2154       : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
2155                                          SourceLocation(), SourceLocation(),
2156                                          N) {}
2157 
2158 public:
2159   /// \brief Creates clause with a list of variables \a VL.
2160   ///
2161   /// \param C AST context.
2162   /// \param StartLoc Starting location of the clause.
2163   /// \param LParenLoc Location of '('.
2164   /// \param EndLoc Ending location of the clause.
2165   /// \param VL List of references to the variables.
2166   ///
2167   static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
2168                                 SourceLocation LParenLoc, SourceLocation EndLoc,
2169                                 ArrayRef<Expr *> VL);
2170   /// \brief Creates an empty clause with \a N variables.
2171   ///
2172   /// \param C AST context.
2173   /// \param N The number of variables.
2174   ///
2175   static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
2176 
children()2177   StmtRange children() {
2178     return StmtRange(reinterpret_cast<Stmt **>(varlist_begin()),
2179                      reinterpret_cast<Stmt **>(varlist_end()));
2180   }
2181 
classof(const OMPClause * T)2182   static bool classof(const OMPClause *T) {
2183     return T->getClauseKind() == OMPC_flush;
2184   }
2185 };
2186 
2187 } // end namespace clang
2188 
2189 #endif
2190 
2191