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