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/Frontend/OpenMP/OMPConstants.h"
34 #include "llvm/Frontend/OpenMP/OMPContext.h"
35 #include "llvm/Support/Casting.h"
36 #include "llvm/Support/Compiler.h"
37 #include "llvm/Support/TrailingObjects.h"
47 //===----------------------------------------------------------------------===//
48 // AST classes for clauses.
49 //===----------------------------------------------------------------------===//
51 /// This is a basic class for representing single OpenMP clause.
53 /// Starting location of the clause (the clause keyword).
54 SourceLocation StartLoc;
56 /// Ending location of the clause.
57 SourceLocation EndLoc;
59 /// Kind of the clause.
60 OpenMPClauseKind Kind;
63 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
64 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
67 /// Returns the starting location of the clause.
68 SourceLocation getBeginLoc() const { return StartLoc; }
70 /// Returns the ending location of the clause.
71 SourceLocation getEndLoc() const { return EndLoc; }
73 /// Sets the starting location of the clause.
74 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
76 /// Sets the ending location of the clause.
77 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
79 /// Returns kind of OpenMP clause (private, shared, reduction, etc.).
80 OpenMPClauseKind getClauseKind() const { return Kind; }
82 bool isImplicit() const { return StartLoc.isInvalid(); }
84 using child_iterator = StmtIterator;
85 using const_child_iterator = ConstStmtIterator;
86 using child_range = llvm::iterator_range<child_iterator>;
87 using const_child_range = llvm::iterator_range<const_child_iterator>;
89 child_range children();
90 const_child_range children() const {
91 auto Children = const_cast<OMPClause *>(this)->children();
92 return const_child_range(Children.begin(), Children.end());
95 /// Get the iterator range for the expressions used in the clauses. Used
96 /// expressions include only the children that must be evaluated at the
97 /// runtime before entering the construct.
98 child_range used_children();
99 const_child_range used_children() const {
100 auto Children = const_cast<OMPClause *>(this)->children();
101 return const_child_range(Children.begin(), Children.end());
104 static bool classof(const OMPClause *) { return true; }
107 /// Class that handles pre-initialization statement for some clauses, like
108 /// 'shedule', 'firstprivate' etc.
109 class OMPClauseWithPreInit {
110 friend class OMPClauseReader;
112 /// Pre-initialization statement for the clause.
113 Stmt *PreInit = nullptr;
115 /// Region that captures the associated stmt.
116 OpenMPDirectiveKind CaptureRegion = llvm::omp::OMPD_unknown;
119 OMPClauseWithPreInit(const OMPClause *This) {
120 assert(get(This) && "get is not tuned for pre-init.");
123 /// Set pre-initialization statement for the clause.
125 setPreInitStmt(Stmt *S,
126 OpenMPDirectiveKind ThisRegion = llvm::omp::OMPD_unknown) {
128 CaptureRegion = ThisRegion;
132 /// Get pre-initialization statement for the clause.
133 const Stmt *getPreInitStmt() const { return PreInit; }
135 /// Get pre-initialization statement for the clause.
136 Stmt *getPreInitStmt() { return PreInit; }
138 /// Get capture region for the stmt in the clause.
139 OpenMPDirectiveKind getCaptureRegion() const { return CaptureRegion; }
141 static OMPClauseWithPreInit *get(OMPClause *C);
142 static const OMPClauseWithPreInit *get(const OMPClause *C);
145 /// Class that handles post-update expression for some clauses, like
146 /// 'lastprivate', 'reduction' etc.
147 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
148 friend class OMPClauseReader;
150 /// Post-update expression for the clause.
151 Expr *PostUpdate = nullptr;
154 OMPClauseWithPostUpdate(const OMPClause *This) : OMPClauseWithPreInit(This) {
155 assert(get(This) && "get is not tuned for post-update.");
158 /// Set pre-initialization statement for the clause.
159 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
162 /// Get post-update expression for the clause.
163 const Expr *getPostUpdateExpr() const { return PostUpdate; }
165 /// Get post-update expression for the clause.
166 Expr *getPostUpdateExpr() { return PostUpdate; }
168 static OMPClauseWithPostUpdate *get(OMPClause *C);
169 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
172 /// This structure contains most locations needed for by an OMPVarListClause.
173 struct OMPVarListLocTy {
174 /// Starting location of the clause (the clause keyword).
175 SourceLocation StartLoc;
177 SourceLocation LParenLoc;
178 /// Ending location of the clause.
179 SourceLocation EndLoc;
180 OMPVarListLocTy() = default;
181 OMPVarListLocTy(SourceLocation StartLoc, SourceLocation LParenLoc,
182 SourceLocation EndLoc)
183 : StartLoc(StartLoc), LParenLoc(LParenLoc), EndLoc(EndLoc) {}
186 /// This represents clauses with the list of variables like 'private',
187 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
188 /// '#pragma omp ...' directives.
189 template <class T> class OMPVarListClause : public OMPClause {
190 friend class OMPClauseReader;
193 SourceLocation LParenLoc;
195 /// Number of variables in the list.
199 /// Build a clause with \a N variables
201 /// \param K Kind of the clause.
202 /// \param StartLoc Starting location of the clause (the clause keyword).
203 /// \param LParenLoc Location of '('.
204 /// \param EndLoc Ending location of the clause.
205 /// \param N Number of the variables in the clause.
206 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
207 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
208 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
210 /// Fetches list of variables associated with this clause.
211 MutableArrayRef<Expr *> getVarRefs() {
212 return MutableArrayRef<Expr *>(
213 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
216 /// Sets the list of variables for this clause.
217 void setVarRefs(ArrayRef<Expr *> VL) {
218 assert(VL.size() == NumVars &&
219 "Number of variables is not the same as the preallocated buffer");
220 std::copy(VL.begin(), VL.end(),
221 static_cast<T *>(this)->template getTrailingObjects<Expr *>());
225 using varlist_iterator = MutableArrayRef<Expr *>::iterator;
226 using varlist_const_iterator = ArrayRef<const Expr *>::iterator;
227 using varlist_range = llvm::iterator_range<varlist_iterator>;
228 using varlist_const_range = llvm::iterator_range<varlist_const_iterator>;
230 unsigned varlist_size() const { return NumVars; }
231 bool varlist_empty() const { return NumVars == 0; }
233 varlist_range varlists() {
234 return varlist_range(varlist_begin(), varlist_end());
236 varlist_const_range varlists() const {
237 return varlist_const_range(varlist_begin(), varlist_end());
240 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
241 varlist_iterator varlist_end() { return getVarRefs().end(); }
242 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
243 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
245 /// Sets the location of '('.
246 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
248 /// Returns the location of '('.
249 SourceLocation getLParenLoc() const { return LParenLoc; }
251 /// Fetches list of all variables in the clause.
252 ArrayRef<const Expr *> getVarRefs() const {
253 return llvm::makeArrayRef(
254 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
259 /// This represents 'allocator' clause in the '#pragma omp ...'
263 /// #pragma omp allocate(a) allocator(omp_default_mem_alloc)
265 /// In this example directive '#pragma omp allocate' has simple 'allocator'
266 /// clause with the allocator 'omp_default_mem_alloc'.
267 class OMPAllocatorClause : public OMPClause {
268 friend class OMPClauseReader;
271 SourceLocation LParenLoc;
273 /// Expression with the allocator.
274 Stmt *Allocator = nullptr;
277 void setAllocator(Expr *A) { Allocator = A; }
280 /// Build 'allocator' clause with the given allocator.
282 /// \param A Allocator.
283 /// \param StartLoc Starting location of the clause.
284 /// \param LParenLoc Location of '('.
285 /// \param EndLoc Ending location of the clause.
286 OMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc,
287 SourceLocation EndLoc)
288 : OMPClause(OMPC_allocator, StartLoc, EndLoc), LParenLoc(LParenLoc),
291 /// Build an empty clause.
293 : OMPClause(OMPC_allocator, SourceLocation(), SourceLocation()) {}
295 /// Sets the location of '('.
296 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
298 /// Returns the location of '('.
299 SourceLocation getLParenLoc() const { return LParenLoc; }
301 /// Returns allocator.
302 Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); }
304 child_range children() { return child_range(&Allocator, &Allocator + 1); }
306 const_child_range children() const {
307 return const_child_range(&Allocator, &Allocator + 1);
310 child_range used_children() {
311 return child_range(child_iterator(), child_iterator());
313 const_child_range used_children() const {
314 return const_child_range(const_child_iterator(), const_child_iterator());
317 static bool classof(const OMPClause *T) {
318 return T->getClauseKind() == OMPC_allocator;
322 /// This represents clause 'allocate' in the '#pragma omp ...' directives.
325 /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
327 /// In this example directive '#pragma omp parallel' has clause 'private'
328 /// and clause 'allocate' for the variable 'a'.
329 class OMPAllocateClause final
330 : public OMPVarListClause<OMPAllocateClause>,
331 private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
332 friend class OMPClauseReader;
333 friend OMPVarListClause;
334 friend TrailingObjects;
336 /// Allocator specified in the clause, or 'nullptr' if the default one is
338 Expr *Allocator = nullptr;
339 /// Position of the ':' delimiter in the clause;
340 SourceLocation ColonLoc;
342 /// Build clause with number of variables \a N.
344 /// \param StartLoc Starting location of the clause.
345 /// \param LParenLoc Location of '('.
346 /// \param Allocator Allocator expression.
347 /// \param ColonLoc Location of ':' delimiter.
348 /// \param EndLoc Ending location of the clause.
349 /// \param N Number of the variables in the clause.
350 OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
351 Expr *Allocator, SourceLocation ColonLoc,
352 SourceLocation EndLoc, unsigned N)
353 : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, StartLoc, LParenLoc,
355 Allocator(Allocator), ColonLoc(ColonLoc) {}
357 /// Build an empty clause.
359 /// \param N Number of variables.
360 explicit OMPAllocateClause(unsigned N)
361 : OMPVarListClause<OMPAllocateClause>(OMPC_allocate, SourceLocation(),
362 SourceLocation(), SourceLocation(),
365 /// Sets location of ':' symbol in clause.
366 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
368 void setAllocator(Expr *A) { Allocator = A; }
371 /// Creates clause with a list of variables \a VL.
373 /// \param C AST context.
374 /// \param StartLoc Starting location of the clause.
375 /// \param LParenLoc Location of '('.
376 /// \param Allocator Allocator expression.
377 /// \param ColonLoc Location of ':' delimiter.
378 /// \param EndLoc Ending location of the clause.
379 /// \param VL List of references to the variables.
380 static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
381 SourceLocation LParenLoc, Expr *Allocator,
382 SourceLocation ColonLoc,
383 SourceLocation EndLoc, ArrayRef<Expr *> VL);
385 /// Returns the allocator expression or nullptr, if no allocator is specified.
386 Expr *getAllocator() const { return Allocator; }
388 /// Returns the location of the ':' delimiter.
389 SourceLocation getColonLoc() const { return ColonLoc; }
391 /// Creates an empty clause with the place for \a N variables.
393 /// \param C AST context.
394 /// \param N The number of variables.
395 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
397 child_range children() {
398 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
399 reinterpret_cast<Stmt **>(varlist_end()));
402 const_child_range children() const {
403 auto Children = const_cast<OMPAllocateClause *>(this)->children();
404 return const_child_range(Children.begin(), Children.end());
407 child_range used_children() {
408 return child_range(child_iterator(), child_iterator());
410 const_child_range used_children() const {
411 return const_child_range(const_child_iterator(), const_child_iterator());
414 static bool classof(const OMPClause *T) {
415 return T->getClauseKind() == OMPC_allocate;
419 /// This represents 'if' clause in the '#pragma omp ...' directive.
422 /// #pragma omp parallel if(parallel:a > 5)
424 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
425 /// condition 'a > 5' and directive name modifier 'parallel'.
426 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
427 friend class OMPClauseReader;
430 SourceLocation LParenLoc;
432 /// Condition of the 'if' clause.
433 Stmt *Condition = nullptr;
435 /// Location of ':' (if any).
436 SourceLocation ColonLoc;
438 /// Directive name modifier for the clause.
439 OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
441 /// Name modifier location.
442 SourceLocation NameModifierLoc;
445 void setCondition(Expr *Cond) { Condition = Cond; }
447 /// Set directive name modifier for the clause.
448 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
450 /// Set location of directive name modifier for the clause.
451 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
453 /// Set location of ':'.
454 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
457 /// Build 'if' clause with condition \a Cond.
459 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
460 /// \param Cond Condition of the clause.
461 /// \param HelperCond Helper condition for the clause.
462 /// \param CaptureRegion Innermost OpenMP region where expressions in this
463 /// clause must be captured.
464 /// \param StartLoc Starting location of the clause.
465 /// \param LParenLoc Location of '('.
466 /// \param NameModifierLoc Location of directive name modifier.
467 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
468 /// \param EndLoc Ending location of the clause.
469 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
470 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
471 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
472 SourceLocation ColonLoc, SourceLocation EndLoc)
473 : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this),
474 LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
475 NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) {
476 setPreInitStmt(HelperCond, CaptureRegion);
479 /// Build an empty clause.
481 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
482 OMPClauseWithPreInit(this) {}
484 /// Sets the location of '('.
485 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
487 /// Returns the location of '('.
488 SourceLocation getLParenLoc() const { return LParenLoc; }
490 /// Return the location of ':'.
491 SourceLocation getColonLoc() const { return ColonLoc; }
493 /// Returns condition.
494 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
496 /// Return directive name modifier associated with the clause.
497 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
499 /// Return the location of directive name modifier.
500 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
502 child_range children() { return child_range(&Condition, &Condition + 1); }
504 const_child_range children() const {
505 return const_child_range(&Condition, &Condition + 1);
508 child_range used_children();
509 const_child_range used_children() const {
510 auto Children = const_cast<OMPIfClause *>(this)->used_children();
511 return const_child_range(Children.begin(), Children.end());
514 static bool classof(const OMPClause *T) {
515 return T->getClauseKind() == OMPC_if;
519 /// This represents 'final' clause in the '#pragma omp ...' directive.
522 /// #pragma omp task final(a > 5)
524 /// In this example directive '#pragma omp task' has simple 'final'
525 /// clause with condition 'a > 5'.
526 class OMPFinalClause : public OMPClause, public OMPClauseWithPreInit {
527 friend class OMPClauseReader;
530 SourceLocation LParenLoc;
532 /// Condition of the 'if' clause.
533 Stmt *Condition = nullptr;
536 void setCondition(Expr *Cond) { Condition = Cond; }
539 /// Build 'final' clause with condition \a Cond.
541 /// \param Cond Condition of the clause.
542 /// \param HelperCond Helper condition for the construct.
543 /// \param CaptureRegion Innermost OpenMP region where expressions in this
544 /// clause must be captured.
545 /// \param StartLoc Starting location of the clause.
546 /// \param LParenLoc Location of '('.
547 /// \param EndLoc Ending location of the clause.
548 OMPFinalClause(Expr *Cond, Stmt *HelperCond,
549 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
550 SourceLocation LParenLoc, SourceLocation EndLoc)
551 : OMPClause(OMPC_final, StartLoc, EndLoc), OMPClauseWithPreInit(this),
552 LParenLoc(LParenLoc), Condition(Cond) {
553 setPreInitStmt(HelperCond, CaptureRegion);
556 /// Build an empty clause.
558 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
559 OMPClauseWithPreInit(this) {}
561 /// Sets the location of '('.
562 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
564 /// Returns the location of '('.
565 SourceLocation getLParenLoc() const { return LParenLoc; }
567 /// Returns condition.
568 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
570 child_range children() { return child_range(&Condition, &Condition + 1); }
572 const_child_range children() const {
573 return const_child_range(&Condition, &Condition + 1);
576 child_range used_children();
577 const_child_range used_children() const {
578 auto Children = const_cast<OMPFinalClause *>(this)->used_children();
579 return const_child_range(Children.begin(), Children.end());
582 static bool classof(const OMPClause *T) {
583 return T->getClauseKind() == OMPC_final;
587 /// This represents 'num_threads' clause in the '#pragma omp ...'
591 /// #pragma omp parallel num_threads(6)
593 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
594 /// clause with number of threads '6'.
595 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
596 friend class OMPClauseReader;
599 SourceLocation LParenLoc;
601 /// Condition of the 'num_threads' clause.
602 Stmt *NumThreads = nullptr;
605 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
608 /// Build 'num_threads' clause with condition \a NumThreads.
610 /// \param NumThreads Number of threads for the construct.
611 /// \param HelperNumThreads Helper Number of threads for the construct.
612 /// \param CaptureRegion Innermost OpenMP region where expressions in this
613 /// clause must be captured.
614 /// \param StartLoc Starting location of the clause.
615 /// \param LParenLoc Location of '('.
616 /// \param EndLoc Ending location of the clause.
617 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
618 OpenMPDirectiveKind CaptureRegion,
619 SourceLocation StartLoc, SourceLocation LParenLoc,
620 SourceLocation EndLoc)
621 : OMPClause(OMPC_num_threads, StartLoc, EndLoc),
622 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
623 NumThreads(NumThreads) {
624 setPreInitStmt(HelperNumThreads, CaptureRegion);
627 /// Build an empty clause.
628 OMPNumThreadsClause()
629 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
630 OMPClauseWithPreInit(this) {}
632 /// Sets the location of '('.
633 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
635 /// Returns the location of '('.
636 SourceLocation getLParenLoc() const { return LParenLoc; }
638 /// Returns number of threads.
639 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
641 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
643 const_child_range children() const {
644 return const_child_range(&NumThreads, &NumThreads + 1);
647 child_range used_children() {
648 return child_range(child_iterator(), child_iterator());
650 const_child_range used_children() const {
651 return const_child_range(const_child_iterator(), const_child_iterator());
654 static bool classof(const OMPClause *T) {
655 return T->getClauseKind() == OMPC_num_threads;
659 /// This represents 'safelen' clause in the '#pragma omp ...'
663 /// #pragma omp simd safelen(4)
665 /// In this example directive '#pragma omp simd' has clause 'safelen'
666 /// with single expression '4'.
667 /// If the safelen clause is used then no two iterations executed
668 /// concurrently with SIMD instructions can have a greater distance
669 /// in the logical iteration space than its value. The parameter of
670 /// the safelen clause must be a constant positive integer expression.
671 class OMPSafelenClause : public OMPClause {
672 friend class OMPClauseReader;
675 SourceLocation LParenLoc;
677 /// Safe iteration space distance.
678 Stmt *Safelen = nullptr;
681 void setSafelen(Expr *Len) { Safelen = Len; }
684 /// Build 'safelen' clause.
686 /// \param Len Expression associated with this clause.
687 /// \param StartLoc Starting location of the clause.
688 /// \param EndLoc Ending location of the clause.
689 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
690 SourceLocation EndLoc)
691 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
694 /// Build an empty clause.
695 explicit OMPSafelenClause()
696 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()) {}
698 /// Sets the location of '('.
699 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
701 /// Returns the location of '('.
702 SourceLocation getLParenLoc() const { return LParenLoc; }
704 /// Return safe iteration space distance.
705 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
707 child_range children() { return child_range(&Safelen, &Safelen + 1); }
709 const_child_range children() const {
710 return const_child_range(&Safelen, &Safelen + 1);
713 child_range used_children() {
714 return child_range(child_iterator(), child_iterator());
716 const_child_range used_children() const {
717 return const_child_range(const_child_iterator(), const_child_iterator());
720 static bool classof(const OMPClause *T) {
721 return T->getClauseKind() == OMPC_safelen;
725 /// This represents 'simdlen' clause in the '#pragma omp ...'
729 /// #pragma omp simd simdlen(4)
731 /// In this example directive '#pragma omp simd' has clause 'simdlen'
732 /// with single expression '4'.
733 /// If the 'simdlen' clause is used then it specifies the preferred number of
734 /// iterations to be executed concurrently. The parameter of the 'simdlen'
735 /// clause must be a constant positive integer expression.
736 class OMPSimdlenClause : public OMPClause {
737 friend class OMPClauseReader;
740 SourceLocation LParenLoc;
742 /// Safe iteration space distance.
743 Stmt *Simdlen = nullptr;
746 void setSimdlen(Expr *Len) { Simdlen = Len; }
749 /// Build 'simdlen' clause.
751 /// \param Len Expression associated with this clause.
752 /// \param StartLoc Starting location of the clause.
753 /// \param EndLoc Ending location of the clause.
754 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
755 SourceLocation EndLoc)
756 : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
759 /// Build an empty clause.
760 explicit OMPSimdlenClause()
761 : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()) {}
763 /// Sets the location of '('.
764 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
766 /// Returns the location of '('.
767 SourceLocation getLParenLoc() const { return LParenLoc; }
769 /// Return safe iteration space distance.
770 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
772 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
774 const_child_range children() const {
775 return const_child_range(&Simdlen, &Simdlen + 1);
778 child_range used_children() {
779 return child_range(child_iterator(), child_iterator());
781 const_child_range used_children() const {
782 return const_child_range(const_child_iterator(), const_child_iterator());
785 static bool classof(const OMPClause *T) {
786 return T->getClauseKind() == OMPC_simdlen;
790 /// This represents 'collapse' clause in the '#pragma omp ...'
794 /// #pragma omp simd collapse(3)
796 /// In this example directive '#pragma omp simd' has clause 'collapse'
797 /// with single expression '3'.
798 /// The parameter must be a constant positive integer expression, it specifies
799 /// the number of nested loops that should be collapsed into a single iteration
801 class OMPCollapseClause : public OMPClause {
802 friend class OMPClauseReader;
805 SourceLocation LParenLoc;
807 /// Number of for-loops.
808 Stmt *NumForLoops = nullptr;
810 /// Set the number of associated for-loops.
811 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
814 /// Build 'collapse' clause.
816 /// \param Num Expression associated with this clause.
817 /// \param StartLoc Starting location of the clause.
818 /// \param LParenLoc Location of '('.
819 /// \param EndLoc Ending location of the clause.
820 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
821 SourceLocation LParenLoc, SourceLocation EndLoc)
822 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
825 /// Build an empty clause.
826 explicit OMPCollapseClause()
827 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()) {}
829 /// Sets the location of '('.
830 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
832 /// Returns the location of '('.
833 SourceLocation getLParenLoc() const { return LParenLoc; }
835 /// Return the number of associated for-loops.
836 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
838 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
840 const_child_range children() const {
841 return const_child_range(&NumForLoops, &NumForLoops + 1);
844 child_range used_children() {
845 return child_range(child_iterator(), child_iterator());
847 const_child_range used_children() const {
848 return const_child_range(const_child_iterator(), const_child_iterator());
851 static bool classof(const OMPClause *T) {
852 return T->getClauseKind() == OMPC_collapse;
856 /// This represents 'default' clause in the '#pragma omp ...' directive.
859 /// #pragma omp parallel default(shared)
861 /// In this example directive '#pragma omp parallel' has simple 'default'
862 /// clause with kind 'shared'.
863 class OMPDefaultClause : public OMPClause {
864 friend class OMPClauseReader;
867 SourceLocation LParenLoc;
869 /// A kind of the 'default' clause.
870 llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
872 /// Start location of the kind in source code.
873 SourceLocation KindKwLoc;
875 /// Set kind of the clauses.
877 /// \param K Argument of clause.
878 void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
880 /// Set argument location.
882 /// \param KLoc Argument location.
883 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
886 /// Build 'default' clause with argument \a A ('none' or 'shared').
888 /// \param A Argument of the clause ('none' or 'shared').
889 /// \param ALoc Starting location of the argument.
890 /// \param StartLoc Starting location of the clause.
891 /// \param LParenLoc Location of '('.
892 /// \param EndLoc Ending location of the clause.
893 OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
894 SourceLocation StartLoc, SourceLocation LParenLoc,
895 SourceLocation EndLoc)
896 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
897 Kind(A), KindKwLoc(ALoc) {}
899 /// Build an empty clause.
901 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()) {}
903 /// Sets the location of '('.
904 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
906 /// Returns the location of '('.
907 SourceLocation getLParenLoc() const { return LParenLoc; }
909 /// Returns kind of the clause.
910 llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
912 /// Returns location of clause kind.
913 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
915 child_range children() {
916 return child_range(child_iterator(), child_iterator());
919 const_child_range children() const {
920 return const_child_range(const_child_iterator(), const_child_iterator());
923 child_range used_children() {
924 return child_range(child_iterator(), child_iterator());
926 const_child_range used_children() const {
927 return const_child_range(const_child_iterator(), const_child_iterator());
930 static bool classof(const OMPClause *T) {
931 return T->getClauseKind() == OMPC_default;
935 /// This represents 'proc_bind' clause in the '#pragma omp ...'
939 /// #pragma omp parallel proc_bind(master)
941 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
942 /// clause with kind 'master'.
943 class OMPProcBindClause : public OMPClause {
944 friend class OMPClauseReader;
947 SourceLocation LParenLoc;
949 /// A kind of the 'proc_bind' clause.
950 llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
952 /// Start location of the kind in source code.
953 SourceLocation KindKwLoc;
955 /// Set kind of the clause.
957 /// \param K Kind of clause.
958 void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
960 /// Set clause kind location.
962 /// \param KLoc Kind location.
963 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
966 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
969 /// \param A Argument of the clause ('master', 'close' or 'spread').
970 /// \param ALoc Starting location of the argument.
971 /// \param StartLoc Starting location of the clause.
972 /// \param LParenLoc Location of '('.
973 /// \param EndLoc Ending location of the clause.
974 OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
975 SourceLocation StartLoc, SourceLocation LParenLoc,
976 SourceLocation EndLoc)
977 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
978 Kind(A), KindKwLoc(ALoc) {}
980 /// Build an empty clause.
982 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()) {}
984 /// Sets the location of '('.
985 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
987 /// Returns the location of '('.
988 SourceLocation getLParenLoc() const { return LParenLoc; }
990 /// Returns kind of the clause.
991 llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
993 /// Returns location of clause kind.
994 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
996 child_range children() {
997 return child_range(child_iterator(), child_iterator());
1000 const_child_range children() const {
1001 return const_child_range(const_child_iterator(), const_child_iterator());
1004 child_range used_children() {
1005 return child_range(child_iterator(), child_iterator());
1007 const_child_range used_children() const {
1008 return const_child_range(const_child_iterator(), const_child_iterator());
1011 static bool classof(const OMPClause *T) {
1012 return T->getClauseKind() == OMPC_proc_bind;
1016 /// This represents 'unified_address' clause in the '#pragma omp requires'
1020 /// #pragma omp requires unified_address
1022 /// In this example directive '#pragma omp requires' has 'unified_address'
1024 class OMPUnifiedAddressClause final : public OMPClause {
1026 friend class OMPClauseReader;
1027 /// Build 'unified_address' clause.
1029 /// \param StartLoc Starting location of the clause.
1030 /// \param EndLoc Ending location of the clause.
1031 OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
1032 : OMPClause(OMPC_unified_address, StartLoc, EndLoc) {}
1034 /// Build an empty clause.
1035 OMPUnifiedAddressClause()
1036 : OMPClause(OMPC_unified_address, SourceLocation(), SourceLocation()) {}
1038 child_range children() {
1039 return child_range(child_iterator(), child_iterator());
1042 const_child_range children() const {
1043 return const_child_range(const_child_iterator(), const_child_iterator());
1046 child_range used_children() {
1047 return child_range(child_iterator(), child_iterator());
1049 const_child_range used_children() const {
1050 return const_child_range(const_child_iterator(), const_child_iterator());
1053 static bool classof(const OMPClause *T) {
1054 return T->getClauseKind() == OMPC_unified_address;
1058 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1062 /// #pragma omp requires unified_shared_memory
1064 /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1066 class OMPUnifiedSharedMemoryClause final : public OMPClause {
1068 friend class OMPClauseReader;
1069 /// Build 'unified_shared_memory' clause.
1071 /// \param StartLoc Starting location of the clause.
1072 /// \param EndLoc Ending location of the clause.
1073 OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
1074 : OMPClause(OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1076 /// Build an empty clause.
1077 OMPUnifiedSharedMemoryClause()
1078 : OMPClause(OMPC_unified_shared_memory, SourceLocation(), SourceLocation()) {}
1080 child_range children() {
1081 return child_range(child_iterator(), child_iterator());
1084 const_child_range children() const {
1085 return const_child_range(const_child_iterator(), const_child_iterator());
1088 child_range used_children() {
1089 return child_range(child_iterator(), child_iterator());
1091 const_child_range used_children() const {
1092 return const_child_range(const_child_iterator(), const_child_iterator());
1095 static bool classof(const OMPClause *T) {
1096 return T->getClauseKind() == OMPC_unified_shared_memory;
1100 /// This represents 'reverse_offload' clause in the '#pragma omp requires'
1104 /// #pragma omp requires reverse_offload
1106 /// In this example directive '#pragma omp requires' has 'reverse_offload'
1108 class OMPReverseOffloadClause final : public OMPClause {
1110 friend class OMPClauseReader;
1111 /// Build 'reverse_offload' clause.
1113 /// \param StartLoc Starting location of the clause.
1114 /// \param EndLoc Ending location of the clause.
1115 OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1116 : OMPClause(OMPC_reverse_offload, StartLoc, EndLoc) {}
1118 /// Build an empty clause.
1119 OMPReverseOffloadClause()
1120 : OMPClause(OMPC_reverse_offload, SourceLocation(), SourceLocation()) {}
1122 child_range children() {
1123 return child_range(child_iterator(), child_iterator());
1126 const_child_range children() const {
1127 return const_child_range(const_child_iterator(), const_child_iterator());
1130 child_range used_children() {
1131 return child_range(child_iterator(), child_iterator());
1133 const_child_range used_children() const {
1134 return const_child_range(const_child_iterator(), const_child_iterator());
1137 static bool classof(const OMPClause *T) {
1138 return T->getClauseKind() == OMPC_reverse_offload;
1142 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1146 /// #pragma omp requires dynamic_allocators
1148 /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1150 class OMPDynamicAllocatorsClause final : public OMPClause {
1152 friend class OMPClauseReader;
1153 /// Build 'dynamic_allocators' clause.
1155 /// \param StartLoc Starting location of the clause.
1156 /// \param EndLoc Ending location of the clause.
1157 OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
1158 : OMPClause(OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1160 /// Build an empty clause.
1161 OMPDynamicAllocatorsClause()
1162 : OMPClause(OMPC_dynamic_allocators, SourceLocation(), SourceLocation()) {
1165 child_range children() {
1166 return child_range(child_iterator(), child_iterator());
1169 const_child_range children() const {
1170 return const_child_range(const_child_iterator(), const_child_iterator());
1173 child_range used_children() {
1174 return child_range(child_iterator(), child_iterator());
1176 const_child_range used_children() const {
1177 return const_child_range(const_child_iterator(), const_child_iterator());
1180 static bool classof(const OMPClause *T) {
1181 return T->getClauseKind() == OMPC_dynamic_allocators;
1185 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1186 /// requires' directive.
1189 /// #pragma omp requires atomic_default_mem_order(seq_cst)
1191 /// In this example directive '#pragma omp requires' has simple
1192 /// atomic_default_mem_order' clause with kind 'seq_cst'.
1193 class OMPAtomicDefaultMemOrderClause final : public OMPClause {
1194 friend class OMPClauseReader;
1197 SourceLocation LParenLoc;
1199 /// A kind of the 'atomic_default_mem_order' clause.
1200 OpenMPAtomicDefaultMemOrderClauseKind Kind =
1201 OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown;
1203 /// Start location of the kind in source code.
1204 SourceLocation KindKwLoc;
1206 /// Set kind of the clause.
1208 /// \param K Kind of clause.
1209 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1213 /// Set clause kind location.
1215 /// \param KLoc Kind location.
1216 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1221 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1222 /// 'acq_rel' or 'relaxed').
1224 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1225 /// \param ALoc Starting location of the argument.
1226 /// \param StartLoc Starting location of the clause.
1227 /// \param LParenLoc Location of '('.
1228 /// \param EndLoc Ending location of the clause.
1229 OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
1230 SourceLocation ALoc, SourceLocation StartLoc,
1231 SourceLocation LParenLoc,
1232 SourceLocation EndLoc)
1233 : OMPClause(OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1234 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1236 /// Build an empty clause.
1237 OMPAtomicDefaultMemOrderClause()
1238 : OMPClause(OMPC_atomic_default_mem_order, SourceLocation(),
1239 SourceLocation()) {}
1241 /// Sets the location of '('.
1242 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1244 /// Returns the locaiton of '('.
1245 SourceLocation getLParenLoc() const { return LParenLoc; }
1247 /// Returns kind of the clause.
1248 OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
1252 /// Returns location of clause kind.
1253 SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
1255 child_range children() {
1256 return child_range(child_iterator(), child_iterator());
1259 const_child_range children() const {
1260 return const_child_range(const_child_iterator(), const_child_iterator());
1263 child_range used_children() {
1264 return child_range(child_iterator(), child_iterator());
1266 const_child_range used_children() const {
1267 return const_child_range(const_child_iterator(), const_child_iterator());
1270 static bool classof(const OMPClause *T) {
1271 return T->getClauseKind() == OMPC_atomic_default_mem_order;
1275 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
1278 /// #pragma omp for schedule(static, 3)
1280 /// In this example directive '#pragma omp for' has 'schedule' clause with
1281 /// arguments 'static' and '3'.
1282 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
1283 friend class OMPClauseReader;
1285 /// Location of '('.
1286 SourceLocation LParenLoc;
1288 /// A kind of the 'schedule' clause.
1289 OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
1291 /// Modifiers for 'schedule' clause.
1292 enum {FIRST, SECOND, NUM_MODIFIERS};
1293 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1295 /// Locations of modifiers.
1296 SourceLocation ModifiersLoc[NUM_MODIFIERS];
1298 /// Start location of the schedule ind in source code.
1299 SourceLocation KindLoc;
1301 /// Location of ',' (if any).
1302 SourceLocation CommaLoc;
1305 Expr *ChunkSize = nullptr;
1307 /// Set schedule kind.
1309 /// \param K Schedule kind.
1310 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1312 /// Set the first schedule modifier.
1314 /// \param M Schedule modifier.
1315 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1316 Modifiers[FIRST] = M;
1319 /// Set the second schedule modifier.
1321 /// \param M Schedule modifier.
1322 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1323 Modifiers[SECOND] = M;
1326 /// Set location of the first schedule modifier.
1327 void setFirstScheduleModifierLoc(SourceLocation Loc) {
1328 ModifiersLoc[FIRST] = Loc;
1331 /// Set location of the second schedule modifier.
1332 void setSecondScheduleModifierLoc(SourceLocation Loc) {
1333 ModifiersLoc[SECOND] = Loc;
1336 /// Set schedule modifier location.
1338 /// \param M Schedule modifier location.
1339 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1340 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1341 Modifiers[FIRST] = M;
1343 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1344 Modifiers[SECOND] = M;
1348 /// Sets the location of '('.
1350 /// \param Loc Location of '('.
1351 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1353 /// Set schedule kind start location.
1355 /// \param KLoc Schedule kind location.
1356 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1358 /// Set location of ','.
1360 /// \param Loc Location of ','.
1361 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1365 /// \param E Chunk size.
1366 void setChunkSize(Expr *E) { ChunkSize = E; }
1369 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1370 /// expression \a ChunkSize.
1372 /// \param StartLoc Starting location of the clause.
1373 /// \param LParenLoc Location of '('.
1374 /// \param KLoc Starting location of the argument.
1375 /// \param CommaLoc Location of ','.
1376 /// \param EndLoc Ending location of the clause.
1377 /// \param Kind Schedule kind.
1378 /// \param ChunkSize Chunk size.
1379 /// \param HelperChunkSize Helper chunk size for combined directives.
1380 /// \param M1 The first modifier applied to 'schedule' clause.
1381 /// \param M1Loc Location of the first modifier
1382 /// \param M2 The second modifier applied to 'schedule' clause.
1383 /// \param M2Loc Location of the second modifier
1384 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1385 SourceLocation KLoc, SourceLocation CommaLoc,
1386 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
1387 Expr *ChunkSize, Stmt *HelperChunkSize,
1388 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
1389 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
1390 : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this),
1391 LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc),
1392 ChunkSize(ChunkSize) {
1393 setPreInitStmt(HelperChunkSize);
1394 Modifiers[FIRST] = M1;
1395 Modifiers[SECOND] = M2;
1396 ModifiersLoc[FIRST] = M1Loc;
1397 ModifiersLoc[SECOND] = M2Loc;
1400 /// Build an empty clause.
1401 explicit OMPScheduleClause()
1402 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
1403 OMPClauseWithPreInit(this) {
1404 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1405 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1408 /// Get kind of the clause.
1409 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
1411 /// Get the first modifier of the clause.
1412 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
1413 return Modifiers[FIRST];
1416 /// Get the second modifier of the clause.
1417 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
1418 return Modifiers[SECOND];
1421 /// Get location of '('.
1422 SourceLocation getLParenLoc() { return LParenLoc; }
1424 /// Get kind location.
1425 SourceLocation getScheduleKindLoc() { return KindLoc; }
1427 /// Get the first modifier location.
1428 SourceLocation getFirstScheduleModifierLoc() const {
1429 return ModifiersLoc[FIRST];
1432 /// Get the second modifier location.
1433 SourceLocation getSecondScheduleModifierLoc() const {
1434 return ModifiersLoc[SECOND];
1437 /// Get location of ','.
1438 SourceLocation getCommaLoc() { return CommaLoc; }
1441 Expr *getChunkSize() { return ChunkSize; }
1444 const Expr *getChunkSize() const { return ChunkSize; }
1446 child_range children() {
1447 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1448 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1451 const_child_range children() const {
1452 auto Children = const_cast<OMPScheduleClause *>(this)->children();
1453 return const_child_range(Children.begin(), Children.end());
1456 child_range used_children() {
1457 return child_range(child_iterator(), child_iterator());
1459 const_child_range used_children() const {
1460 return const_child_range(const_child_iterator(), const_child_iterator());
1463 static bool classof(const OMPClause *T) {
1464 return T->getClauseKind() == OMPC_schedule;
1468 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1471 /// #pragma omp for ordered (2)
1473 /// In this example directive '#pragma omp for' has 'ordered' clause with
1475 class OMPOrderedClause final
1477 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1478 friend class OMPClauseReader;
1479 friend TrailingObjects;
1481 /// Location of '('.
1482 SourceLocation LParenLoc;
1484 /// Number of for-loops.
1485 Stmt *NumForLoops = nullptr;
1487 /// Real number of loops.
1488 unsigned NumberOfLoops = 0;
1490 /// Build 'ordered' clause.
1492 /// \param Num Expression, possibly associated with this clause.
1493 /// \param NumLoops Number of loops, associated with this clause.
1494 /// \param StartLoc Starting location of the clause.
1495 /// \param LParenLoc Location of '('.
1496 /// \param EndLoc Ending location of the clause.
1497 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1498 SourceLocation LParenLoc, SourceLocation EndLoc)
1499 : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
1500 NumForLoops(Num), NumberOfLoops(NumLoops) {}
1502 /// Build an empty clause.
1503 explicit OMPOrderedClause(unsigned NumLoops)
1504 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
1505 NumberOfLoops(NumLoops) {}
1507 /// Set the number of associated for-loops.
1508 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1511 /// Build 'ordered' clause.
1513 /// \param Num Expression, possibly associated with this clause.
1514 /// \param NumLoops Number of loops, associated with this clause.
1515 /// \param StartLoc Starting location of the clause.
1516 /// \param LParenLoc Location of '('.
1517 /// \param EndLoc Ending location of the clause.
1518 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1519 unsigned NumLoops, SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation EndLoc);
1523 /// Build an empty clause.
1524 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1526 /// Sets the location of '('.
1527 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1529 /// Returns the location of '('.
1530 SourceLocation getLParenLoc() const { return LParenLoc; }
1532 /// Return the number of associated for-loops.
1533 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1535 /// Set number of iterations for the specified loop.
1536 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1537 /// Get number of iterations for all the loops.
1538 ArrayRef<Expr *> getLoopNumIterations() const;
1540 /// Set loop counter for the specified loop.
1541 void setLoopCounter(unsigned NumLoop, Expr *Counter);
1542 /// Get loops counter for the specified loop.
1543 Expr *getLoopCounter(unsigned NumLoop);
1544 const Expr *getLoopCounter(unsigned NumLoop) const;
1546 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1548 const_child_range children() const {
1549 return const_child_range(&NumForLoops, &NumForLoops + 1);
1552 child_range used_children() {
1553 return child_range(child_iterator(), child_iterator());
1555 const_child_range used_children() const {
1556 return const_child_range(const_child_iterator(), const_child_iterator());
1559 static bool classof(const OMPClause *T) {
1560 return T->getClauseKind() == OMPC_ordered;
1564 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1567 /// #pragma omp for nowait
1569 /// In this example directive '#pragma omp for' has 'nowait' clause.
1570 class OMPNowaitClause : public OMPClause {
1572 /// Build 'nowait' clause.
1574 /// \param StartLoc Starting location of the clause.
1575 /// \param EndLoc Ending location of the clause.
1576 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
1577 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
1579 /// Build an empty clause.
1581 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
1583 child_range children() {
1584 return child_range(child_iterator(), child_iterator());
1587 const_child_range children() const {
1588 return const_child_range(const_child_iterator(), const_child_iterator());
1591 child_range used_children() {
1592 return child_range(child_iterator(), child_iterator());
1594 const_child_range used_children() const {
1595 return const_child_range(const_child_iterator(), const_child_iterator());
1598 static bool classof(const OMPClause *T) {
1599 return T->getClauseKind() == OMPC_nowait;
1603 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1606 /// #pragma omp task untied
1608 /// In this example directive '#pragma omp task' has 'untied' clause.
1609 class OMPUntiedClause : public OMPClause {
1611 /// Build 'untied' clause.
1613 /// \param StartLoc Starting location of the clause.
1614 /// \param EndLoc Ending location of the clause.
1615 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
1616 : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
1618 /// Build an empty clause.
1620 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
1622 child_range children() {
1623 return child_range(child_iterator(), child_iterator());
1626 const_child_range children() const {
1627 return const_child_range(const_child_iterator(), const_child_iterator());
1630 child_range used_children() {
1631 return child_range(child_iterator(), child_iterator());
1633 const_child_range used_children() const {
1634 return const_child_range(const_child_iterator(), const_child_iterator());
1637 static bool classof(const OMPClause *T) {
1638 return T->getClauseKind() == OMPC_untied;
1642 /// This represents 'mergeable' clause in the '#pragma omp ...'
1646 /// #pragma omp task mergeable
1648 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1649 class OMPMergeableClause : public OMPClause {
1651 /// Build 'mergeable' clause.
1653 /// \param StartLoc Starting location of the clause.
1654 /// \param EndLoc Ending location of the clause.
1655 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
1656 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
1658 /// Build an empty clause.
1659 OMPMergeableClause()
1660 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
1662 child_range children() {
1663 return child_range(child_iterator(), child_iterator());
1666 const_child_range children() const {
1667 return const_child_range(const_child_iterator(), const_child_iterator());
1670 child_range used_children() {
1671 return child_range(child_iterator(), child_iterator());
1673 const_child_range used_children() const {
1674 return const_child_range(const_child_iterator(), const_child_iterator());
1677 static bool classof(const OMPClause *T) {
1678 return T->getClauseKind() == OMPC_mergeable;
1682 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1685 /// #pragma omp atomic read
1687 /// In this example directive '#pragma omp atomic' has 'read' clause.
1688 class OMPReadClause : public OMPClause {
1690 /// Build 'read' clause.
1692 /// \param StartLoc Starting location of the clause.
1693 /// \param EndLoc Ending location of the clause.
1694 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1695 : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1697 /// Build an empty clause.
1698 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1700 child_range children() {
1701 return child_range(child_iterator(), child_iterator());
1704 const_child_range children() const {
1705 return const_child_range(const_child_iterator(), const_child_iterator());
1708 child_range used_children() {
1709 return child_range(child_iterator(), child_iterator());
1711 const_child_range used_children() const {
1712 return const_child_range(const_child_iterator(), const_child_iterator());
1715 static bool classof(const OMPClause *T) {
1716 return T->getClauseKind() == OMPC_read;
1720 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1723 /// #pragma omp atomic write
1725 /// In this example directive '#pragma omp atomic' has 'write' clause.
1726 class OMPWriteClause : public OMPClause {
1728 /// Build 'write' clause.
1730 /// \param StartLoc Starting location of the clause.
1731 /// \param EndLoc Ending location of the clause.
1732 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1733 : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1735 /// Build an empty clause.
1737 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1739 child_range children() {
1740 return child_range(child_iterator(), child_iterator());
1743 const_child_range children() const {
1744 return const_child_range(const_child_iterator(), const_child_iterator());
1747 child_range used_children() {
1748 return child_range(child_iterator(), child_iterator());
1750 const_child_range used_children() const {
1751 return const_child_range(const_child_iterator(), const_child_iterator());
1754 static bool classof(const OMPClause *T) {
1755 return T->getClauseKind() == OMPC_write;
1759 /// This represents 'update' clause in the '#pragma omp atomic'
1763 /// #pragma omp atomic update
1765 /// In this example directive '#pragma omp atomic' has 'update' clause.
1766 /// Also, this class represents 'update' clause in '#pragma omp depobj'
1770 /// #pragma omp depobj(a) update(in)
1772 /// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
1773 /// dependence kind.
1774 class OMPUpdateClause final
1776 private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
1777 OpenMPDependClauseKind> {
1778 friend class OMPClauseReader;
1779 friend TrailingObjects;
1781 /// true if extended version of the clause for 'depobj' directive.
1782 bool IsExtended = false;
1784 /// Define the sizes of each trailing object array except the last one. This
1785 /// is required for TrailingObjects to work properly.
1786 size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
1787 // 2 locations: for '(' and argument location.
1788 return IsExtended ? 2 : 0;
1791 /// Sets the the location of '(' in clause for 'depobj' directive.
1792 void setLParenLoc(SourceLocation Loc) {
1793 assert(IsExtended && "Expected extended clause.");
1794 *getTrailingObjects<SourceLocation>() = Loc;
1797 /// Sets the the location of '(' in clause for 'depobj' directive.
1798 void setArgumentLoc(SourceLocation Loc) {
1799 assert(IsExtended && "Expected extended clause.");
1800 *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
1803 /// Sets the dependence kind for the clause for 'depobj' directive.
1804 void setDependencyKind(OpenMPDependClauseKind DK) {
1805 assert(IsExtended && "Expected extended clause.");
1806 *getTrailingObjects<OpenMPDependClauseKind>() = DK;
1809 /// Build 'update' clause.
1811 /// \param StartLoc Starting location of the clause.
1812 /// \param EndLoc Ending location of the clause.
1813 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
1815 : OMPClause(OMPC_update, StartLoc, EndLoc), IsExtended(IsExtended) {}
1817 /// Build an empty clause.
1818 OMPUpdateClause(bool IsExtended)
1819 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()),
1820 IsExtended(IsExtended) {}
1823 /// Creates clause for 'atomic' directive.
1825 /// \param C AST context.
1826 /// \param StartLoc Starting location of the clause.
1827 /// \param EndLoc Ending location of the clause.
1828 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1829 SourceLocation EndLoc);
1831 /// Creates clause for 'depobj' directive.
1833 /// \param C AST context.
1834 /// \param StartLoc Starting location of the clause.
1835 /// \param LParenLoc Location of '('.
1836 /// \param ArgumentLoc Location of the argument.
1837 /// \param DK Dependence kind.
1838 /// \param EndLoc Ending location of the clause.
1839 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1840 SourceLocation LParenLoc,
1841 SourceLocation ArgumentLoc,
1842 OpenMPDependClauseKind DK,
1843 SourceLocation EndLoc);
1845 /// Creates an empty clause with the place for \a N variables.
1847 /// \param C AST context.
1848 /// \param IsExtended true if extended clause for 'depobj' directive must be
1850 static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
1852 /// Checks if the clause is the extended clauses for 'depobj' directive.
1853 bool isExtended() const { return IsExtended; }
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 /// Gets the the location of '(' in clause for 'depobj' directive.
1871 SourceLocation getLParenLoc() const {
1872 assert(IsExtended && "Expected extended clause.");
1873 return *getTrailingObjects<SourceLocation>();
1876 /// Gets the the location of argument in clause for 'depobj' directive.
1877 SourceLocation getArgumentLoc() const {
1878 assert(IsExtended && "Expected extended clause.");
1879 return *std::next(getTrailingObjects<SourceLocation>(), 1);
1882 /// Gets the dependence kind in clause for 'depobj' directive.
1883 OpenMPDependClauseKind getDependencyKind() const {
1884 assert(IsExtended && "Expected extended clause.");
1885 return *getTrailingObjects<OpenMPDependClauseKind>();
1888 static bool classof(const OMPClause *T) {
1889 return T->getClauseKind() == OMPC_update;
1893 /// This represents 'capture' clause in the '#pragma omp atomic'
1897 /// #pragma omp atomic capture
1899 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1900 class OMPCaptureClause : public OMPClause {
1902 /// Build 'capture' clause.
1904 /// \param StartLoc Starting location of the clause.
1905 /// \param EndLoc Ending location of the clause.
1906 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1907 : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1909 /// Build an empty clause.
1911 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1913 child_range children() {
1914 return child_range(child_iterator(), child_iterator());
1917 const_child_range children() const {
1918 return const_child_range(const_child_iterator(), const_child_iterator());
1921 child_range used_children() {
1922 return child_range(child_iterator(), child_iterator());
1924 const_child_range used_children() const {
1925 return const_child_range(const_child_iterator(), const_child_iterator());
1928 static bool classof(const OMPClause *T) {
1929 return T->getClauseKind() == OMPC_capture;
1933 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
1937 /// #pragma omp atomic seq_cst
1939 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1940 class OMPSeqCstClause : public OMPClause {
1942 /// Build 'seq_cst' clause.
1944 /// \param StartLoc Starting location of the clause.
1945 /// \param EndLoc Ending location of the clause.
1946 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1947 : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1949 /// Build an empty clause.
1951 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1953 child_range children() {
1954 return child_range(child_iterator(), child_iterator());
1957 const_child_range children() const {
1958 return const_child_range(const_child_iterator(), const_child_iterator());
1961 child_range used_children() {
1962 return child_range(child_iterator(), child_iterator());
1964 const_child_range used_children() const {
1965 return const_child_range(const_child_iterator(), const_child_iterator());
1968 static bool classof(const OMPClause *T) {
1969 return T->getClauseKind() == OMPC_seq_cst;
1973 /// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
1977 /// #pragma omp flush acq_rel
1979 /// In this example directive '#pragma omp flush' has 'acq_rel' clause.
1980 class OMPAcqRelClause final : public OMPClause {
1982 /// Build 'ack_rel' clause.
1984 /// \param StartLoc Starting location of the clause.
1985 /// \param EndLoc Ending location of the clause.
1986 OMPAcqRelClause(SourceLocation StartLoc, SourceLocation EndLoc)
1987 : OMPClause(OMPC_acq_rel, StartLoc, EndLoc) {}
1989 /// Build an empty clause.
1991 : OMPClause(OMPC_acq_rel, SourceLocation(), SourceLocation()) {}
1993 child_range children() {
1994 return child_range(child_iterator(), child_iterator());
1997 const_child_range children() const {
1998 return const_child_range(const_child_iterator(), const_child_iterator());
2001 child_range used_children() {
2002 return child_range(child_iterator(), child_iterator());
2004 const_child_range used_children() const {
2005 return const_child_range(const_child_iterator(), const_child_iterator());
2008 static bool classof(const OMPClause *T) {
2009 return T->getClauseKind() == OMPC_acq_rel;
2013 /// This represents 'acquire' clause in the '#pragma omp atomic|flush'
2017 /// #pragma omp flush acquire
2019 /// In this example directive '#pragma omp flush' has 'acquire' clause.
2020 class OMPAcquireClause final : public OMPClause {
2022 /// Build 'acquire' clause.
2024 /// \param StartLoc Starting location of the clause.
2025 /// \param EndLoc Ending location of the clause.
2026 OMPAcquireClause(SourceLocation StartLoc, SourceLocation EndLoc)
2027 : OMPClause(OMPC_acquire, StartLoc, EndLoc) {}
2029 /// Build an empty clause.
2031 : OMPClause(OMPC_acquire, SourceLocation(), SourceLocation()) {}
2033 child_range children() {
2034 return child_range(child_iterator(), child_iterator());
2037 const_child_range children() const {
2038 return const_child_range(const_child_iterator(), const_child_iterator());
2041 child_range used_children() {
2042 return child_range(child_iterator(), child_iterator());
2044 const_child_range used_children() const {
2045 return const_child_range(const_child_iterator(), const_child_iterator());
2048 static bool classof(const OMPClause *T) {
2049 return T->getClauseKind() == OMPC_acquire;
2053 /// This represents 'release' clause in the '#pragma omp atomic|flush'
2057 /// #pragma omp flush release
2059 /// In this example directive '#pragma omp flush' has 'release' clause.
2060 class OMPReleaseClause final : public OMPClause {
2062 /// Build 'release' clause.
2064 /// \param StartLoc Starting location of the clause.
2065 /// \param EndLoc Ending location of the clause.
2066 OMPReleaseClause(SourceLocation StartLoc, SourceLocation EndLoc)
2067 : OMPClause(OMPC_release, StartLoc, EndLoc) {}
2069 /// Build an empty clause.
2071 : OMPClause(OMPC_release, SourceLocation(), SourceLocation()) {}
2073 child_range children() {
2074 return child_range(child_iterator(), child_iterator());
2077 const_child_range children() const {
2078 return const_child_range(const_child_iterator(), const_child_iterator());
2081 child_range used_children() {
2082 return child_range(child_iterator(), child_iterator());
2084 const_child_range used_children() const {
2085 return const_child_range(const_child_iterator(), const_child_iterator());
2088 static bool classof(const OMPClause *T) {
2089 return T->getClauseKind() == OMPC_release;
2093 /// This represents 'relaxed' clause in the '#pragma omp atomic'
2097 /// #pragma omp atomic relaxed
2099 /// In this example directive '#pragma omp atomic' has 'relaxed' clause.
2100 class OMPRelaxedClause final : public OMPClause {
2102 /// Build 'relaxed' clause.
2104 /// \param StartLoc Starting location of the clause.
2105 /// \param EndLoc Ending location of the clause.
2106 OMPRelaxedClause(SourceLocation StartLoc, SourceLocation EndLoc)
2107 : OMPClause(OMPC_relaxed, StartLoc, EndLoc) {}
2109 /// Build an empty clause.
2111 : OMPClause(OMPC_relaxed, SourceLocation(), SourceLocation()) {}
2113 child_range children() {
2114 return child_range(child_iterator(), child_iterator());
2117 const_child_range children() const {
2118 return const_child_range(const_child_iterator(), const_child_iterator());
2121 child_range used_children() {
2122 return child_range(child_iterator(), child_iterator());
2124 const_child_range used_children() const {
2125 return const_child_range(const_child_iterator(), const_child_iterator());
2128 static bool classof(const OMPClause *T) {
2129 return T->getClauseKind() == OMPC_relaxed;
2133 /// This represents clause 'private' in the '#pragma omp ...' directives.
2136 /// #pragma omp parallel private(a,b)
2138 /// In this example directive '#pragma omp parallel' has clause 'private'
2139 /// with the variables 'a' and 'b'.
2140 class OMPPrivateClause final
2141 : public OMPVarListClause<OMPPrivateClause>,
2142 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2143 friend class OMPClauseReader;
2144 friend OMPVarListClause;
2145 friend TrailingObjects;
2147 /// Build clause with number of variables \a N.
2149 /// \param StartLoc Starting location of the clause.
2150 /// \param LParenLoc Location of '('.
2151 /// \param EndLoc Ending location of the clause.
2152 /// \param N Number of the variables in the clause.
2153 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2154 SourceLocation EndLoc, unsigned N)
2155 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
2158 /// Build an empty clause.
2160 /// \param N Number of variables.
2161 explicit OMPPrivateClause(unsigned N)
2162 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
2163 SourceLocation(), SourceLocation(),
2166 /// Sets the list of references to private copies with initializers for
2167 /// new private variables.
2168 /// \param VL List of references.
2169 void setPrivateCopies(ArrayRef<Expr *> VL);
2171 /// Gets the list of references to private copies with initializers for
2172 /// new private variables.
2173 MutableArrayRef<Expr *> getPrivateCopies() {
2174 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2176 ArrayRef<const Expr *> getPrivateCopies() const {
2177 return llvm::makeArrayRef(varlist_end(), varlist_size());
2181 /// Creates clause with a list of variables \a VL.
2183 /// \param C AST context.
2184 /// \param StartLoc Starting location of the clause.
2185 /// \param LParenLoc Location of '('.
2186 /// \param EndLoc Ending location of the clause.
2187 /// \param VL List of references to the variables.
2188 /// \param PrivateVL List of references to private copies with initializers.
2189 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2190 SourceLocation LParenLoc,
2191 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2192 ArrayRef<Expr *> PrivateVL);
2194 /// Creates an empty clause with the place for \a N variables.
2196 /// \param C AST context.
2197 /// \param N The number of variables.
2198 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2200 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
2201 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
2202 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2203 using private_copies_const_range =
2204 llvm::iterator_range<private_copies_const_iterator>;
2206 private_copies_range private_copies() {
2207 return private_copies_range(getPrivateCopies().begin(),
2208 getPrivateCopies().end());
2211 private_copies_const_range private_copies() const {
2212 return private_copies_const_range(getPrivateCopies().begin(),
2213 getPrivateCopies().end());
2216 child_range children() {
2217 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2218 reinterpret_cast<Stmt **>(varlist_end()));
2221 const_child_range children() const {
2222 auto Children = const_cast<OMPPrivateClause *>(this)->children();
2223 return const_child_range(Children.begin(), Children.end());
2226 child_range used_children() {
2227 return child_range(child_iterator(), child_iterator());
2229 const_child_range used_children() const {
2230 return const_child_range(const_child_iterator(), const_child_iterator());
2233 static bool classof(const OMPClause *T) {
2234 return T->getClauseKind() == OMPC_private;
2238 /// This represents clause 'firstprivate' in the '#pragma omp ...'
2242 /// #pragma omp parallel firstprivate(a,b)
2244 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2245 /// with the variables 'a' and 'b'.
2246 class OMPFirstprivateClause final
2247 : public OMPVarListClause<OMPFirstprivateClause>,
2248 public OMPClauseWithPreInit,
2249 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2250 friend class OMPClauseReader;
2251 friend OMPVarListClause;
2252 friend TrailingObjects;
2254 /// Build clause with number of variables \a N.
2256 /// \param StartLoc Starting location of the clause.
2257 /// \param LParenLoc Location of '('.
2258 /// \param EndLoc Ending location of the clause.
2259 /// \param N Number of the variables in the clause.
2260 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2261 SourceLocation EndLoc, unsigned N)
2262 : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
2263 LParenLoc, EndLoc, N),
2264 OMPClauseWithPreInit(this) {}
2266 /// Build an empty clause.
2268 /// \param N Number of variables.
2269 explicit OMPFirstprivateClause(unsigned N)
2270 : OMPVarListClause<OMPFirstprivateClause>(
2271 OMPC_firstprivate, SourceLocation(), SourceLocation(),
2272 SourceLocation(), N),
2273 OMPClauseWithPreInit(this) {}
2275 /// Sets the list of references to private copies with initializers for
2276 /// new private variables.
2277 /// \param VL List of references.
2278 void setPrivateCopies(ArrayRef<Expr *> VL);
2280 /// Gets the list of references to private copies with initializers for
2281 /// new private variables.
2282 MutableArrayRef<Expr *> getPrivateCopies() {
2283 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2285 ArrayRef<const Expr *> getPrivateCopies() const {
2286 return llvm::makeArrayRef(varlist_end(), varlist_size());
2289 /// Sets the list of references to initializer variables for new
2290 /// private variables.
2291 /// \param VL List of references.
2292 void setInits(ArrayRef<Expr *> VL);
2294 /// Gets the list of references to initializer variables for new
2295 /// private variables.
2296 MutableArrayRef<Expr *> getInits() {
2297 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2299 ArrayRef<const Expr *> getInits() const {
2300 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2304 /// Creates clause with a list of variables \a VL.
2306 /// \param C AST context.
2307 /// \param StartLoc Starting location of the clause.
2308 /// \param LParenLoc Location of '('.
2309 /// \param EndLoc Ending location of the clause.
2310 /// \param VL List of references to the original variables.
2311 /// \param PrivateVL List of references to private copies with initializers.
2312 /// \param InitVL List of references to auto generated variables used for
2313 /// initialization of a single array element. Used if firstprivate variable is
2315 /// \param PreInit Statement that must be executed before entering the OpenMP
2316 /// region with this clause.
2317 static OMPFirstprivateClause *
2318 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2319 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2320 ArrayRef<Expr *> InitVL, Stmt *PreInit);
2322 /// Creates an empty clause with the place for \a N variables.
2324 /// \param C AST context.
2325 /// \param N The number of variables.
2326 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2328 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
2329 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
2330 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2331 using private_copies_const_range =
2332 llvm::iterator_range<private_copies_const_iterator>;
2334 private_copies_range private_copies() {
2335 return private_copies_range(getPrivateCopies().begin(),
2336 getPrivateCopies().end());
2338 private_copies_const_range private_copies() const {
2339 return private_copies_const_range(getPrivateCopies().begin(),
2340 getPrivateCopies().end());
2343 using inits_iterator = MutableArrayRef<Expr *>::iterator;
2344 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
2345 using inits_range = llvm::iterator_range<inits_iterator>;
2346 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2348 inits_range inits() {
2349 return inits_range(getInits().begin(), getInits().end());
2351 inits_const_range inits() const {
2352 return inits_const_range(getInits().begin(), getInits().end());
2355 child_range children() {
2356 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2357 reinterpret_cast<Stmt **>(varlist_end()));
2360 const_child_range children() const {
2361 auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2362 return const_child_range(Children.begin(), Children.end());
2365 child_range used_children() {
2366 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2367 reinterpret_cast<Stmt **>(varlist_end()));
2369 const_child_range used_children() const {
2370 auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2371 return const_child_range(Children.begin(), Children.end());
2374 static bool classof(const OMPClause *T) {
2375 return T->getClauseKind() == OMPC_firstprivate;
2379 /// This represents clause 'lastprivate' in the '#pragma omp ...'
2383 /// #pragma omp simd lastprivate(a,b)
2385 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
2386 /// with the variables 'a' and 'b'.
2387 class OMPLastprivateClause final
2388 : public OMPVarListClause<OMPLastprivateClause>,
2389 public OMPClauseWithPostUpdate,
2390 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2391 // There are 4 additional tail-allocated arrays at the end of the class:
2392 // 1. Contains list of pseudo variables with the default initialization for
2393 // each non-firstprivate variables. Used in codegen for initialization of
2394 // lastprivate copies.
2395 // 2. List of helper expressions for proper generation of assignment operation
2396 // required for lastprivate clause. This list represents private variables
2397 // (for arrays, single array element).
2398 // 3. List of helper expressions for proper generation of assignment operation
2399 // required for lastprivate clause. This list represents original variables
2400 // (for arrays, single array element).
2401 // 4. List of helper expressions that represents assignment operation:
2403 // DstExprs = SrcExprs;
2405 // Required for proper codegen of final assignment performed by the
2406 // lastprivate clause.
2407 friend class OMPClauseReader;
2408 friend OMPVarListClause;
2409 friend TrailingObjects;
2411 /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2412 OpenMPLastprivateModifier LPKind;
2413 /// Optional location of the lasptrivate kind, if specified by user.
2414 SourceLocation LPKindLoc;
2415 /// Optional colon location, if specified by user.
2416 SourceLocation ColonLoc;
2418 /// Build clause with number of variables \a N.
2420 /// \param StartLoc Starting location of the clause.
2421 /// \param LParenLoc Location of '('.
2422 /// \param EndLoc Ending location of the clause.
2423 /// \param N Number of the variables in the clause.
2424 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2425 SourceLocation EndLoc, OpenMPLastprivateModifier LPKind,
2426 SourceLocation LPKindLoc, SourceLocation ColonLoc,
2428 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
2429 LParenLoc, EndLoc, N),
2430 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2431 ColonLoc(ColonLoc) {}
2433 /// Build an empty clause.
2435 /// \param N Number of variables.
2436 explicit OMPLastprivateClause(unsigned N)
2437 : OMPVarListClause<OMPLastprivateClause>(
2438 OMPC_lastprivate, SourceLocation(), SourceLocation(),
2439 SourceLocation(), N),
2440 OMPClauseWithPostUpdate(this) {}
2442 /// Get the list of helper expressions for initialization of private
2443 /// copies for lastprivate variables.
2444 MutableArrayRef<Expr *> getPrivateCopies() {
2445 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2447 ArrayRef<const Expr *> getPrivateCopies() const {
2448 return llvm::makeArrayRef(varlist_end(), varlist_size());
2451 /// Set list of helper expressions, required for proper codegen of the
2452 /// clause. These expressions represent private variables (for arrays, single
2453 /// array element) in the final assignment statement performed by the
2454 /// lastprivate clause.
2455 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2457 /// Get the list of helper source expressions.
2458 MutableArrayRef<Expr *> getSourceExprs() {
2459 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2461 ArrayRef<const Expr *> getSourceExprs() const {
2462 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2465 /// Set list of helper expressions, required for proper codegen of the
2466 /// clause. These expressions represent original variables (for arrays, single
2467 /// array element) in the final assignment statement performed by the
2468 /// lastprivate clause.
2469 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2471 /// Get the list of helper destination expressions.
2472 MutableArrayRef<Expr *> getDestinationExprs() {
2473 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2475 ArrayRef<const Expr *> getDestinationExprs() const {
2476 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2479 /// Set list of helper assignment expressions, required for proper
2480 /// codegen of the clause. These expressions are assignment expressions that
2481 /// assign private copy of the variable to original variable.
2482 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2484 /// Get the list of helper assignment expressions.
2485 MutableArrayRef<Expr *> getAssignmentOps() {
2486 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2488 ArrayRef<const Expr *> getAssignmentOps() const {
2489 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2492 /// Sets lastprivate kind.
2493 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
2494 /// Sets location of the lastprivate kind.
2495 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
2496 /// Sets colon symbol location.
2497 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2500 /// Creates clause with a list of variables \a VL.
2502 /// \param C AST context.
2503 /// \param StartLoc Starting location of the clause.
2504 /// \param LParenLoc Location of '('.
2505 /// \param EndLoc Ending location of the clause.
2506 /// \param VL List of references to the variables.
2507 /// \param SrcExprs List of helper expressions for proper generation of
2508 /// assignment operation required for lastprivate clause. This list represents
2509 /// private variables (for arrays, single array element).
2510 /// \param DstExprs List of helper expressions for proper generation of
2511 /// assignment operation required for lastprivate clause. This list represents
2512 /// original variables (for arrays, single array element).
2513 /// \param AssignmentOps List of helper expressions that represents assignment
2516 /// DstExprs = SrcExprs;
2518 /// Required for proper codegen of final assignment performed by the
2519 /// lastprivate clause.
2520 /// \param LPKind Lastprivate kind, e.g. 'conditional'.
2521 /// \param LPKindLoc Location of the lastprivate kind.
2522 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
2523 /// \param PreInit Statement that must be executed before entering the OpenMP
2524 /// region with this clause.
2525 /// \param PostUpdate Expression that must be executed after exit from the
2526 /// OpenMP region with this clause.
2527 static OMPLastprivateClause *
2528 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2529 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2530 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2531 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
2532 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
2534 /// Creates an empty clause with the place for \a N variables.
2536 /// \param C AST context.
2537 /// \param N The number of variables.
2538 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2540 /// Lastprivate kind.
2541 OpenMPLastprivateModifier getKind() const { return LPKind; }
2542 /// Returns the location of the lastprivate kind.
2543 SourceLocation getKindLoc() const { return LPKindLoc; }
2544 /// Returns the location of the ':' symbol, if any.
2545 SourceLocation getColonLoc() const { return ColonLoc; }
2547 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2548 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2549 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2550 using helper_expr_const_range =
2551 llvm::iterator_range<helper_expr_const_iterator>;
2553 /// Set list of helper expressions, required for generation of private
2554 /// copies of original lastprivate variables.
2555 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2557 helper_expr_const_range private_copies() const {
2558 return helper_expr_const_range(getPrivateCopies().begin(),
2559 getPrivateCopies().end());
2562 helper_expr_range private_copies() {
2563 return helper_expr_range(getPrivateCopies().begin(),
2564 getPrivateCopies().end());
2567 helper_expr_const_range source_exprs() const {
2568 return helper_expr_const_range(getSourceExprs().begin(),
2569 getSourceExprs().end());
2572 helper_expr_range source_exprs() {
2573 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2576 helper_expr_const_range destination_exprs() const {
2577 return helper_expr_const_range(getDestinationExprs().begin(),
2578 getDestinationExprs().end());
2581 helper_expr_range destination_exprs() {
2582 return helper_expr_range(getDestinationExprs().begin(),
2583 getDestinationExprs().end());
2586 helper_expr_const_range assignment_ops() const {
2587 return helper_expr_const_range(getAssignmentOps().begin(),
2588 getAssignmentOps().end());
2591 helper_expr_range assignment_ops() {
2592 return helper_expr_range(getAssignmentOps().begin(),
2593 getAssignmentOps().end());
2596 child_range children() {
2597 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2598 reinterpret_cast<Stmt **>(varlist_end()));
2601 const_child_range children() const {
2602 auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2603 return const_child_range(Children.begin(), Children.end());
2606 child_range used_children() {
2607 return child_range(child_iterator(), child_iterator());
2609 const_child_range used_children() const {
2610 return const_child_range(const_child_iterator(), const_child_iterator());
2613 static bool classof(const OMPClause *T) {
2614 return T->getClauseKind() == OMPC_lastprivate;
2618 /// This represents clause 'shared' in the '#pragma omp ...' directives.
2621 /// #pragma omp parallel shared(a,b)
2623 /// In this example directive '#pragma omp parallel' has clause 'shared'
2624 /// with the variables 'a' and 'b'.
2625 class OMPSharedClause final
2626 : public OMPVarListClause<OMPSharedClause>,
2627 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
2628 friend OMPVarListClause;
2629 friend TrailingObjects;
2631 /// Build clause with number of variables \a N.
2633 /// \param StartLoc Starting location of the clause.
2634 /// \param LParenLoc Location of '('.
2635 /// \param EndLoc Ending location of the clause.
2636 /// \param N Number of the variables in the clause.
2637 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2638 SourceLocation EndLoc, unsigned N)
2639 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
2642 /// Build an empty clause.
2644 /// \param N Number of variables.
2645 explicit OMPSharedClause(unsigned N)
2646 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
2647 SourceLocation(), SourceLocation(),
2651 /// Creates clause with a list of variables \a VL.
2653 /// \param C AST context.
2654 /// \param StartLoc Starting location of the clause.
2655 /// \param LParenLoc Location of '('.
2656 /// \param EndLoc Ending location of the clause.
2657 /// \param VL List of references to the variables.
2658 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2659 SourceLocation LParenLoc,
2660 SourceLocation EndLoc, ArrayRef<Expr *> VL);
2662 /// Creates an empty clause with \a N variables.
2664 /// \param C AST context.
2665 /// \param N The number of variables.
2666 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
2668 child_range children() {
2669 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2670 reinterpret_cast<Stmt **>(varlist_end()));
2673 const_child_range children() const {
2674 auto Children = const_cast<OMPSharedClause *>(this)->children();
2675 return const_child_range(Children.begin(), Children.end());
2678 child_range used_children() {
2679 return child_range(child_iterator(), child_iterator());
2681 const_child_range used_children() const {
2682 return const_child_range(const_child_iterator(), const_child_iterator());
2685 static bool classof(const OMPClause *T) {
2686 return T->getClauseKind() == OMPC_shared;
2690 /// This represents clause 'reduction' in the '#pragma omp ...'
2694 /// #pragma omp parallel reduction(+:a,b)
2696 /// In this example directive '#pragma omp parallel' has clause 'reduction'
2697 /// with operator '+' and the variables 'a' and 'b'.
2698 class OMPReductionClause final
2699 : public OMPVarListClause<OMPReductionClause>,
2700 public OMPClauseWithPostUpdate,
2701 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
2702 friend class OMPClauseReader;
2703 friend OMPVarListClause;
2704 friend TrailingObjects;
2706 /// Location of ':'.
2707 SourceLocation ColonLoc;
2709 /// Nested name specifier for C++.
2710 NestedNameSpecifierLoc QualifierLoc;
2712 /// Name of custom operator.
2713 DeclarationNameInfo NameInfo;
2715 /// Build clause with number of variables \a N.
2717 /// \param StartLoc Starting location of the clause.
2718 /// \param LParenLoc Location of '('.
2719 /// \param EndLoc Ending location of the clause.
2720 /// \param ColonLoc Location of ':'.
2721 /// \param N Number of the variables in the clause.
2722 /// \param QualifierLoc The nested-name qualifier with location information
2723 /// \param NameInfo The full name info for reduction identifier.
2724 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2725 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
2726 NestedNameSpecifierLoc QualifierLoc,
2727 const DeclarationNameInfo &NameInfo)
2728 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
2729 LParenLoc, EndLoc, N),
2730 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2731 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2733 /// Build an empty clause.
2735 /// \param N Number of variables.
2736 explicit OMPReductionClause(unsigned N)
2737 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
2738 SourceLocation(), SourceLocation(),
2740 OMPClauseWithPostUpdate(this) {}
2742 /// Sets location of ':' symbol in clause.
2743 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2745 /// Sets the name info for specified reduction identifier.
2746 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2748 /// Sets the nested name specifier.
2749 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2751 /// Set list of helper expressions, required for proper codegen of the
2752 /// clause. These expressions represent private copy of the reduction
2754 void setPrivates(ArrayRef<Expr *> Privates);
2756 /// Get the list of helper privates.
2757 MutableArrayRef<Expr *> getPrivates() {
2758 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2760 ArrayRef<const Expr *> getPrivates() const {
2761 return llvm::makeArrayRef(varlist_end(), varlist_size());
2764 /// Set list of helper expressions, required for proper codegen of the
2765 /// clause. These expressions represent LHS expression in the final
2766 /// reduction expression performed by the reduction clause.
2767 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2769 /// Get the list of helper LHS expressions.
2770 MutableArrayRef<Expr *> getLHSExprs() {
2771 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2773 ArrayRef<const Expr *> getLHSExprs() const {
2774 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2777 /// Set list of helper expressions, required for proper codegen of the
2778 /// clause. These expressions represent RHS expression in the final
2779 /// reduction expression performed by the reduction clause.
2780 /// Also, variables in these expressions are used for proper initialization of
2781 /// reduction copies.
2782 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2784 /// Get the list of helper destination expressions.
2785 MutableArrayRef<Expr *> getRHSExprs() {
2786 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2788 ArrayRef<const Expr *> getRHSExprs() const {
2789 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2792 /// Set list of helper reduction expressions, required for proper
2793 /// codegen of the clause. These expressions are binary expressions or
2794 /// operator/custom reduction call that calculates new value from source
2795 /// helper expressions to destination helper expressions.
2796 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2798 /// Get the list of helper reduction expressions.
2799 MutableArrayRef<Expr *> getReductionOps() {
2800 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2802 ArrayRef<const Expr *> getReductionOps() const {
2803 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2807 /// Creates clause with a list of variables \a VL.
2809 /// \param StartLoc Starting location of the clause.
2810 /// \param LParenLoc Location of '('.
2811 /// \param ColonLoc Location of ':'.
2812 /// \param EndLoc Ending location of the clause.
2813 /// \param VL The variables in the clause.
2814 /// \param QualifierLoc The nested-name qualifier with location information
2815 /// \param NameInfo The full name info for reduction identifier.
2816 /// \param Privates List of helper expressions for proper generation of
2818 /// \param LHSExprs List of helper expressions for proper generation of
2819 /// assignment operation required for copyprivate clause. This list represents
2820 /// LHSs of the reduction expressions.
2821 /// \param RHSExprs List of helper expressions for proper generation of
2822 /// assignment operation required for copyprivate clause. This list represents
2823 /// RHSs of the reduction expressions.
2824 /// Also, variables in these expressions are used for proper initialization of
2825 /// reduction copies.
2826 /// \param ReductionOps List of helper expressions that represents reduction
2829 /// LHSExprs binop RHSExprs;
2830 /// operator binop(LHSExpr, RHSExpr);
2831 /// <CutomReduction>(LHSExpr, RHSExpr);
2833 /// Required for proper codegen of final reduction operation performed by the
2834 /// reduction clause.
2835 /// \param PreInit Statement that must be executed before entering the OpenMP
2836 /// region with this clause.
2837 /// \param PostUpdate Expression that must be executed after exit from the
2838 /// OpenMP region with this clause.
2839 static OMPReductionClause *
2840 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2841 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2842 NestedNameSpecifierLoc QualifierLoc,
2843 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2844 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2845 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2847 /// Creates an empty clause with the place for \a N variables.
2849 /// \param C AST context.
2850 /// \param N The number of variables.
2851 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2853 /// Gets location of ':' symbol in clause.
2854 SourceLocation getColonLoc() const { return ColonLoc; }
2856 /// Gets the name info for specified reduction identifier.
2857 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2859 /// Gets the nested name specifier.
2860 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2862 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2863 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2864 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2865 using helper_expr_const_range =
2866 llvm::iterator_range<helper_expr_const_iterator>;
2868 helper_expr_const_range privates() const {
2869 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2872 helper_expr_range privates() {
2873 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2876 helper_expr_const_range lhs_exprs() const {
2877 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2880 helper_expr_range lhs_exprs() {
2881 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2884 helper_expr_const_range rhs_exprs() const {
2885 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2888 helper_expr_range rhs_exprs() {
2889 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2892 helper_expr_const_range reduction_ops() const {
2893 return helper_expr_const_range(getReductionOps().begin(),
2894 getReductionOps().end());
2897 helper_expr_range reduction_ops() {
2898 return helper_expr_range(getReductionOps().begin(),
2899 getReductionOps().end());
2902 child_range children() {
2903 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2904 reinterpret_cast<Stmt **>(varlist_end()));
2907 const_child_range children() const {
2908 auto Children = const_cast<OMPReductionClause *>(this)->children();
2909 return const_child_range(Children.begin(), Children.end());
2912 child_range used_children() {
2913 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2914 reinterpret_cast<Stmt **>(varlist_end()));
2916 const_child_range used_children() const {
2917 auto Children = const_cast<OMPReductionClause *>(this)->used_children();
2918 return const_child_range(Children.begin(), Children.end());
2921 static bool classof(const OMPClause *T) {
2922 return T->getClauseKind() == OMPC_reduction;
2926 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
2930 /// #pragma omp taskgroup task_reduction(+:a,b)
2932 /// In this example directive '#pragma omp taskgroup' has clause
2933 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
2934 class OMPTaskReductionClause final
2935 : public OMPVarListClause<OMPTaskReductionClause>,
2936 public OMPClauseWithPostUpdate,
2937 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
2938 friend class OMPClauseReader;
2939 friend OMPVarListClause;
2940 friend TrailingObjects;
2942 /// Location of ':'.
2943 SourceLocation ColonLoc;
2945 /// Nested name specifier for C++.
2946 NestedNameSpecifierLoc QualifierLoc;
2948 /// Name of custom operator.
2949 DeclarationNameInfo NameInfo;
2951 /// Build clause with number of variables \a N.
2953 /// \param StartLoc Starting location of the clause.
2954 /// \param LParenLoc Location of '('.
2955 /// \param EndLoc Ending location of the clause.
2956 /// \param ColonLoc Location of ':'.
2957 /// \param N Number of the variables in the clause.
2958 /// \param QualifierLoc The nested-name qualifier with location information
2959 /// \param NameInfo The full name info for reduction identifier.
2960 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2961 SourceLocation ColonLoc, SourceLocation EndLoc,
2962 unsigned N, NestedNameSpecifierLoc QualifierLoc,
2963 const DeclarationNameInfo &NameInfo)
2964 : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
2965 LParenLoc, EndLoc, N),
2966 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2967 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2969 /// Build an empty clause.
2971 /// \param N Number of variables.
2972 explicit OMPTaskReductionClause(unsigned N)
2973 : OMPVarListClause<OMPTaskReductionClause>(
2974 OMPC_task_reduction, SourceLocation(), SourceLocation(),
2975 SourceLocation(), N),
2976 OMPClauseWithPostUpdate(this) {}
2978 /// Sets location of ':' symbol in clause.
2979 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2981 /// Sets the name info for specified reduction identifier.
2982 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2984 /// Sets the nested name specifier.
2985 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2987 /// Set list of helper expressions, required for proper codegen of the clause.
2988 /// These expressions represent private copy of the reduction variable.
2989 void setPrivates(ArrayRef<Expr *> Privates);
2991 /// Get the list of helper privates.
2992 MutableArrayRef<Expr *> getPrivates() {
2993 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2995 ArrayRef<const Expr *> getPrivates() const {
2996 return llvm::makeArrayRef(varlist_end(), varlist_size());
2999 /// Set list of helper expressions, required for proper codegen of the clause.
3000 /// These expressions represent LHS expression in the final reduction
3001 /// expression performed by the reduction clause.
3002 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3004 /// Get the list of helper LHS expressions.
3005 MutableArrayRef<Expr *> getLHSExprs() {
3006 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3008 ArrayRef<const Expr *> getLHSExprs() const {
3009 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3012 /// Set list of helper expressions, required for proper codegen of the clause.
3013 /// These expressions represent RHS expression in the final reduction
3014 /// expression performed by the reduction clause. Also, variables in these
3015 /// expressions are used for proper initialization of reduction copies.
3016 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3018 /// Get the list of helper destination expressions.
3019 MutableArrayRef<Expr *> getRHSExprs() {
3020 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3022 ArrayRef<const Expr *> getRHSExprs() const {
3023 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3026 /// Set list of helper reduction expressions, required for proper
3027 /// codegen of the clause. These expressions are binary expressions or
3028 /// operator/custom reduction call that calculates new value from source
3029 /// helper expressions to destination helper expressions.
3030 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3032 /// Get the list of helper reduction expressions.
3033 MutableArrayRef<Expr *> getReductionOps() {
3034 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3036 ArrayRef<const Expr *> getReductionOps() const {
3037 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3041 /// Creates clause with a list of variables \a VL.
3043 /// \param StartLoc Starting location of the clause.
3044 /// \param LParenLoc Location of '('.
3045 /// \param ColonLoc Location of ':'.
3046 /// \param EndLoc Ending location of the clause.
3047 /// \param VL The variables in the clause.
3048 /// \param QualifierLoc The nested-name qualifier with location information
3049 /// \param NameInfo The full name info for reduction identifier.
3050 /// \param Privates List of helper expressions for proper generation of
3052 /// \param LHSExprs List of helper expressions for proper generation of
3053 /// assignment operation required for copyprivate clause. This list represents
3054 /// LHSs of the reduction expressions.
3055 /// \param RHSExprs List of helper expressions for proper generation of
3056 /// assignment operation required for copyprivate clause. This list represents
3057 /// RHSs of the reduction expressions.
3058 /// Also, variables in these expressions are used for proper initialization of
3059 /// reduction copies.
3060 /// \param ReductionOps List of helper expressions that represents reduction
3063 /// LHSExprs binop RHSExprs;
3064 /// operator binop(LHSExpr, RHSExpr);
3065 /// <CutomReduction>(LHSExpr, RHSExpr);
3067 /// Required for proper codegen of final reduction operation performed by the
3068 /// reduction clause.
3069 /// \param PreInit Statement that must be executed before entering the OpenMP
3070 /// region with this clause.
3071 /// \param PostUpdate Expression that must be executed after exit from the
3072 /// OpenMP region with this clause.
3073 static OMPTaskReductionClause *
3074 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3075 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3076 NestedNameSpecifierLoc QualifierLoc,
3077 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3078 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3079 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3081 /// Creates an empty clause with the place for \a N variables.
3083 /// \param C AST context.
3084 /// \param N The number of variables.
3085 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3087 /// Gets location of ':' symbol in clause.
3088 SourceLocation getColonLoc() const { return ColonLoc; }
3090 /// Gets the name info for specified reduction identifier.
3091 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3093 /// Gets the nested name specifier.
3094 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3096 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3097 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3098 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3099 using helper_expr_const_range =
3100 llvm::iterator_range<helper_expr_const_iterator>;
3102 helper_expr_const_range privates() const {
3103 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3106 helper_expr_range privates() {
3107 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3110 helper_expr_const_range lhs_exprs() const {
3111 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3114 helper_expr_range lhs_exprs() {
3115 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3118 helper_expr_const_range rhs_exprs() const {
3119 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3122 helper_expr_range rhs_exprs() {
3123 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3126 helper_expr_const_range reduction_ops() const {
3127 return helper_expr_const_range(getReductionOps().begin(),
3128 getReductionOps().end());
3131 helper_expr_range reduction_ops() {
3132 return helper_expr_range(getReductionOps().begin(),
3133 getReductionOps().end());
3136 child_range children() {
3137 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3138 reinterpret_cast<Stmt **>(varlist_end()));
3141 const_child_range children() const {
3142 auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3143 return const_child_range(Children.begin(), Children.end());
3146 child_range used_children() {
3147 return child_range(child_iterator(), child_iterator());
3149 const_child_range used_children() const {
3150 return const_child_range(const_child_iterator(), const_child_iterator());
3153 static bool classof(const OMPClause *T) {
3154 return T->getClauseKind() == OMPC_task_reduction;
3158 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
3161 /// #pragma omp task in_reduction(+:a,b)
3163 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
3164 /// operator '+' and the variables 'a' and 'b'.
3165 class OMPInReductionClause final
3166 : public OMPVarListClause<OMPInReductionClause>,
3167 public OMPClauseWithPostUpdate,
3168 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
3169 friend class OMPClauseReader;
3170 friend OMPVarListClause;
3171 friend TrailingObjects;
3173 /// Location of ':'.
3174 SourceLocation ColonLoc;
3176 /// Nested name specifier for C++.
3177 NestedNameSpecifierLoc QualifierLoc;
3179 /// Name of custom operator.
3180 DeclarationNameInfo NameInfo;
3182 /// Build clause with number of variables \a N.
3184 /// \param StartLoc Starting location of the clause.
3185 /// \param LParenLoc Location of '('.
3186 /// \param EndLoc Ending location of the clause.
3187 /// \param ColonLoc Location of ':'.
3188 /// \param N Number of the variables in the clause.
3189 /// \param QualifierLoc The nested-name qualifier with location information
3190 /// \param NameInfo The full name info for reduction identifier.
3191 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3192 SourceLocation ColonLoc, SourceLocation EndLoc,
3193 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3194 const DeclarationNameInfo &NameInfo)
3195 : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc,
3196 LParenLoc, EndLoc, N),
3197 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3198 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3200 /// Build an empty clause.
3202 /// \param N Number of variables.
3203 explicit OMPInReductionClause(unsigned N)
3204 : OMPVarListClause<OMPInReductionClause>(
3205 OMPC_in_reduction, SourceLocation(), SourceLocation(),
3206 SourceLocation(), N),
3207 OMPClauseWithPostUpdate(this) {}
3209 /// Sets location of ':' symbol in clause.
3210 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3212 /// Sets the name info for specified reduction identifier.
3213 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3215 /// Sets the nested name specifier.
3216 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3218 /// Set list of helper expressions, required for proper codegen of the clause.
3219 /// These expressions represent private copy of the reduction variable.
3220 void setPrivates(ArrayRef<Expr *> Privates);
3222 /// Get the list of helper privates.
3223 MutableArrayRef<Expr *> getPrivates() {
3224 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3226 ArrayRef<const Expr *> getPrivates() const {
3227 return llvm::makeArrayRef(varlist_end(), varlist_size());
3230 /// Set list of helper expressions, required for proper codegen of the clause.
3231 /// These expressions represent LHS expression in the final reduction
3232 /// expression performed by the reduction clause.
3233 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3235 /// Get the list of helper LHS expressions.
3236 MutableArrayRef<Expr *> getLHSExprs() {
3237 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3239 ArrayRef<const Expr *> getLHSExprs() const {
3240 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3243 /// Set list of helper expressions, required for proper codegen of the clause.
3244 /// These expressions represent RHS expression in the final reduction
3245 /// expression performed by the reduction clause. Also, variables in these
3246 /// expressions are used for proper initialization of reduction copies.
3247 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3249 /// Get the list of helper destination expressions.
3250 MutableArrayRef<Expr *> getRHSExprs() {
3251 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3253 ArrayRef<const Expr *> getRHSExprs() const {
3254 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3257 /// Set list of helper reduction expressions, required for proper
3258 /// codegen of the clause. These expressions are binary expressions or
3259 /// operator/custom reduction call that calculates new value from source
3260 /// helper expressions to destination helper expressions.
3261 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3263 /// Get the list of helper reduction expressions.
3264 MutableArrayRef<Expr *> getReductionOps() {
3265 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3267 ArrayRef<const Expr *> getReductionOps() const {
3268 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3271 /// Set list of helper reduction taskgroup descriptors.
3272 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3274 /// Get the list of helper reduction taskgroup descriptors.
3275 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3276 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3278 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3279 return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3283 /// Creates clause with a list of variables \a VL.
3285 /// \param StartLoc Starting location of the clause.
3286 /// \param LParenLoc Location of '('.
3287 /// \param ColonLoc Location of ':'.
3288 /// \param EndLoc Ending location of the clause.
3289 /// \param VL The variables in the clause.
3290 /// \param QualifierLoc The nested-name qualifier with location information
3291 /// \param NameInfo The full name info for reduction identifier.
3292 /// \param Privates List of helper expressions for proper generation of
3294 /// \param LHSExprs List of helper expressions for proper generation of
3295 /// assignment operation required for copyprivate clause. This list represents
3296 /// LHSs of the reduction expressions.
3297 /// \param RHSExprs List of helper expressions for proper generation of
3298 /// assignment operation required for copyprivate clause. This list represents
3299 /// RHSs of the reduction expressions.
3300 /// Also, variables in these expressions are used for proper initialization of
3301 /// reduction copies.
3302 /// \param ReductionOps List of helper expressions that represents reduction
3305 /// LHSExprs binop RHSExprs;
3306 /// operator binop(LHSExpr, RHSExpr);
3307 /// <CutomReduction>(LHSExpr, RHSExpr);
3309 /// Required for proper codegen of final reduction operation performed by the
3310 /// reduction clause.
3311 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3312 /// corresponding items in parent taskgroup task_reduction clause.
3313 /// \param PreInit Statement that must be executed before entering the OpenMP
3314 /// region with this clause.
3315 /// \param PostUpdate Expression that must be executed after exit from the
3316 /// OpenMP region with this clause.
3317 static OMPInReductionClause *
3318 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3319 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3320 NestedNameSpecifierLoc QualifierLoc,
3321 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3322 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3323 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3324 Stmt *PreInit, Expr *PostUpdate);
3326 /// Creates an empty clause with the place for \a N variables.
3328 /// \param C AST context.
3329 /// \param N The number of variables.
3330 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3332 /// Gets location of ':' symbol in clause.
3333 SourceLocation getColonLoc() const { return ColonLoc; }
3335 /// Gets the name info for specified reduction identifier.
3336 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3338 /// Gets the nested name specifier.
3339 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3341 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3342 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3343 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3344 using helper_expr_const_range =
3345 llvm::iterator_range<helper_expr_const_iterator>;
3347 helper_expr_const_range privates() const {
3348 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3351 helper_expr_range privates() {
3352 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3355 helper_expr_const_range lhs_exprs() const {
3356 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3359 helper_expr_range lhs_exprs() {
3360 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3363 helper_expr_const_range rhs_exprs() const {
3364 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3367 helper_expr_range rhs_exprs() {
3368 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3371 helper_expr_const_range reduction_ops() const {
3372 return helper_expr_const_range(getReductionOps().begin(),
3373 getReductionOps().end());
3376 helper_expr_range reduction_ops() {
3377 return helper_expr_range(getReductionOps().begin(),
3378 getReductionOps().end());
3381 helper_expr_const_range taskgroup_descriptors() const {
3382 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3383 getTaskgroupDescriptors().end());
3386 helper_expr_range taskgroup_descriptors() {
3387 return helper_expr_range(getTaskgroupDescriptors().begin(),
3388 getTaskgroupDescriptors().end());
3391 child_range children() {
3392 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3393 reinterpret_cast<Stmt **>(varlist_end()));
3396 const_child_range children() const {
3397 auto Children = const_cast<OMPInReductionClause *>(this)->children();
3398 return const_child_range(Children.begin(), Children.end());
3401 child_range used_children() {
3402 return child_range(child_iterator(), child_iterator());
3404 const_child_range used_children() const {
3405 return const_child_range(const_child_iterator(), const_child_iterator());
3408 static bool classof(const OMPClause *T) {
3409 return T->getClauseKind() == OMPC_in_reduction;
3413 /// This represents clause 'linear' in the '#pragma omp ...'
3417 /// #pragma omp simd linear(a,b : 2)
3419 /// In this example directive '#pragma omp simd' has clause 'linear'
3420 /// with variables 'a', 'b' and linear step '2'.
3421 class OMPLinearClause final
3422 : public OMPVarListClause<OMPLinearClause>,
3423 public OMPClauseWithPostUpdate,
3424 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
3425 friend class OMPClauseReader;
3426 friend OMPVarListClause;
3427 friend TrailingObjects;
3429 /// Modifier of 'linear' clause.
3430 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
3432 /// Location of linear modifier if any.
3433 SourceLocation ModifierLoc;
3435 /// Location of ':'.
3436 SourceLocation ColonLoc;
3438 /// Sets the linear step for clause.
3439 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
3441 /// Sets the expression to calculate linear step for clause.
3442 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
3444 /// Build 'linear' clause with given number of variables \a NumVars.
3446 /// \param StartLoc Starting location of the clause.
3447 /// \param LParenLoc Location of '('.
3448 /// \param ColonLoc Location of ':'.
3449 /// \param EndLoc Ending location of the clause.
3450 /// \param NumVars Number of variables.
3451 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3452 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3453 SourceLocation ColonLoc, SourceLocation EndLoc,
3455 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
3457 OMPClauseWithPostUpdate(this), Modifier(Modifier),
3458 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
3460 /// Build an empty clause.
3462 /// \param NumVars Number of variables.
3463 explicit OMPLinearClause(unsigned NumVars)
3464 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
3465 SourceLocation(), SourceLocation(),
3467 OMPClauseWithPostUpdate(this) {}
3469 /// Gets the list of initial values for linear variables.
3471 /// There are NumVars expressions with initial values allocated after the
3472 /// varlist, they are followed by NumVars update expressions (used to update
3473 /// the linear variable's value on current iteration) and they are followed by
3474 /// NumVars final expressions (used to calculate the linear variable's
3475 /// value after the loop body). After these lists, there are 2 helper
3476 /// expressions - linear step and a helper to calculate it before the
3477 /// loop body (used when the linear step is not constant):
3479 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
3480 /// Finals[]; Step; CalcStep; }
3481 MutableArrayRef<Expr *> getPrivates() {
3482 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3484 ArrayRef<const Expr *> getPrivates() const {
3485 return llvm::makeArrayRef(varlist_end(), varlist_size());
3488 MutableArrayRef<Expr *> getInits() {
3489 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3491 ArrayRef<const Expr *> getInits() const {
3492 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3495 /// Sets the list of update expressions for linear variables.
3496 MutableArrayRef<Expr *> getUpdates() {
3497 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
3499 ArrayRef<const Expr *> getUpdates() const {
3500 return llvm::makeArrayRef(getInits().end(), varlist_size());
3503 /// Sets the list of final update expressions for linear variables.
3504 MutableArrayRef<Expr *> getFinals() {
3505 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
3507 ArrayRef<const Expr *> getFinals() const {
3508 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
3511 /// Gets the list of used expressions for linear variables.
3512 MutableArrayRef<Expr *> getUsedExprs() {
3513 return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
3515 ArrayRef<const Expr *> getUsedExprs() const {
3516 return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
3519 /// Sets the list of the copies of original linear variables.
3520 /// \param PL List of expressions.
3521 void setPrivates(ArrayRef<Expr *> PL);
3523 /// Sets the list of the initial values for linear variables.
3524 /// \param IL List of expressions.
3525 void setInits(ArrayRef<Expr *> IL);
3528 /// Creates clause with a list of variables \a VL and a linear step
3531 /// \param C AST Context.
3532 /// \param StartLoc Starting location of the clause.
3533 /// \param LParenLoc Location of '('.
3534 /// \param Modifier Modifier of 'linear' clause.
3535 /// \param ModifierLoc Modifier location.
3536 /// \param ColonLoc Location of ':'.
3537 /// \param EndLoc Ending location of the clause.
3538 /// \param VL List of references to the variables.
3539 /// \param PL List of private copies of original variables.
3540 /// \param IL List of initial values for the variables.
3541 /// \param Step Linear step.
3542 /// \param CalcStep Calculation of the linear step.
3543 /// \param PreInit Statement that must be executed before entering the OpenMP
3544 /// region with this clause.
3545 /// \param PostUpdate Expression that must be executed after exit from the
3546 /// OpenMP region with this clause.
3547 static OMPLinearClause *
3548 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3549 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3550 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3551 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
3552 Stmt *PreInit, Expr *PostUpdate);
3554 /// Creates an empty clause with the place for \a NumVars variables.
3556 /// \param C AST context.
3557 /// \param NumVars Number of variables.
3558 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3561 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
3563 /// Return modifier.
3564 OpenMPLinearClauseKind getModifier() const { return Modifier; }
3566 /// Set modifier location.
3567 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3569 /// Return modifier location.
3570 SourceLocation getModifierLoc() const { return ModifierLoc; }
3572 /// Sets the location of ':'.
3573 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3575 /// Returns the location of ':'.
3576 SourceLocation getColonLoc() const { return ColonLoc; }
3578 /// Returns linear step.
3579 Expr *getStep() { return *(getFinals().end()); }
3581 /// Returns linear step.
3582 const Expr *getStep() const { return *(getFinals().end()); }
3584 /// Returns expression to calculate linear step.
3585 Expr *getCalcStep() { return *(getFinals().end() + 1); }
3587 /// Returns expression to calculate linear step.
3588 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
3590 /// Sets the list of update expressions for linear variables.
3591 /// \param UL List of expressions.
3592 void setUpdates(ArrayRef<Expr *> UL);
3594 /// Sets the list of final update expressions for linear variables.
3595 /// \param FL List of expressions.
3596 void setFinals(ArrayRef<Expr *> FL);
3598 /// Sets the list of used expressions for the linear clause.
3599 void setUsedExprs(ArrayRef<Expr *> UE);
3601 using privates_iterator = MutableArrayRef<Expr *>::iterator;
3602 using privates_const_iterator = ArrayRef<const Expr *>::iterator;
3603 using privates_range = llvm::iterator_range<privates_iterator>;
3604 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
3606 privates_range privates() {
3607 return privates_range(getPrivates().begin(), getPrivates().end());
3610 privates_const_range privates() const {
3611 return privates_const_range(getPrivates().begin(), getPrivates().end());
3614 using inits_iterator = MutableArrayRef<Expr *>::iterator;
3615 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
3616 using inits_range = llvm::iterator_range<inits_iterator>;
3617 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3619 inits_range inits() {
3620 return inits_range(getInits().begin(), getInits().end());
3623 inits_const_range inits() const {
3624 return inits_const_range(getInits().begin(), getInits().end());
3627 using updates_iterator = MutableArrayRef<Expr *>::iterator;
3628 using updates_const_iterator = ArrayRef<const Expr *>::iterator;
3629 using updates_range = llvm::iterator_range<updates_iterator>;
3630 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
3632 updates_range updates() {
3633 return updates_range(getUpdates().begin(), getUpdates().end());
3636 updates_const_range updates() const {
3637 return updates_const_range(getUpdates().begin(), getUpdates().end());
3640 using finals_iterator = MutableArrayRef<Expr *>::iterator;
3641 using finals_const_iterator = ArrayRef<const Expr *>::iterator;
3642 using finals_range = llvm::iterator_range<finals_iterator>;
3643 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
3645 finals_range finals() {