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