1 //===- OpenMPClause.h - Classes for OpenMP clauses --------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file defines OpenMP AST classes for clauses.
11 /// There are clauses for executable directives, clauses for declarative
12 /// directives and clauses which can be used in both kinds of directives.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
19 #include "clang/AST/Decl.h"
20 #include "clang/AST/DeclarationName.h"
21 #include "clang/AST/Expr.h"
22 #include "clang/AST/NestedNameSpecifier.h"
23 #include "clang/AST/Stmt.h"
24 #include "clang/AST/StmtIterator.h"
25 #include "clang/Basic/LLVM.h"
26 #include "clang/Basic/OpenMPKinds.h"
27 #include "clang/Basic/SourceLocation.h"
28 #include "llvm/ADT/ArrayRef.h"
29 #include "llvm/ADT/MapVector.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/ADT/iterator.h"
32 #include "llvm/ADT/iterator_range.h"
33 #include "llvm/Support/Casting.h"
34 #include "llvm/Support/Compiler.h"
35 #include "llvm/Support/TrailingObjects.h"
45 //===----------------------------------------------------------------------===//
46 // AST classes for clauses.
47 //===----------------------------------------------------------------------===//
49 /// This is a basic class for representing single OpenMP clause.
51 /// Starting location of the clause (the clause keyword).
52 SourceLocation StartLoc;
54 /// Ending location of the clause.
55 SourceLocation EndLoc;
57 /// Kind of the clause.
58 OpenMPClauseKind Kind;
61 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
62 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
65 /// Returns the starting location of the clause.
66 SourceLocation getBeginLoc() const { return StartLoc; }
68 /// Returns the ending location of the clause.
69 SourceLocation getEndLoc() const { return EndLoc; }
71 /// Sets the starting location of the clause.
72 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
74 /// Sets the ending location of the clause.
75 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
77 /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
78 OpenMPClauseKind getClauseKind() const { return Kind; }
80 bool isImplicit() const { return StartLoc.isInvalid(); }
82 using child_iterator = StmtIterator;
83 using const_child_iterator = ConstStmtIterator;
84 using child_range = llvm::iterator_range<child_iterator>;
85 using const_child_range = llvm::iterator_range<const_child_iterator>;
87 child_range children();
88 const_child_range children() const {
89 auto Children = const_cast<OMPClause *>(this)->children();
90 return const_child_range(Children.begin(), Children.end());
93 /// Get the iterator range for the expressions used in the clauses. Used
94 /// expressions include only the children that must be evaluated at the
95 /// runtime before entering the construct.
96 child_range used_children();
97 const_child_range used_children() const {
98 auto Children = const_cast<OMPClause *>(this)->children();
99 return const_child_range(Children.begin(), Children.end());
102 static bool classof(const OMPClause *) { return true; }
105 /// Class that handles pre-initialization statement for some clauses, like
106 /// 'shedule', 'firstprivate' etc.
107 class OMPClauseWithPreInit {
108 friend class OMPClauseReader;
110 /// Pre-initialization statement for the clause.
111 Stmt *PreInit = nullptr;
113 /// Region that captures the associated stmt.
114 OpenMPDirectiveKind CaptureRegion = OMPD_unknown;
117 OMPClauseWithPreInit(const OMPClause *This) {
118 assert(get(This) && "get is not tuned for pre-init.");
121 /// Set pre-initialization statement for the clause.
122 void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion = OMPD_unknown) {
124 CaptureRegion = ThisRegion;
128 /// Get pre-initialization statement for the clause.
129 const Stmt *getPreInitStmt() const { return PreInit; }
131 /// Get pre-initialization statement for the clause.
132 Stmt *getPreInitStmt() { return PreInit; }
134 /// Get capture region for the stmt in the clause.
135 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
137 static OMPClauseWithPreInit *get(OMPClause *C);
138 static const OMPClauseWithPreInit *get(const OMPClause *C);
141 /// Class that handles post-update expression for some clauses, like
142 /// 'lastprivate', 'reduction' etc.
143 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
144 friend class OMPClauseReader;
146 /// Post-update expression for the clause.
147 Expr *PostUpdate = nullptr;
150 OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
151 assert(get(This) && "get is not tuned for post-update.");
154 /// Set pre-initialization statement for the clause.
155 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
158 /// Get post-update expression for the clause.
159 const Expr *getPostUpdateExpr() const { return PostUpdate; }
161 /// Get post-update expression for the clause.
162 Expr *getPostUpdateExpr() { return PostUpdate; }
164 static OMPClauseWithPostUpdate *get(OMPClause *C);
165 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
168 /// This structure contains most locations needed for by an OMPVarListClause.
169 struct OMPVarListLocTy {
170 /// Starting location of the clause (the clause keyword).
171 SourceLocation StartLoc;
173 SourceLocation LParenLoc;
174 /// Ending location of the clause.
175 SourceLocation EndLoc;
176 OMPVarListLocTy() = default;
177 OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc,
178 SourceLocation EndLoc)
179 : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {}
182 /// This represents clauses with the list of variables like 'private',
183 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
184 /// '#pragma omp ...' directives.
185 template <class T> class OMPVarListClause : public OMPClause {
186 friend class OMPClauseReader;
189 SourceLocation LParenLoc;
191 /// Number of variables in the list.
195 /// Build a clause with \a N variables
197 /// \param K Kind of the clause.
198 /// \param StartLoc Starting location of the clause (the clause keyword).
199 /// \param LParenLoc Location of '('.
200 /// \param EndLoc Ending location of the clause.
201 /// \param N Number of the variables in the clause.
202 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
203 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
204 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
206 /// Fetches list of variables associated with this clause.
207 MutableArrayRef<Expr *> getVarRefs() {
208 return MutableArrayRef<Expr *>(
209 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
212 /// Sets the list of variables for this clause.
213 void setVarRefs(ArrayRef<Expr *> VL) {
214 assert(VL.size() == NumVars &&
215 "Number of variables is not the same as the preallocated buffer");
216 std::copy(VL.begin(), VL.end(),
217 static_cast<T *>(this)->template getTrailingObjects<Expr *>());
221 using varlist_iterator = MutableArrayRef<Expr *>::iterator;
222 using varlist_const_iterator = ArrayRef<const Expr *>::iterator;
223 using varlist_range = llvm::iterator_range<varlist_iterator>;
224 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
226 unsigned varlist_size() const { return NumVars; }
227 bool varlist_empty() const { return NumVars == 0; }
229 varlist_range varlists() {
230 return varlist_range(varlist_begin(), varlist_end());
232 varlist_const_range varlists() const {
233 return varlist_const_range(varlist_begin(), varlist_end());
236 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
237 varlist_iterator varlist_end() { return getVarRefs().end(); }
238 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
239 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
241 /// Sets the location of '('.
242 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
244 /// Returns the location of '('.
245 SourceLocation getLParenLoc() const { return LParenLoc; }
247 /// Fetches list of all variables in the clause.
248 ArrayRef<const Expr *> getVarRefs() const {
249 return llvm::makeArrayRef(
250 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
255 /// This represents 'allocator' clause in the '#pragma omp ...'
259 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
261 /// In this example directive '#pragma omp allocate' has simple 'allocator'
262 /// clause with the allocator 'omp_default_mem_alloc'.
263 class OMPAllocatorClause : public OMPClause {
264 friend class OMPClauseReader;
267 SourceLocation LParenLoc;
269 /// Expression with the allocator.
270 Stmt *Allocator = nullptr;
273 void setAllocator(Expr *A) { Allocator = A; }
276 /// Build 'allocator' clause with the given allocator.
278 /// \param A Allocator.
279 /// \param StartLoc Starting location of the clause.
280 /// \param LParenLoc Location of '('.
281 /// \param EndLoc Ending location of the clause.
282 OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
283 SourceLocation EndLoc)
284 : OMPClause(OMPC_allocator, StartLoc, EndLoc), LParenLoc(LParenLoc),
287 /// Build an empty clause.
289 : OMPClause(OMPC_allocator, SourceLocation(), SourceLocation()) {}
291 /// Sets the location of '('.
292 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
294 /// Returns the location of '('.
295 SourceLocation getLParenLoc() const { return LParenLoc; }
297 /// Returns allocator.
298 Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); }
300 child_range children() { return child_range(&Allocator, &Allocator + 1); }
302 const_child_range children() const {
303 return const_child_range(&Allocator, &Allocator + 1);
306 child_range used_children() {
307 return child_range(child_iterator(), child_iterator());
309 const_child_range used_children() const {
310 return const_child_range(const_child_iterator(), const_child_iterator());
313 static bool classof(const OMPClause *T) {
314 return T->getClauseKind() == OMPC_allocator;
318 /// This represents clause 'allocate' in the '#pragma omp ...' directives.
321 /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
323 /// In this example directive '#pragma omp parallel' has clause 'private'
324 /// and clause 'allocate' for the variable 'a'.
325 class OMPAllocateClause final
326 : public OMPVarListClause<OMPAllocateClause>,
327 private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
328 friend class OMPClauseReader;
329 friend OMPVarListClause;
330 friend TrailingObjects;
332 /// Allocator specified in the clause, or 'nullptr' if the default one is
334 Expr *Allocator = nullptr;
335 /// Position of the ':' delimiter in the clause;
336 SourceLocation ColonLoc;
338 /// Build clause with number of variables \a N.
340 /// \param StartLoc Starting location of the clause.
341 /// \param LParenLoc Location of '('.
342 /// \param Allocator Allocator expression.
343 /// \param ColonLoc Location of ':' delimiter.
344 /// \param EndLoc Ending location of the clause.
345 /// \param N Number of the variables in the clause.
346 OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
347 Expr *Allocator, SourceLocation ColonLoc,
348 SourceLocation EndLoc, unsigned N)
349 : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, StartLoc, LParenLoc,
351 Allocator(Allocator), ColonLoc(ColonLoc) {}
353 /// Build an empty clause.
355 /// \param N Number of variables.
356 explicit OMPAllocateClause(unsigned N)
357 : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, SourceLocation(),
358 SourceLocation(), SourceLocation(),
361 /// Sets location of ':' symbol in clause.
362 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
364 void setAllocator(Expr *A) { Allocator = A; }
367 /// Creates clause with a list of variables \a VL.
369 /// \param C AST context.
370 /// \param StartLoc Starting location of the clause.
371 /// \param LParenLoc Location of '('.
372 /// \param Allocator Allocator expression.
373 /// \param ColonLoc Location of ':' delimiter.
374 /// \param EndLoc Ending location of the clause.
375 /// \param VL List of references to the variables.
376 static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
377 SourceLocation LParenLoc, Expr *Allocator,
378 SourceLocation ColonLoc,
379 SourceLocation EndLoc, ArrayRef<Expr *> VL);
381 /// Returns the allocator expression or nullptr, if no allocator is specified.
382 Expr *getAllocator() const { return Allocator; }
384 /// Returns the location of the ':' delimiter.
385 SourceLocation getColonLoc() const { return ColonLoc; }
387 /// Creates an empty clause with the place for \a N variables.
389 /// \param C AST context.
390 /// \param N The number of variables.
391 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
393 child_range children() {
394 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
395 reinterpret_cast<Stmt **>(varlist_end()));
398 const_child_range children() const {
399 auto Children = const_cast<OMPAllocateClause *>(this)->children();
400 return const_child_range(Children.begin(), Children.end());
403 child_range used_children() {
404 return child_range(child_iterator(), child_iterator());
406 const_child_range used_children() const {
407 return const_child_range(const_child_iterator(), const_child_iterator());
410 static bool classof(const OMPClause *T) {
411 return T->getClauseKind() == OMPC_allocate;
415 /// This represents 'if' clause in the '#pragma omp ...' directive.
418 /// #pragma omp parallel if(parallel:a > 5)
420 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
421 /// condition 'a > 5' and directive name modifier 'parallel'.
422 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
423 friend class OMPClauseReader;
426 SourceLocation LParenLoc;
428 /// Condition of the 'if' clause.
429 Stmt *Condition = nullptr;
431 /// Location of ':' (if any).
432 SourceLocation ColonLoc;
434 /// Directive name modifier for the clause.
435 OpenMPDirectiveKind NameModifier = OMPD_unknown;
437 /// Name modifier location.
438 SourceLocation NameModifierLoc;
441 void setCondition(Expr *Cond) { Condition = Cond; }
443 /// Set directive name modifier for the clause.
444 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
446 /// Set location of directive name modifier for the clause.
447 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
449 /// Set location of ':'.
450 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
453 /// Build 'if' clause with condition \a Cond.
455 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
456 /// \param Cond Condition of the clause.
457 /// \param HelperCond Helper condition for the clause.
458 /// \param CaptureRegion Innermost OpenMP region where expressions in this
459 /// clause must be captured.
460 /// \param StartLoc Starting location of the clause.
461 /// \param LParenLoc Location of '('.
462 /// \param NameModifierLoc Location of directive name modifier.
463 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
464 /// \param EndLoc Ending location of the clause.
465 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
466 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
467 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
468 SourceLocation ColonLoc, SourceLocation EndLoc)
469 : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this),
470 LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
471 NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) {
472 setPreInitStmt(HelperCond, CaptureRegion);
475 /// Build an empty clause.
477 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
478 OMPClauseWithPreInit(this) {}
480 /// Sets the location of '('.
481 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
483 /// Returns the location of '('.
484 SourceLocation getLParenLoc() const { return LParenLoc; }
486 /// Return the location of ':'.
487 SourceLocation getColonLoc() const { return ColonLoc; }
489 /// Returns condition.
490 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
492 /// Return directive name modifier associated with the clause.
493 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
495 /// Return the location of directive name modifier.
496 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
498 child_range children() { return child_range(&Condition, &Condition + 1); }
500 const_child_range children() const {
501 return const_child_range(&Condition, &Condition + 1);
504 child_range used_children();
505 const_child_range used_children() const {
506 auto Children = const_cast<OMPIfClause *>(this)->used_children();
507 return const_child_range(Children.begin(), Children.end());
510 static bool classof(const OMPClause *T) {
511 return T->getClauseKind() == OMPC_if;
515 /// This represents 'final' clause in the '#pragma omp ...' directive.
518 /// #pragma omp task final(a > 5)
520 /// In this example directive '#pragma omp task' has simple 'final'
521 /// clause with condition 'a > 5'.
522 class OMPFinalClause : public OMPClause, public OMPClauseWithPreInit {
523 friend class OMPClauseReader;
526 SourceLocation LParenLoc;
528 /// Condition of the 'if' clause.
529 Stmt *Condition = nullptr;
532 void setCondition(Expr *Cond) { Condition = Cond; }
535 /// Build 'final' clause with condition \a Cond.
537 /// \param Cond Condition of the clause.
538 /// \param HelperCond Helper condition for the construct.
539 /// \param CaptureRegion Innermost OpenMP region where expressions in this
540 /// clause must be captured.
541 /// \param StartLoc Starting location of the clause.
542 /// \param LParenLoc Location of '('.
543 /// \param EndLoc Ending location of the clause.
544 OMPFinalClause(Expr *Cond, Stmt *HelperCond,
545 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
546 SourceLocation LParenLoc, SourceLocation EndLoc)
547 : OMPClause(OMPC_final, StartLoc, EndLoc), OMPClauseWithPreInit(this),
548 LParenLoc(LParenLoc), Condition(Cond) {
549 setPreInitStmt(HelperCond, CaptureRegion);
552 /// Build an empty clause.
554 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
555 OMPClauseWithPreInit(this) {}
557 /// Sets the location of '('.
558 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
560 /// Returns the location of '('.
561 SourceLocation getLParenLoc() const { return LParenLoc; }
563 /// Returns condition.
564 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
566 child_range children() { return child_range(&Condition, &Condition + 1); }
568 const_child_range children() const {
569 return const_child_range(&Condition, &Condition + 1);
572 child_range used_children();
573 const_child_range used_children() const {
574 auto Children = const_cast<OMPFinalClause *>(this)->used_children();
575 return const_child_range(Children.begin(), Children.end());
578 static bool classof(const OMPClause *T) {
579 return T->getClauseKind() == OMPC_final;
583 /// This represents 'num_threads' clause in the '#pragma omp ...'
587 /// #pragma omp parallel num_threads(6)
589 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
590 /// clause with number of threads '6'.
591 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
592 friend class OMPClauseReader;
595 SourceLocation LParenLoc;
597 /// Condition of the 'num_threads' clause.
598 Stmt *NumThreads = nullptr;
601 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
604 /// Build 'num_threads' clause with condition \a NumThreads.
606 /// \param NumThreads Number of threads for the construct.
607 /// \param HelperNumThreads Helper Number of threads for the construct.
608 /// \param CaptureRegion Innermost OpenMP region where expressions in this
609 /// clause must be captured.
610 /// \param StartLoc Starting location of the clause.
611 /// \param LParenLoc Location of '('.
612 /// \param EndLoc Ending location of the clause.
613 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
614 OpenMPDirectiveKind CaptureRegion,
615 SourceLocation StartLoc, SourceLocation LParenLoc,
616 SourceLocation EndLoc)
617 : OMPClause(OMPC_num_threads, StartLoc, EndLoc),
618 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
619 NumThreads(NumThreads) {
620 setPreInitStmt(HelperNumThreads, CaptureRegion);
623 /// Build an empty clause.
624 OMPNumThreadsClause()
625 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
626 OMPClauseWithPreInit(this) {}
628 /// Sets the location of '('.
629 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
631 /// Returns the location of '('.
632 SourceLocation getLParenLoc() const { return LParenLoc; }
634 /// Returns number of threads.
635 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
637 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
639 const_child_range children() const {
640 return const_child_range(&NumThreads, &NumThreads + 1);
643 child_range used_children() {
644 return child_range(child_iterator(), child_iterator());
646 const_child_range used_children() const {
647 return const_child_range(const_child_iterator(), const_child_iterator());
650 static bool classof(const OMPClause *T) {
651 return T->getClauseKind() == OMPC_num_threads;
655 /// This represents 'safelen' clause in the '#pragma omp ...'
659 /// #pragma omp simd safelen(4)
661 /// In this example directive '#pragma omp simd' has clause 'safelen'
662 /// with single expression '4'.
663 /// If the safelen clause is used then no two iterations executed
664 /// concurrently with SIMD instructions can have a greater distance
665 /// in the logical iteration space than its value. The parameter of
666 /// the safelen clause must be a constant positive integer expression.
667 class OMPSafelenClause : public OMPClause {
668 friend class OMPClauseReader;
671 SourceLocation LParenLoc;
673 /// Safe iteration space distance.
674 Stmt *Safelen = nullptr;
677 void setSafelen(Expr *Len) { Safelen = Len; }
680 /// Build 'safelen' clause.
682 /// \param Len Expression associated with this clause.
683 /// \param StartLoc Starting location of the clause.
684 /// \param EndLoc Ending location of the clause.
685 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
686 SourceLocation EndLoc)
687 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
690 /// Build an empty clause.
691 explicit OMPSafelenClause()
692 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()) {}
694 /// Sets the location of '('.
695 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
697 /// Returns the location of '('.
698 SourceLocation getLParenLoc() const { return LParenLoc; }
700 /// Return safe iteration space distance.
701 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
703 child_range children() { return child_range(&Safelen, &Safelen + 1); }
705 const_child_range children() const {
706 return const_child_range(&Safelen, &Safelen + 1);
709 child_range used_children() {
710 return child_range(child_iterator(), child_iterator());
712 const_child_range used_children() const {
713 return const_child_range(const_child_iterator(), const_child_iterator());
716 static bool classof(const OMPClause *T) {
717 return T->getClauseKind() == OMPC_safelen;
721 /// This represents 'simdlen' clause in the '#pragma omp ...'
725 /// #pragma omp simd simdlen(4)
727 /// In this example directive '#pragma omp simd' has clause 'simdlen'
728 /// with single expression '4'.
729 /// If the 'simdlen' clause is used then it specifies the preferred number of
730 /// iterations to be executed concurrently. The parameter of the 'simdlen'
731 /// clause must be a constant positive integer expression.
732 class OMPSimdlenClause : public OMPClause {
733 friend class OMPClauseReader;
736 SourceLocation LParenLoc;
738 /// Safe iteration space distance.
739 Stmt *Simdlen = nullptr;
742 void setSimdlen(Expr *Len) { Simdlen = Len; }
745 /// Build 'simdlen' clause.
747 /// \param Len Expression associated with this clause.
748 /// \param StartLoc Starting location of the clause.
749 /// \param EndLoc Ending location of the clause.
750 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
751 SourceLocation EndLoc)
752 : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
755 /// Build an empty clause.
756 explicit OMPSimdlenClause()
757 : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()) {}
759 /// Sets the location of '('.
760 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
762 /// Returns the location of '('.
763 SourceLocation getLParenLoc() const { return LParenLoc; }
765 /// Return safe iteration space distance.
766 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
768 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
770 const_child_range children() const {
771 return const_child_range(&Simdlen, &Simdlen + 1);
774 child_range used_children() {
775 return child_range(child_iterator(), child_iterator());
777 const_child_range used_children() const {
778 return const_child_range(const_child_iterator(), const_child_iterator());
781 static bool classof(const OMPClause *T) {
782 return T->getClauseKind() == OMPC_simdlen;
786 /// This represents 'collapse' clause in the '#pragma omp ...'
790 /// #pragma omp simd collapse(3)
792 /// In this example directive '#pragma omp simd' has clause 'collapse'
793 /// with single expression '3'.
794 /// The parameter must be a constant positive integer expression, it specifies
795 /// the number of nested loops that should be collapsed into a single iteration
797 class OMPCollapseClause : public OMPClause {
798 friend class OMPClauseReader;
801 SourceLocation LParenLoc;
803 /// Number of for-loops.
804 Stmt *NumForLoops = nullptr;
806 /// Set the number of associated for-loops.
807 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
810 /// Build 'collapse' clause.
812 /// \param Num Expression associated with this clause.
813 /// \param StartLoc Starting location of the clause.
814 /// \param LParenLoc Location of '('.
815 /// \param EndLoc Ending location of the clause.
816 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
817 SourceLocation LParenLoc, SourceLocation EndLoc)
818 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
821 /// Build an empty clause.
822 explicit OMPCollapseClause()
823 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()) {}
825 /// Sets the location of '('.
826 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
828 /// Returns the location of '('.
829 SourceLocation getLParenLoc() const { return LParenLoc; }
831 /// Return the number of associated for-loops.
832 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
834 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
836 const_child_range children() const {
837 return const_child_range(&NumForLoops, &NumForLoops + 1);
840 child_range used_children() {
841 return child_range(child_iterator(), child_iterator());
843 const_child_range used_children() const {
844 return const_child_range(const_child_iterator(), const_child_iterator());
847 static bool classof(const OMPClause *T) {
848 return T->getClauseKind() == OMPC_collapse;
852 /// This represents 'default' clause in the '#pragma omp ...' directive.
855 /// #pragma omp parallel default(shared)
857 /// In this example directive '#pragma omp parallel' has simple 'default'
858 /// clause with kind 'shared'.
859 class OMPDefaultClause : public OMPClause {
860 friend class OMPClauseReader;
863 SourceLocation LParenLoc;
865 /// A kind of the 'default' clause.
866 OpenMPDefaultClauseKind Kind = OMPC_DEFAULT_unknown;
868 /// Start location of the kind in source code.
869 SourceLocation KindKwLoc;
871 /// Set kind of the clauses.
873 /// \param K Argument of clause.
874 void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
876 /// Set argument location.
878 /// \param KLoc Argument location.
879 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
882 /// Build 'default' clause with argument \a A ('none' or 'shared').
884 /// \param A Argument of the clause ('none' or 'shared').
885 /// \param ALoc Starting location of the argument.
886 /// \param StartLoc Starting location of the clause.
887 /// \param LParenLoc Location of '('.
888 /// \param EndLoc Ending location of the clause.
889 OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
890 SourceLocation StartLoc, SourceLocation LParenLoc,
891 SourceLocation EndLoc)
892 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
893 Kind(A), KindKwLoc(ALoc) {}
895 /// Build an empty clause.
897 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()) {}
899 /// Sets the location of '('.
900 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
902 /// Returns the location of '('.
903 SourceLocation getLParenLoc() const { return LParenLoc; }
905 /// Returns kind of the clause.
906 OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
908 /// Returns location of clause kind.
909 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
911 child_range children() {
912 return child_range(child_iterator(), child_iterator());
915 const_child_range children() const {
916 return const_child_range(const_child_iterator(), const_child_iterator());
919 child_range used_children() {
920 return child_range(child_iterator(), child_iterator());
922 const_child_range used_children() const {
923 return const_child_range(const_child_iterator(), const_child_iterator());
926 static bool classof(const OMPClause *T) {
927 return T->getClauseKind() == OMPC_default;
931 /// This represents 'proc_bind' clause in the '#pragma omp ...'
935 /// #pragma omp parallel proc_bind(master)
937 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
938 /// clause with kind 'master'.
939 class OMPProcBindClause : public OMPClause {
940 friend class OMPClauseReader;
943 SourceLocation LParenLoc;
945 /// A kind of the 'proc_bind' clause.
946 OpenMPProcBindClauseKind Kind = OMPC_PROC_BIND_unknown;
948 /// Start location of the kind in source code.
949 SourceLocation KindKwLoc;
951 /// Set kind of the clause.
953 /// \param K Kind of clause.
954 void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
956 /// Set clause kind location.
958 /// \param KLoc Kind location.
959 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
962 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
965 /// \param A Argument of the clause ('master', 'close' or 'spread').
966 /// \param ALoc Starting location of the argument.
967 /// \param StartLoc Starting location of the clause.
968 /// \param LParenLoc Location of '('.
969 /// \param EndLoc Ending location of the clause.
970 OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
971 SourceLocation StartLoc, SourceLocation LParenLoc,
972 SourceLocation EndLoc)
973 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
974 Kind(A), KindKwLoc(ALoc) {}
976 /// Build an empty clause.
978 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()) {}
980 /// Sets the location of '('.
981 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
983 /// Returns the location of '('.
984 SourceLocation getLParenLoc() const { return LParenLoc; }
986 /// Returns kind of the clause.
987 OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
989 /// Returns location of clause kind.
990 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
992 child_range children() {
993 return child_range(child_iterator(), child_iterator());
996 const_child_range children() const {
997 return const_child_range(const_child_iterator(), const_child_iterator());
1000 child_range used_children() {
1001 return child_range(child_iterator(), child_iterator());
1003 const_child_range used_children() const {
1004 return const_child_range(const_child_iterator(), const_child_iterator());
1007 static bool classof(const OMPClause *T) {
1008 return T->getClauseKind() == OMPC_proc_bind;
1012 /// This represents 'unified_address' clause in the '#pragma omp requires'
1016 /// #pragma omp requires unified_address
1018 /// In this example directive '#pragma omp requires' has 'unified_address'
1020 class OMPUnifiedAddressClause final : public OMPClause {
1022 friend class OMPClauseReader;
1023 /// Build 'unified_address' clause.
1025 /// \param StartLoc Starting location of the clause.
1026 /// \param EndLoc Ending location of the clause.
1027 OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
1028 : OMPClause(OMPC_unified_address, StartLoc, EndLoc) {}
1030 /// Build an empty clause.
1031 OMPUnifiedAddressClause()
1032 : OMPClause(OMPC_unified_address, SourceLocation(), SourceLocation()) {}
1034 child_range children() {
1035 return child_range(child_iterator(), child_iterator());
1038 const_child_range children() const {
1039 return const_child_range(const_child_iterator(), const_child_iterator());
1042 child_range used_children() {
1043 return child_range(child_iterator(), child_iterator());
1045 const_child_range used_children() const {
1046 return const_child_range(const_child_iterator(), const_child_iterator());
1049 static bool classof(const OMPClause *T) {
1050 return T->getClauseKind() == OMPC_unified_address;
1054 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1058 /// #pragma omp requires unified_shared_memory
1060 /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1062 class OMPUnifiedSharedMemoryClause final : public OMPClause {
1064 friend class OMPClauseReader;
1065 /// Build 'unified_shared_memory' clause.
1067 /// \param StartLoc Starting location of the clause.
1068 /// \param EndLoc Ending location of the clause.
1069 OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
1070 : OMPClause(OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1072 /// Build an empty clause.
1073 OMPUnifiedSharedMemoryClause()
1074 : OMPClause(OMPC_unified_shared_memory, SourceLocation(), SourceLocation()) {}
1076 child_range children() {
1077 return child_range(child_iterator(), child_iterator());
1080 const_child_range children() const {
1081 return const_child_range(const_child_iterator(), const_child_iterator());
1084 child_range used_children() {
1085 return child_range(child_iterator(), child_iterator());
1087 const_child_range used_children() const {
1088 return const_child_range(const_child_iterator(), const_child_iterator());
1091 static bool classof(const OMPClause *T) {
1092 return T->getClauseKind() == OMPC_unified_shared_memory;
1096 /// This represents 'reverse_offload' clause in the '#pragma omp requires'
1100 /// #pragma omp requires reverse_offload
1102 /// In this example directive '#pragma omp requires' has 'reverse_offload'
1104 class OMPReverseOffloadClause final : public OMPClause {
1106 friend class OMPClauseReader;
1107 /// Build 'reverse_offload' clause.
1109 /// \param StartLoc Starting location of the clause.
1110 /// \param EndLoc Ending location of the clause.
1111 OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1112 : OMPClause(OMPC_reverse_offload, StartLoc, EndLoc) {}
1114 /// Build an empty clause.
1115 OMPReverseOffloadClause()
1116 : OMPClause(OMPC_reverse_offload, SourceLocation(), SourceLocation()) {}
1118 child_range children() {
1119 return child_range(child_iterator(), child_iterator());
1122 const_child_range children() const {
1123 return const_child_range(const_child_iterator(), const_child_iterator());
1126 child_range used_children() {
1127 return child_range(child_iterator(), child_iterator());
1129 const_child_range used_children() const {
1130 return const_child_range(const_child_iterator(), const_child_iterator());
1133 static bool classof(const OMPClause *T) {
1134 return T->getClauseKind() == OMPC_reverse_offload;
1138 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1142 /// #pragma omp requires dynamic_allocators
1144 /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1146 class OMPDynamicAllocatorsClause final : public OMPClause {
1148 friend class OMPClauseReader;
1149 /// Build 'dynamic_allocators' clause.
1151 /// \param StartLoc Starting location of the clause.
1152 /// \param EndLoc Ending location of the clause.
1153 OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
1154 : OMPClause(OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1156 /// Build an empty clause.
1157 OMPDynamicAllocatorsClause()
1158 : OMPClause(OMPC_dynamic_allocators, SourceLocation(), SourceLocation()) {
1161 child_range children() {
1162 return child_range(child_iterator(), child_iterator());
1165 const_child_range children() const {
1166 return const_child_range(const_child_iterator(), const_child_iterator());
1169 child_range used_children() {
1170 return child_range(child_iterator(), child_iterator());
1172 const_child_range used_children() const {
1173 return const_child_range(const_child_iterator(), const_child_iterator());
1176 static bool classof(const OMPClause *T) {
1177 return T->getClauseKind() == OMPC_dynamic_allocators;
1181 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1182 /// requires' directive.
1185 /// #pragma omp requires atomic_default_mem_order(seq_cst)
1187 /// In this example directive '#pragma omp requires' has simple
1188 /// atomic_default_mem_order' clause with kind 'seq_cst'.
1189 class OMPAtomicDefaultMemOrderClause final : public OMPClause {
1190 friend class OMPClauseReader;
1193 SourceLocation LParenLoc;
1195 /// A kind of the 'atomic_default_mem_order' clause.
1196 OpenMPAtomicDefaultMemOrderClauseKind Kind =
1197 OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown;
1199 /// Start location of the kind in source code.
1200 SourceLocation KindKwLoc;
1202 /// Set kind of the clause.
1204 /// \param K Kind of clause.
1205 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1209 /// Set clause kind location.
1211 /// \param KLoc Kind location.
1212 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1217 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1218 /// 'acq_rel' or 'relaxed').
1220 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1221 /// \param ALoc Starting location of the argument.
1222 /// \param StartLoc Starting location of the clause.
1223 /// \param LParenLoc Location of '('.
1224 /// \param EndLoc Ending location of the clause.
1225 OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
1226 SourceLocation ALoc, SourceLocation StartLoc,
1227 SourceLocation LParenLoc,
1228 SourceLocation EndLoc)
1229 : OMPClause(OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1230 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1232 /// Build an empty clause.
1233 OMPAtomicDefaultMemOrderClause()
1234 : OMPClause(OMPC_atomic_default_mem_order, SourceLocation(),
1235 SourceLocation()) {}
1237 /// Sets the location of '('.
1238 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1240 /// Returns the locaiton of '('.
1241 SourceLocation getLParenLoc() const { return LParenLoc; }
1243 /// Returns kind of the clause.
1244 OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
1248 /// Returns location of clause kind.
1249 SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
1251 child_range children() {
1252 return child_range(child_iterator(), child_iterator());
1255 const_child_range children() const {
1256 return const_child_range(const_child_iterator(), const_child_iterator());
1259 child_range used_children() {
1260 return child_range(child_iterator(), child_iterator());
1262 const_child_range used_children() const {
1263 return const_child_range(const_child_iterator(), const_child_iterator());
1266 static bool classof(const OMPClause *T) {
1267 return T->getClauseKind() == OMPC_atomic_default_mem_order;
1271 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
1274 /// #pragma omp for schedule(static, 3)
1276 /// In this example directive '#pragma omp for' has 'schedule' clause with
1277 /// arguments 'static' and '3'.
1278 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
1279 friend class OMPClauseReader;
1281 /// Location of '('.
1282 SourceLocation LParenLoc;
1284 /// A kind of the 'schedule' clause.
1285 OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
1287 /// Modifiers for 'schedule' clause.
1288 enum {FIRST, SECOND, NUM_MODIFIERS};
1289 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1291 /// Locations of modifiers.
1292 SourceLocation ModifiersLoc[NUM_MODIFIERS];
1294 /// Start location of the schedule ind in source code.
1295 SourceLocation KindLoc;
1297 /// Location of ',' (if any).
1298 SourceLocation CommaLoc;
1301 Expr *ChunkSize = nullptr;
1303 /// Set schedule kind.
1305 /// \param K Schedule kind.
1306 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1308 /// Set the first schedule modifier.
1310 /// \param M Schedule modifier.
1311 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1312 Modifiers[FIRST] = M;
1315 /// Set the second schedule modifier.
1317 /// \param M Schedule modifier.
1318 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1319 Modifiers[SECOND] = M;
1322 /// Set location of the first schedule modifier.
1323 void setFirstScheduleModifierLoc(SourceLocation Loc) {
1324 ModifiersLoc[FIRST] = Loc;
1327 /// Set location of the second schedule modifier.
1328 void setSecondScheduleModifierLoc(SourceLocation Loc) {
1329 ModifiersLoc[SECOND] = Loc;
1332 /// Set schedule modifier location.
1334 /// \param M Schedule modifier location.
1335 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1336 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1337 Modifiers[FIRST] = M;
1339 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1340 Modifiers[SECOND] = M;
1344 /// Sets the location of '('.
1346 /// \param Loc Location of '('.
1347 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1349 /// Set schedule kind start location.
1351 /// \param KLoc Schedule kind location.
1352 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1354 /// Set location of ','.
1356 /// \param Loc Location of ','.
1357 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1361 /// \param E Chunk size.
1362 void setChunkSize(Expr *E) { ChunkSize = E; }
1365 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1366 /// expression \a ChunkSize.
1368 /// \param StartLoc Starting location of the clause.
1369 /// \param LParenLoc Location of '('.
1370 /// \param KLoc Starting location of the argument.
1371 /// \param CommaLoc Location of ','.
1372 /// \param EndLoc Ending location of the clause.
1373 /// \param Kind Schedule kind.
1374 /// \param ChunkSize Chunk size.
1375 /// \param HelperChunkSize Helper chunk size for combined directives.
1376 /// \param M1 The first modifier applied to 'schedule' clause.
1377 /// \param M1Loc Location of the first modifier
1378 /// \param M2 The second modifier applied to 'schedule' clause.
1379 /// \param M2Loc Location of the second modifier
1380 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1381 SourceLocation KLoc, SourceLocation CommaLoc,
1382 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
1383 Expr *ChunkSize, Stmt *HelperChunkSize,
1384 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
1385 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
1386 : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this),
1387 LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc),
1388 ChunkSize(ChunkSize) {
1389 setPreInitStmt(HelperChunkSize);
1390 Modifiers[FIRST] = M1;
1391 Modifiers[SECOND] = M2;
1392 ModifiersLoc[FIRST] = M1Loc;
1393 ModifiersLoc[SECOND] = M2Loc;
1396 /// Build an empty clause.
1397 explicit OMPScheduleClause()
1398 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
1399 OMPClauseWithPreInit(this) {
1400 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1401 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1404 /// Get kind of the clause.
1405 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
1407 /// Get the first modifier of the clause.
1408 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
1409 return Modifiers[FIRST];
1412 /// Get the second modifier of the clause.
1413 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
1414 return Modifiers[SECOND];
1417 /// Get location of '('.
1418 SourceLocation getLParenLoc() { return LParenLoc; }
1420 /// Get kind location.
1421 SourceLocation getScheduleKindLoc() { return KindLoc; }
1423 /// Get the first modifier location.
1424 SourceLocation getFirstScheduleModifierLoc() const {
1425 return ModifiersLoc[FIRST];
1428 /// Get the second modifier location.
1429 SourceLocation getSecondScheduleModifierLoc() const {
1430 return ModifiersLoc[SECOND];
1433 /// Get location of ','.
1434 SourceLocation getCommaLoc() { return CommaLoc; }
1437 Expr *getChunkSize() { return ChunkSize; }
1440 const Expr *getChunkSize() const { return ChunkSize; }
1442 child_range children() {
1443 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1444 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1447 const_child_range children() const {
1448 auto Children = const_cast<OMPScheduleClause *>(this)->children();
1449 return const_child_range(Children.begin(), Children.end());
1452 child_range used_children() {
1453 return child_range(child_iterator(), child_iterator());
1455 const_child_range used_children() const {
1456 return const_child_range(const_child_iterator(), const_child_iterator());
1459 static bool classof(const OMPClause *T) {
1460 return T->getClauseKind() == OMPC_schedule;
1464 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1467 /// #pragma omp for ordered (2)
1469 /// In this example directive '#pragma omp for' has 'ordered' clause with
1471 class OMPOrderedClause final
1473 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1474 friend class OMPClauseReader;
1475 friend TrailingObjects;
1477 /// Location of '('.
1478 SourceLocation LParenLoc;
1480 /// Number of for-loops.
1481 Stmt *NumForLoops = nullptr;
1483 /// Real number of loops.
1484 unsigned NumberOfLoops = 0;
1486 /// Build 'ordered' clause.
1488 /// \param Num Expression, possibly associated with this clause.
1489 /// \param NumLoops Number of loops, associated with this clause.
1490 /// \param StartLoc Starting location of the clause.
1491 /// \param LParenLoc Location of '('.
1492 /// \param EndLoc Ending location of the clause.
1493 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1494 SourceLocation LParenLoc, SourceLocation EndLoc)
1495 : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
1496 NumForLoops(Num), NumberOfLoops(NumLoops) {}
1498 /// Build an empty clause.
1499 explicit OMPOrderedClause(unsigned NumLoops)
1500 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
1501 NumberOfLoops(NumLoops) {}
1503 /// Set the number of associated for-loops.
1504 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1507 /// Build 'ordered' clause.
1509 /// \param Num Expression, possibly associated with this clause.
1510 /// \param NumLoops Number of loops, associated with this clause.
1511 /// \param StartLoc Starting location of the clause.
1512 /// \param LParenLoc Location of '('.
1513 /// \param EndLoc Ending location of the clause.
1514 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1515 unsigned NumLoops, SourceLocation StartLoc,
1516 SourceLocation LParenLoc,
1517 SourceLocation EndLoc);
1519 /// Build an empty clause.
1520 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1522 /// Sets the location of '('.
1523 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1525 /// Returns the location of '('.
1526 SourceLocation getLParenLoc() const { return LParenLoc; }
1528 /// Return the number of associated for-loops.
1529 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1531 /// Set number of iterations for the specified loop.
1532 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1533 /// Get number of iterations for all the loops.
1534 ArrayRef<Expr *> getLoopNumIterations() const;
1536 /// Set loop counter for the specified loop.
1537 void setLoopCounter(unsigned NumLoop, Expr *Counter);
1538 /// Get loops counter for the specified loop.
1539 Expr *getLoopCounter(unsigned NumLoop);
1540 const Expr *getLoopCounter(unsigned NumLoop) const;
1542 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1544 const_child_range children() const {
1545 return const_child_range(&NumForLoops, &NumForLoops + 1);
1548 child_range used_children() {
1549 return child_range(child_iterator(), child_iterator());
1551 const_child_range used_children() const {
1552 return const_child_range(const_child_iterator(), const_child_iterator());
1555 static bool classof(const OMPClause *T) {
1556 return T->getClauseKind() == OMPC_ordered;
1560 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1563 /// #pragma omp for nowait
1565 /// In this example directive '#pragma omp for' has 'nowait' clause.
1566 class OMPNowaitClause : public OMPClause {
1568 /// Build 'nowait' clause.
1570 /// \param StartLoc Starting location of the clause.
1571 /// \param EndLoc Ending location of the clause.
1572 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
1573 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
1575 /// Build an empty clause.
1577 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
1579 child_range children() {
1580 return child_range(child_iterator(), child_iterator());
1583 const_child_range children() const {
1584 return const_child_range(const_child_iterator(), const_child_iterator());
1587 child_range used_children() {
1588 return child_range(child_iterator(), child_iterator());
1590 const_child_range used_children() const {
1591 return const_child_range(const_child_iterator(), const_child_iterator());
1594 static bool classof(const OMPClause *T) {
1595 return T->getClauseKind() == OMPC_nowait;
1599 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1602 /// #pragma omp task untied
1604 /// In this example directive '#pragma omp task' has 'untied' clause.
1605 class OMPUntiedClause : public OMPClause {
1607 /// Build 'untied' clause.
1609 /// \param StartLoc Starting location of the clause.
1610 /// \param EndLoc Ending location of the clause.
1611 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
1612 : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
1614 /// Build an empty clause.
1616 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
1618 child_range children() {
1619 return child_range(child_iterator(), child_iterator());
1622 const_child_range children() const {
1623 return const_child_range(const_child_iterator(), const_child_iterator());
1626 child_range used_children() {
1627 return child_range(child_iterator(), child_iterator());
1629 const_child_range used_children() const {
1630 return const_child_range(const_child_iterator(), const_child_iterator());
1633 static bool classof(const OMPClause *T) {
1634 return T->getClauseKind() == OMPC_untied;
1638 /// This represents 'mergeable' clause in the '#pragma omp ...'
1642 /// #pragma omp task mergeable
1644 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1645 class OMPMergeableClause : public OMPClause {
1647 /// Build 'mergeable' clause.
1649 /// \param StartLoc Starting location of the clause.
1650 /// \param EndLoc Ending location of the clause.
1651 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
1652 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
1654 /// Build an empty clause.
1655 OMPMergeableClause()
1656 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
1658 child_range children() {
1659 return child_range(child_iterator(), child_iterator());
1662 const_child_range children() const {
1663 return const_child_range(const_child_iterator(), const_child_iterator());
1666 child_range used_children() {
1667 return child_range(child_iterator(), child_iterator());
1669 const_child_range used_children() const {
1670 return const_child_range(const_child_iterator(), const_child_iterator());
1673 static bool classof(const OMPClause *T) {
1674 return T->getClauseKind() == OMPC_mergeable;
1678 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1681 /// #pragma omp atomic read
1683 /// In this example directive '#pragma omp atomic' has 'read' clause.
1684 class OMPReadClause : public OMPClause {
1686 /// Build 'read' clause.
1688 /// \param StartLoc Starting location of the clause.
1689 /// \param EndLoc Ending location of the clause.
1690 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1691 : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1693 /// Build an empty clause.
1694 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1696 child_range children() {
1697 return child_range(child_iterator(), child_iterator());
1700 const_child_range children() const {
1701 return const_child_range(const_child_iterator(), const_child_iterator());
1704 child_range used_children() {
1705 return child_range(child_iterator(), child_iterator());
1707 const_child_range used_children() const {
1708 return const_child_range(const_child_iterator(), const_child_iterator());
1711 static bool classof(const OMPClause *T) {
1712 return T->getClauseKind() == OMPC_read;
1716 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1719 /// #pragma omp atomic write
1721 /// In this example directive '#pragma omp atomic' has 'write' clause.
1722 class OMPWriteClause : public OMPClause {
1724 /// Build 'write' clause.
1726 /// \param StartLoc Starting location of the clause.
1727 /// \param EndLoc Ending location of the clause.
1728 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1729 : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1731 /// Build an empty clause.
1733 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1735 child_range children() {
1736 return child_range(child_iterator(), child_iterator());
1739 const_child_range children() const {
1740 return const_child_range(const_child_iterator(), const_child_iterator());
1743 child_range used_children() {
1744 return child_range(child_iterator(), child_iterator());
1746 const_child_range used_children() const {
1747 return const_child_range(const_child_iterator(), const_child_iterator());
1750 static bool classof(const OMPClause *T) {
1751 return T->getClauseKind() == OMPC_write;
1755 /// This represents 'update' clause in the '#pragma omp atomic'
1759 /// #pragma omp atomic update
1761 /// In this example directive '#pragma omp atomic' has 'update' clause.
1762 class OMPUpdateClause : public OMPClause {
1764 /// Build 'update' clause.
1766 /// \param StartLoc Starting location of the clause.
1767 /// \param EndLoc Ending location of the clause.
1768 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
1769 : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1771 /// Build an empty clause.
1773 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1775 child_range children() {
1776 return child_range(child_iterator(), child_iterator());
1779 const_child_range children() const {
1780 return const_child_range(const_child_iterator(), const_child_iterator());
1783 child_range used_children() {
1784 return child_range(child_iterator(), child_iterator());
1786 const_child_range used_children() const {
1787 return const_child_range(const_child_iterator(), const_child_iterator());
1790 static bool classof(const OMPClause *T) {
1791 return T->getClauseKind() == OMPC_update;
1795 /// This represents 'capture' clause in the '#pragma omp atomic'
1799 /// #pragma omp atomic capture
1801 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1802 class OMPCaptureClause : public OMPClause {
1804 /// Build 'capture' clause.
1806 /// \param StartLoc Starting location of the clause.
1807 /// \param EndLoc Ending location of the clause.
1808 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1809 : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1811 /// Build an empty clause.
1813 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1815 child_range children() {
1816 return child_range(child_iterator(), child_iterator());
1819 const_child_range children() const {
1820 return const_child_range(const_child_iterator(), const_child_iterator());
1823 child_range used_children() {
1824 return child_range(child_iterator(), child_iterator());
1826 const_child_range used_children() const {
1827 return const_child_range(const_child_iterator(), const_child_iterator());
1830 static bool classof(const OMPClause *T) {
1831 return T->getClauseKind() == OMPC_capture;
1835 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
1839 /// #pragma omp atomic seq_cst
1841 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1842 class OMPSeqCstClause : public OMPClause {
1844 /// Build 'seq_cst' clause.
1846 /// \param StartLoc Starting location of the clause.
1847 /// \param EndLoc Ending location of the clause.
1848 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1849 : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1851 /// Build an empty clause.
1853 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1855 child_range children() {
1856 return child_range(child_iterator(), child_iterator());
1859 const_child_range children() const {
1860 return const_child_range(const_child_iterator(), const_child_iterator());
1863 child_range used_children() {
1864 return child_range(child_iterator(), child_iterator());
1866 const_child_range used_children() const {
1867 return const_child_range(const_child_iterator(), const_child_iterator());
1870 static bool classof(const OMPClause *T) {
1871 return T->getClauseKind() == OMPC_seq_cst;
1875 /// This represents clause 'private' in the '#pragma omp ...' directives.
1878 /// #pragma omp parallel private(a,b)
1880 /// In this example directive '#pragma omp parallel' has clause 'private'
1881 /// with the variables 'a' and 'b'.
1882 class OMPPrivateClause final
1883 : public OMPVarListClause<OMPPrivateClause>,
1884 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1885 friend class OMPClauseReader;
1886 friend OMPVarListClause;
1887 friend TrailingObjects;
1889 /// Build clause with number of variables \a N.
1891 /// \param StartLoc Starting location of the clause.
1892 /// \param LParenLoc Location of '('.
1893 /// \param EndLoc Ending location of the clause.
1894 /// \param N Number of the variables in the clause.
1895 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1896 SourceLocation EndLoc, unsigned N)
1897 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1900 /// Build an empty clause.
1902 /// \param N Number of variables.
1903 explicit OMPPrivateClause(unsigned N)
1904 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
1905 SourceLocation(), SourceLocation(),
1908 /// Sets the list of references to private copies with initializers for
1909 /// new private variables.
1910 /// \param VL List of references.
1911 void setPrivateCopies(ArrayRef<Expr *> VL);
1913 /// Gets the list of references to private copies with initializers for
1914 /// new private variables.
1915 MutableArrayRef<Expr *> getPrivateCopies() {
1916 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1918 ArrayRef<const Expr *> getPrivateCopies() const {
1919 return llvm::makeArrayRef(varlist_end(), varlist_size());
1923 /// Creates clause with a list of variables \a VL.
1925 /// \param C AST context.
1926 /// \param StartLoc Starting location of the clause.
1927 /// \param LParenLoc Location of '('.
1928 /// \param EndLoc Ending location of the clause.
1929 /// \param VL List of references to the variables.
1930 /// \param PrivateVL List of references to private copies with initializers.
1931 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1932 SourceLocation LParenLoc,
1933 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1934 ArrayRef<Expr *> PrivateVL);
1936 /// Creates an empty clause with the place for \a N variables.
1938 /// \param C AST context.
1939 /// \param N The number of variables.
1940 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1942 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
1943 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
1944 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
1945 using private_copies_const_range =
1946 llvm::iterator_range<private_copies_const_iterator>;
1948 private_copies_range private_copies() {
1949 return private_copies_range(getPrivateCopies().begin(),
1950 getPrivateCopies().end());
1953 private_copies_const_range private_copies() const {
1954 return private_copies_const_range(getPrivateCopies().begin(),
1955 getPrivateCopies().end());
1958 child_range children() {
1959 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1960 reinterpret_cast<Stmt **>(varlist_end()));
1963 const_child_range children() const {
1964 auto Children = const_cast<OMPPrivateClause *>(this)->children();
1965 return const_child_range(Children.begin(), Children.end());
1968 child_range used_children() {
1969 return child_range(child_iterator(), child_iterator());
1971 const_child_range used_children() const {
1972 return const_child_range(const_child_iterator(), const_child_iterator());
1975 static bool classof(const OMPClause *T) {
1976 return T->getClauseKind() == OMPC_private;
1980 /// This represents clause 'firstprivate' in the '#pragma omp ...'
1984 /// #pragma omp parallel firstprivate(a,b)
1986 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1987 /// with the variables 'a' and 'b'.
1988 class OMPFirstprivateClause final
1989 : public OMPVarListClause<OMPFirstprivateClause>,
1990 public OMPClauseWithPreInit,
1991 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1992 friend class OMPClauseReader;
1993 friend OMPVarListClause;
1994 friend TrailingObjects;
1996 /// Build clause with number of variables \a N.
1998 /// \param StartLoc Starting location of the clause.
1999 /// \param LParenLoc Location of '('.
2000 /// \param EndLoc Ending location of the clause.
2001 /// \param N Number of the variables in the clause.
2002 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2003 SourceLocation EndLoc, unsigned N)
2004 : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
2005 LParenLoc, EndLoc, N),
2006 OMPClauseWithPreInit(this) {}
2008 /// Build an empty clause.
2010 /// \param N Number of variables.
2011 explicit OMPFirstprivateClause(unsigned N)
2012 : OMPVarListClause<OMPFirstprivateClause>(
2013 OMPC_firstprivate, SourceLocation(), SourceLocation(),
2014 SourceLocation(), N),
2015 OMPClauseWithPreInit(this) {}
2017 /// Sets the list of references to private copies with initializers for
2018 /// new private variables.
2019 /// \param VL List of references.
2020 void setPrivateCopies(ArrayRef<Expr *> VL);
2022 /// Gets the list of references to private copies with initializers for
2023 /// new private variables.
2024 MutableArrayRef<Expr *> getPrivateCopies() {
2025 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2027 ArrayRef<const Expr *> getPrivateCopies() const {
2028 return llvm::makeArrayRef(varlist_end(), varlist_size());
2031 /// Sets the list of references to initializer variables for new
2032 /// private variables.
2033 /// \param VL List of references.
2034 void setInits(ArrayRef<Expr *> VL);
2036 /// Gets the list of references to initializer variables for new
2037 /// private variables.
2038 MutableArrayRef<Expr *> getInits() {
2039 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2041 ArrayRef<const Expr *> getInits() const {
2042 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2046 /// Creates clause with a list of variables \a VL.
2048 /// \param C AST context.
2049 /// \param StartLoc Starting location of the clause.
2050 /// \param LParenLoc Location of '('.
2051 /// \param EndLoc Ending location of the clause.
2052 /// \param VL List of references to the original variables.
2053 /// \param PrivateVL List of references to private copies with initializers.
2054 /// \param InitVL List of references to auto generated variables used for
2055 /// initialization of a single array element. Used if firstprivate variable is
2057 /// \param PreInit Statement that must be executed before entering the OpenMP
2058 /// region with this clause.
2059 static OMPFirstprivateClause *
2060 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2061 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2062 ArrayRef<Expr *> InitVL, Stmt *PreInit);
2064 /// Creates an empty clause with the place for \a N variables.
2066 /// \param C AST context.
2067 /// \param N The number of variables.
2068 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2070 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
2071 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
2072 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2073 using private_copies_const_range =
2074 llvm::iterator_range<private_copies_const_iterator>;
2076 private_copies_range private_copies() {
2077 return private_copies_range(getPrivateCopies().begin(),
2078 getPrivateCopies().end());
2080 private_copies_const_range private_copies() const {
2081 return private_copies_const_range(getPrivateCopies().begin(),
2082 getPrivateCopies().end());
2085 using inits_iterator = MutableArrayRef<Expr *>::iterator;
2086 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
2087 using inits_range = llvm::iterator_range<inits_iterator>;
2088 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2090 inits_range inits() {
2091 return inits_range(getInits().begin(), getInits().end());
2093 inits_const_range inits() const {
2094 return inits_const_range(getInits().begin(), getInits().end());
2097 child_range children() {
2098 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2099 reinterpret_cast<Stmt **>(varlist_end()));
2102 const_child_range children() const {
2103 auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2104 return const_child_range(Children.begin(), Children.end());
2107 child_range used_children() {
2108 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2109 reinterpret_cast<Stmt **>(varlist_end()));
2111 const_child_range used_children() const {
2112 auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2113 return const_child_range(Children.begin(), Children.end());
2116 static bool classof(const OMPClause *T) {
2117 return T->getClauseKind() == OMPC_firstprivate;
2121 /// This represents clause 'lastprivate' in the '#pragma omp ...'
2125 /// #pragma omp simd lastprivate(a,b)
2127 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
2128 /// with the variables 'a' and 'b'.
2129 class OMPLastprivateClause final
2130 : public OMPVarListClause<OMPLastprivateClause>,
2131 public OMPClauseWithPostUpdate,
2132 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2133 // There are 4 additional tail-allocated arrays at the end of the class:
2134 // 1. Contains list of pseudo variables with the default initialization for
2135 // each non-firstprivate variables. Used in codegen for initialization of
2136 // lastprivate copies.
2137 // 2. List of helper expressions for proper generation of assignment operation
2138 // required for lastprivate clause. This list represents private variables
2139 // (for arrays, single array element).
2140 // 3. List of helper expressions for proper generation of assignment operation
2141 // required for lastprivate clause. This list represents original variables
2142 // (for arrays, single array element).
2143 // 4. List of helper expressions that represents assignment operation:
2145 // DstExprs = SrcExprs;
2147 // Required for proper codegen of final assignment performed by the
2148 // lastprivate clause.
2149 friend class OMPClauseReader;
2150 friend OMPVarListClause;
2151 friend TrailingObjects;
2153 /// Build clause with number of variables \a N.
2155 /// \param StartLoc Starting location of the clause.
2156 /// \param LParenLoc Location of '('.
2157 /// \param EndLoc Ending location of the clause.
2158 /// \param N Number of the variables in the clause.
2159 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2160 SourceLocation EndLoc, unsigned N)
2161 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
2162 LParenLoc, EndLoc, N),
2163 OMPClauseWithPostUpdate(this) {}
2165 /// Build an empty clause.
2167 /// \param N Number of variables.
2168 explicit OMPLastprivateClause(unsigned N)
2169 : OMPVarListClause<OMPLastprivateClause>(
2170 OMPC_lastprivate, SourceLocation(), SourceLocation(),
2171 SourceLocation(), N),
2172 OMPClauseWithPostUpdate(this) {}
2174 /// Get the list of helper expressions for initialization of private
2175 /// copies for lastprivate variables.
2176 MutableArrayRef<Expr *> getPrivateCopies() {
2177 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2179 ArrayRef<const Expr *> getPrivateCopies() const {
2180 return llvm::makeArrayRef(varlist_end(), varlist_size());
2183 /// Set list of helper expressions, required for proper codegen of the
2184 /// clause. These expressions represent private variables (for arrays, single
2185 /// array element) in the final assignment statement performed by the
2186 /// lastprivate clause.
2187 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2189 /// Get the list of helper source expressions.
2190 MutableArrayRef<Expr *> getSourceExprs() {
2191 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2193 ArrayRef<const Expr *> getSourceExprs() const {
2194 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2197 /// Set list of helper expressions, required for proper codegen of the
2198 /// clause. These expressions represent original variables (for arrays, single
2199 /// array element) in the final assignment statement performed by the
2200 /// lastprivate clause.
2201 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2203 /// Get the list of helper destination expressions.
2204 MutableArrayRef<Expr *> getDestinationExprs() {
2205 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2207 ArrayRef<const Expr *> getDestinationExprs() const {
2208 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2211 /// Set list of helper assignment expressions, required for proper
2212 /// codegen of the clause. These expressions are assignment expressions that
2213 /// assign private copy of the variable to original variable.
2214 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2216 /// Get the list of helper assignment expressions.
2217 MutableArrayRef<Expr *> getAssignmentOps() {
2218 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2220 ArrayRef<const Expr *> getAssignmentOps() const {
2221 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2225 /// Creates clause with a list of variables \a VL.
2227 /// \param C AST context.
2228 /// \param StartLoc Starting location of the clause.
2229 /// \param LParenLoc Location of '('.
2230 /// \param EndLoc Ending location of the clause.
2231 /// \param VL List of references to the variables.
2232 /// \param SrcExprs List of helper expressions for proper generation of
2233 /// assignment operation required for lastprivate clause. This list represents
2234 /// private variables (for arrays, single array element).
2235 /// \param DstExprs List of helper expressions for proper generation of
2236 /// assignment operation required for lastprivate clause. This list represents
2237 /// original variables (for arrays, single array element).
2238 /// \param AssignmentOps List of helper expressions that represents assignment
2241 /// DstExprs = SrcExprs;
2243 /// Required for proper codegen of final assignment performed by the
2244 /// lastprivate clause.
2245 /// \param PreInit Statement that must be executed before entering the OpenMP
2246 /// region with this clause.
2247 /// \param PostUpdate Expression that must be executed after exit from the
2248 /// OpenMP region with this clause.
2249 static OMPLastprivateClause *
2250 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2251 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2252 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2253 Stmt *PreInit, Expr *PostUpdate);
2255 /// Creates an empty clause with the place for \a N variables.
2257 /// \param C AST context.
2258 /// \param N The number of variables.
2259 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2261 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2262 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2263 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2264 using helper_expr_const_range =
2265 llvm::iterator_range<helper_expr_const_iterator>;
2267 /// Set list of helper expressions, required for generation of private
2268 /// copies of original lastprivate variables.
2269 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2271 helper_expr_const_range private_copies() const {
2272 return helper_expr_const_range(getPrivateCopies().begin(),
2273 getPrivateCopies().end());
2276 helper_expr_range private_copies() {
2277 return helper_expr_range(getPrivateCopies().begin(),
2278 getPrivateCopies().end());
2281 helper_expr_const_range source_exprs() const {
2282 return helper_expr_const_range(getSourceExprs().begin(),
2283 getSourceExprs().end());
2286 helper_expr_range source_exprs() {
2287 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2290 helper_expr_const_range destination_exprs() const {
2291 return helper_expr_const_range(getDestinationExprs().begin(),
2292 getDestinationExprs().end());
2295 helper_expr_range destination_exprs() {
2296 return helper_expr_range(getDestinationExprs().begin(),
2297 getDestinationExprs().end());
2300 helper_expr_const_range assignment_ops() const {
2301 return helper_expr_const_range(getAssignmentOps().begin(),
2302 getAssignmentOps().end());
2305 helper_expr_range assignment_ops() {
2306 return helper_expr_range(getAssignmentOps().begin(),
2307 getAssignmentOps().end());
2310 child_range children() {
2311 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2312 reinterpret_cast<Stmt **>(varlist_end()));
2315 const_child_range children() const {
2316 auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2317 return const_child_range(Children.begin(), Children.end());
2320 child_range used_children() {
2321 return child_range(child_iterator(), child_iterator());
2323 const_child_range used_children() const {
2324 return const_child_range(const_child_iterator(), const_child_iterator());
2327 static bool classof(const OMPClause *T) {
2328 return T->getClauseKind() == OMPC_lastprivate;
2332 /// This represents clause 'shared' in the '#pragma omp ...' directives.
2335 /// #pragma omp parallel shared(a,b)
2337 /// In this example directive '#pragma omp parallel' has clause 'shared'
2338 /// with the variables 'a' and 'b'.
2339 class OMPSharedClause final
2340 : public OMPVarListClause<OMPSharedClause>,
2341 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
2342 friend OMPVarListClause;
2343 friend TrailingObjects;
2345 /// Build clause with number of variables \a N.
2347 /// \param StartLoc Starting location of the clause.
2348 /// \param LParenLoc Location of '('.
2349 /// \param EndLoc Ending location of the clause.
2350 /// \param N Number of the variables in the clause.
2351 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2352 SourceLocation EndLoc, unsigned N)
2353 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
2356 /// Build an empty clause.
2358 /// \param N Number of variables.
2359 explicit OMPSharedClause(unsigned N)
2360 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
2361 SourceLocation(), SourceLocation(),
2365 /// Creates clause with a list of variables \a VL.
2367 /// \param C AST context.
2368 /// \param StartLoc Starting location of the clause.
2369 /// \param LParenLoc Location of '('.
2370 /// \param EndLoc Ending location of the clause.
2371 /// \param VL List of references to the variables.
2372 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2373 SourceLocation LParenLoc,
2374 SourceLocation EndLoc, ArrayRef<Expr *> VL);
2376 /// Creates an empty clause with \a N variables.
2378 /// \param C AST context.
2379 /// \param N The number of variables.
2380 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
2382 child_range children() {
2383 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2384 reinterpret_cast<Stmt **>(varlist_end()));
2387 const_child_range children() const {
2388 auto Children = const_cast<OMPSharedClause *>(this)->children();
2389 return const_child_range(Children.begin(), Children.end());
2392 child_range used_children() {
2393 return child_range(child_iterator(), child_iterator());
2395 const_child_range used_children() const {
2396 return const_child_range(const_child_iterator(), const_child_iterator());
2399 static bool classof(const OMPClause *T) {
2400 return T->getClauseKind() == OMPC_shared;
2404 /// This represents clause 'reduction' in the '#pragma omp ...'
2408 /// #pragma omp parallel reduction(+:a,b)
2410 /// In this example directive '#pragma omp parallel' has clause 'reduction'
2411 /// with operator '+' and the variables 'a' and 'b'.
2412 class OMPReductionClause final
2413 : public OMPVarListClause<OMPReductionClause>,
2414 public OMPClauseWithPostUpdate,
2415 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
2416 friend class OMPClauseReader;
2417 friend OMPVarListClause;
2418 friend TrailingObjects;
2420 /// Location of ':'.
2421 SourceLocation ColonLoc;
2423 /// Nested name specifier for C++.
2424 NestedNameSpecifierLoc QualifierLoc;
2426 /// Name of custom operator.
2427 DeclarationNameInfo NameInfo;
2429 /// Build clause with number of variables \a N.
2431 /// \param StartLoc Starting location of the clause.
2432 /// \param LParenLoc Location of '('.
2433 /// \param EndLoc Ending location of the clause.
2434 /// \param ColonLoc Location of ':'.
2435 /// \param N Number of the variables in the clause.
2436 /// \param QualifierLoc The nested-name qualifier with location information
2437 /// \param NameInfo The full name info for reduction identifier.
2438 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2439 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
2440 NestedNameSpecifierLoc QualifierLoc,
2441 const DeclarationNameInfo &NameInfo)
2442 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
2443 LParenLoc, EndLoc, N),
2444 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2445 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2447 /// Build an empty clause.
2449 /// \param N Number of variables.
2450 explicit OMPReductionClause(unsigned N)
2451 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
2452 SourceLocation(), SourceLocation(),
2454 OMPClauseWithPostUpdate(this) {}
2456 /// Sets location of ':' symbol in clause.
2457 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2459 /// Sets the name info for specified reduction identifier.
2460 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2462 /// Sets the nested name specifier.
2463 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2465 /// Set list of helper expressions, required for proper codegen of the
2466 /// clause. These expressions represent private copy of the reduction
2468 void setPrivates(ArrayRef<Expr *> Privates);
2470 /// Get the list of helper privates.
2471 MutableArrayRef<Expr *> getPrivates() {
2472 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2474 ArrayRef<const Expr *> getPrivates() const {
2475 return llvm::makeArrayRef(varlist_end(), varlist_size());
2478 /// Set list of helper expressions, required for proper codegen of the
2479 /// clause. These expressions represent LHS expression in the final
2480 /// reduction expression performed by the reduction clause.
2481 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2483 /// Get the list of helper LHS expressions.
2484 MutableArrayRef<Expr *> getLHSExprs() {
2485 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2487 ArrayRef<const Expr *> getLHSExprs() const {
2488 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2491 /// Set list of helper expressions, required for proper codegen of the
2492 /// clause. These expressions represent RHS expression in the final
2493 /// reduction expression performed by the reduction clause.
2494 /// Also, variables in these expressions are used for proper initialization of
2495 /// reduction copies.
2496 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2498 /// Get the list of helper destination expressions.
2499 MutableArrayRef<Expr *> getRHSExprs() {
2500 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2502 ArrayRef<const Expr *> getRHSExprs() const {
2503 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2506 /// Set list of helper reduction expressions, required for proper
2507 /// codegen of the clause. These expressions are binary expressions or
2508 /// operator/custom reduction call that calculates new value from source
2509 /// helper expressions to destination helper expressions.
2510 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2512 /// Get the list of helper reduction expressions.
2513 MutableArrayRef<Expr *> getReductionOps() {
2514 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2516 ArrayRef<const Expr *> getReductionOps() const {
2517 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2521 /// Creates clause with a list of variables \a VL.
2523 /// \param StartLoc Starting location of the clause.
2524 /// \param LParenLoc Location of '('.
2525 /// \param ColonLoc Location of ':'.
2526 /// \param EndLoc Ending location of the clause.
2527 /// \param VL The variables in the clause.
2528 /// \param QualifierLoc The nested-name qualifier with location information
2529 /// \param NameInfo The full name info for reduction identifier.
2530 /// \param Privates List of helper expressions for proper generation of
2532 /// \param LHSExprs List of helper expressions for proper generation of
2533 /// assignment operation required for copyprivate clause. This list represents
2534 /// LHSs of the reduction expressions.
2535 /// \param RHSExprs List of helper expressions for proper generation of
2536 /// assignment operation required for copyprivate clause. This list represents
2537 /// RHSs of the reduction expressions.
2538 /// Also, variables in these expressions are used for proper initialization of
2539 /// reduction copies.
2540 /// \param ReductionOps List of helper expressions that represents reduction
2543 /// LHSExprs binop RHSExprs;
2544 /// operator binop(LHSExpr, RHSExpr);
2545 /// <CutomReduction>(LHSExpr, RHSExpr);
2547 /// Required for proper codegen of final reduction operation performed by the
2548 /// reduction clause.
2549 /// \param PreInit Statement that must be executed before entering the OpenMP
2550 /// region with this clause.
2551 /// \param PostUpdate Expression that must be executed after exit from the
2552 /// OpenMP region with this clause.
2553 static OMPReductionClause *
2554 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2555 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2556 NestedNameSpecifierLoc QualifierLoc,
2557 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2558 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2559 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2561 /// Creates an empty clause with the place for \a N variables.
2563 /// \param C AST context.
2564 /// \param N The number of variables.
2565 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2567 /// Gets location of ':' symbol in clause.
2568 SourceLocation getColonLoc() const { return ColonLoc; }
2570 /// Gets the name info for specified reduction identifier.
2571 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2573 /// Gets the nested name specifier.
2574 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2576 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2577 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2578 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2579 using helper_expr_const_range =
2580 llvm::iterator_range<helper_expr_const_iterator>;
2582 helper_expr_const_range privates() const {
2583 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2586 helper_expr_range privates() {
2587 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2590 helper_expr_const_range lhs_exprs() const {
2591 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2594 helper_expr_range lhs_exprs() {
2595 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2598 helper_expr_const_range rhs_exprs() const {
2599 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2602 helper_expr_range rhs_exprs() {
2603 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2606 helper_expr_const_range reduction_ops() const {
2607 return helper_expr_const_range(getReductionOps().begin(),
2608 getReductionOps().end());
2611 helper_expr_range reduction_ops() {
2612 return helper_expr_range(getReductionOps().begin(),
2613 getReductionOps().end());
2616 child_range children() {
2617 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2618 reinterpret_cast<Stmt **>(varlist_end()));
2621 const_child_range children() const {
2622 auto Children = const_cast<OMPReductionClause *>(this)->children();
2623 return const_child_range(Children.begin(), Children.end());
2626 child_range used_children() {
2627 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2628 reinterpret_cast<Stmt **>(varlist_end()));
2630 const_child_range used_children() const {
2631 auto Children = const_cast<OMPReductionClause *>(this)->used_children();
2632 return const_child_range(Children.begin(), Children.end());
2635 static bool classof(const OMPClause *T) {
2636 return T->getClauseKind() == OMPC_reduction;
2640 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
2644 /// #pragma omp taskgroup task_reduction(+:a,b)
2646 /// In this example directive '#pragma omp taskgroup' has clause
2647 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
2648 class OMPTaskReductionClause final
2649 : public OMPVarListClause<OMPTaskReductionClause>,
2650 public OMPClauseWithPostUpdate,
2651 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
2652 friend class OMPClauseReader;
2653 friend OMPVarListClause;
2654 friend TrailingObjects;
2656 /// Location of ':'.
2657 SourceLocation ColonLoc;
2659 /// Nested name specifier for C++.
2660 NestedNameSpecifierLoc QualifierLoc;
2662 /// Name of custom operator.
2663 DeclarationNameInfo NameInfo;
2665 /// Build clause with number of variables \a N.
2667 /// \param StartLoc Starting location of the clause.
2668 /// \param LParenLoc Location of '('.
2669 /// \param EndLoc Ending location of the clause.
2670 /// \param ColonLoc Location of ':'.
2671 /// \param N Number of the variables in the clause.
2672 /// \param QualifierLoc The nested-name qualifier with location information
2673 /// \param NameInfo The full name info for reduction identifier.
2674 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2675 SourceLocation ColonLoc, SourceLocation EndLoc,
2676 unsigned N, NestedNameSpecifierLoc QualifierLoc,
2677 const DeclarationNameInfo &NameInfo)
2678 : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
2679 LParenLoc, EndLoc, N),
2680 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2681 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2683 /// Build an empty clause.
2685 /// \param N Number of variables.
2686 explicit OMPTaskReductionClause(unsigned N)
2687 : OMPVarListClause<OMPTaskReductionClause>(
2688 OMPC_task_reduction, SourceLocation(), SourceLocation(),
2689 SourceLocation(), N),
2690 OMPClauseWithPostUpdate(this) {}
2692 /// Sets location of ':' symbol in clause.
2693 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2695 /// Sets the name info for specified reduction identifier.
2696 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2698 /// Sets the nested name specifier.
2699 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2701 /// Set list of helper expressions, required for proper codegen of the clause.
2702 /// These expressions represent private copy of the reduction variable.
2703 void setPrivates(ArrayRef<Expr *> Privates);
2705 /// Get the list of helper privates.
2706 MutableArrayRef<Expr *> getPrivates() {
2707 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2709 ArrayRef<const Expr *> getPrivates() const {
2710 return llvm::makeArrayRef(varlist_end(), varlist_size());
2713 /// Set list of helper expressions, required for proper codegen of the clause.
2714 /// These expressions represent LHS expression in the final reduction
2715 /// expression performed by the reduction clause.
2716 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2718 /// Get the list of helper LHS expressions.
2719 MutableArrayRef<Expr *> getLHSExprs() {
2720 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2722 ArrayRef<const Expr *> getLHSExprs() const {
2723 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2726 /// Set list of helper expressions, required for proper codegen of the clause.
2727 /// These expressions represent RHS expression in the final reduction
2728 /// expression performed by the reduction clause. Also, variables in these
2729 /// expressions are used for proper initialization of reduction copies.
2730 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2732 /// Get the list of helper destination expressions.
2733 MutableArrayRef<Expr *> getRHSExprs() {
2734 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2736 ArrayRef<const Expr *> getRHSExprs() const {
2737 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2740 /// Set list of helper reduction expressions, required for proper
2741 /// codegen of the clause. These expressions are binary expressions or
2742 /// operator/custom reduction call that calculates new value from source
2743 /// helper expressions to destination helper expressions.
2744 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2746 /// Get the list of helper reduction expressions.
2747 MutableArrayRef<Expr *> getReductionOps() {
2748 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2750 ArrayRef<const Expr *> getReductionOps() const {
2751 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2755 /// Creates clause with a list of variables \a VL.
2757 /// \param StartLoc Starting location of the clause.
2758 /// \param LParenLoc Location of '('.
2759 /// \param ColonLoc Location of ':'.
2760 /// \param EndLoc Ending location of the clause.
2761 /// \param VL The variables in the clause.
2762 /// \param QualifierLoc The nested-name qualifier with location information
2763 /// \param NameInfo The full name info for reduction identifier.
2764 /// \param Privates List of helper expressions for proper generation of
2766 /// \param LHSExprs List of helper expressions for proper generation of
2767 /// assignment operation required for copyprivate clause. This list represents
2768 /// LHSs of the reduction expressions.
2769 /// \param RHSExprs List of helper expressions for proper generation of
2770 /// assignment operation required for copyprivate clause. This list represents
2771 /// RHSs of the reduction expressions.
2772 /// Also, variables in these expressions are used for proper initialization of
2773 /// reduction copies.
2774 /// \param ReductionOps List of helper expressions that represents reduction
2777 /// LHSExprs binop RHSExprs;
2778 /// operator binop(LHSExpr, RHSExpr);
2779 /// <CutomReduction>(LHSExpr, RHSExpr);
2781 /// Required for proper codegen of final reduction operation performed by the
2782 /// reduction clause.
2783 /// \param PreInit Statement that must be executed before entering the OpenMP
2784 /// region with this clause.
2785 /// \param PostUpdate Expression that must be executed after exit from the
2786 /// OpenMP region with this clause.
2787 static OMPTaskReductionClause *
2788 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2789 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2790 NestedNameSpecifierLoc QualifierLoc,
2791 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2792 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2793 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2795 /// Creates an empty clause with the place for \a N variables.
2797 /// \param C AST context.
2798 /// \param N The number of variables.
2799 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2801 /// Gets location of ':' symbol in clause.
2802 SourceLocation getColonLoc() const { return ColonLoc; }
2804 /// Gets the name info for specified reduction identifier.
2805 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2807 /// Gets the nested name specifier.
2808 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2810 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2811 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2812 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2813 using helper_expr_const_range =
2814 llvm::iterator_range<helper_expr_const_iterator>;
2816 helper_expr_const_range privates() const {
2817 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2820 helper_expr_range privates() {
2821 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2824 helper_expr_const_range lhs_exprs() const {
2825 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2828 helper_expr_range lhs_exprs() {
2829 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2832 helper_expr_const_range rhs_exprs() const {
2833 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2836 helper_expr_range rhs_exprs() {
2837 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2840 helper_expr_const_range reduction_ops() const {
2841 return helper_expr_const_range(getReductionOps().begin(),
2842 getReductionOps().end());
2845 helper_expr_range reduction_ops() {
2846 return helper_expr_range(getReductionOps().begin(),
2847 getReductionOps().end());
2850 child_range children() {
2851 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2852 reinterpret_cast<Stmt **>(varlist_end()));
2855 const_child_range children() const {
2856 auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
2857 return const_child_range(Children.begin(), Children.end());
2860 child_range used_children() {
2861 return child_range(child_iterator(), child_iterator());
2863 const_child_range used_children() const {
2864 return const_child_range(const_child_iterator(), const_child_iterator());
2867 static bool classof(const OMPClause *T) {
2868 return T->getClauseKind() == OMPC_task_reduction;
2872 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
2875 /// #pragma omp task in_reduction(+:a,b)
2877 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
2878 /// operator '+' and the variables 'a' and 'b'.
2879 class OMPInReductionClause final
2880 : public OMPVarListClause<OMPInReductionClause>,
2881 public OMPClauseWithPostUpdate,
2882 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
2883 friend class OMPClauseReader;
2884 friend OMPVarListClause;
2885 friend TrailingObjects;
2887 /// Location of ':'.
2888 SourceLocation ColonLoc;
2890 /// Nested name specifier for C++.
2891 NestedNameSpecifierLoc QualifierLoc;
2893 /// Name of custom operator.
2894 DeclarationNameInfo NameInfo;
2896 /// Build clause with number of variables \a N.
2898 /// \param StartLoc Starting location of the clause.
2899 /// \param LParenLoc Location of '('.
2900 /// \param EndLoc Ending location of the clause.
2901 /// \param ColonLoc Location of ':'.
2902 /// \param N Number of the variables in the clause.
2903 /// \param QualifierLoc The nested-name qualifier with location information
2904 /// \param NameInfo The full name info for reduction identifier.
2905 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2906 SourceLocation ColonLoc, SourceLocation EndLoc,
2907 unsigned N, NestedNameSpecifierLoc QualifierLoc,
2908 const DeclarationNameInfo &NameInfo)
2909 : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc,
2910 LParenLoc, EndLoc, N),
2911 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2912 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2914 /// Build an empty clause.
2916 /// \param N Number of variables.
2917 explicit OMPInReductionClause(unsigned N)
2918 : OMPVarListClause<OMPInReductionClause>(
2919 OMPC_in_reduction, SourceLocation(), SourceLocation(),
2920 SourceLocation(), N),
2921 OMPClauseWithPostUpdate(this) {}
2923 /// Sets location of ':' symbol in clause.
2924 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2926 /// Sets the name info for specified reduction identifier.
2927 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2929 /// Sets the nested name specifier.
2930 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2932 /// Set list of helper expressions, required for proper codegen of the clause.
2933 /// These expressions represent private copy of the reduction variable.
2934 void setPrivates(ArrayRef<Expr *> Privates);
2936 /// Get the list of helper privates.
2937 MutableArrayRef<Expr *> getPrivates() {
2938 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2940 ArrayRef<const Expr *> getPrivates() const {
2941 return llvm::makeArrayRef(varlist_end(), varlist_size());
2944 /// Set list of helper expressions, required for proper codegen of the clause.
2945 /// These expressions represent LHS expression in the final reduction
2946 /// expression performed by the reduction clause.
2947 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2949 /// Get the list of helper LHS expressions.
2950 MutableArrayRef<Expr *> getLHSExprs() {
2951 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2953 ArrayRef<const Expr *> getLHSExprs() const {
2954 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2957 /// Set list of helper expressions, required for proper codegen of the clause.
2958 /// These expressions represent RHS expression in the final reduction
2959 /// expression performed by the reduction clause. Also, variables in these
2960 /// expressions are used for proper initialization of reduction copies.
2961 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2963 /// Get the list of helper destination expressions.
2964 MutableArrayRef<Expr *> getRHSExprs() {
2965 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2967 ArrayRef<const Expr *> getRHSExprs() const {
2968 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2971 /// Set list of helper reduction expressions, required for proper
2972 /// codegen of the clause. These expressions are binary expressions or
2973 /// operator/custom reduction call that calculates new value from source
2974 /// helper expressions to destination helper expressions.
2975 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2977 /// Get the list of helper reduction expressions.
2978 MutableArrayRef<Expr *> getReductionOps() {
2979 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2981 ArrayRef<const Expr *> getReductionOps() const {
2982 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2985 /// Set list of helper reduction taskgroup descriptors.
2986 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
2988 /// Get the list of helper reduction taskgroup descriptors.
2989 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
2990 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
2992 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
2993 return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
2997 /// Creates clause with a list of variables \a VL.
2999 /// \param StartLoc Starting location of the clause.
3000 /// \param LParenLoc Location of '('.
3001 /// \param ColonLoc Location of ':'.
3002 /// \param EndLoc Ending location of the clause.
3003 /// \param VL The variables in the clause.
3004 /// \param QualifierLoc The nested-name qualifier with location information
3005 /// \param NameInfo The full name info for reduction identifier.
3006 /// \param Privates List of helper expressions for proper generation of
3008 /// \param LHSExprs List of helper expressions for proper generation of
3009 /// assignment operation required for copyprivate clause. This list represents
3010 /// LHSs of the reduction expressions.
3011 /// \param RHSExprs List of helper expressions for proper generation of
3012 /// assignment operation required for copyprivate clause. This list represents
3013 /// RHSs of the reduction expressions.
3014 /// Also, variables in these expressions are used for proper initialization of
3015 /// reduction copies.
3016 /// \param ReductionOps List of helper expressions that represents reduction
3019 /// LHSExprs binop RHSExprs;
3020 /// operator binop(LHSExpr, RHSExpr);
3021 /// <CutomReduction>(LHSExpr, RHSExpr);
3023 /// Required for proper codegen of final reduction operation performed by the
3024 /// reduction clause.
3025 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3026 /// corresponding items in parent taskgroup task_reduction clause.
3027 /// \param PreInit Statement that must be executed before entering the OpenMP
3028 /// region with this clause.
3029 /// \param PostUpdate Expression that must be executed after exit from the
3030 /// OpenMP region with this clause.
3031 static OMPInReductionClause *
3032 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3033 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3034 NestedNameSpecifierLoc QualifierLoc,
3035 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3036 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3037 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3038 Stmt *PreInit, Expr *PostUpdate);
3040 /// Creates an empty clause with the place for \a N variables.
3042 /// \param C AST context.
3043 /// \param N The number of variables.
3044 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3046 /// Gets location of ':' symbol in clause.
3047 SourceLocation getColonLoc() const { return ColonLoc; }
3049 /// Gets the name info for specified reduction identifier.
3050 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3052 /// Gets the nested name specifier.
3053 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3055 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3056 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3057 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3058 using helper_expr_const_range =
3059 llvm::iterator_range<helper_expr_const_iterator>;
3061 helper_expr_const_range privates() const {
3062 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3065 helper_expr_range privates() {
3066 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3069 helper_expr_const_range lhs_exprs() const {
3070 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3073 helper_expr_range lhs_exprs() {
3074 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3077 helper_expr_const_range rhs_exprs() const {
3078 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3081 helper_expr_range rhs_exprs() {
3082 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3085 helper_expr_const_range reduction_ops() const {
3086 return helper_expr_const_range(getReductionOps().begin(),
3087 getReductionOps().end());
3090 helper_expr_range reduction_ops() {
3091 return helper_expr_range(getReductionOps().begin(),
3092 getReductionOps().end());
3095 helper_expr_const_range taskgroup_descriptors() const {
3096 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3097 getTaskgroupDescriptors().end());
3100 helper_expr_range taskgroup_descriptors() {
3101 return helper_expr_range(getTaskgroupDescriptors().begin(),
3102 getTaskgroupDescriptors().end());
3105 child_range children() {
3106 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3107 reinterpret_cast<Stmt **>(varlist_end()));
3110 const_child_range children() const {
3111 auto Children = const_cast<OMPInReductionClause *>(this)->children();
3112 return const_child_range(Children.begin(), Children.end());
3115 child_range used_children() {
3116 return child_range(child_iterator(), child_iterator());
3118 const_child_range used_children() const {
3119 return const_child_range(const_child_iterator(), const_child_iterator());
3122 static bool classof(const OMPClause *T) {
3123 return T->getClauseKind() == OMPC_in_reduction;
3127 /// This represents clause 'linear' in the '#pragma omp ...'
3131 /// #pragma omp simd linear(a,b : 2)
3133 /// In this example directive '#pragma omp simd' has clause 'linear'
3134 /// with variables 'a', 'b' and linear step '2'.
3135 class OMPLinearClause final
3136 : public OMPVarListClause<OMPLinearClause>,
3137 public OMPClauseWithPostUpdate,
3138 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
3139 friend class OMPClauseReader;
3140 friend OMPVarListClause;
3141 friend TrailingObjects;
3143 /// Modifier of 'linear' clause.
3144 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
3146 /// Location of linear modifier if any.
3147 SourceLocation ModifierLoc;
3149 /// Location of ':'.
3150 SourceLocation ColonLoc;
3152 /// Sets the linear step for clause.
3153 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
3155 /// Sets the expression to calculate linear step for clause.
3156 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
3158 /// Build 'linear' clause with given number of variables \a NumVars.
3160 /// \param StartLoc Starting location of the clause.
3161 /// \param LParenLoc Location of '('.
3162 /// \param ColonLoc Location of ':'.
3163 /// \param EndLoc Ending location of the clause.
3164 /// \param NumVars Number of variables.
3165 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3166 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3167 SourceLocation ColonLoc, SourceLocation EndLoc,
3169 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
3171 OMPClauseWithPostUpdate(this), Modifier(Modifier),
3172 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
3174 /// Build an empty clause.
3176 /// \param NumVars Number of variables.
3177 explicit OMPLinearClause(unsigned NumVars)
3178 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
3179 SourceLocation(), SourceLocation(),
3181 OMPClauseWithPostUpdate(this) {}
3183 /// Gets the list of initial values for linear variables.
3185 /// There are NumVars expressions with initial values allocated after the
3186 /// varlist, they are followed by NumVars update expressions (used to update
3187 /// the linear variable's value on current iteration) and they are followed by
3188 /// NumVars final expressions (used to calculate the linear variable's
3189 /// value after the loop body). After these lists, there are 2 helper
3190 /// expressions - linear step and a helper to calculate it before the
3191 /// loop body (used when the linear step is not constant):
3193 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
3194 /// Finals[]; Step; CalcStep; }
3195 MutableArrayRef<Expr *> getPrivates() {
3196 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3198 ArrayRef<const Expr *> getPrivates() const {
3199 return llvm::makeArrayRef(varlist_end(), varlist_size());
3202 MutableArrayRef<Expr *> getInits() {
3203 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3205 ArrayRef<const Expr *> getInits() const {
3206 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3209 /// Sets the list of update expressions for linear variables.
3210 MutableArrayRef<Expr *> getUpdates() {
3211 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
3213 ArrayRef<const Expr *> getUpdates() const {
3214 return llvm::makeArrayRef(getInits().end(), varlist_size());
3217 /// Sets the list of final update expressions for linear variables.
3218 MutableArrayRef<Expr *> getFinals() {
3219 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
3221 ArrayRef<const Expr *> getFinals() const {
3222 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
3225 /// Gets the list of used expressions for linear variables.
3226 MutableArrayRef<Expr *> getUsedExprs() {
3227 return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
3229 ArrayRef<const Expr *> getUsedExprs() const {
3230 return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
3233 /// Sets the list of the copies of original linear variables.
3234 /// \param PL List of expressions.
3235 void setPrivates(ArrayRef<Expr *> PL);
3237 /// Sets the list of the initial values for linear variables.
3238 /// \param IL List of expressions.
3239 void setInits(ArrayRef<Expr *> IL);
3242 /// Creates clause with a list of variables \a VL and a linear step
3245 /// \param C AST Context.
3246 /// \param StartLoc Starting location of the clause.
3247 /// \param LParenLoc Location of '('.
3248 /// \param Modifier Modifier of 'linear' clause.
3249 /// \param ModifierLoc Modifier location.
3250 /// \param ColonLoc Location of ':'.
3251 /// \param EndLoc Ending location of the clause.
3252 /// \param VL List of references to the variables.
3253 /// \param PL List of private copies of original variables.
3254 /// \param IL List of initial values for the variables.
3255 /// \param Step Linear step.
3256 /// \param CalcStep Calculation of the linear step.
3257 /// \param PreInit Statement that must be executed before entering the OpenMP
3258 /// region with this clause.
3259 /// \param PostUpdate Expression that must be executed after exit from the
3260 /// OpenMP region with this clause.
3261 static OMPLinearClause *
3262 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3263 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3264 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3265 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
3266 Stmt *PreInit, Expr *PostUpdate);
3268 /// Creates an empty clause with the place for \a NumVars variables.
3270 /// \param C AST context.
3271 /// \param NumVars Number of variables.
3272 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3275 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
3277 /// Return modifier.
3278 OpenMPLinearClauseKind getModifier() const { return Modifier; }
3280 /// Set modifier location.
3281 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3283 /// Return modifier location.
3284 SourceLocation getModifierLoc() const { return ModifierLoc; }
3286 /// Sets the location of ':'.
3287 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3289 /// Returns the location of ':'.
3290 SourceLocation getColonLoc() const { return ColonLoc; }
3292 /// Returns linear step.
3293 Expr *getStep() { return *(getFinals().end()); }
3295 /// Returns linear step.
3296 const Expr *getStep() const { return *(getFinals().end()); }
3298 /// Returns expression to calculate linear step.
3299 Expr *getCalcStep() { return *(getFinals().end() + 1); }
3301 /// Returns expression to calculate linear step.
3302 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
3304 /// Sets the list of update expressions for linear variables.
3305 /// \param UL List of expressions.
3306 void setUpdates(ArrayRef<Expr *> UL);
3308 /// Sets the list of final update expressions for linear variables.
3309 /// \param FL List of expressions.
3310 void setFinals(ArrayRef<Expr *> FL);
3312 /// Sets the list of used expressions for the linear clause.
3313 void setUsedExprs(ArrayRef<Expr *> UE);
3315 using privates_iterator = MutableArrayRef<Expr *>::iterator;
3316 using privates_const_iterator = ArrayRef<const Expr *>::iterator;
3317 using privates_range = llvm::iterator_range<privates_iterator>;
3318 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
3320 privates_range privates() {
3321 return privates_range(getPrivates().begin(), getPrivates().end());
3324 privates_const_range privates() const {
3325 return privates_const_range(getPrivates().begin(), getPrivates().end());
3328 using inits_iterator = MutableArrayRef<Expr *>::iterator;
3329 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
3330 using inits_range = llvm::iterator_range<inits_iterator>;
3331 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3333 inits_range inits() {
3334 return inits_range(getInits().begin(), getInits().end());
3337 inits_const_range inits() const {
3338 return inits_const_range(getInits().begin(), getInits().end());
3341 using updates_iterator = MutableArrayRef<Expr *>::iterator;
3342 using updates_const_iterator = ArrayRef<const Expr *>::iterator;
3343 using updates_range = llvm::iterator_range<updates_iterator>;
3344 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
3346 updates_range updates() {
3347 return updates_range(getUpdates().begin(), getUpdates().end());
3350 updates_const_range updates() const {
3351 return updates_const_range(getUpdates().begin(), getUpdates().end());
3354 using finals_iterator = MutableArrayRef<Expr *>::iterator;
3355 using finals_const_iterator = ArrayRef<const Expr *>::iterator;
3356 using finals_range = llvm::iterator_range<finals_iterator>;
3357 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
3359 finals_range finals() {
3360 return finals_range(getFinals().begin(), getFinals().end());
3363 finals_const_range finals() const {
3364 return finals_const_range(getFinals().begin(), getFinals().end());
3367 using used_expressions_iterator = MutableArrayRef<Expr *>::iterator;
3368 using used_expressions_const_iterator = ArrayRef<const Expr *>::iterator;
3369 using used_expressions_range =
3370 llvm::iterator_range<used_expressions_iterator>;
3371 using used_expressions_const_range =
3372 llvm::iterator_range<used_expressions_const_iterator>;
3374 used_expressions_range used_expressions() {
3375 return finals_range(getUsedExprs().begin(), getUsedExprs().end());
3378 used_expressions_const_range used_expressions() const {
3379 return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
3382 child_range children() {
3383 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3384 reinterpret_cast<Stmt **>(varlist_end()));
3387 const_child_range children() const {
3388 auto Children = const_cast<OMPLinearClause *>(this)->children();
3389 return const_child_range(Children.begin(), Children.end());
3392 child_range used_children();
3394 const_child_range used_children() const {
3395 auto Children = const_cast<OMPLinearClause *>(this)->used_children();
3396 return const_child_range(Children.begin(), Children.end());
3399 static bool classof(const OMPClause *T) {
3400 return T->getClauseKind() == OMPC_linear;
3404 /// This represents clause 'aligned' in the '#pragma omp ...'
3408 /// #pragma omp simd aligned(a,b : 8)
3410 /// In this example directive '#pragma omp simd' has clause 'aligned'
3411 /// with variables 'a', 'b' and alignment '8'.
3412 class OMPAlignedClause final
3413 : public OMPVarListClause<OMPAlignedClause>,
3414 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
3415 friend class OMPClauseReader;
3416 friend OMPVarListClause;
3417 friend TrailingObjects;
3419 /// Location of ':'.
3420 SourceLocation ColonLoc;
3422 /// Sets the alignment for clause.
3423 void setAlignment(Expr *A) { *varlist_end() = A; }
3425 /// Build 'aligned' clause with given number of variables \a NumVars.
3427 /// \param StartLoc Starting location of the clause.
3428 /// \param LParenLoc Location of '('.
3429 /// \param ColonLoc Location of ':'.
3430 /// \param EndLoc Ending location of the clause.
3431 /// \param NumVars Number of variables.
3432 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3433 SourceLocation ColonLoc, SourceLocation EndLoc,
3435 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
3437 ColonLoc(ColonLoc) {}
3439 /// Build an empty clause.
3441 /// \param NumVars Number of variables.
3442 explicit OMPAlignedClause(unsigned NumVars)
3443 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
3444 SourceLocation(), SourceLocation(),
3448 /// Creates clause with a list of variables \a VL and alignment \a A.
3450 /// \param C AST Context.
3451 /// \param StartLoc Starting location of the clause.
3452 /// \param LParenLoc Location of '('.
3453 /// \param ColonLoc Location of ':'.
3454 /// \param EndLoc Ending location of the clause.
3455 /// \param VL List of references to the variables.
3456 /// \param A Alignment.
3457 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3458 SourceLocation LParenLoc,
3459 SourceLocation ColonLoc,
3460 SourceLocation EndLoc, ArrayRef<Expr *> VL,
3463 /// Creates an empty clause with the place for \a NumVars variables.
3465 /// \param C AST context.
3466 /// \param NumVars Number of variables.
3467 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3469 /// Sets the location of ':'.
3470 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3472 /// Returns the location of ':'.
3473 SourceLocation getColonLoc() const { return ColonLoc; }
3475 /// Returns alignment.
3476 Expr *getAlignment() { return *varlist_end(); }
3478 /// Returns alignment.
3479 const Expr *getAlignment() const { return *varlist_end(); }
3481 child_range children() {
3482 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3483 reinterpret_cast<Stmt **>(varlist_end()));
3486 const_child_range children() const {
3487 auto Children = const_cast<OMPAlignedClause *>(this)->children();
3488 return const_child_range(Children.begin(), Children.end());
3491 child_range used_children() {
3492 return child_range(child_iterator(), child_iterator());
3494 const_child_range used_children() const {
3495 return const_child_range(const_child_iterator(), const_child_iterator());
3498 static bool classof(const OMPClause *T) {
3499 return T->getClauseKind() == OMPC_aligned;
3503 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
3506 /// #pragma omp parallel copyin(a,b)
3508 /// In this example directive '#pragma omp parallel' has clause 'copyin'
3509 /// with the variables 'a' and 'b'.
3510 class OMPCopyinClause final
3511 : public OMPVarListClause<OMPCopyinClause>,
3512 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
3513 // Class has 3 additional tail allocated arrays:
3514 // 1. List of helper expressions for proper generation of assignment operation
3515 // required for copyin clause. This list represents sources.
3516 // 2. List of helper expressions for proper generation of assignment operation
3517 // required for copyin clause. This list represents destinations.
3518 // 3. List of helper expressions that represents assignment operation:
3520 // DstExprs = SrcExprs;
3522 // Required for proper codegen of propagation of master's thread values of
3523 // threadprivate variables to local instances of that variables in other
3524 // implicit threads.
3526 friend class OMPClauseReader;
3527 friend OMPVarListClause;
3528 friend TrailingObjects;
3530 /// Build clause with number of variables \a N.
3532 /// \param StartLoc Starting location of the clause.
3533 /// \param LParenLoc Location of '('.
3534 /// \param EndLoc Ending location of the clause.
3535 /// \param N Number of the variables in the clause.
3536 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3537 SourceLocation EndLoc, unsigned N)
3538 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
3541 /// Build an empty clause.
3543 /// \param N Number of variables.
3544 explicit OMPCopyinClause(unsigned N)
3545 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
3546 SourceLocation(), SourceLocation(),
3549 /// Set list of helper expressions, required for proper codegen of the
3550 /// clause. These expressions represent source expression in the final
3551 /// assignment statement performed by the copyin clause.
3552 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3554 /// Get the list of helper source expressions.
3555 MutableArrayRef<Expr *> getSourceExprs() {
3556 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3558 ArrayRef<const Expr *> getSourceExprs() const {
3559 return llvm::makeArrayRef(varlist_end(), varlist_size());
3562 /// Set list of helper expressions, required for proper codegen of the
3563 /// clause. These expressions represent destination expression in the final
3564 /// assignment statement performed by the copyin clause.
3565 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3567 /// Get the list of helper destination expressions.
3568 MutableArrayRef<Expr *> getDestinationExprs() {
3569 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3571 ArrayRef<const Expr *> getDestinationExprs() const {
3572 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3575 /// Set list of helper assignment expressions, required for proper
3576 /// codegen of the clause. These expressions are assignment expressions that
3577 /// assign source helper expressions to destination helper expressions
3578 /// correspondingly.
3579 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3581 /// Get the list of helper assignment expressions.
3582 MutableArrayRef<Expr *> getAssignmentOps() {
3583 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3585 ArrayRef<const Expr *> getAssignmentOps() const {
3586 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3590 /// Creates clause with a list of variables \a VL.
3592 /// \param C AST context.
3593 /// \param StartLoc Starting location of the clause.
3594 /// \param LParenLoc Location of '('.
3595 /// \param EndLoc Ending location of the clause.
3596 /// \param VL List of references to the variables.
3597 /// \param SrcExprs List of helper expressions for proper generation of
3598 /// assignment operation required for copyin clause. This list represents
3600 /// \param DstExprs List of helper expressions for proper generation of
3601 /// assignment operation required for copyin clause. This list represents
3603 /// \param AssignmentOps List of helper expressions that represents assignment
3606 /// DstExprs = SrcExprs;
3608 /// Required for proper codegen of propagation of master's thread values of
3609 /// threadprivate variables to local instances of that variables in other
3610 /// implicit threads.
3611 static OMPCopyinClause *
3612 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3613 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3614 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
3616 /// Creates an empty clause with \a N variables.
3618 /// \param C AST context.
3619 /// \param N The number of variables.
3620 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
3622 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3623 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3624 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3625 using helper_expr_const_range =
3626 llvm::iterator_range<helper_expr_const_iterator>;
3628 helper_expr_const_range source_exprs() const {
3629 return helper_expr_const_range(getSourceExprs().begin(),
3630 getSourceExprs().end());
3633 helper_expr_range source_exprs() {
3634 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3637 helper_expr_const_range destination_exprs() const {
3638 return helper_expr_const_range(getDestinationExprs().begin(),
3639 getDestinationExprs().end());
3642 helper_expr_range destination_exprs() {
3643 return helper_expr_range(getDestinationExprs().begin(),
3644 getDestinationExprs().end());
3647 helper_expr_const_range assignment_ops() const {
3648 return helper_expr_const_range(getAssignmentOps().begin(),
3649 getAssignmentOps().end());
3652 helper_expr_range assignment_ops() {
3653 return helper_expr_range(getAssignmentOps().begin(),
3654 getAssignmentOps().end());
3657 child_range children() {
3658 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3659 reinterpret_cast<Stmt **>(varlist_end()));
3662 const_child_range children() const {
3663 auto Children = const_cast<OMPCopyinClause *>(this)->children();
3664 return const_child_range(Children.begin(), Children.end());
3667 child_range used_children() {
3668 return child_range(child_iterator(), child_iterator());
3670 const_child_range used_children() const {
3671 return const_child_range(const_child_iterator(), const_child_iterator());
3674 static bool classof(const OMPClause *T) {
3675 return T->getClauseKind() == OMPC_copyin;
3679 /// This represents clause 'copyprivate' in the '#pragma omp ...'
3683 /// #pragma omp single copyprivate(a,b)
3685 /// In this example directive '#pragma omp single' has clause 'copyprivate'
3686 /// with the variables 'a' and 'b'.
3687 class OMPCopyprivateClause final
3688 : public OMPVarListClause<OMPCopyprivateClause>,
3689 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
3690 friend class OMPClauseReader;
3691 friend OMPVarListClause;
3692 friend TrailingObjects;
3694 /// Build clause with number of variables \a N.
3696 /// \param StartLoc Starting location of the clause.
3697 /// \param LParenLoc Location of '('.
3698 /// \param EndLoc Ending location of the clause.
3699 /// \param N Number of the variables in the clause.
3700 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3701 SourceLocation EndLoc, unsigned N)
3702 : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
3703 LParenLoc, EndLoc, N) {}
3705 /// Build an empty clause.
3707 /// \param N Number of variables.
3708 explicit OMPCopyprivateClause(unsigned N)
3709 : OMPVarListClause<OMPCopyprivateClause>(
3710 OMPC_copyprivate, SourceLocation(), SourceLocation(),
3711 SourceLocation(), N) {}
3713 /// Set list of helper expressions, required for proper codegen of the
3714 /// clause. These expressions represent source expression in the final
3715 /// assignment statement performed by the copyprivate clause.
3716 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3718 /// Get the list of helper source expressions.
3719 MutableArrayRef<Expr *> getSourceExprs() {
3720 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3722 ArrayRef<const Expr *> getSourceExprs() const {
3723 return llvm::makeArrayRef(varlist_end(), varlist_size());
3726 /// Set list of helper expressions, required for proper codegen of the
3727 /// clause. These expressions represent destination expression in the final
3728 /// assignment statement performed by the copyprivate clause.
3729 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3731 /// Get the list of helper destination expressions.
3732 MutableArrayRef<Expr *> getDestinationExprs() {
3733 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3735 ArrayRef<const Expr *> getDestinationExprs() const {
3736 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3739 /// Set list of helper assignment expressions, required for proper
3740 /// codegen of the clause. These expressions are assignment expressions that
3741 /// assign source helper expressions to destination helper expressions
3742 /// correspondingly.
3743 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3745 /// Get the list of helper assignment expressions.
3746 MutableArrayRef<Expr *> getAssignmentOps() {
3747 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3749 ArrayRef<const Expr *> getAssignmentOps() const {
3750 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3754 /// Creates clause with a list of variables \a VL.
3756 /// \param C AST context.
3757 /// \param StartLoc Starting location of the clause.
3758 /// \param LParenLoc Location of '('.
3759 /// \param EndLoc Ending location of the clause.
3760 /// \param VL List of references to the variables.
3761 /// \param SrcExprs List of helper expressions for proper generation of
3762 /// assignment operation required for copyprivate clause. This list represents
3764 /// \param DstExprs List of helper expressions for proper generation of
3765 /// assignment operation required for copyprivate clause. This list represents
3767 /// \param AssignmentOps List of helper expressions that represents assignment
3770 /// DstExprs = SrcExprs;
3772 /// Required for proper codegen of final assignment performed by the
3773 /// copyprivate clause.
3774 static OMPCopyprivateClause *
3775 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3776 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
3777 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
3779 /// Creates an empty clause with \a N variables.
3781 /// \param C AST context.
3782 /// \param N The number of variables.
3783 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
3785 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3786 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3787 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3788 using helper_expr_const_range =
3789 llvm::iterator_range<helper_expr_const_iterator>;
3791 helper_expr_const_range source_exprs() const {
3792 return helper_expr_const_range(getSourceExprs().begin(),
3793 getSourceExprs().end());
3796 helper_expr_range source_exprs() {
3797 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
3800 helper_expr_const_range destination_exprs() const {
3801 return helper_expr_const_range(getDestinationExprs().begin(),
3802 getDestinationExprs().end());
3805 helper_expr_range destination_exprs() {
3806 return helper_expr_range(getDestinationExprs().begin(),
3807 getDestinationExprs().end());
3810 helper_expr_const_range assignment_ops() const {
3811 return helper_expr_const_range(getAssignmentOps().begin(),
3812 getAssignmentOps().end());
3815 helper_expr_range assignment_ops() {
3816 return helper_expr_range(getAssignmentOps().begin(),
3817 getAssignmentOps().end());
3820 child_range children() {
3821 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3822 reinterpret_cast<Stmt **>(varlist_end()));
3825 const_child_range children() const {
3826 auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
3827 return const_child_range(Children.begin(), Children.end());
3830 child_range used_children() {
3831 return child_range(child_iterator(), child_iterator());
3833 const_child_range used_children() const {
3834 return const_child_range(const_child_iterator(), const_child_iterator());
3837 static bool classof(const OMPClause *T) {
3838 return T->getClauseKind() == OMPC_copyprivate;
3842 /// This represents implicit clause 'flush' for the '#pragma omp flush'
3844 /// This clause does not exist by itself, it can be only as a part of 'omp
3845 /// flush' directive. This clause is introduced to keep the original structure
3846 /// of \a OMPExecutableDirective class and its derivatives and to use the
3847 /// existing infrastructure of clauses with the list of variables.
3850 /// #pragma omp flush(a,b)
3852 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
3853 /// with the variables 'a' and 'b'.
3854 class OMPFlushClause final
3855 : public OMPVarListClause<OMPFlushClause>,
3856 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
3857 friend OMPVarListClause;
3858 friend TrailingObjects;
3860 /// Build clause with number of variables \a N.
3862 /// \param StartLoc Starting location of the clause.
3863 /// \param LParenLoc Location of '('.
3864 /// \param EndLoc Ending location of the clause.
3865 /// \param N Number of the variables in the clause.
3866 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3867 SourceLocation EndLoc, unsigned N)
3868 : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
3871 /// Build an empty clause.
3873 /// \param N Number of variables.
3874 explicit OMPFlushClause(unsigned N)
3875 : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
3876 SourceLocation(), SourceLocation(),
3880 /// Creates clause with a list of variables \a VL.
3882 /// \param C AST context.
3883 /// \param StartLoc Starting location of the clause.
3884 /// \param LParenLoc Location of '('.
3885 /// \param EndLoc Ending location of the clause.
3886 /// \param VL List of references to the variables.
3887 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
3888 SourceLocation LParenLoc, SourceLocation EndLoc,
3889 ArrayRef<Expr *> VL);
3891 /// Creates an empty clause with \a N variables.
3893 /// \param C AST context.
3894 /// \param N The number of variables.
3895 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
3897 child_range children() {
3898 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3899 reinterpret_cast<Stmt **>(varlist_end()));
3902 const_child_range children() const {
3903 auto Children = const_cast<OMPFlushClause *>(this)->children();
3904 return const_child_range(Children.begin(), Children.end());
3907 child_range used_children() {
3908 return child_range(child_iterator(), child_iterator());
3910 const_child_range used_children() const {
3911 return const_child_range(const_child_iterator(), const_child_iterator());
3914 static bool classof(const OMPClause *T) {
3915 return T->getClauseKind() == OMPC_flush;
3919 /// This represents implicit clause 'depend' for the '#pragma omp task'
3923 /// #pragma omp task depend(in:a,b)
3925 /// In this example directive '#pragma omp task' with clause 'depend' with the
3926 /// variables 'a' and 'b' with dependency 'in'.
3927 class OMPDependClause final
3928 : public OMPVarListClause<OMPDependClause>,
3929 private llvm::TrailingObjects<OMPDependClause, Expr *> {
3930 friend class OMPClauseReader;
3931 friend OMPVarListClause;
3932 friend TrailingObjects;
3934 /// Dependency type (one of in, out, inout).
3935 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
3937 /// Dependency type location.
3938 SourceLocation DepLoc;
3941 SourceLocation ColonLoc;
3943 /// Number of loops, associated with the depend clause.
3944 unsigned NumLoops = 0;
3946 /// Build clause with number of variables \a N.
3948 /// \param StartLoc Starting location of the clause.
3949 /// \param LParenLoc Location of '('.
3950 /// \param EndLoc Ending location of the clause.
3951 /// \param N Number of the variables in the clause.
3952 /// \param NumLoops Number of loops that is associated with this depend
3954 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3955 SourceLocation EndLoc, unsigned N, unsigned NumLoops)
3956 : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
3957 EndLoc, N), NumLoops(NumLoops) {}
3959 /// Build an empty clause.
3961 /// \param N Number of variables.
3962 /// \param NumLoops Number of loops that is associated with this depend
3964 explicit OMPDependClause(unsigned N, unsigned NumLoops)
3965 : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
3966 SourceLocation(), SourceLocation(),
3968 NumLoops(NumLoops) {}
3970 /// Set dependency kind.
3971 void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
3973 /// Set dependency kind and its location.
3974 void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
3976 /// Set colon location.
3977 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3980 /// Creates clause with a list of variables \a VL.
3982 /// \param C AST context.
3983 /// \param StartLoc Starting location of the clause.
3984 /// \param LParenLoc Location of '('.
3985 /// \param EndLoc Ending location of the clause.
3986 /// \param DepKind Dependency type.
3987 /// \param DepLoc Location of the dependency type.
3988 /// \param ColonLoc Colon location.
3989 /// \param VL List of references to the variables.
3990 /// \param NumLoops Number of loops that is associated with this depend
3992 static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
3993 SourceLocation LParenLoc,
3994 SourceLocation EndLoc,
3995 OpenMPDependClauseKind DepKind,
3996 SourceLocation DepLoc, SourceLocation ColonLoc,
3997 ArrayRef<Expr *> VL, unsigned NumLoops);
3999 /// Creates an empty clause with \a N variables.
4001 /// \param C AST context.
4002 /// \param N The number of variables.
4003 /// \param NumLoops Number of loops that is associated with this depend
4005 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
4008 /// Get dependency type.
4009 OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
4011 /// Get dependency type location.
4012 SourceLocation getDependencyLoc() const { return DepLoc; }
4014 /// Get colon location.
4015 SourceLocation getColonLoc() const { return ColonLoc; }
4017 /// Get number of loops associated with the clause.
4018 unsigned getNumLoops() const { return NumLoops; }
4020 /// Set the loop data for the depend clauses with 'sink|source' kind of
4022 void setLoopData(unsigned NumLoop, Expr *Cnt);
4024 /// Get the loop data.
4025 Expr *getLoopData(unsigned NumLoop);
4026 const Expr *getLoopData(unsigned NumLoop) const;
4028 child_range children() {
4029 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4030 reinterpret_cast<Stmt **>(varlist_end()));
4033 const_child_range children() const {
4034 auto Children = const_cast<OMPDependClause *>(this)->children();
4035 return const_child_range(Children.begin(), Children.end());
4038 child_range used_children() {
4039 return child_range(child_iterator(), child_iterator());
4041 const_child_range used_children() const {
4042 return const_child_range(const_child_iterator(), const_child_iterator());
4045 static bool classof(const OMPClause *T) {
4046 return T->getClauseKind() == OMPC_depend;
4050 /// This represents 'device' clause in the '#pragma omp ...'
4054 /// #pragma omp target device(a)
4056 /// In this example directive '#pragma omp target' has clause 'device'
4057 /// with single expression 'a'.
4058 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
4059 friend class OMPClauseReader;
4061 /// Location of '('.
4062 SourceLocation LParenLoc;
4065 Stmt *Device = nullptr;
4067 /// Set the device number.
4069 /// \param E Device number.
4070 void setDevice(Expr *E) { Device = E; }
4073 /// Build 'device' clause.
4075 /// \param E Expression associated with this clause.
4076 /// \param CaptureRegion Innermost OpenMP region where expressions in this
4077 /// clause must be captured.
4078 /// \param StartLoc Starting location of the clause.
4079 /// \param LParenLoc Location of '('.
4080 /// \param EndLoc Ending location of the clause.
4081 OMPDeviceClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
4082 SourceLocation StartLoc, SourceLocation LParenLoc,
4083 SourceLocation EndLoc)
4084 : OMPClause(OMPC_device, StartLoc, EndLoc), OMPClauseWithPreInit(this),
4085 LParenLoc(LParenLoc), Device(E) {
4086 setPreInitStmt(HelperE, CaptureRegion);
4089 /// Build an empty clause.
4091 : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
4092 OMPClauseWithPreInit(this) {}
4094 /// Sets the location of '('.
4095 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4097 /// Returns the location of '('.
4098 SourceLocation getLParenLoc() const { return LParenLoc; }
4100 /// Return device number.
4101 Expr *getDevice() { return cast<Expr>(Device); }
4103 /// Return device number.
4104 Expr *getDevice() const { return cast<Expr>(Device); }
4106 child_range children() { return child_range(&Device, &Device + 1); }
4108 const_child_range children() const {
4109 return const_child_range(&Device, &Device + 1);
4112 child_range used_children() {
4113 return child_range(child_iterator(), child_iterator());
4115 const_child_range used_children() const {
4116 return const_child_range(const_child_iterator(), const_child_iterator());
4119 static bool classof(const OMPClause *T) {
4120 return T->getClauseKind() == OMPC_device;
4124 /// This represents 'threads' clause in the '#pragma omp ...' directive.
4127 /// #pragma omp ordered threads
4129 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
4130 class OMPThreadsClause : public OMPClause {
4132 /// Build 'threads' clause.
4134 /// \param StartLoc Starting location of the clause.
4135 /// \param EndLoc Ending location of the clause.
4136 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
4137 : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
4139 /// Build an empty clause.
4141 : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
4143 child_range children() {
4144 return child_range(child_iterator(), child_iterator());
4147 const_child_range children() const {
4148 return const_child_range(const_child_iterator(), const_child_iterator());
4151 child_range used_children() {
4152 return child_range(child_iterator(), child_iterator());
4154 const_child_range used_children() const {
4155 return const_child_range(const_child_iterator(), const_child_iterator());
4158 static bool classof(const OMPClause *T) {
4159 return T->getClauseKind() == OMPC_threads;
4163 /// This represents 'simd' clause in the '#pragma omp ...' directive.
4166 /// #pragma omp ordered simd
4168 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
4169 class OMPSIMDClause : public OMPClause {
4171 /// Build 'simd' clause.
4173 /// \param StartLoc Starting location of the clause.
4174 /// \param EndLoc Ending location of the clause.
4175 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
4176 : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
4178 /// Build an empty clause.
4179 OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
4181 child_range children() {
4182 return child_range(child_iterator(), child_iterator());
4185 const_child_range children() const {
4186 return const_child_range(const_child_iterator(), const_child_iterator());
4189 child_range used_children() {
4190 return child_range(child_iterator(), child_iterator());
4192 const_child_range used_children() const {
4193 return const_child_range(const_child_iterator(), const_child_iterator());
4196 static bool classof(const OMPClause *T) {
4197 return T->getClauseKind() == OMPC_simd;
4201 /// Struct that defines common infrastructure to handle mappable
4202 /// expressions used in OpenMP clauses.
4203 class OMPClauseMappableExprCommon {
4205 /// Class that represents a component of a mappable expression. E.g.
4206 /// for an expression S.a, the first component is a declaration reference
4207 /// expression associated with 'S' and the second is a member expression
4208 /// associated with the field declaration 'a'. If the expression is an array
4209 /// subscript it may not have any associated declaration. In that case the
4210 /// associated declaration is set to nullptr.
4211 class MappableComponent {
4212 /// Expression associated with the component.
4213 Expr *AssociatedExpression = nullptr;
4215 /// Declaration associated with the declaration. If the component does
4216 /// not have a declaration (e.g. array subscripts or section), this is set
4218 ValueDecl *AssociatedDeclaration = nullptr;
4221 explicit MappableComponent() = default;
4222 explicit MappableComponent(Expr *AssociatedExpression,
4223 ValueDecl *AssociatedDeclaration)
4224 : AssociatedExpression(AssociatedExpression),
4225 AssociatedDeclaration(
4226 AssociatedDeclaration
4227 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
4230 Expr *getAssociatedExpression() const { return AssociatedExpression; }
4232 ValueDecl *getAssociatedDeclaration() const {
4233 return AssociatedDeclaration;
4237 // List of components of an expression. This first one is the whole
4238 // expression and the last one is the base expression.
4239 using MappableExprComponentList = SmallVector<MappableComponent, 8>;
4240 using MappableExprComponentListRef = ArrayRef<MappableComponent>;
4242 // List of all component lists associated to the same base declaration.
4243 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
4244 // their component list but the same base declaration 'S'.
4245 using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
4246 using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
4249 // Return the total number of elements in a list of component lists.
4251 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
4253 // Return the total number of elements in a list of declarations. All
4254 // declarations are expected to be canonical.
4256 getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
4259 /// This structure contains all sizes needed for by an
4260 /// OMPMappableExprListClause.
4261 struct OMPMappableExprListSizeTy {
4262 /// Number of expressions listed.
4264 /// Number of unique base declarations.
4265 unsigned NumUniqueDeclarations;
4266 /// Number of component lists.
4267 unsigned NumComponentLists;
4268 /// Total number of expression components.
4269 unsigned NumComponents;
4270 OMPMappableExprListSizeTy() = default;
4271 OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations,
4272 unsigned NumComponentLists, unsigned NumComponents)
4273 : NumVars(NumVars), NumUniqueDeclarations(NumUniqueDeclarations),
4274 NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
4277 /// This represents clauses with a list of expressions that are mappable.
4278 /// Examples of these clauses are 'map' in
4279 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
4280 /// in '#pragma omp target update...' directives.
4282 class OMPMappableExprListClause : public OMPVarListClause<T>,
4283 public OMPClauseMappableExprCommon {
4284 friend class OMPClauseReader;
4286 /// Number of unique declarations in this clause.
4287 unsigned NumUniqueDeclarations;
4289 /// Number of component lists in this clause.
4290 unsigned NumComponentLists;
4292 /// Total number of components in this clause.
4293 unsigned NumComponents;
4295 /// C++ nested name specifier for the associated user-defined mapper.
4296 NestedNameSpecifierLoc MapperQualifierLoc;
4298 /// The associated user-defined mapper identifier information.
4299 DeclarationNameInfo MapperIdInfo;
4302 /// Build a clause for \a NumUniqueDeclarations declarations, \a
4303 /// NumComponentLists total component lists, and \a NumComponents total
4306 /// \param K Kind of the clause.
4307 /// \param Locs Locations needed to build a mappable clause. It includes 1)
4308 /// StartLoc: starting location of the clause (the clause keyword); 2)
4309 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4310 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4311 /// NumVars: number of expressions listed in this clause; 2)
4312 /// NumUniqueDeclarations: number of unique base declarations in this clause;
4313 /// 3) NumComponentLists: number of component lists in this clause; and 4)
4314 /// NumComponents: total number of expression components in the clause.
4315 /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
4316 /// user-defined mapper.
4317 /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
4318 OMPMappableExprListClause(
4319 OpenMPClauseKind K, const OMPVarListLocTy &Locs,
4320 const OMPMappableExprListSizeTy &Sizes,
4321 NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
4322 DeclarationNameInfo *MapperIdInfoPtr = nullptr)
4323 : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
4325 NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
4326 NumComponentLists(Sizes.NumComponentLists),
4327 NumComponents(Sizes.NumComponents) {
4328 if (MapperQualifierLocPtr)
4329 MapperQualifierLoc = *MapperQualifierLocPtr;
4330 if (MapperIdInfoPtr)
4331 MapperIdInfo = *MapperIdInfoPtr;
4334 /// Get the unique declarations that are in the trailing objects of the
4336 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
4337 return MutableArrayRef<ValueDecl *>(
4338 static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
4339 NumUniqueDeclarations);
4342 /// Get the unique declarations that are in the trailing objects of the
4344 ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
4345 return ArrayRef<ValueDecl *>(
4346 static_cast<const T *>(this)
4347 ->template getTrailingObjects<ValueDecl *>(),
4348 NumUniqueDeclarations);
4351 /// Set the unique declarations that are in the trailing objects of the
4353 void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
4354 assert(UDs.size() == NumUniqueDeclarations &&
4355 "Unexpected amount of unique declarations.");
4356 std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
4359 /// Get the number of lists per declaration that are in the trailing
4360 /// objects of the class.
4361 MutableArrayRef<unsigned> getDeclNumListsRef() {
4362 return MutableArrayRef<unsigned>(
4363 static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
4364 NumUniqueDeclarations);
4367 /// Get the number of lists per declaration that are in the trailing
4368 /// objects of the class.
4369 ArrayRef<unsigned> getDeclNumListsRef() const {
4370 return ArrayRef<unsigned>(
4371 static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
4372 NumUniqueDeclarations);
4375 /// Set the number of lists per declaration that are in the trailing
4376 /// objects of the class.
4377 void setDeclNumLists(ArrayRef<unsigned> DNLs) {
4378 assert(DNLs.size() == NumUniqueDeclarations &&
4379 "Unexpected amount of list numbers.");
4380 std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
4383 /// Get the cumulative component lists sizes that are in the trailing
4384 /// objects of the class. They are appended after the number of lists.
4385 MutableArrayRef<unsigned> getComponentListSizesRef() {
4386 return MutableArrayRef<unsigned>(
4387 static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
4388 NumUniqueDeclarations,
4392 /// Get the cumulative component lists sizes that are in the trailing
4393 /// objects of the class. They are appended after the number of lists.
4394 ArrayRef<unsigned> getComponentListSizesRef() const {
4395 return ArrayRef<unsigned>(
4396 static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
4397 NumUniqueDeclarations,
4401 /// Set the cumulative component lists sizes that are in the trailing
4402 /// objects of the class.
4403 void setComponentListSizes(ArrayRef<unsigned> CLSs) {
4404 assert(CLSs.size() == NumComponentLists &&
4405 "Unexpected amount of component lists.");
4406 std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
4409 /// Get the components that are in the trailing objects of the class.
4410 MutableArrayRef<MappableComponent> getComponentsRef() {
4411 return MutableArrayRef<MappableComponent>(
4412 static_cast<T *>(this)
4413 ->template getTrailingObjects<MappableComponent>(),
4417 /// Get the components that are in the trailing objects of the class.
4418 ArrayRef<MappableComponent> getComponentsRef() const {
4419 return ArrayRef<MappableComponent>(
4420 static_cast<const T *>(this)
4421 ->template getTrailingObjects<MappableComponent>(),
4425 /// Set the components that are in the trailing objects of the class.
4426 /// This requires the list sizes so that it can also fill the original
4427 /// expressions, which are the first component of each list.
4428 void setComponents(ArrayRef<MappableComponent> Components,
4429 ArrayRef<unsigned> CLSs) {
4430 assert(Components.size() == NumComponents &&
4431 "Unexpected amount of component lists.");
4432 assert(CLSs.size() == NumComponentLists &&
4433 "Unexpected amount of list sizes.");
4434 std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
4437 /// Fill the clause information from the list of declarations and
4438 /// associated component lists.
4439 void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
4440 MappableExprComponentListsRef ComponentLists) {
4441 // Perform some checks to make sure the data sizes are consistent with the
4442 // information available when the clause was created.
4443 assert(getUniqueDeclarationsTotalNumber(Declarations) ==
4444 NumUniqueDeclarations &&
4445 "Unexpected number of mappable expression info entries!");
4446 assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
4447 "Unexpected total number of components!");
4448 assert(Declarations.size() == ComponentLists.size() &&
4449 "Declaration and component lists size is not consistent!");
4450 assert(Declarations.size() == NumComponentLists &&
4451 "Unexpected declaration and component lists size!");
4453 // Organize the components by declaration and retrieve the original
4454 // expression. Original expressions are always the first component of the
4455 // mappable component list.
4456 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
4459 auto CI = ComponentLists.begin();
4460 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
4462 assert(!CI->empty() && "Invalid component list!");
4463 ComponentListMap[*DI].push_back(*CI);
4467 // Iterators of the target storage.
4468 auto UniqueDeclarations = getUniqueDeclsRef();
4469 auto UDI = UniqueDeclarations.begin();
4471 auto DeclNumLists = getDeclNumListsRef();
4472 auto DNLI = DeclNumLists.begin();
4474 auto ComponentListSizes = getComponentListSizesRef();
4475 auto CLSI = ComponentListSizes.begin();
4477 auto Components = getComponentsRef();
4478 auto CI = Components.begin();
4480 // Variable to compute the accumulation of the number of components.
4481 unsigned PrevSize = 0u;
4483 // Scan all the declarations and associated component lists.
4484 for (auto &M : ComponentListMap) {
4487 // The component lists.
4490 // Initialize the entry.
4497 // Obtain the cumulative sizes and concatenate all the components in the
4498 // reserved storage.
4500 // Accumulate with the previous size.
4501 PrevSize += C.size();
4507 // Append components after the current components iterator.
4508 CI = std::copy(C.begin(), C.end(), CI);
4513 /// Set the nested name specifier of associated user-defined mapper.
4514 void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) {
4515 MapperQualifierLoc = NNSL;
4518 /// Set the name of associated user-defined mapper.
4519 void setMapperIdInfo(DeclarationNameInfo MapperId) {
4520 MapperIdInfo = MapperId;
4523 /// Get the user-defined mapper references that are in the trailing objects of
4525 MutableArrayRef<Expr *> getUDMapperRefs() {
4526 return llvm::makeMutableArrayRef<Expr *>(
4527 static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
4528 OMPVarListClause<T>::varlist_size(),
4529 OMPVarListClause<T>::varlist_size());
4532 /// Get the user-defined mappers references that are in the trailing objects
4534 ArrayRef<Expr *> getUDMapperRefs() const {
4535 return llvm::makeArrayRef<Expr *>(
4536 static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
4537 OMPVarListClause<T>::varlist_size(),
4538 OMPVarListClause<T>::varlist_size());
4541 /// Set the user-defined mappers that are in the trailing objects of the
4543 void setUDMapperRefs(ArrayRef<Expr *> DMDs) {
4544 assert(DMDs.size() == OMPVarListClause<T>::varlist_size() &&
4545 "Unexpected number of user-defined mappers.");
4546 std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin());
4550 /// Return the number of unique base declarations in this clause.
4551 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
4553 /// Return the number of lists derived from the clause expressions.
4554 unsigned getTotalComponentListNum() const { return NumComponentLists; }
4556 /// Return the total number of components in all lists derived from the
4558 unsigned getTotalComponentsNum() const { return NumComponents; }
4560 /// Gets the nested name specifier for associated user-defined mapper.
4561 NestedNameSpecifierLoc getMapperQualifierLoc() const {
4562 return MapperQualifierLoc;
4565 /// Gets the name info for associated user-defined mapper.
4566 const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; }
4568 /// Iterator that browse the components by lists. It also allows
4569 /// browsing components of a single declaration.
4570 class const_component_lists_iterator
4571 : public llvm::iterator_adaptor_base<
4572 const_component_lists_iterator,
4573 MappableExprComponentListRef::const_iterator,
4574 std::forward_iterator_tag, MappableComponent, ptrdiff_t,
4575 MappableComponent, MappableComponent> {
4576 // The declaration the iterator currently refers to.
4577 ArrayRef<ValueDecl *>::iterator DeclCur;
4579 // The list number associated with the current declaration.
4580 ArrayRef<unsigned>::iterator NumListsCur;
4582 // Remaining lists for the current declaration.
4583 unsigned RemainingLists = 0;
4585 // The cumulative size of the previous list, or zero if there is no previous
4587 unsigned PrevListSize = 0;
4589 // The cumulative sizes of the current list - it will delimit the remaining
4590 // range of interest.
4591 ArrayRef<unsigned>::const_iterator ListSizeCur;
4592 ArrayRef<unsigned>::const_iterator ListSizeEnd;
4594 // Iterator to the end of the components storage.
4595 MappableExprComponentListRef::const_iterator End;
4598 /// Construct an iterator that scans all lists.
4599 explicit const_component_lists_iterator(
4600 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
4601 ArrayRef<unsigned> CumulativeListSizes,
4602 MappableExprComponentListRef Components)
4603 : const_component_lists_iterator::iterator_adaptor_base(
4604 Components.begin()),
4605 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
4606 ListSizeCur(CumulativeListSizes.begin()),
4607 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
4608 assert(UniqueDecls.size() == DeclsListNum.size() &&
4609 "Inconsistent number of declarations and list sizes!");
4610 if (!DeclsListNum.empty())
4611 RemainingLists = *NumListsCur;
4614 /// Construct an iterator that scan lists for a given declaration \a
4616 explicit const_component_lists_iterator(
4617 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
4618 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
4619 MappableExprComponentListRef Components)
4620 : const_component_lists_iterator(UniqueDecls, DeclsListNum,
4621 CumulativeListSizes, Components) {
4622 // Look for the desired declaration. While we are looking for it, we
4623 // update the state so that we know the component where a given list
4625 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
4626 if (*DeclCur == Declaration)
4629 assert(*NumListsCur > 0 && "No lists associated with declaration??");
4631 // Skip the lists associated with the current declaration, but save the
4632 // last list size that was skipped.
4633 std::advance(ListSizeCur, *NumListsCur - 1);
4634 PrevListSize = *ListSizeCur;
4638 // If we didn't find any declaration, advance the iterator to after the
4639 // last component and set remaining lists to zero.
4640 if (ListSizeCur == CumulativeListSizes.end()) {
4642 RemainingLists = 0u;
4646 // Set the remaining lists with the total number of lists of the current
4648 RemainingLists = *NumListsCur;
4650 // Adjust the list size end iterator to the end of the relevant range.
4651 ListSizeEnd = ListSizeCur;
4652 std::advance(ListSizeEnd, RemainingLists);
4654 // Given that the list sizes are cumulative, the index of the component
4655 // that start the list is the size of the previous list.
4656 std::advance(this->I, PrevListSize);
4659 // Return the array with the current list. The sizes are cumulative, so the
4660 // array size is the difference between the current size and previous one.
4661 std::pair<const ValueDecl *, MappableExprComponentListRef>
4663 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
4664 return std::make_pair(
4666 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize));
4668 std::pair<const ValueDecl *, MappableExprComponentListRef>
4669 operator->() const {
4673 // Skip the components of the current list.
4674 const_component_lists_iterator &operator++() {
4675 assert(ListSizeCur != ListSizeEnd && RemainingLists &&
4676 "Invalid iterator!");
4678 // If we don't have more lists just skip all the components. Otherwise,
4679 // advance the iterator by the number of components in the current list.
4680 if (std::next(ListSizeCur) == ListSizeEnd) {
4684 std::advance(this->I, *ListSizeCur - PrevListSize);
4685 PrevListSize = *ListSizeCur;
4687 // We are done with a declaration, move to the next one.
4688 if (!(--RemainingLists)) {
4691 RemainingLists = *NumListsCur;
4692 assert(RemainingLists && "No lists in the following declaration??");
4701 using const_component_lists_range =
4702 llvm::iterator_range<const_component_lists_iterator>;
4704 /// Iterators for all component lists.
4705 const_component_lists_iterator component_lists_begin() const {
4706 return const_component_lists_iterator(
4707 getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
4708 getComponentsRef());
4710 const_component_lists_iterator component_lists_end() const {
4711 return const_component_lists_iterator(
4712 ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
4713 MappableExprComponentListRef(getComponentsRef().end(),
4714 getComponentsRef().end()));
4716 const_component_lists_range component_lists() const {
4717 return {component_lists_begin(), component_lists_end()};
4720 /// Iterators for component lists associated with the provided
4722 const_component_lists_iterator
4723 decl_component_lists_begin(const ValueDecl *VD) const {
4724 return const_component_lists_iterator(
4725 VD, getUniqueDeclsRef(), getDeclNumListsRef(),
4726 getComponentListSizesRef(), getComponentsRef());
4728 const_component_lists_iterator decl_component_lists_end() const {
4729 return component_lists_end();
4731 const_component_lists_range decl_component_lists(const ValueDecl *VD) const {
4732 return {decl_component_lists_begin(VD), decl_component_lists_end()};
4735 /// Iterators to access all the declarations, number of lists, list sizes, and
4737 using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
4738 using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
4740 const_all_decls_range all_decls() const {
4741 auto A = getUniqueDeclsRef();
4742 return const_all_decls_range(A.begin(), A.end());
4745 using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
4746 using const_all_num_lists_range =
4747 llvm::iterator_range<const_all_num_lists_iterator>;
4749 const_all_num_lists_range all_num_lists() const {
4750 auto A = getDeclNumListsRef();
4751 return const_all_num_lists_range(A.begin(), A.end());
4754 using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
4755 using const_all_lists_sizes_range =
4756 llvm::iterator_range<const_all_lists_sizes_iterator>;
4758 const_all_lists_sizes_range all_lists_sizes() const {
4759 auto A = getComponentListSizesRef();
4760 return const_all_lists_sizes_range(A.begin(), A.end());
4763 using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
4764 using const_all_components_range =
4765 llvm::iterator_range<const_all_components_iterator>;
4767 const_all_components_range all_components() const {
4768 auto A = getComponentsRef();
4769 return const_all_components_range(A.begin(), A.end());
4772 using mapperlist_iterator = MutableArrayRef<Expr *>::iterator;
4773 using mapperlist_const_iterator = ArrayRef<const Expr *>::iterator;
4774 using mapperlist_range = llvm::iterator_range<mapperlist_iterator>;
4775 using mapperlist_const_range =
4776 llvm::iterator_range<mapperlist_const_iterator>;
4778 mapperlist_iterator mapperlist_begin() { return getUDMapperRefs().begin(); }
4779 mapperlist_iterator mapperlist_end() { return getUDMapperRefs().end(); }
4780 mapperlist_const_iterator mapperlist_begin() const {
4781 return getUDMapperRefs().begin();
4783 mapperlist_const_iterator mapperlist_end() const {
4784 return getUDMapperRefs().end();
4786 mapperlist_range mapperlists() {
4787 return mapperlist_range(mapperlist_begin(), mapperlist_end());
4789 mapperlist_const_range mapperlists() const {
4790 return mapperlist_const_range(mapperlist_begin(), mapperlist_end());
4794 /// This represents clause 'map' in the '#pragma omp ...'
4798 /// #pragma omp target map(a,b)
4800 /// In this example directive '#pragma omp target' has clause 'map'
4801 /// with the variables 'a' and 'b'.
4802 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
4803 private llvm::TrailingObjects<
4804 OMPMapClause, Expr *, ValueDecl *, unsigned,
4805 OMPClauseMappableExprCommon::MappableComponent> {
4806 friend class OMPClauseReader;
4807 friend OMPMappableExprListClause;
4808 friend OMPVarListClause;
4809 friend TrailingObjects;
4811 /// Define the sizes of each trailing object array except the last one. This
4812 /// is required for TrailingObjects to work properly.
4813 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4814 // There are varlist_size() of expressions, and varlist_size() of
4815 // user-defined mappers.
4816 return 2 * varlist_size();
4818 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4819 return getUniqueDeclarationsNum();
4821 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4822 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4826 /// Number of allowed map-type-modifiers.
4827 static constexpr unsigned NumberOfModifiers =
4828 OMPC_MAP_MODIFIER_last - OMPC_MAP_MODIFIER_unknown - 1;
4831 /// Map-type-modifiers for the 'map' clause.
4832 OpenMPMapModifierKind MapTypeModifiers[NumberOfModifiers] = {
4833 OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
4834 OMPC_MAP_MODIFIER_unknown};
4836 /// Location of map-type-modifiers for the 'map' clause.
4837 SourceLocation MapTypeModifiersLoc[NumberOfModifiers];
4839 /// Map type for the 'map' clause.
4840 OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
4842 /// Is this an implicit map type or not.
4843 bool MapTypeIsImplicit = false;
4845 /// Location of the map type.
4846 SourceLocation MapLoc;
4849 SourceLocation ColonLoc;
4851 /// Build a clause for \a NumVars listed expressions, \a
4852 /// NumUniqueDeclarations declarations, \a NumComponentLists total component
4853 /// lists, and \a NumComponents total expression components.
4855 /// \param MapModifiers Map-type-modifiers.
4856 /// \param MapModifiersLoc Locations of map-type-modifiers.
4857 /// \param MapperQualifierLoc C++ nested name specifier for the associated
4858 /// user-defined mapper.
4859 /// \param MapperIdInfo The identifier of associated user-defined mapper.
4860 /// \param MapType Map type.
4861 /// \param MapTypeIsImplicit Map type is inferred implicitly.
4862 /// \param MapLoc Location of the map type.
4863 /// \param Locs Locations needed to build a mappable clause. It includes 1)
4864 /// StartLoc: starting location of the clause (the clause keyword); 2)
4865 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4866 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4867 /// NumVars: number of expressions listed in this clause; 2)
4868 /// NumUniqueDeclarations: number of unique base declarations in this clause;
4869 /// 3) NumComponentLists: number of component lists in this clause; and 4)
4870 /// NumComponents: total number of expression components in the clause.
4871 explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,
4872 ArrayRef<SourceLocation> MapModifiersLoc,
4873 NestedNameSpecifierLoc MapperQualifierLoc,
4874 DeclarationNameInfo MapperIdInfo,
4875 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
4876 SourceLocation MapLoc, const OMPVarListLocTy &Locs,
4877 const OMPMappableExprListSizeTy &Sizes)
4878 : OMPMappableExprListClause(OMPC_map, Locs, Sizes, &MapperQualifierLoc,
4880 MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
4881 assert(llvm::array_lengthof(MapTypeModifiers) == MapModifiers.size() &&
4882 "Unexpected number of map type modifiers.");
4883 llvm::copy(MapModifiers, std::begin(MapTypeModifiers));
4885 assert(llvm::array_lengthof(MapTypeModifiersLoc) ==
4886 MapModifiersLoc.size() &&
4887 "Unexpected number of map type modifier locations.");
4888 llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
4891 /// Build an empty clause.
4893 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4894 /// NumVars: number of expressions listed in this clause; 2)
4895 /// NumUniqueDeclarations: number of unique base declarations in this clause;
4896 /// 3) NumComponentLists: number of component lists in this clause; and 4)
4897 /// NumComponents: total number of expression components in the clause.
4898 explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes)
4899 : OMPMappableExprListClause(OMPC_map, OMPVarListLocTy(), Sizes) {}
4901 /// Set map-type-modifier for the clause.
4903 /// \param I index for map-type-modifier.
4904 /// \param T map-type-modifier for the clause.
4905 void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
4906 assert(I < NumberOfModifiers &&
4907 "Unexpected index to store map type modifier, exceeds array size.");
4908 MapTypeModifiers[I] = T;
4911 /// Set location for the map-type-modifier.
4913 /// \param I index for map-type-modifier location.
4914 /// \param TLoc map-type-modifier location.
4915 void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
4916 assert(I < NumberOfModifiers &&
4917 "Index to store map type modifier location exceeds array size.");
4918 MapTypeModifiersLoc[I] = TLoc;
4921 /// Set type for the clause.
4923 /// \param T Type for the clause.
4924 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
4926 /// Set type location.
4928 /// \param TLoc Type location.
4929 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
4931 /// Set colon location.
4932 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4935 /// Creates clause with a list of variables \a VL.
4937 /// \param C AST context.
4938 /// \param Locs Locations needed to build a mappable clause. It includes 1)
4939 /// StartLoc: starting location of the clause (the clause keyword); 2)
4940 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4941 /// \param Vars The original expression used in the clause.
4942 /// \param Declarations Declarations used in the clause.
4943 /// \param ComponentLists Component lists used in the clause.
4944 /// \param UDMapperRefs References to user-defined mappers associated with
4945 /// expressions used in the clause.
4946 /// \param MapModifiers Map-type-modifiers.
4947 /// \param MapModifiersLoc Location of map-type-modifiers.
4948 /// \param UDMQualifierLoc C++ nested name specifier for the associated
4949 /// user-defined mapper.
4950 /// \param MapperId The identifier of associated user-defined mapper.
4951 /// \param Type Map type.
4952 /// \param TypeIsImplicit Map type is inferred implicitly.
4953 /// \param TypeLoc Location of the map type.
4954 static OMPMapClause *
4955 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
4956 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
4957 MappableExprComponentListsRef ComponentLists,
4958 ArrayRef<Expr *> UDMapperRefs,
4959 ArrayRef<OpenMPMapModifierKind> MapModifiers,
4960 ArrayRef<SourceLocation> MapModifiersLoc,
4961 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
4962 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc);
4964 /// Creates an empty clause with the place for \a NumVars original
4965 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
4966 /// lists, and \a NumComponents expression components.
4968 /// \param C AST context.
4969 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4970 /// NumVars: number of expressions listed in this clause; 2)
4971 /// NumUniqueDeclarations: number of unique base declarations in this clause;
4972 /// 3) NumComponentLists: number of component lists in this clause; and 4)
4973 /// NumComponents: total number of expression components in the clause.
4974 static OMPMapClause *CreateEmpty(const ASTContext &C,
4975 const OMPMappableExprListSizeTy &Sizes);
4977 /// Fetches mapping kind for the clause.
4978 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
4980 /// Is this an implicit map type?
4981 /// We have to capture 'IsMapTypeImplicit' from the parser for more
4982 /// informative error messages. It helps distinguish map(r) from
4983 /// map(tofrom: r), which is important to print more helpful error
4984 /// messages for some target directives.
4985 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
4987 /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
4989 /// \param Cnt index for map-type-modifier.
4990 OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
4991 assert(Cnt < NumberOfModifiers &&
4992 "Requested modifier exceeds the total number of modifiers.");
4993 return MapTypeModifiers[Cnt];
4996 /// Fetches the map-type-modifier location at 'Cnt' index of array of
4997 /// modifiers' locations.
4999 /// \param Cnt index for map-type-modifier location.
5000 SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
5001 assert(Cnt < NumberOfModifiers &&
5002 "Requested modifier location exceeds total number of modifiers.");
5003 return MapTypeModifiersLoc[Cnt];
5006 /// Fetches ArrayRef of map-type-modifiers.
5007 ArrayRef<OpenMPMapModifierKind> getMapTypeModifiers() const LLVM_READONLY {
5008 return llvm::makeArrayRef(MapTypeModifiers);
5011 /// Fetches ArrayRef of location of map-type-modifiers.
5012 ArrayRef<SourceLocation> getMapTypeModifiersLoc() const LLVM_READONLY {
5013 return llvm::makeArrayRef(MapTypeModifiersLoc);
5016 /// Fetches location of clause mapping kind.
5017 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
5019 /// Get colon location.
5020 SourceLocation getColonLoc() const { return ColonLoc; }
5022 child_range children() {
5024 reinterpret_cast<Stmt **>(varlist_begin()),
5025 reinterpret_cast<Stmt **>(varlist_end()));
5028 const_child_range children() const {
5029 auto Children = const_cast<OMPMapClause *>(this)->children();
5030 return const_child_range(Children.begin(), Children.end());
5033 child_range used_children() {
5034 if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_tofrom)
5035 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5036 reinterpret_cast<Stmt **>(varlist_end()));
5037 return child_range(child_iterator(), child_iterator());
5039 const_child_range used_children() const {
5040 auto Children = const_cast<OMPMapClause *>(this)->used_children();
5041 return const_child_range(Children.begin(), Children.end());
5045 static bool classof(const OMPClause *T) {
5046 return T->getClauseKind() == OMPC_map;
5050 /// This represents 'num_teams' clause in the '#pragma omp ...'
5054 /// #pragma omp teams num_teams(n)
5056 /// In this example directive '#pragma omp teams' has clause 'num_teams'
5057 /// with single expression 'n'.
5058 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
5059 friend class OMPClauseReader;
5061 /// Location of '('.
5062 SourceLocation LParenLoc;
5064 /// NumTeams number.
5065 Stmt *NumTeams = nullptr;
5067 /// Set the NumTeams number.
5069 /// \param E NumTeams number.
5070 void setNumTeams(Expr *E) { NumTeams = E; }
5073 /// Build 'num_teams' clause.
5075 /// \param E Expression associated with this clause.
5076 /// \param HelperE Helper Expression associated with this clause.
5077 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5078 /// clause must be captured.
5079 /// \param StartLoc Starting location of the clause.
5080 /// \param LParenLoc Location of '('.
5081 /// \param EndLoc Ending location of the clause.
5082 OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
5083 SourceLocation StartLoc, SourceLocation LParenLoc,
5084 SourceLocation EndLoc)
5085 : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this),
5086 LParenLoc(LParenLoc), NumTeams(E) {
5087 setPreInitStmt(HelperE, CaptureRegion);
5090 /// Build an empty clause.
5092 : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
5093 OMPClauseWithPreInit(this) {}
5095 /// Sets the location of '('.
5096 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5098 /// Returns the location of '('.
5099 SourceLocation getLParenLoc() const { return LParenLoc; }
5101 /// Return NumTeams number.
5102 Expr *getNumTeams() { return cast<Expr>(NumTeams); }
5104 /// Return NumTeams number.
5105 Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
5107 child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
5109 const_child_range children() const {
5110 return const_child_range(&NumTeams, &NumTeams + 1);
5113 child_range used_children() {
5114 return child_range(child_iterator(), child_iterator());
5116 const_child_range used_children() const {
5117 return const_child_range(const_child_iterator(), const_child_iterator());
5120 static bool classof(const OMPClause *T) {
5121 return T->getClauseKind() == OMPC_num_teams;
5125 /// This represents 'thread_limit' clause in the '#pragma omp ...'
5129 /// #pragma omp teams thread_limit(n)
5131 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
5132 /// with single expression 'n'.
5133 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
5134 friend class OMPClauseReader;
5136 /// Location of '('.
5137 SourceLocation LParenLoc;
5139 /// ThreadLimit number.
5140 Stmt *ThreadLimit = nullptr;
5142 /// Set the ThreadLimit number.
5144 /// \param E ThreadLimit number.
5145 void setThreadLimit(Expr *E) { ThreadLimit = E; }
5148 /// Build 'thread_limit' clause.
5150 /// \param E Expression associated with this clause.
5151 /// \param HelperE Helper Expression associated with this clause.
5152 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5153 /// clause must be captured.
5154 /// \param StartLoc Starting location of the clause.
5155 /// \param LParenLoc Location of '('.
5156 /// \param EndLoc Ending location of the clause.
5157 OMPThreadLimitClause(Expr *E, Stmt *HelperE,
5158 OpenMPDirectiveKind CaptureRegion,
5159 SourceLocation StartLoc, SourceLocation LParenLoc,
5160 SourceLocation EndLoc)
5161 : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
5162 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
5163 setPreInitStmt(HelperE, CaptureRegion);
5166 /// Build an empty clause.
5167 OMPThreadLimitClause()
5168 : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
5169 OMPClauseWithPreInit(this) {}
5171 /// Sets the location of '('.
5172 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5174 /// Returns the location of '('.
5175 SourceLocation getLParenLoc() const { return LParenLoc; }
5177 /// Return ThreadLimit number.
5178 Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
5180 /// Return ThreadLimit number.
5181 Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
5183 child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
5185 const_child_range children() const {
5186 return const_child_range(&ThreadLimit, &ThreadLimit + 1);
5189 child_range used_children() {
5190 return child_range(child_iterator(), child_iterator());
5192 const_child_range used_children() const {
5193 return const_child_range(const_child_iterator(), const_child_iterator());
5196 static bool classof(const OMPClause *T) {
5197 return T->getClauseKind() == OMPC_thread_limit;
5201 /// This represents 'priority' clause in the '#pragma omp ...'
5205 /// #pragma omp task priority(n)
5207 /// In this example directive '#pragma omp teams' has clause 'priority' with
5208 /// single expression 'n'.
5209 class OMPPriorityClause : public OMPClause, public OMPClauseWithPreInit {
5210 friend class OMPClauseReader;
5212 /// Location of '('.
5213 SourceLocation LParenLoc;
5215 /// Priority number.
5216 Stmt *Priority = nullptr;
5218 /// Set the Priority number.
5220 /// \param E Priority number.
5221 void setPriority(Expr *E) { Priority = E; }
5224 /// Build 'priority' clause.
5226 /// \param Priority Expression associated with this clause.
5227 /// \param HelperPriority Helper priority for the construct.
5228 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5229 /// clause must be captured.
5230 /// \param StartLoc Starting location of the clause.
5231 /// \param LParenLoc Location of '('.
5232 /// \param EndLoc Ending location of the clause.
5233 OMPPriorityClause(Expr *Priority, Stmt *HelperPriority,
5234 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5235 SourceLocation LParenLoc, SourceLocation EndLoc)
5236 : OMPClause(OMPC_priority, StartLoc, EndLoc), OMPClauseWithPreInit(this),
5237 LParenLoc(LParenLoc), Priority(Priority) {
5238 setPreInitStmt(HelperPriority, CaptureRegion);
5241 /// Build an empty clause.
5243 : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()),
5244 OMPClauseWithPreInit(this) {}
5246 /// Sets the location of '('.
5247 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5249 /// Returns the location of '('.
5250 SourceLocation getLParenLoc() const { return LParenLoc; }
5252 /// Return Priority number.
5253 Expr *getPriority() { return cast<Expr>(Priority); }
5255 /// Return Priority number.
5256 Expr *getPriority() const { return cast<Expr>(Priority); }
5258 child_range children() { return child_range(&Priority, &Priority + 1); }
5260 const_child_range children() const {
5261 return const_child_range(&Priority, &Priority + 1);
5264 child_range used_children();
5265 const_child_range used_children() const {
5266 auto Children = const_cast<OMPPriorityClause *>(this)->used_children();
5267 return const_child_range(Children.begin(), Children.end());
5270 static bool classof(const OMPClause *T) {
5271 return T->getClauseKind() == OMPC_priority;
5275 /// This represents 'grainsize' clause in the '#pragma omp ...'
5279 /// #pragma omp taskloop grainsize(4)
5281 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
5282 /// with single expression '4'.
5283 class OMPGrainsizeClause : public OMPClause, public OMPClauseWithPreInit {
5284 friend class OMPClauseReader;
5286 /// Location of '('.
5287 SourceLocation LParenLoc;
5289 /// Safe iteration space distance.
5290 Stmt *Grainsize = nullptr;
5293 void setGrainsize(Expr *Size) { Grainsize = Size; }
5296 /// Build 'grainsize' clause.
5298 /// \param Size Expression associated with this clause.
5299 /// \param HelperSize Helper grainsize for the construct.
5300 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5301 /// clause must be captured.
5302 /// \param StartLoc Starting location of the clause.
5303 /// \param EndLoc Ending location of the clause.
5304 OMPGrainsizeClause(Expr *Size, Stmt *HelperSize,
5305 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5306 SourceLocation LParenLoc, SourceLocation EndLoc)
5307 : OMPClause(OMPC_grainsize, StartLoc, EndLoc), OMPClauseWithPreInit(this),
5308 LParenLoc(LParenLoc), Grainsize(Size) {
5309 setPreInitStmt(HelperSize, CaptureRegion);
5312 /// Build an empty clause.
5313 explicit OMPGrainsizeClause()
5314 : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()),
5315 OMPClauseWithPreInit(this) {}
5317 /// Sets the location of '('.
5318 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5320 /// Returns the location of '('.
5321 SourceLocation getLParenLoc() const { return LParenLoc; }
5323 /// Return safe iteration space distance.
5324 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
5326 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
5328 const_child_range children() const {
5329 return const_child_range(&Grainsize, &Grainsize + 1);
5332 child_range used_children();
5333 const_child_range used_children() const {
5334 auto Children = const_cast<OMPGrainsizeClause *>(this)->used_children();
5335 return const_child_range(Children.begin(), Children.end());
5338 static bool classof(const OMPClause *T) {
5339 return T->getClauseKind() == OMPC_grainsize;
5343 /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
5346 /// #pragma omp taskloop nogroup
5348 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
5349 class OMPNogroupClause : public OMPClause {
5351 /// Build 'nogroup' clause.
5353 /// \param StartLoc Starting location of the clause.
5354 /// \param EndLoc Ending location of the clause.
5355 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
5356 : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
5358 /// Build an empty clause.
5360 : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
5362 child_range children() {
5363 return child_range(child_iterator(), child_iterator());
5366 const_child_range children() const {
5367 return const_child_range(const_child_iterator(), const_child_iterator());
5370 child_range used_children() {
5371 return child_range(child_iterator(), child_iterator());
5373 const_child_range used_children() const {
5374 return const_child_range(const_child_iterator(), const_child_iterator());
5377 static bool classof(const OMPClause *T) {
5378 return T->getClauseKind() == OMPC_nogroup;
5382 /// This represents 'num_tasks' clause in the '#pragma omp ...'
5386 /// #pragma omp taskloop num_tasks(4)
5388 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
5389 /// with single expression '4'.
5390 class OMPNumTasksClause : public OMPClause, public OMPClauseWithPreInit {
5391 friend class OMPClauseReader;
5393 /// Location of '('.
5394 SourceLocation LParenLoc;
5396 /// Safe iteration space distance.
5397 Stmt *NumTasks = nullptr;
5400 void setNumTasks(Expr *Size) { NumTasks = Size; }
5403 /// Build 'num_tasks' clause.
5405 /// \param Size Expression associated with this clause.
5406 /// \param HelperSize Helper grainsize for the construct.
5407 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5408 /// clause must be captured.
5409 /// \param StartLoc Starting location of the clause.
5410 /// \param EndLoc Ending location of the clause.
5411 OMPNumTasksClause(Expr *Size, Stmt *HelperSize,
5412 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5413 SourceLocation LParenLoc, SourceLocation EndLoc)
5414 : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), OMPClauseWithPreInit(this),
5415 LParenLoc(LParenLoc), NumTasks(Size) {
5416 setPreInitStmt(HelperSize, CaptureRegion);
5419 /// Build an empty clause.
5420 explicit OMPNumTasksClause()
5421 : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()),
5422 OMPClauseWithPreInit(this) {}
5424 /// Sets the location of '('.
5425 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5427 /// Returns the location of '('.
5428 SourceLocation getLParenLoc() const { return LParenLoc; }
5430 /// Return safe iteration space distance.
5431 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
5433 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
5435 const_child_range children() const {
5436 return const_child_range(&NumTasks, &NumTasks + 1);
5439 child_range used_children();
5440 const_child_range used_children() const {
5441 auto Children = const_cast<OMPNumTasksClause *>(this)->used_children();
5442 return const_child_range(Children.begin(), Children.end());
5445 static bool classof(const OMPClause *T) {
5446 return T->getClauseKind() == OMPC_num_tasks;
5450 /// This represents 'hint' clause in the '#pragma omp ...' directive.
5453 /// #pragma omp critical (name) hint(6)
5455 /// In this example directive '#pragma omp critical' has name 'name' and clause
5456 /// 'hint' with argument '6'.
5457 class OMPHintClause : public OMPClause {
5458 friend class OMPClauseReader;
5460 /// Location of '('.
5461 SourceLocation LParenLoc;
5463 /// Hint expression of the 'hint' clause.
5464 Stmt *Hint = nullptr;
5466 /// Set hint expression.
5467 void setHint(Expr *H) { Hint = H; }
5470 /// Build 'hint' clause with expression \a Hint.
5472 /// \param Hint Hint expression.
5473 /// \param StartLoc Starting location of the clause.
5474 /// \param LParenLoc Location of '('.
5475 /// \param EndLoc Ending location of the clause.
5476 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
5477 SourceLocation EndLoc)
5478 : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
5481 /// Build an empty clause.
5482 OMPHintClause() : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()) {}
5484 /// Sets the location of '('.
5485 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5487 /// Returns the location of '('.
5488 SourceLocation getLParenLoc() const { return LParenLoc; }
5490 /// Returns number of threads.
5491 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
5493 child_range children() { return child_range(&Hint, &Hint + 1); }
5495 const_child_range children() const {
5496 return const_child_range(&Hint, &Hint + 1);
5499 child_range used_children() {
5500 return child_range(child_iterator(), child_iterator());
5502 const_child_range used_children() const {
5503 return const_child_range(const_child_iterator(), const_child_iterator());
5506 static bool classof(const OMPClause *T) {
5507 return T->getClauseKind() == OMPC_hint;
5511 /// This represents 'dist_schedule' clause in the '#pragma omp ...'
5515 /// #pragma omp distribute dist_schedule(static, 3)
5517 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
5518 /// clause with arguments 'static' and '3'.
5519 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
5520 friend class OMPClauseReader;
5522 /// Location of '('.
5523 SourceLocation LParenLoc;
5525 /// A kind of the 'schedule' clause.
5526 OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
5528 /// Start location of the schedule kind in source code.
5529 SourceLocation KindLoc;
5531 /// Location of ',' (if any).
5532 SourceLocation CommaLoc;
5535 Expr *ChunkSize = nullptr;
5537 /// Set schedule kind.
5539 /// \param K Schedule kind.
5540 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
5542 /// Sets the location of '('.
5544 /// \param Loc Location of '('.
5545 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5547 /// Set schedule kind start location.
5549 /// \param KLoc Schedule kind location.
5550 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
5552 /// Set location of ','.
5554 /// \param Loc Location of ','.
5555 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
5559 /// \param E Chunk size.
5560 void setChunkSize(Expr *E) { ChunkSize = E; }
5563 /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
5564 /// size expression \a ChunkSize.
5566 /// \param StartLoc Starting location of the clause.
5567 /// \param LParenLoc Location of '('.
5568 /// \param KLoc Starting location of the argument.
5569 /// \param CommaLoc Location of ','.
5570 /// \param EndLoc Ending location of the clause.
5571 /// \param Kind DistSchedule kind.
5572 /// \param ChunkSize Chunk size.
5573 /// \param HelperChunkSize Helper chunk size for combined directives.
5574 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5575 SourceLocation KLoc, SourceLocation CommaLoc,
5576 SourceLocation EndLoc,
5577 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
5578 Stmt *HelperChunkSize)
5579 : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc),
5580 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
5581 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
5582 setPreInitStmt(HelperChunkSize);
5585 /// Build an empty clause.
5586 explicit OMPDistScheduleClause()
5587 : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()),
5588 OMPClauseWithPreInit(this) {}
5590 /// Get kind of the clause.
5591 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
5593 /// Get location of '('.
5594 SourceLocation getLParenLoc() { return LParenLoc; }
5596 /// Get kind location.
5597 SourceLocation getDistScheduleKindLoc() { return KindLoc; }
5599 /// Get location of ','.
5600 SourceLocation getCommaLoc() { return CommaLoc; }
5603 Expr *getChunkSize() { return ChunkSize; }
5606 const Expr *getChunkSize() const { return ChunkSize; }
5608 child_range children() {
5609 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
5610 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
5613 const_child_range children() const {
5614 auto Children = const_cast<OMPDistScheduleClause *>(this)->children();
5615 return const_child_range(Children.begin(), Children.end());
5618 child_range used_children() {
5619 return child_range(child_iterator(), child_iterator());
5621 const_child_range used_children() const {
5622 return const_child_range(const_child_iterator(), const_child_iterator());
5625 static bool classof(const OMPClause *T) {
5626 return T->getClauseKind() == OMPC_dist_schedule;
5630 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
5633 /// #pragma omp target defaultmap(tofrom: scalar)
5635 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
5636 /// 'scalar' with modifier 'tofrom'.
5637 class OMPDefaultmapClause : public OMPClause {
5638 friend class OMPClauseReader;
5640 /// Location of '('.
5641 SourceLocation LParenLoc;
5643 /// Modifiers for 'defaultmap' clause.
5644 OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
5646 /// Locations of modifiers.
5647 SourceLocation ModifierLoc;
5649 /// A kind of the 'defaultmap' clause.
5650 OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
5652 /// Start location of the defaultmap kind in source code.
5653 SourceLocation KindLoc;
5655 /// Set defaultmap kind.
5657 /// \param K Defaultmap kind.
5658 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
5660 /// Set the defaultmap modifier.
5662 /// \param M Defaultmap modifier.
5663 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
5667 /// Set location of the defaultmap modifier.
5668 void setDefaultmapModifierLoc(SourceLocation Loc) {
5672 /// Sets the location of '('.
5674 /// \param Loc Location of '('.
5675 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5677 /// Set defaultmap kind start location.
5679 /// \param KLoc Defaultmap kind location.
5680 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
5683 /// Build 'defaultmap' clause with defaultmap kind \a Kind
5685 /// \param StartLoc Starting location of the clause.
5686 /// \param LParenLoc Location of '('.
5687 /// \param KLoc Starting location of the argument.
5688 /// \param EndLoc Ending location of the clause.
5689 /// \param Kind Defaultmap kind.
5690 /// \param M The modifier applied to 'defaultmap' clause.
5691 /// \param MLoc Location of the modifier
5692 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
5693 SourceLocation MLoc, SourceLocation KLoc,
5694 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
5695 OpenMPDefaultmapClauseModifier M)
5696 : OMPClause(OMPC_defaultmap, StartLoc, EndLoc), LParenLoc(LParenLoc),
5697 Modifier(M), ModifierLoc(MLoc), Kind(Kind), KindLoc(KLoc) {}
5699 /// Build an empty clause.
5700 explicit OMPDefaultmapClause()
5701 : OMPClause(OMPC_defaultmap, SourceLocation(), SourceLocation()) {}
5703 /// Get kind of the clause.
5704 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
5706 /// Get the modifier of the clause.
5707 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
5711 /// Get location of '('.
5712 SourceLocation getLParenLoc() { return LParenLoc; }
5714 /// Get kind location.
5715 SourceLocation getDefaultmapKindLoc() { return KindLoc; }
5717 /// Get the modifier location.
5718 SourceLocation getDefaultmapModifierLoc() const {
5722 child_range children() {
5723 return child_range(child_iterator(), child_iterator());
5726 const_child_range children() const {
5727 return const_child_range(const_child_iterator(), const_child_iterator());
5730 child_range used_children() {
5731 return child_range(child_iterator(), child_iterator());
5733 const_child_range used_children() const {
5734 return const_child_range(const_child_iterator(), const_child_iterator());
5737 static bool classof(const OMPClause *T) {
5738 return T->getClauseKind() == OMPC_defaultmap;
5742 /// This represents clause 'to' in the '#pragma omp ...'
5746 /// #pragma omp target update to(a,b)
5748 /// In this example directive '#pragma omp target update' has clause 'to'
5749 /// with the variables 'a' and 'b'.
5750 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
5751 private llvm::TrailingObjects<
5752 OMPToClause, Expr *, ValueDecl *, unsigned,
5753 OMPClauseMappableExprCommon::MappableComponent> {
5754 friend class OMPClauseReader;
5755 friend OMPMappableExprListClause;
5756 friend OMPVarListClause;
5757 friend TrailingObjects;
5759 /// Build clause with number of variables \a NumVars.
5761 /// \param MapperQualifierLoc C++ nested name specifier for the associated
5762 /// user-defined mapper.
5763 /// \param MapperIdInfo The identifier of associated user-defined mapper.
5764 /// \param Locs Locations needed to build a mappable clause. It includes 1)
5765 /// StartLoc: starting location of the clause (the clause keyword); 2)
5766 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5767 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5768 /// NumVars: number of expressions listed in this clause; 2)
5769 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5770 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5771 /// NumComponents: total number of expression components in the clause.
5772 explicit OMPToClause(NestedNameSpecifierLoc MapperQualifierLoc,
5773 DeclarationNameInfo MapperIdInfo,
5774 const OMPVarListLocTy &Locs,
5775 const OMPMappableExprListSizeTy &Sizes)
5776 : OMPMappableExprListClause(OMPC_to, Locs, Sizes, &MapperQualifierLoc,
5779 /// Build an empty clause.
5781 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5782 /// NumVars: number of expressions listed in this clause; 2)
5783 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5784 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5785 /// NumComponents: total number of expression components in the clause.
5786 explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes)
5787 : OMPMappableExprListClause(OMPC_to, OMPVarListLocTy(), Sizes) {}
5789 /// Define the sizes of each trailing object array except the last one. This
5790 /// is required for TrailingObjects to work properly.
5791 size_t numTrailingObjects(OverloadToken<Expr *>) const {
5792 // There are varlist_size() of expressions, and varlist_size() of
5793 // user-defined mappers.
5794 return 2 * varlist_size();
5796 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
5797 return getUniqueDeclarationsNum();
5799 size_t numTrailingObjects(OverloadToken<unsigned>) const {
5800 return getUniqueDeclarationsNum() + getTotalComponentListNum();
5804 /// Creates clause with a list of variables \a Vars.
5806 /// \param C AST context.
5807 /// \param Locs Locations needed to build a mappable clause. It includes 1)
5808 /// StartLoc: starting location of the clause (the clause keyword); 2)
5809 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5810 /// \param Vars The original expression used in the clause.
5811 /// \param Declarations Declarations used in the clause.
5812 /// \param ComponentLists Component lists used in the clause.
5813 /// \param UDMapperRefs References to user-defined mappers associated with
5814 /// expressions used in the clause.
5815 /// \param UDMQualifierLoc C++ nested name specifier for the associated
5816 /// user-defined mapper.
5817 /// \param MapperId The identifier of associated user-defined mapper.
5818 static OMPToClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
5819 ArrayRef<Expr *> Vars,
5820 ArrayRef<ValueDecl *> Declarations,
5821 MappableExprComponentListsRef ComponentLists,
5822 ArrayRef<Expr *> UDMapperRefs,
5823 NestedNameSpecifierLoc UDMQualifierLoc,
5824 DeclarationNameInfo MapperId);
5826 /// Creates an empty clause with the place for \a NumVars variables.
5828 /// \param C AST context.
5829 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5830 /// NumVars: number of expressions listed in this clause; 2)
5831 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5832 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5833 /// NumComponents: total number of expression components in the clause.
5834 static OMPToClause *CreateEmpty(const ASTContext &C,
5835 const OMPMappableExprListSizeTy &Sizes);
5837 child_range children() {
5838 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5839 reinterpret_cast<Stmt **>(varlist_end()));
5842 const_child_range children() const {
5843 auto Children = const_cast<OMPToClause *>(this)->children();
5844 return const_child_range(Children.begin(), Children.end());
5847 child_range used_children() {
5848 return child_range(child_iterator(), child_iterator());
5850 const_child_range used_children() const {
5851 return const_child_range(const_child_iterator(), const_child_iterator());
5854 static bool classof(const OMPClause *T) {
5855 return T->getClauseKind() == OMPC_to;
5859 /// This represents clause 'from' in the '#pragma omp ...'
5863 /// #pragma omp target update from(a,b)
5865 /// In this example directive '#pragma omp target update' has clause 'from'
5866 /// with the variables 'a' and 'b'.
5867 class OMPFromClause final
5868 : public OMPMappableExprListClause<OMPFromClause>,
5869 private llvm::TrailingObjects<
5870 OMPFromClause, Expr *, ValueDecl *, unsigned,
5871 OMPClauseMappableExprCommon::MappableComponent> {
5872 friend class OMPClauseReader;
5873 friend OMPMappableExprListClause;
5874 friend OMPVarListClause;
5875 friend TrailingObjects;
5877 /// Build clause with number of variables \a NumVars.
5879 /// \param MapperQualifierLoc C++ nested name specifier for the associated
5880 /// user-defined mapper.
5881 /// \param MapperIdInfo The identifier of associated user-defined mapper.
5882 /// \param Locs Locations needed to build a mappable clause. It includes 1)
5883 /// StartLoc: starting location of the clause (the clause keyword); 2)
5884 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5885 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5886 /// NumVars: number of expressions listed in this clause; 2)
5887 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5888 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5889 /// NumComponents: total number of expression components in the clause.
5890 explicit OMPFromClause(NestedNameSpecifierLoc MapperQualifierLoc,
5891 DeclarationNameInfo MapperIdInfo,
5892 const OMPVarListLocTy &Locs,
5893 const OMPMappableExprListSizeTy &Sizes)
5894 : OMPMappableExprListClause(OMPC_from, Locs, Sizes, &MapperQualifierLoc,
5897 /// Build an empty clause.
5899 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5900 /// NumVars: number of expressions listed in this clause; 2)
5901 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5902 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5903 /// NumComponents: total number of expression components in the clause.
5904 explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes)
5905 : OMPMappableExprListClause(OMPC_from, OMPVarListLocTy(), Sizes) {}
5907 /// Define the sizes of each trailing object array except the last one. This
5908 /// is required for TrailingObjects to work properly.
5909 size_t numTrailingObjects(OverloadToken<Expr *>) const {
5910 // There are varlist_size() of expressions, and varlist_size() of
5911 // user-defined mappers.
5912 return 2 * varlist_size();
5914 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
5915 return getUniqueDeclarationsNum();
5917 size_t numTrailingObjects(OverloadToken<unsigned>) const {
5918 return getUniqueDeclarationsNum() + getTotalComponentListNum();
5922 /// Creates clause with a list of variables \a Vars.
5924 /// \param C AST context.
5925 /// \param Locs Locations needed to build a mappable clause. It includes 1)
5926 /// StartLoc: starting location of the clause (the clause keyword); 2)
5927 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5928 /// \param Vars The original expression used in the clause.
5929 /// \param Declarations Declarations used in the clause.
5930 /// \param ComponentLists Component lists used in the clause.
5931 /// \param UDMapperRefs References to user-defined mappers associated with
5932 /// expressions used in the clause.
5933 /// \param UDMQualifierLoc C++ nested name specifier for the associated
5934 /// user-defined mapper.
5935 /// \param MapperId The identifier of associated user-defined mapper.
5936 static OMPFromClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
5937 ArrayRef<Expr *> Vars,
5938 ArrayRef<ValueDecl *> Declarations,
5939 MappableExprComponentListsRef ComponentLists,
5940 ArrayRef<Expr *> UDMapperRefs,
5941 NestedNameSpecifierLoc UDMQualifierLoc,
5942 DeclarationNameInfo MapperId);
5944 /// Creates an empty clause with the place for \a NumVars variables.
5946 /// \param C AST context.
5947 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5948 /// NumVars: number of expressions listed in this clause; 2)
5949 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5950 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5951 /// NumComponents: total number of expression components in the clause.
5952 static OMPFromClause *CreateEmpty(const ASTContext &C,
5953 const OMPMappableExprListSizeTy &Sizes);
5955 child_range children() {
5956 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5957 reinterpret_cast<Stmt **>(varlist_end()));
5960 const_child_range children() const {
5961 auto Children = const_cast<OMPFromClause *>(this)->children();
5962 return const_child_range(Children.begin(), Children.end());
5965 child_range used_children() {
5966 return child_range(child_iterator(), child_iterator());
5968 const_child_range used_children() const {
5969 return const_child_range(const_child_iterator(), const_child_iterator());
5972 static bool classof(const OMPClause *T) {
5973 return T->getClauseKind() == OMPC_from;
5977 /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
5981 /// #pragma omp target data use_device_ptr(a,b)
5983 /// In this example directive '#pragma omp target data' has clause
5984 /// 'use_device_ptr' with the variables 'a' and 'b'.
5985 class OMPUseDevicePtrClause final
5986 : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
5987 private llvm::TrailingObjects<
5988 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
5989 OMPClauseMappableExprCommon::MappableComponent> {
5990 friend class OMPClauseReader;
5991 friend OMPMappableExprListClause;
5992 friend OMPVarListClause;
5993 friend TrailingObjects;
5995 /// Build clause with number of variables \a NumVars.
5997 /// \param Locs Locations needed to build a mappable clause. It includes 1)
5998 /// StartLoc: starting location of the clause (the clause keyword); 2)
5999 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6000 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6001 /// NumVars: number of expressions listed in this clause; 2)
6002 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6003 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6004 /// NumComponents: total number of expression components in the clause.
6005 explicit OMPUseDevicePtrClause(const OMPVarListLocTy &Locs,
6006 const OMPMappableExprListSizeTy &Sizes)
6007 : OMPMappableExprListClause(OMPC_use_device_ptr, Locs, Sizes) {}
6009 /// Build an empty clause.
6011 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6012 /// NumVars: number of expressions listed in this clause; 2)
6013 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6014 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6015 /// NumComponents: total number of expression components in the clause.
6016 explicit OMPUseDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
6017 : OMPMappableExprListClause(OMPC_use_device_ptr, OMPVarListLocTy(),
6020 /// Define the sizes of each trailing object array except the last one. This
6021 /// is required for TrailingObjects to work properly.
6022 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6023 return 3 * varlist_size();
6025 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6026 return getUniqueDeclarationsNum();
6028 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6029 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6032 /// Sets the list of references to private copies with initializers for new
6033 /// private variables.
6034 /// \param VL List of references.
6035 void setPrivateCopies(ArrayRef<Expr *> VL);
6037 /// Gets the list of references to private copies with initializers for new
6038 /// private variables.
6039 MutableArrayRef<Expr *> getPrivateCopies() {
6040 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
6042 ArrayRef<const Expr *> getPrivateCopies() const {
6043 return llvm::makeArrayRef(varlist_end(), varlist_size());
6046 /// Sets the list of references to initializer variables for new private
6048 /// \param VL List of references.
6049 void setInits(ArrayRef<Expr *> VL);
6051 /// Gets the list of references to initializer variables for new private
6053 MutableArrayRef<Expr *> getInits() {
6054 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
6056 ArrayRef<const Expr *> getInits() const {
6057 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
6061 /// Creates clause with a list of variables \a Vars.
6063 /// \param C AST context.
6064 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6065 /// StartLoc: starting location of the clause (the clause keyword); 2)
6066 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6067 /// \param Vars The original expression used in the clause.
6068 /// \param PrivateVars Expressions referring to private copies.
6069 /// \param Inits Expressions referring to private copy initializers.
6070 /// \param Declarations Declarations used in the clause.
6071 /// \param ComponentLists Component lists used in the clause.
6072 static OMPUseDevicePtrClause *
6073 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6074 ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
6075 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
6076 MappableExprComponentListsRef ComponentLists);
6078 /// Creates an empty clause with the place for \a NumVars variables.
6080 /// \param C AST context.
6081 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6082 /// NumVars: number of expressions listed in this clause; 2)
6083 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6084 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6085 /// NumComponents: total number of expression components in the clause.
6086 static OMPUseDevicePtrClause *
6087 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
6089 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
6090 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
6091 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
6092 using private_copies_const_range =
6093 llvm::iterator_range<private_copies_const_iterator>;
6095 private_copies_range private_copies() {
6096 return private_copies_range(getPrivateCopies().begin(),
6097 getPrivateCopies().end());
6100 private_copies_const_range private_copies() const {
6101 return private_copies_const_range(getPrivateCopies().begin(),
6102 getPrivateCopies().end());
6105 using inits_iterator = MutableArrayRef<Expr *>::iterator;
6106 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
6107 using inits_range = llvm::iterator_range<inits_iterator>;
6108 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
6110 inits_range inits() {
6111 return inits_range(getInits().begin(), getInits().end());
6114 inits_const_range inits() const {
6115 return inits_const_range(getInits().begin(), getInits().end());
6118 child_range children() {
6119 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6120 reinterpret_cast<Stmt **>(varlist_end()));
6123 const_child_range children() const {
6124 auto Children = const_cast<OMPUseDevicePtrClause *>(this)->children();
6125 return const_child_range(Children.begin(), Children.end());
6128 child_range used_children() {
6129 return child_range(child_iterator(), child_iterator());
6131 const_child_range used_children() const {
6132 return const_child_range(const_child_iterator(), const_child_iterator());
6135 static bool classof(const OMPClause *T) {
6136 return T->getClauseKind() == OMPC_use_device_ptr;
6140 /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
6144 /// #pragma omp target is_device_ptr(a,b)
6146 /// In this example directive '#pragma omp target' has clause
6147 /// 'is_device_ptr' with the variables 'a' and 'b'.
6148 class OMPIsDevicePtrClause final
6149 : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
6150 private llvm::TrailingObjects<
6151 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
6152 OMPClauseMappableExprCommon::MappableComponent> {
6153 friend class OMPClauseReader;
6154 friend OMPMappableExprListClause;
6155 friend OMPVarListClause;
6156 friend TrailingObjects;
6158 /// Build clause with number of variables \a NumVars.
6160 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6161 /// StartLoc: starting location of the clause (the clause keyword); 2)
6162 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6163 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6164 /// NumVars: number of expressions listed in this clause; 2)
6165 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6166 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6167 /// NumComponents: total number of expression components in the clause.
6168 explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs,
6169 const OMPMappableExprListSizeTy &Sizes)
6170 : OMPMappableExprListClause(OMPC_is_device_ptr, Locs, Sizes) {}
6172 /// Build an empty clause.
6174 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6175 /// NumVars: number of expressions listed in this clause; 2)
6176 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6177 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6178 /// NumComponents: total number of expression components in the clause.
6179 explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
6180 : OMPMappableExprListClause(OMPC_is_device_ptr, OMPVarListLocTy(),
6183 /// Define the sizes of each trailing object array except the last one. This
6184 /// is required for TrailingObjects to work properly.
6185 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6186 return varlist_size();
6188 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6189 return getUniqueDeclarationsNum();
6191 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6192 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6196 /// Creates clause with a list of variables \a Vars.
6198 /// \param C AST context.
6199 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6200 /// StartLoc: starting location of the clause (the clause keyword); 2)
6201 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6202 /// \param Vars The original expression used in the clause.
6203 /// \param Declarations Declarations used in the clause.
6204 /// \param ComponentLists Component lists used in the clause.
6205 static OMPIsDevicePtrClause *
6206 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6207 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
6208 MappableExprComponentListsRef ComponentLists);
6210 /// Creates an empty clause with the place for \a NumVars variables.
6212 /// \param C AST context.
6213 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6214 /// NumVars: number of expressions listed in this clause; 2)
6215 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6216 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6217 /// NumComponents: total number of expression components in the clause.
6218 static OMPIsDevicePtrClause *
6219 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
6221 child_range children() {
6222 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6223 reinterpret_cast<Stmt **>(varlist_end()));
6226 const_child_range children() const {
6227 auto Children = const_cast<OMPIsDevicePtrClause *>(this)->children();
6228 return const_child_range(Children.begin(), Children.end());
6231 child_range used_children() {
6232 return child_range(child_iterator(), child_iterator());
6234 const_child_range used_children() const {
6235 return const_child_range(const_child_iterator(), const_child_iterator());
6238 static bool classof(const OMPClause *T) {
6239 return T->getClauseKind() == OMPC_is_device_ptr;
6243 /// This class implements a simple visitor for OMPClause
6245 template<class ImplClass, template <typename> class Ptr, typename RetTy>
6246 class OMPClauseVisitorBase {
6248 #define PTR(CLASS) typename Ptr<CLASS>::type
6249 #define DISPATCH(CLASS) \
6250 return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
6252 #define OPENMP_CLAUSE(Name, Class) \
6253 RetTy Visit ## Class (PTR(Class) S) { DISPATCH(Class); }
6254 #include "clang/Basic/OpenMPKinds.def"
6256 RetTy Visit(PTR(OMPClause) S) {
6257 // Top switch clause: visit each OMPClause.
6258 switch (S->getClauseKind()) {
6259 default: llvm_unreachable("Unknown clause kind!");
6260 #define OPENMP_CLAUSE(Name, Class) \
6261 case OMPC_ ## Name : return Visit ## Class(static_cast<PTR(Class)>(S));
6262 #include "clang/Basic/OpenMPKinds.def"
6265 // Base case, ignore it. :)
6266 RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); }
6271 template <typename T>
6272 using const_ptr = typename std::add_pointer<typename std::add_const<T>::type>;
6274 template<class ImplClass, typename RetTy = void>
6275 class OMPClauseVisitor :
6276 public OMPClauseVisitorBase <ImplClass, std::add_pointer, RetTy> {};
6277 template<class ImplClass, typename RetTy = void>
6278 class ConstOMPClauseVisitor :
6279 public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {};
6281 class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
6283 const PrintingPolicy &Policy;
6285 /// Process clauses with list of variables.
6286 template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
6289 OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
6290 : OS(OS), Policy(Policy) {}
6292 #define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *S);
6293 #include "clang/Basic/OpenMPKinds.def"
6296 } // namespace clang
6298 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H