clang  13.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 /// This represents 'collapse' clause in the '#pragma omp ...'
892 /// directive.
893 ///
894 /// \code
895 /// #pragma omp simd collapse(3)
896 /// \endcode
897 /// In this example directive '#pragma omp simd' has clause 'collapse'
898 /// with single expression '3'.
899 /// The parameter must be a constant positive integer expression, it specifies
900 /// the number of nested loops that should be collapsed into a single iteration
901 /// space.
902 class OMPCollapseClause : public OMPClause {
903  friend class OMPClauseReader;
904 
905  /// Location of '('.
906  SourceLocation LParenLoc;
907 
908  /// Number of for-loops.
909  Stmt *NumForLoops = nullptr;
910 
911  /// Set the number of associated for-loops.
912  void setNumForLoops(Expr *Num) { NumForLoops = Num; }
913 
914 public:
915  /// Build 'collapse' clause.
916  ///
917  /// \param Num Expression associated with this clause.
918  /// \param StartLoc Starting location of the clause.
919  /// \param LParenLoc Location of '('.
920  /// \param EndLoc Ending location of the clause.
922  SourceLocation LParenLoc, SourceLocation EndLoc)
923  : OMPClause(llvm::omp::OMPC_collapse, StartLoc, EndLoc),
924  LParenLoc(LParenLoc), NumForLoops(Num) {}
925 
926  /// Build an empty clause.
927  explicit OMPCollapseClause()
928  : OMPClause(llvm::omp::OMPC_collapse, SourceLocation(),
929  SourceLocation()) {}
930 
931  /// Sets the location of '('.
932  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
933 
934  /// Returns the location of '('.
935  SourceLocation getLParenLoc() const { return LParenLoc; }
936 
937  /// Return the number of associated for-loops.
938  Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
939 
940  child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
941 
943  return const_child_range(&NumForLoops, &NumForLoops + 1);
944  }
945 
948  }
951  }
952 
953  static bool classof(const OMPClause *T) {
954  return T->getClauseKind() == llvm::omp::OMPC_collapse;
955  }
956 };
957 
958 /// This represents 'default' clause in the '#pragma omp ...' directive.
959 ///
960 /// \code
961 /// #pragma omp parallel default(shared)
962 /// \endcode
963 /// In this example directive '#pragma omp parallel' has simple 'default'
964 /// clause with kind 'shared'.
965 class OMPDefaultClause : public OMPClause {
966  friend class OMPClauseReader;
967 
968  /// Location of '('.
969  SourceLocation LParenLoc;
970 
971  /// A kind of the 'default' clause.
972  llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
973 
974  /// Start location of the kind in source code.
975  SourceLocation KindKwLoc;
976 
977  /// Set kind of the clauses.
978  ///
979  /// \param K Argument of clause.
980  void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
981 
982  /// Set argument location.
983  ///
984  /// \param KLoc Argument location.
985  void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
986 
987 public:
988  /// Build 'default' clause with argument \a A ('none' or 'shared').
989  ///
990  /// \param A Argument of the clause ('none' or 'shared').
991  /// \param ALoc Starting location of the argument.
992  /// \param StartLoc Starting location of the clause.
993  /// \param LParenLoc Location of '('.
994  /// \param EndLoc Ending location of the clause.
995  OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
996  SourceLocation StartLoc, SourceLocation LParenLoc,
997  SourceLocation EndLoc)
998  : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
999  LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1000 
1001  /// Build an empty clause.
1003  : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
1004  }
1005 
1006  /// Sets the location of '('.
1007  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1008 
1009  /// Returns the location of '('.
1010  SourceLocation getLParenLoc() const { return LParenLoc; }
1011 
1012  /// Returns kind of the clause.
1013  llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
1014 
1015  /// Returns location of clause kind.
1016  SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
1017 
1020  }
1021 
1024  }
1025 
1028  }
1031  }
1032 
1033  static bool classof(const OMPClause *T) {
1034  return T->getClauseKind() == llvm::omp::OMPC_default;
1035  }
1036 };
1037 
1038 /// This represents 'proc_bind' clause in the '#pragma omp ...'
1039 /// directive.
1040 ///
1041 /// \code
1042 /// #pragma omp parallel proc_bind(master)
1043 /// \endcode
1044 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
1045 /// clause with kind 'master'.
1047  friend class OMPClauseReader;
1048 
1049  /// Location of '('.
1050  SourceLocation LParenLoc;
1051 
1052  /// A kind of the 'proc_bind' clause.
1053  llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
1054 
1055  /// Start location of the kind in source code.
1056  SourceLocation KindKwLoc;
1057 
1058  /// Set kind of the clause.
1059  ///
1060  /// \param K Kind of clause.
1061  void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
1062 
1063  /// Set clause kind location.
1064  ///
1065  /// \param KLoc Kind location.
1066  void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
1067 
1068 public:
1069  /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
1070  /// 'spread').
1071  ///
1072  /// \param A Argument of the clause ('master', 'close' or 'spread').
1073  /// \param ALoc Starting location of the argument.
1074  /// \param StartLoc Starting location of the clause.
1075  /// \param LParenLoc Location of '('.
1076  /// \param EndLoc Ending location of the clause.
1077  OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
1078  SourceLocation StartLoc, SourceLocation LParenLoc,
1079  SourceLocation EndLoc)
1080  : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
1081  LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1082 
1083  /// Build an empty clause.
1085  : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
1086  SourceLocation()) {}
1087 
1088  /// Sets the location of '('.
1089  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1090 
1091  /// Returns the location of '('.
1092  SourceLocation getLParenLoc() const { return LParenLoc; }
1093 
1094  /// Returns kind of the clause.
1095  llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
1096 
1097  /// Returns location of clause kind.
1098  SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
1099 
1102  }
1103 
1106  }
1107 
1110  }
1113  }
1114 
1115  static bool classof(const OMPClause *T) {
1116  return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
1117  }
1118 };
1119 
1120 /// This represents 'unified_address' clause in the '#pragma omp requires'
1121 /// directive.
1122 ///
1123 /// \code
1124 /// #pragma omp requires unified_address
1125 /// \endcode
1126 /// In this example directive '#pragma omp requires' has 'unified_address'
1127 /// clause.
1128 class OMPUnifiedAddressClause final : public OMPClause {
1129 public:
1130  friend class OMPClauseReader;
1131  /// Build 'unified_address' clause.
1132  ///
1133  /// \param StartLoc Starting location of the clause.
1134  /// \param EndLoc Ending location of the clause.
1136  : OMPClause(llvm::omp::OMPC_unified_address, StartLoc, EndLoc) {}
1137 
1138  /// Build an empty clause.
1140  : OMPClause(llvm::omp::OMPC_unified_address, SourceLocation(),
1141  SourceLocation()) {}
1142 
1145  }
1146 
1149  }
1150 
1153  }
1156  }
1157 
1158  static bool classof(const OMPClause *T) {
1159  return T->getClauseKind() == llvm::omp::OMPC_unified_address;
1160  }
1161 };
1162 
1163 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1164 /// directive.
1165 ///
1166 /// \code
1167 /// #pragma omp requires unified_shared_memory
1168 /// \endcode
1169 /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1170 /// clause.
1172 public:
1173  friend class OMPClauseReader;
1174  /// Build 'unified_shared_memory' clause.
1175  ///
1176  /// \param StartLoc Starting location of the clause.
1177  /// \param EndLoc Ending location of the clause.
1179  : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1180 
1181  /// Build an empty clause.
1183  : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
1184  SourceLocation()) {}
1185 
1188  }
1189 
1192  }
1193 
1196  }
1199  }
1200 
1201  static bool classof(const OMPClause *T) {
1202  return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
1203  }
1204 };
1205 
1206 /// This represents 'reverse_offload' clause in the '#pragma omp requires'
1207 /// directive.
1208 ///
1209 /// \code
1210 /// #pragma omp requires reverse_offload
1211 /// \endcode
1212 /// In this example directive '#pragma omp requires' has 'reverse_offload'
1213 /// clause.
1214 class OMPReverseOffloadClause final : public OMPClause {
1215 public:
1216  friend class OMPClauseReader;
1217  /// Build 'reverse_offload' clause.
1218  ///
1219  /// \param StartLoc Starting location of the clause.
1220  /// \param EndLoc Ending location of the clause.
1222  : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
1223 
1224  /// Build an empty clause.
1226  : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
1227  SourceLocation()) {}
1228 
1231  }
1232 
1235  }
1236 
1239  }
1242  }
1243 
1244  static bool classof(const OMPClause *T) {
1245  return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
1246  }
1247 };
1248 
1249 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1250 /// directive.
1251 ///
1252 /// \code
1253 /// #pragma omp requires dynamic_allocators
1254 /// \endcode
1255 /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1256 /// clause.
1258 public:
1259  friend class OMPClauseReader;
1260  /// Build 'dynamic_allocators' clause.
1261  ///
1262  /// \param StartLoc Starting location of the clause.
1263  /// \param EndLoc Ending location of the clause.
1265  : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1266 
1267  /// Build an empty clause.
1269  : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
1270  SourceLocation()) {}
1271 
1274  }
1275 
1278  }
1279 
1282  }
1285  }
1286 
1287  static bool classof(const OMPClause *T) {
1288  return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
1289  }
1290 };
1291 
1292 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1293 /// requires' directive.
1294 ///
1295 /// \code
1296 /// #pragma omp requires atomic_default_mem_order(seq_cst)
1297 /// \endcode
1298 /// In this example directive '#pragma omp requires' has simple
1299 /// atomic_default_mem_order' clause with kind 'seq_cst'.
1301  friend class OMPClauseReader;
1302 
1303  /// Location of '('
1304  SourceLocation LParenLoc;
1305 
1306  /// A kind of the 'atomic_default_mem_order' clause.
1309 
1310  /// Start location of the kind in source code.
1311  SourceLocation KindKwLoc;
1312 
1313  /// Set kind of the clause.
1314  ///
1315  /// \param K Kind of clause.
1316  void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1317  Kind = K;
1318  }
1319 
1320  /// Set clause kind location.
1321  ///
1322  /// \param KLoc Kind location.
1323  void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1324  KindKwLoc = KLoc;
1325  }
1326 
1327 public:
1328  /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1329  /// 'acq_rel' or 'relaxed').
1330  ///
1331  /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1332  /// \param ALoc Starting location of the argument.
1333  /// \param StartLoc Starting location of the clause.
1334  /// \param LParenLoc Location of '('.
1335  /// \param EndLoc Ending location of the clause.
1337  SourceLocation ALoc, SourceLocation StartLoc,
1338  SourceLocation LParenLoc,
1339  SourceLocation EndLoc)
1340  : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1341  LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1342 
1343  /// Build an empty clause.
1345  : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
1346  SourceLocation()) {}
1347 
1348  /// Sets the location of '('.
1349  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1350 
1351  /// Returns the locaiton of '('.
1352  SourceLocation getLParenLoc() const { return LParenLoc; }
1353 
1354  /// Returns kind of the clause.
1356  return Kind;
1357  }
1358 
1359  /// Returns location of clause kind.
1361 
1364  }
1365 
1368  }
1369 
1372  }
1375  }
1376 
1377  static bool classof(const OMPClause *T) {
1378  return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
1379  }
1380 };
1381 
1382 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
1383 ///
1384 /// \code
1385 /// #pragma omp for schedule(static, 3)
1386 /// \endcode
1387 /// In this example directive '#pragma omp for' has 'schedule' clause with
1388 /// arguments 'static' and '3'.
1390  friend class OMPClauseReader;
1391 
1392  /// Location of '('.
1393  SourceLocation LParenLoc;
1394 
1395  /// A kind of the 'schedule' clause.
1397 
1398  /// Modifiers for 'schedule' clause.
1399  enum {FIRST, SECOND, NUM_MODIFIERS};
1400  OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1401 
1402  /// Locations of modifiers.
1403  SourceLocation ModifiersLoc[NUM_MODIFIERS];
1404 
1405  /// Start location of the schedule ind in source code.
1406  SourceLocation KindLoc;
1407 
1408  /// Location of ',' (if any).
1409  SourceLocation CommaLoc;
1410 
1411  /// Chunk size.
1412  Expr *ChunkSize = nullptr;
1413 
1414  /// Set schedule kind.
1415  ///
1416  /// \param K Schedule kind.
1417  void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1418 
1419  /// Set the first schedule modifier.
1420  ///
1421  /// \param M Schedule modifier.
1422  void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1423  Modifiers[FIRST] = M;
1424  }
1425 
1426  /// Set the second schedule modifier.
1427  ///
1428  /// \param M Schedule modifier.
1429  void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1430  Modifiers[SECOND] = M;
1431  }
1432 
1433  /// Set location of the first schedule modifier.
1434  void setFirstScheduleModifierLoc(SourceLocation Loc) {
1435  ModifiersLoc[FIRST] = Loc;
1436  }
1437 
1438  /// Set location of the second schedule modifier.
1439  void setSecondScheduleModifierLoc(SourceLocation Loc) {
1440  ModifiersLoc[SECOND] = Loc;
1441  }
1442 
1443  /// Set schedule modifier location.
1444  ///
1445  /// \param M Schedule modifier location.
1446  void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1447  if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1448  Modifiers[FIRST] = M;
1449  else {
1450  assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1451  Modifiers[SECOND] = M;
1452  }
1453  }
1454 
1455  /// Sets the location of '('.
1456  ///
1457  /// \param Loc Location of '('.
1458  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1459 
1460  /// Set schedule kind start location.
1461  ///
1462  /// \param KLoc Schedule kind location.
1463  void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1464 
1465  /// Set location of ','.
1466  ///
1467  /// \param Loc Location of ','.
1468  void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1469 
1470  /// Set chunk size.
1471  ///
1472  /// \param E Chunk size.
1473  void setChunkSize(Expr *E) { ChunkSize = E; }
1474 
1475 public:
1476  /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1477  /// expression \a ChunkSize.
1478  ///
1479  /// \param StartLoc Starting location of the clause.
1480  /// \param LParenLoc Location of '('.
1481  /// \param KLoc Starting location of the argument.
1482  /// \param CommaLoc Location of ','.
1483  /// \param EndLoc Ending location of the clause.
1484  /// \param Kind Schedule kind.
1485  /// \param ChunkSize Chunk size.
1486  /// \param HelperChunkSize Helper chunk size for combined directives.
1487  /// \param M1 The first modifier applied to 'schedule' clause.
1488  /// \param M1Loc Location of the first modifier
1489  /// \param M2 The second modifier applied to 'schedule' clause.
1490  /// \param M2Loc Location of the second modifier
1492  SourceLocation KLoc, SourceLocation CommaLoc,
1494  Expr *ChunkSize, Stmt *HelperChunkSize,
1497  : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
1498  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
1499  KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
1500  setPreInitStmt(HelperChunkSize);
1501  Modifiers[FIRST] = M1;
1502  Modifiers[SECOND] = M2;
1503  ModifiersLoc[FIRST] = M1Loc;
1504  ModifiersLoc[SECOND] = M2Loc;
1505  }
1506 
1507  /// Build an empty clause.
1509  : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
1510  OMPClauseWithPreInit(this) {
1511  Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1512  Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1513  }
1514 
1515  /// Get kind of the clause.
1517 
1518  /// Get the first modifier of the clause.
1520  return Modifiers[FIRST];
1521  }
1522 
1523  /// Get the second modifier of the clause.
1525  return Modifiers[SECOND];
1526  }
1527 
1528  /// Get location of '('.
1529  SourceLocation getLParenLoc() { return LParenLoc; }
1530 
1531  /// Get kind location.
1532  SourceLocation getScheduleKindLoc() { return KindLoc; }
1533 
1534  /// Get the first modifier location.
1536  return ModifiersLoc[FIRST];
1537  }
1538 
1539  /// Get the second modifier location.
1541  return ModifiersLoc[SECOND];
1542  }
1543 
1544  /// Get location of ','.
1545  SourceLocation getCommaLoc() { return CommaLoc; }
1546 
1547  /// Get chunk size.
1548  Expr *getChunkSize() { return ChunkSize; }
1549 
1550  /// Get chunk size.
1551  const Expr *getChunkSize() const { return ChunkSize; }
1552 
1554  return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1555  reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1556  }
1557 
1559  auto Children = const_cast<OMPScheduleClause *>(this)->children();
1560  return const_child_range(Children.begin(), Children.end());
1561  }
1562 
1565  }
1568  }
1569 
1570  static bool classof(const OMPClause *T) {
1571  return T->getClauseKind() == llvm::omp::OMPC_schedule;
1572  }
1573 };
1574 
1575 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1576 ///
1577 /// \code
1578 /// #pragma omp for ordered (2)
1579 /// \endcode
1580 /// In this example directive '#pragma omp for' has 'ordered' clause with
1581 /// parameter 2.
1582 class OMPOrderedClause final
1583  : public OMPClause,
1584  private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1585  friend class OMPClauseReader;
1586  friend TrailingObjects;
1587 
1588  /// Location of '('.
1589  SourceLocation LParenLoc;
1590 
1591  /// Number of for-loops.
1592  Stmt *NumForLoops = nullptr;
1593 
1594  /// Real number of loops.
1595  unsigned NumberOfLoops = 0;
1596 
1597  /// Build 'ordered' clause.
1598  ///
1599  /// \param Num Expression, possibly associated with this clause.
1600  /// \param NumLoops Number of loops, associated with this clause.
1601  /// \param StartLoc Starting location of the clause.
1602  /// \param LParenLoc Location of '('.
1603  /// \param EndLoc Ending location of the clause.
1604  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1605  SourceLocation LParenLoc, SourceLocation EndLoc)
1606  : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
1607  LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
1608 
1609  /// Build an empty clause.
1610  explicit OMPOrderedClause(unsigned NumLoops)
1611  : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
1612  NumberOfLoops(NumLoops) {}
1613 
1614  /// Set the number of associated for-loops.
1615  void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1616 
1617 public:
1618  /// Build 'ordered' clause.
1619  ///
1620  /// \param Num Expression, possibly associated with this clause.
1621  /// \param NumLoops Number of loops, associated with this clause.
1622  /// \param StartLoc Starting location of the clause.
1623  /// \param LParenLoc Location of '('.
1624  /// \param EndLoc Ending location of the clause.
1625  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1626  unsigned NumLoops, SourceLocation StartLoc,
1627  SourceLocation LParenLoc,
1628  SourceLocation EndLoc);
1629 
1630  /// Build an empty clause.
1631  static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1632 
1633  /// Sets the location of '('.
1634  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1635 
1636  /// Returns the location of '('.
1637  SourceLocation getLParenLoc() const { return LParenLoc; }
1638 
1639  /// Return the number of associated for-loops.
1640  Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1641 
1642  /// Set number of iterations for the specified loop.
1643  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1644  /// Get number of iterations for all the loops.
1646 
1647  /// Set loop counter for the specified loop.
1648  void setLoopCounter(unsigned NumLoop, Expr *Counter);
1649  /// Get loops counter for the specified loop.
1650  Expr *getLoopCounter(unsigned NumLoop);
1651  const Expr *getLoopCounter(unsigned NumLoop) const;
1652 
1653  child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1654 
1656  return const_child_range(&NumForLoops, &NumForLoops + 1);
1657  }
1658 
1661  }
1664  }
1665 
1666  static bool classof(const OMPClause *T) {
1667  return T->getClauseKind() == llvm::omp::OMPC_ordered;
1668  }
1669 };
1670 
1671 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1672 ///
1673 /// \code
1674 /// #pragma omp for nowait
1675 /// \endcode
1676 /// In this example directive '#pragma omp for' has 'nowait' clause.
1677 class OMPNowaitClause : public OMPClause {
1678 public:
1679  /// Build 'nowait' clause.
1680  ///
1681  /// \param StartLoc Starting location of the clause.
1682  /// \param EndLoc Ending location of the clause.
1684  : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc) {}
1685 
1686  /// Build an empty clause.
1688  : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {}
1689 
1692  }
1693 
1696  }
1697 
1700  }
1703  }
1704 
1705  static bool classof(const OMPClause *T) {
1706  return T->getClauseKind() == llvm::omp::OMPC_nowait;
1707  }
1708 };
1709 
1710 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1711 ///
1712 /// \code
1713 /// #pragma omp task untied
1714 /// \endcode
1715 /// In this example directive '#pragma omp task' has 'untied' clause.
1716 class OMPUntiedClause : public OMPClause {
1717 public:
1718  /// Build 'untied' clause.
1719  ///
1720  /// \param StartLoc Starting location of the clause.
1721  /// \param EndLoc Ending location of the clause.
1723  : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
1724 
1725  /// Build an empty clause.
1727  : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
1728 
1731  }
1732 
1735  }
1736 
1739  }
1742  }
1743 
1744  static bool classof(const OMPClause *T) {
1745  return T->getClauseKind() == llvm::omp::OMPC_untied;
1746  }
1747 };
1748 
1749 /// This represents 'mergeable' clause in the '#pragma omp ...'
1750 /// directive.
1751 ///
1752 /// \code
1753 /// #pragma omp task mergeable
1754 /// \endcode
1755 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1757 public:
1758  /// Build 'mergeable' clause.
1759  ///
1760  /// \param StartLoc Starting location of the clause.
1761  /// \param EndLoc Ending location of the clause.
1763  : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
1764 
1765  /// Build an empty clause.
1767  : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
1768  SourceLocation()) {}
1769 
1772  }
1773 
1776  }
1777 
1780  }
1783  }
1784 
1785  static bool classof(const OMPClause *T) {
1786  return T->getClauseKind() == llvm::omp::OMPC_mergeable;
1787  }
1788 };
1789 
1790 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1791 ///
1792 /// \code
1793 /// #pragma omp atomic read
1794 /// \endcode
1795 /// In this example directive '#pragma omp atomic' has 'read' clause.
1796 class OMPReadClause : public OMPClause {
1797 public:
1798  /// Build 'read' clause.
1799  ///
1800  /// \param StartLoc Starting location of the clause.
1801  /// \param EndLoc Ending location of the clause.
1803  : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
1804 
1805  /// Build an empty clause.
1807  : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
1808 
1811  }
1812 
1815  }
1816 
1819  }
1822  }
1823 
1824  static bool classof(const OMPClause *T) {
1825  return T->getClauseKind() == llvm::omp::OMPC_read;
1826  }
1827 };
1828 
1829 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1830 ///
1831 /// \code
1832 /// #pragma omp atomic write
1833 /// \endcode
1834 /// In this example directive '#pragma omp atomic' has 'write' clause.
1835 class OMPWriteClause : public OMPClause {
1836 public:
1837  /// Build 'write' clause.
1838  ///
1839  /// \param StartLoc Starting location of the clause.
1840  /// \param EndLoc Ending location of the clause.
1842  : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
1843 
1844  /// Build an empty clause.
1846  : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
1847 
1850  }
1851 
1854  }
1855 
1858  }
1861  }
1862 
1863  static bool classof(const OMPClause *T) {
1864  return T->getClauseKind() == llvm::omp::OMPC_write;
1865  }
1866 };
1867 
1868 /// This represents 'update' clause in the '#pragma omp atomic'
1869 /// directive.
1870 ///
1871 /// \code
1872 /// #pragma omp atomic update
1873 /// \endcode
1874 /// In this example directive '#pragma omp atomic' has 'update' clause.
1875 /// Also, this class represents 'update' clause in '#pragma omp depobj'
1876 /// directive.
1877 ///
1878 /// \code
1879 /// #pragma omp depobj(a) update(in)
1880 /// \endcode
1881 /// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
1882 /// dependence kind.
1883 class OMPUpdateClause final
1884  : public OMPClause,
1885  private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
1886  OpenMPDependClauseKind> {
1887  friend class OMPClauseReader;
1888  friend TrailingObjects;
1889 
1890  /// true if extended version of the clause for 'depobj' directive.
1891  bool IsExtended = false;
1892 
1893  /// Define the sizes of each trailing object array except the last one. This
1894  /// is required for TrailingObjects to work properly.
1895  size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
1896  // 2 locations: for '(' and argument location.
1897  return IsExtended ? 2 : 0;
1898  }
1899 
1900  /// Sets the the location of '(' in clause for 'depobj' directive.
1901  void setLParenLoc(SourceLocation Loc) {
1902  assert(IsExtended && "Expected extended clause.");
1903  *getTrailingObjects<SourceLocation>() = Loc;
1904  }
1905 
1906  /// Sets the the location of '(' in clause for 'depobj' directive.
1907  void setArgumentLoc(SourceLocation Loc) {
1908  assert(IsExtended && "Expected extended clause.");
1909  *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
1910  }
1911 
1912  /// Sets the dependence kind for the clause for 'depobj' directive.
1913  void setDependencyKind(OpenMPDependClauseKind DK) {
1914  assert(IsExtended && "Expected extended clause.");
1915  *getTrailingObjects<OpenMPDependClauseKind>() = DK;
1916  }
1917 
1918  /// Build 'update' clause.
1919  ///
1920  /// \param StartLoc Starting location of the clause.
1921  /// \param EndLoc Ending location of the clause.
1922  OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
1923  bool IsExtended)
1924  : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
1925  IsExtended(IsExtended) {}
1926 
1927  /// Build an empty clause.
1928  OMPUpdateClause(bool IsExtended)
1929  : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
1930  IsExtended(IsExtended) {}
1931 
1932 public:
1933  /// Creates clause for 'atomic' directive.
1934  ///
1935  /// \param C AST context.
1936  /// \param StartLoc Starting location of the clause.
1937  /// \param EndLoc Ending location of the clause.
1938  static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1939  SourceLocation EndLoc);
1940 
1941  /// Creates clause for 'depobj' directive.
1942  ///
1943  /// \param C AST context.
1944  /// \param StartLoc Starting location of the clause.
1945  /// \param LParenLoc Location of '('.
1946  /// \param ArgumentLoc Location of the argument.
1947  /// \param DK Dependence kind.
1948  /// \param EndLoc Ending location of the clause.
1949  static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1950  SourceLocation LParenLoc,
1951  SourceLocation ArgumentLoc,
1953  SourceLocation EndLoc);
1954 
1955  /// Creates an empty clause with the place for \a N variables.
1956  ///
1957  /// \param C AST context.
1958  /// \param IsExtended true if extended clause for 'depobj' directive must be
1959  /// created.
1960  static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
1961 
1962  /// Checks if the clause is the extended clauses for 'depobj' directive.
1963  bool isExtended() const { return IsExtended; }
1964 
1967  }
1968 
1971  }
1972 
1975  }
1978  }
1979 
1980  /// Gets the the location of '(' in clause for 'depobj' directive.
1982  assert(IsExtended && "Expected extended clause.");
1983  return *getTrailingObjects<SourceLocation>();
1984  }
1985 
1986  /// Gets the the location of argument in clause for 'depobj' directive.
1988  assert(IsExtended && "Expected extended clause.");
1989  return *std::next(getTrailingObjects<SourceLocation>(), 1);
1990  }
1991 
1992  /// Gets the dependence kind in clause for 'depobj' directive.
1994  assert(IsExtended && "Expected extended clause.");
1995  return *getTrailingObjects<OpenMPDependClauseKind>();
1996  }
1997 
1998  static bool classof(const OMPClause *T) {
1999  return T->getClauseKind() == llvm::omp::OMPC_update;
2000  }
2001 };
2002 
2003 /// This represents 'capture' clause in the '#pragma omp atomic'
2004 /// directive.
2005 ///
2006 /// \code
2007 /// #pragma omp atomic capture
2008 /// \endcode
2009 /// In this example directive '#pragma omp atomic' has 'capture' clause.
2010 class OMPCaptureClause : public OMPClause {
2011 public:
2012  /// Build 'capture' clause.
2013  ///
2014  /// \param StartLoc Starting location of the clause.
2015  /// \param EndLoc Ending location of the clause.
2017  : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
2018 
2019  /// Build an empty clause.
2021  : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
2022  }
2023 
2026  }
2027 
2030  }
2031 
2034  }
2037  }
2038 
2039  static bool classof(const OMPClause *T) {
2040  return T->getClauseKind() == llvm::omp::OMPC_capture;
2041  }
2042 };
2043 
2044 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
2045 /// directive.
2046 ///
2047 /// \code
2048 /// #pragma omp atomic seq_cst
2049 /// \endcode
2050 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
2051 class OMPSeqCstClause : public OMPClause {
2052 public:
2053  /// Build 'seq_cst' clause.
2054  ///
2055  /// \param StartLoc Starting location of the clause.
2056  /// \param EndLoc Ending location of the clause.
2058  : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
2059 
2060  /// Build an empty clause.
2062  : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
2063  }
2064 
2067  }
2068 
2071  }
2072 
2075  }
2078  }
2079 
2080  static bool classof(const OMPClause *T) {
2081  return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
2082  }
2083 };
2084 
2085 /// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
2086 /// directives.
2087 ///
2088 /// \code
2089 /// #pragma omp flush acq_rel
2090 /// \endcode
2091 /// In this example directive '#pragma omp flush' has 'acq_rel' clause.
2092 class OMPAcqRelClause final : public OMPClause {
2093 public:
2094  /// Build 'ack_rel' clause.
2095  ///
2096  /// \param StartLoc Starting location of the clause.
2097  /// \param EndLoc Ending location of the clause.
2099  : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
2100 
2101  /// Build an empty clause.
2103  : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
2104  }
2105 
2108  }
2109 
2112  }
2113 
2116  }
2119  }
2120 
2121  static bool classof(const OMPClause *T) {
2122  return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
2123  }
2124 };
2125 
2126 /// This represents 'acquire' clause in the '#pragma omp atomic|flush'
2127 /// directives.
2128 ///
2129 /// \code
2130 /// #pragma omp flush acquire
2131 /// \endcode
2132 /// In this example directive '#pragma omp flush' has 'acquire' clause.
2133 class OMPAcquireClause final : public OMPClause {
2134 public:
2135  /// Build 'acquire' clause.
2136  ///
2137  /// \param StartLoc Starting location of the clause.
2138  /// \param EndLoc Ending location of the clause.
2140  : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
2141 
2142  /// Build an empty clause.
2144  : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
2145  }
2146 
2149  }
2150 
2153  }
2154 
2157  }
2160  }
2161 
2162  static bool classof(const OMPClause *T) {
2163  return T->getClauseKind() == llvm::omp::OMPC_acquire;
2164  }
2165 };
2166 
2167 /// This represents 'release' clause in the '#pragma omp atomic|flush'
2168 /// directives.
2169 ///
2170 /// \code
2171 /// #pragma omp flush release
2172 /// \endcode
2173 /// In this example directive '#pragma omp flush' has 'release' clause.
2174 class OMPReleaseClause final : public OMPClause {
2175 public:
2176  /// Build 'release' clause.
2177  ///
2178  /// \param StartLoc Starting location of the clause.
2179  /// \param EndLoc Ending location of the clause.
2181  : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
2182 
2183  /// Build an empty clause.
2185  : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
2186  }
2187 
2190  }
2191 
2194  }
2195 
2198  }
2201  }
2202 
2203  static bool classof(const OMPClause *T) {
2204  return T->getClauseKind() == llvm::omp::OMPC_release;
2205  }
2206 };
2207 
2208 /// This represents 'relaxed' clause in the '#pragma omp atomic'
2209 /// directives.
2210 ///
2211 /// \code
2212 /// #pragma omp atomic relaxed
2213 /// \endcode
2214 /// In this example directive '#pragma omp atomic' has 'relaxed' clause.
2215 class OMPRelaxedClause final : public OMPClause {
2216 public:
2217  /// Build 'relaxed' clause.
2218  ///
2219  /// \param StartLoc Starting location of the clause.
2220  /// \param EndLoc Ending location of the clause.
2222  : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
2223 
2224  /// Build an empty clause.
2226  : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
2227  }
2228 
2231  }
2232 
2235  }
2236 
2239  }
2242  }
2243 
2244  static bool classof(const OMPClause *T) {
2245  return T->getClauseKind() == llvm::omp::OMPC_relaxed;
2246  }
2247 };
2248 
2249 /// This represents clause 'private' in the '#pragma omp ...' directives.
2250 ///
2251 /// \code
2252 /// #pragma omp parallel private(a,b)
2253 /// \endcode
2254 /// In this example directive '#pragma omp parallel' has clause 'private'
2255 /// with the variables 'a' and 'b'.
2256 class OMPPrivateClause final
2257  : public OMPVarListClause<OMPPrivateClause>,
2258  private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2259  friend class OMPClauseReader;
2260  friend OMPVarListClause;
2261  friend TrailingObjects;
2262 
2263  /// Build clause with number of variables \a N.
2264  ///
2265  /// \param StartLoc Starting location of the clause.
2266  /// \param LParenLoc Location of '('.
2267  /// \param EndLoc Ending location of the clause.
2268  /// \param N Number of the variables in the clause.
2269  OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2270  SourceLocation EndLoc, unsigned N)
2271  : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
2272  LParenLoc, EndLoc, N) {}
2273 
2274  /// Build an empty clause.
2275  ///
2276  /// \param N Number of variables.
2277  explicit OMPPrivateClause(unsigned N)
2278  : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
2280  SourceLocation(), N) {}
2281 
2282  /// Sets the list of references to private copies with initializers for
2283  /// new private variables.
2284  /// \param VL List of references.
2285  void setPrivateCopies(ArrayRef<Expr *> VL);
2286 
2287  /// Gets the list of references to private copies with initializers for
2288  /// new private variables.
2289  MutableArrayRef<Expr *> getPrivateCopies() {
2290  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2291  }
2292  ArrayRef<const Expr *> getPrivateCopies() const {
2293  return llvm::makeArrayRef(varlist_end(), varlist_size());
2294  }
2295 
2296 public:
2297  /// Creates clause with a list of variables \a VL.
2298  ///
2299  /// \param C AST context.
2300  /// \param StartLoc Starting location of the clause.
2301  /// \param LParenLoc Location of '('.
2302  /// \param EndLoc Ending location of the clause.
2303  /// \param VL List of references to the variables.
2304  /// \param PrivateVL List of references to private copies with initializers.
2305  static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2306  SourceLocation LParenLoc,
2307  SourceLocation EndLoc, ArrayRef<Expr *> VL,
2308  ArrayRef<Expr *> PrivateVL);
2309 
2310  /// Creates an empty clause with the place for \a N variables.
2311  ///
2312  /// \param C AST context.
2313  /// \param N The number of variables.
2314  static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2315 
2318  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2320  llvm::iterator_range<private_copies_const_iterator>;
2321 
2323  return private_copies_range(getPrivateCopies().begin(),
2324  getPrivateCopies().end());
2325  }
2326 
2328  return private_copies_const_range(getPrivateCopies().begin(),
2329  getPrivateCopies().end());
2330  }
2331 
2333  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2334  reinterpret_cast<Stmt **>(varlist_end()));
2335  }
2336 
2338  auto Children = const_cast<OMPPrivateClause *>(this)->children();
2339  return const_child_range(Children.begin(), Children.end());
2340  }
2341 
2344  }
2347  }
2348 
2349  static bool classof(const OMPClause *T) {
2350  return T->getClauseKind() == llvm::omp::OMPC_private;
2351  }
2352 };
2353 
2354 /// This represents clause 'firstprivate' in the '#pragma omp ...'
2355 /// directives.
2356 ///
2357 /// \code
2358 /// #pragma omp parallel firstprivate(a,b)
2359 /// \endcode
2360 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2361 /// with the variables 'a' and 'b'.
2363  : public OMPVarListClause<OMPFirstprivateClause>,
2364  public OMPClauseWithPreInit,
2365  private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2366  friend class OMPClauseReader;
2367  friend OMPVarListClause;
2368  friend TrailingObjects;
2369 
2370  /// Build clause with number of variables \a N.
2371  ///
2372  /// \param StartLoc Starting location of the clause.
2373  /// \param LParenLoc Location of '('.
2374  /// \param EndLoc Ending location of the clause.
2375  /// \param N Number of the variables in the clause.
2377  SourceLocation EndLoc, unsigned N)
2378  : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
2379  StartLoc, LParenLoc, EndLoc, N),
2380  OMPClauseWithPreInit(this) {}
2381 
2382  /// Build an empty clause.
2383  ///
2384  /// \param N Number of variables.
2385  explicit OMPFirstprivateClause(unsigned N)
2387  llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
2388  SourceLocation(), N),
2389  OMPClauseWithPreInit(this) {}
2390 
2391  /// Sets the list of references to private copies with initializers for
2392  /// new private variables.
2393  /// \param VL List of references.
2394  void setPrivateCopies(ArrayRef<Expr *> VL);
2395 
2396  /// Gets the list of references to private copies with initializers for
2397  /// new private variables.
2398  MutableArrayRef<Expr *> getPrivateCopies() {
2399  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2400  }
2401  ArrayRef<const Expr *> getPrivateCopies() const {
2402  return llvm::makeArrayRef(varlist_end(), varlist_size());
2403  }
2404 
2405  /// Sets the list of references to initializer variables for new
2406  /// private variables.
2407  /// \param VL List of references.
2408  void setInits(ArrayRef<Expr *> VL);
2409 
2410  /// Gets the list of references to initializer variables for new
2411  /// private variables.
2412  MutableArrayRef<Expr *> getInits() {
2413  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2414  }
2415  ArrayRef<const Expr *> getInits() const {
2416  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2417  }
2418 
2419 public:
2420  /// Creates clause with a list of variables \a VL.
2421  ///
2422  /// \param C AST context.
2423  /// \param StartLoc Starting location of the clause.
2424  /// \param LParenLoc Location of '('.
2425  /// \param EndLoc Ending location of the clause.
2426  /// \param VL List of references to the original variables.
2427  /// \param PrivateVL List of references to private copies with initializers.
2428  /// \param InitVL List of references to auto generated variables used for
2429  /// initialization of a single array element. Used if firstprivate variable is
2430  /// of array type.
2431  /// \param PreInit Statement that must be executed before entering the OpenMP
2432  /// region with this clause.
2433  static OMPFirstprivateClause *
2434  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2435  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2436  ArrayRef<Expr *> InitVL, Stmt *PreInit);
2437 
2438  /// Creates an empty clause with the place for \a N variables.
2439  ///
2440  /// \param C AST context.
2441  /// \param N The number of variables.
2442  static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2443 
2446  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2448  llvm::iterator_range<private_copies_const_iterator>;
2449 
2451  return private_copies_range(getPrivateCopies().begin(),
2452  getPrivateCopies().end());
2453  }
2455  return private_copies_const_range(getPrivateCopies().begin(),
2456  getPrivateCopies().end());
2457  }
2458 
2461  using inits_range = llvm::iterator_range<inits_iterator>;
2462  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2463 
2465  return inits_range(getInits().begin(), getInits().end());
2466  }
2468  return inits_const_range(getInits().begin(), getInits().end());
2469  }
2470 
2472  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2473  reinterpret_cast<Stmt **>(varlist_end()));
2474  }
2475 
2477  auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2478  return const_child_range(Children.begin(), Children.end());
2479  }
2480 
2482  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2483  reinterpret_cast<Stmt **>(varlist_end()));
2484  }
2486  auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2487  return const_child_range(Children.begin(), Children.end());
2488  }
2489 
2490  static bool classof(const OMPClause *T) {
2491  return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
2492  }
2493 };
2494 
2495 /// This represents clause 'lastprivate' in the '#pragma omp ...'
2496 /// directives.
2497 ///
2498 /// \code
2499 /// #pragma omp simd lastprivate(a,b)
2500 /// \endcode
2501 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
2502 /// with the variables 'a' and 'b'.
2504  : public OMPVarListClause<OMPLastprivateClause>,
2505  public OMPClauseWithPostUpdate,
2506  private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2507  // There are 4 additional tail-allocated arrays at the end of the class:
2508  // 1. Contains list of pseudo variables with the default initialization for
2509  // each non-firstprivate variables. Used in codegen for initialization of
2510  // lastprivate copies.
2511  // 2. List of helper expressions for proper generation of assignment operation
2512  // required for lastprivate clause. This list represents private variables
2513  // (for arrays, single array element).
2514  // 3. List of helper expressions for proper generation of assignment operation
2515  // required for lastprivate clause. This list represents original variables
2516  // (for arrays, single array element).
2517  // 4. List of helper expressions that represents assignment operation:
2518  // \code
2519  // DstExprs = SrcExprs;
2520  // \endcode
2521  // Required for proper codegen of final assignment performed by the
2522  // lastprivate clause.
2523  friend class OMPClauseReader;
2524  friend OMPVarListClause;
2525  friend TrailingObjects;
2526 
2527  /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2529  /// Optional location of the lasptrivate kind, if specified by user.
2530  SourceLocation LPKindLoc;
2531  /// Optional colon location, if specified by user.
2532  SourceLocation ColonLoc;
2533 
2534  /// Build clause with number of variables \a N.
2535  ///
2536  /// \param StartLoc Starting location of the clause.
2537  /// \param LParenLoc Location of '('.
2538  /// \param EndLoc Ending location of the clause.
2539  /// \param N Number of the variables in the clause.
2542  SourceLocation LPKindLoc, SourceLocation ColonLoc,
2543  unsigned N)
2544  : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
2545  StartLoc, LParenLoc, EndLoc, N),
2546  OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2547  ColonLoc(ColonLoc) {}
2548 
2549  /// Build an empty clause.
2550  ///
2551  /// \param N Number of variables.
2552  explicit OMPLastprivateClause(unsigned N)
2554  llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
2555  SourceLocation(), N),
2556  OMPClauseWithPostUpdate(this) {}
2557 
2558  /// Get the list of helper expressions for initialization of private
2559  /// copies for lastprivate variables.
2560  MutableArrayRef<Expr *> getPrivateCopies() {
2561  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2562  }
2563  ArrayRef<const Expr *> getPrivateCopies() const {
2564  return llvm::makeArrayRef(varlist_end(), varlist_size());
2565  }
2566 
2567  /// Set list of helper expressions, required for proper codegen of the
2568  /// clause. These expressions represent private variables (for arrays, single
2569  /// array element) in the final assignment statement performed by the
2570  /// lastprivate clause.
2571  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2572 
2573  /// Get the list of helper source expressions.
2574  MutableArrayRef<Expr *> getSourceExprs() {
2575  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2576  }
2577  ArrayRef<const Expr *> getSourceExprs() const {
2578  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2579  }
2580 
2581  /// Set list of helper expressions, required for proper codegen of the
2582  /// clause. These expressions represent original variables (for arrays, single
2583  /// array element) in the final assignment statement performed by the
2584  /// lastprivate clause.
2585  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2586 
2587  /// Get the list of helper destination expressions.
2588  MutableArrayRef<Expr *> getDestinationExprs() {
2589  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2590  }
2591  ArrayRef<const Expr *> getDestinationExprs() const {
2592  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2593  }
2594 
2595  /// Set list of helper assignment expressions, required for proper
2596  /// codegen of the clause. These expressions are assignment expressions that
2597  /// assign private copy of the variable to original variable.
2598  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2599 
2600  /// Get the list of helper assignment expressions.
2601  MutableArrayRef<Expr *> getAssignmentOps() {
2602  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2603  }
2604  ArrayRef<const Expr *> getAssignmentOps() const {
2605  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2606  }
2607 
2608  /// Sets lastprivate kind.
2609  void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
2610  /// Sets location of the lastprivate kind.
2611  void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
2612  /// Sets colon symbol location.
2613  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2614 
2615 public:
2616  /// Creates clause with a list of variables \a VL.
2617  ///
2618  /// \param C AST context.
2619  /// \param StartLoc Starting location of the clause.
2620  /// \param LParenLoc Location of '('.
2621  /// \param EndLoc Ending location of the clause.
2622  /// \param VL List of references to the variables.
2623  /// \param SrcExprs List of helper expressions for proper generation of
2624  /// assignment operation required for lastprivate clause. This list represents
2625  /// private variables (for arrays, single array element).
2626  /// \param DstExprs List of helper expressions for proper generation of
2627  /// assignment operation required for lastprivate clause. This list represents
2628  /// original variables (for arrays, single array element).
2629  /// \param AssignmentOps List of helper expressions that represents assignment
2630  /// operation:
2631  /// \code
2632  /// DstExprs = SrcExprs;
2633  /// \endcode
2634  /// Required for proper codegen of final assignment performed by the
2635  /// lastprivate clause.
2636  /// \param LPKind Lastprivate kind, e.g. 'conditional'.
2637  /// \param LPKindLoc Location of the lastprivate kind.
2638  /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
2639  /// \param PreInit Statement that must be executed before entering the OpenMP
2640  /// region with this clause.
2641  /// \param PostUpdate Expression that must be executed after exit from the
2642  /// OpenMP region with this clause.
2643  static OMPLastprivateClause *
2644  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2645  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2646  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2647  OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
2648  SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
2649 
2650  /// Creates an empty clause with the place for \a N variables.
2651  ///
2652  /// \param C AST context.
2653  /// \param N The number of variables.
2654  static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2655 
2656  /// Lastprivate kind.
2657  OpenMPLastprivateModifier getKind() const { return LPKind; }
2658  /// Returns the location of the lastprivate kind.
2659  SourceLocation getKindLoc() const { return LPKindLoc; }
2660  /// Returns the location of the ':' symbol, if any.
2661  SourceLocation getColonLoc() const { return ColonLoc; }
2662 
2665  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2666  using helper_expr_const_range =
2667  llvm::iterator_range<helper_expr_const_iterator>;
2668 
2669  /// Set list of helper expressions, required for generation of private
2670  /// copies of original lastprivate variables.
2671  void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2672 
2674  return helper_expr_const_range(getPrivateCopies().begin(),
2675  getPrivateCopies().end());
2676  }
2677 
2679  return helper_expr_range(getPrivateCopies().begin(),
2680  getPrivateCopies().end());
2681  }
2682 
2684  return helper_expr_const_range(getSourceExprs().begin(),
2685  getSourceExprs().end());
2686  }
2687 
2689  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2690  }
2691 
2693  return helper_expr_const_range(getDestinationExprs().begin(),
2694  getDestinationExprs().end());
2695  }
2696 
2698  return helper_expr_range(getDestinationExprs().begin(),
2699  getDestinationExprs().end());
2700  }
2701 
2703  return helper_expr_const_range(getAssignmentOps().begin(),
2704  getAssignmentOps().end());
2705  }
2706 
2708  return helper_expr_range(getAssignmentOps().begin(),
2709  getAssignmentOps().end());
2710  }
2711 
2713  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2714  reinterpret_cast<Stmt **>(varlist_end()));
2715  }
2716 
2718  auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2719  return const_child_range(Children.begin(), Children.end());
2720  }
2721 
2724  }
2727  }
2728 
2729  static bool classof(const OMPClause *T) {
2730  return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
2731  }
2732 };
2733 
2734 /// This represents clause 'shared' in the '#pragma omp ...' directives.
2735 ///
2736 /// \code
2737 /// #pragma omp parallel shared(a,b)
2738 /// \endcode
2739 /// In this example directive '#pragma omp parallel' has clause 'shared'
2740 /// with the variables 'a' and 'b'.
2741 class OMPSharedClause final
2742  : public OMPVarListClause<OMPSharedClause>,
2743  private llvm::TrailingObjects<OMPSharedClause, Expr *> {
2744  friend OMPVarListClause;
2745  friend TrailingObjects;
2746 
2747  /// Build clause with number of variables \a N.
2748  ///
2749  /// \param StartLoc Starting location of the clause.
2750  /// \param LParenLoc Location of '('.
2751  /// \param EndLoc Ending location of the clause.
2752  /// \param N Number of the variables in the clause.
2753  OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2754  SourceLocation EndLoc, unsigned N)
2755  : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
2756  LParenLoc, EndLoc, N) {}
2757 
2758  /// Build an empty clause.
2759  ///
2760  /// \param N Number of variables.
2761  explicit OMPSharedClause(unsigned N)
2762  : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
2764  SourceLocation(), N) {}
2765 
2766 public:
2767  /// Creates clause with a list of variables \a VL.
2768  ///
2769  /// \param C AST context.
2770  /// \param StartLoc Starting location of the clause.
2771  /// \param LParenLoc Location of '('.
2772  /// \param EndLoc Ending location of the clause.
2773  /// \param VL List of references to the variables.
2774  static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2775  SourceLocation LParenLoc,
2776  SourceLocation EndLoc, ArrayRef<Expr *> VL);
2777 
2778  /// Creates an empty clause with \a N variables.
2779  ///
2780  /// \param C AST context.
2781  /// \param N The number of variables.
2782  static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
2783 
2785  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2786  reinterpret_cast<Stmt **>(varlist_end()));
2787  }
2788 
2790  auto Children = const_cast<OMPSharedClause *>(this)->children();
2791  return const_child_range(Children.begin(), Children.end());
2792  }
2793 
2796  }
2799  }
2800 
2801  static bool classof(const OMPClause *T) {
2802  return T->getClauseKind() == llvm::omp::OMPC_shared;
2803  }
2804 };
2805 
2806 /// This represents clause 'reduction' in the '#pragma omp ...'
2807 /// directives.
2808 ///
2809 /// \code
2810 /// #pragma omp parallel reduction(+:a,b)
2811 /// \endcode
2812 /// In this example directive '#pragma omp parallel' has clause 'reduction'
2813 /// with operator '+' and the variables 'a' and 'b'.
2815  : public OMPVarListClause<OMPReductionClause>,
2816  public OMPClauseWithPostUpdate,
2817  private llvm::TrailingObjects<OMPReductionClause, Expr *> {
2818  friend class OMPClauseReader;
2819  friend OMPVarListClause;
2820  friend TrailingObjects;
2821 
2822  /// Reduction modifier.
2824 
2825  /// Reduction modifier location.
2826  SourceLocation ModifierLoc;
2827 
2828  /// Location of ':'.
2829  SourceLocation ColonLoc;
2830 
2831  /// Nested name specifier for C++.
2832  NestedNameSpecifierLoc QualifierLoc;
2833 
2834  /// Name of custom operator.
2835  DeclarationNameInfo NameInfo;
2836 
2837  /// Build clause with number of variables \a N.
2838  ///
2839  /// \param StartLoc Starting location of the clause.
2840  /// \param LParenLoc Location of '('.
2841  /// \param ModifierLoc Modifier location.
2842  /// \param ColonLoc Location of ':'.
2843  /// \param EndLoc Ending location of the clause.
2844  /// \param N Number of the variables in the clause.
2845  /// \param QualifierLoc The nested-name qualifier with location information
2846  /// \param NameInfo The full name info for reduction identifier.
2847  OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2848  SourceLocation ModifierLoc, SourceLocation ColonLoc,
2849  SourceLocation EndLoc,
2850  OpenMPReductionClauseModifier Modifier, unsigned N,
2851  NestedNameSpecifierLoc QualifierLoc,
2852  const DeclarationNameInfo &NameInfo)
2853  : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
2854  StartLoc, LParenLoc, EndLoc, N),
2855  OMPClauseWithPostUpdate(this), Modifier(Modifier),
2856  ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
2857  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2858 
2859  /// Build an empty clause.
2860  ///
2861  /// \param N Number of variables.
2862  explicit OMPReductionClause(unsigned N)
2863  : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
2865  SourceLocation(), N),
2866  OMPClauseWithPostUpdate(this) {}
2867 
2868  /// Sets reduction modifier.
2869  void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
2870 
2871  /// Sets location of the modifier.
2872  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
2873 
2874  /// Sets location of ':' symbol in clause.
2875  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2876 
2877  /// Sets the name info for specified reduction identifier.
2878  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2879 
2880  /// Sets the nested name specifier.
2881  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2882 
2883  /// Set list of helper expressions, required for proper codegen of the
2884  /// clause. These expressions represent private copy of the reduction
2885  /// variable.
2886  void setPrivates(ArrayRef<Expr *> Privates);
2887 
2888  /// Get the list of helper privates.
2889  MutableArrayRef<Expr *> getPrivates() {
2890  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2891  }
2892  ArrayRef<const Expr *> getPrivates() const {
2893  return llvm::makeArrayRef(varlist_end(), varlist_size());
2894  }
2895 
2896  /// Set list of helper expressions, required for proper codegen of the
2897  /// clause. These expressions represent LHS expression in the final
2898  /// reduction expression performed by the reduction clause.
2899  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2900 
2901  /// Get the list of helper LHS expressions.
2902  MutableArrayRef<Expr *> getLHSExprs() {
2903  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2904  }
2905  ArrayRef<const Expr *> getLHSExprs() const {
2906  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2907  }
2908 
2909  /// Set list of helper expressions, required for proper codegen of the
2910  /// clause. These expressions represent RHS expression in the final
2911  /// reduction expression performed by the reduction clause.
2912  /// Also, variables in these expressions are used for proper initialization of
2913  /// reduction copies.
2914  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2915 
2916  /// Get the list of helper destination expressions.
2917  MutableArrayRef<Expr *> getRHSExprs() {
2918  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2919  }
2920  ArrayRef<const Expr *> getRHSExprs() const {
2921  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2922  }
2923 
2924  /// Set list of helper reduction expressions, required for proper
2925  /// codegen of the clause. These expressions are binary expressions or
2926  /// operator/custom reduction call that calculates new value from source
2927  /// helper expressions to destination helper expressions.
2928  void setReductionOps(ArrayRef<Expr *> ReductionOps);
2929 
2930  /// Get the list of helper reduction expressions.
2931  MutableArrayRef<Expr *> getReductionOps() {
2932  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2933  }
2934  ArrayRef<const Expr *> getReductionOps() const {
2935  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2936  }
2937 
2938  /// Set list of helper copy operations for inscan reductions.
2939  /// The form is: Temps[i] = LHS[i];
2940  void setInscanCopyOps(ArrayRef<Expr *> Ops);
2941 
2942  /// Get the list of helper inscan copy operations.
2943  MutableArrayRef<Expr *> getInscanCopyOps() {
2944  return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
2945  }
2946  ArrayRef<const Expr *> getInscanCopyOps() const {
2947  return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
2948  }
2949 
2950  /// Set list of helper temp vars for inscan copy array operations.
2951  void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
2952 
2953  /// Get the list of helper inscan copy temps.
2954  MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
2955  return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
2956  }
2957  ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
2958  return llvm::makeArrayRef(getInscanCopyOps().end(), varlist_size());
2959  }
2960 
2961  /// Set list of helper temp elements vars for inscan copy array operations.
2962  void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
2963 
2964  /// Get the list of helper inscan copy temps.
2965  MutableArrayRef<Expr *> getInscanCopyArrayElems() {
2966  return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
2967  varlist_size());
2968  }
2969  ArrayRef<const Expr *> getInscanCopyArrayElems() const {
2970  return llvm::makeArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
2971  }
2972 
2973 public:
2974  /// Creates clause with a list of variables \a VL.
2975  ///
2976  /// \param StartLoc Starting location of the clause.
2977  /// \param LParenLoc Location of '('.
2978  /// \param ModifierLoc Modifier location.
2979  /// \param ColonLoc Location of ':'.
2980  /// \param EndLoc Ending location of the clause.
2981  /// \param VL The variables in the clause.
2982  /// \param QualifierLoc The nested-name qualifier with location information
2983  /// \param NameInfo The full name info for reduction identifier.
2984  /// \param Privates List of helper expressions for proper generation of
2985  /// private copies.
2986  /// \param LHSExprs List of helper expressions for proper generation of
2987  /// assignment operation required for copyprivate clause. This list represents
2988  /// LHSs of the reduction expressions.
2989  /// \param RHSExprs List of helper expressions for proper generation of
2990  /// assignment operation required for copyprivate clause. This list represents
2991  /// RHSs of the reduction expressions.
2992  /// Also, variables in these expressions are used for proper initialization of
2993  /// reduction copies.
2994  /// \param ReductionOps List of helper expressions that represents reduction
2995  /// expressions:
2996  /// \code
2997  /// LHSExprs binop RHSExprs;
2998  /// operator binop(LHSExpr, RHSExpr);
2999  /// <CutomReduction>(LHSExpr, RHSExpr);
3000  /// \endcode
3001  /// Required for proper codegen of final reduction operation performed by the
3002  /// reduction clause.
3003  /// \param CopyOps List of copy operations for inscan reductions:
3004  /// \code
3005  /// TempExprs = LHSExprs;
3006  /// \endcode
3007  /// \param CopyArrayTemps Temp arrays for prefix sums.
3008  /// \param CopyArrayElems Temp arrays for prefix sums.
3009  /// \param PreInit Statement that must be executed before entering the OpenMP
3010  /// region with this clause.
3011  /// \param PostUpdate Expression that must be executed after exit from the
3012  /// OpenMP region with this clause.
3013  static OMPReductionClause *
3014  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3015  SourceLocation ModifierLoc, SourceLocation ColonLoc,
3016  SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
3017  ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
3018  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3019  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3020  ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
3021  ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
3022  Stmt *PreInit, Expr *PostUpdate);
3023 
3024  /// Creates an empty clause with the place for \a N variables.
3025  ///
3026  /// \param C AST context.
3027  /// \param N The number of variables.
3028  /// \param Modifier Reduction modifier.
3029  static OMPReductionClause *
3030  CreateEmpty(const ASTContext &C, unsigned N,
3032 
3033  /// Returns modifier.
3034  OpenMPReductionClauseModifier getModifier() const { return Modifier; }
3035 
3036  /// Returns modifier location.
3037  SourceLocation getModifierLoc() const { return ModifierLoc; }
3038 
3039  /// Gets location of ':' symbol in clause.
3040  SourceLocation getColonLoc() const { return ColonLoc; }
3041 
3042  /// Gets the name info for specified reduction identifier.
3043  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3044 
3045  /// Gets the nested name specifier.
3046  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3047 
3050  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3051  using helper_expr_const_range =
3052  llvm::iterator_range<helper_expr_const_iterator>;
3053 
3055  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3056  }
3057 
3059  return helper_expr_range(getPrivates().begin(), getPrivates().end());
3060  }
3061 
3063  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3064  }
3065 
3067  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3068  }
3069 
3071  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3072  }
3073 
3075  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3076  }
3077 
3079  return helper_expr_const_range(getReductionOps().begin(),
3080  getReductionOps().end());
3081  }
3082 
3084  return helper_expr_range(getReductionOps().begin(),
3085  getReductionOps().end());
3086  }
3087 
3089  return helper_expr_const_range(getInscanCopyOps().begin(),
3090  getInscanCopyOps().end());
3091  }
3092 
3094  return helper_expr_range(getInscanCopyOps().begin(),
3095  getInscanCopyOps().end());
3096  }
3097 
3099  return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
3100  getInscanCopyArrayTemps().end());
3101  }
3102 
3104  return helper_expr_range(getInscanCopyArrayTemps().begin(),
3105  getInscanCopyArrayTemps().end());
3106  }
3107 
3109  return helper_expr_const_range(getInscanCopyArrayElems().begin(),
3110  getInscanCopyArrayElems().end());
3111  }
3112 
3114  return helper_expr_range(getInscanCopyArrayElems().begin(),
3115  getInscanCopyArrayElems().end());
3116  }
3117 
3119  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3120  reinterpret_cast<Stmt **>(varlist_end()));
3121  }
3122 
3124  auto Children = const_cast<OMPReductionClause *>(this)->children();
3125  return const_child_range(Children.begin(), Children.end());
3126  }
3127 
3129  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3130  reinterpret_cast<Stmt **>(varlist_end()));
3131  }
3133  auto Children = const_cast<OMPReductionClause *>(this)->used_children();
3134  return const_child_range(Children.begin(), Children.end());
3135  }
3136 
3137  static bool classof(const OMPClause *T) {
3138  return T->getClauseKind() == llvm::omp::OMPC_reduction;
3139  }
3140 };
3141 
3142 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
3143 /// directives.
3144 ///
3145 /// \code
3146 /// #pragma omp taskgroup task_reduction(+:a,b)
3147 /// \endcode
3148 /// In this example directive '#pragma omp taskgroup' has clause
3149 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
3151  : public OMPVarListClause<OMPTaskReductionClause>,
3152  public OMPClauseWithPostUpdate,
3153  private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
3154  friend class OMPClauseReader;
3155  friend OMPVarListClause;
3156  friend TrailingObjects;
3157 
3158  /// Location of ':'.
3159  SourceLocation ColonLoc;
3160 
3161  /// Nested name specifier for C++.
3162  NestedNameSpecifierLoc QualifierLoc;
3163 
3164  /// Name of custom operator.
3165  DeclarationNameInfo NameInfo;
3166 
3167  /// Build clause with number of variables \a N.
3168  ///
3169  /// \param StartLoc Starting location of the clause.
3170  /// \param LParenLoc Location of '('.
3171  /// \param EndLoc Ending location of the clause.
3172  /// \param ColonLoc Location of ':'.
3173  /// \param N Number of the variables in the clause.
3174  /// \param QualifierLoc The nested-name qualifier with location information
3175  /// \param NameInfo The full name info for reduction identifier.
3177  SourceLocation ColonLoc, SourceLocation EndLoc,
3178  unsigned N, NestedNameSpecifierLoc QualifierLoc,
3179  const DeclarationNameInfo &NameInfo)
3181  llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
3182  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3183  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3184 
3185  /// Build an empty clause.
3186  ///
3187  /// \param N Number of variables.
3188  explicit OMPTaskReductionClause(unsigned N)
3190  llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
3191  SourceLocation(), N),
3192  OMPClauseWithPostUpdate(this) {}
3193 
3194  /// Sets location of ':' symbol in clause.
3195  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3196 
3197  /// Sets the name info for specified reduction identifier.
3198  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3199 
3200  /// Sets the nested name specifier.
3201  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3202 
3203  /// Set list of helper expressions, required for proper codegen of the clause.
3204  /// These expressions represent private copy of the reduction variable.
3205  void setPrivates(ArrayRef<Expr *> Privates);
3206 
3207  /// Get the list of helper privates.
3208  MutableArrayRef<Expr *> getPrivates() {
3209  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3210  }
3211  ArrayRef<const Expr *> getPrivates() const {
3212  return llvm::makeArrayRef(varlist_end(), varlist_size());
3213  }
3214 
3215  /// Set list of helper expressions, required for proper codegen of the clause.
3216  /// These expressions represent LHS expression in the final reduction
3217  /// expression performed by the reduction clause.
3218  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3219 
3220  /// Get the list of helper LHS expressions.
3221  MutableArrayRef<Expr *> getLHSExprs() {
3222  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3223  }
3224  ArrayRef<const Expr *> getLHSExprs() const {
3225  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3226  }
3227 
3228  /// Set list of helper expressions, required for proper codegen of the clause.
3229  /// These expressions represent RHS expression in the final reduction
3230  /// expression performed by the reduction clause. Also, variables in these
3231  /// expressions are used for proper initialization of reduction copies.
3232  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3233 
3234  /// Get the list of helper destination expressions.
3235  MutableArrayRef<Expr *> getRHSExprs() {
3236  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3237  }
3238  ArrayRef<const Expr *> getRHSExprs() const {
3239  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3240  }
3241 
3242  /// Set list of helper reduction expressions, required for proper
3243  /// codegen of the clause. These expressions are binary expressions or
3244  /// operator/custom reduction call that calculates new value from source
3245  /// helper expressions to destination helper expressions.
3246  void setReductionOps(ArrayRef<Expr *> ReductionOps);
3247 
3248  /// Get the list of helper reduction expressions.
3249  MutableArrayRef<Expr *> getReductionOps() {
3250  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3251  }
3252  ArrayRef<const Expr *> getReductionOps() const {
3253  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3254  }
3255 
3256 public:
3257  /// Creates clause with a list of variables \a VL.
3258  ///
3259  /// \param StartLoc Starting location of the clause.
3260  /// \param LParenLoc Location of '('.
3261  /// \param ColonLoc Location of ':'.
3262  /// \param EndLoc Ending location of the clause.
3263  /// \param VL The variables in the clause.
3264  /// \param QualifierLoc The nested-name qualifier with location information
3265  /// \param NameInfo The full name info for reduction identifier.
3266  /// \param Privates List of helper expressions for proper generation of
3267  /// private copies.
3268  /// \param LHSExprs List of helper expressions for proper generation of
3269  /// assignment operation required for copyprivate clause. This list represents
3270  /// LHSs of the reduction expressions.
3271  /// \param RHSExprs List of helper expressions for proper generation of
3272  /// assignment operation required for copyprivate clause. This list represents
3273  /// RHSs of the reduction expressions.
3274  /// Also, variables in these expressions are used for proper initialization of
3275  /// reduction copies.
3276  /// \param ReductionOps List of helper expressions that represents reduction
3277  /// expressions:
3278  /// \code
3279  /// LHSExprs binop RHSExprs;
3280  /// operator binop(LHSExpr, RHSExpr);
3281  /// <CutomReduction>(LHSExpr, RHSExpr);
3282  /// \endcode
3283  /// Required for proper codegen of final reduction operation performed by the
3284  /// reduction clause.
3285  /// \param PreInit Statement that must be executed before entering the OpenMP
3286  /// region with this clause.
3287  /// \param PostUpdate Expression that must be executed after exit from the
3288  /// OpenMP region with this clause.
3289  static OMPTaskReductionClause *
3290  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3291  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3292  NestedNameSpecifierLoc QualifierLoc,
3293  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3294  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3295  ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3296 
3297  /// Creates an empty clause with the place for \a N variables.
3298  ///
3299  /// \param C AST context.
3300  /// \param N The number of variables.
3301  static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3302 
3303  /// Gets location of ':' symbol in clause.
3304  SourceLocation getColonLoc() const { return ColonLoc; }
3305 
3306  /// Gets the name info for specified reduction identifier.
3307  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3308 
3309  /// Gets the nested name specifier.
3310  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3311 
3314  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3315  using helper_expr_const_range =
3316  llvm::iterator_range<helper_expr_const_iterator>;
3317 
3319  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3320  }
3321 
3323  return helper_expr_range(getPrivates().begin(), getPrivates().end());
3324  }
3325 
3327  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3328  }
3329 
3331  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3332  }
3333 
3335  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3336  }
3337 
3339  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3340  }
3341 
3343  return helper_expr_const_range(getReductionOps().begin(),
3344  getReductionOps().end());
3345  }
3346 
3348  return helper_expr_range(getReductionOps().begin(),
3349  getReductionOps().end());
3350  }
3351 
3353  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3354  reinterpret_cast<Stmt **>(varlist_end()));
3355  }
3356 
3358  auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3359  return const_child_range(Children.begin(), Children.end());
3360  }
3361 
3364  }
3367  }
3368 
3369  static bool classof(const OMPClause *T) {
3370  return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
3371  }
3372 };
3373 
3374 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
3375 ///
3376 /// \code
3377 /// #pragma omp task in_reduction(+:a,b)
3378 /// \endcode
3379 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
3380 /// operator '+' and the variables 'a' and 'b'.
3382  : public OMPVarListClause<OMPInReductionClause>,
3383  public OMPClauseWithPostUpdate,
3384  private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
3385  friend class OMPClauseReader;
3386  friend OMPVarListClause;
3387  friend TrailingObjects;
3388 
3389  /// Location of ':'.
3390  SourceLocation ColonLoc;
3391 
3392  /// Nested name specifier for C++.
3393  NestedNameSpecifierLoc QualifierLoc;
3394 
3395  /// Name of custom operator.
3396  DeclarationNameInfo NameInfo;
3397 
3398  /// Build clause with number of variables \a N.
3399  ///
3400  /// \param StartLoc Starting location of the clause.
3401  /// \param LParenLoc Location of '('.
3402  /// \param EndLoc Ending location of the clause.
3403  /// \param ColonLoc Location of ':'.
3404  /// \param N Number of the variables in the clause.
3405  /// \param QualifierLoc The nested-name qualifier with location information
3406  /// \param NameInfo The full name info for reduction identifier.
3408  SourceLocation ColonLoc, SourceLocation EndLoc,
3409  unsigned N, NestedNameSpecifierLoc QualifierLoc,
3410  const DeclarationNameInfo &NameInfo)
3411  : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
3412  StartLoc, LParenLoc, EndLoc, N),
3413  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3414  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3415 
3416  /// Build an empty clause.
3417  ///
3418  /// \param N Number of variables.
3419  explicit OMPInReductionClause(unsigned N)
3421  llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
3422  SourceLocation(), N),
3423  OMPClauseWithPostUpdate(this) {}
3424 
3425  /// Sets location of ':' symbol in clause.
3426  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3427 
3428  /// Sets the name info for specified reduction identifier.
3429  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3430 
3431  /// Sets the nested name specifier.
3432  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3433 
3434  /// Set list of helper expressions, required for proper codegen of the clause.
3435  /// These expressions represent private copy of the reduction variable.
3436  void setPrivates(ArrayRef<Expr *> Privates);
3437 
3438  /// Get the list of helper privates.
3439  MutableArrayRef<Expr *> getPrivates() {
3440  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3441  }
3442  ArrayRef<const Expr *> getPrivates() const {
3443  return llvm::makeArrayRef(varlist_end(), varlist_size());
3444  }
3445 
3446  /// Set list of helper expressions, required for proper codegen of the clause.
3447  /// These expressions represent LHS expression in the final reduction
3448  /// expression performed by the reduction clause.
3449  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3450 
3451  /// Get the list of helper LHS expressions.
3452  MutableArrayRef<Expr *> getLHSExprs() {
3453  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3454  }
3455  ArrayRef<const Expr *> getLHSExprs() const {
3456  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3457  }
3458 
3459  /// Set list of helper expressions, required for proper codegen of the clause.
3460  /// These expressions represent RHS expression in the final reduction
3461  /// expression performed by the reduction clause. Also, variables in these
3462  /// expressions are used for proper initialization of reduction copies.
3463  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3464 
3465  /// Get the list of helper destination expressions.
3466  MutableArrayRef<Expr *> getRHSExprs() {
3467  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3468  }
3469  ArrayRef<const Expr *> getRHSExprs() const {
3470  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3471  }
3472 
3473  /// Set list of helper reduction expressions, required for proper
3474  /// codegen of the clause. These expressions are binary expressions or
3475  /// operator/custom reduction call that calculates new value from source
3476  /// helper expressions to destination helper expressions.
3477  void setReductionOps(ArrayRef<Expr *> ReductionOps);
3478 
3479  /// Get the list of helper reduction expressions.
3480  MutableArrayRef<Expr *> getReductionOps() {
3481  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3482  }
3483  ArrayRef<const Expr *> getReductionOps() const {
3484  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3485  }
3486 
3487  /// Set list of helper reduction taskgroup descriptors.
3488  void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3489 
3490  /// Get the list of helper reduction taskgroup descriptors.
3491  MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3492  return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3493  }
3494  ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3495  return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3496  }
3497 
3498 public:
3499  /// Creates clause with a list of variables \a VL.
3500  ///
3501  /// \param StartLoc Starting location of the clause.
3502  /// \param LParenLoc Location of '('.
3503  /// \param ColonLoc Location of ':'.
3504  /// \param EndLoc Ending location of the clause.
3505  /// \param VL The variables in the clause.
3506  /// \param QualifierLoc The nested-name qualifier with location information
3507  /// \param NameInfo The full name info for reduction identifier.
3508  /// \param Privates List of helper expressions for proper generation of
3509  /// private copies.
3510  /// \param LHSExprs List of helper expressions for proper generation of
3511  /// assignment operation required for copyprivate clause. This list represents
3512  /// LHSs of the reduction expressions.
3513  /// \param RHSExprs List of helper expressions for proper generation of
3514  /// assignment operation required for copyprivate clause. This list represents
3515  /// RHSs of the reduction expressions.
3516  /// Also, variables in these expressions are used for proper initialization of
3517  /// reduction copies.
3518  /// \param ReductionOps List of helper expressions that represents reduction
3519  /// expressions:
3520  /// \code
3521  /// LHSExprs binop RHSExprs;
3522  /// operator binop(LHSExpr, RHSExpr);
3523  /// <CutomReduction>(LHSExpr, RHSExpr);
3524  /// \endcode
3525  /// Required for proper codegen of final reduction operation performed by the
3526  /// reduction clause.
3527  /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3528  /// corresponding items in parent taskgroup task_reduction clause.
3529  /// \param PreInit Statement that must be executed before entering the OpenMP
3530  /// region with this clause.
3531  /// \param PostUpdate Expression that must be executed after exit from the
3532  /// OpenMP region with this clause.
3533  static OMPInReductionClause *
3534  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3535  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3536  NestedNameSpecifierLoc QualifierLoc,
3537  const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3538  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3539  ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3540  Stmt *PreInit, Expr *PostUpdate);
3541 
3542  /// Creates an empty clause with the place for \a N variables.
3543  ///
3544  /// \param C AST context.
3545  /// \param N The number of variables.
3546  static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3547 
3548  /// Gets location of ':' symbol in clause.
3549  SourceLocation getColonLoc() const { return ColonLoc; }
3550 
3551  /// Gets the name info for specified reduction identifier.
3552  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3553 
3554  /// Gets the nested name specifier.
3555  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3556 
3559  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3560  using helper_expr_const_range =
3561  llvm::iterator_range<helper_expr_const_iterator>;
3562 
3564  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3565  }
3566 
3568  return helper_expr_range(getPrivates().begin(), getPrivates().end());
3569  }
3570 
3572  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3573  }
3574 
3576  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3577  }
3578 
3580  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3581  }
3582 
3584  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3585  }
3586 
3588  return helper_expr_const_range(getReductionOps().begin(),
3589  getReductionOps().end());
3590  }
3591 
3593  return helper_expr_range(getReductionOps().begin(),
3594  getReductionOps().end());
3595  }
3596 
3598  return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3599  getTaskgroupDescriptors().end());
3600  }
3601 
3603  return helper_expr_range(getTaskgroupDescriptors().begin(),
3604  getTaskgroupDescriptors().end());
3605  }
3606 
3608  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3609  reinterpret_cast<Stmt **>(varlist_end()));
3610  }
3611 
3613  auto Children = const_cast<OMPInReductionClause *>(this)->children();
3614  return const_child_range(Children.begin(), Children.end());
3615  }
3616 
3619  }
3622  }
3623 
3624  static bool classof(const OMPClause *T) {
3625  return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
3626  }
3627 };
3628 
3629 /// This represents clause 'linear' in the '#pragma omp ...'
3630 /// directives.
3631 ///
3632 /// \code
3633 /// #pragma omp simd linear(a,b : 2)
3634 /// \endcode
3635 /// In this example directive '#pragma omp simd' has clause 'linear'
3636 /// with variables 'a', 'b' and linear step '2'.
3637 class OMPLinearClause final
3638  : public OMPVarListClause<OMPLinearClause>,
3639  public OMPClauseWithPostUpdate,
3640  private llvm::TrailingObjects<OMPLinearClause, Expr *> {
3641  friend class OMPClauseReader;
3642  friend OMPVarListClause;
3643  friend TrailingObjects;
3644 
3645  /// Modifier of 'linear' clause.
3646  OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
3647 
3648  /// Location of linear modifier if any.
3649  SourceLocation ModifierLoc;
3650 
3651  /// Location of ':'.
3652  SourceLocation ColonLoc;
3653 
3654  /// Sets the linear step for clause.
3655  void setStep(Expr *Step) { *(getFinals().end()) = Step; }
3656 
3657  /// Sets the expression to calculate linear step for clause.
3658  void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
3659 
3660  /// Build 'linear' clause with given number of variables \a NumVars.
3661  ///
3662  /// \param StartLoc Starting location of the clause.
3663  /// \param LParenLoc Location of '('.
3664  /// \param ColonLoc Location of ':'.
3665  /// \param EndLoc Ending location of the clause.
3666  /// \param NumVars Number of variables.
3667  OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3668  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3669  SourceLocation ColonLoc, SourceLocation EndLoc,
3670  unsigned NumVars)
3671  : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
3672  LParenLoc, EndLoc, NumVars),
3673  OMPClauseWithPostUpdate(this), Modifier(Modifier),
3674  ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
3675 
3676  /// Build an empty clause.
3677  ///
3678  /// \param NumVars Number of variables.
3679  explicit OMPLinearClause(unsigned NumVars)
3680  : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
3681  SourceLocation(), SourceLocation(),
3682  SourceLocation(), NumVars),
3683  OMPClauseWithPostUpdate(this) {}
3684 
3685  /// Gets the list of initial values for linear variables.
3686  ///
3687  /// There are NumVars expressions with initial values allocated after the
3688  /// varlist, they are followed by NumVars update expressions (used to update
3689  /// the linear variable's value on current iteration) and they are followed by
3690  /// NumVars final expressions (used to calculate the linear variable's
3691  /// value after the loop body). After these lists, there are 2 helper
3692  /// expressions - linear step and a helper to calculate it before the
3693  /// loop body (used when the linear step is not constant):
3694  ///
3695  /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
3696  /// Finals[]; Step; CalcStep; }
3697  MutableArrayRef<Expr *> getPrivates() {
3698  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3699  }
3700  ArrayRef<const Expr *> getPrivates() const {
3701  return llvm::makeArrayRef(varlist_end(), varlist_size());
3702  }
3703 
3704  MutableArrayRef<Expr *> getInits() {
3705  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3706  }
3707  ArrayRef<const Expr *> getInits() const {
3708  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3709  }
3710 
3711  /// Sets the list of update expressions for linear variables.
3712  MutableArrayRef<Expr *> getUpdates() {
3713  return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
3714  }
3715  ArrayRef<const Expr *> getUpdates() const {
3716  return llvm::makeArrayRef(getInits().end(), varlist_size());
3717  }
3718 
3719  /// Sets the list of final update expressions for linear variables.
3720  MutableArrayRef<Expr *> getFinals() {
3721  return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
3722  }
3723  ArrayRef<const Expr *> getFinals() const {
3724  return llvm::makeArrayRef(getUpdates().end(), varlist_size());
3725  }
3726 
3727  /// Gets the list of used expressions for linear variables.
3728  MutableArrayRef<Expr *> getUsedExprs() {
3729  return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
3730  }
3731  ArrayRef<const Expr *> getUsedExprs() const {
3732  return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
3733  }
3734 
3735  /// Sets the list of the copies of original linear variables.
3736  /// \param PL List of expressions.
3737  void setPrivates(ArrayRef<Expr *> PL);
3738 
3739  /// Sets the list of the initial values for linear variables.
3740  /// \param IL List of expressions.
3741  void setInits(ArrayRef<Expr *> IL);
3742 
3743 public:
3744  /// Creates clause with a list of variables \a VL and a linear step
3745  /// \a Step.
3746  ///
3747  /// \param C AST Context.
3748  /// \param StartLoc Starting location of the clause.
3749  /// \param LParenLoc Location of '('.
3750  /// \param Modifier Modifier of 'linear' clause.
3751  /// \param ModifierLoc Modifier location.
3752  /// \param ColonLoc Location of ':'.
3753  /// \param EndLoc Ending location of the clause.
3754  /// \param VL List of references to the variables.
3755  /// \param PL List of private copies of original variables.
3756  /// \param IL List of initial values for the variables.
3757  /// \param Step Linear step.
3758  /// \param CalcStep Calculation of the linear step.
3759  /// \param PreInit Statement that must be executed before entering the OpenMP
3760  /// region with this clause.
3761  /// \param PostUpdate Expression that must be executed after exit from the
3762  /// OpenMP region with this clause.
3763  static OMPLinearClause *
3764  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3765  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3766  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3767  ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
3768  Stmt *PreInit, Expr *PostUpdate);
3769 
3770  /// Creates an empty clause with the place for \a NumVars variables.
3771  ///
3772  /// \param C AST context.
3773  /// \param NumVars Number of variables.
3774  static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3775 
3776  /// Set modifier.
3778 
3779  /// Return modifier.
3780  OpenMPLinearClauseKind getModifier() const { return Modifier; }
3781 
3782  /// Set modifier location.
3783  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3784 
3785  /// Return modifier location.
3786  SourceLocation getModifierLoc() const { return ModifierLoc; }
3787 
3788  /// Sets the location of ':'.
3789  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3790 
3791  /// Returns the location of ':'.
3792  SourceLocation getColonLoc() const { return ColonLoc; }
3793 
3794  /// Returns linear step.
3795  Expr *getStep() { return *(getFinals().end()); }
3796 
3797  /// Returns linear step.
3798  const Expr *getStep() const { return *(getFinals().end()); }
3799 
3800  /// Returns expression to calculate linear step.
3801  Expr *getCalcStep() { return *(getFinals().end() + 1); }
3802 
3803  /// Returns expression to calculate linear step.
3804  const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
3805 
3806  /// Sets the list of update expressions for linear variables.
3807  /// \param UL List of expressions.
3808  void setUpdates(ArrayRef<Expr *> UL);
3809 
3810  /// Sets the list of final update expressions for linear variables.
3811  /// \param FL List of expressions.
3812  void setFinals(ArrayRef<Expr *> FL);
3813 
3814  /// Sets the list of used expressions for the linear clause.
3815  void setUsedExprs(ArrayRef<Expr *> UE);
3816 
3819  using privates_range = llvm::iterator_range<privates_iterator>;
3820  using privates_const_range = llvm::iterator_range<privates_const_iterator>;
3821 
3823  return privates_range(getPrivates().begin(), getPrivates().end());
3824  }
3825 
3827  return privates_const_range(getPrivates().begin(), getPrivates().end());
3828  }
3829 
3832  using inits_range = llvm::iterator_range<inits_iterator>;
3833  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3834 
3836  return inits_range(getInits().begin(), getInits().end());
3837  }
3838 
3840  return inits_const_range(getInits().begin(), getInits().end());
3841  }
3842 
3845  using updates_range = llvm::iterator_range<updates_iterator>;
3846  using updates_const_range = llvm::iterator_range<updates_const_iterator>;
3847 
3849  return updates_range(getUpdates().begin(), getUpdates().end());
3850  }
3851 
3853  return updates_const_range(getUpdates().begin(), getUpdates().end());
3854  }
3855 
3858  using finals_range = llvm::iterator_range<finals_iterator>;
3859  using finals_const_range = llvm::iterator_range<finals_const_iterator>;
3860 
3862  return finals_range(getFinals().begin(), getFinals().end());
3863  }
3864 
3866  return finals_const_range(getFinals().begin(), getFinals().end());
3867  }
3868 
3871  using used_expressions_range =
3872  llvm::iterator_range<used_expressions_iterator>;
3874  llvm::iterator_range<used_expressions_const_iterator>;
3875 
3877  return finals_range(getUsedExprs().begin(), getUsedExprs().end());
3878  }
3879 
3881  return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
3882  }
3883 
3885  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3886  reinterpret_cast<Stmt **>(varlist_end()));
3887  }
3888 
3890  auto Children = const_cast<OMPLinearClause *>(this)->children();
3891  return const_child_range(Children.begin(), Children.end());
3892  }
3893 
3895 
3897  auto Children = const_cast<OMPLinearClause *>(this)->used_children();
3898  return const_child_range(Children.begin(), Children.end());
3899  }
3900 
3901  static bool classof(const OMPClause *T) {
3902  return T->getClauseKind() == llvm::omp::OMPC_linear;
3903  }
3904 };
3905 
3906 /// This represents clause 'aligned' in the '#pragma omp ...'
3907 /// directives.
3908 ///
3909 /// \code
3910 /// #pragma omp simd aligned(a,b : 8)
3911 /// \endcode
3912 /// In this example directive '#pragma omp simd' has clause 'aligned'
3913 /// with variables 'a', 'b' and alignment '8'.
3914 class OMPAlignedClause final
3915  : public OMPVarListClause<OMPAlignedClause>,
3916  private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
3917  friend class OMPClauseReader;
3918  friend OMPVarListClause;
3919  friend TrailingObjects;
3920 
3921  /// Location of ':'.
3922  SourceLocation ColonLoc;
3923 
3924  /// Sets the alignment for clause.
3925  void setAlignment(Expr *A) { *varlist_end() = A; }
3926 
3927  /// Build 'aligned' clause with given number of variables \a NumVars.
3928  ///
3929  /// \param StartLoc Starting location of the clause.
3930  /// \param LParenLoc Location of '('.
3931  /// \param ColonLoc Location of ':'.
3932  /// \param EndLoc Ending location of the clause.
3933  /// \param NumVars Number of variables.
3934  OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3935  SourceLocation ColonLoc, SourceLocation EndLoc,
3936  unsigned NumVars)
3937  : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
3938  LParenLoc, EndLoc, NumVars),
3939  ColonLoc(ColonLoc) {}
3940 
3941  /// Build an empty clause.
3942  ///
3943  /// \param NumVars Number of variables.
3944  explicit OMPAlignedClause(unsigned NumVars)
3945  : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
3946  SourceLocation(), SourceLocation(),
3947  SourceLocation(), NumVars) {}
3948 
3949 public:
3950  /// Creates clause with a list of variables \a VL and alignment \a A.
3951  ///
3952  /// \param C AST Context.
3953  /// \param StartLoc Starting location of the clause.
3954  /// \param LParenLoc Location of '('.
3955  /// \param ColonLoc Location of ':'.
3956  /// \param EndLoc Ending location of the clause.
3957  /// \param VL List of references to the variables.
3958  /// \param A Alignment.
3959  static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3960  SourceLocation LParenLoc,
3961  SourceLocation ColonLoc,
3962  SourceLocation EndLoc, ArrayRef<Expr *> VL,
3963  Expr *A);
3964 
3965  /// Creates an empty clause with the place for \a NumVars variables.
3966  ///
3967  /// \param C AST context.
3968  /// \param NumVars Number of variables.
3969  static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3970 
3971  /// Sets the location of ':'.
3972  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3973 
3974  /// Returns the location of ':'.
3975  SourceLocation getColonLoc() const { return ColonLoc; }
3976 
3977  /// Returns alignment.
3978  Expr *getAlignment() { return *varlist_end(); }
3979 
3980  /// Returns alignment.
3981  const Expr *getAlignment() const { return *varlist_end(); }
3982 
3984  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3985  reinterpret_cast<Stmt **>(varlist_end()));
3986  }
3987 
3989  auto Children = const_cast<OMPAlignedClause *>(this)->children();
3990  return const_child_range(Children.begin(), Children.end());
3991  }
3992 
3995  }
3998  }
3999 
4000  static bool classof(const OMPClause *T) {
4001  return T->getClauseKind() == llvm::omp::OMPC_aligned;
4002  }
4003 };
4004 
4005 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
4006 ///
4007 /// \code
4008 /// #pragma omp parallel copyin(a,b)
4009 /// \endcode
4010 /// In this example directive '#pragma omp parallel' has clause 'copyin'
4011 /// with the variables 'a' and 'b'.
4012 class OMPCopyinClause final
4013  : public OMPVarListClause<OMPCopyinClause>,
4014  private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
4015  // Class has 3 additional tail allocated arrays:
4016  // 1. List of helper expressions for proper generation of assignment operation
4017  // required for copyin clause. This list represents sources.
4018  // 2. List of helper expressions for proper generation of assignment operation
4019  // required for copyin clause. This list represents destinations.
4020  // 3. List of helper expressions that represents assignment operation:
4021  // \code
4022  // DstExprs = SrcExprs;
4023  // \endcode
4024  // Required for proper codegen of propagation of master's thread values of
4025  // threadprivate variables to local instances of that variables in other
4026  // implicit threads.
4027 
4028  friend class OMPClauseReader;
4029  friend OMPVarListClause;
4030  friend TrailingObjects;
4031 
4032  /// Build clause with number of variables \a N.
4033  ///
4034  /// \param StartLoc Starting location of the clause.
4035  /// \param LParenLoc Location of '('.
4036  /// \param EndLoc Ending location of the clause.
4037  /// \param N Number of the variables in the clause.
4038  OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4039  SourceLocation EndLoc, unsigned N)
4040  : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
4041  LParenLoc, EndLoc, N) {}
4042 
4043  /// Build an empty clause.
4044  ///
4045  /// \param N Number of variables.
4046  explicit OMPCopyinClause(unsigned N)
4047  : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
4049  SourceLocation(), N) {}
4050 
4051  /// Set list of helper expressions, required for proper codegen of the
4052  /// clause. These expressions represent source expression in the final
4053  /// assignment statement performed by the copyin clause.
4054  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4055 
4056  /// Get the list of helper source expressions.
4057  MutableArrayRef<Expr *> getSourceExprs() {
4058  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4059  }
4060  ArrayRef<const Expr *> getSourceExprs() const {
4061  return llvm::makeArrayRef(varlist_end(), varlist_size());
4062  }
4063 
4064  /// Set list of helper expressions, required for proper codegen of the
4065  /// clause. These expressions represent destination expression in the final
4066  /// assignment statement performed by the copyin clause.
4067  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4068 
4069  /// Get the list of helper destination expressions.
4070  MutableArrayRef<Expr *> getDestinationExprs() {
4071  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4072  }
4073  ArrayRef<const Expr *> getDestinationExprs() const {
4074  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
4075  }
4076 
4077  /// Set list of helper assignment expressions, required for proper
4078  /// codegen of the clause. These expressions are assignment expressions that
4079  /// assign source helper expressions to destination helper expressions
4080  /// correspondingly.
4081  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4082 
4083  /// Get the list of helper assignment expressions.
4084  MutableArrayRef<Expr *> getAssignmentOps() {
4085  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4086  }
4087  ArrayRef<const Expr *> getAssignmentOps() const {
4088  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
4089  }
4090 
4091 public:
4092  /// Creates clause with a list of variables \a VL.
4093  ///
4094  /// \param C AST context.
4095  /// \param StartLoc Starting location of the clause.
4096  /// \param LParenLoc Location of '('.
4097  /// \param EndLoc Ending location of the clause.
4098  /// \param VL List of references to the variables.
4099  /// \param SrcExprs List of helper expressions for proper generation of
4100  /// assignment operation required for copyin clause. This list represents
4101  /// sources.
4102  /// \param DstExprs List of helper expressions for proper generation of
4103  /// assignment operation required for copyin clause. This list represents
4104  /// destinations.
4105  /// \param AssignmentOps List of helper expressions that represents assignment
4106  /// operation:
4107  /// \code
4108  /// DstExprs = SrcExprs;
4109  /// \endcode
4110  /// Required for proper codegen of propagation of master's thread values of
4111  /// threadprivate variables to local instances of that variables in other
4112  /// implicit threads.
4113  static OMPCopyinClause *
4114  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4115  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4116  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4117 
4118  /// Creates an empty clause with \a N variables.
4119  ///
4120  /// \param C AST context.
4121  /// \param N The number of variables.
4122  static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
4123 
4126  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4127  using helper_expr_const_range =
4128  llvm::iterator_range<helper_expr_const_iterator>;
4129 
4131  return helper_expr_const_range(getSourceExprs().begin(),
4132  getSourceExprs().end());
4133  }
4134 
4136  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4137  }
4138 
4140  return helper_expr_const_range(getDestinationExprs().begin(),
4141  getDestinationExprs().end());
4142  }
4143 
4145  return helper_expr_range(getDestinationExprs().begin(),
4146  getDestinationExprs().end());
4147  }
4148 
4150  return helper_expr_const_range(getAssignmentOps().begin(),
4151  getAssignmentOps().end());
4152  }
4153 
4155  return helper_expr_range(getAssignmentOps().begin(),
4156  getAssignmentOps().end());
4157  }
4158 
4160  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4161  reinterpret_cast<Stmt **>(varlist_end()));
4162  }
4163 
4165  auto Children = const_cast<OMPCopyinClause *>(this)->children();
4166  return const_child_range(Children.begin(), Children.end());
4167  }
4168 
4171  }
4174  }
4175 
4176  static bool classof(const OMPClause *T) {
4177  return T->getClauseKind() == llvm::omp::OMPC_copyin;
4178  }
4179 };
4180 
4181 /// This represents clause 'copyprivate' in the '#pragma omp ...'
4182 /// directives.
4183 ///
4184 /// \code
4185 /// #pragma omp single copyprivate(a,b)
4186 /// \endcode
4187 /// In this example directive '#pragma omp single' has clause 'copyprivate'
4188 /// with the variables 'a' and 'b'.
4190  : public OMPVarListClause<OMPCopyprivateClause>,
4191  private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
4192  friend class OMPClauseReader;
4193  friend OMPVarListClause;
4194  friend TrailingObjects;
4195 
4196  /// Build clause with number of variables \a N.
4197  ///
4198  /// \param StartLoc Starting location of the clause.
4199  /// \param LParenLoc Location of '('.
4200  /// \param EndLoc Ending location of the clause.
4201  /// \param N Number of the variables in the clause.
4203  SourceLocation EndLoc, unsigned N)
4204  : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
4205  StartLoc, LParenLoc, EndLoc, N) {
4206  }
4207 
4208  /// Build an empty clause.
4209  ///
4210  /// \param N Number of variables.
4211  explicit OMPCopyprivateClause(unsigned N)
4213  llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
4214  SourceLocation(), N) {}
4215 
4216  /// Set list of helper expressions, required for proper codegen of the
4217  /// clause. These expressions represent source expression in the final
4218  /// assignment statement performed by the copyprivate clause.
4219  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4220 
4221  /// Get the list of helper source expressions.
4222  MutableArrayRef<Expr *> getSourceExprs() {
4223  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4224  }
4225  ArrayRef<const Expr *> getSourceExprs() const {
4226  return llvm::makeArrayRef(varlist_end(), varlist_size());
4227  }
4228 
4229  /// Set list of helper expressions, required for proper codegen of the
4230  /// clause. These expressions represent destination expression in the final
4231  /// assignment statement performed by the copyprivate clause.
4232  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4233 
4234  /// Get the list of helper destination expressions.
4235  MutableArrayRef<Expr *> getDestinationExprs() {
4236  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4237  }
4238  ArrayRef<const Expr *> getDestinationExprs() const {
4239  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
4240  }
4241 
4242  /// Set list of helper assignment expressions, required for proper
4243  /// codegen of the clause. These expressions are assignment expressions that
4244  /// assign source helper expressions to destination helper expressions
4245  /// correspondingly.
4246  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4247 
4248  /// Get the list of helper assignment expressions.
4249  MutableArrayRef<Expr *> getAssignmentOps() {
4250  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4251  }
4252  ArrayRef<const Expr *> getAssignmentOps() const {
4253  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
4254  }
4255 
4256 public:
4257  /// Creates clause with a list of variables \a VL.
4258  ///
4259  /// \param C AST context.
4260  /// \param StartLoc Starting location of the clause.
4261  /// \param LParenLoc Location of '('.
4262  /// \param EndLoc Ending location of the clause.
4263  /// \param VL List of references to the variables.
4264  /// \param SrcExprs List of helper expressions for proper generation of
4265  /// assignment operation required for copyprivate clause. This list represents
4266  /// sources.
4267  /// \param DstExprs List of helper expressions for proper generation of
4268  /// assignment operation required for copyprivate clause. This list represents
4269  /// destinations.
4270  /// \param AssignmentOps List of helper expressions that represents assignment
4271  /// operation:
4272  /// \code
4273  /// DstExprs = SrcExprs;
4274  /// \endcode
4275  /// Required for proper codegen of final assignment performed by the
4276  /// copyprivate clause.
4277  static OMPCopyprivateClause *
4278  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4279  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4280  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4281 
4282  /// Creates an empty clause with \a N variables.
4283  ///
4284  /// \param C AST context.
4285  /// \param N The number of variables.
4286  static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
4287 
4290  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4291  using helper_expr_const_range =
4292  llvm::iterator_range<helper_expr_const_iterator>;
4293 
4295  return helper_expr_const_range(getSourceExprs().begin(),
4296  getSourceExprs().end());
4297  }
4298 
4300  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4301  }
4302 
4304  return helper_expr_const_range(getDestinationExprs().begin(),
4305  getDestinationExprs().end());
4306  }
4307 
4309  return helper_expr_range(getDestinationExprs().begin(),
4310  getDestinationExprs().end());
4311  }
4312 
4314  return helper_expr_const_range(getAssignmentOps().begin(),
4315  getAssignmentOps().end());
4316  }
4317 
4319  return helper_expr_range(getAssignmentOps().begin(),
4320  getAssignmentOps().end());
4321  }
4322 
4324  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4325  reinterpret_cast<Stmt **>(varlist_end()));
4326  }
4327 
4329  auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
4330  return const_child_range(Children.begin(), Children.end());
4331  }
4332 
4335  }
4338  }
4339 
4340  static bool classof(const OMPClause *T) {
4341  return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
4342  }
4343 };
4344 
4345 /// This represents implicit clause 'flush' for the '#pragma omp flush'
4346 /// directive.
4347 /// This clause does not exist by itself, it can be only as a part of 'omp
4348 /// flush' directive. This clause is introduced to keep the original structure
4349 /// of \a OMPExecutableDirective class and its derivatives and to use the
4350 /// existing infrastructure of clauses with the list of variables.
4351 ///
4352 /// \code
4353 /// #pragma omp flush(a,b)
4354 /// \endcode
4355 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
4356 /// with the variables 'a' and 'b'.
4357 class OMPFlushClause final
4358  : public OMPVarListClause<OMPFlushClause>,
4359  private llvm::TrailingObjects<OMPFlushClause, Expr *> {
4360  friend OMPVarListClause;
4361  friend TrailingObjects;
4362 
4363  /// Build clause with number of variables \a N.
4364  ///
4365  /// \param StartLoc Starting location of the clause.
4366  /// \param LParenLoc Location of '('.
4367  /// \param EndLoc Ending location of the clause.
4368  /// \param N Number of the variables in the clause.
4369  OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4370  SourceLocation EndLoc, unsigned N)
4371  : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
4372  LParenLoc, EndLoc, N) {}
4373 
4374  /// Build an empty clause.
4375  ///
4376  /// \param N Number of variables.
4377  explicit OMPFlushClause(unsigned N)
4378  : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
4380  SourceLocation(), N) {}
4381 
4382 public:
4383  /// Creates clause with a list of variables \a VL.
4384  ///
4385  /// \param C AST context.
4386  /// \param StartLoc Starting location of the clause.
4387  /// \param LParenLoc Location of '('.
4388  /// \param EndLoc Ending location of the clause.
4389  /// \param VL List of references to the variables.
4390  static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
4391  SourceLocation LParenLoc, SourceLocation EndLoc,
4392  ArrayRef<Expr *> VL);
4393 
4394  /// Creates an empty clause with \a N variables.
4395  ///
4396  /// \param C AST context.
4397  /// \param N The number of variables.
4398  static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
4399 
4401  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4402  reinterpret_cast<Stmt **>(varlist_end()));
4403  }
4404 
4406  auto Children = const_cast<OMPFlushClause *>(this)->children();
4407  return const_child_range(Children.begin(), Children.end());
4408  }
4409 
4412  }
4415  }
4416 
4417  static bool classof(const OMPClause *T) {
4418  return T->getClauseKind() == llvm::omp::OMPC_flush;
4419  }
4420 };
4421 
4422 /// This represents implicit clause 'depobj' for the '#pragma omp depobj'
4423 /// directive.
4424 /// This clause does not exist by itself, it can be only as a part of 'omp
4425 /// depobj' directive. This clause is introduced to keep the original structure
4426 /// of \a OMPExecutableDirective class and its derivatives and to use the
4427 /// existing infrastructure of clauses with the list of variables.
4428 ///
4429 /// \code
4430 /// #pragma omp depobj(a) destroy
4431 /// \endcode
4432 /// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
4433 /// with the depobj 'a'.
4434 class OMPDepobjClause final : public OMPClause {
4435  friend class OMPClauseReader;
4436 
4437  /// Location of '('.
4438  SourceLocation LParenLoc;
4439 
4440  /// Chunk size.
4441  Expr *Depobj = nullptr;
4442 
4443  /// Build clause with number of variables \a N.
4444  ///
4445  /// \param StartLoc Starting location of the clause.
4446  /// \param LParenLoc Location of '('.
4447  /// \param EndLoc Ending location of the clause.
4448  OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4449  SourceLocation EndLoc)
4450  : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
4451  LParenLoc(LParenLoc) {}
4452 
4453  /// Build an empty clause.
4454  ///
4455  explicit OMPDepobjClause()
4456  : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
4457 
4458  void setDepobj(Expr *E) { Depobj = E; }
4459 
4460  /// Sets the location of '('.
4461  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4462 
4463 public:
4464  /// Creates clause.
4465  ///
4466  /// \param C AST context.
4467  /// \param StartLoc Starting location of the clause.
4468  /// \param LParenLoc Location of '('.
4469  /// \param EndLoc Ending location of the clause.
4470  /// \param Depobj depobj expression associated with the 'depobj' directive.
4471  static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc,
4472  SourceLocation LParenLoc,
4473  SourceLocation EndLoc, Expr *Depobj);
4474 
4475  /// Creates an empty clause.
4476  ///
4477  /// \param C AST context.
4478  static OMPDepobjClause *CreateEmpty(const ASTContext &C);
4479 
4480  /// Returns depobj expression associated with the clause.
4481  Expr *getDepobj() { return Depobj; }
4482  const Expr *getDepobj() const { return Depobj; }
4483 
4484  /// Returns the location of '('.
4485  SourceLocation getLParenLoc() const { return LParenLoc; }
4486 
4488  return child_range(reinterpret_cast<Stmt **>(&Depobj),
4489  reinterpret_cast<Stmt **>(&Depobj) + 1);
4490  }
4491 
4493  auto Children = const_cast<OMPDepobjClause *>(this)->children();
4494  return const_child_range(Children.begin(), Children.end());
4495  }
4496 
4499  }
4502  }
4503 
4504  static bool classof(const OMPClause *T) {
4505  return T->getClauseKind() == llvm::omp::OMPC_depobj;
4506  }
4507 };
4508 
4509 /// This represents implicit clause 'depend' for the '#pragma omp task'
4510 /// directive.
4511 ///
4512 /// \code
4513 /// #pragma omp task depend(in:a,b)
4514 /// \endcode
4515 /// In this example directive '#pragma omp task' with clause 'depend' with the
4516 /// variables 'a' and 'b' with dependency 'in'.
4517 class OMPDependClause final
4518  : public OMPVarListClause<OMPDependClause>,
4519  private llvm::TrailingObjects<OMPDependClause, Expr *> {
4520  friend class OMPClauseReader;
4521  friend OMPVarListClause;
4522  friend TrailingObjects;
4523 
4524  /// Dependency type (one of in, out, inout).
4526 
4527  /// Dependency type location.
4528  SourceLocation DepLoc;
4529 
4530  /// Colon location.
4531  SourceLocation ColonLoc;
4532 
4533  /// Number of loops, associated with the depend clause.
4534  unsigned NumLoops = 0;
4535 
4536  /// Build clause with number of variables \a N.
4537  ///
4538  /// \param StartLoc Starting location of the clause.
4539  /// \param LParenLoc Location of '('.
4540  /// \param EndLoc Ending location of the clause.
4541  /// \param N Number of the variables in the clause.
4542  /// \param NumLoops Number of loops that is associated with this depend
4543  /// clause.
4544  OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4545  SourceLocation EndLoc, unsigned N, unsigned NumLoops)
4546  : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, StartLoc,
4547  LParenLoc, EndLoc, N),
4548  NumLoops(NumLoops) {}
4549 
4550  /// Build an empty clause.
4551  ///
4552  /// \param N Number of variables.
4553  /// \param NumLoops Number of loops that is associated with this depend
4554  /// clause.
4555  explicit OMPDependClause(unsigned N, unsigned NumLoops)
4556  : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend,
4558  SourceLocation(), N),
4559  NumLoops(NumLoops) {}
4560 
4561  /// Set dependency kind.
4562  void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
4563 
4564  /// Set dependency kind and its location.
4565  void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
4566 
4567  /// Set colon location.
4568  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4569 
4570  /// Sets optional dependency modifier.
4571  void setModifier(Expr *DepModifier);
4572 
4573 public:
4574  /// Creates clause with a list of variables \a VL.
4575  ///
4576  /// \param C AST context.
4577  /// \param StartLoc Starting location of the clause.
4578  /// \param LParenLoc Location of '('.
4579  /// \param EndLoc Ending location of the clause.
4580  /// \param DepKind Dependency type.
4581  /// \param DepLoc Location of the dependency type.
4582  /// \param ColonLoc Colon location.
4583  /// \param VL List of references to the variables.
4584  /// \param NumLoops Number of loops that is associated with this depend
4585  /// clause.
4586  static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
4587  SourceLocation LParenLoc,
4588  SourceLocation EndLoc, Expr *DepModifier,
4589  OpenMPDependClauseKind DepKind,
4590  SourceLocation DepLoc, SourceLocation ColonLoc,
4591  ArrayRef<Expr *> VL, unsigned NumLoops);
4592 
4593  /// Creates an empty clause with \a N variables.
4594  ///
4595  /// \param C AST context.
4596  /// \param N The number of variables.
4597  /// \param NumLoops Number of loops that is associated with this depend
4598  /// clause.
4599  static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
4600  unsigned NumLoops);
4601 
4602  /// Get dependency type.
4603  OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
4604 
4605  /// Return optional depend modifier.
4606  Expr *getModifier();
4607  const Expr *getModifier() const {
4608  return const_cast<OMPDependClause *>(this)->getModifier();
4609  }
4610 
4611  /// Get dependency type location.
4612  SourceLocation getDependencyLoc() const { return DepLoc; }
4613 
4614  /// Get colon location.
4615  SourceLocation getColonLoc() const { return ColonLoc; }
4616 
4617  /// Get number of loops associated with the clause.
4618  unsigned getNumLoops() const { return NumLoops; }
4619 
4620  /// Set the loop data for the depend clauses with 'sink|source' kind of
4621  /// dependency.
4622  void setLoopData(unsigned NumLoop, Expr *Cnt);
4623 
4624  /// Get the loop data.
4625  Expr *getLoopData(unsigned NumLoop);
4626  const Expr *getLoopData(unsigned NumLoop) const;
4627 
4629  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4630  reinterpret_cast<Stmt **>(varlist_end()));
4631  }
4632 
4634  auto Children = const_cast<OMPDependClause *>(this)->children();
4635  return const_child_range(Children.begin(), Children.end());
4636  }
4637 
4640  }
4643  }
4644 
4645  static bool classof(const OMPClause *T) {
4646  return T->getClauseKind() == llvm::omp::OMPC_depend;
4647  }
4648 };
4649 
4650 /// This represents 'device' clause in the '#pragma omp ...'
4651 /// directive.
4652 ///
4653 /// \code
4654 /// #pragma omp target device(a)
4655 /// \endcode
4656 /// In this example directive '#pragma omp target' has clause 'device'
4657 /// with single expression 'a'.
4659  friend class OMPClauseReader;
4660 
4661  /// Location of '('.
4662  SourceLocation LParenLoc;
4663 
4664  /// Device clause modifier.
4666 
4667  /// Location of the modifier.
4668  SourceLocation ModifierLoc;
4669 
4670  /// Device number.
4671  Stmt *Device = nullptr;
4672 
4673  /// Set the device number.
4674  ///
4675  /// \param E Device number.
4676  void setDevice(Expr *E) { Device = E; }
4677 
4678  /// Sets modifier.
4679  void setModifier(OpenMPDeviceClauseModifier M) { Modifier = M; }
4680 
4681  /// Setst modifier location.
4682  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4683 
4684 public:
4685  /// Build 'device' clause.
4686  ///
4687  /// \param Modifier Clause modifier.
4688  /// \param E Expression associated with this clause.
4689  /// \param CaptureRegion Innermost OpenMP region where expressions in this
4690  /// clause must be captured.
4691  /// \param StartLoc Starting location of the clause.
4692  /// \param ModifierLoc Modifier location.
4693  /// \param LParenLoc Location of '('.
4694  /// \param EndLoc Ending location of the clause.
4696  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
4697  SourceLocation LParenLoc, SourceLocation ModifierLoc,
4698  SourceLocation EndLoc)
4699  : OMPClause(llvm::omp::OMPC_device, StartLoc, EndLoc),
4700  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
4701  ModifierLoc(ModifierLoc), Device(E) {
4702  setPreInitStmt(HelperE, CaptureRegion);
4703  }
4704 
4705  /// Build an empty clause.
4707  : OMPClause(llvm::omp::OMPC_device, SourceLocation(), SourceLocation()),
4708  OMPClauseWithPreInit(this) {}
4709 
4710  /// Sets the location of '('.
4711  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4712 
4713  /// Returns the location of '('.
4714  SourceLocation getLParenLoc() const { return LParenLoc; }
4715 
4716  /// Return device number.
4717  Expr *getDevice() { return cast<Expr>(Device); }
4718 
4719  /// Return device number.
4720  Expr *getDevice() const { return cast<Expr>(Device); }
4721 
4722  /// Gets modifier.
4723  OpenMPDeviceClauseModifier getModifier() const { return Modifier; }
4724 
4725  /// Gets modifier location.
4726  SourceLocation getModifierLoc() const { return ModifierLoc; }
4727 
4728  child_range children() { return child_range(&Device, &Device + 1); }
4729 
4731  return const_child_range(&Device, &Device + 1);
4732  }
4733 
4736  }
4739  }
4740 
4741  static bool classof(const OMPClause *T) {
4742  return T->getClauseKind() == llvm::omp::OMPC_device;
4743  }
4744 };
4745 
4746 /// This represents 'threads' clause in the '#pragma omp ...' directive.
4747 ///
4748 /// \code
4749 /// #pragma omp ordered threads
4750 /// \endcode
4751 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
4752 class OMPThreadsClause : public OMPClause {
4753 public:
4754  /// Build 'threads' clause.
4755  ///
4756  /// \param StartLoc Starting location of the clause.
4757  /// \param EndLoc Ending location of the clause.
4759  : OMPClause(llvm::omp::OMPC_threads, StartLoc, EndLoc) {}
4760 
4761  /// Build an empty clause.
4763  : OMPClause(llvm::omp::OMPC_threads, SourceLocation(), SourceLocation()) {
4764  }
4765 
4768  }
4769 
4772  }
4773 
4776  }
4779  }
4780 
4781  static bool classof(const OMPClause *T) {
4782  return T->getClauseKind() == llvm::omp::OMPC_threads;
4783  }
4784 };
4785 
4786 /// This represents 'simd' clause in the '#pragma omp ...' directive.
4787 ///
4788 /// \code
4789 /// #pragma omp ordered simd
4790 /// \endcode
4791 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
4792 class OMPSIMDClause : public OMPClause {
4793 public:
4794  /// Build 'simd' clause.
4795  ///
4796  /// \param StartLoc Starting location of the clause.
4797  /// \param EndLoc Ending location of the clause.
4799  : OMPClause(llvm::omp::OMPC_simd, StartLoc, EndLoc) {}
4800 
4801  /// Build an empty clause.
4803  : OMPClause(llvm::omp::OMPC_simd, SourceLocation(), SourceLocation()) {}
4804 
4807  }
4808 
4811  }
4812 
4815  }
4818  }
4819 
4820  static bool classof(const OMPClause *T) {
4821  return T->getClauseKind() == llvm::omp::OMPC_simd;
4822  }
4823 };
4824 
4825 /// Struct that defines common infrastructure to handle mappable
4826 /// expressions used in OpenMP clauses.
4828 public:
4829  /// Class that represents a component of a mappable expression. E.g.
4830  /// for an expression S.a, the first component is a declaration reference
4831  /// expression associated with 'S' and the second is a member expression
4832  /// associated with the field declaration 'a'. If the expression is an array
4833  /// subscript it may not have any associated declaration. In that case the
4834  /// associated declaration is set to nullptr.
4836  /// Pair of Expression and Non-contiguous pair associated with the
4837  /// component.
4838  llvm::PointerIntPair<Expr *, 1, bool> AssociatedExpressionNonContiguousPr;
4839 
4840  /// Declaration associated with the declaration. If the component does
4841  /// not have a declaration (e.g. array subscripts or section), this is set
4842  /// to nullptr.
4843  ValueDecl *AssociatedDeclaration = nullptr;
4844 
4845  public:
4846  explicit MappableComponent() = default;
4847  explicit MappableComponent(Expr *AssociatedExpression,
4848  ValueDecl *AssociatedDeclaration,
4849  bool IsNonContiguous)
4850  : AssociatedExpressionNonContiguousPr(AssociatedExpression,
4851  IsNonContiguous),
4852  AssociatedDeclaration(
4853  AssociatedDeclaration
4854  ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
4855  : nullptr) {}
4856 
4858  return AssociatedExpressionNonContiguousPr.getPointer();
4859  }
4860 
4861  bool isNonContiguous() const {
4862  return AssociatedExpressionNonContiguousPr.getInt();
4863  }
4864 
4866  return AssociatedDeclaration;
4867  }
4868  };
4869 
4870  // List of components of an expression. This first one is the whole
4871  // expression and the last one is the base expression.
4874 
4875  // List of all component lists associated to the same base declaration.
4876  // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
4877  // their component list but the same base declaration 'S'.
4880 
4881 protected:
4882  // Return the total number of elements in a list of component lists.
4883  static unsigned
4885 
4886  // Return the total number of elements in a list of declarations. All
4887  // declarations are expected to be canonical.
4888  static unsigned
4890 };
4891 
4892 /// This structure contains all sizes needed for by an
4893 /// OMPMappableExprListClause.
4895  /// Number of expressions listed.
4896  unsigned NumVars;
4897  /// Number of unique base declarations.
4899  /// Number of component lists.
4901  /// Total number of expression components.
4902  unsigned NumComponents;
4903  OMPMappableExprListSizeTy() = default;
4905  unsigned NumComponentLists, unsigned NumComponents)
4908 };
4909 
4910 /// This represents clauses with a list of expressions that are mappable.
4911 /// Examples of these clauses are 'map' in
4912 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
4913 /// in '#pragma omp target update...' directives.
4914 template <class T>
4917  friend class OMPClauseReader;
4918 
4919  /// Number of unique declarations in this clause.
4920  unsigned NumUniqueDeclarations;
4921 
4922  /// Number of component lists in this clause.
4923  unsigned NumComponentLists;
4924 
4925  /// Total number of components in this clause.
4926  unsigned NumComponents;
4927 
4928  /// Whether this clause is possible to have user-defined mappers associated.
4929  /// It should be true for map, to, and from clauses, and false for
4930  /// use_device_ptr and is_device_ptr.
4931  const bool SupportsMapper;
4932 
4933  /// C++ nested name specifier for the associated user-defined mapper.
4934  NestedNameSpecifierLoc MapperQualifierLoc;
4935 
4936  /// The associated user-defined mapper identifier information.
4937  DeclarationNameInfo MapperIdInfo;
4938 
4939 protected:
4940  /// Build a clause for \a NumUniqueDeclarations declarations, \a
4941  /// NumComponentLists total component lists, and \a NumComponents total
4942  /// components.
4943  ///
4944  /// \param K Kind of the clause.
4945  /// \param Locs Locations needed to build a mappable clause. It includes 1)
4946  /// StartLoc: starting location of the clause (the clause keyword); 2)
4947  /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4948  /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4949  /// NumVars: number of expressions listed in this clause; 2)
4950  /// NumUniqueDeclarations: number of unique base declarations in this clause;
4951  /// 3) NumComponentLists: number of component lists in this clause; and 4)
4952  /// NumComponents: total number of expression components in the clause.
4953  /// \param SupportsMapper Indicates whether this clause is possible to have
4954  /// user-defined mappers associated.
4955  /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
4956  /// user-defined mapper.
4957  /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
4959  OpenMPClauseKind K, const OMPVarListLocTy &Locs,
4960  const OMPMappableExprListSizeTy &Sizes, bool SupportsMapper = false,
4961  NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
4962  DeclarationNameInfo *MapperIdInfoPtr = nullptr)
4963  : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
4964  Sizes.NumVars),
4965  NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
4966  NumComponentLists(Sizes.NumComponentLists),
4967  NumComponents(Sizes.NumComponents), SupportsMapper(SupportsMapper) {
4968  if (MapperQualifierLocPtr)
4969  MapperQualifierLoc = *MapperQualifierLocPtr;
4970  if (MapperIdInfoPtr)
4971  MapperIdInfo = *MapperIdInfoPtr;
4972  }
4973 
4974  /// Get the unique declarations that are in the trailing objects of the
4975  /// class.
4978  static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
4979  NumUniqueDeclarations);
4980  }
4981 
4982  /// Get the unique declarations that are in the trailing objects of the
4983  /// class.
4985  return ArrayRef<ValueDecl *>(
4986  static_cast<const T *>(this)
4987  ->template getTrailingObjects<ValueDecl *>(),
4988  NumUniqueDeclarations);
4989  }
4990 
4991  /// Set the unique declarations that are in the trailing objects of the
4992  /// class.
4994  assert(UDs.size() == NumUniqueDeclarations &&
4995  "Unexpected amount of u