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