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