clang  16.0.0git
OpenMPClause.h
Go to the documentation of this file.
1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// This file defines OpenMP AST classes for clauses.
11 /// There are clauses for executable directives, clauses for declarative
12 /// directives and clauses which can be used in both kinds of directives.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
18 
19 #include "clang/AST/ASTFwd.h"
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/PointerIntPair.h"
32 #include "llvm/ADT/SmallVector.h"
33 #include "llvm/ADT/iterator.h"
34 #include "llvm/ADT/iterator_range.h"
35 #include "llvm/Frontend/OpenMP/OMPAssume.h"
36 #include "llvm/Frontend/OpenMP/OMPConstants.h"
37 #include "llvm/Frontend/OpenMP/OMPContext.h"
38 #include "llvm/Support/Casting.h"
39 #include "llvm/Support/Compiler.h"
40 #include "llvm/Support/TrailingObjects.h"
41 #include <cassert>
42 #include <cstddef>
43 #include <iterator>
44 #include <utility>
45 
46 namespace clang {
47 
48 class ASTContext;
49 
50 //===----------------------------------------------------------------------===//
51 // AST classes for clauses.
52 //===----------------------------------------------------------------------===//
53 
54 /// This is a basic class for representing single OpenMP clause.
55 class OMPClause {
56  /// Starting location of the clause (the clause keyword).
57  SourceLocation StartLoc;
58 
59  /// Ending location of the clause.
60  SourceLocation EndLoc;
61 
62  /// Kind of the clause.
63  OpenMPClauseKind Kind;
64 
65 protected:
67  : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
68 
69 public:
70  /// Returns the starting location of the clause.
71  SourceLocation getBeginLoc() const { return StartLoc; }
72 
73  /// Returns the ending location of the clause.
74  SourceLocation getEndLoc() const { return EndLoc; }
75 
76  /// Sets the starting location of the clause.
77  void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
78 
79  /// Sets the ending location of the clause.
80  void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
81 
82  /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
83  OpenMPClauseKind getClauseKind() const { return Kind; }
84 
85  bool isImplicit() const { return StartLoc.isInvalid(); }
86 
89  using child_range = llvm::iterator_range<child_iterator>;
90  using const_child_range = llvm::iterator_range<const_child_iterator>;
91 
94  auto Children = const_cast<OMPClause *>(this)->children();
95  return const_child_range(Children.begin(), Children.end());
96  }
97 
98  /// Get the iterator range for the expressions used in the clauses. Used
99  /// expressions include only the children that must be evaluated at the
100  /// runtime before entering the construct.
103  auto Children = const_cast<OMPClause *>(this)->children();
104  return const_child_range(Children.begin(), Children.end());
105  }
106 
107  static bool classof(const OMPClause *) { return true; }
108 };
109 
110 /// Class that handles pre-initialization statement for some clauses, like
111 /// 'shedule', 'firstprivate' etc.
113  friend class OMPClauseReader;
114 
115  /// Pre-initialization statement for the clause.
116  Stmt *PreInit = nullptr;
117 
118  /// Region that captures the associated stmt.
119  OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
120 
121 protected:
123  assert(get(This) && "get is not tuned for pre-init.");
124  }
125 
126  /// Set pre-initialization statement for the clause.
127  void
129  OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
130  PreInit = S;
131  CaptureRegion = ThisRegion;
132  }
133 
134 public:
135  /// Get pre-initialization statement for the clause.
136  const Stmt *getPreInitStmt() const { return PreInit; }
137 
138  /// Get pre-initialization statement for the clause.
139  Stmt *getPreInitStmt() { return PreInit; }
140 
141  /// Get capture region for the stmt in the clause.
142  OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
143 
145  static const OMPClauseWithPreInit *get(const OMPClause *C);
146 };
147 
148 /// Class that handles post-update expression for some clauses, like
149 /// 'lastprivate', 'reduction' etc.
151  friend class OMPClauseReader;
152 
153  /// Post-update expression for the clause.
154  Expr *PostUpdate = nullptr;
155 
156 protected:
158  assert(get(This) && "get is not tuned for post-update.");
159  }
160 
161  /// Set pre-initialization statement for the clause.
162  void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
163 
164 public:
165  /// Get post-update expression for the clause.
166  const Expr *getPostUpdateExpr() const { return PostUpdate; }
167 
168  /// Get post-update expression for the clause.
169  Expr *getPostUpdateExpr() { return PostUpdate; }
170 
172  static const OMPClauseWithPostUpdate *get(const OMPClause *C);
173 };
174 
175 /// This structure contains most locations needed for by an OMPVarListClause.
177  /// Starting location of the clause (the clause keyword).
179  /// Location of '('.
181  /// Ending location of the clause.
183  OMPVarListLocTy() = default;
187 };
188 
189 /// This represents clauses with the list of variables like 'private',
190 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
191 /// '#pragma omp ...' directives.
192 template <class T> class OMPVarListClause : public OMPClause {
193  friend class OMPClauseReader;
194 
195  /// Location of '('.
196  SourceLocation LParenLoc;
197 
198  /// Number of variables in the list.
199  unsigned NumVars;
200 
201 protected:
202  /// Build a clause with \a N variables
203  ///
204  /// \param K Kind of the clause.
205  /// \param StartLoc Starting location of the clause (the clause keyword).
206  /// \param LParenLoc Location of '('.
207  /// \param EndLoc Ending location of the clause.
208  /// \param N Number of the variables in the clause.
210  SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
211  : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
212 
213  /// Fetches list of variables associated with this clause.
216  static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
217  }
218 
219  /// Sets the list of variables for this clause.
221  assert(VL.size() == NumVars &&
222  "Number of variables is not the same as the preallocated buffer");
223  std::copy(VL.begin(), VL.end(),
224  static_cast<T *>(this)->template getTrailingObjects<Expr *>());
225  }
226 
227 public:
230  using varlist_range = llvm::iterator_range<varlist_iterator>;
231  using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
232 
233  unsigned varlist_size() const { return NumVars; }
234  bool varlist_empty() const { return NumVars == 0; }
235 
238  }
241  }
242 
243  varlist_iterator varlist_begin() { return getVarRefs().begin(); }
245  varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
246  varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
247 
248  /// Sets the location of '('.
249  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
250 
251  /// Returns the location of '('.
252  SourceLocation getLParenLoc() const { return LParenLoc; }
253 
254  /// Fetches list of all variables in the clause.
256  return llvm::makeArrayRef(
257  static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
258  NumVars);
259  }
260 };
261 
262 /// This represents 'allocator' clause in the '#pragma omp ...'
263 /// directive.
264 ///
265 /// \code
266 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
267 /// \endcode
268 /// In this example directive '#pragma omp allocate' has simple 'allocator'
269 /// clause with the allocator 'omp_default_mem_alloc'.
271  friend class OMPClauseReader;
272 
273  /// Location of '('.
274  SourceLocation LParenLoc;
275 
276  /// Expression with the allocator.
277  Stmt *Allocator = nullptr;
278 
279  /// Set allocator.
280  void setAllocator(Expr *A) { Allocator = A; }
281 
282 public:
283  /// Build 'allocator' clause with the given allocator.
284  ///
285  /// \param A Allocator.
286  /// \param StartLoc Starting location of the clause.
287  /// \param LParenLoc Location of '('.
288  /// \param EndLoc Ending location of the clause.
290  SourceLocation EndLoc)
291  : OMPClause(llvm::omp::OMPC_allocator, StartLoc, EndLoc),
292  LParenLoc(LParenLoc), Allocator(A) {}
293 
294  /// Build an empty clause.
296  : OMPClause(llvm::omp::OMPC_allocator, SourceLocation(),
297  SourceLocation()) {}
298 
299  /// Sets the location of '('.
300  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
301 
302  /// Returns the location of '('.
303  SourceLocation getLParenLoc() const { return LParenLoc; }
304 
305  /// Returns allocator.
306  Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); }
307 
308  child_range children() { return child_range(&Allocator, &Allocator + 1); }
309 
311  return const_child_range(&Allocator, &Allocator + 1);
312  }
313 
316  }
319  }
320 
321  static bool classof(const OMPClause *T) {
322  return T->getClauseKind() == llvm::omp::OMPC_allocator;
323  }
324 };
325 
326 /// This represents the 'align' clause in the '#pragma omp allocate'
327 /// directive.
328 ///
329 /// \code
330 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc) align(8)
331 /// \endcode
332 /// In this example directive '#pragma omp allocate' has simple 'allocator'
333 /// clause with the allocator 'omp_default_mem_alloc' and align clause with
334 /// value of 8.
335 class OMPAlignClause final : public OMPClause {
336  friend class OMPClauseReader;
337 
338  /// Location of '('.
339  SourceLocation LParenLoc;
340 
341  /// Alignment specified with align clause.
342  Stmt *Alignment = nullptr;
343 
344  /// Set alignment value.
345  void setAlignment(Expr *A) { Alignment = A; }
346 
347  /// Sets the location of '('.
348  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
349 
350  /// Build 'align' clause with the given alignment
351  ///
352  /// \param A Alignment value.
353  /// \param StartLoc Starting location of the clause.
354  /// \param LParenLoc Location of '('.
355  /// \param EndLoc Ending location of the clause.
356  OMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
357  SourceLocation EndLoc)
358  : OMPClause(llvm::omp::OMPC_align, StartLoc, EndLoc),
359  LParenLoc(LParenLoc), Alignment(A) {}
360 
361  /// Build an empty clause.
362  OMPAlignClause()
363  : OMPClause(llvm::omp::OMPC_align, SourceLocation(), SourceLocation()) {}
364 
365 public:
366  /// Build 'align' clause with the given alignment
367  ///
368  /// \param A Alignment value.
369  /// \param StartLoc Starting location of the clause.
370  /// \param LParenLoc Location of '('.
371  /// \param EndLoc Ending location of the clause.
372  static OMPAlignClause *Create(const ASTContext &C, Expr *A,
373  SourceLocation StartLoc,
374  SourceLocation LParenLoc,
375  SourceLocation EndLoc);
376 
377  /// Returns the location of '('.
378  SourceLocation getLParenLoc() const { return LParenLoc; }
379 
380  /// Returns alignment
381  Expr *getAlignment() const { return cast_or_null<Expr>(Alignment); }
382 
383  child_range children() { return child_range(&Alignment, &Alignment + 1); }
384 
386  return const_child_range(&Alignment, &Alignment + 1);
387  }
388 
391  }
394  }
395 
396  static bool classof(const OMPClause *T) {
397  return T->getClauseKind() == llvm::omp::OMPC_align;
398  }
399 };
400 
401 /// This represents clause 'allocate' in the '#pragma omp ...' directives.
402 ///
403 /// \code
404 /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
405 /// \endcode
406 /// In this example directive '#pragma omp parallel' has clause 'private'
407 /// and clause 'allocate' for the variable 'a'.
408 class OMPAllocateClause final
409  : public OMPVarListClause<OMPAllocateClause>,
410  private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
411  friend class OMPClauseReader;
412  friend OMPVarListClause;
413  friend TrailingObjects;
414 
415  /// Allocator specified in the clause, or 'nullptr' if the default one is
416  /// used.
417  Expr *Allocator = nullptr;
418  /// Position of the ':' delimiter in the clause;
419  SourceLocation ColonLoc;
420 
421  /// Build clause with number of variables \a N.
422  ///
423  /// \param StartLoc Starting location of the clause.
424  /// \param LParenLoc Location of '('.
425  /// \param Allocator Allocator expression.
426  /// \param ColonLoc Location of ':' delimiter.
427  /// \param EndLoc Ending location of the clause.
428  /// \param N Number of the variables in the clause.
429  OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
430  Expr *Allocator, SourceLocation ColonLoc,
431  SourceLocation EndLoc, unsigned N)
432  : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
433  LParenLoc, EndLoc, N),
434  Allocator(Allocator), ColonLoc(ColonLoc) {}
435 
436  /// Build an empty clause.
437  ///
438  /// \param N Number of variables.
439  explicit OMPAllocateClause(unsigned N)
440  : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
442  SourceLocation(), N) {}
443 
444  /// Sets location of ':' symbol in clause.
445  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
446 
447  void setAllocator(Expr *A) { Allocator = A; }
448 
449 public:
450  /// Creates clause with a list of variables \a VL.
451  ///
452  /// \param C AST context.
453  /// \param StartLoc Starting location of the clause.
454  /// \param LParenLoc Location of '('.
455  /// \param Allocator Allocator expression.
456  /// \param ColonLoc Location of ':' delimiter.
457  /// \param EndLoc Ending location of the clause.
458  /// \param VL List of references to the variables.
459  static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
460  SourceLocation LParenLoc, Expr *Allocator,
461  SourceLocation ColonLoc,
462  SourceLocation EndLoc, ArrayRef<Expr *> VL);
463 
464  /// Returns the allocator expression or nullptr, if no allocator is specified.
465  Expr *getAllocator() const { return Allocator; }
466 
467  /// Returns the location of the ':' delimiter.
468  SourceLocation getColonLoc() const { return ColonLoc; }
469 
470  /// Creates an empty clause with the place for \a N variables.
471  ///
472  /// \param C AST context.
473  /// \param N The number of variables.
474  static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
475 
477  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
478  reinterpret_cast<Stmt **>(varlist_end()));
479  }
480 
482  auto Children = const_cast<OMPAllocateClause *>(this)->children();
483  return const_child_range(Children.begin(), Children.end());
484  }
485 
488  }
491  }
492 
493  static bool classof(const OMPClause *T) {
494  return T->getClauseKind() == llvm::omp::OMPC_allocate;
495  }
496 };
497 
498 /// This represents 'if' clause in the '#pragma omp ...' directive.
499 ///
500 /// \code
501 /// #pragma omp parallel if(parallel:a > 5)
502 /// \endcode
503 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
504 /// condition 'a > 5' and directive name modifier 'parallel'.
506  friend class OMPClauseReader;
507 
508  /// Location of '('.
509  SourceLocation LParenLoc;
510 
511  /// Condition of the 'if' clause.
512  Stmt *Condition = nullptr;
513 
514  /// Location of ':' (if any).
515  SourceLocation ColonLoc;
516 
517  /// Directive name modifier for the clause.
518  OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
519 
520  /// Name modifier location.
521  SourceLocation NameModifierLoc;
522 
523  /// Set condition.
524  void setCondition(Expr *Cond) { Condition = Cond; }
525 
526  /// Set directive name modifier for the clause.
527  void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
528 
529  /// Set location of directive name modifier for the clause.
530  void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
531 
532  /// Set location of ':'.
533  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
534 
535 public:
536  /// Build 'if' clause with condition \a Cond.
537  ///
538  /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
539  /// \param Cond Condition of the clause.
540  /// \param HelperCond Helper condition for the clause.
541  /// \param CaptureRegion Innermost OpenMP region where expressions in this
542  /// clause must be captured.
543  /// \param StartLoc Starting location of the clause.
544  /// \param LParenLoc Location of '('.
545  /// \param NameModifierLoc Location of directive name modifier.
546  /// \param ColonLoc [OpenMP 4.1] Location of ':'.
547  /// \param EndLoc Ending location of the clause.
548  OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
549  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
550  SourceLocation LParenLoc, SourceLocation NameModifierLoc,
551  SourceLocation ColonLoc, SourceLocation EndLoc)
552  : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
553  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
554  ColonLoc(ColonLoc), NameModifier(NameModifier),
555  NameModifierLoc(NameModifierLoc) {
556  setPreInitStmt(HelperCond, CaptureRegion);
557  }
558 
559  /// Build an empty clause.
561  : OMPClause(llvm::omp::OMPC_if, SourceLocation(), SourceLocation()),
562  OMPClauseWithPreInit(this) {}
563 
564  /// Sets the location of '('.
565  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
566 
567  /// Returns the location of '('.
568  SourceLocation getLParenLoc() const { return LParenLoc; }
569 
570  /// Return the location of ':'.
571  SourceLocation getColonLoc() const { return ColonLoc; }
572 
573  /// Returns condition.
574  Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
575 
576  /// Return directive name modifier associated with the clause.
577  OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
578 
579  /// Return the location of directive name modifier.
580  SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
581 
583 
585  return const_child_range(&Condition, &Condition + 1);
586  }
587 
590  auto Children = const_cast<OMPIfClause *>(this)->used_children();
591  return const_child_range(Children.begin(), Children.end());
592  }
593 
594  static bool classof(const OMPClause *T) {
595  return T->getClauseKind() == llvm::omp::OMPC_if;
596  }
597 };
598 
599 /// This represents 'final' clause in the '#pragma omp ...' directive.
600 ///
601 /// \code
602 /// #pragma omp task final(a > 5)
603 /// \endcode
604 /// In this example directive '#pragma omp task' has simple 'final'
605 /// clause with condition 'a > 5'.
607  friend class OMPClauseReader;
608 
609  /// Location of '('.
610  SourceLocation LParenLoc;
611 
612  /// Condition of the 'if' clause.
613  Stmt *Condition = nullptr;
614 
615  /// Set condition.
616  void setCondition(Expr *Cond) { Condition = Cond; }
617 
618 public:
619  /// Build 'final' clause with condition \a Cond.
620  ///
621  /// \param Cond Condition of the clause.
622  /// \param HelperCond Helper condition for the construct.
623  /// \param CaptureRegion Innermost OpenMP region where expressions in this
624  /// clause must be captured.
625  /// \param StartLoc Starting location of the clause.
626  /// \param LParenLoc Location of '('.
627  /// \param EndLoc Ending location of the clause.
628  OMPFinalClause(Expr *Cond, Stmt *HelperCond,
629  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
630  SourceLocation LParenLoc, SourceLocation EndLoc)
631  : OMPClause(llvm::omp::OMPC_final, StartLoc, EndLoc),
632  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
633  setPreInitStmt(HelperCond, CaptureRegion);
634  }
635 
636  /// Build an empty clause.
638  : OMPClause(llvm::omp::OMPC_final, SourceLocation(), SourceLocation()),
639  OMPClauseWithPreInit(this) {}
640 
641  /// Sets the location of '('.
642  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
643 
644  /// Returns the location of '('.
645  SourceLocation getLParenLoc() const { return LParenLoc; }
646 
647  /// Returns condition.
648  Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
649 
651 
653  return const_child_range(&Condition, &Condition + 1);
654  }
655 
658  auto Children = const_cast<OMPFinalClause *>(this)->used_children();
659  return const_child_range(Children.begin(), Children.end());
660  }
661 
662  static bool classof(const OMPClause *T) {
663  return T->getClauseKind() == llvm::omp::OMPC_final;
664  }
665 };
666 
667 /// This represents 'num_threads' clause in the '#pragma omp ...'
668 /// directive.
669 ///
670 /// \code
671 /// #pragma omp parallel num_threads(6)
672 /// \endcode
673 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
674 /// clause with number of threads '6'.
676  friend class OMPClauseReader;
677 
678  /// Location of '('.
679  SourceLocation LParenLoc;
680 
681  /// Condition of the 'num_threads' clause.
682  Stmt *NumThreads = nullptr;
683 
684  /// Set condition.
685  void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
686 
687 public:
688  /// Build 'num_threads' clause with condition \a NumThreads.
689  ///
690  /// \param NumThreads Number of threads for the construct.
691  /// \param HelperNumThreads Helper Number of threads for the construct.
692  /// \param CaptureRegion Innermost OpenMP region where expressions in this
693  /// clause must be captured.
694  /// \param StartLoc Starting location of the clause.
695  /// \param LParenLoc Location of '('.
696  /// \param EndLoc Ending location of the clause.
697  OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
698  OpenMPDirectiveKind CaptureRegion,
699  SourceLocation StartLoc, SourceLocation LParenLoc,
700  SourceLocation EndLoc)
701  : OMPClause(llvm::omp::OMPC_num_threads, StartLoc, EndLoc),
702  OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
703  NumThreads(NumThreads) {
704  setPreInitStmt(HelperNumThreads, CaptureRegion);
705  }
706 
707  /// Build an empty clause.
709  : OMPClause(llvm::omp::OMPC_num_threads, SourceLocation(),
710  SourceLocation()),
711  OMPClauseWithPreInit(this) {}
712 
713  /// Sets the location of '('.
714  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
715 
716  /// Returns the location of '('.
717  SourceLocation getLParenLoc() const { return LParenLoc; }
718 
719  /// Returns number of threads.
720  Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
721 
722  child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
723 
725  return const_child_range(&NumThreads, &NumThreads + 1);
726  }
727 
730  }
733  }
734 
735  static bool classof(const OMPClause *T) {
736  return T->getClauseKind() == llvm::omp::OMPC_num_threads;
737  }
738 };
739 
740 /// This represents 'safelen' clause in the '#pragma omp ...'
741 /// directive.
742 ///
743 /// \code
744 /// #pragma omp simd safelen(4)
745 /// \endcode
746 /// In this example directive '#pragma omp simd' has clause 'safelen'
747 /// with single expression '4'.
748 /// If the safelen clause is used then no two iterations executed
749 /// concurrently with SIMD instructions can have a greater distance
750 /// in the logical iteration space than its value. The parameter of
751 /// the safelen clause must be a constant positive integer expression.
752 class OMPSafelenClause : public OMPClause {
753  friend class OMPClauseReader;
754 
755  /// Location of '('.
756  SourceLocation LParenLoc;
757 
758  /// Safe iteration space distance.
759  Stmt *Safelen = nullptr;
760 
761  /// Set safelen.
762  void setSafelen(Expr *Len) { Safelen = Len; }
763 
764 public:
765  /// Build 'safelen' clause.
766  ///
767  /// \param Len Expression associated with this clause.
768  /// \param StartLoc Starting location of the clause.
769  /// \param EndLoc Ending location of the clause.
771  SourceLocation EndLoc)
772  : OMPClause(llvm::omp::OMPC_safelen, StartLoc, EndLoc),
773  LParenLoc(LParenLoc), Safelen(Len) {}
774 
775  /// Build an empty clause.
776  explicit OMPSafelenClause()
777  : OMPClause(llvm::omp::OMPC_safelen, SourceLocation(), SourceLocation()) {
778  }
779 
780  /// Sets the location of '('.
781  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
782 
783  /// Returns the location of '('.
784  SourceLocation getLParenLoc() const { return LParenLoc; }
785 
786  /// Return safe iteration space distance.
787  Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
788 
789  child_range children() { return child_range(&Safelen, &Safelen + 1); }
790 
792  return const_child_range(&Safelen, &Safelen + 1);
793  }
794 
797  }
800  }
801 
802  static bool classof(const OMPClause *T) {
803  return T->getClauseKind() == llvm::omp::OMPC_safelen;
804  }
805 };
806 
807 /// This represents 'simdlen' clause in the '#pragma omp ...'
808 /// directive.
809 ///
810 /// \code
811 /// #pragma omp simd simdlen(4)
812 /// \endcode
813 /// In this example directive '#pragma omp simd' has clause 'simdlen'
814 /// with single expression '4'.
815 /// If the 'simdlen' clause is used then it specifies the preferred number of
816 /// iterations to be executed concurrently. The parameter of the 'simdlen'
817 /// clause must be a constant positive integer expression.
818 class OMPSimdlenClause : public OMPClause {
819  friend class OMPClauseReader;
820 
821  /// Location of '('.
822  SourceLocation LParenLoc;
823 
824  /// Safe iteration space distance.
825  Stmt *Simdlen = nullptr;
826 
827  /// Set simdlen.
828  void setSimdlen(Expr *Len) { Simdlen = Len; }
829 
830 public:
831  /// Build 'simdlen' clause.
832  ///
833  /// \param Len Expression associated with this clause.
834  /// \param StartLoc Starting location of the clause.
835  /// \param EndLoc Ending location of the clause.
837  SourceLocation EndLoc)
838  : OMPClause(llvm::omp::OMPC_simdlen, StartLoc, EndLoc),
839  LParenLoc(LParenLoc), Simdlen(Len) {}
840 
841  /// Build an empty clause.
842  explicit OMPSimdlenClause()
843  : OMPClause(llvm::omp::OMPC_simdlen, SourceLocation(), SourceLocation()) {
844  }
845 
846  /// Sets the location of '('.
847  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
848 
849  /// Returns the location of '('.
850  SourceLocation getLParenLoc() const { return LParenLoc; }
851 
852  /// Return safe iteration space distance.
853  Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
854 
855  child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
856 
858  return const_child_range(&Simdlen, &Simdlen + 1);
859  }
860 
863  }
866  }
867 
868  static bool classof(const OMPClause *T) {
869  return T->getClauseKind() == llvm::omp::OMPC_simdlen;
870  }
871 };
872 
873 /// This represents the 'sizes' clause in the '#pragma omp tile' directive.
874 ///
875 /// \code
876 /// #pragma omp tile sizes(5,5)
877 /// for (int i = 0; i < 64; ++i)
878 /// for (int j = 0; j < 64; ++j)
879 /// \endcode
880 class OMPSizesClause final
881  : public OMPClause,
882  private llvm::TrailingObjects<OMPSizesClause, Expr *> {
883  friend class OMPClauseReader;
884  friend class llvm::TrailingObjects<OMPSizesClause, Expr *>;
885 
886  /// Location of '('.
887  SourceLocation LParenLoc;
888 
889  /// Number of tile sizes in the clause.
890  unsigned NumSizes;
891 
892  /// Build an empty clause.
893  explicit OMPSizesClause(int NumSizes)
894  : OMPClause(llvm::omp::OMPC_sizes, SourceLocation(), SourceLocation()),
895  NumSizes(NumSizes) {}
896 
897 public:
898  /// Build a 'sizes' AST node.
899  ///
900  /// \param C Context of the AST.
901  /// \param StartLoc Location of the 'sizes' identifier.
902  /// \param LParenLoc Location of '('.
903  /// \param EndLoc Location of ')'.
904  /// \param Sizes Content of the clause.
905  static OMPSizesClause *Create(const ASTContext &C, SourceLocation StartLoc,
906  SourceLocation LParenLoc, SourceLocation EndLoc,
907  ArrayRef<Expr *> Sizes);
908 
909  /// Build an empty 'sizes' AST node for deserialization.
910  ///
911  /// \param C Context of the AST.
912  /// \param NumSizes Number of items in the clause.
913  static OMPSizesClause *CreateEmpty(const ASTContext &C, unsigned NumSizes);
914 
915  /// Sets the location of '('.
916  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
917 
918  /// Returns the location of '('.
919  SourceLocation getLParenLoc() const { return LParenLoc; }
920 
921  /// Returns the number of list items.
922  unsigned getNumSizes() const { return NumSizes; }
923 
924  /// Returns the tile size expressions.
926  return MutableArrayRef<Expr *>(static_cast<OMPSizesClause *>(this)
927  ->template getTrailingObjects<Expr *>(),
928  NumSizes);
929  }
931  return ArrayRef<Expr *>(static_cast<const OMPSizesClause *>(this)
932  ->template getTrailingObjects<Expr *>(),
933  NumSizes);
934  }
935 
936  /// Sets the tile size expressions.
938  assert(VL.size() == NumSizes);
939  std::copy(VL.begin(), VL.end(),
940  static_cast<OMPSizesClause *>(this)
941  ->template getTrailingObjects<Expr *>());
942  }
943 
946  return child_range(reinterpret_cast<Stmt **>(Sizes.begin()),
947  reinterpret_cast<Stmt **>(Sizes.end()));
948  }
950  ArrayRef<Expr *> Sizes = getSizesRefs();
951  return const_child_range(reinterpret_cast<Stmt *const *>(Sizes.begin()),
952  reinterpret_cast<Stmt *const *>(Sizes.end()));
953  }
954 
957  }
960  }
961 
962  static bool classof(const OMPClause *T) {
963  return T->getClauseKind() == llvm::omp::OMPC_sizes;
964  }
965 };
966 
967 /// Representation of the 'full' clause of the '#pragma omp unroll' directive.
968 ///
969 /// \code
970 /// #pragma omp unroll full
971 /// for (int i = 0; i < 64; ++i)
972 /// \endcode
973 class OMPFullClause final : public OMPClause {
974  friend class OMPClauseReader;
975 
976  /// Build an empty clause.
977  explicit OMPFullClause() : OMPClause(llvm::omp::OMPC_full, {}, {}) {}
978 
979 public:
980  /// Build an AST node for a 'full' clause.
981  ///
982  /// \param C Context of the AST.
983  /// \param StartLoc Starting location of the clause.
984  /// \param EndLoc Ending location of the clause.
985  static OMPFullClause *Create(const ASTContext &C, SourceLocation StartLoc,
986  SourceLocation EndLoc);
987 
988  /// Build an empty 'full' AST node for deserialization.
989  ///
990  /// \param C Context of the AST.
991  static OMPFullClause *CreateEmpty(const ASTContext &C);
992 
996  }
997 
1000  }
1003  }
1004 
1005  static bool classof(const OMPClause *T) {
1006  return T->getClauseKind() == llvm::omp::OMPC_full;
1007  }
1008 };
1009 
1010 /// Representation of the 'partial' clause of the '#pragma omp unroll'
1011 /// directive.
1012 ///
1013 /// \code
1014 /// #pragma omp unroll partial(4)
1015 /// for (int i = start; i < end; ++i)
1016 /// \endcode
1017 class OMPPartialClause final : public OMPClause {
1018  friend class OMPClauseReader;
1019 
1020  /// Location of '('.
1021  SourceLocation LParenLoc;
1022 
1023  /// Optional argument to the clause (unroll factor).
1024  Stmt *Factor;
1025 
1026  /// Build an empty clause.
1027  explicit OMPPartialClause() : OMPClause(llvm::omp::OMPC_partial, {}, {}) {}
1028 
1029  /// Set the unroll factor.
1030  void setFactor(Expr *E) { Factor = E; }
1031 
1032  /// Sets the location of '('.
1033  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1034 
1035 public:
1036  /// Build an AST node for a 'partial' clause.
1037  ///
1038  /// \param C Context of the AST.
1039  /// \param StartLoc Location of the 'partial' identifier.
1040  /// \param LParenLoc Location of '('.
1041  /// \param EndLoc Location of ')'.
1042  /// \param Factor Clause argument.
1043  static OMPPartialClause *Create(const ASTContext &C, SourceLocation StartLoc,
1044  SourceLocation LParenLoc,
1045  SourceLocation EndLoc, Expr *Factor);
1046 
1047  /// Build an empty 'partial' AST node for deserialization.
1048  ///
1049  /// \param C Context of the AST.
1050  static OMPPartialClause *CreateEmpty(const ASTContext &C);
1051 
1052  /// Returns the location of '('.
1053  SourceLocation getLParenLoc() const { return LParenLoc; }
1054 
1055  /// Returns the argument of the clause or nullptr if not set.
1056  Expr *getFactor() const { return cast_or_null<Expr>(Factor); }
1057 
1058  child_range children() { return child_range(&Factor, &Factor + 1); }
1060  return const_child_range(&Factor, &Factor + 1);
1061  }
1062 
1065  }
1068  }
1069 
1070  static bool classof(const OMPClause *T) {
1071  return T->getClauseKind() == llvm::omp::OMPC_partial;
1072  }
1073 };
1074 
1075 /// This represents 'collapse' clause in the '#pragma omp ...'
1076 /// directive.
1077 ///
1078 /// \code
1079 /// #pragma omp simd collapse(3)
1080 /// \endcode
1081 /// In this example directive '#pragma omp simd' has clause 'collapse'
1082 /// with single expression '3'.
1083 /// The parameter must be a constant positive integer expression, it specifies
1084 /// the number of nested loops that should be collapsed into a single iteration
1085 /// space.
1087  friend class OMPClauseReader;
1088 
1089  /// Location of '('.
1090  SourceLocation LParenLoc;
1091 
1092  /// Number of for-loops.
1093  Stmt *NumForLoops = nullptr;
1094 
1095  /// Set the number of associated for-loops.
1096  void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1097 
1098 public:
1099  /// Build 'collapse' clause.
1100  ///
1101  /// \param Num Expression associated with this clause.
1102  /// \param StartLoc Starting location of the clause.
1103  /// \param LParenLoc Location of '('.
1104  /// \param EndLoc Ending location of the clause.
1106  SourceLocation LParenLoc, SourceLocation EndLoc)
1107  : OMPClause(llvm::omp::OMPC_collapse, StartLoc, EndLoc),
1108  LParenLoc(LParenLoc), NumForLoops(Num) {}
1109 
1110  /// Build an empty clause.
1112  : OMPClause(llvm::omp::OMPC_collapse, SourceLocation(),
1113  SourceLocation()) {}
1114 
1115  /// Sets the location of '('.
1116  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1117 
1118  /// Returns the location of '('.
1119  SourceLocation getLParenLoc() const { return LParenLoc; }
1120 
1121  /// Return the number of associated for-loops.
1122  Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1123 
1124  child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1125 
1127  return const_child_range(&NumForLoops, &NumForLoops + 1);
1128  }
1129 
1132  }
1135  }
1136 
1137  static bool classof(const OMPClause *T) {
1138  return T->getClauseKind() == llvm::omp::OMPC_collapse;
1139  }
1140 };
1141 
1142 /// This represents 'default' clause in the '#pragma omp ...' directive.
1143 ///
1144 /// \code
1145 /// #pragma omp parallel default(shared)
1146 /// \endcode
1147 /// In this example directive '#pragma omp parallel' has simple 'default'
1148 /// clause with kind 'shared'.
1149 class OMPDefaultClause : public OMPClause {
1150  friend class OMPClauseReader;
1151 
1152  /// Location of '('.
1153  SourceLocation LParenLoc;
1154 
1155  /// A kind of the 'default' clause.
1156  llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
1157 
1158  /// Start location of the kind in source code.
1159  SourceLocation KindKwLoc;
1160 
1161  /// Set kind of the clauses.
1162  ///
1163  /// \param K Argument of clause.
1164  void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
1165 
1166  /// Set argument location.
1167  ///
1168  /// \param KLoc Argument location.
1169  void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1170 
1171 public:
1172  /// Build 'default' clause with argument \a A ('none' or 'shared').
1173  ///
1174  /// \param A Argument of the clause ('none' or 'shared').
1175  /// \param ALoc Starting location of the argument.
1176  /// \param StartLoc Starting location of the clause.
1177  /// \param LParenLoc Location of '('.
1178  /// \param EndLoc Ending location of the clause.
1179  OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
1180  SourceLocation StartLoc, SourceLocation LParenLoc,
1181  SourceLocation EndLoc)
1182  : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
1183  LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1184 
1185  /// Build an empty clause.
1187  : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
1188  }
1189 
1190  /// Sets the location of '('.
1191  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1192 
1193  /// Returns the location of '('.
1194  SourceLocation getLParenLoc() const { return LParenLoc; }
1195 
1196  /// Returns kind of the clause.
1197  llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
1198 
1199  /// Returns location of clause kind.
1200  SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
1201 
1204  }
1205 
1208  }
1209 
1212  }
1215  }
1216 
1217  static bool classof(const OMPClause *T) {
1218  return T->getClauseKind() == llvm::omp::OMPC_default;
1219  }
1220 };
1221 
1222 /// This represents 'proc_bind' clause in the '#pragma omp ...'
1223 /// directive.
1224 ///
1225 /// \code
1226 /// #pragma omp parallel proc_bind(master)
1227 /// \endcode
1228 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
1229 /// clause with kind 'master'.
1231  friend class OMPClauseReader;
1232 
1233  /// Location of '('.
1234  SourceLocation LParenLoc;
1235 
1236  /// A kind of the 'proc_bind' clause.
1237  llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
1238 
1239  /// Start location of the kind in source code.
1240  SourceLocation KindKwLoc;
1241 
1242  /// Set kind of the clause.
1243  ///
1244  /// \param K Kind of clause.
1245  void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
1246 
1247  /// Set clause kind location.
1248  ///
1249  /// \param KLoc Kind location.
1250  void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1251 
1252 public:
1253  /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
1254  /// 'spread').
1255  ///
1256  /// \param A Argument of the clause ('master', 'close' or 'spread').
1257  /// \param ALoc Starting location of the argument.
1258  /// \param StartLoc Starting location of the clause.
1259  /// \param LParenLoc Location of '('.
1260  /// \param EndLoc Ending location of the clause.
1261  OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
1262  SourceLocation StartLoc, SourceLocation LParenLoc,
1263  SourceLocation EndLoc)
1264  : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
1265  LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1266 
1267  /// Build an empty clause.
1269  : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
1270  SourceLocation()) {}
1271 
1272  /// Sets the location of '('.
1273  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1274 
1275  /// Returns the location of '('.
1276  SourceLocation getLParenLoc() const { return LParenLoc; }
1277 
1278  /// Returns kind of the clause.
1279  llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
1280 
1281  /// Returns location of clause kind.
1282  SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
1283 
1286  }
1287 
1290  }
1291 
1294  }
1297  }
1298 
1299  static bool classof(const OMPClause *T) {
1300  return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
1301  }
1302 };
1303 
1304 /// This represents 'unified_address' clause in the '#pragma omp requires'
1305 /// directive.
1306 ///
1307 /// \code
1308 /// #pragma omp requires unified_address
1309 /// \endcode
1310 /// In this example directive '#pragma omp requires' has 'unified_address'
1311 /// clause.
1312 class OMPUnifiedAddressClause final : public OMPClause {
1313 public:
1314  friend class OMPClauseReader;
1315  /// Build 'unified_address' clause.
1316  ///
1317  /// \param StartLoc Starting location of the clause.
1318  /// \param EndLoc Ending location of the clause.
1320  : OMPClause(llvm::omp::OMPC_unified_address, StartLoc, EndLoc) {}
1321 
1322  /// Build an empty clause.
1324  : OMPClause(llvm::omp::OMPC_unified_address, SourceLocation(),
1325  SourceLocation()) {}
1326 
1329  }
1330 
1333  }
1334 
1337  }
1340  }
1341 
1342  static bool classof(const OMPClause *T) {
1343  return T->getClauseKind() == llvm::omp::OMPC_unified_address;
1344  }
1345 };
1346 
1347 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1348 /// directive.
1349 ///
1350 /// \code
1351 /// #pragma omp requires unified_shared_memory
1352 /// \endcode
1353 /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1354 /// clause.
1356 public:
1357  friend class OMPClauseReader;
1358  /// Build 'unified_shared_memory' clause.
1359  ///
1360  /// \param StartLoc Starting location of the clause.
1361  /// \param EndLoc Ending location of the clause.
1363  : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1364 
1365  /// Build an empty clause.
1367  : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
1368  SourceLocation()) {}
1369 
1372  }
1373 
1376  }
1377 
1380  }
1383  }
1384 
1385  static bool classof(const OMPClause *T) {
1386  return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
1387  }
1388 };
1389 
1390 /// This represents 'reverse_offload' clause in the '#pragma omp requires'
1391 /// directive.
1392 ///
1393 /// \code
1394 /// #pragma omp requires reverse_offload
1395 /// \endcode
1396 /// In this example directive '#pragma omp requires' has 'reverse_offload'
1397 /// clause.
1398 class OMPReverseOffloadClause final : public OMPClause {
1399 public:
1400  friend class OMPClauseReader;
1401  /// Build 'reverse_offload' clause.
1402  ///
1403  /// \param StartLoc Starting location of the clause.
1404  /// \param EndLoc Ending location of the clause.
1406  : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
1407 
1408  /// Build an empty clause.
1410  : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
1411  SourceLocation()) {}
1412 
1415  }
1416 
1419  }
1420 
1423  }
1426  }
1427 
1428  static bool classof(const OMPClause *T) {
1429  return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
1430  }
1431 };
1432 
1433 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1434 /// directive.
1435 ///
1436 /// \code
1437 /// #pragma omp requires dynamic_allocators
1438 /// \endcode
1439 /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1440 /// clause.
1442 public:
1443  friend class OMPClauseReader;
1444  /// Build 'dynamic_allocators' clause.
1445  ///
1446  /// \param StartLoc Starting location of the clause.
1447  /// \param EndLoc Ending location of the clause.
1449  : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1450 
1451  /// Build an empty clause.
1453  : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
1454  SourceLocation()) {}
1455 
1458  }
1459 
1462  }
1463 
1466  }
1469  }
1470 
1471  static bool classof(const OMPClause *T) {
1472  return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
1473  }
1474 };
1475 
1476 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1477 /// requires' directive.
1478 ///
1479 /// \code
1480 /// #pragma omp requires atomic_default_mem_order(seq_cst)
1481 /// \endcode
1482 /// In this example directive '#pragma omp requires' has simple
1483 /// atomic_default_mem_order' clause with kind 'seq_cst'.
1485  friend class OMPClauseReader;
1486 
1487  /// Location of '('
1488  SourceLocation LParenLoc;
1489 
1490  /// A kind of the 'atomic_default_mem_order' clause.
1493 
1494  /// Start location of the kind in source code.
1495  SourceLocation KindKwLoc;
1496 
1497  /// Set kind of the clause.
1498  ///
1499  /// \param K Kind of clause.
1500  void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1501  Kind = K;
1502  }
1503 
1504  /// Set clause kind location.
1505  ///
1506  /// \param KLoc Kind location.
1507  void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1508  KindKwLoc = KLoc;
1509  }
1510 
1511 public:
1512  /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1513  /// 'acq_rel' or 'relaxed').
1514  ///
1515  /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1516  /// \param ALoc Starting location of the argument.
1517  /// \param StartLoc Starting location of the clause.
1518  /// \param LParenLoc Location of '('.
1519  /// \param EndLoc Ending location of the clause.
1521  SourceLocation ALoc, SourceLocation StartLoc,
1522  SourceLocation LParenLoc,
1523  SourceLocation EndLoc)
1524  : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1525  LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1526 
1527  /// Build an empty clause.
1529  : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
1530  SourceLocation()) {}
1531 
1532  /// Sets the location of '('.
1533  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1534 
1535  /// Returns the locaiton of '('.
1536  SourceLocation getLParenLoc() const { return LParenLoc; }
1537 
1538  /// Returns kind of the clause.
1540  return Kind;
1541  }
1542 
1543  /// Returns location of clause kind.
1545 
1548  }
1549 
1552  }
1553 
1556  }
1559  }
1560 
1561  static bool classof(const OMPClause *T) {
1562  return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
1563  }
1564 };
1565 
1566 /// This represents 'at' clause in the '#pragma omp error' directive
1567 ///
1568 /// \code
1569 /// #pragma omp error at(compilation)
1570 /// \endcode
1571 /// In this example directive '#pragma omp error' has simple
1572 /// 'at' clause with kind 'complilation'.
1573 class OMPAtClause final : public OMPClause {
1574  friend class OMPClauseReader;
1575 
1576  /// Location of '('
1577  SourceLocation LParenLoc;
1578 
1579  /// A kind of the 'at' clause.
1581 
1582  /// Start location of the kind in source code.
1583  SourceLocation KindKwLoc;
1584 
1585  /// Set kind of the clause.
1586  ///
1587  /// \param K Kind of clause.
1588  void setAtKind(OpenMPAtClauseKind K) { Kind = K; }
1589 
1590  /// Set clause kind location.
1591  ///
1592  /// \param KLoc Kind location.
1593  void setAtKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1594 
1595  /// Sets the location of '('.
1596  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1597 
1598 public:
1599  /// Build 'at' clause with argument \a A ('compilation' or 'execution').
1600  ///
1601  /// \param A Argument of the clause ('compilation' or 'execution').
1602  /// \param ALoc Starting location of the argument.
1603  /// \param StartLoc Starting location of the clause.
1604  /// \param LParenLoc Location of '('.
1605  /// \param EndLoc Ending location of the clause.
1607  SourceLocation StartLoc, SourceLocation LParenLoc,
1608  SourceLocation EndLoc)
1609  : OMPClause(llvm::omp::OMPC_at, StartLoc, EndLoc), LParenLoc(LParenLoc),
1610  Kind(A), KindKwLoc(ALoc) {}
1611 
1612  /// Build an empty clause.
1614  : OMPClause(llvm::omp::OMPC_at, SourceLocation(), SourceLocation()) {}
1615 
1616  /// Returns the locaiton of '('.
1617  SourceLocation getLParenLoc() const { return LParenLoc; }
1618 
1619  /// Returns kind of the clause.
1620  OpenMPAtClauseKind getAtKind() const { return Kind; }
1621 
1622  /// Returns location of clause kind.
1623  SourceLocation getAtKindKwLoc() const { return KindKwLoc; }
1624 
1627  }
1628 
1631  }
1632 
1635  }
1638  }
1639 
1640  static bool classof(const OMPClause *T) {
1641  return T->getClauseKind() == llvm::omp::OMPC_at;
1642  }
1643 };
1644 
1645 /// This represents 'severity' clause in the '#pragma omp error' directive
1646 ///
1647 /// \code
1648 /// #pragma omp error severity(fatal)
1649 /// \endcode
1650 /// In this example directive '#pragma omp error' has simple
1651 /// 'severity' clause with kind 'fatal'.
1652 class OMPSeverityClause final : public OMPClause {
1653  friend class OMPClauseReader;
1654 
1655  /// Location of '('
1656  SourceLocation LParenLoc;
1657 
1658  /// A kind of the 'severity' clause.
1660 
1661  /// Start location of the kind in source code.
1662  SourceLocation KindKwLoc;
1663 
1664  /// Set kind of the clause.
1665  ///
1666  /// \param K Kind of clause.
1667  void setSeverityKind(OpenMPSeverityClauseKind K) { Kind = K; }
1668 
1669  /// Set clause kind location.
1670  ///
1671  /// \param KLoc Kind location.
1672  void setSeverityKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1673 
1674  /// Sets the location of '('.
1675  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1676 
1677 public:
1678  /// Build 'severity' clause with argument \a A ('fatal' or 'warning').
1679  ///
1680  /// \param A Argument of the clause ('fatal' or 'warning').
1681  /// \param ALoc Starting location of the argument.
1682  /// \param StartLoc Starting location of the clause.
1683  /// \param LParenLoc Location of '('.
1684  /// \param EndLoc Ending location of the clause.
1686  SourceLocation StartLoc, SourceLocation LParenLoc,
1687  SourceLocation EndLoc)
1688  : OMPClause(llvm::omp::OMPC_severity, StartLoc, EndLoc),
1689  LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1690 
1691  /// Build an empty clause.
1693  : OMPClause(llvm::omp::OMPC_severity, SourceLocation(),
1694  SourceLocation()) {}
1695 
1696  /// Returns the locaiton of '('.
1697  SourceLocation getLParenLoc() const { return LParenLoc; }
1698 
1699  /// Returns kind of the clause.
1701 
1702  /// Returns location of clause kind.
1703  SourceLocation getSeverityKindKwLoc() const { return KindKwLoc; }
1704 
1707  }
1708 
1711  }
1712 
1715  }
1718  }
1719 
1720  static bool classof(const OMPClause *T) {
1721  return T->getClauseKind() == llvm::omp::OMPC_severity;
1722  }
1723 };
1724 
1725 /// This represents 'message' clause in the '#pragma omp error' directive
1726 ///
1727 /// \code
1728 /// #pragma omp error message("GNU compiler required.")
1729 /// \endcode
1730 /// In this example directive '#pragma omp error' has simple
1731 /// 'message' clause with user error message of "GNU compiler required.".
1732 class OMPMessageClause final : public OMPClause {
1733  friend class OMPClauseReader;
1734 
1735  /// Location of '('
1736  SourceLocation LParenLoc;
1737 
1738  // Expression of the 'message' clause.
1739  Stmt *MessageString = nullptr;
1740 
1741  /// Set message string of the clause.
1742  void setMessageString(Expr *MS) { MessageString = MS; }
1743 
1744  /// Sets the location of '('.
1745  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1746 
1747 public:
1748  /// Build 'message' clause with message string argument
1749  ///
1750  /// \param A Argument of the clause (message string).
1751  /// \param StartLoc Starting location of the clause.
1752  /// \param LParenLoc Location of '('.
1753  /// \param EndLoc Ending location of the clause.
1755  SourceLocation EndLoc)
1756  : OMPClause(llvm::omp::OMPC_message, StartLoc, EndLoc),
1757  LParenLoc(LParenLoc), MessageString(MS) {}
1758 
1759  /// Build an empty clause.
1761  : OMPClause(llvm::omp::OMPC_message, SourceLocation(), SourceLocation()) {
1762  }
1763 
1764  /// Returns the locaiton of '('.
1765  SourceLocation getLParenLoc() const { return LParenLoc; }
1766 
1767  /// Returns message string of the clause.
1768  Expr *getMessageString() const { return cast_or_null<Expr>(MessageString); }
1769 
1771  return child_range(&MessageString, &MessageString + 1);
1772  }
1773 
1775  return const_child_range(&MessageString, &MessageString + 1);
1776  }
1777 
1780  }
1781 
1784  }
1785 
1786  static bool classof(const OMPClause *T) {
1787  return T->getClauseKind() == llvm::omp::OMPC_message;
1788  }
1789 };
1790 
1791 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
1792 ///
1793 /// \code
1794 /// #pragma omp for schedule(static, 3)
1795 /// \endcode
1796 /// In this example directive '#pragma omp for' has 'schedule' clause with
1797 /// arguments 'static' and '3'.
1799  friend class OMPClauseReader;
1800 
1801  /// Location of '('.
1802  SourceLocation LParenLoc;
1803 
1804  /// A kind of the 'schedule' clause.
1806 
1807  /// Modifiers for 'schedule' clause.
1808  enum {FIRST, SECOND, NUM_MODIFIERS};
1809  OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1810 
1811  /// Locations of modifiers.
1812  SourceLocation ModifiersLoc[NUM_MODIFIERS];
1813 
1814  /// Start location of the schedule ind in source code.
1815  SourceLocation KindLoc;
1816 
1817  /// Location of ',' (if any).
1818  SourceLocation CommaLoc;
1819 
1820  /// Chunk size.
1821  Expr *ChunkSize = nullptr;
1822 
1823  /// Set schedule kind.
1824  ///
1825  /// \param K Schedule kind.
1826  void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1827 
1828  /// Set the first schedule modifier.
1829  ///
1830  /// \param M Schedule modifier.
1831  void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1832  Modifiers[FIRST] = M;
1833  }
1834 
1835  /// Set the second schedule modifier.
1836  ///
1837  /// \param M Schedule modifier.
1838  void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1839  Modifiers[SECOND] = M;
1840  }
1841 
1842  /// Set location of the first schedule modifier.
1843  void setFirstScheduleModifierLoc(SourceLocation Loc) {
1844  ModifiersLoc[FIRST] = Loc;
1845  }
1846 
1847  /// Set location of the second schedule modifier.
1848  void setSecondScheduleModifierLoc(SourceLocation Loc) {
1849  ModifiersLoc[SECOND] = Loc;
1850  }
1851 
1852  /// Set schedule modifier location.
1853  ///
1854  /// \param M Schedule modifier location.
1855  void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1856  if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1857  Modifiers[FIRST] = M;
1858  else {
1859  assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1860  Modifiers[SECOND] = M;
1861  }
1862  }
1863 
1864  /// Sets the location of '('.
1865  ///
1866  /// \param Loc Location of '('.
1867  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1868 
1869  /// Set schedule kind start location.
1870  ///
1871  /// \param KLoc Schedule kind location.
1872  void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1873 
1874  /// Set location of ','.
1875  ///
1876  /// \param Loc Location of ','.
1877  void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1878 
1879  /// Set chunk size.
1880  ///
1881  /// \param E Chunk size.
1882  void setChunkSize(Expr *E) { ChunkSize = E; }
1883 
1884 public:
1885  /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1886  /// expression \a ChunkSize.
1887  ///
1888  /// \param StartLoc Starting location of the clause.
1889  /// \param LParenLoc Location of '('.
1890  /// \param KLoc Starting location of the argument.
1891  /// \param CommaLoc Location of ','.
1892  /// \param EndLoc Ending location of the clause.
1893  /// \param Kind Schedule kind.
1894  /// \param ChunkSize Chunk size.
1895  /// \param HelperChunkSize Helper chunk size for combined directives.
1896  /// \param M1 The first modifier applied to 'schedule' clause.
1897  /// \param M1Loc Location of the first modifier
1898  /// \param M2 The second modifier applied to 'schedule' clause.
1899  /// \param M2Loc Location of the second modifier
1901  SourceLocation KLoc, SourceLocation CommaLoc,
1903  Expr *ChunkSize, Stmt *HelperChunkSize,
1906  : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
1907  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
1908  KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
1909  setPreInitStmt(HelperChunkSize);
1910  Modifiers[FIRST] = M1;
1911  Modifiers[SECOND] = M2;
1912  ModifiersLoc[FIRST] = M1Loc;
1913  ModifiersLoc[SECOND] = M2Loc;
1914  }
1915 
1916  /// Build an empty clause.
1918  : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
1919  OMPClauseWithPreInit(this) {
1920  Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1921  Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1922  }
1923 
1924  /// Get kind of the clause.
1926 
1927  /// Get the first modifier of the clause.
1929  return Modifiers[FIRST];
1930  }
1931 
1932  /// Get the second modifier of the clause.
1934  return Modifiers[SECOND];
1935  }
1936 
1937  /// Get location of '('.
1938  SourceLocation getLParenLoc() { return LParenLoc; }
1939 
1940  /// Get kind location.
1941  SourceLocation getScheduleKindLoc() { return KindLoc; }
1942 
1943  /// Get the first modifier location.
1945  return ModifiersLoc[FIRST];
1946  }
1947 
1948  /// Get the second modifier location.
1950  return ModifiersLoc[SECOND];
1951  }
1952 
1953  /// Get location of ','.
1954  SourceLocation getCommaLoc() { return CommaLoc; }
1955 
1956  /// Get chunk size.
1957  Expr *getChunkSize() { return ChunkSize; }
1958 
1959  /// Get chunk size.
1960  const Expr *getChunkSize() const { return ChunkSize; }
1961 
1963  return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1964  reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1965  }
1966 
1968  auto Children = const_cast<OMPScheduleClause *>(this)->children();
1969  return const_child_range(Children.begin(), Children.end());
1970  }
1971 
1974  }
1977  }
1978 
1979  static bool classof(const OMPClause *T) {
1980  return T->getClauseKind() == llvm::omp::OMPC_schedule;
1981  }
1982 };
1983 
1984 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1985 ///
1986 /// \code
1987 /// #pragma omp for ordered (2)
1988 /// \endcode
1989 /// In this example directive '#pragma omp for' has 'ordered' clause with
1990 /// parameter 2.
1991 class OMPOrderedClause final
1992  : public OMPClause,
1993  private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1994  friend class OMPClauseReader;
1995  friend TrailingObjects;
1996 
1997  /// Location of '('.
1998  SourceLocation LParenLoc;
1999 
2000  /// Number of for-loops.
2001  Stmt *NumForLoops = nullptr;
2002 
2003  /// Real number of loops.
2004  unsigned NumberOfLoops = 0;
2005 
2006  /// Build 'ordered' clause.
2007  ///
2008  /// \param Num Expression, possibly associated with this clause.
2009  /// \param NumLoops Number of loops, associated with this clause.
2010  /// \param StartLoc Starting location of the clause.
2011  /// \param LParenLoc Location of '('.
2012  /// \param EndLoc Ending location of the clause.
2013  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
2014  SourceLocation LParenLoc, SourceLocation EndLoc)
2015  : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
2016  LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
2017 
2018  /// Build an empty clause.
2019  explicit OMPOrderedClause(unsigned NumLoops)
2020  : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
2021  NumberOfLoops(NumLoops) {}
2022 
2023  /// Set the number of associated for-loops.
2024  void setNumForLoops(Expr *Num) { NumForLoops = Num; }
2025 
2026 public:
2027  /// Build 'ordered' clause.
2028  ///
2029  /// \param Num Expression, possibly associated with this clause.
2030  /// \param NumLoops Number of loops, associated with this clause.
2031  /// \param StartLoc Starting location of the clause.
2032  /// \param LParenLoc Location of '('.
2033  /// \param EndLoc Ending location of the clause.
2034  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
2035  unsigned NumLoops, SourceLocation StartLoc,
2036  SourceLocation LParenLoc,
2037  SourceLocation EndLoc);
2038 
2039  /// Build an empty clause.
2040  static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
2041 
2042  /// Sets the location of '('.
2043  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2044 
2045  /// Returns the location of '('.
2046  SourceLocation getLParenLoc() const { return LParenLoc; }
2047 
2048  /// Return the number of associated for-loops.
2049  Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
2050 
2051  /// Set number of iterations for the specified loop.
2052  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
2053  /// Get number of iterations for all the loops.
2055 
2056  /// Set loop counter for the specified loop.
2057  void setLoopCounter(unsigned NumLoop, Expr *Counter);
2058  /// Get loops counter for the specified loop.
2059  Expr *getLoopCounter(unsigned NumLoop);
2060  const Expr *getLoopCounter(unsigned NumLoop) const;
2061 
2062  child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
2063 
2065  return const_child_range(&NumForLoops, &NumForLoops + 1);
2066  }
2067 
2070  }
2073  }
2074 
2075  static bool classof(const OMPClause *T) {
2076  return T->getClauseKind() == llvm::omp::OMPC_ordered;
2077  }
2078 };
2079 
2080 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
2081 ///
2082 /// \code
2083 /// #pragma omp for nowait
2084 /// \endcode
2085 /// In this example directive '#pragma omp for' has 'nowait' clause.
2086 class OMPNowaitClause : public OMPClause {
2087 public:
2088  /// Build 'nowait' clause.
2089  ///
2090  /// \param StartLoc Starting location of the clause.
2091  /// \param EndLoc Ending location of the clause.
2093  : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc) {}
2094 
2095  /// Build an empty clause.
2097  : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {}
2098 
2101  }
2102 
2105  }
2106 
2109  }
2112  }
2113 
2114  static bool classof(const OMPClause *T) {
2115  return T->getClauseKind() == llvm::omp::OMPC_nowait;
2116  }
2117 };
2118 
2119 /// This represents 'untied' clause in the '#pragma omp ...' directive.
2120 ///
2121 /// \code
2122 /// #pragma omp task untied
2123 /// \endcode
2124 /// In this example directive '#pragma omp task' has 'untied' clause.
2125 class OMPUntiedClause : public OMPClause {
2126 public:
2127  /// Build 'untied' clause.
2128  ///
2129  /// \param StartLoc Starting location of the clause.
2130  /// \param EndLoc Ending location of the clause.
2132  : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
2133 
2134  /// Build an empty clause.
2136  : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
2137 
2140  }
2141 
2144  }
2145 
2148  }
2151  }
2152 
2153  static bool classof(const OMPClause *T) {
2154  return T->getClauseKind() == llvm::omp::OMPC_untied;
2155  }
2156 };
2157 
2158 /// This represents 'mergeable' clause in the '#pragma omp ...'
2159 /// directive.
2160 ///
2161 /// \code
2162 /// #pragma omp task mergeable
2163 /// \endcode
2164 /// In this example directive '#pragma omp task' has 'mergeable' clause.
2166 public:
2167  /// Build 'mergeable' clause.
2168  ///
2169  /// \param StartLoc Starting location of the clause.
2170  /// \param EndLoc Ending location of the clause.
2172  : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
2173 
2174  /// Build an empty clause.
2176  : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
2177  SourceLocation()) {}
2178 
2181  }
2182 
2185  }
2186 
2189  }
2192  }
2193 
2194  static bool classof(const OMPClause *T) {
2195  return T->getClauseKind() == llvm::omp::OMPC_mergeable;
2196  }
2197 };
2198 
2199 /// This represents 'read' clause in the '#pragma omp atomic' directive.
2200 ///
2201 /// \code
2202 /// #pragma omp atomic read
2203 /// \endcode
2204 /// In this example directive '#pragma omp atomic' has 'read' clause.
2205 class OMPReadClause : public OMPClause {
2206 public:
2207  /// Build 'read' clause.
2208  ///
2209  /// \param StartLoc Starting location of the clause.
2210  /// \param EndLoc Ending location of the clause.
2212  : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
2213 
2214  /// Build an empty clause.
2216  : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
2217 
2220  }
2221 
2224  }
2225 
2228  }
2231  }
2232 
2233  static bool classof(const OMPClause *T) {
2234  return T->getClauseKind() == llvm::omp::OMPC_read;
2235  }
2236 };
2237 
2238 /// This represents 'write' clause in the '#pragma omp atomic' directive.
2239 ///
2240 /// \code
2241 /// #pragma omp atomic write
2242 /// \endcode
2243 /// In this example directive '#pragma omp atomic' has 'write' clause.
2244 class OMPWriteClause : public OMPClause {
2245 public:
2246  /// Build 'write' clause.
2247  ///
2248  /// \param StartLoc Starting location of the clause.
2249  /// \param EndLoc Ending location of the clause.
2251  : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
2252 
2253  /// Build an empty clause.
2255  : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
2256 
2259  }
2260 
2263  }
2264 
2267  }
2270  }
2271 
2272  static bool classof(const OMPClause *T) {
2273  return T->getClauseKind() == llvm::omp::OMPC_write;
2274  }
2275 };
2276 
2277 /// This represents 'update' clause in the '#pragma omp atomic'
2278 /// directive.
2279 ///
2280 /// \code
2281 /// #pragma omp atomic update
2282 /// \endcode
2283 /// In this example directive '#pragma omp atomic' has 'update' clause.
2284 /// Also, this class represents 'update' clause in '#pragma omp depobj'
2285 /// directive.
2286 ///
2287 /// \code
2288 /// #pragma omp depobj(a) update(in)
2289 /// \endcode
2290 /// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
2291 /// dependence kind.
2292 class OMPUpdateClause final
2293  : public OMPClause,
2294  private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
2295  OpenMPDependClauseKind> {
2296  friend class OMPClauseReader;
2297  friend TrailingObjects;
2298 
2299  /// true if extended version of the clause for 'depobj' directive.
2300  bool IsExtended = false;
2301 
2302  /// Define the sizes of each trailing object array except the last one. This
2303  /// is required for TrailingObjects to work properly.
2304  size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
2305  // 2 locations: for '(' and argument location.
2306  return IsExtended ? 2 : 0;
2307  }
2308 
2309  /// Sets the location of '(' in clause for 'depobj' directive.
2310  void setLParenLoc(SourceLocation Loc) {
2311  assert(IsExtended && "Expected extended clause.");
2312  *getTrailingObjects<SourceLocation>() = Loc;
2313  }
2314 
2315  /// Sets the location of '(' in clause for 'depobj' directive.
2316  void setArgumentLoc(SourceLocation Loc) {
2317  assert(IsExtended && "Expected extended clause.");
2318  *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
2319  }
2320 
2321  /// Sets the dependence kind for the clause for 'depobj' directive.
2322  void setDependencyKind(OpenMPDependClauseKind DK) {
2323  assert(IsExtended && "Expected extended clause.");
2324  *getTrailingObjects<OpenMPDependClauseKind>() = DK;
2325  }
2326 
2327  /// Build 'update' clause.
2328  ///
2329  /// \param StartLoc Starting location of the clause.
2330  /// \param EndLoc Ending location of the clause.
2331  OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
2332  bool IsExtended)
2333  : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
2334  IsExtended(IsExtended) {}
2335 
2336  /// Build an empty clause.
2337  OMPUpdateClause(bool IsExtended)
2338  : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
2339  IsExtended(IsExtended) {}
2340 
2341 public:
2342  /// Creates clause for 'atomic' directive.
2343  ///
2344  /// \param C AST context.
2345  /// \param StartLoc Starting location of the clause.
2346  /// \param EndLoc Ending location of the clause.
2347  static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2348  SourceLocation EndLoc);
2349 
2350  /// Creates clause for 'depobj' directive.
2351  ///
2352  /// \param C AST context.
2353  /// \param StartLoc Starting location of the clause.
2354  /// \param LParenLoc Location of '('.
2355  /// \param ArgumentLoc Location of the argument.
2356  /// \param DK Dependence kind.
2357  /// \param EndLoc Ending location of the clause.
2358  static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2359  SourceLocation LParenLoc,
2360  SourceLocation ArgumentLoc,
2362  SourceLocation EndLoc);
2363 
2364  /// Creates an empty clause with the place for \a N variables.
2365  ///
2366  /// \param C AST context.
2367  /// \param IsExtended true if extended clause for 'depobj' directive must be
2368  /// created.
2369  static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
2370 
2371  /// Checks if the clause is the extended clauses for 'depobj' directive.
2372  bool isExtended() const { return IsExtended; }
2373 
2376  }
2377 
2380  }
2381 
2384  }
2387  }
2388 
2389  /// Gets the location of '(' in clause for 'depobj' directive.
2391  assert(IsExtended && "Expected extended clause.");
2392  return *getTrailingObjects<SourceLocation>();
2393  }
2394 
2395  /// Gets the location of argument in clause for 'depobj' directive.
2397  assert(IsExtended && "Expected extended clause.");
2398  return *std::next(getTrailingObjects<SourceLocation>(), 1);
2399  }
2400 
2401  /// Gets the dependence kind in clause for 'depobj' directive.
2403  assert(IsExtended && "Expected extended clause.");
2404  return *getTrailingObjects<OpenMPDependClauseKind>();
2405  }
2406 
2407  static bool classof(const OMPClause *T) {
2408  return T->getClauseKind() == llvm::omp::OMPC_update;
2409  }
2410 };
2411 
2412 /// This represents 'capture' clause in the '#pragma omp atomic'
2413 /// directive.
2414 ///
2415 /// \code
2416 /// #pragma omp atomic capture
2417 /// \endcode
2418 /// In this example directive '#pragma omp atomic' has 'capture' clause.
2419 class OMPCaptureClause : public OMPClause {
2420 public:
2421  /// Build 'capture' clause.
2422  ///
2423  /// \param StartLoc Starting location of the clause.
2424  /// \param EndLoc Ending location of the clause.
2426  : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
2427 
2428  /// Build an empty clause.
2430  : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
2431  }
2432 
2435  }
2436 
2439  }
2440 
2443  }
2446  }
2447 
2448  static bool classof(const OMPClause *T) {
2449  return T->getClauseKind() == llvm::omp::OMPC_capture;
2450  }
2451 };
2452 
2453 /// This represents 'compare' clause in the '#pragma omp atomic'
2454 /// directive.
2455 ///
2456 /// \code
2457 /// #pragma omp atomic compare
2458 /// \endcode
2459 /// In this example directive '#pragma omp atomic' has 'compare' clause.
2460 class OMPCompareClause final : public OMPClause {
2461 public:
2462  /// Build 'compare' clause.
2463  ///
2464  /// \param StartLoc Starting location of the clause.
2465  /// \param EndLoc Ending location of the clause.
2467  : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {}
2468 
2469  /// Build an empty clause.
2471  : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) {
2472  }
2473 
2476  }
2477 
2480  }
2481 
2484  }
2487  }
2488 
2489  static bool classof(const OMPClause *T) {
2490  return T->getClauseKind() == llvm::omp::OMPC_compare;
2491  }
2492 };
2493 
2494 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
2495 /// directive.
2496 ///
2497 /// \code
2498 /// #pragma omp atomic seq_cst
2499 /// \endcode
2500 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
2501 class OMPSeqCstClause : public OMPClause {
2502 public:
2503  /// Build 'seq_cst' clause.
2504  ///
2505  /// \param StartLoc Starting location of the clause.
2506  /// \param EndLoc Ending location of the clause.
2508  : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
2509 
2510  /// Build an empty clause.
2512  : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
2513  }
2514 
2517  }
2518 
2521  }
2522 
2525  }
2528  }
2529 
2530  static bool classof(const OMPClause *T) {
2531  return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
2532  }
2533 };
2534 
2535 /// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
2536 /// directives.
2537 ///
2538 /// \code
2539 /// #pragma omp flush acq_rel
2540 /// \endcode
2541 /// In this example directive '#pragma omp flush' has 'acq_rel' clause.
2542 class OMPAcqRelClause final : public OMPClause {
2543 public:
2544  /// Build 'ack_rel' clause.
2545  ///
2546  /// \param StartLoc Starting location of the clause.
2547  /// \param EndLoc Ending location of the clause.
2549  : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
2550 
2551  /// Build an empty clause.
2553  : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
2554  }
2555 
2558  }
2559 
2562  }
2563 
2566  }
2569  }
2570 
2571  static bool classof(const OMPClause *T) {
2572  return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
2573  }
2574 };
2575 
2576 /// This represents 'acquire' clause in the '#pragma omp atomic|flush'
2577 /// directives.
2578 ///
2579 /// \code
2580 /// #pragma omp flush acquire
2581 /// \endcode
2582 /// In this example directive '#pragma omp flush' has 'acquire' clause.
2583 class OMPAcquireClause final : public OMPClause {
2584 public:
2585  /// Build 'acquire' clause.
2586  ///
2587  /// \param StartLoc Starting location of the clause.
2588  /// \param EndLoc Ending location of the clause.
2590  : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
2591 
2592  /// Build an empty clause.
2594  : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
2595  }
2596 
2599  }
2600 
2603  }
2604 
2607  }
2610  }
2611 
2612  static bool classof(const OMPClause *T) {
2613  return T->getClauseKind() == llvm::omp::OMPC_acquire;
2614  }
2615 };
2616 
2617 /// This represents 'release' clause in the '#pragma omp atomic|flush'
2618 /// directives.
2619 ///
2620 /// \code
2621 /// #pragma omp flush release
2622 /// \endcode
2623 /// In this example directive '#pragma omp flush' has 'release' clause.
2624 class OMPReleaseClause final : public OMPClause {
2625 public:
2626  /// Build 'release' clause.
2627  ///
2628  /// \param StartLoc Starting location of the clause.
2629  /// \param EndLoc Ending location of the clause.
2631  : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
2632 
2633  /// Build an empty clause.
2635  : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
2636  }
2637 
2640  }
2641 
2644  }
2645 
2648  }
2651  }
2652 
2653  static bool classof(const OMPClause *T) {
2654  return T->getClauseKind() == llvm::omp::OMPC_release;
2655  }
2656 };
2657 
2658 /// This represents 'relaxed' clause in the '#pragma omp atomic'
2659 /// directives.
2660 ///
2661 /// \code
2662 /// #pragma omp atomic relaxed
2663 /// \endcode
2664 /// In this example directive '#pragma omp atomic' has 'relaxed' clause.
2665 class OMPRelaxedClause final : public OMPClause {
2666 public:
2667  /// Build 'relaxed' clause.
2668  ///
2669  /// \param StartLoc Starting location of the clause.
2670  /// \param EndLoc Ending location of the clause.
2672  : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
2673 
2674  /// Build an empty clause.
2676  : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
2677  }
2678 
2681  }
2682 
2685  }
2686 
2689  }
2692  }
2693 
2694  static bool classof(const OMPClause *T) {
2695  return T->getClauseKind() == llvm::omp::OMPC_relaxed;
2696  }
2697 };
2698 
2699 /// This represents clause 'private' in the '#pragma omp ...' directives.
2700 ///
2701 /// \code
2702 /// #pragma omp parallel private(a,b)
2703 /// \endcode
2704 /// In this example directive '#pragma omp parallel' has clause 'private'
2705 /// with the variables 'a' and 'b'.
2706 class OMPPrivateClause final
2707  : public OMPVarListClause<OMPPrivateClause>,
2708  private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2709  friend class OMPClauseReader;
2710  friend OMPVarListClause;
2711  friend TrailingObjects;
2712 
2713  /// 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  OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2720  SourceLocation EndLoc, unsigned N)
2721  : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
2722  LParenLoc, EndLoc, N) {}
2723 
2724  /// Build an empty clause.
2725  ///
2726  /// \param N Number of variables.
2727  explicit OMPPrivateClause(unsigned N)
2728  : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
2730  SourceLocation(), N) {}
2731 
2732  /// Sets the list of references to private copies with initializers for
2733  /// new private variables.
2734  /// \param VL List of references.
2735  void setPrivateCopies(ArrayRef<Expr *> VL);
2736 
2737  /// Gets the list of references to private copies with initializers for
2738  /// new private variables.
2739  MutableArrayRef<Expr *> getPrivateCopies() {
2740  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2741  }
2742  ArrayRef<const Expr *> getPrivateCopies() const {
2743  return llvm::makeArrayRef(varlist_end(), varlist_size());
2744  }
2745 
2746 public:
2747  /// Creates clause with a list of variables \a VL.
2748  ///
2749  /// \param C AST context.
2750  /// \param StartLoc Starting location of the clause.
2751  /// \param LParenLoc Location of '('.
2752  /// \param EndLoc Ending location of the clause.
2753  /// \param VL List of references to the variables.
2754  /// \param PrivateVL List of references to private copies with initializers.
2755  static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2756  SourceLocation LParenLoc,
2757  SourceLocation EndLoc, ArrayRef<Expr *> VL,
2758  ArrayRef<Expr *> PrivateVL);
2759 
2760  /// Creates an empty clause with the place for \a N variables.
2761  ///
2762  /// \param C AST context.
2763  /// \param N The number of variables.
2764  static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2765 
2768  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2770  llvm::iterator_range<private_copies_const_iterator>;
2771 
2773  return private_copies_range(getPrivateCopies().begin(),
2774  getPrivateCopies().end());
2775  }
2776 
2778  return private_copies_const_range(getPrivateCopies().begin(),
2779  getPrivateCopies().end());
2780  }
2781 
2783  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2784  reinterpret_cast<Stmt **>(varlist_end()));
2785  }
2786 
2788  auto Children = const_cast<OMPPrivateClause *>(this)->children();
2789  return const_child_range(Children.begin(), Children.end());
2790  }
2791 
2794  }
2797  }
2798 
2799  static bool classof(const OMPClause *T) {
2800  return T->getClauseKind() == llvm::omp::OMPC_private;
2801  }
2802 };
2803 
2804 /// This represents clause 'firstprivate' in the '#pragma omp ...'
2805 /// directives.
2806 ///
2807 /// \code
2808 /// #pragma omp parallel firstprivate(a,b)
2809 /// \endcode
2810 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2811 /// with the variables 'a' and 'b'.
2813  : public OMPVarListClause<OMPFirstprivateClause>,
2814  public OMPClauseWithPreInit,
2815  private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2816  friend class OMPClauseReader;
2817  friend OMPVarListClause;
2818  friend TrailingObjects;
2819 
2820  /// Build clause with number of variables \a N.
2821  ///
2822  /// \param StartLoc Starting location of the clause.
2823  /// \param LParenLoc Location of '('.
2824  /// \param EndLoc Ending location of the clause.
2825  /// \param N Number of the variables in the clause.
2827  SourceLocation EndLoc, unsigned N)
2828  : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
2829  StartLoc, LParenLoc, EndLoc, N),
2830  OMPClauseWithPreInit(this) {}
2831 
2832  /// Build an empty clause.
2833  ///
2834  /// \param N Number of variables.
2835  explicit OMPFirstprivateClause(unsigned N)
2837  llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
2838  SourceLocation(), N),
2839  OMPClauseWithPreInit(this) {}
2840 
2841  /// Sets the list of references to private copies with initializers for
2842  /// new private variables.
2843  /// \param VL List of references.
2844  void setPrivateCopies(ArrayRef<Expr *> VL);
2845 
2846  /// Gets the list of references to private copies with initializers for
2847  /// new private variables.
2848  MutableArrayRef<Expr *> getPrivateCopies() {
2849  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2850  }
2851  ArrayRef<const Expr *> getPrivateCopies() const {
2852  return llvm::makeArrayRef(varlist_end(), varlist_size());
2853  }
2854 
2855  /// Sets the list of references to initializer variables for new
2856  /// private variables.
2857  /// \param VL List of references.
2858  void setInits(ArrayRef<Expr *> VL);
2859 
2860  /// Gets the list of references to initializer variables for new
2861  /// private variables.
2862  MutableArrayRef<Expr *> getInits() {
2863  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2864  }
2865  ArrayRef<const Expr *> getInits() const {
2866  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2867  }
2868 
2869 public:
2870  /// Creates clause with a list of variables \a VL.
2871  ///
2872  /// \param C AST context.
2873  /// \param StartLoc Starting location of the clause.
2874  /// \param LParenLoc Location of '('.
2875  /// \param EndLoc Ending location of the clause.
2876  /// \param VL List of references to the original variables.
2877  /// \param PrivateVL List of references to private copies with initializers.
2878  /// \param InitVL List of references to auto generated variables used for
2879  /// initialization of a single array element. Used if firstprivate variable is
2880  /// of array type.
2881  /// \param PreInit Statement that must be executed before entering the OpenMP
2882  /// region with this clause.
2883  static OMPFirstprivateClause *
2884  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2885  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2886  ArrayRef<Expr *> InitVL, Stmt *PreInit);
2887 
2888  /// Creates an empty clause with the place for \a N variables.
2889  ///
2890  /// \param C AST context.
2891  /// \param N The number of variables.
2892  static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2893 
2896  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2898  llvm::iterator_range<private_copies_const_iterator>;
2899 
2901  return private_copies_range(getPrivateCopies().begin(),
2902  getPrivateCopies().end());
2903  }
2905  return private_copies_const_range(getPrivateCopies().begin(),
2906  getPrivateCopies().end());
2907  }
2908 
2911  using inits_range = llvm::iterator_range<inits_iterator>;
2912  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2913 
2915  return inits_range(getInits().begin(), getInits().end());
2916  }
2918  return inits_const_range(getInits().begin(), getInits().end());
2919  }
2920 
2922  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2923  reinterpret_cast<Stmt **>(varlist_end()));
2924  }
2925 
2927  auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2928  return const_child_range(Children.begin(), Children.end());
2929  }
2930 
2932  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2933  reinterpret_cast<Stmt **>(varlist_end()));
2934  }
2936  auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2937  return const_child_range(Children.begin(), Children.end());
2938  }
2939 
2940  static bool classof(const OMPClause *T) {
2941  return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
2942  }
2943 };
2944 
2945 /// This represents clause 'lastprivate' in the '#pragma omp ...'
2946 /// directives.
2947 ///
2948 /// \code
2949 /// #pragma omp simd lastprivate(a,b)
2950 /// \endcode
2951 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
2952 /// with the variables 'a' and 'b'.
2954  : public OMPVarListClause<OMPLastprivateClause>,
2955  public OMPClauseWithPostUpdate,
2956  private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2957  // There are 4 additional tail-allocated arrays at the end of the class:
2958  // 1. Contains list of pseudo variables with the default initialization for
2959  // each non-firstprivate variables. Used in codegen for initialization of
2960  // lastprivate copies.
2961  // 2. List of helper expressions for proper generation of assignment operation
2962  // required for lastprivate clause. This list represents private variables
2963  // (for arrays, single array element).
2964  // 3. List of helper expressions for proper generation of assignment operation
2965  // required for lastprivate clause. This list represents original variables
2966  // (for arrays, single array element).
2967  // 4. List of helper expressions that represents assignment operation:
2968  // \code
2969  // DstExprs = SrcExprs;
2970  // \endcode
2971  // Required for proper codegen of final assignment performed by the
2972  // lastprivate clause.
2973  friend class OMPClauseReader;
2974  friend OMPVarListClause;
2975  friend TrailingObjects;
2976 
2977  /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2979  /// Optional location of the lasptrivate kind, if specified by user.
2980  SourceLocation LPKindLoc;
2981  /// Optional colon location, if specified by user.
2982  SourceLocation ColonLoc;
2983 
2984  /// Build clause with number of variables \a N.
2985  ///
2986  /// \param StartLoc Starting location of the clause.
2987  /// \param LParenLoc Location of '('.
2988  /// \param EndLoc Ending location of the clause.
2989  /// \param N Number of the variables in the clause.
2992  SourceLocation LPKindLoc, SourceLocation ColonLoc,
2993  unsigned N)
2994  : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
2995  StartLoc, LParenLoc, EndLoc, N),
2996  OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2997  ColonLoc(ColonLoc) {}
2998 
2999  /// Build an empty clause.
3000  ///
3001  /// \param N Number of variables.
3002  explicit OMPLastprivateClause(unsigned N)
3004  llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
3005  SourceLocation(), N),
3006  OMPClauseWithPostUpdate(this) {}
3007 
3008  /// Get the list of helper expressions for initialization of private
3009  /// copies for lastprivate variables.
3010  MutableArrayRef<Expr *> getPrivateCopies() {
3011  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3012  }
3013  ArrayRef<const Expr *> getPrivateCopies() const {
3014  return llvm::makeArrayRef(varlist_end(), varlist_size());
3015  }
3016 
3017  /// Set list of helper expressions, required for proper codegen of the
3018  /// clause. These expressions represent private variables (for arrays, single
3019  /// array element) in the final assignment statement performed by the
3020  /// lastprivate clause.
3021  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3022 
3023  /// Get the list of helper source expressions.
3024  MutableArrayRef<Expr *> getSourceExprs() {
3025  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
3026  }
3027  ArrayRef<const Expr *> getSourceExprs() const {
3028  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
3029  }
3030 
3031  /// Set list of helper expressions, required for proper codegen of the
3032  /// clause. These expressions represent original variables (for arrays, single
3033  /// array element) in the final assignment statement performed by the
3034  /// lastprivate clause.
3035  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3036 
3037  /// Get the list of helper destination expressions.
3038  MutableArrayRef<Expr *> getDestinationExprs() {
3039  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3040  }
3041  ArrayRef<const Expr *> getDestinationExprs() const {
3042  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3043  }
3044 
3045  /// Set list of helper assignment expressions, required for proper
3046  /// codegen of the clause. These expressions are assignment expressions that
3047  /// assign private copy of the variable to original variable.
3048  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3049 
3050  /// Get the list of helper assignment expressions.
3051  MutableArrayRef<Expr *> getAssignmentOps() {
3052  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3053  }
3054  ArrayRef<const Expr *> getAssignmentOps() const {
3055  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3056  }
3057 
3058  /// Sets lastprivate kind.
3059  void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
3060  /// Sets location of the lastprivate kind.
3061  void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
3062  /// Sets colon symbol location.
3063  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3064 
3065 public:
3066  /// Creates clause with a list of variables \a VL.
3067  ///
3068  /// \param C AST context.
3069  /// \param StartLoc Starting location of the clause.
3070  /// \param LParenLoc Location of '('.
3071  /// \param EndLoc Ending location of the clause.
3072  /// \param VL List of references to the variables.
3073  /// \param SrcExprs List of helper expressions for proper generation of
3074  /// assignment operation required for lastprivate clause. This list represents
3075  /// private variables (for arrays, single array element).
3076  /// \param DstExprs List of helper expressions for proper generation of
3077  /// assignment operation required for lastprivate clause. This list represents
3078  /// original variables (for arrays, single array element).
3079  /// \param AssignmentOps List of helper expressions that represents assignment
3080  /// operation:
3081  /// \code
3082  /// DstExprs = SrcExprs;
3083  /// \endcode
3084  /// Required for proper codegen of final assignment performed by the
3085  /// lastprivate clause.
3086  /// \param LPKind Lastprivate kind, e.g. 'conditional'.
3087  /// \param LPKindLoc Location of the lastprivate kind.
3088  /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
3089  /// \param PreInit Statement that must be executed before entering the OpenMP
3090  /// region with this clause.
3091  /// \param PostUpdate Expression that must be executed after exit from the
3092  /// OpenMP region with this clause.
3093  static OMPLastprivateClause *
3094  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3095  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3096  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
3097  OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
3098  SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
3099 
3100  /// Creates an empty clause with the place for \a N variables.
3101  ///
3102  /// \param C AST context.
3103  /// \param N The number of variables.
3104  static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3105 
3106  /// Lastprivate kind.
3107  OpenMPLastprivateModifier getKind() const { return LPKind; }
3108  /// Returns the location of the lastprivate kind.
3109  SourceLocation getKindLoc() const { return LPKindLoc; }
3110  /// Returns the location of the ':' symbol, if any.
3111  SourceLocation getColonLoc() const { return ColonLoc; }
3112 
3115  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3116  using helper_expr_const_range =
3117  llvm::iterator_range<helper_expr_const_iterator>;
3118 
3119  /// Set list of helper expressions, required for generation of private
3120  /// copies of original lastprivate variables.
3121  void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
3122 
3124  return helper_expr_const_range(getPrivateCopies().begin(),
3125  getPrivateCopies().end());
3126  }
3127 
3129  return helper_expr_range(getPrivateCopies().begin(),
3130  getPrivateCopies().end());
3131  }
3132 
3134  return helper_expr_const_range(getSourceExprs().begin(),
3135  getSourceExprs().end());
3136  }
3137 
3139  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3140  }
3141 
3143  return helper_expr_const_range(getDestinationExprs().begin(),
3144  getDestinationExprs().end());
3145  }
3146 
3148  return helper_expr_range(getDestinationExprs().begin(),
3149  getDestinationExprs().end());
3150  }
3151 
3153  return helper_expr_const_range(getAssignmentOps().begin(),
3154  getAssignmentOps().end());
3155  }
3156 
3158  return helper_expr_range(getAssignmentOps().begin(),
3159  getAssignmentOps().end());
3160  }
3161 
3163  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3164  reinterpret_cast<Stmt **>(varlist_end()));
3165  }
3166 
3168  auto Children = const_cast<OMPLastprivateClause *>(this)->children();
3169  return const_child_range(Children.begin(), Children.end());
3170  }
3171 
3174  }
3177  }
3178 
3179  static bool classof(const OMPClause *T) {
3180  return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
3181  }
3182 };
3183 
3184 /// This represents clause 'shared' in the '#pragma omp ...' directives.
3185 ///
3186 /// \code
3187 /// #pragma omp parallel shared(a,b)
3188 /// \endcode
3189 /// In this example directive '#pragma omp parallel' has clause 'shared'
3190 /// with the variables 'a' and 'b'.
3191 class OMPSharedClause final
3192  : public OMPVarListClause<OMPSharedClause>,
3193  private llvm::TrailingObjects<OMPSharedClause, Expr *> {
3194  friend OMPVarListClause;
3195  friend TrailingObjects;
3196 
3197  /// Build clause with number of variables \a N.
3198  ///
3199  /// \param StartLoc Starting location of the clause.
3200  /// \param LParenLoc Location of '('.
3201  /// \param EndLoc Ending location of the clause.
3202  /// \param N Number of the variables in the clause.
3203  OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3204  SourceLocation EndLoc, unsigned N)
3205  : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
3206  LParenLoc, EndLoc, N) {}
3207 
3208  /// Build an empty clause.
3209  ///
3210  /// \param N Number of variables.
3211  explicit OMPSharedClause(unsigned N)
3212  : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
3214  SourceLocation(), N) {}
3215 
3216 public:
3217  /// Creates clause with a list of variables \a VL.
3218  ///
3219  /// \param C AST context.
3220  /// \param StartLoc Starting location of the clause.
3221  /// \param LParenLoc Location of '('.
3222  /// \param EndLoc Ending location of the clause.
3223  /// \param VL List of references to the variables.
3224  static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3225  SourceLocation LParenLoc,
3226  SourceLocation EndLoc, ArrayRef<Expr *> VL);
3227 
3228  /// Creates an empty clause with \a N variables.
3229  ///
3230  /// \param C AST context.
3231  /// \param N The number of variables.
3232  static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
3233 
3235  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3236  reinterpret_cast<Stmt **>(varlist_end()));
3237  }
3238 
3240  auto Children = const_cast<OMPSharedClause *>(this)->children();
3241  return const_child_range(Children.begin(), Children.end());
3242  }
3243 
3246  }
3249  }
3250 
3251  static bool classof(const OMPClause *T) {
3252  return T->getClauseKind() == llvm::omp::OMPC_shared;
3253  }
3254 };
3255 
3256 /// This represents clause 'reduction' in the '#pragma omp ...'
3257 /// directives.
3258 ///
3259 /// \code
3260 /// #pragma omp parallel reduction(+:a,b)
3261 /// \endcode
3262 /// In this example directive '#pragma omp parallel' has clause 'reduction'
3263 /// with operator '+' and the variables 'a' and 'b'.
3265  : public OMPVarListClause<OMPReductionClause>,
3266  public OMPClauseWithPostUpdate,
3267  private llvm::TrailingObjects<OMPReductionClause, Expr *> {
3268  friend class OMPClauseReader;
3269  friend OMPVarListClause;
3270  friend TrailingObjects;
3271 
3272  /// Reduction modifier.
3274 
3275  /// Reduction modifier location.
3276  SourceLocation ModifierLoc;
3277 
3278  /// Location of ':'.
3279  SourceLocation ColonLoc;
3280 
3281  /// Nested name specifier for C++.
3282  NestedNameSpecifierLoc QualifierLoc;
3283 
3284  /// Name of custom operator.
3285  DeclarationNameInfo NameInfo;
3286 
3287  /// Build clause with number of variables \a N.
3288  ///
3289  /// \param StartLoc Starting location of the clause.
3290  /// \param LParenLoc Location of '('.
3291  /// \param ModifierLoc Modifier location.
3292  /// \param ColonLoc Location of ':'.
3293  /// \param EndLoc Ending location of the clause.
3294  /// \param N Number of the variables in the clause.
3295  /// \param QualifierLoc The nested-name qualifier with location information
3296  /// \param NameInfo The full name info for reduction identifier.
3297  OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3298  SourceLocation ModifierLoc, SourceLocation ColonLoc,
3299  SourceLocation EndLoc,
3300  OpenMPReductionClauseModifier Modifier, unsigned N,
3301  NestedNameSpecifierLoc QualifierLoc,
3302  const DeclarationNameInfo &NameInfo)
3303  : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3304  StartLoc, LParenLoc, EndLoc, N),
3305  OMPClauseWithPostUpdate(this), Modifier(Modifier),
3306  ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
3307  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3308 
3309  /// Build an empty clause.
3310  ///
3311  /// \param N Number of variables.
3312  explicit OMPReductionClause(unsigned N)
3313  : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3315  SourceLocation(), N),
3316  OMPClauseWithPostUpdate(this) {}
3317 
3318  /// Sets reduction modifier.
3319  void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
3320 
3321  /// Sets location of the modifier.
3322  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3323 
3324  /// Sets location of ':' symbol in clause.
3325  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3326 
3327  /// Sets the name info for specified reduction identifier.
3328  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3329 
3330  /// Sets the nested name specifier.
3331  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3332 
3333  /// Set list of helper expressions, required for proper codegen of the
3334  /// clause. These expressions represent private copy of the reduction
3335  /// variable.
3336  void setPrivates(ArrayRef<Expr *> Privates);
3337 
3338  /// Get the list of helper privates.
3339  MutableArrayRef<Expr *> getPrivates() {
3340  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3341  }
3342  ArrayRef<const Expr *> getPrivates() const {
3343  return llvm::makeArrayRef(varlist_end(), varlist_size());
3344  }
3345 
3346  /// Set list of helper expressions, required for proper codegen of the
3347  /// clause. These expressions represent LHS expression in the final
3348  /// reduction expression performed by the reduction clause.
3349  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3350 
3351  /// Get the list of helper LHS expressions.
3352  MutableArrayRef<Expr *> getLHSExprs() {
3353  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3354  }
3355  ArrayRef<const Expr *> getLHSExprs() const {
3356  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3357  }
3358 
3359  /// Set list of helper expressions, required for proper codegen of the
3360  /// clause. These expressions represent RHS expression in the final
3361  /// reduction expression performed by the reduction clause.
3362  /// Also, variables in these expressions are used for proper initialization of
3363  /// reduction copies.
3364  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3365 
3366  /// Get the list of helper destination expressions.
3367  MutableArrayRef<Expr *> getRHSExprs() {
3368  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3369  }
3370  ArrayRef<const Expr *> getRHSExprs() const {
3371  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3372  }
3373 
3374  /// Set list of helper reduction expressions, required for proper
3375  /// codegen of the clause. These expressions are binary expressions or
3376  /// operator/custom reduction call that calculates new value from source
3377  /// helper expressions to destination helper expressions.
3378  void setReductionOps(ArrayRef<Expr *> ReductionOps);
3379 
3380  /// Get the list of helper reduction expressions.
3381  MutableArrayRef<Expr *> getReductionOps() {
3382  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3383  }
3384  ArrayRef<const Expr *> getReductionOps() const {
3385  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3386  }
3387 
3388  /// Set list of helper copy operations for inscan reductions.
3389  /// The form is: Temps[i] = LHS[i];
3390  void setInscanCopyOps(ArrayRef<Expr *> Ops);
3391 
3392  /// Get the list of helper inscan copy operations.
3393  MutableArrayRef<Expr *> getInscanCopyOps() {
3394  return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3395  }
3396  ArrayRef<const Expr *> getInscanCopyOps() const {
3397  return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3398  }
3399 
3400  /// Set list of helper temp vars for inscan copy array operations.
3401  void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
3402 
3403  /// Get the list of helper inscan copy temps.
3404  MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
3405  return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
3406  }
3407  ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
3408  return llvm::makeArrayRef(getInscanCopyOps().end(), varlist_size());
3409  }
3410 
3411  /// Set list of helper temp elements vars for inscan copy array operations.
3412  void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
3413 
3414  /// Get the list of helper inscan copy temps.
3415  MutableArrayRef<Expr *> getInscanCopyArrayElems() {
3416  return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
3417  varlist_size());
3418  }
3419  ArrayRef<const Expr *> getInscanCopyArrayElems() const {
3420  return llvm::makeArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
3421  }
3422 
3423 public:
3424  /// Creates clause with a list of variables \a VL.
3425  ///
3426  /// \param StartLoc Starting location of the clause.
3427  /// \param LParenLoc Location of '('.
3428  /// \param ModifierLoc Modifier location.
3429  /// \param ColonLoc Location of ':'.
3430  /// \param EndLoc Ending location of the clause.
3431  /// \param VL The variables in the clause.
3432  /// \param QualifierLoc The nested-name qualifier with location information
3433  /// \param NameInfo The full name info for reduction identifier.
3434  /// \param Privates List of helper expressions for proper generation of
3435  /// private copies.
3436  /// \param LHSExprs List of helper expressions for proper generation of
3437  /// assignment operation required for copyprivate clause. This list represents
3438  /// LHSs of the reduction expressions.
3439  /// \param RHSExprs List of helper expressions for proper generation of
3440  /// assignment operation required for copyprivate clause. This list represents
3441  /// RHSs of the reduction expressions.
3442  /// Also, variables in these expressions are used for proper initialization of
3443  /// reduction copies.
3444  /// \param ReductionOps List of helper expressions that represents reduction
3445  /// expressions:
3446  /// \code
3447  /// LHSExprs binop RHSExprs;
3448  /// operator binop(LHSExpr, RHSExpr);
3449  /// <CutomReduction>(LHSExpr, RHSExpr);
3450  /// \endcode
3451  /// Required for proper codegen of final reduction operation performed by the
3452  /// reduction clause.
3453  /// \param CopyOps List of copy operations for inscan reductions:
3454  /// \code
3455  /// TempExprs = LHSExprs;
3456  /// \endcode
3457  /// \param CopyArrayTemps Temp arrays for prefix sums.
3458  /// \param CopyArrayElems Temp arrays for prefix sums.
3459  /// \param PreInit Statement that must be executed before entering the OpenMP
3460  /// region with this clause.
3461  /// \param PostUpdate Expression that must be executed after exit from the
3462  /// OpenMP region with this clause.
3463  static OMPReductionClause *
3464  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3465  SourceLocation ModifierLoc, SourceLocation ColonLoc,
3466  SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
3467  ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
3468  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3469  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3470  ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
3471  ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
3472  Stmt *PreInit, Expr *PostUpdate);
3473 
3474  /// Creates an empty clause with the place for \a N variables.
3475  ///
3476  /// \param C AST context.
3477  /// \param N The number of variables.
3478  /// \param Modifier Reduction modifier.
3479  static OMPReductionClause *
3480  CreateEmpty(const ASTContext &C, unsigned N,
3482 
3483  /// Returns modifier.
3484  OpenMPReductionClauseModifier getModifier() const { return Modifier; }
3485 
3486  /// Returns modifier location.
3487  SourceLocation getModifierLoc() const { return ModifierLoc; }
3488 
3489  /// Gets location of ':' symbol in clause.
3490  SourceLocation getColonLoc() const { return ColonLoc; }
3491 
3492  /// Gets the name info for specified reduction identifier.
3493  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3494 
3495  /// Gets the nested name specifier.
3496  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3497 
3500  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3501  using helper_expr_const_range =
3502  llvm::iterator_range<helper_expr_const_iterator>;
3503 
3505  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3506  }
3507 
3509  return helper_expr_range(getPrivates().begin(), getPrivates().end());
3510  }
3511 
3513  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3514  }
3515 
3517  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3518  }
3519 
3521  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3522  }
3523 
3525  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3526  }
3527 
3529  return helper_expr_const_range(getReductionOps().begin(),
3530  getReductionOps().end());
3531  }
3532 
3534  return helper_expr_range(getReductionOps().begin(),
3535  getReductionOps().end());
3536  }
3537 
3539  return helper_expr_const_range(getInscanCopyOps().begin(),
3540  getInscanCopyOps().end());
3541  }
3542 
3544  return helper_expr_range(getInscanCopyOps().begin(),
3545  getInscanCopyOps().end());
3546  }
3547 
3549  return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
3550  getInscanCopyArrayTemps().end());
3551  }
3552 
3554  return helper_expr_range(getInscanCopyArrayTemps().begin(),
3555  getInscanCopyArrayTemps().end());
3556  }
3557 
3559  return helper_expr_const_range(getInscanCopyArrayElems().begin(),
3560  getInscanCopyArrayElems().end());
3561  }
3562 
3564  return helper_expr_range(getInscanCopyArrayElems().begin(),
3565  getInscanCopyArrayElems().end());
3566  }
3567 
3569  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3570  reinterpret_cast<Stmt **>(varlist_end()));
3571  }
3572 
3574  auto Children = const_cast<OMPReductionClause *>(this)->children();
3575  return const_child_range(Children.begin(), Children.end());
3576  }
3577 
3579  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3580  reinterpret_cast<Stmt **>(varlist_end()));
3581  }
3583  auto Children = const_cast<OMPReductionClause *>(this)->used_children();
3584  return const_child_range(Children.begin(), Children.end());
3585  }
3586 
3587  static bool classof(const OMPClause *T) {
3588  return T->getClauseKind() == llvm::omp::OMPC_reduction;
3589  }
3590 };
3591 
3592 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
3593 /// directives.
3594 ///
3595 /// \code
3596 /// #pragma omp taskgroup task_reduction(+:a,b)
3597 /// \endcode
3598 /// In this example directive '#pragma omp taskgroup' has clause
3599 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
3601  : public OMPVarListClause<OMPTaskReductionClause>,
3602  public OMPClauseWithPostUpdate,
3603  private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
3604  friend class OMPClauseReader;
3605  friend OMPVarListClause;
3606  friend TrailingObjects;
3607 
3608  /// Location of ':'.
3609  SourceLocation ColonLoc;
3610 
3611  /// Nested name specifier for C++.
3612  NestedNameSpecifierLoc QualifierLoc;
3613 
3614  /// Name of custom operator.
3615  DeclarationNameInfo NameInfo;
3616 
3617  /// Build clause with number of variables \a N.
3618  ///
3619  /// \param StartLoc Starting location of the clause.
3620  /// \param LParenLoc Location of '('.
3621  /// \param EndLoc Ending location of the clause.
3622  /// \param ColonLoc Location of ':'.
3623  /// \param N Number of the variables in the clause.
3624  /// \param QualifierLoc The nested-name qualifier with location information
3625  /// \param NameInfo The full name info for reduction identifier.
3627  SourceLocation ColonLoc, SourceLocation EndLoc,
3628  unsigned N, NestedNameSpecifierLoc QualifierLoc,
3629  const DeclarationNameInfo &NameInfo)
3631  llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
3632  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3633  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3634 
3635  /// Build an empty clause.
3636  ///
3637  /// \param N Number of variables.
3638  explicit OMPTaskReductionClause(unsigned N)
3640  llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
3641  SourceLocation(), N),
3642  OMPClauseWithPostUpdate(this) {}
3643 
3644  /// Sets location of ':' symbol in clause.
3645  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3646 
3647  /// Sets the name info for specified reduction identifier.
3648  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3649 
3650  /// Sets the nested name specifier.
3651  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3652 
3653  /// Set list of helper expressions, required for proper codegen of the clause.
3654  /// These expressions represent private copy of the reduction variable.
3655  void setPrivates(ArrayRef<Expr *> Privates);
3656 
3657  /// Get the list of helper privates.
3658  MutableArrayRef<Expr *> getPrivates() {
3659  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3660  }
3661  ArrayRef<const Expr *> getPrivates() const {
3662  return llvm::makeArrayRef(varlist_end(), varlist_size());
3663  }
3664 
3665  /// Set list of helper expressions, required for proper codegen of the clause.
3666  /// These expressions represent LHS expression in the final reduction
3667  /// expression performed by the reduction clause.
3668  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3669 
3670  /// Get the list of helper LHS expressions.
3671  MutableArrayRef<Expr *> getLHSExprs() {
3672  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3673  }
3674  ArrayRef<const Expr *> getLHSExprs() const {
3675  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3676  }
3677 
3678  /// Set list of helper expressions, required for proper codegen of the clause.
3679  /// These expressions represent RHS expression in the final reduction
3680  /// expression performed by the reduction clause. Also, variables in these
3681  /// expressions are used for proper initialization of reduction copies.
3682  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3683 
3684  /// Get the list of helper destination expressions.
3685  MutableArrayRef<Expr *> getRHSExprs() {
3686  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3687  }
3688  ArrayRef<const Expr *> getRHSExprs() const {
3689  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3690  }
3691 
3692  /// Set list of helper reduction expressions, required for proper
3693  /// codegen of the clause. These expressions are binary expressions or
3694  /// operator/custom reduction call that calculates new value from source
3695  /// helper expressions to destination helper expressions.
3696  void setReductionOps(ArrayRef<Expr *> ReductionOps);
3697 
3698  /// Get the list of helper reduction expressions.
3699  MutableArrayRef<Expr *> getReductionOps() {
3700  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3701  }
3702  ArrayRef<const Expr *> getReductionOps() const {
3703  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3704  }
3705 
3706 public:
3707  /// Creates clause with a list of variables \a VL.
3708  ///
3709  /// \param StartLoc Starting location of the clause.
3710  /// \param LParenLoc Location of '('.
3711  /// \param ColonLoc Location of ':'.
3712  /// \param EndLoc Ending location of the clause.
3713  /// \param VL The variables in the clause.
3714  /// \param QualifierLoc The nested-name qualifier with location information
3715  /// \param NameInfo The full name info for reduction identifier.
3716  /// \param Privates List of helper expressions for proper generation of
3717  /// private copies.
3718  /// \param LHSExprs List of helper expressions for proper generation of
3719  /// assignment operation required for copyprivate clause. This list represents
3720  /// LHSs of the reduction expressions.
3721  /// \param RHSExprs List of helper expressions for proper generation of
3722  /// assignment operation required for copyprivate clause. This list represents
3723  /// RHSs of the reduction expressions.
3724  /// Also, variables in these expressions are used for proper initialization of
3725  /// reduction copies.
3726  /// \param ReductionOps List of helper expressions that represents reduction
3727  /// expressions:
3728  /// \code
3729  /// LHSExprs binop RHSExprs;
3730  /// operator binop(LHSExpr, RHSExpr);
3731  /// <CutomReduction>(LHSExpr, RHSExpr);
3732  /// \endcode
3733  /// Required for proper codegen of final reduction operation performed by the
3734  /// reduction clause.
3735  /// \param PreInit Statement that must be executed before entering the OpenMP
3736  /// region with this clause.
3737  /// \param PostUpdate Expression that must be executed after exit from the
3738  /// OpenMP region with this clause.
3739  static OMPTaskReductionClause *
3740  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3741  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3742  NestedNameSpecifierLoc QualifierLoc,
3743  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3744  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3745  ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3746 
3747  /// Creates an empty clause with the place for \a N variables.
3748  ///
3749  /// \param C AST context.
3750  /// \param N The number of variables.
3751  static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3752 
3753  /// Gets location of ':' symbol in clause.
3754  SourceLocation getColonLoc() const { return ColonLoc; }
3755 
3756  /// Gets the name info for specified reduction identifier.
3757  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3758 
3759  /// Gets the nested name specifier.
3760  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3761 
3764  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3765  using helper_expr_const_range =
3766  llvm::iterator_range<helper_expr_const_iterator>;
3767 
3769  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3770  }
3771 
3773  return helper_expr_range(getPrivates().begin(), getPrivates().end());
3774  }
3775 
3777  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3778  }
3779 
3781  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3782  }
3783 
3785  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3786  }
3787 
3789  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3790  }
3791 
3793  return helper_expr_const_range(getReductionOps().begin(),
3794  getReductionOps().end());
3795  }
3796 
3798  return helper_expr_range(getReductionOps().begin(),
3799  getReductionOps().end());
3800  }
3801 
3803  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3804  reinterpret_cast<Stmt **>(varlist_end()));
3805  }
3806 
3808  auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3809  return const_child_range(Children.begin(), Children.end());
3810  }
3811 
3814  }
3817  }
3818 
3819  static bool classof(const OMPClause *T) {
3820  return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
3821  }
3822 };
3823 
3824 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
3825 ///
3826 /// \code
3827 /// #pragma omp task in_reduction(+:a,b)
3828 /// \endcode
3829 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
3830 /// operator '+' and the variables 'a' and 'b'.
3832  : public OMPVarListClause<OMPInReductionClause>,
3833  public OMPClauseWithPostUpdate,
3834  private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
3835  friend class OMPClauseReader;
3836  friend OMPVarListClause;
3837  friend TrailingObjects;
3838 
3839  /// Location of ':'.
3840  SourceLocation ColonLoc;
3841 
3842  /// Nested name specifier for C++.
3843  NestedNameSpecifierLoc QualifierLoc;
3844 
3845  /// Name of custom operator.
3846  DeclarationNameInfo NameInfo;
3847 
3848  /// Build clause with number of variables \a N.
3849  ///
3850  /// \param StartLoc Starting location of the clause.
3851  /// \param LParenLoc Location of '('.
3852  /// \param EndLoc Ending location of the clause.
3853  /// \param ColonLoc Location of ':'.
3854  /// \param N Number of the variables in the clause.
3855  /// \param QualifierLoc The nested-name qualifier with location information
3856  /// \param NameInfo The full name info for reduction identifier.
3858  SourceLocation ColonLoc, SourceLocation EndLoc,
3859  unsigned N, NestedNameSpecifierLoc QualifierLoc,
3860  const DeclarationNameInfo &NameInfo)
3861  : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
3862  StartLoc, LParenLoc, EndLoc, N),
3863  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3864  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3865 
3866  /// Build an empty clause.
3867  ///
3868  /// \param N Number of variables.
3869  explicit OMPInReductionClause(unsigned N)
3871  llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
3872  SourceLocation(), N),
3873  OMPClauseWithPostUpdate(this) {}
3874 
3875  /// Sets location of ':' symbol in clause.
3876  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3877 
3878  /// Sets the name info for specified reduction identifier.
3879  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3880 
3881  /// Sets the nested name specifier.
3882  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3883 
3884  /// Set list of helper expressions, required for proper codegen of the clause.
3885  /// These expressions represent private copy of the reduction variable.
3886  void setPrivates(ArrayRef<Expr *> Privates);
3887 
3888  /// Get the list of helper privates.
3889  MutableArrayRef<Expr *> getPrivates() {
3890  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3891  }
3892  ArrayRef<const Expr *> getPrivates() const {
3893  return llvm::makeArrayRef(varlist_end(), varlist_size());
3894  }
3895 
3896  /// Set list of helper expressions, required for proper codegen of the clause.
3897  /// These expressions represent LHS expression in the final reduction
3898  /// expression performed by the reduction clause.
3899  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3900 
3901  /// Get the list of helper LHS expressions.
3902  MutableArrayRef<Expr *> getLHSExprs() {
3903  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3904  }
3905  ArrayRef<const Expr *> getLHSExprs() const {
3906  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3907  }
3908 
3909  /// Set list of helper expressions, required for proper codegen of the clause.
3910  /// These expressions represent RHS expression in the final reduction
3911  /// expression performed by the reduction clause. Also, variables in these
3912  /// expressions are used for proper initialization of reduction copies.
3913  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3914 
3915  /// Get the list of helper destination expressions.
3916  MutableArrayRef<Expr *> getRHSExprs() {
3917  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3918  }
3919  ArrayRef<const Expr *> getRHSExprs() const {
3920  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3921  }
3922 
3923  /// Set list of helper reduction expressions, required for proper
3924  /// codegen of the clause. These expressions are binary expressions or
3925  /// operator/custom reduction call that calculates new value from source
3926  /// helper expressions to destination helper expressions.
3927  void setReductionOps(ArrayRef<Expr *> ReductionOps);
3928 
3929  /// Get the list of helper reduction expressions.
3930  MutableArrayRef<Expr *> getReductionOps() {
3931  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3932  }
3933  ArrayRef<const Expr *> getReductionOps() const {
3934  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3935  }
3936 
3937  /// Set list of helper reduction taskgroup descriptors.
3938  void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3939 
3940  /// Get the list of helper reduction taskgroup descriptors.
3941  MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3942  return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3943  }
3944  ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3945  return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3946  }
3947 
3948 public:
3949  /// Creates clause with a list of variables \a VL.
3950  ///
3951  /// \param StartLoc Starting location of the clause.
3952  /// \param LParenLoc Location of '('.
3953  /// \param ColonLoc Location of ':'.
3954  /// \param EndLoc Ending location of the clause.
3955  /// \param VL The variables in the clause.
3956  /// \param QualifierLoc The nested-name qualifier with location information
3957  /// \param NameInfo The full name info for reduction identifier.
3958  /// \param Privates List of helper expressions for proper generation of
3959  /// private copies.
3960  /// \param LHSExprs List of helper expressions for proper generation of
3961  /// assignment operation required for copyprivate clause. This list represents
3962  /// LHSs of the reduction expressions.
3963  /// \param RHSExprs List of helper expressions for proper generation of
3964  /// assignment operation required for copyprivate clause. This list represents
3965  /// RHSs of the reduction expressions.
3966  /// Also, variables in these expressions are used for proper initialization of
3967  /// reduction copies.
3968  /// \param ReductionOps List of helper expressions that represents reduction
3969  /// expressions:
3970  /// \code
3971  /// LHSExprs binop RHSExprs;
3972  /// operator binop(LHSExpr, RHSExpr);
3973  /// <CutomReduction>(LHSExpr, RHSExpr);
3974  /// \endcode
3975  /// Required for proper codegen of final reduction operation performed by the
3976  /// reduction clause.
3977  /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3978  /// corresponding items in parent taskgroup task_reduction clause.
3979  /// \param PreInit Statement that must be executed before entering the OpenMP
3980  /// region with this clause.
3981  /// \param PostUpdate Expression that must be executed after exit from the
3982  /// OpenMP region with this clause.
3983  static OMPInReductionClause *
3984  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3985  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3986  NestedNameSpecifierLoc QualifierLoc,
3987  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3988  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3989  ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3990  Stmt *PreInit, Expr *PostUpdate);
3991 
3992  /// Creates an empty clause with the place for \a N variables.
3993  ///
3994  /// \param C AST context.
3995  /// \param N The number of variables.
3996  static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3997 
3998  /// Gets location of ':' symbol in clause.
3999  SourceLocation getColonLoc() const { return ColonLoc; }
4000 
4001  /// Gets the name info for specified reduction identifier.
4002  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
4003 
4004  /// Gets the nested name specifier.
4005  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4006 
4009  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4010  using helper_expr_const_range =
4011  llvm::iterator_range<helper_expr_const_iterator>;
4012 
4014  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
4015  }
4016 
4018  return helper_expr_range(getPrivates().begin(), getPrivates().end());
4019  }
4020 
4022  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
4023  }
4024 
4026  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
4027  }
4028 
4030  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
4031  }
4032 
4034  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
4035  }
4036 
4038  return helper_expr_const_range(getReductionOps().begin(),
4039  getReductionOps().end());
4040  }
4041 
4043  return helper_expr_range(getReductionOps().begin(),
4044  getReductionOps().end());
4045  }
4046 
4048  return helper_expr_const_range(getTaskgroupDescriptors().begin(),
4049  getTaskgroupDescriptors().end());
4050  }
4051 
4053  return helper_expr_range(getTaskgroupDescriptors().begin(),
4054  getTaskgroupDescriptors().end());
4055  }
4056 
4058  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4059  reinterpret_cast<Stmt **>(varlist_end()));
4060  }
4061 
4063  auto Children = const_cast<OMPInReductionClause *>(this)->children();
4064  return const_child_range(Children.begin(), Children.end());
4065  }
4066 
4069  }
4072  }
4073 
4074  static bool classof(const OMPClause *T) {
4075  return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
4076  }
4077 };
4078 
4079 /// This represents clause 'linear' in the '#pragma omp ...'
4080 /// directives.
4081 ///
4082 /// \code
4083 /// #pragma omp simd linear(a,b : 2)
4084 /// \endcode
4085 /// In this example directive '#pragma omp simd' has clause 'linear'
4086 /// with variables 'a', 'b' and linear step '2'.
4087 class OMPLinearClause final
4088  : public OMPVarListClause<OMPLinearClause>,
4089  public OMPClauseWithPostUpdate,
4090  private llvm::TrailingObjects<OMPLinearClause, Expr *> {
4091  friend class OMPClauseReader;
4092  friend OMPVarListClause;
4093  friend TrailingObjects;
4094 
4095  /// Modifier of 'linear' clause.
4096  OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
4097 
4098  /// Location of linear modifier if any.
4099  SourceLocation ModifierLoc;
4100 
4101  /// Location of ':'.
4102  SourceLocation ColonLoc;
4103 
4104  /// Sets the linear step for clause.
4105  void setStep(Expr *Step) { *(getFinals().end()) = Step; }
4106 
4107  /// Sets the expression to calculate linear step for clause.
4108  void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
4109 
4110  /// Build 'linear' clause with given number of variables \a NumVars.
4111  ///
4112  /// \param StartLoc Starting location of the clause.
4113  /// \param LParenLoc Location of '('.
4114  /// \param ColonLoc Location of ':'.
4115  /// \param EndLoc Ending location of the clause.
4116  /// \param NumVars Number of variables.
4117  OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4118  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4119  SourceLocation ColonLoc, SourceLocation EndLoc,
4120  unsigned NumVars)
4121  : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
4122  LParenLoc, EndLoc, NumVars),
4123  OMPClauseWithPostUpdate(this), Modifier(Modifier),
4124  ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
4125 
4126  /// Build an empty clause.
4127  ///
4128  /// \param NumVars Number of variables.
4129  explicit OMPLinearClause(unsigned NumVars)
4130  : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
4131  SourceLocation(), SourceLocation(),
4132  SourceLocation(), NumVars),
4133  OMPClauseWithPostUpdate(this) {}
4134 
4135  /// Gets the list of initial values for linear variables.
4136  ///
4137  /// There are NumVars expressions with initial values allocated after the
4138  /// varlist, they are followed by NumVars update expressions (used to update
4139  /// the linear variable's value on current iteration) and they are followed by
4140  /// NumVars final expressions (used to calculate the linear variable's
4141  /// value after the loop body). After these lists, there are 2 helper
4142  /// expressions - linear step and a helper to calculate it before the
4143  /// loop body (used when the linear step is not constant):
4144  ///
4145  /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
4146  /// Finals[]; Step; CalcStep; }
4147  MutableArrayRef<Expr *> getPrivates() {
4148  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4149  }
4150  ArrayRef<const Expr *> getPrivates() const {
4151  return llvm::makeArrayRef(varlist_end(), varlist_size());
4152  }
4153 
4154  MutableArrayRef<Expr *> getInits() {
4155  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
4156  }
4157  ArrayRef<const Expr *> getInits() const {
4158  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
4159  }
4160 
4161  /// Sets the list of update expressions for linear variables.
4162  MutableArrayRef<Expr *> getUpdates() {
4163  return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
4164  }
4165  ArrayRef<const Expr *> getUpdates() const {
4166  return llvm::makeArrayRef(getInits().end(), varlist_size());
4167  }
4168 
4169  /// Sets the list of final update expressions for linear variables.
4170  MutableArrayRef<Expr *> getFinals() {
4171  return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
4172  }
4173  ArrayRef<const Expr *> getFinals() const {
4174  return llvm::makeArrayRef(getUpdates().end(), varlist_size());
4175  }
4176 
4177  /// Gets the list of used expressions for linear variables.
4178  MutableArrayRef<Expr *> getUsedExprs() {
4179  return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
4180  }
4181  ArrayRef<const Expr *> getUsedExprs() const {
4182  return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
4183  }
4184 
4185  /// Sets the list of the copies of original linear variables.
4186  /// \param PL List of expressions.
4187  void setPrivates(ArrayRef<Expr *> PL);
4188 
4189  /// Sets the list of the initial values for linear variables.
4190  /// \param IL List of expressions.
4191  void setInits(ArrayRef<Expr *> IL);
4192 
4193 public:
4194  /// Creates clause with a list of variables \a VL and a linear step
4195  /// \a Step.
4196  ///
4197  /// \param C AST Context.
4198  /// \param StartLoc Starting location of the clause.
4199  /// \param LParenLoc Location of '('.
4200  /// \param Modifier Modifier of 'linear' clause.
4201  /// \param ModifierLoc Modifier location.
4202  /// \param ColonLoc Location of ':'.
4203  /// \param EndLoc Ending location of the clause.
4204  /// \param VL List of references to the variables.
4205  /// \param PL List of private copies of original variables.
4206  /// \param IL List of initial values for the variables.
4207  /// \param Step Linear step.
4208  /// \param CalcStep Calculation of the linear step.
4209  /// \param PreInit Statement that must be executed before entering the OpenMP
4210  /// region with this clause.
4211  /// \param PostUpdate Expression that must be executed after exit from the
4212  /// OpenMP region with this clause.
4213  static OMPLinearClause *
4214  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4215  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
4216  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
4217  ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
4218  Stmt *PreInit, Expr *PostUpdate);
4219 
4220  /// Creates an empty clause with the place for \a NumVars variables.
4221  ///
4222  /// \param C AST context.
4223  /// \param NumVars Number of variables.
4224  static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4225 
4226  /// Set modifier.
4228 
4229  /// Return modifier.
4230  OpenMPLinearClauseKind getModifier() const { return Modifier; }
4231 
4232  /// Set modifier location.
4233  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4234 
4235  /// Return modifier location.
4236  SourceLocation getModifierLoc() const { return ModifierLoc; }
4237 
4238  /// Sets the location of ':'.
4239  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4240 
4241  /// Returns the location of ':'.
4242  SourceLocation getColonLoc() const { return ColonLoc; }
4243 
4244  /// Returns linear step.
4245  Expr *getStep() { return *(getFinals().end()); }
4246 
4247  /// Returns linear step.
4248  const Expr *getStep() const { return *(getFinals().end()); }
4249 
4250  /// Returns expression to calculate linear step.
4251  Expr *getCalcStep() { return *(getFinals().end() + 1); }
4252 
4253  /// Returns expression to calculate linear step.
4254  const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
4255 
4256  /// Sets the list of update expressions for linear variables.
4257  /// \param UL List of expressions.
4258  void setUpdates(ArrayRef<Expr *> UL);
4259 
4260  /// Sets the list of final update expressions for linear variables.
4261  /// \param FL List of expressions.
4262  void setFinals(ArrayRef<Expr *> FL);
4263 
4264  /// Sets the list of used expressions for the linear clause.
4265  void setUsedExprs(ArrayRef<Expr *> UE);
4266 
4269  using privates_range = llvm::iterator_range<privates_iterator>;
4270  using privates_const_range = llvm::iterator_range<privates_const_iterator>;
4271 
4273  return privates_range(getPrivates().begin(), getPrivates().end());
4274  }
4275 
4277  return privates_const_range(getPrivates().begin(), getPrivates().end());
4278  }
4279 
4282  using inits_range = llvm::iterator_range<inits_iterator>;
4283  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
4284 
4286  return inits_range(getInits().begin(), getInits().end());
4287  }
4288 
4290  return inits_const_range(getInits().begin(), getInits().end());
4291  }
4292 
4295  using updates_range = llvm::iterator_range<updates_iterator>;
4296  using updates_const_range = llvm::iterator_range<updates_const_iterator>;
4297 
4299  return updates_range(getUpdates().begin(), getUpdates().end());
4300  }
4301 
4303  return updates_const_range(getUpdates().begin(), getUpdates().end());
4304  }
4305 
4308  using finals_range = llvm::iterator_range<finals_iterator>;
4309  using finals_const_range = llvm::iterator_range<finals_const_iterator>;
4310 
4312  return finals_range(getFinals().begin(), getFinals().end());
4313  }
4314 
4316  return finals_const_range(getFinals().begin(), getFinals().end());
4317  }
4318 
4321  using used_expressions_range =
4322  llvm::iterator_range<used_expressions_iterator>;
4324  llvm::iterator_range<used_expressions_const_iterator>;
4325 
4327  return finals_range(getUsedExprs().begin(), getUsedExprs().end());
4328  }
4329 
4331  return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
4332  }
4333 
4335  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4336  reinterpret_cast<Stmt **>(varlist_end()));
4337  }
4338 
4340  auto Children = const_cast<OMPLinearClause *>(this)->children();
4341  return const_child_range(Children.begin(), Children.end());
4342  }
4343 
4345 
4347  auto Children = const_cast<OMPLinearClause *>(this)->used_children();
4348  return const_child_range(Children.begin(), Children.end());
4349  }
4350 
4351  static bool classof(const OMPClause *T) {
4352  return T->getClauseKind() == llvm::omp::OMPC_linear;
4353  }
4354 };
4355 
4356 /// This represents clause 'aligned' in the '#pragma omp ...'
4357 /// directives.
4358 ///
4359 /// \code
4360 /// #pragma omp simd aligned(a,b : 8)
4361 /// \endcode
4362 /// In this example directive '#pragma omp simd' has clause 'aligned'
4363 /// with variables 'a', 'b' and alignment '8'.
4364 class OMPAlignedClause final
4365  : public OMPVarListClause<OMPAlignedClause>,
4366  private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
4367  friend class OMPClauseReader;
4368  friend OMPVarListClause;
4369  friend TrailingObjects;
4370 
4371  /// Location of ':'.
4372  SourceLocation ColonLoc;
4373 
4374  /// Sets the alignment for clause.
4375  void setAlignment(Expr *A) { *varlist_end() = A; }
4376 
4377  /// Build 'aligned' clause with given number of variables \a NumVars.
4378  ///
4379  /// \param StartLoc Starting location of the clause.
4380  /// \param LParenLoc Location of '('.
4381  /// \param ColonLoc Location of ':'.
4382  /// \param EndLoc Ending location of the clause.
4383  /// \param NumVars Number of variables.
4384  OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4385  SourceLocation ColonLoc, SourceLocation EndLoc,
4386  unsigned NumVars)
4387  : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
4388  LParenLoc, EndLoc, NumVars),
4389  ColonLoc(ColonLoc) {}
4390 
4391  /// Build an empty clause.
4392  ///
4393  /// \param NumVars Number of variables.
4394  explicit OMPAlignedClause(unsigned NumVars)
4395  : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
4396  SourceLocation(), SourceLocation(),
4397  SourceLocation(), NumVars) {}
4398 
4399 public:
4400  /// Creates clause with a list of variables \a VL and alignment \a A.
4401  ///
4402  /// \param C AST Context.
4403  /// \param StartLoc Starting location of the clause.
4404  /// \param LParenLoc Location of '('.
4405  /// \param ColonLoc Location of ':'.
4406  /// \param EndLoc Ending location of the clause.
4407  /// \param VL List of references to the variables.
4408  /// \param A Alignment.
4409  static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
4410  SourceLocation LParenLoc,
4411  SourceLocation ColonLoc,
4412  SourceLocation EndLoc, ArrayRef<Expr *> VL,
4413  Expr *A);
4414 
4415  /// Creates an empty clause with the place for \a NumVars variables.
4416  ///
4417  /// \param C AST context.
4418  /// \param NumVars Number of variables.
4419  static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4420 
4421  /// Sets the location of ':'.
4422  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4423 
4424  /// Returns the location of ':'.
4425  SourceLocation getColonLoc() const { return ColonLoc; }
4426 
4427  /// Returns alignment.
4428  Expr *getAlignment() { return *varlist_end(); }
4429 
4430  /// Returns alignment.
4431  const Expr *getAlignment() const { return *varlist_end(); }
4432 
4434  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4435  reinterpret_cast<Stmt **>(varlist_end()));
4436  }
4437 
4439  auto Children = const_cast<OMPAlignedClause *>(this)->children();
4440  return const_child_range(Children.begin(), Children.end());
4441  }
4442 
4445  }
4448  }
4449 
4450  static bool classof(const OMPClause *T) {
4451  return T->getClauseKind() == llvm::omp::OMPC_aligned;
4452  }
4453 };
4454 
4455 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
4456 ///
4457 /// \code
4458 /// #pragma omp parallel copyin(a,b)
4459 /// \endcode
4460 /// In this example directive '#pragma omp parallel' has clause 'copyin'
4461 /// with the variables 'a' and 'b'.
4462 class OMPCopyinClause final
4463  : public OMPVarListClause<OMPCopyinClause>,
4464  private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
4465  // Class has 3 additional tail allocated arrays:
4466  // 1. List of helper expressions for proper generation of assignment operation
4467  // required for copyin clause. This list represents sources.
4468  // 2. List of helper expressions for proper generation of assignment operation
4469  // required for copyin clause. This list represents destinations.
4470  // 3. List of helper expressions that represents assignment operation:
4471  // \code
4472  // DstExprs = SrcExprs;
4473  // \endcode
4474  // Required for proper codegen of propagation of master's thread values of
4475  // threadprivate variables to local instances of that variables in other
4476  // implicit threads.
4477 
4478  friend class OMPClauseReader;
4479  friend OMPVarListClause;
4480  friend TrailingObjects;
4481 
4482  /// Build clause with number of variables \a N.
4483  ///
4484  /// \param StartLoc Starting location of the clause.
4485  /// \param LParenLoc Location of '('.
4486  /// \param EndLoc Ending location of the clause.
4487  /// \param N Number of the variables in the clause.
4488  OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4489  SourceLocation EndLoc, unsigned N)
4490  : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
4491  LParenLoc, EndLoc, N) {}
4492 
4493  /// Build an empty clause.
4494  ///
4495  /// \param N Number of variables.
4496  explicit OMPCopyinClause(unsigned N)
4497  : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
4499  SourceLocation(), N) {}
4500 
4501  /// Set list of helper expressions, required for proper codegen of the
4502  /// clause. These expressions represent source expression in the final
4503  /// assignment statement performed by the copyin clause.
4504  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4505 
4506  /// Get the list of helper source expressions.
4507  MutableArrayRef<Expr *> getSourceExprs() {
4508  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4509  }
4510  ArrayRef<const Expr *> getSourceExprs() const {
4511  return llvm::makeArrayRef(varlist_end(), varlist_size());
4512  }
4513 
4514  /// Set list of helper expressions, required for proper codegen of the
4515  /// clause. These expressions represent destination expression in the final
4516  /// assignment statement performed by the copyin clause.
4517  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4518 
4519  /// Get the list of helper destination expressions.
4520  MutableArrayRef<Expr *> getDestinationExprs() {
4521  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4522  }
4523  ArrayRef<const Expr *> getDestinationExprs() const {
4524  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
4525  }
4526 
4527  /// Set list of helper assignment expressions, required for proper
4528  /// codegen of the clause. These expressions are assignment expressions that
4529  /// assign source helper expressions to destination helper expressions
4530  /// correspondingly.
4531  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4532 
4533  /// Get the list of helper assignment expressions.
4534  MutableArrayRef<Expr *> getAssignmentOps() {
4535  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4536  }
4537  ArrayRef<const Expr *> getAssignmentOps() const {
4538  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
4539  }
4540 
4541 public:
4542  /// Creates clause with a list of variables \a VL.
4543  ///
4544  /// \param C AST context.
4545  /// \param StartLoc Starting location of the clause.
4546  /// \param LParenLoc Location of '('.
4547  /// \param EndLoc Ending location of the clause.
4548  /// \param VL List of references to the variables.
4549  /// \param SrcExprs List of helper expressions for proper generation of
4550  /// assignment operation required for copyin clause. This list represents
4551  /// sources.
4552  /// \param DstExprs List of helper expressions for proper generation of
4553  /// assignment operation required for copyin clause. This list represents
4554  /// destinations.
4555  /// \param AssignmentOps List of helper expressions that represents assignment
4556  /// operation:
4557  /// \code
4558  /// DstExprs = SrcExprs;
4559  /// \endcode
4560  /// Required for proper codegen of propagation of master's thread values of
4561  /// threadprivate variables to local instances of that variables in other
4562  /// implicit threads.
4563  static OMPCopyinClause *
4564  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4565  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4566  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4567 
4568  /// Creates an empty clause with \a N variables.
4569  ///
4570  /// \param C AST context.
4571  /// \param N The number of variables.
4572  static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
4573 
4576  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4577  using helper_expr_const_range =
4578  llvm::iterator_range<helper_expr_const_iterator>;
4579 
4581  return helper_expr_const_range(getSourceExprs().begin(),
4582  getSourceExprs().end());
4583  }
4584 
4586  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4587  }
4588 
4590  return helper_expr_const_range(getDestinationExprs().begin(),
4591  getDestinationExprs().end());
4592  }
4593 
4595  return helper_expr_range(getDestinationExprs().begin(),
4596  getDestinationExprs().end());
4597  }
4598 
4600  return helper_expr_const_range(getAssignmentOps().begin(),
4601  getAssignmentOps().end());
4602  }
4603 
4605  return helper_expr_range(getAssignmentOps().begin(),
4606  getAssignmentOps().end());
4607  }
4608 
4610  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4611  reinterpret_cast<Stmt **>(varlist_end()));
4612  }
4613 
4615  auto Children = const_cast<OMPCopyinClause *>(this)->children();
4616  return const_child_range(Children.begin(), Children.end());
4617  }
4618 
4621  }
4624  }
4625 
4626  static bool classof(const OMPClause *T) {
4627  return T->getClauseKind() == llvm::omp::OMPC_copyin;
4628  }
4629 };
4630 
4631 /// This represents clause 'copyprivate' in the '#pragma omp ...'
4632 /// directives.
4633 ///
4634 /// \code
4635 /// #pragma omp single copyprivate(a,b)
4636 /// \endcode
4637 /// In this example directive '#pragma omp single' has clause 'copyprivate'
4638 /// with the variables 'a' and 'b'.
4640  : public OMPVarListClause<OMPCopyprivateClause>,
4641  private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
4642  friend class OMPClauseReader;
4643  friend OMPVarListClause;
4644  friend TrailingObjects;
4645 
4646  /// Build clause with number of variables \a N.
4647  ///
4648  /// \param StartLoc Starting location of the clause.
4649  /// \param LParenLoc Location of '('.
4650  /// \param EndLoc Ending location of the clause.
4651  /// \param N Number of the variables in the clause.
4653  SourceLocation EndLoc, unsigned N)
4654  : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
4655  StartLoc, LParenLoc, EndLoc, N) {
4656  }
4657 
4658  /// Build an empty clause.
4659  ///
4660  /// \param N Number of variables.
4661  explicit OMPCopyprivateClause(unsigned N)
4663  llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
4664  SourceLocation(), N) {}
4665 
4666  /// Set list of helper expressions, required for proper codegen of the
4667  /// clause. These expressions represent source expression in the final
4668  /// assignment statement performed by the copyprivate clause.
4669  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4670 
4671  /// Get the list of helper source expressions.
4672  MutableArrayRef<Expr *> getSourceExprs() {
4673  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4674  }
4675  ArrayRef<const Expr *> getSourceExprs() const {
4676  return llvm::makeArrayRef(varlist_end(), varlist_size());
4677  }
4678 
4679  /// Set list of helper expressions, required for proper codegen of the
4680  /// clause. These expressions represent destination expression in the final
4681  /// assignment statement performed by the copyprivate clause.
4682  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4683 
4684  /// Get the list of helper destination expressions.
4685  MutableArrayRef<Expr *> getDestinationExprs() {
4686  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4687  }
4688  ArrayRef<const Expr *> getDestinationExprs() const {
4689  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
4690  }
4691 
4692  /// Set list of helper assignment expressions, required for proper
4693  /// codegen of the clause. These expressions are assignment expressions that
4694  /// assign source helper expressions to destination helper expressions
4695  /// correspondingly.
4696  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4697 
4698  /// Get the list of helper assignment expressions.
4699  MutableArrayRef<Expr *> getAssignmentOps() {
4700  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4701  }
4702  ArrayRef<const Expr *> getAssignmentOps() const {
4703  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
4704  }
4705 
4706 public:
4707  /// Creates clause with a list of variables \a VL.
4708  ///
4709  /// \param C AST context.
4710  /// \param StartLoc Starting location of the clause.
4711  /// \param LParenLoc Location of '('.
4712  /// \param EndLoc Ending location of the clause.
4713  /// \param VL List of references to the variables.
4714  /// \param SrcExprs List of helper expressions for proper generation of
4715  /// assignment operation required for copyprivate clause. This list represents
4716  /// sources.
4717  /// \param DstExprs List of helper expressions for proper generation of
4718  /// assignment operation required for copyprivate clause. This list represents
4719  /// destinations.
4720  /// \param AssignmentOps List of helper expressions that represents assignment
4721  /// operation:
4722  /// \code
4723  /// DstExprs = SrcExprs;
4724  /// \endcode
4725  /// Required for proper codegen of final assignment performed by the
4726  /// copyprivate clause.
4727  static OMPCopyprivateClause *
4728  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4729  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4730  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4731 
4732  /// Creates an empty clause with \a N variables.
4733  ///
4734  /// \param C AST context.
4735  /// \param N The number of variables.
4736  static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
4737 
4740  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4741  using helper_expr_const_range =
4742  llvm::iterator_range<helper_expr_const_iterator>;
4743 
4745  return helper_expr_const_range(getSourceExprs().begin(),
4746  getSourceExprs().end());
4747  }
4748 
4750  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4751  }
4752 
4754  return helper_expr_const_range(getDestinationExprs().begin(),
4755  getDestinationExprs().end());
4756  }
4757 
4759  return helper_expr_range(getDestinationExprs().begin(),
4760  getDestinationExprs().end());
4761  }
4762 
4764  return helper_expr_const_range(getAssignmentOps().begin(),
4765  getAssignmentOps().end());
4766  }
4767 
4769  return helper_expr_range(getAssignmentOps().begin(),
4770  getAssignmentOps().end());
4771  }
4772 
4774  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4775  reinterpret_cast<Stmt **>(varlist_end()));
4776  }
4777 
4779  auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
4780  return const_child_range(Children.begin(), Children.end());
4781  }
4782 
4785  }
4788  }
4789 
4790  static bool classof(const OMPClause *T) {
4791  return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
4792  }
4793 };
4794 
4795 /// This represents implicit clause 'flush' for the '#pragma omp flush'
4796 /// directive.
4797 /// This clause does not exist by itself, it can be only as a part of 'omp
4798 /// flush' directive. This clause is introduced to keep the original structure
4799 /// of \a OMPExecutableDirective class and its derivatives and to use the
4800 /// existing infrastructure of clauses with the list of variables.
4801 ///
4802 /// \code
4803 /// #pragma omp flush(a,b)
4804 /// \endcode
4805 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
4806 /// with the variables 'a' and 'b'.
4807 class OMPFlushClause final
4808  : public OMPVarListClause<OMPFlushClause>,
4809  private llvm::TrailingObjects<OMPFlushClause, Expr *> {
4810  friend OMPVarListClause;
4811  friend TrailingObjects;
4812 
4813  /// Build clause with number of variables \a N.
4814  ///
4815  /// \param StartLoc Starting location of the clause.
4816  /// \param LParenLoc Location of '('.
4817  /// \param EndLoc Ending location of the clause.
4818  /// \param N Number of the variables in the clause.
4819  OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4820  SourceLocation EndLoc, unsigned N)
4821  : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
4822  LParenLoc, EndLoc, N) {}
4823 
4824  /// Build an empty clause.
4825  ///
4826  /// \param N Number of variables.
4827  explicit OMPFlushClause(unsigned N)
4828  : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
4830  SourceLocation(), N) {}
4831 
4832 public:
4833  /// Creates clause with a list of variables \a VL.
4834  ///
4835  /// \param C AST context.
4836  /// \param StartLoc Starting location of the clause.
4837  /// \param LParenLoc Location of '('.
4838  /// \param EndLoc Ending location of the clause.
4839  /// \param VL List of references to the variables.
4840  static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
4841  SourceLocation LParenLoc, SourceLocation EndLoc,
4842  ArrayRef<Expr *> VL);
4843 
4844  /// Creates an empty clause with \a N variables.
4845  ///
4846  /// \param C AST context.
4847  /// \param N The number of variables.
4848  static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
4849 
4851  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4852  reinterpret_cast<Stmt **>(varlist_end()));
4853  }
4854 
4856  auto Children = const_cast<OMPFlushClause *>(this)->children();
4857  return const_child_range(Children.begin(), Children.end());
4858  }
4859 
4862  }
4865  }
4866 
4867  static bool classof(const OMPClause *T) {
4868  return T->getClauseKind() == llvm::omp::OMPC_flush;
4869  }
4870 };
4871 
4872 /// This represents implicit clause 'depobj' for the '#pragma omp depobj'
4873 /// directive.
4874 /// This clause does not exist by itself, it can be only as a part of 'omp
4875 /// depobj' directive. This clause is introduced to keep the original structure
4876 /// of \a OMPExecutableDirective class and its derivatives and to use the
4877 /// existing infrastructure of clauses with the list of variables.
4878 ///
4879 /// \code
4880 /// #pragma omp depobj(a) destroy
4881 /// \endcode
4882 /// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
4883 /// with the depobj 'a'.
4884 class OMPDepobjClause final : public OMPClause {
4885  friend class OMPClauseReader;
4886 
4887  /// Location of '('.
4888  SourceLocation LParenLoc;
4889 
4890  /// Chunk size.
4891  Expr *Depobj = nullptr;
4892 
4893  /// Build clause with number of variables \a N.
4894  ///
4895  /// \param StartLoc Starting location of the clause.
4896  /// \param LParenLoc Location of '('.
4897  /// \param EndLoc Ending location of the clause.
4898  OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4899  SourceLocation EndLoc)
4900  : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
4901  LParenLoc(LParenLoc) {}
4902 
4903  /// Build an empty clause.
4904  ///
4905  explicit OMPDepobjClause()
4906  : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
4907 
4908  void setDepobj(Expr *E) { Depobj = E; }
4909 
4910  /// Sets the location of '('.
4911  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4912 
4913 public:
4914  /// Creates clause.
4915  ///
4916  /// \param C AST context.
4917  /// \param StartLoc Starting location of the clause.
4918  /// \param LParenLoc Location of '('.
4919  /// \param EndLoc Ending location of the clause.
4920  /// \param Depobj depobj expression associated with the 'depobj' directive.
4921  static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc,
4922  SourceLocation LParenLoc,
4923  SourceLocation EndLoc, Expr *Depobj);
4924 
4925  /// Creates an empty clause.
4926  ///
4927  /// \param C AST context.
4928  static OMPDepobjClause *CreateEmpty(const ASTContext &C);
4929 
4930  /// Returns depobj expression associated with the clause.
4931  Expr *getDepobj() { return Depobj; }
4932  const Expr *getDepobj() const { return Depobj; }
4933 
4934  /// Returns the location of '('.
4935  SourceLocation getLParenLoc() const { return LParenLoc; }
4936 
4938  return child_range(reinterpret_cast<Stmt **>(&Depobj),
4939  reinterpret_cast<Stmt **>(&Depobj) + 1);
4940  }
4941 
4943  auto Children = const_cast<OMPDepobjClause *>(this)->children();
4944  return const_child_range(Children.begin(), Children.end());
4945  }
4946 
4949  }
4952  }
4953 
4954  static bool classof(const OMPClause *T) {
4955  return T->getClauseKind() == llvm::omp::OMPC_depobj;
4956  }
4957 };
4958 
4959 /// This represents implicit clause 'depend' for the '#pragma omp task'
4960 /// directive.
4961 ///
4962 /// \code
4963 /// #pragma omp task depend(in:a,b)
4964 /// \endcode
4965 /// In this example directive '#pragma omp task' with clause 'depend' with the
4966 /// variables 'a' and 'b' with dependency 'in'.
4967 class OMPDependClause final
4968  : public OMPVarListClause<OMPDependClause>,
4969  private llvm::TrailingObjects<OMPDependClause, Expr *> {
4970  friend class OMPClauseReader;
4971  friend OMPVarListClause;
4972  friend TrailingObjects;
4973 
4974 public:
4975  struct DependDataTy final {
4976  /// Dependency type (one of in, out, inout).
4978 
4979  /// Dependency type location.
4981 
4982  /// Colon location.
4984 
4985  /// Location of 'omp_all_memory'.
4987  };
4988 
4989 private:
4990  /// Dependency type and source locations.
4991