clang  15.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 'schedule' clause in the '#pragma omp ...' directive.
1567 ///
1568 /// \code
1569 /// #pragma omp for schedule(static, 3)
1570 /// \endcode
1571 /// In this example directive '#pragma omp for' has 'schedule' clause with
1572 /// arguments 'static' and '3'.
1574  friend class OMPClauseReader;
1575 
1576  /// Location of '('.
1577  SourceLocation LParenLoc;
1578 
1579  /// A kind of the 'schedule' clause.
1581 
1582  /// Modifiers for 'schedule' clause.
1583  enum {FIRST, SECOND, NUM_MODIFIERS};
1584  OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1585 
1586  /// Locations of modifiers.
1587  SourceLocation ModifiersLoc[NUM_MODIFIERS];
1588 
1589  /// Start location of the schedule ind in source code.
1590  SourceLocation KindLoc;
1591 
1592  /// Location of ',' (if any).
1593  SourceLocation CommaLoc;
1594 
1595  /// Chunk size.
1596  Expr *ChunkSize = nullptr;
1597 
1598  /// Set schedule kind.
1599  ///
1600  /// \param K Schedule kind.
1601  void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1602 
1603  /// Set the first schedule modifier.
1604  ///
1605  /// \param M Schedule modifier.
1606  void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1607  Modifiers[FIRST] = M;
1608  }
1609 
1610  /// Set the second schedule modifier.
1611  ///
1612  /// \param M Schedule modifier.
1613  void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1614  Modifiers[SECOND] = M;
1615  }
1616 
1617  /// Set location of the first schedule modifier.
1618  void setFirstScheduleModifierLoc(SourceLocation Loc) {
1619  ModifiersLoc[FIRST] = Loc;
1620  }
1621 
1622  /// Set location of the second schedule modifier.
1623  void setSecondScheduleModifierLoc(SourceLocation Loc) {
1624  ModifiersLoc[SECOND] = Loc;
1625  }
1626 
1627  /// Set schedule modifier location.
1628  ///
1629  /// \param M Schedule modifier location.
1630  void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1631  if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1632  Modifiers[FIRST] = M;
1633  else {
1634  assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1635  Modifiers[SECOND] = M;
1636  }
1637  }
1638 
1639  /// Sets the location of '('.
1640  ///
1641  /// \param Loc Location of '('.
1642  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1643 
1644  /// Set schedule kind start location.
1645  ///
1646  /// \param KLoc Schedule kind location.
1647  void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1648 
1649  /// Set location of ','.
1650  ///
1651  /// \param Loc Location of ','.
1652  void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1653 
1654  /// Set chunk size.
1655  ///
1656  /// \param E Chunk size.
1657  void setChunkSize(Expr *E) { ChunkSize = E; }
1658 
1659 public:
1660  /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1661  /// expression \a ChunkSize.
1662  ///
1663  /// \param StartLoc Starting location of the clause.
1664  /// \param LParenLoc Location of '('.
1665  /// \param KLoc Starting location of the argument.
1666  /// \param CommaLoc Location of ','.
1667  /// \param EndLoc Ending location of the clause.
1668  /// \param Kind Schedule kind.
1669  /// \param ChunkSize Chunk size.
1670  /// \param HelperChunkSize Helper chunk size for combined directives.
1671  /// \param M1 The first modifier applied to 'schedule' clause.
1672  /// \param M1Loc Location of the first modifier
1673  /// \param M2 The second modifier applied to 'schedule' clause.
1674  /// \param M2Loc Location of the second modifier
1676  SourceLocation KLoc, SourceLocation CommaLoc,
1678  Expr *ChunkSize, Stmt *HelperChunkSize,
1681  : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
1682  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
1683  KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
1684  setPreInitStmt(HelperChunkSize);
1685  Modifiers[FIRST] = M1;
1686  Modifiers[SECOND] = M2;
1687  ModifiersLoc[FIRST] = M1Loc;
1688  ModifiersLoc[SECOND] = M2Loc;
1689  }
1690 
1691  /// Build an empty clause.
1693  : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
1694  OMPClauseWithPreInit(this) {
1695  Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1696  Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1697  }
1698 
1699  /// Get kind of the clause.
1701 
1702  /// Get the first modifier of the clause.
1704  return Modifiers[FIRST];
1705  }
1706 
1707  /// Get the second modifier of the clause.
1709  return Modifiers[SECOND];
1710  }
1711 
1712  /// Get location of '('.
1713  SourceLocation getLParenLoc() { return LParenLoc; }
1714 
1715  /// Get kind location.
1716  SourceLocation getScheduleKindLoc() { return KindLoc; }
1717 
1718  /// Get the first modifier location.
1720  return ModifiersLoc[FIRST];
1721  }
1722 
1723  /// Get the second modifier location.
1725  return ModifiersLoc[SECOND];
1726  }
1727 
1728  /// Get location of ','.
1729  SourceLocation getCommaLoc() { return CommaLoc; }
1730 
1731  /// Get chunk size.
1732  Expr *getChunkSize() { return ChunkSize; }
1733 
1734  /// Get chunk size.
1735  const Expr *getChunkSize() const { return ChunkSize; }
1736 
1738  return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1739  reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1740  }
1741 
1743  auto Children = const_cast<OMPScheduleClause *>(this)->children();
1744  return const_child_range(Children.begin(), Children.end());
1745  }
1746 
1749  }
1752  }
1753 
1754  static bool classof(const OMPClause *T) {
1755  return T->getClauseKind() == llvm::omp::OMPC_schedule;
1756  }
1757 };
1758 
1759 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1760 ///
1761 /// \code
1762 /// #pragma omp for ordered (2)
1763 /// \endcode
1764 /// In this example directive '#pragma omp for' has 'ordered' clause with
1765 /// parameter 2.
1766 class OMPOrderedClause final
1767  : public OMPClause,
1768  private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1769  friend class OMPClauseReader;
1770  friend TrailingObjects;
1771 
1772  /// Location of '('.
1773  SourceLocation LParenLoc;
1774 
1775  /// Number of for-loops.
1776  Stmt *NumForLoops = nullptr;
1777 
1778  /// Real number of loops.
1779  unsigned NumberOfLoops = 0;
1780 
1781  /// Build 'ordered' clause.
1782  ///
1783  /// \param Num Expression, possibly associated with this clause.
1784  /// \param NumLoops Number of loops, associated with this clause.
1785  /// \param StartLoc Starting location of the clause.
1786  /// \param LParenLoc Location of '('.
1787  /// \param EndLoc Ending location of the clause.
1788  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1789  SourceLocation LParenLoc, SourceLocation EndLoc)
1790  : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
1791  LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
1792 
1793  /// Build an empty clause.
1794  explicit OMPOrderedClause(unsigned NumLoops)
1795  : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
1796  NumberOfLoops(NumLoops) {}
1797 
1798  /// Set the number of associated for-loops.
1799  void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1800 
1801 public:
1802  /// Build 'ordered' clause.
1803  ///
1804  /// \param Num Expression, possibly associated with this clause.
1805  /// \param NumLoops Number of loops, associated with this clause.
1806  /// \param StartLoc Starting location of the clause.
1807  /// \param LParenLoc Location of '('.
1808  /// \param EndLoc Ending location of the clause.
1809  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1810  unsigned NumLoops, SourceLocation StartLoc,
1811  SourceLocation LParenLoc,
1812  SourceLocation EndLoc);
1813 
1814  /// Build an empty clause.
1815  static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1816 
1817  /// Sets the location of '('.
1818  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1819 
1820  /// Returns the location of '('.
1821  SourceLocation getLParenLoc() const { return LParenLoc; }
1822 
1823  /// Return the number of associated for-loops.
1824  Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1825 
1826  /// Set number of iterations for the specified loop.
1827  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1828  /// Get number of iterations for all the loops.
1830 
1831  /// Set loop counter for the specified loop.
1832  void setLoopCounter(unsigned NumLoop, Expr *Counter);
1833  /// Get loops counter for the specified loop.
1834  Expr *getLoopCounter(unsigned NumLoop);
1835  const Expr *getLoopCounter(unsigned NumLoop) const;
1836 
1837  child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1838 
1840  return const_child_range(&NumForLoops, &NumForLoops + 1);
1841  }
1842 
1845  }
1848  }
1849 
1850  static bool classof(const OMPClause *T) {
1851  return T->getClauseKind() == llvm::omp::OMPC_ordered;
1852  }
1853 };
1854 
1855 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1856 ///
1857 /// \code
1858 /// #pragma omp for nowait
1859 /// \endcode
1860 /// In this example directive '#pragma omp for' has 'nowait' clause.
1861 class OMPNowaitClause : public OMPClause {
1862 public:
1863  /// Build 'nowait' clause.
1864  ///
1865  /// \param StartLoc Starting location of the clause.
1866  /// \param EndLoc Ending location of the clause.
1868  : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc) {}
1869 
1870  /// Build an empty clause.
1872  : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {}
1873 
1876  }
1877 
1880  }
1881 
1884  }
1887  }
1888 
1889  static bool classof(const OMPClause *T) {
1890  return T->getClauseKind() == llvm::omp::OMPC_nowait;
1891  }
1892 };
1893 
1894 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1895 ///
1896 /// \code
1897 /// #pragma omp task untied
1898 /// \endcode
1899 /// In this example directive '#pragma omp task' has 'untied' clause.
1900 class OMPUntiedClause : public OMPClause {
1901 public:
1902  /// Build 'untied' clause.
1903  ///
1904  /// \param StartLoc Starting location of the clause.
1905  /// \param EndLoc Ending location of the clause.
1907  : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
1908 
1909  /// Build an empty clause.
1911  : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
1912 
1915  }
1916 
1919  }
1920 
1923  }
1926  }
1927 
1928  static bool classof(const OMPClause *T) {
1929  return T->getClauseKind() == llvm::omp::OMPC_untied;
1930  }
1931 };
1932 
1933 /// This represents 'mergeable' clause in the '#pragma omp ...'
1934 /// directive.
1935 ///
1936 /// \code
1937 /// #pragma omp task mergeable
1938 /// \endcode
1939 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1941 public:
1942  /// Build 'mergeable' clause.
1943  ///
1944  /// \param StartLoc Starting location of the clause.
1945  /// \param EndLoc Ending location of the clause.
1947  : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
1948 
1949  /// Build an empty clause.
1951  : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
1952  SourceLocation()) {}
1953 
1956  }
1957 
1960  }
1961 
1964  }
1967  }
1968 
1969  static bool classof(const OMPClause *T) {
1970  return T->getClauseKind() == llvm::omp::OMPC_mergeable;
1971  }
1972 };
1973 
1974 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1975 ///
1976 /// \code
1977 /// #pragma omp atomic read
1978 /// \endcode
1979 /// In this example directive '#pragma omp atomic' has 'read' clause.
1980 class OMPReadClause : public OMPClause {
1981 public:
1982  /// Build 'read' clause.
1983  ///
1984  /// \param StartLoc Starting location of the clause.
1985  /// \param EndLoc Ending location of the clause.
1987  : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
1988 
1989  /// Build an empty clause.
1991  : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
1992 
1995  }
1996 
1999  }
2000 
2003  }
2006  }
2007 
2008  static bool classof(const OMPClause *T) {
2009  return T->getClauseKind() == llvm::omp::OMPC_read;
2010  }
2011 };
2012 
2013 /// This represents 'write' clause in the '#pragma omp atomic' directive.
2014 ///
2015 /// \code
2016 /// #pragma omp atomic write
2017 /// \endcode
2018 /// In this example directive '#pragma omp atomic' has 'write' clause.
2019 class OMPWriteClause : public OMPClause {
2020 public:
2021  /// Build 'write' clause.
2022  ///
2023  /// \param StartLoc Starting location of the clause.
2024  /// \param EndLoc Ending location of the clause.
2026  : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
2027 
2028  /// Build an empty clause.
2030  : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
2031 
2034  }
2035 
2038  }
2039 
2042  }
2045  }
2046 
2047  static bool classof(const OMPClause *T) {
2048  return T->getClauseKind() == llvm::omp::OMPC_write;
2049  }
2050 };
2051 
2052 /// This represents 'update' clause in the '#pragma omp atomic'
2053 /// directive.
2054 ///
2055 /// \code
2056 /// #pragma omp atomic update
2057 /// \endcode
2058 /// In this example directive '#pragma omp atomic' has 'update' clause.
2059 /// Also, this class represents 'update' clause in '#pragma omp depobj'
2060 /// directive.
2061 ///
2062 /// \code
2063 /// #pragma omp depobj(a) update(in)
2064 /// \endcode
2065 /// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
2066 /// dependence kind.
2067 class OMPUpdateClause final
2068  : public OMPClause,
2069  private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
2070  OpenMPDependClauseKind> {
2071  friend class OMPClauseReader;
2072  friend TrailingObjects;
2073 
2074  /// true if extended version of the clause for 'depobj' directive.
2075  bool IsExtended = false;
2076 
2077  /// Define the sizes of each trailing object array except the last one. This
2078  /// is required for TrailingObjects to work properly.
2079  size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
2080  // 2 locations: for '(' and argument location.
2081  return IsExtended ? 2 : 0;
2082  }
2083 
2084  /// Sets the location of '(' in clause for 'depobj' directive.
2085  void setLParenLoc(SourceLocation Loc) {
2086  assert(IsExtended && "Expected extended clause.");
2087  *getTrailingObjects<SourceLocation>() = Loc;
2088  }
2089 
2090  /// Sets the location of '(' in clause for 'depobj' directive.
2091  void setArgumentLoc(SourceLocation Loc) {
2092  assert(IsExtended && "Expected extended clause.");
2093  *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
2094  }
2095 
2096  /// Sets the dependence kind for the clause for 'depobj' directive.
2097  void setDependencyKind(OpenMPDependClauseKind DK) {
2098  assert(IsExtended && "Expected extended clause.");
2099  *getTrailingObjects<OpenMPDependClauseKind>() = DK;
2100  }
2101 
2102  /// Build 'update' clause.
2103  ///
2104  /// \param StartLoc Starting location of the clause.
2105  /// \param EndLoc Ending location of the clause.
2106  OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
2107  bool IsExtended)
2108  : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
2109  IsExtended(IsExtended) {}
2110 
2111  /// Build an empty clause.
2112  OMPUpdateClause(bool IsExtended)
2113  : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
2114  IsExtended(IsExtended) {}
2115 
2116 public:
2117  /// Creates clause for 'atomic' directive.
2118  ///
2119  /// \param C AST context.
2120  /// \param StartLoc Starting location of the clause.
2121  /// \param EndLoc Ending location of the clause.
2122  static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2123  SourceLocation EndLoc);
2124 
2125  /// Creates clause for 'depobj' directive.
2126  ///
2127  /// \param C AST context.
2128  /// \param StartLoc Starting location of the clause.
2129  /// \param LParenLoc Location of '('.
2130  /// \param ArgumentLoc Location of the argument.
2131  /// \param DK Dependence kind.
2132  /// \param EndLoc Ending location of the clause.
2133  static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2134  SourceLocation LParenLoc,
2135  SourceLocation ArgumentLoc,
2137  SourceLocation EndLoc);
2138 
2139  /// Creates an empty clause with the place for \a N variables.
2140  ///
2141  /// \param C AST context.
2142  /// \param IsExtended true if extended clause for 'depobj' directive must be
2143  /// created.
2144  static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
2145 
2146  /// Checks if the clause is the extended clauses for 'depobj' directive.
2147  bool isExtended() const { return IsExtended; }
2148 
2151  }
2152 
2155  }
2156 
2159  }
2162  }
2163 
2164  /// Gets the location of '(' in clause for 'depobj' directive.
2166  assert(IsExtended && "Expected extended clause.");
2167  return *getTrailingObjects<SourceLocation>();
2168  }
2169 
2170  /// Gets the location of argument in clause for 'depobj' directive.
2172  assert(IsExtended && "Expected extended clause.");
2173  return *std::next(getTrailingObjects<SourceLocation>(), 1);
2174  }
2175 
2176  /// Gets the dependence kind in clause for 'depobj' directive.
2178  assert(IsExtended && "Expected extended clause.");
2179  return *getTrailingObjects<OpenMPDependClauseKind>();
2180  }
2181 
2182  static bool classof(const OMPClause *T) {
2183  return T->getClauseKind() == llvm::omp::OMPC_update;
2184  }
2185 };
2186 
2187 /// This represents 'capture' clause in the '#pragma omp atomic'
2188 /// directive.
2189 ///
2190 /// \code
2191 /// #pragma omp atomic capture
2192 /// \endcode
2193 /// In this example directive '#pragma omp atomic' has 'capture' clause.
2194 class OMPCaptureClause : public OMPClause {
2195 public:
2196  /// Build 'capture' clause.
2197  ///
2198  /// \param StartLoc Starting location of the clause.
2199  /// \param EndLoc Ending location of the clause.
2201  : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
2202 
2203  /// Build an empty clause.
2205  : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
2206  }
2207 
2210  }
2211 
2214  }
2215 
2218  }
2221  }
2222 
2223  static bool classof(const OMPClause *T) {
2224  return T->getClauseKind() == llvm::omp::OMPC_capture;
2225  }
2226 };
2227 
2228 /// This represents 'compare' clause in the '#pragma omp atomic'
2229 /// directive.
2230 ///
2231 /// \code
2232 /// #pragma omp atomic compare
2233 /// \endcode
2234 /// In this example directive '#pragma omp atomic' has 'compare' clause.
2235 class OMPCompareClause final : public OMPClause {
2236 public:
2237  /// Build 'compare' clause.
2238  ///
2239  /// \param StartLoc Starting location of the clause.
2240  /// \param EndLoc Ending location of the clause.
2242  : OMPClause(llvm::omp::OMPC_compare, StartLoc, EndLoc) {}
2243 
2244  /// Build an empty clause.
2246  : OMPClause(llvm::omp::OMPC_compare, SourceLocation(), SourceLocation()) {
2247  }
2248 
2251  }
2252 
2255  }
2256 
2259  }
2262  }
2263 
2264  static bool classof(const OMPClause *T) {
2265  return T->getClauseKind() == llvm::omp::OMPC_compare;
2266  }
2267 };
2268 
2269 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
2270 /// directive.
2271 ///
2272 /// \code
2273 /// #pragma omp atomic seq_cst
2274 /// \endcode
2275 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
2276 class OMPSeqCstClause : public OMPClause {
2277 public:
2278  /// Build 'seq_cst' clause.
2279  ///
2280  /// \param StartLoc Starting location of the clause.
2281  /// \param EndLoc Ending location of the clause.
2283  : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
2284 
2285  /// Build an empty clause.
2287  : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
2288  }
2289 
2292  }
2293 
2296  }
2297 
2300  }
2303  }
2304 
2305  static bool classof(const OMPClause *T) {
2306  return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
2307  }
2308 };
2309 
2310 /// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
2311 /// directives.
2312 ///
2313 /// \code
2314 /// #pragma omp flush acq_rel
2315 /// \endcode
2316 /// In this example directive '#pragma omp flush' has 'acq_rel' clause.
2317 class OMPAcqRelClause final : public OMPClause {
2318 public:
2319  /// Build 'ack_rel' clause.
2320  ///
2321  /// \param StartLoc Starting location of the clause.
2322  /// \param EndLoc Ending location of the clause.
2324  : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
2325 
2326  /// Build an empty clause.
2328  : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
2329  }
2330 
2333  }
2334 
2337  }
2338 
2341  }
2344  }
2345 
2346  static bool classof(const OMPClause *T) {
2347  return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
2348  }
2349 };
2350 
2351 /// This represents 'acquire' clause in the '#pragma omp atomic|flush'
2352 /// directives.
2353 ///
2354 /// \code
2355 /// #pragma omp flush acquire
2356 /// \endcode
2357 /// In this example directive '#pragma omp flush' has 'acquire' clause.
2358 class OMPAcquireClause final : public OMPClause {
2359 public:
2360  /// Build 'acquire' clause.
2361  ///
2362  /// \param StartLoc Starting location of the clause.
2363  /// \param EndLoc Ending location of the clause.
2365  : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
2366 
2367  /// Build an empty clause.
2369  : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
2370  }
2371 
2374  }
2375 
2378  }
2379 
2382  }
2385  }
2386 
2387  static bool classof(const OMPClause *T) {
2388  return T->getClauseKind() == llvm::omp::OMPC_acquire;
2389  }
2390 };
2391 
2392 /// This represents 'release' clause in the '#pragma omp atomic|flush'
2393 /// directives.
2394 ///
2395 /// \code
2396 /// #pragma omp flush release
2397 /// \endcode
2398 /// In this example directive '#pragma omp flush' has 'release' clause.
2399 class OMPReleaseClause final : public OMPClause {
2400 public:
2401  /// Build 'release' clause.
2402  ///
2403  /// \param StartLoc Starting location of the clause.
2404  /// \param EndLoc Ending location of the clause.
2406  : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
2407 
2408  /// Build an empty clause.
2410  : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
2411  }
2412 
2415  }
2416 
2419  }
2420 
2423  }
2426  }
2427 
2428  static bool classof(const OMPClause *T) {
2429  return T->getClauseKind() == llvm::omp::OMPC_release;
2430  }
2431 };
2432 
2433 /// This represents 'relaxed' clause in the '#pragma omp atomic'
2434 /// directives.
2435 ///
2436 /// \code
2437 /// #pragma omp atomic relaxed
2438 /// \endcode
2439 /// In this example directive '#pragma omp atomic' has 'relaxed' clause.
2440 class OMPRelaxedClause final : public OMPClause {
2441 public:
2442  /// Build 'relaxed' clause.
2443  ///
2444  /// \param StartLoc Starting location of the clause.
2445  /// \param EndLoc Ending location of the clause.
2447  : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
2448 
2449  /// Build an empty clause.
2451  : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
2452  }
2453 
2456  }
2457 
2460  }
2461 
2464  }
2467  }
2468 
2469  static bool classof(const OMPClause *T) {
2470  return T->getClauseKind() == llvm::omp::OMPC_relaxed;
2471  }
2472 };
2473 
2474 /// This represents clause 'private' in the '#pragma omp ...' directives.
2475 ///
2476 /// \code
2477 /// #pragma omp parallel private(a,b)
2478 /// \endcode
2479 /// In this example directive '#pragma omp parallel' has clause 'private'
2480 /// with the variables 'a' and 'b'.
2481 class OMPPrivateClause final
2482  : public OMPVarListClause<OMPPrivateClause>,
2483  private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2484  friend class OMPClauseReader;
2485  friend OMPVarListClause;
2486  friend TrailingObjects;
2487 
2488  /// Build clause with number of variables \a N.
2489  ///
2490  /// \param StartLoc Starting location of the clause.
2491  /// \param LParenLoc Location of '('.
2492  /// \param EndLoc Ending location of the clause.
2493  /// \param N Number of the variables in the clause.
2494  OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2495  SourceLocation EndLoc, unsigned N)
2496  : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
2497  LParenLoc, EndLoc, N) {}
2498 
2499  /// Build an empty clause.
2500  ///
2501  /// \param N Number of variables.
2502  explicit OMPPrivateClause(unsigned N)
2503  : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
2505  SourceLocation(), N) {}
2506 
2507  /// Sets the list of references to private copies with initializers for
2508  /// new private variables.
2509  /// \param VL List of references.
2510  void setPrivateCopies(ArrayRef<Expr *> VL);
2511 
2512  /// Gets the list of references to private copies with initializers for
2513  /// new private variables.
2514  MutableArrayRef<Expr *> getPrivateCopies() {
2515  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2516  }
2517  ArrayRef<const Expr *> getPrivateCopies() const {
2518  return llvm::makeArrayRef(varlist_end(), varlist_size());
2519  }
2520 
2521 public:
2522  /// Creates clause with a list of variables \a VL.
2523  ///
2524  /// \param C AST context.
2525  /// \param StartLoc Starting location of the clause.
2526  /// \param LParenLoc Location of '('.
2527  /// \param EndLoc Ending location of the clause.
2528  /// \param VL List of references to the variables.
2529  /// \param PrivateVL List of references to private copies with initializers.
2530  static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2531  SourceLocation LParenLoc,
2532  SourceLocation EndLoc, ArrayRef<Expr *> VL,
2533  ArrayRef<Expr *> PrivateVL);
2534 
2535  /// Creates an empty clause with the place for \a N variables.
2536  ///
2537  /// \param C AST context.
2538  /// \param N The number of variables.
2539  static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2540 
2543  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2545  llvm::iterator_range<private_copies_const_iterator>;
2546 
2548  return private_copies_range(getPrivateCopies().begin(),
2549  getPrivateCopies().end());
2550  }
2551 
2553  return private_copies_const_range(getPrivateCopies().begin(),
2554  getPrivateCopies().end());
2555  }
2556 
2558  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2559  reinterpret_cast<Stmt **>(varlist_end()));
2560  }
2561 
2563  auto Children = const_cast<OMPPrivateClause *>(this)->children();
2564  return const_child_range(Children.begin(), Children.end());
2565  }
2566 
2569  }
2572  }
2573 
2574  static bool classof(const OMPClause *T) {
2575  return T->getClauseKind() == llvm::omp::OMPC_private;
2576  }
2577 };
2578 
2579 /// This represents clause 'firstprivate' in the '#pragma omp ...'
2580 /// directives.
2581 ///
2582 /// \code
2583 /// #pragma omp parallel firstprivate(a,b)
2584 /// \endcode
2585 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2586 /// with the variables 'a' and 'b'.
2588  : public OMPVarListClause<OMPFirstprivateClause>,
2589  public OMPClauseWithPreInit,
2590  private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2591  friend class OMPClauseReader;
2592  friend OMPVarListClause;
2593  friend TrailingObjects;
2594 
2595  /// Build clause with number of variables \a N.
2596  ///
2597  /// \param StartLoc Starting location of the clause.
2598  /// \param LParenLoc Location of '('.
2599  /// \param EndLoc Ending location of the clause.
2600  /// \param N Number of the variables in the clause.
2602  SourceLocation EndLoc, unsigned N)
2603  : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
2604  StartLoc, LParenLoc, EndLoc, N),
2605  OMPClauseWithPreInit(this) {}
2606 
2607  /// Build an empty clause.
2608  ///
2609  /// \param N Number of variables.
2610  explicit OMPFirstprivateClause(unsigned N)
2612  llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
2613  SourceLocation(), N),
2614  OMPClauseWithPreInit(this) {}
2615 
2616  /// Sets the list of references to private copies with initializers for
2617  /// new private variables.
2618  /// \param VL List of references.
2619  void setPrivateCopies(ArrayRef<Expr *> VL);
2620 
2621  /// Gets the list of references to private copies with initializers for
2622  /// new private variables.
2623  MutableArrayRef<Expr *> getPrivateCopies() {
2624  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2625  }
2626  ArrayRef<const Expr *> getPrivateCopies() const {
2627  return llvm::makeArrayRef(varlist_end(), varlist_size());
2628  }
2629 
2630  /// Sets the list of references to initializer variables for new
2631  /// private variables.
2632  /// \param VL List of references.
2633  void setInits(ArrayRef<Expr *> VL);
2634 
2635  /// Gets the list of references to initializer variables for new
2636  /// private variables.
2637  MutableArrayRef<Expr *> getInits() {
2638  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2639  }
2640  ArrayRef<const Expr *> getInits() const {
2641  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2642  }
2643 
2644 public:
2645  /// Creates clause with a list of variables \a VL.
2646  ///
2647  /// \param C AST context.
2648  /// \param StartLoc Starting location of the clause.
2649  /// \param LParenLoc Location of '('.
2650  /// \param EndLoc Ending location of the clause.
2651  /// \param VL List of references to the original variables.
2652  /// \param PrivateVL List of references to private copies with initializers.
2653  /// \param InitVL List of references to auto generated variables used for
2654  /// initialization of a single array element. Used if firstprivate variable is
2655  /// of array type.
2656  /// \param PreInit Statement that must be executed before entering the OpenMP
2657  /// region with this clause.
2658  static OMPFirstprivateClause *
2659  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2660  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2661  ArrayRef<Expr *> InitVL, Stmt *PreInit);
2662 
2663  /// Creates an empty clause with the place for \a N variables.
2664  ///
2665  /// \param C AST context.
2666  /// \param N The number of variables.
2667  static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2668 
2671  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2673  llvm::iterator_range<private_copies_const_iterator>;
2674 
2676  return private_copies_range(getPrivateCopies().begin(),
2677  getPrivateCopies().end());
2678  }
2680  return private_copies_const_range(getPrivateCopies().begin(),
2681  getPrivateCopies().end());
2682  }
2683 
2686  using inits_range = llvm::iterator_range<inits_iterator>;
2687  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2688 
2690  return inits_range(getInits().begin(), getInits().end());
2691  }
2693  return inits_const_range(getInits().begin(), getInits().end());
2694  }
2695 
2697  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2698  reinterpret_cast<Stmt **>(varlist_end()));
2699  }
2700 
2702  auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2703  return const_child_range(Children.begin(), Children.end());
2704  }
2705 
2707  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2708  reinterpret_cast<Stmt **>(varlist_end()));
2709  }
2711  auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2712  return const_child_range(Children.begin(), Children.end());
2713  }
2714 
2715  static bool classof(const OMPClause *T) {
2716  return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
2717  }
2718 };
2719 
2720 /// This represents clause 'lastprivate' in the '#pragma omp ...'
2721 /// directives.
2722 ///
2723 /// \code
2724 /// #pragma omp simd lastprivate(a,b)
2725 /// \endcode
2726 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
2727 /// with the variables 'a' and 'b'.
2729  : public OMPVarListClause<OMPLastprivateClause>,
2730  public OMPClauseWithPostUpdate,
2731  private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2732  // There are 4 additional tail-allocated arrays at the end of the class:
2733  // 1. Contains list of pseudo variables with the default initialization for
2734  // each non-firstprivate variables. Used in codegen for initialization of
2735  // lastprivate copies.
2736  // 2. List of helper expressions for proper generation of assignment operation
2737  // required for lastprivate clause. This list represents private variables
2738  // (for arrays, single array element).
2739  // 3. List of helper expressions for proper generation of assignment operation
2740  // required for lastprivate clause. This list represents original variables
2741  // (for arrays, single array element).
2742  // 4. List of helper expressions that represents assignment operation:
2743  // \code
2744  // DstExprs = SrcExprs;
2745  // \endcode
2746  // Required for proper codegen of final assignment performed by the
2747  // lastprivate clause.
2748  friend class OMPClauseReader;
2749  friend OMPVarListClause;
2750  friend TrailingObjects;
2751 
2752  /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2754  /// Optional location of the lasptrivate kind, if specified by user.
2755  SourceLocation LPKindLoc;
2756  /// Optional colon location, if specified by user.
2757  SourceLocation ColonLoc;
2758 
2759  /// Build clause with number of variables \a N.
2760  ///
2761  /// \param StartLoc Starting location of the clause.
2762  /// \param LParenLoc Location of '('.
2763  /// \param EndLoc Ending location of the clause.
2764  /// \param N Number of the variables in the clause.
2767  SourceLocation LPKindLoc, SourceLocation ColonLoc,
2768  unsigned N)
2769  : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
2770  StartLoc, LParenLoc, EndLoc, N),
2771  OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2772  ColonLoc(ColonLoc) {}
2773 
2774  /// Build an empty clause.
2775  ///
2776  /// \param N Number of variables.
2777  explicit OMPLastprivateClause(unsigned N)
2779  llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
2780  SourceLocation(), N),
2781  OMPClauseWithPostUpdate(this) {}
2782 
2783  /// Get the list of helper expressions for initialization of private
2784  /// copies for lastprivate variables.
2785  MutableArrayRef<Expr *> getPrivateCopies() {
2786  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2787  }
2788  ArrayRef<const Expr *> getPrivateCopies() const {
2789  return llvm::makeArrayRef(varlist_end(), varlist_size());
2790  }
2791 
2792  /// Set list of helper expressions, required for proper codegen of the
2793  /// clause. These expressions represent private variables (for arrays, single
2794  /// array element) in the final assignment statement performed by the
2795  /// lastprivate clause.
2796  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2797 
2798  /// Get the list of helper source expressions.
2799  MutableArrayRef<Expr *> getSourceExprs() {
2800  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2801  }
2802  ArrayRef<const Expr *> getSourceExprs() const {
2803  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2804  }
2805 
2806  /// Set list of helper expressions, required for proper codegen of the
2807  /// clause. These expressions represent original variables (for arrays, single
2808  /// array element) in the final assignment statement performed by the
2809  /// lastprivate clause.
2810  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2811 
2812  /// Get the list of helper destination expressions.
2813  MutableArrayRef<Expr *> getDestinationExprs() {
2814  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2815  }
2816  ArrayRef<const Expr *> getDestinationExprs() const {
2817  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2818  }
2819 
2820  /// Set list of helper assignment expressions, required for proper
2821  /// codegen of the clause. These expressions are assignment expressions that
2822  /// assign private copy of the variable to original variable.
2823  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2824 
2825  /// Get the list of helper assignment expressions.
2826  MutableArrayRef<Expr *> getAssignmentOps() {
2827  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2828  }
2829  ArrayRef<const Expr *> getAssignmentOps() const {
2830  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2831  }
2832 
2833  /// Sets lastprivate kind.
2834  void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
2835  /// Sets location of the lastprivate kind.
2836  void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
2837  /// Sets colon symbol location.
2838  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2839 
2840 public:
2841  /// Creates clause with a list of variables \a VL.
2842  ///
2843  /// \param C AST context.
2844  /// \param StartLoc Starting location of the clause.
2845  /// \param LParenLoc Location of '('.
2846  /// \param EndLoc Ending location of the clause.
2847  /// \param VL List of references to the variables.
2848  /// \param SrcExprs List of helper expressions for proper generation of
2849  /// assignment operation required for lastprivate clause. This list represents
2850  /// private variables (for arrays, single array element).
2851  /// \param DstExprs List of helper expressions for proper generation of
2852  /// assignment operation required for lastprivate clause. This list represents
2853  /// original variables (for arrays, single array element).
2854  /// \param AssignmentOps List of helper expressions that represents assignment
2855  /// operation:
2856  /// \code
2857  /// DstExprs = SrcExprs;
2858  /// \endcode
2859  /// Required for proper codegen of final assignment performed by the
2860  /// lastprivate clause.
2861  /// \param LPKind Lastprivate kind, e.g. 'conditional'.
2862  /// \param LPKindLoc Location of the lastprivate kind.
2863  /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
2864  /// \param PreInit Statement that must be executed before entering the OpenMP
2865  /// region with this clause.
2866  /// \param PostUpdate Expression that must be executed after exit from the
2867  /// OpenMP region with this clause.
2868  static OMPLastprivateClause *
2869  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2870  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2871  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2872  OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
2873  SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
2874 
2875  /// Creates an empty clause with the place for \a N variables.
2876  ///
2877  /// \param C AST context.
2878  /// \param N The number of variables.
2879  static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2880 
2881  /// Lastprivate kind.
2882  OpenMPLastprivateModifier getKind() const { return LPKind; }
2883  /// Returns the location of the lastprivate kind.
2884  SourceLocation getKindLoc() const { return LPKindLoc; }
2885  /// Returns the location of the ':' symbol, if any.
2886  SourceLocation getColonLoc() const { return ColonLoc; }
2887 
2890  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2891  using helper_expr_const_range =
2892  llvm::iterator_range<helper_expr_const_iterator>;
2893 
2894  /// Set list of helper expressions, required for generation of private
2895  /// copies of original lastprivate variables.
2896  void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2897 
2899  return helper_expr_const_range(getPrivateCopies().begin(),
2900  getPrivateCopies().end());
2901  }
2902 
2904  return helper_expr_range(getPrivateCopies().begin(),
2905  getPrivateCopies().end());
2906  }
2907 
2909  return helper_expr_const_range(getSourceExprs().begin(),
2910  getSourceExprs().end());
2911  }
2912 
2914  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2915  }
2916 
2918  return helper_expr_const_range(getDestinationExprs().begin(),
2919  getDestinationExprs().end());
2920  }
2921 
2923  return helper_expr_range(getDestinationExprs().begin(),
2924  getDestinationExprs().end());
2925  }
2926 
2928  return helper_expr_const_range(getAssignmentOps().begin(),
2929  getAssignmentOps().end());
2930  }
2931 
2933  return helper_expr_range(getAssignmentOps().begin(),
2934  getAssignmentOps().end());
2935  }
2936 
2938  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2939  reinterpret_cast<Stmt **>(varlist_end()));
2940  }
2941 
2943  auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2944  return const_child_range(Children.begin(), Children.end());
2945  }
2946 
2949  }
2952  }
2953 
2954  static bool classof(const OMPClause *T) {
2955  return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
2956  }
2957 };
2958 
2959 /// This represents clause 'shared' in the '#pragma omp ...' directives.
2960 ///
2961 /// \code
2962 /// #pragma omp parallel shared(a,b)
2963 /// \endcode
2964 /// In this example directive '#pragma omp parallel' has clause 'shared'
2965 /// with the variables 'a' and 'b'.
2966 class OMPSharedClause final
2967  : public OMPVarListClause<OMPSharedClause>,
2968  private llvm::TrailingObjects<OMPSharedClause, Expr *> {
2969  friend OMPVarListClause;
2970  friend TrailingObjects;
2971 
2972  /// Build clause with number of variables \a N.
2973  ///
2974  /// \param StartLoc Starting location of the clause.
2975  /// \param LParenLoc Location of '('.
2976  /// \param EndLoc Ending location of the clause.
2977  /// \param N Number of the variables in the clause.
2978  OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2979  SourceLocation EndLoc, unsigned N)
2980  : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
2981  LParenLoc, EndLoc, N) {}
2982 
2983  /// Build an empty clause.
2984  ///
2985  /// \param N Number of variables.
2986  explicit OMPSharedClause(unsigned N)
2987  : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
2989  SourceLocation(), N) {}
2990 
2991 public:
2992  /// Creates clause with a list of variables \a VL.
2993  ///
2994  /// \param C AST context.
2995  /// \param StartLoc Starting location of the clause.
2996  /// \param LParenLoc Location of '('.
2997  /// \param EndLoc Ending location of the clause.
2998  /// \param VL List of references to the variables.
2999  static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3000  SourceLocation LParenLoc,
3001  SourceLocation EndLoc, ArrayRef<Expr *> VL);
3002 
3003  /// Creates an empty clause with \a N variables.
3004  ///
3005  /// \param C AST context.
3006  /// \param N The number of variables.
3007  static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
3008 
3010  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3011  reinterpret_cast<Stmt **>(varlist_end()));
3012  }
3013 
3015  auto Children = const_cast<OMPSharedClause *>(this)->children();
3016  return const_child_range(Children.begin(), Children.end());
3017  }
3018 
3021  }
3024  }
3025 
3026  static bool classof(const OMPClause *T) {
3027  return T->getClauseKind() == llvm::omp::OMPC_shared;
3028  }
3029 };
3030 
3031 /// This represents clause 'reduction' in the '#pragma omp ...'
3032 /// directives.
3033 ///
3034 /// \code
3035 /// #pragma omp parallel reduction(+:a,b)
3036 /// \endcode
3037 /// In this example directive '#pragma omp parallel' has clause 'reduction'
3038 /// with operator '+' and the variables 'a' and 'b'.
3040  : public OMPVarListClause<OMPReductionClause>,
3041  public OMPClauseWithPostUpdate,
3042  private llvm::TrailingObjects<OMPReductionClause, Expr *> {
3043  friend class OMPClauseReader;
3044  friend OMPVarListClause;
3045  friend TrailingObjects;
3046 
3047  /// Reduction modifier.
3049 
3050  /// Reduction modifier location.
3051  SourceLocation ModifierLoc;
3052 
3053  /// Location of ':'.
3054  SourceLocation ColonLoc;
3055 
3056  /// Nested name specifier for C++.
3057  NestedNameSpecifierLoc QualifierLoc;
3058 
3059  /// Name of custom operator.
3060  DeclarationNameInfo NameInfo;
3061 
3062  /// Build clause with number of variables \a N.
3063  ///
3064  /// \param StartLoc Starting location of the clause.
3065  /// \param LParenLoc Location of '('.
3066  /// \param ModifierLoc Modifier location.
3067  /// \param ColonLoc Location of ':'.
3068  /// \param EndLoc Ending location of the clause.
3069  /// \param N Number of the variables in the clause.
3070  /// \param QualifierLoc The nested-name qualifier with location information
3071  /// \param NameInfo The full name info for reduction identifier.
3072  OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3073  SourceLocation ModifierLoc, SourceLocation ColonLoc,
3074  SourceLocation EndLoc,
3075  OpenMPReductionClauseModifier Modifier, unsigned N,
3076  NestedNameSpecifierLoc QualifierLoc,
3077  const DeclarationNameInfo &NameInfo)
3078  : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3079  StartLoc, LParenLoc, EndLoc, N),
3080  OMPClauseWithPostUpdate(this), Modifier(Modifier),
3081  ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
3082  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3083 
3084  /// Build an empty clause.
3085  ///
3086  /// \param N Number of variables.
3087  explicit OMPReductionClause(unsigned N)
3088  : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
3090  SourceLocation(), N),
3091  OMPClauseWithPostUpdate(this) {}
3092 
3093  /// Sets reduction modifier.
3094  void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
3095 
3096  /// Sets location of the modifier.
3097  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3098 
3099  /// Sets location of ':' symbol in clause.
3100  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3101 
3102  /// Sets the name info for specified reduction identifier.
3103  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3104 
3105  /// Sets the nested name specifier.
3106  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3107 
3108  /// Set list of helper expressions, required for proper codegen of the
3109  /// clause. These expressions represent private copy of the reduction
3110  /// variable.
3111  void setPrivates(ArrayRef<Expr *> Privates);
3112 
3113  /// Get the list of helper privates.
3114  MutableArrayRef<Expr *> getPrivates() {
3115  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3116  }
3117  ArrayRef<const Expr *> getPrivates() const {
3118  return llvm::makeArrayRef(varlist_end(), varlist_size());
3119  }
3120 
3121  /// Set list of helper expressions, required for proper codegen of the
3122  /// clause. These expressions represent LHS expression in the final
3123  /// reduction expression performed by the reduction clause.
3124  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3125 
3126  /// Get the list of helper LHS expressions.
3127  MutableArrayRef<Expr *> getLHSExprs() {
3128  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3129  }
3130  ArrayRef<const Expr *> getLHSExprs() const {
3131  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3132  }
3133 
3134  /// Set list of helper expressions, required for proper codegen of the
3135  /// clause. These expressions represent RHS expression in the final
3136  /// reduction expression performed by the reduction clause.
3137  /// Also, variables in these expressions are used for proper initialization of
3138  /// reduction copies.
3139  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3140 
3141  /// Get the list of helper destination expressions.
3142  MutableArrayRef<Expr *> getRHSExprs() {
3143  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3144  }
3145  ArrayRef<const Expr *> getRHSExprs() const {
3146  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3147  }
3148 
3149  /// Set list of helper reduction expressions, required for proper
3150  /// codegen of the clause. These expressions are binary expressions or
3151  /// operator/custom reduction call that calculates new value from source
3152  /// helper expressions to destination helper expressions.
3153  void setReductionOps(ArrayRef<Expr *> ReductionOps);
3154 
3155  /// Get the list of helper reduction expressions.
3156  MutableArrayRef<Expr *> getReductionOps() {
3157  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3158  }
3159  ArrayRef<const Expr *> getReductionOps() const {
3160  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3161  }
3162 
3163  /// Set list of helper copy operations for inscan reductions.
3164  /// The form is: Temps[i] = LHS[i];
3165  void setInscanCopyOps(ArrayRef<Expr *> Ops);
3166 
3167  /// Get the list of helper inscan copy operations.
3168  MutableArrayRef<Expr *> getInscanCopyOps() {
3169  return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3170  }
3171  ArrayRef<const Expr *> getInscanCopyOps() const {
3172  return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3173  }
3174 
3175  /// Set list of helper temp vars for inscan copy array operations.
3176  void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
3177 
3178  /// Get the list of helper inscan copy temps.
3179  MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
3180  return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
3181  }
3182  ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
3183  return llvm::makeArrayRef(getInscanCopyOps().end(), varlist_size());
3184  }
3185 
3186  /// Set list of helper temp elements vars for inscan copy array operations.
3187  void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
3188 
3189  /// Get the list of helper inscan copy temps.
3190  MutableArrayRef<Expr *> getInscanCopyArrayElems() {
3191  return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
3192  varlist_size());
3193  }
3194  ArrayRef<const Expr *> getInscanCopyArrayElems() const {
3195  return llvm::makeArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
3196  }
3197 
3198 public:
3199  /// Creates clause with a list of variables \a VL.
3200  ///
3201  /// \param StartLoc Starting location of the clause.
3202  /// \param LParenLoc Location of '('.
3203  /// \param ModifierLoc Modifier location.
3204  /// \param ColonLoc Location of ':'.
3205  /// \param EndLoc Ending location of the clause.
3206  /// \param VL The variables in the clause.
3207  /// \param QualifierLoc The nested-name qualifier with location information
3208  /// \param NameInfo The full name info for reduction identifier.
3209  /// \param Privates List of helper expressions for proper generation of
3210  /// private copies.
3211  /// \param LHSExprs List of helper expressions for proper generation of
3212  /// assignment operation required for copyprivate clause. This list represents
3213  /// LHSs of the reduction expressions.
3214  /// \param RHSExprs List of helper expressions for proper generation of
3215  /// assignment operation required for copyprivate clause. This list represents
3216  /// RHSs of the reduction expressions.
3217  /// Also, variables in these expressions are used for proper initialization of
3218  /// reduction copies.
3219  /// \param ReductionOps List of helper expressions that represents reduction
3220  /// expressions:
3221  /// \code
3222  /// LHSExprs binop RHSExprs;
3223  /// operator binop(LHSExpr, RHSExpr);
3224  /// <CutomReduction>(LHSExpr, RHSExpr);
3225  /// \endcode
3226  /// Required for proper codegen of final reduction operation performed by the
3227  /// reduction clause.
3228  /// \param CopyOps List of copy operations for inscan reductions:
3229  /// \code
3230  /// TempExprs = LHSExprs;
3231  /// \endcode
3232  /// \param CopyArrayTemps Temp arrays for prefix sums.
3233  /// \param CopyArrayElems Temp arrays for prefix sums.
3234  /// \param PreInit Statement that must be executed before entering the OpenMP
3235  /// region with this clause.
3236  /// \param PostUpdate Expression that must be executed after exit from the
3237  /// OpenMP region with this clause.
3238  static OMPReductionClause *
3239  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3240  SourceLocation ModifierLoc, SourceLocation ColonLoc,
3241  SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
3242  ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
3243  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3244  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3245  ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
3246  ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
3247  Stmt *PreInit, Expr *PostUpdate);
3248 
3249  /// Creates an empty clause with the place for \a N variables.
3250  ///
3251  /// \param C AST context.
3252  /// \param N The number of variables.
3253  /// \param Modifier Reduction modifier.
3254  static OMPReductionClause *
3255  CreateEmpty(const ASTContext &C, unsigned N,
3257 
3258  /// Returns modifier.
3259  OpenMPReductionClauseModifier getModifier() const { return Modifier; }
3260 
3261  /// Returns modifier location.
3262  SourceLocation getModifierLoc() const { return ModifierLoc; }
3263 
3264  /// Gets location of ':' symbol in clause.
3265  SourceLocation getColonLoc() const { return ColonLoc; }
3266 
3267  /// Gets the name info for specified reduction identifier.
3268  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3269 
3270  /// Gets the nested name specifier.
3271  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3272 
3275  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3276  using helper_expr_const_range =
3277  llvm::iterator_range<helper_expr_const_iterator>;
3278 
3280  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3281  }
3282 
3284  return helper_expr_range(getPrivates().begin(), getPrivates().end());
3285  }
3286 
3288  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3289  }
3290 
3292  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3293  }
3294 
3296  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3297  }
3298 
3300  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3301  }
3302 
3304  return helper_expr_const_range(getReductionOps().begin(),
3305  getReductionOps().end());
3306  }
3307 
3309  return helper_expr_range(getReductionOps().begin(),
3310  getReductionOps().end());
3311  }
3312 
3314  return helper_expr_const_range(getInscanCopyOps().begin(),
3315  getInscanCopyOps().end());
3316  }
3317 
3319  return helper_expr_range(getInscanCopyOps().begin(),
3320  getInscanCopyOps().end());
3321  }
3322 
3324  return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
3325  getInscanCopyArrayTemps().end());
3326  }
3327 
3329  return helper_expr_range(getInscanCopyArrayTemps().begin(),
3330  getInscanCopyArrayTemps().end());
3331  }
3332 
3334  return helper_expr_const_range(getInscanCopyArrayElems().begin(),
3335  getInscanCopyArrayElems().end());
3336  }
3337 
3339  return helper_expr_range(getInscanCopyArrayElems().begin(),
3340  getInscanCopyArrayElems().end());
3341  }
3342 
3344  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3345  reinterpret_cast<Stmt **>(varlist_end()));
3346  }
3347 
3349  auto Children = const_cast<OMPReductionClause *>(this)->children();
3350  return const_child_range(Children.begin(), Children.end());
3351  }
3352 
3354  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3355  reinterpret_cast<Stmt **>(varlist_end()));
3356  }
3358  auto Children = const_cast<OMPReductionClause *>(this)->used_children();
3359  return const_child_range(Children.begin(), Children.end());
3360  }
3361 
3362  static bool classof(const OMPClause *T) {
3363  return T->getClauseKind() == llvm::omp::OMPC_reduction;
3364  }
3365 };
3366 
3367 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
3368 /// directives.
3369 ///
3370 /// \code
3371 /// #pragma omp taskgroup task_reduction(+:a,b)
3372 /// \endcode
3373 /// In this example directive '#pragma omp taskgroup' has clause
3374 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
3376  : public OMPVarListClause<OMPTaskReductionClause>,
3377  public OMPClauseWithPostUpdate,
3378  private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
3379  friend class OMPClauseReader;
3380  friend OMPVarListClause;
3381  friend TrailingObjects;
3382 
3383  /// Location of ':'.
3384  SourceLocation ColonLoc;
3385 
3386  /// Nested name specifier for C++.
3387  NestedNameSpecifierLoc QualifierLoc;
3388 
3389  /// Name of custom operator.
3390  DeclarationNameInfo NameInfo;
3391 
3392  /// Build clause with number of variables \a N.
3393  ///
3394  /// \param StartLoc Starting location of the clause.
3395  /// \param LParenLoc Location of '('.
3396  /// \param EndLoc Ending location of the clause.
3397  /// \param ColonLoc Location of ':'.
3398  /// \param N Number of the variables in the clause.
3399  /// \param QualifierLoc The nested-name qualifier with location information
3400  /// \param NameInfo The full name info for reduction identifier.
3402  SourceLocation ColonLoc, SourceLocation EndLoc,
3403  unsigned N, NestedNameSpecifierLoc QualifierLoc,
3404  const DeclarationNameInfo &NameInfo)
3406  llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
3407  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3408  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3409 
3410  /// Build an empty clause.
3411  ///
3412  /// \param N Number of variables.
3413  explicit OMPTaskReductionClause(unsigned N)
3415  llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
3416  SourceLocation(), N),
3417  OMPClauseWithPostUpdate(this) {}
3418 
3419  /// Sets location of ':' symbol in clause.
3420  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3421 
3422  /// Sets the name info for specified reduction identifier.
3423  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3424 
3425  /// Sets the nested name specifier.
3426  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3427 
3428  /// Set list of helper expressions, required for proper codegen of the clause.
3429  /// These expressions represent private copy of the reduction variable.
3430  void setPrivates(ArrayRef<Expr *> Privates);
3431 
3432  /// Get the list of helper privates.
3433  MutableArrayRef<Expr *> getPrivates() {
3434  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3435  }
3436  ArrayRef<const Expr *> getPrivates() const {
3437  return llvm::makeArrayRef(varlist_end(), varlist_size());
3438  }
3439 
3440  /// Set list of helper expressions, required for proper codegen of the clause.
3441  /// These expressions represent LHS expression in the final reduction
3442  /// expression performed by the reduction clause.
3443  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3444 
3445  /// Get the list of helper LHS expressions.
3446  MutableArrayRef<Expr *> getLHSExprs() {
3447  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3448  }
3449  ArrayRef<const Expr *> getLHSExprs() const {
3450  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3451  }
3452 
3453  /// Set list of helper expressions, required for proper codegen of the clause.
3454  /// These expressions represent RHS expression in the final reduction
3455  /// expression performed by the reduction clause. Also, variables in these
3456  /// expressions are used for proper initialization of reduction copies.
3457  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3458 
3459  /// Get the list of helper destination expressions.
3460  MutableArrayRef<Expr *> getRHSExprs() {
3461  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3462  }
3463  ArrayRef<const Expr *> getRHSExprs() const {
3464  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3465  }
3466 
3467  /// Set list of helper reduction expressions, required for proper
3468  /// codegen of the clause. These expressions are binary expressions or
3469  /// operator/custom reduction call that calculates new value from source
3470  /// helper expressions to destination helper expressions.
3471  void setReductionOps(ArrayRef<Expr *> ReductionOps);
3472 
3473  /// Get the list of helper reduction expressions.
3474  MutableArrayRef<Expr *> getReductionOps() {
3475  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3476  }
3477  ArrayRef<const Expr *> getReductionOps() const {
3478  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3479  }
3480 
3481 public:
3482  /// Creates clause with a list of variables \a VL.
3483  ///
3484  /// \param StartLoc Starting location of the clause.
3485  /// \param LParenLoc Location of '('.
3486  /// \param ColonLoc Location of ':'.
3487  /// \param EndLoc Ending location of the clause.
3488  /// \param VL The variables in the clause.
3489  /// \param QualifierLoc The nested-name qualifier with location information
3490  /// \param NameInfo The full name info for reduction identifier.
3491  /// \param Privates List of helper expressions for proper generation of
3492  /// private copies.
3493  /// \param LHSExprs List of helper expressions for proper generation of
3494  /// assignment operation required for copyprivate clause. This list represents
3495  /// LHSs of the reduction expressions.
3496  /// \param RHSExprs List of helper expressions for proper generation of
3497  /// assignment operation required for copyprivate clause. This list represents
3498  /// RHSs of the reduction expressions.
3499  /// Also, variables in these expressions are used for proper initialization of
3500  /// reduction copies.
3501  /// \param ReductionOps List of helper expressions that represents reduction
3502  /// expressions:
3503  /// \code
3504  /// LHSExprs binop RHSExprs;
3505  /// operator binop(LHSExpr, RHSExpr);
3506  /// <CutomReduction>(LHSExpr, RHSExpr);
3507  /// \endcode
3508  /// Required for proper codegen of final reduction operation performed by the
3509  /// reduction clause.
3510  /// \param PreInit Statement that must be executed before entering the OpenMP
3511  /// region with this clause.
3512  /// \param PostUpdate Expression that must be executed after exit from the
3513  /// OpenMP region with this clause.
3514  static OMPTaskReductionClause *
3515  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3516  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3517  NestedNameSpecifierLoc QualifierLoc,
3518  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3519  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3520  ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3521 
3522  /// Creates an empty clause with the place for \a N variables.
3523  ///
3524  /// \param C AST context.
3525  /// \param N The number of variables.
3526  static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3527 
3528  /// Gets location of ':' symbol in clause.
3529  SourceLocation getColonLoc() const { return ColonLoc; }
3530 
3531  /// Gets the name info for specified reduction identifier.
3532  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3533 
3534  /// Gets the nested name specifier.
3535  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3536 
3539  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3540  using helper_expr_const_range =
3541  llvm::iterator_range<helper_expr_const_iterator>;
3542 
3544  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3545  }
3546 
3548  return helper_expr_range(getPrivates().begin(), getPrivates().end());
3549  }
3550 
3552  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3553  }
3554 
3556  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3557  }
3558 
3560  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3561  }
3562 
3564  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3565  }
3566 
3568  return helper_expr_const_range(getReductionOps().begin(),
3569  getReductionOps().end());
3570  }
3571 
3573  return helper_expr_range(getReductionOps().begin(),
3574  getReductionOps().end());
3575  }
3576 
3578  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3579  reinterpret_cast<Stmt **>(varlist_end()));
3580  }
3581 
3583  auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3584  return const_child_range(Children.begin(), Children.end());
3585  }
3586 
3589  }
3592  }
3593 
3594  static bool classof(const OMPClause *T) {
3595  return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
3596  }
3597 };
3598 
3599 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
3600 ///
3601 /// \code
3602 /// #pragma omp task in_reduction(+:a,b)
3603 /// \endcode
3604 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
3605 /// operator '+' and the variables 'a' and 'b'.
3607  : public OMPVarListClause<OMPInReductionClause>,
3608  public OMPClauseWithPostUpdate,
3609  private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
3610  friend class OMPClauseReader;
3611  friend OMPVarListClause;
3612  friend TrailingObjects;
3613 
3614  /// Location of ':'.
3615  SourceLocation ColonLoc;
3616 
3617  /// Nested name specifier for C++.
3618  NestedNameSpecifierLoc QualifierLoc;
3619 
3620  /// Name of custom operator.
3621  DeclarationNameInfo NameInfo;
3622 
3623  /// Build clause with number of variables \a N.
3624  ///
3625  /// \param StartLoc Starting location of the clause.
3626  /// \param LParenLoc Location of '('.
3627  /// \param EndLoc Ending location of the clause.
3628  /// \param ColonLoc Location of ':'.
3629  /// \param N Number of the variables in the clause.
3630  /// \param QualifierLoc The nested-name qualifier with location information
3631  /// \param NameInfo The full name info for reduction identifier.
3633  SourceLocation ColonLoc, SourceLocation EndLoc,
3634  unsigned N, NestedNameSpecifierLoc QualifierLoc,
3635  const DeclarationNameInfo &NameInfo)
3636  : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
3637  StartLoc, LParenLoc, EndLoc, N),
3638  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3639  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3640 
3641  /// Build an empty clause.
3642  ///
3643  /// \param N Number of variables.
3644  explicit OMPInReductionClause(unsigned N)
3646  llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
3647  SourceLocation(), N),
3648  OMPClauseWithPostUpdate(this) {}
3649 
3650  /// Sets location of ':' symbol in clause.
3651  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3652 
3653  /// Sets the name info for specified reduction identifier.
3654  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3655 
3656  /// Sets the nested name specifier.
3657  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3658 
3659  /// Set list of helper expressions, required for proper codegen of the clause.
3660  /// These expressions represent private copy of the reduction variable.
3661  void setPrivates(ArrayRef<Expr *> Privates);
3662 
3663  /// Get the list of helper privates.
3664  MutableArrayRef<Expr *> getPrivates() {
3665  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3666  }
3667  ArrayRef<const Expr *> getPrivates() const {
3668  return llvm::makeArrayRef(varlist_end(), varlist_size());
3669  }
3670 
3671  /// Set list of helper expressions, required for proper codegen of the clause.
3672  /// These expressions represent LHS expression in the final reduction
3673  /// expression performed by the reduction clause.
3674  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3675 
3676  /// Get the list of helper LHS expressions.
3677  MutableArrayRef<Expr *> getLHSExprs() {
3678  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3679  }
3680  ArrayRef<const Expr *> getLHSExprs() const {
3681  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3682  }
3683 
3684  /// Set list of helper expressions, required for proper codegen of the clause.
3685  /// These expressions represent RHS expression in the final reduction
3686  /// expression performed by the reduction clause. Also, variables in these
3687  /// expressions are used for proper initialization of reduction copies.
3688  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3689 
3690  /// Get the list of helper destination expressions.
3691  MutableArrayRef<Expr *> getRHSExprs() {
3692  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3693  }
3694  ArrayRef<const Expr *> getRHSExprs() const {
3695  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3696  }
3697 
3698  /// Set list of helper reduction expressions, required for proper
3699  /// codegen of the clause. These expressions are binary expressions or
3700  /// operator/custom reduction call that calculates new value from source
3701  /// helper expressions to destination helper expressions.
3702  void setReductionOps(ArrayRef<Expr *> ReductionOps);
3703 
3704  /// Get the list of helper reduction expressions.
3705  MutableArrayRef<Expr *> getReductionOps() {
3706  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3707  }
3708  ArrayRef<const Expr *> getReductionOps() const {
3709  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3710  }
3711 
3712  /// Set list of helper reduction taskgroup descriptors.
3713  void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3714 
3715  /// Get the list of helper reduction taskgroup descriptors.
3716  MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3717  return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3718  }
3719  ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3720  return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3721  }
3722 
3723 public:
3724  /// Creates clause with a list of variables \a VL.
3725  ///
3726  /// \param StartLoc Starting location of the clause.
3727  /// \param LParenLoc Location of '('.
3728  /// \param ColonLoc Location of ':'.
3729  /// \param EndLoc Ending location of the clause.
3730  /// \param VL The variables in the clause.
3731  /// \param QualifierLoc The nested-name qualifier with location information
3732  /// \param NameInfo The full name info for reduction identifier.
3733  /// \param Privates List of helper expressions for proper generation of
3734  /// private copies.
3735  /// \param LHSExprs List of helper expressions for proper generation of
3736  /// assignment operation required for copyprivate clause. This list represents
3737  /// LHSs of the reduction expressions.
3738  /// \param RHSExprs List of helper expressions for proper generation of
3739  /// assignment operation required for copyprivate clause. This list represents
3740  /// RHSs of the reduction expressions.
3741  /// Also, variables in these expressions are used for proper initialization of
3742  /// reduction copies.
3743  /// \param ReductionOps List of helper expressions that represents reduction
3744  /// expressions:
3745  /// \code
3746  /// LHSExprs binop RHSExprs;
3747  /// operator binop(LHSExpr, RHSExpr);
3748  /// <CutomReduction>(LHSExpr, RHSExpr);
3749  /// \endcode
3750  /// Required for proper codegen of final reduction operation performed by the
3751  /// reduction clause.
3752  /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3753  /// corresponding items in parent taskgroup task_reduction clause.
3754  /// \param PreInit Statement that must be executed before entering the OpenMP
3755  /// region with this clause.
3756  /// \param PostUpdate Expression that must be executed after exit from the
3757  /// OpenMP region with this clause.
3758  static OMPInReductionClause *
3759  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3760  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3761  NestedNameSpecifierLoc QualifierLoc,
3762  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3763  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3764  ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3765  Stmt *PreInit, Expr *PostUpdate);
3766 
3767  /// Creates an empty clause with the place for \a N variables.
3768  ///
3769  /// \param C AST context.
3770  /// \param N The number of variables.
3771  static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3772 
3773  /// Gets location of ':' symbol in clause.
3774  SourceLocation getColonLoc() const { return ColonLoc; }
3775 
3776  /// Gets the name info for specified reduction identifier.
3777  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3778 
3779  /// Gets the nested name specifier.
3780  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3781 
3784  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3785  using helper_expr_const_range =
3786  llvm::iterator_range<helper_expr_const_iterator>;
3787 
3789  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3790  }
3791 
3793  return helper_expr_range(getPrivates().begin(), getPrivates().end());
3794  }
3795 
3797  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3798  }
3799 
3801  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3802  }
3803 
3805  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3806  }
3807 
3809  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3810  }
3811 
3813  return helper_expr_const_range(getReductionOps().begin(),
3814  getReductionOps().end());
3815  }
3816 
3818  return helper_expr_range(getReductionOps().begin(),
3819  getReductionOps().end());
3820  }
3821 
3823  return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3824  getTaskgroupDescriptors().end());
3825  }
3826 
3828  return helper_expr_range(getTaskgroupDescriptors().begin(),
3829  getTaskgroupDescriptors().end());
3830  }
3831 
3833  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3834  reinterpret_cast<Stmt **>(varlist_end()));
3835  }
3836 
3838  auto Children = const_cast<OMPInReductionClause *>(this)->children();
3839  return const_child_range(Children.begin(), Children.end());
3840  }
3841 
3844  }
3847  }
3848 
3849  static bool classof(const OMPClause *T) {
3850  return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
3851  }
3852 };
3853 
3854 /// This represents clause 'linear' in the '#pragma omp ...'
3855 /// directives.
3856 ///
3857 /// \code
3858 /// #pragma omp simd linear(a,b : 2)
3859 /// \endcode
3860 /// In this example directive '#pragma omp simd' has clause 'linear'
3861 /// with variables 'a', 'b' and linear step '2'.
3862 class OMPLinearClause final
3863  : public OMPVarListClause<OMPLinearClause>,
3864  public OMPClauseWithPostUpdate,
3865  private llvm::TrailingObjects<OMPLinearClause, Expr *> {
3866  friend class OMPClauseReader;
3867  friend OMPVarListClause;
3868  friend TrailingObjects;
3869 
3870  /// Modifier of 'linear' clause.
3871  OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
3872 
3873  /// Location of linear modifier if any.
3874  SourceLocation ModifierLoc;
3875 
3876  /// Location of ':'.
3877  SourceLocation ColonLoc;
3878 
3879  /// Sets the linear step for clause.
3880  void setStep(Expr *Step) { *(getFinals().end()) = Step; }
3881 
3882  /// Sets the expression to calculate linear step for clause.
3883  void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
3884 
3885  /// Build 'linear' clause with given number of variables \a NumVars.
3886  ///
3887  /// \param StartLoc Starting location of the clause.
3888  /// \param LParenLoc Location of '('.
3889  /// \param ColonLoc Location of ':'.
3890  /// \param EndLoc Ending location of the clause.
3891  /// \param NumVars Number of variables.
3892  OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3893  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3894  SourceLocation ColonLoc, SourceLocation EndLoc,
3895  unsigned NumVars)
3896  : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
3897  LParenLoc, EndLoc, NumVars),
3898  OMPClauseWithPostUpdate(this), Modifier(Modifier),
3899  ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
3900 
3901  /// Build an empty clause.
3902  ///
3903  /// \param NumVars Number of variables.
3904  explicit OMPLinearClause(unsigned NumVars)
3905  : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
3906  SourceLocation(), SourceLocation(),
3907  SourceLocation(), NumVars),
3908  OMPClauseWithPostUpdate(this) {}
3909 
3910  /// Gets the list of initial values for linear variables.
3911  ///
3912  /// There are NumVars expressions with initial values allocated after the
3913  /// varlist, they are followed by NumVars update expressions (used to update
3914  /// the linear variable's value on current iteration) and they are followed by
3915  /// NumVars final expressions (used to calculate the linear variable's
3916  /// value after the loop body). After these lists, there are 2 helper
3917  /// expressions - linear step and a helper to calculate it before the
3918  /// loop body (used when the linear step is not constant):
3919  ///
3920  /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
3921  /// Finals[]; Step; CalcStep; }
3922  MutableArrayRef<Expr *> getPrivates() {
3923  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3924  }
3925  ArrayRef<const Expr *> getPrivates() const {
3926  return llvm::makeArrayRef(varlist_end(), varlist_size());
3927  }
3928 
3929  MutableArrayRef<Expr *> getInits() {
3930  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3931  }
3932  ArrayRef<const Expr *> getInits() const {
3933  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3934  }
3935 
3936  /// Sets the list of update expressions for linear variables.
3937  MutableArrayRef<Expr *> getUpdates() {
3938  return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
3939  }
3940  ArrayRef<const Expr *> getUpdates() const {
3941  return llvm::makeArrayRef(getInits().end(), varlist_size());
3942  }
3943 
3944  /// Sets the list of final update expressions for linear variables.
3945  MutableArrayRef<Expr *> getFinals() {
3946  return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
3947  }
3948  ArrayRef<const Expr *> getFinals() const {
3949  return llvm::makeArrayRef(getUpdates().end(), varlist_size());
3950  }
3951 
3952  /// Gets the list of used expressions for linear variables.
3953  MutableArrayRef<Expr *> getUsedExprs() {
3954  return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
3955  }
3956  ArrayRef<const Expr *> getUsedExprs() const {
3957  return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
3958  }
3959 
3960  /// Sets the list of the copies of original linear variables.
3961  /// \param PL List of expressions.
3962  void setPrivates(ArrayRef<Expr *> PL);
3963 
3964  /// Sets the list of the initial values for linear variables.
3965  /// \param IL List of expressions.
3966  void setInits(ArrayRef<Expr *> IL);
3967 
3968 public:
3969  /// Creates clause with a list of variables \a VL and a linear step
3970  /// \a Step.
3971  ///
3972  /// \param C AST Context.
3973  /// \param StartLoc Starting location of the clause.
3974  /// \param LParenLoc Location of '('.
3975  /// \param Modifier Modifier of 'linear' clause.
3976  /// \param ModifierLoc Modifier location.
3977  /// \param ColonLoc Location of ':'.
3978  /// \param EndLoc Ending location of the clause.
3979  /// \param VL List of references to the variables.
3980  /// \param PL List of private copies of original variables.
3981  /// \param IL List of initial values for the variables.
3982  /// \param Step Linear step.
3983  /// \param CalcStep Calculation of the linear step.
3984  /// \param PreInit Statement that must be executed before entering the OpenMP
3985  /// region with this clause.
3986  /// \param PostUpdate Expression that must be executed after exit from the
3987  /// OpenMP region with this clause.
3988  static OMPLinearClause *
3989  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3990  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3991  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3992  ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
3993  Stmt *PreInit, Expr *PostUpdate);
3994 
3995  /// Creates an empty clause with the place for \a NumVars variables.
3996  ///
3997  /// \param C AST context.
3998  /// \param NumVars Number of variables.
3999  static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4000 
4001  /// Set modifier.
4003 
4004  /// Return modifier.
4005  OpenMPLinearClauseKind getModifier() const { return Modifier; }
4006 
4007  /// Set modifier location.
4008  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4009 
4010  /// Return modifier location.
4011  SourceLocation getModifierLoc() const { return ModifierLoc; }
4012 
4013  /// Sets the location of ':'.
4014  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4015 
4016  /// Returns the location of ':'.
4017  SourceLocation getColonLoc() const { return ColonLoc; }
4018 
4019  /// Returns linear step.
4020  Expr *getStep() { return *(getFinals().end()); }
4021 
4022  /// Returns linear step.
4023  const Expr *getStep() const { return *(getFinals().end()); }
4024 
4025  /// Returns expression to calculate linear step.
4026  Expr *getCalcStep() { return *(getFinals().end() + 1); }
4027 
4028  /// Returns expression to calculate linear step.
4029  const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
4030 
4031  /// Sets the list of update expressions for linear variables.
4032  /// \param UL List of expressions.
4033  void setUpdates(ArrayRef<Expr *> UL);
4034 
4035  /// Sets the list of final update expressions for linear variables.
4036  /// \param FL List of expressions.
4037  void setFinals(ArrayRef<Expr *> FL);
4038 
4039  /// Sets the list of used expressions for the linear clause.
4040  void setUsedExprs(ArrayRef<Expr *> UE);
4041 
4044  using privates_range = llvm::iterator_range<privates_iterator>;
4045  using privates_const_range = llvm::iterator_range<privates_const_iterator>;
4046 
4048  return privates_range(getPrivates().begin(), getPrivates().end());
4049  }
4050 
4052  return privates_const_range(getPrivates().begin(), getPrivates().end());
4053  }
4054 
4057  using inits_range = llvm::iterator_range<inits_iterator>;
4058  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
4059 
4061  return inits_range(getInits().begin(), getInits().end());
4062  }
4063 
4065  return inits_const_range(getInits().begin(), getInits().end());
4066  }
4067 
4070  using updates_range = llvm::iterator_range<updates_iterator>;
4071  using updates_const_range = llvm::iterator_range<updates_const_iterator>;
4072 
4074  return updates_range(getUpdates().begin(), getUpdates().end());
4075  }
4076 
4078  return updates_const_range(getUpdates().begin(), getUpdates().end());
4079  }
4080 
4083  using finals_range = llvm::iterator_range<finals_iterator>;
4084  using finals_const_range = llvm::iterator_range<finals_const_iterator>;
4085 
4087  return finals_range(getFinals().begin(), getFinals().end());
4088  }
4089 
4091  return finals_const_range(getFinals().begin(), getFinals().end());
4092  }
4093 
4096  using used_expressions_range =
4097  llvm::iterator_range<used_expressions_iterator>;
4099  llvm::iterator_range<used_expressions_const_iterator>;
4100 
4102  return finals_range(getUsedExprs().begin(), getUsedExprs().end());
4103  }
4104 
4106  return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
4107  }
4108 
4110  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4111  reinterpret_cast<Stmt **>(varlist_end()));
4112  }
4113 
4115  auto Children = const_cast<OMPLinearClause *>(this)->children();
4116  return const_child_range(Children.begin(), Children.end());
4117  }
4118 
4120 
4122  auto Children = const_cast<OMPLinearClause *>(this)->used_children();
4123  return const_child_range(Children.begin(), Children.end());
4124  }
4125 
4126  static bool classof(const OMPClause *T) {
4127  return T->getClauseKind() == llvm::omp::OMPC_linear;
4128  }
4129 };
4130 
4131 /// This represents clause 'aligned' in the '#pragma omp ...'
4132 /// directives.
4133 ///
4134 /// \code
4135 /// #pragma omp simd aligned(a,b : 8)
4136 /// \endcode
4137 /// In this example directive '#pragma omp simd' has clause 'aligned'
4138 /// with variables 'a', 'b' and alignment '8'.
4139 class OMPAlignedClause final
4140  : public OMPVarListClause<OMPAlignedClause>,
4141  private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
4142  friend class OMPClauseReader;
4143  friend OMPVarListClause;
4144  friend TrailingObjects;
4145 
4146  /// Location of ':'.
4147  SourceLocation ColonLoc;
4148 
4149  /// Sets the alignment for clause.
4150  void setAlignment(Expr *A) { *varlist_end() = A; }
4151 
4152  /// Build 'aligned' clause with given number of variables \a NumVars.
4153  ///
4154  /// \param StartLoc Starting location of the clause.
4155  /// \param LParenLoc Location of '('.
4156  /// \param ColonLoc Location of ':'.
4157  /// \param EndLoc Ending location of the clause.
4158  /// \param NumVars Number of variables.
4159  OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4160  SourceLocation ColonLoc, SourceLocation EndLoc,
4161  unsigned NumVars)
4162  : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
4163  LParenLoc, EndLoc, NumVars),
4164  ColonLoc(ColonLoc) {}
4165 
4166  /// Build an empty clause.
4167  ///
4168  /// \param NumVars Number of variables.
4169  explicit OMPAlignedClause(unsigned NumVars)
4170  : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
4171  SourceLocation(), SourceLocation(),
4172  SourceLocation(), NumVars) {}
4173 
4174 public:
4175  /// Creates clause with a list of variables \a VL and alignment \a A.
4176  ///
4177  /// \param C AST Context.
4178  /// \param StartLoc Starting location of the clause.
4179  /// \param LParenLoc Location of '('.
4180  /// \param ColonLoc Location of ':'.
4181  /// \param EndLoc Ending location of the clause.
4182  /// \param VL List of references to the variables.
4183  /// \param A Alignment.
4184  static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
4185  SourceLocation LParenLoc,
4186  SourceLocation ColonLoc,
4187  SourceLocation EndLoc, ArrayRef<Expr *> VL,
4188  Expr *A);
4189 
4190  /// Creates an empty clause with the place for \a NumVars variables.
4191  ///
4192  /// \param C AST context.
4193  /// \param NumVars Number of variables.
4194  static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
4195 
4196  /// Sets the location of ':'.
4197  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4198 
4199  /// Returns the location of ':'.
4200  SourceLocation getColonLoc() const { return ColonLoc; }
4201 
4202  /// Returns alignment.
4203  Expr *getAlignment() { return *varlist_end(); }
4204 
4205  /// Returns alignment.
4206  const Expr *getAlignment() const { return *varlist_end(); }
4207 
4209  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4210  reinterpret_cast<Stmt **>(varlist_end()));
4211  }
4212 
4214  auto Children = const_cast<OMPAlignedClause *>(this)->children();
4215  return const_child_range(Children.begin(), Children.end());
4216  }
4217 
4220  }
4223  }
4224 
4225  static bool classof(const OMPClause *T) {
4226  return T->getClauseKind() == llvm::omp::OMPC_aligned;
4227  }
4228 };
4229 
4230 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
4231 ///
4232 /// \code
4233 /// #pragma omp parallel copyin(a,b)
4234 /// \endcode
4235 /// In this example directive '#pragma omp parallel' has clause 'copyin'
4236 /// with the variables 'a' and 'b'.
4237 class OMPCopyinClause final
4238  : public OMPVarListClause<OMPCopyinClause>,
4239  private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
4240  // Class has 3 additional tail allocated arrays:
4241  // 1. List of helper expressions for proper generation of assignment operation
4242  // required for copyin clause. This list represents sources.
4243  // 2. List of helper expressions for proper generation of assignment operation
4244  // required for copyin clause. This list represents destinations.
4245  // 3. List of helper expressions that represents assignment operation:
4246  // \code
4247  // DstExprs = SrcExprs;
4248  // \endcode
4249  // Required for proper codegen of propagation of master's thread values of
4250  // threadprivate variables to local instances of that variables in other
4251  // implicit threads.
4252 
4253  friend class OMPClauseReader;
4254  friend OMPVarListClause;
4255  friend TrailingObjects;
4256 
4257  /// Build clause with number of variables \a N.
4258  ///
4259  /// \param StartLoc Starting location of the clause.
4260  /// \param LParenLoc Location of '('.
4261  /// \param EndLoc Ending location of the clause.
4262  /// \param N Number of the variables in the clause.
4263  OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4264  SourceLocation EndLoc, unsigned N)
4265  : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
4266  LParenLoc, EndLoc, N) {}
4267 
4268  /// Build an empty clause.
4269  ///
4270  /// \param N Number of variables.
4271  explicit OMPCopyinClause(unsigned N)
4272  : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
4274  SourceLocation(), N) {}
4275 
4276  /// Set list of helper expressions, required for proper codegen of the
4277  /// clause. These expressions represent source expression in the final
4278  /// assignment statement performed by the copyin clause.
4279  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4280 
4281  /// Get the list of helper source expressions.
4282  MutableArrayRef<Expr *> getSourceExprs() {
4283  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4284  }
4285  ArrayRef<const Expr *> getSourceExprs() const {
4286  return llvm::makeArrayRef(varlist_end(), varlist_size());
4287  }
4288 
4289  /// Set list of helper expressions, required for proper codegen of the
4290  /// clause. These expressions represent destination expression in the final
4291  /// assignment statement performed by the copyin clause.
4292  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4293 
4294  /// Get the list of helper destination expressions.
4295  MutableArrayRef<Expr *> getDestinationExprs() {
4296  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4297  }
4298  ArrayRef<const Expr *> getDestinationExprs() const {
4299  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
4300  }
4301 
4302  /// Set list of helper assignment expressions, required for proper
4303  /// codegen of the clause. These expressions are assignment expressions that
4304  /// assign source helper expressions to destination helper expressions
4305  /// correspondingly.
4306  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4307 
4308  /// Get the list of helper assignment expressions.
4309  MutableArrayRef<Expr *> getAssignmentOps() {
4310  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4311  }
4312  ArrayRef<const Expr *> getAssignmentOps() const {
4313  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
4314  }
4315 
4316 public:
4317  /// Creates clause with a list of variables \a VL.
4318  ///
4319  /// \param C AST context.
4320  /// \param StartLoc Starting location of the clause.
4321  /// \param LParenLoc Location of '('.
4322  /// \param EndLoc Ending location of the clause.
4323  /// \param VL List of references to the variables.
4324  /// \param SrcExprs List of helper expressions for proper generation of
4325  /// assignment operation required for copyin clause. This list represents
4326  /// sources.
4327  /// \param DstExprs List of helper expressions for proper generation of
4328  /// assignment operation required for copyin clause. This list represents
4329  /// destinations.
4330  /// \param AssignmentOps List of helper expressions that represents assignment
4331  /// operation:
4332  /// \code
4333  /// DstExprs = SrcExprs;
4334  /// \endcode
4335  /// Required for proper codegen of propagation of master's thread values of
4336  /// threadprivate variables to local instances of that variables in other
4337  /// implicit threads.
4338  static OMPCopyinClause *
4339  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4340  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4341  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4342 
4343  /// Creates an empty clause with \a N variables.
4344  ///
4345  /// \param C AST context.
4346  /// \param N The number of variables.
4347  static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
4348 
4351  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4352  using helper_expr_const_range =
4353  llvm::iterator_range<helper_expr_const_iterator>;
4354 
4356  return helper_expr_const_range(getSourceExprs().begin(),
4357  getSourceExprs().end());
4358  }
4359 
4361  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4362  }
4363 
4365  return helper_expr_const_range(getDestinationExprs().begin(),
4366  getDestinationExprs().end());
4367  }
4368 
4370  return helper_expr_range(getDestinationExprs().begin(),
4371  getDestinationExprs().end());
4372  }
4373 
4375  return helper_expr_const_range(getAssignmentOps().begin(),
4376  getAssignmentOps().end());
4377  }
4378 
4380  return helper_expr_range(getAssignmentOps().begin(),
4381  getAssignmentOps().end());
4382  }
4383 
4385  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4386  reinterpret_cast<Stmt **>(varlist_end()));
4387  }
4388 
4390  auto Children = const_cast<OMPCopyinClause *>(this)->children();
4391  return const_child_range(Children.begin(), Children.end());
4392  }
4393 
4396  }
4399  }
4400 
4401  static bool classof(const OMPClause *T) {
4402  return T->getClauseKind() == llvm::omp::OMPC_copyin;
4403  }
4404 };
4405 
4406 /// This represents clause 'copyprivate' in the '#pragma omp ...'
4407 /// directives.
4408 ///
4409 /// \code
4410 /// #pragma omp single copyprivate(a,b)
4411 /// \endcode
4412 /// In this example directive '#pragma omp single' has clause 'copyprivate'
4413 /// with the variables 'a' and 'b'.
4415  : public OMPVarListClause<OMPCopyprivateClause>,
4416  private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
4417  friend class OMPClauseReader;
4418  friend OMPVarListClause;
4419  friend TrailingObjects;
4420 
4421  /// Build clause with number of variables \a N.
4422  ///
4423  /// \param StartLoc Starting location of the clause.
4424  /// \param LParenLoc Location of '('.
4425  /// \param EndLoc Ending location of the clause.
4426  /// \param N Number of the variables in the clause.
4428  SourceLocation EndLoc, unsigned N)
4429  : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
4430  StartLoc, LParenLoc, EndLoc, N) {
4431  }
4432 
4433  /// Build an empty clause.
4434  ///
4435  /// \param N Number of variables.
4436  explicit OMPCopyprivateClause(unsigned N)
4438  llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
4439  SourceLocation(), N) {}
4440 
4441  /// Set list of helper expressions, required for proper codegen of the
4442  /// clause. These expressions represent source expression in the final
4443  /// assignment statement performed by the copyprivate clause.
4444  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4445 
4446  /// Get the list of helper source expressions.
4447  MutableArrayRef<Expr *> getSourceExprs() {
4448  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4449  }
4450  ArrayRef<const Expr *> getSourceExprs() const {
4451  return llvm::makeArrayRef(varlist_end(), varlist_size());
4452  }
4453 
4454  /// Set list of helper expressions, required for proper codegen of the
4455  /// clause. These expressions represent destination expression in the final
4456  /// assignment statement performed by the copyprivate clause.
4457  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4458 
4459  /// Get the list of helper destination expressions.
4460  MutableArrayRef<Expr *> getDestinationExprs() {
4461  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4462  }
4463  ArrayRef<const Expr *> getDestinationExprs() const {
4464  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
4465  }
4466 
4467  /// Set list of helper assignment expressions, required for proper
4468  /// codegen of the clause. These expressions are assignment expressions that
4469  /// assign source helper expressions to destination helper expressions
4470  /// correspondingly.
4471  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4472 
4473  /// Get the list of helper assignment expressions.
4474  MutableArrayRef<Expr *> getAssignmentOps() {
4475  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4476  }
4477  ArrayRef<const Expr *> getAssignmentOps() const {
4478  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
4479  }
4480 
4481 public:
4482  /// Creates clause with a list of variables \a VL.
4483  ///
4484  /// \param C AST context.
4485  /// \param StartLoc Starting location of the clause.
4486  /// \param LParenLoc Location of '('.
4487  /// \param EndLoc Ending location of the clause.
4488  /// \param VL List of references to the variables.
4489  /// \param SrcExprs List of helper expressions for proper generation of
4490  /// assignment operation required for copyprivate clause. This list represents
4491  /// sources.
4492  /// \param DstExprs List of helper expressions for proper generation of
4493  /// assignment operation required for copyprivate clause. This list represents
4494  /// destinations.
4495  /// \param AssignmentOps List of helper expressions that represents assignment
4496  /// operation:
4497  /// \code
4498  /// DstExprs = SrcExprs;
4499  /// \endcode
4500  /// Required for proper codegen of final assignment performed by the
4501  /// copyprivate clause.
4502  static OMPCopyprivateClause *
4503  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4504  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4505  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4506 
4507  /// Creates an empty clause with \a N variables.
4508  ///
4509  /// \param C AST context.
4510  /// \param N The number of variables.
4511  static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
4512 
4515  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4516  using helper_expr_const_range =
4517  llvm::iterator_range<helper_expr_const_iterator>;
4518 
4520  return helper_expr_const_range(getSourceExprs().begin(),
4521  getSourceExprs().end());
4522  }
4523 
4525  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4526  }
4527 
4529  return helper_expr_const_range(getDestinationExprs().begin(),
4530  getDestinationExprs().end());
4531  }
4532 
4534  return helper_expr_range(getDestinationExprs().begin(),
4535  getDestinationExprs().end());
4536  }
4537 
4539  return helper_expr_const_range(getAssignmentOps().begin(),
4540  getAssignmentOps().end());
4541  }
4542 
4544  return helper_expr_range(getAssignmentOps().begin(),
4545  getAssignmentOps().end());
4546  }
4547 
4549  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4550  reinterpret_cast<Stmt **>(varlist_end()));
4551  }
4552 
4554  auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
4555  return const_child_range(Children.begin(), Children.end());
4556  }
4557 
4560  }
4563  }
4564 
4565  static bool classof(const OMPClause *T) {
4566  return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
4567  }
4568 };
4569 
4570 /// This represents implicit clause 'flush' for the '#pragma omp flush'
4571 /// directive.
4572 /// This clause does not exist by itself, it can be only as a part of 'omp
4573 /// flush' directive. This clause is introduced to keep the original structure
4574 /// of \a OMPExecutableDirective class and its derivatives and to use the
4575 /// existing infrastructure of clauses with the list of variables.
4576 ///
4577 /// \code
4578 /// #pragma omp flush(a,b)
4579 /// \endcode
4580 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
4581 /// with the variables 'a' and 'b'.
4582 class OMPFlushClause final
4583  : public OMPVarListClause<OMPFlushClause>,
4584  private llvm::TrailingObjects<OMPFlushClause, Expr *> {
4585  friend OMPVarListClause;
4586  friend TrailingObjects;
4587 
4588  /// Build clause with number of variables \a N.
4589  ///
4590  /// \param StartLoc Starting location of the clause.
4591  /// \param LParenLoc Location of '('.
4592  /// \param EndLoc Ending location of the clause.
4593  /// \param N Number of the variables in the clause.
4594  OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4595  SourceLocation EndLoc, unsigned N)
4596  : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
4597  LParenLoc, EndLoc, N) {}
4598 
4599  /// Build an empty clause.
4600  ///
4601  /// \param N Number of variables.
4602  explicit OMPFlushClause(unsigned N)
4603  : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
4605  SourceLocation(), N) {}
4606 
4607 public:
4608  /// Creates clause with a list of variables \a VL.
4609  ///
4610  /// \param C AST context.
4611  /// \param StartLoc Starting location of the clause.
4612  /// \param LParenLoc Location of '('.
4613  /// \param EndLoc Ending location of the clause.
4614  /// \param VL List of references to the variables.
4615  static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
4616  SourceLocation LParenLoc, SourceLocation EndLoc,
4617  ArrayRef<Expr *> VL);
4618 
4619  /// Creates an empty clause with \a N variables.
4620  ///
4621  /// \param C AST context.
4622  /// \param N The number of variables.
4623  static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
4624 
4626  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4627  reinterpret_cast<Stmt **>(varlist_end()));
4628  }
4629 
4631  auto Children = const_cast<OMPFlushClause *>(this)->children();
4632  return const_child_range(Children.begin(), Children.end());
4633  }
4634 
4637  }
4640  }
4641 
4642  static bool classof(const OMPClause *T) {
4643  return T->getClauseKind() == llvm::omp::OMPC_flush;
4644  }
4645 };
4646 
4647 /// This represents implicit clause 'depobj' for the '#pragma omp depobj'
4648 /// directive.
4649 /// This clause does not exist by itself, it can be only as a part of 'omp
4650 /// depobj' directive. This clause is introduced to keep the original structure
4651 /// of \a OMPExecutableDirective class and its derivatives and to use the
4652 /// existing infrastructure of clauses with the list of variables.
4653 ///
4654 /// \code
4655 /// #pragma omp depobj(a) destroy
4656 /// \endcode
4657 /// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
4658 /// with the depobj 'a'.
4659 class OMPDepobjClause final : public OMPClause {
4660  friend class OMPClauseReader;
4661 
4662  /// Location of '('.
4663  SourceLocation LParenLoc;
4664 
4665  /// Chunk size.
4666  Expr *Depobj = nullptr;
4667 
4668  /// Build clause with number of variables \a N.
4669  ///
4670  /// \param StartLoc Starting location of the clause.
4671  /// \param LParenLoc Location of '('.
4672  /// \param EndLoc Ending location of the clause.
4673  OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4674  SourceLocation EndLoc)
4675  : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
4676  LParenLoc(LParenLoc) {}
4677 
4678  /// Build an empty clause.
4679  ///
4680  explicit OMPDepobjClause()
4681  : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
4682 
4683  void setDepobj(Expr *E) { Depobj = E; }
4684 
4685  /// Sets the location of '('.
4686  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4687 
4688 public:
4689  /// Creates clause.
4690  ///
4691  /// \param C AST context.
4692  /// \param StartLoc Starting location of the clause.
4693  /// \param LParenLoc Location of '('.
4694  /// \param EndLoc Ending location of the clause.
4695  /// \param Depobj depobj expression associated with the 'depobj' directive.
4696  static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc,
4697  SourceLocation LParenLoc,
4698  SourceLocation EndLoc, Expr *Depobj);
4699 
4700  /// Creates an empty clause.
4701  ///
4702  /// \param C AST context.
4703  static OMPDepobjClause *CreateEmpty(const ASTContext &C);
4704 
4705  /// Returns depobj expression associated with the clause.
4706  Expr *getDepobj() { return Depobj; }
4707  const Expr *getDepobj() const { return Depobj; }
4708 
4709  /// Returns the location of '('.
4710  SourceLocation getLParenLoc() const { return LParenLoc; }
4711 
4713  return child_range(reinterpret_cast<Stmt **>(&Depobj),
4714  reinterpret_cast<Stmt **>(&Depobj) + 1);
4715  }
4716 
4718  auto Children = const_cast<OMPDepobjClause *>(this)->children();
4719  return const_child_range(Children.begin(), Children.end());
4720  }
4721 
4724  }
4727  }
4728 
4729  static bool classof(const OMPClause *T) {
4730  return T->getClauseKind() == llvm::omp::OMPC_depobj;
4731  }
4732 };
4733 
4734 /// This represents implicit clause 'depend' for the '#pragma omp task'
4735 /// directive.
4736 ///
4737 /// \code
4738 /// #pragma omp task depend(in:a,b)
4739 /// \endcode
4740 /// In this example directive '#pragma omp task' with clause 'depend' with the
4741 /// variables 'a' and 'b' with dependency 'in'.
4742 class OMPDependClause final
4743  : public OMPVarListClause<OMPDependClause>,
4744  private llvm::TrailingObjects<OMPDependClause, Expr *> {
4745  friend class OMPClauseReader;
4746  friend OMPVarListClause;
4747  friend TrailingObjects;
4748 
4749  /// Dependency type (one of in, out, inout).
4751 
4752  /// Dependency type location.
4753  SourceLocation DepLoc;
4754 
4755  /// Colon location.
4756  SourceLocation ColonLoc;
4757 
4758  /// Number of loops, associated with the depend clause.
4759  unsigned NumLoops = 0;
4760 
4761  /// Build clause with number of variables \a N.
4762  ///
4763  /// \param StartLoc Starting location of the clause.
4764  /// \param LParenLoc Location of '('.
4765  /// \param EndLoc Ending location of the clause.
4766  /// \param N Number of the variables in the clause.
4767  /// \param NumLoops Number of loops that is associated with this depend
4768  /// clause.
4769  OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4770  SourceLocation EndLoc, unsigned N, unsigned NumLoops)
4771  : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, StartLoc,
4772  LParenLoc, EndLoc, N),
4773  NumLoops(NumLoops) {}
4774 
4775  /// Build an empty clause.
4776  ///
4777  /// \param N Number of variables.
4778  /// \param NumLoops Number of loops that is associated with this depend
4779  /// clause.
4780  explicit OMPDependClause(unsigned N, unsigned NumLoops)
4781  : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend,
4783  SourceLocation(), N),
4784  NumLoops(NumLoops) {}
4785 
4786  /// Set dependency kind.
4787  void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
4788 
4789  /// Set dependency kind and its location.
4790  void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
4791 
4792  /// Set colon location.
4793  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4794 
4795  /// Sets optional dependency modifier.
4796  void setModifier(Expr *DepModifier);
4797 
4798 public:
4799  /// Creates clause with a list of variables \a VL.
4800  ///
4801  /// \param C AST context.
4802  /// \param StartLoc Starting location of the clause.
4803  /// \param LParenLoc Location of '('.
4804  /// \param EndLoc Ending location of the clause.
4805  /// \param DepKind Dependency type.
4806  /// \param DepLoc Location of the dependency type.
4807  /// \param ColonLoc Colon location.
4808  /// \param VL List of references to the variables.
4809  /// \param NumLoops Number of loops that is associated with this depend
4810  /// clause.
4811  static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
4812  SourceLocation LParenLoc,
4813  SourceLocation EndLoc, Expr *DepModifier,
4814  OpenMPDependClauseKind DepKind,
4815  SourceLocation DepLoc, SourceLocation ColonLoc,
4816  ArrayRef<Expr *> VL, unsigned NumLoops);
4817 
4818  /// Creates an empty clause with \a N variables.
4819  ///
4820  /// \param C AST context.
4821  /// \param N The number of variables.
4822  /// \param NumLoops Number of loops that is associated with this depend
4823  /// clause.
4824  static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
4825  unsigned NumLoops);
4826 
4827  /// Get dependency type.
4828  OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
4829 
4830  /// Return optional depend modifier.
4831  Expr *getModifier();
4832  const Expr *getModifier() const {
4833  return const_cast<OMPDependClause *>(this)->getModifier();
4834  }
4835 
4836  /// Get dependency type location.
4837  SourceLocation getDependencyLoc() const { return DepLoc; }
4838 
4839  /// Get colon location.
4840  SourceLocation getColonLoc() const { return ColonLoc; }
4841 
4842  /// Get number of loops associated with the clause.
4843  unsigned getNumLoops() const { return NumLoops; }
4844 
4845  /// Set the loop data for the depend clauses with 'sink|source' kind of
4846  /// dependency.
4847  void setLoopData(unsigned NumLoop, Expr *Cnt);
4848 
4849  /// Get the loop data.
4850  Expr *getLoopData(unsigned NumLoop);
4851  const Expr *getLoopData(unsigned NumLoop) const;
4852 
4854  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4855  reinterpret_cast<Stmt **>(varlist_end()));
4856  }
4857 
4859  auto Children = const_cast<OMPDependClause *>(this)->children();
4860  return const_child_range(Children.begin(), Children.end());
4861  }
4862 
4865  }
4868  }
4869 
4870  static bool classof(const OMPClause *T) {
4871  return T->getClauseKind() == llvm::omp::OMPC_depend;
4872  }
4873 };
4874 
4875 /// This represents 'device' clause in the '#pragma omp ...'
4876 /// directive.
4877 ///
4878 /// \code
4879 /// #pragma omp target device(a)
4880 /// \endcode
4881 /// In this example directive '#pragma omp target' has clause 'device'
4882 /// with single expression 'a'.
4884  friend class OMPClauseReader;
4885 
4886  /// Location of '('.
4887  SourceLocation LParenLoc;
4888 
4889  /// Device clause modifier.
4891 
4892  /// Location of the modifier.
4893  SourceLocation ModifierLoc;
4894 
4895  /// Device number.
4896  Stmt *Device = nullptr;
4897 
4898  /// Set the device number.
4899  ///
4900  /// \param E Device number.
4901  void setDevice(Expr *E) { Device = E; }
4902 
4903  /// Sets modifier.
4904  void setModifier(OpenMPDeviceClauseModifier M) { Modifier = M; }
4905 
4906  /// Setst modifier location.
4907  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4908 
4909 public:
4910  /// Build 'device' clause.
4911  ///
4912  /// \param Modifier Clause modifier.
4913  /// \param E Expression associated with this clause.
4914  /// \param CaptureRegion Innermost OpenMP region where expressions in this
4915  /// clause must be captured.
4916  /// \param StartLoc Starting location of the clause.
4917  /// \param ModifierLoc Modifier location.
4918  /// \param LParenLoc Location of '('.
4919  /// \param EndLoc Ending location of the clause.
4921  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
4922  SourceLocation LParenLoc, SourceLocation ModifierLoc,
4923  SourceLocation EndLoc)
4924  : OMPClause(llvm::omp::OMPC_device, StartLoc, EndLoc),
4925  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
4926  ModifierLoc(ModifierLoc), Device(E) {
4927  setPreInitStmt(HelperE, CaptureRegion);
4928  }
4929 
4930  /// Build an empty clause.
4932  : OMPClause(llvm::omp::OMPC_device, SourceLocation(), SourceLocation()),
4933  OMPClauseWithPreInit(this) {}
4934 
4935  /// Sets the location of '('.
4936  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4937 
4938  /// Returns the location of '('.
4939  SourceLocation getLParenLoc() const { return LParenLoc; }
4940 
4941  /// Return device number.
4942  Expr *getDevice() { return cast<Expr>(Device); }
4943 
4944  /// Return device number.
4945  Expr *getDevice() const { return cast<Expr>(Device); }
4946 
4947  /// Gets modifier.
4948  OpenMPDeviceClauseModifier getModifier() const { return Modifier; }
4949 
4950  /// Gets modifier location.
4951  SourceLocation getModifierLoc() const { return ModifierLoc; }
4952 
4953  child_range children() { return child_range(&Device, &Device + 1); }
4954 
4956  return const_child_range(&Device, &Device + 1);
4957  }
4958 
4961  }
4964  }
4965 
4966  static bool classof(const OMPClause *T) {
4967  return T->getClauseKind() == llvm::omp::OMPC_device;
4968  }
4969 };
4970 
4971 /// This represents 'threads' clause in the '#pragma omp ...' directive.
4972 ///
4973 /// \code
4974 /// #pragma omp ordered threads
4975 /// \endcode
4976 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
4977 class OMPThreadsClause : public OMPClause {
4978 public:
4979  /// Build 'threads' clause.
4980  ///
4981  /// \param StartLoc Starting location of the clause.
4982  /// \param EndLoc Ending location of the clause.
4984  : OMPClause(llvm::omp::OMPC_threads, StartLoc, EndLoc) {}
4985 
4986  /// Build an empty clause.
4988  : OMPClause(llvm::omp::OMPC_threads, SourceLocation(), SourceLocation()) {
4989  }
4990 
4993  }
4994