clang  9.0.0svn
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/Decl.h"
21 #include "clang/AST/Expr.h"
23 #include "clang/AST/Stmt.h"
24 #include "clang/AST/StmtIterator.h"
25 #include "clang/Basic/LLVM.h"
28 #include "llvm/ADT/ArrayRef.h"
29 #include "llvm/ADT/MapVector.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/ADT/iterator.h"
32 #include "llvm/ADT/iterator_range.h"
33 #include "llvm/Support/Casting.h"
34 #include "llvm/Support/Compiler.h"
35 #include "llvm/Support/TrailingObjects.h"
36 #include <cassert>
37 #include <cstddef>
38 #include <iterator>
39 #include <utility>
40 
41 namespace clang {
42 
43 class ASTContext;
44 
45 //===----------------------------------------------------------------------===//
46 // AST classes for clauses.
47 //===----------------------------------------------------------------------===//
48 
49 /// This is a basic class for representing single OpenMP clause.
50 class OMPClause {
51  /// Starting location of the clause (the clause keyword).
52  SourceLocation StartLoc;
53 
54  /// Ending location of the clause.
55  SourceLocation EndLoc;
56 
57  /// Kind of the clause.
59 
60 protected:
62  : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
63 
64 public:
65  /// Returns the starting location of the clause.
66  SourceLocation getBeginLoc() const { return StartLoc; }
67 
68  /// Returns the ending location of the clause.
69  SourceLocation getEndLoc() const { return EndLoc; }
70 
71  /// Sets the starting location of the clause.
72  void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
73 
74  /// Sets the ending location of the clause.
75  void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
76 
77  /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
78  OpenMPClauseKind getClauseKind() const { return Kind; }
79 
80  bool isImplicit() const { return StartLoc.isInvalid(); }
81 
84  using child_range = llvm::iterator_range<child_iterator>;
85  using const_child_range = llvm::iterator_range<const_child_iterator>;
86 
89  auto Children = const_cast<OMPClause *>(this)->children();
90  return const_child_range(Children.begin(), Children.end());
91  }
92 
93  static bool classof(const OMPClause *) { return true; }
94 };
95 
96 /// Class that handles pre-initialization statement for some clauses, like
97 /// 'shedule', 'firstprivate' etc.
99  friend class OMPClauseReader;
100 
101  /// Pre-initialization statement for the clause.
102  Stmt *PreInit = nullptr;
103 
104  /// Region that captures the associated stmt.
105  OpenMPDirectiveKind CaptureRegion = OMPD_unknown;
106 
107 protected:
109  assert(get(This) && "get is not tuned for pre-init.");
110  }
111 
112  /// Set pre-initialization statement for the clause.
113  void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion = OMPD_unknown) {
114  PreInit = S;
115  CaptureRegion = ThisRegion;
116  }
117 
118 public:
119  /// Get pre-initialization statement for the clause.
120  const Stmt *getPreInitStmt() const { return PreInit; }
121 
122  /// Get pre-initialization statement for the clause.
123  Stmt *getPreInitStmt() { return PreInit; }
124 
125  /// Get capture region for the stmt in the clause.
126  OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
127 
128  static OMPClauseWithPreInit *get(OMPClause *C);
129  static const OMPClauseWithPreInit *get(const OMPClause *C);
130 };
131 
132 /// Class that handles post-update expression for some clauses, like
133 /// 'lastprivate', 'reduction' etc.
134 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
135  friend class OMPClauseReader;
136 
137  /// Post-update expression for the clause.
138  Expr *PostUpdate = nullptr;
139 
140 protected:
141  OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
142  assert(get(This) && "get is not tuned for post-update.");
143  }
144 
145  /// Set pre-initialization statement for the clause.
146  void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
147 
148 public:
149  /// Get post-update expression for the clause.
150  const Expr *getPostUpdateExpr() const { return PostUpdate; }
152  /// Get post-update expression for the clause.
153  Expr *getPostUpdateExpr() { return PostUpdate; }
154 
155  static OMPClauseWithPostUpdate *get(OMPClause *C);
156  static const OMPClauseWithPostUpdate *get(const OMPClause *C);
157 };
158 
159 /// This structure contains most locations needed for by an OMPVarListClause.
161  /// Starting location of the clause (the clause keyword).
163  /// Location of '('.
165  /// Ending location of the clause.
167  OMPVarListLocTy() = default;
169  SourceLocation EndLoc)
170  : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {}
171 };
172 
173 /// This represents clauses with the list of variables like 'private',
174 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
175 /// '#pragma omp ...' directives.
176 template <class T> class OMPVarListClause : public OMPClause {
177  friend class OMPClauseReader;
178 
179  /// Location of '('.
180  SourceLocation LParenLoc;
181 
182  /// Number of variables in the list.
183  unsigned NumVars;
184 
185 protected:
186  /// Build a clause with \a N variables
187  ///
188  /// \param K Kind of the clause.
189  /// \param StartLoc Starting location of the clause (the clause keyword).
190  /// \param LParenLoc Location of '('.
191  /// \param EndLoc Ending location of the clause.
192  /// \param N Number of the variables in the clause.
194  SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
195  : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
196 
197  /// Fetches list of variables associated with this clause.
200  static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
201  }
202 
203  /// Sets the list of variables for this clause.
205  assert(VL.size() == NumVars &&
206  "Number of variables is not the same as the preallocated buffer");
207  std::copy(VL.begin(), VL.end(),
208  static_cast<T *>(this)->template getTrailingObjects<Expr *>());
209  }
210 
211 public:
214  using varlist_range = llvm::iterator_range<varlist_iterator>;
215  using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
216 
217  unsigned varlist_size() const { return NumVars; }
218  bool varlist_empty() const { return NumVars == 0; }
219 
221  return varlist_range(varlist_begin(), varlist_end());
222  }
224  return varlist_const_range(varlist_begin(), varlist_end());
225  }
226 
227  varlist_iterator varlist_begin() { return getVarRefs().begin(); }
228  varlist_iterator varlist_end() { return getVarRefs().end(); }
229  varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
230  varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
231 
232  /// Sets the location of '('.
233  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
234 
235  /// Returns the location of '('.
236  SourceLocation getLParenLoc() const { return LParenLoc; }
237 
238  /// Fetches list of all variables in the clause.
240  return llvm::makeArrayRef(
241  static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
242  NumVars);
243  }
244 };
245 
246 /// This represents 'allocator' clause in the '#pragma omp ...'
247 /// directive.
248 ///
249 /// \code
250 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
251 /// \endcode
252 /// In this example directive '#pragma omp allocate' has simple 'allocator'
253 /// clause with the allocator 'omp_default_mem_alloc'.
255  friend class OMPClauseReader;
256 
257  /// Location of '('.
258  SourceLocation LParenLoc;
259 
260  /// Expression with the allocator.
261  Stmt *Allocator = nullptr;
262 
263  /// Set allocator.
264  void setAllocator(Expr *A) { Allocator = A; }
265 
266 public:
267  /// Build 'allocator' clause with the given allocator.
268  ///
269  /// \param A Allocator.
270  /// \param StartLoc Starting location of the clause.
271  /// \param LParenLoc Location of '('.
272  /// \param EndLoc Ending location of the clause.
274  SourceLocation EndLoc)
275  : OMPClause(OMPC_allocator, StartLoc, EndLoc), LParenLoc(LParenLoc),
276  Allocator(A) {}
277 
278  /// Build an empty clause.
280  : OMPClause(OMPC_allocator, SourceLocation(), SourceLocation()) {}
281 
282  /// Sets the location of '('.
283  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
284 
285  /// Returns the location of '('.
286  SourceLocation getLParenLoc() const { return LParenLoc; }
287 
288  /// Returns allocator.
289  Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); }
290 
291  child_range children() { return child_range(&Allocator, &Allocator + 1); }
292 
294  return const_child_range(&Allocator, &Allocator + 1);
295  }
296 
297  static bool classof(const OMPClause *T) {
298  return T->getClauseKind() == OMPC_allocator;
299  }
300 };
301 
302 /// This represents clause 'allocate' in the '#pragma omp ...' directives.
303 ///
304 /// \code
305 /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
306 /// \endcode
307 /// In this example directive '#pragma omp parallel' has clause 'private'
308 /// and clause 'allocate' for the variable 'a'.
309 class OMPAllocateClause final
310  : public OMPVarListClause<OMPAllocateClause>,
311  private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
312  friend class OMPClauseReader;
313  friend OMPVarListClause;
314  friend TrailingObjects;
315 
316  /// Allocator specified in the clause, or 'nullptr' if the default one is
317  /// used.
318  Expr *Allocator = nullptr;
319  /// Position of the ':' delimiter in the clause;
321 
322  /// Build clause with number of variables \a N.
323  ///
324  /// \param StartLoc Starting location of the clause.
325  /// \param LParenLoc Location of '('.
326  /// \param Allocator Allocator expression.
327  /// \param ColonLoc Location of ':' delimiter.
328  /// \param EndLoc Ending location of the clause.
329  /// \param N Number of the variables in the clause.
330  OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
331  Expr *Allocator, SourceLocation ColonLoc,
332  SourceLocation EndLoc, unsigned N)
333  : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, StartLoc, LParenLoc,
334  EndLoc, N),
335  Allocator(Allocator), ColonLoc(ColonLoc) {}
336 
337  /// Build an empty clause.
338  ///
339  /// \param N Number of variables.
340  explicit OMPAllocateClause(unsigned N)
343  N) {}
344 
345  /// Sets location of ':' symbol in clause.
346  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
347 
348  void setAllocator(Expr *A) { Allocator = A; }
349 
350 public:
351  /// Creates clause with a list of variables \a VL.
352  ///
353  /// \param C AST context.
354  /// \param StartLoc Starting location of the clause.
355  /// \param LParenLoc Location of '('.
356  /// \param Allocator Allocator expression.
357  /// \param ColonLoc Location of ':' delimiter.
358  /// \param EndLoc Ending location of the clause.
359  /// \param VL List of references to the variables.
360  static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
361  SourceLocation LParenLoc, Expr *Allocator,
362  SourceLocation ColonLoc,
363  SourceLocation EndLoc, ArrayRef<Expr *> VL);
364 
365  /// Returns the allocator expression or nullptr, if no allocator is specified.
366  Expr *getAllocator() const { return Allocator; }
367 
368  /// Returns the location of the ':' delimiter.
369  SourceLocation getColonLoc() const { return ColonLoc; }
370 
371  /// Creates an empty clause with the place for \a N variables.
372  ///
373  /// \param C AST context.
374  /// \param N The number of variables.
375  static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
376 
378  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
379  reinterpret_cast<Stmt **>(varlist_end()));
380  }
381 
383  auto Children = const_cast<OMPAllocateClause *>(this)->children();
384  return const_child_range(Children.begin(), Children.end());
385  }
386 
387  static bool classof(const OMPClause *T) {
388  return T->getClauseKind() == OMPC_allocate;
389  }
390 };
391 
392 /// This represents 'if' clause in the '#pragma omp ...' directive.
393 ///
394 /// \code
395 /// #pragma omp parallel if(parallel:a > 5)
396 /// \endcode
397 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
398 /// condition 'a > 5' and directive name modifier 'parallel'.
399 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
400  friend class OMPClauseReader;
401 
402  /// Location of '('.
403  SourceLocation LParenLoc;
404 
405  /// Condition of the 'if' clause.
406  Stmt *Condition = nullptr;
407 
408  /// Location of ':' (if any).
410 
411  /// Directive name modifier for the clause.
412  OpenMPDirectiveKind NameModifier = OMPD_unknown;
413 
414  /// Name modifier location.
415  SourceLocation NameModifierLoc;
416 
417  /// Set condition.
418  void setCondition(Expr *Cond) { Condition = Cond; }
419 
420  /// Set directive name modifier for the clause.
421  void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
422 
423  /// Set location of directive name modifier for the clause.
424  void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
425 
426  /// Set location of ':'.
427  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
428 
429 public:
430  /// Build 'if' clause with condition \a Cond.
431  ///
432  /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
433  /// \param Cond Condition of the clause.
434  /// \param HelperCond Helper condition for the clause.
435  /// \param CaptureRegion Innermost OpenMP region where expressions in this
436  /// clause must be captured.
437  /// \param StartLoc Starting location of the clause.
438  /// \param LParenLoc Location of '('.
439  /// \param NameModifierLoc Location of directive name modifier.
440  /// \param ColonLoc [OpenMP 4.1] Location of ':'.
441  /// \param EndLoc Ending location of the clause.
442  OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
443  OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
444  SourceLocation LParenLoc, SourceLocation NameModifierLoc,
445  SourceLocation ColonLoc, SourceLocation EndLoc)
446  : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this),
447  LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
448  NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) {
449  setPreInitStmt(HelperCond, CaptureRegion);
450  }
451 
452  /// Build an empty clause.
454  : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
455  OMPClauseWithPreInit(this) {}
456 
457  /// Sets the location of '('.
458  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
459 
460  /// Returns the location of '('.
461  SourceLocation getLParenLoc() const { return LParenLoc; }
462 
463  /// Return the location of ':'.
464  SourceLocation getColonLoc() const { return ColonLoc; }
465 
466  /// Returns condition.
467  Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
468 
469  /// Return directive name modifier associated with the clause.
470  OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
471 
472  /// Return the location of directive name modifier.
473  SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
474 
475  child_range children() { return child_range(&Condition, &Condition + 1); }
476 
478  return const_child_range(&Condition, &Condition + 1);
479  }
480 
481  static bool classof(const OMPClause *T) {
482  return T->getClauseKind() == OMPC_if;
483  }
484 };
485 
486 /// This represents 'final' clause in the '#pragma omp ...' directive.
487 ///
488 /// \code
489 /// #pragma omp task final(a > 5)
490 /// \endcode
491 /// In this example directive '#pragma omp task' has simple 'final'
492 /// clause with condition 'a > 5'.
493 class OMPFinalClause : public OMPClause {
494  friend class OMPClauseReader;
495 
496  /// Location of '('.
497  SourceLocation LParenLoc;
498 
499  /// Condition of the 'if' clause.
500  Stmt *Condition = nullptr;
501 
502  /// Set condition.
503  void setCondition(Expr *Cond) { Condition = Cond; }
504 
505 public:
506  /// Build 'final' clause with condition \a Cond.
507  ///
508  /// \param StartLoc Starting location of the clause.
509  /// \param LParenLoc Location of '('.
510  /// \param Cond Condition of the clause.
511  /// \param EndLoc Ending location of the clause.
512  OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
513  SourceLocation EndLoc)
514  : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
515  Condition(Cond) {}
516 
517  /// Build an empty clause.
519  : OMPClause(OMPC_final, SourceLocation(), SourceLocation()) {}
520 
521  /// Sets the location of '('.
522  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
523 
524  /// Returns the location of '('.
525  SourceLocation getLParenLoc() const { return LParenLoc; }
526 
527  /// Returns condition.
528  Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
529 
530  child_range children() { return child_range(&Condition, &Condition + 1); }
531 
533  return const_child_range(&Condition, &Condition + 1);
534  }
535 
536  static bool classof(const OMPClause *T) {
537  return T->getClauseKind() == OMPC_final;
538  }
539 };
540 
541 /// This represents 'num_threads' clause in the '#pragma omp ...'
542 /// directive.
543 ///
544 /// \code
545 /// #pragma omp parallel num_threads(6)
546 /// \endcode
547 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
548 /// clause with number of threads '6'.
549 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
550  friend class OMPClauseReader;
551 
552  /// Location of '('.
553  SourceLocation LParenLoc;
554 
555  /// Condition of the 'num_threads' clause.
556  Stmt *NumThreads = nullptr;
557 
558  /// Set condition.
559  void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
560 
561 public:
562  /// Build 'num_threads' clause with condition \a NumThreads.
563  ///
564  /// \param NumThreads Number of threads for the construct.
565  /// \param HelperNumThreads Helper Number of threads for the construct.
566  /// \param CaptureRegion Innermost OpenMP region where expressions in this
567  /// clause must be captured.
568  /// \param StartLoc Starting location of the clause.
569  /// \param LParenLoc Location of '('.
570  /// \param EndLoc Ending location of the clause.
571  OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
572  OpenMPDirectiveKind CaptureRegion,
573  SourceLocation StartLoc, SourceLocation LParenLoc,
574  SourceLocation EndLoc)
575  : OMPClause(OMPC_num_threads, StartLoc, EndLoc),
576  OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
577  NumThreads(NumThreads) {
578  setPreInitStmt(HelperNumThreads, CaptureRegion);
579  }
580 
581  /// Build an empty clause.
583  : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
584  OMPClauseWithPreInit(this) {}
585 
586  /// Sets the location of '('.
587  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
588 
589  /// Returns the location of '('.
590  SourceLocation getLParenLoc() const { return LParenLoc; }
591 
592  /// Returns number of threads.
593  Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
594 
595  child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
596 
598  return const_child_range(&NumThreads, &NumThreads + 1);
599  }
600 
601  static bool classof(const OMPClause *T) {
602  return T->getClauseKind() == OMPC_num_threads;
603  }
604 };
605 
606 /// This represents 'safelen' clause in the '#pragma omp ...'
607 /// directive.
608 ///
609 /// \code
610 /// #pragma omp simd safelen(4)
611 /// \endcode
612 /// In this example directive '#pragma omp simd' has clause 'safelen'
613 /// with single expression '4'.
614 /// If the safelen clause is used then no two iterations executed
615 /// concurrently with SIMD instructions can have a greater distance
616 /// in the logical iteration space than its value. The parameter of
617 /// the safelen clause must be a constant positive integer expression.
618 class OMPSafelenClause : public OMPClause {
619  friend class OMPClauseReader;
620 
621  /// Location of '('.
622  SourceLocation LParenLoc;
623 
624  /// Safe iteration space distance.
625  Stmt *Safelen = nullptr;
626 
627  /// Set safelen.
628  void setSafelen(Expr *Len) { Safelen = Len; }
629 
630 public:
631  /// Build 'safelen' clause.
632  ///
633  /// \param Len Expression associated with this clause.
634  /// \param StartLoc Starting location of the clause.
635  /// \param EndLoc Ending location of the clause.
637  SourceLocation EndLoc)
638  : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
639  Safelen(Len) {}
640 
641  /// Build an empty clause.
642  explicit OMPSafelenClause()
643  : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()) {}
644 
645  /// Sets the location of '('.
646  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
647 
648  /// Returns the location of '('.
649  SourceLocation getLParenLoc() const { return LParenLoc; }
650 
651  /// Return safe iteration space distance.
652  Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
653 
654  child_range children() { return child_range(&Safelen, &Safelen + 1); }
655 
657  return const_child_range(&Safelen, &Safelen + 1);
658  }
659 
660  static bool classof(const OMPClause *T) {
661  return T->getClauseKind() == OMPC_safelen;
662  }
663 };
664 
665 /// This represents 'simdlen' clause in the '#pragma omp ...'
666 /// directive.
667 ///
668 /// \code
669 /// #pragma omp simd simdlen(4)
670 /// \endcode
671 /// In this example directive '#pragma omp simd' has clause 'simdlen'
672 /// with single expression '4'.
673 /// If the 'simdlen' clause is used then it specifies the preferred number of
674 /// iterations to be executed concurrently. The parameter of the 'simdlen'
675 /// clause must be a constant positive integer expression.
676 class OMPSimdlenClause : public OMPClause {
677  friend class OMPClauseReader;
678 
679  /// Location of '('.
680  SourceLocation LParenLoc;
681 
682  /// Safe iteration space distance.
683  Stmt *Simdlen = nullptr;
684 
685  /// Set simdlen.
686  void setSimdlen(Expr *Len) { Simdlen = Len; }
687 
688 public:
689  /// Build 'simdlen' 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(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
697  Simdlen(Len) {}
698 
699  /// Build an empty clause.
700  explicit OMPSimdlenClause()
701  : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()) {}
702 
703  /// Sets the location of '('.
704  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
705 
706  /// Returns the location of '('.
707  SourceLocation getLParenLoc() const { return LParenLoc; }
708 
709  /// Return safe iteration space distance.
710  Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
711 
712  child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
713 
715  return const_child_range(&Simdlen, &Simdlen + 1);
716  }
717 
718  static bool classof(const OMPClause *T) {
719  return T->getClauseKind() == OMPC_simdlen;
720  }
721 };
722 
723 /// This represents 'collapse' clause in the '#pragma omp ...'
724 /// directive.
725 ///
726 /// \code
727 /// #pragma omp simd collapse(3)
728 /// \endcode
729 /// In this example directive '#pragma omp simd' has clause 'collapse'
730 /// with single expression '3'.
731 /// The parameter must be a constant positive integer expression, it specifies
732 /// the number of nested loops that should be collapsed into a single iteration
733 /// space.
734 class OMPCollapseClause : public OMPClause {
735  friend class OMPClauseReader;
736 
737  /// Location of '('.
738  SourceLocation LParenLoc;
739 
740  /// Number of for-loops.
741  Stmt *NumForLoops = nullptr;
742 
743  /// Set the number of associated for-loops.
744  void setNumForLoops(Expr *Num) { NumForLoops = Num; }
745 
746 public:
747  /// Build 'collapse' clause.
748  ///
749  /// \param Num Expression associated with this clause.
750  /// \param StartLoc Starting location of the clause.
751  /// \param LParenLoc Location of '('.
752  /// \param EndLoc Ending location of the clause.
754  SourceLocation LParenLoc, SourceLocation EndLoc)
755  : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
756  NumForLoops(Num) {}
757 
758  /// Build an empty clause.
759  explicit OMPCollapseClause()
760  : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()) {}
761 
762  /// Sets the location of '('.
763  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
764 
765  /// Returns the location of '('.
766  SourceLocation getLParenLoc() const { return LParenLoc; }
767 
768  /// Return the number of associated for-loops.
769  Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
770 
771  child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
772 
774  return const_child_range(&NumForLoops, &NumForLoops + 1);
775  }
776 
777  static bool classof(const OMPClause *T) {
778  return T->getClauseKind() == OMPC_collapse;
779  }
780 };
781 
782 /// This represents 'default' clause in the '#pragma omp ...' directive.
783 ///
784 /// \code
785 /// #pragma omp parallel default(shared)
786 /// \endcode
787 /// In this example directive '#pragma omp parallel' has simple 'default'
788 /// clause with kind 'shared'.
789 class OMPDefaultClause : public OMPClause {
790  friend class OMPClauseReader;
791 
792  /// Location of '('.
793  SourceLocation LParenLoc;
794 
795  /// A kind of the 'default' clause.
797 
798  /// Start location of the kind in source code.
799  SourceLocation KindKwLoc;
800 
801  /// Set kind of the clauses.
802  ///
803  /// \param K Argument of clause.
804  void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
805 
806  /// Set argument location.
807  ///
808  /// \param KLoc Argument location.
809  void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
810 
811 public:
812  /// Build 'default' clause with argument \a A ('none' or 'shared').
813  ///
814  /// \param A Argument of the clause ('none' or 'shared').
815  /// \param ALoc Starting location of the argument.
816  /// \param StartLoc Starting location of the clause.
817  /// \param LParenLoc Location of '('.
818  /// \param EndLoc Ending location of the clause.
820  SourceLocation StartLoc, SourceLocation LParenLoc,
821  SourceLocation EndLoc)
822  : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
823  Kind(A), KindKwLoc(ALoc) {}
824 
825  /// Build an empty clause.
827  : OMPClause(OMPC_default, SourceLocation(), SourceLocation()) {}
828 
829  /// Sets the location of '('.
830  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
831 
832  /// Returns the location of '('.
833  SourceLocation getLParenLoc() const { return LParenLoc; }
834 
835  /// Returns kind of the clause.
837 
838  /// Returns location of clause kind.
839  SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
840 
843  }
844 
847  }
848 
849  static bool classof(const OMPClause *T) {
850  return T->getClauseKind() == OMPC_default;
851  }
852 };
853 
854 /// This represents 'proc_bind' clause in the '#pragma omp ...'
855 /// directive.
856 ///
857 /// \code
858 /// #pragma omp parallel proc_bind(master)
859 /// \endcode
860 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
861 /// clause with kind 'master'.
862 class OMPProcBindClause : public OMPClause {
863  friend class OMPClauseReader;
864 
865  /// Location of '('.
866  SourceLocation LParenLoc;
867 
868  /// A kind of the 'proc_bind' clause.
870 
871  /// Start location of the kind in source code.
872  SourceLocation KindKwLoc;
873 
874  /// Set kind of the clause.
875  ///
876  /// \param K Kind of clause.
877  void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
878 
879  /// Set clause kind location.
880  ///
881  /// \param KLoc Kind location.
882  void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
883 
884 public:
885  /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
886  /// 'spread').
887  ///
888  /// \param A Argument of the clause ('master', 'close' or 'spread').
889  /// \param ALoc Starting location of the argument.
890  /// \param StartLoc Starting location of the clause.
891  /// \param LParenLoc Location of '('.
892  /// \param EndLoc Ending location of the clause.
894  SourceLocation StartLoc, SourceLocation LParenLoc,
895  SourceLocation EndLoc)
896  : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
897  Kind(A), KindKwLoc(ALoc) {}
898 
899  /// Build an empty clause.
901  : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()) {}
902 
903  /// Sets the location of '('.
904  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
905 
906  /// Returns the location of '('.
907  SourceLocation getLParenLoc() const { return LParenLoc; }
908 
909  /// Returns kind of the clause.
911 
912  /// Returns location of clause kind.
913  SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
914 
917  }
918 
921  }
922 
923  static bool classof(const OMPClause *T) {
924  return T->getClauseKind() == OMPC_proc_bind;
925  }
926 };
927 
928 /// This represents 'unified_address' clause in the '#pragma omp requires'
929 /// directive.
930 ///
931 /// \code
932 /// #pragma omp requires unified_address
933 /// \endcode
934 /// In this example directive '#pragma omp requires' has 'unified_address'
935 /// clause.
936 class OMPUnifiedAddressClause final : public OMPClause {
937 public:
938  friend class OMPClauseReader;
939  /// Build 'unified_address' clause.
940  ///
941  /// \param StartLoc Starting location of the clause.
942  /// \param EndLoc Ending location of the clause.
944  : OMPClause(OMPC_unified_address, StartLoc, EndLoc) {}
945 
946  /// Build an empty clause.
948  : OMPClause(OMPC_unified_address, SourceLocation(), SourceLocation()) {}
949 
952  }
953 
956  }
957 
958  static bool classof(const OMPClause *T) {
959  return T->getClauseKind() == OMPC_unified_address;
960  }
961 };
962 
963 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
964 /// directive.
965 ///
966 /// \code
967 /// #pragma omp requires unified_shared_memory
968 /// \endcode
969 /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
970 /// clause.
972 public:
973  friend class OMPClauseReader;
974  /// Build 'unified_shared_memory' clause.
975  ///
976  /// \param StartLoc Starting location of the clause.
977  /// \param EndLoc Ending location of the clause.
979  : OMPClause(OMPC_unified_shared_memory, StartLoc, EndLoc) {}
980 
981  /// Build an empty clause.
983  : OMPClause(OMPC_unified_shared_memory, SourceLocation(), SourceLocation()) {}
984 
987  }
988 
991  }
992 
993  static bool classof(const OMPClause *T) {
994  return T->getClauseKind() == OMPC_unified_shared_memory;
995  }
996 };
997 
998 /// This represents 'reverse_offload' clause in the '#pragma omp requires'
999 /// directive.
1000 ///
1001 /// \code
1002 /// #pragma omp requires reverse_offload
1003 /// \endcode
1004 /// In this example directive '#pragma omp requires' has 'reverse_offload'
1005 /// clause.
1006 class OMPReverseOffloadClause final : public OMPClause {
1007 public:
1008  friend class OMPClauseReader;
1009  /// Build 'reverse_offload' clause.
1010  ///
1011  /// \param StartLoc Starting location of the clause.
1012  /// \param EndLoc Ending location of the clause.
1014  : OMPClause(OMPC_reverse_offload, StartLoc, EndLoc) {}
1015 
1016  /// Build an empty clause.
1018  : OMPClause(OMPC_reverse_offload, SourceLocation(), SourceLocation()) {}
1019 
1022  }
1023 
1026  }
1027 
1028  static bool classof(const OMPClause *T) {
1029  return T->getClauseKind() == OMPC_reverse_offload;
1030  }
1031 };
1032 
1033 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1034 /// directive.
1035 ///
1036 /// \code
1037 /// #pragma omp requires dynamic_allocators
1038 /// \endcode
1039 /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1040 /// clause.
1042 public:
1043  friend class OMPClauseReader;
1044  /// Build 'dynamic_allocators' clause.
1045  ///
1046  /// \param StartLoc Starting location of the clause.
1047  /// \param EndLoc Ending location of the clause.
1049  : OMPClause(OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1050 
1051  /// Build an empty clause.
1053  : OMPClause(OMPC_dynamic_allocators, SourceLocation(), SourceLocation()) {
1054  }
1055 
1058  }
1059 
1062  }
1063 
1064  static bool classof(const OMPClause *T) {
1065  return T->getClauseKind() == OMPC_dynamic_allocators;
1066  }
1067 };
1068 
1069 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1070 /// requires' directive.
1071 ///
1072 /// \code
1073 /// #pragma omp requires atomic_default_mem_order(seq_cst)
1074 /// \endcode
1075 /// In this example directive '#pragma omp requires' has simple
1076 /// atomic_default_mem_order' clause with kind 'seq_cst'.
1078  friend class OMPClauseReader;
1079 
1080  /// Location of '('
1081  SourceLocation LParenLoc;
1082 
1083  /// A kind of the 'atomic_default_mem_order' clause.
1086 
1087  /// Start location of the kind in source code.
1088  SourceLocation KindKwLoc;
1089 
1090  /// Set kind of the clause.
1091  ///
1092  /// \param K Kind of clause.
1093  void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1094  Kind = K;
1095  }
1096 
1097  /// Set clause kind location.
1098  ///
1099  /// \param KLoc Kind location.
1100  void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1101  KindKwLoc = KLoc;
1102  }
1103 
1104 public:
1105  /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1106  /// 'acq_rel' or 'relaxed').
1107  ///
1108  /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1109  /// \param ALoc Starting location of the argument.
1110  /// \param StartLoc Starting location of the clause.
1111  /// \param LParenLoc Location of '('.
1112  /// \param EndLoc Ending location of the clause.
1114  SourceLocation ALoc, SourceLocation StartLoc,
1115  SourceLocation LParenLoc,
1116  SourceLocation EndLoc)
1117  : OMPClause(OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1118  LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1119 
1120  /// Build an empty clause.
1122  : OMPClause(OMPC_atomic_default_mem_order, SourceLocation(),
1123  SourceLocation()) {}
1124 
1125  /// Sets the location of '('.
1126  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1127 
1128  /// Returns the locaiton of '('.
1129  SourceLocation getLParenLoc() const { return LParenLoc; }
1130 
1131  /// Returns kind of the clause.
1133  return Kind;
1134  }
1135 
1136  /// Returns location of clause kind.
1138 
1141  }
1142 
1145  }
1146 
1147  static bool classof(const OMPClause *T) {
1148  return T->getClauseKind() == OMPC_atomic_default_mem_order;
1149  }
1150 };
1151 
1152 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
1153 ///
1154 /// \code
1155 /// #pragma omp for schedule(static, 3)
1156 /// \endcode
1157 /// In this example directive '#pragma omp for' has 'schedule' clause with
1158 /// arguments 'static' and '3'.
1159 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
1160  friend class OMPClauseReader;
1161 
1162  /// Location of '('.
1163  SourceLocation LParenLoc;
1164 
1165  /// A kind of the 'schedule' clause.
1167 
1168  /// Modifiers for 'schedule' clause.
1169  enum {FIRST, SECOND, NUM_MODIFIERS};
1170  OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1171 
1172  /// Locations of modifiers.
1173  SourceLocation ModifiersLoc[NUM_MODIFIERS];
1174 
1175  /// Start location of the schedule ind in source code.
1176  SourceLocation KindLoc;
1177 
1178  /// Location of ',' (if any).
1179  SourceLocation CommaLoc;
1180 
1181  /// Chunk size.
1182  Expr *ChunkSize = nullptr;
1183 
1184  /// Set schedule kind.
1185  ///
1186  /// \param K Schedule kind.
1187  void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1188 
1189  /// Set the first schedule modifier.
1190  ///
1191  /// \param M Schedule modifier.
1192  void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1193  Modifiers[FIRST] = M;
1194  }
1195 
1196  /// Set the second schedule modifier.
1197  ///
1198  /// \param M Schedule modifier.
1199  void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1200  Modifiers[SECOND] = M;
1201  }
1202 
1203  /// Set location of the first schedule modifier.
1204  void setFirstScheduleModifierLoc(SourceLocation Loc) {
1205  ModifiersLoc[FIRST] = Loc;
1206  }
1207 
1208  /// Set location of the second schedule modifier.
1209  void setSecondScheduleModifierLoc(SourceLocation Loc) {
1210  ModifiersLoc[SECOND] = Loc;
1211  }
1212 
1213  /// Set schedule modifier location.
1214  ///
1215  /// \param M Schedule modifier location.
1216  void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1217  if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1218  Modifiers[FIRST] = M;
1219  else {
1220  assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1221  Modifiers[SECOND] = M;
1222  }
1223  }
1224 
1225  /// Sets the location of '('.
1226  ///
1227  /// \param Loc Location of '('.
1228  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1229 
1230  /// Set schedule kind start location.
1231  ///
1232  /// \param KLoc Schedule kind location.
1233  void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1234 
1235  /// Set location of ','.
1236  ///
1237  /// \param Loc Location of ','.
1238  void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1239 
1240  /// Set chunk size.
1241  ///
1242  /// \param E Chunk size.
1243  void setChunkSize(Expr *E) { ChunkSize = E; }
1244 
1245 public:
1246  /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1247  /// expression \a ChunkSize.
1248  ///
1249  /// \param StartLoc Starting location of the clause.
1250  /// \param LParenLoc Location of '('.
1251  /// \param KLoc Starting location of the argument.
1252  /// \param CommaLoc Location of ','.
1253  /// \param EndLoc Ending location of the clause.
1254  /// \param Kind Schedule kind.
1255  /// \param ChunkSize Chunk size.
1256  /// \param HelperChunkSize Helper chunk size for combined directives.
1257  /// \param M1 The first modifier applied to 'schedule' clause.
1258  /// \param M1Loc Location of the first modifier
1259  /// \param M2 The second modifier applied to 'schedule' clause.
1260  /// \param M2Loc Location of the second modifier
1262  SourceLocation KLoc, SourceLocation CommaLoc,
1264  Expr *ChunkSize, Stmt *HelperChunkSize,
1267  : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this),
1268  LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc),
1269  ChunkSize(ChunkSize) {
1270  setPreInitStmt(HelperChunkSize);
1271  Modifiers[FIRST] = M1;
1272  Modifiers[SECOND] = M2;
1273  ModifiersLoc[FIRST] = M1Loc;
1274  ModifiersLoc[SECOND] = M2Loc;
1275  }
1276 
1277  /// Build an empty clause.
1279  : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
1280  OMPClauseWithPreInit(this) {
1281  Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1282  Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1283  }
1284 
1285  /// Get kind of the clause.
1287 
1288  /// Get the first modifier of the clause.
1290  return Modifiers[FIRST];
1291  }
1292 
1293  /// Get the second modifier of the clause.
1295  return Modifiers[SECOND];
1296  }
1297 
1298  /// Get location of '('.
1299  SourceLocation getLParenLoc() { return LParenLoc; }
1300 
1301  /// Get kind location.
1302  SourceLocation getScheduleKindLoc() { return KindLoc; }
1303 
1304  /// Get the first modifier location.
1306  return ModifiersLoc[FIRST];
1307  }
1308 
1309  /// Get the second modifier location.
1311  return ModifiersLoc[SECOND];
1312  }
1313 
1314  /// Get location of ','.
1315  SourceLocation getCommaLoc() { return CommaLoc; }
1316 
1317  /// Get chunk size.
1318  Expr *getChunkSize() { return ChunkSize; }
1319 
1320  /// Get chunk size.
1321  const Expr *getChunkSize() const { return ChunkSize; }
1322 
1324  return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1325  reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1326  }
1327 
1329  auto Children = const_cast<OMPScheduleClause *>(this)->children();
1330  return const_child_range(Children.begin(), Children.end());
1331  }
1332 
1333  static bool classof(const OMPClause *T) {
1334  return T->getClauseKind() == OMPC_schedule;
1335  }
1336 };
1337 
1338 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1339 ///
1340 /// \code
1341 /// #pragma omp for ordered (2)
1342 /// \endcode
1343 /// In this example directive '#pragma omp for' has 'ordered' clause with
1344 /// parameter 2.
1345 class OMPOrderedClause final
1346  : public OMPClause,
1347  private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1348  friend class OMPClauseReader;
1349  friend TrailingObjects;
1350 
1351  /// Location of '('.
1352  SourceLocation LParenLoc;
1353 
1354  /// Number of for-loops.
1355  Stmt *NumForLoops = nullptr;
1356 
1357  /// Real number of loops.
1358  unsigned NumberOfLoops = 0;
1359 
1360  /// Build 'ordered' clause.
1361  ///
1362  /// \param Num Expression, possibly associated with this clause.
1363  /// \param NumLoops Number of loops, associated with this clause.
1364  /// \param StartLoc Starting location of the clause.
1365  /// \param LParenLoc Location of '('.
1366  /// \param EndLoc Ending location of the clause.
1367  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1368  SourceLocation LParenLoc, SourceLocation EndLoc)
1369  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
1370  NumForLoops(Num), NumberOfLoops(NumLoops) {}
1371 
1372  /// Build an empty clause.
1373  explicit OMPOrderedClause(unsigned NumLoops)
1374  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
1375  NumberOfLoops(NumLoops) {}
1376 
1377  /// Set the number of associated for-loops.
1378  void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1379 
1380 public:
1381  /// Build 'ordered' clause.
1382  ///
1383  /// \param Num Expression, possibly associated with this clause.
1384  /// \param NumLoops Number of loops, associated with this clause.
1385  /// \param StartLoc Starting location of the clause.
1386  /// \param LParenLoc Location of '('.
1387  /// \param EndLoc Ending location of the clause.
1388  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1389  unsigned NumLoops, SourceLocation StartLoc,
1390  SourceLocation LParenLoc,
1391  SourceLocation EndLoc);
1392 
1393  /// Build an empty clause.
1394  static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1395 
1396  /// Sets the location of '('.
1397  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1398 
1399  /// Returns the location of '('.
1400  SourceLocation getLParenLoc() const { return LParenLoc; }
1401 
1402  /// Return the number of associated for-loops.
1403  Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1404 
1405  /// Set number of iterations for the specified loop.
1406  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1407  /// Get number of iterations for all the loops.
1408  ArrayRef<Expr *> getLoopNumIterations() const;
1409 
1410  /// Set loop counter for the specified loop.
1411  void setLoopCounter(unsigned NumLoop, Expr *Counter);
1412  /// Get loops counter for the specified loop.
1413  Expr *getLoopCounter(unsigned NumLoop);
1414  const Expr *getLoopCounter(unsigned NumLoop) const;
1415 
1416  child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1417 
1419  return const_child_range(&NumForLoops, &NumForLoops + 1);
1420  }
1421 
1422  static bool classof(const OMPClause *T) {
1423  return T->getClauseKind() == OMPC_ordered;
1424  }
1425 };
1426 
1427 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1428 ///
1429 /// \code
1430 /// #pragma omp for nowait
1431 /// \endcode
1432 /// In this example directive '#pragma omp for' has 'nowait' clause.
1433 class OMPNowaitClause : public OMPClause {
1434 public:
1435  /// Build 'nowait' clause.
1436  ///
1437  /// \param StartLoc Starting location of the clause.
1438  /// \param EndLoc Ending location of the clause.
1440  : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
1441 
1442  /// Build an empty clause.
1444  : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
1445 
1448  }
1449 
1452  }
1453 
1454  static bool classof(const OMPClause *T) {
1455  return T->getClauseKind() == OMPC_nowait;
1456  }
1457 };
1458 
1459 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1460 ///
1461 /// \code
1462 /// #pragma omp task untied
1463 /// \endcode
1464 /// In this example directive '#pragma omp task' has 'untied' clause.
1465 class OMPUntiedClause : public OMPClause {
1466 public:
1467  /// Build 'untied' clause.
1468  ///
1469  /// \param StartLoc Starting location of the clause.
1470  /// \param EndLoc Ending location of the clause.
1472  : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
1473 
1474  /// Build an empty clause.
1476  : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
1477 
1480  }
1481 
1484  }
1485 
1486  static bool classof(const OMPClause *T) {
1487  return T->getClauseKind() == OMPC_untied;
1488  }
1489 };
1490 
1491 /// This represents 'mergeable' clause in the '#pragma omp ...'
1492 /// directive.
1493 ///
1494 /// \code
1495 /// #pragma omp task mergeable
1496 /// \endcode
1497 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1499 public:
1500  /// Build 'mergeable' clause.
1501  ///
1502  /// \param StartLoc Starting location of the clause.
1503  /// \param EndLoc Ending location of the clause.
1505  : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
1506 
1507  /// Build an empty clause.
1509  : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
1510 
1513  }
1514 
1517  }
1518 
1519  static bool classof(const OMPClause *T) {
1520  return T->getClauseKind() == OMPC_mergeable;
1521  }
1522 };
1523 
1524 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1525 ///
1526 /// \code
1527 /// #pragma omp atomic read
1528 /// \endcode
1529 /// In this example directive '#pragma omp atomic' has 'read' clause.
1530 class OMPReadClause : public OMPClause {
1531 public:
1532  /// Build 'read' clause.
1533  ///
1534  /// \param StartLoc Starting location of the clause.
1535  /// \param EndLoc Ending location of the clause.
1537  : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1538 
1539  /// Build an empty clause.
1541 
1544  }
1545 
1548  }
1549 
1550  static bool classof(const OMPClause *T) {
1551  return T->getClauseKind() == OMPC_read;
1552  }
1553 };
1554 
1555 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1556 ///
1557 /// \code
1558 /// #pragma omp atomic write
1559 /// \endcode
1560 /// In this example directive '#pragma omp atomic' has 'write' clause.
1561 class OMPWriteClause : public OMPClause {
1562 public:
1563  /// Build 'write' clause.
1564  ///
1565  /// \param StartLoc Starting location of the clause.
1566  /// \param EndLoc Ending location of the clause.
1568  : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1569 
1570  /// Build an empty clause.
1572  : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1573 
1576  }
1577 
1580  }
1581 
1582  static bool classof(const OMPClause *T) {
1583  return T->getClauseKind() == OMPC_write;
1584  }
1585 };
1586 
1587 /// This represents 'update' clause in the '#pragma omp atomic'
1588 /// directive.
1589 ///
1590 /// \code
1591 /// #pragma omp atomic update
1592 /// \endcode
1593 /// In this example directive '#pragma omp atomic' has 'update' clause.
1594 class OMPUpdateClause : public OMPClause {
1595 public:
1596  /// Build 'update' clause.
1597  ///
1598  /// \param StartLoc Starting location of the clause.
1599  /// \param EndLoc Ending location of the clause.
1601  : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1602 
1603  /// Build an empty clause.
1605  : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1606 
1609  }
1610 
1613  }
1614 
1615  static bool classof(const OMPClause *T) {
1616  return T->getClauseKind() == OMPC_update;
1617  }
1618 };
1619 
1620 /// This represents 'capture' clause in the '#pragma omp atomic'
1621 /// directive.
1622 ///
1623 /// \code
1624 /// #pragma omp atomic capture
1625 /// \endcode
1626 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1627 class OMPCaptureClause : public OMPClause {
1628 public:
1629  /// Build 'capture' clause.
1630  ///
1631  /// \param StartLoc Starting location of the clause.
1632  /// \param EndLoc Ending location of the clause.
1634  : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1635 
1636  /// Build an empty clause.
1638  : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1639 
1642  }
1643 
1646  }
1647 
1648  static bool classof(const OMPClause *T) {
1649  return T->getClauseKind() == OMPC_capture;
1650  }
1651 };
1652 
1653 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
1654 /// directive.
1655 ///
1656 /// \code
1657 /// #pragma omp atomic seq_cst
1658 /// \endcode
1659 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1660 class OMPSeqCstClause : public OMPClause {
1661 public:
1662  /// Build 'seq_cst' clause.
1663  ///
1664  /// \param StartLoc Starting location of the clause.
1665  /// \param EndLoc Ending location of the clause.
1667  : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1668 
1669  /// Build an empty clause.
1671  : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1672 
1675  }
1676 
1679  }
1680 
1681  static bool classof(const OMPClause *T) {
1682  return T->getClauseKind() == OMPC_seq_cst;
1683  }
1684 };
1685 
1686 /// This represents clause 'private' in the '#pragma omp ...' directives.
1687 ///
1688 /// \code
1689 /// #pragma omp parallel private(a,b)
1690 /// \endcode
1691 /// In this example directive '#pragma omp parallel' has clause 'private'
1692 /// with the variables 'a' and 'b'.
1693 class OMPPrivateClause final
1694  : public OMPVarListClause<OMPPrivateClause>,
1695  private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1696  friend class OMPClauseReader;
1697  friend OMPVarListClause;
1698  friend TrailingObjects;
1699 
1700  /// Build clause with number of variables \a N.
1701  ///
1702  /// \param StartLoc Starting location of the clause.
1703  /// \param LParenLoc Location of '('.
1704  /// \param EndLoc Ending location of the clause.
1705  /// \param N Number of the variables in the clause.
1706  OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1707  SourceLocation EndLoc, unsigned N)
1708  : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1709  EndLoc, N) {}
1710 
1711  /// Build an empty clause.
1712  ///
1713  /// \param N Number of variables.
1714  explicit OMPPrivateClause(unsigned N)
1717  N) {}
1718 
1719  /// Sets the list of references to private copies with initializers for
1720  /// new private variables.
1721  /// \param VL List of references.
1722  void setPrivateCopies(ArrayRef<Expr *> VL);
1723 
1724  /// Gets the list of references to private copies with initializers for
1725  /// new private variables.
1726  MutableArrayRef<Expr *> getPrivateCopies() {
1727  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1728  }
1729  ArrayRef<const Expr *> getPrivateCopies() const {
1730  return llvm::makeArrayRef(varlist_end(), varlist_size());
1731  }
1732 
1733 public:
1734  /// Creates clause with a list of variables \a VL.
1735  ///
1736  /// \param C AST context.
1737  /// \param StartLoc Starting location of the clause.
1738  /// \param LParenLoc Location of '('.
1739  /// \param EndLoc Ending location of the clause.
1740  /// \param VL List of references to the variables.
1741  /// \param PrivateVL List of references to private copies with initializers.
1742  static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1743  SourceLocation LParenLoc,
1744  SourceLocation EndLoc, ArrayRef<Expr *> VL,
1745  ArrayRef<Expr *> PrivateVL);
1746 
1747  /// Creates an empty clause with the place for \a N variables.
1748  ///
1749  /// \param C AST context.
1750  /// \param N The number of variables.
1751  static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1752 
1755  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1757  llvm::iterator_range<private_copies_const_iterator>;
1758 
1760  return private_copies_range(getPrivateCopies().begin(),
1761  getPrivateCopies().end());
1762  }
1763 
1765  return private_copies_const_range(getPrivateCopies().begin(),
1766  getPrivateCopies().end());
1767  }
1768 
1770  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1771  reinterpret_cast<Stmt **>(varlist_end()));
1772  }
1773 
1775  auto Children = const_cast<OMPPrivateClause *>(this)->children();
1776  return const_child_range(Children.begin(), Children.end());
1777  }
1778 
1779  static bool classof(const OMPClause *T) {
1780  return T->getClauseKind() == OMPC_private;
1781  }
1782 };
1783 
1784 /// This represents clause 'firstprivate' in the '#pragma omp ...'
1785 /// directives.
1786 ///
1787 /// \code
1788 /// #pragma omp parallel firstprivate(a,b)
1789 /// \endcode
1790 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1791 /// with the variables 'a' and 'b'.
1793  : public OMPVarListClause<OMPFirstprivateClause>,
1794  public OMPClauseWithPreInit,
1795  private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1796  friend class OMPClauseReader;
1797  friend OMPVarListClause;
1798  friend TrailingObjects;
1799 
1800  /// Build clause with number of variables \a N.
1801  ///
1802  /// \param StartLoc Starting location of the clause.
1803  /// \param LParenLoc Location of '('.
1804  /// \param EndLoc Ending location of the clause.
1805  /// \param N Number of the variables in the clause.
1807  SourceLocation EndLoc, unsigned N)
1808  : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1809  LParenLoc, EndLoc, N),
1810  OMPClauseWithPreInit(this) {}
1811 
1812  /// Build an empty clause.
1813  ///
1814  /// \param N Number of variables.
1815  explicit OMPFirstprivateClause(unsigned N)
1817  OMPC_firstprivate, SourceLocation(), SourceLocation(),
1818  SourceLocation(), N),
1819  OMPClauseWithPreInit(this) {}
1820 
1821  /// Sets the list of references to private copies with initializers for
1822  /// new private variables.
1823  /// \param VL List of references.
1824  void setPrivateCopies(ArrayRef<Expr *> VL);
1825 
1826  /// Gets the list of references to private copies with initializers for
1827  /// new private variables.
1828  MutableArrayRef<Expr *> getPrivateCopies() {
1829  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1830  }
1831  ArrayRef<const Expr *> getPrivateCopies() const {
1832  return llvm::makeArrayRef(varlist_end(), varlist_size());
1833  }
1834 
1835  /// Sets the list of references to initializer variables for new
1836  /// private variables.
1837  /// \param VL List of references.
1838  void setInits(ArrayRef<Expr *> VL);
1839 
1840  /// Gets the list of references to initializer variables for new
1841  /// private variables.
1843  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1844  }
1846  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1847  }
1848 
1849 public:
1850  /// Creates clause with a list of variables \a VL.
1851  ///
1852  /// \param C AST context.
1853  /// \param StartLoc Starting location of the clause.
1854  /// \param LParenLoc Location of '('.
1855  /// \param EndLoc Ending location of the clause.
1856  /// \param VL List of references to the original variables.
1857  /// \param PrivateVL List of references to private copies with initializers.
1858  /// \param InitVL List of references to auto generated variables used for
1859  /// initialization of a single array element. Used if firstprivate variable is
1860  /// of array type.
1861  /// \param PreInit Statement that must be executed before entering the OpenMP
1862  /// region with this clause.
1863  static OMPFirstprivateClause *
1864  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1865  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1866  ArrayRef<Expr *> InitVL, Stmt *PreInit);
1867 
1868  /// Creates an empty clause with the place for \a N variables.
1869  ///
1870  /// \param C AST context.
1871  /// \param N The number of variables.
1872  static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1873 
1876  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1878  llvm::iterator_range<private_copies_const_iterator>;
1879 
1881  return private_copies_range(getPrivateCopies().begin(),
1882  getPrivateCopies().end());
1883  }
1885  return private_copies_const_range(getPrivateCopies().begin(),
1886  getPrivateCopies().end());
1887  }
1888 
1891  using inits_range = llvm::iterator_range<inits_iterator>;
1892  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
1893 
1895  return inits_range(getInits().begin(), getInits().end());
1896  }
1898  return inits_const_range(getInits().begin(), getInits().end());
1899  }
1900 
1902  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1903  reinterpret_cast<Stmt **>(varlist_end()));
1904  }
1905 
1907  auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
1908  return const_child_range(Children.begin(), Children.end());
1909  }
1910 
1911  static bool classof(const OMPClause *T) {
1912  return T->getClauseKind() == OMPC_firstprivate;
1913  }
1914 };
1915 
1916 /// This represents clause 'lastprivate' in the '#pragma omp ...'
1917 /// directives.
1918 ///
1919 /// \code
1920 /// #pragma omp simd lastprivate(a,b)
1921 /// \endcode
1922 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1923 /// with the variables 'a' and 'b'.
1925  : public OMPVarListClause<OMPLastprivateClause>,
1926  public OMPClauseWithPostUpdate,
1927  private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
1928  // There are 4 additional tail-allocated arrays at the end of the class:
1929  // 1. Contains list of pseudo variables with the default initialization for
1930  // each non-firstprivate variables. Used in codegen for initialization of
1931  // lastprivate copies.
1932  // 2. List of helper expressions for proper generation of assignment operation
1933  // required for lastprivate clause. This list represents private variables
1934  // (for arrays, single array element).
1935  // 3. List of helper expressions for proper generation of assignment operation
1936  // required for lastprivate clause. This list represents original variables
1937  // (for arrays, single array element).
1938  // 4. List of helper expressions that represents assignment operation:
1939  // \code
1940  // DstExprs = SrcExprs;
1941  // \endcode
1942  // Required for proper codegen of final assignment performed by the
1943  // lastprivate clause.
1944  friend class OMPClauseReader;
1945  friend OMPVarListClause;
1946  friend TrailingObjects;
1947 
1948  /// Build clause with number of variables \a N.
1949  ///
1950  /// \param StartLoc Starting location of the clause.
1951  /// \param LParenLoc Location of '('.
1952  /// \param EndLoc Ending location of the clause.
1953  /// \param N Number of the variables in the clause.
1955  SourceLocation EndLoc, unsigned N)
1956  : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1957  LParenLoc, EndLoc, N),
1958  OMPClauseWithPostUpdate(this) {}
1959 
1960  /// Build an empty clause.
1961  ///
1962  /// \param N Number of variables.
1963  explicit OMPLastprivateClause(unsigned N)
1965  OMPC_lastprivate, SourceLocation(), SourceLocation(),
1966  SourceLocation(), N),
1967  OMPClauseWithPostUpdate(this) {}
1968 
1969  /// Get the list of helper expressions for initialization of private
1970  /// copies for lastprivate variables.
1971  MutableArrayRef<Expr *> getPrivateCopies() {
1972  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1973  }
1974  ArrayRef<const Expr *> getPrivateCopies() const {
1975  return llvm::makeArrayRef(varlist_end(), varlist_size());
1976  }
1977 
1978  /// Set list of helper expressions, required for proper codegen of the
1979  /// clause. These expressions represent private variables (for arrays, single
1980  /// array element) in the final assignment statement performed by the
1981  /// lastprivate clause.
1982  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1983 
1984  /// Get the list of helper source expressions.
1985  MutableArrayRef<Expr *> getSourceExprs() {
1986  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1987  }
1988  ArrayRef<const Expr *> getSourceExprs() const {
1989  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1990  }
1991 
1992  /// Set list of helper expressions, required for proper codegen of the
1993  /// clause. These expressions represent original variables (for arrays, single
1994  /// array element) in the final assignment statement performed by the
1995  /// lastprivate clause.
1996  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1997 
1998  /// Get the list of helper destination expressions.
1999  MutableArrayRef<Expr *> getDestinationExprs() {
2000  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2001  }
2002  ArrayRef<const Expr *> getDestinationExprs() const {
2003  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2004  }
2005 
2006  /// Set list of helper assignment expressions, required for proper
2007  /// codegen of the clause. These expressions are assignment expressions that
2008  /// assign private copy of the variable to original variable.
2009  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2010 
2011  /// Get the list of helper assignment expressions.
2012  MutableArrayRef<Expr *> getAssignmentOps() {
2013  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2014  }
2015  ArrayRef<const Expr *> getAssignmentOps() const {
2016  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2017  }
2018 
2019 public:
2020  /// Creates clause with a list of variables \a VL.
2021  ///
2022  /// \param C AST context.
2023  /// \param StartLoc Starting location of the clause.
2024  /// \param LParenLoc Location of '('.
2025  /// \param EndLoc Ending location of the clause.
2026  /// \param VL List of references to the variables.
2027  /// \param SrcExprs List of helper expressions for proper generation of
2028  /// assignment operation required for lastprivate clause. This list represents
2029  /// private variables (for arrays, single array element).
2030  /// \param DstExprs List of helper expressions for proper generation of
2031  /// assignment operation required for lastprivate clause. This list represents
2032  /// original variables (for arrays, single array element).
2033  /// \param AssignmentOps List of helper expressions that represents assignment
2034  /// operation:
2035  /// \code
2036  /// DstExprs = SrcExprs;
2037  /// \endcode
2038  /// Required for proper codegen of final assignment performed by the
2039  /// lastprivate clause.
2040  /// \param PreInit Statement that must be executed before entering the OpenMP
2041  /// region with this clause.
2042  /// \param PostUpdate Expression that must be executed after exit from the
2043  /// OpenMP region with this clause.
2044  static OMPLastprivateClause *
2045  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2046  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2047  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2048  Stmt *PreInit, Expr *PostUpdate);
2049 
2050  /// Creates an empty clause with the place for \a N variables.
2051  ///
2052  /// \param C AST context.
2053  /// \param N The number of variables.
2054  static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2055 
2058  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2059  using helper_expr_const_range =
2060  llvm::iterator_range<helper_expr_const_iterator>;
2061 
2062  /// Set list of helper expressions, required for generation of private
2063  /// copies of original lastprivate variables.
2064  void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2065 
2067  return helper_expr_const_range(getPrivateCopies().begin(),
2068  getPrivateCopies().end());
2069  }
2070 
2072  return helper_expr_range(getPrivateCopies().begin(),
2073  getPrivateCopies().end());
2074  }
2075 
2077  return helper_expr_const_range(getSourceExprs().begin(),
2078  getSourceExprs().end());
2079  }
2080 
2082  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2083  }
2084 
2086  return helper_expr_const_range(getDestinationExprs().begin(),
2087  getDestinationExprs().end());
2088  }
2089 
2091  return helper_expr_range(getDestinationExprs().begin(),
2092  getDestinationExprs().end());
2093  }
2094 
2096  return helper_expr_const_range(getAssignmentOps().begin(),
2097  getAssignmentOps().end());
2098  }
2099 
2101  return helper_expr_range(getAssignmentOps().begin(),
2102  getAssignmentOps().end());
2103  }
2104 
2106  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2107  reinterpret_cast<Stmt **>(varlist_end()));
2108  }
2109 
2111  auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2112  return const_child_range(Children.begin(), Children.end());
2113  }
2114 
2115  static bool classof(const OMPClause *T) {
2116  return T->getClauseKind() == OMPC_lastprivate;
2117  }
2118 };
2119 
2120 /// This represents clause 'shared' in the '#pragma omp ...' directives.
2121 ///
2122 /// \code
2123 /// #pragma omp parallel shared(a,b)
2124 /// \endcode
2125 /// In this example directive '#pragma omp parallel' has clause 'shared'
2126 /// with the variables 'a' and 'b'.
2127 class OMPSharedClause final
2128  : public OMPVarListClause<OMPSharedClause>,
2129  private llvm::TrailingObjects<OMPSharedClause, Expr *> {
2130  friend OMPVarListClause;
2131  friend TrailingObjects;
2132 
2133  /// Build clause with number of variables \a N.
2134  ///
2135  /// \param StartLoc Starting location of the clause.
2136  /// \param LParenLoc Location of '('.
2137  /// \param EndLoc Ending location of the clause.
2138  /// \param N Number of the variables in the clause.
2139  OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2140  SourceLocation EndLoc, unsigned N)
2141  : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
2142  EndLoc, N) {}
2143 
2144  /// Build an empty clause.
2145  ///
2146  /// \param N Number of variables.
2147  explicit OMPSharedClause(unsigned N)
2150  N) {}
2151 
2152 public:
2153  /// Creates clause with a list of variables \a VL.
2154  ///
2155  /// \param C AST context.
2156  /// \param StartLoc Starting location of the clause.
2157  /// \param LParenLoc Location of '('.
2158  /// \param EndLoc Ending location of the clause.
2159  /// \param VL List of references to the variables.
2160  static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2161  SourceLocation LParenLoc,
2162  SourceLocation EndLoc, ArrayRef<Expr *> VL);
2163 
2164  /// Creates an empty clause with \a N variables.
2165  ///
2166  /// \param C AST context.
2167  /// \param N The number of variables.
2168  static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
2169 
2171  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2172  reinterpret_cast<Stmt **>(varlist_end()));
2173  }
2174 
2176  auto Children = const_cast<OMPSharedClause *>(this)->children();
2177  return const_child_range(Children.begin(), Children.end());
2178  }
2179 
2180  static bool classof(const OMPClause *T) {
2181  return T->getClauseKind() == OMPC_shared;
2182  }
2183 };
2184 
2185 /// This represents clause 'reduction' in the '#pragma omp ...'
2186 /// directives.
2187 ///
2188 /// \code
2189 /// #pragma omp parallel reduction(+:a,b)
2190 /// \endcode
2191 /// In this example directive '#pragma omp parallel' has clause 'reduction'
2192 /// with operator '+' and the variables 'a' and 'b'.
2194  : public OMPVarListClause<OMPReductionClause>,
2195  public OMPClauseWithPostUpdate,
2196  private llvm::TrailingObjects<OMPReductionClause, Expr *> {
2197  friend class OMPClauseReader;
2198  friend OMPVarListClause;
2199  friend TrailingObjects;
2200 
2201  /// Location of ':'.
2203 
2204  /// Nested name specifier for C++.
2205  NestedNameSpecifierLoc QualifierLoc;
2206 
2207  /// Name of custom operator.
2208  DeclarationNameInfo NameInfo;
2209 
2210  /// Build clause with number of variables \a N.
2211  ///
2212  /// \param StartLoc Starting location of the clause.
2213  /// \param LParenLoc Location of '('.
2214  /// \param EndLoc Ending location of the clause.
2215  /// \param ColonLoc Location of ':'.
2216  /// \param N Number of the variables in the clause.
2217  /// \param QualifierLoc The nested-name qualifier with location information
2218  /// \param NameInfo The full name info for reduction identifier.
2219  OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2220  SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
2221  NestedNameSpecifierLoc QualifierLoc,
2222  const DeclarationNameInfo &NameInfo)
2223  : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
2224  LParenLoc, EndLoc, N),
2225  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2226  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2227 
2228  /// Build an empty clause.
2229  ///
2230  /// \param N Number of variables.
2231  explicit OMPReductionClause(unsigned N)
2232  : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
2234  N),
2235  OMPClauseWithPostUpdate(this) {}
2236 
2237  /// Sets location of ':' symbol in clause.
2238  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2239 
2240  /// Sets the name info for specified reduction identifier.
2241  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2242 
2243  /// Sets the nested name specifier.
2244  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2245 
2246  /// Set list of helper expressions, required for proper codegen of the
2247  /// clause. These expressions represent private copy of the reduction
2248  /// variable.
2250 
2251  /// Get the list of helper privates.
2253  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2254  }
2256  return llvm::makeArrayRef(varlist_end(), varlist_size());
2257  }
2258 
2259  /// Set list of helper expressions, required for proper codegen of the
2260  /// clause. These expressions represent LHS expression in the final
2261  /// reduction expression performed by the reduction clause.
2262  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2263 
2264  /// Get the list of helper LHS expressions.
2265  MutableArrayRef<Expr *> getLHSExprs() {
2266  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2267  }
2268  ArrayRef<const Expr *> getLHSExprs() const {
2269  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2270  }
2271 
2272  /// Set list of helper expressions, required for proper codegen of the
2273  /// clause. These expressions represent RHS expression in the final
2274  /// reduction expression performed by the reduction clause.
2275  /// Also, variables in these expressions are used for proper initialization of
2276  /// reduction copies.
2277  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2278 
2279  /// Get the list of helper destination expressions.
2280  MutableArrayRef<Expr *> getRHSExprs() {
2281  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2282  }
2283  ArrayRef<const Expr *> getRHSExprs() const {
2284  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2285  }
2286 
2287  /// Set list of helper reduction expressions, required for proper
2288  /// codegen of the clause. These expressions are binary expressions or
2289  /// operator/custom reduction call that calculates new value from source
2290  /// helper expressions to destination helper expressions.
2291  void setReductionOps(ArrayRef<Expr *> ReductionOps);
2292 
2293  /// Get the list of helper reduction expressions.
2294  MutableArrayRef<Expr *> getReductionOps() {
2295  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2296  }
2297  ArrayRef<const Expr *> getReductionOps() const {
2298  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2299  }
2300 
2301 public:
2302  /// Creates clause with a list of variables \a VL.
2303  ///
2304  /// \param StartLoc Starting location of the clause.
2305  /// \param LParenLoc Location of '('.
2306  /// \param ColonLoc Location of ':'.
2307  /// \param EndLoc Ending location of the clause.
2308  /// \param VL The variables in the clause.
2309  /// \param QualifierLoc The nested-name qualifier with location information
2310  /// \param NameInfo The full name info for reduction identifier.
2311  /// \param Privates List of helper expressions for proper generation of
2312  /// private copies.
2313  /// \param LHSExprs List of helper expressions for proper generation of
2314  /// assignment operation required for copyprivate clause. This list represents
2315  /// LHSs of the reduction expressions.
2316  /// \param RHSExprs List of helper expressions for proper generation of
2317  /// assignment operation required for copyprivate clause. This list represents
2318  /// RHSs of the reduction expressions.
2319  /// Also, variables in these expressions are used for proper initialization of
2320  /// reduction copies.
2321  /// \param ReductionOps List of helper expressions that represents reduction
2322  /// expressions:
2323  /// \code
2324  /// LHSExprs binop RHSExprs;
2325  /// operator binop(LHSExpr, RHSExpr);
2326  /// <CutomReduction>(LHSExpr, RHSExpr);
2327  /// \endcode
2328  /// Required for proper codegen of final reduction operation performed by the
2329  /// reduction clause.
2330  /// \param PreInit Statement that must be executed before entering the OpenMP
2331  /// region with this clause.
2332  /// \param PostUpdate Expression that must be executed after exit from the
2333  /// OpenMP region with this clause.
2334  static OMPReductionClause *
2335  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2336  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2337  NestedNameSpecifierLoc QualifierLoc,
2339  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2340  ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2341 
2342  /// Creates an empty clause with the place for \a N variables.
2343  ///
2344  /// \param C AST context.
2345  /// \param N The number of variables.
2346  static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2347 
2348  /// Gets location of ':' symbol in clause.
2350 
2351  /// Gets the name info for specified reduction identifier.
2352  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2353 
2354  /// Gets the nested name specifier.
2355  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2356 
2359  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2360  using helper_expr_const_range =
2361  llvm::iterator_range<helper_expr_const_iterator>;
2362 
2364  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2365  }
2366 
2368  return helper_expr_range(getPrivates().begin(), getPrivates().end());
2369  }
2370 
2372  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2373  }
2374 
2376  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2377  }
2378 
2380  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2381  }
2382 
2384  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2385  }
2386 
2388  return helper_expr_const_range(getReductionOps().begin(),
2389  getReductionOps().end());
2390  }
2391 
2393  return helper_expr_range(getReductionOps().begin(),
2394  getReductionOps().end());
2395  }
2396 
2398  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2399  reinterpret_cast<Stmt **>(varlist_end()));
2400  }
2401 
2403  auto Children = const_cast<OMPReductionClause *>(this)->children();
2404  return const_child_range(Children.begin(), Children.end());
2405  }
2406 
2407  static bool classof(const OMPClause *T) {
2408  return T->getClauseKind() == OMPC_reduction;
2409  }
2410 };
2411 
2412 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
2413 /// directives.
2414 ///
2415 /// \code
2416 /// #pragma omp taskgroup task_reduction(+:a,b)
2417 /// \endcode
2418 /// In this example directive '#pragma omp taskgroup' has clause
2419 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
2421  : public OMPVarListClause<OMPTaskReductionClause>,
2422  public OMPClauseWithPostUpdate,
2423  private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
2424  friend class OMPClauseReader;
2425  friend OMPVarListClause;
2426  friend TrailingObjects;
2427 
2428  /// Location of ':'.
2430 
2431  /// Nested name specifier for C++.
2432  NestedNameSpecifierLoc QualifierLoc;
2433 
2434  /// Name of custom operator.
2435  DeclarationNameInfo NameInfo;
2436 
2437  /// Build clause with number of variables \a N.
2438  ///
2439  /// \param StartLoc Starting location of the clause.
2440  /// \param LParenLoc Location of '('.
2441  /// \param EndLoc Ending location of the clause.
2442  /// \param ColonLoc Location of ':'.
2443  /// \param N Number of the variables in the clause.
2444  /// \param QualifierLoc The nested-name qualifier with location information
2445  /// \param NameInfo The full name info for reduction identifier.
2447  SourceLocation ColonLoc, SourceLocation EndLoc,
2448  unsigned N, NestedNameSpecifierLoc QualifierLoc,
2449  const DeclarationNameInfo &NameInfo)
2450  : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
2451  LParenLoc, EndLoc, N),
2452  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2453  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2454 
2455  /// Build an empty clause.
2456  ///
2457  /// \param N Number of variables.
2458  explicit OMPTaskReductionClause(unsigned N)
2460  OMPC_task_reduction, SourceLocation(), SourceLocation(),
2461  SourceLocation(), N),
2462  OMPClauseWithPostUpdate(this) {}
2463 
2464  /// Sets location of ':' symbol in clause.
2465  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2466 
2467  /// Sets the name info for specified reduction identifier.
2468  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2469 
2470  /// Sets the nested name specifier.
2471  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2472 
2473  /// Set list of helper expressions, required for proper codegen of the clause.
2474  /// These expressions represent private copy of the reduction variable.
2476 
2477  /// Get the list of helper privates.
2479  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2480  }
2482  return llvm::makeArrayRef(varlist_end(), varlist_size());
2483  }
2484 
2485  /// Set list of helper expressions, required for proper codegen of the clause.
2486  /// These expressions represent LHS expression in the final reduction
2487  /// expression performed by the reduction clause.
2488  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2489 
2490  /// Get the list of helper LHS expressions.
2491  MutableArrayRef<Expr *> getLHSExprs() {
2492  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2493  }
2494  ArrayRef<const Expr *> getLHSExprs() const {
2495  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2496  }
2497 
2498  /// Set list of helper expressions, required for proper codegen of the clause.
2499  /// These expressions represent RHS expression in the final reduction
2500  /// expression performed by the reduction clause. Also, variables in these
2501  /// expressions are used for proper initialization of reduction copies.
2502  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2503 
2504  /// Get the list of helper destination expressions.
2505  MutableArrayRef<Expr *> getRHSExprs() {
2506  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2507  }
2508  ArrayRef<const Expr *> getRHSExprs() const {
2509  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2510  }
2511 
2512  /// Set list of helper reduction expressions, required for proper
2513  /// codegen of the clause. These expressions are binary expressions or
2514  /// operator/custom reduction call that calculates new value from source
2515  /// helper expressions to destination helper expressions.
2516  void setReductionOps(ArrayRef<Expr *> ReductionOps);
2517 
2518  /// Get the list of helper reduction expressions.
2519  MutableArrayRef<Expr *> getReductionOps() {
2520  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2521  }
2522  ArrayRef<const Expr *> getReductionOps() const {
2523  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2524  }
2525 
2526 public:
2527  /// Creates clause with a list of variables \a VL.
2528  ///
2529  /// \param StartLoc Starting location of the clause.
2530  /// \param LParenLoc Location of '('.
2531  /// \param ColonLoc Location of ':'.
2532  /// \param EndLoc Ending location of the clause.
2533  /// \param VL The variables in the clause.
2534  /// \param QualifierLoc The nested-name qualifier with location information
2535  /// \param NameInfo The full name info for reduction identifier.
2536  /// \param Privates List of helper expressions for proper generation of
2537  /// private copies.
2538  /// \param LHSExprs List of helper expressions for proper generation of
2539  /// assignment operation required for copyprivate clause. This list represents
2540  /// LHSs of the reduction expressions.
2541  /// \param RHSExprs List of helper expressions for proper generation of
2542  /// assignment operation required for copyprivate clause. This list represents
2543  /// RHSs of the reduction expressions.
2544  /// Also, variables in these expressions are used for proper initialization of
2545  /// reduction copies.
2546  /// \param ReductionOps List of helper expressions that represents reduction
2547  /// expressions:
2548  /// \code
2549  /// LHSExprs binop RHSExprs;
2550  /// operator binop(LHSExpr, RHSExpr);
2551  /// <CutomReduction>(LHSExpr, RHSExpr);
2552  /// \endcode
2553  /// Required for proper codegen of final reduction operation performed by the
2554  /// reduction clause.
2555  /// \param PreInit Statement that must be executed before entering the OpenMP
2556  /// region with this clause.
2557  /// \param PostUpdate Expression that must be executed after exit from the
2558  /// OpenMP region with this clause.
2559  static OMPTaskReductionClause *
2560  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2561  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2562  NestedNameSpecifierLoc QualifierLoc,
2564  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2565  ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2566 
2567  /// Creates an empty clause with the place for \a N variables.
2568  ///
2569  /// \param C AST context.
2570  /// \param N The number of variables.
2571  static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2572 
2573  /// Gets location of ':' symbol in clause.
2575 
2576  /// Gets the name info for specified reduction identifier.
2577  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2578 
2579  /// Gets the nested name specifier.
2580  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2581 
2584  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2585  using helper_expr_const_range =
2586  llvm::iterator_range<helper_expr_const_iterator>;
2587 
2589  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2590  }
2591 
2593  return helper_expr_range(getPrivates().begin(), getPrivates().end());
2594  }
2595 
2597  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2598  }
2599 
2601  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2602  }
2603 
2605  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2606  }
2607 
2609  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2610  }
2611 
2613  return helper_expr_const_range(getReductionOps().begin(),
2614  getReductionOps().end());
2615  }
2616 
2618  return helper_expr_range(getReductionOps().begin(),
2619  getReductionOps().end());
2620  }
2621 
2623  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2624  reinterpret_cast<Stmt **>(varlist_end()));
2625  }
2626 
2628  auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
2629  return const_child_range(Children.begin(), Children.end());
2630  }
2631 
2632  static bool classof(const OMPClause *T) {
2633  return T->getClauseKind() == OMPC_task_reduction;
2634  }
2635 };
2636 
2637 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
2638 ///
2639 /// \code
2640 /// #pragma omp task in_reduction(+:a,b)
2641 /// \endcode
2642 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
2643 /// operator '+' and the variables 'a' and 'b'.
2645  : public OMPVarListClause<OMPInReductionClause>,
2646  public OMPClauseWithPostUpdate,
2647  private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
2648  friend class OMPClauseReader;
2649  friend OMPVarListClause;
2650  friend TrailingObjects;
2651 
2652  /// Location of ':'.
2654 
2655  /// Nested name specifier for C++.
2656  NestedNameSpecifierLoc QualifierLoc;
2657 
2658  /// Name of custom operator.
2659  DeclarationNameInfo NameInfo;
2660 
2661  /// Build clause with number of variables \a N.
2662  ///
2663  /// \param StartLoc Starting location of the clause.
2664  /// \param LParenLoc Location of '('.
2665  /// \param EndLoc Ending location of the clause.
2666  /// \param ColonLoc Location of ':'.
2667  /// \param N Number of the variables in the clause.
2668  /// \param QualifierLoc The nested-name qualifier with location information
2669  /// \param NameInfo The full name info for reduction identifier.
2671  SourceLocation ColonLoc, SourceLocation EndLoc,
2672  unsigned N, NestedNameSpecifierLoc QualifierLoc,
2673  const DeclarationNameInfo &NameInfo)
2674  : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc,
2675  LParenLoc, EndLoc, N),
2676  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2677  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2678 
2679  /// Build an empty clause.
2680  ///
2681  /// \param N Number of variables.
2682  explicit OMPInReductionClause(unsigned N)
2684  OMPC_in_reduction, SourceLocation(), SourceLocation(),
2685  SourceLocation(), N),
2686  OMPClauseWithPostUpdate(this) {}
2687 
2688  /// Sets location of ':' symbol in clause.
2689  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2690 
2691  /// Sets the name info for specified reduction identifier.
2692  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2693 
2694  /// Sets the nested name specifier.
2695  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2696 
2697  /// Set list of helper expressions, required for proper codegen of the clause.
2698  /// These expressions represent private copy of the reduction variable.
2700 
2701  /// Get the list of helper privates.
2703  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2704  }
2706  return llvm::makeArrayRef(varlist_end(), varlist_size());
2707  }
2708 
2709  /// Set list of helper expressions, required for proper codegen of the clause.
2710  /// These expressions represent LHS expression in the final reduction
2711  /// expression performed by the reduction clause.
2712  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2713 
2714  /// Get the list of helper LHS expressions.
2715  MutableArrayRef<Expr *> getLHSExprs() {
2716  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2717  }
2718  ArrayRef<const Expr *> getLHSExprs() const {
2719  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2720  }
2721 
2722  /// Set list of helper expressions, required for proper codegen of the clause.
2723  /// These expressions represent RHS expression in the final reduction
2724  /// expression performed by the reduction clause. Also, variables in these
2725  /// expressions are used for proper initialization of reduction copies.
2726  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2727 
2728  /// Get the list of helper destination expressions.
2729  MutableArrayRef<Expr *> getRHSExprs() {
2730  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2731  }
2732  ArrayRef<const Expr *> getRHSExprs() const {
2733  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2734  }
2735 
2736  /// Set list of helper reduction expressions, required for proper
2737  /// codegen of the clause. These expressions are binary expressions or
2738  /// operator/custom reduction call that calculates new value from source
2739  /// helper expressions to destination helper expressions.
2740  void setReductionOps(ArrayRef<Expr *> ReductionOps);
2741 
2742  /// Get the list of helper reduction expressions.
2743  MutableArrayRef<Expr *> getReductionOps() {
2744  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2745  }
2746  ArrayRef<const Expr *> getReductionOps() const {
2747  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2748  }
2749 
2750  /// Set list of helper reduction taskgroup descriptors.
2751  void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
2752 
2753  /// Get the list of helper reduction taskgroup descriptors.
2754  MutableArrayRef<Expr *> getTaskgroupDescriptors() {
2755  return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
2756  }
2757  ArrayRef<const Expr *> getTaskgroupDescriptors() const {
2758  return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
2759  }
2760 
2761 public:
2762  /// Creates clause with a list of variables \a VL.
2763  ///
2764  /// \param StartLoc Starting location of the clause.
2765  /// \param LParenLoc Location of '('.
2766  /// \param ColonLoc Location of ':'.
2767  /// \param EndLoc Ending location of the clause.
2768  /// \param VL The variables in the clause.
2769  /// \param QualifierLoc The nested-name qualifier with location information
2770  /// \param NameInfo The full name info for reduction identifier.
2771  /// \param Privates List of helper expressions for proper generation of
2772  /// private copies.
2773  /// \param LHSExprs List of helper expressions for proper generation of
2774  /// assignment operation required for copyprivate clause. This list represents
2775  /// LHSs of the reduction expressions.
2776  /// \param RHSExprs List of helper expressions for proper generation of
2777  /// assignment operation required for copyprivate clause. This list represents
2778  /// RHSs of the reduction expressions.
2779  /// Also, variables in these expressions are used for proper initialization of
2780  /// reduction copies.
2781  /// \param ReductionOps List of helper expressions that represents reduction
2782  /// expressions:
2783  /// \code
2784  /// LHSExprs binop RHSExprs;
2785  /// operator binop(LHSExpr, RHSExpr);
2786  /// <CutomReduction>(LHSExpr, RHSExpr);
2787  /// \endcode
2788  /// Required for proper codegen of final reduction operation performed by the
2789  /// reduction clause.
2790  /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
2791  /// corresponding items in parent taskgroup task_reduction clause.
2792  /// \param PreInit Statement that must be executed before entering the OpenMP
2793  /// region with this clause.
2794  /// \param PostUpdate Expression that must be executed after exit from the
2795  /// OpenMP region with this clause.
2796  static OMPInReductionClause *
2797  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2798  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2799  NestedNameSpecifierLoc QualifierLoc,
2801  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2802  ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
2803  Stmt *PreInit, Expr *PostUpdate);
2804 
2805  /// Creates an empty clause with the place for \a N variables.
2806  ///
2807  /// \param C AST context.
2808  /// \param N The number of variables.
2809  static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2810 
2811  /// Gets location of ':' symbol in clause.
2813 
2814  /// Gets the name info for specified reduction identifier.
2815  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2816 
2817  /// Gets the nested name specifier.
2818  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2819 
2822  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2823  using helper_expr_const_range =
2824  llvm::iterator_range<helper_expr_const_iterator>;
2825 
2827  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2828  }
2829 
2831  return helper_expr_range(getPrivates().begin(), getPrivates().end());
2832  }
2833 
2835  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2836  }
2837 
2839  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2840  }
2841 
2843  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2844  }
2845 
2847  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2848  }
2849 
2851  return helper_expr_const_range(getReductionOps().begin(),
2852  getReductionOps().end());
2853  }
2854 
2856  return helper_expr_range(getReductionOps().begin(),
2857  getReductionOps().end());
2858  }
2859 
2861  return helper_expr_const_range(getTaskgroupDescriptors().begin(),
2862  getTaskgroupDescriptors().end());
2863  }
2864 
2866  return helper_expr_range(getTaskgroupDescriptors().begin(),
2867  getTaskgroupDescriptors().end());
2868  }
2869 
2871  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2872  reinterpret_cast<Stmt **>(varlist_end()));
2873  }
2874 
2876  auto Children = const_cast<OMPInReductionClause *>(this)->children();
2877  return const_child_range(Children.begin(), Children.end());
2878  }
2879 
2880  static bool classof(const OMPClause *T) {
2881  return T->getClauseKind() == OMPC_in_reduction;
2882  }
2883 };
2884 
2885 /// This represents clause 'linear' in the '#pragma omp ...'
2886 /// directives.
2887 ///
2888 /// \code
2889 /// #pragma omp simd linear(a,b : 2)
2890 /// \endcode
2891 /// In this example directive '#pragma omp simd' has clause 'linear'
2892 /// with variables 'a', 'b' and linear step '2'.
2893 class OMPLinearClause final
2894  : public OMPVarListClause<OMPLinearClause>,
2895  public OMPClauseWithPostUpdate,
2896  private llvm::TrailingObjects<OMPLinearClause, Expr *> {
2897  friend class OMPClauseReader;
2898  friend OMPVarListClause;
2899  friend TrailingObjects;
2900 
2901  /// Modifier of 'linear' clause.
2902  OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
2903 
2904  /// Location of linear modifier if any.
2906 
2907  /// Location of ':'.
2909 
2910  /// Sets the linear step for clause.
2911  void setStep(Expr *Step) { *(getFinals().end()) = Step; }
2912 
2913  /// Sets the expression to calculate linear step for clause.
2914  void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
2915 
2916  /// Build 'linear' clause with given number of variables \a NumVars.
2917  ///
2918  /// \param StartLoc Starting location of the clause.
2919  /// \param LParenLoc Location of '('.
2920  /// \param ColonLoc Location of ':'.
2921  /// \param EndLoc Ending location of the clause.
2922  /// \param NumVars Number of variables.
2923  OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2924  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2925  SourceLocation ColonLoc, SourceLocation EndLoc,
2926  unsigned NumVars)
2927  : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
2928  EndLoc, NumVars),
2929  OMPClauseWithPostUpdate(this), Modifier(Modifier),
2930  ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
2931 
2932  /// Build an empty clause.
2933  ///
2934  /// \param NumVars Number of variables.
2935  explicit OMPLinearClause(unsigned NumVars)
2938  NumVars),
2939  OMPClauseWithPostUpdate(this) {}
2940 
2941  /// Gets the list of initial values for linear variables.
2942  ///
2943  /// There are NumVars expressions with initial values allocated after the
2944  /// varlist, they are followed by NumVars update expressions (used to update
2945  /// the linear variable's value on current iteration) and they are followed by
2946  /// NumVars final expressions (used to calculate the linear variable's
2947  /// value after the loop body). After these lists, there are 2 helper
2948  /// expressions - linear step and a helper to calculate it before the
2949  /// loop body (used when the linear step is not constant):
2950  ///
2951  /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
2952  /// Finals[]; Step; CalcStep; }
2954  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2955  }
2957  return llvm::makeArrayRef(varlist_end(), varlist_size());
2958  }
2959 
2961  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2962  }
2964  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2965  }
2966 
2967  /// Sets the list of update expressions for linear variables.
2969  return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
2970  }
2972  return llvm::makeArrayRef(getInits().end(), varlist_size());
2973  }
2974 
2975  /// Sets the list of final update expressions for linear variables.
2977  return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
2978  }
2980  return llvm::makeArrayRef(getUpdates().end(), varlist_size());
2981  }
2982 
2983  /// Sets the list of the copies of original linear variables.
2984  /// \param PL List of expressions.
2985  void setPrivates(ArrayRef<Expr *> PL);
2986 
2987  /// Sets the list of the initial values for linear variables.
2988  /// \param IL List of expressions.
2989  void setInits(ArrayRef<Expr *> IL);
2990 
2991 public:
2992  /// Creates clause with a list of variables \a VL and a linear step
2993  /// \a Step.
2994  ///
2995  /// \param C AST Context.
2996  /// \param StartLoc Starting location of the clause.
2997  /// \param LParenLoc Location of '('.
2998  /// \param Modifier Modifier of 'linear' clause.
2999  /// \param ModifierLoc Modifier location.
3000  /// \param ColonLoc Location of ':'.
3001  /// \param EndLoc Ending location of the clause.
3002  /// \param VL List of references to the variables.
3003  /// \param PL List of private copies of original variables.
3004  /// \param IL List of initial values for the variables.
3005  /// \param Step Linear step.
3006  /// \param CalcStep Calculation of the linear step.
3007  /// \param PreInit Statement that must be executed before entering the OpenMP
3008  /// region with this clause.
3009  /// \param PostUpdate Expression that must be executed after exit from the
3010  /// OpenMP region with this clause.
3011  static OMPLinearClause *
3012  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3013  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3014  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3015  ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
3016  Stmt *PreInit, Expr *PostUpdate);
3017 
3018  /// Creates an empty clause with the place for \a NumVars variables.
3019  ///
3020  /// \param C AST context.
3021  /// \param NumVars Number of variables.
3022  static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3023 
3024  /// Set modifier.
3025  void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
3026 
3027  /// Return modifier.
3029 
3030  /// Set modifier location.
3031  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3032 
3033  /// Return modifier location.
3035 
3036  /// Sets the location of ':'.
3037  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3038 
3039  /// Returns the location of ':'.
3041 
3042  /// Returns linear step.
3043  Expr *getStep() { return *(getFinals().end()); }
3044 
3045  /// Returns linear step.
3046  const Expr *getStep() const { return *(getFinals().end()); }
3047 
3048  /// Returns expression to calculate linear step.
3049  Expr *getCalcStep() { return *(getFinals().end() + 1); }
3050 
3051  /// Returns expression to calculate linear step.
3052  const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
3053 
3054  /// Sets the list of update expressions for linear variables.
3055  /// \param UL List of expressions.
3056  void setUpdates(ArrayRef<Expr *> UL);
3057 
3058  /// Sets the list of final update expressions for linear variables.
3059  /// \param FL List of expressions.
3060  void setFinals(ArrayRef<Expr *> FL);
3061 
3064  using privates_range = llvm::iterator_range<privates_iterator>;
3065  using privates_const_range = llvm::iterator_range<privates_const_iterator>;
3066 
3068  return privates_range(getPrivates().begin(), getPrivates().end());
3069  }
3070 
3071  privates_const_range privates() const {
3072  return privates_const_range(getPrivates().begin(), getPrivates().end());
3073  }
3074 
3077  using inits_range = llvm::iterator_range<inits_iterator>;
3078  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3079 
3081  return inits_range(getInits().begin(), getInits().end());
3082  }
3083 
3084  inits_const_range inits() const {
3085  return inits_const_range(getInits().begin(), getInits().end());
3086  }
3087 
3090  using updates_range = llvm::iterator_range<updates_iterator>;
3091  using updates_const_range = llvm::iterator_range<updates_const_iterator>;
3092 
3094  return updates_range(getUpdates().begin(), getUpdates().end());
3095  }
3096 
3097  updates_const_range updates() const {
3098  return updates_const_range(getUpdates().begin(), getUpdates().end());
3099  }
3100 
3103  using finals_range = llvm::iterator_range<finals_iterator>;
3104  using finals_const_range = llvm::iterator_range<finals_const_iterator>;
3105 
3107  return finals_range(getFinals().begin(), getFinals().end());
3108  }
3109 
3110  finals_const_range finals() const {
3111  return finals_const_range(getFinals().begin(), getFinals().end());
3112  }
3113 
3115  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3116  reinterpret_cast<Stmt **>(varlist_end()));
3117  }
3118 
3119  const_child_range children() const {
3120  auto Children = const_cast<OMPLinearClause *>(this)->children();
3121  return const_child_range(Children.begin(), Children.end());
3122  }
3123 
3124  static bool classof(const OMPClause *T) {
3125  return T->getClauseKind() == OMPC_linear;
3126  }
3127 };
3128 
3129 /// This represents clause 'aligned' in the '#pragma omp ...'
3130 /// directives.
3131 ///
3132 /// \code
3133 /// #pragma omp simd aligned(a,b : 8)
3134 /// \endcode
3135 /// In this example directive '#pragma omp simd' has clause 'aligned'
3136 /// with variables 'a', 'b' and alignment '8'.
3137 class OMPAlignedClause final
3138  : public OMPVarListClause<OMPAlignedClause>,
3139  private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
3140  friend class OMPClauseReader;
3141  friend OMPVarListClause;
3142  friend TrailingObjects;
3143 
3144  /// Location of ':'.
3145  SourceLocation ColonLoc;
3146 
3147  /// Sets the alignment for clause.
3148  void setAlignment(Expr *A) { *varlist_end() = A; }
3149 
3150  /// Build 'aligned' clause with given number of variables \a NumVars.
3151  ///
3152  /// \param StartLoc Starting location of the clause.
3153  /// \param LParenLoc Location of '('.
3154  /// \param ColonLoc Location of ':'.
3155  /// \param EndLoc Ending location of the clause.
3156  /// \param NumVars Number of variables.
3157  OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3158  SourceLocation ColonLoc, SourceLocation EndLoc,
3159  unsigned NumVars)
3160  : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
3161  EndLoc, NumVars),
3162  ColonLoc(ColonLoc) {}
3163 
3164  /// Build an empty clause.
3165  ///
3166  /// \param NumVars Number of variables.
3167  explicit OMPAlignedClause(unsigned NumVars)
3168  : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
3169  SourceLocation(), SourceLocation(),
3170  NumVars) {}
3171 
3172 public:
3173  /// Creates clause with a list of variables \a VL and alignment \a A.
3174  ///
3175  /// \param C AST Context.
3176  /// \param StartLoc Starting location of the clause.
3177  /// \param LParenLoc Location of '('.
3178  /// \param ColonLoc Location of ':'.
3179  /// \param EndLoc Ending location of the clause.
3180  /// \param VL List of references to the variables.
3181  /// \param A Alignment.
3182  static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3183  SourceLocation LParenLoc,
3184  SourceLocation ColonLoc,
3185  SourceLocation EndLoc, ArrayRef<Expr *> VL,
3186  Expr *A);
3187 
3188  /// Creates an empty clause with the place for \a NumVars variables.
3189  ///
3190  /// \param C AST context.
3191  /// \param NumVars Number of variables.
3192  static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3193 
3194  /// Sets the location of ':'.
3195  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3196 
3197  /// Returns the location of ':'.
3198  SourceLocation getColonLoc() const { return ColonLoc; }
3199 
3200  /// Returns alignment.
3201  Expr *getAlignment() { return *varlist_end(); }
3202 
3203  /// Returns alignment.
3204  const Expr *getAlignment() const { return *varlist_end(); }
3205 
3207  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3208  reinterpret_cast<Stmt **>(varlist_end()));
3209  }
3210 
3212  auto Children = const_cast<OMPAlignedClause *>(this)->children();
3213  return const_child_range(Children.begin(), Children.end());
3214  }
3215 
3216  static bool classof(const OMPClause *T) {
3217  return T->getClauseKind() == OMPC_aligned;
3218  }
3219 };
3220 
3221 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
3222 ///
3223 /// \code
3224 /// #pragma omp parallel copyin(a,b)
3225 /// \endcode
3226 /// In this example directive '#pragma omp parallel' has clause 'copyin'
3227 /// with the variables 'a' and 'b'.
3228 class OMPCopyinClause final
3229  : public OMPVarListClause<OMPCopyinClause>,
3230  private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
3231  // Class has 3 additional tail allocated arrays:
3232  // 1. List of helper expressions for proper generation of assignment operation
3233  // required for copyin clause. This list represents sources.
3234  // 2. List of helper expressions for proper generation of assignment operation
3235  // required for copyin clause. This list represents destinations.
3236  // 3. List of helper expressions that represents assignment operation:
3237  // \code
3238  // DstExprs = SrcExprs;
3239  // \endcode
3240  // Required for proper codegen of propagation of master's thread values of
3241  // threadprivate variables to local instances of that variables in other
3242  // implicit threads.
3243 
3244  friend class OMPClauseReader;
3245  friend OMPVarListClause;
3246  friend TrailingObjects;
3247 
3248  /// Build clause with number of variables \a N.
3249  ///
3250  /// \param StartLoc Starting location of the clause.
3251  /// \param LParenLoc Location of '('.
3252  /// \param EndLoc Ending location of the clause.
3253  /// \param N Number of the variables in the clause.
3254  OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3255  SourceLocation EndLoc, unsigned N)
3256  : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
3257  EndLoc, N) {}
3258 
3259  /// Build an empty clause.
3260  ///
3261  /// \param N Number of variables.
3262  explicit OMPCopyinClause(unsigned N)
3263  : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
3264  SourceLocation(), SourceLocation(),
3265  N) {}
3266 
3267  /// Set list of helper expressions, required for proper codegen of the
3268  /// clause. These expressions represent source expression in the final
3269  /// assignment statement performed by the copyin clause.
3270  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3271 
3272  /// Get the list of helper source expressions.
3273  MutableArrayRef<Expr *> getSourceExprs() {
3274  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3275  }
3276  ArrayRef<const Expr *> getSourceExprs() const {
3277  return llvm::makeArrayRef(varlist_end(), varlist_size());
3278  }
3279 
3280  /// Set list of helper expressions, required for proper codegen of the
3281  /// clause. These expressions represent destination expression in the final
3282  /// assignment statement performed by the copyin clause.
3283  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3284 
3285  /// Get the list of helper destination expressions.
3286  MutableArrayRef<Expr *> getDestinationExprs() {
3287  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3288  }
3289  ArrayRef<const Expr *> getDestinationExprs() const {
3290  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3291  }
3292 
3293  /// Set list of helper assignment expressions, required for proper
3294  /// codegen of the clause. These expressions are assignment expressions that
3295  /// assign source helper expressions to destination helper expressions
3296  /// correspondingly.
3297  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3298 
3299  /// Get the list of helper assignment expressions.
3300  MutableArrayRef<Expr *> getAssignmentOps() {
3301  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3302  }
3303  ArrayRef<const Expr *> getAssignmentOps() const {
3304  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3305  }
3306 
3307 public:
3308  /// Creates clause with a list of variables \a VL.
3309  ///
3310  /// \param C AST context.
3311  /// \param StartLoc Starting location of the clause.
3312  /// \param LParenLoc Location of '('.
3313  /// \param EndLoc Ending location of the clause.
3314  /// \param VL List of references to the variables.
3315  /// \param SrcExprs List of helper expressions for proper generation of
3316  /// assignment operation required for copyin clause. This list represents
3317  /// sources.
3318  /// \param DstExprs List of helper expressions for proper generation of
3319  /// assignment operation required for copyin clause. This list represents
3320  /// destinations.
3321  /// \param AssignmentOps List of helper expressions that represents assignment
3322  /// operation:
3323  /// \code
3324  /// DstExprs = SrcExprs;
3325  /// \endcode
3326  /// Required for proper codegen of propagation of master's thread values of
3327  /// threadprivate variables to local instances of that variables in other
3328  /// implicit threads.
3329  static OMPCopyinClause *
3330  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3331  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3332  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
3333 
3334  /// Creates an empty clause with \a N variables.
3335  ///
3336  /// \param C AST context.
3337  /// \param N The number of variables.
3338  static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
3339 
3340  using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3341  using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3342  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3343  using helper_expr_const_range =
3344  llvm::iterator_range<helper_expr_const_iterator>;
3345 
3347  return helper_expr_const_range(getSourceExprs().begin(),
3348  getSourceExprs().end());
3349  }
3350 
3352  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3353  }
3354 
3356  return helper_expr_const_range(getDestinationExprs().begin(),
3357  getDestinationExprs().end());
3358  }
3359 
3361  return helper_expr_range(getDestinationExprs().begin(),
3362  getDestinationExprs().end());
3363  }
3364 
3366  return helper_expr_const_range(getAssignmentOps().begin(),
3367  getAssignmentOps().end());
3368  }
3369 
3371  return helper_expr_range(getAssignmentOps().begin(),
3372  getAssignmentOps().end());
3373  }
3374 
3376  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3377  reinterpret_cast<Stmt **>(varlist_end()));
3378  }
3379 
3381  auto Children = const_cast<OMPCopyinClause *>(this)->children();
3382  return const_child_range(Children.begin(), Children.end());
3383  }
3384 
3385  static bool classof(const OMPClause *T) {
3386  return T->getClauseKind() == OMPC_copyin;
3387  }
3388 };
3389 
3390 /// This represents clause 'copyprivate' in the '#pragma omp ...'
3391 /// directives.
3392 ///
3393 /// \code
3394 /// #pragma omp single copyprivate(a,b)
3395 /// \endcode
3396 /// In this example directive '#pragma omp single' has clause 'copyprivate'
3397 /// with the variables 'a' and 'b'.
3399  : public OMPVarListClause<OMPCopyprivateClause>,
3400  private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
3401  friend class OMPClauseReader;
3402  friend OMPVarListClause;
3403  friend TrailingObjects;
3404 
3405  /// Build clause with number of variables \a N.
3406  ///
3407  /// \param StartLoc Starting location of the clause.
3408  /// \param LParenLoc Location of '('.
3409  /// \param EndLoc Ending location of the clause.
3410  /// \param N Number of the variables in the clause.
3411  OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3412  SourceLocation EndLoc, unsigned N)
3413  : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
3414  LParenLoc, EndLoc, N) {}
3415 
3416  /// Build an empty clause.
3417  ///
3418  /// \param N Number of variables.
3419  explicit OMPCopyprivateClause(unsigned N)
3421  OMPC_copyprivate, SourceLocation(), SourceLocation(),
3422  SourceLocation(), N) {}
3423 
3424  /// Set list of helper expressions, required for proper codegen of the
3425  /// clause. These expressions represent source expression in the final
3426  /// assignment statement performed by the copyprivate clause.
3427  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3428 
3429  /// Get the list of helper source expressions.
3430  MutableArrayRef<Expr *> getSourceExprs() {
3431  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3432  }
3433  ArrayRef<const Expr *> getSourceExprs() const {
3434  return llvm::makeArrayRef(varlist_end(), varlist_size());
3435  }
3436 
3437  /// Set list of helper expressions, required for proper codegen of the
3438  /// clause. These expressions represent destination expression in the final
3439  /// assignment statement performed by the copyprivate clause.
3440  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3441 
3442  /// Get the list of helper destination expressions.
3443  MutableArrayRef<Expr *> getDestinationExprs() {
3444  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3445  }
3446  ArrayRef<const Expr *> getDestinationExprs() const {
3447  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3448  }
3449 
3450  /// Set list of helper assignment expressions, required for proper
3451  /// codegen of the clause. These expressions are assignment expressions that
3452  /// assign source helper expressions to destination helper expressions
3453  /// correspondingly.
3454  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3455 
3456  /// Get the list of helper assignment expressions.
3457  MutableArrayRef<Expr *> getAssignmentOps() {
3458  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3459  }
3460  ArrayRef<const Expr *> getAssignmentOps() const {
3461  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3462  }
3463 
3464 public:
3465  /// Creates clause with a list of variables \a VL.
3466  ///
3467  /// \param C AST context.
3468  /// \param StartLoc Starting location of the clause.
3469  /// \param LParenLoc Location of '('.
3470  /// \param EndLoc Ending location of the clause.
3471  /// \param VL List of references to the variables.
3472  /// \param SrcExprs List of helper expressions for proper generation of
3473  /// assignment operation required for copyprivate clause. This list represents
3474  /// sources.
3475  /// \param DstExprs List of helper expressions for proper generation of
3476  /// assignment operation required for copyprivate clause. This list represents
3477  /// destinations.
3478  /// \param AssignmentOps List of helper expressions that represents assignment
3479  /// operation:
3480  /// \code
3481  /// DstExprs = SrcExprs;
3482  /// \endcode
3483  /// Required for proper codegen of final assignment performed by the
3484  /// copyprivate clause.
3485  static OMPCopyprivateClause *
3486  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3487  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3488  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
3489 
3490  /// Creates an empty clause with \a N variables.
3491  ///
3492  /// \param C AST context.
3493  /// \param N The number of variables.
3494  static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3495 
3496  using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3497  using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3498  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3499  using helper_expr_const_range =
3500  llvm::iterator_range<helper_expr_const_iterator>;
3501 
3503  return helper_expr_const_range(getSourceExprs().begin(),
3504  getSourceExprs().end());
3505  }
3506 
3508  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3509  }
3510 
3512  return helper_expr_const_range(getDestinationExprs().begin(),
3513  getDestinationExprs().end());
3514  }
3515 
3517  return helper_expr_range(getDestinationExprs().begin(),
3518  getDestinationExprs().end());
3519  }
3520 
3522  return helper_expr_const_range(getAssignmentOps().begin(),
3523  getAssignmentOps().end());
3524  }
3525 
3527  return helper_expr_range(getAssignmentOps().begin(),
3528  getAssignmentOps().end());
3529  }
3530 
3532  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3533  reinterpret_cast<Stmt **>(varlist_end()));
3534  }
3535 
3537  auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
3538  return const_child_range(Children.begin(), Children.end());
3539  }
3540 
3541  static bool classof(const OMPClause *T) {
3542  return T->getClauseKind() == OMPC_copyprivate;
3543  }
3544 };
3545 
3546 /// This represents implicit clause 'flush' for the '#pragma omp flush'
3547 /// directive.
3548 /// This clause does not exist by itself, it can be only as a part of 'omp
3549 /// flush' directive. This clause is introduced to keep the original structure
3550 /// of \a OMPExecutableDirective class and its derivatives and to use the
3551 /// existing infrastructure of clauses with the list of variables.
3552 ///
3553 /// \code
3554 /// #pragma omp flush(a,b)
3555 /// \endcode
3556 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
3557 /// with the variables 'a' and 'b'.
3558 class OMPFlushClause final
3559  : public OMPVarListClause<OMPFlushClause>,
3560  private llvm::TrailingObjects<OMPFlushClause, Expr *> {
3561  friend OMPVarListClause;
3562  friend TrailingObjects;
3563 
3564  /// Build clause with number of variables \a N.
3565  ///
3566  /// \param StartLoc Starting location of the clause.
3567  /// \param LParenLoc Location of '('.
3568  /// \param EndLoc Ending location of the clause.
3569  /// \param N Number of the variables in the clause.
3570  OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3571  SourceLocation EndLoc, unsigned N)
3572  : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
3573  EndLoc, N) {}
3574 
3575  /// Build an empty clause.
3576  ///
3577  /// \param N Number of variables.
3578  explicit OMPFlushClause(unsigned N)
3579  : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
3580  SourceLocation(), SourceLocation(),
3581  N) {}
3582 
3583 public:
3584  /// Creates clause with a list of variables \a VL.
3585  ///
3586  /// \param C AST context.
3587  /// \param StartLoc Starting location of the clause.
3588  /// \param LParenLoc Location of '('.
3589  /// \param EndLoc Ending location of the clause.
3590  /// \param VL List of references to the variables.
3591  static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
3592  SourceLocation LParenLoc, SourceLocation EndLoc,
3593  ArrayRef<Expr *> VL);
3594 
3595  /// Creates an empty clause with \a N variables.
3596  ///
3597  /// \param C AST context.
3598  /// \param N The number of variables.
3599  static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
3600 
3602  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3603  reinterpret_cast<Stmt **>(varlist_end()));
3604  }
3605 
3607  auto Children = const_cast<OMPFlushClause *>(this)->children();
3608  return const_child_range(Children.begin(), Children.end());
3609  }
3610 
3611  static bool classof(const OMPClause *T) {
3612  return T->getClauseKind() == OMPC_flush;
3613  }
3614 };
3615 
3616 /// This represents implicit clause 'depend' for the '#pragma omp task'
3617 /// directive.
3618 ///
3619 /// \code
3620 /// #pragma omp task depend(in:a,b)
3621 /// \endcode
3622 /// In this example directive '#pragma omp task' with clause 'depend' with the
3623 /// variables 'a' and 'b' with dependency 'in'.
3624 class OMPDependClause final
3625  : public OMPVarListClause<OMPDependClause>,
3626  private llvm::TrailingObjects<OMPDependClause, Expr *> {
3627  friend class OMPClauseReader;
3628  friend OMPVarListClause;
3629  friend TrailingObjects;
3630 
3631  /// Dependency type (one of in, out, inout).
3633 
3634  /// Dependency type location.
3635  SourceLocation DepLoc;
3636 
3637  /// Colon location.
3638  SourceLocation ColonLoc;
3639 
3640  /// Number of loops, associated with the depend clause.
3641  unsigned NumLoops = 0;
3642 
3643  /// Build clause with number of variables \a N.
3644  ///
3645  /// \param StartLoc Starting location of the clause.
3646  /// \param LParenLoc Location of '('.
3647  /// \param EndLoc Ending location of the clause.
3648  /// \param N Number of the variables in the clause.
3649  /// \param NumLoops Number of loops that is associated with this depend
3650  /// clause.
3651  OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3652  SourceLocation EndLoc, unsigned N, unsigned NumLoops)
3653  : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
3654  EndLoc, N), NumLoops(NumLoops) {}
3655 
3656  /// Build an empty clause.
3657  ///
3658  /// \param N Number of variables.
3659  /// \param NumLoops Number of loops that is associated with this depend
3660  /// clause.
3661  explicit OMPDependClause(unsigned N, unsigned NumLoops)
3662  : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
3663  SourceLocation(), SourceLocation(),
3664  N),
3665  NumLoops(NumLoops) {}
3666 
3667  /// Set dependency kind.
3668  void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
3669 
3670  /// Set dependency kind and its location.
3671  void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
3672 
3673  /// Set colon location.
3674  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3675 
3676 public:
3677  /// Creates clause with a list of variables \a VL.
3678  ///
3679  /// \param C AST context.
3680  /// \param StartLoc Starting location of the clause.
3681  /// \param LParenLoc Location of '('.
3682  /// \param EndLoc Ending location of the clause.
3683  /// \param DepKind Dependency type.
3684  /// \param DepLoc Location of the dependency type.
3685  /// \param ColonLoc Colon location.
3686  /// \param VL List of references to the variables.
3687  /// \param NumLoops Number of loops that is associated with this depend
3688  /// clause.
3689  static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
3690  SourceLocation LParenLoc,
3691  SourceLocation EndLoc,
3692  OpenMPDependClauseKind DepKind,
3693  SourceLocation DepLoc, SourceLocation ColonLoc,
3694  ArrayRef<Expr *> VL, unsigned NumLoops);
3695 
3696  /// Creates an empty clause with \a N variables.
3697  ///
3698  /// \param C AST context.
3699  /// \param N The number of variables.
3700  /// \param NumLoops Number of loops that is associated with this depend
3701  /// clause.
3702  static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
3703  unsigned NumLoops);
3704 
3705  /// Get dependency type.
3706  OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
3707 
3708  /// Get dependency type location.
3709  SourceLocation getDependencyLoc() const { return DepLoc; }
3710 
3711  /// Get colon location.
3712  SourceLocation getColonLoc() const { return ColonLoc; }
3713 
3714  /// Get number of loops associated with the clause.
3715  unsigned getNumLoops() const { return NumLoops; }
3716 
3717  /// Set the loop data for the depend clauses with 'sink|source' kind of
3718  /// dependency.
3719  void setLoopData(unsigned NumLoop, Expr *Cnt);
3720 
3721  /// Get the loop data.
3722  Expr *getLoopData(unsigned NumLoop);
3723  const Expr *getLoopData(unsigned NumLoop) const;
3724 
3726  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3727  reinterpret_cast<Stmt **>(varlist_end()));
3728  }
3729 
3731  auto Children = const_cast<OMPDependClause *>(this)->children();
3732  return const_child_range(Children.begin(), Children.end());
3733  }
3734 
3735  static bool classof(const OMPClause *T) {
3736  return T->getClauseKind() == OMPC_depend;
3737  }
3738 };
3739 
3740 /// This represents 'device' clause in the '#pragma omp ...'
3741 /// directive.
3742 ///
3743 /// \code
3744 /// #pragma omp target device(a)
3745 /// \endcode
3746 /// In this example directive '#pragma omp target' has clause 'device'
3747 /// with single expression 'a'.
3748 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
3749  friend class OMPClauseReader;
3750 
3751  /// Location of '('.
3752  SourceLocation LParenLoc;
3753 
3754  /// Device number.
3755  Stmt *Device = nullptr;
3756 
3757  /// Set the device number.
3758  ///
3759  /// \param E Device number.
3760  void setDevice(Expr *E) { Device = E; }
3761 
3762 public:
3763  /// Build 'device' clause.
3764  ///
3765  /// \param E Expression associated with this clause.
3766  /// \param CaptureRegion Innermost OpenMP region where expressions in this
3767  /// clause must be captured.
3768  /// \param StartLoc Starting location of the clause.
3769  /// \param LParenLoc Location of '('.
3770  /// \param EndLoc Ending location of the clause.
3771  OMPDeviceClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
3772  SourceLocation StartLoc, SourceLocation LParenLoc,
3773  SourceLocation EndLoc)
3774  : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this),
3775  LParenLoc(LParenLoc), Device(E) {
3776  setPreInitStmt(HelperE, CaptureRegion);
3777  }
3778 
3779  /// Build an empty clause.
3781  : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
3782  OMPClauseWithPreInit(this) {}
3783 
3784  /// Sets the location of '('.
3785  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3786 
3787  /// Returns the location of '('.
3788  SourceLocation getLParenLoc() const { return LParenLoc; }
3789 
3790  /// Return device number.
3791  Expr *getDevice() { return cast<Expr>(Device); }
3792 
3793  /// Return device number.
3794  Expr *getDevice() const { return cast<Expr>(Device); }
3795 
3796  child_range children() { return child_range(&Device, &Device + 1); }
3797 
3799  return const_child_range(&Device, &Device + 1);
3800  }
3801 
3802  static bool classof(const OMPClause *T) {
3803  return T->getClauseKind() == OMPC_device;
3804  }
3805 };
3806 
3807 /// This represents 'threads' clause in the '#pragma omp ...' directive.
3808 ///
3809 /// \code
3810 /// #pragma omp ordered threads
3811 /// \endcode
3812 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
3813 class OMPThreadsClause : public OMPClause {
3814 public:
3815  /// Build 'threads' clause.
3816  ///
3817  /// \param StartLoc Starting location of the clause.
3818  /// \param EndLoc Ending location of the clause.
3819  OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
3820  : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
3821 
3822  /// Build an empty clause.
3824  : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
3825 
3828  }
3829 
3832  }
3833 
3834  static bool classof(const OMPClause *T) {
3835  return T->getClauseKind() == OMPC_threads;
3836  }
3837 };
3838 
3839 /// This represents 'simd' clause in the '#pragma omp ...' directive.
3840 ///
3841 /// \code
3842 /// #pragma omp ordered simd
3843 /// \endcode
3844 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
3845 class OMPSIMDClause : public OMPClause {
3846 public:
3847  /// Build 'simd' clause.
3848  ///
3849  /// \param StartLoc Starting location of the clause.
3850  /// \param EndLoc Ending location of the clause.
3851  OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
3852  : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
3853 
3854  /// Build an empty clause.
3855  OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
3856 
3859  }
3860 
3863  }
3864 
3865  static bool classof(const OMPClause *T) {
3866  return T->getClauseKind() == OMPC_simd;
3867  }
3868 };
3869 
3870 /// Struct that defines common infrastructure to handle mappable
3871 /// expressions used in OpenMP clauses.
3873 public:
3874  /// Class that represents a component of a mappable expression. E.g.
3875  /// for an expression S.a, the first component is a declaration reference
3876  /// expression associated with 'S' and the second is a member expression
3877  /// associated with the field declaration 'a'. If the expression is an array
3878  /// subscript it may not have any associated declaration. In that case the
3879  /// associated declaration is set to nullptr.
3881  /// Expression associated with the component.
3882  Expr *AssociatedExpression = nullptr;
3883 
3884  /// Declaration associated with the declaration. If the component does
3885  /// not have a declaration (e.g. array subscripts or section), this is set
3886  /// to nullptr.
3887  ValueDecl *AssociatedDeclaration = nullptr;
3888 
3889  public:
3890  explicit MappableComponent() = default;
3891  explicit MappableComponent(Expr *AssociatedExpression,
3892  ValueDecl *AssociatedDeclaration)
3893  : AssociatedExpression(AssociatedExpression),
3894  AssociatedDeclaration(
3895  AssociatedDeclaration
3896  ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
3897  : nullptr) {}
3898 
3899  Expr *getAssociatedExpression() const { return AssociatedExpression; }
3900 
3901  ValueDecl *getAssociatedDeclaration() const {
3902  return AssociatedDeclaration;
3903  }
3904  };
3905 
3906  // List of components of an expression. This first one is the whole
3907  // expression and the last one is the base expression.
3908  using MappableExprComponentList = SmallVector<MappableComponent, 8>;
3909  using MappableExprComponentListRef = ArrayRef<MappableComponent>;
3910 
3911  // List of all component lists associated to the same base declaration.
3912  // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
3913  // their component list but the same base declaration 'S'.
3914  using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
3915  using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
3916 
3917 protected:
3918  // Return the total number of elements in a list of component lists.
3919  static unsigned
3920  getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
3921 
3922  // Return the total number of elements in a list of declarations. All
3923  // declarations are expected to be canonical.
3924  static unsigned
3925  getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
3926 };
3927 
3928 /// This structure contains all sizes needed for by an
3929 /// OMPMappableExprListClause.
3931  /// Number of expressions listed.
3932  unsigned NumVars;
3933  /// Number of unique base declarations.
3935  /// Number of component lists.
3937  /// Total number of expression components.
3938  unsigned NumComponents;
3939  OMPMappableExprListSizeTy() = default;
3940  OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations,
3941  unsigned NumComponentLists, unsigned NumComponents)
3942  : NumVars(NumVars), NumUniqueDeclarations(NumUniqueDeclarations),
3943  NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
3944 };
3945 
3946 /// This represents clauses with a list of expressions that are mappable.
3947 /// Examples of these clauses are 'map' in
3948 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
3949 /// in '#pragma omp target update...' directives.
3950 template <class T>
3953  friend class OMPClauseReader;
3954 
3955  /// Number of unique declarations in this clause.
3956  unsigned NumUniqueDeclarations;
3957 
3958  /// Number of component lists in this clause.
3959  unsigned NumComponentLists;
3960 
3961  /// Total number of components in this clause.
3962  unsigned NumComponents;
3963 
3964  /// C++ nested name specifier for the associated user-defined mapper.
3965  NestedNameSpecifierLoc MapperQualifierLoc;
3966 
3967  /// The associated user-defined mapper identifier information.
3968  DeclarationNameInfo MapperIdInfo;
3969 
3970 protected:
3971  /// Build a clause for \a NumUniqueDeclarations declarations, \a
3972  /// NumComponentLists total component lists, and \a NumComponents total
3973  /// components.
3974  ///
3975  /// \param K Kind of the clause.
3976  /// \param Locs Locations needed to build a mappable clause. It includes 1)
3977  /// StartLoc: starting location of the clause (the clause keyword); 2)
3978  /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
3979  /// \param Sizes All required sizes to build a mappable clause. It includes 1)
3980  /// NumVars: number of expressions listed in this clause; 2)
3981  /// NumUniqueDeclarations: number of unique base declarations in this clause;
3982  /// 3) NumComponentLists: number of component lists in this clause; and 4)
3983  /// NumComponents: total number of expression components in the clause.
3984  /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
3985  /// user-defined mapper.
3986  /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
3988  OpenMPClauseKind K, const OMPVarListLocTy &Locs,
3989  const OMPMappableExprListSizeTy &Sizes,
3990  NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
3991  DeclarationNameInfo *MapperIdInfoPtr = nullptr)
3992  : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
3993  Sizes.NumVars),
3994  NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
3995  NumComponentLists(Sizes.NumComponentLists),
3996  NumComponents(Sizes.NumComponents) {
3997  if (MapperQualifierLocPtr)
3998  MapperQualifierLoc = *MapperQualifierLocPtr;
3999  if (MapperIdInfoPtr)
4000  MapperIdInfo = *MapperIdInfoPtr;
4001  }
4002 
4003  /// Get the unique declarations that are in the trailing objects of the
4004  /// class.
4005  MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
4006  return MutableArrayRef<ValueDecl *>(
4007  static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
4008  NumUniqueDeclarations);
4009  }
4010 
4011  /// Get the unique declarations that are in the trailing objects of the
4012  /// class.
4013  ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
4014  return ArrayRef<ValueDecl *>(
4015  static_cast<const T *>(this)
4016  ->template getTrailingObjects<ValueDecl *>(),
4017  NumUniqueDeclarations);
4018  }
4019 
4020  /// Set the unique declarations that are in the trailing objects of the
4021  /// class.
4022  void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
4023  assert(UDs.size() == NumUniqueDeclarations &&
4024  "Unexpected amount of unique declarations.");
4025  std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
4026  }
4027 
4028  /// Get the number of lists per declaration that are in the trailing
4029  /// objects of the class.
4030  MutableArrayRef<unsigned> getDeclNumListsRef() {
4031  return MutableArrayRef<unsigned>(
4032  static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
4033  NumUniqueDeclarations);
4034  }
4035 
4036  /// Get the number of lists per declaration that are in the trailing
4037  /// objects of the class.
4038  ArrayRef<unsigned> getDeclNumListsRef() const {
4039  return ArrayRef<unsigned>(
4040  static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
4041  NumUniqueDeclarations);
4042  }
4043 
4044  /// Set the number of lists per declaration that are in the trailing
4045  /// objects of the class.
4046  void setDeclNumLists(ArrayRef<unsigned> DNLs) {
4047  assert(DNLs.size() == NumUniqueDeclarations &&
4048  "Unexpected amount of list numbers.");
4049  std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
4050  }
4051 
4052  /// Get the cumulative component lists sizes that are in the trailing
4053  /// objects of the class. They are appended after the number of lists.
4054  MutableArrayRef<unsigned> getComponentListSizesRef() {
4055  return MutableArrayRef<unsigned>(
4056  static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
4057  NumUniqueDeclarations,
4058  NumComponentLists);
4059  }
4060 
4061  /// Get the cumulative component lists sizes that are in the trailing
4062  /// objects of the class. They are appended after the number of lists.
4063  ArrayRef<unsigned> getComponentListSizesRef() const {
4064  return ArrayRef<unsigned>(
4065  static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
4066  NumUniqueDeclarations,
4067  NumComponentLists);
4068  }
4069 
4070  /// Set the cumulative component lists sizes that are in the trailing
4071  /// objects of the class.
4072  void setComponentListSizes(ArrayRef<unsigned> CLSs) {
4073  assert(CLSs.size() == NumComponentLists &&
4074  "Unexpected amount of component lists.");
4075  std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
4076  }
4077 
4078  /// Get the components that are in the trailing objects of the class.
4079  MutableArrayRef<MappableComponent> getComponentsRef() {
4080  return MutableArrayRef<MappableComponent>(
4081  static_cast<T *>(this)
4082  ->template getTrailingObjects<MappableComponent>(),
4083  NumComponents);
4084  }
4085 
4086  /// Get the components that are in the trailing objects of the class.
4087  ArrayRef<MappableComponent> getComponentsRef() const {
4088  return ArrayRef<MappableComponent>(
4089  static_cast<const T *>(this)
4090  ->template getTrailingObjects<MappableComponent>(),
4091  NumComponents);
4092  }
4093 
4094  /// Set the components that are in the trailing objects of the class.
4095  /// This requires the list sizes so that it can also fill the original
4096  /// expressions, which are the first component of each list.
4097  void setComponents(ArrayRef<MappableComponent> Components,
4098  ArrayRef<unsigned> CLSs) {
4099  assert(Components.size() == NumComponents &&
4100  "Unexpected amount of component lists.");
4101  assert(CLSs.size() == NumComponentLists &&
4102  "Unexpected amount of list sizes.");
4103  std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
4104  }
4105 
4106  /// Fill the clause information from the list of declarations and
4107  /// associated component lists.
4108  void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
4109  MappableExprComponentListsRef ComponentLists) {
4110  // Perform some checks to make sure the data sizes are consistent with the
4111  // information available when the clause was created.
4112  assert(getUniqueDeclarationsTotalNumber(Declarations) ==
4113  NumUniqueDeclarations &&
4114  "Unexpected number of mappable expression info entries!");
4115  assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
4116  "Unexpected total number of components!");
4117  assert(Declarations.size() == ComponentLists.size() &&
4118  "Declaration and component lists size is not consistent!");
4119  assert(Declarations.size() == NumComponentLists &&
4120  "Unexpected declaration and component lists size!");
4121 
4122  // Organize the components by declaration and retrieve the original
4123  // expression. Original expressions are always the first component of the
4124  // mappable component list.
4125  llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
4126  ComponentListMap;
4127  {
4128  auto CI = ComponentLists.begin();
4129  for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
4130  ++DI, ++CI) {
4131  assert(!CI->empty() && "Invalid component list!");
4132  ComponentListMap[*DI].push_back(*CI);
4133  }
4134  }
4135 
4136  // Iterators of the target storage.
4137  auto UniqueDeclarations = getUniqueDeclsRef();
4138  auto UDI = UniqueDeclarations.begin();
4139 
4140  auto DeclNumLists = getDeclNumListsRef();
4141  auto DNLI = DeclNumLists.begin();
4142 
4143  auto ComponentListSizes = getComponentListSizesRef();
4144  auto CLSI = ComponentListSizes.begin();
4145 
4146  auto Components = getComponentsRef();
4147  auto CI = Components.begin();
4148 
4149  // Variable to compute the accumulation of the number of components.
4150  unsigned PrevSize = 0u;
4151 
4152  // Scan all the declarations and associated component lists.
4153  for (auto &M : ComponentListMap) {
4154  // The declaration.
4155  auto *D = M.first;
4156  // The component lists.
4157  auto CL = M.second;
4158 
4159  // Initialize the entry.
4160  *UDI = D;
4161  ++UDI;
4162 
4163  *DNLI = CL.size();
4164  ++DNLI;
4165 
4166  // Obtain the cumulative sizes and concatenate all the components in the
4167  // reserved storage.
4168  for (auto C : CL) {
4169  // Accumulate with the previous size.
4170  PrevSize += C.size();
4171 
4172  // Save the size.
4173  *CLSI = PrevSize;
4174  ++CLSI;
4175 
4176  // Append components after the current components iterator.
4177  CI = std::copy(C.begin(), C.end(), CI);
4178  }
4179  }
4180  }
4181 
4182  /// Set the nested name specifier of associated user-defined mapper.
4183  void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) {
4184  MapperQualifierLoc = NNSL;
4185  }
4186 
4187  /// Set the name of associated user-defined mapper.
4188  void setMapperIdInfo(DeclarationNameInfo MapperId) {
4189  MapperIdInfo = MapperId;
4190  }
4191 
4192  /// Get the user-defined mapper references that are in the trailing objects of
4193  /// the class.
4194  MutableArrayRef<Expr *> getUDMapperRefs() {
4195  return llvm::makeMutableArrayRef<Expr *>(
4196  static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
4199  }
4200 
4201  /// Get the user-defined mappers references that are in the trailing objects
4202  /// of the class.
4203  ArrayRef<Expr *> getUDMapperRefs() const {
4204  return llvm::makeArrayRef<Expr *>(
4205  static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
4208  }
4209 
4210  /// Set the user-defined mappers that are in the trailing objects of the
4211  /// class.
4212  void setUDMapperRefs(ArrayRef<Expr *> DMDs) {
4213  assert(DMDs.size() == OMPVarListClause<T>::varlist_size() &&
4214  "Unexpected number of user-defined mappers.");
4215  std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin());
4216  }
4217 
4218 public:
4219  /// Return the number of unique base declarations in this clause.
4220  unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
4221 
4222  /// Return the number of lists derived from the clause expressions.
4223  unsigned getTotalComponentListNum() const { return NumComponentLists; }
4224 
4225  /// Return the total number of components in all lists derived from the
4226  /// clause.
4227  unsigned getTotalComponentsNum() const { return NumComponents; }
4228 
4229  /// Gets the nested name specifier for associated user-defined mapper.
4230  NestedNameSpecifierLoc getMapperQualifierLoc() const {
4231  return MapperQualifierLoc;
4232  }
4233 
4234  /// Gets the name info for associated user-defined mapper.
4235  const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; }
4236 
4237  /// Iterator that browse the components by lists. It also allows
4238  /// browsing components of a single declaration.
4240  : public llvm::iterator_adaptor_base<
4241  const_component_lists_iterator,
4242  MappableExprComponentListRef::const_iterator,
4243  std::forward_iterator_tag, MappableComponent, ptrdiff_t,
4244  MappableComponent, MappableComponent> {
4245  // The declaration the iterator currently refers to.
4246  ArrayRef<ValueDecl *>::iterator DeclCur;
4247 
4248  // The list number associated with the current declaration.
4249  ArrayRef<unsigned>::iterator NumListsCur;
4250 
4251  // Remaining lists for the current declaration.
4252  unsigned RemainingLists = 0;
4253 
4254  // The cumulative size of the previous list, or zero if there is no previous
4255  // list.
4256  unsigned PrevListSize = 0;
4257 
4258  // The cumulative sizes of the current list - it will delimit the remaining
4259  // range of interest.
4260  ArrayRef<unsigned>::const_iterator ListSizeCur;
4261  ArrayRef<unsigned>::const_iterator ListSizeEnd;
4262 
4263  // Iterator to the end of the components storage.
4264  MappableExprComponentListRef::const_iterator End;
4265 
4266  public:
4267  /// Construct an iterator that scans all lists.
4269  ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
4270  ArrayRef<unsigned> CumulativeListSizes,
4271  MappableExprComponentListRef Components)
4272  : const_component_lists_iterator::iterator_adaptor_base(
4273  Components.begin()),
4274  DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
4275  ListSizeCur(CumulativeListSizes.begin()),
4276  ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
4277  assert(UniqueDecls.size() == DeclsListNum.size() &&
4278  "Inconsistent number of declarations and list sizes!");
4279  if (!DeclsListNum.empty())
4280  RemainingLists = *NumListsCur;
4281  }
4282 
4283  /// Construct an iterator that scan lists for a given declaration \a
4284  /// Declaration.
4286  const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
4287  ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
4288  MappableExprComponentListRef Components)
4289  : const_component_lists_iterator(UniqueDecls, DeclsListNum,
4290  CumulativeListSizes, Components) {
4291  // Look for the desired declaration. While we are looking for it, we
4292  // update the state so that we know the component where a given list
4293  // starts.
4294  for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
4295  if (*DeclCur == Declaration)
4296  break;
4297 
4298  assert(*NumListsCur > 0 && "No lists associated with declaration??");
4299 
4300  // Skip the lists associated with the current declaration, but save the
4301  // last list size that was skipped.
4302  std::advance(ListSizeCur, *NumListsCur - 1);
4303  PrevListSize = *ListSizeCur;
4304  ++ListSizeCur;
4305  }
4306 
4307  // If we didn't find any declaration, advance the iterator to after the
4308  // last component and set remaining lists to zero.
4309  if (ListSizeCur == CumulativeListSizes.end()) {
4310  this->I = End;
4311  RemainingLists = 0u;
4312  return;
4313  }
4314 
4315  // Set the remaining lists with the total number of lists of the current
4316  // declaration.
4317  RemainingLists = *NumListsCur;
4318 
4319  // Adjust the list size end iterator to the end of the relevant range.
4320  ListSizeEnd = ListSizeCur;
4321  std::advance(ListSizeEnd, RemainingLists);
4322 
4323  // Given that the list sizes are cumulative, the index of the component
4324  // that start the list is the size of the previous list.
4325  std::advance(this->I, PrevListSize);
4326  }
4327 
4328  // Return the array with the current list. The sizes are cumulative, so the
4329  // array size is the difference between the current size and previous one.
4330  std::pair<const ValueDecl *, MappableExprComponentListRef>
4331  operator*() const {
4332  assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
4333  return std::make_pair(
4334  *DeclCur,
4335  MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize));
4336  }
4337  std::pair<const ValueDecl *, MappableExprComponentListRef>
4338  operator->() const {
4339  return **this;
4340  }
4341 
4342  // Skip the components of the current list.
4344  assert(ListSizeCur != ListSizeEnd && RemainingLists &&
4345  "Invalid iterator!");
4346 
4347  // If we don't have more lists just skip all the components. Otherwise,
4348  // advance the iterator by the number of components in the current list.
4349  if (std::next(ListSizeCur) == ListSizeEnd) {
4350  this->I = End;
4351  RemainingLists = 0;
4352  } else {
4353  std::advance(this->I, *ListSizeCur - PrevListSize);
4354  PrevListSize = *ListSizeCur;
4355 
4356  // We are done with a declaration, move to the next one.
4357  if (!(--RemainingLists)) {
4358  ++DeclCur;
4359  ++NumListsCur;
4360  RemainingLists = *NumListsCur;
4361  assert(RemainingLists && "No lists in the following declaration??");
4362  }
4363  }
4364 
4365  ++ListSizeCur;
4366  return *this;
4367  }
4368  };
4369 
4371  llvm::iterator_range<const_component_lists_iterator>;
4372 
4373  /// Iterators for all component lists.
4374  const_component_lists_iterator component_lists_begin() const {
4375  return const_component_lists_iterator(
4376  getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
4377  getComponentsRef());
4378  }
4379  const_component_lists_iterator component_lists_end() const {
4380  return const_component_lists_iterator(
4381  ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
4382  MappableExprComponentListRef(getComponentsRef().end(),
4383  getComponentsRef().end()));
4384  }
4386  return {component_lists_begin(), component_lists_end()};
4387  }
4388 
4389  /// Iterators for component lists associated with the provided
4390  /// declaration.
4391  const_component_lists_iterator
4392  decl_component_lists_begin(const ValueDecl *VD) const {
4393  return const_component_lists_iterator(
4394  VD, getUniqueDeclsRef(), getDeclNumListsRef(),
4395  getComponentListSizesRef(), getComponentsRef());
4396  }
4397  const_component_lists_iterator decl_component_lists_end() const {
4398  return component_lists_end();
4399  }
4401  return {decl_component_lists_begin(VD), decl_component_lists_end()};
4402  }
4403 
4404  /// Iterators to access all the declarations, number of lists, list sizes, and
4405  /// components.
4406  using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
4407  using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
4408 
4410  auto A = getUniqueDeclsRef();
4411  return const_all_decls_range(A.begin(), A.end());
4412  }
4413 
4414  using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
4416  llvm::iterator_range<const_all_num_lists_iterator>;
4417 
4419  auto A = getDeclNumListsRef();
4420  return const_all_num_lists_range(A.begin(), A.end());
4421  }
4422 
4423  using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
4425  llvm::iterator_range<const_all_lists_sizes_iterator>;
4426 
4428  auto A = getComponentListSizesRef();
4429  return const_all_lists_sizes_range(A.begin(), A.end());
4430  }
4431 
4432  using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
4434  llvm::iterator_range<const_all_components_iterator>;
4435 
4437  auto A = getComponentsRef();
4438  return const_all_components_range(A.begin(), A.end());
4439  }
4440 
4441  using mapperlist_iterator = MutableArrayRef<Expr *>::iterator;
4442  using mapperlist_const_iterator = ArrayRef<const Expr *>::iterator;
4443  using mapperlist_range = llvm::iterator_range<mapperlist_iterator>;
4444  using mapperlist_const_range =
4445  llvm::iterator_range<mapperlist_const_iterator>;
4446 
4447  mapperlist_iterator mapperlist_begin() { return getUDMapperRefs().begin(); }
4448  mapperlist_iterator mapperlist_end() { return getUDMapperRefs().end(); }
4450  return getUDMapperRefs().begin();
4451  }
4453  return getUDMapperRefs().end();
4454  }
4456  return mapperlist_range(mapperlist_begin(), mapperlist_end());
4457  }
4459  return mapperlist_const_range(mapperlist_begin(), mapperlist_end());
4460  }
4461 };
4462 
4463 /// This represents clause 'map' in the '#pragma omp ...'
4464 /// directives.
4465 ///
4466 /// \code
4467 /// #pragma omp target map(a,b)
4468 /// \endcode
4469 /// In this example directive '#pragma omp target' has clause 'map'
4470 /// with the variables 'a' and 'b'.
4471 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
4472  private llvm::TrailingObjects<
4473  OMPMapClause, Expr *, ValueDecl *, unsigned,
4474  OMPClauseMappableExprCommon::MappableComponent> {
4475  friend class OMPClauseReader;
4477  friend OMPVarListClause;
4478  friend TrailingObjects;
4479 
4480  /// Define the sizes of each trailing object array except the last one. This
4481  /// is required for TrailingObjects to work properly.
4482  size_t numTrailingObjects(OverloadToken<Expr *>) const {
4483  // There are varlist_size() of expressions, and varlist_size() of
4484  // user-defined mappers.
4485  return 2 * varlist_size();
4486  }
4487  size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4488  return getUniqueDeclarationsNum();
4489  }
4490  size_t numTrailingObjects(OverloadToken<unsigned>) const {
4491  return getUniqueDeclarationsNum() + getTotalComponentListNum();
4492  }
4493 
4494 public:
4495  /// Number of allowed map-type-modifiers.
4496  static constexpr unsigned NumberOfModifiers =
4498 
4499 private:
4500  /// Map-type-modifiers for the 'map' clause.
4501  OpenMPMapModifierKind MapTypeModifiers[NumberOfModifiers] = {
4503  OMPC_MAP_MODIFIER_unknown};
4504 
4505  /// Location of map-type-modifiers for the 'map' clause.
4506  SourceLocation MapTypeModifiersLoc[NumberOfModifiers];
4507 
4508  /// Map type for the 'map' clause.
4510 
4511  /// Is this an implicit map type or not.
4512  bool MapTypeIsImplicit = false;
4513 
4514  /// Location of the map type.
4515  SourceLocation MapLoc;
4516 
4517  /// Colon location.
4518  SourceLocation ColonLoc;
4519 
4520  /// Build a clause for \a NumVars listed expressions, \a
4521  /// NumUniqueDeclarations declarations, \a NumComponentLists total component
4522  /// lists, and \a NumComponents total expression components.
4523  ///
4524  /// \param MapModifiers Map-type-modifiers.
4525  /// \param MapModifiersLoc Locations of map-type-modifiers.
4526  /// \param MapperQualifierLoc C++ nested name specifier for the associated
4527  /// user-defined mapper.
4528  /// \param MapperIdInfo The identifier of associated user-defined mapper.
4529  /// \param MapType Map type.
4530  /// \param MapTypeIsImplicit Map type is inferred implicitly.
4531  /// \param MapLoc Location of the map type.
4532  /// \param Locs Locations needed to build a mappable clause. It includes 1)
4533  /// StartLoc: starting location of the clause (the clause keyword); 2)
4534  /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4535  /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4536  /// NumVars: number of expressions listed in this clause; 2)
4537  /// NumUniqueDeclarations: number of unique base declarations in this clause;
4538  /// 3) NumComponentLists: number of component lists in this clause; and 4)
4539  /// NumComponents: total number of expression components in the clause.
4540  explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,
4541  ArrayRef<SourceLocation> MapModifiersLoc,
4542  NestedNameSpecifierLoc MapperQualifierLoc,
4543  DeclarationNameInfo MapperIdInfo,
4544  OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
4545  SourceLocation MapLoc, const OMPVarListLocTy &Locs,
4546  const OMPMappableExprListSizeTy &Sizes)
4547  : OMPMappableExprListClause(OMPC_map, Locs, Sizes, &MapperQualifierLoc,
4548  &MapperIdInfo),
4549  MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
4550  assert(llvm::array_lengthof(MapTypeModifiers) == MapModifiers.size() &&
4551  "Unexpected number of map type modifiers.");
4552  llvm::copy(MapModifiers, std::begin(MapTypeModifiers));
4553 
4554  assert(llvm::array_lengthof(MapTypeModifiersLoc) ==
4555  MapModifiersLoc.size() &&
4556  "Unexpected number of map type modifier locations.");
4557  llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
4558  }
4559 
4560  /// Build an empty clause.
4561  ///
4562  /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4563  /// NumVars: number of expressions listed in this clause; 2)
4564  /// NumUniqueDeclarations: number of unique base declarations in this clause;
4565  /// 3) NumComponentLists: number of component lists in this clause; and 4)
4566  /// NumComponents: total number of expression components in the clause.
4567  explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes)
4568  : OMPMappableExprListClause(OMPC_map, OMPVarListLocTy(), Sizes) {}
4569 
4570  /// Set map-type-modifier for the clause.
4571  ///
4572  /// \param I index for map-type-modifier.
4573  /// \param T map-type-modifier for the clause.
4574  void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
4575  assert(I < NumberOfModifiers &&
4576  "Unexpected index to store map type modifier, exceeds array size.");
4577  MapTypeModifiers[I] = T;
4578  }
4579 
4580  /// Set location for the map-type-modifier.
4581  ///
4582  /// \param I index for map-type-modifier location.
4583  /// \param TLoc map-type-modifier location.
4584  void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
4585  assert(I < NumberOfModifiers &&
4586  "Index to store map type modifier location exceeds array size.");
4587  MapTypeModifiersLoc[I] = TLoc;
4588  }
4589 
4590  /// Set type for the clause.
4591  ///
4592  /// \param T Type for the clause.
4593  void setMapType(OpenMPMapClauseKind T) { MapType = T; }
4594 
4595  /// Set type location.
4596  ///
4597  /// \param TLoc Type location.
4598  void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
4599 
4600  /// Set colon location.
4601  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4602 
4603 public:
4604  /// Creates clause with a list of variables \a VL.
4605  ///
4606  /// \param C AST context.
4607  /// \param Locs Locations needed to build a mappable clause. It includes 1)
4608  /// StartLoc: starting location of the clause (the clause keyword); 2)
4609  /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4610  /// \param Vars The original expression used in the clause.
4611  /// \param Declarations Declarations used in the clause.
4612  /// \param ComponentLists Component lists used in the clause.
4613  /// \param UDMapperRefs References to user-defined mappers associated with
4614  /// expressions used in the clause.
4615  /// \param MapModifiers Map-type-modifiers.
4616  /// \param MapModifiersLoc Location of map-type-modifiers.
4617  /// \param UDMQualifierLoc C++ nested name specifier for the associated
4618  /// user-defined mapper.
4619  /// \param MapperId The identifier of associated user-defined mapper.
4620  /// \param Type Map type.
4621  /// \param TypeIsImplicit Map type is inferred implicitly.
4622  /// \param TypeLoc Location of the map type.
4623  static OMPMapClause *
4624  Create(const ASTContext &C, const OMPVarListLocTy &Locs,
4625  ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
4626  MappableExprComponentListsRef ComponentLists,
4627  ArrayRef<Expr *> UDMapperRefs,
4628  ArrayRef<OpenMPMapModifierKind> MapModifiers,
4629  ArrayRef<SourceLocation> MapModifiersLoc,
4630  NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
4631  OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc);
4632 
4633  /// Creates an empty clause with the place for \a NumVars original
4634  /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
4635  /// lists, and \a NumComponents expression components.
4636  ///
4637  /// \param C AST context.
4638  /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4639  /// NumVars: number of expressions listed in this clause; 2)
4640  /// NumUniqueDeclarations: number of unique base declarations in this clause;
4641  /// 3) NumComponentLists: number of component lists in this clause; and 4)
4642  /// NumComponents: total number of expression components in the clause.
4643  static OMPMapClause *CreateEmpty(const ASTContext &C,
4644  const OMPMappableExprListSizeTy &Sizes);
4645 
4646  /// Fetches mapping kind for the clause.
4647  OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
4648 
4649  /// Is this an implicit map type?
4650  /// We have to capture 'IsMapTypeImplicit' from the parser for more
4651  /// informative error messages. It helps distinguish map(r) from
4652  /// map(tofrom: r), which is important to print more helpful error
4653  /// messages for some target directives.
4654  bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
4655 
4656  /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
4657  ///
4658  /// \param Cnt index for map-type-modifier.
4659  OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
4660  assert(Cnt < NumberOfModifiers &&
4661  "Requested modifier exceeds the total number of modifiers.");
4662  return MapTypeModifiers[Cnt];
4663  }
4664 
4665  /// Fetches the map-type-modifier location at 'Cnt' index of array of
4666  /// modifiers' locations.
4667  ///
4668  /// \param Cnt index for map-type-modifier location.
4669  SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
4670  assert(Cnt < NumberOfModifiers &&
4671  "Requested modifier location exceeds total number of modifiers.");
4672  return MapTypeModifiersLoc[Cnt];
4673  }
4674 
4675  /// Fetches ArrayRef of map-type-modifiers.
4676  ArrayRef<OpenMPMapModifierKind> getMapTypeModifiers() const LLVM_READONLY {
4677  return llvm::makeArrayRef(MapTypeModifiers);
4678  }
4679 
4680  /// Fetches ArrayRef of location of map-type-modifiers.
4681  ArrayRef<SourceLocation> getMapTypeModifiersLoc() const LLVM_READONLY {
4682  return llvm::makeArrayRef(MapTypeModifiersLoc);
4683  }
4684 
4685  /// Fetches location of clause mapping kind.
4686  SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
4687 
4688  /// Get colon location.
4689  SourceLocation getColonLoc() const { return ColonLoc; }
4690 
4692  return child_range(
4693  reinterpret_cast<Stmt **>(varlist_begin()),
4694  reinterpret_cast<Stmt **>(varlist_end()));
4695  }
4696 
4698  auto Children = const_cast<OMPMapClause *>(this)->children();
4699  return const_child_range(Children.begin(), Children.end());
4700  }
4701 
4702  static bool classof(const OMPClause *T) {
4703  return T->getClauseKind() == OMPC_map;
4704  }
4705 };
4706 
4707 /// This represents 'num_teams' clause in the '#pragma omp ...'
4708 /// directive.
4709 ///
4710 /// \code
4711 /// #pragma omp teams num_teams(n)
4712 /// \endcode
4713 /// In this example directive '#pragma omp teams' has clause 'num_teams'
4714 /// with single expression 'n'.
4715 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
4716  friend class OMPClauseReader;
4717 
4718  /// Location of '('.
4719  SourceLocation LParenLoc;
4720 
4721  /// NumTeams number.
4722  Stmt *NumTeams = nullptr;
4723 
4724  /// Set the NumTeams number.
4725  ///
4726  /// \param E NumTeams number.
4727  void setNumTeams(Expr *E) { NumTeams = E; }
4728 
4729 public:
4730  /// Build 'num_teams' clause.
4731  ///
4732  /// \param E Expression associated with this clause.
4733  /// \param HelperE Helper Expression associated with this clause.
4734  /// \param CaptureRegion Innermost OpenMP region where expressions in this
4735  /// clause must be captured.
4736  /// \param StartLoc Starting location of the clause.
4737  /// \param LParenLoc Location of '('.
4738  /// \param EndLoc Ending location of the clause.
4739  OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
4740  SourceLocation StartLoc, SourceLocation LParenLoc,
4741  SourceLocation EndLoc)
4742  : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this),
4743  LParenLoc(LParenLoc), NumTeams(E) {
4744  setPreInitStmt(HelperE, CaptureRegion);
4745  }
4746 
4747  /// Build an empty clause.
4749  : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
4750  OMPClauseWithPreInit(this) {}
4751 
4752  /// Sets the location of '('.
4753  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4754 
4755  /// Returns the location of '('.
4756  SourceLocation getLParenLoc() const { return LParenLoc; }
4757 
4758  /// Return NumTeams number.
4759  Expr *getNumTeams() { return cast<Expr>(NumTeams); }
4760 
4761  /// Return NumTeams number.
4762  Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
4763 
4764  child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
4765 
4767  return const_child_range(&NumTeams, &NumTeams + 1);
4768  }
4769 
4770  static bool classof(const OMPClause *T) {
4771  return T->getClauseKind() == OMPC_num_teams;
4772  }
4773 };
4774 
4775 /// This represents 'thread_limit' clause in the '#pragma omp ...'
4776 /// directive.
4777 ///
4778 /// \code
4779 /// #pragma omp teams thread_limit(n)
4780 /// \endcode
4781 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
4782 /// with single expression 'n'.
4783 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
4784  friend class OMPClauseReader;
4785 
4786  /// Location of '('.
4787  SourceLocation LParenLoc;
4788 
4789  /// ThreadLimit number.
4790  Stmt *ThreadLimit = nullptr;
4791 
4792  /// Set the ThreadLimit number.
4793  ///
4794  /// \param E ThreadLimit number.
4795  void setThreadLimit(Expr *E) { ThreadLimit = E; }
4796 
4797 public:
4798  /// Build 'thread_limit' clause.
4799  ///
4800  /// \param E Expression associated with this clause.
4801  /// \param HelperE Helper Expression associated with this clause.
4802  /// \param CaptureRegion Innermost OpenMP region where expressions in this
4803  /// clause must be captured.
4804  /// \param StartLoc Starting location of the clause.
4805  /// \param LParenLoc Location of '('.
4806  /// \param EndLoc Ending location of the clause.
4807  OMPThreadLimitClause(Expr *E, Stmt *HelperE,
4808  OpenMPDirectiveKind CaptureRegion,
4809  SourceLocation StartLoc, SourceLocation LParenLoc,
4810  SourceLocation EndLoc)
4811  : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
4812  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
4813  setPreInitStmt(HelperE, CaptureRegion);
4814  }
4815 
4816  /// Build an empty clause.
4818  : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
4819  OMPClauseWithPreInit(this) {}
4820 
4821  /// Sets the location of '('.
4822  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4823 
4824  /// Returns the location of '('.
4825  SourceLocation getLParenLoc() const { return LParenLoc; }
4826 
4827  /// Return ThreadLimit number.
4828  Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
4829 
4830  /// Return ThreadLimit number.
4831  Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
4832 
4833  child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
4834 
4836  return const_child_range(&ThreadLimit, &ThreadLimit + 1);
4837  }
4838 
4839  static bool classof(const OMPClause *T) {
4840  return T->getClauseKind() == OMPC_thread_limit;
4841  }
4842 };
4843 
4844 /// This represents 'priority' clause in the '#pragma omp ...'
4845 /// directive.
4846 ///
4847 /// \code
4848 /// #pragma omp task priority(n)
4849 /// \endcode
4850 /// In this example directive '#pragma omp teams' has clause 'priority' with
4851 /// single expression 'n'.
4853  friend class OMPClauseReader;
4854 
4855  /// Location of '('.
4856  SourceLocation LParenLoc;
4857 
4858  /// Priority number.
4859  Stmt *Priority = nullptr;
4860 
4861  /// Set the Priority number.
4862  ///
4863  /// \param E Priority number.
4864  void setPriority(Expr *E) { Priority = E; }
4865 
4866 public:
4867  /// Build 'priority' clause.
4868  ///
4869  /// \param E Expression associated with this clause.
4870  /// \param StartLoc Starting location of the clause.
4871  /// \param LParenLoc Location of '('.
4872  /// \param EndLoc Ending location of the clause.
4873  OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
4874  SourceLocation EndLoc)
4875  : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
4876  Priority(E) {}
4877 
4878  /// Build an empty clause.
4880  : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()) {}
4881 
4882  /// Sets the location of '('.
4883  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4884 
4885  /// Returns the location of '('.
4886  SourceLocation getLParenLoc() const { return LParenLoc; }
4887 
4888  /// Return Priority number.
4889  Expr *getPriority() { return cast<Expr>(Priority); }
4890 
4891  /// Return Priority number.
4892  Expr *getPriority() const { return cast<Expr>(Priority); }
4893 
4894  child_range children() { return child_range(&Priority, &Priority + 1); }
4895 
4897  return const_child_range(&Priority, &Priority + 1);
4898  }
4899 
4900  static bool classof(const OMPClause *T) {
4901  return T->getClauseKind() == OMPC_priority;
4902  }
4903 };
4904 
4905 /// This represents 'grainsize' clause in the '#pragma omp ...'
4906 /// directive.
4907 ///
4908 /// \code
4909 /// #pragma omp taskloop grainsize(4)
4910 /// \endcode
4911 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
4912 /// with single expression '4'.
4914  friend class OMPClauseReader;
4915 
4916  /// Location of '('.
4917  SourceLocation LParenLoc;
4918 
4919  /// Safe iteration space distance.
4920  Stmt *Grainsize = nullptr;
4921 
4922  /// Set safelen.
4923  void setGrainsize(Expr *Size) { Grainsize = Size; }
4924 
4925 public:
4926  /// Build 'grainsize' clause.
4927  ///
4928  /// \param Size Expression associated with this clause.
4929  /// \param StartLoc Starting location of the clause.
4930  /// \param EndLoc Ending location of the clause.
4931  OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
4932  SourceLocation LParenLoc, SourceLocation EndLoc)
4933  : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
4934  Grainsize(Size) {}
4935 
4936  /// Build an empty clause.
4938  : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()) {}
4939 
4940  /// Sets the location of '('.
4941  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4942 
4943  /// Returns the location of '('.
4944  SourceLocation getLParenLoc() const { return LParenLoc; }
4945 
4946  /// Return safe iteration space distance.
4947  Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
4948 
4949  child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
4950 
4952  return const_child_range(&Grainsize, &Grainsize + 1);
4953  }
4954 
4955  static bool classof(const OMPClause *T) {
4956  return T->getClauseKind() == OMPC_grainsize;
4957  }
4958 };
4959 
4960 /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
4961 ///
4962 /// \code
4963 /// #pragma omp taskloop nogroup
4964 /// \endcode
4965 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
4966 class OMPNogroupClause : public OMPClause {
4967 public:
4968  /// Build 'nogroup' clause.
4969  ///
4970  /// \param StartLoc Starting location of the clause.
4971  /// \param EndLoc Ending location of the clause.
4972  OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
4973  : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
4974 
4975  /// Build an empty clause.
4977  : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
4978 
4981  }
4982 
4985  }
4986 
4987  static bool classof(const OMPClause *T) {
4988  return T->getClauseKind() == OMPC_nogroup;
4989  }
4990 };
4991 
4992 /// This represents 'num_tasks' clause in the '#pragma omp ...'
4993 /// directive.
4994 ///
4995 /// \code
4996 /// #pragma omp taskloop num_tasks(4)
4997 /// \endcode
4998 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
4999 /// with single expression '4'.
5001  friend class OMPClauseReader;
5002 
5003  /// Location of '('.
5004  SourceLocation LParenLoc;
5005 
5006  /// Safe iteration space distance.
5007  Stmt *NumTasks = nullptr;
5008 
5009  /// Set safelen.
5010  void setNumTasks(Expr *Size) { NumTasks = Size; }
5011 
5012 public:
5013  /// Build 'num_tasks' clause.
5014  ///
5015  /// \param Size Expression associated with this clause.
5016  /// \param StartLoc Starting location of the clause.
5017  /// \param EndLoc Ending location of the clause.
5018  OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
5019  SourceLocation LParenLoc, SourceLocation EndLoc)
5020  : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
5021  NumTasks(Size) {}
5022 
5023  /// Build an empty clause.
5025  : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()) {}
5026 
5027  /// Sets the location of '('.
5028  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5029 
5030  /// Returns the location of '('.
5031  SourceLocation getLParenLoc() const { return LParenLoc; }
5032 
5033  /// Return safe iteration space distance.
5034  Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
5035 
5036  child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
5037 
5039  return const_child_range(&NumTasks, &NumTasks + 1);
5040  }
5041 
5042  static bool classof(const OMPClause *T) {
5043  return T->getClauseKind() == OMPC_num_tasks;
5044  }
5045 };
5046 
5047 /// This represents 'hint' clause in the '#pragma omp ...' directive.
5048 ///
5049 /// \code
5050 /// #pragma omp critical (name) hint(6)
5051 /// \endcode
5052 /// In this example directive '#pragma omp critical' has name 'name' and clause
5053 /// 'hint' with argument '6'.
5054 class OMPHintClause : public OMPClause {
5055  friend class OMPClauseReader;
5056 
5057  /// Location of '('.
5058  SourceLocation LParenLoc;
5059 
5060  /// Hint expression of the 'hint' clause.
5061  Stmt *Hint = nullptr;
5062 
5063  /// Set hint expression.
5064  void setHint(Expr *H) { Hint = H; }
5065 
5066 public:
5067  /// Build 'hint' clause with expression \a Hint.
5068  ///
5069  /// \param Hint Hint expression.
5070  /// \param StartLoc Starting location of the clause.
5071  /// \param LParenLoc Location of '('.
5072  /// \param EndLoc Ending location of the clause.
5073  OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
5074  SourceLocation EndLoc)
5075  : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
5076  Hint(Hint) {}
5077 
5078  /// Build an empty clause.
5079  OMPHintClause() : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()) {}
5080 
5081  /// Sets the location of '('.
5082  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5083 
5084  /// Returns the location of '('.
5085  SourceLocation getLParenLoc() const { return LParenLoc; }
5086 
5087  /// Returns number of threads.
5088  Expr *getHint() const { return cast_or_null<Expr>(Hint); }
5089 
5090  child_range children() { return child_range(&Hint, &Hint + 1); }
5091 
5093  return const_child_range(&Hint, &Hint + 1);
5094  }
5095 
5096  static bool classof(const OMPClause *T) {
5097  return T->getClauseKind() == OMPC_hint;
5098  }
5099 };
5100 
5101 /// This represents 'dist_schedule' clause in the '#pragma omp ...'
5102 /// directive.
5103 ///
5104 /// \code
5105 /// #pragma omp distribute dist_schedule(static, 3)
5106 /// \endcode
5107 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
5108 /// clause with arguments 'static' and '3'.
5109 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
5110  friend class OMPClauseReader;
5111 
5112  /// Location of '('.
5113  SourceLocation LParenLoc;
5114 
5115  /// A kind of the 'schedule' clause.
5117 
5118  /// Start location of the schedule kind in source code.
5119  SourceLocation KindLoc;
5120 
5121  /// Location of ',' (if any).
5122  SourceLocation CommaLoc;
5123 
5124  /// Chunk size.
5125  Expr *ChunkSize = nullptr;
5126 
5127  /// Set schedule kind.
5128  ///
5129  /// \param K Schedule kind.
5130  void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
5131 
5132  /// Sets the location of '('.
5133  ///
5134  /// \param Loc Location of '('.
5135  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5136 
5137  /// Set schedule kind start location.
5138  ///
5139  /// \param KLoc Schedule kind location.
5140  void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
5141 
5142  /// Set location of ','.
5143  ///
5144  /// \param Loc Location of ','.
5145  void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
5146 
5147  /// Set chunk size.
5148  ///
5149  /// \param E Chunk size.
5150  void setChunkSize(Expr *E) { ChunkSize = E; }
5151 
5152 public:
5153  /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
5154  /// size expression \a ChunkSize.
5155  ///
5156  /// \param StartLoc Starting location of the clause.
5157  /// \param LParenLoc Location of '('.
5158  /// \param KLoc Starting location of the argument.
5159  /// \param CommaLoc Location of ','.
5160  /// \param EndLoc Ending location of the clause.
5161  /// \param Kind DistSchedule kind.
5162  /// \param ChunkSize Chunk size.
5163  /// \param HelperChunkSize Helper chunk size for combined directives.
5164  OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5165  SourceLocation KLoc, SourceLocation CommaLoc,
5166  SourceLocation EndLoc,
5167  OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
5168  Stmt *HelperChunkSize)
5169  : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc),
5170  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
5171  KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
5172  setPreInitStmt(HelperChunkSize);
5173  }
5174 
5175  /// Build an empty clause.
5177  : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()),
5178  OMPClauseWithPreInit(this) {}
5179 
5180  /// Get kind of the clause.
5182 
5183  /// Get location of '('.
5184  SourceLocation getLParenLoc() { return LParenLoc; }
5185 
5186  /// Get kind location.
5187  SourceLocation getDistScheduleKindLoc() { return KindLoc; }
5188 
5189  /// Get location of ','.
5190  SourceLocation getCommaLoc() { return CommaLoc; }
5191 
5192  /// Get chunk size.
5193  Expr *getChunkSize() { return ChunkSize; }
5194 
5195  /// Get chunk size.
5196  const Expr *getChunkSize() const { return ChunkSize; }
5197 
5199  return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
5200  reinterpret_cast<Stmt **>(&ChunkSize) + 1);
5201  }
5202 
5204  auto Children = const_cast<OMPDistScheduleClause *>(this)->children();
5205  return const_child_range(Children.begin(), Children.end());
5206  }
5207 
5208  static bool classof(const OMPClause *T) {
5209  return T->getClauseKind() == OMPC_dist_schedule;
5210  }
5211 };
5212 
5213 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
5214 ///
5215 /// \code
5216 /// #pragma omp target defaultmap(tofrom: scalar)
5217 /// \endcode
5218 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
5219 /// 'scalar' with modifier 'tofrom'.
5221  friend class OMPClauseReader;
5222 
5223  /// Location of '('.
5224  SourceLocation LParenLoc;
5225 
5226  /// Modifiers for 'defaultmap' clause.
5228 
5229  /// Locations of modifiers.
5230  SourceLocation ModifierLoc;
5231 
5232  /// A kind of the 'defaultmap' clause.
5234 
5235  /// Start location of the defaultmap kind in source code.
5236  SourceLocation KindLoc;
5237 
5238  /// Set defaultmap kind.
5239  ///
5240  /// \param K Defaultmap kind.
5241  void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
5242 
5243  /// Set the defaultmap modifier.
5244  ///
5245  /// \param M Defaultmap modifier.
5246  void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
5247  Modifier = M;
5248  }
5249 
5250  /// Set location of the defaultmap modifier.
5251  void setDefaultmapModifierLoc(SourceLocation Loc) {
5252  ModifierLoc = Loc;
5253  }
5254 
5255  /// Sets the location of '('.
5256  ///
5257  /// \param Loc Location of '('.
5258  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5259 
5260  /// Set defaultmap kind start location.
5261  ///
5262  /// \param KLoc Defaultmap kind location.
5263  void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
5264 
5265 public:
5266  /// Build 'defaultmap' clause with defaultmap kind \a Kind
5267  ///
5268  /// \param StartLoc Starting location of the clause.
5269  /// \param LParenLoc Location of '('.
5270  /// \param KLoc Starting location of the argument.
5271  /// \param EndLoc Ending location of the clause.
5272  /// \param Kind Defaultmap kind.
5273  /// \param M The modifier applied to 'defaultmap' clause.
5274  /// \param MLoc Location of the modifier
5275  OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5276  SourceLocation MLoc, SourceLocation KLoc,
5277  SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
5279  : OMPClause(OMPC_defaultmap, StartLoc, EndLoc), LParenLoc(LParenLoc),
5280  Modifier(M), ModifierLoc(MLoc), Kind(Kind), KindLoc(KLoc) {}
5281 
5282  /// Build an empty clause.
5284  : OMPClause(OMPC_defaultmap, SourceLocation(), SourceLocation()) {}
5285 
5286  /// Get kind of the clause.
5288 
5289  /// Get the modifier of the clause.
5291  return Modifier;
5292  }
5293 
5294  /// Get location of '('.
5295  SourceLocation getLParenLoc() { return LParenLoc; }
5296 
5297  /// Get kind location.
5298  SourceLocation getDefaultmapKindLoc() { return KindLoc; }
5299 
5300  /// Get the modifier location.
5301  SourceLocation getDefaultmapModifierLoc() const {
5302  return ModifierLoc;
5303  }
5304 
5307  }
5308 
5311  }
5312 
5313  static bool classof(const OMPClause *T) {
5314  return T->getClauseKind() == OMPC_defaultmap;
5315  }
5316 };
5317 
5318 /// This represents clause 'to' in the '#pragma omp ...'
5319 /// directives.
5320 ///
5321 /// \code
5322 /// #pragma omp target update to(a,b)
5323 /// \endcode
5324 /// In this example directive '#pragma omp target update' has clause 'to'
5325 /// with the variables 'a' and 'b'.
5326 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
5327  private llvm::TrailingObjects<
5328  OMPToClause, Expr *, ValueDecl *, unsigned,
5329  OMPClauseMappableExprCommon::MappableComponent> {
5330  friend class OMPClauseReader;
5332  friend OMPVarListClause;
5333  friend TrailingObjects;