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 'schedule' clause in the '#pragma omp ...' directive.
863 ///
864 /// \code
865 /// #pragma omp for schedule(static, 3)
866 /// \endcode
867 /// In this example directive '#pragma omp for' has 'schedule' clause with
868 /// arguments 'static' and '3'.
869 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
870  friend class OMPClauseReader;
871 
872  /// Location of '('.
873  SourceLocation LParenLoc;
874 
875  /// A kind of the 'schedule' clause.
877 
878  /// Modifiers for 'schedule' clause.
879  enum {FIRST, SECOND, NUM_MODIFIERS};
880  OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
881 
882  /// Locations of modifiers.
883  SourceLocation ModifiersLoc[NUM_MODIFIERS];
884 
885  /// Start location of the schedule ind in source code.
886  SourceLocation KindLoc;
887 
888  /// Location of ',' (if any).
889  SourceLocation CommaLoc;
890 
891  /// Chunk size.
892  Expr *ChunkSize = nullptr;
893 
894  /// Set schedule kind.
895  ///
896  /// \param K Schedule kind.
897  void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
898 
899  /// Set the first schedule modifier.
900  ///
901  /// \param M Schedule modifier.
902  void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
903  Modifiers[FIRST] = M;
904  }
905 
906  /// Set the second schedule modifier.
907  ///
908  /// \param M Schedule modifier.
909  void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
910  Modifiers[SECOND] = M;
911  }
912 
913  /// Set location of the first schedule modifier.
914  void setFirstScheduleModifierLoc(SourceLocation Loc) {
915  ModifiersLoc[FIRST] = Loc;
916  }
917 
918  /// Set location of the second schedule modifier.
919  void setSecondScheduleModifierLoc(SourceLocation Loc) {
920  ModifiersLoc[SECOND] = Loc;
921  }
922 
923  /// Set schedule modifier location.
924  ///
925  /// \param M Schedule modifier location.
926  void setScheduleModifer(OpenMPScheduleClauseModifier M) {
927  if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
928  Modifiers[FIRST] = M;
929  else {
930  assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
931  Modifiers[SECOND] = M;
932  }
933  }
934 
935  /// Sets the location of '('.
936  ///
937  /// \param Loc Location of '('.
938  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
939 
940  /// Set schedule kind start location.
941  ///
942  /// \param KLoc Schedule kind location.
943  void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
944 
945  /// Set location of ','.
946  ///
947  /// \param Loc Location of ','.
948  void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
949 
950  /// Set chunk size.
951  ///
952  /// \param E Chunk size.
953  void setChunkSize(Expr *E) { ChunkSize = E; }
954 
955 public:
956  /// Build 'schedule' clause with schedule kind \a Kind and chunk size
957  /// expression \a ChunkSize.
958  ///
959  /// \param StartLoc Starting location of the clause.
960  /// \param LParenLoc Location of '('.
961  /// \param KLoc Starting location of the argument.
962  /// \param CommaLoc Location of ','.
963  /// \param EndLoc Ending location of the clause.
964  /// \param Kind Schedule kind.
965  /// \param ChunkSize Chunk size.
966  /// \param HelperChunkSize Helper chunk size for combined directives.
967  /// \param M1 The first modifier applied to 'schedule' clause.
968  /// \param M1Loc Location of the first modifier
969  /// \param M2 The second modifier applied to 'schedule' clause.
970  /// \param M2Loc Location of the second modifier
972  SourceLocation KLoc, SourceLocation CommaLoc,
974  Expr *ChunkSize, Stmt *HelperChunkSize,
977  : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this),
978  LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc),
979  ChunkSize(ChunkSize) {
980  setPreInitStmt(HelperChunkSize);
981  Modifiers[FIRST] = M1;
982  Modifiers[SECOND] = M2;
983  ModifiersLoc[FIRST] = M1Loc;
984  ModifiersLoc[SECOND] = M2Loc;
985  }
986 
987  /// Build an empty clause.
988  explicit OMPScheduleClause()
989  : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
990  OMPClauseWithPreInit(this) {
991  Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
992  Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
993  }
994 
995  /// Get kind of the clause.
997 
998  /// Get the first modifier of the clause.
1000  return Modifiers[FIRST];
1001  }
1002 
1003  /// Get the second modifier of the clause.
1005  return Modifiers[SECOND];
1006  }
1007 
1008  /// Get location of '('.
1009  SourceLocation getLParenLoc() { return LParenLoc; }
1010 
1011  /// Get kind location.
1012  SourceLocation getScheduleKindLoc() { return KindLoc; }
1013 
1014  /// Get the first modifier location.
1016  return ModifiersLoc[FIRST];
1017  }
1018 
1019  /// Get the second modifier location.
1021  return ModifiersLoc[SECOND];
1022  }
1023 
1024  /// Get location of ','.
1025  SourceLocation getCommaLoc() { return CommaLoc; }
1026 
1027  /// Get chunk size.
1028  Expr *getChunkSize() { return ChunkSize; }
1029 
1030  /// Get chunk size.
1031  const Expr *getChunkSize() const { return ChunkSize; }
1032 
1034  return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1035  reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1036  }
1037 
1038  static bool classof(const OMPClause *T) {
1039  return T->getClauseKind() == OMPC_schedule;
1040  }
1041 };
1042 
1043 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1044 ///
1045 /// \code
1046 /// #pragma omp for ordered (2)
1047 /// \endcode
1048 /// In this example directive '#pragma omp for' has 'ordered' clause with
1049 /// parameter 2.
1050 class OMPOrderedClause final
1051  : public OMPClause,
1052  private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1053  friend class OMPClauseReader;
1054  friend TrailingObjects;
1055 
1056  /// Location of '('.
1057  SourceLocation LParenLoc;
1058 
1059  /// Number of for-loops.
1060  Stmt *NumForLoops = nullptr;
1061 
1062  /// Real number of loops.
1063  unsigned NumberOfLoops = 0;
1064 
1065  /// Build 'ordered' clause.
1066  ///
1067  /// \param Num Expression, possibly associated with this clause.
1068  /// \param NumLoops Number of loops, associated with this clause.
1069  /// \param StartLoc Starting location of the clause.
1070  /// \param LParenLoc Location of '('.
1071  /// \param EndLoc Ending location of the clause.
1072  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1073  SourceLocation LParenLoc, SourceLocation EndLoc)
1074  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
1075  NumForLoops(Num), NumberOfLoops(NumLoops) {}
1076 
1077  /// Build an empty clause.
1078  explicit OMPOrderedClause(unsigned NumLoops)
1079  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
1080  NumberOfLoops(NumLoops) {}
1081 
1082  /// Set the number of associated for-loops.
1083  void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1084 
1085 public:
1086  /// Build 'ordered' clause.
1087  ///
1088  /// \param Num Expression, possibly associated with this clause.
1089  /// \param NumLoops Number of loops, associated with this clause.
1090  /// \param StartLoc Starting location of the clause.
1091  /// \param LParenLoc Location of '('.
1092  /// \param EndLoc Ending location of the clause.
1093  static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1094  unsigned NumLoops, SourceLocation StartLoc,
1095  SourceLocation LParenLoc,
1096  SourceLocation EndLoc);
1097 
1098  /// Build an empty clause.
1099  static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1100 
1101  /// Sets the location of '('.
1102  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1103 
1104  /// Returns the location of '('.
1105  SourceLocation getLParenLoc() const { return LParenLoc; }
1106 
1107  /// Return the number of associated for-loops.
1108  Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1109 
1110  /// Set number of iterations for the specified loop.
1111  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1112  /// Get number of iterations for all the loops.
1113  ArrayRef<Expr *> getLoopNumIterations() const;
1114 
1115  /// Set loop counter for the specified loop.
1116  void setLoopCounter(unsigned NumLoop, Expr *Counter);
1117  /// Get loops counter for the specified loop.
1118  Expr *getLoopCounter(unsigned NumLoop);
1119  const Expr *getLoopCounter(unsigned NumLoop) const;
1120 
1121  child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1122 
1123  static bool classof(const OMPClause *T) {
1124  return T->getClauseKind() == OMPC_ordered;
1125  }
1126 };
1127 
1128 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1129 ///
1130 /// \code
1131 /// #pragma omp for nowait
1132 /// \endcode
1133 /// In this example directive '#pragma omp for' has 'nowait' clause.
1134 class OMPNowaitClause : public OMPClause {
1135 public:
1136  /// Build 'nowait' clause.
1137  ///
1138  /// \param StartLoc Starting location of the clause.
1139  /// \param EndLoc Ending location of the clause.
1141  : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
1142 
1143  /// Build an empty clause.
1145  : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
1146 
1149  }
1150 
1151  static bool classof(const OMPClause *T) {
1152  return T->getClauseKind() == OMPC_nowait;
1153  }
1154 };
1155 
1156 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1157 ///
1158 /// \code
1159 /// #pragma omp task untied
1160 /// \endcode
1161 /// In this example directive '#pragma omp task' has 'untied' clause.
1162 class OMPUntiedClause : public OMPClause {
1163 public:
1164  /// Build 'untied' clause.
1165  ///
1166  /// \param StartLoc Starting location of the clause.
1167  /// \param EndLoc Ending location of the clause.
1169  : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
1170 
1171  /// Build an empty clause.
1173  : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
1174 
1177  }
1178 
1179  static bool classof(const OMPClause *T) {
1180  return T->getClauseKind() == OMPC_untied;
1181  }
1182 };
1183 
1184 /// This represents 'mergeable' clause in the '#pragma omp ...'
1185 /// directive.
1186 ///
1187 /// \code
1188 /// #pragma omp task mergeable
1189 /// \endcode
1190 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1192 public:
1193  /// Build 'mergeable' clause.
1194  ///
1195  /// \param StartLoc Starting location of the clause.
1196  /// \param EndLoc Ending location of the clause.
1198  : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
1199 
1200  /// Build an empty clause.
1202  : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
1203 
1206  }
1207 
1208  static bool classof(const OMPClause *T) {
1209  return T->getClauseKind() == OMPC_mergeable;
1210  }
1211 };
1212 
1213 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1214 ///
1215 /// \code
1216 /// #pragma omp atomic read
1217 /// \endcode
1218 /// In this example directive '#pragma omp atomic' has 'read' clause.
1219 class OMPReadClause : public OMPClause {
1220 public:
1221  /// Build 'read' clause.
1222  ///
1223  /// \param StartLoc Starting location of the clause.
1224  /// \param EndLoc Ending location of the clause.
1226  : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1227 
1228  /// Build an empty clause.
1230 
1233  }
1234 
1235  static bool classof(const OMPClause *T) {
1236  return T->getClauseKind() == OMPC_read;
1237  }
1238 };
1239 
1240 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1241 ///
1242 /// \code
1243 /// #pragma omp atomic write
1244 /// \endcode
1245 /// In this example directive '#pragma omp atomic' has 'write' clause.
1246 class OMPWriteClause : public OMPClause {
1247 public:
1248  /// Build 'write' clause.
1249  ///
1250  /// \param StartLoc Starting location of the clause.
1251  /// \param EndLoc Ending location of the clause.
1253  : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1254 
1255  /// Build an empty clause.
1257  : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1258 
1261  }
1262 
1263  static bool classof(const OMPClause *T) {
1264  return T->getClauseKind() == OMPC_write;
1265  }
1266 };
1267 
1268 /// This represents 'update' clause in the '#pragma omp atomic'
1269 /// directive.
1270 ///
1271 /// \code
1272 /// #pragma omp atomic update
1273 /// \endcode
1274 /// In this example directive '#pragma omp atomic' has 'update' clause.
1275 class OMPUpdateClause : public OMPClause {
1276 public:
1277  /// Build 'update' clause.
1278  ///
1279  /// \param StartLoc Starting location of the clause.
1280  /// \param EndLoc Ending location of the clause.
1282  : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1283 
1284  /// Build an empty clause.
1286  : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1287 
1290  }
1291 
1292  static bool classof(const OMPClause *T) {
1293  return T->getClauseKind() == OMPC_update;
1294  }
1295 };
1296 
1297 /// This represents 'capture' clause in the '#pragma omp atomic'
1298 /// directive.
1299 ///
1300 /// \code
1301 /// #pragma omp atomic capture
1302 /// \endcode
1303 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1304 class OMPCaptureClause : public OMPClause {
1305 public:
1306  /// Build 'capture' clause.
1307  ///
1308  /// \param StartLoc Starting location of the clause.
1309  /// \param EndLoc Ending location of the clause.
1311  : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1312 
1313  /// Build an empty clause.
1315  : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1316 
1319  }
1320 
1321  static bool classof(const OMPClause *T) {
1322  return T->getClauseKind() == OMPC_capture;
1323  }
1324 };
1325 
1326 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
1327 /// directive.
1328 ///
1329 /// \code
1330 /// #pragma omp atomic seq_cst
1331 /// \endcode
1332 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1333 class OMPSeqCstClause : public OMPClause {
1334 public:
1335  /// Build 'seq_cst' clause.
1336  ///
1337  /// \param StartLoc Starting location of the clause.
1338  /// \param EndLoc Ending location of the clause.
1340  : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1341 
1342  /// Build an empty clause.
1344  : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1345 
1348  }
1349 
1350  static bool classof(const OMPClause *T) {
1351  return T->getClauseKind() == OMPC_seq_cst;
1352  }
1353 };
1354 
1355 /// This represents clause 'private' in the '#pragma omp ...' directives.
1356 ///
1357 /// \code
1358 /// #pragma omp parallel private(a,b)
1359 /// \endcode
1360 /// In this example directive '#pragma omp parallel' has clause 'private'
1361 /// with the variables 'a' and 'b'.
1362 class OMPPrivateClause final
1363  : public OMPVarListClause<OMPPrivateClause>,
1364  private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1365  friend class OMPClauseReader;
1366  friend OMPVarListClause;
1367  friend TrailingObjects;
1368 
1369  /// Build clause with number of variables \a N.
1370  ///
1371  /// \param StartLoc Starting location of the clause.
1372  /// \param LParenLoc Location of '('.
1373  /// \param EndLoc Ending location of the clause.
1374  /// \param N Number of the variables in the clause.
1375  OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1376  SourceLocation EndLoc, unsigned N)
1377  : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1378  EndLoc, N) {}
1379 
1380  /// Build an empty clause.
1381  ///
1382  /// \param N Number of variables.
1383  explicit OMPPrivateClause(unsigned N)
1386  N) {}
1387 
1388  /// Sets the list of references to private copies with initializers for
1389  /// new private variables.
1390  /// \param VL List of references.
1391  void setPrivateCopies(ArrayRef<Expr *> VL);
1392 
1393  /// Gets the list of references to private copies with initializers for
1394  /// new private variables.
1395  MutableArrayRef<Expr *> getPrivateCopies() {
1396  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1397  }
1398  ArrayRef<const Expr *> getPrivateCopies() const {
1399  return llvm::makeArrayRef(varlist_end(), varlist_size());
1400  }
1401 
1402 public:
1403  /// Creates clause with a list of variables \a VL.
1404  ///
1405  /// \param C AST context.
1406  /// \param StartLoc Starting location of the clause.
1407  /// \param LParenLoc Location of '('.
1408  /// \param EndLoc Ending location of the clause.
1409  /// \param VL List of references to the variables.
1410  /// \param PrivateVL List of references to private copies with initializers.
1411  static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1412  SourceLocation LParenLoc,
1413  SourceLocation EndLoc, ArrayRef<Expr *> VL,
1414  ArrayRef<Expr *> PrivateVL);
1415 
1416  /// Creates an empty clause with the place for \a N variables.
1417  ///
1418  /// \param C AST context.
1419  /// \param N The number of variables.
1420  static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1421 
1424  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1426  llvm::iterator_range<private_copies_const_iterator>;
1427 
1429  return private_copies_range(getPrivateCopies().begin(),
1430  getPrivateCopies().end());
1431  }
1432 
1434  return private_copies_const_range(getPrivateCopies().begin(),
1435  getPrivateCopies().end());
1436  }
1437 
1439  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1440  reinterpret_cast<Stmt **>(varlist_end()));
1441  }
1442 
1443  static bool classof(const OMPClause *T) {
1444  return T->getClauseKind() == OMPC_private;
1445  }
1446 };
1447 
1448 /// This represents clause 'firstprivate' in the '#pragma omp ...'
1449 /// directives.
1450 ///
1451 /// \code
1452 /// #pragma omp parallel firstprivate(a,b)
1453 /// \endcode
1454 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1455 /// with the variables 'a' and 'b'.
1457  : public OMPVarListClause<OMPFirstprivateClause>,
1458  public OMPClauseWithPreInit,
1459  private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1460  friend class OMPClauseReader;
1461  friend OMPVarListClause;
1462  friend TrailingObjects;
1463 
1464  /// Build clause with number of variables \a N.
1465  ///
1466  /// \param StartLoc Starting location of the clause.
1467  /// \param LParenLoc Location of '('.
1468  /// \param EndLoc Ending location of the clause.
1469  /// \param N Number of the variables in the clause.
1471  SourceLocation EndLoc, unsigned N)
1472  : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1473  LParenLoc, EndLoc, N),
1474  OMPClauseWithPreInit(this) {}
1475 
1476  /// Build an empty clause.
1477  ///
1478  /// \param N Number of variables.
1479  explicit OMPFirstprivateClause(unsigned N)
1481  OMPC_firstprivate, SourceLocation(), SourceLocation(),
1482  SourceLocation(), N),
1483  OMPClauseWithPreInit(this) {}
1484 
1485  /// Sets the list of references to private copies with initializers for
1486  /// new private variables.
1487  /// \param VL List of references.
1488  void setPrivateCopies(ArrayRef<Expr *> VL);
1489 
1490  /// Gets the list of references to private copies with initializers for
1491  /// new private variables.
1492  MutableArrayRef<Expr *> getPrivateCopies() {
1493  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1494  }
1495  ArrayRef<const Expr *> getPrivateCopies() const {
1496  return llvm::makeArrayRef(varlist_end(), varlist_size());
1497  }
1498 
1499  /// Sets the list of references to initializer variables for new
1500  /// private variables.
1501  /// \param VL List of references.
1502  void setInits(ArrayRef<Expr *> VL);
1503 
1504  /// Gets the list of references to initializer variables for new
1505  /// private variables.
1507  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1508  }
1510  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1511  }
1512 
1513 public:
1514  /// Creates clause with a list of variables \a VL.
1515  ///
1516  /// \param C AST context.
1517  /// \param StartLoc Starting location of the clause.
1518  /// \param LParenLoc Location of '('.
1519  /// \param EndLoc Ending location of the clause.
1520  /// \param VL List of references to the original variables.
1521  /// \param PrivateVL List of references to private copies with initializers.
1522  /// \param InitVL List of references to auto generated variables used for
1523  /// initialization of a single array element. Used if firstprivate variable is
1524  /// of array type.
1525  /// \param PreInit Statement that must be executed before entering the OpenMP
1526  /// region with this clause.
1527  static OMPFirstprivateClause *
1528  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1529  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1530  ArrayRef<Expr *> InitVL, Stmt *PreInit);
1531 
1532  /// Creates an empty clause with the place for \a N variables.
1533  ///
1534  /// \param C AST context.
1535  /// \param N The number of variables.
1536  static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1537 
1540  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1542  llvm::iterator_range<private_copies_const_iterator>;
1543 
1545  return private_copies_range(getPrivateCopies().begin(),
1546  getPrivateCopies().end());
1547  }
1549  return private_copies_const_range(getPrivateCopies().begin(),
1550  getPrivateCopies().end());
1551  }
1552 
1555  using inits_range = llvm::iterator_range<inits_iterator>;
1556  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
1557 
1559  return inits_range(getInits().begin(), getInits().end());
1560  }
1562  return inits_const_range(getInits().begin(), getInits().end());
1563  }
1564 
1566  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1567  reinterpret_cast<Stmt **>(varlist_end()));
1568  }
1569 
1570  static bool classof(const OMPClause *T) {
1571  return T->getClauseKind() == OMPC_firstprivate;
1572  }
1573 };
1574 
1575 /// This represents clause 'lastprivate' in the '#pragma omp ...'
1576 /// directives.
1577 ///
1578 /// \code
1579 /// #pragma omp simd lastprivate(a,b)
1580 /// \endcode
1581 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1582 /// with the variables 'a' and 'b'.
1584  : public OMPVarListClause<OMPLastprivateClause>,
1585  public OMPClauseWithPostUpdate,
1586  private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
1587  // There are 4 additional tail-allocated arrays at the end of the class:
1588  // 1. Contains list of pseudo variables with the default initialization for
1589  // each non-firstprivate variables. Used in codegen for initialization of
1590  // lastprivate copies.
1591  // 2. List of helper expressions for proper generation of assignment operation
1592  // required for lastprivate clause. This list represents private variables
1593  // (for arrays, single array element).
1594  // 3. List of helper expressions for proper generation of assignment operation
1595  // required for lastprivate clause. This list represents original variables
1596  // (for arrays, single array element).
1597  // 4. List of helper expressions that represents assignment operation:
1598  // \code
1599  // DstExprs = SrcExprs;
1600  // \endcode
1601  // Required for proper codegen of final assignment performed by the
1602  // lastprivate clause.
1603  friend class OMPClauseReader;
1604  friend OMPVarListClause;
1605  friend TrailingObjects;
1606 
1607  /// Build clause with number of variables \a N.
1608  ///
1609  /// \param StartLoc Starting location of the clause.
1610  /// \param LParenLoc Location of '('.
1611  /// \param EndLoc Ending location of the clause.
1612  /// \param N Number of the variables in the clause.
1614  SourceLocation EndLoc, unsigned N)
1615  : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1616  LParenLoc, EndLoc, N),
1617  OMPClauseWithPostUpdate(this) {}
1618 
1619  /// Build an empty clause.
1620  ///
1621  /// \param N Number of variables.
1622  explicit OMPLastprivateClause(unsigned N)
1624  OMPC_lastprivate, SourceLocation(), SourceLocation(),
1625  SourceLocation(), N),
1626  OMPClauseWithPostUpdate(this) {}
1627 
1628  /// Get the list of helper expressions for initialization of private
1629  /// copies for lastprivate variables.
1630  MutableArrayRef<Expr *> getPrivateCopies() {
1631  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1632  }
1633  ArrayRef<const Expr *> getPrivateCopies() const {
1634  return llvm::makeArrayRef(varlist_end(), varlist_size());
1635  }
1636 
1637  /// Set list of helper expressions, required for proper codegen of the
1638  /// clause. These expressions represent private variables (for arrays, single
1639  /// array element) in the final assignment statement performed by the
1640  /// lastprivate clause.
1641  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1642 
1643  /// Get the list of helper source expressions.
1644  MutableArrayRef<Expr *> getSourceExprs() {
1645  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1646  }
1647  ArrayRef<const Expr *> getSourceExprs() const {
1648  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1649  }
1650 
1651  /// Set list of helper expressions, required for proper codegen of the
1652  /// clause. These expressions represent original variables (for arrays, single
1653  /// array element) in the final assignment statement performed by the
1654  /// lastprivate clause.
1655  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1656 
1657  /// Get the list of helper destination expressions.
1658  MutableArrayRef<Expr *> getDestinationExprs() {
1659  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1660  }
1661  ArrayRef<const Expr *> getDestinationExprs() const {
1662  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1663  }
1664 
1665  /// Set list of helper assignment expressions, required for proper
1666  /// codegen of the clause. These expressions are assignment expressions that
1667  /// assign private copy of the variable to original variable.
1668  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1669 
1670  /// Get the list of helper assignment expressions.
1671  MutableArrayRef<Expr *> getAssignmentOps() {
1672  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1673  }
1674  ArrayRef<const Expr *> getAssignmentOps() const {
1675  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1676  }
1677 
1678 public:
1679  /// Creates clause with a list of variables \a VL.
1680  ///
1681  /// \param C AST context.
1682  /// \param StartLoc Starting location of the clause.
1683  /// \param LParenLoc Location of '('.
1684  /// \param EndLoc Ending location of the clause.
1685  /// \param VL List of references to the variables.
1686  /// \param SrcExprs List of helper expressions for proper generation of
1687  /// assignment operation required for lastprivate clause. This list represents
1688  /// private variables (for arrays, single array element).
1689  /// \param DstExprs List of helper expressions for proper generation of
1690  /// assignment operation required for lastprivate clause. This list represents
1691  /// original variables (for arrays, single array element).
1692  /// \param AssignmentOps List of helper expressions that represents assignment
1693  /// operation:
1694  /// \code
1695  /// DstExprs = SrcExprs;
1696  /// \endcode
1697  /// Required for proper codegen of final assignment performed by the
1698  /// lastprivate clause.
1699  /// \param PreInit Statement that must be executed before entering the OpenMP
1700  /// region with this clause.
1701  /// \param PostUpdate Expression that must be executed after exit from the
1702  /// OpenMP region with this clause.
1703  static OMPLastprivateClause *
1704  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1705  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1706  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
1707  Stmt *PreInit, Expr *PostUpdate);
1708 
1709  /// Creates an empty clause with the place for \a N variables.
1710  ///
1711  /// \param C AST context.
1712  /// \param N The number of variables.
1713  static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1714 
1717  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
1718  using helper_expr_const_range =
1719  llvm::iterator_range<helper_expr_const_iterator>;
1720 
1721  /// Set list of helper expressions, required for generation of private
1722  /// copies of original lastprivate variables.
1723  void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1724 
1726  return helper_expr_const_range(getPrivateCopies().begin(),
1727  getPrivateCopies().end());
1728  }
1729 
1731  return helper_expr_range(getPrivateCopies().begin(),
1732  getPrivateCopies().end());
1733  }
1734 
1736  return helper_expr_const_range(getSourceExprs().begin(),
1737  getSourceExprs().end());
1738  }
1739 
1741  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1742  }
1743 
1745  return helper_expr_const_range(getDestinationExprs().begin(),
1746  getDestinationExprs().end());
1747  }
1748 
1750  return helper_expr_range(getDestinationExprs().begin(),
1751  getDestinationExprs().end());
1752  }
1753 
1755  return helper_expr_const_range(getAssignmentOps().begin(),
1756  getAssignmentOps().end());
1757  }
1758 
1760  return helper_expr_range(getAssignmentOps().begin(),
1761  getAssignmentOps().end());
1762  }
1763 
1765  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1766  reinterpret_cast<Stmt **>(varlist_end()));
1767  }
1768 
1769  static bool classof(const OMPClause *T) {
1770  return T->getClauseKind() == OMPC_lastprivate;
1771  }
1772 };
1773 
1774 /// This represents clause 'shared' in the '#pragma omp ...' directives.
1775 ///
1776 /// \code
1777 /// #pragma omp parallel shared(a,b)
1778 /// \endcode
1779 /// In this example directive '#pragma omp parallel' has clause 'shared'
1780 /// with the variables 'a' and 'b'.
1781 class OMPSharedClause final
1782  : public OMPVarListClause<OMPSharedClause>,
1783  private llvm::TrailingObjects<OMPSharedClause, Expr *> {
1784  friend OMPVarListClause;
1785  friend TrailingObjects;
1786 
1787  /// Build clause with number of variables \a N.
1788  ///
1789  /// \param StartLoc Starting location of the clause.
1790  /// \param LParenLoc Location of '('.
1791  /// \param EndLoc Ending location of the clause.
1792  /// \param N Number of the variables in the clause.
1793  OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1794  SourceLocation EndLoc, unsigned N)
1795  : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1796  EndLoc, N) {}
1797 
1798  /// Build an empty clause.
1799  ///
1800  /// \param N Number of variables.
1801  explicit OMPSharedClause(unsigned N)
1804  N) {}
1805 
1806 public:
1807  /// Creates clause with a list of variables \a VL.
1808  ///
1809  /// \param C AST context.
1810  /// \param StartLoc Starting location of the clause.
1811  /// \param LParenLoc Location of '('.
1812  /// \param EndLoc Ending location of the clause.
1813  /// \param VL List of references to the variables.
1814  static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1815  SourceLocation LParenLoc,
1816  SourceLocation EndLoc, ArrayRef<Expr *> VL);
1817 
1818  /// Creates an empty clause with \a N variables.
1819  ///
1820  /// \param C AST context.
1821  /// \param N The number of variables.
1822  static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1823 
1825  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1826  reinterpret_cast<Stmt **>(varlist_end()));
1827  }
1828 
1829  static bool classof(const OMPClause *T) {
1830  return T->getClauseKind() == OMPC_shared;
1831  }
1832 };
1833 
1834 /// This represents clause 'reduction' in the '#pragma omp ...'
1835 /// directives.
1836 ///
1837 /// \code
1838 /// #pragma omp parallel reduction(+:a,b)
1839 /// \endcode
1840 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1841 /// with operator '+' and the variables 'a' and 'b'.
1843  : public OMPVarListClause<OMPReductionClause>,
1844  public OMPClauseWithPostUpdate,
1845  private llvm::TrailingObjects<OMPReductionClause, Expr *> {
1846  friend class OMPClauseReader;
1847  friend OMPVarListClause;
1848  friend TrailingObjects;
1849 
1850  /// Location of ':'.
1852 
1853  /// Nested name specifier for C++.
1854  NestedNameSpecifierLoc QualifierLoc;
1855 
1856  /// Name of custom operator.
1857  DeclarationNameInfo NameInfo;
1858 
1859  /// Build clause with number of variables \a N.
1860  ///
1861  /// \param StartLoc Starting location of the clause.
1862  /// \param LParenLoc Location of '('.
1863  /// \param EndLoc Ending location of the clause.
1864  /// \param ColonLoc Location of ':'.
1865  /// \param N Number of the variables in the clause.
1866  /// \param QualifierLoc The nested-name qualifier with location information
1867  /// \param NameInfo The full name info for reduction identifier.
1868  OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1869  SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1870  NestedNameSpecifierLoc QualifierLoc,
1871  const DeclarationNameInfo &NameInfo)
1872  : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1873  LParenLoc, EndLoc, N),
1874  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
1875  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1876 
1877  /// Build an empty clause.
1878  ///
1879  /// \param N Number of variables.
1880  explicit OMPReductionClause(unsigned N)
1881  : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1883  N),
1884  OMPClauseWithPostUpdate(this) {}
1885 
1886  /// Sets location of ':' symbol in clause.
1887  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1888 
1889  /// Sets the name info for specified reduction identifier.
1890  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1891 
1892  /// Sets the nested name specifier.
1893  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1894 
1895  /// Set list of helper expressions, required for proper codegen of the
1896  /// clause. These expressions represent private copy of the reduction
1897  /// variable.
1899 
1900  /// Get the list of helper privates.
1902  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1903  }
1905  return llvm::makeArrayRef(varlist_end(), varlist_size());
1906  }
1907 
1908  /// Set list of helper expressions, required for proper codegen of the
1909  /// clause. These expressions represent LHS expression in the final
1910  /// reduction expression performed by the reduction clause.
1911  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1912 
1913  /// Get the list of helper LHS expressions.
1914  MutableArrayRef<Expr *> getLHSExprs() {
1915  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1916  }
1917  ArrayRef<const Expr *> getLHSExprs() const {
1918  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1919  }
1920 
1921  /// Set list of helper expressions, required for proper codegen of the
1922  /// clause. These expressions represent RHS expression in the final
1923  /// reduction expression performed by the reduction clause.
1924  /// Also, variables in these expressions are used for proper initialization of
1925  /// reduction copies.
1926  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1927 
1928  /// Get the list of helper destination expressions.
1929  MutableArrayRef<Expr *> getRHSExprs() {
1930  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1931  }
1932  ArrayRef<const Expr *> getRHSExprs() const {
1933  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1934  }
1935 
1936  /// Set list of helper reduction expressions, required for proper
1937  /// codegen of the clause. These expressions are binary expressions or
1938  /// operator/custom reduction call that calculates new value from source
1939  /// helper expressions to destination helper expressions.
1940  void setReductionOps(ArrayRef<Expr *> ReductionOps);
1941 
1942  /// Get the list of helper reduction expressions.
1943  MutableArrayRef<Expr *> getReductionOps() {
1944  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1945  }
1946  ArrayRef<const Expr *> getReductionOps() const {
1947  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1948  }
1949 
1950 public:
1951  /// Creates clause with a list of variables \a VL.
1952  ///
1953  /// \param StartLoc Starting location of the clause.
1954  /// \param LParenLoc Location of '('.
1955  /// \param ColonLoc Location of ':'.
1956  /// \param EndLoc Ending location of the clause.
1957  /// \param VL The variables in the clause.
1958  /// \param QualifierLoc The nested-name qualifier with location information
1959  /// \param NameInfo The full name info for reduction identifier.
1960  /// \param Privates List of helper expressions for proper generation of
1961  /// private copies.
1962  /// \param LHSExprs List of helper expressions for proper generation of
1963  /// assignment operation required for copyprivate clause. This list represents
1964  /// LHSs of the reduction expressions.
1965  /// \param RHSExprs List of helper expressions for proper generation of
1966  /// assignment operation required for copyprivate clause. This list represents
1967  /// RHSs of the reduction expressions.
1968  /// Also, variables in these expressions are used for proper initialization of
1969  /// reduction copies.
1970  /// \param ReductionOps List of helper expressions that represents reduction
1971  /// expressions:
1972  /// \code
1973  /// LHSExprs binop RHSExprs;
1974  /// operator binop(LHSExpr, RHSExpr);
1975  /// <CutomReduction>(LHSExpr, RHSExpr);
1976  /// \endcode
1977  /// Required for proper codegen of final reduction operation performed by the
1978  /// reduction clause.
1979  /// \param PreInit Statement that must be executed before entering the OpenMP
1980  /// region with this clause.
1981  /// \param PostUpdate Expression that must be executed after exit from the
1982  /// OpenMP region with this clause.
1983  static OMPReductionClause *
1984  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1985  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1986  NestedNameSpecifierLoc QualifierLoc,
1988  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1989  ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
1990 
1991  /// Creates an empty clause with the place for \a N variables.
1992  ///
1993  /// \param C AST context.
1994  /// \param N The number of variables.
1995  static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1996 
1997  /// Gets location of ':' symbol in clause.
1999 
2000  /// Gets the name info for specified reduction identifier.
2001  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2002 
2003  /// Gets the nested name specifier.
2004  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2005 
2008  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2009  using helper_expr_const_range =
2010  llvm::iterator_range<helper_expr_const_iterator>;
2011 
2013  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2014  }
2015 
2017  return helper_expr_range(getPrivates().begin(), getPrivates().end());
2018  }
2019 
2021  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2022  }
2023 
2025  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2026  }
2027 
2029  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2030  }
2031 
2033  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2034  }
2035 
2037  return helper_expr_const_range(getReductionOps().begin(),
2038  getReductionOps().end());
2039  }
2040 
2042  return helper_expr_range(getReductionOps().begin(),
2043  getReductionOps().end());
2044  }
2045 
2047  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2048  reinterpret_cast<Stmt **>(varlist_end()));
2049  }
2050 
2051  static bool classof(const OMPClause *T) {
2052  return T->getClauseKind() == OMPC_reduction;
2053  }
2054 };
2055 
2056 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
2057 /// directives.
2058 ///
2059 /// \code
2060 /// #pragma omp taskgroup task_reduction(+:a,b)
2061 /// \endcode
2062 /// In this example directive '#pragma omp taskgroup' has clause
2063 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
2065  : public OMPVarListClause<OMPTaskReductionClause>,
2066  public OMPClauseWithPostUpdate,
2067  private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
2068  friend class OMPClauseReader;
2069  friend OMPVarListClause;
2070  friend TrailingObjects;
2071 
2072  /// Location of ':'.
2074 
2075  /// Nested name specifier for C++.
2076  NestedNameSpecifierLoc QualifierLoc;
2077 
2078  /// Name of custom operator.
2079  DeclarationNameInfo NameInfo;
2080 
2081  /// Build clause with number of variables \a N.
2082  ///
2083  /// \param StartLoc Starting location of the clause.
2084  /// \param LParenLoc Location of '('.
2085  /// \param EndLoc Ending location of the clause.
2086  /// \param ColonLoc Location of ':'.
2087  /// \param N Number of the variables in the clause.
2088  /// \param QualifierLoc The nested-name qualifier with location information
2089  /// \param NameInfo The full name info for reduction identifier.
2091  SourceLocation ColonLoc, SourceLocation EndLoc,
2092  unsigned N, NestedNameSpecifierLoc QualifierLoc,
2093  const DeclarationNameInfo &NameInfo)
2094  : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
2095  LParenLoc, EndLoc, N),
2096  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2097  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2098 
2099  /// Build an empty clause.
2100  ///
2101  /// \param N Number of variables.
2102  explicit OMPTaskReductionClause(unsigned N)
2104  OMPC_task_reduction, SourceLocation(), SourceLocation(),
2105  SourceLocation(), N),
2106  OMPClauseWithPostUpdate(this) {}
2107 
2108  /// Sets location of ':' symbol in clause.
2109  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2110 
2111  /// Sets the name info for specified reduction identifier.
2112  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2113 
2114  /// Sets the nested name specifier.
2115  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2116 
2117  /// Set list of helper expressions, required for proper codegen of the clause.
2118  /// These expressions represent private copy of the reduction variable.
2120 
2121  /// Get the list of helper privates.
2123  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2124  }
2126  return llvm::makeArrayRef(varlist_end(), varlist_size());
2127  }
2128 
2129  /// Set list of helper expressions, required for proper codegen of the clause.
2130  /// These expressions represent LHS expression in the final reduction
2131  /// expression performed by the reduction clause.
2132  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2133 
2134  /// Get the list of helper LHS expressions.
2135  MutableArrayRef<Expr *> getLHSExprs() {
2136  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2137  }
2138  ArrayRef<const Expr *> getLHSExprs() const {
2139  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2140  }
2141 
2142  /// Set list of helper expressions, required for proper codegen of the clause.
2143  /// These expressions represent RHS expression in the final reduction
2144  /// expression performed by the reduction clause. Also, variables in these
2145  /// expressions are used for proper initialization of reduction copies.
2146  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2147 
2148  /// Get the list of helper destination expressions.
2149  MutableArrayRef<Expr *> getRHSExprs() {
2150  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2151  }
2152  ArrayRef<const Expr *> getRHSExprs() const {
2153  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2154  }
2155 
2156  /// Set list of helper reduction expressions, required for proper
2157  /// codegen of the clause. These expressions are binary expressions or
2158  /// operator/custom reduction call that calculates new value from source
2159  /// helper expressions to destination helper expressions.
2160  void setReductionOps(ArrayRef<Expr *> ReductionOps);
2161 
2162  /// Get the list of helper reduction expressions.
2163  MutableArrayRef<Expr *> getReductionOps() {
2164  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2165  }
2166  ArrayRef<const Expr *> getReductionOps() const {
2167  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2168  }
2169 
2170 public:
2171  /// Creates clause with a list of variables \a VL.
2172  ///
2173  /// \param StartLoc Starting location of the clause.
2174  /// \param LParenLoc Location of '('.
2175  /// \param ColonLoc Location of ':'.
2176  /// \param EndLoc Ending location of the clause.
2177  /// \param VL The variables in the clause.
2178  /// \param QualifierLoc The nested-name qualifier with location information
2179  /// \param NameInfo The full name info for reduction identifier.
2180  /// \param Privates List of helper expressions for proper generation of
2181  /// private copies.
2182  /// \param LHSExprs List of helper expressions for proper generation of
2183  /// assignment operation required for copyprivate clause. This list represents
2184  /// LHSs of the reduction expressions.
2185  /// \param RHSExprs List of helper expressions for proper generation of
2186  /// assignment operation required for copyprivate clause. This list represents
2187  /// RHSs of the reduction expressions.
2188  /// Also, variables in these expressions are used for proper initialization of
2189  /// reduction copies.
2190  /// \param ReductionOps List of helper expressions that represents reduction
2191  /// expressions:
2192  /// \code
2193  /// LHSExprs binop RHSExprs;
2194  /// operator binop(LHSExpr, RHSExpr);
2195  /// <CutomReduction>(LHSExpr, RHSExpr);
2196  /// \endcode
2197  /// Required for proper codegen of final reduction operation performed by the
2198  /// reduction clause.
2199  /// \param PreInit Statement that must be executed before entering the OpenMP
2200  /// region with this clause.
2201  /// \param PostUpdate Expression that must be executed after exit from the
2202  /// OpenMP region with this clause.
2203  static OMPTaskReductionClause *
2204  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2205  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2206  NestedNameSpecifierLoc QualifierLoc,
2208  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2209  ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2210 
2211  /// Creates an empty clause with the place for \a N variables.
2212  ///
2213  /// \param C AST context.
2214  /// \param N The number of variables.
2215  static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2216 
2217  /// Gets location of ':' symbol in clause.
2219 
2220  /// Gets the name info for specified reduction identifier.
2221  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2222 
2223  /// Gets the nested name specifier.
2224  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2225 
2228  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2229  using helper_expr_const_range =
2230  llvm::iterator_range<helper_expr_const_iterator>;
2231 
2233  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2234  }
2235 
2237  return helper_expr_range(getPrivates().begin(), getPrivates().end());
2238  }
2239 
2241  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2242  }
2243 
2245  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2246  }
2247 
2249  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2250  }
2251 
2253  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2254  }
2255 
2257  return helper_expr_const_range(getReductionOps().begin(),
2258  getReductionOps().end());
2259  }
2260 
2262  return helper_expr_range(getReductionOps().begin(),
2263  getReductionOps().end());
2264  }
2265 
2267  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2268  reinterpret_cast<Stmt **>(varlist_end()));
2269  }
2270 
2271  static bool classof(const OMPClause *T) {
2272  return T->getClauseKind() == OMPC_task_reduction;
2273  }
2274 };
2275 
2276 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
2277 ///
2278 /// \code
2279 /// #pragma omp task in_reduction(+:a,b)
2280 /// \endcode
2281 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
2282 /// operator '+' and the variables 'a' and 'b'.
2284  : public OMPVarListClause<OMPInReductionClause>,
2285  public OMPClauseWithPostUpdate,
2286  private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
2287  friend class OMPClauseReader;
2288  friend OMPVarListClause;
2289  friend TrailingObjects;
2290 
2291  /// Location of ':'.
2293 
2294  /// Nested name specifier for C++.
2295  NestedNameSpecifierLoc QualifierLoc;
2296 
2297  /// Name of custom operator.
2298  DeclarationNameInfo NameInfo;
2299 
2300  /// Build clause with number of variables \a N.
2301  ///
2302  /// \param StartLoc Starting location of the clause.
2303  /// \param LParenLoc Location of '('.
2304  /// \param EndLoc Ending location of the clause.
2305  /// \param ColonLoc Location of ':'.
2306  /// \param N Number of the variables in the clause.
2307  /// \param QualifierLoc The nested-name qualifier with location information
2308  /// \param NameInfo The full name info for reduction identifier.
2310  SourceLocation ColonLoc, SourceLocation EndLoc,
2311  unsigned N, NestedNameSpecifierLoc QualifierLoc,
2312  const DeclarationNameInfo &NameInfo)
2313  : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc,
2314  LParenLoc, EndLoc, N),
2315  OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2316  QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2317 
2318  /// Build an empty clause.
2319  ///
2320  /// \param N Number of variables.
2321  explicit OMPInReductionClause(unsigned N)
2323  OMPC_in_reduction, SourceLocation(), SourceLocation(),
2324  SourceLocation(), N),
2325  OMPClauseWithPostUpdate(this) {}
2326 
2327  /// Sets location of ':' symbol in clause.
2328  void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2329 
2330  /// Sets the name info for specified reduction identifier.
2331  void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2332 
2333  /// Sets the nested name specifier.
2334  void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2335 
2336  /// Set list of helper expressions, required for proper codegen of the clause.
2337  /// These expressions represent private copy of the reduction variable.
2339 
2340  /// Get the list of helper privates.
2342  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2343  }
2345  return llvm::makeArrayRef(varlist_end(), varlist_size());
2346  }
2347 
2348  /// Set list of helper expressions, required for proper codegen of the clause.
2349  /// These expressions represent LHS expression in the final reduction
2350  /// expression performed by the reduction clause.
2351  void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2352 
2353  /// Get the list of helper LHS expressions.
2354  MutableArrayRef<Expr *> getLHSExprs() {
2355  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2356  }
2357  ArrayRef<const Expr *> getLHSExprs() const {
2358  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2359  }
2360 
2361  /// Set list of helper expressions, required for proper codegen of the clause.
2362  /// These expressions represent RHS expression in the final reduction
2363  /// expression performed by the reduction clause. Also, variables in these
2364  /// expressions are used for proper initialization of reduction copies.
2365  void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2366 
2367  /// Get the list of helper destination expressions.
2368  MutableArrayRef<Expr *> getRHSExprs() {
2369  return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2370  }
2371  ArrayRef<const Expr *> getRHSExprs() const {
2372  return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2373  }
2374 
2375  /// Set list of helper reduction expressions, required for proper
2376  /// codegen of the clause. These expressions are binary expressions or
2377  /// operator/custom reduction call that calculates new value from source
2378  /// helper expressions to destination helper expressions.
2379  void setReductionOps(ArrayRef<Expr *> ReductionOps);
2380 
2381  /// Get the list of helper reduction expressions.
2382  MutableArrayRef<Expr *> getReductionOps() {
2383  return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2384  }
2385  ArrayRef<const Expr *> getReductionOps() const {
2386  return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2387  }
2388 
2389  /// Set list of helper reduction taskgroup descriptors.
2390  void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
2391 
2392  /// Get the list of helper reduction taskgroup descriptors.
2393  MutableArrayRef<Expr *> getTaskgroupDescriptors() {
2394  return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
2395  }
2396  ArrayRef<const Expr *> getTaskgroupDescriptors() const {
2397  return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
2398  }
2399 
2400 public:
2401  /// Creates clause with a list of variables \a VL.
2402  ///
2403  /// \param StartLoc Starting location of the clause.
2404  /// \param LParenLoc Location of '('.
2405  /// \param ColonLoc Location of ':'.
2406  /// \param EndLoc Ending location of the clause.
2407  /// \param VL The variables in the clause.
2408  /// \param QualifierLoc The nested-name qualifier with location information
2409  /// \param NameInfo The full name info for reduction identifier.
2410  /// \param Privates List of helper expressions for proper generation of
2411  /// private copies.
2412  /// \param LHSExprs List of helper expressions for proper generation of
2413  /// assignment operation required for copyprivate clause. This list represents
2414  /// LHSs of the reduction expressions.
2415  /// \param RHSExprs List of helper expressions for proper generation of
2416  /// assignment operation required for copyprivate clause. This list represents
2417  /// RHSs of the reduction expressions.
2418  /// Also, variables in these expressions are used for proper initialization of
2419  /// reduction copies.
2420  /// \param ReductionOps List of helper expressions that represents reduction
2421  /// expressions:
2422  /// \code
2423  /// LHSExprs binop RHSExprs;
2424  /// operator binop(LHSExpr, RHSExpr);
2425  /// <CutomReduction>(LHSExpr, RHSExpr);
2426  /// \endcode
2427  /// Required for proper codegen of final reduction operation performed by the
2428  /// reduction clause.
2429  /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
2430  /// corresponding items in parent taskgroup task_reduction clause.
2431  /// \param PreInit Statement that must be executed before entering the OpenMP
2432  /// region with this clause.
2433  /// \param PostUpdate Expression that must be executed after exit from the
2434  /// OpenMP region with this clause.
2435  static OMPInReductionClause *
2436  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2437  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2438  NestedNameSpecifierLoc QualifierLoc,
2440  ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2441  ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
2442  Stmt *PreInit, Expr *PostUpdate);
2443 
2444  /// Creates an empty clause with the place for \a N variables.
2445  ///
2446  /// \param C AST context.
2447  /// \param N The number of variables.
2448  static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2449 
2450  /// Gets location of ':' symbol in clause.
2452 
2453  /// Gets the name info for specified reduction identifier.
2454  const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2455 
2456  /// Gets the nested name specifier.
2457  NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2458 
2461  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2462  using helper_expr_const_range =
2463  llvm::iterator_range<helper_expr_const_iterator>;
2464 
2466  return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2467  }
2468 
2470  return helper_expr_range(getPrivates().begin(), getPrivates().end());
2471  }
2472 
2474  return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2475  }
2476 
2478  return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2479  }
2480 
2482  return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2483  }
2484 
2486  return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2487  }
2488 
2490  return helper_expr_const_range(getReductionOps().begin(),
2491  getReductionOps().end());
2492  }
2493 
2495  return helper_expr_range(getReductionOps().begin(),
2496  getReductionOps().end());
2497  }
2498 
2500  return helper_expr_const_range(getTaskgroupDescriptors().begin(),
2501  getTaskgroupDescriptors().end());
2502  }
2503 
2505  return helper_expr_range(getTaskgroupDescriptors().begin(),
2506  getTaskgroupDescriptors().end());
2507  }
2508 
2510  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2511  reinterpret_cast<Stmt **>(varlist_end()));
2512  }
2513 
2514  static bool classof(const OMPClause *T) {
2515  return T->getClauseKind() == OMPC_in_reduction;
2516  }
2517 };
2518 
2519 /// This represents clause 'linear' in the '#pragma omp ...'
2520 /// directives.
2521 ///
2522 /// \code
2523 /// #pragma omp simd linear(a,b : 2)
2524 /// \endcode
2525 /// In this example directive '#pragma omp simd' has clause 'linear'
2526 /// with variables 'a', 'b' and linear step '2'.
2527 class OMPLinearClause final
2528  : public OMPVarListClause<OMPLinearClause>,
2529  public OMPClauseWithPostUpdate,
2530  private llvm::TrailingObjects<OMPLinearClause, Expr *> {
2531  friend class OMPClauseReader;
2532  friend OMPVarListClause;
2533  friend TrailingObjects;
2534 
2535  /// Modifier of 'linear' clause.
2536  OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
2537 
2538  /// Location of linear modifier if any.
2540 
2541  /// Location of ':'.
2543 
2544  /// Sets the linear step for clause.
2545  void setStep(Expr *Step) { *(getFinals().end()) = Step; }
2546 
2547  /// Sets the expression to calculate linear step for clause.
2548  void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
2549 
2550  /// Build 'linear' clause with given number of variables \a NumVars.
2551  ///
2552  /// \param StartLoc Starting location of the clause.
2553  /// \param LParenLoc Location of '('.
2554  /// \param ColonLoc Location of ':'.
2555  /// \param EndLoc Ending location of the clause.
2556  /// \param NumVars Number of variables.
2557  OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2558  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2559  SourceLocation ColonLoc, SourceLocation EndLoc,
2560  unsigned NumVars)
2561  : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
2562  EndLoc, NumVars),
2563  OMPClauseWithPostUpdate(this), Modifier(Modifier),
2564  ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
2565 
2566  /// Build an empty clause.
2567  ///
2568  /// \param NumVars Number of variables.
2569  explicit OMPLinearClause(unsigned NumVars)
2572  NumVars),
2573  OMPClauseWithPostUpdate(this) {}
2574 
2575  /// Gets the list of initial values for linear variables.
2576  ///
2577  /// There are NumVars expressions with initial values allocated after the
2578  /// varlist, they are followed by NumVars update expressions (used to update
2579  /// the linear variable's value on current iteration) and they are followed by
2580  /// NumVars final expressions (used to calculate the linear variable's
2581  /// value after the loop body). After these lists, there are 2 helper
2582  /// expressions - linear step and a helper to calculate it before the
2583  /// loop body (used when the linear step is not constant):
2584  ///
2585  /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
2586  /// Finals[]; Step; CalcStep; }
2588  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2589  }
2591  return llvm::makeArrayRef(varlist_end(), varlist_size());
2592  }
2593 
2595  return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2596  }
2598  return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2599  }
2600 
2601  /// Sets the list of update expressions for linear variables.
2603  return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
2604  }
2606  return llvm::makeArrayRef(getInits().end(), varlist_size());
2607  }
2608 
2609  /// Sets the list of final update expressions for linear variables.
2611  return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
2612  }
2614  return llvm::makeArrayRef(getUpdates().end(), varlist_size());
2615  }
2616 
2617  /// Sets the list of the copies of original linear variables.
2618  /// \param PL List of expressions.
2619  void setPrivates(ArrayRef<Expr *> PL);
2620 
2621  /// Sets the list of the initial values for linear variables.
2622  /// \param IL List of expressions.
2623  void setInits(ArrayRef<Expr *> IL);
2624 
2625 public:
2626  /// Creates clause with a list of variables \a VL and a linear step
2627  /// \a Step.
2628  ///
2629  /// \param C AST Context.
2630  /// \param StartLoc Starting location of the clause.
2631  /// \param LParenLoc Location of '('.
2632  /// \param Modifier Modifier of 'linear' clause.
2633  /// \param ModifierLoc Modifier location.
2634  /// \param ColonLoc Location of ':'.
2635  /// \param EndLoc Ending location of the clause.
2636  /// \param VL List of references to the variables.
2637  /// \param PL List of private copies of original variables.
2638  /// \param IL List of initial values for the variables.
2639  /// \param Step Linear step.
2640  /// \param CalcStep Calculation of the linear step.
2641  /// \param PreInit Statement that must be executed before entering the OpenMP
2642  /// region with this clause.
2643  /// \param PostUpdate Expression that must be executed after exit from the
2644  /// OpenMP region with this clause.
2645  static OMPLinearClause *
2646  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2647  OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2648  SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2649  ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
2650  Stmt *PreInit, Expr *PostUpdate);
2651 
2652  /// Creates an empty clause with the place for \a NumVars variables.
2653  ///
2654  /// \param C AST context.
2655  /// \param NumVars Number of variables.
2656  static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2657 
2658  /// Set modifier.
2659  void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
2660 
2661  /// Return modifier.
2663 
2664  /// Set modifier location.
2665  void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
2666 
2667  /// Return modifier location.
2669 
2670  /// Sets the location of ':'.
2671  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2672 
2673  /// Returns the location of ':'.
2675 
2676  /// Returns linear step.
2677  Expr *getStep() { return *(getFinals().end()); }
2678 
2679  /// Returns linear step.
2680  const Expr *getStep() const { return *(getFinals().end()); }
2681 
2682  /// Returns expression to calculate linear step.
2683  Expr *getCalcStep() { return *(getFinals().end() + 1); }
2684 
2685  /// Returns expression to calculate linear step.
2686  const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
2687 
2688  /// Sets the list of update expressions for linear variables.
2689  /// \param UL List of expressions.
2690  void setUpdates(ArrayRef<Expr *> UL);
2691 
2692  /// Sets the list of final update expressions for linear variables.
2693  /// \param FL List of expressions.
2694  void setFinals(ArrayRef<Expr *> FL);
2695 
2698  using privates_range = llvm::iterator_range<privates_iterator>;
2699  using privates_const_range = llvm::iterator_range<privates_const_iterator>;
2700 
2702  return privates_range(getPrivates().begin(), getPrivates().end());
2703  }
2704 
2705  privates_const_range privates() const {
2706  return privates_const_range(getPrivates().begin(), getPrivates().end());
2707  }
2708 
2711  using inits_range = llvm::iterator_range<inits_iterator>;
2712  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2713 
2715  return inits_range(getInits().begin(), getInits().end());
2716  }
2717 
2718  inits_const_range inits() const {
2719  return inits_const_range(getInits().begin(), getInits().end());
2720  }
2721 
2724  using updates_range = llvm::iterator_range<updates_iterator>;
2725  using updates_const_range = llvm::iterator_range<updates_const_iterator>;
2726 
2728  return updates_range(getUpdates().begin(), getUpdates().end());
2729  }
2730 
2731  updates_const_range updates() const {
2732  return updates_const_range(getUpdates().begin(), getUpdates().end());
2733  }
2734 
2737  using finals_range = llvm::iterator_range<finals_iterator>;
2738  using finals_const_range = llvm::iterator_range<finals_const_iterator>;
2739 
2741  return finals_range(getFinals().begin(), getFinals().end());
2742  }
2743 
2744  finals_const_range finals() const {
2745  return finals_const_range(getFinals().begin(), getFinals().end());
2746  }
2747 
2749  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2750  reinterpret_cast<Stmt **>(varlist_end()));
2751  }
2752 
2753  static bool classof(const OMPClause *T) {
2754  return T->getClauseKind() == OMPC_linear;
2755  }
2756 };
2757 
2758 /// This represents clause 'aligned' in the '#pragma omp ...'
2759 /// directives.
2760 ///
2761 /// \code
2762 /// #pragma omp simd aligned(a,b : 8)
2763 /// \endcode
2764 /// In this example directive '#pragma omp simd' has clause 'aligned'
2765 /// with variables 'a', 'b' and alignment '8'.
2766 class OMPAlignedClause final
2767  : public OMPVarListClause<OMPAlignedClause>,
2768  private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
2769  friend class OMPClauseReader;
2770  friend OMPVarListClause;
2771  friend TrailingObjects;
2772 
2773  /// Location of ':'.
2774  SourceLocation ColonLoc;
2775 
2776  /// Sets the alignment for clause.
2777  void setAlignment(Expr *A) { *varlist_end() = A; }
2778 
2779  /// Build 'aligned' clause with given number of variables \a NumVars.
2780  ///
2781  /// \param StartLoc Starting location of the clause.
2782  /// \param LParenLoc Location of '('.
2783  /// \param ColonLoc Location of ':'.
2784  /// \param EndLoc Ending location of the clause.
2785  /// \param NumVars Number of variables.
2786  OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2787  SourceLocation ColonLoc, SourceLocation EndLoc,
2788  unsigned NumVars)
2789  : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
2790  EndLoc, NumVars),
2791  ColonLoc(ColonLoc) {}
2792 
2793  /// Build an empty clause.
2794  ///
2795  /// \param NumVars Number of variables.
2796  explicit OMPAlignedClause(unsigned NumVars)
2797  : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
2798  SourceLocation(), SourceLocation(),
2799  NumVars) {}
2800 
2801 public:
2802  /// Creates clause with a list of variables \a VL and alignment \a A.
2803  ///
2804  /// \param C AST Context.
2805  /// \param StartLoc Starting location of the clause.
2806  /// \param LParenLoc Location of '('.
2807  /// \param ColonLoc Location of ':'.
2808  /// \param EndLoc Ending location of the clause.
2809  /// \param VL List of references to the variables.
2810  /// \param A Alignment.
2811  static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2812  SourceLocation LParenLoc,
2813  SourceLocation ColonLoc,
2814  SourceLocation EndLoc, ArrayRef<Expr *> VL,
2815  Expr *A);
2816 
2817  /// Creates an empty clause with the place for \a NumVars variables.
2818  ///
2819  /// \param C AST context.
2820  /// \param NumVars Number of variables.
2821  static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2822 
2823  /// Sets the location of ':'.
2824  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2825 
2826  /// Returns the location of ':'.
2827  SourceLocation getColonLoc() const { return ColonLoc; }
2828 
2829  /// Returns alignment.
2830  Expr *getAlignment() { return *varlist_end(); }
2831 
2832  /// Returns alignment.
2833  const Expr *getAlignment() const { return *varlist_end(); }
2834 
2836  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2837  reinterpret_cast<Stmt **>(varlist_end()));
2838  }
2839 
2840  static bool classof(const OMPClause *T) {
2841  return T->getClauseKind() == OMPC_aligned;
2842  }
2843 };
2844 
2845 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
2846 ///
2847 /// \code
2848 /// #pragma omp parallel copyin(a,b)
2849 /// \endcode
2850 /// In this example directive '#pragma omp parallel' has clause 'copyin'
2851 /// with the variables 'a' and 'b'.
2852 class OMPCopyinClause final
2853  : public OMPVarListClause<OMPCopyinClause>,
2854  private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
2855  // Class has 3 additional tail allocated arrays:
2856  // 1. List of helper expressions for proper generation of assignment operation
2857  // required for copyin clause. This list represents sources.
2858  // 2. List of helper expressions for proper generation of assignment operation
2859  // required for copyin clause. This list represents destinations.
2860  // 3. List of helper expressions that represents assignment operation:
2861  // \code
2862  // DstExprs = SrcExprs;
2863  // \endcode
2864  // Required for proper codegen of propagation of master's thread values of
2865  // threadprivate variables to local instances of that variables in other
2866  // implicit threads.
2867 
2868  friend class OMPClauseReader;
2869  friend OMPVarListClause;
2870  friend TrailingObjects;
2871 
2872  /// Build clause with number of variables \a N.
2873  ///
2874  /// \param StartLoc Starting location of the clause.
2875  /// \param LParenLoc Location of '('.
2876  /// \param EndLoc Ending location of the clause.
2877  /// \param N Number of the variables in the clause.
2878  OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2879  SourceLocation EndLoc, unsigned N)
2880  : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
2881  EndLoc, N) {}
2882 
2883  /// Build an empty clause.
2884  ///
2885  /// \param N Number of variables.
2886  explicit OMPCopyinClause(unsigned N)
2887  : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
2888  SourceLocation(), SourceLocation(),
2889  N) {}
2890 
2891  /// Set list of helper expressions, required for proper codegen of the
2892  /// clause. These expressions represent source expression in the final
2893  /// assignment statement performed by the copyin clause.
2894  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2895 
2896  /// Get the list of helper source expressions.
2897  MutableArrayRef<Expr *> getSourceExprs() {
2898  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2899  }
2900  ArrayRef<const Expr *> getSourceExprs() const {
2901  return llvm::makeArrayRef(varlist_end(), varlist_size());
2902  }
2903 
2904  /// Set list of helper expressions, required for proper codegen of the
2905  /// clause. These expressions represent destination expression in the final
2906  /// assignment statement performed by the copyin clause.
2907  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2908 
2909  /// Get the list of helper destination expressions.
2910  MutableArrayRef<Expr *> getDestinationExprs() {
2911  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2912  }
2913  ArrayRef<const Expr *> getDestinationExprs() const {
2914  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2915  }
2916 
2917  /// Set list of helper assignment expressions, required for proper
2918  /// codegen of the clause. These expressions are assignment expressions that
2919  /// assign source helper expressions to destination helper expressions
2920  /// correspondingly.
2921  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2922 
2923  /// Get the list of helper assignment expressions.
2924  MutableArrayRef<Expr *> getAssignmentOps() {
2925  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2926  }
2927  ArrayRef<const Expr *> getAssignmentOps() const {
2928  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2929  }
2930 
2931 public:
2932  /// Creates clause with a list of variables \a VL.
2933  ///
2934  /// \param C AST context.
2935  /// \param StartLoc Starting location of the clause.
2936  /// \param LParenLoc Location of '('.
2937  /// \param EndLoc Ending location of the clause.
2938  /// \param VL List of references to the variables.
2939  /// \param SrcExprs List of helper expressions for proper generation of
2940  /// assignment operation required for copyin clause. This list represents
2941  /// sources.
2942  /// \param DstExprs List of helper expressions for proper generation of
2943  /// assignment operation required for copyin clause. This list represents
2944  /// destinations.
2945  /// \param AssignmentOps List of helper expressions that represents assignment
2946  /// operation:
2947  /// \code
2948  /// DstExprs = SrcExprs;
2949  /// \endcode
2950  /// Required for proper codegen of propagation of master's thread values of
2951  /// threadprivate variables to local instances of that variables in other
2952  /// implicit threads.
2953  static OMPCopyinClause *
2954  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2955  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2956  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2957 
2958  /// Creates an empty clause with \a N variables.
2959  ///
2960  /// \param C AST context.
2961  /// \param N The number of variables.
2962  static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
2963 
2964  using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2965  using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2966  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2967  using helper_expr_const_range =
2968  llvm::iterator_range<helper_expr_const_iterator>;
2969 
2971  return helper_expr_const_range(getSourceExprs().begin(),
2972  getSourceExprs().end());
2973  }
2974 
2976  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2977  }
2978 
2980  return helper_expr_const_range(getDestinationExprs().begin(),
2981  getDestinationExprs().end());
2982  }
2983 
2985  return helper_expr_range(getDestinationExprs().begin(),
2986  getDestinationExprs().end());
2987  }
2988 
2990  return helper_expr_const_range(getAssignmentOps().begin(),
2991  getAssignmentOps().end());
2992  }
2993 
2995  return helper_expr_range(getAssignmentOps().begin(),
2996  getAssignmentOps().end());
2997  }
2998 
3000  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3001  reinterpret_cast<Stmt **>(varlist_end()));
3002  }
3003 
3004  static bool classof(const OMPClause *T) {
3005  return T->getClauseKind() == OMPC_copyin;
3006  }
3007 };
3008 
3009 /// This represents clause 'copyprivate' in the '#pragma omp ...'
3010 /// directives.
3011 ///
3012 /// \code
3013 /// #pragma omp single copyprivate(a,b)
3014 /// \endcode
3015 /// In this example directive '#pragma omp single' has clause 'copyprivate'
3016 /// with the variables 'a' and 'b'.
3018  : public OMPVarListClause<OMPCopyprivateClause>,
3019  private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
3020  friend class OMPClauseReader;
3021  friend OMPVarListClause;
3022  friend TrailingObjects;
3023 
3024  /// Build clause with number of variables \a N.
3025  ///
3026  /// \param StartLoc Starting location of the clause.
3027  /// \param LParenLoc Location of '('.
3028  /// \param EndLoc Ending location of the clause.
3029  /// \param N Number of the variables in the clause.
3030  OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3031  SourceLocation EndLoc, unsigned N)
3032  : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
3033  LParenLoc, EndLoc, N) {}
3034 
3035  /// Build an empty clause.
3036  ///
3037  /// \param N Number of variables.
3038  explicit OMPCopyprivateClause(unsigned N)
3040  OMPC_copyprivate, SourceLocation(), SourceLocation(),
3041  SourceLocation(), N) {}
3042 
3043  /// Set list of helper expressions, required for proper codegen of the
3044  /// clause. These expressions represent source expression in the final
3045  /// assignment statement performed by the copyprivate clause.
3046  void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3047 
3048  /// Get the list of helper source expressions.
3049  MutableArrayRef<Expr *> getSourceExprs() {
3050  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3051  }
3052  ArrayRef<const Expr *> getSourceExprs() const {
3053  return llvm::makeArrayRef(varlist_end(), varlist_size());
3054  }
3055 
3056  /// Set list of helper expressions, required for proper codegen of the
3057  /// clause. These expressions represent destination expression in the final
3058  /// assignment statement performed by the copyprivate clause.
3059  void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3060 
3061  /// Get the list of helper destination expressions.
3062  MutableArrayRef<Expr *> getDestinationExprs() {
3063  return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3064  }
3065  ArrayRef<const Expr *> getDestinationExprs() const {
3066  return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3067  }
3068 
3069  /// Set list of helper assignment expressions, required for proper
3070  /// codegen of the clause. These expressions are assignment expressions that
3071  /// assign source helper expressions to destination helper expressions
3072  /// correspondingly.
3073  void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3074 
3075  /// Get the list of helper assignment expressions.
3076  MutableArrayRef<Expr *> getAssignmentOps() {
3077  return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3078  }
3079  ArrayRef<const Expr *> getAssignmentOps() const {
3080  return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3081  }
3082 
3083 public:
3084  /// Creates clause with a list of variables \a VL.
3085  ///
3086  /// \param C AST context.
3087  /// \param StartLoc Starting location of the clause.
3088  /// \param LParenLoc Location of '('.
3089  /// \param EndLoc Ending location of the clause.
3090  /// \param VL List of references to the variables.
3091  /// \param SrcExprs List of helper expressions for proper generation of
3092  /// assignment operation required for copyprivate clause. This list represents
3093  /// sources.
3094  /// \param DstExprs List of helper expressions for proper generation of
3095  /// assignment operation required for copyprivate clause. This list represents
3096  /// destinations.
3097  /// \param AssignmentOps List of helper expressions that represents assignment
3098  /// operation:
3099  /// \code
3100  /// DstExprs = SrcExprs;
3101  /// \endcode
3102  /// Required for proper codegen of final assignment performed by the
3103  /// copyprivate clause.
3104  static OMPCopyprivateClause *
3105  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3106  SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3107  ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
3108 
3109  /// Creates an empty clause with \a N variables.
3110  ///
3111  /// \param C AST context.
3112  /// \param N The number of variables.
3113  static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3114 
3115  using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3116  using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3117  using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3118  using helper_expr_const_range =
3119  llvm::iterator_range<helper_expr_const_iterator>;
3120 
3122  return helper_expr_const_range(getSourceExprs().begin(),
3123  getSourceExprs().end());
3124  }
3125 
3127  return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3128  }
3129 
3131  return helper_expr_const_range(getDestinationExprs().begin(),
3132  getDestinationExprs().end());
3133  }
3134 
3136  return helper_expr_range(getDestinationExprs().begin(),
3137  getDestinationExprs().end());
3138  }
3139 
3141  return helper_expr_const_range(getAssignmentOps().begin(),
3142  getAssignmentOps().end());
3143  }
3144 
3146  return helper_expr_range(getAssignmentOps().begin(),
3147  getAssignmentOps().end());
3148  }
3149 
3151  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3152  reinterpret_cast<Stmt **>(varlist_end()));
3153  }
3154 
3155  static bool classof(const OMPClause *T) {
3156  return T->getClauseKind() == OMPC_copyprivate;
3157  }
3158 };
3159 
3160 /// This represents implicit clause 'flush' for the '#pragma omp flush'
3161 /// directive.
3162 /// This clause does not exist by itself, it can be only as a part of 'omp
3163 /// flush' directive. This clause is introduced to keep the original structure
3164 /// of \a OMPExecutableDirective class and its derivatives and to use the
3165 /// existing infrastructure of clauses with the list of variables.
3166 ///
3167 /// \code
3168 /// #pragma omp flush(a,b)
3169 /// \endcode
3170 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
3171 /// with the variables 'a' and 'b'.
3172 class OMPFlushClause final
3173  : public OMPVarListClause<OMPFlushClause>,
3174  private llvm::TrailingObjects<OMPFlushClause, Expr *> {
3175  friend OMPVarListClause;
3176  friend TrailingObjects;
3177 
3178  /// Build clause with number of variables \a N.
3179  ///
3180  /// \param StartLoc Starting location of the clause.
3181  /// \param LParenLoc Location of '('.
3182  /// \param EndLoc Ending location of the clause.
3183  /// \param N Number of the variables in the clause.
3184  OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3185  SourceLocation EndLoc, unsigned N)
3186  : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
3187  EndLoc, N) {}
3188 
3189  /// Build an empty clause.
3190  ///
3191  /// \param N Number of variables.
3192  explicit OMPFlushClause(unsigned N)
3193  : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
3194  SourceLocation(), SourceLocation(),
3195  N) {}
3196 
3197 public:
3198  /// Creates clause with a list of variables \a VL.
3199  ///
3200  /// \param C AST context.
3201  /// \param StartLoc Starting location of the clause.
3202  /// \param LParenLoc Location of '('.
3203  /// \param EndLoc Ending location of the clause.
3204  /// \param VL List of references to the variables.
3205  static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
3206  SourceLocation LParenLoc, SourceLocation EndLoc,
3207  ArrayRef<Expr *> VL);
3208 
3209  /// Creates an empty clause with \a N variables.
3210  ///
3211  /// \param C AST context.
3212  /// \param N The number of variables.
3213  static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
3214 
3216  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3217  reinterpret_cast<Stmt **>(varlist_end()));
3218  }
3219 
3220  static bool classof(const OMPClause *T) {
3221  return T->getClauseKind() == OMPC_flush;
3222  }
3223 };
3224 
3225 /// This represents implicit clause 'depend' for the '#pragma omp task'
3226 /// directive.
3227 ///
3228 /// \code
3229 /// #pragma omp task depend(in:a,b)
3230 /// \endcode
3231 /// In this example directive '#pragma omp task' with clause 'depend' with the
3232 /// variables 'a' and 'b' with dependency 'in'.
3233 class OMPDependClause final
3234  : public OMPVarListClause<OMPDependClause>,
3235  private llvm::TrailingObjects<OMPDependClause, Expr *> {
3236  friend class OMPClauseReader;
3237  friend OMPVarListClause;
3238  friend TrailingObjects;
3239 
3240  /// Dependency type (one of in, out, inout).
3242 
3243  /// Dependency type location.
3244  SourceLocation DepLoc;
3245 
3246  /// Colon location.
3247  SourceLocation ColonLoc;
3248 
3249  /// Number of loops, associated with the depend clause.
3250  unsigned NumLoops = 0;
3251 
3252  /// Build clause with number of variables \a N.
3253  ///
3254  /// \param StartLoc Starting location of the clause.
3255  /// \param LParenLoc Location of '('.
3256  /// \param EndLoc Ending location of the clause.
3257  /// \param N Number of the variables in the clause.
3258  /// \param NumLoops Number of loops that is associated with this depend
3259  /// clause.
3260  OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3261  SourceLocation EndLoc, unsigned N, unsigned NumLoops)
3262  : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
3263  EndLoc, N), NumLoops(NumLoops) {}
3264 
3265  /// Build an empty clause.
3266  ///
3267  /// \param N Number of variables.
3268  /// \param NumLoops Number of loops that is associated with this depend
3269  /// clause.
3270  explicit OMPDependClause(unsigned N, unsigned NumLoops)
3271  : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
3272  SourceLocation(), SourceLocation(),
3273  N),
3274  NumLoops(NumLoops) {}
3275 
3276  /// Set dependency kind.
3277  void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
3278 
3279  /// Set dependency kind and its location.
3280  void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
3281 
3282  /// Set colon location.
3283  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3284 
3285 public:
3286  /// Creates clause with a list of variables \a VL.
3287  ///
3288  /// \param C AST context.
3289  /// \param StartLoc Starting location of the clause.
3290  /// \param LParenLoc Location of '('.
3291  /// \param EndLoc Ending location of the clause.
3292  /// \param DepKind Dependency type.
3293  /// \param DepLoc Location of the dependency type.
3294  /// \param ColonLoc Colon location.
3295  /// \param VL List of references to the variables.
3296  /// \param NumLoops Number of loops that is associated with this depend
3297  /// clause.
3298  static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
3299  SourceLocation LParenLoc,
3300  SourceLocation EndLoc,
3301  OpenMPDependClauseKind DepKind,
3302  SourceLocation DepLoc, SourceLocation ColonLoc,
3303  ArrayRef<Expr *> VL, unsigned NumLoops);
3304 
3305  /// Creates an empty clause with \a N variables.
3306  ///
3307  /// \param C AST context.
3308  /// \param N The number of variables.
3309  /// \param NumLoops Number of loops that is associated with this depend
3310  /// clause.
3311  static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
3312  unsigned NumLoops);
3313 
3314  /// Get dependency type.
3315  OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
3316 
3317  /// Get dependency type location.
3318  SourceLocation getDependencyLoc() const { return DepLoc; }
3319 
3320  /// Get colon location.
3321  SourceLocation getColonLoc() const { return ColonLoc; }
3322 
3323  /// Get number of loops associated with the clause.
3324  unsigned getNumLoops() const { return NumLoops; }
3325 
3326  /// Set the loop data for the depend clauses with 'sink|source' kind of
3327  /// dependency.
3328  void setLoopData(unsigned NumLoop, Expr *Cnt);
3329 
3330  /// Get the loop data.
3331  Expr *getLoopData(unsigned NumLoop);
3332  const Expr *getLoopData(unsigned NumLoop) const;
3333 
3335  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3336  reinterpret_cast<Stmt **>(varlist_end()));
3337  }
3338 
3339  static bool classof(const OMPClause *T) {
3340  return T->getClauseKind() == OMPC_depend;
3341  }
3342 };
3343 
3344 /// This represents 'device' clause in the '#pragma omp ...'
3345 /// directive.
3346 ///
3347 /// \code
3348 /// #pragma omp target device(a)
3349 /// \endcode
3350 /// In this example directive '#pragma omp target' has clause 'device'
3351 /// with single expression 'a'.
3352 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
3353  friend class OMPClauseReader;
3354 
3355  /// Location of '('.
3356  SourceLocation LParenLoc;
3357 
3358  /// Device number.
3359  Stmt *Device = nullptr;
3360 
3361  /// Set the device number.
3362  ///
3363  /// \param E Device number.
3364  void setDevice(Expr *E) { Device = E; }
3365 
3366 public:
3367  /// Build 'device' clause.
3368  ///
3369  /// \param E Expression associated with this clause.
3370  /// \param CaptureRegion Innermost OpenMP region where expressions in this
3371  /// clause must be captured.
3372  /// \param StartLoc Starting location of the clause.
3373  /// \param LParenLoc Location of '('.
3374  /// \param EndLoc Ending location of the clause.
3375  OMPDeviceClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
3376  SourceLocation StartLoc, SourceLocation LParenLoc,
3377  SourceLocation EndLoc)
3378  : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this),
3379  LParenLoc(LParenLoc), Device(E) {
3380  setPreInitStmt(HelperE, CaptureRegion);
3381  }
3382 
3383  /// Build an empty clause.
3385  : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
3386  OMPClauseWithPreInit(this) {}
3387 
3388  /// Sets the location of '('.
3389  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3390 
3391  /// Returns the location of '('.
3392  SourceLocation getLParenLoc() const { return LParenLoc; }
3393 
3394  /// Return device number.
3395  Expr *getDevice() { return cast<Expr>(Device); }
3396 
3397  /// Return device number.
3398  Expr *getDevice() const { return cast<Expr>(Device); }
3399 
3400  child_range children() { return child_range(&Device, &Device + 1); }
3401 
3402  static bool classof(const OMPClause *T) {
3403  return T->getClauseKind() == OMPC_device;
3404  }
3405 };
3406 
3407 /// This represents 'threads' clause in the '#pragma omp ...' directive.
3408 ///
3409 /// \code
3410 /// #pragma omp ordered threads
3411 /// \endcode
3412 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
3413 class OMPThreadsClause : public OMPClause {
3414 public:
3415  /// Build 'threads' clause.
3416  ///
3417  /// \param StartLoc Starting location of the clause.
3418  /// \param EndLoc Ending location of the clause.
3419  OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
3420  : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
3421 
3422  /// Build an empty clause.
3424  : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
3425 
3428  }
3429 
3430  static bool classof(const OMPClause *T) {
3431  return T->getClauseKind() == OMPC_threads;
3432  }
3433 };
3434 
3435 /// This represents 'simd' clause in the '#pragma omp ...' directive.
3436 ///
3437 /// \code
3438 /// #pragma omp ordered simd
3439 /// \endcode
3440 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
3441 class OMPSIMDClause : public OMPClause {
3442 public:
3443  /// Build 'simd' clause.
3444  ///
3445  /// \param StartLoc Starting location of the clause.
3446  /// \param EndLoc Ending location of the clause.
3447  OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
3448  : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
3449 
3450  /// Build an empty clause.
3451  OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
3452 
3455  }
3456 
3457  static bool classof(const OMPClause *T) {
3458  return T->getClauseKind() == OMPC_simd;
3459  }
3460 };
3461 
3462 /// Struct that defines common infrastructure to handle mappable
3463 /// expressions used in OpenMP clauses.
3465 public:
3466  /// Class that represents a component of a mappable expression. E.g.
3467  /// for an expression S.a, the first component is a declaration reference
3468  /// expression associated with 'S' and the second is a member expression
3469  /// associated with the field declaration 'a'. If the expression is an array
3470  /// subscript it may not have any associated declaration. In that case the
3471  /// associated declaration is set to nullptr.
3473  /// Expression associated with the component.
3474  Expr *AssociatedExpression = nullptr;
3475 
3476  /// Declaration associated with the declaration. If the component does
3477  /// not have a declaration (e.g. array subscripts or section), this is set
3478  /// to nullptr.
3479  ValueDecl *AssociatedDeclaration = nullptr;
3480 
3481  public:
3482  explicit MappableComponent() = default;
3483  explicit MappableComponent(Expr *AssociatedExpression,
3484  ValueDecl *AssociatedDeclaration)
3485  : AssociatedExpression(AssociatedExpression),
3486  AssociatedDeclaration(
3487  AssociatedDeclaration
3488  ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
3489  : nullptr) {}
3490 
3491  Expr *getAssociatedExpression() const { return AssociatedExpression; }
3492 
3493  ValueDecl *getAssociatedDeclaration() const {
3494  return AssociatedDeclaration;
3495  }
3496  };
3497 
3498  // List of components of an expression. This first one is the whole
3499  // expression and the last one is the base expression.
3500  using MappableExprComponentList = SmallVector<MappableComponent, 8>;
3501  using MappableExprComponentListRef = ArrayRef<MappableComponent>;
3502 
3503  // List of all component lists associated to the same base declaration.
3504  // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
3505  // their component list but the same base declaration 'S'.
3506  using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
3507  using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
3508 
3509 protected:
3510  // Return the total number of elements in a list of component lists.
3511  static unsigned
3512  getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
3513 
3514  // Return the total number of elements in a list of declarations. All
3515  // declarations are expected to be canonical.
3516  static unsigned
3517  getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
3518 };
3519 
3520 /// This represents clauses with a list of expressions that are mappable.
3521 /// Examples of these clauses are 'map' in
3522 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
3523 /// in '#pragma omp target update...' directives.
3524 template <class T>
3527  friend class OMPClauseReader;
3528 
3529  /// Number of unique declarations in this clause.
3530  unsigned NumUniqueDeclarations;
3531 
3532  /// Number of component lists in this clause.
3533  unsigned NumComponentLists;
3534 
3535  /// Total number of components in this clause.
3536  unsigned NumComponents;
3537 
3538 protected:
3539  /// Build a clause for \a NumUniqueDeclarations declarations, \a
3540  /// NumComponentLists total component lists, and \a NumComponents total
3541  /// components.
3542  ///
3543  /// \param K Kind of the clause.
3544  /// \param StartLoc Starting location of the clause (the clause keyword).
3545  /// \param LParenLoc Location of '('.
3546  /// \param EndLoc Ending location of the clause.
3547  /// \param NumVars Number of expressions listed in the clause.
3548  /// \param NumUniqueDeclarations Number of unique base declarations in this
3549  /// clause.
3550  /// \param NumComponentLists Number of component lists in this clause - one
3551  /// list for each expression in the clause.
3552  /// \param NumComponents Total number of expression components in the clause.
3553  OMPMappableExprListClause(OpenMPClauseKind K, SourceLocation StartLoc,
3554  SourceLocation LParenLoc, SourceLocation EndLoc,
3555  unsigned NumVars, unsigned NumUniqueDeclarations,
3556  unsigned NumComponentLists, unsigned NumComponents)
3557  : OMPVarListClause<T>(K, StartLoc, LParenLoc, EndLoc, NumVars),
3558  NumUniqueDeclarations(NumUniqueDeclarations),
3559  NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
3560 
3561  /// Get the unique declarations that are in the trailing objects of the
3562  /// class.
3563  MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
3564  return MutableArrayRef<ValueDecl *>(
3565  static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
3566  NumUniqueDeclarations);
3567  }
3568 
3569  /// Get the unique declarations that are in the trailing objects of the
3570  /// class.
3571  ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
3572  return ArrayRef<ValueDecl *>(
3573  static_cast<const T *>(this)
3574  ->template getTrailingObjects<ValueDecl *>(),
3575  NumUniqueDeclarations);
3576  }
3577 
3578  /// Set the unique declarations that are in the trailing objects of the
3579  /// class.
3580  void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
3581  assert(UDs.size() == NumUniqueDeclarations &&
3582  "Unexpected amount of unique declarations.");
3583  std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
3584  }
3585 
3586  /// Get the number of lists per declaration that are in the trailing
3587  /// objects of the class.
3588  MutableArrayRef<unsigned> getDeclNumListsRef() {
3589  return MutableArrayRef<unsigned>(
3590  static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
3591  NumUniqueDeclarations);
3592  }
3593 
3594  /// Get the number of lists per declaration that are in the trailing
3595  /// objects of the class.
3596  ArrayRef<unsigned> getDeclNumListsRef() const {
3597  return ArrayRef<unsigned>(
3598  static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
3599  NumUniqueDeclarations);
3600  }
3601 
3602  /// Set the number of lists per declaration that are in the trailing
3603  /// objects of the class.
3604  void setDeclNumLists(ArrayRef<unsigned> DNLs) {
3605  assert(DNLs.size() == NumUniqueDeclarations &&
3606  "Unexpected amount of list numbers.");
3607  std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
3608  }
3609 
3610  /// Get the cumulative component lists sizes that are in the trailing
3611  /// objects of the class. They are appended after the number of lists.
3612  MutableArrayRef<unsigned> getComponentListSizesRef() {
3613  return MutableArrayRef<unsigned>(
3614  static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
3615  NumUniqueDeclarations,
3616  NumComponentLists);
3617  }
3618 
3619  /// Get the cumulative component lists sizes that are in the trailing
3620  /// objects of the class. They are appended after the number of lists.
3621  ArrayRef<unsigned> getComponentListSizesRef() const {
3622  return ArrayRef<unsigned>(
3623  static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
3624  NumUniqueDeclarations,
3625  NumComponentLists);
3626  }
3627 
3628  /// Set the cumulative component lists sizes that are in the trailing
3629  /// objects of the class.
3630  void setComponentListSizes(ArrayRef<unsigned> CLSs) {
3631  assert(CLSs.size() == NumComponentLists &&
3632  "Unexpected amount of component lists.");
3633  std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
3634  }
3635 
3636  /// Get the components that are in the trailing objects of the class.
3637  MutableArrayRef<MappableComponent> getComponentsRef() {
3638  return MutableArrayRef<MappableComponent>(
3639  static_cast<T *>(this)
3640  ->template getTrailingObjects<MappableComponent>(),
3641  NumComponents);
3642  }
3643 
3644  /// Get the components that are in the trailing objects of the class.
3645  ArrayRef<MappableComponent> getComponentsRef() const {
3646  return ArrayRef<MappableComponent>(
3647  static_cast<const T *>(this)
3648  ->template getTrailingObjects<MappableComponent>(),
3649  NumComponents);
3650  }
3651 
3652  /// Set the components that are in the trailing objects of the class.
3653  /// This requires the list sizes so that it can also fill the original
3654  /// expressions, which are the first component of each list.
3655  void setComponents(ArrayRef<MappableComponent> Components,
3656  ArrayRef<unsigned> CLSs) {
3657  assert(Components.size() == NumComponents &&
3658  "Unexpected amount of component lists.");
3659  assert(CLSs.size() == NumComponentLists &&
3660  "Unexpected amount of list sizes.");
3661  std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
3662  }
3663 
3664  /// Fill the clause information from the list of declarations and
3665  /// associated component lists.
3666  void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
3667  MappableExprComponentListsRef ComponentLists) {
3668  // Perform some checks to make sure the data sizes are consistent with the
3669  // information available when the clause was created.
3670  assert(getUniqueDeclarationsTotalNumber(Declarations) ==
3671  NumUniqueDeclarations &&
3672  "Unexpected number of mappable expression info entries!");
3673  assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
3674  "Unexpected total number of components!");
3675  assert(Declarations.size() == ComponentLists.size() &&
3676  "Declaration and component lists size is not consistent!");
3677  assert(Declarations.size() == NumComponentLists &&
3678  "Unexpected declaration and component lists size!");
3679 
3680  // Organize the components by declaration and retrieve the original
3681  // expression. Original expressions are always the first component of the
3682  // mappable component list.
3683  llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
3684  ComponentListMap;
3685  {
3686  auto CI = ComponentLists.begin();
3687  for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
3688  ++DI, ++CI) {
3689  assert(!CI->empty() && "Invalid component list!");
3690  ComponentListMap[*DI].push_back(*CI);
3691  }
3692  }
3693 
3694  // Iterators of the target storage.
3695  auto UniqueDeclarations = getUniqueDeclsRef();
3696  auto UDI = UniqueDeclarations.begin();
3697 
3698  auto DeclNumLists = getDeclNumListsRef();
3699  auto DNLI = DeclNumLists.begin();
3700 
3701  auto ComponentListSizes = getComponentListSizesRef();
3702  auto CLSI = ComponentListSizes.begin();
3703 
3704  auto Components = getComponentsRef();
3705  auto CI = Components.begin();
3706 
3707  // Variable to compute the accumulation of the number of components.
3708  unsigned PrevSize = 0u;
3709 
3710  // Scan all the declarations and associated component lists.
3711  for (auto &M : ComponentListMap) {
3712  // The declaration.
3713  auto *D = M.first;
3714  // The component lists.
3715  auto CL = M.second;
3716 
3717  // Initialize the entry.
3718  *UDI = D;
3719  ++UDI;
3720 
3721  *DNLI = CL.size();
3722  ++DNLI;
3723 
3724  // Obtain the cumulative sizes and concatenate all the components in the
3725  // reserved storage.
3726  for (auto C : CL) {
3727  // Accumulate with the previous size.
3728  PrevSize += C.size();
3729 
3730  // Save the size.
3731  *CLSI = PrevSize;
3732  ++CLSI;
3733 
3734  // Append components after the current components iterator.
3735  CI = std::copy(C.begin(), C.end(), CI);
3736  }
3737  }
3738  }
3739 
3740 public:
3741  /// Return the number of unique base declarations in this clause.
3742  unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
3743 
3744  /// Return the number of lists derived from the clause expressions.
3745  unsigned getTotalComponentListNum() const { return NumComponentLists; }
3746 
3747  /// Return the total number of components in all lists derived from the
3748  /// clause.
3749  unsigned getTotalComponentsNum() const { return NumComponents; }
3750 
3751  /// Iterator that browse the components by lists. It also allows
3752  /// browsing components of a single declaration.
3754  : public llvm::iterator_adaptor_base<
3755  const_component_lists_iterator,
3756  MappableExprComponentListRef::const_iterator,
3757  std::forward_iterator_tag, MappableComponent, ptrdiff_t,
3758  MappableComponent, MappableComponent> {
3759  // The declaration the iterator currently refers to.
3760  ArrayRef<ValueDecl *>::iterator DeclCur;
3761 
3762  // The list number associated with the current declaration.
3763  ArrayRef<unsigned>::iterator NumListsCur;
3764 
3765  // Remaining lists for the current declaration.
3766  unsigned RemainingLists = 0;
3767 
3768  // The cumulative size of the previous list, or zero if there is no previous
3769  // list.
3770  unsigned PrevListSize = 0;
3771 
3772  // The cumulative sizes of the current list - it will delimit the remaining
3773  // range of interest.
3774  ArrayRef<unsigned>::const_iterator ListSizeCur;
3775  ArrayRef<unsigned>::const_iterator ListSizeEnd;
3776 
3777  // Iterator to the end of the components storage.
3778  MappableExprComponentListRef::const_iterator End;
3779 
3780  public:
3781  /// Construct an iterator that scans all lists.
3783  ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
3784  ArrayRef<unsigned> CumulativeListSizes,
3785  MappableExprComponentListRef Components)
3786  : const_component_lists_iterator::iterator_adaptor_base(
3787  Components.begin()),
3788  DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
3789  ListSizeCur(CumulativeListSizes.begin()),
3790  ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
3791  assert(UniqueDecls.size() == DeclsListNum.size() &&
3792  "Inconsistent number of declarations and list sizes!");
3793  if (!DeclsListNum.empty())
3794  RemainingLists = *NumListsCur;
3795  }
3796 
3797  /// Construct an iterator that scan lists for a given declaration \a
3798  /// Declaration.
3800  const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
3801  ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
3802  MappableExprComponentListRef Components)
3803  : const_component_lists_iterator(UniqueDecls, DeclsListNum,
3804  CumulativeListSizes, Components) {
3805  // Look for the desired declaration. While we are looking for it, we
3806  // update the state so that we know the component where a given list
3807  // starts.
3808  for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
3809  if (*DeclCur == Declaration)
3810  break;
3811 
3812  assert(*NumListsCur > 0 && "No lists associated with declaration??");
3813 
3814  // Skip the lists associated with the current declaration, but save the
3815  // last list size that was skipped.
3816  std::advance(ListSizeCur, *NumListsCur - 1);
3817  PrevListSize = *ListSizeCur;
3818  ++ListSizeCur;
3819  }
3820 
3821  // If we didn't find any declaration, advance the iterator to after the
3822  // last component and set remaining lists to zero.
3823  if (ListSizeCur == CumulativeListSizes.end()) {
3824  this->I = End;
3825  RemainingLists = 0u;
3826  return;
3827  }
3828 
3829  // Set the remaining lists with the total number of lists of the current
3830  // declaration.
3831  RemainingLists = *NumListsCur;
3832 
3833  // Adjust the list size end iterator to the end of the relevant range.
3834  ListSizeEnd = ListSizeCur;
3835  std::advance(ListSizeEnd, RemainingLists);
3836 
3837  // Given that the list sizes are cumulative, the index of the component
3838  // that start the list is the size of the previous list.
3839  std::advance(this->I, PrevListSize);
3840  }
3841 
3842  // Return the array with the current list. The sizes are cumulative, so the
3843  // array size is the difference between the current size and previous one.
3844  std::pair<const ValueDecl *, MappableExprComponentListRef>
3845  operator*() const {
3846  assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
3847  return std::make_pair(
3848  *DeclCur,
3849  MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize));
3850  }
3851  std::pair<const ValueDecl *, MappableExprComponentListRef>
3852  operator->() const {
3853  return **this;
3854  }
3855 
3856  // Skip the components of the current list.
3858  assert(ListSizeCur != ListSizeEnd && RemainingLists &&
3859  "Invalid iterator!");
3860 
3861  // If we don't have more lists just skip all the components. Otherwise,
3862  // advance the iterator by the number of components in the current list.
3863  if (std::next(ListSizeCur) == ListSizeEnd) {
3864  this->I = End;
3865  RemainingLists = 0;
3866  } else {
3867  std::advance(this->I, *ListSizeCur - PrevListSize);
3868  PrevListSize = *ListSizeCur;
3869 
3870  // We are done with a declaration, move to the next one.
3871  if (!(--RemainingLists)) {
3872  ++DeclCur;
3873  ++NumListsCur;
3874  RemainingLists = *NumListsCur;
3875  assert(RemainingLists && "No lists in the following declaration??");
3876  }
3877  }
3878 
3879  ++ListSizeCur;
3880  return *this;
3881  }
3882  };
3883 
3885  llvm::iterator_range<const_component_lists_iterator>;
3886 
3887  /// Iterators for all component lists.
3888  const_component_lists_iterator component_lists_begin() const {
3889  return const_component_lists_iterator(
3890  getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
3891  getComponentsRef());
3892  }
3893  const_component_lists_iterator component_lists_end() const {
3894  return const_component_lists_iterator(
3895  ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
3896  MappableExprComponentListRef(getComponentsRef().end(),
3897  getComponentsRef().end()));
3898  }
3900  return {component_lists_begin(), component_lists_end()};
3901  }
3902 
3903  /// Iterators for component lists associated with the provided
3904  /// declaration.
3905  const_component_lists_iterator
3906  decl_component_lists_begin(const ValueDecl *VD) const {
3907  return const_component_lists_iterator(
3908  VD, getUniqueDeclsRef(), getDeclNumListsRef(),
3909  getComponentListSizesRef(), getComponentsRef());
3910  }
3911  const_component_lists_iterator decl_component_lists_end() const {
3912  return component_lists_end();
3913  }
3915  return {decl_component_lists_begin(VD), decl_component_lists_end()};
3916  }
3917 
3918  /// Iterators to access all the declarations, number of lists, list sizes, and
3919  /// components.
3920  using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
3921  using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
3922 
3924  auto A = getUniqueDeclsRef();
3925  return const_all_decls_range(A.begin(), A.end());
3926  }
3927 
3928  using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
3930  llvm::iterator_range<const_all_num_lists_iterator>;
3931 
3933  auto A = getDeclNumListsRef();
3934  return const_all_num_lists_range(A.begin(), A.end());
3935  }
3936 
3937  using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
3939  llvm::iterator_range<const_all_lists_sizes_iterator>;
3940 
3942  auto A = getComponentListSizesRef();
3943  return const_all_lists_sizes_range(A.begin(), A.end());
3944  }
3945 
3946  using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
3948  llvm::iterator_range<const_all_components_iterator>;
3949 
3951  auto A = getComponentsRef();
3952  return const_all_components_range(A.begin(), A.end());
3953  }
3954 };
3955 
3956 /// This represents clause 'map' in the '#pragma omp ...'
3957 /// directives.
3958 ///
3959 /// \code
3960 /// #pragma omp target map(a,b)
3961 /// \endcode
3962 /// In this example directive '#pragma omp target' has clause 'map'
3963 /// with the variables 'a' and 'b'.
3964 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
3965  private llvm::TrailingObjects<
3966  OMPMapClause, Expr *, ValueDecl *, unsigned,
3967  OMPClauseMappableExprCommon::MappableComponent> {
3968  friend class OMPClauseReader;
3970  friend OMPVarListClause;
3971  friend TrailingObjects;
3972 
3973  /// Define the sizes of each trailing object array except the last one. This
3974  /// is required for TrailingObjects to work properly.
3975  size_t numTrailingObjects(OverloadToken<Expr *>) const {
3976  return varlist_size();
3977  }
3978  size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
3979  return getUniqueDeclarationsNum();
3980  }
3981  size_t numTrailingObjects(OverloadToken<unsigned>) const {
3982  return getUniqueDeclarationsNum() + getTotalComponentListNum();
3983  }
3984 
3985  /// Map type modifier for the 'map' clause.
3986  OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown;
3987 
3988  /// Map type for the 'map' clause.
3990 
3991  /// Is this an implicit map type or not.
3992  bool MapTypeIsImplicit = false;
3993 
3994  /// Location of the map type.
3995  SourceLocation MapLoc;
3996 
3997  /// Colon location.
3998  SourceLocation ColonLoc;
3999 
4000  /// Build a clause for \a NumVars listed expressions, \a
4001  /// NumUniqueDeclarations declarations, \a NumComponentLists total component
4002  /// lists, and \a NumComponents total expression components.
4003  ///
4004  /// \param MapTypeModifier Map type modifier.
4005  /// \param MapType Map type.
4006  /// \param MapTypeIsImplicit Map type is inferred implicitly.
4007  /// \param MapLoc Location of the map type.
4008  /// \param StartLoc Starting location of the clause.
4009  /// \param EndLoc Ending location of the clause.
4010  /// \param NumVars Number of expressions listed in this clause.
4011  /// \param NumUniqueDeclarations Number of unique base declarations in this
4012  /// clause.
4013  /// \param NumComponentLists Number of component lists in this clause.
4014  /// \param NumComponents Total number of expression components in the clause.
4015  explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier,
4016  OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
4017  SourceLocation MapLoc, SourceLocation StartLoc,
4018  SourceLocation LParenLoc, SourceLocation EndLoc,
4019  unsigned NumVars, unsigned NumUniqueDeclarations,
4020  unsigned NumComponentLists, unsigned NumComponents)
4021  : OMPMappableExprListClause(OMPC_map, StartLoc, LParenLoc, EndLoc,
4022  NumVars, NumUniqueDeclarations,
4023  NumComponentLists, NumComponents),
4024  MapTypeModifier(MapTypeModifier), MapType(MapType),
4025  MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {}
4026 
4027  /// Build an empty clause.
4028  ///
4029  /// \param NumVars Number of expressions listed in this clause.
4030  /// \param NumUniqueDeclarations Number of unique base declarations in this
4031  /// clause.
4032  /// \param NumComponentLists Number of component lists in this clause.
4033  /// \param NumComponents Total number of expression components in the clause.
4034  explicit OMPMapClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4035  unsigned NumComponentLists, unsigned NumComponents)
4037  OMPC_map, SourceLocation(), SourceLocation(), SourceLocation(),
4038  NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4039 
4040  /// Set type modifier for the clause.
4041  ///
4042  /// \param T Type Modifier for the clause.
4043  void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; }
4044 
4045  /// Set type for the clause.
4046  ///
4047  /// \param T Type for the clause.
4048  void setMapType(OpenMPMapClauseKind T) { MapType = T; }
4049 
4050  /// Set type location.
4051  ///
4052  /// \param TLoc Type location.
4053  void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
4054 
4055  /// Set colon location.
4056  void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4057 
4058 public:
4059  /// Creates clause with a list of variables \a VL.
4060  ///
4061  /// \param C AST context.
4062  /// \param StartLoc Starting location of the clause.
4063  /// \param EndLoc Ending location of the clause.
4064  /// \param Vars The original expression used in the clause.
4065  /// \param Declarations Declarations used in the clause.
4066  /// \param ComponentLists Component lists used in the clause.
4067  /// \param TypeModifier Map type modifier.
4068  /// \param Type Map type.
4069  /// \param TypeIsImplicit Map type is inferred implicitly.
4070  /// \param TypeLoc Location of the map type.
4071  static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc,
4072  SourceLocation LParenLoc, SourceLocation EndLoc,
4073  ArrayRef<Expr *> Vars,
4074  ArrayRef<ValueDecl *> Declarations,
4075  MappableExprComponentListsRef ComponentLists,
4076  OpenMPMapClauseKind TypeModifier,
4077  OpenMPMapClauseKind Type, bool TypeIsImplicit,
4078  SourceLocation TypeLoc);
4079 
4080  /// Creates an empty clause with the place for \a NumVars original
4081  /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
4082  /// lists, and \a NumComponents expression components.
4083  ///
4084  /// \param C AST context.
4085  /// \param NumVars Number of expressions listed in the clause.
4086  /// \param NumUniqueDeclarations Number of unique base declarations in this
4087  /// clause.
4088  /// \param NumComponentLists Number of unique base declarations in this
4089  /// clause.
4090  /// \param NumComponents Total number of expression components in the clause.
4091  static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4092  unsigned NumUniqueDeclarations,
4093  unsigned NumComponentLists,
4094  unsigned NumComponents);
4095 
4096  /// Fetches mapping kind for the clause.
4097  OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
4098 
4099  /// Is this an implicit map type?
4100  /// We have to capture 'IsMapTypeImplicit' from the parser for more
4101  /// informative error messages. It helps distinguish map(r) from
4102  /// map(tofrom: r), which is important to print more helpful error
4103  /// messages for some target directives.
4104  bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
4105 
4106  /// Fetches the map type modifier for the clause.
4107  OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY {
4108  return MapTypeModifier;
4109  }
4110 
4111  /// Fetches location of clause mapping kind.
4112  SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
4113 
4114  /// Get colon location.
4115  SourceLocation getColonLoc() const { return ColonLoc; }
4116 
4118  return child_range(
4119  reinterpret_cast<Stmt **>(varlist_begin()),
4120  reinterpret_cast<Stmt **>(varlist_end()));
4121  }
4122 
4123  static bool classof(const OMPClause *T) {
4124  return T->getClauseKind() == OMPC_map;
4125  }
4126 };
4127 
4128 /// This represents 'num_teams' clause in the '#pragma omp ...'
4129 /// directive.
4130 ///
4131 /// \code
4132 /// #pragma omp teams num_teams(n)
4133 /// \endcode
4134 /// In this example directive '#pragma omp teams' has clause 'num_teams'
4135 /// with single expression 'n'.
4136 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
4137  friend class OMPClauseReader;
4138 
4139  /// Location of '('.
4140  SourceLocation LParenLoc;
4141 
4142  /// NumTeams number.
4143  Stmt *NumTeams = nullptr;
4144 
4145  /// Set the NumTeams number.
4146  ///
4147  /// \param E NumTeams number.
4148  void setNumTeams(Expr *E) { NumTeams = E; }
4149 
4150 public:
4151  /// Build 'num_teams' clause.
4152  ///
4153  /// \param E Expression associated with this clause.
4154  /// \param HelperE Helper Expression associated with this clause.
4155  /// \param CaptureRegion Innermost OpenMP region where expressions in this
4156  /// clause must be captured.
4157  /// \param StartLoc Starting location of the clause.
4158  /// \param LParenLoc Location of '('.
4159  /// \param EndLoc Ending location of the clause.
4160  OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
4161  SourceLocation StartLoc, SourceLocation LParenLoc,
4162  SourceLocation EndLoc)
4163  : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this),
4164  LParenLoc(LParenLoc), NumTeams(E) {
4165  setPreInitStmt(HelperE, CaptureRegion);
4166  }
4167 
4168  /// Build an empty clause.
4170  : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
4171  OMPClauseWithPreInit(this) {}
4172 
4173  /// Sets the location of '('.
4174  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4175 
4176  /// Returns the location of '('.
4177  SourceLocation getLParenLoc() const { return LParenLoc; }
4178 
4179  /// Return NumTeams number.
4180  Expr *getNumTeams() { return cast<Expr>(NumTeams); }
4181 
4182  /// Return NumTeams number.
4183  Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
4184 
4185  child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
4186 
4187  static bool classof(const OMPClause *T) {
4188  return T->getClauseKind() == OMPC_num_teams;
4189  }
4190 };
4191 
4192 /// This represents 'thread_limit' clause in the '#pragma omp ...'
4193 /// directive.
4194 ///
4195 /// \code
4196 /// #pragma omp teams thread_limit(n)
4197 /// \endcode
4198 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
4199 /// with single expression 'n'.
4200 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
4201  friend class OMPClauseReader;
4202 
4203  /// Location of '('.
4204  SourceLocation LParenLoc;
4205 
4206  /// ThreadLimit number.
4207  Stmt *ThreadLimit = nullptr;
4208 
4209  /// Set the ThreadLimit number.
4210  ///
4211  /// \param E ThreadLimit number.
4212  void setThreadLimit(Expr *E) { ThreadLimit = E; }
4213 
4214 public:
4215  /// Build 'thread_limit' clause.
4216  ///
4217  /// \param E Expression associated with this clause.
4218  /// \param HelperE Helper Expression associated with this clause.
4219  /// \param CaptureRegion Innermost OpenMP region where expressions in this
4220  /// clause must be captured.
4221  /// \param StartLoc Starting location of the clause.
4222  /// \param LParenLoc Location of '('.
4223  /// \param EndLoc Ending location of the clause.
4224  OMPThreadLimitClause(Expr *E, Stmt *HelperE,
4225  OpenMPDirectiveKind CaptureRegion,
4226  SourceLocation StartLoc, SourceLocation LParenLoc,
4227  SourceLocation EndLoc)
4228  : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
4229  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
4230  setPreInitStmt(HelperE, CaptureRegion);
4231  }
4232 
4233  /// Build an empty clause.
4235  : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
4236  OMPClauseWithPreInit(this) {}
4237 
4238  /// Sets the location of '('.
4239  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4240 
4241  /// Returns the location of '('.
4242  SourceLocation getLParenLoc() const { return LParenLoc; }
4243 
4244  /// Return ThreadLimit number.
4245  Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
4246 
4247  /// Return ThreadLimit number.
4248  Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
4249 
4250  child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
4251 
4252  static bool classof(const OMPClause *T) {
4253  return T->getClauseKind() == OMPC_thread_limit;
4254  }
4255 };
4256 
4257 /// This represents 'priority' clause in the '#pragma omp ...'
4258 /// directive.
4259 ///
4260 /// \code
4261 /// #pragma omp task priority(n)
4262 /// \endcode
4263 /// In this example directive '#pragma omp teams' has clause 'priority' with
4264 /// single expression 'n'.
4266  friend class OMPClauseReader;
4267 
4268  /// Location of '('.
4269  SourceLocation LParenLoc;
4270 
4271  /// Priority number.
4272  Stmt *Priority = nullptr;
4273 
4274  /// Set the Priority number.
4275  ///
4276  /// \param E Priority number.
4277  void setPriority(Expr *E) { Priority = E; }
4278 
4279 public:
4280  /// Build 'priority' clause.
4281  ///
4282  /// \param E Expression associated with this clause.
4283  /// \param StartLoc Starting location of the clause.
4284  /// \param LParenLoc Location of '('.
4285  /// \param EndLoc Ending location of the clause.
4286  OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
4287  SourceLocation EndLoc)
4288  : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
4289  Priority(E) {}
4290 
4291  /// Build an empty clause.
4293  : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()) {}
4294 
4295  /// Sets the location of '('.
4296  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4297 
4298  /// Returns the location of '('.
4299  SourceLocation getLParenLoc() const { return LParenLoc; }
4300 
4301  /// Return Priority number.
4302  Expr *getPriority() { return cast<Expr>(Priority); }
4303 
4304  /// Return Priority number.
4305  Expr *getPriority() const { return cast<Expr>(Priority); }
4306 
4307  child_range children() { return child_range(&Priority, &Priority + 1); }
4308 
4309  static bool classof(const OMPClause *T) {
4310  return T->getClauseKind() == OMPC_priority;
4311  }
4312 };
4313 
4314 /// This represents 'grainsize' clause in the '#pragma omp ...'
4315 /// directive.
4316 ///
4317 /// \code
4318 /// #pragma omp taskloop grainsize(4)
4319 /// \endcode
4320 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
4321 /// with single expression '4'.
4323  friend class OMPClauseReader;
4324 
4325  /// Location of '('.
4326  SourceLocation LParenLoc;
4327 
4328  /// Safe iteration space distance.
4329  Stmt *Grainsize = nullptr;
4330 
4331  /// Set safelen.
4332  void setGrainsize(Expr *Size) { Grainsize = Size; }
4333 
4334 public:
4335  /// Build 'grainsize' clause.
4336  ///
4337  /// \param Size Expression associated with this clause.
4338  /// \param StartLoc Starting location of the clause.
4339  /// \param EndLoc Ending location of the clause.
4340  OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
4341  SourceLocation LParenLoc, SourceLocation EndLoc)
4342  : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
4343  Grainsize(Size) {}
4344 
4345  /// Build an empty clause.
4347  : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()) {}
4348 
4349  /// Sets the location of '('.
4350  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4351 
4352  /// Returns the location of '('.
4353  SourceLocation getLParenLoc() const { return LParenLoc; }
4354 
4355  /// Return safe iteration space distance.
4356  Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
4357 
4358  child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
4359 
4360  static bool classof(const OMPClause *T) {
4361  return T->getClauseKind() == OMPC_grainsize;
4362  }
4363 };
4364 
4365 /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
4366 ///
4367 /// \code
4368 /// #pragma omp taskloop nogroup
4369 /// \endcode
4370 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
4371 class OMPNogroupClause : public OMPClause {
4372 public:
4373  /// Build 'nogroup' clause.
4374  ///
4375  /// \param StartLoc Starting location of the clause.
4376  /// \param EndLoc Ending location of the clause.
4377  OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
4378  : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
4379 
4380  /// Build an empty clause.
4382  : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
4383 
4386  }
4387 
4388  static bool classof(const OMPClause *T) {
4389  return T->getClauseKind() == OMPC_nogroup;
4390  }
4391 };
4392 
4393 /// This represents 'num_tasks' clause in the '#pragma omp ...'
4394 /// directive.
4395 ///
4396 /// \code
4397 /// #pragma omp taskloop num_tasks(4)
4398 /// \endcode
4399 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
4400 /// with single expression '4'.
4402  friend class OMPClauseReader;
4403 
4404  /// Location of '('.
4405  SourceLocation LParenLoc;
4406 
4407  /// Safe iteration space distance.
4408  Stmt *NumTasks = nullptr;
4409 
4410  /// Set safelen.
4411  void setNumTasks(Expr *Size) { NumTasks = Size; }
4412 
4413 public:
4414  /// Build 'num_tasks' 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  OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
4420  SourceLocation LParenLoc, SourceLocation EndLoc)
4421  : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
4422  NumTasks(Size) {}
4423 
4424  /// Build an empty clause.
4426  : OMPClause(OMPC_num_tasks, 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 *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
4436 
4437  child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
4438 
4439  static bool classof(const OMPClause *T) {
4440  return T->getClauseKind() == OMPC_num_tasks;
4441  }
4442 };
4443 
4444 /// This represents 'hint' clause in the '#pragma omp ...' directive.
4445 ///
4446 /// \code
4447 /// #pragma omp critical (name) hint(6)
4448 /// \endcode
4449 /// In this example directive '#pragma omp critical' has name 'name' and clause
4450 /// 'hint' with argument '6'.
4451 class OMPHintClause : public OMPClause {
4452  friend class OMPClauseReader;
4453 
4454  /// Location of '('.
4455  SourceLocation LParenLoc;
4456 
4457  /// Hint expression of the 'hint' clause.
4458  Stmt *Hint = nullptr;
4459 
4460  /// Set hint expression.
4461  void setHint(Expr *H) { Hint = H; }
4462 
4463 public:
4464  /// Build 'hint' clause with expression \a Hint.
4465  ///
4466  /// \param Hint Hint expression.
4467  /// \param StartLoc Starting location of the clause.
4468  /// \param LParenLoc Location of '('.
4469  /// \param EndLoc Ending location of the clause.
4470  OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
4471  SourceLocation EndLoc)
4472  : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
4473  Hint(Hint) {}
4474 
4475  /// Build an empty clause.
4476  OMPHintClause() : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()) {}
4477 
4478  /// Sets the location of '('.
4479  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4480 
4481  /// Returns the location of '('.
4482  SourceLocation getLParenLoc() const { return LParenLoc; }
4483 
4484  /// Returns number of threads.
4485  Expr *getHint() const { return cast_or_null<Expr>(Hint); }
4486 
4487  child_range children() { return child_range(&Hint, &Hint + 1); }
4488 
4489  static bool classof(const OMPClause *T) {
4490  return T->getClauseKind() == OMPC_hint;
4491  }
4492 };
4493 
4494 /// This represents 'dist_schedule' clause in the '#pragma omp ...'
4495 /// directive.
4496 ///
4497 /// \code
4498 /// #pragma omp distribute dist_schedule(static, 3)
4499 /// \endcode
4500 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
4501 /// clause with arguments 'static' and '3'.
4502 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
4503  friend class OMPClauseReader;
4504 
4505  /// Location of '('.
4506  SourceLocation LParenLoc;
4507 
4508  /// A kind of the 'schedule' clause.
4510 
4511  /// Start location of the schedule kind in source code.
4512  SourceLocation KindLoc;
4513 
4514  /// Location of ',' (if any).
4515  SourceLocation CommaLoc;
4516 
4517  /// Chunk size.
4518  Expr *ChunkSize = nullptr;
4519 
4520  /// Set schedule kind.
4521  ///
4522  /// \param K Schedule kind.
4523  void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
4524 
4525  /// Sets the location of '('.
4526  ///
4527  /// \param Loc Location of '('.
4528  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4529 
4530  /// Set schedule kind start location.
4531  ///
4532  /// \param KLoc Schedule kind location.
4533  void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
4534 
4535  /// Set location of ','.
4536  ///
4537  /// \param Loc Location of ','.
4538  void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
4539 
4540  /// Set chunk size.
4541  ///
4542  /// \param E Chunk size.
4543  void setChunkSize(Expr *E) { ChunkSize = E; }
4544 
4545 public:
4546  /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
4547  /// size expression \a ChunkSize.
4548  ///
4549  /// \param StartLoc Starting location of the clause.
4550  /// \param LParenLoc Location of '('.
4551  /// \param KLoc Starting location of the argument.
4552  /// \param CommaLoc Location of ','.
4553  /// \param EndLoc Ending location of the clause.
4554  /// \param Kind DistSchedule kind.
4555  /// \param ChunkSize Chunk size.
4556  /// \param HelperChunkSize Helper chunk size for combined directives.
4557  OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4558  SourceLocation KLoc, SourceLocation CommaLoc,
4559  SourceLocation EndLoc,
4560  OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
4561  Stmt *HelperChunkSize)
4562  : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc),
4563  OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
4564  KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
4565  setPreInitStmt(HelperChunkSize);
4566  }
4567 
4568  /// Build an empty clause.
4570  : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()),
4571  OMPClauseWithPreInit(this) {}
4572 
4573  /// Get kind of the clause.
4575 
4576  /// Get location of '('.
4577  SourceLocation getLParenLoc() { return LParenLoc; }
4578 
4579  /// Get kind location.
4580  SourceLocation getDistScheduleKindLoc() { return KindLoc; }
4581 
4582  /// Get location of ','.
4583  SourceLocation getCommaLoc() { return CommaLoc; }
4584 
4585  /// Get chunk size.
4586  Expr *getChunkSize() { return ChunkSize; }
4587 
4588  /// Get chunk size.
4589  const Expr *getChunkSize() const { return ChunkSize; }
4590 
4592  return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
4593  reinterpret_cast<Stmt **>(&ChunkSize) + 1);
4594  }
4595 
4596  static bool classof(const OMPClause *T) {
4597  return T->getClauseKind() == OMPC_dist_schedule;
4598  }
4599 };
4600 
4601 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
4602 ///
4603 /// \code
4604 /// #pragma omp target defaultmap(tofrom: scalar)
4605 /// \endcode
4606 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
4607 /// 'scalar' with modifier 'tofrom'.
4609  friend class OMPClauseReader;
4610 
4611  /// Location of '('.
4612  SourceLocation LParenLoc;
4613 
4614  /// Modifiers for 'defaultmap' clause.
4616 
4617  /// Locations of modifiers.
4618  SourceLocation ModifierLoc;
4619 
4620  /// A kind of the 'defaultmap' clause.
4622 
4623  /// Start location of the defaultmap kind in source code.
4624  SourceLocation KindLoc;
4625 
4626  /// Set defaultmap kind.
4627  ///
4628  /// \param K Defaultmap kind.
4629  void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
4630 
4631  /// Set the defaultmap modifier.
4632  ///
4633  /// \param M Defaultmap modifier.
4634  void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
4635  Modifier = M;
4636  }
4637 
4638  /// Set location of the defaultmap modifier.
4639  void setDefaultmapModifierLoc(SourceLocation Loc) {
4640  ModifierLoc = Loc;
4641  }
4642 
4643  /// Sets the location of '('.
4644  ///
4645  /// \param Loc Location of '('.
4646  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4647 
4648  /// Set defaultmap kind start location.
4649  ///
4650  /// \param KLoc Defaultmap kind location.
4651  void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
4652 
4653 public:
4654  /// Build 'defaultmap' clause with defaultmap kind \a Kind
4655  ///
4656  /// \param StartLoc Starting location of the clause.
4657  /// \param LParenLoc Location of '('.
4658  /// \param KLoc Starting location of the argument.
4659  /// \param EndLoc Ending location of the clause.
4660  /// \param Kind Defaultmap kind.
4661  /// \param M The modifier applied to 'defaultmap' clause.
4662  /// \param MLoc Location of the modifier
4663  OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4664  SourceLocation MLoc, SourceLocation KLoc,
4665  SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
4667  : OMPClause(OMPC_defaultmap, StartLoc, EndLoc), LParenLoc(LParenLoc),
4668  Modifier(M), ModifierLoc(MLoc), Kind(Kind), KindLoc(KLoc) {}
4669 
4670  /// Build an empty clause.
4672  : OMPClause(OMPC_defaultmap, SourceLocation(), SourceLocation()) {}
4673 
4674  /// Get kind of the clause.
4676 
4677  /// Get the modifier of the clause.
4679  return Modifier;
4680  }
4681 
4682  /// Get location of '('.
4683  SourceLocation getLParenLoc() { return LParenLoc; }
4684 
4685  /// Get kind location.
4686  SourceLocation getDefaultmapKindLoc() { return KindLoc; }
4687 
4688  /// Get the modifier location.
4689  SourceLocation getDefaultmapModifierLoc() const {
4690  return ModifierLoc;
4691  }
4692 
4695  }
4696 
4697  static bool classof(const OMPClause *T) {
4698  return T->getClauseKind() == OMPC_defaultmap;
4699  }
4700 };
4701 
4702 /// This represents clause 'to' in the '#pragma omp ...'
4703 /// directives.
4704 ///
4705 /// \code
4706 /// #pragma omp target update to(a,b)
4707 /// \endcode
4708 /// In this example directive '#pragma omp target update' has clause 'to'
4709 /// with the variables 'a' and 'b'.
4710 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
4711  private llvm::TrailingObjects<
4712  OMPToClause, Expr *, ValueDecl *, unsigned,
4713  OMPClauseMappableExprCommon::MappableComponent> {
4714  friend class OMPClauseReader;
4716  friend OMPVarListClause;
4717  friend TrailingObjects;
4718 
4719  /// Build clause with number of variables \a NumVars.
4720  ///
4721  /// \param StartLoc Starting location of the clause.
4722  /// \param EndLoc Ending location of the clause.
4723  /// \param NumVars Number of expressions listed in this clause.
4724  /// \param NumUniqueDeclarations Number of unique base declarations in this
4725  /// clause.
4726  /// \param NumComponentLists Number of component lists in this clause.
4727  /// \param NumComponents Total number of expression components in the clause.
4728  explicit OMPToClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4729  SourceLocation EndLoc, unsigned NumVars,
4730  unsigned NumUniqueDeclarations,
4731  unsigned NumComponentLists, unsigned NumComponents)
4732  : OMPMappableExprListClause(OMPC_to, StartLoc, LParenLoc, EndLoc, NumVars,
4733  NumUniqueDeclarations, NumComponentLists,
4734  NumComponents) {}
4735 
4736  /// Build an empty clause.
4737  ///
4738  /// \param NumVars Number of expressions listed in this clause.
4739  /// \param NumUniqueDeclarations Number of unique base declarations in this
4740  /// clause.
4741  /// \param NumComponentLists Number of component lists in this clause.
4742  /// \param NumComponents Total number of expression components in the clause.
4743  explicit OMPToClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4744  unsigned NumComponentLists, unsigned NumComponents)
4746  OMPC_to, SourceLocation(), SourceLocation(), SourceLocation(),
4747  NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4748 
4749  /// Define the sizes of each trailing object array except the last one. This
4750  /// is required for TrailingObjects to work properly.
4751  size_t numTrailingObjects(OverloadToken<Expr *>) const {
4752  return varlist_size();
4753  }
4754  size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4755  return getUniqueDeclarationsNum();
4756  }
4757  size_t numTrailingObjects(OverloadToken<unsigned>) const {
4758  return getUniqueDeclarationsNum() + getTotalComponentListNum();
4759  }
4760 
4761 public:
4762  /// Creates clause with a list of variables \a Vars.
4763  ///
4764  /// \param C AST context.
4765  /// \param StartLoc Starting location of the clause.
4766  /// \param EndLoc Ending location of the clause.
4767  /// \param Vars The original expression used in the clause.
4768  /// \param Declarations Declarations used in the clause.
4769  /// \param ComponentLists Component lists used in the clause.
4770  static OMPToClause *Create(const ASTContext &C, SourceLocation StartLoc,
4771  SourceLocation LParenLoc, SourceLocation EndLoc,
4772  ArrayRef<Expr *> Vars,
4773  ArrayRef<ValueDecl *> Declarations,
4774  MappableExprComponentListsRef ComponentLists);
4775 
4776  /// Creates an empty clause with the place for \a NumVars variables.
4777  ///
4778  /// \param C AST context.
4779  /// \param NumVars Number of expressions listed in the clause.
4780  /// \param NumUniqueDeclarations Number of unique base declarations in this
4781  /// clause.
4782  /// \param NumComponentLists Number of unique base declarations in this
4783  /// clause.
4784  /// \param NumComponents Total number of expression components in the clause.
4785  static OMPToClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4786  unsigned NumUniqueDeclarations,
4787  unsigned NumComponentLists,
4788  unsigned NumComponents);
4789 
4791  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4792  reinterpret_cast<Stmt **>(varlist_end()));
4793  }
4794 
4795  static bool classof(const OMPClause *T) {
4796  return T->getClauseKind() == OMPC_to;
4797  }
4798 };
4799 
4800 /// This represents clause 'from' in the '#pragma omp ...'
4801 /// directives.
4802 ///
4803 /// \code
4804 /// #pragma omp target update from(a,b)
4805 /// \endcode
4806 /// In this example directive '#pragma omp target update' has clause 'from'
4807 /// with the variables 'a' and 'b'.
4808 class OMPFromClause final
4809  : public OMPMappableExprListClause<OMPFromClause>,
4810  private llvm::TrailingObjects<
4811  OMPFromClause, Expr *, ValueDecl *, unsigned,
4812  OMPClauseMappableExprCommon::MappableComponent> {
4813  friend class OMPClauseReader;
4815  friend OMPVarListClause;
4816  friend TrailingObjects;
4817 
4818  /// Build clause with number of variables \a NumVars.
4819  ///
4820  /// \param StartLoc Starting location of the clause.
4821  /// \param EndLoc Ending location of the clause.
4822  /// \param NumVars Number of expressions listed in this clause.
4823  /// \param NumUniqueDeclarations Number of unique base declarations in this
4824  /// clause.
4825  /// \param NumComponentLists Number of component lists in this clause.
4826  /// \param NumComponents Total number of expression components in the clause.
4827  explicit OMPFromClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4828  SourceLocation EndLoc, unsigned NumVars,
4829  unsigned NumUniqueDeclarations,
4830  unsigned NumComponentLists, unsigned NumComponents)
4831  : OMPMappableExprListClause(OMPC_from, StartLoc, LParenLoc, EndLoc,
4832  NumVars, NumUniqueDeclarations,
4833  NumComponentLists, NumComponents) {}
4834 
4835  /// Build an empty clause.
4836  ///
4837  /// \param NumVars Number of expressions listed in this clause.
4838  /// \param NumUniqueDeclarations Number of unique base declarations in this
4839  /// clause.
4840  /// \param NumComponentLists Number of component lists in this clause.
4841  /// \param NumComponents Total number of expression components in the clause.
4842  explicit OMPFromClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4843  unsigned NumComponentLists, unsigned NumComponents)
4845  OMPC_from, SourceLocation(), SourceLocation(), SourceLocation(),
4846  NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4847 
4848  /// Define the sizes of each trailing object array except the last one. This
4849  /// is required for TrailingObjects to work properly.
4850  size_t numTrailingObjects(OverloadToken<Expr *>) const {
4851  return varlist_size();
4852  }
4853  size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4854  return getUniqueDeclarationsNum();
4855  }
4856  size_t numTrailingObjects(OverloadToken<unsigned>) const {
4857  return getUniqueDeclarationsNum() + getTotalComponentListNum();
4858  }
4859 
4860 public:
4861  /// Creates clause with a list of variables \a Vars.
4862  ///
4863  /// \param C AST context.
4864  /// \param StartLoc Starting location of the clause.
4865  /// \param EndLoc Ending location of the clause.
4866  /// \param Vars The original expression used in the clause.
4867  /// \param Declarations Declarations used in the clause.
4868  /// \param ComponentLists Component lists used in the clause.
4869  static OMPFromClause *Create(const ASTContext &C, SourceLocation StartLoc,
4870  SourceLocation LParenLoc, SourceLocation EndLoc,
4871  ArrayRef<Expr *> Vars,
4872  ArrayRef<ValueDecl *> Declarations,
4873  MappableExprComponentListsRef ComponentLists);
4874 
4875  /// Creates an empty clause with the place for \a NumVars variables.
4876  ///
4877  /// \param C AST context.
4878  /// \param NumVars Number of expressions listed in the clause.
4879  /// \param NumUniqueDeclarations Number of unique base declarations in this
4880  /// clause.
4881  /// \param NumComponentLists Number of unique base declarations in this
4882  /// clause.
4883  /// \param NumComponents Total number of expression components in the clause.
4884  static OMPFromClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4885  unsigned NumUniqueDeclarations,
4886  unsigned NumComponentLists,
4887  unsigned NumComponents);
4888 
4890  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4891  reinterpret_cast<Stmt **>(varlist_end()));
4892  }
4893 
4894  static bool classof(const OMPClause *T) {
4895  return T->getClauseKind() == OMPC_from;
4896  }
4897 };
4898 
4899 /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
4900 /// directives.
4901 ///
4902 /// \code
4903 /// #pragma omp target data use_device_ptr(a,b)
4904 /// \endcode
4905 /// In this example directive '#pragma omp target data' has clause
4906 /// 'use_device_ptr' with the variables 'a' and 'b'.
4908  : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
4909  private llvm::TrailingObjects<
4910  OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
4911  OMPClauseMappableExprCommon::MappableComponent> {
4912  friend class OMPClauseReader;
4914  friend OMPVarListClause;
4915  friend TrailingObjects;
4916 
4917  /// Build clause with number of variables \a NumVars.
4918  ///
4919  /// \param StartLoc Starting location of the clause.
4920  /// \param EndLoc Ending location of the clause.
4921  /// \param NumVars Number of expressions listed in this clause.
4922  /// \param NumUniqueDeclarations Number of unique base declarations in this
4923  /// clause.
4924  /// \param NumComponentLists Number of component lists in this clause.
4925  /// \param NumComponents Total number of expression components in the clause.
4926  explicit OMPUseDevicePtrClause(SourceLocation StartLoc,
4927  SourceLocation LParenLoc,
4928  SourceLocation EndLoc, unsigned NumVars,
4929  unsigned NumUniqueDeclarations,
4930  unsigned NumComponentLists,
4931  unsigned NumComponents)
4932  : OMPMappableExprListClause(OMPC_use_device_ptr, StartLoc, LParenLoc,
4933  EndLoc, NumVars, NumUniqueDeclarations,
4934  NumComponentLists, NumComponents) {}
4935 
4936  /// Build an empty clause.
4937  ///
4938  /// \param NumVars Number of expressions listed in this clause.
4939  /// \param NumUniqueDeclarations Number of unique base declarations in this
4940  /// clause.
4941  /// \param NumComponentLists Number of component lists in this clause.
4942  /// \param NumComponents Total number of expression components in the clause.
4943  explicit OMPUseDevicePtrClause(unsigned NumVars,
4944  unsigned NumUniqueDeclarations,
4945  unsigned NumComponentLists,
4946  unsigned NumComponents)
4947  : OMPMappableExprListClause(OMPC_use_device_ptr, SourceLocation(),
4948  SourceLocation(), SourceLocation(), NumVars,
4949  NumUniqueDeclarations, NumComponentLists,
4950  NumComponents) {}
4951 
4952  /// Define the sizes of each trailing object array except the last one. This
4953  /// is required for TrailingObjects to work properly.
4954  size_t numTrailingObjects(OverloadToken<Expr *>) const {
4955  return 3 * varlist_size();
4956  }
4957  size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4958  return getUniqueDeclarationsNum();
4959  }
4960  size_t numTrailingObjects(OverloadToken<unsigned>) const {
4961  return getUniqueDeclarationsNum() + getTotalComponentListNum();
4962  }
4963 
4964  /// Sets the list of references to private copies with initializers for new
4965  /// private variables.
4966  /// \param VL List of references.
4967  void setPrivateCopies(ArrayRef<Expr *> VL);
4968 
4969  /// Gets the list of references to private copies with initializers for new
4970  /// private variables.
4971  MutableArrayRef<Expr *> getPrivateCopies() {
4972  return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4973  }
4974  ArrayRef<const Expr *> getPrivateCopies() const {
4975  return llvm::makeArrayRef(varlist_end(), varlist_size());
4976  }
4977 
4978  /// Sets the list of references to initializer variables for new private
4979  /// variables.
4980  /// \param VL List of references.
4981  void setInits(ArrayRef<Expr *> VL);
4982 
4983  /// Gets the list of references to initializer variables for new private
4984  /// variables.
4985  MutableArrayRef<Expr *> getInits() {
4986  return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
4987  }
4988  ArrayRef<const Expr *> getInits() const {
4989  return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
4990  }
4991 
4992 public:
4993  /// Creates clause with a list of variables \a Vars.
4994  ///
4995  /// \param C AST context.
4996  /// \param StartLoc Starting location of the clause.
4997  /// \param EndLoc Ending location of the clause.
4998  /// \param Vars The original expression used in the clause.
4999  /// \param PrivateVars Expressions referring to private copies.
5000  /// \param Inits Expressions referring to private copy initializers.
5001  /// \param Declarations Declarations used in the clause.
5002  /// \param ComponentLists Component lists used in the clause.
5003  static OMPUseDevicePtrClause *
5004  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
5005  SourceLocation EndLoc, ArrayRef<Expr *> Vars,
5006  ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
5007  ArrayRef<ValueDecl *> Declarations,
5008  MappableExprComponentListsRef ComponentLists);
5009 
5010  /// Creates an empty clause with the place for \a NumVars variables.
5011  ///
5012  /// \param C AST context.
5013  /// \param NumVars Number of expressions listed in the clause.
5014  /// \param NumUniqueDeclarations Number of unique base declarations in this
5015  /// clause.
5016  /// \param NumComponentLists Number of unique base declarations in this
5017  /// clause.
5018  /// \param NumComponents Total number of expression components in the clause.
5019  static OMPUseDevicePtrClause *CreateEmpty(const ASTContext &C,
5020  unsigned NumVars,
5021  unsigned NumUniqueDeclarations,
5022  unsigned NumComponentLists,
5023  unsigned NumComponents);
5024 
5025  using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
5026  using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
5027  using private_copies_range = llvm::iterator_range<private_copies_iterator>;
5029  llvm::iterator_range<private_copies_const_iterator>;
5030 
5032  return private_copies_range(getPrivateCopies().begin(),
5033  getPrivateCopies().end());
5034  }
5035 
5037  return private_copies_const_range(getPrivateCopies().begin(),
5038  getPrivateCopies().end());
5039  }
5040 
5041  using inits_iterator = MutableArrayRef<Expr *>::iterator;
5042  using inits_const_iterator = ArrayRef<const Expr *>::iterator;
5043  using inits_range = llvm::iterator_range<inits_iterator>;
5044  using inits_const_range = llvm::iterator_range<inits_const_iterator>;
5045 
5047  return inits_range(getInits().begin(), getInits().end());
5048  }
5049 
5051  return inits_const_range(getInits().begin(), getInits().end());
5052  }
5053 
5055  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5056  reinterpret_cast<Stmt **>(varlist_end()));
5057  }
5058 
5059  static bool classof(const OMPClause *T) {
5060  return T->getClauseKind() == OMPC_use_device_ptr;
5061  }
5062 };
5063 
5064 /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
5065 /// directives.
5066 ///
5067 /// \code
5068 /// #pragma omp target is_device_ptr(a,b)
5069 /// \endcode
5070 /// In this example directive '#pragma omp target' has clause
5071 /// 'is_device_ptr' with the variables 'a' and 'b'.
5073  : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
5074  private llvm::TrailingObjects<
5075  OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
5076  OMPClauseMappableExprCommon::MappableComponent> {
5077  friend class OMPClauseReader;
5079  friend OMPVarListClause;
5080  friend TrailingObjects;
5081 
5082  /// Build clause with number of variables \a NumVars.
5083  ///
5084  /// \param StartLoc Starting location of the clause.
5085  /// \param EndLoc Ending location of the clause.
5086  /// \param NumVars Number of expressions listed in this clause.
5087  /// \param NumUniqueDeclarations Number of unique base declarations in this
5088  /// clause.
5089  /// \param NumComponentLists Number of component lists in this clause.
5090  /// \param NumComponents Total number of expression components in the clause.
5091  explicit OMPIsDevicePtrClause(SourceLocation StartLoc,
5092  SourceLocation LParenLoc, SourceLocation EndLoc,
5093  unsigned NumVars,
5094  unsigned NumUniqueDeclarations,
5095  unsigned NumComponentLists,
5096  unsigned NumComponents)
5097  : OMPMappableExprListClause(OMPC_is_device_ptr, StartLoc, LParenLoc,
5098  EndLoc, NumVars, NumUniqueDeclarations,
5099  NumComponentLists, NumComponents) {}
5100 
5101  /// Build an empty clause.
5102  ///
5103  /// \param NumVars Number of expressions listed in this clause.
5104  /// \param NumUniqueDeclarations Number of unique base declarations in this
5105  /// clause.
5106  /// \param NumComponentLists Number of component lists in this clause.
5107  /// \param NumComponents Total number of expression components in the clause.
5108  explicit OMPIsDevicePtrClause(unsigned NumVars,
5109  unsigned NumUniqueDeclarations,
5110  unsigned NumComponentLists,
5111  unsigned NumComponents)
5112  : OMPMappableExprListClause(OMPC_is_device_ptr, SourceLocation(),
5113  SourceLocation(), SourceLocation(), NumVars,
5114  NumUniqueDeclarations, NumComponentLists,
5115  NumComponents) {}
5116 
5117  /// Define the sizes of each trailing object array except the last one. This
5118  /// is required for TrailingObjects to work properly.
5119  size_t numTrailingObjects(OverloadToken<Expr *>) const {
5120  return varlist_size();
5121  }
5122  size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
5123  return getUniqueDeclarationsNum();
5124  }
5125  size_t numTrailingObjects(OverloadToken<unsigned>) const {
5126  return getUniqueDeclarationsNum() + getTotalComponentListNum();
5127  }
5128 
5129 public:
5130  /// Creates clause with a list of variables \a Vars.
5131  ///
5132  /// \param C AST context.
5133  /// \param StartLoc Starting location of the clause.
5134  /// \param EndLoc Ending location of the clause.
5135  /// \param Vars The original expression used in the clause.
5136  /// \param Declarations Declarations used in the clause.
5137  /// \param ComponentLists Component lists used in the clause.
5138  static OMPIsDevicePtrClause *
5139  Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
5140  SourceLocation EndLoc, ArrayRef<Expr *> Vars,
5141  ArrayRef<ValueDecl *> Declarations,
5142  MappableExprComponentListsRef ComponentLists);
5143 
5144  /// Creates an empty clause with the place for \a NumVars variables.
5145  ///
5146  /// \param C AST context.
5147  /// \param NumVars Number of expressions listed in the clause.
5148  /// \param NumUniqueDeclarations Number of unique base declarations in this
5149  /// clause.
5150  /// \param NumComponentLists Number of unique base declarations in this
5151  /// clause.
5152  /// \param NumComponents Total number of expression components in the clause.
5153  static OMPIsDevicePtrClause *CreateEmpty(const ASTContext &C,
5154  unsigned NumVars,
5155  unsigned NumUniqueDeclarations,
5156  unsigned NumComponentLists,
5157  unsigned NumComponents);
5158 
5160  return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5161  reinterpret_cast<Stmt **>(varlist_end()));
5162  }
5163 
5164  static bool classof(const OMPClause *T) {
5165  return T->getClauseKind() == OMPC_is_device_ptr;
5166  }
5167 };
5168 
5169 /// This class implements a simple visitor for OMPClause
5170 /// subclasses.
5171 template<class ImplClass, template <typename> class Ptr, typename RetTy>
5173 public:
5174 #define PTR(CLASS) typename Ptr<CLASS>::type
5175 #define DISPATCH(CLASS) \
5176  return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
5177 
5178 #define OPENMP_CLAUSE(Name, Class) \
5179  RetTy Visit ## Class (PTR(Class) S) { DISPATCH(Class); }
5180 #include "clang/Basic/OpenMPKinds.def"
5181 
5182  RetTy Visit(PTR(OMPClause) S) {
5183  // Top switch clause: visit each OMPClause.
5184  switch (S->getClauseKind()) {
5185  default: llvm_unreachable("Unknown clause kind!");
5186 #define OPENMP_CLAUSE(Name, Class) \
5187  case OMPC_ ## Name : return Visit ## Class(static_cast<PTR(Class)>(S));
5188 #include "clang/Basic/OpenMPKinds.def"
5189  }
5190  }
5191  // Base case, ignore it. :)
5192  RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); }
5193 #undef PTR
5194 #undef DISPATCH
5195 };
5196 
5197 template <typename T>
5199 
5200 template<class ImplClass, typename RetTy = void>
5202  public OMPClauseVisitorBase <ImplClass, std::add_pointer, RetTy> {};
5203 template<class ImplClass, typename RetTy = void>
5205  public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {};
5206 } // namespace clang
5207 
5208 #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
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
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; clause in the &#39;#pragma omp ...&#39; directive.
helper_expr_const_range lhs_exprs() const
llvm::iterator_range< private_copies_iterator > private_copies_range
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:717
inits_range inits()
Expr * getCondition() const
Returns condition.
Definition: OpenMPClause.h:365
This represents &#39;update&#39; clause in the &#39;#pragma omp atomic&#39; directive.
child_range children()
void setComponents(ArrayRef< MappableComponent > Components, ArrayRef< unsigned > CLSs)
Set the components that are in the trailing objects of the class.
ArrayRef< const Expr * >::iterator private_copies_const_iterator
Expr * getCondition() const
Returns condition.
Definition: OpenMPClause.h:308
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:584
MutableArrayRef< Expr * >::iterator helper_expr_iterator
OpenMPDefaultmapClauseModifier
OpenMP modifiers for &#39;defaultmap&#39; clause.
Definition: OpenMPKinds.h:115
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
Definition: OpenMPClause.h:529
Expr * getAlignment()
Returns alignment.
Expr * getNumForLoops() const
Return the number of associated for-loops.
SourceLocation getSecondScheduleModifierLoc() const
Get the second modifier location.
helper_expr_range rhs_exprs()
ArrayRef< MappableComponent > getComponentsRef() const
Get the components that are in the trailing objects of the class.
void setLParenLoc(SourceLocation Loc)
Sets the location of &#39;(&#39;.
static bool classof(const OMPClause *T)
Definition: OpenMPClause.h:732
SourceLocation getDependencyLoc() const
Get dependency type location.
This represents &#39;read&#39; clause in the &#39;#pragma omp atomic&#39; directive.
helper_expr_const_range assignment_ops() const
OMPFinalClause()
Build an empty clause.
Definition: OpenMPClause.h:355
finals_range finals()
helper_expr_range source_exprs()
This represents clause &#39;private&#39; in the &#39;#pragma omp ...&#39; directives.
static bool classof(const OMPClause *T)
Definition: OpenMPClause.h:485
static bool classof(const OMPClause *T)
This represents &#39;num_threads&#39; clause in the &#39;#pragma omp ...&#39; directive.
Definition: OpenMPClause.h:382
varlist_range varlists()
Definition: OpenMPClause.h:207
llvm::iterator_range< const_all_num_lists_iterator > const_all_num_lists_range
This represents &#39;defaultmap&#39; clause in the &#39;#pragma omp ...&#39; directive.
friend OMPVarListClause
Definition: OpenMPClause.h:98
This represents clauses with a list of expressions that are mappable.
llvm::iterator_range< const_all_components_iterator > const_all_components_range
void setUpdates(ArrayRef< Expr *> UL)
Sets the list of update expressions for linear variables.
StmtIterator child_iterator
Definition: OpenMPClause.h:83
SourceLocation getColonLoc() const
Return the location of &#39;:&#39;.
Definition: OpenMPClause.h:305
This represents implicit clause &#39;flush&#39; for the &#39;#pragma omp flush&#39; directive.
const DeclarationNameInfo & getNameInfo() const
Gets the name info for specified reduction identifier.
Definit