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