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 /// Reduction modifier.
2707 OpenMPReductionClauseModifier Modifier = OMPC_REDUCTION_unknown;
2709 /// Reduction modifier location.
2710 SourceLocation ModifierLoc;
2712 /// Location of ':'.
2713 SourceLocation ColonLoc;
2715 /// Nested name specifier for C++.
2716 NestedNameSpecifierLoc QualifierLoc;
2718 /// Name of custom operator.
2719 DeclarationNameInfo NameInfo;
2721 /// Build clause with number of variables \a N.
2723 /// \param StartLoc Starting location of the clause.
2724 /// \param LParenLoc Location of '('.
2725 /// \param ModifierLoc Modifier location.
2726 /// \param ColonLoc Location of ':'.
2727 /// \param EndLoc Ending location of the clause.
2728 /// \param N Number of the variables in the clause.
2729 /// \param QualifierLoc The nested-name qualifier with location information
2730 /// \param NameInfo The full name info for reduction identifier.
2731 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2732 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2733 SourceLocation EndLoc,
2734 OpenMPReductionClauseModifier Modifier, unsigned N,
2735 NestedNameSpecifierLoc QualifierLoc,
2736 const DeclarationNameInfo &NameInfo)
2737 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
2738 LParenLoc, EndLoc, N),
2739 OMPClauseWithPostUpdate(this), Modifier(Modifier),
2740 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
2741 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2743 /// Build an empty clause.
2745 /// \param N Number of variables.
2746 explicit OMPReductionClause(unsigned N)
2747 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
2748 SourceLocation(), SourceLocation(),
2750 OMPClauseWithPostUpdate(this) {}
2752 /// Sets reduction modifier.
2753 void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
2755 /// Sets location of the modifier.
2756 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
2758 /// Sets location of ':' symbol in clause.
2759 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2761 /// Sets the name info for specified reduction identifier.
2762 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2764 /// Sets the nested name specifier.
2765 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2767 /// Set list of helper expressions, required for proper codegen of the
2768 /// clause. These expressions represent private copy of the reduction
2770 void setPrivates(ArrayRef<Expr *> Privates);
2772 /// Get the list of helper privates.
2773 MutableArrayRef<Expr *> getPrivates() {
2774 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2776 ArrayRef<const Expr *> getPrivates() const {
2777 return llvm::makeArrayRef(varlist_end(), varlist_size());
2780 /// Set list of helper expressions, required for proper codegen of the
2781 /// clause. These expressions represent LHS expression in the final
2782 /// reduction expression performed by the reduction clause.
2783 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2785 /// Get the list of helper LHS expressions.
2786 MutableArrayRef<Expr *> getLHSExprs() {
2787 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2789 ArrayRef<const Expr *> getLHSExprs() const {
2790 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2793 /// Set list of helper expressions, required for proper codegen of the
2794 /// clause. These expressions represent RHS expression in the final
2795 /// reduction expression performed by the reduction clause.
2796 /// Also, variables in these expressions are used for proper initialization of
2797 /// reduction copies.
2798 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2800 /// Get the list of helper destination expressions.
2801 MutableArrayRef<Expr *> getRHSExprs() {
2802 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2804 ArrayRef<const Expr *> getRHSExprs() const {
2805 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2808 /// Set list of helper reduction expressions, required for proper
2809 /// codegen of the clause. These expressions are binary expressions or
2810 /// operator/custom reduction call that calculates new value from source
2811 /// helper expressions to destination helper expressions.
2812 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2814 /// Get the list of helper reduction expressions.
2815 MutableArrayRef<Expr *> getReductionOps() {
2816 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2818 ArrayRef<const Expr *> getReductionOps() const {
2819 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2823 /// Creates clause with a list of variables \a VL.
2825 /// \param StartLoc Starting location of the clause.
2826 /// \param LParenLoc Location of '('.
2827 /// \param ModifierLoc Modifier location.
2828 /// \param ColonLoc Location of ':'.
2829 /// \param EndLoc Ending location of the clause.
2830 /// \param VL The variables in the clause.
2831 /// \param QualifierLoc The nested-name qualifier with location information
2832 /// \param NameInfo The full name info for reduction identifier.
2833 /// \param Privates List of helper expressions for proper generation of
2835 /// \param LHSExprs List of helper expressions for proper generation of
2836 /// assignment operation required for copyprivate clause. This list represents
2837 /// LHSs of the reduction expressions.
2838 /// \param RHSExprs List of helper expressions for proper generation of
2839 /// assignment operation required for copyprivate clause. This list represents
2840 /// RHSs of the reduction expressions.
2841 /// Also, variables in these expressions are used for proper initialization of
2842 /// reduction copies.
2843 /// \param ReductionOps List of helper expressions that represents reduction
2846 /// LHSExprs binop RHSExprs;
2847 /// operator binop(LHSExpr, RHSExpr);
2848 /// <CutomReduction>(LHSExpr, RHSExpr);
2850 /// Required for proper codegen of final reduction operation performed by the
2851 /// reduction clause.
2852 /// \param PreInit Statement that must be executed before entering the OpenMP
2853 /// region with this clause.
2854 /// \param PostUpdate Expression that must be executed after exit from the
2855 /// OpenMP region with this clause.
2856 static OMPReductionClause *
2857 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2858 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2859 SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
2860 ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
2861 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2862 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2863 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2865 /// Creates an empty clause with the place for \a N variables.
2867 /// \param C AST context.
2868 /// \param N The number of variables.
2869 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2871 /// Returns modifier.
2872 OpenMPReductionClauseModifier getModifier() const { return Modifier; }
2874 /// Returns modifier location.
2875 SourceLocation getModifierLoc() const { return ModifierLoc; }
2877 /// Gets location of ':' symbol in clause.
2878 SourceLocation getColonLoc() const { return ColonLoc; }
2880 /// Gets the name info for specified reduction identifier.
2881 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2883 /// Gets the nested name specifier.
2884 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2886 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2887 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2888 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2889 using helper_expr_const_range =
2890 llvm::iterator_range<helper_expr_const_iterator>;
2892 helper_expr_const_range privates() const {
2893 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2896 helper_expr_range privates() {
2897 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2900 helper_expr_const_range lhs_exprs() const {
2901 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2904 helper_expr_range lhs_exprs() {
2905 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2908 helper_expr_const_range rhs_exprs() const {
2909 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2912 helper_expr_range rhs_exprs() {
2913 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2916 helper_expr_const_range reduction_ops() const {
2917 return helper_expr_const_range(getReductionOps().begin(),
2918 getReductionOps().end());
2921 helper_expr_range reduction_ops() {
2922 return helper_expr_range(getReductionOps().begin(),
2923 getReductionOps().end());
2926 child_range children() {
2927 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2928 reinterpret_cast<Stmt **>(varlist_end()));
2931 const_child_range children() const {
2932 auto Children = const_cast<OMPReductionClause *>(this)->children();
2933 return const_child_range(Children.begin(), Children.end());
2936 child_range used_children() {
2937 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2938 reinterpret_cast<Stmt **>(varlist_end()));
2940 const_child_range used_children() const {
2941 auto Children = const_cast<OMPReductionClause *>(this)->used_children();
2942 return const_child_range(Children.begin(), Children.end());
2945 static bool classof(const OMPClause *T) {
2946 return T->getClauseKind() == OMPC_reduction;
2950 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
2954 /// #pragma omp taskgroup task_reduction(+:a,b)
2956 /// In this example directive '#pragma omp taskgroup' has clause
2957 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
2958 class OMPTaskReductionClause final
2959 : public OMPVarListClause<OMPTaskReductionClause>,
2960 public OMPClauseWithPostUpdate,
2961 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
2962 friend class OMPClauseReader;
2963 friend OMPVarListClause;
2964 friend TrailingObjects;
2966 /// Location of ':'.
2967 SourceLocation ColonLoc;
2969 /// Nested name specifier for C++.
2970 NestedNameSpecifierLoc QualifierLoc;
2972 /// Name of custom operator.
2973 DeclarationNameInfo NameInfo;
2975 /// Build clause with number of variables \a N.
2977 /// \param StartLoc Starting location of the clause.
2978 /// \param LParenLoc Location of '('.
2979 /// \param EndLoc Ending location of the clause.
2980 /// \param ColonLoc Location of ':'.
2981 /// \param N Number of the variables in the clause.
2982 /// \param QualifierLoc The nested-name qualifier with location information
2983 /// \param NameInfo The full name info for reduction identifier.
2984 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2985 SourceLocation ColonLoc, SourceLocation EndLoc,
2986 unsigned N, NestedNameSpecifierLoc QualifierLoc,
2987 const DeclarationNameInfo &NameInfo)
2988 : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
2989 LParenLoc, EndLoc, N),
2990 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
2991 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2993 /// Build an empty clause.
2995 /// \param N Number of variables.
2996 explicit OMPTaskReductionClause(unsigned N)
2997 : OMPVarListClause<OMPTaskReductionClause>(
2998 OMPC_task_reduction, SourceLocation(), SourceLocation(),
2999 SourceLocation(), N),
3000 OMPClauseWithPostUpdate(this) {}
3002 /// Sets location of ':' symbol in clause.
3003 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3005 /// Sets the name info for specified reduction identifier.
3006 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3008 /// Sets the nested name specifier.
3009 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3011 /// Set list of helper expressions, required for proper codegen of the clause.
3012 /// These expressions represent private copy of the reduction variable.
3013 void setPrivates(ArrayRef<Expr *> Privates);
3015 /// Get the list of helper privates.
3016 MutableArrayRef<Expr *> getPrivates() {
3017 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3019 ArrayRef<const Expr *> getPrivates() const {
3020 return llvm::makeArrayRef(varlist_end(), varlist_size());
3023 /// Set list of helper expressions, required for proper codegen of the clause.
3024 /// These expressions represent LHS expression in the final reduction
3025 /// expression performed by the reduction clause.
3026 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3028 /// Get the list of helper LHS expressions.
3029 MutableArrayRef<Expr *> getLHSExprs() {
3030 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3032 ArrayRef<const Expr *> getLHSExprs() const {
3033 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3036 /// Set list of helper expressions, required for proper codegen of the clause.
3037 /// These expressions represent RHS expression in the final reduction
3038 /// expression performed by the reduction clause. Also, variables in these
3039 /// expressions are used for proper initialization of reduction copies.
3040 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3042 /// Get the list of helper destination expressions.
3043 MutableArrayRef<Expr *> getRHSExprs() {
3044 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3046 ArrayRef<const Expr *> getRHSExprs() const {
3047 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3050 /// Set list of helper reduction expressions, required for proper
3051 /// codegen of the clause. These expressions are binary expressions or
3052 /// operator/custom reduction call that calculates new value from source
3053 /// helper expressions to destination helper expressions.
3054 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3056 /// Get the list of helper reduction expressions.
3057 MutableArrayRef<Expr *> getReductionOps() {
3058 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3060 ArrayRef<const Expr *> getReductionOps() const {
3061 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3065 /// Creates clause with a list of variables \a VL.
3067 /// \param StartLoc Starting location of the clause.
3068 /// \param LParenLoc Location of '('.
3069 /// \param ColonLoc Location of ':'.
3070 /// \param EndLoc Ending location of the clause.
3071 /// \param VL The variables in the clause.
3072 /// \param QualifierLoc The nested-name qualifier with location information
3073 /// \param NameInfo The full name info for reduction identifier.
3074 /// \param Privates List of helper expressions for proper generation of
3076 /// \param LHSExprs List of helper expressions for proper generation of
3077 /// assignment operation required for copyprivate clause. This list represents
3078 /// LHSs of the reduction expressions.
3079 /// \param RHSExprs List of helper expressions for proper generation of
3080 /// assignment operation required for copyprivate clause. This list represents
3081 /// RHSs of the reduction expressions.
3082 /// Also, variables in these expressions are used for proper initialization of
3083 /// reduction copies.
3084 /// \param ReductionOps List of helper expressions that represents reduction
3087 /// LHSExprs binop RHSExprs;
3088 /// operator binop(LHSExpr, RHSExpr);
3089 /// <CutomReduction>(LHSExpr, RHSExpr);
3091 /// Required for proper codegen of final reduction operation performed by the
3092 /// reduction clause.
3093 /// \param PreInit Statement that must be executed before entering the OpenMP
3094 /// region with this clause.
3095 /// \param PostUpdate Expression that must be executed after exit from the
3096 /// OpenMP region with this clause.
3097 static OMPTaskReductionClause *
3098 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3099 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3100 NestedNameSpecifierLoc QualifierLoc,
3101 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3102 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3103 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3105 /// Creates an empty clause with the place for \a N variables.
3107 /// \param C AST context.
3108 /// \param N The number of variables.
3109 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3111 /// Gets location of ':' symbol in clause.
3112 SourceLocation getColonLoc() const { return ColonLoc; }
3114 /// Gets the name info for specified reduction identifier.
3115 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3117 /// Gets the nested name specifier.
3118 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3120 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3121 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3122 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3123 using helper_expr_const_range =
3124 llvm::iterator_range<helper_expr_const_iterator>;
3126 helper_expr_const_range privates() const {
3127 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3130 helper_expr_range privates() {
3131 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3134 helper_expr_const_range lhs_exprs() const {
3135 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3138 helper_expr_range lhs_exprs() {
3139 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3142 helper_expr_const_range rhs_exprs() const {
3143 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3146 helper_expr_range rhs_exprs() {
3147 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3150 helper_expr_const_range reduction_ops() const {
3151 return helper_expr_const_range(getReductionOps().begin(),
3152 getReductionOps().end());
3155 helper_expr_range reduction_ops() {
3156 return helper_expr_range(getReductionOps().begin(),
3157 getReductionOps().end());
3160 child_range children() {
3161 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3162 reinterpret_cast<Stmt **>(varlist_end()));
3165 const_child_range children() const {
3166 auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3167 return const_child_range(Children.begin(), Children.end());
3170 child_range used_children() {
3171 return child_range(child_iterator(), child_iterator());
3173 const_child_range used_children() const {
3174 return const_child_range(const_child_iterator(), const_child_iterator());
3177 static bool classof(const OMPClause *T) {
3178 return T->getClauseKind() == OMPC_task_reduction;
3182 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
3185 /// #pragma omp task in_reduction(+:a,b)
3187 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
3188 /// operator '+' and the variables 'a' and 'b'.
3189 class OMPInReductionClause final
3190 : public OMPVarListClause<OMPInReductionClause>,
3191 public OMPClauseWithPostUpdate,
3192 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
3193 friend class OMPClauseReader;
3194 friend OMPVarListClause;
3195 friend TrailingObjects;
3197 /// Location of ':'.
3198 SourceLocation ColonLoc;
3200 /// Nested name specifier for C++.
3201 NestedNameSpecifierLoc QualifierLoc;
3203 /// Name of custom operator.
3204 DeclarationNameInfo NameInfo;
3206 /// Build clause with number of variables \a N.
3208 /// \param StartLoc Starting location of the clause.
3209 /// \param LParenLoc Location of '('.
3210 /// \param EndLoc Ending location of the clause.
3211 /// \param ColonLoc Location of ':'.
3212 /// \param N Number of the variables in the clause.
3213 /// \param QualifierLoc The nested-name qualifier with location information
3214 /// \param NameInfo The full name info for reduction identifier.
3215 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3216 SourceLocation ColonLoc, SourceLocation EndLoc,
3217 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3218 const DeclarationNameInfo &NameInfo)
3219 : OMPVarListClause<OMPInReductionClause>(OMPC_in_reduction, StartLoc,
3220 LParenLoc, EndLoc, N),
3221 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3222 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3224 /// Build an empty clause.
3226 /// \param N Number of variables.
3227 explicit OMPInReductionClause(unsigned N)
3228 : OMPVarListClause<OMPInReductionClause>(
3229 OMPC_in_reduction, SourceLocation(), SourceLocation(),
3230 SourceLocation(), N),
3231 OMPClauseWithPostUpdate(this) {}
3233 /// Sets location of ':' symbol in clause.
3234 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3236 /// Sets the name info for specified reduction identifier.
3237 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3239 /// Sets the nested name specifier.
3240 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3242 /// Set list of helper expressions, required for proper codegen of the clause.
3243 /// These expressions represent private copy of the reduction variable.
3244 void setPrivates(ArrayRef<Expr *> Privates);
3246 /// Get the list of helper privates.
3247 MutableArrayRef<Expr *> getPrivates() {
3248 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3250 ArrayRef<const Expr *> getPrivates() const {
3251 return llvm::makeArrayRef(varlist_end(), varlist_size());
3254 /// Set list of helper expressions, required for proper codegen of the clause.
3255 /// These expressions represent LHS expression in the final reduction
3256 /// expression performed by the reduction clause.
3257 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3259 /// Get the list of helper LHS expressions.
3260 MutableArrayRef<Expr *> getLHSExprs() {
3261 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3263 ArrayRef<const Expr *> getLHSExprs() const {
3264 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3267 /// Set list of helper expressions, required for proper codegen of the clause.
3268 /// These expressions represent RHS expression in the final reduction
3269 /// expression performed by the reduction clause. Also, variables in these
3270 /// expressions are used for proper initialization of reduction copies.
3271 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3273 /// Get the list of helper destination expressions.
3274 MutableArrayRef<Expr *> getRHSExprs() {
3275 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3277 ArrayRef<const Expr *> getRHSExprs() const {
3278 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3281 /// Set list of helper reduction expressions, required for proper
3282 /// codegen of the clause. These expressions are binary expressions or
3283 /// operator/custom reduction call that calculates new value from source
3284 /// helper expressions to destination helper expressions.
3285 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3287 /// Get the list of helper reduction expressions.
3288 MutableArrayRef<Expr *> getReductionOps() {
3289 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3291 ArrayRef<const Expr *> getReductionOps() const {
3292 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3295 /// Set list of helper reduction taskgroup descriptors.
3296 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3298 /// Get the list of helper reduction taskgroup descriptors.
3299 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3300 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3302 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3303 return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3307 /// Creates clause with a list of variables \a VL.
3309 /// \param StartLoc Starting location of the clause.
3310 /// \param LParenLoc Location of '('.
3311 /// \param ColonLoc Location of ':'.
3312 /// \param EndLoc Ending location of the clause.
3313 /// \param VL The variables in the clause.
3314 /// \param QualifierLoc The nested-name qualifier with location information
3315 /// \param NameInfo The full name info for reduction identifier.
3316 /// \param Privates List of helper expressions for proper generation of
3318 /// \param LHSExprs List of helper expressions for proper generation of
3319 /// assignment operation required for copyprivate clause. This list represents
3320 /// LHSs of the reduction expressions.
3321 /// \param RHSExprs List of helper expressions for proper generation of
3322 /// assignment operation required for copyprivate clause. This list represents
3323 /// RHSs of the reduction expressions.
3324 /// Also, variables in these expressions are used for proper initialization of
3325 /// reduction copies.
3326 /// \param ReductionOps List of helper expressions that represents reduction
3329 /// LHSExprs binop RHSExprs;
3330 /// operator binop(LHSExpr, RHSExpr);
3331 /// <CutomReduction>(LHSExpr, RHSExpr);
3333 /// Required for proper codegen of final reduction operation performed by the
3334 /// reduction clause.
3335 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3336 /// corresponding items in parent taskgroup task_reduction clause.
3337 /// \param PreInit Statement that must be executed before entering the OpenMP
3338 /// region with this clause.
3339 /// \param PostUpdate Expression that must be executed after exit from the
3340 /// OpenMP region with this clause.
3341 static OMPInReductionClause *
3342 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3343 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3344 NestedNameSpecifierLoc QualifierLoc,
3345 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3346 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3347 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3348 Stmt *PreInit, Expr *PostUpdate);
3350 /// Creates an empty clause with the place for \a N variables.
3352 /// \param C AST context.
3353 /// \param N The number of variables.
3354 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3356 /// Gets location of ':' symbol in clause.
3357 SourceLocation getColonLoc() const { return ColonLoc; }
3359 /// Gets the name info for specified reduction identifier.
3360 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3362 /// Gets the nested name specifier.
3363 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3365 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3366 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3367 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3368 using helper_expr_const_range =
3369 llvm::iterator_range<helper_expr_const_iterator>;
3371 helper_expr_const_range privates() const {
3372 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3375 helper_expr_range privates() {
3376 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3379 helper_expr_const_range lhs_exprs() const {
3380 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3383 helper_expr_range lhs_exprs() {
3384 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3387 helper_expr_const_range rhs_exprs() const {
3388 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3391 helper_expr_range rhs_exprs() {
3392 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3395 helper_expr_const_range reduction_ops() const {
3396 return helper_expr_const_range(getReductionOps().begin(),
3397 getReductionOps().end());
3400 helper_expr_range reduction_ops() {
3401 return helper_expr_range(getReductionOps().begin(),
3402 getReductionOps().end());
3405 helper_expr_const_range taskgroup_descriptors() const {
3406 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3407 getTaskgroupDescriptors().end());
3410 helper_expr_range taskgroup_descriptors() {
3411 return helper_expr_range(getTaskgroupDescriptors().begin(),
3412 getTaskgroupDescriptors().end());
3415 child_range children() {
3416 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3417 reinterpret_cast<Stmt **>(varlist_end()));
3420 const_child_range children() const {
3421 auto Children = const_cast<OMPInReductionClause *>(this)->children();
3422 return const_child_range(Children.begin(), Children.end());
3425 child_range used_children() {
3426 return child_range(child_iterator(), child_iterator());
3428 const_child_range used_children() const {
3429 return const_child_range(const_child_iterator(), const_child_iterator());
3432 static bool classof(const OMPClause *T) {
3433 return T->getClauseKind() == OMPC_in_reduction;
3437 /// This represents clause 'linear' in the '#pragma omp ...'
3441 /// #pragma omp simd linear(a,b : 2)
3443 /// In this example directive '#pragma omp simd' has clause 'linear'
3444 /// with variables 'a', 'b' and linear step '2'.
3445 class OMPLinearClause final
3446 : public OMPVarListClause<OMPLinearClause>,
3447 public OMPClauseWithPostUpdate,
3448 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
3449 friend class OMPClauseReader;
3450 friend OMPVarListClause;
3451 friend TrailingObjects;
3453 /// Modifier of 'linear' clause.
3454 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
3456 /// Location of linear modifier if any.
3457 SourceLocation ModifierLoc;
3459 /// Location of ':'.
3460 SourceLocation ColonLoc;
3462 /// Sets the linear step for clause.
3463 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
3465 /// Sets the expression to calculate linear step for clause.
3466 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
3468 /// Build 'linear' clause with given number of variables \a NumVars.
3470 /// \param StartLoc Starting location of the clause.
3471 /// \param LParenLoc Location of '('.
3472 /// \param ColonLoc Location of ':'.
3473 /// \param EndLoc Ending location of the clause.
3474 /// \param NumVars Number of variables.
3475 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3476 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3477 SourceLocation ColonLoc, SourceLocation EndLoc,
3479 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
3481 OMPClauseWithPostUpdate(this), Modifier(Modifier),
3482 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
3484 /// Build an empty clause.
3486 /// \param NumVars Number of variables.
3487 explicit OMPLinearClause(unsigned NumVars)
3488 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
3489 SourceLocation(), SourceLocation(),
3491 OMPClauseWithPostUpdate(this) {}
3493 /// Gets the list of initial values for linear variables.
3495 /// There are NumVars expressions with initial values allocated after the
3496 /// varlist, they are followed by NumVars update expressions (used to update
3497 /// the linear variable's value on current iteration) and they are followed by
3498 /// NumVars final expressions (used to calculate the linear variable's
3499 /// value after the loop body). After these lists, there are 2 helper
3500 /// expressions - linear step and a helper to calculate it before the
3501 /// loop body (used when the linear step is not constant):
3503 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
3504 /// Finals[]; Step; CalcStep; }
3505 MutableArrayRef<Expr *> getPrivates() {
3506 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3508 ArrayRef<const Expr *> getPrivates() const {
3509 return llvm::makeArrayRef(varlist_end(), varlist_size());
3512 MutableArrayRef<Expr *> getInits() {
3513 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3515 ArrayRef<const Expr *> getInits() const {
3516 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3519 /// Sets the list of update expressions for linear variables.
3520 MutableArrayRef<Expr *> getUpdates() {
3521 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
3523 ArrayRef<const Expr *> getUpdates() const {
3524 return llvm::makeArrayRef(getInits().end(), varlist_size());
3527 /// Sets the list of final update expressions for linear variables.
3528 MutableArrayRef<Expr *> getFinals() {
3529 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
3531 ArrayRef<const Expr *> getFinals() const {
3532 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
3535 /// Gets the list of used expressions for linear variables.
3536 MutableArrayRef<Expr *> getUsedExprs() {
3537 return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
3539 ArrayRef<const Expr *> getUsedExprs() const {
3540 return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
3543 /// Sets the list of the copies of original linear variables.
3544 /// \param PL List of expressions.
3545 void setPrivates(ArrayRef<Expr *> PL);
3547 /// Sets the list of the initial values for linear variables.
3548 /// \param IL List of expressions.
3549 void setInits(ArrayRef<Expr *> IL);
3552 /// Creates clause with a list of variables \a VL and a linear step
3555 /// \param C AST Context.
3556 /// \param StartLoc Starting location of the clause.
3557 /// \param LParenLoc Location of '('.
3558 /// \param Modifier Modifier of 'linear' clause.
3559 /// \param ModifierLoc Modifier location.
3560 /// \param ColonLoc Location of ':'.
3561 /// \param EndLoc Ending location of the clause.
3562 /// \param VL List of references to the variables.
3563 /// \param PL List of private copies of original variables.
3564 /// \param IL List of initial values for the variables.
3565 /// \param Step Linear step.
3566 /// \param CalcStep Calculation of the linear step.
3567 /// \param PreInit Statement that must be executed before entering the OpenMP
3568 /// region with this clause.
3569 /// \param PostUpdate Expression that must be executed after exit from the
3570 /// OpenMP region with this clause.
3571 static OMPLinearClause *
3572 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3573 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3574 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3575 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
3576 Stmt *PreInit, Expr *PostUpdate);
3578 /// Creates an empty clause with the place for \a NumVars variables.
3580 /// \param C AST context.
3581 /// \param NumVars Number of variables.
3582 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3585 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
3587 /// Return modifier.
3588 OpenMPLinearClauseKind getModifier() const { return Modifier; }
3590 /// Set modifier location.
3591 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3593 /// Return modifier location.
3594 SourceLocation getModifierLoc() const { return ModifierLoc; }
3596 /// Sets the location of ':'.
3597 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3599 /// Returns the location of ':'.
3600 SourceLocation getColonLoc() const { return ColonLoc; }
3602 /// Returns linear step.
3603 Expr *getStep() { return *(getFinals().end()); }
3605 /// Returns linear step.
3606 const Expr *getStep() const { return *(getFinals().end()); }
3608 /// Returns expression to calculate linear step.
3609 Expr *getCalcStep() { return *(getFinals().end() + 1); }
3611 /// Returns expression to calculate linear step.
3612 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
3614 /// Sets the list of update expressions for linear variables.
3615 /// \param UL List of expressions.
3616 void setUpdates(ArrayRef<Expr *> UL);
3618 /// Sets the list of final update expressions for linear variables.
3619 /// \param FL List of expressions.
3620 void setFinals(ArrayRef<Expr *> FL);
3622 /// Sets the list of used expressions for the linear clause.
3623 void setUsedExprs(ArrayRef<Expr *> UE);
3625 using privates_iterator = MutableArrayRef<Expr *>::iterator;
3626 using privates_const_iterator = ArrayRef<const Expr *>::iterator;
3627 using privates_range = llvm::iterator_range<privates_iterator>;
3628 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
3630 privates_range privates() {
3631 return privates_range(getPrivates().begin(), getPrivates().end());
3634 privates_const_range privates() const {
3635 return privates_const_range(getPrivates().begin(), getPrivates().end());
3638 using inits_iterator = MutableArrayRef<Expr *>::iterator;
3639 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
3640 using inits_range = llvm::iterator_range<inits_iterator>;
3641 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3643 inits_range inits() {
3644 return inits_range(getInits().begin(), getInits().end());