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