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