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 { return StartLoc; }
69 /// Returns the ending location of the clause.
70 SourceLocation getLocEnd() const { return EndLoc; }
72 /// Sets the starting location of the clause.
73 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
75 /// Sets the ending location of the clause.
76 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
78 /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
79 OpenMPClauseKind getClauseKind() const { return Kind; }
81 bool isImplicit() const { return StartLoc.isInvalid(); }
83 using child_iterator = StmtIterator;
84 using const_child_iterator = ConstStmtIterator;
85 using child_range = llvm::iterator_range<child_iterator>;
86 using const_child_range = llvm::iterator_range<const_child_iterator>;
88 child_range children();
89 const_child_range children() const {
90 auto Children = const_cast<OMPClause *>(this)->children();
91 return const_child_range(Children.begin(), Children.end());
94 static bool classof(const OMPClause *) { return true; }
97 /// Class that handles pre-initialization statement for some clauses, like
98 /// 'shedule', 'firstprivate' etc.
99 class OMPClauseWithPreInit {
100 friend class OMPClauseReader;
102 /// Pre-initialization statement for the clause.
103 Stmt *PreInit = nullptr;
105 /// Region that captures the associated stmt.
106 OpenMPDirectiveKind CaptureRegion = OMPD_unknown;
109 OMPClauseWithPreInit(const OMPClause *This) {
110 assert(get(This) && "get is not tuned for pre-init.");
113 /// Set pre-initialization statement for the clause.
114 void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion = OMPD_unknown) {
116 CaptureRegion = ThisRegion;
120 /// Get pre-initialization statement for the clause.
121 const Stmt *getPreInitStmt() const { return PreInit; }
123 /// Get pre-initialization statement for the clause.
124 Stmt *getPreInitStmt() { return PreInit; }
126 /// Get capture region for the stmt in the clause.
127 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
129 static OMPClauseWithPreInit *get(OMPClause *C);
130 static const OMPClauseWithPreInit *get(const OMPClause *C);
133 /// Class that handles post-update expression for some clauses, like
134 /// 'lastprivate', 'reduction' etc.
135 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
136 friend class OMPClauseReader;
138 /// Post-update expression for the clause.
139 Expr *PostUpdate = nullptr;
142 OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
143 assert(get(This) && "get is not tuned for post-update.");
146 /// Set pre-initialization statement for the clause.
147 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
150 /// Get post-update expression for the clause.
151 const Expr *getPostUpdateExpr() const { return PostUpdate; }
153 /// Get post-update expression for the clause.
154 Expr *getPostUpdateExpr() { return PostUpdate; }
156 static OMPClauseWithPostUpdate *get(OMPClause *C);
157 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
160 /// This represents clauses with the list of variables like 'private',
161 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
162 /// '#pragma omp ...' directives.
163 template <class T> class OMPVarListClause : public OMPClause {
164 friend class OMPClauseReader;
167 SourceLocation LParenLoc;
169 /// Number of variables in the list.
173 /// Build a clause with \a N variables
175 /// \param K Kind of the clause.
176 /// \param StartLoc Starting location of the clause (the clause keyword).
177 /// \param LParenLoc Location of '('.
178 /// \param EndLoc Ending location of the clause.
179 /// \param N Number of the variables in the clause.
180 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
181 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
182 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
184 /// Fetches list of variables associated with this clause.
185 MutableArrayRef<Expr *> getVarRefs() {
186 return MutableArrayRef<Expr *>(
187 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
190 /// Sets the list of variables for this clause.
191 void setVarRefs(ArrayRef<Expr *> VL) {
192 assert(VL.size() == NumVars &&
193 "Number of variables is not the same as the preallocated buffer");
194 std::copy(VL.begin(), VL.end(),
195 static_cast<T *>(this)->template getTrailingObjects<Expr *>());
199 using varlist_iterator = MutableArrayRef<Expr *>::iterator;
200 using varlist_const_iterator = ArrayRef<const Expr *>::iterator;
201 using varlist_range = llvm::iterator_range<varlist_iterator>;
202 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
204 unsigned varlist_size() const { return NumVars; }
205 bool varlist_empty() const { return NumVars == 0; }
207 varlist_range varlists() {
208 return varlist_range(varlist_begin(), varlist_end());
210 varlist_const_range varlists() const {
211 return varlist_const_range(varlist_begin(), varlist_end());
214 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
215 varlist_iterator varlist_end() { return getVarRefs().end(); }
216 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
217 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
219 /// Sets the location of '('.
220 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
222 /// Returns the location of '('.
223 SourceLocation getLParenLoc() const { return LParenLoc; }
225 /// Fetches list of all variables in the clause.
226 ArrayRef<const Expr *> getVarRefs() const {
227 return llvm::makeArrayRef(
228 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
233 /// This represents 'if' clause in the '#pragma omp ...' directive.
236 /// #pragma omp parallel if(parallel:a > 5)
238 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
239 /// condition 'a > 5' and directive name modifier 'parallel'.
240 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
241 friend class OMPClauseReader;
244 SourceLocation LParenLoc;
246 /// Condition of the 'if' clause.
247 Stmt *Condition = nullptr;
249 /// Location of ':' (if any).
250 SourceLocation ColonLoc;
252 /// Directive name modifier for the clause.
253 OpenMPDirectiveKind NameModifier = OMPD_unknown;
255 /// Name modifier location.
256 SourceLocation NameModifierLoc;
259 void setCondition(Expr *Cond) { Condition = Cond; }
261 /// Set directive name modifier for the clause.
262 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
264 /// Set location of directive name modifier for the clause.
265 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
267 /// Set location of ':'.
268 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
271 /// Build 'if' clause with condition \a Cond.
273 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
274 /// \param Cond Condition of the clause.
275 /// \param HelperCond Helper condition for the clause.
276 /// \param CaptureRegion Innermost OpenMP region where expressions in this
277 /// clause must be captured.
278 /// \param StartLoc Starting location of the clause.
279 /// \param LParenLoc Location of '('.
280 /// \param NameModifierLoc Location of directive name modifier.
281 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
282 /// \param EndLoc Ending location of the clause.
283 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
284 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
285 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
286 SourceLocation ColonLoc, SourceLocation EndLoc)
287 : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this),
288 LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
289 NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) {
290 setPreInitStmt(HelperCond, CaptureRegion);
293 /// Build an empty clause.
295 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
296 OMPClauseWithPreInit(this) {}
298 /// Sets the location of '('.
299 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
301 /// Returns the location of '('.
302 SourceLocation getLParenLoc() const { return LParenLoc; }
304 /// Return the location of ':'.
305 SourceLocation getColonLoc() const { return ColonLoc; }
307 /// Returns condition.
308 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
310 /// Return directive name modifier associated with the clause.
311 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
313 /// Return the location of directive name modifier.
314 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
316 child_range children() { return child_range(&Condition, &Condition + 1); }
318 static bool classof(const OMPClause *T) {
319 return T->getClauseKind() == OMPC_if;
323 /// This represents 'final' clause in the '#pragma omp ...' directive.
326 /// #pragma omp task final(a > 5)
328 /// In this example directive '#pragma omp task' has simple 'final'
329 /// clause with condition 'a > 5'.
330 class OMPFinalClause : public OMPClause {
331 friend class OMPClauseReader;
334 SourceLocation LParenLoc;
336 /// Condition of the 'if' clause.
337 Stmt *Condition = nullptr;
340 void setCondition(Expr *Cond) { Condition = Cond; }
343 /// Build 'final' clause with condition \a Cond.
345 /// \param StartLoc Starting location of the clause.
346 /// \param LParenLoc Location of '('.
347 /// \param Cond Condition of the clause.
348 /// \param EndLoc Ending location of the clause.
349 OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
350 SourceLocation EndLoc)
351 : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
354 /// Build an empty clause.
356 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()) {}
358 /// Sets the location of '('.
359 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
361 /// Returns the location of '('.
362 SourceLocation getLParenLoc() const { return LParenLoc; }
364 /// Returns condition.
365 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
367 child_range children() { return child_range(&Condition, &Condition + 1); }
369 static bool classof(const OMPClause *T) {
370 return T->getClauseKind() == OMPC_final;
374 /// This represents 'num_threads' clause in the '#pragma omp ...'
378 /// #pragma omp parallel num_threads(6)
380 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
381 /// clause with number of threads '6'.
382 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
383 friend class OMPClauseReader;
386 SourceLocation LParenLoc;
388 /// Condition of the 'num_threads' clause.
389 Stmt *NumThreads = nullptr;
392 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
395 /// Build 'num_threads' clause with condition \a NumThreads.
397 /// \param NumThreads Number of threads for the construct.
398 /// \param HelperNumThreads Helper Number of threads for the construct.
399 /// \param CaptureRegion Innermost OpenMP region where expressions in this
400 /// clause must be captured.
401 /// \param StartLoc Starting location of the clause.
402 /// \param LParenLoc Location of '('.
403 /// \param EndLoc Ending location of the clause.
404 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
405 OpenMPDirectiveKind CaptureRegion,
406 SourceLocation StartLoc, SourceLocation LParenLoc,
407 SourceLocation EndLoc)
408 : OMPClause(OMPC_num_threads, StartLoc, EndLoc),
409 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
410 NumThreads(NumThreads) {
411 setPreInitStmt(HelperNumThreads, CaptureRegion);
414 /// Build an empty clause.
415 OMPNumThreadsClause()
416 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
417 OMPClauseWithPreInit(this) {}
419 /// Sets the location of '('.
420 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
422 /// Returns the location of '('.
423 SourceLocation getLParenLoc() const { return LParenLoc; }
425 /// Returns number of threads.
426 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
428 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
430 static bool classof(const OMPClause *T) {
431 return T->getClauseKind() == OMPC_num_threads;
435 /// This represents 'safelen' clause in the '#pragma omp ...'
439 /// #pragma omp simd safelen(4)
441 /// In this example directive '#pragma omp simd' has clause 'safelen'
442 /// with single expression '4'.
443 /// If the safelen clause is used then no two iterations executed
444 /// concurrently with SIMD instructions can have a greater distance
445 /// in the logical iteration space than its value. The parameter of
446 /// the safelen clause must be a constant positive integer expression.
447 class OMPSafelenClause : public OMPClause {
448 friend class OMPClauseReader;
451 SourceLocation LParenLoc;
453 /// Safe iteration space distance.
454 Stmt *Safelen = nullptr;
457 void setSafelen(Expr *Len) { Safelen = Len; }
460 /// Build 'safelen' clause.
462 /// \param Len Expression associated with this clause.
463 /// \param StartLoc Starting location of the clause.
464 /// \param EndLoc Ending location of the clause.
465 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
466 SourceLocation EndLoc)
467 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
470 /// Build an empty clause.
471 explicit OMPSafelenClause()
472 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()) {}
474 /// Sets the location of '('.
475 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
477 /// Returns the location of '('.
478 SourceLocation getLParenLoc() const { return LParenLoc; }
480 /// Return safe iteration space distance.
481 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
483 child_range children() { return child_range(&Safelen, &Safelen + 1); }
485 static bool classof(const OMPClause *T) {
486 return T->getClauseKind() == OMPC_safelen;
490 /// This represents 'simdlen' clause in the '#pragma omp ...'
494 /// #pragma omp simd simdlen(4)
496 /// In this example directive '#pragma omp simd' has clause 'simdlen'
497 /// with single expression '4'.
498 /// If the 'simdlen' clause is used then it specifies the preferred number of
499 /// iterations to be executed concurrently. The parameter of the 'simdlen'
500 /// clause must be a constant positive integer expression.
501 class OMPSimdlenClause : public OMPClause {
502 friend class OMPClauseReader;
505 SourceLocation LParenLoc;
507 /// Safe iteration space distance.
508 Stmt *Simdlen = nullptr;
511 void setSimdlen(Expr *Len) { Simdlen = Len; }
514 /// Build 'simdlen' clause.
516 /// \param Len Expression associated with this clause.
517 /// \param StartLoc Starting location of the clause.
518 /// \param EndLoc Ending location of the clause.
519 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
520 SourceLocation EndLoc)
521 : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
524 /// Build an empty clause.
525 explicit OMPSimdlenClause()
526 : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()) {}
528 /// Sets the location of '('.
529 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
531 /// Returns the location of '('.
532 SourceLocation getLParenLoc() const { return LParenLoc; }
534 /// Return safe iteration space distance.
535 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
537 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
539 static bool classof(const OMPClause *T) {
540 return T->getClauseKind() == OMPC_simdlen;
544 /// This represents 'collapse' clause in the '#pragma omp ...'
548 /// #pragma omp simd collapse(3)
550 /// In this example directive '#pragma omp simd' has clause 'collapse'
551 /// with single expression '3'.
552 /// The parameter must be a constant positive integer expression, it specifies
553 /// the number of nested loops that should be collapsed into a single iteration
555 class OMPCollapseClause : public OMPClause {
556 friend class OMPClauseReader;
559 SourceLocation LParenLoc;
561 /// Number of for-loops.
562 Stmt *NumForLoops = nullptr;
564 /// Set the number of associated for-loops.
565 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
568 /// Build 'collapse' clause.
570 /// \param Num Expression associated with this clause.
571 /// \param StartLoc Starting location of the clause.
572 /// \param LParenLoc Location of '('.
573 /// \param EndLoc Ending location of the clause.
574 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
575 SourceLocation LParenLoc, SourceLocation EndLoc)
576 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
579 /// Build an empty clause.
580 explicit OMPCollapseClause()
581 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()) {}
583 /// Sets the location of '('.
584 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
586 /// Returns the location of '('.
587 SourceLocation getLParenLoc() const { return LParenLoc; }
589 /// Return the number of associated for-loops.
590 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
592 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
594 static bool classof(const OMPClause *T) {
595 return T->getClauseKind() == OMPC_collapse;
599 /// This represents 'default' clause in the '#pragma omp ...' directive.
602 /// #pragma omp parallel default(shared)
604 /// In this example directive '#pragma omp parallel' has simple 'default'
605 /// clause with kind 'shared'.
606 class OMPDefaultClause : public OMPClause {
607 friend class OMPClauseReader;
610 SourceLocation LParenLoc;
612 /// A kind of the 'default' clause.
613 OpenMPDefaultClauseKind Kind = OMPC_DEFAULT_unknown;
615 /// Start location of the kind in source code.
616 SourceLocation KindKwLoc;
618 /// Set kind of the clauses.
620 /// \param K Argument of clause.
621 void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
623 /// Set argument location.
625 /// \param KLoc Argument location.
626 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
629 /// Build 'default' clause with argument \a A ('none' or 'shared').
631 /// \param A Argument of the clause ('none' or 'shared').
632 /// \param ALoc Starting location of the argument.
633 /// \param StartLoc Starting location of the clause.
634 /// \param LParenLoc Location of '('.
635 /// \param EndLoc Ending location of the clause.
636 OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
637 SourceLocation StartLoc, SourceLocation LParenLoc,
638 SourceLocation EndLoc)
639 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
640 Kind(A), KindKwLoc(ALoc) {}
642 /// Build an empty clause.
644 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()) {}
646 /// Sets the location of '('.
647 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
649 /// Returns the location of '('.
650 SourceLocation getLParenLoc() const { return LParenLoc; }
652 /// Returns kind of the clause.
653 OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
655 /// Returns location of clause kind.
656 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
658 child_range children() {
659 return child_range(child_iterator(), child_iterator());
662 static bool classof(const OMPClause *T) {
663 return T->getClauseKind() == OMPC_default;
667 /// This represents 'proc_bind' clause in the '#pragma omp ...'
671 /// #pragma omp parallel proc_bind(master)
673 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
674 /// clause with kind 'master'.
675 class OMPProcBindClause : public OMPClause {
676 friend class OMPClauseReader;
679 SourceLocation LParenLoc;
681 /// A kind of the 'proc_bind' clause.
682 OpenMPProcBindClauseKind Kind = OMPC_PROC_BIND_unknown;
684 /// Start location of the kind in source code.
685 SourceLocation KindKwLoc;
687 /// Set kind of the clause.
689 /// \param K Kind of clause.
690 void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
692 /// Set clause kind location.
694 /// \param KLoc Kind location.
695 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
698 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
701 /// \param A Argument of the clause ('master', 'close' or 'spread').
702 /// \param ALoc Starting location of the argument.
703 /// \param StartLoc Starting location of the clause.
704 /// \param LParenLoc Location of '('.
705 /// \param EndLoc Ending location of the clause.
706 OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
707 SourceLocation StartLoc, SourceLocation LParenLoc,
708 SourceLocation EndLoc)
709 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
710 Kind(A), KindKwLoc(ALoc) {}
712 /// Build an empty clause.
714 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()) {}
716 /// Sets the location of '('.
717 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
719 /// Returns the location of '('.
720 SourceLocation getLParenLoc() const { return LParenLoc; }
722 /// Returns kind of the clause.
723 OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
725 /// Returns location of clause kind.
726 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
728 child_range children() {
729 return child_range(child_iterator(), child_iterator());
732 static bool classof(const OMPClause *T) {
733 return T->getClauseKind() == OMPC_proc_bind;
737 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
740 /// #pragma omp for schedule(static, 3)
742 /// In this example directive '#pragma omp for' has 'schedule' clause with
743 /// arguments 'static' and '3'.
744 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
745 friend class OMPClauseReader;
748 SourceLocation LParenLoc;
750 /// A kind of the 'schedule' clause.
751 OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
753 /// Modifiers for 'schedule' clause.
754 enum {FIRST, SECOND, NUM_MODIFIERS};
755 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
757 /// Locations of modifiers.
758 SourceLocation ModifiersLoc[NUM_MODIFIERS];
760 /// Start location of the schedule ind in source code.
761 SourceLocation KindLoc;
763 /// Location of ',' (if any).
764 SourceLocation CommaLoc;
767 Expr *ChunkSize = nullptr;
769 /// Set schedule kind.
771 /// \param K Schedule kind.
772 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
774 /// Set the first schedule modifier.
776 /// \param M Schedule modifier.
777 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
778 Modifiers[FIRST] = M;
781 /// Set the second schedule modifier.
783 /// \param M Schedule modifier.
784 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
785 Modifiers[SECOND] = M;
788 /// Set location of the first schedule modifier.
789 void setFirstScheduleModifierLoc(SourceLocation Loc) {
790 ModifiersLoc[FIRST] = Loc;
793 /// Set location of the second schedule modifier.
794 void setSecondScheduleModifierLoc(SourceLocation Loc) {
795 ModifiersLoc[SECOND] = Loc;
798 /// Set schedule modifier location.
800 /// \param M Schedule modifier location.
801 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
802 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
803 Modifiers[FIRST] = M;
805 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
806 Modifiers[SECOND] = M;
810 /// Sets the location of '('.
812 /// \param Loc Location of '('.
813 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
815 /// Set schedule kind start location.
817 /// \param KLoc Schedule kind location.
818 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
820 /// Set location of ','.
822 /// \param Loc Location of ','.
823 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
827 /// \param E Chunk size.
828 void setChunkSize(Expr *E) { ChunkSize = E; }
831 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
832 /// expression \a ChunkSize.
834 /// \param StartLoc Starting location of the clause.
835 /// \param LParenLoc Location of '('.
836 /// \param KLoc Starting location of the argument.
837 /// \param CommaLoc Location of ','.
838 /// \param EndLoc Ending location of the clause.
839 /// \param Kind Schedule kind.
840 /// \param ChunkSize Chunk size.
841 /// \param HelperChunkSize Helper chunk size for combined directives.
842 /// \param M1 The first modifier applied to 'schedule' clause.
843 /// \param M1Loc Location of the first modifier
844 /// \param M2 The second modifier applied to 'schedule' clause.
845 /// \param M2Loc Location of the second modifier
846 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
847 SourceLocation KLoc, SourceLocation CommaLoc,
848 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
849 Expr *ChunkSize, Stmt *HelperChunkSize,
850 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
851 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
852 : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this),
853 LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc),
854 ChunkSize(ChunkSize) {
855 setPreInitStmt(HelperChunkSize);
856 Modifiers[FIRST] = M1;
857 Modifiers[SECOND] = M2;
858 ModifiersLoc[FIRST] = M1Loc;
859 ModifiersLoc[SECOND] = M2Loc;
862 /// Build an empty clause.
863 explicit OMPScheduleClause()
864 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
865 OMPClauseWithPreInit(this) {
866 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
867 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
870 /// Get kind of the clause.
871 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
873 /// Get the first modifier of the clause.
874 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
875 return Modifiers[FIRST];
878 /// Get the second modifier of the clause.
879 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
880 return Modifiers[SECOND];
883 /// Get location of '('.
884 SourceLocation getLParenLoc() { return LParenLoc; }
886 /// Get kind location.
887 SourceLocation getScheduleKindLoc() { return KindLoc; }
889 /// Get the first modifier location.
890 SourceLocation getFirstScheduleModifierLoc() const {
891 return ModifiersLoc[FIRST];
894 /// Get the second modifier location.
895 SourceLocation getSecondScheduleModifierLoc() const {
896 return ModifiersLoc[SECOND];
899 /// Get location of ','.
900 SourceLocation getCommaLoc() { return CommaLoc; }
903 Expr *getChunkSize() { return ChunkSize; }
906 const Expr *getChunkSize() const { return ChunkSize; }
908 child_range children() {
909 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
910 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
913 static bool classof(const OMPClause *T) {
914 return T->getClauseKind() == OMPC_schedule;
918 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
921 /// #pragma omp for ordered (2)
923 /// In this example directive '#pragma omp for' has 'ordered' clause with
925 class OMPOrderedClause : public OMPClause {
926 friend class OMPClauseReader;
929 SourceLocation LParenLoc;
931 /// Number of for-loops.
932 Stmt *NumForLoops = nullptr;
934 /// Set the number of associated for-loops.
935 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
938 /// Build 'ordered' clause.
940 /// \param Num Expression, possibly associated with this clause.
941 /// \param StartLoc Starting location of the clause.
942 /// \param LParenLoc Location of '('.
943 /// \param EndLoc Ending location of the clause.
944 OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
945 SourceLocation LParenLoc, SourceLocation EndLoc)
946 : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
949 /// Build an empty clause.
950 explicit OMPOrderedClause()
951 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
953 /// Sets the location of '('.
954 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
956 /// Returns the location of '('.
957 SourceLocation getLParenLoc() const { return LParenLoc; }
959 /// Return the number of associated for-loops.
960 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
962 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
964 static bool classof(const OMPClause *T) {
965 return T->getClauseKind() == OMPC_ordered;
969 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
972 /// #pragma omp for nowait
974 /// In this example directive '#pragma omp for' has 'nowait' clause.
975 class OMPNowaitClause : public OMPClause {
977 /// Build 'nowait' clause.
979 /// \param StartLoc Starting location of the clause.
980 /// \param EndLoc Ending location of the clause.
981 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
982 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
984 /// Build an empty clause.
986 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
988 child_range children() {
989 return child_range(child_iterator(), child_iterator());
992 static bool classof(const OMPClause *T) {
993 return T->getClauseKind() == OMPC_nowait;
997 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1000 /// #pragma omp task untied
1002 /// In this example directive '#pragma omp task' has 'untied' clause.
1003 class OMPUntiedClause : public OMPClause {
1005 /// Build 'untied' clause.
1007 /// \param StartLoc Starting location of the clause.
1008 /// \param EndLoc Ending location of the clause.
1009 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
1010 : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
1012 /// Build an empty clause.
1014 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
1016 child_range children() {
1017 return child_range(child_iterator(), child_iterator());
1020 static bool classof(const OMPClause *T) {
1021 return T->getClauseKind() == OMPC_untied;
1025 /// This represents 'mergeable' clause in the '#pragma omp ...'
1029 /// #pragma omp task mergeable
1031 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1032 class OMPMergeableClause : public OMPClause {
1034 /// Build 'mergeable' clause.
1036 /// \param StartLoc Starting location of the clause.
1037 /// \param EndLoc Ending location of the clause.
1038 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
1039 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
1041 /// Build an empty clause.
1042 OMPMergeableClause()
1043 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
1045 child_range children() {
1046 return child_range(child_iterator(), child_iterator());
1049 static bool classof(const OMPClause *T) {
1050 return T->getClauseKind() == OMPC_mergeable;
1054 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1057 /// #pragma omp atomic read
1059 /// In this example directive '#pragma omp atomic' has 'read' clause.
1060 class OMPReadClause : public OMPClause {
1062 /// Build 'read' clause.
1064 /// \param StartLoc Starting location of the clause.
1065 /// \param EndLoc Ending location of the clause.
1066 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1067 : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1069 /// Build an empty clause.
1070 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1072 child_range children() {
1073 return child_range(child_iterator(), child_iterator());
1076 static bool classof(const OMPClause *T) {
1077 return T->getClauseKind() == OMPC_read;
1081 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1084 /// #pragma omp atomic write
1086 /// In this example directive '#pragma omp atomic' has 'write' clause.
1087 class OMPWriteClause : public OMPClause {
1089 /// Build 'write' clause.
1091 /// \param StartLoc Starting location of the clause.
1092 /// \param EndLoc Ending location of the clause.
1093 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1094 : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1096 /// Build an empty clause.
1098 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1100 child_range children() {
1101 return child_range(child_iterator(), child_iterator());
1104 static bool classof(const OMPClause *T) {
1105 return T->getClauseKind() == OMPC_write;
1109 /// This represents 'update' clause in the '#pragma omp atomic'
1113 /// #pragma omp atomic update
1115 /// In this example directive '#pragma omp atomic' has 'update' clause.
1116 class OMPUpdateClause : public OMPClause {
1118 /// Build 'update' clause.
1120 /// \param StartLoc Starting location of the clause.
1121 /// \param EndLoc Ending location of the clause.
1122 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
1123 : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1125 /// Build an empty clause.
1127 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1129 child_range children() {
1130 return child_range(child_iterator(), child_iterator());
1133 static bool classof(const OMPClause *T) {
1134 return T->getClauseKind() == OMPC_update;
1138 /// This represents 'capture' clause in the '#pragma omp atomic'
1142 /// #pragma omp atomic capture
1144 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1145 class OMPCaptureClause : public OMPClause {
1147 /// Build 'capture' clause.
1149 /// \param StartLoc Starting location of the clause.
1150 /// \param EndLoc Ending location of the clause.
1151 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1152 : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1154 /// Build an empty clause.
1156 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1158 child_range children() {
1159 return child_range(child_iterator(), child_iterator());
1162 static bool classof(const OMPClause *T) {
1163 return T->getClauseKind() == OMPC_capture;
1167 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
1171 /// #pragma omp atomic seq_cst
1173 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1174 class OMPSeqCstClause : public OMPClause {
1176 /// Build 'seq_cst' clause.
1178 /// \param StartLoc Starting location of the clause.
1179 /// \param EndLoc Ending location of the clause.
1180 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1181 : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1183 /// Build an empty clause.
1185 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1187 child_range children() {
1188 return child_range(child_iterator(), child_iterator());
1191 static bool classof(const OMPClause *T) {
1192 return T->getClauseKind() == OMPC_seq_cst;
1196 /// This represents clause 'private' in the '#pragma omp ...' directives.
1199 /// #pragma omp parallel private(a,b)
1201 /// In this example directive '#pragma omp parallel' has clause 'private'
1202 /// with the variables 'a' and 'b'.
1203 class OMPPrivateClause final
1204 : public OMPVarListClause<OMPPrivateClause>,
1205 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1206 friend class OMPClauseReader;
1207 friend OMPVarListClause;
1208 friend TrailingObjects;
1210 /// Build clause with number of variables \a N.
1212 /// \param StartLoc Starting location of the clause.
1213 /// \param LParenLoc Location of '('.
1214 /// \param EndLoc Ending location of the clause.
1215 /// \param N Number of the variables in the clause.
1216 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1217 SourceLocation EndLoc, unsigned N)
1218 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1221 /// Build an empty clause.
1223 /// \param N Number of variables.
1224 explicit OMPPrivateClause(unsigned N)
1225 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
1226 SourceLocation(), SourceLocation(),
1229 /// Sets the list of references to private copies with initializers for
1230 /// new private variables.
1231 /// \param VL List of references.
1232 void setPrivateCopies(ArrayRef<Expr *> VL);
1234 /// Gets the list of references to private copies with initializers for
1235 /// new private variables.
1236 MutableArrayRef<Expr *> getPrivateCopies() {
1237 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1239 ArrayRef<const Expr *> getPrivateCopies() const {
1240 return llvm::makeArrayRef(varlist_end(), varlist_size());
1244 /// Creates clause with a list of variables \a VL.
1246 /// \param C AST context.
1247 /// \param StartLoc Starting location of the clause.
1248 /// \param LParenLoc Location of '('.
1249 /// \param EndLoc Ending location of the clause.
1250 /// \param VL List of references to the variables.
1251 /// \param PrivateVL List of references to private copies with initializers.
1252 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1253 SourceLocation LParenLoc,
1254 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1255 ArrayRef<Expr *> PrivateVL);
1257 /// Creates an empty clause with the place for \a N variables.
1259 /// \param C AST context.
1260 /// \param N The number of variables.
1261 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1263 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
1264 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
1265 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1266 using private_copies_const_range =
1267 llvm::iterator_range<private_copies_const_iterator>;
1269 private_copies_range private_copies() {
1270 return private_copies_range(getPrivateCopies().begin(),
1271 getPrivateCopies().end());
1274 private_copies_const_range private_copies() const {
1275 return private_copies_const_range(getPrivateCopies().begin(),
1276 getPrivateCopies().end());
1279 child_range children() {
1280 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1281 reinterpret_cast<Stmt **>(varlist_end()));
1284 static bool classof(const OMPClause *T) {
1285 return T->getClauseKind() == OMPC_private;
1289 /// This represents clause 'firstprivate' in the '#pragma omp ...'
1293 /// #pragma omp parallel firstprivate(a,b)
1295 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1296 /// with the variables 'a' and 'b'.
1297 class OMPFirstprivateClause final
1298 : public OMPVarListClause<OMPFirstprivateClause>,
1299 public OMPClauseWithPreInit,
1300 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1301 friend class OMPClauseReader;
1302 friend OMPVarListClause;
1303 friend TrailingObjects;
1305 /// Build clause with number of variables \a N.
1307 /// \param StartLoc Starting location of the clause.
1308 /// \param LParenLoc Location of '('.
1309 /// \param EndLoc Ending location of the clause.
1310 /// \param N Number of the variables in the clause.
1311 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1312 SourceLocation EndLoc, unsigned N)
1313 : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1314 LParenLoc, EndLoc, N),
1315 OMPClauseWithPreInit(this) {}
1317 /// Build an empty clause.
1319 /// \param N Number of variables.
1320 explicit OMPFirstprivateClause(unsigned N)
1321 : OMPVarListClause<OMPFirstprivateClause>(
1322 OMPC_firstprivate, SourceLocation(), SourceLocation(),
1323 SourceLocation(), N),
1324 OMPClauseWithPreInit(this) {}
1326 /// Sets the list of references to private copies with initializers for
1327 /// new private variables.
1328 /// \param VL List of references.
1329 void setPrivateCopies(ArrayRef<Expr *> VL);
1331 /// Gets the list of references to private copies with initializers for
1332 /// new private variables.
1333 MutableArrayRef<Expr *> getPrivateCopies() {
1334 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1336 ArrayRef<const Expr *> getPrivateCopies() const {
1337 return llvm::makeArrayRef(varlist_end(), varlist_size());
1340 /// Sets the list of references to initializer variables for new
1341 /// private variables.
1342 /// \param VL List of references.
1343 void setInits(ArrayRef<Expr *> VL);
1345 /// Gets the list of references to initializer variables for new
1346 /// private variables.
1347 MutableArrayRef<Expr *> getInits() {
1348 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1350 ArrayRef<const Expr *> getInits() const {
1351 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1355 /// Creates clause with a list of variables \a VL.
1357 /// \param C AST context.
1358 /// \param StartLoc Starting location of the clause.
1359 /// \param LParenLoc Location of '('.
1360 /// \param EndLoc Ending location of the clause.
1361 /// \param VL List of references to the original variables.
1362 /// \param PrivateVL List of references to private copies with initializers.
1363 /// \param InitVL List of references to auto generated variables used for
1364 /// initialization of a single array element. Used if firstprivate variable is
1366 /// \param PreInit Statement that must be executed before entering the OpenMP
1367 /// region with this clause.
1368 static OMPFirstprivateClause *
1369 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1370 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1371 ArrayRef<Expr *> InitVL, Stmt *PreInit);
1373 /// Creates an empty clause with the place for \a N variables.
1375 /// \param C AST context.
1376 /// \param N The number of variables.
1377 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1379 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
1380 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
1381 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1382 using private_copies_const_range =
1383 llvm::iterator_range<private_copies_const_iterator>;
1385 private_copies_range private_copies() {
1386 return private_copies_range(getPrivateCopies().begin(),
1387 getPrivateCopies().end());
1389 private_copies_const_range private_copies() const {
1390 return private_copies_const_range(getPrivateCopies().begin(),
1391 getPrivateCopies().end());
1394 using inits_iterator = MutableArrayRef<Expr *>::iterator;
1395 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
1396 using inits_range = llvm::iterator_range<inits_iterator>;
1397 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
1399 inits_range inits() {
1400 return inits_range(getInits().begin(), getInits().end());
1402 inits_const_range inits() const {
1403 return inits_const_range(getInits().begin(), getInits().end());
1406 child_range children() {
1407 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1408 reinterpret_cast<Stmt **>(varlist_end()));
1411 static bool classof(const OMPClause *T) {
1412 return T->getClauseKind() == OMPC_firstprivate;
1416 /// This represents clause 'lastprivate' in the '#pragma omp ...'
1420 /// #pragma omp simd lastprivate(a,b)
1422 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1423 /// with the variables 'a' and 'b'.
1424 class OMPLastprivateClause final
1425 : public OMPVarListClause<OMPLastprivateClause>,
1426 public OMPClauseWithPostUpdate,
1427 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
1428 // There are 4 additional tail-allocated arrays at the end of the class:
1429 // 1. Contains list of pseudo variables with the default initialization for
1430 // each non-firstprivate variables. Used in codegen for initialization of
1431 // lastprivate copies.
1432 // 2. List of helper expressions for proper generation of assignment operation
1433 // required for lastprivate clause. This list represents private variables
1434 // (for arrays, single array element).
1435 // 3. List of helper expressions for proper generation of assignment operation
1436 // required for lastprivate clause. This list represents original variables
1437 // (for arrays, single array element).
1438 // 4. List of helper expressions that represents assignment operation:
1440 // DstExprs = SrcExprs;
1442 // Required for proper codegen of final assignment performed by the
1443 // lastprivate clause.
1444 friend class OMPClauseReader;
1445 friend OMPVarListClause;
1446 friend TrailingObjects;
1448 /// Build clause with number of variables \a N.
1450 /// \param StartLoc Starting location of the clause.
1451 /// \param LParenLoc Location of '('.
1452 /// \param EndLoc Ending location of the clause.
1453 /// \param N Number of the variables in the clause.
1454 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1455 SourceLocation EndLoc, unsigned N)
1456 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1457 LParenLoc, EndLoc, N),
1458 OMPClauseWithPostUpdate(this) {}
1460 /// Build an empty clause.
1462 /// \param N Number of variables.
1463 explicit OMPLastprivateClause(unsigned N)
1464 : OMPVarListClause<OMPLastprivateClause>(
1465 OMPC_lastprivate, SourceLocation(), SourceLocation(),
1466 SourceLocation(), N),
1467 OMPClauseWithPostUpdate(this) {}
1469 /// Get the list of helper expressions for initialization of private
1470 /// copies for lastprivate variables.
1471 MutableArrayRef<Expr *> getPrivateCopies() {
1472 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1474 ArrayRef<const Expr *> getPrivateCopies() const {
1475 return llvm::makeArrayRef(varlist_end(), varlist_size());
1478 /// Set list of helper expressions, required for proper codegen of the
1479 /// clause. These expressions represent private variables (for arrays, single
1480 /// array element) in the final assignment statement performed by the
1481 /// lastprivate clause.
1482 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1484 /// Get the list of helper source expressions.
1485 MutableArrayRef<Expr *> getSourceExprs() {
1486 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1488 ArrayRef<const Expr *> getSourceExprs() const {
1489 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1492 /// Set list of helper expressions, required for proper codegen of the
1493 /// clause. These expressions represent original variables (for arrays, single
1494 /// array element) in the final assignment statement performed by the
1495 /// lastprivate clause.
1496 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1498 /// Get the list of helper destination expressions.
1499 MutableArrayRef<Expr *> getDestinationExprs() {
1500 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1502 ArrayRef<const Expr *> getDestinationExprs() const {
1503 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1506 /// Set list of helper assignment expressions, required for proper
1507 /// codegen of the clause. These expressions are assignment expressions that
1508 /// assign private copy of the variable to original variable.
1509 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1511 /// Get the list of helper assignment expressions.
1512 MutableArrayRef<Expr *> getAssignmentOps() {
1513 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1515 ArrayRef<const Expr *> getAssignmentOps() const {
1516 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1520 /// Creates clause with a list of variables \a VL.
1522 /// \param C AST context.
1523 /// \param StartLoc Starting location of the clause.
1524 /// \param LParenLoc Location of '('.
1525 /// \param EndLoc Ending location of the clause.
1526 /// \param VL List of references to the variables.
1527 /// \param SrcExprs List of helper expressions for proper generation of
1528 /// assignment operation required for lastprivate clause. This list represents
1529 /// private variables (for arrays, single array element).
1530 /// \param DstExprs List of helper expressions for proper generation of
1531 /// assignment operation required for lastprivate clause. This list represents
1532 /// original variables (for arrays, single array element).
1533 /// \param AssignmentOps List of helper expressions that represents assignment
1536 /// DstExprs = SrcExprs;
1538 /// Required for proper codegen of final assignment performed by the
1539 /// lastprivate clause.
1540 /// \param PreInit Statement that must be executed before entering the OpenMP
1541 /// region with this clause.
1542 /// \param PostUpdate Expression that must be executed after exit from the
1543 /// OpenMP region with this clause.
1544 static OMPLastprivateClause *
1545 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1546 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1547 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
1548 Stmt *PreInit, Expr *PostUpdate);
1550 /// Creates an empty clause with the place for \a N variables.
1552 /// \param C AST context.
1553 /// \param N The number of variables.
1554 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1556 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
1557 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
1558 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
1559 using helper_expr_const_range =
1560 llvm::iterator_range<helper_expr_const_iterator>;
1562 /// Set list of helper expressions, required for generation of private
1563 /// copies of original lastprivate variables.
1564 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1566 helper_expr_const_range private_copies() const {
1567 return helper_expr_const_range(getPrivateCopies().begin(),
1568 getPrivateCopies().end());
1571 helper_expr_range private_copies() {
1572 return helper_expr_range(getPrivateCopies().begin(),
1573 getPrivateCopies().end());
1576 helper_expr_const_range source_exprs() const {
1577 return helper_expr_const_range(getSourceExprs().begin(),
1578 getSourceExprs().end());
1581 helper_expr_range source_exprs() {
1582 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1585 helper_expr_const_range destination_exprs() const {
1586 return helper_expr_const_range(getDestinationExprs().begin(),
1587 getDestinationExprs().end());
1590 helper_expr_range destination_exprs() {
1591 return helper_expr_range(getDestinationExprs().begin(),
1592 getDestinationExprs().end());
1595 helper_expr_const_range assignment_ops() const {
1596 return helper_expr_const_range(getAssignmentOps().begin(),
1597 getAssignmentOps().end());
1600 helper_expr_range assignment_ops() {
1601 return helper_expr_range(getAssignmentOps().begin(),
1602 getAssignmentOps().end());
1605 child_range children() {
1606 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1607 reinterpret_cast<Stmt **>(varlist_end()));
1610 static bool classof(const OMPClause *T) {
1611 return T->getClauseKind() == OMPC_lastprivate;
1615 /// This represents clause 'shared' in the '#pragma omp ...' directives.
1618 /// #pragma omp parallel shared(a,b)
1620 /// In this example directive '#pragma omp parallel' has clause 'shared'
1621 /// with the variables 'a' and 'b'.
1622 class OMPSharedClause final
1623 : public OMPVarListClause<OMPSharedClause>,
1624 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
1625 friend OMPVarListClause;
1626 friend TrailingObjects;
1628 /// Build clause with number of variables \a N.
1630 /// \param StartLoc Starting location of the clause.
1631 /// \param LParenLoc Location of '('.
1632 /// \param EndLoc Ending location of the clause.
1633 /// \param N Number of the variables in the clause.
1634 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1635 SourceLocation EndLoc, unsigned N)
1636 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1639 /// Build an empty clause.
1641 /// \param N Number of variables.
1642 explicit OMPSharedClause(unsigned N)
1643 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1644 SourceLocation(), SourceLocation(),
1648 /// Creates clause with a list of variables \a VL.
1650 /// \param C AST context.
1651 /// \param StartLoc Starting location of the clause.
1652 /// \param LParenLoc Location of '('.
1653 /// \param EndLoc Ending location of the clause.
1654 /// \param VL List of references to the variables.
1655 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1656 SourceLocation LParenLoc,
1657 SourceLocation EndLoc, ArrayRef<Expr *> VL);
1659 /// Creates an empty clause with \a N variables.
1661 /// \param C AST context.
1662 /// \param N The number of variables.
1663 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1665 child_range children() {
1666 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1667 reinterpret_cast<Stmt **>(varlist_end()));
1670 static bool classof(const OMPClause *T) {
1671 return T->getClauseKind() == OMPC_shared;
1675 /// This represents clause 'reduction' in the '#pragma omp ...'
1679 /// #pragma omp parallel reduction(+:a,b)
1681 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1682 /// with operator '+' and the variables 'a' and 'b'.
1683 class OMPReductionClause final
1684 : public OMPVarListClause<OMPReductionClause>,
1685 public OMPClauseWithPostUpdate,
1686 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
1687 friend class OMPClauseReader;
1688 friend OMPVarListClause;
1689 friend TrailingObjects;
1691 /// Location of ':'.
1692 SourceLocation ColonLoc;
1694 /// Nested name specifier for C++.
1695 NestedNameSpecifierLoc QualifierLoc;
1697 /// Name of custom operator.
1698 DeclarationNameInfo NameInfo;
1700 /// Build clause with number of variables \a N.
1702 /// \param StartLoc Starting location of the clause.
1703 /// \param LParenLoc Location of '('.
1704 /// \param EndLoc Ending location of the clause.
1705 /// \param ColonLoc Location of ':'.
1706 /// \param N Number of the variables in the clause.
1707 /// \param QualifierLoc The nested-name qualifier with location information
1708 /// \param NameInfo The full name info for reduction identifier.
1709 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1710 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1711 NestedNameSpecifierLoc QualifierLoc,
1712 const DeclarationNameInfo &NameInfo)
1713 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1714 LParenLoc, EndLoc, N),
1715 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
1716 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1718 /// Build an empty clause.
1720 /// \param N Number of variables.
1721 explicit OMPReductionClause(unsigned N)
1722 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1723 SourceLocation(), SourceLocation(),
1725 OMPClauseWithPostUpdate(this) {}
1727 /// Sets location of ':' symbol in clause.
1728 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1730 /// Sets the name info for specified reduction identifier.
1731 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1733 /// Sets the nested name specifier.
1734 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1736 /// Set list of helper expressions, required for proper codegen of the
1737 /// clause. These expressions represent private copy of the reduction
1739 void setPrivates(ArrayRef<Expr *> Privates);
1741 /// Get the list of helper privates.
1742 MutableArrayRef<Expr *> getPrivates() {
1743 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1745 ArrayRef<const Expr *> getPrivates() const {
1746 return llvm::makeArrayRef(varlist_end(), varlist_size());
1749 /// Set list of helper expressions, required for proper codegen of the
1750 /// clause. These expressions represent LHS expression in the final
1751 /// reduction expression performed by the reduction clause.
1752 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1754 /// Get the list of helper LHS expressions.
1755 MutableArrayRef<Expr *> getLHSExprs() {
1756 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1758 ArrayRef<const Expr *> getLHSExprs() const {
1759 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1762 /// Set list of helper expressions, required for proper codegen of the
1763 /// clause. These expressions represent RHS expression in the final
1764 /// reduction expression performed by the reduction clause.
1765 /// Also, variables in these expressions are used for proper initialization of
1766 /// reduction copies.
1767 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1769 /// Get the list of helper destination expressions.
1770 MutableArrayRef<Expr *> getRHSExprs() {
1771 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1773 ArrayRef<const Expr *> getRHSExprs() const {
1774 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1777 /// Set list of helper reduction expressions, required for proper
1778 /// codegen of the clause. These expressions are binary expressions or
1779 /// operator/custom reduction call that calculates new value from source
1780 /// helper expressions to destination helper expressions.
1781 void setReductionOps(ArrayRef<Expr *> ReductionOps);
1783 /// Get the list of helper reduction expressions.
1784 MutableArrayRef<Expr *> getReductionOps() {
1785 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1787 ArrayRef<const Expr *> getReductionOps() const {
1788 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1792 /// Creates clause with a list of variables \a VL.
1794 /// \param StartLoc Starting location of the clause.
1795 /// \param LParenLoc Location of '('.
1796 /// \param ColonLoc Location of ':'.
1797 /// \param EndLoc Ending location of the clause.
1798 /// \param VL The variables in the clause.
1799 /// \param QualifierLoc The nested-name qualifier with location information
1800 /// \param NameInfo The full name info for reduction identifier.
1801 /// \param Privates List of helper expressions for proper generation of
1803 /// \param LHSExprs List of helper expressions for proper generation of
1804 /// assignment operation required for copyprivate clause. This list represents
1805 /// LHSs of the reduction expressions.
1806 /// \param RHSExprs List of helper expressions for proper generation of
1807 /// assignment operation required for copyprivate clause. This list represents
1808 /// RHSs of the reduction expressions.
1809 /// Also, variables in these expressions are used for proper initialization of
1810 /// reduction copies.
1811 /// \param ReductionOps List of helper expressions that represents reduction
1814 /// LHSExprs binop RHSExprs;
1815 /// operator binop(LHSExpr, RHSExpr);
1816 /// <CutomReduction>(LHSExpr, RHSExpr);
1818 /// Required for proper codegen of final reduction operation performed by the
1819 /// reduction clause.
1820 /// \param PreInit Statement that must be executed before entering the OpenMP
1821 /// region with this clause.
1822 /// \param PostUpdate Expression that must be executed after exit from the
1823 /// OpenMP region with this clause.
1824 static OMPReductionClause *
1825 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1826 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1827 NestedNameSpecifierLoc QualifierLoc,
1828 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
1829 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1830 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
1832 /// Creates an empty clause with the place for \a N variables.
1834 /// \param C AST context.
1835 /// \param N The number of variables.
1836 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1838 /// Gets location of ':' symbol in clause.
1839 SourceLocation getColonLoc() const { return ColonLoc; }
1841 /// Gets the name info for specified reduction identifier.
1842 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1844 /// Gets the nested name specifier.
1845 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1847 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
1848 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
1849 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
1850 using helper_expr_const_range =
1851 llvm::iterator_range<helper_expr_const_iterator>;
1853 helper_expr_const_range privates() const {
1854 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
1857 helper_expr_range privates() {
1858 return helper_expr_range(getPrivates().begin(), getPrivates().end());
1861 helper_expr_const_range lhs_exprs() const {
1862 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
1865 helper_expr_range lhs_exprs() {
1866 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
1869 helper_expr_const_range rhs_exprs() const {
1870 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
1873 helper_expr_range rhs_exprs() {
1874 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
1877 helper_expr_const_range reduction_ops() const {
1878 return helper_expr_const_range(getReductionOps().begin(),
1879 getReductionOps().end());
1882 helper_expr_range reduction_ops() {
1883 return helper_expr_range(getReductionOps().begin(),
1884 getReductionOps().end());
1887 child_range children() {
1888 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1889 reinterpret_cast<Stmt **>(varlist_end()));
1892 static bool classof(const OMPClause *T) {
1893 return T->getClauseKind() == OMPC_reduction;
1897 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
1901 /// #pragma omp taskgroup task_reduction(+:a,b)
1903 /// In this example directive '#pragma omp taskgroup' has clause
1904 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
1905 class OMPTaskReductionClause final
1906 : public OMPVarListClause<OMPTaskReductionClause>,
1907 public OMPClauseWithPostUpdate,
1908 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
1909 friend class OMPClauseReader;
1910 friend OMPVarListClause;
1911 friend TrailingObjects;
1913 /// Location of ':'.
1914 SourceLocation ColonLoc;
1916 /// Nested name specifier for C++.
1917 NestedNameSpecifierLoc QualifierLoc;
1919 /// Name of custom operator.
1920 DeclarationNameInfo NameInfo;
1922 /// Build clause with number of variables \a N.
1924 /// \param StartLoc Starting location of the clause.
1925 /// \param LParenLoc Location of '('.
1926 /// \param EndLoc Ending location of the clause.
1927 /// \param ColonLoc Location of ':'.
1928 /// \param N Number of the variables in the clause.
1929 /// \param QualifierLoc The nested-name qualifier with location information
1930 /// \param NameInfo The full name info for reduction identifier.
1931 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1932 SourceLocation ColonLoc, SourceLocation EndLoc,
1933 unsigned N, NestedNameSpecifierLoc QualifierLoc,
1934 const DeclarationNameInfo &NameInfo)
1935 : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
1936 LParenLoc, EndLoc, N),
1937 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
1938 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1940 /// Build an empty clause.
1942 /// \param N Number of variables.
1943 explicit OMPTaskReductionClause(unsigned N)
1944 : OMPVarListClause<OMPTaskReductionClause>(
1945 OMPC_task_reduction, SourceLocation(), SourceLocation(),
1946 SourceLocation(), N),
1947 OMPClauseWithPostUpdate(this) {}
1949 /// Sets location of ':' symbol in clause.
1950 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1952 /// Sets the name info for specified reduction identifier.
1953 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1955 /// Sets the nested name specifier.
1956 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1958 /// Set list of helper expressions, required for proper codegen of the clause.
1959 /// These expressions represent private copy of the reduction variable.
1960 void setPrivates(ArrayRef<Expr *> Privates);
1962 /// Get the list of helper privates.
1963 MutableArrayRef<Expr *> getPrivates() {
1964 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1966 ArrayRef<const Expr *> getPrivates() const {
1967 return llvm::makeArrayRef(varlist_end(), varlist_size());
1970 /// Set list of helper expressions, required for proper codegen of the clause.
1971 /// These expressions represent LHS expression in the final reduction
1972 /// expression performed by the reduction clause.
1973 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1975 /// Get the list of helper LHS expressions.
1976 MutableArrayRef<Expr *> getLHSExprs() {
1977 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1979 ArrayRef<const Expr *> getLHSExprs() const {
1980 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1983 /// Set list of helper expressions, required for proper codegen of the clause.
1984 /// These expressions represent RHS expression in the final reduction
1985 /// expression performed by the reduction clause. Also, variables in these
1986 /// expressions are used for proper initialization of reduction copies.
1987 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1989 /// Get the list of helper destination expressions.
1990 MutableArrayRef<Expr *> getRHSExprs() {
1991 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1993 ArrayRef<const Expr *> getRHSExprs() const {
1994 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1997 /// Set list of helper reduction expressions, required for proper
1998 /// codegen of the clause. These expressions are binary expressions or
1999 /// operator/custom reduction call that calculates new value from source
2000 /// helper expressions to destination helper expressions.
2001 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2003 /// Get the list of helper reduction expressions.
2004 MutableArrayRef<Expr *> getReductionOps() {
2005 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2007 ArrayRef<const Expr *> getReductionOps() const {
2008 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2012 /// Creates clause with a list of variables \a VL.
2014 /// \param StartLoc Starting location of the clause.
2015 /// \param LParenLoc Location of '('.
2016 /// \param ColonLoc Location of ':'.
2017 /// \param EndLoc Ending location of the clause.
2018 /// \param VL The variables in the clause.
2019 /// \param QualifierLoc The nested-name qualifier with location information
2020 /// \param NameInfo The full name info for reduction identifier.
2021 /// \param Privates List of helper expressions for proper generation of
2023 /// \param LHSExprs List of helper expressions for proper generation of
2024 /// assignment operation required for copyprivate clause. This list represents
2025 /// LHSs of the reduction expressions.
2026 /// \param RHSExprs List of helper expressions for proper generation of
2027 /// assignment operation required for copyprivate clause. This list represents
2028 /// RHSs of the reduction expressions.
2029 /// Also, variables in these expressions are used for proper initialization of
2030 /// reduction copies.
2031 /// \param ReductionOps List of helper expressions that represents reduction
2034 /// LHSExprs binop RHSExprs;
2035 /// operator binop(LHSExpr, RHSExpr);
2036 /// <CutomReduction>(LHSExpr, RHSExpr);
2038 /// Required for proper codegen of final reduction operation performed by the
2039 /// reduction clause.
2040 /// \param PreInit Statement that must be executed before entering the OpenMP
2041 /// region with this clause.
2042 /// \param PostUpdate Expression that must be executed after exit from the
2043 /// OpenMP region with this clause.
2044 static OMPTaskReductionClause *
2045 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2046 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2047 NestedNameSpecifierLoc QualifierLoc,
2048 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2049 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2050 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2052 /// Creates an empty clause with the place for \a N variables.
2054 /// \param C AST context.
2055 /// \param N The number of variables.
2056 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2058 /// Gets location of ':' symbol in clause.
2059 SourceLocation getColonLoc() const { return ColonLoc; }
2061 /// Gets the name info for specified reduction identifier.
2062 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2064 /// Gets the nested name specifier.
2065 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2067 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2068 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2069 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2070 using helper_expr_const_range =
2071 llvm::iterator_range<helper_expr_const_iterator>;
2073 helper_expr_const_range privates() const {
2074 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2077 helper_expr_range privates() {
2078 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2081 helper_expr_const_range lhs_exprs() const {
2082 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2085 helper_expr_range lhs_exprs() {
2086 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2089 helper_expr_const_range rhs_exprs() const {
2090 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2093 helper_expr_range rhs_exprs() {
2094 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2097 helper_expr_const_range reduction_ops() const {
2098 return helper_expr_const_range(getReductionOps().begin(),
2099 getReductionOps().end());
2102 helper_expr_range reduction_ops() {
2103 return helper_expr_range(getReductionOps().begin(),
2104 getReductionOps().end());
2107 child_range children() {
2108 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2109 reinterpret_cast<Stmt **>(varlist_end()));
2112 static bool classof(const OMPClause *T) {
2113 return T->getClauseKind() == OMPC_task_reduction;
2117 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
2120 /// #pragma omp task in_reduction(+:a,b)
2122 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
2123 /// operator '+' and the variables 'a' and 'b'.
2124 class OMPInReductionClause final
2125 : public OMPVarListClause<OMPInReductionClause>,
2126 public OMPClauseWithPostUpdate,
2127 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
2128 friend class OMPClauseReader;
2129 friend OMPVarListClause;
2130 friend TrailingObjects;
2132 /// Location of ':'.
2133 SourceLocation ColonLoc;
2135 /// Nested name specifier for C++.
2136 NestedNameSpecifierLoc QualifierLoc;
2138 /// Name of custom operator.
2139 DeclarationNameInfo NameInfo;
2141 /// Build clause with number of variables \a N.
2143 /// \param StartLoc Starting location of the clause.
2144 /// \param LParenLoc Location of '('.
2145 /// \param EndLoc Ending location of the clause.
2146 /// \param ColonLoc Location of ':'.
2147 /// \param N Number of the variables in the clause.
2148 /// \param QualifierLoc The nested-name qualifier with location information
2149 /// \param NameInfo The full name info for reduction identifier.
2150 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2151 SourceLocation ColonLoc, SourceLocation EndLoc,
2152 unsigned N, NestedNameSpecifierLoc QualifierLoc,
2153 const DeclarationNameInfo &NameInfo)
2154 : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc,
2155 LParenLoc, EndLoc, N),
2156 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2157 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2159 /// Build an empty clause.
2161 /// \param N Number of variables.
2162 explicit OMPInReductionClause(unsigned N)
2163 : OMPVarListClause<OMPInReductionClause>(
2164 OMPC_in_reduction, SourceLocation(), SourceLocation(),
2165 SourceLocation(), N),
2166 OMPClauseWithPostUpdate(this) {}
2168 /// Sets location of ':' symbol in clause.
2169 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2171 /// Sets the name info for specified reduction identifier.
2172 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2174 /// Sets the nested name specifier.
2175 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2177 /// Set list of helper expressions, required for proper codegen of the clause.
2178 /// These expressions represent private copy of the reduction variable.
2179 void setPrivates(ArrayRef<Expr *> Privates);
2181 /// Get the list of helper privates.
2182 MutableArrayRef<Expr *> getPrivates() {
2183 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2185 ArrayRef<const Expr *> getPrivates() const {
2186 return llvm::makeArrayRef(varlist_end(), varlist_size());
2189 /// Set list of helper expressions, required for proper codegen of the clause.
2190 /// These expressions represent LHS expression in the final reduction
2191 /// expression performed by the reduction clause.
2192 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2194 /// Get the list of helper LHS expressions.
2195 MutableArrayRef<Expr *> getLHSExprs() {
2196 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2198 ArrayRef<const Expr *> getLHSExprs() const {
2199 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2202 /// Set list of helper expressions, required for proper codegen of the clause.
2203 /// These expressions represent RHS expression in the final reduction
2204 /// expression performed by the reduction clause. Also, variables in these
2205 /// expressions are used for proper initialization of reduction copies.
2206 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2208 /// Get the list of helper destination expressions.
2209 MutableArrayRef<Expr *> getRHSExprs() {
2210 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2212 ArrayRef<const Expr *> getRHSExprs() const {
2213 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2216 /// Set list of helper reduction expressions, required for proper
2217 /// codegen of the clause. These expressions are binary expressions or
2218 /// operator/custom reduction call that calculates new value from source
2219 /// helper expressions to destination helper expressions.
2220 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2222 /// Get the list of helper reduction expressions.
2223 MutableArrayRef<Expr *> getReductionOps() {
2224 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2226 ArrayRef<const Expr *> getReductionOps() const {
2227 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2230 /// Set list of helper reduction taskgroup descriptors.
2231 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
2233 /// Get the list of helper reduction taskgroup descriptors.
2234 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
2235 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
2237 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
2238 return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
2242 /// Creates clause with a list of variables \a VL.
2244 /// \param StartLoc Starting location of the clause.
2245 /// \param LParenLoc Location of '('.
2246 /// \param ColonLoc Location of ':'.
2247 /// \param EndLoc Ending location of the clause.
2248 /// \param VL The variables in the clause.
2249 /// \param QualifierLoc The nested-name qualifier with location information
2250 /// \param NameInfo The full name info for reduction identifier.
2251 /// \param Privates List of helper expressions for proper generation of
2253 /// \param LHSExprs List of helper expressions for proper generation of
2254 /// assignment operation required for copyprivate clause. This list represents
2255 /// LHSs of the reduction expressions.
2256 /// \param RHSExprs List of helper expressions for proper generation of
2257 /// assignment operation required for copyprivate clause. This list represents
2258 /// RHSs of the reduction expressions.
2259 /// Also, variables in these expressions are used for proper initialization of
2260 /// reduction copies.
2261 /// \param ReductionOps List of helper expressions that represents reduction
2264 /// LHSExprs binop RHSExprs;
2265 /// operator binop(LHSExpr, RHSExpr);
2266 /// <CutomReduction>(LHSExpr, RHSExpr);
2268 /// Required for proper codegen of final reduction operation performed by the
2269 /// reduction clause.
2270 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
2271 /// corresponding items in parent taskgroup task_reduction clause.
2272 /// \param PreInit Statement that must be executed before entering the OpenMP
2273 /// region with this clause.
2274 /// \param PostUpdate Expression that must be executed after exit from the
2275 /// OpenMP region with this clause.
2276 static OMPInReductionClause *
2277 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2278 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2279 NestedNameSpecifierLoc QualifierLoc,
2280 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2281 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2282 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
2283 Stmt *PreInit, Expr *PostUpdate);
2285 /// Creates an empty clause with the place for \a N variables.
2287 /// \param C AST context.
2288 /// \param N The number of variables.
2289 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2291 /// Gets location of ':' symbol in clause.
2292 SourceLocation getColonLoc() const { return ColonLoc; }
2294 /// Gets the name info for specified reduction identifier.
2295 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2297 /// Gets the nested name specifier.
2298 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2300 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2301 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2302 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2303 using helper_expr_const_range =
2304 llvm::iterator_range<helper_expr_const_iterator>;
2306 helper_expr_const_range privates() const {
2307 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2310 helper_expr_range privates() {
2311 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2314 helper_expr_const_range lhs_exprs() const {
2315 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2318 helper_expr_range lhs_exprs() {
2319 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2322 helper_expr_const_range rhs_exprs() const {
2323 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2326 helper_expr_range rhs_exprs() {
2327 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2330 helper_expr_const_range reduction_ops() const {
2331 return helper_expr_const_range(getReductionOps().begin(),
2332 getReductionOps().end());
2335 helper_expr_range reduction_ops() {
2336 return helper_expr_range(getReductionOps().begin(),
2337 getReductionOps().end());
2340 helper_expr_const_range taskgroup_descriptors() const {
2341 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
2342 getTaskgroupDescriptors().end());
2345 helper_expr_range taskgroup_descriptors() {
2346 return helper_expr_range(getTaskgroupDescriptors().begin(),
2347 getTaskgroupDescriptors().end());
2350 child_range children() {
2351 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2352 reinterpret_cast<Stmt **>(varlist_end()));
2355 static bool classof(const OMPClause *T) {
2356 return T->getClauseKind() == OMPC_in_reduction;
2360 /// This represents clause 'linear' in the '#pragma omp ...'
2364 /// #pragma omp simd linear(a,b : 2)
2366 /// In this example directive '#pragma omp simd' has clause 'linear'
2367 /// with variables 'a', 'b' and linear step '2'.
2368 class OMPLinearClause final
2369 : public OMPVarListClause<OMPLinearClause>,
2370 public OMPClauseWithPostUpdate,
2371 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
2372 friend class OMPClauseReader;
2373 friend OMPVarListClause;
2374 friend TrailingObjects;
2376 /// Modifier of 'linear' clause.
2377 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
2379 /// Location of linear modifier if any.
2380 SourceLocation ModifierLoc;
2382 /// Location of ':'.
2383 SourceLocation ColonLoc;
2385 /// Sets the linear step for clause.
2386 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
2388 /// Sets the expression to calculate linear step for clause.
2389 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
2391 /// Build 'linear' clause with given number of variables \a NumVars.
2393 /// \param StartLoc Starting location of the clause.
2394 /// \param LParenLoc Location of '('.
2395 /// \param ColonLoc Location of ':'.
2396 /// \param EndLoc Ending location of the clause.
2397 /// \param NumVars Number of variables.
2398 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2399 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2400 SourceLocation ColonLoc, SourceLocation EndLoc,
2402 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
2404 OMPClauseWithPostUpdate(this), Modifier(Modifier),
2405 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
2407 /// Build an empty clause.
2409 /// \param NumVars Number of variables.
2410 explicit OMPLinearClause(unsigned NumVars)
2411 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
2412 SourceLocation(), SourceLocation(),
2414 OMPClauseWithPostUpdate(this) {}
2416 /// Gets the list of initial values for linear variables.
2418 /// There are NumVars expressions with initial values allocated after the
2419 /// varlist, they are followed by NumVars update expressions (used to update
2420 /// the linear variable's value on current iteration) and they are followed by
2421 /// NumVars final expressions (used to calculate the linear variable's
2422 /// value after the loop body). After these lists, there are 2 helper
2423 /// expressions - linear step and a helper to calculate it before the
2424 /// loop body (used when the linear step is not constant):
2426 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
2427 /// Finals[]; Step; CalcStep; }
2428 MutableArrayRef<Expr *> getPrivates() {
2429 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2431 ArrayRef<const Expr *> getPrivates() const {
2432 return llvm::makeArrayRef(varlist_end(), varlist_size());
2435 MutableArrayRef<Expr *> getInits() {
2436 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2438 ArrayRef<const Expr *> getInits() const {
2439 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2442 /// Sets the list of update expressions for linear variables.
2443 MutableArrayRef<Expr *> getUpdates() {
2444 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
2446 ArrayRef<const Expr *> getUpdates() const {
2447 return llvm::makeArrayRef(getInits().end(), varlist_size());
2450 /// Sets the list of final update expressions for linear variables.
2451 MutableArrayRef<Expr *> getFinals() {
2452 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
2454 ArrayRef<const Expr *> getFinals() const {
2455 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
2458 /// Sets the list of the copies of original linear variables.
2459 /// \param PL List of expressions.
2460 void setPrivates(ArrayRef<Expr *> PL);
2462 /// Sets the list of the initial values for linear variables.
2463 /// \param IL List of expressions.
2464 void setInits(ArrayRef<Expr *> IL);
2467 /// Creates clause with a list of variables \a VL and a linear step
2470 /// \param C AST Context.
2471 /// \param StartLoc Starting location of the clause.
2472 /// \param LParenLoc Location of '('.
2473 /// \param Modifier Modifier of 'linear' clause.
2474 /// \param ModifierLoc Modifier location.
2475 /// \param ColonLoc Location of ':'.
2476 /// \param EndLoc Ending location of the clause.
2477 /// \param VL List of references to the variables.
2478 /// \param PL List of private copies of original variables.
2479 /// \param IL List of initial values for the variables.
2480 /// \param Step Linear step.
2481 /// \param CalcStep Calculation of the linear step.
2482 /// \param PreInit Statement that must be executed before entering the OpenMP
2483 /// region with this clause.
2484 /// \param PostUpdate Expression that must be executed after exit from the
2485 /// OpenMP region with this clause.
2486 static OMPLinearClause *
2487 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2488 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2489 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2490 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
2491 Stmt *PreInit, Expr *PostUpdate);
2493 /// Creates an empty clause with the place for \a NumVars variables.
2495 /// \param C AST context.
2496 /// \param NumVars Number of variables.
2497 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2500 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
2502 /// Return modifier.
2503 OpenMPLinearClauseKind getModifier() const { return Modifier; }
2505 /// Set modifier location.
2506 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
2508 /// Return modifier location.
2509 SourceLocation getModifierLoc() const { return ModifierLoc; }
2511 /// Sets the location of ':'.
2512 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2514 /// Returns the location of ':'.
2515 SourceLocation getColonLoc() const { return ColonLoc; }
2517 /// Returns linear step.
2518 Expr *getStep() { return *(getFinals().end()); }
2520 /// Returns linear step.
2521 const Expr *getStep() const { return *(getFinals().end()); }
2523 /// Returns expression to calculate linear step.
2524 Expr *getCalcStep() { return *(getFinals().end() + 1); }
2526 /// Returns expression to calculate linear step.
2527 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
2529 /// Sets the list of update expressions for linear variables.
2530 /// \param UL List of expressions.
2531 void setUpdates(ArrayRef<Expr *> UL);
2533 /// Sets the list of final update expressions for linear variables.
2534 /// \param FL List of expressions.
2535 void setFinals(ArrayRef<Expr *> FL);
2537 using privates_iterator = MutableArrayRef<Expr *>::iterator;
2538 using privates_const_iterator = ArrayRef<const Expr *>::iterator;
2539 using privates_range = llvm::iterator_range<privates_iterator>;
2540 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
2542 privates_range privates() {
2543 return privates_range(getPrivates().begin(), getPrivates().end());
2546 privates_const_range privates() const {
2547 return privates_const_range(getPrivates().begin(), getPrivates().end());
2550 using inits_iterator = MutableArrayRef<Expr *>::iterator;
2551 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
2552 using inits_range = llvm::iterator_range<inits_iterator>;
2553 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2555 inits_range inits() {
2556 return inits_range(getInits().begin(), getInits().end());
2559 inits_const_range inits() const {
2560 return inits_const_range(getInits().begin(), getInits().end());
2563 using updates_iterator = MutableArrayRef<Expr *>::iterator;
2564 using updates_const_iterator = ArrayRef<const Expr *>::iterator;
2565 using updates_range = llvm::iterator_range<updates_iterator>;
2566 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
2568 updates_range updates() {
2569 return updates_range(getUpdates().begin(), getUpdates().end());
2572 updates_const_range updates() const {
2573 return updates_const_range(getUpdates().begin(), getUpdates().end());
2576 using finals_iterator = MutableArrayRef<Expr *>::iterator;
2577 using finals_const_iterator = ArrayRef<const Expr *>::iterator;
2578 using finals_range = llvm::iterator_range<finals_iterator>;
2579 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
2581 finals_range finals() {
2582 return finals_range(getFinals().begin(), getFinals().end());
2585 finals_const_range finals() const {
2586 return finals_const_range(getFinals().begin(), getFinals().end());
2589 child_range children() {
2590 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2591 reinterpret_cast<Stmt **>(varlist_end()));
2594 static bool classof(const OMPClause *T) {
2595 return T->getClauseKind() == OMPC_linear;
2599 /// This represents clause 'aligned' in the '#pragma omp ...'
2603 /// #pragma omp simd aligned(a,b : 8)
2605 /// In this example directive '#pragma omp simd' has clause 'aligned'
2606 /// with variables 'a', 'b' and alignment '8'.
2607 class OMPAlignedClause final
2608 : public OMPVarListClause<OMPAlignedClause>,
2609 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
2610 friend class OMPClauseReader;
2611 friend OMPVarListClause;
2612 friend TrailingObjects;
2614 /// Location of ':'.
2615 SourceLocation ColonLoc;
2617 /// Sets the alignment for clause.
2618 void setAlignment(Expr *A) { *varlist_end() = A; }
2620 /// Build 'aligned' clause with given number of variables \a NumVars.
2622 /// \param StartLoc Starting location of the clause.
2623 /// \param LParenLoc Location of '('.
2624 /// \param ColonLoc Location of ':'.
2625 /// \param EndLoc Ending location of the clause.
2626 /// \param NumVars Number of variables.
2627 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2628 SourceLocation ColonLoc, SourceLocation EndLoc,
2630 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
2632 ColonLoc(ColonLoc) {}
2634 /// Build an empty clause.
2636 /// \param NumVars Number of variables.
2637 explicit OMPAlignedClause(unsigned NumVars)
2638 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
2639 SourceLocation(), SourceLocation(),
2643 /// Creates clause with a list of variables \a VL and alignment \a A.
2645 /// \param C AST Context.
2646 /// \param StartLoc Starting location of the clause.
2647 /// \param LParenLoc Location of '('.
2648 /// \param ColonLoc Location of ':'.
2649 /// \param EndLoc Ending location of the clause.
2650 /// \param VL List of references to the variables.
2651 /// \param A Alignment.
2652 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2653 SourceLocation LParenLoc,
2654 SourceLocation ColonLoc,
2655 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2658 /// Creates an empty clause with the place for \a NumVars variables.
2660 /// \param C AST context.
2661 /// \param NumVars Number of variables.
2662 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2664 /// Sets the location of ':'.
2665 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2667 /// Returns the location of ':'.
2668 SourceLocation getColonLoc() const { return ColonLoc; }
2670 /// Returns alignment.
2671 Expr *getAlignment() { return *varlist_end(); }
2673 /// Returns alignment.
2674 const Expr *getAlignment() const { return *varlist_end(); }
2676 child_range children() {
2677 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2678 reinterpret_cast<Stmt **>(varlist_end()));
2681 static bool classof(const OMPClause *T) {
2682 return T->getClauseKind() == OMPC_aligned;
2686 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
2689 /// #pragma omp parallel copyin(a,b)
2691 /// In this example directive '#pragma omp parallel' has clause 'copyin'
2692 /// with the variables 'a' and 'b'.
2693 class OMPCopyinClause final
2694 : public OMPVarListClause<OMPCopyinClause>,
2695 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
2696 // Class has 3 additional tail allocated arrays:
2697 // 1. List of helper expressions for proper generation of assignment operation
2698 // required for copyin clause. This list represents sources.
2699 // 2. List of helper expressions for proper generation of assignment operation
2700 // required for copyin clause. This list represents destinations.
2701 // 3. List of helper expressions that represents assignment operation:
2703 // DstExprs = SrcExprs;
2705 // Required for proper codegen of propagation of master's thread values of
2706 // threadprivate variables to local instances of that variables in other
2707 // implicit threads.
2709 friend class OMPClauseReader;
2710 friend OMPVarListClause;
2711 friend TrailingObjects;
2713 /// Build clause with number of variables \a N.
2715 /// \param StartLoc Starting location of the clause.
2716 /// \param LParenLoc Location of '('.
2717 /// \param EndLoc Ending location of the clause.
2718 /// \param N Number of the variables in the clause.
2719 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2720 SourceLocation EndLoc, unsigned N)
2721 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
2724 /// Build an empty clause.
2726 /// \param N Number of variables.
2727 explicit OMPCopyinClause(unsigned N)
2728 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
2729 SourceLocation(), SourceLocation(),
2732 /// Set list of helper expressions, required for proper codegen of the
2733 /// clause. These expressions represent source expression in the final
2734 /// assignment statement performed by the copyin clause.
2735 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2737 /// Get the list of helper source expressions.
2738 MutableArrayRef<Expr *> getSourceExprs() {
2739 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2741 ArrayRef<const Expr *> getSourceExprs() const {
2742 return llvm::makeArrayRef(varlist_end(), varlist_size());
2745 /// Set list of helper expressions, required for proper codegen of the
2746 /// clause. These expressions represent destination expression in the final
2747 /// assignment statement performed by the copyin clause.
2748 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2750 /// Get the list of helper destination expressions.
2751 MutableArrayRef<Expr *> getDestinationExprs() {
2752 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2754 ArrayRef<const Expr *> getDestinationExprs() const {
2755 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2758 /// Set list of helper assignment expressions, required for proper
2759 /// codegen of the clause. These expressions are assignment expressions that
2760 /// assign source helper expressions to destination helper expressions
2761 /// correspondingly.
2762 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2764 /// Get the list of helper assignment expressions.
2765 MutableArrayRef<Expr *> getAssignmentOps() {
2766 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2768 ArrayRef<const Expr *> getAssignmentOps() const {
2769 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2773 /// Creates clause with a list of variables \a VL.
2775 /// \param C AST context.
2776 /// \param StartLoc Starting location of the clause.
2777 /// \param LParenLoc Location of '('.
2778 /// \param EndLoc Ending location of the clause.
2779 /// \param VL List of references to the variables.
2780 /// \param SrcExprs List of helper expressions for proper generation of
2781 /// assignment operation required for copyin clause. This list represents
2783 /// \param DstExprs List of helper expressions for proper generation of
2784 /// assignment operation required for copyin clause. This list represents
2786 /// \param AssignmentOps List of helper expressions that represents assignment
2789 /// DstExprs = SrcExprs;
2791 /// Required for proper codegen of propagation of master's thread values of
2792 /// threadprivate variables to local instances of that variables in other
2793 /// implicit threads.
2794 static OMPCopyinClause *
2795 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2796 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2797 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2799 /// Creates an empty clause with \a N variables.
2801 /// \param C AST context.
2802 /// \param N The number of variables.
2803 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
2805 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2806 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2807 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2808 using helper_expr_const_range =
2809 llvm::iterator_range<helper_expr_const_iterator>;
2811 helper_expr_const_range source_exprs() const {
2812 return helper_expr_const_range(getSourceExprs().begin(),
2813 getSourceExprs().end());
2816 helper_expr_range source_exprs() {
2817 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2820 helper_expr_const_range destination_exprs() const {
2821 return helper_expr_const_range(getDestinationExprs().begin(),
2822 getDestinationExprs().end());
2825 helper_expr_range destination_exprs() {
2826 return helper_expr_range(getDestinationExprs().begin(),
2827 getDestinationExprs().end());
2830 helper_expr_const_range assignment_ops() const {
2831 return helper_expr_const_range(getAssignmentOps().begin(),
2832 getAssignmentOps().end());
2835 helper_expr_range assignment_ops() {
2836 return helper_expr_range(getAssignmentOps().begin(),
2837 getAssignmentOps().end());
2840 child_range children() {
2841 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2842 reinterpret_cast<Stmt **>(varlist_end()));
2845 static bool classof(const OMPClause *T) {
2846 return T->getClauseKind() == OMPC_copyin;
2850 /// This represents clause 'copyprivate' in the '#pragma omp ...'
2854 /// #pragma omp single copyprivate(a,b)
2856 /// In this example directive '#pragma omp single' has clause 'copyprivate'
2857 /// with the variables 'a' and 'b'.
2858 class OMPCopyprivateClause final
2859 : public OMPVarListClause<OMPCopyprivateClause>,
2860 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
2861 friend class OMPClauseReader;
2862 friend OMPVarListClause;
2863 friend TrailingObjects;
2865 /// Build clause with number of variables \a N.
2867 /// \param StartLoc Starting location of the clause.
2868 /// \param LParenLoc Location of '('.
2869 /// \param EndLoc Ending location of the clause.
2870 /// \param N Number of the variables in the clause.
2871 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2872 SourceLocation EndLoc, unsigned N)
2873 : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
2874 LParenLoc, EndLoc, N) {}
2876 /// Build an empty clause.
2878 /// \param N Number of variables.
2879 explicit OMPCopyprivateClause(unsigned N)
2880 : OMPVarListClause<OMPCopyprivateClause>(
2881 OMPC_copyprivate, SourceLocation(), SourceLocation(),
2882 SourceLocation(), N) {}
2884 /// Set list of helper expressions, required for proper codegen of the
2885 /// clause. These expressions represent source expression in the final
2886 /// assignment statement performed by the copyprivate clause.
2887 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2889 /// Get the list of helper source expressions.
2890 MutableArrayRef<Expr *> getSourceExprs() {
2891 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2893 ArrayRef<const Expr *> getSourceExprs() const {
2894 return llvm::makeArrayRef(varlist_end(), varlist_size());
2897 /// Set list of helper expressions, required for proper codegen of the
2898 /// clause. These expressions represent destination expression in the final
2899 /// assignment statement performed by the copyprivate clause.
2900 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2902 /// Get the list of helper destination expressions.
2903 MutableArrayRef<Expr *> getDestinationExprs() {
2904 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2906 ArrayRef<const Expr *> getDestinationExprs() const {
2907 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2910 /// Set list of helper assignment expressions, required for proper
2911 /// codegen of the clause. These expressions are assignment expressions that
2912 /// assign source helper expressions to destination helper expressions
2913 /// correspondingly.
2914 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2916 /// Get the list of helper assignment expressions.
2917 MutableArrayRef<Expr *> getAssignmentOps() {
2918 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2920 ArrayRef<const Expr *> getAssignmentOps() const {
2921 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2925 /// Creates clause with a list of variables \a VL.
2927 /// \param C AST context.
2928 /// \param StartLoc Starting location of the clause.
2929 /// \param LParenLoc Location of '('.
2930 /// \param EndLoc Ending location of the clause.
2931 /// \param VL List of references to the variables.
2932 /// \param SrcExprs List of helper expressions for proper generation of
2933 /// assignment operation required for copyprivate clause. This list represents
2935 /// \param DstExprs List of helper expressions for proper generation of
2936 /// assignment operation required for copyprivate clause. This list represents
2938 /// \param AssignmentOps List of helper expressions that represents assignment
2941 /// DstExprs = SrcExprs;
2943 /// Required for proper codegen of final assignment performed by the
2944 /// copyprivate clause.
2945 static OMPCopyprivateClause *
2946 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2947 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2948 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2950 /// Creates an empty clause with \a N variables.
2952 /// \param C AST context.
2953 /// \param N The number of variables.
2954 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2956 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2957 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2958 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2959 using helper_expr_const_range =
2960 llvm::iterator_range<helper_expr_const_iterator>;
2962 helper_expr_const_range source_exprs() const {
2963 return helper_expr_const_range(getSourceExprs().begin(),
2964 getSourceExprs().end());
2967 helper_expr_range source_exprs() {
2968 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2971 helper_expr_const_range destination_exprs() const {
2972 return helper_expr_const_range(getDestinationExprs().begin(),
2973 getDestinationExprs().end());
2976 helper_expr_range destination_exprs() {
2977 return helper_expr_range(getDestinationExprs().begin(),
2978 getDestinationExprs().end());
2981 helper_expr_const_range assignment_ops() const {
2982 return helper_expr_const_range(getAssignmentOps().begin(),
2983 getAssignmentOps().end());
2986 helper_expr_range assignment_ops() {
2987 return helper_expr_range(getAssignmentOps().begin(),
2988 getAssignmentOps().end());
2991 child_range children() {
2992 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2993 reinterpret_cast<Stmt **>(varlist_end()));
2996 static bool classof(const OMPClause *T) {
2997 return T->getClauseKind() == OMPC_copyprivate;
3001 /// This represents implicit clause 'flush' for the '#pragma omp flush'
3003 /// This clause does not exist by itself, it can be only as a part of 'omp
3004 /// flush' directive. This clause is introduced to keep the original structure
3005 /// of \a OMPExecutableDirective class and its derivatives and to use the
3006 /// existing infrastructure of clauses with the list of variables.
3009 /// #pragma omp flush(a,b)
3011 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
3012 /// with the variables 'a' and 'b'.
3013 class OMPFlushClause final
3014 : public OMPVarListClause<OMPFlushClause>,
3015 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
3016 friend OMPVarListClause;
3017 friend TrailingObjects;
3019 /// Build clause with number of variables \a N.
3021 /// \param StartLoc Starting location of the clause.
3022 /// \param LParenLoc Location of '('.
3023 /// \param EndLoc Ending location of the clause.
3024 /// \param N Number of the variables in the clause.
3025 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3026 SourceLocation EndLoc, unsigned N)
3027 : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
3030 /// Build an empty clause.
3032 /// \param N Number of variables.
3033 explicit OMPFlushClause(unsigned N)
3034 : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
3035 SourceLocation(), SourceLocation(),
3039 /// Creates clause with a list of variables \a VL.
3041 /// \param C AST context.
3042 /// \param StartLoc Starting location of the clause.
3043 /// \param LParenLoc Location of '('.
3044 /// \param EndLoc Ending location of the clause.
3045 /// \param VL List of references to the variables.
3046 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
3047 SourceLocation LParenLoc, SourceLocation EndLoc,
3048 ArrayRef<Expr *> VL);
3050 /// Creates an empty clause with \a N variables.
3052 /// \param C AST context.
3053 /// \param N The number of variables.
3054 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
3056 child_range children() {
3057 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3058 reinterpret_cast<Stmt **>(varlist_end()));
3061 static bool classof(const OMPClause *T) {
3062 return T->getClauseKind() == OMPC_flush;
3066 /// This represents implicit clause 'depend' for the '#pragma omp task'
3070 /// #pragma omp task depend(in:a,b)
3072 /// In this example directive '#pragma omp task' with clause 'depend' with the
3073 /// variables 'a' and 'b' with dependency 'in'.
3074 class OMPDependClause final
3075 : public OMPVarListClause<OMPDependClause>,
3076 private llvm::TrailingObjects<OMPDependClause, Expr *> {
3077 friend class OMPClauseReader;
3078 friend OMPVarListClause;
3079 friend TrailingObjects;
3081 /// Dependency type (one of in, out, inout).
3082 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
3084 /// Dependency type location.
3085 SourceLocation DepLoc;
3088 SourceLocation ColonLoc;
3090 /// Build clause with number of variables \a N.
3092 /// \param StartLoc Starting location of the clause.
3093 /// \param LParenLoc Location of '('.
3094 /// \param EndLoc Ending location of the clause.
3095 /// \param N Number of the variables in the clause.
3096 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3097 SourceLocation EndLoc, unsigned N)
3098 : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
3101 /// Build an empty clause.
3103 /// \param N Number of variables.
3104 explicit OMPDependClause(unsigned N)
3105 : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
3106 SourceLocation(), SourceLocation(),
3109 /// Set dependency kind.
3110 void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
3112 /// Set dependency kind and its location.
3113 void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
3115 /// Set colon location.
3116 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3119 /// Creates clause with a list of variables \a VL.
3121 /// \param C AST context.
3122 /// \param StartLoc Starting location of the clause.
3123 /// \param LParenLoc Location of '('.
3124 /// \param EndLoc Ending location of the clause.
3125 /// \param DepKind Dependency type.
3126 /// \param DepLoc Location of the dependency type.
3127 /// \param ColonLoc Colon location.
3128 /// \param VL List of references to the variables.
3129 static OMPDependClause *
3130 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3131 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
3132 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL);
3134 /// Creates an empty clause with \a N variables.
3136 /// \param C AST context.
3137 /// \param N The number of variables.
3138 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N);
3140 /// Get dependency type.
3141 OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
3143 /// Get dependency type location.
3144 SourceLocation getDependencyLoc() const { return DepLoc; }
3146 /// Get colon location.
3147 SourceLocation getColonLoc() const { return ColonLoc; }
3149 /// Set the loop counter value for the depend clauses with 'sink|source' kind
3150 /// of dependency. Required for codegen.
3151 void setCounterValue(Expr *V);
3153 /// Get the loop counter value.
3154 Expr *getCounterValue();
3156 /// Get the loop counter value.
3157 const Expr *getCounterValue() const;
3159 child_range children() {
3160 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3161 reinterpret_cast<Stmt **>(varlist_end()));
3164 static bool classof(const OMPClause *T) {
3165 return T->getClauseKind() == OMPC_depend;
3169 /// This represents 'device' clause in the '#pragma omp ...'
3173 /// #pragma omp target device(a)
3175 /// In this example directive '#pragma omp target' has clause 'device'
3176 /// with single expression 'a'.
3177 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
3178 friend class OMPClauseReader;
3180 /// Location of '('.
3181 SourceLocation LParenLoc;
3184 Stmt *Device = nullptr;
3186 /// Set the device number.
3188 /// \param E Device number.
3189 void setDevice(Expr *E) { Device = E; }
3192 /// Build 'device' clause.
3194 /// \param E Expression associated with this clause.
3195 /// \param CaptureRegion Innermost OpenMP region where expressions in this
3196 /// clause must be captured.
3197 /// \param StartLoc Starting location of the clause.
3198 /// \param LParenLoc Location of '('.
3199 /// \param EndLoc Ending location of the clause.
3200 OMPDeviceClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
3201 SourceLocation StartLoc, SourceLocation LParenLoc,
3202 SourceLocation EndLoc)
3203 : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this),
3204 LParenLoc(LParenLoc), Device(E) {
3205 setPreInitStmt(HelperE, CaptureRegion);
3208 /// Build an empty clause.
3210 : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
3211 OMPClauseWithPreInit(this) {}
3213 /// Sets the location of '('.
3214 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3216 /// Returns the location of '('.
3217 SourceLocation getLParenLoc() const { return LParenLoc; }
3219 /// Return device number.
3220 Expr *getDevice() { return cast<Expr>(Device); }
3222 /// Return device number.
3223 Expr *getDevice() const { return cast<Expr>(Device); }
3225 child_range children() { return child_range(&Device, &Device + 1); }
3227 static bool classof(const OMPClause *T) {
3228 return T->getClauseKind() == OMPC_device;
3232 /// This represents 'threads' clause in the '#pragma omp ...' directive.
3235 /// #pragma omp ordered threads
3237 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
3238 class OMPThreadsClause : public OMPClause {
3240 /// Build 'threads' clause.
3242 /// \param StartLoc Starting location of the clause.
3243 /// \param EndLoc Ending location of the clause.
3244 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
3245 : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
3247 /// Build an empty clause.
3249 : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
3251 child_range children() {
3252 return child_range(child_iterator(), child_iterator());
3255 static bool classof(const OMPClause *T) {
3256 return T->getClauseKind() == OMPC_threads;
3260 /// This represents 'simd' clause in the '#pragma omp ...' directive.
3263 /// #pragma omp ordered simd
3265 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
3266 class OMPSIMDClause : public OMPClause {
3268 /// Build 'simd' clause.
3270 /// \param StartLoc Starting location of the clause.
3271 /// \param EndLoc Ending location of the clause.
3272 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
3273 : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
3275 /// Build an empty clause.
3276 OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
3278 child_range children() {
3279 return child_range(child_iterator(), child_iterator());
3282 static bool classof(const OMPClause *T) {
3283 return T->getClauseKind() == OMPC_simd;
3287 /// Struct that defines common infrastructure to handle mappable
3288 /// expressions used in OpenMP clauses.
3289 class OMPClauseMappableExprCommon {
3291 /// Class that represents a component of a mappable expression. E.g.
3292 /// for an expression S.a, the first component is a declaration reference
3293 /// expression associated with 'S' and the second is a member expression
3294 /// associated with the field declaration 'a'. If the expression is an array
3295 /// subscript it may not have any associated declaration. In that case the
3296 /// associated declaration is set to nullptr.
3297 class MappableComponent {
3298 /// Expression associated with the component.
3299 Expr *AssociatedExpression = nullptr;
3301 /// Declaration associated with the declaration. If the component does
3302 /// not have a declaration (e.g. array subscripts or section), this is set
3304 ValueDecl *AssociatedDeclaration = nullptr;
3307 explicit MappableComponent() = default;
3308 explicit MappableComponent(Expr *AssociatedExpression,
3309 ValueDecl *AssociatedDeclaration)
3310 : AssociatedExpression(AssociatedExpression),
3311 AssociatedDeclaration(
3312 AssociatedDeclaration
3313 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
3316 Expr *getAssociatedExpression() const { return AssociatedExpression; }
3318 ValueDecl *getAssociatedDeclaration() const {
3319 return AssociatedDeclaration;
3323 // List of components of an expression. This first one is the whole
3324 // expression and the last one is the base expression.
3325 using MappableExprComponentList = SmallVector<MappableComponent, 8>;
3326 using MappableExprComponentListRef = ArrayRef<MappableComponent>;
3328 // List of all component lists associated to the same base declaration.
3329 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
3330 // their component list but the same base declaration 'S'.
3331 using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
3332 using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
3335 // Return the total number of elements in a list of component lists.
3337 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
3339 // Return the total number of elements in a list of declarations. All
3340 // declarations are expected to be canonical.
3342 getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
3345 /// This represents clauses with a list of expressions that are mappable.
3346 /// Examples of these clauses are 'map' in
3347 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
3348 /// in '#pragma omp target update...' directives.
3350 class OMPMappableExprListClause : public OMPVarListClause<T>,
3351 public OMPClauseMappableExprCommon {
3352 friend class OMPClauseReader;
3354 /// Number of unique declarations in this clause.
3355 unsigned NumUniqueDeclarations;
3357 /// Number of component lists in this clause.
3358 unsigned NumComponentLists;
3360 /// Total number of components in this clause.
3361 unsigned NumComponents;
3364 /// Build a clause for \a NumUniqueDeclarations declarations, \a
3365 /// NumComponentLists total component lists, and \a NumComponents total
3368 /// \param K Kind of the clause.
3369 /// \param StartLoc Starting location of the clause (the clause keyword).
3370 /// \param LParenLoc Location of '('.
3371 /// \param EndLoc Ending location of the clause.
3372 /// \param NumVars Number of expressions listed in the clause.
3373 /// \param NumUniqueDeclarations Number of unique base declarations in this
3375 /// \param NumComponentLists Number of component lists in this clause - one
3376 /// list for each expression in the clause.
3377 /// \param NumComponents Total number of expression components in the clause.
3378 OMPMappableExprListClause(OpenMPClauseKind K, SourceLocation StartLoc,
3379 SourceLocation LParenLoc, SourceLocation EndLoc,
3380 unsigned NumVars, unsigned NumUniqueDeclarations,
3381 unsigned NumComponentLists, unsigned NumComponents)
3382 : OMPVarListClause<T>(K, StartLoc, LParenLoc, EndLoc, NumVars),
3383 NumUniqueDeclarations(NumUniqueDeclarations),
3384 NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
3386 /// Get the unique declarations that are in the trailing objects of the
3388 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
3389 return MutableArrayRef<ValueDecl *>(
3390 static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
3391 NumUniqueDeclarations);
3394 /// Get the unique declarations that are in the trailing objects of the
3396 ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
3397 return ArrayRef<ValueDecl *>(
3398 static_cast<const T *>(this)
3399 ->template getTrailingObjects<ValueDecl *>(),
3400 NumUniqueDeclarations);
3403 /// Set the unique declarations that are in the trailing objects of the
3405 void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
3406 assert(UDs.size() == NumUniqueDeclarations &&
3407 "Unexpected amount of unique declarations.");
3408 std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
3411 /// Get the number of lists per declaration that are in the trailing
3412 /// objects of the class.
3413 MutableArrayRef<unsigned> getDeclNumListsRef() {
3414 return MutableArrayRef<unsigned>(
3415 static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
3416 NumUniqueDeclarations);
3419 /// Get the number of lists per declaration that are in the trailing
3420 /// objects of the class.
3421 ArrayRef<unsigned> getDeclNumListsRef() const {
3422 return ArrayRef<unsigned>(
3423 static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
3424 NumUniqueDeclarations);
3427 /// Set the number of lists per declaration that are in the trailing
3428 /// objects of the class.
3429 void setDeclNumLists(ArrayRef<unsigned> DNLs) {
3430 assert(DNLs.size() == NumUniqueDeclarations &&
3431 "Unexpected amount of list numbers.");
3432 std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
3435 /// Get the cumulative component lists sizes that are in the trailing
3436 /// objects of the class. They are appended after the number of lists.
3437 MutableArrayRef<unsigned> getComponentListSizesRef() {
3438 return MutableArrayRef<unsigned>(
3439 static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
3440 NumUniqueDeclarations,
3444 /// Get the cumulative component lists sizes that are in the trailing
3445 /// objects of the class. They are appended after the number of lists.
3446 ArrayRef<unsigned> getComponentListSizesRef() const {
3447 return ArrayRef<unsigned>(
3448 static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
3449 NumUniqueDeclarations,
3453 /// Set the cumulative component lists sizes that are in the trailing
3454 /// objects of the class.
3455 void setComponentListSizes(ArrayRef<unsigned> CLSs) {
3456 assert(CLSs.size() == NumComponentLists &&
3457 "Unexpected amount of component lists.");
3458 std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
3461 /// Get the components that are in the trailing objects of the class.
3462 MutableArrayRef<MappableComponent> getComponentsRef() {
3463 return MutableArrayRef<MappableComponent>(
3464 static_cast<T *>(this)
3465 ->template getTrailingObjects<MappableComponent>(),
3469 /// Get the components that are in the trailing objects of the class.
3470 ArrayRef<MappableComponent> getComponentsRef() const {
3471 return ArrayRef<MappableComponent>(
3472 static_cast<const T *>(this)
3473 ->template getTrailingObjects<MappableComponent>(),
3477 /// Set the components that are in the trailing objects of the class.
3478 /// This requires the list sizes so that it can also fill the original
3479 /// expressions, which are the first component of each list.
3480 void setComponents(ArrayRef<MappableComponent> Components,
3481 ArrayRef<unsigned> CLSs) {
3482 assert(Components.size() == NumComponents &&
3483 "Unexpected amount of component lists.");
3484 assert(CLSs.size() == NumComponentLists &&
3485 "Unexpected amount of list sizes.");
3486 std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
3489 /// Fill the clause information from the list of declarations and
3490 /// associated component lists.
3491 void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
3492 MappableExprComponentListsRef ComponentLists) {
3493 // Perform some checks to make sure the data sizes are consistent with the
3494 // information available when the clause was created.
3495 assert(getUniqueDeclarationsTotalNumber(Declarations) ==
3496 NumUniqueDeclarations &&
3497 "Unexpected number of mappable expression info entries!");
3498 assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
3499 "Unexpected total number of components!");
3500 assert(Declarations.size() == ComponentLists.size() &&
3501 "Declaration and component lists size is not consistent!");
3502 assert(Declarations.size() == NumComponentLists &&
3503 "Unexpected declaration and component lists size!");
3505 // Organize the components by declaration and retrieve the original
3506 // expression. Original expressions are always the first component of the
3507 // mappable component list.
3508 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
3511 auto CI = ComponentLists.begin();
3512 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
3514 assert(!CI->empty() && "Invalid component list!");
3515 ComponentListMap[*DI].push_back(*CI);
3519 // Iterators of the target storage.
3520 auto UniqueDeclarations = getUniqueDeclsRef();
3521 auto UDI = UniqueDeclarations.begin();
3523 auto DeclNumLists = getDeclNumListsRef();
3524 auto DNLI = DeclNumLists.begin();
3526 auto ComponentListSizes = getComponentListSizesRef();
3527 auto CLSI = ComponentListSizes.begin();
3529 auto Components = getComponentsRef();
3530 auto CI = Components.begin();
3532 // Variable to compute the accumulation of the number of components.
3533 unsigned PrevSize = 0u;
3535 // Scan all the declarations and associated component lists.
3536 for (auto &M : ComponentListMap) {
3539 // The component lists.
3542 // Initialize the entry.
3549 // Obtain the cumulative sizes and concatenate all the components in the
3550 // reserved storage.
3552 // Accumulate with the previous size.
3553 PrevSize += C.size();
3559 // Append components after the current components iterator.
3560 CI = std::copy(C.begin(), C.end(), CI);
3566 /// Return the number of unique base declarations in this clause.
3567 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
3569 /// Return the number of lists derived from the clause expressions.
3570 unsigned getTotalComponentListNum() const { return NumComponentLists; }
3572 /// Return the total number of components in all lists derived from the
3574 unsigned getTotalComponentsNum() const { return NumComponents; }
3576 /// Iterator that browse the components by lists. It also allows
3577 /// browsing components of a single declaration.
3578 class const_component_lists_iterator
3579 : public llvm::iterator_adaptor_base<
3580 const_component_lists_iterator,
3581 MappableExprComponentListRef::const_iterator,
3582 std::forward_iterator_tag, MappableComponent, ptrdiff_t,
3583 MappableComponent, MappableComponent> {
3584 // The declaration the iterator currently refers to.
3585 ArrayRef<ValueDecl *>::iterator DeclCur;
3587 // The list number associated with the current declaration.
3588 ArrayRef<unsigned>::iterator NumListsCur;
3590 // Remaining lists for the current declaration.
3591 unsigned RemainingLists = 0;
3593 // The cumulative size of the previous list, or zero if there is no previous
3595 unsigned PrevListSize = 0;
3597 // The cumulative sizes of the current list - it will delimit the remaining
3598 // range of interest.
3599 ArrayRef<unsigned>::const_iterator ListSizeCur;
3600 ArrayRef<unsigned>::const_iterator ListSizeEnd;
3602 // Iterator to the end of the components storage.
3603 MappableExprComponentListRef::const_iterator End;
3606 /// Construct an iterator that scans all lists.
3607 explicit const_component_lists_iterator(
3608 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
3609 ArrayRef<unsigned> CumulativeListSizes,
3610 MappableExprComponentListRef Components)
3611 : const_component_lists_iterator::iterator_adaptor_base(
3612 Components.begin()),
3613 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
3614 ListSizeCur(CumulativeListSizes.begin()),
3615 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
3616 assert(UniqueDecls.size() == DeclsListNum.size() &&
3617 "Inconsistent number of declarations and list sizes!");
3618 if (!DeclsListNum.empty())
3619 RemainingLists = *NumListsCur;
3622 /// Construct an iterator that scan lists for a given declaration \a
3624 explicit const_component_lists_iterator(
3625 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
3626 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
3627 MappableExprComponentListRef Components)
3628 : const_component_lists_iterator(UniqueDecls, DeclsListNum,
3629 CumulativeListSizes, Components) {
3630 // Look for the desired declaration. While we are looking for it, we
3631 // update the state so that we know the component where a given list
3633 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
3634 if (*DeclCur == Declaration)
3637 assert(*NumListsCur > 0 && "No lists associated with declaration??");
3639 // Skip the lists associated with the current declaration, but save the
3640 // last list size that was skipped.
3641 std::advance(ListSizeCur, *NumListsCur - 1);
3642 PrevListSize = *ListSizeCur;
3646 // If we didn't find any declaration, advance the iterator to after the
3647 // last component and set remaining lists to zero.
3648 if (ListSizeCur == CumulativeListSizes.end()) {
3650 RemainingLists = 0u;
3654 // Set the remaining lists with the total number of lists of the current
3656 RemainingLists = *NumListsCur;
3658 // Adjust the list size end iterator to the end of the relevant range.
3659 ListSizeEnd = ListSizeCur;
3660 std::advance(ListSizeEnd, RemainingLists);
3662 // Given that the list sizes are cumulative, the index of the component
3663 // that start the list is the size of the previous list.
3664 std::advance(this->I, PrevListSize);
3667 // Return the array with the current list. The sizes are cumulative, so the
3668 // array size is the difference between the current size and previous one.
3669 std::pair<const ValueDecl *, MappableExprComponentListRef>
3671 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
3672 return std::make_pair(
3674 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize));
3676 std::pair<const ValueDecl *, MappableExprComponentListRef>
3677 operator->() const {
3681 // Skip the components of the current list.
3682 const_component_lists_iterator &operator++() {
3683 assert(ListSizeCur != ListSizeEnd && RemainingLists &&
3684 "Invalid iterator!");
3686 // If we don't have more lists just skip all the components. Otherwise,
3687 // advance the iterator by the number of components in the current list.
3688 if (std::next(ListSizeCur) == ListSizeEnd) {
3692 std::advance(this->I, *ListSizeCur - PrevListSize);
3693 PrevListSize = *ListSizeCur;
3695 // We are done with a declaration, move to the next one.
3696 if (!(--RemainingLists)) {
3699 RemainingLists = *NumListsCur;
3700 assert(RemainingLists && "No lists in the following declaration??");
3709 using const_component_lists_range =
3710 llvm::iterator_range<const_component_lists_iterator>;
3712 /// Iterators for all component lists.
3713 const_component_lists_iterator component_lists_begin() const {
3714 return const_component_lists_iterator(
3715 getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
3716 getComponentsRef());
3718 const_component_lists_iterator component_lists_end() const {
3719 return const_component_lists_iterator(
3720 ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
3721 MappableExprComponentListRef(getComponentsRef().end(),
3722 getComponentsRef().end()));
3724 const_component_lists_range component_lists() const {
3725 return {component_lists_begin(), component_lists_end()};
3728 /// Iterators for component lists associated with the provided
3730 const_component_lists_iterator
3731 decl_component_lists_begin(const ValueDecl *VD) const {
3732 return const_component_lists_iterator(
3733 VD, getUniqueDeclsRef(), getDeclNumListsRef(),
3734 getComponentListSizesRef(), getComponentsRef());
3736 const_component_lists_iterator decl_component_lists_end() const {
3737 return component_lists_end();
3739 const_component_lists_range decl_component_lists(const ValueDecl *VD) const {
3740 return {decl_component_lists_begin(VD), decl_component_lists_end()};
3743 /// Iterators to access all the declarations, number of lists, list sizes, and
3745 using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
3746 using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
3748 const_all_decls_range all_decls() const {
3749 auto A = getUniqueDeclsRef();
3750 return const_all_decls_range(A.begin(), A.end());
3753 using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
3754 using const_all_num_lists_range =
3755 llvm::iterator_range<const_all_num_lists_iterator>;
3757 const_all_num_lists_range all_num_lists() const {
3758 auto A = getDeclNumListsRef();
3759 return const_all_num_lists_range(A.begin(), A.end());
3762 using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
3763 using const_all_lists_sizes_range =
3764 llvm::iterator_range<const_all_lists_sizes_iterator>;
3766 const_all_lists_sizes_range all_lists_sizes() const {
3767 auto A = getComponentListSizesRef();
3768 return const_all_lists_sizes_range(A.begin(), A.end());
3771 using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
3772 using const_all_components_range =
3773 llvm::iterator_range<const_all_components_iterator>;
3775 const_all_components_range all_components() const {
3776 auto A = getComponentsRef();
3777 return const_all_components_range(A.begin(), A.end());
3781 /// This represents clause 'map' in the '#pragma omp ...'
3785 /// #pragma omp target map(a,b)
3787 /// In this example directive '#pragma omp target' has clause 'map'
3788 /// with the variables 'a' and 'b'.
3789 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
3790 private llvm::TrailingObjects<
3791 OMPMapClause, Expr *, ValueDecl *, unsigned,
3792 OMPClauseMappableExprCommon::MappableComponent> {
3793 friend class OMPClauseReader;
3794 friend OMPMappableExprListClause;
3795 friend OMPVarListClause;
3796 friend TrailingObjects;
3798 /// Define the sizes of each trailing object array except the last one. This
3799 /// is required for TrailingObjects to work properly.
3800 size_t numTrailingObjects(OverloadToken<Expr *>) const {
3801 return varlist_size();
3803 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
3804 return getUniqueDeclarationsNum();
3806 size_t numTrailingObjects(OverloadToken<unsigned>) const {
3807 return getUniqueDeclarationsNum() + getTotalComponentListNum();
3810 /// Map type modifier for the 'map' clause.
3811 OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown;
3813 /// Map type for the 'map' clause.
3814 OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
3816 /// Is this an implicit map type or not.
3817 bool MapTypeIsImplicit = false;
3819 /// Location of the map type.
3820 SourceLocation MapLoc;
3823 SourceLocation ColonLoc;
3825 /// Build a clause for \a NumVars listed expressions, \a
3826 /// NumUniqueDeclarations declarations, \a NumComponentLists total component
3827 /// lists, and \a NumComponents total expression components.
3829 /// \param MapTypeModifier Map type modifier.
3830 /// \param MapType Map type.
3831 /// \param MapTypeIsImplicit Map type is inferred implicitly.
3832 /// \param MapLoc Location of the map type.
3833 /// \param StartLoc Starting location of the clause.
3834 /// \param EndLoc Ending location of the clause.
3835 /// \param NumVars Number of expressions listed in this clause.
3836 /// \param NumUniqueDeclarations Number of unique base declarations in this
3838 /// \param NumComponentLists Number of component lists in this clause.
3839 /// \param NumComponents Total number of expression components in the clause.
3840 explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier,
3841 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
3842 SourceLocation MapLoc, SourceLocation StartLoc,
3843 SourceLocation LParenLoc, SourceLocation EndLoc,
3844 unsigned NumVars, unsigned NumUniqueDeclarations,
3845 unsigned NumComponentLists, unsigned NumComponents)
3846 : OMPMappableExprListClause(OMPC_map, StartLoc, LParenLoc, EndLoc,
3847 NumVars, NumUniqueDeclarations,
3848 NumComponentLists, NumComponents),
3849 MapTypeModifier(MapTypeModifier), MapType(MapType),
3850 MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {}
3852 /// Build an empty clause.
3854 /// \param NumVars Number of expressions listed in this clause.
3855 /// \param NumUniqueDeclarations Number of unique base declarations in this
3857 /// \param NumComponentLists Number of component lists in this clause.
3858 /// \param NumComponents Total number of expression components in the clause.
3859 explicit OMPMapClause(unsigned NumVars, unsigned NumUniqueDeclarations,
3860 unsigned NumComponentLists, unsigned NumComponents)
3861 : OMPMappableExprListClause(
3862 OMPC_map, SourceLocation(), SourceLocation(), SourceLocation(),
3863 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
3865 /// Set type modifier for the clause.
3867 /// \param T Type Modifier for the clause.
3868 void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; }
3870 /// Set type for the clause.
3872 /// \param T Type for the clause.
3873 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
3875 /// Set type location.
3877 /// \param TLoc Type location.
3878 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
3880 /// Set colon location.
3881 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3884 /// Creates clause with a list of variables \a VL.
3886 /// \param C AST context.
3887 /// \param StartLoc Starting location of the clause.
3888 /// \param EndLoc Ending location of the clause.
3889 /// \param Vars The original expression used in the clause.
3890 /// \param Declarations Declarations used in the clause.
3891 /// \param ComponentLists Component lists used in the clause.
3892 /// \param TypeModifier Map type modifier.
3893 /// \param Type Map type.
3894 /// \param TypeIsImplicit Map type is inferred implicitly.
3895 /// \param TypeLoc Location of the map type.
3896 static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc,
3897 SourceLocation LParenLoc, SourceLocation EndLoc,
3898 ArrayRef<Expr *> Vars,
3899 ArrayRef<ValueDecl *> Declarations,
3900 MappableExprComponentListsRef ComponentLists,
3901 OpenMPMapClauseKind TypeModifier,
3902 OpenMPMapClauseKind Type, bool TypeIsImplicit,
3903 SourceLocation TypeLoc);
3905 /// Creates an empty clause with the place for \a NumVars original
3906 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
3907 /// lists, and \a NumComponents expression components.
3909 /// \param C AST context.
3910 /// \param NumVars Number of expressions listed in the clause.
3911 /// \param NumUniqueDeclarations Number of unique base declarations in this
3913 /// \param NumComponentLists Number of unique base declarations in this
3915 /// \param NumComponents Total number of expression components in the clause.
3916 static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
3917 unsigned NumUniqueDeclarations,
3918 unsigned NumComponentLists,
3919 unsigned NumComponents);
3921 /// Fetches mapping kind for the clause.
3922 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
3924 /// Is this an implicit map type?
3925 /// We have to capture 'IsMapTypeImplicit' from the parser for more
3926 /// informative error messages. It helps distinguish map(r) from
3927 /// map(tofrom: r), which is important to print more helpful error
3928 /// messages for some target directives.
3929 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
3931 /// Fetches the map type modifier for the clause.
3932 OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY {
3933 return MapTypeModifier;
3936 /// Fetches location of clause mapping kind.
3937 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
3939 /// Get colon location.
3940 SourceLocation getColonLoc() const { return ColonLoc; }
3942 child_range children() {
3944 reinterpret_cast<Stmt **>(varlist_begin()),
3945 reinterpret_cast<Stmt **>(varlist_end()));
3948 static bool classof(const OMPClause *T) {
3949 return T->getClauseKind() == OMPC_map;
3953 /// This represents 'num_teams' clause in the '#pragma omp ...'
3957 /// #pragma omp teams num_teams(n)
3959 /// In this example directive '#pragma omp teams' has clause 'num_teams'
3960 /// with single expression 'n'.
3961 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
3962 friend class OMPClauseReader;
3964 /// Location of '('.
3965 SourceLocation LParenLoc;
3967 /// NumTeams number.
3968 Stmt *NumTeams = nullptr;
3970 /// Set the NumTeams number.
3972 /// \param E NumTeams number.
3973 void setNumTeams(Expr *E) { NumTeams = E; }
3976 /// Build 'num_teams' clause.
3978 /// \param E Expression associated with this clause.
3979 /// \param HelperE Helper Expression associated with this clause.
3980 /// \param CaptureRegion Innermost OpenMP region where expressions in this
3981 /// clause must be captured.
3982 /// \param StartLoc Starting location of the clause.
3983 /// \param LParenLoc Location of '('.
3984 /// \param EndLoc Ending location of the clause.
3985 OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
3986 SourceLocation StartLoc, SourceLocation LParenLoc,
3987 SourceLocation EndLoc)
3988 : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this),
3989 LParenLoc(LParenLoc), NumTeams(E) {
3990 setPreInitStmt(HelperE, CaptureRegion);
3993 /// Build an empty clause.
3995 : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
3996 OMPClauseWithPreInit(this) {}
3998 /// Sets the location of '('.
3999 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4001 /// Returns the location of '('.
4002 SourceLocation getLParenLoc() const { return LParenLoc; }
4004 /// Return NumTeams number.
4005 Expr *getNumTeams() { return cast<Expr>(NumTeams); }
4007 /// Return NumTeams number.
4008 Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
4010 child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
4012 static bool classof(const OMPClause *T) {
4013 return T->getClauseKind() == OMPC_num_teams;
4017 /// This represents 'thread_limit' clause in the '#pragma omp ...'
4021 /// #pragma omp teams thread_limit(n)
4023 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
4024 /// with single expression 'n'.
4025 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
4026 friend class OMPClauseReader;
4028 /// Location of '('.
4029 SourceLocation LParenLoc;
4031 /// ThreadLimit number.
4032 Stmt *ThreadLimit = nullptr;
4034 /// Set the ThreadLimit number.
4036 /// \param E ThreadLimit number.
4037 void setThreadLimit(Expr *E) { ThreadLimit = E; }
4040 /// Build 'thread_limit' clause.
4042 /// \param E Expression associated with this clause.
4043 /// \param HelperE Helper Expression associated with this clause.
4044 /// \param CaptureRegion Innermost OpenMP region where expressions in this
4045 /// clause must be captured.
4046 /// \param StartLoc Starting location of the clause.
4047 /// \param LParenLoc Location of '('.
4048 /// \param EndLoc Ending location of the clause.
4049 OMPThreadLimitClause(Expr *E, Stmt *HelperE,
4050 OpenMPDirectiveKind CaptureRegion,
4051 SourceLocation StartLoc, SourceLocation LParenLoc,
4052 SourceLocation EndLoc)
4053 : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
4054 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
4055 setPreInitStmt(HelperE, CaptureRegion);
4058 /// Build an empty clause.
4059 OMPThreadLimitClause()
4060 : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
4061 OMPClauseWithPreInit(this) {}
4063 /// Sets the location of '('.
4064 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4066 /// Returns the location of '('.
4067 SourceLocation getLParenLoc() const { return LParenLoc; }
4069 /// Return ThreadLimit number.
4070 Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
4072 /// Return ThreadLimit number.
4073 Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
4075 child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
4077 static bool classof(const OMPClause *T) {
4078 return T->getClauseKind() == OMPC_thread_limit;
4082 /// This represents 'priority' clause in the '#pragma omp ...'
4086 /// #pragma omp task priority(n)
4088 /// In this example directive '#pragma omp teams' has clause 'priority' with
4089 /// single expression 'n'.
4090 class OMPPriorityClause : public OMPClause {
4091 friend class OMPClauseReader;
4093 /// Location of '('.
4094 SourceLocation LParenLoc;
4096 /// Priority number.
4097 Stmt *Priority = nullptr;
4099 /// Set the Priority number.
4101 /// \param E Priority number.
4102 void setPriority(Expr *E) { Priority = E; }
4105 /// Build 'priority' clause.
4107 /// \param E Expression associated with this clause.
4108 /// \param StartLoc Starting location of the clause.
4109 /// \param LParenLoc Location of '('.
4110 /// \param EndLoc Ending location of the clause.
4111 OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
4112 SourceLocation EndLoc)
4113 : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
4116 /// Build an empty clause.
4118 : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()) {}
4120 /// Sets the location of '('.
4121 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4123 /// Returns the location of '('.
4124 SourceLocation getLParenLoc() const { return LParenLoc; }
4126 /// Return Priority number.
4127 Expr *getPriority() { return cast<Expr>(Priority); }
4129 /// Return Priority number.
4130 Expr *getPriority() const { return cast<Expr>(Priority); }
4132 child_range children() { return child_range(&Priority, &Priority + 1); }
4134 static bool classof(const OMPClause *T) {
4135 return T->getClauseKind() == OMPC_priority;
4139 /// This represents 'grainsize' clause in the '#pragma omp ...'
4143 /// #pragma omp taskloop grainsize(4)
4145 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
4146 /// with single expression '4'.
4147 class OMPGrainsizeClause : public OMPClause {
4148 friend class OMPClauseReader;
4150 /// Location of '('.
4151 SourceLocation LParenLoc;
4153 /// Safe iteration space distance.
4154 Stmt *Grainsize = nullptr;
4157 void setGrainsize(Expr *Size) { Grainsize = Size; }
4160 /// Build 'grainsize' clause.
4162 /// \param Size Expression associated with this clause.
4163 /// \param StartLoc Starting location of the clause.
4164 /// \param EndLoc Ending location of the clause.
4165 OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
4166 SourceLocation LParenLoc, SourceLocation EndLoc)
4167 : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
4170 /// Build an empty clause.
4171 explicit OMPGrainsizeClause()
4172 : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()) {}
4174 /// Sets the location of '('.
4175 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4177 /// Returns the location of '('.
4178 SourceLocation getLParenLoc() const { return LParenLoc; }
4180 /// Return safe iteration space distance.
4181 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
4183 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
4185 static bool classof(const OMPClause *T) {
4186 return T->getClauseKind() == OMPC_grainsize;
4190 /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
4193 /// #pragma omp taskloop nogroup
4195 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
4196 class OMPNogroupClause : public OMPClause {
4198 /// Build 'nogroup' clause.
4200 /// \param StartLoc Starting location of the clause.
4201 /// \param EndLoc Ending location of the clause.
4202 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
4203 : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
4205 /// Build an empty clause.
4207 : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
4209 child_range children() {
4210 return child_range(child_iterator(), child_iterator());
4213 static bool classof(const OMPClause *T) {
4214 return T->getClauseKind() == OMPC_nogroup;
4218 /// This represents 'num_tasks' clause in the '#pragma omp ...'
4222 /// #pragma omp taskloop num_tasks(4)
4224 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
4225 /// with single expression '4'.
4226 class OMPNumTasksClause : public OMPClause {
4227 friend class OMPClauseReader;
4229 /// Location of '('.
4230 SourceLocation LParenLoc;
4232 /// Safe iteration space distance.
4233 Stmt *NumTasks = nullptr;
4236 void setNumTasks(Expr *Size) { NumTasks = Size; }
4239 /// Build 'num_tasks' clause.
4241 /// \param Size Expression associated with this clause.
4242 /// \param StartLoc Starting location of the clause.
4243 /// \param EndLoc Ending location of the clause.
4244 OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
4245 SourceLocation LParenLoc, SourceLocation EndLoc)
4246 : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
4249 /// Build an empty clause.
4250 explicit OMPNumTasksClause()
4251 : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()) {}
4253 /// Sets the location of '('.
4254 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4256 /// Returns the location of '('.
4257 SourceLocation getLParenLoc() const { return LParenLoc; }
4259 /// Return safe iteration space distance.
4260 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
4262 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
4264 static bool classof(const OMPClause *T) {
4265 return T->getClauseKind() == OMPC_num_tasks;
4269 /// This represents 'hint' clause in the '#pragma omp ...' directive.
4272 /// #pragma omp critical (name) hint(6)
4274 /// In this example directive '#pragma omp critical' has name 'name' and clause
4275 /// 'hint' with argument '6'.
4276 class OMPHintClause : public OMPClause {
4277 friend class OMPClauseReader;
4279 /// Location of '('.
4280 SourceLocation LParenLoc;
4282 /// Hint expression of the 'hint' clause.
4283 Stmt *Hint = nullptr;
4285 /// Set hint expression.
4286 void setHint(Expr *H) { Hint = H; }
4289 /// Build 'hint' clause with expression \a Hint.
4291 /// \param Hint Hint expression.
4292 /// \param StartLoc Starting location of the clause.
4293 /// \param LParenLoc Location of '('.
4294 /// \param EndLoc Ending location of the clause.
4295 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
4296 SourceLocation EndLoc)
4297 : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
4300 /// Build an empty clause.
4301 OMPHintClause() : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()) {}
4303 /// Sets the location of '('.
4304 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4306 /// Returns the location of '('.
4307 SourceLocation getLParenLoc() const { return LParenLoc; }
4309 /// Returns number of threads.
4310 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
4312 child_range children() { return child_range(&Hint, &Hint + 1); }
4314 static bool classof(const OMPClause *T) {
4315 return T->getClauseKind() == OMPC_hint;
4319 /// This represents 'dist_schedule' clause in the '#pragma omp ...'
4323 /// #pragma omp distribute dist_schedule(static, 3)
4325 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
4326 /// clause with arguments 'static' and '3'.
4327 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
4328 friend class OMPClauseReader;
4330 /// Location of '('.
4331 SourceLocation LParenLoc;
4333 /// A kind of the 'schedule' clause.
4334 OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
4336 /// Start location of the schedule kind in source code.
4337 SourceLocation KindLoc;
4339 /// Location of ',' (if any).
4340 SourceLocation CommaLoc;
4343 Expr *ChunkSize = nullptr;
4345 /// Set schedule kind.
4347 /// \param K Schedule kind.
4348 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
4350 /// Sets the location of '('.
4352 /// \param Loc Location of '('.
4353 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4355 /// Set schedule kind start location.
4357 /// \param KLoc Schedule kind location.
4358 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
4360 /// Set location of ','.
4362 /// \param Loc Location of ','.
4363 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
4367 /// \param E Chunk size.
4368 void setChunkSize(Expr *E) { ChunkSize = E; }
4371 /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
4372 /// size expression \a ChunkSize.
4374 /// \param StartLoc Starting location of the clause.
4375 /// \param LParenLoc Location of '('.
4376 /// \param KLoc Starting location of the argument.
4377 /// \param CommaLoc Location of ','.
4378 /// \param EndLoc Ending location of the clause.
4379 /// \param Kind DistSchedule kind.
4380 /// \param ChunkSize Chunk size.
4381 /// \param HelperChunkSize Helper chunk size for combined directives.
4382 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4383 SourceLocation KLoc, SourceLocation CommaLoc,
4384 SourceLocation EndLoc,
4385 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
4386 Stmt *HelperChunkSize)
4387 : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc),
4388 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
4389 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
4390 setPreInitStmt(HelperChunkSize);
4393 /// Build an empty clause.
4394 explicit OMPDistScheduleClause()
4395 : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()),
4396 OMPClauseWithPreInit(this) {}
4398 /// Get kind of the clause.
4399 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
4401 /// Get location of '('.
4402 SourceLocation getLParenLoc() { return LParenLoc; }
4404 /// Get kind location.
4405 SourceLocation getDistScheduleKindLoc() { return KindLoc; }
4407 /// Get location of ','.
4408 SourceLocation getCommaLoc() { return CommaLoc; }
4411 Expr *getChunkSize() { return ChunkSize; }
4414 const Expr *getChunkSize() const { return ChunkSize; }
4416 child_range children() {
4417 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
4418 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
4421 static bool classof(const OMPClause *T) {
4422 return T->getClauseKind() == OMPC_dist_schedule;
4426 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
4429 /// #pragma omp target defaultmap(tofrom: scalar)
4431 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
4432 /// 'scalar' with modifier 'tofrom'.
4433 class OMPDefaultmapClause : public OMPClause {
4434 friend class OMPClauseReader;
4436 /// Location of '('.
4437 SourceLocation LParenLoc;
4439 /// Modifiers for 'defaultmap' clause.
4440 OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
4442 /// Locations of modifiers.
4443 SourceLocation ModifierLoc;
4445 /// A kind of the 'defaultmap' clause.
4446 OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
4448 /// Start location of the defaultmap kind in source code.
4449 SourceLocation KindLoc;
4451 /// Set defaultmap kind.
4453 /// \param K Defaultmap kind.
4454 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
4456 /// Set the defaultmap modifier.
4458 /// \param M Defaultmap modifier.
4459 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
4463 /// Set location of the defaultmap modifier.
4464 void setDefaultmapModifierLoc(SourceLocation Loc) {
4468 /// Sets the location of '('.
4470 /// \param Loc Location of '('.
4471 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4473 /// Set defaultmap kind start location.
4475 /// \param KLoc Defaultmap kind location.
4476 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
4479 /// Build 'defaultmap' clause with defaultmap kind \a Kind
4481 /// \param StartLoc Starting location of the clause.
4482 /// \param LParenLoc Location of '('.
4483 /// \param KLoc Starting location of the argument.
4484 /// \param EndLoc Ending location of the clause.
4485 /// \param Kind Defaultmap kind.
4486 /// \param M The modifier applied to 'defaultmap' clause.
4487 /// \param MLoc Location of the modifier
4488 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4489 SourceLocation MLoc, SourceLocation KLoc,
4490 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
4491 OpenMPDefaultmapClauseModifier M)
4492 : OMPClause(OMPC_defaultmap, StartLoc, EndLoc), LParenLoc(LParenLoc),
4493 Modifier(M), ModifierLoc(MLoc), Kind(Kind), KindLoc(KLoc) {}
4495 /// Build an empty clause.
4496 explicit OMPDefaultmapClause()
4497 : OMPClause(OMPC_defaultmap, SourceLocation(), SourceLocation()) {}
4499 /// Get kind of the clause.
4500 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
4502 /// Get the modifier of the clause.
4503 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
4507 /// Get location of '('.
4508 SourceLocation getLParenLoc() { return LParenLoc; }
4510 /// Get kind location.
4511 SourceLocation getDefaultmapKindLoc() { return KindLoc; }
4513 /// Get the modifier location.
4514 SourceLocation getDefaultmapModifierLoc() const {
4518 child_range children() {
4519 return child_range(child_iterator(), child_iterator());
4522 static bool classof(const OMPClause *T) {
4523 return T->getClauseKind() == OMPC_defaultmap;
4527 /// This represents clause 'to' in the '#pragma omp ...'
4531 /// #pragma omp target update to(a,b)
4533 /// In this example directive '#pragma omp target update' has clause 'to'
4534 /// with the variables 'a' and 'b'.
4535 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
4536 private llvm::TrailingObjects<
4537 OMPToClause, Expr *, ValueDecl *, unsigned,
4538 OMPClauseMappableExprCommon::MappableComponent> {
4539 friend class OMPClauseReader;
4540 friend OMPMappableExprListClause;
4541 friend OMPVarListClause;
4542 friend TrailingObjects;
4544 /// Build clause with number of variables \a NumVars.
4546 /// \param StartLoc Starting location of the clause.
4547 /// \param EndLoc Ending location of the clause.
4548 /// \param NumVars Number of expressions listed in this clause.
4549 /// \param NumUniqueDeclarations Number of unique base declarations in this
4551 /// \param NumComponentLists Number of component lists in this clause.
4552 /// \param NumComponents Total number of expression components in the clause.
4553 explicit OMPToClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4554 SourceLocation EndLoc, unsigned NumVars,
4555 unsigned NumUniqueDeclarations,
4556 unsigned NumComponentLists, unsigned NumComponents)
4557 : OMPMappableExprListClause(OMPC_to, StartLoc, LParenLoc, EndLoc, NumVars,
4558 NumUniqueDeclarations, NumComponentLists,
4561 /// Build an empty clause.
4563 /// \param NumVars Number of expressions listed in this clause.
4564 /// \param NumUniqueDeclarations Number of unique base declarations in this
4566 /// \param NumComponentLists Number of component lists in this clause.
4567 /// \param NumComponents Total number of expression components in the clause.
4568 explicit OMPToClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4569 unsigned NumComponentLists, unsigned NumComponents)
4570 : OMPMappableExprListClause(
4571 OMPC_to, SourceLocation(), SourceLocation(), SourceLocation(),
4572 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4574 /// Define the sizes of each trailing object array except the last one. This
4575 /// is required for TrailingObjects to work properly.
4576 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4577 return varlist_size();
4579 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4580 return getUniqueDeclarationsNum();
4582 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4583 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4587 /// Creates clause with a list of variables \a Vars.
4589 /// \param C AST context.
4590 /// \param StartLoc Starting location of the clause.
4591 /// \param EndLoc Ending location of the clause.
4592 /// \param Vars The original expression used in the clause.
4593 /// \param Declarations Declarations used in the clause.
4594 /// \param ComponentLists Component lists used in the clause.
4595 static OMPToClause *Create(const ASTContext &C, SourceLocation StartLoc,
4596 SourceLocation LParenLoc, SourceLocation EndLoc,
4597 ArrayRef<Expr *> Vars,
4598 ArrayRef<ValueDecl *> Declarations,
4599 MappableExprComponentListsRef ComponentLists);
4601 /// Creates an empty clause with the place for \a NumVars variables.
4603 /// \param C AST context.
4604 /// \param NumVars Number of expressions listed in the clause.
4605 /// \param NumUniqueDeclarations Number of unique base declarations in this
4607 /// \param NumComponentLists Number of unique base declarations in this
4609 /// \param NumComponents Total number of expression components in the clause.
4610 static OMPToClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4611 unsigned NumUniqueDeclarations,
4612 unsigned NumComponentLists,
4613 unsigned NumComponents);
4615 child_range children() {
4616 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4617 reinterpret_cast<Stmt **>(varlist_end()));
4620 static bool classof(const OMPClause *T) {
4621 return T->getClauseKind() == OMPC_to;
4625 /// This represents clause 'from' in the '#pragma omp ...'
4629 /// #pragma omp target update from(a,b)
4631 /// In this example directive '#pragma omp target update' has clause 'from'
4632 /// with the variables 'a' and 'b'.
4633 class OMPFromClause final
4634 : public OMPMappableExprListClause<OMPFromClause>,
4635 private llvm::TrailingObjects<
4636 OMPFromClause, Expr *, ValueDecl *, unsigned,
4637 OMPClauseMappableExprCommon::MappableComponent> {
4638 friend class OMPClauseReader;
4639 friend OMPMappableExprListClause;
4640 friend OMPVarListClause;
4641 friend TrailingObjects;
4643 /// Build clause with number of variables \a NumVars.
4645 /// \param StartLoc Starting location of the clause.
4646 /// \param EndLoc Ending location of the clause.
4647 /// \param NumVars Number of expressions listed in this clause.
4648 /// \param NumUniqueDeclarations Number of unique base declarations in this
4650 /// \param NumComponentLists Number of component lists in this clause.
4651 /// \param NumComponents Total number of expression components in the clause.
4652 explicit OMPFromClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4653 SourceLocation EndLoc, unsigned NumVars,
4654 unsigned NumUniqueDeclarations,
4655 unsigned NumComponentLists, unsigned NumComponents)
4656 : OMPMappableExprListClause(OMPC_from, StartLoc, LParenLoc, EndLoc,
4657 NumVars, NumUniqueDeclarations,
4658 NumComponentLists, NumComponents) {}
4660 /// Build an empty clause.
4662 /// \param NumVars Number of expressions listed in this clause.
4663 /// \param NumUniqueDeclarations Number of unique base declarations in this
4665 /// \param NumComponentLists Number of component lists in this clause.
4666 /// \param NumComponents Total number of expression components in the clause.
4667 explicit OMPFromClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4668 unsigned NumComponentLists, unsigned NumComponents)
4669 : OMPMappableExprListClause(
4670 OMPC_from, SourceLocation(), SourceLocation(), SourceLocation(),
4671 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4673 /// Define the sizes of each trailing object array except the last one. This
4674 /// is required for TrailingObjects to work properly.
4675 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4676 return varlist_size();
4678 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4679 return getUniqueDeclarationsNum();
4681 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4682 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4686 /// Creates clause with a list of variables \a Vars.
4688 /// \param C AST context.
4689 /// \param StartLoc Starting location of the clause.
4690 /// \param EndLoc Ending location of the clause.
4691 /// \param Vars The original expression used in the clause.
4692 /// \param Declarations Declarations used in the clause.
4693 /// \param ComponentLists Component lists used in the clause.
4694 static OMPFromClause *Create(const ASTContext &C, SourceLocation StartLoc,
4695 SourceLocation LParenLoc, SourceLocation EndLoc,
4696 ArrayRef<Expr *> Vars,
4697 ArrayRef<ValueDecl *> Declarations,
4698 MappableExprComponentListsRef ComponentLists);
4700 /// Creates an empty clause with the place for \a NumVars variables.
4702 /// \param C AST context.
4703 /// \param NumVars Number of expressions listed in the clause.
4704 /// \param NumUniqueDeclarations Number of unique base declarations in this
4706 /// \param NumComponentLists Number of unique base declarations in this
4708 /// \param NumComponents Total number of expression components in the clause.
4709 static OMPFromClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4710 unsigned NumUniqueDeclarations,
4711 unsigned NumComponentLists,
4712 unsigned NumComponents);
4714 child_range children() {
4715 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4716 reinterpret_cast<Stmt **>(varlist_end()));
4719 static bool classof(const OMPClause *T) {
4720 return T->getClauseKind() == OMPC_from;
4724 /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
4728 /// #pragma omp target data use_device_ptr(a,b)
4730 /// In this example directive '#pragma omp target data' has clause
4731 /// 'use_device_ptr' with the variables 'a' and 'b'.
4732 class OMPUseDevicePtrClause final
4733 : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
4734 private llvm::TrailingObjects<
4735 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
4736 OMPClauseMappableExprCommon::MappableComponent> {
4737 friend class OMPClauseReader;
4738 friend OMPMappableExprListClause;
4739 friend OMPVarListClause;
4740 friend TrailingObjects;
4742 /// Build clause with number of variables \a NumVars.
4744 /// \param StartLoc Starting location of the clause.
4745 /// \param EndLoc Ending location of the clause.
4746 /// \param NumVars Number of expressions listed in this clause.
4747 /// \param NumUniqueDeclarations Number of unique base declarations in this
4749 /// \param NumComponentLists Number of component lists in this clause.
4750 /// \param NumComponents Total number of expression components in the clause.
4751 explicit OMPUseDevicePtrClause(SourceLocation StartLoc,
4752 SourceLocation LParenLoc,
4753 SourceLocation EndLoc, unsigned NumVars,
4754 unsigned NumUniqueDeclarations,
4755 unsigned NumComponentLists,
4756 unsigned NumComponents)
4757 : OMPMappableExprListClause(OMPC_use_device_ptr, StartLoc, LParenLoc,
4758 EndLoc, NumVars, NumUniqueDeclarations,
4759 NumComponentLists, NumComponents) {}
4761 /// Build an empty clause.
4763 /// \param NumVars Number of expressions listed in this clause.
4764 /// \param NumUniqueDeclarations Number of unique base declarations in this
4766 /// \param NumComponentLists Number of component lists in this clause.
4767 /// \param NumComponents Total number of expression components in the clause.
4768 explicit OMPUseDevicePtrClause(unsigned NumVars,
4769 unsigned NumUniqueDeclarations,
4770 unsigned NumComponentLists,
4771 unsigned NumComponents)
4772 : OMPMappableExprListClause(OMPC_use_device_ptr, SourceLocation(),
4773 SourceLocation(), SourceLocation(), NumVars,
4774 NumUniqueDeclarations, NumComponentLists,
4777 /// Define the sizes of each trailing object array except the last one. This
4778 /// is required for TrailingObjects to work properly.
4779 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4780 return 3 * varlist_size();
4782 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4783 return getUniqueDeclarationsNum();
4785 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4786 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4789 /// Sets the list of references to private copies with initializers for new
4790 /// private variables.
4791 /// \param VL List of references.
4792 void setPrivateCopies(ArrayRef<Expr *> VL);
4794 /// Gets the list of references to private copies with initializers for new
4795 /// private variables.
4796 MutableArrayRef<Expr *> getPrivateCopies() {
4797 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4799 ArrayRef<const Expr *> getPrivateCopies() const {
4800 return llvm::makeArrayRef(varlist_end(), varlist_size());
4803 /// Sets the list of references to initializer variables for new private
4805 /// \param VL List of references.
4806 void setInits(ArrayRef<Expr *> VL);
4808 /// Gets the list of references to initializer variables for new private
4810 MutableArrayRef<Expr *> getInits() {
4811 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
4813 ArrayRef<const Expr *> getInits() const {
4814 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
4818 /// Creates clause with a list of variables \a Vars.
4820 /// \param C AST context.
4821 /// \param StartLoc Starting location of the clause.
4822 /// \param EndLoc Ending location of the clause.
4823 /// \param Vars The original expression used in the clause.
4824 /// \param PrivateVars Expressions referring to private copies.
4825 /// \param Inits Expressions referring to private copy initializers.
4826 /// \param Declarations Declarations used in the clause.
4827 /// \param ComponentLists Component lists used in the clause.
4828 static OMPUseDevicePtrClause *
4829 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4830 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
4831 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
4832 ArrayRef<ValueDecl *> Declarations,
4833 MappableExprComponentListsRef ComponentLists);
4835 /// Creates an empty clause with the place for \a NumVars variables.
4837 /// \param C AST context.
4838 /// \param NumVars Number of expressions listed in the clause.
4839 /// \param NumUniqueDeclarations Number of unique base declarations in this
4841 /// \param NumComponentLists Number of unique base declarations in this
4843 /// \param NumComponents Total number of expression components in the clause.
4844 static OMPUseDevicePtrClause *CreateEmpty(const ASTContext &C,
4846 unsigned NumUniqueDeclarations,
4847 unsigned NumComponentLists,
4848 unsigned NumComponents);
4850 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
4851 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
4852 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
4853 using private_copies_const_range =
4854 llvm::iterator_range<private_copies_const_iterator>;
4856 private_copies_range private_copies() {
4857 return private_copies_range(getPrivateCopies().begin(),
4858 getPrivateCopies().end());
4861 private_copies_const_range private_copies() const {
4862 return private_copies_const_range(getPrivateCopies().begin(),
4863 getPrivateCopies().end());
4866 using inits_iterator = MutableArrayRef<Expr *>::iterator;
4867 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
4868 using inits_range = llvm::iterator_range<inits_iterator>;
4869 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
4871 inits_range inits() {
4872 return inits_range(getInits().begin(), getInits().end());
4875 inits_const_range inits() const {
4876 return inits_const_range(getInits().begin(), getInits().end());
4879 child_range children() {
4880 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4881 reinterpret_cast<Stmt **>(varlist_end()));
4884 static bool classof(const OMPClause *T) {
4885 return T->getClauseKind() == OMPC_use_device_ptr;
4889 /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
4893 /// #pragma omp target is_device_ptr(a,b)
4895 /// In this example directive '#pragma omp target' has clause
4896 /// 'is_device_ptr' with the variables 'a' and 'b'.
4897 class OMPIsDevicePtrClause final
4898 : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
4899 private llvm::TrailingObjects<
4900 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
4901 OMPClauseMappableExprCommon::MappableComponent> {
4902 friend class OMPClauseReader;
4903 friend OMPMappableExprListClause;
4904 friend OMPVarListClause;
4905 friend TrailingObjects;
4907 /// Build clause with number of variables \a NumVars.
4909 /// \param StartLoc Starting location of the clause.
4910 /// \param EndLoc Ending location of the clause.
4911 /// \param NumVars Number of expressions listed in this clause.
4912 /// \param NumUniqueDeclarations Number of unique base declarations in this
4914 /// \param NumComponentLists Number of component lists in this clause.
4915 /// \param NumComponents Total number of expression components in the clause.
4916 explicit OMPIsDevicePtrClause(SourceLocation StartLoc,
4917 SourceLocation LParenLoc, SourceLocation EndLoc,
4919 unsigned NumUniqueDeclarations,
4920 unsigned NumComponentLists,
4921 unsigned NumComponents)
4922 : OMPMappableExprListClause(OMPC_is_device_ptr, StartLoc, LParenLoc,
4923 EndLoc, NumVars, NumUniqueDeclarations,
4924 NumComponentLists, NumComponents) {}
4926 /// Build an empty clause.
4928 /// \param NumVars Number of expressions listed in this clause.
4929 /// \param NumUniqueDeclarations Number of unique base declarations in this
4931 /// \param NumComponentLists Number of component lists in this clause.
4932 /// \param NumComponents Total number of expression components in the clause.
4933 explicit OMPIsDevicePtrClause(unsigned NumVars,
4934 unsigned NumUniqueDeclarations,
4935 unsigned NumComponentLists,
4936 unsigned NumComponents)
4937 : OMPMappableExprListClause(OMPC_is_device_ptr, SourceLocation(),
4938 SourceLocation(), SourceLocation(), NumVars,
4939 NumUniqueDeclarations, NumComponentLists,
4942 /// Define the sizes of each trailing object array except the last one. This
4943 /// is required for TrailingObjects to work properly.
4944 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4945 return varlist_size();
4947 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4948 return getUniqueDeclarationsNum();
4950 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4951 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4955 /// Creates clause with a list of variables \a Vars.
4957 /// \param C AST context.
4958 /// \param StartLoc Starting location of the clause.
4959 /// \param EndLoc Ending location of the clause.
4960 /// \param Vars The original expression used in the clause.
4961 /// \param Declarations Declarations used in the clause.
4962 /// \param ComponentLists Component lists used in the clause.
4963 static OMPIsDevicePtrClause *
4964 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4965 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
4966 ArrayRef<ValueDecl *> Declarations,
4967 MappableExprComponentListsRef ComponentLists);
4969 /// Creates an empty clause with the place for \a NumVars variables.
4971 /// \param C AST context.
4972 /// \param NumVars Number of expressions listed in the clause.
4973 /// \param NumUniqueDeclarations Number of unique base declarations in this
4975 /// \param NumComponentLists Number of unique base declarations in this
4977 /// \param NumComponents Total number of expression components in the clause.
4978 static OMPIsDevicePtrClause *CreateEmpty(const ASTContext &C,
4980 unsigned NumUniqueDeclarations,
4981 unsigned NumComponentLists,
4982 unsigned NumComponents);
4984 child_range children() {
4985 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4986 reinterpret_cast<Stmt **>(varlist_end()));
4989 static bool classof(const OMPClause *T) {
4990 return T->getClauseKind() == OMPC_is_device_ptr;
4994 } // namespace clang
4996 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H