1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
18 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
20 #include "clang/AST/Decl.h"
21 #include "clang/AST/DeclarationName.h"
22 #include "clang/AST/Expr.h"
23 #include "clang/AST/NestedNameSpecifier.h"
24 #include "clang/AST/Stmt.h"
25 #include "clang/AST/StmtIterator.h"
26 #include "clang/Basic/LLVM.h"
27 #include "clang/Basic/OpenMPKinds.h"
28 #include "clang/Basic/SourceLocation.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"
46 //===----------------------------------------------------------------------===//
47 // AST classes for clauses.
48 //===----------------------------------------------------------------------===//
50 /// This is a basic class for representing single OpenMP clause.
52 /// Starting location of the clause (the clause keyword).
53 SourceLocation StartLoc;
55 /// Ending location of the clause.
56 SourceLocation EndLoc;
58 /// Kind of the clause.
59 OpenMPClauseKind Kind;
62 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
63 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
66 /// Returns the starting location of the clause.
67 SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc(); }
68 SourceLocation getBeginLoc() const { return StartLoc; }
70 /// Returns the ending location of the clause.
71 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
72 SourceLocation getEndLoc() const { return EndLoc; }
74 /// Sets the starting location of the clause.
75 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
77 /// Sets the ending location of the clause.
78 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
80 /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
81 OpenMPClauseKind getClauseKind() const { return Kind; }
83 bool isImplicit() const { return StartLoc.isInvalid(); }
85 using child_iterator = StmtIterator;
86 using const_child_iterator = ConstStmtIterator;
87 using child_range = llvm::iterator_range<child_iterator>;
88 using const_child_range = llvm::iterator_range<const_child_iterator>;
90 child_range children();
91 const_child_range children() const {
92 auto Children = const_cast<OMPClause *>(this)->children();
93 return const_child_range(Children.begin(), Children.end());
96 static bool classof(const OMPClause *) { return true; }
99 /// Class that handles pre-initialization statement for some clauses, like
100 /// 'shedule', 'firstprivate' etc.
101 class OMPClauseWithPreInit {
102 friend class OMPClauseReader;
104 /// Pre-initialization statement for the clause.
105 Stmt *PreInit = nullptr;
107 /// Region that captures the associated stmt.
108 OpenMPDirectiveKind CaptureRegion = OMPD_unknown;
111 OMPClauseWithPreInit(const OMPClause *This) {
112 assert(get(This) && "get is not tuned for pre-init.");
115 /// Set pre-initialization statement for the clause.
116 void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion = OMPD_unknown) {
118 CaptureRegion = ThisRegion;
122 /// Get pre-initialization statement for the clause.
123 const Stmt *getPreInitStmt() const { return PreInit; }
125 /// Get pre-initialization statement for the clause.
126 Stmt *getPreInitStmt() { return PreInit; }
128 /// Get capture region for the stmt in the clause.
129 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
131 static OMPClauseWithPreInit *get(OMPClause *C);
132 static const OMPClauseWithPreInit *get(const OMPClause *C);
135 /// Class that handles post-update expression for some clauses, like
136 /// 'lastprivate', 'reduction' etc.
137 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
138 friend class OMPClauseReader;
140 /// Post-update expression for the clause.
141 Expr *PostUpdate = nullptr;
144 OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
145 assert(get(This) && "get is not tuned for post-update.");
148 /// Set pre-initialization statement for the clause.
149 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
152 /// Get post-update expression for the clause.
153 const Expr *getPostUpdateExpr() const { return PostUpdate; }
155 /// Get post-update expression for the clause.
156 Expr *getPostUpdateExpr() { return PostUpdate; }
158 static OMPClauseWithPostUpdate *get(OMPClause *C);
159 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
162 /// This represents clauses with the list of variables like 'private',
163 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
164 /// '#pragma omp ...' directives.
165 template <class T> class OMPVarListClause : public OMPClause {
166 friend class OMPClauseReader;
169 SourceLocation LParenLoc;
171 /// Number of variables in the list.
175 /// Build a clause with \a N variables
177 /// \param K Kind of the clause.
178 /// \param StartLoc Starting location of the clause (the clause keyword).
179 /// \param LParenLoc Location of '('.
180 /// \param EndLoc Ending location of the clause.
181 /// \param N Number of the variables in the clause.
182 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
183 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
184 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
186 /// Fetches list of variables associated with this clause.
187 MutableArrayRef<Expr *> getVarRefs() {
188 return MutableArrayRef<Expr *>(
189 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
192 /// Sets the list of variables for this clause.
193 void setVarRefs(ArrayRef<Expr *> VL) {
194 assert(VL.size() == NumVars &&
195 "Number of variables is not the same as the preallocated buffer");
196 std::copy(VL.begin(), VL.end(),
197 static_cast<T *>(this)->template getTrailingObjects<Expr *>());
201 using varlist_iterator = MutableArrayRef<Expr *>::iterator;
202 using varlist_const_iterator = ArrayRef<const Expr *>::iterator;
203 using varlist_range = llvm::iterator_range<varlist_iterator>;
204 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
206 unsigned varlist_size() const { return NumVars; }
207 bool varlist_empty() const { return NumVars == 0; }
209 varlist_range varlists() {
210 return varlist_range(varlist_begin(), varlist_end());
212 varlist_const_range varlists() const {
213 return varlist_const_range(varlist_begin(), varlist_end());
216 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
217 varlist_iterator varlist_end() { return getVarRefs().end(); }
218 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
219 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
221 /// Sets the location of '('.
222 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
224 /// Returns the location of '('.
225 SourceLocation getLParenLoc() const { return LParenLoc; }
227 /// Fetches list of all variables in the clause.
228 ArrayRef<const Expr *> getVarRefs() const {
229 return llvm::makeArrayRef(
230 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
235 /// This represents 'if' clause in the '#pragma omp ...' directive.
238 /// #pragma omp parallel if(parallel:a > 5)
240 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
241 /// condition 'a > 5' and directive name modifier 'parallel'.
242 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
243 friend class OMPClauseReader;
246 SourceLocation LParenLoc;
248 /// Condition of the 'if' clause.
249 Stmt *Condition = nullptr;
251 /// Location of ':' (if any).
252 SourceLocation ColonLoc;
254 /// Directive name modifier for the clause.
255 OpenMPDirectiveKind NameModifier = OMPD_unknown;
257 /// Name modifier location.
258 SourceLocation NameModifierLoc;
261 void setCondition(Expr *Cond) { Condition = Cond; }
263 /// Set directive name modifier for the clause.
264 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
266 /// Set location of directive name modifier for the clause.
267 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
269 /// Set location of ':'.
270 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
273 /// Build 'if' clause with condition \a Cond.
275 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
276 /// \param Cond Condition of the clause.
277 /// \param HelperCond Helper condition for the clause.
278 /// \param CaptureRegion Innermost OpenMP region where expressions in this
279 /// clause must be captured.
280 /// \param StartLoc Starting location of the clause.
281 /// \param LParenLoc Location of '('.
282 /// \param NameModifierLoc Location of directive name modifier.
283 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
284 /// \param EndLoc Ending location of the clause.
285 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
286 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
287 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
288 SourceLocation ColonLoc, SourceLocation EndLoc)
289 : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this),
290 LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
291 NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) {
292 setPreInitStmt(HelperCond, CaptureRegion);
295 /// Build an empty clause.
297 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
298 OMPClauseWithPreInit(this) {}
300 /// Sets the location of '('.
301 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
303 /// Returns the location of '('.
304 SourceLocation getLParenLoc() const { return LParenLoc; }
306 /// Return the location of ':'.
307 SourceLocation getColonLoc() const { return ColonLoc; }
309 /// Returns condition.
310 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
312 /// Return directive name modifier associated with the clause.
313 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
315 /// Return the location of directive name modifier.
316 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
318 child_range children() { return child_range(&Condition, &Condition + 1); }
320 static bool classof(const OMPClause *T) {
321 return T->getClauseKind() == OMPC_if;
325 /// This represents 'final' clause in the '#pragma omp ...' directive.
328 /// #pragma omp task final(a > 5)
330 /// In this example directive '#pragma omp task' has simple 'final'
331 /// clause with condition 'a > 5'.
332 class OMPFinalClause : public OMPClause {
333 friend class OMPClauseReader;
336 SourceLocation LParenLoc;
338 /// Condition of the 'if' clause.
339 Stmt *Condition = nullptr;
342 void setCondition(Expr *Cond) { Condition = Cond; }
345 /// Build 'final' clause with condition \a Cond.
347 /// \param StartLoc Starting location of the clause.
348 /// \param LParenLoc Location of '('.
349 /// \param Cond Condition of the clause.
350 /// \param EndLoc Ending location of the clause.
351 OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
352 SourceLocation EndLoc)
353 : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
356 /// Build an empty clause.
358 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()) {}
360 /// Sets the location of '('.
361 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
363 /// Returns the location of '('.
364 SourceLocation getLParenLoc() const { return LParenLoc; }
366 /// Returns condition.
367 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
369 child_range children() { return child_range(&Condition, &Condition + 1); }
371 static bool classof(const OMPClause *T) {
372 return T->getClauseKind() == OMPC_final;
376 /// This represents 'num_threads' clause in the '#pragma omp ...'
380 /// #pragma omp parallel num_threads(6)
382 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
383 /// clause with number of threads '6'.
384 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
385 friend class OMPClauseReader;
388 SourceLocation LParenLoc;
390 /// Condition of the 'num_threads' clause.
391 Stmt *NumThreads = nullptr;
394 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
397 /// Build 'num_threads' clause with condition \a NumThreads.
399 /// \param NumThreads Number of threads for the construct.
400 /// \param HelperNumThreads Helper Number of threads for the construct.
401 /// \param CaptureRegion Innermost OpenMP region where expressions in this
402 /// clause must be captured.
403 /// \param StartLoc Starting location of the clause.
404 /// \param LParenLoc Location of '('.
405 /// \param EndLoc Ending location of the clause.
406 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
407 OpenMPDirectiveKind CaptureRegion,
408 SourceLocation StartLoc, SourceLocation LParenLoc,
409 SourceLocation EndLoc)
410 : OMPClause(OMPC_num_threads, StartLoc, EndLoc),
411 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
412 NumThreads(NumThreads) {
413 setPreInitStmt(HelperNumThreads, CaptureRegion);
416 /// Build an empty clause.
417 OMPNumThreadsClause()
418 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
419 OMPClauseWithPreInit(this) {}
421 /// Sets the location of '('.
422 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
424 /// Returns the location of '('.
425 SourceLocation getLParenLoc() const { return LParenLoc; }
427 /// Returns number of threads.
428 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
430 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
432 static bool classof(const OMPClause *T) {
433 return T->getClauseKind() == OMPC_num_threads;
437 /// This represents 'safelen' clause in the '#pragma omp ...'
441 /// #pragma omp simd safelen(4)
443 /// In this example directive '#pragma omp simd' has clause 'safelen'
444 /// with single expression '4'.
445 /// If the safelen clause is used then no two iterations executed
446 /// concurrently with SIMD instructions can have a greater distance
447 /// in the logical iteration space than its value. The parameter of
448 /// the safelen clause must be a constant positive integer expression.
449 class OMPSafelenClause : public OMPClause {
450 friend class OMPClauseReader;
453 SourceLocation LParenLoc;
455 /// Safe iteration space distance.
456 Stmt *Safelen = nullptr;
459 void setSafelen(Expr *Len) { Safelen = Len; }
462 /// Build 'safelen' clause.
464 /// \param Len Expression associated with this clause.
465 /// \param StartLoc Starting location of the clause.
466 /// \param EndLoc Ending location of the clause.
467 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
468 SourceLocation EndLoc)
469 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
472 /// Build an empty clause.
473 explicit OMPSafelenClause()
474 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()) {}
476 /// Sets the location of '('.
477 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
479 /// Returns the location of '('.
480 SourceLocation getLParenLoc() const { return LParenLoc; }
482 /// Return safe iteration space distance.
483 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
485 child_range children() { return child_range(&Safelen, &Safelen + 1); }
487 static bool classof(const OMPClause *T) {
488 return T->getClauseKind() == OMPC_safelen;
492 /// This represents 'simdlen' clause in the '#pragma omp ...'
496 /// #pragma omp simd simdlen(4)
498 /// In this example directive '#pragma omp simd' has clause 'simdlen'
499 /// with single expression '4'.
500 /// If the 'simdlen' clause is used then it specifies the preferred number of
501 /// iterations to be executed concurrently. The parameter of the 'simdlen'
502 /// clause must be a constant positive integer expression.
503 class OMPSimdlenClause : public OMPClause {
504 friend class OMPClauseReader;
507 SourceLocation LParenLoc;
509 /// Safe iteration space distance.
510 Stmt *Simdlen = nullptr;
513 void setSimdlen(Expr *Len) { Simdlen = Len; }
516 /// Build 'simdlen' clause.
518 /// \param Len Expression associated with this clause.
519 /// \param StartLoc Starting location of the clause.
520 /// \param EndLoc Ending location of the clause.
521 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
522 SourceLocation EndLoc)
523 : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
526 /// Build an empty clause.
527 explicit OMPSimdlenClause()
528 : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()) {}
530 /// Sets the location of '('.
531 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
533 /// Returns the location of '('.
534 SourceLocation getLParenLoc() const { return LParenLoc; }
536 /// Return safe iteration space distance.
537 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
539 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
541 static bool classof(const OMPClause *T) {
542 return T->getClauseKind() == OMPC_simdlen;
546 /// This represents 'collapse' clause in the '#pragma omp ...'
550 /// #pragma omp simd collapse(3)
552 /// In this example directive '#pragma omp simd' has clause 'collapse'
553 /// with single expression '3'.
554 /// The parameter must be a constant positive integer expression, it specifies
555 /// the number of nested loops that should be collapsed into a single iteration
557 class OMPCollapseClause : public OMPClause {
558 friend class OMPClauseReader;
561 SourceLocation LParenLoc;
563 /// Number of for-loops.
564 Stmt *NumForLoops = nullptr;
566 /// Set the number of associated for-loops.
567 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
570 /// Build 'collapse' clause.
572 /// \param Num Expression associated with this clause.
573 /// \param StartLoc Starting location of the clause.
574 /// \param LParenLoc Location of '('.
575 /// \param EndLoc Ending location of the clause.
576 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
577 SourceLocation LParenLoc, SourceLocation EndLoc)
578 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
581 /// Build an empty clause.
582 explicit OMPCollapseClause()
583 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()) {}
585 /// Sets the location of '('.
586 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
588 /// Returns the location of '('.
589 SourceLocation getLParenLoc() const { return LParenLoc; }
591 /// Return the number of associated for-loops.
592 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
594 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
596 static bool classof(const OMPClause *T) {
597 return T->getClauseKind() == OMPC_collapse;
601 /// This represents 'default' clause in the '#pragma omp ...' directive.
604 /// #pragma omp parallel default(shared)
606 /// In this example directive '#pragma omp parallel' has simple 'default'
607 /// clause with kind 'shared'.
608 class OMPDefaultClause : public OMPClause {
609 friend class OMPClauseReader;
612 SourceLocation LParenLoc;
614 /// A kind of the 'default' clause.
615 OpenMPDefaultClauseKind Kind = OMPC_DEFAULT_unknown;
617 /// Start location of the kind in source code.
618 SourceLocation KindKwLoc;
620 /// Set kind of the clauses.
622 /// \param K Argument of clause.
623 void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
625 /// Set argument location.
627 /// \param KLoc Argument location.
628 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
631 /// Build 'default' clause with argument \a A ('none' or 'shared').
633 /// \param A Argument of the clause ('none' or 'shared').
634 /// \param ALoc Starting location of the argument.
635 /// \param StartLoc Starting location of the clause.
636 /// \param LParenLoc Location of '('.
637 /// \param EndLoc Ending location of the clause.
638 OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
639 SourceLocation StartLoc, SourceLocation LParenLoc,
640 SourceLocation EndLoc)
641 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
642 Kind(A), KindKwLoc(ALoc) {}
644 /// Build an empty clause.
646 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()) {}
648 /// Sets the location of '('.
649 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
651 /// Returns the location of '('.
652 SourceLocation getLParenLoc() const { return LParenLoc; }
654 /// Returns kind of the clause.
655 OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
657 /// Returns location of clause kind.
658 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
660 child_range children() {
661 return child_range(child_iterator(), child_iterator());
664 static bool classof(const OMPClause *T) {
665 return T->getClauseKind() == OMPC_default;
669 /// This represents 'proc_bind' clause in the '#pragma omp ...'
673 /// #pragma omp parallel proc_bind(master)
675 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
676 /// clause with kind 'master'.
677 class OMPProcBindClause : public OMPClause {
678 friend class OMPClauseReader;
681 SourceLocation LParenLoc;
683 /// A kind of the 'proc_bind' clause.
684 OpenMPProcBindClauseKind Kind = OMPC_PROC_BIND_unknown;
686 /// Start location of the kind in source code.
687 SourceLocation KindKwLoc;
689 /// Set kind of the clause.
691 /// \param K Kind of clause.
692 void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
694 /// Set clause kind location.
696 /// \param KLoc Kind location.
697 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
700 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
703 /// \param A Argument of the clause ('master', 'close' or 'spread').
704 /// \param ALoc Starting location of the argument.
705 /// \param StartLoc Starting location of the clause.
706 /// \param LParenLoc Location of '('.
707 /// \param EndLoc Ending location of the clause.
708 OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
709 SourceLocation StartLoc, SourceLocation LParenLoc,
710 SourceLocation EndLoc)
711 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
712 Kind(A), KindKwLoc(ALoc) {}
714 /// Build an empty clause.
716 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()) {}
718 /// Sets the location of '('.
719 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
721 /// Returns the location of '('.
722 SourceLocation getLParenLoc() const { return LParenLoc; }
724 /// Returns kind of the clause.
725 OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
727 /// Returns location of clause kind.
728 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
730 child_range children() {
731 return child_range(child_iterator(), child_iterator());
734 static bool classof(const OMPClause *T) {
735 return T->getClauseKind() == OMPC_proc_bind;
739 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
742 /// #pragma omp for schedule(static, 3)
744 /// In this example directive '#pragma omp for' has 'schedule' clause with
745 /// arguments 'static' and '3'.
746 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
747 friend class OMPClauseReader;
750 SourceLocation LParenLoc;
752 /// A kind of the 'schedule' clause.
753 OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
755 /// Modifiers for 'schedule' clause.
756 enum {FIRST, SECOND, NUM_MODIFIERS};
757 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
759 /// Locations of modifiers.
760 SourceLocation ModifiersLoc[NUM_MODIFIERS];
762 /// Start location of the schedule ind in source code.
763 SourceLocation KindLoc;
765 /// Location of ',' (if any).
766 SourceLocation CommaLoc;
769 Expr *ChunkSize = nullptr;
771 /// Set schedule kind.
773 /// \param K Schedule kind.
774 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
776 /// Set the first schedule modifier.
778 /// \param M Schedule modifier.
779 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
780 Modifiers[FIRST] = M;
783 /// Set the second schedule modifier.
785 /// \param M Schedule modifier.
786 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
787 Modifiers[SECOND] = M;
790 /// Set location of the first schedule modifier.
791 void setFirstScheduleModifierLoc(SourceLocation Loc) {
792 ModifiersLoc[FIRST] = Loc;
795 /// Set location of the second schedule modifier.
796 void setSecondScheduleModifierLoc(SourceLocation Loc) {
797 ModifiersLoc[SECOND] = Loc;
800 /// Set schedule modifier location.
802 /// \param M Schedule modifier location.
803 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
804 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
805 Modifiers[FIRST] = M;
807 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
808 Modifiers[SECOND] = M;
812 /// Sets the location of '('.
814 /// \param Loc Location of '('.
815 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
817 /// Set schedule kind start location.
819 /// \param KLoc Schedule kind location.
820 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
822 /// Set location of ','.
824 /// \param Loc Location of ','.
825 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
829 /// \param E Chunk size.
830 void setChunkSize(Expr *E) { ChunkSize = E; }
833 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
834 /// expression \a ChunkSize.
836 /// \param StartLoc Starting location of the clause.
837 /// \param LParenLoc Location of '('.
838 /// \param KLoc Starting location of the argument.
839 /// \param CommaLoc Location of ','.
840 /// \param EndLoc Ending location of the clause.
841 /// \param Kind Schedule kind.
842 /// \param ChunkSize Chunk size.
843 /// \param HelperChunkSize Helper chunk size for combined directives.
844 /// \param M1 The first modifier applied to 'schedule' clause.
845 /// \param M1Loc Location of the first modifier
846 /// \param M2 The second modifier applied to 'schedule' clause.
847 /// \param M2Loc Location of the second modifier
848 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
849 SourceLocation KLoc, SourceLocation CommaLoc,
850 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
851 Expr *ChunkSize, Stmt *HelperChunkSize,
852 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
853 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
854 : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this),
855 LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc),
856 ChunkSize(ChunkSize) {
857 setPreInitStmt(HelperChunkSize);
858 Modifiers[FIRST] = M1;
859 Modifiers[SECOND] = M2;
860 ModifiersLoc[FIRST] = M1Loc;
861 ModifiersLoc[SECOND] = M2Loc;
864 /// Build an empty clause.
865 explicit OMPScheduleClause()
866 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
867 OMPClauseWithPreInit(this) {
868 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
869 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
872 /// Get kind of the clause.
873 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
875 /// Get the first modifier of the clause.
876 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
877 return Modifiers[FIRST];
880 /// Get the second modifier of the clause.
881 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
882 return Modifiers[SECOND];
885 /// Get location of '('.
886 SourceLocation getLParenLoc() { return LParenLoc; }
888 /// Get kind location.
889 SourceLocation getScheduleKindLoc() { return KindLoc; }
891 /// Get the first modifier location.
892 SourceLocation getFirstScheduleModifierLoc() const {
893 return ModifiersLoc[FIRST];
896 /// Get the second modifier location.
897 SourceLocation getSecondScheduleModifierLoc() const {
898 return ModifiersLoc[SECOND];
901 /// Get location of ','.
902 SourceLocation getCommaLoc() { return CommaLoc; }
905 Expr *getChunkSize() { return ChunkSize; }
908 const Expr *getChunkSize() const { return ChunkSize; }
910 child_range children() {
911 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
912 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
915 static bool classof(const OMPClause *T) {
916 return T->getClauseKind() == OMPC_schedule;
920 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
923 /// #pragma omp for ordered (2)
925 /// In this example directive '#pragma omp for' has 'ordered' clause with
927 class OMPOrderedClause final
929 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
930 friend class OMPClauseReader;
931 friend TrailingObjects;
934 SourceLocation LParenLoc;
936 /// Number of for-loops.
937 Stmt *NumForLoops = nullptr;
939 /// Real number of loops.
940 unsigned NumberOfLoops = 0;
942 /// Build 'ordered' clause.
944 /// \param Num Expression, possibly associated with this clause.
945 /// \param NumLoops Number of loops, associated with this clause.
946 /// \param StartLoc Starting location of the clause.
947 /// \param LParenLoc Location of '('.
948 /// \param EndLoc Ending location of the clause.
949 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
950 SourceLocation LParenLoc, SourceLocation EndLoc)
951 : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
952 NumForLoops(Num), NumberOfLoops(NumLoops) {}
954 /// Build an empty clause.
955 explicit OMPOrderedClause(unsigned NumLoops)
956 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
957 NumberOfLoops(NumLoops) {}
959 /// Set the number of associated for-loops.
960 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
963 /// Build 'ordered' clause.
965 /// \param Num Expression, possibly associated with this clause.
966 /// \param NumLoops Number of loops, associated with this clause.
967 /// \param StartLoc Starting location of the clause.
968 /// \param LParenLoc Location of '('.
969 /// \param EndLoc Ending location of the clause.
970 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
971 unsigned NumLoops, SourceLocation StartLoc,
972 SourceLocation LParenLoc,
973 SourceLocation EndLoc);
975 /// Build an empty clause.
976 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
978 /// Sets the location of '('.
979 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
981 /// Returns the location of '('.
982 SourceLocation getLParenLoc() const { return LParenLoc; }
984 /// Return the number of associated for-loops.
985 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
987 /// Set number of iterations for the specified loop.
988 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
989 /// Get number of iterations for all the loops.
990 ArrayRef<Expr *> getLoopNumIterations() const;
992 /// Set loop counter for the specified loop.
993 void setLoopCounter(unsigned NumLoop, Expr *Counter);
994 /// Get loops counter for the specified loop.
995 Expr *getLoopCunter(unsigned NumLoop);
996 const Expr *getLoopCunter(unsigned NumLoop) const;
998 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1000 static bool classof(const OMPClause *T) {
1001 return T->getClauseKind() == OMPC_ordered;
1005 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1008 /// #pragma omp for nowait
1010 /// In this example directive '#pragma omp for' has 'nowait' clause.
1011 class OMPNowaitClause : public OMPClause {
1013 /// Build 'nowait' clause.
1015 /// \param StartLoc Starting location of the clause.
1016 /// \param EndLoc Ending location of the clause.
1017 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
1018 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
1020 /// Build an empty clause.
1022 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
1024 child_range children() {
1025 return child_range(child_iterator(), child_iterator());
1028 static bool classof(const OMPClause *T) {
1029 return T->getClauseKind() == OMPC_nowait;
1033 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1036 /// #pragma omp task untied
1038 /// In this example directive '#pragma omp task' has 'untied' clause.
1039 class OMPUntiedClause : public OMPClause {
1041 /// Build 'untied' clause.
1043 /// \param StartLoc Starting location of the clause.
1044 /// \param EndLoc Ending location of the clause.
1045 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
1046 : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
1048 /// Build an empty clause.
1050 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
1052 child_range children() {
1053 return child_range(child_iterator(), child_iterator());
1056 static bool classof(const OMPClause *T) {
1057 return T->getClauseKind() == OMPC_untied;
1061 /// This represents 'mergeable' clause in the '#pragma omp ...'
1065 /// #pragma omp task mergeable
1067 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1068 class OMPMergeableClause : public OMPClause {
1070 /// Build 'mergeable' clause.
1072 /// \param StartLoc Starting location of the clause.
1073 /// \param EndLoc Ending location of the clause.
1074 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
1075 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
1077 /// Build an empty clause.
1078 OMPMergeableClause()
1079 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
1081 child_range children() {
1082 return child_range(child_iterator(), child_iterator());
1085 static bool classof(const OMPClause *T) {
1086 return T->getClauseKind() == OMPC_mergeable;
1090 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1093 /// #pragma omp atomic read
1095 /// In this example directive '#pragma omp atomic' has 'read' clause.
1096 class OMPReadClause : public OMPClause {
1098 /// Build 'read' clause.
1100 /// \param StartLoc Starting location of the clause.
1101 /// \param EndLoc Ending location of the clause.
1102 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1103 : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1105 /// Build an empty clause.
1106 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1108 child_range children() {
1109 return child_range(child_iterator(), child_iterator());
1112 static bool classof(const OMPClause *T) {
1113 return T->getClauseKind() == OMPC_read;
1117 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1120 /// #pragma omp atomic write
1122 /// In this example directive '#pragma omp atomic' has 'write' clause.
1123 class OMPWriteClause : public OMPClause {
1125 /// Build 'write' clause.
1127 /// \param StartLoc Starting location of the clause.
1128 /// \param EndLoc Ending location of the clause.
1129 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1130 : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1132 /// Build an empty clause.
1134 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1136 child_range children() {
1137 return child_range(child_iterator(), child_iterator());
1140 static bool classof(const OMPClause *T) {
1141 return T->getClauseKind() == OMPC_write;
1145 /// This represents 'update' clause in the '#pragma omp atomic'
1149 /// #pragma omp atomic update
1151 /// In this example directive '#pragma omp atomic' has 'update' clause.
1152 class OMPUpdateClause : public OMPClause {
1154 /// Build 'update' clause.
1156 /// \param StartLoc Starting location of the clause.
1157 /// \param EndLoc Ending location of the clause.
1158 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
1159 : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1161 /// Build an empty clause.
1163 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1165 child_range children() {
1166 return child_range(child_iterator(), child_iterator());
1169 static bool classof(const OMPClause *T) {
1170 return T->getClauseKind() == OMPC_update;
1174 /// This represents 'capture' clause in the '#pragma omp atomic'
1178 /// #pragma omp atomic capture
1180 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1181 class OMPCaptureClause : public OMPClause {
1183 /// Build 'capture' clause.
1185 /// \param StartLoc Starting location of the clause.
1186 /// \param EndLoc Ending location of the clause.
1187 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1188 : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1190 /// Build an empty clause.
1192 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1194 child_range children() {
1195 return child_range(child_iterator(), child_iterator());
1198 static bool classof(const OMPClause *T) {
1199 return T->getClauseKind() == OMPC_capture;
1203 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
1207 /// #pragma omp atomic seq_cst
1209 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1210 class OMPSeqCstClause : public OMPClause {
1212 /// Build 'seq_cst' clause.
1214 /// \param StartLoc Starting location of the clause.
1215 /// \param EndLoc Ending location of the clause.
1216 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1217 : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1219 /// Build an empty clause.
1221 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1223 child_range children() {
1224 return child_range(child_iterator(), child_iterator());
1227 static bool classof(const OMPClause *T) {
1228 return T->getClauseKind() == OMPC_seq_cst;
1232 /// This represents clause 'private' in the '#pragma omp ...' directives.
1235 /// #pragma omp parallel private(a,b)
1237 /// In this example directive '#pragma omp parallel' has clause 'private'
1238 /// with the variables 'a' and 'b'.
1239 class OMPPrivateClause final
1240 : public OMPVarListClause<OMPPrivateClause>,
1241 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1242 friend class OMPClauseReader;
1243 friend OMPVarListClause;
1244 friend TrailingObjects;
1246 /// Build clause with number of variables \a N.
1248 /// \param StartLoc Starting location of the clause.
1249 /// \param LParenLoc Location of '('.
1250 /// \param EndLoc Ending location of the clause.
1251 /// \param N Number of the variables in the clause.
1252 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1253 SourceLocation EndLoc, unsigned N)
1254 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1257 /// Build an empty clause.
1259 /// \param N Number of variables.
1260 explicit OMPPrivateClause(unsigned N)
1261 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
1262 SourceLocation(), SourceLocation(),
1265 /// Sets the list of references to private copies with initializers for
1266 /// new private variables.
1267 /// \param VL List of references.
1268 void setPrivateCopies(ArrayRef<Expr *> VL);
1270 /// Gets the list of references to private copies with initializers for
1271 /// new private variables.
1272 MutableArrayRef<Expr *> getPrivateCopies() {
1273 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1275 ArrayRef<const Expr *> getPrivateCopies() const {
1276 return llvm::makeArrayRef(varlist_end(), varlist_size());
1280 /// Creates clause with a list of variables \a VL.
1282 /// \param C AST context.
1283 /// \param StartLoc Starting location of the clause.
1284 /// \param LParenLoc Location of '('.
1285 /// \param EndLoc Ending location of the clause.
1286 /// \param VL List of references to the variables.
1287 /// \param PrivateVL List of references to private copies with initializers.
1288 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1289 SourceLocation LParenLoc,
1290 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1291 ArrayRef<Expr *> PrivateVL);
1293 /// Creates an empty clause with the place for \a N variables.
1295 /// \param C AST context.
1296 /// \param N The number of variables.
1297 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1299 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
1300 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
1301 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1302 using private_copies_const_range =
1303 llvm::iterator_range<private_copies_const_iterator>;
1305 private_copies_range private_copies() {
1306 return private_copies_range(getPrivateCopies().begin(),
1307 getPrivateCopies().end());
1310 private_copies_const_range private_copies() const {
1311 return private_copies_const_range(getPrivateCopies().begin(),
1312 getPrivateCopies().end());
1315 child_range children() {
1316 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1317 reinterpret_cast<Stmt **>(varlist_end()));
1320 static bool classof(const OMPClause *T) {
1321 return T->getClauseKind() == OMPC_private;
1325 /// This represents clause 'firstprivate' in the '#pragma omp ...'
1329 /// #pragma omp parallel firstprivate(a,b)
1331 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1332 /// with the variables 'a' and 'b'.
1333 class OMPFirstprivateClause final
1334 : public OMPVarListClause<OMPFirstprivateClause>,
1335 public OMPClauseWithPreInit,
1336 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1337 friend class OMPClauseReader;
1338 friend OMPVarListClause;
1339 friend TrailingObjects;
1341 /// Build clause with number of variables \a N.
1343 /// \param StartLoc Starting location of the clause.
1344 /// \param LParenLoc Location of '('.
1345 /// \param EndLoc Ending location of the clause.
1346 /// \param N Number of the variables in the clause.
1347 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1348 SourceLocation EndLoc, unsigned N)
1349 : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1350 LParenLoc, EndLoc, N),
1351 OMPClauseWithPreInit(this) {}
1353 /// Build an empty clause.
1355 /// \param N Number of variables.
1356 explicit OMPFirstprivateClause(unsigned N)
1357 : OMPVarListClause<OMPFirstprivateClause>(
1358 OMPC_firstprivate, SourceLocation(), SourceLocation(),
1359 SourceLocation(), N),
1360 OMPClauseWithPreInit(this) {}
1362 /// Sets the list of references to private copies with initializers for
1363 /// new private variables.
1364 /// \param VL List of references.
1365 void setPrivateCopies(ArrayRef<Expr *> VL);
1367 /// Gets the list of references to private copies with initializers for
1368 /// new private variables.
1369 MutableArrayRef<Expr *> getPrivateCopies() {
1370 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1372 ArrayRef<const Expr *> getPrivateCopies() const {
1373 return llvm::makeArrayRef(varlist_end(), varlist_size());
1376 /// Sets the list of references to initializer variables for new
1377 /// private variables.
1378 /// \param VL List of references.
1379 void setInits(ArrayRef<Expr *> VL);
1381 /// Gets the list of references to initializer variables for new
1382 /// private variables.
1383 MutableArrayRef<Expr *> getInits() {
1384 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1386 ArrayRef<const Expr *> getInits() const {
1387 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1391 /// Creates clause with a list of variables \a VL.
1393 /// \param C AST context.
1394 /// \param StartLoc Starting location of the clause.
1395 /// \param LParenLoc Location of '('.
1396 /// \param EndLoc Ending location of the clause.
1397 /// \param VL List of references to the original variables.
1398 /// \param PrivateVL List of references to private copies with initializers.
1399 /// \param InitVL List of references to auto generated variables used for
1400 /// initialization of a single array element. Used if firstprivate variable is
1402 /// \param PreInit Statement that must be executed before entering the OpenMP
1403 /// region with this clause.
1404 static OMPFirstprivateClause *
1405 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1406 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1407 ArrayRef<Expr *> InitVL, Stmt *PreInit);
1409 /// Creates an empty clause with the place for \a N variables.
1411 /// \param C AST context.
1412 /// \param N The number of variables.
1413 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1415 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
1416 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
1417 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1418 using private_copies_const_range =
1419 llvm::iterator_range<private_copies_const_iterator>;
1421 private_copies_range private_copies() {
1422 return private_copies_range(getPrivateCopies().begin(),
1423 getPrivateCopies().end());
1425 private_copies_const_range private_copies() const {
1426 return private_copies_const_range(getPrivateCopies().begin(),
1427 getPrivateCopies().end());
1430 using inits_iterator = MutableArrayRef<Expr *>::iterator;
1431 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
1432 using inits_range = llvm::iterator_range<inits_iterator>;
1433 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
1435 inits_range inits() {
1436 return inits_range(getInits().begin(), getInits().end());
1438 inits_const_range inits() const {
1439 return inits_const_range(getInits().begin(), getInits().end());
1442 child_range children() {
1443 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1444 reinterpret_cast<Stmt **>(varlist_end()));
1447 static bool classof(const OMPClause *T) {
1448 return T->getClauseKind() == OMPC_firstprivate;
1452 /// This represents clause 'lastprivate' in the '#pragma omp ...'
1456 /// #pragma omp simd lastprivate(a,b)
1458 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1459 /// with the variables 'a' and 'b'.
1460 class OMPLastprivateClause final
1461 : public OMPVarListClause<OMPLastprivateClause>,
1462 public OMPClauseWithPostUpdate,
1463 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
1464 // There are 4 additional tail-allocated arrays at the end of the class:
1465 // 1. Contains list of pseudo variables with the default initialization for
1466 // each non-firstprivate variables. Used in codegen for initialization of
1467 // lastprivate copies.
1468 // 2. List of helper expressions for proper generation of assignment operation
1469 // required for lastprivate clause. This list represents private variables
1470 // (for arrays, single array element).
1471 // 3. List of helper expressions for proper generation of assignment operation
1472 // required for lastprivate clause. This list represents original variables
1473 // (for arrays, single array element).
1474 // 4. List of helper expressions that represents assignment operation:
1476 // DstExprs = SrcExprs;
1478 // Required for proper codegen of final assignment performed by the
1479 // lastprivate clause.
1480 friend class OMPClauseReader;
1481 friend OMPVarListClause;
1482 friend TrailingObjects;
1484 /// Build clause with number of variables \a N.
1486 /// \param StartLoc Starting location of the clause.
1487 /// \param LParenLoc Location of '('.
1488 /// \param EndLoc Ending location of the clause.
1489 /// \param N Number of the variables in the clause.
1490 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1491 SourceLocation EndLoc, unsigned N)
1492 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1493 LParenLoc, EndLoc, N),
1494 OMPClauseWithPostUpdate(this) {}
1496 /// Build an empty clause.
1498 /// \param N Number of variables.
1499 explicit OMPLastprivateClause(unsigned N)
1500 : OMPVarListClause<OMPLastprivateClause>(
1501 OMPC_lastprivate, SourceLocation(), SourceLocation(),
1502 SourceLocation(), N),
1503 OMPClauseWithPostUpdate(this) {}
1505 /// Get the list of helper expressions for initialization of private
1506 /// copies for lastprivate variables.
1507 MutableArrayRef<Expr *> getPrivateCopies() {
1508 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1510 ArrayRef<const Expr *> getPrivateCopies() const {
1511 return llvm::makeArrayRef(varlist_end(), varlist_size());
1514 /// Set list of helper expressions, required for proper codegen of the
1515 /// clause. These expressions represent private variables (for arrays, single
1516 /// array element) in the final assignment statement performed by the
1517 /// lastprivate clause.
1518 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1520 /// Get the list of helper source expressions.
1521 MutableArrayRef<Expr *> getSourceExprs() {
1522 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1524 ArrayRef<const Expr *> getSourceExprs() const {
1525 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1528 /// Set list of helper expressions, required for proper codegen of the
1529 /// clause. These expressions represent original variables (for arrays, single
1530 /// array element) in the final assignment statement performed by the
1531 /// lastprivate clause.
1532 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1534 /// Get the list of helper destination expressions.
1535 MutableArrayRef<Expr *> getDestinationExprs() {
1536 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1538 ArrayRef<const Expr *> getDestinationExprs() const {
1539 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1542 /// Set list of helper assignment expressions, required for proper
1543 /// codegen of the clause. These expressions are assignment expressions that
1544 /// assign private copy of the variable to original variable.
1545 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1547 /// Get the list of helper assignment expressions.
1548 MutableArrayRef<Expr *> getAssignmentOps() {
1549 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1551 ArrayRef<const Expr *> getAssignmentOps() const {
1552 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1556 /// Creates clause with a list of variables \a VL.
1558 /// \param C AST context.
1559 /// \param StartLoc Starting location of the clause.
1560 /// \param LParenLoc Location of '('.
1561 /// \param EndLoc Ending location of the clause.
1562 /// \param VL List of references to the variables.
1563 /// \param SrcExprs List of helper expressions for proper generation of
1564 /// assignment operation required for lastprivate clause. This list represents
1565 /// private variables (for arrays, single array element).
1566 /// \param DstExprs List of helper expressions for proper generation of
1567 /// assignment operation required for lastprivate clause. This list represents
1568 /// original variables (for arrays, single array element).
1569 /// \param AssignmentOps List of helper expressions that represents assignment
1572 /// DstExprs = SrcExprs;
1574 /// Required for proper codegen of final assignment performed by the
1575 /// lastprivate clause.
1576 /// \param PreInit Statement that must be executed before entering the OpenMP
1577 /// region with this clause.
1578 /// \param PostUpdate Expression that must be executed after exit from the
1579 /// OpenMP region with this clause.
1580 static OMPLastprivateClause *
1581 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1582 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1583 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
1584 Stmt *PreInit, Expr *PostUpdate);
1586 /// Creates an empty clause with the place for \a N variables.
1588 /// \param C AST context.
1589 /// \param N The number of variables.
1590 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1592 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
1593 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
1594 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
1595 using helper_expr_const_range =
1596 llvm::iterator_range<helper_expr_const_iterator>;
1598 /// Set list of helper expressions, required for generation of private
1599 /// copies of original lastprivate variables.
1600 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1602 helper_expr_const_range private_copies() const {
1603 return helper_expr_const_range(getPrivateCopies().begin(),
1604 getPrivateCopies().end());
1607 helper_expr_range private_copies() {
1608 return helper_expr_range(getPrivateCopies().begin(),
1609 getPrivateCopies().end());
1612 helper_expr_const_range source_exprs() const {
1613 return helper_expr_const_range(getSourceExprs().begin(),
1614 getSourceExprs().end());
1617 helper_expr_range source_exprs() {
1618 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1621 helper_expr_const_range destination_exprs() const {
1622 return helper_expr_const_range(getDestinationExprs().begin(),
1623 getDestinationExprs().end());
1626 helper_expr_range destination_exprs() {
1627 return helper_expr_range(getDestinationExprs().begin(),
1628 getDestinationExprs().end());
1631 helper_expr_const_range assignment_ops() const {
1632 return helper_expr_const_range(getAssignmentOps().begin(),
1633 getAssignmentOps().end());
1636 helper_expr_range assignment_ops() {
1637 return helper_expr_range(getAssignmentOps().begin(),
1638 getAssignmentOps().end());
1641 child_range children() {
1642 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1643 reinterpret_cast<Stmt **>(varlist_end()));
1646 static bool classof(const OMPClause *T) {
1647 return T->getClauseKind() == OMPC_lastprivate;
1651 /// This represents clause 'shared' in the '#pragma omp ...' directives.
1654 /// #pragma omp parallel shared(a,b)
1656 /// In this example directive '#pragma omp parallel' has clause 'shared'
1657 /// with the variables 'a' and 'b'.
1658 class OMPSharedClause final
1659 : public OMPVarListClause<OMPSharedClause>,
1660 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
1661 friend OMPVarListClause;
1662 friend TrailingObjects;
1664 /// Build clause with number of variables \a N.
1666 /// \param StartLoc Starting location of the clause.
1667 /// \param LParenLoc Location of '('.
1668 /// \param EndLoc Ending location of the clause.
1669 /// \param N Number of the variables in the clause.
1670 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1671 SourceLocation EndLoc, unsigned N)
1672 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1675 /// Build an empty clause.
1677 /// \param N Number of variables.
1678 explicit OMPSharedClause(unsigned N)
1679 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1680 SourceLocation(), SourceLocation(),
1684 /// Creates clause with a list of variables \a VL.
1686 /// \param C AST context.
1687 /// \param StartLoc Starting location of the clause.
1688 /// \param LParenLoc Location of '('.
1689 /// \param EndLoc Ending location of the clause.
1690 /// \param VL List of references to the variables.
1691 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1692 SourceLocation LParenLoc,
1693 SourceLocation EndLoc, ArrayRef<Expr *> VL);
1695 /// Creates an empty clause with \a N variables.
1697 /// \param C AST context.
1698 /// \param N The number of variables.
1699 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1701 child_range children() {
1702 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1703 reinterpret_cast<Stmt **>(varlist_end()));
1706 static bool classof(const OMPClause *T) {
1707 return T->getClauseKind() == OMPC_shared;
1711 /// This represents clause 'reduction' in the '#pragma omp ...'
1715 /// #pragma omp parallel reduction(+:a,b)
1717 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1718 /// with operator '+' and the variables 'a' and 'b'.
1719 class OMPReductionClause final
1720 : public OMPVarListClause<OMPReductionClause>,
1721 public OMPClauseWithPostUpdate,
1722 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
1723 friend class OMPClauseReader;
1724 friend OMPVarListClause;
1725 friend TrailingObjects;
1727 /// Location of ':'.
1728 SourceLocation ColonLoc;
1730 /// Nested name specifier for C++.
1731 NestedNameSpecifierLoc QualifierLoc;
1733 /// Name of custom operator.
1734 DeclarationNameInfo NameInfo;
1736 /// Build clause with number of variables \a N.
1738 /// \param StartLoc Starting location of the clause.
1739 /// \param LParenLoc Location of '('.
1740 /// \param EndLoc Ending location of the clause.
1741 /// \param ColonLoc Location of ':'.
1742 /// \param N Number of the variables in the clause.
1743 /// \param QualifierLoc The nested-name qualifier with location information
1744 /// \param NameInfo The full name info for reduction identifier.
1745 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1746 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1747 NestedNameSpecifierLoc QualifierLoc,
1748 const DeclarationNameInfo &NameInfo)
1749 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1750 LParenLoc, EndLoc, N),
1751 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
1752 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1754 /// Build an empty clause.
1756 /// \param N Number of variables.
1757 explicit OMPReductionClause(unsigned N)
1758 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1759 SourceLocation(), SourceLocation(),
1761 OMPClauseWithPostUpdate(this) {}
1763 /// Sets location of ':' symbol in clause.
1764 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1766 /// Sets the name info for specified reduction identifier.
1767 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1769 /// Sets the nested name specifier.
1770 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1772 /// Set list of helper expressions, required for proper codegen of the
1773 /// clause. These expressions represent private copy of the reduction
1775 void setPrivates(ArrayRef<Expr *> Privates);
1777 /// Get the list of helper privates.
1778 MutableArrayRef<Expr *> getPrivates() {
1779 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1781 ArrayRef<const Expr *> getPrivates() const {
1782 return llvm::makeArrayRef(varlist_end(), varlist_size());
1785 /// Set list of helper expressions, required for proper codegen of the
1786 /// clause. These expressions represent LHS expression in the final
1787 /// reduction expression performed by the reduction clause.
1788 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1790 /// Get the list of helper LHS expressions.
1791 MutableArrayRef<Expr *> getLHSExprs() {
1792 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1794 ArrayRef<const Expr *> getLHSExprs() const {
1795 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1798 /// Set list of helper expressions, required for proper codegen of the
1799 /// clause. These expressions represent RHS expression in the final
1800 /// reduction expression performed by the reduction clause.
1801 /// Also, variables in these expressions are used for proper initialization of
1802 /// reduction copies.
1803 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1805 /// Get the list of helper destination expressions.
1806 MutableArrayRef<Expr *> getRHSExprs() {
1807 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1809 ArrayRef<const Expr *> getRHSExprs() const {
1810 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1813 /// Set list of helper reduction expressions, required for proper
1814 /// codegen of the clause. These expressions are binary expressions or
1815 /// operator/custom reduction call that calculates new value from source
1816 /// helper expressions to destination helper expressions.
1817 void setReductionOps(ArrayRef<Expr *> ReductionOps);
1819 /// Get the list of helper reduction expressions.
1820 MutableArrayRef<Expr *> getReductionOps() {
1821 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1823 ArrayRef<const Expr *> getReductionOps() const {
1824 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1828 /// Creates clause with a list of variables \a VL.
1830 /// \param StartLoc Starting location of the clause.
1831 /// \param LParenLoc Location of '('.
1832 /// \param ColonLoc Location of ':'.
1833 /// \param EndLoc Ending location of the clause.
1834 /// \param VL The variables in the clause.
1835 /// \param QualifierLoc The nested-name qualifier with location information
1836 /// \param NameInfo The full name info for reduction identifier.
1837 /// \param Privates List of helper expressions for proper generation of
1839 /// \param LHSExprs List of helper expressions for proper generation of
1840 /// assignment operation required for copyprivate clause. This list represents
1841 /// LHSs of the reduction expressions.
1842 /// \param RHSExprs List of helper expressions for proper generation of
1843 /// assignment operation required for copyprivate clause. This list represents
1844 /// RHSs of the reduction expressions.
1845 /// Also, variables in these expressions are used for proper initialization of
1846 /// reduction copies.
1847 /// \param ReductionOps List of helper expressions that represents reduction
1850 /// LHSExprs binop RHSExprs;
1851 /// operator binop(LHSExpr, RHSExpr);
1852 /// <CutomReduction>(LHSExpr, RHSExpr);
1854 /// Required for proper codegen of final reduction operation performed by the
1855 /// reduction clause.
1856 /// \param PreInit Statement that must be executed before entering the OpenMP
1857 /// region with this clause.
1858 /// \param PostUpdate Expression that must be executed after exit from the
1859 /// OpenMP region with this clause.
1860 static OMPReductionClause *
1861 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1862 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1863 NestedNameSpecifierLoc QualifierLoc,
1864 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
1865 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1866 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
1868 /// Creates an empty clause with the place for \a N variables.
1870 /// \param C AST context.
1871 /// \param N The number of variables.
1872 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1874 /// Gets location of ':' symbol in clause.
1875 SourceLocation getColonLoc() const { return ColonLoc; }
1877 /// Gets the name info for specified reduction identifier.
1878 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1880 /// Gets the nested name specifier.
1881 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1883 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
1884 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
1885 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
1886 using helper_expr_const_range =
1887 llvm::iterator_range<helper_expr_const_iterator>;
1889 helper_expr_const_range privates() const {
1890 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
1893 helper_expr_range privates() {
1894 return helper_expr_range(getPrivates().begin(), getPrivates().end());
1897 helper_expr_const_range lhs_exprs() const {
1898 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
1901 helper_expr_range lhs_exprs() {
1902 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
1905 helper_expr_const_range rhs_exprs() const {
1906 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
1909 helper_expr_range rhs_exprs() {
1910 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
1913 helper_expr_const_range reduction_ops() const {
1914 return helper_expr_const_range(getReductionOps().begin(),
1915 getReductionOps().end());
1918 helper_expr_range reduction_ops() {
1919 return helper_expr_range(getReductionOps().begin(),
1920 getReductionOps().end());
1923 child_range children() {
1924 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1925 reinterpret_cast<Stmt **>(varlist_end()));
1928 static bool classof(const OMPClause *T) {
1929 return T->getClauseKind() == OMPC_reduction;
1933 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
1937 /// #pragma omp taskgroup task_reduction(+:a,b)
1939 /// In this example directive '#pragma omp taskgroup' has clause
1940 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
1941 class OMPTaskReductionClause final
1942 : public OMPVarListClause<OMPTaskReductionClause>,
1943 public OMPClauseWithPostUpdate,
1944 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
1945 friend class OMPClauseReader;
1946 friend OMPVarListClause;
1947 friend TrailingObjects;
1949 /// Location of ':'.
1950 SourceLocation ColonLoc;
1952 /// Nested name specifier for C++.
1953 NestedNameSpecifierLoc QualifierLoc;
1955 /// Name of custom operator.
1956 DeclarationNameInfo NameInfo;
1958 /// Build clause with number of variables \a N.
1960 /// \param StartLoc Starting location of the clause.
1961 /// \param LParenLoc Location of '('.
1962 /// \param EndLoc Ending location of the clause.
1963 /// \param ColonLoc Location of ':'.
1964 /// \param N Number of the variables in the clause.
1965 /// \param QualifierLoc The nested-name qualifier with location information
1966 /// \param NameInfo The full name info for reduction identifier.
1967 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1968 SourceLocation ColonLoc, SourceLocation EndLoc,
1969 unsigned N, NestedNameSpecifierLoc QualifierLoc,
1970 const DeclarationNameInfo &NameInfo)
1971 : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
1972 LParenLoc, EndLoc, N),
1973 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
1974 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1976 /// Build an empty clause.
1978 /// \param N Number of variables.
1979 explicit OMPTaskReductionClause(unsigned N)
1980 : OMPVarListClause<OMPTaskReductionClause>(
1981 OMPC_task_reduction, SourceLocation(), SourceLocation(),
1982 SourceLocation(), N),
1983 OMPClauseWithPostUpdate(this) {}
1985 /// Sets location of ':' symbol in clause.
1986 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1988 /// Sets the name info for specified reduction identifier.
1989 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1991 /// Sets the nested name specifier.
1992 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1994 /// Set list of helper expressions, required for proper codegen of the clause.
1995 /// These expressions represent private copy of the reduction variable.
1996 void setPrivates(ArrayRef<Expr *> Privates);
1998 /// Get the list of helper privates.
1999 MutableArrayRef<Expr *> getPrivates() {
2000 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2002 ArrayRef<const Expr *> getPrivates() const {
2003 return llvm::makeArrayRef(varlist_end(), varlist_size());
2006 /// Set list of helper expressions, required for proper codegen of the clause.
2007 /// These expressions represent LHS expression in the final reduction
2008 /// expression performed by the reduction clause.
2009 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2011 /// Get the list of helper LHS expressions.
2012 MutableArrayRef<Expr *> getLHSExprs() {
2013 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2015 ArrayRef<const Expr *> getLHSExprs() const {
2016 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2019 /// Set list of helper expressions, required for proper codegen of the clause.
2020 /// These expressions represent RHS expression in the final reduction
2021 /// expression performed by the reduction clause. Also, variables in these
2022 /// expressions are used for proper initialization of reduction copies.
2023 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2025 /// Get the list of helper destination expressions.
2026 MutableArrayRef<Expr *> getRHSExprs() {
2027 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2029 ArrayRef<const Expr *> getRHSExprs() const {
2030 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2033 /// Set list of helper reduction expressions, required for proper
2034 /// codegen of the clause. These expressions are binary expressions or
2035 /// operator/custom reduction call that calculates new value from source
2036 /// helper expressions to destination helper expressions.
2037 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2039 /// Get the list of helper reduction expressions.
2040 MutableArrayRef<Expr *> getReductionOps() {
2041 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2043 ArrayRef<const Expr *> getReductionOps() const {
2044 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2048 /// Creates clause with a list of variables \a VL.
2050 /// \param StartLoc Starting location of the clause.
2051 /// \param LParenLoc Location of '('.
2052 /// \param ColonLoc Location of ':'.
2053 /// \param EndLoc Ending location of the clause.
2054 /// \param VL The variables in the clause.
2055 /// \param QualifierLoc The nested-name qualifier with location information
2056 /// \param NameInfo The full name info for reduction identifier.
2057 /// \param Privates List of helper expressions for proper generation of
2059 /// \param LHSExprs List of helper expressions for proper generation of
2060 /// assignment operation required for copyprivate clause. This list represents
2061 /// LHSs of the reduction expressions.
2062 /// \param RHSExprs List of helper expressions for proper generation of
2063 /// assignment operation required for copyprivate clause. This list represents
2064 /// RHSs of the reduction expressions.
2065 /// Also, variables in these expressions are used for proper initialization of
2066 /// reduction copies.
2067 /// \param ReductionOps List of helper expressions that represents reduction
2070 /// LHSExprs binop RHSExprs;
2071 /// operator binop(LHSExpr, RHSExpr);
2072 /// <CutomReduction>(LHSExpr, RHSExpr);
2074 /// Required for proper codegen of final reduction operation performed by the
2075 /// reduction clause.
2076 /// \param PreInit Statement that must be executed before entering the OpenMP
2077 /// region with this clause.
2078 /// \param PostUpdate Expression that must be executed after exit from the
2079 /// OpenMP region with this clause.
2080 static OMPTaskReductionClause *
2081 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2082 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2083 NestedNameSpecifierLoc QualifierLoc,
2084 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2085 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2086 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2088 /// Creates an empty clause with the place for \a N variables.
2090 /// \param C AST context.
2091 /// \param N The number of variables.
2092 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2094 /// Gets location of ':' symbol in clause.
2095 SourceLocation getColonLoc() const { return ColonLoc; }
2097 /// Gets the name info for specified reduction identifier.
2098 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2100 /// Gets the nested name specifier.
2101 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2103 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2104 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2105 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2106 using helper_expr_const_range =
2107 llvm::iterator_range<helper_expr_const_iterator>;
2109 helper_expr_const_range privates() const {
2110 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2113 helper_expr_range privates() {
2114 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2117 helper_expr_const_range lhs_exprs() const {
2118 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2121 helper_expr_range lhs_exprs() {
2122 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2125 helper_expr_const_range rhs_exprs() const {
2126 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2129 helper_expr_range rhs_exprs() {
2130 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2133 helper_expr_const_range reduction_ops() const {
2134 return helper_expr_const_range(getReductionOps().begin(),
2135 getReductionOps().end());
2138 helper_expr_range reduction_ops() {
2139 return helper_expr_range(getReductionOps().begin(),
2140 getReductionOps().end());
2143 child_range children() {
2144 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2145 reinterpret_cast<Stmt **>(varlist_end()));
2148 static bool classof(const OMPClause *T) {
2149 return T->getClauseKind() == OMPC_task_reduction;
2153 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
2156 /// #pragma omp task in_reduction(+:a,b)
2158 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
2159 /// operator '+' and the variables 'a' and 'b'.
2160 class OMPInReductionClause final
2161 : public OMPVarListClause<OMPInReductionClause>,
2162 public OMPClauseWithPostUpdate,
2163 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
2164 friend class OMPClauseReader;
2165 friend OMPVarListClause;
2166 friend TrailingObjects;
2168 /// Location of ':'.
2169 SourceLocation ColonLoc;
2171 /// Nested name specifier for C++.
2172 NestedNameSpecifierLoc QualifierLoc;
2174 /// Name of custom operator.
2175 DeclarationNameInfo NameInfo;
2177 /// Build clause with number of variables \a N.
2179 /// \param StartLoc Starting location of the clause.
2180 /// \param LParenLoc Location of '('.
2181 /// \param EndLoc Ending location of the clause.
2182 /// \param ColonLoc Location of ':'.
2183 /// \param N Number of the variables in the clause.
2184 /// \param QualifierLoc The nested-name qualifier with location information
2185 /// \param NameInfo The full name info for reduction identifier.
2186 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2187 SourceLocation ColonLoc, SourceLocation EndLoc,
2188 unsigned N, NestedNameSpecifierLoc QualifierLoc,
2189 const DeclarationNameInfo &NameInfo)
2190 : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc,
2191 LParenLoc, EndLoc, N),
2192 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2193 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2195 /// Build an empty clause.
2197 /// \param N Number of variables.
2198 explicit OMPInReductionClause(unsigned N)
2199 : OMPVarListClause<OMPInReductionClause>(
2200 OMPC_in_reduction, SourceLocation(), SourceLocation(),
2201 SourceLocation(), N),
2202 OMPClauseWithPostUpdate(this) {}
2204 /// Sets location of ':' symbol in clause.
2205 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2207 /// Sets the name info for specified reduction identifier.
2208 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2210 /// Sets the nested name specifier.
2211 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2213 /// Set list of helper expressions, required for proper codegen of the clause.
2214 /// These expressions represent private copy of the reduction variable.
2215 void setPrivates(ArrayRef<Expr *> Privates);
2217 /// Get the list of helper privates.
2218 MutableArrayRef<Expr *> getPrivates() {
2219 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2221 ArrayRef<const Expr *> getPrivates() const {
2222 return llvm::makeArrayRef(varlist_end(), varlist_size());
2225 /// Set list of helper expressions, required for proper codegen of the clause.
2226 /// These expressions represent LHS expression in the final reduction
2227 /// expression performed by the reduction clause.
2228 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2230 /// Get the list of helper LHS expressions.
2231 MutableArrayRef<Expr *> getLHSExprs() {
2232 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2234 ArrayRef<const Expr *> getLHSExprs() const {
2235 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2238 /// Set list of helper expressions, required for proper codegen of the clause.
2239 /// These expressions represent RHS expression in the final reduction
2240 /// expression performed by the reduction clause. Also, variables in these
2241 /// expressions are used for proper initialization of reduction copies.
2242 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2244 /// Get the list of helper destination expressions.
2245 MutableArrayRef<Expr *> getRHSExprs() {
2246 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2248 ArrayRef<const Expr *> getRHSExprs() const {
2249 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2252 /// Set list of helper reduction expressions, required for proper
2253 /// codegen of the clause. These expressions are binary expressions or
2254 /// operator/custom reduction call that calculates new value from source
2255 /// helper expressions to destination helper expressions.
2256 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2258 /// Get the list of helper reduction expressions.
2259 MutableArrayRef<Expr *> getReductionOps() {
2260 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2262 ArrayRef<const Expr *> getReductionOps() const {
2263 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2266 /// Set list of helper reduction taskgroup descriptors.
2267 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
2269 /// Get the list of helper reduction taskgroup descriptors.
2270 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
2271 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
2273 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
2274 return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
2278 /// Creates clause with a list of variables \a VL.
2280 /// \param StartLoc Starting location of the clause.
2281 /// \param LParenLoc Location of '('.
2282 /// \param ColonLoc Location of ':'.
2283 /// \param EndLoc Ending location of the clause.
2284 /// \param VL The variables in the clause.
2285 /// \param QualifierLoc The nested-name qualifier with location information
2286 /// \param NameInfo The full name info for reduction identifier.
2287 /// \param Privates List of helper expressions for proper generation of
2289 /// \param LHSExprs List of helper expressions for proper generation of
2290 /// assignment operation required for copyprivate clause. This list represents
2291 /// LHSs of the reduction expressions.
2292 /// \param RHSExprs List of helper expressions for proper generation of
2293 /// assignment operation required for copyprivate clause. This list represents
2294 /// RHSs of the reduction expressions.
2295 /// Also, variables in these expressions are used for proper initialization of
2296 /// reduction copies.
2297 /// \param ReductionOps List of helper expressions that represents reduction
2300 /// LHSExprs binop RHSExprs;
2301 /// operator binop(LHSExpr, RHSExpr);
2302 /// <CutomReduction>(LHSExpr, RHSExpr);
2304 /// Required for proper codegen of final reduction operation performed by the
2305 /// reduction clause.
2306 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
2307 /// corresponding items in parent taskgroup task_reduction clause.
2308 /// \param PreInit Statement that must be executed before entering the OpenMP
2309 /// region with this clause.
2310 /// \param PostUpdate Expression that must be executed after exit from the
2311 /// OpenMP region with this clause.
2312 static OMPInReductionClause *
2313 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2314 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2315 NestedNameSpecifierLoc QualifierLoc,
2316 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2317 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2318 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
2319 Stmt *PreInit, Expr *PostUpdate);
2321 /// Creates an empty clause with the place for \a N variables.
2323 /// \param C AST context.
2324 /// \param N The number of variables.
2325 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2327 /// Gets location of ':' symbol in clause.
2328 SourceLocation getColonLoc() const { return ColonLoc; }
2330 /// Gets the name info for specified reduction identifier.
2331 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2333 /// Gets the nested name specifier.
2334 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2336 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2337 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2338 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2339 using helper_expr_const_range =
2340 llvm::iterator_range<helper_expr_const_iterator>;
2342 helper_expr_const_range privates() const {
2343 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2346 helper_expr_range privates() {
2347 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2350 helper_expr_const_range lhs_exprs() const {
2351 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2354 helper_expr_range lhs_exprs() {
2355 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2358 helper_expr_const_range rhs_exprs() const {
2359 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2362 helper_expr_range rhs_exprs() {
2363 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2366 helper_expr_const_range reduction_ops() const {
2367 return helper_expr_const_range(getReductionOps().begin(),
2368 getReductionOps().end());
2371 helper_expr_range reduction_ops() {
2372 return helper_expr_range(getReductionOps().begin(),
2373 getReductionOps().end());
2376 helper_expr_const_range taskgroup_descriptors() const {
2377 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
2378 getTaskgroupDescriptors().end());
2381 helper_expr_range taskgroup_descriptors() {
2382 return helper_expr_range(getTaskgroupDescriptors().begin(),
2383 getTaskgroupDescriptors().end());
2386 child_range children() {
2387 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2388 reinterpret_cast<Stmt **>(varlist_end()));
2391 static bool classof(const OMPClause *T) {
2392 return T->getClauseKind() == OMPC_in_reduction;
2396 /// This represents clause 'linear' in the '#pragma omp ...'
2400 /// #pragma omp simd linear(a,b : 2)
2402 /// In this example directive '#pragma omp simd' has clause 'linear'
2403 /// with variables 'a', 'b' and linear step '2'.
2404 class OMPLinearClause final
2405 : public OMPVarListClause<OMPLinearClause>,
2406 public OMPClauseWithPostUpdate,
2407 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
2408 friend class OMPClauseReader;
2409 friend OMPVarListClause;
2410 friend TrailingObjects;
2412 /// Modifier of 'linear' clause.
2413 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
2415 /// Location of linear modifier if any.
2416 SourceLocation ModifierLoc;
2418 /// Location of ':'.
2419 SourceLocation ColonLoc;
2421 /// Sets the linear step for clause.
2422 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
2424 /// Sets the expression to calculate linear step for clause.
2425 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
2427 /// Build 'linear' clause with given number of variables \a NumVars.
2429 /// \param StartLoc Starting location of the clause.
2430 /// \param LParenLoc Location of '('.
2431 /// \param ColonLoc Location of ':'.
2432 /// \param EndLoc Ending location of the clause.
2433 /// \param NumVars Number of variables.
2434 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2435 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2436 SourceLocation ColonLoc, SourceLocation EndLoc,
2438 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
2440 OMPClauseWithPostUpdate(this), Modifier(Modifier),
2441 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
2443 /// Build an empty clause.
2445 /// \param NumVars Number of variables.
2446 explicit OMPLinearClause(unsigned NumVars)
2447 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
2448 SourceLocation(), SourceLocation(),
2450 OMPClauseWithPostUpdate(this) {}
2452 /// Gets the list of initial values for linear variables.
2454 /// There are NumVars expressions with initial values allocated after the
2455 /// varlist, they are followed by NumVars update expressions (used to update
2456 /// the linear variable's value on current iteration) and they are followed by
2457 /// NumVars final expressions (used to calculate the linear variable's
2458 /// value after the loop body). After these lists, there are 2 helper
2459 /// expressions - linear step and a helper to calculate it before the
2460 /// loop body (used when the linear step is not constant):
2462 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
2463 /// Finals[]; Step; CalcStep; }
2464 MutableArrayRef<Expr *> getPrivates() {
2465 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2467 ArrayRef<const Expr *> getPrivates() const {
2468 return llvm::makeArrayRef(varlist_end(), varlist_size());
2471 MutableArrayRef<Expr *> getInits() {
2472 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2474 ArrayRef<const Expr *> getInits() const {
2475 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2478 /// Sets the list of update expressions for linear variables.
2479 MutableArrayRef<Expr *> getUpdates() {
2480 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
2482 ArrayRef<const Expr *> getUpdates() const {
2483 return llvm::makeArrayRef(getInits().end(), varlist_size());
2486 /// Sets the list of final update expressions for linear variables.
2487 MutableArrayRef<Expr *> getFinals() {
2488 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
2490 ArrayRef<const Expr *> getFinals() const {
2491 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
2494 /// Sets the list of the copies of original linear variables.
2495 /// \param PL List of expressions.
2496 void setPrivates(ArrayRef<Expr *> PL);
2498 /// Sets the list of the initial values for linear variables.
2499 /// \param IL List of expressions.
2500 void setInits(ArrayRef<Expr *> IL);
2503 /// Creates clause with a list of variables \a VL and a linear step
2506 /// \param C AST Context.
2507 /// \param StartLoc Starting location of the clause.
2508 /// \param LParenLoc Location of '('.
2509 /// \param Modifier Modifier of 'linear' clause.
2510 /// \param ModifierLoc Modifier location.
2511 /// \param ColonLoc Location of ':'.
2512 /// \param EndLoc Ending location of the clause.
2513 /// \param VL List of references to the variables.
2514 /// \param PL List of private copies of original variables.
2515 /// \param IL List of initial values for the variables.
2516 /// \param Step Linear step.
2517 /// \param CalcStep Calculation of the linear step.
2518 /// \param PreInit Statement that must be executed before entering the OpenMP
2519 /// region with this clause.
2520 /// \param PostUpdate Expression that must be executed after exit from the
2521 /// OpenMP region with this clause.
2522 static OMPLinearClause *
2523 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2524 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2525 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2526 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
2527 Stmt *PreInit, Expr *PostUpdate);
2529 /// Creates an empty clause with the place for \a NumVars variables.
2531 /// \param C AST context.
2532 /// \param NumVars Number of variables.
2533 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2536 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
2538 /// Return modifier.
2539 OpenMPLinearClauseKind getModifier() const { return Modifier; }
2541 /// Set modifier location.
2542 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
2544 /// Return modifier location.
2545 SourceLocation getModifierLoc() const { return ModifierLoc; }
2547 /// Sets the location of ':'.
2548 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2550 /// Returns the location of ':'.
2551 SourceLocation getColonLoc() const { return ColonLoc; }
2553 /// Returns linear step.
2554 Expr *getStep() { return *(getFinals().end()); }
2556 /// Returns linear step.
2557 const Expr *getStep() const { return *(getFinals().end()); }
2559 /// Returns expression to calculate linear step.
2560 Expr *getCalcStep() { return *(getFinals().end() + 1); }
2562 /// Returns expression to calculate linear step.
2563 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
2565 /// Sets the list of update expressions for linear variables.
2566 /// \param UL List of expressions.
2567 void setUpdates(ArrayRef<Expr *> UL);
2569 /// Sets the list of final update expressions for linear variables.
2570 /// \param FL List of expressions.
2571 void setFinals(ArrayRef<Expr *> FL);
2573 using privates_iterator = MutableArrayRef<Expr *>::iterator;
2574 using privates_const_iterator = ArrayRef<const Expr *>::iterator;
2575 using privates_range = llvm::iterator_range<privates_iterator>;
2576 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
2578 privates_range privates() {
2579 return privates_range(getPrivates().begin(), getPrivates().end());
2582 privates_const_range privates() const {
2583 return privates_const_range(getPrivates().begin(), getPrivates().end());
2586 using inits_iterator = MutableArrayRef<Expr *>::iterator;
2587 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
2588 using inits_range = llvm::iterator_range<inits_iterator>;
2589 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2591 inits_range inits() {
2592 return inits_range(getInits().begin(), getInits().end());
2595 inits_const_range inits() const {
2596 return inits_const_range(getInits().begin(), getInits().end());
2599 using updates_iterator = MutableArrayRef<Expr *>::iterator;
2600 using updates_const_iterator = ArrayRef<const Expr *>::iterator;
2601 using updates_range = llvm::iterator_range<updates_iterator>;
2602 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
2604 updates_range updates() {
2605 return updates_range(getUpdates().begin(), getUpdates().end());
2608 updates_const_range updates() const {
2609 return updates_const_range(getUpdates().begin(), getUpdates().end());
2612 using finals_iterator = MutableArrayRef<Expr *>::iterator;
2613 using finals_const_iterator = ArrayRef<const Expr *>::iterator;
2614 using finals_range = llvm::iterator_range<finals_iterator>;
2615 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
2617 finals_range finals() {
2618 return finals_range(getFinals().begin(), getFinals().end());
2621 finals_const_range finals() const {
2622 return finals_const_range(getFinals().begin(), getFinals().end());
2625 child_range children() {
2626 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2627 reinterpret_cast<Stmt **>(varlist_end()));
2630 static bool classof(const OMPClause *T) {
2631 return T->getClauseKind() == OMPC_linear;
2635 /// This represents clause 'aligned' in the '#pragma omp ...'
2639 /// #pragma omp simd aligned(a,b : 8)
2641 /// In this example directive '#pragma omp simd' has clause 'aligned'
2642 /// with variables 'a', 'b' and alignment '8'.
2643 class OMPAlignedClause final
2644 : public OMPVarListClause<OMPAlignedClause>,
2645 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
2646 friend class OMPClauseReader;
2647 friend OMPVarListClause;
2648 friend TrailingObjects;
2650 /// Location of ':'.
2651 SourceLocation ColonLoc;
2653 /// Sets the alignment for clause.
2654 void setAlignment(Expr *A) { *varlist_end() = A; }
2656 /// Build 'aligned' clause with given number of variables \a NumVars.
2658 /// \param StartLoc Starting location of the clause.
2659 /// \param LParenLoc Location of '('.
2660 /// \param ColonLoc Location of ':'.
2661 /// \param EndLoc Ending location of the clause.
2662 /// \param NumVars Number of variables.
2663 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2664 SourceLocation ColonLoc, SourceLocation EndLoc,
2666 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
2668 ColonLoc(ColonLoc) {}
2670 /// Build an empty clause.
2672 /// \param NumVars Number of variables.
2673 explicit OMPAlignedClause(unsigned NumVars)
2674 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
2675 SourceLocation(), SourceLocation(),
2679 /// Creates clause with a list of variables \a VL and alignment \a A.
2681 /// \param C AST Context.
2682 /// \param StartLoc Starting location of the clause.
2683 /// \param LParenLoc Location of '('.
2684 /// \param ColonLoc Location of ':'.
2685 /// \param EndLoc Ending location of the clause.
2686 /// \param VL List of references to the variables.
2687 /// \param A Alignment.
2688 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2689 SourceLocation LParenLoc,
2690 SourceLocation ColonLoc,
2691 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2694 /// Creates an empty clause with the place for \a NumVars variables.
2696 /// \param C AST context.
2697 /// \param NumVars Number of variables.
2698 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2700 /// Sets the location of ':'.
2701 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2703 /// Returns the location of ':'.
2704 SourceLocation getColonLoc() const { return ColonLoc; }
2706 /// Returns alignment.
2707 Expr *getAlignment() { return *varlist_end(); }
2709 /// Returns alignment.
2710 const Expr *getAlignment() const { return *varlist_end(); }
2712 child_range children() {
2713 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2714 reinterpret_cast<Stmt **>(varlist_end()));
2717 static bool classof(const OMPClause *T) {
2718 return T->getClauseKind() == OMPC_aligned;
2722 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
2725 /// #pragma omp parallel copyin(a,b)
2727 /// In this example directive '#pragma omp parallel' has clause 'copyin'
2728 /// with the variables 'a' and 'b'.
2729 class OMPCopyinClause final
2730 : public OMPVarListClause<OMPCopyinClause>,
2731 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
2732 // Class has 3 additional tail allocated arrays:
2733 // 1. List of helper expressions for proper generation of assignment operation
2734 // required for copyin clause. This list represents sources.
2735 // 2. List of helper expressions for proper generation of assignment operation
2736 // required for copyin clause. This list represents destinations.
2737 // 3. List of helper expressions that represents assignment operation:
2739 // DstExprs = SrcExprs;
2741 // Required for proper codegen of propagation of master's thread values of
2742 // threadprivate variables to local instances of that variables in other
2743 // implicit threads.
2745 friend class OMPClauseReader;
2746 friend OMPVarListClause;
2747 friend TrailingObjects;
2749 /// Build clause with number of variables \a N.
2751 /// \param StartLoc Starting location of the clause.
2752 /// \param LParenLoc Location of '('.
2753 /// \param EndLoc Ending location of the clause.
2754 /// \param N Number of the variables in the clause.
2755 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2756 SourceLocation EndLoc, unsigned N)
2757 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
2760 /// Build an empty clause.
2762 /// \param N Number of variables.
2763 explicit OMPCopyinClause(unsigned N)
2764 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
2765 SourceLocation(), SourceLocation(),
2768 /// Set list of helper expressions, required for proper codegen of the
2769 /// clause. These expressions represent source expression in the final
2770 /// assignment statement performed by the copyin clause.
2771 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2773 /// Get the list of helper source expressions.
2774 MutableArrayRef<Expr *> getSourceExprs() {
2775 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2777 ArrayRef<const Expr *> getSourceExprs() const {
2778 return llvm::makeArrayRef(varlist_end(), varlist_size());
2781 /// Set list of helper expressions, required for proper codegen of the
2782 /// clause. These expressions represent destination expression in the final
2783 /// assignment statement performed by the copyin clause.
2784 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2786 /// Get the list of helper destination expressions.
2787 MutableArrayRef<Expr *> getDestinationExprs() {
2788 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2790 ArrayRef<const Expr *> getDestinationExprs() const {
2791 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2794 /// Set list of helper assignment expressions, required for proper
2795 /// codegen of the clause. These expressions are assignment expressions that
2796 /// assign source helper expressions to destination helper expressions
2797 /// correspondingly.
2798 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2800 /// Get the list of helper assignment expressions.
2801 MutableArrayRef<Expr *> getAssignmentOps() {
2802 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2804 ArrayRef<const Expr *> getAssignmentOps() const {
2805 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2809 /// Creates clause with a list of variables \a VL.
2811 /// \param C AST context.
2812 /// \param StartLoc Starting location of the clause.
2813 /// \param LParenLoc Location of '('.
2814 /// \param EndLoc Ending location of the clause.
2815 /// \param VL List of references to the variables.
2816 /// \param SrcExprs List of helper expressions for proper generation of
2817 /// assignment operation required for copyin clause. This list represents
2819 /// \param DstExprs List of helper expressions for proper generation of
2820 /// assignment operation required for copyin clause. This list represents
2822 /// \param AssignmentOps List of helper expressions that represents assignment
2825 /// DstExprs = SrcExprs;
2827 /// Required for proper codegen of propagation of master's thread values of
2828 /// threadprivate variables to local instances of that variables in other
2829 /// implicit threads.
2830 static OMPCopyinClause *
2831 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2832 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2833 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2835 /// Creates an empty clause with \a N variables.
2837 /// \param C AST context.
2838 /// \param N The number of variables.
2839 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
2841 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2842 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2843 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2844 using helper_expr_const_range =
2845 llvm::iterator_range<helper_expr_const_iterator>;
2847 helper_expr_const_range source_exprs() const {
2848 return helper_expr_const_range(getSourceExprs().begin(),
2849 getSourceExprs().end());
2852 helper_expr_range source_exprs() {
2853 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2856 helper_expr_const_range destination_exprs() const {
2857 return helper_expr_const_range(getDestinationExprs().begin(),
2858 getDestinationExprs().end());
2861 helper_expr_range destination_exprs() {
2862 return helper_expr_range(getDestinationExprs().begin(),
2863 getDestinationExprs().end());
2866 helper_expr_const_range assignment_ops() const {
2867 return helper_expr_const_range(getAssignmentOps().begin(),
2868 getAssignmentOps().end());
2871 helper_expr_range assignment_ops() {
2872 return helper_expr_range(getAssignmentOps().begin(),
2873 getAssignmentOps().end());
2876 child_range children() {
2877 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2878 reinterpret_cast<Stmt **>(varlist_end()));
2881 static bool classof(const OMPClause *T) {
2882 return T->getClauseKind() == OMPC_copyin;
2886 /// This represents clause 'copyprivate' in the '#pragma omp ...'
2890 /// #pragma omp single copyprivate(a,b)
2892 /// In this example directive '#pragma omp single' has clause 'copyprivate'
2893 /// with the variables 'a' and 'b'.
2894 class OMPCopyprivateClause final
2895 : public OMPVarListClause<OMPCopyprivateClause>,
2896 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
2897 friend class OMPClauseReader;
2898 friend OMPVarListClause;
2899 friend TrailingObjects;
2901 /// Build clause with number of variables \a N.
2903 /// \param StartLoc Starting location of the clause.
2904 /// \param LParenLoc Location of '('.
2905 /// \param EndLoc Ending location of the clause.
2906 /// \param N Number of the variables in the clause.
2907 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2908 SourceLocation EndLoc, unsigned N)
2909 : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
2910 LParenLoc, EndLoc, N) {}
2912 /// Build an empty clause.
2914 /// \param N Number of variables.
2915 explicit OMPCopyprivateClause(unsigned N)
2916 : OMPVarListClause<OMPCopyprivateClause>(
2917 OMPC_copyprivate, SourceLocation(), SourceLocation(),
2918 SourceLocation(), N) {}
2920 /// Set list of helper expressions, required for proper codegen of the
2921 /// clause. These expressions represent source expression in the final
2922 /// assignment statement performed by the copyprivate clause.
2923 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2925 /// Get the list of helper source expressions.
2926 MutableArrayRef<Expr *> getSourceExprs() {
2927 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2929 ArrayRef<const Expr *> getSourceExprs() const {
2930 return llvm::makeArrayRef(varlist_end(), varlist_size());
2933 /// Set list of helper expressions, required for proper codegen of the
2934 /// clause. These expressions represent destination expression in the final
2935 /// assignment statement performed by the copyprivate clause.
2936 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2938 /// Get the list of helper destination expressions.
2939 MutableArrayRef<Expr *> getDestinationExprs() {
2940 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2942 ArrayRef<const Expr *> getDestinationExprs() const {
2943 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2946 /// Set list of helper assignment expressions, required for proper
2947 /// codegen of the clause. These expressions are assignment expressions that
2948 /// assign source helper expressions to destination helper expressions
2949 /// correspondingly.
2950 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2952 /// Get the list of helper assignment expressions.
2953 MutableArrayRef<Expr *> getAssignmentOps() {
2954 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2956 ArrayRef<const Expr *> getAssignmentOps() const {
2957 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2961 /// Creates clause with a list of variables \a VL.
2963 /// \param C AST context.
2964 /// \param StartLoc Starting location of the clause.
2965 /// \param LParenLoc Location of '('.
2966 /// \param EndLoc Ending location of the clause.
2967 /// \param VL List of references to the variables.
2968 /// \param SrcExprs List of helper expressions for proper generation of
2969 /// assignment operation required for copyprivate clause. This list represents
2971 /// \param DstExprs List of helper expressions for proper generation of
2972 /// assignment operation required for copyprivate clause. This list represents
2974 /// \param AssignmentOps List of helper expressions that represents assignment
2977 /// DstExprs = SrcExprs;
2979 /// Required for proper codegen of final assignment performed by the
2980 /// copyprivate clause.
2981 static OMPCopyprivateClause *
2982 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2983 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2984 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2986 /// Creates an empty clause with \a N variables.
2988 /// \param C AST context.
2989 /// \param N The number of variables.
2990 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2992 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2993 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2994 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2995 using helper_expr_const_range =
2996 llvm::iterator_range<helper_expr_const_iterator>;
2998 helper_expr_const_range source_exprs() const {
2999 return helper_expr_const_range(getSourceExprs().begin(),
3000 getSourceExprs().end());
3003 helper_expr_range source_exprs() {
3004 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3007 helper_expr_const_range destination_exprs() const {
3008 return helper_expr_const_range(getDestinationExprs().begin(),
3009 getDestinationExprs().end());
3012 helper_expr_range destination_exprs() {
3013 return helper_expr_range(getDestinationExprs().begin(),
3014 getDestinationExprs().end());
3017 helper_expr_const_range assignment_ops() const {
3018 return helper_expr_const_range(getAssignmentOps().begin(),
3019 getAssignmentOps().end());
3022 helper_expr_range assignment_ops() {
3023 return helper_expr_range(getAssignmentOps().begin(),
3024 getAssignmentOps().end());
3027 child_range children() {
3028 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3029 reinterpret_cast<Stmt **>(varlist_end()));
3032 static bool classof(const OMPClause *T) {
3033 return T->getClauseKind() == OMPC_copyprivate;
3037 /// This represents implicit clause 'flush' for the '#pragma omp flush'
3039 /// This clause does not exist by itself, it can be only as a part of 'omp
3040 /// flush' directive. This clause is introduced to keep the original structure
3041 /// of \a OMPExecutableDirective class and its derivatives and to use the
3042 /// existing infrastructure of clauses with the list of variables.
3045 /// #pragma omp flush(a,b)
3047 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
3048 /// with the variables 'a' and 'b'.
3049 class OMPFlushClause final
3050 : public OMPVarListClause<OMPFlushClause>,
3051 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
3052 friend OMPVarListClause;
3053 friend TrailingObjects;
3055 /// Build clause with number of variables \a N.
3057 /// \param StartLoc Starting location of the clause.
3058 /// \param LParenLoc Location of '('.
3059 /// \param EndLoc Ending location of the clause.
3060 /// \param N Number of the variables in the clause.
3061 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3062 SourceLocation EndLoc, unsigned N)
3063 : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
3066 /// Build an empty clause.
3068 /// \param N Number of variables.
3069 explicit OMPFlushClause(unsigned N)
3070 : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
3071 SourceLocation(), SourceLocation(),
3075 /// Creates clause with a list of variables \a VL.
3077 /// \param C AST context.
3078 /// \param StartLoc Starting location of the clause.
3079 /// \param LParenLoc Location of '('.
3080 /// \param EndLoc Ending location of the clause.
3081 /// \param VL List of references to the variables.
3082 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
3083 SourceLocation LParenLoc, SourceLocation EndLoc,
3084 ArrayRef<Expr *> VL);
3086 /// Creates an empty clause with \a N variables.
3088 /// \param C AST context.
3089 /// \param N The number of variables.
3090 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
3092 child_range children() {
3093 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3094 reinterpret_cast<Stmt **>(varlist_end()));
3097 static bool classof(const OMPClause *T) {
3098 return T->getClauseKind() == OMPC_flush;
3102 /// This represents implicit clause 'depend' for the '#pragma omp task'
3106 /// #pragma omp task depend(in:a,b)
3108 /// In this example directive '#pragma omp task' with clause 'depend' with the
3109 /// variables 'a' and 'b' with dependency 'in'.
3110 class OMPDependClause final
3111 : public OMPVarListClause<OMPDependClause>,
3112 private llvm::TrailingObjects<OMPDependClause, Expr *> {
3113 friend class OMPClauseReader;
3114 friend OMPVarListClause;
3115 friend TrailingObjects;
3117 /// Dependency type (one of in, out, inout).
3118 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
3120 /// Dependency type location.
3121 SourceLocation DepLoc;
3124 SourceLocation ColonLoc;
3126 /// Number of loops, associated with the depend clause.
3127 unsigned NumLoops = 0;
3129 /// Build clause with number of variables \a N.
3131 /// \param StartLoc Starting location of the clause.
3132 /// \param LParenLoc Location of '('.
3133 /// \param EndLoc Ending location of the clause.
3134 /// \param N Number of the variables in the clause.
3135 /// \param NumLoops Number of loops that is associated with this depend
3137 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3138 SourceLocation EndLoc, unsigned N, unsigned NumLoops)
3139 : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
3140 EndLoc, N), NumLoops(NumLoops) {}
3142 /// Build an empty clause.
3144 /// \param N Number of variables.
3145 /// \param NumLoops Number of loops that is associated with this depend
3147 explicit OMPDependClause(unsigned N, unsigned NumLoops)
3148 : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
3149 SourceLocation(), SourceLocation(),
3151 NumLoops(NumLoops) {}
3153 /// Set dependency kind.
3154 void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
3156 /// Set dependency kind and its location.
3157 void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
3159 /// Set colon location.
3160 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3163 /// Creates clause with a list of variables \a VL.
3165 /// \param C AST context.
3166 /// \param StartLoc Starting location of the clause.
3167 /// \param LParenLoc Location of '('.
3168 /// \param EndLoc Ending location of the clause.
3169 /// \param DepKind Dependency type.
3170 /// \param DepLoc Location of the dependency type.
3171 /// \param ColonLoc Colon location.
3172 /// \param VL List of references to the variables.
3173 /// \param NumLoops Number of loops that is associated with this depend
3175 static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
3176 SourceLocation LParenLoc,
3177 SourceLocation EndLoc,
3178 OpenMPDependClauseKind DepKind,
3179 SourceLocation DepLoc, SourceLocation ColonLoc,
3180 ArrayRef<Expr *> VL, unsigned NumLoops);
3182 /// Creates an empty clause with \a N variables.
3184 /// \param C AST context.
3185 /// \param N The number of variables.
3186 /// \param NumLoops Number of loops that is associated with this depend
3188 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
3191 /// Get dependency type.
3192 OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
3194 /// Get dependency type location.
3195 SourceLocation getDependencyLoc() const { return DepLoc; }
3197 /// Get colon location.
3198 SourceLocation getColonLoc() const { return ColonLoc; }
3200 /// Get number of loops associated with the clause.
3201 unsigned getNumLoops() const { return NumLoops; }
3203 /// Set the loop data for the depend clauses with 'sink|source' kind of
3205 void setLoopData(unsigned NumLoop, Expr *Cnt);
3207 /// Get the loop data.
3208 Expr *getLoopData(unsigned NumLoop);
3209 const Expr *getLoopData(unsigned NumLoop) const;
3211 child_range children() {
3212 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3213 reinterpret_cast<Stmt **>(varlist_end()));
3216 static bool classof(const OMPClause *T) {
3217 return T->getClauseKind() == OMPC_depend;
3221 /// This represents 'device' clause in the '#pragma omp ...'
3225 /// #pragma omp target device(a)
3227 /// In this example directive '#pragma omp target' has clause 'device'
3228 /// with single expression 'a'.
3229 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
3230 friend class OMPClauseReader;
3232 /// Location of '('.
3233 SourceLocation LParenLoc;
3236 Stmt *Device = nullptr;
3238 /// Set the device number.
3240 /// \param E Device number.
3241 void setDevice(Expr *E) { Device = E; }
3244 /// Build 'device' clause.
3246 /// \param E Expression associated with this clause.
3247 /// \param CaptureRegion Innermost OpenMP region where expressions in this
3248 /// clause must be captured.
3249 /// \param StartLoc Starting location of the clause.
3250 /// \param LParenLoc Location of '('.
3251 /// \param EndLoc Ending location of the clause.
3252 OMPDeviceClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
3253 SourceLocation StartLoc, SourceLocation LParenLoc,
3254 SourceLocation EndLoc)
3255 : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this),
3256 LParenLoc(LParenLoc), Device(E) {
3257 setPreInitStmt(HelperE, CaptureRegion);
3260 /// Build an empty clause.
3262 : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
3263 OMPClauseWithPreInit(this) {}
3265 /// Sets the location of '('.
3266 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3268 /// Returns the location of '('.
3269 SourceLocation getLParenLoc() const { return LParenLoc; }
3271 /// Return device number.
3272 Expr *getDevice() { return cast<Expr>(Device); }
3274 /// Return device number.
3275 Expr *getDevice() const { return cast<Expr>(Device); }
3277 child_range children() { return child_range(&Device, &Device + 1); }
3279 static bool classof(const OMPClause *T) {
3280 return T->getClauseKind() == OMPC_device;
3284 /// This represents 'threads' clause in the '#pragma omp ...' directive.
3287 /// #pragma omp ordered threads
3289 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
3290 class OMPThreadsClause : public OMPClause {
3292 /// Build 'threads' clause.
3294 /// \param StartLoc Starting location of the clause.
3295 /// \param EndLoc Ending location of the clause.
3296 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
3297 : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
3299 /// Build an empty clause.
3301 : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
3303 child_range children() {
3304 return child_range(child_iterator(), child_iterator());
3307 static bool classof(const OMPClause *T) {
3308 return T->getClauseKind() == OMPC_threads;
3312 /// This represents 'simd' clause in the '#pragma omp ...' directive.
3315 /// #pragma omp ordered simd
3317 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
3318 class OMPSIMDClause : public OMPClause {
3320 /// Build 'simd' clause.
3322 /// \param StartLoc Starting location of the clause.
3323 /// \param EndLoc Ending location of the clause.
3324 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
3325 : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
3327 /// Build an empty clause.
3328 OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
3330 child_range children() {
3331 return child_range(child_iterator(), child_iterator());
3334 static bool classof(const OMPClause *T) {
3335 return T->getClauseKind() == OMPC_simd;
3339 /// Struct that defines common infrastructure to handle mappable
3340 /// expressions used in OpenMP clauses.
3341 class OMPClauseMappableExprCommon {
3343 /// Class that represents a component of a mappable expression. E.g.
3344 /// for an expression S.a, the first component is a declaration reference
3345 /// expression associated with 'S' and the second is a member expression
3346 /// associated with the field declaration 'a'. If the expression is an array
3347 /// subscript it may not have any associated declaration. In that case the
3348 /// associated declaration is set to nullptr.
3349 class MappableComponent {
3350 /// Expression associated with the component.
3351 Expr *AssociatedExpression = nullptr;
3353 /// Declaration associated with the declaration. If the component does
3354 /// not have a declaration (e.g. array subscripts or section), this is set
3356 ValueDecl *AssociatedDeclaration = nullptr;
3359 explicit MappableComponent() = default;
3360 explicit MappableComponent(Expr *AssociatedExpression,
3361 ValueDecl *AssociatedDeclaration)
3362 : AssociatedExpression(AssociatedExpression),
3363 AssociatedDeclaration(
3364 AssociatedDeclaration
3365 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
3368 Expr *getAssociatedExpression() const { return AssociatedExpression; }
3370 ValueDecl *getAssociatedDeclaration() const {
3371 return AssociatedDeclaration;
3375 // List of components of an expression. This first one is the whole
3376 // expression and the last one is the base expression.
3377 using MappableExprComponentList = SmallVector<MappableComponent, 8>;
3378 using MappableExprComponentListRef = ArrayRef<MappableComponent>;
3380 // List of all component lists associated to the same base declaration.
3381 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
3382 // their component list but the same base declaration 'S'.
3383 using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
3384 using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
3387 // Return the total number of elements in a list of component lists.
3389 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
3391 // Return the total number of elements in a list of declarations. All
3392 // declarations are expected to be canonical.
3394 getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
3397 /// This represents clauses with a list of expressions that are mappable.
3398 /// Examples of these clauses are 'map' in
3399 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
3400 /// in '#pragma omp target update...' directives.
3402 class OMPMappableExprListClause : public OMPVarListClause<T>,
3403 public OMPClauseMappableExprCommon {
3404 friend class OMPClauseReader;
3406 /// Number of unique declarations in this clause.
3407 unsigned NumUniqueDeclarations;
3409 /// Number of component lists in this clause.
3410 unsigned NumComponentLists;
3412 /// Total number of components in this clause.
3413 unsigned NumComponents;
3416 /// Build a clause for \a NumUniqueDeclarations declarations, \a
3417 /// NumComponentLists total component lists, and \a NumComponents total
3420 /// \param K Kind of the clause.
3421 /// \param StartLoc Starting location of the clause (the clause keyword).
3422 /// \param LParenLoc Location of '('.
3423 /// \param EndLoc Ending location of the clause.
3424 /// \param NumVars Number of expressions listed in the clause.
3425 /// \param NumUniqueDeclarations Number of unique base declarations in this
3427 /// \param NumComponentLists Number of component lists in this clause - one
3428 /// list for each expression in the clause.
3429 /// \param NumComponents Total number of expression components in the clause.
3430 OMPMappableExprListClause(OpenMPClauseKind K, SourceLocation StartLoc,
3431 SourceLocation LParenLoc, SourceLocation EndLoc,
3432 unsigned NumVars, unsigned NumUniqueDeclarations,
3433 unsigned NumComponentLists, unsigned NumComponents)
3434 : OMPVarListClause<T>(K, StartLoc, LParenLoc, EndLoc, NumVars),
3435 NumUniqueDeclarations(NumUniqueDeclarations),
3436 NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
3438 /// Get the unique declarations that are in the trailing objects of the
3440 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
3441 return MutableArrayRef<ValueDecl *>(
3442 static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
3443 NumUniqueDeclarations);
3446 /// Get the unique declarations that are in the trailing objects of the
3448 ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
3449 return ArrayRef<ValueDecl *>(
3450 static_cast<const T *>(this)
3451 ->template getTrailingObjects<ValueDecl *>(),
3452 NumUniqueDeclarations);
3455 /// Set the unique declarations that are in the trailing objects of the
3457 void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
3458 assert(UDs.size() == NumUniqueDeclarations &&
3459 "Unexpected amount of unique declarations.");
3460 std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
3463 /// Get the number of lists per declaration that are in the trailing
3464 /// objects of the class.
3465 MutableArrayRef<unsigned> getDeclNumListsRef() {
3466 return MutableArrayRef<unsigned>(
3467 static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
3468 NumUniqueDeclarations);
3471 /// Get the number of lists per declaration that are in the trailing
3472 /// objects of the class.
3473 ArrayRef<unsigned> getDeclNumListsRef() const {
3474 return ArrayRef<unsigned>(
3475 static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
3476 NumUniqueDeclarations);
3479 /// Set the number of lists per declaration that are in the trailing
3480 /// objects of the class.
3481 void setDeclNumLists(ArrayRef<unsigned> DNLs) {
3482 assert(DNLs.size() == NumUniqueDeclarations &&
3483 "Unexpected amount of list numbers.");
3484 std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
3487 /// Get the cumulative component lists sizes that are in the trailing
3488 /// objects of the class. They are appended after the number of lists.
3489 MutableArrayRef<unsigned> getComponentListSizesRef() {
3490 return MutableArrayRef<unsigned>(
3491 static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
3492 NumUniqueDeclarations,
3496 /// Get the cumulative component lists sizes that are in the trailing
3497 /// objects of the class. They are appended after the number of lists.
3498 ArrayRef<unsigned> getComponentListSizesRef() const {
3499 return ArrayRef<unsigned>(
3500 static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
3501 NumUniqueDeclarations,
3505 /// Set the cumulative component lists sizes that are in the trailing
3506 /// objects of the class.
3507 void setComponentListSizes(ArrayRef<unsigned> CLSs) {
3508 assert(CLSs.size() == NumComponentLists &&
3509 "Unexpected amount of component lists.");
3510 std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
3513 /// Get the components that are in the trailing objects of the class.
3514 MutableArrayRef<MappableComponent> getComponentsRef() {
3515 return MutableArrayRef<MappableComponent>(
3516 static_cast<T *>(this)
3517 ->template getTrailingObjects<MappableComponent>(),
3521 /// Get the components that are in the trailing objects of the class.
3522 ArrayRef<MappableComponent> getComponentsRef() const {
3523 return ArrayRef<MappableComponent>(
3524 static_cast<const T *>(this)
3525 ->template getTrailingObjects<MappableComponent>(),
3529 /// Set the components that are in the trailing objects of the class.
3530 /// This requires the list sizes so that it can also fill the original
3531 /// expressions, which are the first component of each list.
3532 void setComponents(ArrayRef<MappableComponent> Components,
3533 ArrayRef<unsigned> CLSs) {
3534 assert(Components.size() == NumComponents &&
3535 "Unexpected amount of component lists.");
3536 assert(CLSs.size() == NumComponentLists &&
3537 "Unexpected amount of list sizes.");
3538 std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
3541 /// Fill the clause information from the list of declarations and
3542 /// associated component lists.
3543 void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
3544 MappableExprComponentListsRef ComponentLists) {
3545 // Perform some checks to make sure the data sizes are consistent with the
3546 // information available when the clause was created.
3547 assert(getUniqueDeclarationsTotalNumber(Declarations) ==
3548 NumUniqueDeclarations &&
3549 "Unexpected number of mappable expression info entries!");
3550 assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
3551 "Unexpected total number of components!");
3552 assert(Declarations.size() == ComponentLists.size() &&
3553 "Declaration and component lists size is not consistent!");
3554 assert(Declarations.size() == NumComponentLists &&
3555 "Unexpected declaration and component lists size!");
3557 // Organize the components by declaration and retrieve the original
3558 // expression. Original expressions are always the first component of the
3559 // mappable component list.
3560 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
3563 auto CI = ComponentLists.begin();
3564 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
3566 assert(!CI->empty() && "Invalid component list!");
3567 ComponentListMap[*DI].push_back(*CI);
3571 // Iterators of the target storage.
3572 auto UniqueDeclarations = getUniqueDeclsRef();
3573 auto UDI = UniqueDeclarations.begin();
3575 auto DeclNumLists = getDeclNumListsRef();
3576 auto DNLI = DeclNumLists.begin();
3578 auto ComponentListSizes = getComponentListSizesRef();
3579 auto CLSI = ComponentListSizes.begin();
3581 auto Components = getComponentsRef();
3582 auto CI = Components.begin();
3584 // Variable to compute the accumulation of the number of components.
3585 unsigned PrevSize = 0u;
3587 // Scan all the declarations and associated component lists.
3588 for (auto &M : ComponentListMap) {
3591 // The component lists.
3594 // Initialize the entry.
3601 // Obtain the cumulative sizes and concatenate all the components in the
3602 // reserved storage.
3604 // Accumulate with the previous size.
3605 PrevSize += C.size();
3611 // Append components after the current components iterator.
3612 CI = std::copy(C.begin(), C.end(), CI);
3618 /// Return the number of unique base declarations in this clause.
3619 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
3621 /// Return the number of lists derived from the clause expressions.
3622 unsigned getTotalComponentListNum() const { return NumComponentLists; }
3624 /// Return the total number of components in all lists derived from the
3626 unsigned getTotalComponentsNum() const { return NumComponents; }
3628 /// Iterator that browse the components by lists. It also allows
3629 /// browsing components of a single declaration.
3630 class const_component_lists_iterator
3631 : public llvm::iterator_adaptor_base<
3632 const_component_lists_iterator,
3633 MappableExprComponentListRef::const_iterator,
3634 std::forward_iterator_tag, MappableComponent, ptrdiff_t,
3635 MappableComponent, MappableComponent> {
3636 // The declaration the iterator currently refers to.
3637 ArrayRef<ValueDecl *>::iterator DeclCur;
3639 // The list number associated with the current declaration.
3640 ArrayRef<unsigned>::iterator NumListsCur;
3642 // Remaining lists for the current declaration.
3643 unsigned RemainingLists = 0;
3645 // The cumulative size of the previous list, or zero if there is no previous
3647 unsigned PrevListSize = 0;
3649 // The cumulative sizes of the current list - it will delimit the remaining
3650 // range of interest.
3651 ArrayRef<unsigned>::const_iterator ListSizeCur;
3652 ArrayRef<unsigned>::const_iterator ListSizeEnd;
3654 // Iterator to the end of the components storage.
3655 MappableExprComponentListRef::const_iterator End;
3658 /// Construct an iterator that scans all lists.
3659 explicit const_component_lists_iterator(
3660 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
3661 ArrayRef<unsigned> CumulativeListSizes,
3662 MappableExprComponentListRef Components)
3663 : const_component_lists_iterator::iterator_adaptor_base(
3664 Components.begin()),
3665 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
3666 ListSizeCur(CumulativeListSizes.begin()),
3667 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
3668 assert(UniqueDecls.size() == DeclsListNum.size() &&
3669 "Inconsistent number of declarations and list sizes!");
3670 if (!DeclsListNum.empty())
3671 RemainingLists = *NumListsCur;
3674 /// Construct an iterator that scan lists for a given declaration \a
3676 explicit const_component_lists_iterator(
3677 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
3678 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
3679 MappableExprComponentListRef Components)
3680 : const_component_lists_iterator(UniqueDecls, DeclsListNum,
3681 CumulativeListSizes, Components) {
3682 // Look for the desired declaration. While we are looking for it, we
3683 // update the state so that we know the component where a given list
3685 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
3686 if (*DeclCur == Declaration)
3689 assert(*NumListsCur > 0 && "No lists associated with declaration??");
3691 // Skip the lists associated with the current declaration, but save the
3692 // last list size that was skipped.
3693 std::advance(ListSizeCur, *NumListsCur - 1);
3694 PrevListSize = *ListSizeCur;
3698 // If we didn't find any declaration, advance the iterator to after the
3699 // last component and set remaining lists to zero.
3700 if (ListSizeCur == CumulativeListSizes.end()) {
3702 RemainingLists = 0u;
3706 // Set the remaining lists with the total number of lists of the current
3708 RemainingLists = *NumListsCur;
3710 // Adjust the list size end iterator to the end of the relevant range.
3711 ListSizeEnd = ListSizeCur;
3712 std::advance(ListSizeEnd, RemainingLists);
3714 // Given that the list sizes are cumulative, the index of the component
3715 // that start the list is the size of the previous list.
3716 std::advance(this->I, PrevListSize);
3719 // Return the array with the current list. The sizes are cumulative, so the
3720 // array size is the difference between the current size and previous one.
3721 std::pair<const ValueDecl *, MappableExprComponentListRef>
3723 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
3724 return std::make_pair(
3726 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize));
3728 std::pair<const ValueDecl *, MappableExprComponentListRef>
3729 operator->() const {
3733 // Skip the components of the current list.
3734 const_component_lists_iterator &operator++() {
3735 assert(ListSizeCur != ListSizeEnd && RemainingLists &&
3736 "Invalid iterator!");
3738 // If we don't have more lists just skip all the components. Otherwise,
3739 // advance the iterator by the number of components in the current list.
3740 if (std::next(ListSizeCur) == ListSizeEnd) {
3744 std::advance(this->I, *ListSizeCur - PrevListSize);
3745 PrevListSize = *ListSizeCur;
3747 // We are done with a declaration, move to the next one.
3748 if (!(--RemainingLists)) {
3751 RemainingLists = *NumListsCur;
3752 assert(RemainingLists && "No lists in the following declaration??");
3761 using const_component_lists_range =
3762 llvm::iterator_range<const_component_lists_iterator>;
3764 /// Iterators for all component lists.
3765 const_component_lists_iterator component_lists_begin() const {
3766 return const_component_lists_iterator(
3767 getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
3768 getComponentsRef());
3770 const_component_lists_iterator component_lists_end() const {
3771 return const_component_lists_iterator(
3772 ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
3773 MappableExprComponentListRef(getComponentsRef().end(),
3774 getComponentsRef().end()));
3776 const_component_lists_range component_lists() const {
3777 return {component_lists_begin(), component_lists_end()};
3780 /// Iterators for component lists associated with the provided
3782 const_component_lists_iterator
3783 decl_component_lists_begin(const ValueDecl *VD) const {
3784 return const_component_lists_iterator(
3785 VD, getUniqueDeclsRef(), getDeclNumListsRef(),
3786 getComponentListSizesRef(), getComponentsRef());
3788 const_component_lists_iterator decl_component_lists_end() const {
3789 return component_lists_end();
3791 const_component_lists_range decl_component_lists(const ValueDecl *VD) const {
3792 return {decl_component_lists_begin(VD), decl_component_lists_end()};
3795 /// Iterators to access all the declarations, number of lists, list sizes, and
3797 using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
3798 using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
3800 const_all_decls_range all_decls() const {
3801 auto A = getUniqueDeclsRef();
3802 return const_all_decls_range(A.begin(), A.end());
3805 using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
3806 using const_all_num_lists_range =
3807 llvm::iterator_range<const_all_num_lists_iterator>;
3809 const_all_num_lists_range all_num_lists() const {
3810 auto A = getDeclNumListsRef();
3811 return const_all_num_lists_range(A.begin(), A.end());
3814 using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
3815 using const_all_lists_sizes_range =
3816 llvm::iterator_range<const_all_lists_sizes_iterator>;
3818 const_all_lists_sizes_range all_lists_sizes() const {
3819 auto A = getComponentListSizesRef();
3820 return const_all_lists_sizes_range(A.begin(), A.end());
3823 using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
3824 using const_all_components_range =
3825 llvm::iterator_range<const_all_components_iterator>;
3827 const_all_components_range all_components() const {
3828 auto A = getComponentsRef();
3829 return const_all_components_range(A.begin(), A.end());
3833 /// This represents clause 'map' in the '#pragma omp ...'
3837 /// #pragma omp target map(a,b)
3839 /// In this example directive '#pragma omp target' has clause 'map'
3840 /// with the variables 'a' and 'b'.
3841 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
3842 private llvm::TrailingObjects<
3843 OMPMapClause, Expr *, ValueDecl *, unsigned,
3844 OMPClauseMappableExprCommon::MappableComponent> {
3845 friend class OMPClauseReader;
3846 friend OMPMappableExprListClause;
3847 friend OMPVarListClause;
3848 friend TrailingObjects;
3850 /// Define the sizes of each trailing object array except the last one. This
3851 /// is required for TrailingObjects to work properly.
3852 size_t numTrailingObjects(OverloadToken<Expr *>) const {
3853 return varlist_size();
3855 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
3856 return getUniqueDeclarationsNum();
3858 size_t numTrailingObjects(OverloadToken<unsigned>) const {
3859 return getUniqueDeclarationsNum() + getTotalComponentListNum();
3862 /// Map type modifier for the 'map' clause.
3863 OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown;
3865 /// Map type for the 'map' clause.
3866 OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
3868 /// Is this an implicit map type or not.
3869 bool MapTypeIsImplicit = false;
3871 /// Location of the map type.
3872 SourceLocation MapLoc;
3875 SourceLocation ColonLoc;
3877 /// Build a clause for \a NumVars listed expressions, \a
3878 /// NumUniqueDeclarations declarations, \a NumComponentLists total component
3879 /// lists, and \a NumComponents total expression components.
3881 /// \param MapTypeModifier Map type modifier.
3882 /// \param MapType Map type.
3883 /// \param MapTypeIsImplicit Map type is inferred implicitly.
3884 /// \param MapLoc Location of the map type.
3885 /// \param StartLoc Starting location of the clause.
3886 /// \param EndLoc Ending location of the clause.
3887 /// \param NumVars Number of expressions listed in this clause.
3888 /// \param NumUniqueDeclarations Number of unique base declarations in this
3890 /// \param NumComponentLists Number of component lists in this clause.
3891 /// \param NumComponents Total number of expression components in the clause.
3892 explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier,
3893 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
3894 SourceLocation MapLoc, SourceLocation StartLoc,
3895 SourceLocation LParenLoc, SourceLocation EndLoc,
3896 unsigned NumVars, unsigned NumUniqueDeclarations,
3897 unsigned NumComponentLists, unsigned NumComponents)
3898 : OMPMappableExprListClause(OMPC_map, StartLoc, LParenLoc, EndLoc,
3899 NumVars, NumUniqueDeclarations,
3900 NumComponentLists, NumComponents),
3901 MapTypeModifier(MapTypeModifier), MapType(MapType),
3902 MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {}
3904 /// Build an empty clause.
3906 /// \param NumVars Number of expressions listed in this clause.
3907 /// \param NumUniqueDeclarations Number of unique base declarations in this
3909 /// \param NumComponentLists Number of component lists in this clause.
3910 /// \param NumComponents Total number of expression components in the clause.
3911 explicit OMPMapClause(unsigned NumVars, unsigned NumUniqueDeclarations,
3912 unsigned NumComponentLists, unsigned NumComponents)
3913 : OMPMappableExprListClause(
3914 OMPC_map, SourceLocation(), SourceLocation(), SourceLocation(),
3915 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
3917 /// Set type modifier for the clause.
3919 /// \param T Type Modifier for the clause.
3920 void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; }
3922 /// Set type for the clause.
3924 /// \param T Type for the clause.
3925 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
3927 /// Set type location.
3929 /// \param TLoc Type location.
3930 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
3932 /// Set colon location.
3933 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3936 /// Creates clause with a list of variables \a VL.
3938 /// \param C AST context.
3939 /// \param StartLoc Starting location of the clause.
3940 /// \param EndLoc Ending location of the clause.
3941 /// \param Vars The original expression used in the clause.
3942 /// \param Declarations Declarations used in the clause.
3943 /// \param ComponentLists Component lists used in the clause.
3944 /// \param TypeModifier Map type modifier.
3945 /// \param Type Map type.
3946 /// \param TypeIsImplicit Map type is inferred implicitly.
3947 /// \param TypeLoc Location of the map type.
3948 static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc,
3949 SourceLocation LParenLoc, SourceLocation EndLoc,
3950 ArrayRef<Expr *> Vars,
3951 ArrayRef<ValueDecl *> Declarations,
3952 MappableExprComponentListsRef ComponentLists,
3953 OpenMPMapClauseKind TypeModifier,
3954 OpenMPMapClauseKind Type, bool TypeIsImplicit,
3955 SourceLocation TypeLoc);
3957 /// Creates an empty clause with the place for \a NumVars original
3958 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
3959 /// lists, and \a NumComponents expression components.
3961 /// \param C AST context.
3962 /// \param NumVars Number of expressions listed in the clause.
3963 /// \param NumUniqueDeclarations Number of unique base declarations in this
3965 /// \param NumComponentLists Number of unique base declarations in this
3967 /// \param NumComponents Total number of expression components in the clause.
3968 static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
3969 unsigned NumUniqueDeclarations,
3970 unsigned NumComponentLists,
3971 unsigned NumComponents);
3973 /// Fetches mapping kind for the clause.
3974 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
3976 /// Is this an implicit map type?
3977 /// We have to capture 'IsMapTypeImplicit' from the parser for more
3978 /// informative error messages. It helps distinguish map(r) from
3979 /// map(tofrom: r), which is important to print more helpful error
3980 /// messages for some target directives.
3981 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
3983 /// Fetches the map type modifier for the clause.
3984 OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY {
3985 return MapTypeModifier;
3988 /// Fetches location of clause mapping kind.
3989 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
3991 /// Get colon location.
3992 SourceLocation getColonLoc() const { return ColonLoc; }
3994 child_range children() {
3996 reinterpret_cast<Stmt **>(varlist_begin()),
3997 reinterpret_cast<Stmt **>(varlist_end()));
4000 static bool classof(const OMPClause *T) {
4001 return T->getClauseKind() == OMPC_map;
4005 /// This represents 'num_teams' clause in the '#pragma omp ...'
4009 /// #pragma omp teams num_teams(n)
4011 /// In this example directive '#pragma omp teams' has clause 'num_teams'
4012 /// with single expression 'n'.
4013 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
4014 friend class OMPClauseReader;
4016 /// Location of '('.
4017 SourceLocation LParenLoc;
4019 /// NumTeams number.
4020 Stmt *NumTeams = nullptr;
4022 /// Set the NumTeams number.
4024 /// \param E NumTeams number.
4025 void setNumTeams(Expr *E) { NumTeams = E; }
4028 /// Build 'num_teams' clause.
4030 /// \param E Expression associated with this clause.
4031 /// \param HelperE Helper Expression associated with this clause.
4032 /// \param CaptureRegion Innermost OpenMP region where expressions in this
4033 /// clause must be captured.
4034 /// \param StartLoc Starting location of the clause.
4035 /// \param LParenLoc Location of '('.
4036 /// \param EndLoc Ending location of the clause.
4037 OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
4038 SourceLocation StartLoc, SourceLocation LParenLoc,
4039 SourceLocation EndLoc)
4040 : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this),
4041 LParenLoc(LParenLoc), NumTeams(E) {
4042 setPreInitStmt(HelperE, CaptureRegion);
4045 /// Build an empty clause.
4047 : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
4048 OMPClauseWithPreInit(this) {}
4050 /// Sets the location of '('.
4051 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4053 /// Returns the location of '('.
4054 SourceLocation getLParenLoc() const { return LParenLoc; }
4056 /// Return NumTeams number.
4057 Expr *getNumTeams() { return cast<Expr>(NumTeams); }
4059 /// Return NumTeams number.
4060 Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
4062 child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
4064 static bool classof(const OMPClause *T) {
4065 return T->getClauseKind() == OMPC_num_teams;
4069 /// This represents 'thread_limit' clause in the '#pragma omp ...'
4073 /// #pragma omp teams thread_limit(n)
4075 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
4076 /// with single expression 'n'.
4077 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
4078 friend class OMPClauseReader;
4080 /// Location of '('.
4081 SourceLocation LParenLoc;
4083 /// ThreadLimit number.
4084 Stmt *ThreadLimit = nullptr;
4086 /// Set the ThreadLimit number.
4088 /// \param E ThreadLimit number.
4089 void setThreadLimit(Expr *E) { ThreadLimit = E; }
4092 /// Build 'thread_limit' clause.
4094 /// \param E Expression associated with this clause.
4095 /// \param HelperE Helper Expression associated with this clause.
4096 /// \param CaptureRegion Innermost OpenMP region where expressions in this
4097 /// clause must be captured.
4098 /// \param StartLoc Starting location of the clause.
4099 /// \param LParenLoc Location of '('.
4100 /// \param EndLoc Ending location of the clause.
4101 OMPThreadLimitClause(Expr *E, Stmt *HelperE,
4102 OpenMPDirectiveKind CaptureRegion,
4103 SourceLocation StartLoc, SourceLocation LParenLoc,
4104 SourceLocation EndLoc)
4105 : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
4106 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
4107 setPreInitStmt(HelperE, CaptureRegion);
4110 /// Build an empty clause.
4111 OMPThreadLimitClause()
4112 : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
4113 OMPClauseWithPreInit(this) {}
4115 /// Sets the location of '('.
4116 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4118 /// Returns the location of '('.
4119 SourceLocation getLParenLoc() const { return LParenLoc; }
4121 /// Return ThreadLimit number.
4122 Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
4124 /// Return ThreadLimit number.
4125 Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
4127 child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
4129 static bool classof(const OMPClause *T) {
4130 return T->getClauseKind() == OMPC_thread_limit;
4134 /// This represents 'priority' clause in the '#pragma omp ...'
4138 /// #pragma omp task priority(n)
4140 /// In this example directive '#pragma omp teams' has clause 'priority' with
4141 /// single expression 'n'.
4142 class OMPPriorityClause : public OMPClause {
4143 friend class OMPClauseReader;
4145 /// Location of '('.
4146 SourceLocation LParenLoc;
4148 /// Priority number.
4149 Stmt *Priority = nullptr;
4151 /// Set the Priority number.
4153 /// \param E Priority number.
4154 void setPriority(Expr *E) { Priority = E; }
4157 /// Build 'priority' clause.
4159 /// \param E Expression associated with this clause.
4160 /// \param StartLoc Starting location of the clause.
4161 /// \param LParenLoc Location of '('.
4162 /// \param EndLoc Ending location of the clause.
4163 OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
4164 SourceLocation EndLoc)
4165 : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
4168 /// Build an empty clause.
4170 : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()) {}
4172 /// Sets the location of '('.
4173 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4175 /// Returns the location of '('.
4176 SourceLocation getLParenLoc() const { return LParenLoc; }
4178 /// Return Priority number.
4179 Expr *getPriority() { return cast<Expr>(Priority); }
4181 /// Return Priority number.
4182 Expr *getPriority() const { return cast<Expr>(Priority); }
4184 child_range children() { return child_range(&Priority, &Priority + 1); }
4186 static bool classof(const OMPClause *T) {
4187 return T->getClauseKind() == OMPC_priority;
4191 /// This represents 'grainsize' clause in the '#pragma omp ...'
4195 /// #pragma omp taskloop grainsize(4)
4197 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
4198 /// with single expression '4'.
4199 class OMPGrainsizeClause : public OMPClause {
4200 friend class OMPClauseReader;
4202 /// Location of '('.
4203 SourceLocation LParenLoc;
4205 /// Safe iteration space distance.
4206 Stmt *Grainsize = nullptr;
4209 void setGrainsize(Expr *Size) { Grainsize = Size; }
4212 /// Build 'grainsize' clause.
4214 /// \param Size Expression associated with this clause.
4215 /// \param StartLoc Starting location of the clause.
4216 /// \param EndLoc Ending location of the clause.
4217 OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
4218 SourceLocation LParenLoc, SourceLocation EndLoc)
4219 : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
4222 /// Build an empty clause.
4223 explicit OMPGrainsizeClause()
4224 : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()) {}
4226 /// Sets the location of '('.
4227 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4229 /// Returns the location of '('.
4230 SourceLocation getLParenLoc() const { return LParenLoc; }
4232 /// Return safe iteration space distance.
4233 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
4235 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
4237 static bool classof(const OMPClause *T) {
4238 return T->getClauseKind() == OMPC_grainsize;
4242 /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
4245 /// #pragma omp taskloop nogroup
4247 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
4248 class OMPNogroupClause : public OMPClause {
4250 /// Build 'nogroup' clause.
4252 /// \param StartLoc Starting location of the clause.
4253 /// \param EndLoc Ending location of the clause.
4254 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
4255 : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
4257 /// Build an empty clause.
4259 : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
4261 child_range children() {
4262 return child_range(child_iterator(), child_iterator());
4265 static bool classof(const OMPClause *T) {
4266 return T->getClauseKind() == OMPC_nogroup;
4270 /// This represents 'num_tasks' clause in the '#pragma omp ...'
4274 /// #pragma omp taskloop num_tasks(4)
4276 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
4277 /// with single expression '4'.
4278 class OMPNumTasksClause : public OMPClause {
4279 friend class OMPClauseReader;
4281 /// Location of '('.
4282 SourceLocation LParenLoc;
4284 /// Safe iteration space distance.
4285 Stmt *NumTasks = nullptr;
4288 void setNumTasks(Expr *Size) { NumTasks = Size; }
4291 /// Build 'num_tasks' clause.
4293 /// \param Size Expression associated with this clause.
4294 /// \param StartLoc Starting location of the clause.
4295 /// \param EndLoc Ending location of the clause.
4296 OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
4297 SourceLocation LParenLoc, SourceLocation EndLoc)
4298 : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
4301 /// Build an empty clause.
4302 explicit OMPNumTasksClause()
4303 : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()) {}
4305 /// Sets the location of '('.
4306 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4308 /// Returns the location of '('.
4309 SourceLocation getLParenLoc() const { return LParenLoc; }
4311 /// Return safe iteration space distance.
4312 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
4314 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
4316 static bool classof(const OMPClause *T) {
4317 return T->getClauseKind() == OMPC_num_tasks;
4321 /// This represents 'hint' clause in the '#pragma omp ...' directive.
4324 /// #pragma omp critical (name) hint(6)
4326 /// In this example directive '#pragma omp critical' has name 'name' and clause
4327 /// 'hint' with argument '6'.
4328 class OMPHintClause : public OMPClause {
4329 friend class OMPClauseReader;
4331 /// Location of '('.
4332 SourceLocation LParenLoc;
4334 /// Hint expression of the 'hint' clause.
4335 Stmt *Hint = nullptr;
4337 /// Set hint expression.
4338 void setHint(Expr *H) { Hint = H; }
4341 /// Build 'hint' clause with expression \a Hint.
4343 /// \param Hint Hint expression.
4344 /// \param StartLoc Starting location of the clause.
4345 /// \param LParenLoc Location of '('.
4346 /// \param EndLoc Ending location of the clause.
4347 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
4348 SourceLocation EndLoc)
4349 : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
4352 /// Build an empty clause.
4353 OMPHintClause() : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()) {}
4355 /// Sets the location of '('.
4356 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4358 /// Returns the location of '('.
4359 SourceLocation getLParenLoc() const { return LParenLoc; }
4361 /// Returns number of threads.
4362 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
4364 child_range children() { return child_range(&Hint, &Hint + 1); }
4366 static bool classof(const OMPClause *T) {
4367 return T->getClauseKind() == OMPC_hint;
4371 /// This represents 'dist_schedule' clause in the '#pragma omp ...'
4375 /// #pragma omp distribute dist_schedule(static, 3)
4377 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
4378 /// clause with arguments 'static' and '3'.
4379 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
4380 friend class OMPClauseReader;
4382 /// Location of '('.
4383 SourceLocation LParenLoc;
4385 /// A kind of the 'schedule' clause.
4386 OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
4388 /// Start location of the schedule kind in source code.
4389 SourceLocation KindLoc;
4391 /// Location of ',' (if any).
4392 SourceLocation CommaLoc;
4395 Expr *ChunkSize = nullptr;
4397 /// Set schedule kind.
4399 /// \param K Schedule kind.
4400 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
4402 /// Sets the location of '('.
4404 /// \param Loc Location of '('.
4405 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4407 /// Set schedule kind start location.
4409 /// \param KLoc Schedule kind location.
4410 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
4412 /// Set location of ','.
4414 /// \param Loc Location of ','.
4415 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
4419 /// \param E Chunk size.
4420 void setChunkSize(Expr *E) { ChunkSize = E; }
4423 /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
4424 /// size expression \a ChunkSize.
4426 /// \param StartLoc Starting location of the clause.
4427 /// \param LParenLoc Location of '('.
4428 /// \param KLoc Starting location of the argument.
4429 /// \param CommaLoc Location of ','.
4430 /// \param EndLoc Ending location of the clause.
4431 /// \param Kind DistSchedule kind.
4432 /// \param ChunkSize Chunk size.
4433 /// \param HelperChunkSize Helper chunk size for combined directives.
4434 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4435 SourceLocation KLoc, SourceLocation CommaLoc,
4436 SourceLocation EndLoc,
4437 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
4438 Stmt *HelperChunkSize)
4439 : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc),
4440 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
4441 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
4442 setPreInitStmt(HelperChunkSize);
4445 /// Build an empty clause.
4446 explicit OMPDistScheduleClause()
4447 : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()),
4448 OMPClauseWithPreInit(this) {}
4450 /// Get kind of the clause.
4451 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
4453 /// Get location of '('.
4454 SourceLocation getLParenLoc() { return LParenLoc; }
4456 /// Get kind location.
4457 SourceLocation getDistScheduleKindLoc() { return KindLoc; }
4459 /// Get location of ','.
4460 SourceLocation getCommaLoc() { return CommaLoc; }
4463 Expr *getChunkSize() { return ChunkSize; }
4466 const Expr *getChunkSize() const { return ChunkSize; }
4468 child_range children() {
4469 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
4470 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
4473 static bool classof(const OMPClause *T) {
4474 return T->getClauseKind() == OMPC_dist_schedule;
4478 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
4481 /// #pragma omp target defaultmap(tofrom: scalar)
4483 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
4484 /// 'scalar' with modifier 'tofrom'.
4485 class OMPDefaultmapClause : public OMPClause {
4486 friend class OMPClauseReader;
4488 /// Location of '('.
4489 SourceLocation LParenLoc;
4491 /// Modifiers for 'defaultmap' clause.
4492 OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
4494 /// Locations of modifiers.
4495 SourceLocation ModifierLoc;
4497 /// A kind of the 'defaultmap' clause.
4498 OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
4500 /// Start location of the defaultmap kind in source code.
4501 SourceLocation KindLoc;
4503 /// Set defaultmap kind.
4505 /// \param K Defaultmap kind.
4506 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
4508 /// Set the defaultmap modifier.
4510 /// \param M Defaultmap modifier.
4511 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
4515 /// Set location of the defaultmap modifier.
4516 void setDefaultmapModifierLoc(SourceLocation Loc) {
4520 /// Sets the location of '('.
4522 /// \param Loc Location of '('.
4523 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4525 /// Set defaultmap kind start location.
4527 /// \param KLoc Defaultmap kind location.
4528 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
4531 /// Build 'defaultmap' clause with defaultmap kind \a Kind
4533 /// \param StartLoc Starting location of the clause.
4534 /// \param LParenLoc Location of '('.
4535 /// \param KLoc Starting location of the argument.
4536 /// \param EndLoc Ending location of the clause.
4537 /// \param Kind Defaultmap kind.
4538 /// \param M The modifier applied to 'defaultmap' clause.
4539 /// \param MLoc Location of the modifier
4540 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4541 SourceLocation MLoc, SourceLocation KLoc,
4542 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
4543 OpenMPDefaultmapClauseModifier M)
4544 : OMPClause(OMPC_defaultmap, StartLoc, EndLoc), LParenLoc(LParenLoc),
4545 Modifier(M), ModifierLoc(MLoc), Kind(Kind), KindLoc(KLoc) {}
4547 /// Build an empty clause.
4548 explicit OMPDefaultmapClause()
4549 : OMPClause(OMPC_defaultmap, SourceLocation(), SourceLocation()) {}
4551 /// Get kind of the clause.
4552 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
4554 /// Get the modifier of the clause.
4555 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
4559 /// Get location of '('.
4560 SourceLocation getLParenLoc() { return LParenLoc; }
4562 /// Get kind location.
4563 SourceLocation getDefaultmapKindLoc() { return KindLoc; }
4565 /// Get the modifier location.
4566 SourceLocation getDefaultmapModifierLoc() const {
4570 child_range children() {
4571 return child_range(child_iterator(), child_iterator());
4574 static bool classof(const OMPClause *T) {
4575 return T->getClauseKind() == OMPC_defaultmap;
4579 /// This represents clause 'to' in the '#pragma omp ...'
4583 /// #pragma omp target update to(a,b)
4585 /// In this example directive '#pragma omp target update' has clause 'to'
4586 /// with the variables 'a' and 'b'.
4587 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
4588 private llvm::TrailingObjects<
4589 OMPToClause, Expr *, ValueDecl *, unsigned,
4590 OMPClauseMappableExprCommon::MappableComponent> {
4591 friend class OMPClauseReader;
4592 friend OMPMappableExprListClause;
4593 friend OMPVarListClause;
4594 friend TrailingObjects;
4596 /// Build clause with number of variables \a NumVars.
4598 /// \param StartLoc Starting location of the clause.
4599 /// \param EndLoc Ending location of the clause.
4600 /// \param NumVars Number of expressions listed in this clause.
4601 /// \param NumUniqueDeclarations Number of unique base declarations in this
4603 /// \param NumComponentLists Number of component lists in this clause.
4604 /// \param NumComponents Total number of expression components in the clause.
4605 explicit OMPToClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4606 SourceLocation EndLoc, unsigned NumVars,
4607 unsigned NumUniqueDeclarations,
4608 unsigned NumComponentLists, unsigned NumComponents)
4609 : OMPMappableExprListClause(OMPC_to, StartLoc, LParenLoc, EndLoc, NumVars,
4610 NumUniqueDeclarations, NumComponentLists,
4613 /// Build an empty clause.
4615 /// \param NumVars Number of expressions listed in this clause.
4616 /// \param NumUniqueDeclarations Number of unique base declarations in this
4618 /// \param NumComponentLists Number of component lists in this clause.
4619 /// \param NumComponents Total number of expression components in the clause.
4620 explicit OMPToClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4621 unsigned NumComponentLists, unsigned NumComponents)
4622 : OMPMappableExprListClause(
4623 OMPC_to, SourceLocation(), SourceLocation(), SourceLocation(),
4624 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4626 /// Define the sizes of each trailing object array except the last one. This
4627 /// is required for TrailingObjects to work properly.
4628 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4629 return varlist_size();
4631 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4632 return getUniqueDeclarationsNum();
4634 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4635 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4639 /// Creates clause with a list of variables \a Vars.
4641 /// \param C AST context.
4642 /// \param StartLoc Starting location of the clause.
4643 /// \param EndLoc Ending location of the clause.
4644 /// \param Vars The original expression used in the clause.
4645 /// \param Declarations Declarations used in the clause.
4646 /// \param ComponentLists Component lists used in the clause.
4647 static OMPToClause *Create(const ASTContext &C, SourceLocation StartLoc,
4648 SourceLocation LParenLoc, SourceLocation EndLoc,
4649 ArrayRef<Expr *> Vars,
4650 ArrayRef<ValueDecl *> Declarations,
4651 MappableExprComponentListsRef ComponentLists);
4653 /// Creates an empty clause with the place for \a NumVars variables.
4655 /// \param C AST context.
4656 /// \param NumVars Number of expressions listed in the clause.
4657 /// \param NumUniqueDeclarations Number of unique base declarations in this
4659 /// \param NumComponentLists Number of unique base declarations in this
4661 /// \param NumComponents Total number of expression components in the clause.
4662 static OMPToClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4663 unsigned NumUniqueDeclarations,
4664 unsigned NumComponentLists,
4665 unsigned NumComponents);
4667 child_range children() {
4668 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4669 reinterpret_cast<Stmt **>(varlist_end()));
4672 static bool classof(const OMPClause *T) {
4673 return T->getClauseKind() == OMPC_to;
4677 /// This represents clause 'from' in the '#pragma omp ...'
4681 /// #pragma omp target update from(a,b)
4683 /// In this example directive '#pragma omp target update' has clause 'from'
4684 /// with the variables 'a' and 'b'.
4685 class OMPFromClause final
4686 : public OMPMappableExprListClause<OMPFromClause>,
4687 private llvm::TrailingObjects<
4688 OMPFromClause, Expr *, ValueDecl *, unsigned,
4689 OMPClauseMappableExprCommon::MappableComponent> {
4690 friend class OMPClauseReader;
4691 friend OMPMappableExprListClause;
4692 friend OMPVarListClause;
4693 friend TrailingObjects;
4695 /// Build clause with number of variables \a NumVars.
4697 /// \param StartLoc Starting location of the clause.
4698 /// \param EndLoc Ending location of the clause.
4699 /// \param NumVars Number of expressions listed in this clause.
4700 /// \param NumUniqueDeclarations Number of unique base declarations in this
4702 /// \param NumComponentLists Number of component lists in this clause.
4703 /// \param NumComponents Total number of expression components in the clause.
4704 explicit OMPFromClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4705 SourceLocation EndLoc, unsigned NumVars,
4706 unsigned NumUniqueDeclarations,
4707 unsigned NumComponentLists, unsigned NumComponents)
4708 : OMPMappableExprListClause(OMPC_from, StartLoc, LParenLoc, EndLoc,
4709 NumVars, NumUniqueDeclarations,
4710 NumComponentLists, NumComponents) {}
4712 /// Build an empty clause.
4714 /// \param NumVars Number of expressions listed in this clause.
4715 /// \param NumUniqueDeclarations Number of unique base declarations in this
4717 /// \param NumComponentLists Number of component lists in this clause.
4718 /// \param NumComponents Total number of expression components in the clause.
4719 explicit OMPFromClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4720 unsigned NumComponentLists, unsigned NumComponents)
4721 : OMPMappableExprListClause(
4722 OMPC_from, SourceLocation(), SourceLocation(), SourceLocation(),
4723 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4725 /// Define the sizes of each trailing object array except the last one. This
4726 /// is required for TrailingObjects to work properly.
4727 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4728 return varlist_size();
4730 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4731 return getUniqueDeclarationsNum();
4733 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4734 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4738 /// Creates clause with a list of variables \a Vars.
4740 /// \param C AST context.
4741 /// \param StartLoc Starting location of the clause.
4742 /// \param EndLoc Ending location of the clause.
4743 /// \param Vars The original expression used in the clause.
4744 /// \param Declarations Declarations used in the clause.
4745 /// \param ComponentLists Component lists used in the clause.
4746 static OMPFromClause *Create(const ASTContext &C, SourceLocation StartLoc,
4747 SourceLocation LParenLoc, SourceLocation EndLoc,
4748 ArrayRef<Expr *> Vars,
4749 ArrayRef<ValueDecl *> Declarations,
4750 MappableExprComponentListsRef ComponentLists);
4752 /// Creates an empty clause with the place for \a NumVars variables.
4754 /// \param C AST context.
4755 /// \param NumVars Number of expressions listed in the clause.
4756 /// \param NumUniqueDeclarations Number of unique base declarations in this
4758 /// \param NumComponentLists Number of unique base declarations in this
4760 /// \param NumComponents Total number of expression components in the clause.
4761 static OMPFromClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4762 unsigned NumUniqueDeclarations,
4763 unsigned NumComponentLists,
4764 unsigned NumComponents);
4766 child_range children() {
4767 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4768 reinterpret_cast<Stmt **>(varlist_end()));
4771 static bool classof(const OMPClause *T) {
4772 return T->getClauseKind() == OMPC_from;
4776 /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
4780 /// #pragma omp target data use_device_ptr(a,b)
4782 /// In this example directive '#pragma omp target data' has clause
4783 /// 'use_device_ptr' with the variables 'a' and 'b'.
4784 class OMPUseDevicePtrClause final
4785 : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
4786 private llvm::TrailingObjects<
4787 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
4788 OMPClauseMappableExprCommon::MappableComponent> {
4789 friend class OMPClauseReader;
4790 friend OMPMappableExprListClause;
4791 friend OMPVarListClause;
4792 friend TrailingObjects;
4794 /// Build clause with number of variables \a NumVars.
4796 /// \param StartLoc Starting location of the clause.
4797 /// \param EndLoc Ending location of the clause.
4798 /// \param NumVars Number of expressions listed in this clause.
4799 /// \param NumUniqueDeclarations Number of unique base declarations in this
4801 /// \param NumComponentLists Number of component lists in this clause.
4802 /// \param NumComponents Total number of expression components in the clause.
4803 explicit OMPUseDevicePtrClause(SourceLocation StartLoc,
4804 SourceLocation LParenLoc,
4805 SourceLocation EndLoc, unsigned NumVars,
4806 unsigned NumUniqueDeclarations,
4807 unsigned NumComponentLists,
4808 unsigned NumComponents)
4809 : OMPMappableExprListClause(OMPC_use_device_ptr, StartLoc, LParenLoc,
4810 EndLoc, NumVars, NumUniqueDeclarations,
4811 NumComponentLists, NumComponents) {}
4813 /// Build an empty clause.
4815 /// \param NumVars Number of expressions listed in this clause.
4816 /// \param NumUniqueDeclarations Number of unique base declarations in this
4818 /// \param NumComponentLists Number of component lists in this clause.
4819 /// \param NumComponents Total number of expression components in the clause.
4820 explicit OMPUseDevicePtrClause(unsigned NumVars,
4821 unsigned NumUniqueDeclarations,
4822 unsigned NumComponentLists,
4823 unsigned NumComponents)
4824 : OMPMappableExprListClause(OMPC_use_device_ptr, SourceLocation(),
4825 SourceLocation(), SourceLocation(), NumVars,
4826 NumUniqueDeclarations, NumComponentLists,
4829 /// Define the sizes of each trailing object array except the last one. This
4830 /// is required for TrailingObjects to work properly.
4831 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4832 return 3 * varlist_size();
4834 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4835 return getUniqueDeclarationsNum();
4837 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4838 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4841 /// Sets the list of references to private copies with initializers for new
4842 /// private variables.
4843 /// \param VL List of references.
4844 void setPrivateCopies(ArrayRef<Expr *> VL);
4846 /// Gets the list of references to private copies with initializers for new
4847 /// private variables.
4848 MutableArrayRef<Expr *> getPrivateCopies() {
4849 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4851 ArrayRef<const Expr *> getPrivateCopies() const {
4852 return llvm::makeArrayRef(varlist_end(), varlist_size());
4855 /// Sets the list of references to initializer variables for new private
4857 /// \param VL List of references.
4858 void setInits(ArrayRef<Expr *> VL);
4860 /// Gets the list of references to initializer variables for new private
4862 MutableArrayRef<Expr *> getInits() {
4863 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
4865 ArrayRef<const Expr *> getInits() const {
4866 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
4870 /// Creates clause with a list of variables \a Vars.
4872 /// \param C AST context.
4873 /// \param StartLoc Starting location of the clause.
4874 /// \param EndLoc Ending location of the clause.
4875 /// \param Vars The original expression used in the clause.
4876 /// \param PrivateVars Expressions referring to private copies.
4877 /// \param Inits Expressions referring to private copy initializers.
4878 /// \param Declarations Declarations used in the clause.
4879 /// \param ComponentLists Component lists used in the clause.
4880 static OMPUseDevicePtrClause *
4881 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4882 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
4883 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
4884 ArrayRef<ValueDecl *> Declarations,
4885 MappableExprComponentListsRef ComponentLists);
4887 /// Creates an empty clause with the place for \a NumVars variables.
4889 /// \param C AST context.
4890 /// \param NumVars Number of expressions listed in the clause.
4891 /// \param NumUniqueDeclarations Number of unique base declarations in this
4893 /// \param NumComponentLists Number of unique base declarations in this
4895 /// \param NumComponents Total number of expression components in the clause.
4896 static OMPUseDevicePtrClause *CreateEmpty(const ASTContext &C,
4898 unsigned NumUniqueDeclarations,
4899 unsigned NumComponentLists,
4900 unsigned NumComponents);
4902 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
4903 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
4904 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
4905 using private_copies_const_range =
4906 llvm::iterator_range<private_copies_const_iterator>;
4908 private_copies_range private_copies() {
4909 return private_copies_range(getPrivateCopies().begin(),
4910 getPrivateCopies().end());
4913 private_copies_const_range private_copies() const {
4914 return private_copies_const_range(getPrivateCopies().begin(),
4915 getPrivateCopies().end());
4918 using inits_iterator = MutableArrayRef<Expr *>::iterator;
4919 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
4920 using inits_range = llvm::iterator_range<inits_iterator>;
4921 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
4923 inits_range inits() {
4924 return inits_range(getInits().begin(), getInits().end());
4927 inits_const_range inits() const {
4928 return inits_const_range(getInits().begin(), getInits().end());
4931 child_range children() {
4932 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4933 reinterpret_cast<Stmt **>(varlist_end()));
4936 static bool classof(const OMPClause *T) {
4937 return T->getClauseKind() == OMPC_use_device_ptr;
4941 /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
4945 /// #pragma omp target is_device_ptr(a,b)
4947 /// In this example directive '#pragma omp target' has clause
4948 /// 'is_device_ptr' with the variables 'a' and 'b'.
4949 class OMPIsDevicePtrClause final
4950 : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
4951 private llvm::TrailingObjects<
4952 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
4953 OMPClauseMappableExprCommon::MappableComponent> {
4954 friend class OMPClauseReader;
4955 friend OMPMappableExprListClause;
4956 friend OMPVarListClause;
4957 friend TrailingObjects;
4959 /// Build clause with number of variables \a NumVars.
4961 /// \param StartLoc Starting location of the clause.
4962 /// \param EndLoc Ending location of the clause.
4963 /// \param NumVars Number of expressions listed in this clause.
4964 /// \param NumUniqueDeclarations Number of unique base declarations in this
4966 /// \param NumComponentLists Number of component lists in this clause.
4967 /// \param NumComponents Total number of expression components in the clause.
4968 explicit OMPIsDevicePtrClause(SourceLocation StartLoc,
4969 SourceLocation LParenLoc, SourceLocation EndLoc,
4971 unsigned NumUniqueDeclarations,
4972 unsigned NumComponentLists,
4973 unsigned NumComponents)
4974 : OMPMappableExprListClause(OMPC_is_device_ptr, StartLoc, LParenLoc,
4975 EndLoc, NumVars, NumUniqueDeclarations,
4976 NumComponentLists, NumComponents) {}
4978 /// Build an empty clause.
4980 /// \param NumVars Number of expressions listed in this clause.
4981 /// \param NumUniqueDeclarations Number of unique base declarations in this
4983 /// \param NumComponentLists Number of component lists in this clause.
4984 /// \param NumComponents Total number of expression components in the clause.
4985 explicit OMPIsDevicePtrClause(unsigned NumVars,
4986 unsigned NumUniqueDeclarations,
4987 unsigned NumComponentLists,
4988 unsigned NumComponents)
4989 : OMPMappableExprListClause(OMPC_is_device_ptr, SourceLocation(),
4990 SourceLocation(), SourceLocation(), NumVars,
4991 NumUniqueDeclarations, NumComponentLists,
4994 /// Define the sizes of each trailing object array except the last one. This
4995 /// is required for TrailingObjects to work properly.
4996 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4997 return varlist_size();
4999 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
5000 return getUniqueDeclarationsNum();
5002 size_t numTrailingObjects(OverloadToken<unsigned>) const {
5003 return getUniqueDeclarationsNum() + getTotalComponentListNum();
5007 /// Creates clause with a list of variables \a Vars.
5009 /// \param C AST context.
5010 /// \param StartLoc Starting location of the clause.
5011 /// \param EndLoc Ending location of the clause.
5012 /// \param Vars The original expression used in the clause.
5013 /// \param Declarations Declarations used in the clause.
5014 /// \param ComponentLists Component lists used in the clause.
5015 static OMPIsDevicePtrClause *
5016 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
5017 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
5018 ArrayRef<ValueDecl *> Declarations,
5019 MappableExprComponentListsRef ComponentLists);
5021 /// Creates an empty clause with the place for \a NumVars variables.
5023 /// \param C AST context.
5024 /// \param NumVars Number of expressions listed in the clause.
5025 /// \param NumUniqueDeclarations Number of unique base declarations in this
5027 /// \param NumComponentLists Number of unique base declarations in this
5029 /// \param NumComponents Total number of expression components in the clause.
5030 static OMPIsDevicePtrClause *CreateEmpty(const ASTContext &C,
5032 unsigned NumUniqueDeclarations,
5033 unsigned NumComponentLists,
5034 unsigned NumComponents);
5036 child_range children() {
5037 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5038 reinterpret_cast<Stmt **>(varlist_end()));
5041 static bool classof(const OMPClause *T) {
5042 return T->getClauseKind() == OMPC_is_device_ptr;
5046 } // namespace clang
5048 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H