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(llvm::omp::OMPC_allocator, StartLoc, EndLoc),
289 LParenLoc(LParenLoc), Allocator(A) {}
291 /// Build an empty clause.
293 : OMPClause(llvm::omp::OMPC_allocator, SourceLocation(),
296 /// Sets the location of '('.
297 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
299 /// Returns the location of '('.
300 SourceLocation getLParenLoc() const { return LParenLoc; }
302 /// Returns allocator.
303 Expr *getAllocator() const { return cast_or_null<Expr>(Allocator); }
305 child_range children() { return child_range(&Allocator, &Allocator + 1); }
307 const_child_range children() const {
308 return const_child_range(&Allocator, &Allocator + 1);
311 child_range used_children() {
312 return child_range(child_iterator(), child_iterator());
314 const_child_range used_children() const {
315 return const_child_range(const_child_iterator(), const_child_iterator());
318 static bool classof(const OMPClause *T) {
319 return T->getClauseKind() == llvm::omp::OMPC_allocator;
323 /// This represents clause 'allocate' in the '#pragma omp ...' directives.
326 /// #pragma omp parallel private(a) allocate(omp_default_mem_alloc :a)
328 /// In this example directive '#pragma omp parallel' has clause 'private'
329 /// and clause 'allocate' for the variable 'a'.
330 class OMPAllocateClause final
331 : public OMPVarListClause<OMPAllocateClause>,
332 private llvm::TrailingObjects<OMPAllocateClause, Expr *> {
333 friend class OMPClauseReader;
334 friend OMPVarListClause;
335 friend TrailingObjects;
337 /// Allocator specified in the clause, or 'nullptr' if the default one is
339 Expr *Allocator = nullptr;
340 /// Position of the ':' delimiter in the clause;
341 SourceLocation ColonLoc;
343 /// Build clause with number of variables \a N.
345 /// \param StartLoc Starting location of the clause.
346 /// \param LParenLoc Location of '('.
347 /// \param Allocator Allocator expression.
348 /// \param ColonLoc Location of ':' delimiter.
349 /// \param EndLoc Ending location of the clause.
350 /// \param N Number of the variables in the clause.
351 OMPAllocateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
352 Expr *Allocator, SourceLocation ColonLoc,
353 SourceLocation EndLoc, unsigned N)
354 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate, StartLoc,
355 LParenLoc, EndLoc, N),
356 Allocator(Allocator), ColonLoc(ColonLoc) {}
358 /// Build an empty clause.
360 /// \param N Number of variables.
361 explicit OMPAllocateClause(unsigned N)
362 : OMPVarListClause<OMPAllocateClause>(llvm::omp::OMPC_allocate,
363 SourceLocation(), SourceLocation(),
364 SourceLocation(), N) {}
366 /// Sets location of ':' symbol in clause.
367 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
369 void setAllocator(Expr *A) { Allocator = A; }
372 /// Creates clause with a list of variables \a VL.
374 /// \param C AST context.
375 /// \param StartLoc Starting location of the clause.
376 /// \param LParenLoc Location of '('.
377 /// \param Allocator Allocator expression.
378 /// \param ColonLoc Location of ':' delimiter.
379 /// \param EndLoc Ending location of the clause.
380 /// \param VL List of references to the variables.
381 static OMPAllocateClause *Create(const ASTContext &C, SourceLocation StartLoc,
382 SourceLocation LParenLoc, Expr *Allocator,
383 SourceLocation ColonLoc,
384 SourceLocation EndLoc, ArrayRef<Expr *> VL);
386 /// Returns the allocator expression or nullptr, if no allocator is specified.
387 Expr *getAllocator() const { return Allocator; }
389 /// Returns the location of the ':' delimiter.
390 SourceLocation getColonLoc() const { return ColonLoc; }
392 /// Creates an empty clause with the place for \a N variables.
394 /// \param C AST context.
395 /// \param N The number of variables.
396 static OMPAllocateClause *CreateEmpty(const ASTContext &C, unsigned N);
398 child_range children() {
399 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
400 reinterpret_cast<Stmt **>(varlist_end()));
403 const_child_range children() const {
404 auto Children = const_cast<OMPAllocateClause *>(this)->children();
405 return const_child_range(Children.begin(), Children.end());
408 child_range used_children() {
409 return child_range(child_iterator(), child_iterator());
411 const_child_range used_children() const {
412 return const_child_range(const_child_iterator(), const_child_iterator());
415 static bool classof(const OMPClause *T) {
416 return T->getClauseKind() == llvm::omp::OMPC_allocate;
420 /// This represents 'if' clause in the '#pragma omp ...' directive.
423 /// #pragma omp parallel if(parallel:a > 5)
425 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
426 /// condition 'a > 5' and directive name modifier 'parallel'.
427 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
428 friend class OMPClauseReader;
431 SourceLocation LParenLoc;
433 /// Condition of the 'if' clause.
434 Stmt *Condition = nullptr;
436 /// Location of ':' (if any).
437 SourceLocation ColonLoc;
439 /// Directive name modifier for the clause.
440 OpenMPDirectiveKind NameModifier = llvm::omp::OMPD_unknown;
442 /// Name modifier location.
443 SourceLocation NameModifierLoc;
446 void setCondition(Expr *Cond) { Condition = Cond; }
448 /// Set directive name modifier for the clause.
449 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
451 /// Set location of directive name modifier for the clause.
452 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
454 /// Set location of ':'.
455 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
458 /// Build 'if' clause with condition \a Cond.
460 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
461 /// \param Cond Condition of the clause.
462 /// \param HelperCond Helper condition for the clause.
463 /// \param CaptureRegion Innermost OpenMP region where expressions in this
464 /// clause must be captured.
465 /// \param StartLoc Starting location of the clause.
466 /// \param LParenLoc Location of '('.
467 /// \param NameModifierLoc Location of directive name modifier.
468 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
469 /// \param EndLoc Ending location of the clause.
470 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
471 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
472 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
473 SourceLocation ColonLoc, SourceLocation EndLoc)
474 : OMPClause(llvm::omp::OMPC_if, StartLoc, EndLoc),
475 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond),
476 ColonLoc(ColonLoc), NameModifier(NameModifier),
477 NameModifierLoc(NameModifierLoc) {
478 setPreInitStmt(HelperCond, CaptureRegion);
481 /// Build an empty clause.
483 : OMPClause(llvm::omp::OMPC_if, SourceLocation(), SourceLocation()),
484 OMPClauseWithPreInit(this) {}
486 /// Sets the location of '('.
487 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
489 /// Returns the location of '('.
490 SourceLocation getLParenLoc() const { return LParenLoc; }
492 /// Return the location of ':'.
493 SourceLocation getColonLoc() const { return ColonLoc; }
495 /// Returns condition.
496 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
498 /// Return directive name modifier associated with the clause.
499 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
501 /// Return the location of directive name modifier.
502 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
504 child_range children() { return child_range(&Condition, &Condition + 1); }
506 const_child_range children() const {
507 return const_child_range(&Condition, &Condition + 1);
510 child_range used_children();
511 const_child_range used_children() const {
512 auto Children = const_cast<OMPIfClause *>(this)->used_children();
513 return const_child_range(Children.begin(), Children.end());
516 static bool classof(const OMPClause *T) {
517 return T->getClauseKind() == llvm::omp::OMPC_if;
521 /// This represents 'final' clause in the '#pragma omp ...' directive.
524 /// #pragma omp task final(a > 5)
526 /// In this example directive '#pragma omp task' has simple 'final'
527 /// clause with condition 'a > 5'.
528 class OMPFinalClause : public OMPClause, public OMPClauseWithPreInit {
529 friend class OMPClauseReader;
532 SourceLocation LParenLoc;
534 /// Condition of the 'if' clause.
535 Stmt *Condition = nullptr;
538 void setCondition(Expr *Cond) { Condition = Cond; }
541 /// Build 'final' clause with condition \a Cond.
543 /// \param Cond Condition of the clause.
544 /// \param HelperCond Helper condition for the construct.
545 /// \param CaptureRegion Innermost OpenMP region where expressions in this
546 /// clause must be captured.
547 /// \param StartLoc Starting location of the clause.
548 /// \param LParenLoc Location of '('.
549 /// \param EndLoc Ending location of the clause.
550 OMPFinalClause(Expr *Cond, Stmt *HelperCond,
551 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
552 SourceLocation LParenLoc, SourceLocation EndLoc)
553 : OMPClause(llvm::omp::OMPC_final, StartLoc, EndLoc),
554 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Condition(Cond) {
555 setPreInitStmt(HelperCond, CaptureRegion);
558 /// Build an empty clause.
560 : OMPClause(llvm::omp::OMPC_final, SourceLocation(), SourceLocation()),
561 OMPClauseWithPreInit(this) {}
563 /// Sets the location of '('.
564 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
566 /// Returns the location of '('.
567 SourceLocation getLParenLoc() const { return LParenLoc; }
569 /// Returns condition.
570 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
572 child_range children() { return child_range(&Condition, &Condition + 1); }
574 const_child_range children() const {
575 return const_child_range(&Condition, &Condition + 1);
578 child_range used_children();
579 const_child_range used_children() const {
580 auto Children = const_cast<OMPFinalClause *>(this)->used_children();
581 return const_child_range(Children.begin(), Children.end());
584 static bool classof(const OMPClause *T) {
585 return T->getClauseKind() == llvm::omp::OMPC_final;
589 /// This represents 'num_threads' clause in the '#pragma omp ...'
593 /// #pragma omp parallel num_threads(6)
595 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
596 /// clause with number of threads '6'.
597 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
598 friend class OMPClauseReader;
601 SourceLocation LParenLoc;
603 /// Condition of the 'num_threads' clause.
604 Stmt *NumThreads = nullptr;
607 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
610 /// Build 'num_threads' clause with condition \a NumThreads.
612 /// \param NumThreads Number of threads for the construct.
613 /// \param HelperNumThreads Helper Number of threads for the construct.
614 /// \param CaptureRegion Innermost OpenMP region where expressions in this
615 /// clause must be captured.
616 /// \param StartLoc Starting location of the clause.
617 /// \param LParenLoc Location of '('.
618 /// \param EndLoc Ending location of the clause.
619 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
620 OpenMPDirectiveKind CaptureRegion,
621 SourceLocation StartLoc, SourceLocation LParenLoc,
622 SourceLocation EndLoc)
623 : OMPClause(llvm::omp::OMPC_num_threads, StartLoc, EndLoc),
624 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
625 NumThreads(NumThreads) {
626 setPreInitStmt(HelperNumThreads, CaptureRegion);
629 /// Build an empty clause.
630 OMPNumThreadsClause()
631 : OMPClause(llvm::omp::OMPC_num_threads, SourceLocation(),
633 OMPClauseWithPreInit(this) {}
635 /// Sets the location of '('.
636 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
638 /// Returns the location of '('.
639 SourceLocation getLParenLoc() const { return LParenLoc; }
641 /// Returns number of threads.
642 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
644 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
646 const_child_range children() const {
647 return const_child_range(&NumThreads, &NumThreads + 1);
650 child_range used_children() {
651 return child_range(child_iterator(), child_iterator());
653 const_child_range used_children() const {
654 return const_child_range(const_child_iterator(), const_child_iterator());
657 static bool classof(const OMPClause *T) {
658 return T->getClauseKind() == llvm::omp::OMPC_num_threads;
662 /// This represents 'safelen' clause in the '#pragma omp ...'
666 /// #pragma omp simd safelen(4)
668 /// In this example directive '#pragma omp simd' has clause 'safelen'
669 /// with single expression '4'.
670 /// If the safelen clause is used then no two iterations executed
671 /// concurrently with SIMD instructions can have a greater distance
672 /// in the logical iteration space than its value. The parameter of
673 /// the safelen clause must be a constant positive integer expression.
674 class OMPSafelenClause : public OMPClause {
675 friend class OMPClauseReader;
678 SourceLocation LParenLoc;
680 /// Safe iteration space distance.
681 Stmt *Safelen = nullptr;
684 void setSafelen(Expr *Len) { Safelen = Len; }
687 /// Build 'safelen' clause.
689 /// \param Len Expression associated with this clause.
690 /// \param StartLoc Starting location of the clause.
691 /// \param EndLoc Ending location of the clause.
692 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
693 SourceLocation EndLoc)
694 : OMPClause(llvm::omp::OMPC_safelen, StartLoc, EndLoc),
695 LParenLoc(LParenLoc), Safelen(Len) {}
697 /// Build an empty clause.
698 explicit OMPSafelenClause()
699 : OMPClause(llvm::omp::OMPC_safelen, SourceLocation(), SourceLocation()) {
702 /// Sets the location of '('.
703 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
705 /// Returns the location of '('.
706 SourceLocation getLParenLoc() const { return LParenLoc; }
708 /// Return safe iteration space distance.
709 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
711 child_range children() { return child_range(&Safelen, &Safelen + 1); }
713 const_child_range children() const {
714 return const_child_range(&Safelen, &Safelen + 1);
717 child_range used_children() {
718 return child_range(child_iterator(), child_iterator());
720 const_child_range used_children() const {
721 return const_child_range(const_child_iterator(), const_child_iterator());
724 static bool classof(const OMPClause *T) {
725 return T->getClauseKind() == llvm::omp::OMPC_safelen;
729 /// This represents 'simdlen' clause in the '#pragma omp ...'
733 /// #pragma omp simd simdlen(4)
735 /// In this example directive '#pragma omp simd' has clause 'simdlen'
736 /// with single expression '4'.
737 /// If the 'simdlen' clause is used then it specifies the preferred number of
738 /// iterations to be executed concurrently. The parameter of the 'simdlen'
739 /// clause must be a constant positive integer expression.
740 class OMPSimdlenClause : public OMPClause {
741 friend class OMPClauseReader;
744 SourceLocation LParenLoc;
746 /// Safe iteration space distance.
747 Stmt *Simdlen = nullptr;
750 void setSimdlen(Expr *Len) { Simdlen = Len; }
753 /// Build 'simdlen' clause.
755 /// \param Len Expression associated with this clause.
756 /// \param StartLoc Starting location of the clause.
757 /// \param EndLoc Ending location of the clause.
758 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
759 SourceLocation EndLoc)
760 : OMPClause(llvm::omp::OMPC_simdlen, StartLoc, EndLoc),
761 LParenLoc(LParenLoc), Simdlen(Len) {}
763 /// Build an empty clause.
764 explicit OMPSimdlenClause()
765 : OMPClause(llvm::omp::OMPC_simdlen, SourceLocation(), SourceLocation()) {
768 /// Sets the location of '('.
769 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
771 /// Returns the location of '('.
772 SourceLocation getLParenLoc() const { return LParenLoc; }
774 /// Return safe iteration space distance.
775 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
777 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
779 const_child_range children() const {
780 return const_child_range(&Simdlen, &Simdlen + 1);
783 child_range used_children() {
784 return child_range(child_iterator(), child_iterator());
786 const_child_range used_children() const {
787 return const_child_range(const_child_iterator(), const_child_iterator());
790 static bool classof(const OMPClause *T) {
791 return T->getClauseKind() == llvm::omp::OMPC_simdlen;
795 /// This represents 'collapse' clause in the '#pragma omp ...'
799 /// #pragma omp simd collapse(3)
801 /// In this example directive '#pragma omp simd' has clause 'collapse'
802 /// with single expression '3'.
803 /// The parameter must be a constant positive integer expression, it specifies
804 /// the number of nested loops that should be collapsed into a single iteration
806 class OMPCollapseClause : public OMPClause {
807 friend class OMPClauseReader;
810 SourceLocation LParenLoc;
812 /// Number of for-loops.
813 Stmt *NumForLoops = nullptr;
815 /// Set the number of associated for-loops.
816 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
819 /// Build 'collapse' clause.
821 /// \param Num Expression associated with this clause.
822 /// \param StartLoc Starting location of the clause.
823 /// \param LParenLoc Location of '('.
824 /// \param EndLoc Ending location of the clause.
825 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
826 SourceLocation LParenLoc, SourceLocation EndLoc)
827 : OMPClause(llvm::omp::OMPC_collapse, StartLoc, EndLoc),
828 LParenLoc(LParenLoc), NumForLoops(Num) {}
830 /// Build an empty clause.
831 explicit OMPCollapseClause()
832 : OMPClause(llvm::omp::OMPC_collapse, SourceLocation(),
835 /// Sets the location of '('.
836 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
838 /// Returns the location of '('.
839 SourceLocation getLParenLoc() const { return LParenLoc; }
841 /// Return the number of associated for-loops.
842 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
844 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
846 const_child_range children() const {
847 return const_child_range(&NumForLoops, &NumForLoops + 1);
850 child_range used_children() {
851 return child_range(child_iterator(), child_iterator());
853 const_child_range used_children() const {
854 return const_child_range(const_child_iterator(), const_child_iterator());
857 static bool classof(const OMPClause *T) {
858 return T->getClauseKind() == llvm::omp::OMPC_collapse;
862 /// This represents 'default' clause in the '#pragma omp ...' directive.
865 /// #pragma omp parallel default(shared)
867 /// In this example directive '#pragma omp parallel' has simple 'default'
868 /// clause with kind 'shared'.
869 class OMPDefaultClause : public OMPClause {
870 friend class OMPClauseReader;
873 SourceLocation LParenLoc;
875 /// A kind of the 'default' clause.
876 llvm::omp::DefaultKind Kind = llvm::omp::OMP_DEFAULT_unknown;
878 /// Start location of the kind in source code.
879 SourceLocation KindKwLoc;
881 /// Set kind of the clauses.
883 /// \param K Argument of clause.
884 void setDefaultKind(llvm::omp::DefaultKind K) { Kind = K; }
886 /// Set argument location.
888 /// \param KLoc Argument location.
889 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
892 /// Build 'default' clause with argument \a A ('none' or 'shared').
894 /// \param A Argument of the clause ('none' or 'shared').
895 /// \param ALoc Starting location of the argument.
896 /// \param StartLoc Starting location of the clause.
897 /// \param LParenLoc Location of '('.
898 /// \param EndLoc Ending location of the clause.
899 OMPDefaultClause(llvm::omp::DefaultKind A, SourceLocation ALoc,
900 SourceLocation StartLoc, SourceLocation LParenLoc,
901 SourceLocation EndLoc)
902 : OMPClause(llvm::omp::OMPC_default, StartLoc, EndLoc),
903 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
905 /// Build an empty clause.
907 : OMPClause(llvm::omp::OMPC_default, SourceLocation(), SourceLocation()) {
910 /// Sets the location of '('.
911 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
913 /// Returns the location of '('.
914 SourceLocation getLParenLoc() const { return LParenLoc; }
916 /// Returns kind of the clause.
917 llvm::omp::DefaultKind getDefaultKind() const { return Kind; }
919 /// Returns location of clause kind.
920 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
922 child_range children() {
923 return child_range(child_iterator(), child_iterator());
926 const_child_range children() const {
927 return const_child_range(const_child_iterator(), const_child_iterator());
930 child_range used_children() {
931 return child_range(child_iterator(), child_iterator());
933 const_child_range used_children() const {
934 return const_child_range(const_child_iterator(), const_child_iterator());
937 static bool classof(const OMPClause *T) {
938 return T->getClauseKind() == llvm::omp::OMPC_default;
942 /// This represents 'proc_bind' clause in the '#pragma omp ...'
946 /// #pragma omp parallel proc_bind(master)
948 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
949 /// clause with kind 'master'.
950 class OMPProcBindClause : public OMPClause {
951 friend class OMPClauseReader;
954 SourceLocation LParenLoc;
956 /// A kind of the 'proc_bind' clause.
957 llvm::omp::ProcBindKind Kind = llvm::omp::OMP_PROC_BIND_unknown;
959 /// Start location of the kind in source code.
960 SourceLocation KindKwLoc;
962 /// Set kind of the clause.
964 /// \param K Kind of clause.
965 void setProcBindKind(llvm::omp::ProcBindKind K) { Kind = K; }
967 /// Set clause kind location.
969 /// \param KLoc Kind location.
970 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
973 /// Build 'proc_bind' clause with argument \a A ('master', 'close' or
976 /// \param A Argument of the clause ('master', 'close' or 'spread').
977 /// \param ALoc Starting location of the argument.
978 /// \param StartLoc Starting location of the clause.
979 /// \param LParenLoc Location of '('.
980 /// \param EndLoc Ending location of the clause.
981 OMPProcBindClause(llvm::omp::ProcBindKind A, SourceLocation ALoc,
982 SourceLocation StartLoc, SourceLocation LParenLoc,
983 SourceLocation EndLoc)
984 : OMPClause(llvm::omp::OMPC_proc_bind, StartLoc, EndLoc),
985 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
987 /// Build an empty clause.
989 : OMPClause(llvm::omp::OMPC_proc_bind, SourceLocation(),
992 /// Sets the location of '('.
993 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
995 /// Returns the location of '('.
996 SourceLocation getLParenLoc() const { return LParenLoc; }
998 /// Returns kind of the clause.
999 llvm::omp::ProcBindKind getProcBindKind() const { return Kind; }
1001 /// Returns location of clause kind.
1002 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
1004 child_range children() {
1005 return child_range(child_iterator(), child_iterator());
1008 const_child_range children() const {
1009 return const_child_range(const_child_iterator(), const_child_iterator());
1012 child_range used_children() {
1013 return child_range(child_iterator(), child_iterator());
1015 const_child_range used_children() const {
1016 return const_child_range(const_child_iterator(), const_child_iterator());
1019 static bool classof(const OMPClause *T) {
1020 return T->getClauseKind() == llvm::omp::OMPC_proc_bind;
1024 /// This represents 'unified_address' clause in the '#pragma omp requires'
1028 /// #pragma omp requires unified_address
1030 /// In this example directive '#pragma omp requires' has 'unified_address'
1032 class OMPUnifiedAddressClause final : public OMPClause {
1034 friend class OMPClauseReader;
1035 /// Build 'unified_address' clause.
1037 /// \param StartLoc Starting location of the clause.
1038 /// \param EndLoc Ending location of the clause.
1039 OMPUnifiedAddressClause(SourceLocation StartLoc, SourceLocation EndLoc)
1040 : OMPClause(llvm::omp::OMPC_unified_address, StartLoc, EndLoc) {}
1042 /// Build an empty clause.
1043 OMPUnifiedAddressClause()
1044 : OMPClause(llvm::omp::OMPC_unified_address, SourceLocation(),
1045 SourceLocation()) {}
1047 child_range children() {
1048 return child_range(child_iterator(), child_iterator());
1051 const_child_range children() const {
1052 return const_child_range(const_child_iterator(), const_child_iterator());
1055 child_range used_children() {
1056 return child_range(child_iterator(), child_iterator());
1058 const_child_range used_children() const {
1059 return const_child_range(const_child_iterator(), const_child_iterator());
1062 static bool classof(const OMPClause *T) {
1063 return T->getClauseKind() == llvm::omp::OMPC_unified_address;
1067 /// This represents 'unified_shared_memory' clause in the '#pragma omp requires'
1071 /// #pragma omp requires unified_shared_memory
1073 /// In this example directive '#pragma omp requires' has 'unified_shared_memory'
1075 class OMPUnifiedSharedMemoryClause final : public OMPClause {
1077 friend class OMPClauseReader;
1078 /// Build 'unified_shared_memory' clause.
1080 /// \param StartLoc Starting location of the clause.
1081 /// \param EndLoc Ending location of the clause.
1082 OMPUnifiedSharedMemoryClause(SourceLocation StartLoc, SourceLocation EndLoc)
1083 : OMPClause(llvm::omp::OMPC_unified_shared_memory, StartLoc, EndLoc) {}
1085 /// Build an empty clause.
1086 OMPUnifiedSharedMemoryClause()
1087 : OMPClause(llvm::omp::OMPC_unified_shared_memory, SourceLocation(),
1088 SourceLocation()) {}
1090 child_range children() {
1091 return child_range(child_iterator(), child_iterator());
1094 const_child_range children() const {
1095 return const_child_range(const_child_iterator(), const_child_iterator());
1098 child_range used_children() {
1099 return child_range(child_iterator(), child_iterator());
1101 const_child_range used_children() const {
1102 return const_child_range(const_child_iterator(), const_child_iterator());
1105 static bool classof(const OMPClause *T) {
1106 return T->getClauseKind() == llvm::omp::OMPC_unified_shared_memory;
1110 /// This represents 'reverse_offload' clause in the '#pragma omp requires'
1114 /// #pragma omp requires reverse_offload
1116 /// In this example directive '#pragma omp requires' has 'reverse_offload'
1118 class OMPReverseOffloadClause final : public OMPClause {
1120 friend class OMPClauseReader;
1121 /// Build 'reverse_offload' clause.
1123 /// \param StartLoc Starting location of the clause.
1124 /// \param EndLoc Ending location of the clause.
1125 OMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1126 : OMPClause(llvm::omp::OMPC_reverse_offload, StartLoc, EndLoc) {}
1128 /// Build an empty clause.
1129 OMPReverseOffloadClause()
1130 : OMPClause(llvm::omp::OMPC_reverse_offload, SourceLocation(),
1131 SourceLocation()) {}
1133 child_range children() {
1134 return child_range(child_iterator(), child_iterator());
1137 const_child_range children() const {
1138 return const_child_range(const_child_iterator(), const_child_iterator());
1141 child_range used_children() {
1142 return child_range(child_iterator(), child_iterator());
1144 const_child_range used_children() const {
1145 return const_child_range(const_child_iterator(), const_child_iterator());
1148 static bool classof(const OMPClause *T) {
1149 return T->getClauseKind() == llvm::omp::OMPC_reverse_offload;
1153 /// This represents 'dynamic_allocators' clause in the '#pragma omp requires'
1157 /// #pragma omp requires dynamic_allocators
1159 /// In this example directive '#pragma omp requires' has 'dynamic_allocators'
1161 class OMPDynamicAllocatorsClause final : public OMPClause {
1163 friend class OMPClauseReader;
1164 /// Build 'dynamic_allocators' clause.
1166 /// \param StartLoc Starting location of the clause.
1167 /// \param EndLoc Ending location of the clause.
1168 OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc)
1169 : OMPClause(llvm::omp::OMPC_dynamic_allocators, StartLoc, EndLoc) {}
1171 /// Build an empty clause.
1172 OMPDynamicAllocatorsClause()
1173 : OMPClause(llvm::omp::OMPC_dynamic_allocators, SourceLocation(),
1174 SourceLocation()) {}
1176 child_range children() {
1177 return child_range(child_iterator(), child_iterator());
1180 const_child_range children() const {
1181 return const_child_range(const_child_iterator(), const_child_iterator());
1184 child_range used_children() {
1185 return child_range(child_iterator(), child_iterator());
1187 const_child_range used_children() const {
1188 return const_child_range(const_child_iterator(), const_child_iterator());
1191 static bool classof(const OMPClause *T) {
1192 return T->getClauseKind() == llvm::omp::OMPC_dynamic_allocators;
1196 /// This represents 'atomic_default_mem_order' clause in the '#pragma omp
1197 /// requires' directive.
1200 /// #pragma omp requires atomic_default_mem_order(seq_cst)
1202 /// In this example directive '#pragma omp requires' has simple
1203 /// atomic_default_mem_order' clause with kind 'seq_cst'.
1204 class OMPAtomicDefaultMemOrderClause final : public OMPClause {
1205 friend class OMPClauseReader;
1208 SourceLocation LParenLoc;
1210 /// A kind of the 'atomic_default_mem_order' clause.
1211 OpenMPAtomicDefaultMemOrderClauseKind Kind =
1212 OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown;
1214 /// Start location of the kind in source code.
1215 SourceLocation KindKwLoc;
1217 /// Set kind of the clause.
1219 /// \param K Kind of clause.
1220 void setAtomicDefaultMemOrderKind(OpenMPAtomicDefaultMemOrderClauseKind K) {
1224 /// Set clause kind location.
1226 /// \param KLoc Kind location.
1227 void setAtomicDefaultMemOrderKindKwLoc(SourceLocation KLoc) {
1232 /// Build 'atomic_default_mem_order' clause with argument \a A ('seq_cst',
1233 /// 'acq_rel' or 'relaxed').
1235 /// \param A Argument of the clause ('seq_cst', 'acq_rel' or 'relaxed').
1236 /// \param ALoc Starting location of the argument.
1237 /// \param StartLoc Starting location of the clause.
1238 /// \param LParenLoc Location of '('.
1239 /// \param EndLoc Ending location of the clause.
1240 OMPAtomicDefaultMemOrderClause(OpenMPAtomicDefaultMemOrderClauseKind A,
1241 SourceLocation ALoc, SourceLocation StartLoc,
1242 SourceLocation LParenLoc,
1243 SourceLocation EndLoc)
1244 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, StartLoc, EndLoc),
1245 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
1247 /// Build an empty clause.
1248 OMPAtomicDefaultMemOrderClause()
1249 : OMPClause(llvm::omp::OMPC_atomic_default_mem_order, SourceLocation(),
1250 SourceLocation()) {}
1252 /// Sets the location of '('.
1253 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1255 /// Returns the locaiton of '('.
1256 SourceLocation getLParenLoc() const { return LParenLoc; }
1258 /// Returns kind of the clause.
1259 OpenMPAtomicDefaultMemOrderClauseKind getAtomicDefaultMemOrderKind() const {
1263 /// Returns location of clause kind.
1264 SourceLocation getAtomicDefaultMemOrderKindKwLoc() const { return KindKwLoc; }
1266 child_range children() {
1267 return child_range(child_iterator(), child_iterator());
1270 const_child_range children() const {
1271 return const_child_range(const_child_iterator(), const_child_iterator());
1274 child_range used_children() {
1275 return child_range(child_iterator(), child_iterator());
1277 const_child_range used_children() const {
1278 return const_child_range(const_child_iterator(), const_child_iterator());
1281 static bool classof(const OMPClause *T) {
1282 return T->getClauseKind() == llvm::omp::OMPC_atomic_default_mem_order;
1286 /// This represents 'schedule' clause in the '#pragma omp ...' directive.
1289 /// #pragma omp for schedule(static, 3)
1291 /// In this example directive '#pragma omp for' has 'schedule' clause with
1292 /// arguments 'static' and '3'.
1293 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
1294 friend class OMPClauseReader;
1296 /// Location of '('.
1297 SourceLocation LParenLoc;
1299 /// A kind of the 'schedule' clause.
1300 OpenMPScheduleClauseKind Kind = OMPC_SCHEDULE_unknown;
1302 /// Modifiers for 'schedule' clause.
1303 enum {FIRST, SECOND, NUM_MODIFIERS};
1304 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
1306 /// Locations of modifiers.
1307 SourceLocation ModifiersLoc[NUM_MODIFIERS];
1309 /// Start location of the schedule ind in source code.
1310 SourceLocation KindLoc;
1312 /// Location of ',' (if any).
1313 SourceLocation CommaLoc;
1316 Expr *ChunkSize = nullptr;
1318 /// Set schedule kind.
1320 /// \param K Schedule kind.
1321 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
1323 /// Set the first schedule modifier.
1325 /// \param M Schedule modifier.
1326 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
1327 Modifiers[FIRST] = M;
1330 /// Set the second schedule modifier.
1332 /// \param M Schedule modifier.
1333 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
1334 Modifiers[SECOND] = M;
1337 /// Set location of the first schedule modifier.
1338 void setFirstScheduleModifierLoc(SourceLocation Loc) {
1339 ModifiersLoc[FIRST] = Loc;
1342 /// Set location of the second schedule modifier.
1343 void setSecondScheduleModifierLoc(SourceLocation Loc) {
1344 ModifiersLoc[SECOND] = Loc;
1347 /// Set schedule modifier location.
1349 /// \param M Schedule modifier location.
1350 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
1351 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
1352 Modifiers[FIRST] = M;
1354 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
1355 Modifiers[SECOND] = M;
1359 /// Sets the location of '('.
1361 /// \param Loc Location of '('.
1362 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1364 /// Set schedule kind start location.
1366 /// \param KLoc Schedule kind location.
1367 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
1369 /// Set location of ','.
1371 /// \param Loc Location of ','.
1372 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
1376 /// \param E Chunk size.
1377 void setChunkSize(Expr *E) { ChunkSize = E; }
1380 /// Build 'schedule' clause with schedule kind \a Kind and chunk size
1381 /// expression \a ChunkSize.
1383 /// \param StartLoc Starting location of the clause.
1384 /// \param LParenLoc Location of '('.
1385 /// \param KLoc Starting location of the argument.
1386 /// \param CommaLoc Location of ','.
1387 /// \param EndLoc Ending location of the clause.
1388 /// \param Kind Schedule kind.
1389 /// \param ChunkSize Chunk size.
1390 /// \param HelperChunkSize Helper chunk size for combined directives.
1391 /// \param M1 The first modifier applied to 'schedule' clause.
1392 /// \param M1Loc Location of the first modifier
1393 /// \param M2 The second modifier applied to 'schedule' clause.
1394 /// \param M2Loc Location of the second modifier
1395 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1396 SourceLocation KLoc, SourceLocation CommaLoc,
1397 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
1398 Expr *ChunkSize, Stmt *HelperChunkSize,
1399 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
1400 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
1401 : OMPClause(llvm::omp::OMPC_schedule, StartLoc, EndLoc),
1402 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
1403 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
1404 setPreInitStmt(HelperChunkSize);
1405 Modifiers[FIRST] = M1;
1406 Modifiers[SECOND] = M2;
1407 ModifiersLoc[FIRST] = M1Loc;
1408 ModifiersLoc[SECOND] = M2Loc;
1411 /// Build an empty clause.
1412 explicit OMPScheduleClause()
1413 : OMPClause(llvm::omp::OMPC_schedule, SourceLocation(), SourceLocation()),
1414 OMPClauseWithPreInit(this) {
1415 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
1416 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
1419 /// Get kind of the clause.
1420 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
1422 /// Get the first modifier of the clause.
1423 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
1424 return Modifiers[FIRST];
1427 /// Get the second modifier of the clause.
1428 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
1429 return Modifiers[SECOND];
1432 /// Get location of '('.
1433 SourceLocation getLParenLoc() { return LParenLoc; }
1435 /// Get kind location.
1436 SourceLocation getScheduleKindLoc() { return KindLoc; }
1438 /// Get the first modifier location.
1439 SourceLocation getFirstScheduleModifierLoc() const {
1440 return ModifiersLoc[FIRST];
1443 /// Get the second modifier location.
1444 SourceLocation getSecondScheduleModifierLoc() const {
1445 return ModifiersLoc[SECOND];
1448 /// Get location of ','.
1449 SourceLocation getCommaLoc() { return CommaLoc; }
1452 Expr *getChunkSize() { return ChunkSize; }
1455 const Expr *getChunkSize() const { return ChunkSize; }
1457 child_range children() {
1458 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
1459 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
1462 const_child_range children() const {
1463 auto Children = const_cast<OMPScheduleClause *>(this)->children();
1464 return const_child_range(Children.begin(), Children.end());
1467 child_range used_children() {
1468 return child_range(child_iterator(), child_iterator());
1470 const_child_range used_children() const {
1471 return const_child_range(const_child_iterator(), const_child_iterator());
1474 static bool classof(const OMPClause *T) {
1475 return T->getClauseKind() == llvm::omp::OMPC_schedule;
1479 /// This represents 'ordered' clause in the '#pragma omp ...' directive.
1482 /// #pragma omp for ordered (2)
1484 /// In this example directive '#pragma omp for' has 'ordered' clause with
1486 class OMPOrderedClause final
1488 private llvm::TrailingObjects<OMPOrderedClause, Expr *> {
1489 friend class OMPClauseReader;
1490 friend TrailingObjects;
1492 /// Location of '('.
1493 SourceLocation LParenLoc;
1495 /// Number of for-loops.
1496 Stmt *NumForLoops = nullptr;
1498 /// Real number of loops.
1499 unsigned NumberOfLoops = 0;
1501 /// Build 'ordered' clause.
1503 /// \param Num Expression, possibly associated with this clause.
1504 /// \param NumLoops Number of loops, associated with this clause.
1505 /// \param StartLoc Starting location of the clause.
1506 /// \param LParenLoc Location of '('.
1507 /// \param EndLoc Ending location of the clause.
1508 OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
1509 SourceLocation LParenLoc, SourceLocation EndLoc)
1510 : OMPClause(llvm::omp::OMPC_ordered, StartLoc, EndLoc),
1511 LParenLoc(LParenLoc), NumForLoops(Num), NumberOfLoops(NumLoops) {}
1513 /// Build an empty clause.
1514 explicit OMPOrderedClause(unsigned NumLoops)
1515 : OMPClause(llvm::omp::OMPC_ordered, SourceLocation(), SourceLocation()),
1516 NumberOfLoops(NumLoops) {}
1518 /// Set the number of associated for-loops.
1519 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
1522 /// Build 'ordered' clause.
1524 /// \param Num Expression, possibly associated with this clause.
1525 /// \param NumLoops Number of loops, associated with this clause.
1526 /// \param StartLoc Starting location of the clause.
1527 /// \param LParenLoc Location of '('.
1528 /// \param EndLoc Ending location of the clause.
1529 static OMPOrderedClause *Create(const ASTContext &C, Expr *Num,
1530 unsigned NumLoops, SourceLocation StartLoc,
1531 SourceLocation LParenLoc,
1532 SourceLocation EndLoc);
1534 /// Build an empty clause.
1535 static OMPOrderedClause* CreateEmpty(const ASTContext &C, unsigned NumLoops);
1537 /// Sets the location of '('.
1538 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
1540 /// Returns the location of '('.
1541 SourceLocation getLParenLoc() const { return LParenLoc; }
1543 /// Return the number of associated for-loops.
1544 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
1546 /// Set number of iterations for the specified loop.
1547 void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
1548 /// Get number of iterations for all the loops.
1549 ArrayRef<Expr *> getLoopNumIterations() const;
1551 /// Set loop counter for the specified loop.
1552 void setLoopCounter(unsigned NumLoop, Expr *Counter);
1553 /// Get loops counter for the specified loop.
1554 Expr *getLoopCounter(unsigned NumLoop);
1555 const Expr *getLoopCounter(unsigned NumLoop) const;
1557 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
1559 const_child_range children() const {
1560 return const_child_range(&NumForLoops, &NumForLoops + 1);
1563 child_range used_children() {
1564 return child_range(child_iterator(), child_iterator());
1566 const_child_range used_children() const {
1567 return const_child_range(const_child_iterator(), const_child_iterator());
1570 static bool classof(const OMPClause *T) {
1571 return T->getClauseKind() == llvm::omp::OMPC_ordered;
1575 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
1578 /// #pragma omp for nowait
1580 /// In this example directive '#pragma omp for' has 'nowait' clause.
1581 class OMPNowaitClause : public OMPClause {
1583 /// Build 'nowait' clause.
1585 /// \param StartLoc Starting location of the clause.
1586 /// \param EndLoc Ending location of the clause.
1587 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
1588 : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc) {}
1590 /// Build an empty clause.
1592 : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) {}
1594 child_range children() {
1595 return child_range(child_iterator(), child_iterator());
1598 const_child_range children() const {
1599 return const_child_range(const_child_iterator(), const_child_iterator());
1602 child_range used_children() {
1603 return child_range(child_iterator(), child_iterator());
1605 const_child_range used_children() const {
1606 return const_child_range(const_child_iterator(), const_child_iterator());
1609 static bool classof(const OMPClause *T) {
1610 return T->getClauseKind() == llvm::omp::OMPC_nowait;
1614 /// This represents 'untied' clause in the '#pragma omp ...' directive.
1617 /// #pragma omp task untied
1619 /// In this example directive '#pragma omp task' has 'untied' clause.
1620 class OMPUntiedClause : public OMPClause {
1622 /// Build 'untied' clause.
1624 /// \param StartLoc Starting location of the clause.
1625 /// \param EndLoc Ending location of the clause.
1626 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
1627 : OMPClause(llvm::omp::OMPC_untied, StartLoc, EndLoc) {}
1629 /// Build an empty clause.
1631 : OMPClause(llvm::omp::OMPC_untied, SourceLocation(), SourceLocation()) {}
1633 child_range children() {
1634 return child_range(child_iterator(), child_iterator());
1637 const_child_range children() const {
1638 return const_child_range(const_child_iterator(), const_child_iterator());
1641 child_range used_children() {
1642 return child_range(child_iterator(), child_iterator());
1644 const_child_range used_children() const {
1645 return const_child_range(const_child_iterator(), const_child_iterator());
1648 static bool classof(const OMPClause *T) {
1649 return T->getClauseKind() == llvm::omp::OMPC_untied;
1653 /// This represents 'mergeable' clause in the '#pragma omp ...'
1657 /// #pragma omp task mergeable
1659 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1660 class OMPMergeableClause : public OMPClause {
1662 /// Build 'mergeable' clause.
1664 /// \param StartLoc Starting location of the clause.
1665 /// \param EndLoc Ending location of the clause.
1666 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
1667 : OMPClause(llvm::omp::OMPC_mergeable, StartLoc, EndLoc) {}
1669 /// Build an empty clause.
1670 OMPMergeableClause()
1671 : OMPClause(llvm::omp::OMPC_mergeable, SourceLocation(),
1672 SourceLocation()) {}
1674 child_range children() {
1675 return child_range(child_iterator(), child_iterator());
1678 const_child_range children() const {
1679 return const_child_range(const_child_iterator(), const_child_iterator());
1682 child_range used_children() {
1683 return child_range(child_iterator(), child_iterator());
1685 const_child_range used_children() const {
1686 return const_child_range(const_child_iterator(), const_child_iterator());
1689 static bool classof(const OMPClause *T) {
1690 return T->getClauseKind() == llvm::omp::OMPC_mergeable;
1694 /// This represents 'read' clause in the '#pragma omp atomic' directive.
1697 /// #pragma omp atomic read
1699 /// In this example directive '#pragma omp atomic' has 'read' clause.
1700 class OMPReadClause : public OMPClause {
1702 /// Build 'read' clause.
1704 /// \param StartLoc Starting location of the clause.
1705 /// \param EndLoc Ending location of the clause.
1706 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1707 : OMPClause(llvm::omp::OMPC_read, StartLoc, EndLoc) {}
1709 /// Build an empty clause.
1711 : OMPClause(llvm::omp::OMPC_read, SourceLocation(), SourceLocation()) {}
1713 child_range children() {
1714 return child_range(child_iterator(), child_iterator());
1717 const_child_range children() const {
1718 return const_child_range(const_child_iterator(), const_child_iterator());
1721 child_range used_children() {
1722 return child_range(child_iterator(), child_iterator());
1724 const_child_range used_children() const {
1725 return const_child_range(const_child_iterator(), const_child_iterator());
1728 static bool classof(const OMPClause *T) {
1729 return T->getClauseKind() == llvm::omp::OMPC_read;
1733 /// This represents 'write' clause in the '#pragma omp atomic' directive.
1736 /// #pragma omp atomic write
1738 /// In this example directive '#pragma omp atomic' has 'write' clause.
1739 class OMPWriteClause : public OMPClause {
1741 /// Build 'write' clause.
1743 /// \param StartLoc Starting location of the clause.
1744 /// \param EndLoc Ending location of the clause.
1745 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1746 : OMPClause(llvm::omp::OMPC_write, StartLoc, EndLoc) {}
1748 /// Build an empty clause.
1750 : OMPClause(llvm::omp::OMPC_write, SourceLocation(), SourceLocation()) {}
1752 child_range children() {
1753 return child_range(child_iterator(), child_iterator());
1756 const_child_range children() const {
1757 return const_child_range(const_child_iterator(), const_child_iterator());
1760 child_range used_children() {
1761 return child_range(child_iterator(), child_iterator());
1763 const_child_range used_children() const {
1764 return const_child_range(const_child_iterator(), const_child_iterator());
1767 static bool classof(const OMPClause *T) {
1768 return T->getClauseKind() == llvm::omp::OMPC_write;
1772 /// This represents 'update' clause in the '#pragma omp atomic'
1776 /// #pragma omp atomic update
1778 /// In this example directive '#pragma omp atomic' has 'update' clause.
1779 /// Also, this class represents 'update' clause in '#pragma omp depobj'
1783 /// #pragma omp depobj(a) update(in)
1785 /// In this example directive '#pragma omp depobj' has 'update' clause with 'in'
1786 /// dependence kind.
1787 class OMPUpdateClause final
1789 private llvm::TrailingObjects<OMPUpdateClause, SourceLocation,
1790 OpenMPDependClauseKind> {
1791 friend class OMPClauseReader;
1792 friend TrailingObjects;
1794 /// true if extended version of the clause for 'depobj' directive.
1795 bool IsExtended = false;
1797 /// Define the sizes of each trailing object array except the last one. This
1798 /// is required for TrailingObjects to work properly.
1799 size_t numTrailingObjects(OverloadToken<SourceLocation>) const {
1800 // 2 locations: for '(' and argument location.
1801 return IsExtended ? 2 : 0;
1804 /// Sets the the location of '(' in clause for 'depobj' directive.
1805 void setLParenLoc(SourceLocation Loc) {
1806 assert(IsExtended && "Expected extended clause.");
1807 *getTrailingObjects<SourceLocation>() = Loc;
1810 /// Sets the the location of '(' in clause for 'depobj' directive.
1811 void setArgumentLoc(SourceLocation Loc) {
1812 assert(IsExtended && "Expected extended clause.");
1813 *std::next(getTrailingObjects<SourceLocation>(), 1) = Loc;
1816 /// Sets the dependence kind for the clause for 'depobj' directive.
1817 void setDependencyKind(OpenMPDependClauseKind DK) {
1818 assert(IsExtended && "Expected extended clause.");
1819 *getTrailingObjects<OpenMPDependClauseKind>() = DK;
1822 /// Build 'update' clause.
1824 /// \param StartLoc Starting location of the clause.
1825 /// \param EndLoc Ending location of the clause.
1826 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc,
1828 : OMPClause(llvm::omp::OMPC_update, StartLoc, EndLoc),
1829 IsExtended(IsExtended) {}
1831 /// Build an empty clause.
1832 OMPUpdateClause(bool IsExtended)
1833 : OMPClause(llvm::omp::OMPC_update, SourceLocation(), SourceLocation()),
1834 IsExtended(IsExtended) {}
1837 /// Creates clause for 'atomic' directive.
1839 /// \param C AST context.
1840 /// \param StartLoc Starting location of the clause.
1841 /// \param EndLoc Ending location of the clause.
1842 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1843 SourceLocation EndLoc);
1845 /// Creates clause for 'depobj' directive.
1847 /// \param C AST context.
1848 /// \param StartLoc Starting location of the clause.
1849 /// \param LParenLoc Location of '('.
1850 /// \param ArgumentLoc Location of the argument.
1851 /// \param DK Dependence kind.
1852 /// \param EndLoc Ending location of the clause.
1853 static OMPUpdateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1854 SourceLocation LParenLoc,
1855 SourceLocation ArgumentLoc,
1856 OpenMPDependClauseKind DK,
1857 SourceLocation EndLoc);
1859 /// Creates an empty clause with the place for \a N variables.
1861 /// \param C AST context.
1862 /// \param IsExtended true if extended clause for 'depobj' directive must be
1864 static OMPUpdateClause *CreateEmpty(const ASTContext &C, bool IsExtended);
1866 /// Checks if the clause is the extended clauses for 'depobj' directive.
1867 bool isExtended() const { return IsExtended; }
1869 child_range children() {
1870 return child_range(child_iterator(), child_iterator());
1873 const_child_range children() const {
1874 return const_child_range(const_child_iterator(), const_child_iterator());
1877 child_range used_children() {
1878 return child_range(child_iterator(), child_iterator());
1880 const_child_range used_children() const {
1881 return const_child_range(const_child_iterator(), const_child_iterator());
1884 /// Gets the the location of '(' in clause for 'depobj' directive.
1885 SourceLocation getLParenLoc() const {
1886 assert(IsExtended && "Expected extended clause.");
1887 return *getTrailingObjects<SourceLocation>();
1890 /// Gets the the location of argument in clause for 'depobj' directive.
1891 SourceLocation getArgumentLoc() const {
1892 assert(IsExtended && "Expected extended clause.");
1893 return *std::next(getTrailingObjects<SourceLocation>(), 1);
1896 /// Gets the dependence kind in clause for 'depobj' directive.
1897 OpenMPDependClauseKind getDependencyKind() const {
1898 assert(IsExtended && "Expected extended clause.");
1899 return *getTrailingObjects<OpenMPDependClauseKind>();
1902 static bool classof(const OMPClause *T) {
1903 return T->getClauseKind() == llvm::omp::OMPC_update;
1907 /// This represents 'capture' clause in the '#pragma omp atomic'
1911 /// #pragma omp atomic capture
1913 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1914 class OMPCaptureClause : public OMPClause {
1916 /// Build 'capture' clause.
1918 /// \param StartLoc Starting location of the clause.
1919 /// \param EndLoc Ending location of the clause.
1920 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1921 : OMPClause(llvm::omp::OMPC_capture, StartLoc, EndLoc) {}
1923 /// Build an empty clause.
1925 : OMPClause(llvm::omp::OMPC_capture, SourceLocation(), SourceLocation()) {
1928 child_range children() {
1929 return child_range(child_iterator(), child_iterator());
1932 const_child_range children() const {
1933 return const_child_range(const_child_iterator(), const_child_iterator());
1936 child_range used_children() {
1937 return child_range(child_iterator(), child_iterator());
1939 const_child_range used_children() const {
1940 return const_child_range(const_child_iterator(), const_child_iterator());
1943 static bool classof(const OMPClause *T) {
1944 return T->getClauseKind() == llvm::omp::OMPC_capture;
1948 /// This represents 'seq_cst' clause in the '#pragma omp atomic'
1952 /// #pragma omp atomic seq_cst
1954 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1955 class OMPSeqCstClause : public OMPClause {
1957 /// Build 'seq_cst' clause.
1959 /// \param StartLoc Starting location of the clause.
1960 /// \param EndLoc Ending location of the clause.
1961 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1962 : OMPClause(llvm::omp::OMPC_seq_cst, StartLoc, EndLoc) {}
1964 /// Build an empty clause.
1966 : OMPClause(llvm::omp::OMPC_seq_cst, SourceLocation(), SourceLocation()) {
1969 child_range children() {
1970 return child_range(child_iterator(), child_iterator());
1973 const_child_range children() const {
1974 return const_child_range(const_child_iterator(), const_child_iterator());
1977 child_range used_children() {
1978 return child_range(child_iterator(), child_iterator());
1980 const_child_range used_children() const {
1981 return const_child_range(const_child_iterator(), const_child_iterator());
1984 static bool classof(const OMPClause *T) {
1985 return T->getClauseKind() == llvm::omp::OMPC_seq_cst;
1989 /// This represents 'acq_rel' clause in the '#pragma omp atomic|flush'
1993 /// #pragma omp flush acq_rel
1995 /// In this example directive '#pragma omp flush' has 'acq_rel' clause.
1996 class OMPAcqRelClause final : public OMPClause {
1998 /// Build 'ack_rel' clause.
2000 /// \param StartLoc Starting location of the clause.
2001 /// \param EndLoc Ending location of the clause.
2002 OMPAcqRelClause(SourceLocation StartLoc, SourceLocation EndLoc)
2003 : OMPClause(llvm::omp::OMPC_acq_rel, StartLoc, EndLoc) {}
2005 /// Build an empty clause.
2007 : OMPClause(llvm::omp::OMPC_acq_rel, SourceLocation(), SourceLocation()) {
2010 child_range children() {
2011 return child_range(child_iterator(), child_iterator());
2014 const_child_range children() const {
2015 return const_child_range(const_child_iterator(), const_child_iterator());
2018 child_range used_children() {
2019 return child_range(child_iterator(), child_iterator());
2021 const_child_range used_children() const {
2022 return const_child_range(const_child_iterator(), const_child_iterator());
2025 static bool classof(const OMPClause *T) {
2026 return T->getClauseKind() == llvm::omp::OMPC_acq_rel;
2030 /// This represents 'acquire' clause in the '#pragma omp atomic|flush'
2034 /// #pragma omp flush acquire
2036 /// In this example directive '#pragma omp flush' has 'acquire' clause.
2037 class OMPAcquireClause final : public OMPClause {
2039 /// Build 'acquire' clause.
2041 /// \param StartLoc Starting location of the clause.
2042 /// \param EndLoc Ending location of the clause.
2043 OMPAcquireClause(SourceLocation StartLoc, SourceLocation EndLoc)
2044 : OMPClause(llvm::omp::OMPC_acquire, StartLoc, EndLoc) {}
2046 /// Build an empty clause.
2048 : OMPClause(llvm::omp::OMPC_acquire, SourceLocation(), SourceLocation()) {
2051 child_range children() {
2052 return child_range(child_iterator(), child_iterator());
2055 const_child_range children() const {
2056 return const_child_range(const_child_iterator(), const_child_iterator());
2059 child_range used_children() {
2060 return child_range(child_iterator(), child_iterator());
2062 const_child_range used_children() const {
2063 return const_child_range(const_child_iterator(), const_child_iterator());
2066 static bool classof(const OMPClause *T) {
2067 return T->getClauseKind() == llvm::omp::OMPC_acquire;
2071 /// This represents 'release' clause in the '#pragma omp atomic|flush'
2075 /// #pragma omp flush release
2077 /// In this example directive '#pragma omp flush' has 'release' clause.
2078 class OMPReleaseClause final : public OMPClause {
2080 /// Build 'release' clause.
2082 /// \param StartLoc Starting location of the clause.
2083 /// \param EndLoc Ending location of the clause.
2084 OMPReleaseClause(SourceLocation StartLoc, SourceLocation EndLoc)
2085 : OMPClause(llvm::omp::OMPC_release, StartLoc, EndLoc) {}
2087 /// Build an empty clause.
2089 : OMPClause(llvm::omp::OMPC_release, SourceLocation(), SourceLocation()) {
2092 child_range children() {
2093 return child_range(child_iterator(), child_iterator());
2096 const_child_range children() const {
2097 return const_child_range(const_child_iterator(), const_child_iterator());
2100 child_range used_children() {
2101 return child_range(child_iterator(), child_iterator());
2103 const_child_range used_children() const {
2104 return const_child_range(const_child_iterator(), const_child_iterator());
2107 static bool classof(const OMPClause *T) {
2108 return T->getClauseKind() == llvm::omp::OMPC_release;
2112 /// This represents 'relaxed' clause in the '#pragma omp atomic'
2116 /// #pragma omp atomic relaxed
2118 /// In this example directive '#pragma omp atomic' has 'relaxed' clause.
2119 class OMPRelaxedClause final : public OMPClause {
2121 /// Build 'relaxed' clause.
2123 /// \param StartLoc Starting location of the clause.
2124 /// \param EndLoc Ending location of the clause.
2125 OMPRelaxedClause(SourceLocation StartLoc, SourceLocation EndLoc)
2126 : OMPClause(llvm::omp::OMPC_relaxed, StartLoc, EndLoc) {}
2128 /// Build an empty clause.
2130 : OMPClause(llvm::omp::OMPC_relaxed, SourceLocation(), SourceLocation()) {
2133 child_range children() {
2134 return child_range(child_iterator(), child_iterator());
2137 const_child_range children() const {
2138 return const_child_range(const_child_iterator(), const_child_iterator());
2141 child_range used_children() {
2142 return child_range(child_iterator(), child_iterator());
2144 const_child_range used_children() const {
2145 return const_child_range(const_child_iterator(), const_child_iterator());
2148 static bool classof(const OMPClause *T) {
2149 return T->getClauseKind() == llvm::omp::OMPC_relaxed;
2153 /// This represents clause 'private' in the '#pragma omp ...' directives.
2156 /// #pragma omp parallel private(a,b)
2158 /// In this example directive '#pragma omp parallel' has clause 'private'
2159 /// with the variables 'a' and 'b'.
2160 class OMPPrivateClause final
2161 : public OMPVarListClause<OMPPrivateClause>,
2162 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
2163 friend class OMPClauseReader;
2164 friend OMPVarListClause;
2165 friend TrailingObjects;
2167 /// Build clause with number of variables \a N.
2169 /// \param StartLoc Starting location of the clause.
2170 /// \param LParenLoc Location of '('.
2171 /// \param EndLoc Ending location of the clause.
2172 /// \param N Number of the variables in the clause.
2173 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2174 SourceLocation EndLoc, unsigned N)
2175 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private, StartLoc,
2176 LParenLoc, EndLoc, N) {}
2178 /// Build an empty clause.
2180 /// \param N Number of variables.
2181 explicit OMPPrivateClause(unsigned N)
2182 : OMPVarListClause<OMPPrivateClause>(llvm::omp::OMPC_private,
2183 SourceLocation(), SourceLocation(),
2184 SourceLocation(), N) {}
2186 /// Sets the list of references to private copies with initializers for
2187 /// new private variables.
2188 /// \param VL List of references.
2189 void setPrivateCopies(ArrayRef<Expr *> VL);
2191 /// Gets the list of references to private copies with initializers for
2192 /// new private variables.
2193 MutableArrayRef<Expr *> getPrivateCopies() {
2194 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2196 ArrayRef<const Expr *> getPrivateCopies() const {
2197 return llvm::makeArrayRef(varlist_end(), varlist_size());
2201 /// Creates clause with a list of variables \a VL.
2203 /// \param C AST context.
2204 /// \param StartLoc Starting location of the clause.
2205 /// \param LParenLoc Location of '('.
2206 /// \param EndLoc Ending location of the clause.
2207 /// \param VL List of references to the variables.
2208 /// \param PrivateVL List of references to private copies with initializers.
2209 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
2210 SourceLocation LParenLoc,
2211 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2212 ArrayRef<Expr *> PrivateVL);
2214 /// Creates an empty clause with the place for \a N variables.
2216 /// \param C AST context.
2217 /// \param N The number of variables.
2218 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2220 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
2221 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
2222 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2223 using private_copies_const_range =
2224 llvm::iterator_range<private_copies_const_iterator>;
2226 private_copies_range private_copies() {
2227 return private_copies_range(getPrivateCopies().begin(),
2228 getPrivateCopies().end());
2231 private_copies_const_range private_copies() const {
2232 return private_copies_const_range(getPrivateCopies().begin(),
2233 getPrivateCopies().end());
2236 child_range children() {
2237 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2238 reinterpret_cast<Stmt **>(varlist_end()));
2241 const_child_range children() const {
2242 auto Children = const_cast<OMPPrivateClause *>(this)->children();
2243 return const_child_range(Children.begin(), Children.end());
2246 child_range used_children() {
2247 return child_range(child_iterator(), child_iterator());
2249 const_child_range used_children() const {
2250 return const_child_range(const_child_iterator(), const_child_iterator());
2253 static bool classof(const OMPClause *T) {
2254 return T->getClauseKind() == llvm::omp::OMPC_private;
2258 /// This represents clause 'firstprivate' in the '#pragma omp ...'
2262 /// #pragma omp parallel firstprivate(a,b)
2264 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
2265 /// with the variables 'a' and 'b'.
2266 class OMPFirstprivateClause final
2267 : public OMPVarListClause<OMPFirstprivateClause>,
2268 public OMPClauseWithPreInit,
2269 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
2270 friend class OMPClauseReader;
2271 friend OMPVarListClause;
2272 friend TrailingObjects;
2274 /// Build clause with number of variables \a N.
2276 /// \param StartLoc Starting location of the clause.
2277 /// \param LParenLoc Location of '('.
2278 /// \param EndLoc Ending location of the clause.
2279 /// \param N Number of the variables in the clause.
2280 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2281 SourceLocation EndLoc, unsigned N)
2282 : OMPVarListClause<OMPFirstprivateClause>(llvm::omp::OMPC_firstprivate,
2283 StartLoc, LParenLoc, EndLoc, N),
2284 OMPClauseWithPreInit(this) {}
2286 /// Build an empty clause.
2288 /// \param N Number of variables.
2289 explicit OMPFirstprivateClause(unsigned N)
2290 : OMPVarListClause<OMPFirstprivateClause>(
2291 llvm::omp::OMPC_firstprivate, SourceLocation(), SourceLocation(),
2292 SourceLocation(), N),
2293 OMPClauseWithPreInit(this) {}
2295 /// Sets the list of references to private copies with initializers for
2296 /// new private variables.
2297 /// \param VL List of references.
2298 void setPrivateCopies(ArrayRef<Expr *> VL);
2300 /// Gets the list of references to private copies with initializers for
2301 /// new private variables.
2302 MutableArrayRef<Expr *> getPrivateCopies() {
2303 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2305 ArrayRef<const Expr *> getPrivateCopies() const {
2306 return llvm::makeArrayRef(varlist_end(), varlist_size());
2309 /// Sets the list of references to initializer variables for new
2310 /// private variables.
2311 /// \param VL List of references.
2312 void setInits(ArrayRef<Expr *> VL);
2314 /// Gets the list of references to initializer variables for new
2315 /// private variables.
2316 MutableArrayRef<Expr *> getInits() {
2317 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2319 ArrayRef<const Expr *> getInits() const {
2320 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2324 /// Creates clause with a list of variables \a VL.
2326 /// \param C AST context.
2327 /// \param StartLoc Starting location of the clause.
2328 /// \param LParenLoc Location of '('.
2329 /// \param EndLoc Ending location of the clause.
2330 /// \param VL List of references to the original variables.
2331 /// \param PrivateVL List of references to private copies with initializers.
2332 /// \param InitVL List of references to auto generated variables used for
2333 /// initialization of a single array element. Used if firstprivate variable is
2335 /// \param PreInit Statement that must be executed before entering the OpenMP
2336 /// region with this clause.
2337 static OMPFirstprivateClause *
2338 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2339 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
2340 ArrayRef<Expr *> InitVL, Stmt *PreInit);
2342 /// Creates an empty clause with the place for \a N variables.
2344 /// \param C AST context.
2345 /// \param N The number of variables.
2346 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2348 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
2349 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
2350 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
2351 using private_copies_const_range =
2352 llvm::iterator_range<private_copies_const_iterator>;
2354 private_copies_range private_copies() {
2355 return private_copies_range(getPrivateCopies().begin(),
2356 getPrivateCopies().end());
2358 private_copies_const_range private_copies() const {
2359 return private_copies_const_range(getPrivateCopies().begin(),
2360 getPrivateCopies().end());
2363 using inits_iterator = MutableArrayRef<Expr *>::iterator;
2364 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
2365 using inits_range = llvm::iterator_range<inits_iterator>;
2366 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
2368 inits_range inits() {
2369 return inits_range(getInits().begin(), getInits().end());
2371 inits_const_range inits() const {
2372 return inits_const_range(getInits().begin(), getInits().end());
2375 child_range children() {
2376 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2377 reinterpret_cast<Stmt **>(varlist_end()));
2380 const_child_range children() const {
2381 auto Children = const_cast<OMPFirstprivateClause *>(this)->children();
2382 return const_child_range(Children.begin(), Children.end());
2385 child_range used_children() {
2386 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2387 reinterpret_cast<Stmt **>(varlist_end()));
2389 const_child_range used_children() const {
2390 auto Children = const_cast<OMPFirstprivateClause *>(this)->used_children();
2391 return const_child_range(Children.begin(), Children.end());
2394 static bool classof(const OMPClause *T) {
2395 return T->getClauseKind() == llvm::omp::OMPC_firstprivate;
2399 /// This represents clause 'lastprivate' in the '#pragma omp ...'
2403 /// #pragma omp simd lastprivate(a,b)
2405 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
2406 /// with the variables 'a' and 'b'.
2407 class OMPLastprivateClause final
2408 : public OMPVarListClause<OMPLastprivateClause>,
2409 public OMPClauseWithPostUpdate,
2410 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
2411 // There are 4 additional tail-allocated arrays at the end of the class:
2412 // 1. Contains list of pseudo variables with the default initialization for
2413 // each non-firstprivate variables. Used in codegen for initialization of
2414 // lastprivate copies.
2415 // 2. List of helper expressions for proper generation of assignment operation
2416 // required for lastprivate clause. This list represents private variables
2417 // (for arrays, single array element).
2418 // 3. List of helper expressions for proper generation of assignment operation
2419 // required for lastprivate clause. This list represents original variables
2420 // (for arrays, single array element).
2421 // 4. List of helper expressions that represents assignment operation:
2423 // DstExprs = SrcExprs;
2425 // Required for proper codegen of final assignment performed by the
2426 // lastprivate clause.
2427 friend class OMPClauseReader;
2428 friend OMPVarListClause;
2429 friend TrailingObjects;
2431 /// Optional lastprivate kind, e.g. 'conditional', if specified by user.
2432 OpenMPLastprivateModifier LPKind;
2433 /// Optional location of the lasptrivate kind, if specified by user.
2434 SourceLocation LPKindLoc;
2435 /// Optional colon location, if specified by user.
2436 SourceLocation ColonLoc;
2438 /// Build clause with number of variables \a N.
2440 /// \param StartLoc Starting location of the clause.
2441 /// \param LParenLoc Location of '('.
2442 /// \param EndLoc Ending location of the clause.
2443 /// \param N Number of the variables in the clause.
2444 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2445 SourceLocation EndLoc, OpenMPLastprivateModifier LPKind,
2446 SourceLocation LPKindLoc, SourceLocation ColonLoc,
2448 : OMPVarListClause<OMPLastprivateClause>(llvm::omp::OMPC_lastprivate,
2449 StartLoc, LParenLoc, EndLoc, N),
2450 OMPClauseWithPostUpdate(this), LPKind(LPKind), LPKindLoc(LPKindLoc),
2451 ColonLoc(ColonLoc) {}
2453 /// Build an empty clause.
2455 /// \param N Number of variables.
2456 explicit OMPLastprivateClause(unsigned N)
2457 : OMPVarListClause<OMPLastprivateClause>(
2458 llvm::omp::OMPC_lastprivate, SourceLocation(), SourceLocation(),
2459 SourceLocation(), N),
2460 OMPClauseWithPostUpdate(this) {}
2462 /// Get the list of helper expressions for initialization of private
2463 /// copies for lastprivate variables.
2464 MutableArrayRef<Expr *> getPrivateCopies() {
2465 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2467 ArrayRef<const Expr *> getPrivateCopies() const {
2468 return llvm::makeArrayRef(varlist_end(), varlist_size());
2471 /// Set list of helper expressions, required for proper codegen of the
2472 /// clause. These expressions represent private variables (for arrays, single
2473 /// array element) in the final assignment statement performed by the
2474 /// lastprivate clause.
2475 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2477 /// Get the list of helper source expressions.
2478 MutableArrayRef<Expr *> getSourceExprs() {
2479 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
2481 ArrayRef<const Expr *> getSourceExprs() const {
2482 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
2485 /// Set list of helper expressions, required for proper codegen of the
2486 /// clause. These expressions represent original variables (for arrays, single
2487 /// array element) in the final assignment statement performed by the
2488 /// lastprivate clause.
2489 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2491 /// Get the list of helper destination expressions.
2492 MutableArrayRef<Expr *> getDestinationExprs() {
2493 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2495 ArrayRef<const Expr *> getDestinationExprs() const {
2496 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2499 /// Set list of helper assignment expressions, required for proper
2500 /// codegen of the clause. These expressions are assignment expressions that
2501 /// assign private copy of the variable to original variable.
2502 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2504 /// Get the list of helper assignment expressions.
2505 MutableArrayRef<Expr *> getAssignmentOps() {
2506 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2508 ArrayRef<const Expr *> getAssignmentOps() const {
2509 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2512 /// Sets lastprivate kind.
2513 void setKind(OpenMPLastprivateModifier Kind) { LPKind = Kind; }
2514 /// Sets location of the lastprivate kind.
2515 void setKindLoc(SourceLocation Loc) { LPKindLoc = Loc; }
2516 /// Sets colon symbol location.
2517 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2520 /// Creates clause with a list of variables \a VL.
2522 /// \param C AST context.
2523 /// \param StartLoc Starting location of the clause.
2524 /// \param LParenLoc Location of '('.
2525 /// \param EndLoc Ending location of the clause.
2526 /// \param VL List of references to the variables.
2527 /// \param SrcExprs List of helper expressions for proper generation of
2528 /// assignment operation required for lastprivate clause. This list represents
2529 /// private variables (for arrays, single array element).
2530 /// \param DstExprs List of helper expressions for proper generation of
2531 /// assignment operation required for lastprivate clause. This list represents
2532 /// original variables (for arrays, single array element).
2533 /// \param AssignmentOps List of helper expressions that represents assignment
2536 /// DstExprs = SrcExprs;
2538 /// Required for proper codegen of final assignment performed by the
2539 /// lastprivate clause.
2540 /// \param LPKind Lastprivate kind, e.g. 'conditional'.
2541 /// \param LPKindLoc Location of the lastprivate kind.
2542 /// \param ColonLoc Location of the ':' symbol if lastprivate kind is used.
2543 /// \param PreInit Statement that must be executed before entering the OpenMP
2544 /// region with this clause.
2545 /// \param PostUpdate Expression that must be executed after exit from the
2546 /// OpenMP region with this clause.
2547 static OMPLastprivateClause *
2548 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2549 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2550 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
2551 OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc,
2552 SourceLocation ColonLoc, Stmt *PreInit, Expr *PostUpdate);
2554 /// Creates an empty clause with the place for \a N variables.
2556 /// \param C AST context.
2557 /// \param N The number of variables.
2558 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2560 /// Lastprivate kind.
2561 OpenMPLastprivateModifier getKind() const { return LPKind; }
2562 /// Returns the location of the lastprivate kind.
2563 SourceLocation getKindLoc() const { return LPKindLoc; }
2564 /// Returns the location of the ':' symbol, if any.
2565 SourceLocation getColonLoc() const { return ColonLoc; }
2567 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2568 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2569 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2570 using helper_expr_const_range =
2571 llvm::iterator_range<helper_expr_const_iterator>;
2573 /// Set list of helper expressions, required for generation of private
2574 /// copies of original lastprivate variables.
2575 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
2577 helper_expr_const_range private_copies() const {
2578 return helper_expr_const_range(getPrivateCopies().begin(),
2579 getPrivateCopies().end());
2582 helper_expr_range private_copies() {
2583 return helper_expr_range(getPrivateCopies().begin(),
2584 getPrivateCopies().end());
2587 helper_expr_const_range source_exprs() const {
2588 return helper_expr_const_range(getSourceExprs().begin(),
2589 getSourceExprs().end());
2592 helper_expr_range source_exprs() {
2593 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2596 helper_expr_const_range destination_exprs() const {
2597 return helper_expr_const_range(getDestinationExprs().begin(),
2598 getDestinationExprs().end());
2601 helper_expr_range destination_exprs() {
2602 return helper_expr_range(getDestinationExprs().begin(),
2603 getDestinationExprs().end());
2606 helper_expr_const_range assignment_ops() const {
2607 return helper_expr_const_range(getAssignmentOps().begin(),
2608 getAssignmentOps().end());
2611 helper_expr_range assignment_ops() {
2612 return helper_expr_range(getAssignmentOps().begin(),
2613 getAssignmentOps().end());
2616 child_range children() {
2617 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2618 reinterpret_cast<Stmt **>(varlist_end()));
2621 const_child_range children() const {
2622 auto Children = const_cast<OMPLastprivateClause *>(this)->children();
2623 return const_child_range(Children.begin(), Children.end());
2626 child_range used_children() {
2627 return child_range(child_iterator(), child_iterator());
2629 const_child_range used_children() const {
2630 return const_child_range(const_child_iterator(), const_child_iterator());
2633 static bool classof(const OMPClause *T) {
2634 return T->getClauseKind() == llvm::omp::OMPC_lastprivate;
2638 /// This represents clause 'shared' in the '#pragma omp ...' directives.
2641 /// #pragma omp parallel shared(a,b)
2643 /// In this example directive '#pragma omp parallel' has clause 'shared'
2644 /// with the variables 'a' and 'b'.
2645 class OMPSharedClause final
2646 : public OMPVarListClause<OMPSharedClause>,
2647 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
2648 friend OMPVarListClause;
2649 friend TrailingObjects;
2651 /// Build clause with number of variables \a N.
2653 /// \param StartLoc Starting location of the clause.
2654 /// \param LParenLoc Location of '('.
2655 /// \param EndLoc Ending location of the clause.
2656 /// \param N Number of the variables in the clause.
2657 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2658 SourceLocation EndLoc, unsigned N)
2659 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared, StartLoc,
2660 LParenLoc, EndLoc, N) {}
2662 /// Build an empty clause.
2664 /// \param N Number of variables.
2665 explicit OMPSharedClause(unsigned N)
2666 : OMPVarListClause<OMPSharedClause>(llvm::omp::OMPC_shared,
2667 SourceLocation(), SourceLocation(),
2668 SourceLocation(), N) {}
2671 /// Creates clause with a list of variables \a VL.
2673 /// \param C AST context.
2674 /// \param StartLoc Starting location of the clause.
2675 /// \param LParenLoc Location of '('.
2676 /// \param EndLoc Ending location of the clause.
2677 /// \param VL List of references to the variables.
2678 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2679 SourceLocation LParenLoc,
2680 SourceLocation EndLoc, ArrayRef<Expr *> VL);
2682 /// Creates an empty clause with \a N variables.
2684 /// \param C AST context.
2685 /// \param N The number of variables.
2686 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
2688 child_range children() {
2689 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2690 reinterpret_cast<Stmt **>(varlist_end()));
2693 const_child_range children() const {
2694 auto Children = const_cast<OMPSharedClause *>(this)->children();
2695 return const_child_range(Children.begin(), Children.end());
2698 child_range used_children() {
2699 return child_range(child_iterator(), child_iterator());
2701 const_child_range used_children() const {
2702 return const_child_range(const_child_iterator(), const_child_iterator());
2705 static bool classof(const OMPClause *T) {
2706 return T->getClauseKind() == llvm::omp::OMPC_shared;
2710 /// This represents clause 'reduction' in the '#pragma omp ...'
2714 /// #pragma omp parallel reduction(+:a,b)
2716 /// In this example directive '#pragma omp parallel' has clause 'reduction'
2717 /// with operator '+' and the variables 'a' and 'b'.
2718 class OMPReductionClause final
2719 : public OMPVarListClause<OMPReductionClause>,
2720 public OMPClauseWithPostUpdate,
2721 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
2722 friend class OMPClauseReader;
2723 friend OMPVarListClause;
2724 friend TrailingObjects;
2726 /// Reduction modifier.
2727 OpenMPReductionClauseModifier Modifier = OMPC_REDUCTION_unknown;
2729 /// Reduction modifier location.
2730 SourceLocation ModifierLoc;
2732 /// Location of ':'.
2733 SourceLocation ColonLoc;
2735 /// Nested name specifier for C++.
2736 NestedNameSpecifierLoc QualifierLoc;
2738 /// Name of custom operator.
2739 DeclarationNameInfo NameInfo;
2741 /// Build clause with number of variables \a N.
2743 /// \param StartLoc Starting location of the clause.
2744 /// \param LParenLoc Location of '('.
2745 /// \param ModifierLoc Modifier location.
2746 /// \param ColonLoc Location of ':'.
2747 /// \param EndLoc Ending location of the clause.
2748 /// \param N Number of the variables in the clause.
2749 /// \param QualifierLoc The nested-name qualifier with location information
2750 /// \param NameInfo The full name info for reduction identifier.
2751 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2752 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2753 SourceLocation EndLoc,
2754 OpenMPReductionClauseModifier Modifier, unsigned N,
2755 NestedNameSpecifierLoc QualifierLoc,
2756 const DeclarationNameInfo &NameInfo)
2757 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
2758 StartLoc, LParenLoc, EndLoc, N),
2759 OMPClauseWithPostUpdate(this), Modifier(Modifier),
2760 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc),
2761 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
2763 /// Build an empty clause.
2765 /// \param N Number of variables.
2766 explicit OMPReductionClause(unsigned N)
2767 : OMPVarListClause<OMPReductionClause>(llvm::omp::OMPC_reduction,
2768 SourceLocation(), SourceLocation(),
2769 SourceLocation(), N),
2770 OMPClauseWithPostUpdate(this) {}
2772 /// Sets reduction modifier.
2773 void setModifier(OpenMPReductionClauseModifier M) { Modifier = M; }
2775 /// Sets location of the modifier.
2776 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
2778 /// Sets location of ':' symbol in clause.
2779 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
2781 /// Sets the name info for specified reduction identifier.
2782 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
2784 /// Sets the nested name specifier.
2785 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
2787 /// Set list of helper expressions, required for proper codegen of the
2788 /// clause. These expressions represent private copy of the reduction
2790 void setPrivates(ArrayRef<Expr *> Privates);
2792 /// Get the list of helper privates.
2793 MutableArrayRef<Expr *> getPrivates() {
2794 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2796 ArrayRef<const Expr *> getPrivates() const {
2797 return llvm::makeArrayRef(varlist_end(), varlist_size());
2800 /// Set list of helper expressions, required for proper codegen of the
2801 /// clause. These expressions represent LHS expression in the final
2802 /// reduction expression performed by the reduction clause.
2803 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
2805 /// Get the list of helper LHS expressions.
2806 MutableArrayRef<Expr *> getLHSExprs() {
2807 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2809 ArrayRef<const Expr *> getLHSExprs() const {
2810 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2813 /// Set list of helper expressions, required for proper codegen of the
2814 /// clause. These expressions represent RHS expression in the final
2815 /// reduction expression performed by the reduction clause.
2816 /// Also, variables in these expressions are used for proper initialization of
2817 /// reduction copies.
2818 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
2820 /// Get the list of helper destination expressions.
2821 MutableArrayRef<Expr *> getRHSExprs() {
2822 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
2824 ArrayRef<const Expr *> getRHSExprs() const {
2825 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
2828 /// Set list of helper reduction expressions, required for proper
2829 /// codegen of the clause. These expressions are binary expressions or
2830 /// operator/custom reduction call that calculates new value from source
2831 /// helper expressions to destination helper expressions.
2832 void setReductionOps(ArrayRef<Expr *> ReductionOps);
2834 /// Get the list of helper reduction expressions.
2835 MutableArrayRef<Expr *> getReductionOps() {
2836 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2838 ArrayRef<const Expr *> getReductionOps() const {
2839 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2842 /// Set list of helper copy operations for inscan reductions.
2843 /// The form is: Temps[i] = LHS[i];
2844 void setInscanCopyOps(ArrayRef<Expr *> Ops);
2846 /// Get the list of helper inscan copy operations.
2847 MutableArrayRef<Expr *> getInscanCopyOps() {
2848 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
2850 ArrayRef<const Expr *> getInscanCopyOps() const {
2851 return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
2854 /// Set list of helper temp vars for inscan copy array operations.
2855 void setInscanCopyArrayTemps(ArrayRef<Expr *> CopyArrayTemps);
2857 /// Get the list of helper inscan copy temps.
2858 MutableArrayRef<Expr *> getInscanCopyArrayTemps() {
2859 return MutableArrayRef<Expr *>(getInscanCopyOps().end(), varlist_size());
2861 ArrayRef<const Expr *> getInscanCopyArrayTemps() const {
2862 return llvm::makeArrayRef(getInscanCopyOps().end(), varlist_size());
2865 /// Set list of helper temp elements vars for inscan copy array operations.
2866 void setInscanCopyArrayElems(ArrayRef<Expr *> CopyArrayElems);
2868 /// Get the list of helper inscan copy temps.
2869 MutableArrayRef<Expr *> getInscanCopyArrayElems() {
2870 return MutableArrayRef<Expr *>(getInscanCopyArrayTemps().end(),
2873 ArrayRef<const Expr *> getInscanCopyArrayElems() const {
2874 return llvm::makeArrayRef(getInscanCopyArrayTemps().end(), varlist_size());
2878 /// Creates clause with a list of variables \a VL.
2880 /// \param StartLoc Starting location of the clause.
2881 /// \param LParenLoc Location of '('.
2882 /// \param ModifierLoc Modifier location.
2883 /// \param ColonLoc Location of ':'.
2884 /// \param EndLoc Ending location of the clause.
2885 /// \param VL The variables in the clause.
2886 /// \param QualifierLoc The nested-name qualifier with location information
2887 /// \param NameInfo The full name info for reduction identifier.
2888 /// \param Privates List of helper expressions for proper generation of
2890 /// \param LHSExprs List of helper expressions for proper generation of
2891 /// assignment operation required for copyprivate clause. This list represents
2892 /// LHSs of the reduction expressions.
2893 /// \param RHSExprs List of helper expressions for proper generation of
2894 /// assignment operation required for copyprivate clause. This list represents
2895 /// RHSs of the reduction expressions.
2896 /// Also, variables in these expressions are used for proper initialization of
2897 /// reduction copies.
2898 /// \param ReductionOps List of helper expressions that represents reduction
2901 /// LHSExprs binop RHSExprs;
2902 /// operator binop(LHSExpr, RHSExpr);
2903 /// <CutomReduction>(LHSExpr, RHSExpr);
2905 /// Required for proper codegen of final reduction operation performed by the
2906 /// reduction clause.
2907 /// \param CopyOps List of copy operations for inscan reductions:
2909 /// TempExprs = LHSExprs;
2911 /// \param CopyArrayTemps Temp arrays for prefix sums.
2912 /// \param CopyArrayElems Temp arrays for prefix sums.
2913 /// \param PreInit Statement that must be executed before entering the OpenMP
2914 /// region with this clause.
2915 /// \param PostUpdate Expression that must be executed after exit from the
2916 /// OpenMP region with this clause.
2917 static OMPReductionClause *
2918 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2919 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2920 SourceLocation EndLoc, OpenMPReductionClauseModifier Modifier,
2921 ArrayRef<Expr *> VL, NestedNameSpecifierLoc QualifierLoc,
2922 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2923 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2924 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> CopyOps,
2925 ArrayRef<Expr *> CopyArrayTemps, ArrayRef<Expr *> CopyArrayElems,
2926 Stmt *PreInit, Expr *PostUpdate);
2928 /// Creates an empty clause with the place for \a N variables.
2930 /// \param C AST context.
2931 /// \param N The number of variables.
2932 /// \param Modifier Reduction modifier.
2933 static OMPReductionClause *
2934 CreateEmpty(const ASTContext &C, unsigned N,
2935 OpenMPReductionClauseModifier Modifier);
2937 /// Returns modifier.
2938 OpenMPReductionClauseModifier getModifier() const { return Modifier; }
2940 /// Returns modifier location.
2941 SourceLocation getModifierLoc() const { return ModifierLoc; }
2943 /// Gets location of ':' symbol in clause.
2944 SourceLocation getColonLoc() const { return ColonLoc; }
2946 /// Gets the name info for specified reduction identifier.
2947 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2949 /// Gets the nested name specifier.
2950 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2952 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
2953 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
2954 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
2955 using helper_expr_const_range =
2956 llvm::iterator_range<helper_expr_const_iterator>;
2958 helper_expr_const_range privates() const {
2959 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2962 helper_expr_range privates() {
2963 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2966 helper_expr_const_range lhs_exprs() const {
2967 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2970 helper_expr_range lhs_exprs() {
2971 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2974 helper_expr_const_range rhs_exprs() const {
2975 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2978 helper_expr_range rhs_exprs() {
2979 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2982 helper_expr_const_range reduction_ops() const {
2983 return helper_expr_const_range(getReductionOps().begin(),
2984 getReductionOps().end());
2987 helper_expr_range reduction_ops() {
2988 return helper_expr_range(getReductionOps().begin(),
2989 getReductionOps().end());
2992 helper_expr_const_range copy_ops() const {
2993 return helper_expr_const_range(getInscanCopyOps().begin(),
2994 getInscanCopyOps().end());
2997 helper_expr_range copy_ops() {
2998 return helper_expr_range(getInscanCopyOps().begin(),
2999 getInscanCopyOps().end());
3002 helper_expr_const_range copy_array_temps() const {
3003 return helper_expr_const_range(getInscanCopyArrayTemps().begin(),
3004 getInscanCopyArrayTemps().end());
3007 helper_expr_range copy_array_temps() {
3008 return helper_expr_range(getInscanCopyArrayTemps().begin(),
3009 getInscanCopyArrayTemps().end());
3012 helper_expr_const_range copy_array_elems() const {
3013 return helper_expr_const_range(getInscanCopyArrayElems().begin(),
3014 getInscanCopyArrayElems().end());
3017 helper_expr_range copy_array_elems() {
3018 return helper_expr_range(getInscanCopyArrayElems().begin(),
3019 getInscanCopyArrayElems().end());
3022 child_range children() {
3023 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3024 reinterpret_cast<Stmt **>(varlist_end()));
3027 const_child_range children() const {
3028 auto Children = const_cast<OMPReductionClause *>(this)->children();
3029 return const_child_range(Children.begin(), Children.end());
3032 child_range used_children() {
3033 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3034 reinterpret_cast<Stmt **>(varlist_end()));
3036 const_child_range used_children() const {
3037 auto Children = const_cast<OMPReductionClause *>(this)->used_children();
3038 return const_child_range(Children.begin(), Children.end());
3041 static bool classof(const OMPClause *T) {
3042 return T->getClauseKind() == llvm::omp::OMPC_reduction;
3046 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
3050 /// #pragma omp taskgroup task_reduction(+:a,b)
3052 /// In this example directive '#pragma omp taskgroup' has clause
3053 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
3054 class OMPTaskReductionClause final
3055 : public OMPVarListClause<OMPTaskReductionClause>,
3056 public OMPClauseWithPostUpdate,
3057 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
3058 friend class OMPClauseReader;
3059 friend OMPVarListClause;
3060 friend TrailingObjects;
3062 /// Location of ':'.
3063 SourceLocation ColonLoc;
3065 /// Nested name specifier for C++.
3066 NestedNameSpecifierLoc QualifierLoc;
3068 /// Name of custom operator.
3069 DeclarationNameInfo NameInfo;
3071 /// Build clause with number of variables \a N.
3073 /// \param StartLoc Starting location of the clause.
3074 /// \param LParenLoc Location of '('.
3075 /// \param EndLoc Ending location of the clause.
3076 /// \param ColonLoc Location of ':'.
3077 /// \param N Number of the variables in the clause.
3078 /// \param QualifierLoc The nested-name qualifier with location information
3079 /// \param NameInfo The full name info for reduction identifier.
3080 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3081 SourceLocation ColonLoc, SourceLocation EndLoc,
3082 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3083 const DeclarationNameInfo &NameInfo)
3084 : OMPVarListClause<OMPTaskReductionClause>(
3085 llvm::omp::OMPC_task_reduction, StartLoc, LParenLoc, EndLoc, N),
3086 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3087 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3089 /// Build an empty clause.
3091 /// \param N Number of variables.
3092 explicit OMPTaskReductionClause(unsigned N)
3093 : OMPVarListClause<OMPTaskReductionClause>(
3094 llvm::omp::OMPC_task_reduction, SourceLocation(), SourceLocation(),
3095 SourceLocation(), N),
3096 OMPClauseWithPostUpdate(this) {}
3098 /// Sets location of ':' symbol in clause.
3099 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3101 /// Sets the name info for specified reduction identifier.
3102 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3104 /// Sets the nested name specifier.
3105 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3107 /// Set list of helper expressions, required for proper codegen of the clause.
3108 /// These expressions represent private copy of the reduction variable.
3109 void setPrivates(ArrayRef<Expr *> Privates);
3111 /// Get the list of helper privates.
3112 MutableArrayRef<Expr *> getPrivates() {
3113 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3115 ArrayRef<const Expr *> getPrivates() const {
3116 return llvm::makeArrayRef(varlist_end(), varlist_size());
3119 /// Set list of helper expressions, required for proper codegen of the clause.
3120 /// These expressions represent LHS expression in the final reduction
3121 /// expression performed by the reduction clause.
3122 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3124 /// Get the list of helper LHS expressions.
3125 MutableArrayRef<Expr *> getLHSExprs() {
3126 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3128 ArrayRef<const Expr *> getLHSExprs() const {
3129 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3132 /// Set list of helper expressions, required for proper codegen of the clause.
3133 /// These expressions represent RHS expression in the final reduction
3134 /// expression performed by the reduction clause. Also, variables in these
3135 /// expressions are used for proper initialization of reduction copies.
3136 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3138 /// Get the list of helper destination expressions.
3139 MutableArrayRef<Expr *> getRHSExprs() {
3140 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3142 ArrayRef<const Expr *> getRHSExprs() const {
3143 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3146 /// Set list of helper reduction expressions, required for proper
3147 /// codegen of the clause. These expressions are binary expressions or
3148 /// operator/custom reduction call that calculates new value from source
3149 /// helper expressions to destination helper expressions.
3150 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3152 /// Get the list of helper reduction expressions.
3153 MutableArrayRef<Expr *> getReductionOps() {
3154 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3156 ArrayRef<const Expr *> getReductionOps() const {
3157 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3161 /// Creates clause with a list of variables \a VL.
3163 /// \param StartLoc Starting location of the clause.
3164 /// \param LParenLoc Location of '('.
3165 /// \param ColonLoc Location of ':'.
3166 /// \param EndLoc Ending location of the clause.
3167 /// \param VL The variables in the clause.
3168 /// \param QualifierLoc The nested-name qualifier with location information
3169 /// \param NameInfo The full name info for reduction identifier.
3170 /// \param Privates List of helper expressions for proper generation of
3172 /// \param LHSExprs List of helper expressions for proper generation of
3173 /// assignment operation required for copyprivate clause. This list represents
3174 /// LHSs of the reduction expressions.
3175 /// \param RHSExprs List of helper expressions for proper generation of
3176 /// assignment operation required for copyprivate clause. This list represents
3177 /// RHSs of the reduction expressions.
3178 /// Also, variables in these expressions are used for proper initialization of
3179 /// reduction copies.
3180 /// \param ReductionOps List of helper expressions that represents reduction
3183 /// LHSExprs binop RHSExprs;
3184 /// operator binop(LHSExpr, RHSExpr);
3185 /// <CutomReduction>(LHSExpr, RHSExpr);
3187 /// Required for proper codegen of final reduction operation performed by the
3188 /// reduction clause.
3189 /// \param PreInit Statement that must be executed before entering the OpenMP
3190 /// region with this clause.
3191 /// \param PostUpdate Expression that must be executed after exit from the
3192 /// OpenMP region with this clause.
3193 static OMPTaskReductionClause *
3194 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3195 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3196 NestedNameSpecifierLoc QualifierLoc,
3197 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3198 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3199 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
3201 /// Creates an empty clause with the place for \a N variables.
3203 /// \param C AST context.
3204 /// \param N The number of variables.
3205 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3207 /// Gets location of ':' symbol in clause.
3208 SourceLocation getColonLoc() const { return ColonLoc; }
3210 /// Gets the name info for specified reduction identifier.
3211 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3213 /// Gets the nested name specifier.
3214 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3216 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3217 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3218 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3219 using helper_expr_const_range =
3220 llvm::iterator_range<helper_expr_const_iterator>;
3222 helper_expr_const_range privates() const {
3223 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3226 helper_expr_range privates() {
3227 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3230 helper_expr_const_range lhs_exprs() const {
3231 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3234 helper_expr_range lhs_exprs() {
3235 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3238 helper_expr_const_range rhs_exprs() const {
3239 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3242 helper_expr_range rhs_exprs() {
3243 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3246 helper_expr_const_range reduction_ops() const {
3247 return helper_expr_const_range(getReductionOps().begin(),
3248 getReductionOps().end());
3251 helper_expr_range reduction_ops() {
3252 return helper_expr_range(getReductionOps().begin(),
3253 getReductionOps().end());
3256 child_range children() {
3257 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3258 reinterpret_cast<Stmt **>(varlist_end()));
3261 const_child_range children() const {
3262 auto Children = const_cast<OMPTaskReductionClause *>(this)->children();
3263 return const_child_range(Children.begin(), Children.end());
3266 child_range used_children() {
3267 return child_range(child_iterator(), child_iterator());
3269 const_child_range used_children() const {
3270 return const_child_range(const_child_iterator(), const_child_iterator());
3273 static bool classof(const OMPClause *T) {
3274 return T->getClauseKind() == llvm::omp::OMPC_task_reduction;
3278 /// This represents clause 'in_reduction' in the '#pragma omp task' directives.
3281 /// #pragma omp task in_reduction(+:a,b)
3283 /// In this example directive '#pragma omp task' has clause 'in_reduction' with
3284 /// operator '+' and the variables 'a' and 'b'.
3285 class OMPInReductionClause final
3286 : public OMPVarListClause<OMPInReductionClause>,
3287 public OMPClauseWithPostUpdate,
3288 private llvm::TrailingObjects<OMPInReductionClause, Expr *> {
3289 friend class OMPClauseReader;
3290 friend OMPVarListClause;
3291 friend TrailingObjects;
3293 /// Location of ':'.
3294 SourceLocation ColonLoc;
3296 /// Nested name specifier for C++.
3297 NestedNameSpecifierLoc QualifierLoc;
3299 /// Name of custom operator.
3300 DeclarationNameInfo NameInfo;
3302 /// Build clause with number of variables \a N.
3304 /// \param StartLoc Starting location of the clause.
3305 /// \param LParenLoc Location of '('.
3306 /// \param EndLoc Ending location of the clause.
3307 /// \param ColonLoc Location of ':'.
3308 /// \param N Number of the variables in the clause.
3309 /// \param QualifierLoc The nested-name qualifier with location information
3310 /// \param NameInfo The full name info for reduction identifier.
3311 OMPInReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3312 SourceLocation ColonLoc, SourceLocation EndLoc,
3313 unsigned N, NestedNameSpecifierLoc QualifierLoc,
3314 const DeclarationNameInfo &NameInfo)
3315 : OMPVarListClause<OMPInReductionClause>(llvm::omp::OMPC_in_reduction,
3316 StartLoc, LParenLoc, EndLoc, N),
3317 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
3318 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
3320 /// Build an empty clause.
3322 /// \param N Number of variables.
3323 explicit OMPInReductionClause(unsigned N)
3324 : OMPVarListClause<OMPInReductionClause>(
3325 llvm::omp::OMPC_in_reduction, SourceLocation(), SourceLocation(),
3326 SourceLocation(), N),
3327 OMPClauseWithPostUpdate(this) {}
3329 /// Sets location of ':' symbol in clause.
3330 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
3332 /// Sets the name info for specified reduction identifier.
3333 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
3335 /// Sets the nested name specifier.
3336 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
3338 /// Set list of helper expressions, required for proper codegen of the clause.
3339 /// These expressions represent private copy of the reduction variable.
3340 void setPrivates(ArrayRef<Expr *> Privates);
3342 /// Get the list of helper privates.
3343 MutableArrayRef<Expr *> getPrivates() {
3344 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3346 ArrayRef<const Expr *> getPrivates() const {
3347 return llvm::makeArrayRef(varlist_end(), varlist_size());
3350 /// Set list of helper expressions, required for proper codegen of the clause.
3351 /// These expressions represent LHS expression in the final reduction
3352 /// expression performed by the reduction clause.
3353 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
3355 /// Get the list of helper LHS expressions.
3356 MutableArrayRef<Expr *> getLHSExprs() {
3357 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3359 ArrayRef<const Expr *> getLHSExprs() const {
3360 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3363 /// Set list of helper expressions, required for proper codegen of the clause.
3364 /// These expressions represent RHS expression in the final reduction
3365 /// expression performed by the reduction clause. Also, variables in these
3366 /// expressions are used for proper initialization of reduction copies.
3367 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
3369 /// Get the list of helper destination expressions.
3370 MutableArrayRef<Expr *> getRHSExprs() {
3371 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
3373 ArrayRef<const Expr *> getRHSExprs() const {
3374 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
3377 /// Set list of helper reduction expressions, required for proper
3378 /// codegen of the clause. These expressions are binary expressions or
3379 /// operator/custom reduction call that calculates new value from source
3380 /// helper expressions to destination helper expressions.
3381 void setReductionOps(ArrayRef<Expr *> ReductionOps);
3383 /// Get the list of helper reduction expressions.
3384 MutableArrayRef<Expr *> getReductionOps() {
3385 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
3387 ArrayRef<const Expr *> getReductionOps() const {
3388 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
3391 /// Set list of helper reduction taskgroup descriptors.
3392 void setTaskgroupDescriptors(ArrayRef<Expr *> ReductionOps);
3394 /// Get the list of helper reduction taskgroup descriptors.
3395 MutableArrayRef<Expr *> getTaskgroupDescriptors() {
3396 return MutableArrayRef<Expr *>(getReductionOps().end(), varlist_size());
3398 ArrayRef<const Expr *> getTaskgroupDescriptors() const {
3399 return llvm::makeArrayRef(getReductionOps().end(), varlist_size());
3403 /// Creates clause with a list of variables \a VL.
3405 /// \param StartLoc Starting location of the clause.
3406 /// \param LParenLoc Location of '('.
3407 /// \param ColonLoc Location of ':'.
3408 /// \param EndLoc Ending location of the clause.
3409 /// \param VL The variables in the clause.
3410 /// \param QualifierLoc The nested-name qualifier with location information
3411 /// \param NameInfo The full name info for reduction identifier.
3412 /// \param Privates List of helper expressions for proper generation of
3414 /// \param LHSExprs List of helper expressions for proper generation of
3415 /// assignment operation required for copyprivate clause. This list represents
3416 /// LHSs of the reduction expressions.
3417 /// \param RHSExprs List of helper expressions for proper generation of
3418 /// assignment operation required for copyprivate clause. This list represents
3419 /// RHSs of the reduction expressions.
3420 /// Also, variables in these expressions are used for proper initialization of
3421 /// reduction copies.
3422 /// \param ReductionOps List of helper expressions that represents reduction
3425 /// LHSExprs binop RHSExprs;
3426 /// operator binop(LHSExpr, RHSExpr);
3427 /// <CutomReduction>(LHSExpr, RHSExpr);
3429 /// Required for proper codegen of final reduction operation performed by the
3430 /// reduction clause.
3431 /// \param TaskgroupDescriptors List of helper taskgroup descriptors for
3432 /// corresponding items in parent taskgroup task_reduction clause.
3433 /// \param PreInit Statement that must be executed before entering the OpenMP
3434 /// region with this clause.
3435 /// \param PostUpdate Expression that must be executed after exit from the
3436 /// OpenMP region with this clause.
3437 static OMPInReductionClause *
3438 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3439 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3440 NestedNameSpecifierLoc QualifierLoc,
3441 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
3442 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
3443 ArrayRef<Expr *> ReductionOps, ArrayRef<Expr *> TaskgroupDescriptors,
3444 Stmt *PreInit, Expr *PostUpdate);
3446 /// Creates an empty clause with the place for \a N variables.
3448 /// \param C AST context.
3449 /// \param N The number of variables.
3450 static OMPInReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
3452 /// Gets location of ':' symbol in clause.
3453 SourceLocation getColonLoc() const { return ColonLoc; }
3455 /// Gets the name info for specified reduction identifier.
3456 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
3458 /// Gets the nested name specifier.
3459 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3461 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
3462 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
3463 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
3464 using helper_expr_const_range =
3465 llvm::iterator_range<helper_expr_const_iterator>;
3467 helper_expr_const_range privates() const {
3468 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
3471 helper_expr_range privates() {
3472 return helper_expr_range(getPrivates().begin(), getPrivates().end());
3475 helper_expr_const_range lhs_exprs() const {
3476 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
3479 helper_expr_range lhs_exprs() {
3480 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
3483 helper_expr_const_range rhs_exprs() const {
3484 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
3487 helper_expr_range rhs_exprs() {
3488 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
3491 helper_expr_const_range reduction_ops() const {
3492 return helper_expr_const_range(getReductionOps().begin(),
3493 getReductionOps().end());
3496 helper_expr_range reduction_ops() {
3497 return helper_expr_range(getReductionOps().begin(),
3498 getReductionOps().end());
3501 helper_expr_const_range taskgroup_descriptors() const {
3502 return helper_expr_const_range(getTaskgroupDescriptors().begin(),
3503 getTaskgroupDescriptors().end());
3506 helper_expr_range taskgroup_descriptors() {
3507 return helper_expr_range(getTaskgroupDescriptors().begin(),
3508 getTaskgroupDescriptors().end());
3511 child_range children() {
3512 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3513 reinterpret_cast<Stmt **>(varlist_end()));
3516 const_child_range children() const {
3517 auto Children = const_cast<OMPInReductionClause *>(this)->children();
3518 return const_child_range(Children.begin(), Children.end());
3521 child_range used_children() {
3522 return child_range(child_iterator(), child_iterator());
3524 const_child_range used_children() const {
3525 return const_child_range(const_child_iterator(), const_child_iterator());
3528 static bool classof(const OMPClause *T) {
3529 return T->getClauseKind() == llvm::omp::OMPC_in_reduction;
3533 /// This represents clause 'linear' in the '#pragma omp ...'
3537 /// #pragma omp simd linear(a,b : 2)
3539 /// In this example directive '#pragma omp simd' has clause 'linear'
3540 /// with variables 'a', 'b' and linear step '2'.
3541 class OMPLinearClause final
3542 : public OMPVarListClause<OMPLinearClause>,
3543 public OMPClauseWithPostUpdate,
3544 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
3545 friend class OMPClauseReader;
3546 friend OMPVarListClause;
3547 friend TrailingObjects;
3549 /// Modifier of 'linear' clause.
3550 OpenMPLinearClauseKind Modifier = OMPC_LINEAR_val;
3552 /// Location of linear modifier if any.
3553 SourceLocation ModifierLoc;
3555 /// Location of ':'.
3556 SourceLocation ColonLoc;
3558 /// Sets the linear step for clause.
3559 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
3561 /// Sets the expression to calculate linear step for clause.
3562 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
3564 /// Build 'linear' clause with given number of variables \a NumVars.
3566 /// \param StartLoc Starting location of the clause.
3567 /// \param LParenLoc Location of '('.
3568 /// \param ColonLoc Location of ':'.
3569 /// \param EndLoc Ending location of the clause.
3570 /// \param NumVars Number of variables.
3571 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3572 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3573 SourceLocation ColonLoc, SourceLocation EndLoc,
3575 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear, StartLoc,
3576 LParenLoc, EndLoc, NumVars),
3577 OMPClauseWithPostUpdate(this), Modifier(Modifier),
3578 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
3580 /// Build an empty clause.
3582 /// \param NumVars Number of variables.
3583 explicit OMPLinearClause(unsigned NumVars)
3584 : OMPVarListClause<OMPLinearClause>(llvm::omp::OMPC_linear,
3585 SourceLocation(), SourceLocation(),
3586 SourceLocation(), NumVars),
3587 OMPClauseWithPostUpdate(this) {}
3589 /// Gets the list of initial values for linear variables.
3591 /// There are NumVars expressions with initial values allocated after the
3592 /// varlist, they are followed by NumVars update expressions (used to update
3593 /// the linear variable's value on current iteration) and they are followed by
3594 /// NumVars final expressions (used to calculate the linear variable's
3595 /// value after the loop body). After these lists, there are 2 helper
3596 /// expressions - linear step and a helper to calculate it before the
3597 /// loop body (used when the linear step is not constant):
3599 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
3600 /// Finals[]; Step; CalcStep; }
3601 MutableArrayRef<Expr *> getPrivates() {
3602 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3604 ArrayRef<const Expr *> getPrivates() const {
3605 return llvm::makeArrayRef(varlist_end(), varlist_size());
3608 MutableArrayRef<Expr *> getInits() {
3609 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
3611 ArrayRef<const Expr *> getInits() const {
3612 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
3615 /// Sets the list of update expressions for linear variables.
3616 MutableArrayRef<Expr *> getUpdates() {
3617 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
3619 ArrayRef<const Expr *> getUpdates() const {
3620 return llvm::makeArrayRef(getInits().end(), varlist_size());
3623 /// Sets the list of final update expressions for linear variables.
3624 MutableArrayRef<Expr *> getFinals() {
3625 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
3627 ArrayRef<const Expr *> getFinals() const {
3628 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
3631 /// Gets the list of used expressions for linear variables.
3632 MutableArrayRef<Expr *> getUsedExprs() {
3633 return MutableArrayRef<Expr *>(getFinals().end() + 2, varlist_size() + 1);
3635 ArrayRef<const Expr *> getUsedExprs() const {
3636 return llvm::makeArrayRef(getFinals().end() + 2, varlist_size() + 1);
3639 /// Sets the list of the copies of original linear variables.
3640 /// \param PL List of expressions.
3641 void setPrivates(ArrayRef<Expr *> PL);
3643 /// Sets the list of the initial values for linear variables.
3644 /// \param IL List of expressions.
3645 void setInits(ArrayRef<Expr *> IL);
3648 /// Creates clause with a list of variables \a VL and a linear step
3651 /// \param C AST Context.
3652 /// \param StartLoc Starting location of the clause.
3653 /// \param LParenLoc Location of '('.
3654 /// \param Modifier Modifier of 'linear' clause.
3655 /// \param ModifierLoc Modifier location.
3656 /// \param ColonLoc Location of ':'.
3657 /// \param EndLoc Ending location of the clause.
3658 /// \param VL List of references to the variables.
3659 /// \param PL List of private copies of original variables.
3660 /// \param IL List of initial values for the variables.
3661 /// \param Step Linear step.
3662 /// \param CalcStep Calculation of the linear step.
3663 /// \param PreInit Statement that must be executed before entering the OpenMP
3664 /// region with this clause.
3665 /// \param PostUpdate Expression that must be executed after exit from the
3666 /// OpenMP region with this clause.
3667 static OMPLinearClause *
3668 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
3669 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
3670 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
3671 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
3672 Stmt *PreInit, Expr *PostUpdate);
3674 /// Creates an empty clause with the place for \a NumVars variables.
3676 /// \param C AST context.
3677 /// \param NumVars Number of variables.
3678 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3681 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
3683 /// Return modifier.
3684 OpenMPLinearClauseKind getModifier() const { return Modifier; }
3686 /// Set modifier location.
3687 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
3689 /// Return modifier location.
3690 SourceLocation getModifierLoc() const { return ModifierLoc; }
3692 /// Sets the location of ':'.
3693 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3695 /// Returns the location of ':'.
3696 SourceLocation getColonLoc() const { return ColonLoc; }
3698 /// Returns linear step.
3699 Expr *getStep() { return *(getFinals().end()); }
3701 /// Returns linear step.
3702 const Expr *getStep() const { return *(getFinals().end()); }
3704 /// Returns expression to calculate linear step.
3705 Expr *getCalcStep() { return *(getFinals().end() + 1); }
3707 /// Returns expression to calculate linear step.
3708 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
3710 /// Sets the list of update expressions for linear variables.
3711 /// \param UL List of expressions.
3712 void setUpdates(ArrayRef<Expr *> UL);
3714 /// Sets the list of final update expressions for linear variables.
3715 /// \param FL List of expressions.
3716 void setFinals(ArrayRef<Expr *> FL);
3718 /// Sets the list of used expressions for the linear clause.
3719 void setUsedExprs(ArrayRef<Expr *> UE);
3721 using privates_iterator = MutableArrayRef<Expr *>::iterator;
3722 using privates_const_iterator = ArrayRef<const Expr *>::iterator;
3723 using privates_range = llvm::iterator_range<privates_iterator>;
3724 using privates_const_range = llvm::iterator_range<privates_const_iterator>;
3726 privates_range privates() {
3727 return privates_range(getPrivates().begin(), getPrivates().end());
3730 privates_const_range privates() const {
3731 return privates_const_range(getPrivates().begin(), getPrivates().end());
3734 using inits_iterator = MutableArrayRef<Expr *>::iterator;
3735 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
3736 using inits_range = llvm::iterator_range<inits_iterator>;
3737 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
3739 inits_range inits() {
3740 return inits_range(getInits().begin(), getInits().end());
3743 inits_const_range inits() const {
3744 return inits_const_range(getInits().begin(), getInits().end());
3747 using updates_iterator = MutableArrayRef<Expr *>::iterator;
3748 using updates_const_iterator = ArrayRef<const Expr *>::iterator;
3749 using updates_range = llvm::iterator_range<updates_iterator>;
3750 using updates_const_range = llvm::iterator_range<updates_const_iterator>;
3752 updates_range updates() {
3753 return updates_range(getUpdates().begin(), getUpdates().end());
3756 updates_const_range updates() const {
3757 return updates_const_range(getUpdates().begin(), getUpdates().end());
3760 using finals_iterator = MutableArrayRef<Expr *>::iterator;
3761 using finals_const_iterator = ArrayRef<const Expr *>::iterator;
3762 using finals_range = llvm::iterator_range<finals_iterator>;
3763 using finals_const_range = llvm::iterator_range<finals_const_iterator>;
3765 finals_range finals() {
3766 return finals_range(getFinals().begin(), getFinals().end());
3769 finals_const_range finals() const {
3770 return finals_const_range(getFinals().begin(), getFinals().end());
3773 using used_expressions_iterator = MutableArrayRef<Expr *>::iterator;
3774 using used_expressions_const_iterator = ArrayRef<const Expr *>::iterator;
3775 using used_expressions_range =
3776 llvm::iterator_range<used_expressions_iterator>;
3777 using used_expressions_const_range =
3778 llvm::iterator_range<used_expressions_const_iterator>;
3780 used_expressions_range used_expressions() {
3781 return finals_range(getUsedExprs().begin(), getUsedExprs().end());
3784 used_expressions_const_range used_expressions() const {
3785 return finals_const_range(getUsedExprs().begin(), getUsedExprs().end());
3788 child_range children() {
3789 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3790 reinterpret_cast<Stmt **>(varlist_end()));
3793 const_child_range children() const {
3794 auto Children = const_cast<OMPLinearClause *>(this)->children();
3795 return const_child_range(Children.begin(), Children.end());
3798 child_range used_children();
3800 const_child_range used_children() const {
3801 auto Children = const_cast<OMPLinearClause *>(this)->used_children();
3802 return const_child_range(Children.begin(), Children.end());
3805 static bool classof(const OMPClause *T) {
3806 return T->getClauseKind() == llvm::omp::OMPC_linear;
3810 /// This represents clause 'aligned' in the '#pragma omp ...'
3814 /// #pragma omp simd aligned(a,b : 8)
3816 /// In this example directive '#pragma omp simd' has clause 'aligned'
3817 /// with variables 'a', 'b' and alignment '8'.
3818 class OMPAlignedClause final
3819 : public OMPVarListClause<OMPAlignedClause>,
3820 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
3821 friend class OMPClauseReader;
3822 friend OMPVarListClause;
3823 friend TrailingObjects;
3825 /// Location of ':'.
3826 SourceLocation ColonLoc;
3828 /// Sets the alignment for clause.
3829 void setAlignment(Expr *A) { *varlist_end() = A; }
3831 /// Build 'aligned' clause with given number of variables \a NumVars.
3833 /// \param StartLoc Starting location of the clause.
3834 /// \param LParenLoc Location of '('.
3835 /// \param ColonLoc Location of ':'.
3836 /// \param EndLoc Ending location of the clause.
3837 /// \param NumVars Number of variables.
3838 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3839 SourceLocation ColonLoc, SourceLocation EndLoc,
3841 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned, StartLoc,
3842 LParenLoc, EndLoc, NumVars),
3843 ColonLoc(ColonLoc) {}
3845 /// Build an empty clause.
3847 /// \param NumVars Number of variables.
3848 explicit OMPAlignedClause(unsigned NumVars)
3849 : OMPVarListClause<OMPAlignedClause>(llvm::omp::OMPC_aligned,
3850 SourceLocation(), SourceLocation(),
3851 SourceLocation(), NumVars) {}
3854 /// Creates clause with a list of variables \a VL and alignment \a A.
3856 /// \param C AST Context.
3857 /// \param StartLoc Starting location of the clause.
3858 /// \param LParenLoc Location of '('.
3859 /// \param ColonLoc Location of ':'.
3860 /// \param EndLoc Ending location of the clause.
3861 /// \param VL List of references to the variables.
3862 /// \param A Alignment.
3863 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
3864 SourceLocation LParenLoc,
3865 SourceLocation ColonLoc,
3866 SourceLocation EndLoc, ArrayRef<Expr *> VL,
3869 /// Creates an empty clause with the place for \a NumVars variables.
3871 /// \param C AST context.
3872 /// \param NumVars Number of variables.
3873 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
3875 /// Sets the location of ':'.
3876 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3878 /// Returns the location of ':'.
3879 SourceLocation getColonLoc() const { return ColonLoc; }
3881 /// Returns alignment.
3882 Expr *getAlignment() { return *varlist_end(); }
3884 /// Returns alignment.
3885 const Expr *getAlignment() const { return *varlist_end(); }
3887 child_range children() {
3888 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
3889 reinterpret_cast<Stmt **>(varlist_end()));
3892 const_child_range children() const {
3893 auto Children = const_cast<OMPAlignedClause *>(this)->children();
3894 return const_child_range(Children.begin(), Children.end());
3897 child_range used_children() {
3898 return child_range(child_iterator(), child_iterator());
3900 const_child_range used_children() const {
3901 return const_child_range(const_child_iterator(), const_child_iterator());
3904 static bool classof(const OMPClause *T) {
3905 return T->getClauseKind() == llvm::omp::OMPC_aligned;
3909 /// This represents clause 'copyin' in the '#pragma omp ...' directives.
3912 /// #pragma omp parallel copyin(a,b)
3914 /// In this example directive '#pragma omp parallel' has clause 'copyin'
3915 /// with the variables 'a' and 'b'.
3916 class OMPCopyinClause final
3917 : public OMPVarListClause<OMPCopyinClause>,
3918 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
3919 // Class has 3 additional tail allocated arrays:
3920 // 1. List of helper expressions for proper generation of assignment operation
3921 // required for copyin clause. This list represents sources.
3922 // 2. List of helper expressions for proper generation of assignment operation
3923 // required for copyin clause. This list represents destinations.
3924 // 3. List of helper expressions that represents assignment operation:
3926 // DstExprs = SrcExprs;
3928 // Required for proper codegen of propagation of master's thread values of
3929 // threadprivate variables to local instances of that variables in other
3930 // implicit threads.
3932 friend class OMPClauseReader;
3933 friend OMPVarListClause;
3934 friend TrailingObjects;
3936 /// Build clause with number of variables \a N.
3938 /// \param StartLoc Starting location of the clause.
3939 /// \param LParenLoc Location of '('.
3940 /// \param EndLoc Ending location of the clause.
3941 /// \param N Number of the variables in the clause.
3942 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
3943 SourceLocation EndLoc, unsigned N)
3944 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin, StartLoc,
3945 LParenLoc, EndLoc, N) {}
3947 /// Build an empty clause.
3949 /// \param N Number of variables.
3950 explicit OMPCopyinClause(unsigned N)
3951 : OMPVarListClause<OMPCopyinClause>(llvm::omp::OMPC_copyin,
3952 SourceLocation(), SourceLocation(),
3953 SourceLocation(), N) {}
3955 /// Set list of helper expressions, required for proper codegen of the
3956 /// clause. These expressions represent source expression in the final
3957 /// assignment statement performed by the copyin clause.
3958 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
3960 /// Get the list of helper source expressions.
3961 MutableArrayRef<Expr *> getSourceExprs() {
3962 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
3964 ArrayRef<const Expr *> getSourceExprs() const {
3965 return llvm::makeArrayRef(varlist_end(), varlist_size());
3968 /// Set list of helper expressions, required for proper codegen of the
3969 /// clause. These expressions represent destination expression in the final
3970 /// assignment statement performed by the copyin clause.
3971 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
3973 /// Get the list of helper destination expressions.
3974 MutableArrayRef<Expr *> getDestinationExprs() {
3975 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
3977 ArrayRef<const Expr *> getDestinationExprs() const {
3978 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
3981 /// Set list of helper assignment expressions, required for proper
3982 /// codegen of the clause. These expressions are assignment expressions that
3983 /// assign source helper expressions to destination helper expressions
3984 /// correspondingly.
3985 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
3987 /// Get the list of helper assignment expressions.
3988 MutableArrayRef<Expr *> getAssignmentOps() {
3989 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
3991 ArrayRef<const Expr *> getAssignmentOps() const {
3992 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
3996 /// Creates clause with a list of variables \a VL.
3998 /// \param C AST context.
3999 /// \param StartLoc Starting location of the clause.
4000 /// \param LParenLoc Location of '('.
4001 /// \param EndLoc Ending location of the clause.
4002 /// \param VL List of references to the variables.
4003 /// \param SrcExprs List of helper expressions for proper generation of
4004 /// assignment operation required for copyin clause. This list represents
4006 /// \param DstExprs List of helper expressions for proper generation of
4007 /// assignment operation required for copyin clause. This list represents
4009 /// \param AssignmentOps List of helper expressions that represents assignment
4012 /// DstExprs = SrcExprs;
4014 /// Required for proper codegen of propagation of master's thread values of
4015 /// threadprivate variables to local instances of that variables in other
4016 /// implicit threads.
4017 static OMPCopyinClause *
4018 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4019 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4020 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4022 /// Creates an empty clause with \a N variables.
4024 /// \param C AST context.
4025 /// \param N The number of variables.
4026 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
4028 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4029 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4030 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4031 using helper_expr_const_range =
4032 llvm::iterator_range<helper_expr_const_iterator>;
4034 helper_expr_const_range source_exprs() const {
4035 return helper_expr_const_range(getSourceExprs().begin(),
4036 getSourceExprs().end());
4039 helper_expr_range source_exprs() {
4040 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4043 helper_expr_const_range destination_exprs() const {
4044 return helper_expr_const_range(getDestinationExprs().begin(),
4045 getDestinationExprs().end());
4048 helper_expr_range destination_exprs() {
4049 return helper_expr_range(getDestinationExprs().begin(),
4050 getDestinationExprs().end());
4053 helper_expr_const_range assignment_ops() const {
4054 return helper_expr_const_range(getAssignmentOps().begin(),
4055 getAssignmentOps().end());
4058 helper_expr_range assignment_ops() {
4059 return helper_expr_range(getAssignmentOps().begin(),
4060 getAssignmentOps().end());
4063 child_range children() {
4064 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4065 reinterpret_cast<Stmt **>(varlist_end()));
4068 const_child_range children() const {
4069 auto Children = const_cast<OMPCopyinClause *>(this)->children();
4070 return const_child_range(Children.begin(), Children.end());
4073 child_range used_children() {
4074 return child_range(child_iterator(), child_iterator());
4076 const_child_range used_children() const {
4077 return const_child_range(const_child_iterator(), const_child_iterator());
4080 static bool classof(const OMPClause *T) {
4081 return T->getClauseKind() == llvm::omp::OMPC_copyin;
4085 /// This represents clause 'copyprivate' in the '#pragma omp ...'
4089 /// #pragma omp single copyprivate(a,b)
4091 /// In this example directive '#pragma omp single' has clause 'copyprivate'
4092 /// with the variables 'a' and 'b'.
4093 class OMPCopyprivateClause final
4094 : public OMPVarListClause<OMPCopyprivateClause>,
4095 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
4096 friend class OMPClauseReader;
4097 friend OMPVarListClause;
4098 friend TrailingObjects;
4100 /// Build clause with number of variables \a N.
4102 /// \param StartLoc Starting location of the clause.
4103 /// \param LParenLoc Location of '('.
4104 /// \param EndLoc Ending location of the clause.
4105 /// \param N Number of the variables in the clause.
4106 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4107 SourceLocation EndLoc, unsigned N)
4108 : OMPVarListClause<OMPCopyprivateClause>(llvm::omp::OMPC_copyprivate,
4109 StartLoc, LParenLoc, EndLoc, N) {
4112 /// Build an empty clause.
4114 /// \param N Number of variables.
4115 explicit OMPCopyprivateClause(unsigned N)
4116 : OMPVarListClause<OMPCopyprivateClause>(
4117 llvm::omp::OMPC_copyprivate, SourceLocation(), SourceLocation(),
4118 SourceLocation(), N) {}
4120 /// Set list of helper expressions, required for proper codegen of the
4121 /// clause. These expressions represent source expression in the final
4122 /// assignment statement performed by the copyprivate clause.
4123 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
4125 /// Get the list of helper source expressions.
4126 MutableArrayRef<Expr *> getSourceExprs() {
4127 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4129 ArrayRef<const Expr *> getSourceExprs() const {
4130 return llvm::makeArrayRef(varlist_end(), varlist_size());
4133 /// Set list of helper expressions, required for proper codegen of the
4134 /// clause. These expressions represent destination expression in the final
4135 /// assignment statement performed by the copyprivate clause.
4136 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
4138 /// Get the list of helper destination expressions.
4139 MutableArrayRef<Expr *> getDestinationExprs() {
4140 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
4142 ArrayRef<const Expr *> getDestinationExprs() const {
4143 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
4146 /// Set list of helper assignment expressions, required for proper
4147 /// codegen of the clause. These expressions are assignment expressions that
4148 /// assign source helper expressions to destination helper expressions
4149 /// correspondingly.
4150 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
4152 /// Get the list of helper assignment expressions.
4153 MutableArrayRef<Expr *> getAssignmentOps() {
4154 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
4156 ArrayRef<const Expr *> getAssignmentOps() const {
4157 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
4161 /// Creates clause with a list of variables \a VL.
4163 /// \param C AST context.
4164 /// \param StartLoc Starting location of the clause.
4165 /// \param LParenLoc Location of '('.
4166 /// \param EndLoc Ending location of the clause.
4167 /// \param VL List of references to the variables.
4168 /// \param SrcExprs List of helper expressions for proper generation of
4169 /// assignment operation required for copyprivate clause. This list represents
4171 /// \param DstExprs List of helper expressions for proper generation of
4172 /// assignment operation required for copyprivate clause. This list represents
4174 /// \param AssignmentOps List of helper expressions that represents assignment
4177 /// DstExprs = SrcExprs;
4179 /// Required for proper codegen of final assignment performed by the
4180 /// copyprivate clause.
4181 static OMPCopyprivateClause *
4182 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4183 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
4184 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
4186 /// Creates an empty clause with \a N variables.
4188 /// \param C AST context.
4189 /// \param N The number of variables.
4190 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
4192 using helper_expr_iterator = MutableArrayRef<Expr *>::iterator;
4193 using helper_expr_const_iterator = ArrayRef<const Expr *>::iterator;
4194 using helper_expr_range = llvm::iterator_range<helper_expr_iterator>;
4195 using helper_expr_const_range =
4196 llvm::iterator_range<helper_expr_const_iterator>;
4198 helper_expr_const_range source_exprs() const {
4199 return helper_expr_const_range(getSourceExprs().begin(),
4200 getSourceExprs().end());
4203 helper_expr_range source_exprs() {
4204 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
4207 helper_expr_const_range destination_exprs() const {
4208 return helper_expr_const_range(getDestinationExprs().begin(),
4209 getDestinationExprs().end());
4212 helper_expr_range destination_exprs() {
4213 return helper_expr_range(getDestinationExprs().begin(),
4214 getDestinationExprs().end());
4217 helper_expr_const_range assignment_ops() const {
4218 return helper_expr_const_range(getAssignmentOps().begin(),
4219 getAssignmentOps().end());
4222 helper_expr_range assignment_ops() {
4223 return helper_expr_range(getAssignmentOps().begin(),
4224 getAssignmentOps().end());
4227 child_range children() {
4228 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4229 reinterpret_cast<Stmt **>(varlist_end()));
4232 const_child_range children() const {
4233 auto Children = const_cast<OMPCopyprivateClause *>(this)->children();
4234 return const_child_range(Children.begin(), Children.end());
4237 child_range used_children() {
4238 return child_range(child_iterator(), child_iterator());
4240 const_child_range used_children() const {
4241 return const_child_range(const_child_iterator(), const_child_iterator());
4244 static bool classof(const OMPClause *T) {
4245 return T->getClauseKind() == llvm::omp::OMPC_copyprivate;
4249 /// This represents implicit clause 'flush' for the '#pragma omp flush'
4251 /// This clause does not exist by itself, it can be only as a part of 'omp
4252 /// flush' directive. This clause is introduced to keep the original structure
4253 /// of \a OMPExecutableDirective class and its derivatives and to use the
4254 /// existing infrastructure of clauses with the list of variables.
4257 /// #pragma omp flush(a,b)
4259 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
4260 /// with the variables 'a' and 'b'.
4261 class OMPFlushClause final
4262 : public OMPVarListClause<OMPFlushClause>,
4263 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
4264 friend OMPVarListClause;
4265 friend TrailingObjects;
4267 /// Build clause with number of variables \a N.
4269 /// \param StartLoc Starting location of the clause.
4270 /// \param LParenLoc Location of '('.
4271 /// \param EndLoc Ending location of the clause.
4272 /// \param N Number of the variables in the clause.
4273 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4274 SourceLocation EndLoc, unsigned N)
4275 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush, StartLoc,
4276 LParenLoc, EndLoc, N) {}
4278 /// Build an empty clause.
4280 /// \param N Number of variables.
4281 explicit OMPFlushClause(unsigned N)
4282 : OMPVarListClause<OMPFlushClause>(llvm::omp::OMPC_flush,
4283 SourceLocation(), SourceLocation(),
4284 SourceLocation(), N) {}
4287 /// Creates clause with a list of variables \a VL.
4289 /// \param C AST context.
4290 /// \param StartLoc Starting location of the clause.
4291 /// \param LParenLoc Location of '('.
4292 /// \param EndLoc Ending location of the clause.
4293 /// \param VL List of references to the variables.
4294 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
4295 SourceLocation LParenLoc, SourceLocation EndLoc,
4296 ArrayRef<Expr *> VL);
4298 /// Creates an empty clause with \a N variables.
4300 /// \param C AST context.
4301 /// \param N The number of variables.
4302 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
4304 child_range children() {
4305 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4306 reinterpret_cast<Stmt **>(varlist_end()));
4309 const_child_range children() const {
4310 auto Children = const_cast<OMPFlushClause *>(this)->children();
4311 return const_child_range(Children.begin(), Children.end());
4314 child_range used_children() {
4315 return child_range(child_iterator(), child_iterator());
4317 const_child_range used_children() const {
4318 return const_child_range(const_child_iterator(), const_child_iterator());
4321 static bool classof(const OMPClause *T) {
4322 return T->getClauseKind() == llvm::omp::OMPC_flush;
4326 /// This represents implicit clause 'depobj' for the '#pragma omp depobj'
4328 /// This clause does not exist by itself, it can be only as a part of 'omp
4329 /// depobj' directive. This clause is introduced to keep the original structure
4330 /// of \a OMPExecutableDirective class and its derivatives and to use the
4331 /// existing infrastructure of clauses with the list of variables.
4334 /// #pragma omp depobj(a) destroy
4336 /// In this example directive '#pragma omp depobj' has implicit clause 'depobj'
4337 /// with the depobj 'a'.
4338 class OMPDepobjClause final : public OMPClause {
4339 friend class OMPClauseReader;
4341 /// Location of '('.
4342 SourceLocation LParenLoc;
4345 Expr *Depobj = nullptr;
4347 /// Build clause with number of variables \a N.
4349 /// \param StartLoc Starting location of the clause.
4350 /// \param LParenLoc Location of '('.
4351 /// \param EndLoc Ending location of the clause.
4352 OMPDepobjClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4353 SourceLocation EndLoc)
4354 : OMPClause(llvm::omp::OMPC_depobj, StartLoc, EndLoc),
4355 LParenLoc(LParenLoc) {}
4357 /// Build an empty clause.
4359 explicit OMPDepobjClause()
4360 : OMPClause(llvm::omp::OMPC_depobj, SourceLocation(), SourceLocation()) {}
4362 void setDepobj(Expr *E) { Depobj = E; }
4364 /// Sets the location of '('.
4365 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4370 /// \param C AST context.
4371 /// \param StartLoc Starting location of the clause.
4372 /// \param LParenLoc Location of '('.
4373 /// \param EndLoc Ending location of the clause.
4374 /// \param Depobj depobj expression associated with the 'depobj' directive.
4375 static OMPDepobjClause *Create(const ASTContext &C, SourceLocation StartLoc,
4376 SourceLocation LParenLoc,
4377 SourceLocation EndLoc, Expr *Depobj);
4379 /// Creates an empty clause.
4381 /// \param C AST context.
4382 static OMPDepobjClause *CreateEmpty(const ASTContext &C);
4384 /// Returns depobj expression associated with the clause.
4385 Expr *getDepobj() { return Depobj; }
4386 const Expr *getDepobj() const { return Depobj; }
4388 /// Returns the location of '('.
4389 SourceLocation getLParenLoc() const { return LParenLoc; }
4391 child_range children() {
4392 return child_range(reinterpret_cast<Stmt **>(&Depobj),
4393 reinterpret_cast<Stmt **>(&Depobj) + 1);
4396 const_child_range children() const {
4397 auto Children = const_cast<OMPDepobjClause *>(this)->children();
4398 return const_child_range(Children.begin(), Children.end());
4401 child_range used_children() {
4402 return child_range(child_iterator(), child_iterator());
4404 const_child_range used_children() const {
4405 return const_child_range(const_child_iterator(), const_child_iterator());
4408 static bool classof(const OMPClause *T) {
4409 return T->getClauseKind() == llvm::omp::OMPC_depobj;
4413 /// This represents implicit clause 'depend' for the '#pragma omp task'
4417 /// #pragma omp task depend(in:a,b)
4419 /// In this example directive '#pragma omp task' with clause 'depend' with the
4420 /// variables 'a' and 'b' with dependency 'in'.
4421 class OMPDependClause final
4422 : public OMPVarListClause<OMPDependClause>,
4423 private llvm::TrailingObjects<OMPDependClause, Expr *> {
4424 friend class OMPClauseReader;
4425 friend OMPVarListClause;
4426 friend TrailingObjects;
4428 /// Dependency type (one of in, out, inout).
4429 OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown;
4431 /// Dependency type location.
4432 SourceLocation DepLoc;
4435 SourceLocation ColonLoc;
4437 /// Number of loops, associated with the depend clause.
4438 unsigned NumLoops = 0;
4440 /// Build clause with number of variables \a N.
4442 /// \param StartLoc Starting location of the clause.
4443 /// \param LParenLoc Location of '('.
4444 /// \param EndLoc Ending location of the clause.
4445 /// \param N Number of the variables in the clause.
4446 /// \param NumLoops Number of loops that is associated with this depend
4448 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4449 SourceLocation EndLoc, unsigned N, unsigned NumLoops)
4450 : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend, StartLoc,
4451 LParenLoc, EndLoc, N),
4452 NumLoops(NumLoops) {}
4454 /// Build an empty clause.
4456 /// \param N Number of variables.
4457 /// \param NumLoops Number of loops that is associated with this depend
4459 explicit OMPDependClause(unsigned N, unsigned NumLoops)
4460 : OMPVarListClause<OMPDependClause>(llvm::omp::OMPC_depend,
4461 SourceLocation(), SourceLocation(),
4462 SourceLocation(), N),
4463 NumLoops(NumLoops) {}
4465 /// Set dependency kind.
4466 void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
4468 /// Set dependency kind and its location.
4469 void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
4471 /// Set colon location.
4472 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
4474 /// Sets optional dependency modifier.
4475 void setModifier(Expr *DepModifier);
4478 /// Creates clause with a list of variables \a VL.
4480 /// \param C AST context.
4481 /// \param StartLoc Starting location of the clause.
4482 /// \param LParenLoc Location of '('.
4483 /// \param EndLoc Ending location of the clause.
4484 /// \param DepKind Dependency type.
4485 /// \param DepLoc Location of the dependency type.
4486 /// \param ColonLoc Colon location.
4487 /// \param VL List of references to the variables.
4488 /// \param NumLoops Number of loops that is associated with this depend
4490 static OMPDependClause *Create(const ASTContext &C, SourceLocation StartLoc,
4491 SourceLocation LParenLoc,
4492 SourceLocation EndLoc, Expr *DepModifier,
4493 OpenMPDependClauseKind DepKind,
4494 SourceLocation DepLoc, SourceLocation ColonLoc,
4495 ArrayRef<Expr *> VL, unsigned NumLoops);
4497 /// Creates an empty clause with \a N variables.
4499 /// \param C AST context.
4500 /// \param N The number of variables.
4501 /// \param NumLoops Number of loops that is associated with this depend
4503 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N,
4506 /// Get dependency type.
4507 OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
4509 /// Return optional depend modifier.
4510 Expr *getModifier();
4511 const Expr *getModifier() const {
4512 return const_cast<OMPDependClause *>(this)->getModifier();
4515 /// Get dependency type location.
4516 SourceLocation getDependencyLoc() const { return DepLoc; }
4518 /// Get colon location.
4519 SourceLocation getColonLoc() const { return ColonLoc; }
4521 /// Get number of loops associated with the clause.
4522 unsigned getNumLoops() const { return NumLoops; }
4524 /// Set the loop data for the depend clauses with 'sink|source' kind of
4526 void setLoopData(unsigned NumLoop, Expr *Cnt);
4528 /// Get the loop data.
4529 Expr *getLoopData(unsigned NumLoop);
4530 const Expr *getLoopData(unsigned NumLoop) const;
4532 child_range children() {
4533 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4534 reinterpret_cast<Stmt **>(varlist_end()));
4537 const_child_range children() const {
4538 auto Children = const_cast<OMPDependClause *>(this)->children();
4539 return const_child_range(Children.begin(), Children.end());
4542 child_range used_children() {
4543 return child_range(child_iterator(), child_iterator());
4545 const_child_range used_children() const {
4546 return const_child_range(const_child_iterator(), const_child_iterator());
4549 static bool classof(const OMPClause *T) {
4550 return T->getClauseKind() == llvm::omp::OMPC_depend;
4554 /// This represents 'device' clause in the '#pragma omp ...'
4558 /// #pragma omp target device(a)
4560 /// In this example directive '#pragma omp target' has clause 'device'
4561 /// with single expression 'a'.
4562 class OMPDeviceClause : public OMPClause, public OMPClauseWithPreInit {
4563 friend class OMPClauseReader;
4565 /// Location of '('.
4566 SourceLocation LParenLoc;
4568 /// Device clause modifier.
4569 OpenMPDeviceClauseModifier Modifier = OMPC_DEVICE_unknown;
4571 /// Location of the modifier.
4572 SourceLocation ModifierLoc;
4575 Stmt *Device = nullptr;
4577 /// Set the device number.
4579 /// \param E Device number.
4580 void setDevice(Expr *E) { Device = E; }
4583 void setModifier(OpenMPDeviceClauseModifier M) { Modifier = M; }
4585 /// Setst modifier location.
4586 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
4589 /// Build 'device' clause.
4591 /// \param Modifier Clause modifier.
4592 /// \param E Expression associated with this clause.
4593 /// \param CaptureRegion Innermost OpenMP region where expressions in this
4594 /// clause must be captured.
4595 /// \param StartLoc Starting location of the clause.
4596 /// \param ModifierLoc Modifier location.
4597 /// \param LParenLoc Location of '('.
4598 /// \param EndLoc Ending location of the clause.
4599 OMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *E, Stmt *HelperE,
4600 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
4601 SourceLocation LParenLoc, SourceLocation ModifierLoc,
4602 SourceLocation EndLoc)
4603 : OMPClause(llvm::omp::OMPC_device, StartLoc, EndLoc),
4604 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Modifier(Modifier),
4605 ModifierLoc(ModifierLoc), Device(E) {
4606 setPreInitStmt(HelperE, CaptureRegion);
4609 /// Build an empty clause.
4611 : OMPClause(llvm::omp::OMPC_device, SourceLocation(), SourceLocation()),
4612 OMPClauseWithPreInit(this) {}
4614 /// Sets the location of '('.
4615 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4617 /// Returns the location of '('.
4618 SourceLocation getLParenLoc() const { return LParenLoc; }
4620 /// Return device number.
4621 Expr *getDevice() { return cast<Expr>(Device); }
4623 /// Return device number.
4624 Expr *getDevice() const { return cast<Expr>(Device); }
4627 OpenMPDeviceClauseModifier getModifier() const { return Modifier; }
4629 /// Gets modifier location.
4630 SourceLocation getModifierLoc() const { return ModifierLoc; }
4632 child_range children() { return child_range(&Device, &Device + 1); }
4634 const_child_range children() const {
4635 return const_child_range(&Device, &Device + 1);
4638 child_range used_children() {
4639 return child_range(child_iterator(), child_iterator());
4641 const_child_range used_children() const {
4642 return const_child_range(const_child_iterator(), const_child_iterator());
4645 static bool classof(const OMPClause *T) {
4646 return T->getClauseKind() == llvm::omp::OMPC_device;
4650 /// This represents 'threads' clause in the '#pragma omp ...' directive.
4653 /// #pragma omp ordered threads
4655 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
4656 class OMPThreadsClause : public OMPClause {
4658 /// Build 'threads' clause.
4660 /// \param StartLoc Starting location of the clause.
4661 /// \param EndLoc Ending location of the clause.
4662 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
4663 : OMPClause(llvm::omp::OMPC_threads, StartLoc, EndLoc) {}
4665 /// Build an empty clause.
4667 : OMPClause(llvm::omp::OMPC_threads, SourceLocation(), SourceLocation()) {
4670 child_range children() {
4671 return child_range(child_iterator(), child_iterator());
4674 const_child_range children() const {
4675 return const_child_range(const_child_iterator(), const_child_iterator());
4678 child_range used_children() {
4679 return child_range(child_iterator(), child_iterator());
4681 const_child_range used_children() const {
4682 return const_child_range(const_child_iterator(), const_child_iterator());
4685 static bool classof(const OMPClause *T) {
4686 return T->getClauseKind() == llvm::omp::OMPC_threads;
4690 /// This represents 'simd' clause in the '#pragma omp ...' directive.
4693 /// #pragma omp ordered simd
4695 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
4696 class OMPSIMDClause : public OMPClause {
4698 /// Build 'simd' clause.
4700 /// \param StartLoc Starting location of the clause.
4701 /// \param EndLoc Ending location of the clause.
4702 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
4703 : OMPClause(llvm::omp::OMPC_simd, StartLoc, EndLoc) {}
4705 /// Build an empty clause.
4707 : OMPClause(llvm::omp::OMPC_simd, SourceLocation(), SourceLocation()) {}
4709 child_range children() {
4710 return child_range(child_iterator(), child_iterator());
4713 const_child_range children() const {
4714 return const_child_range(const_child_iterator(), const_child_iterator());
4717 child_range used_children() {
4718 return child_range(child_iterator(), child_iterator());
4720 const_child_range used_children() const {
4721 return const_child_range(const_child_iterator(), const_child_iterator());
4724 static bool classof(const OMPClause *T) {
4725 return T->getClauseKind() == llvm::omp::OMPC_simd;
4729 /// Struct that defines common infrastructure to handle mappable
4730 /// expressions used in OpenMP clauses.
4731 class OMPClauseMappableExprCommon {
4733 /// Class that represents a component of a mappable expression. E.g.
4734 /// for an expression S.a, the first component is a declaration reference
4735 /// expression associated with 'S' and the second is a member expression
4736 /// associated with the field declaration 'a'. If the expression is an array
4737 /// subscript it may not have any associated declaration. In that case the
4738 /// associated declaration is set to nullptr.
4739 class MappableComponent {
4740 /// Expression associated with the component.
4741 Expr *AssociatedExpression = nullptr;
4743 /// Declaration associated with the declaration. If the component does
4744 /// not have a declaration (e.g. array subscripts or section), this is set
4746 ValueDecl *AssociatedDeclaration = nullptr;
4749 explicit MappableComponent() = default;
4750 explicit MappableComponent(Expr *AssociatedExpression,
4751 ValueDecl *AssociatedDeclaration)
4752 : AssociatedExpression(AssociatedExpression),
4753 AssociatedDeclaration(
4754 AssociatedDeclaration
4755 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
4758 Expr *getAssociatedExpression() const { return AssociatedExpression; }
4760 ValueDecl *getAssociatedDeclaration() const {
4761 return AssociatedDeclaration;
4765 // List of components of an expression. This first one is the whole
4766 // expression and the last one is the base expression.
4767 using MappableExprComponentList = SmallVector<MappableComponent, 8>;
4768 using MappableExprComponentListRef = ArrayRef<MappableComponent>;
4770 // List of all component lists associated to the same base declaration.
4771 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
4772 // their component list but the same base declaration 'S'.
4773 using MappableExprComponentLists = SmallVector<MappableExprComponentList, 8>;
4774 using MappableExprComponentListsRef = ArrayRef<MappableExprComponentList>;
4777 // Return the total number of elements in a list of component lists.
4779 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
4781 // Return the total number of elements in a list of declarations. All
4782 // declarations are expected to be canonical.
4784 getUniqueDeclarationsTotalNumber(ArrayRef<const ValueDecl *> Declarations);
4787 /// This structure contains all sizes needed for by an
4788 /// OMPMappableExprListClause.
4789 struct OMPMappableExprListSizeTy {
4790 /// Number of expressions listed.
4792 /// Number of unique base declarations.
4793 unsigned NumUniqueDeclarations;
4794 /// Number of component lists.
4795 unsigned NumComponentLists;
4796 /// Total number of expression components.
4797 unsigned NumComponents;
4798 OMPMappableExprListSizeTy() = default;
4799 OMPMappableExprListSizeTy(unsigned NumVars, unsigned NumUniqueDeclarations,
4800 unsigned NumComponentLists, unsigned NumComponents)
4801 : NumVars(NumVars), NumUniqueDeclarations(NumUniqueDeclarations),
4802 NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
4805 /// This represents clauses with a list of expressions that are mappable.
4806 /// Examples of these clauses are 'map' in
4807 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
4808 /// in '#pragma omp target update...' directives.
4810 class OMPMappableExprListClause : public OMPVarListClause<T>,
4811 public OMPClauseMappableExprCommon {
4812 friend class OMPClauseReader;
4814 /// Number of unique declarations in this clause.
4815 unsigned NumUniqueDeclarations;
4817 /// Number of component lists in this clause.
4818 unsigned NumComponentLists;
4820 /// Total number of components in this clause.
4821 unsigned NumComponents;
4823 /// C++ nested name specifier for the associated user-defined mapper.
4824 NestedNameSpecifierLoc MapperQualifierLoc;
4826 /// The associated user-defined mapper identifier information.
4827 DeclarationNameInfo MapperIdInfo;
4830 /// Build a clause for \a NumUniqueDeclarations declarations, \a
4831 /// NumComponentLists total component lists, and \a NumComponents total
4834 /// \param K Kind of the clause.
4835 /// \param Locs Locations needed to build a mappable clause. It includes 1)
4836 /// StartLoc: starting location of the clause (the clause keyword); 2)
4837 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
4838 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
4839 /// NumVars: number of expressions listed in this clause; 2)
4840 /// NumUniqueDeclarations: number of unique base declarations in this clause;
4841 /// 3) NumComponentLists: number of component lists in this clause; and 4)
4842 /// NumComponents: total number of expression components in the clause.
4843 /// \param MapperQualifierLocPtr C++ nested name specifier for the associated
4844 /// user-defined mapper.
4845 /// \param MapperIdInfoPtr The identifier of associated user-defined mapper.
4846 OMPMappableExprListClause(
4847 OpenMPClauseKind K, const OMPVarListLocTy &Locs,
4848 const OMPMappableExprListSizeTy &Sizes,
4849 NestedNameSpecifierLoc *MapperQualifierLocPtr = nullptr,
4850 DeclarationNameInfo *MapperIdInfoPtr = nullptr)
4851 : OMPVarListClause<T>(K, Locs.StartLoc, Locs.LParenLoc, Locs.EndLoc,
4853 NumUniqueDeclarations(Sizes.NumUniqueDeclarations),
4854 NumComponentLists(Sizes.NumComponentLists),
4855 NumComponents(Sizes.NumComponents) {
4856 if (MapperQualifierLocPtr)
4857 MapperQualifierLoc = *MapperQualifierLocPtr;
4858 if (MapperIdInfoPtr)
4859 MapperIdInfo = *MapperIdInfoPtr;
4862 /// Get the unique declarations that are in the trailing objects of the
4864 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
4865 return MutableArrayRef<ValueDecl *>(
4866 static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
4867 NumUniqueDeclarations);
4870 /// Get the unique declarations that are in the trailing objects of the
4872 ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
4873 return ArrayRef<ValueDecl *>(
4874 static_cast<const T *>(this)
4875 ->template getTrailingObjects<ValueDecl *>(),
4876 NumUniqueDeclarations);
4879 /// Set the unique declarations that are in the trailing objects of the
4881 void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
4882 assert(UDs.size() == NumUniqueDeclarations &&
4883 "Unexpected amount of unique declarations.");
4884 std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
4887 /// Get the number of lists per declaration that are in the trailing
4888 /// objects of the class.
4889 MutableArrayRef<unsigned> getDeclNumListsRef() {
4890 return MutableArrayRef<unsigned>(
4891 static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
4892 NumUniqueDeclarations);
4895 /// Get the number of lists per declaration that are in the trailing
4896 /// objects of the class.
4897 ArrayRef<unsigned> getDeclNumListsRef() const {
4898 return ArrayRef<unsigned>(
4899 static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
4900 NumUniqueDeclarations);
4903 /// Set the number of lists per declaration that are in the trailing
4904 /// objects of the class.
4905 void setDeclNumLists(ArrayRef<unsigned> DNLs) {
4906 assert(DNLs.size() == NumUniqueDeclarations &&
4907 "Unexpected amount of list numbers.");
4908 std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
4911 /// Get the cumulative component lists sizes that are in the trailing
4912 /// objects of the class. They are appended after the number of lists.
4913 MutableArrayRef<unsigned> getComponentListSizesRef() {
4914 return MutableArrayRef<unsigned>(
4915 static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
4916 NumUniqueDeclarations,
4920 /// Get the cumulative component lists sizes that are in the trailing
4921 /// objects of the class. They are appended after the number of lists.
4922 ArrayRef<unsigned> getComponentListSizesRef() const {
4923 return ArrayRef<unsigned>(
4924 static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
4925 NumUniqueDeclarations,
4929 /// Set the cumulative component lists sizes that are in the trailing
4930 /// objects of the class.
4931 void setComponentListSizes(ArrayRef<unsigned> CLSs) {
4932 assert(CLSs.size() == NumComponentLists &&
4933 "Unexpected amount of component lists.");
4934 std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
4937 /// Get the components that are in the trailing objects of the class.
4938 MutableArrayRef<MappableComponent> getComponentsRef() {
4939 return MutableArrayRef<MappableComponent>(
4940 static_cast<T *>(this)
4941 ->template getTrailingObjects<MappableComponent>(),
4945 /// Get the components that are in the trailing objects of the class.
4946 ArrayRef<MappableComponent> getComponentsRef() const {
4947 return ArrayRef<MappableComponent>(
4948 static_cast<const T *>(this)
4949 ->template getTrailingObjects<MappableComponent>(),
4953 /// Set the components that are in the trailing objects of the class.
4954 /// This requires the list sizes so that it can also fill the original
4955 /// expressions, which are the first component of each list.
4956 void setComponents(ArrayRef<MappableComponent> Components,
4957 ArrayRef<unsigned> CLSs) {
4958 assert(Components.size() == NumComponents &&
4959 "Unexpected amount of component lists.");
4960 assert(CLSs.size() == NumComponentLists &&
4961 "Unexpected amount of list sizes.");
4962 std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
4965 /// Fill the clause information from the list of declarations and
4966 /// associated component lists.
4967 void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
4968 MappableExprComponentListsRef ComponentLists) {
4969 // Perform some checks to make sure the data sizes are consistent with the
4970 // information available when the clause was created.
4971 assert(getUniqueDeclarationsTotalNumber(Declarations) ==
4972 NumUniqueDeclarations &&
4973 "Unexpected number of mappable expression info entries!");
4974 assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
4975 "Unexpected total number of components!");
4976 assert(Declarations.size() == ComponentLists.size() &&
4977 "Declaration and component lists size is not consistent!");
4978 assert(Declarations.size() == NumComponentLists &&
4979 "Unexpected declaration and component lists size!");
4981 // Organize the components by declaration and retrieve the original
4982 // expression. Original expressions are always the first component of the
4983 // mappable component list.
4984 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
4987 auto CI = ComponentLists.begin();
4988 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
4990 assert(!CI->empty() && "Invalid component list!");
4991 ComponentListMap[*DI].push_back(*CI);
4995 // Iterators of the target storage.
4996 auto UniqueDeclarations = getUniqueDeclsRef();
4997 auto UDI = UniqueDeclarations.begin();
4999 auto DeclNumLists = getDeclNumListsRef();
5000 auto DNLI = DeclNumLists.begin();
5002 auto ComponentListSizes = getComponentListSizesRef();
5003 auto CLSI = ComponentListSizes.begin();
5005 auto Components = getComponentsRef();
5006 auto CI = Components.begin();
5008 // Variable to compute the accumulation of the number of components.
5009 unsigned PrevSize = 0u;
5011 // Scan all the declarations and associated component lists.
5012 for (auto &M : ComponentListMap) {
5015 // The component lists.
5018 // Initialize the entry.
5025 // Obtain the cumulative sizes and concatenate all the components in the
5026 // reserved storage.
5028 // Accumulate with the previous size.
5029 PrevSize += C.size();
5035 // Append components after the current components iterator.
5036 CI = std::copy(C.begin(), C.end(), CI);
5041 /// Set the nested name specifier of associated user-defined mapper.
5042 void setMapperQualifierLoc(NestedNameSpecifierLoc NNSL) {
5043 MapperQualifierLoc = NNSL;
5046 /// Set the name of associated user-defined mapper.
5047 void setMapperIdInfo(DeclarationNameInfo MapperId) {
5048 MapperIdInfo = MapperId;
5051 /// Get the user-defined mapper references that are in the trailing objects of
5053 MutableArrayRef<Expr *> getUDMapperRefs() {
5054 return llvm::makeMutableArrayRef<Expr *>(
5055 static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
5056 OMPVarListClause<T>::varlist_size(),
5057 OMPVarListClause<T>::varlist_size());
5060 /// Get the user-defined mappers references that are in the trailing objects
5062 ArrayRef<Expr *> getUDMapperRefs() const {
5063 return llvm::makeArrayRef<Expr *>(
5064 static_cast<T *>(this)->template getTrailingObjects<Expr *>() +
5065 OMPVarListClause<T>::varlist_size(),
5066 OMPVarListClause<T>::varlist_size());
5069 /// Set the user-defined mappers that are in the trailing objects of the
5071 void setUDMapperRefs(ArrayRef<Expr *> DMDs) {
5072 assert(DMDs.size() == OMPVarListClause<T>::varlist_size() &&
5073 "Unexpected number of user-defined mappers.");
5074 std::copy(DMDs.begin(), DMDs.end(), getUDMapperRefs().begin());
5078 /// Return the number of unique base declarations in this clause.
5079 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
5081 /// Return the number of lists derived from the clause expressions.
5082 unsigned getTotalComponentListNum() const { return NumComponentLists; }
5084 /// Return the total number of components in all lists derived from the
5086 unsigned getTotalComponentsNum() const { return NumComponents; }
5088 /// Gets the nested name specifier for associated user-defined mapper.
5089 NestedNameSpecifierLoc getMapperQualifierLoc() const {
5090 return MapperQualifierLoc;
5093 /// Gets the name info for associated user-defined mapper.
5094 const DeclarationNameInfo &getMapperIdInfo() const { return MapperIdInfo; }
5096 /// Iterator that browse the components by lists. It also allows
5097 /// browsing components of a single declaration.
5098 class const_component_lists_iterator
5099 : public llvm::iterator_adaptor_base<
5100 const_component_lists_iterator,
5101 MappableExprComponentListRef::const_iterator,
5102 std::forward_iterator_tag, MappableComponent, ptrdiff_t,
5103 MappableComponent, MappableComponent> {
5104 // The declaration the iterator currently refers to.
5105 ArrayRef<ValueDecl *>::iterator DeclCur;
5107 // The list number associated with the current declaration.
5108 ArrayRef<unsigned>::iterator NumListsCur;
5110 // Remaining lists for the current declaration.
5111 unsigned RemainingLists = 0;
5113 // The cumulative size of the previous list, or zero if there is no previous
5115 unsigned PrevListSize = 0;
5117 // The cumulative sizes of the current list - it will delimit the remaining
5118 // range of interest.
5119 ArrayRef<unsigned>::const_iterator ListSizeCur;
5120 ArrayRef<unsigned>::const_iterator ListSizeEnd;
5122 // Iterator to the end of the components storage.
5123 MappableExprComponentListRef::const_iterator End;
5126 /// Construct an iterator that scans all lists.
5127 explicit const_component_lists_iterator(
5128 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
5129 ArrayRef<unsigned> CumulativeListSizes,
5130 MappableExprComponentListRef Components)
5131 : const_component_lists_iterator::iterator_adaptor_base(
5132 Components.begin()),
5133 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
5134 ListSizeCur(CumulativeListSizes.begin()),
5135 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
5136 assert(UniqueDecls.size() == DeclsListNum.size() &&
5137 "Inconsistent number of declarations and list sizes!");
5138 if (!DeclsListNum.empty())
5139 RemainingLists = *NumListsCur;
5142 /// Construct an iterator that scan lists for a given declaration \a
5144 explicit const_component_lists_iterator(
5145 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
5146 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
5147 MappableExprComponentListRef Components)
5148 : const_component_lists_iterator(UniqueDecls, DeclsListNum,
5149 CumulativeListSizes, Components) {
5150 // Look for the desired declaration. While we are looking for it, we
5151 // update the state so that we know the component where a given list
5153 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
5154 if (*DeclCur == Declaration)
5157 assert(*NumListsCur > 0 && "No lists associated with declaration??");
5159 // Skip the lists associated with the current declaration, but save the
5160 // last list size that was skipped.
5161 std::advance(ListSizeCur, *NumListsCur - 1);
5162 PrevListSize = *ListSizeCur;
5166 // If we didn't find any declaration, advance the iterator to after the
5167 // last component and set remaining lists to zero.
5168 if (ListSizeCur == CumulativeListSizes.end()) {
5170 RemainingLists = 0u;
5174 // Set the remaining lists with the total number of lists of the current
5176 RemainingLists = *NumListsCur;
5178 // Adjust the list size end iterator to the end of the relevant range.
5179 ListSizeEnd = ListSizeCur;
5180 std::advance(ListSizeEnd, RemainingLists);
5182 // Given that the list sizes are cumulative, the index of the component
5183 // that start the list is the size of the previous list.
5184 std::advance(this->I, PrevListSize);
5187 // Return the array with the current list. The sizes are cumulative, so the
5188 // array size is the difference between the current size and previous one.
5189 std::pair<const ValueDecl *, MappableExprComponentListRef>
5191 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
5192 return std::make_pair(
5194 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize));
5196 std::pair<const ValueDecl *, MappableExprComponentListRef>
5197 operator->() const {
5201 // Skip the components of the current list.
5202 const_component_lists_iterator &operator++() {
5203 assert(ListSizeCur != ListSizeEnd && RemainingLists &&
5204 "Invalid iterator!");
5206 // If we don't have more lists just skip all the components. Otherwise,
5207 // advance the iterator by the number of components in the current list.
5208 if (std::next(ListSizeCur) == ListSizeEnd) {
5212 std::advance(this->I, *ListSizeCur - PrevListSize);
5213 PrevListSize = *ListSizeCur;
5215 // We are done with a declaration, move to the next one.
5216 if (!(--RemainingLists)) {
5219 RemainingLists = *NumListsCur;
5220 assert(RemainingLists && "No lists in the following declaration??");
5229 using const_component_lists_range =
5230 llvm::iterator_range<const_component_lists_iterator>;
5232 /// Iterators for all component lists.
5233 const_component_lists_iterator component_lists_begin() const {
5234 return const_component_lists_iterator(
5235 getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
5236 getComponentsRef());
5238 const_component_lists_iterator component_lists_end() const {
5239 return const_component_lists_iterator(
5240 ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
5241 MappableExprComponentListRef(getComponentsRef().end(),
5242 getComponentsRef().end()));
5244 const_component_lists_range component_lists() const {
5245 return {component_lists_begin(), component_lists_end()};
5248 /// Iterators for component lists associated with the provided
5250 const_component_lists_iterator
5251 decl_component_lists_begin(const ValueDecl *VD) const {
5252 return const_component_lists_iterator(
5253 VD, getUniqueDeclsRef(), getDeclNumListsRef(),
5254 getComponentListSizesRef(), getComponentsRef());
5256 const_component_lists_iterator decl_component_lists_end() const {
5257 return component_lists_end();
5259 const_component_lists_range decl_component_lists(const ValueDecl *VD) const {
5260 return {decl_component_lists_begin(VD), decl_component_lists_end()};
5263 /// Iterators to access all the declarations, number of lists, list sizes, and
5265 using const_all_decls_iterator = ArrayRef<ValueDecl *>::iterator;
5266 using const_all_decls_range = llvm::iterator_range<const_all_decls_iterator>;
5268 const_all_decls_range all_decls() const {
5269 auto A = getUniqueDeclsRef();
5270 return const_all_decls_range(A.begin(), A.end());
5273 using const_all_num_lists_iterator = ArrayRef<unsigned>::iterator;
5274 using const_all_num_lists_range =
5275 llvm::iterator_range<const_all_num_lists_iterator>;
5277 const_all_num_lists_range all_num_lists() const {
5278 auto A = getDeclNumListsRef();
5279 return const_all_num_lists_range(A.begin(), A.end());
5282 using const_all_lists_sizes_iterator = ArrayRef<unsigned>::iterator;
5283 using const_all_lists_sizes_range =
5284 llvm::iterator_range<const_all_lists_sizes_iterator>;
5286 const_all_lists_sizes_range all_lists_sizes() const {
5287 auto A = getComponentListSizesRef();
5288 return const_all_lists_sizes_range(A.begin(), A.end());
5291 using const_all_components_iterator = ArrayRef<MappableComponent>::iterator;
5292 using const_all_components_range =
5293 llvm::iterator_range<const_all_components_iterator>;
5295 const_all_components_range all_components() const {
5296 auto A = getComponentsRef();
5297 return const_all_components_range(A.begin(), A.end());
5300 using mapperlist_iterator = MutableArrayRef<Expr *>::iterator;
5301 using mapperlist_const_iterator = ArrayRef<const Expr *>::iterator;
5302 using mapperlist_range = llvm::iterator_range<mapperlist_iterator>;
5303 using mapperlist_const_range =
5304 llvm::iterator_range<mapperlist_const_iterator>;
5306 mapperlist_iterator mapperlist_begin() { return getUDMapperRefs().begin(); }
5307 mapperlist_iterator mapperlist_end() { return getUDMapperRefs().end(); }
5308 mapperlist_const_iterator mapperlist_begin() const {
5309 return getUDMapperRefs().begin();
5311 mapperlist_const_iterator mapperlist_end() const {
5312 return getUDMapperRefs().end();
5314 mapperlist_range mapperlists() {
5315 return mapperlist_range(mapperlist_begin(), mapperlist_end());
5317 mapperlist_const_range mapperlists() const {
5318 return mapperlist_const_range(mapperlist_begin(), mapperlist_end());
5322 /// This represents clause 'map' in the '#pragma omp ...'
5326 /// #pragma omp target map(a,b)
5328 /// In this example directive '#pragma omp target' has clause 'map'
5329 /// with the variables 'a' and 'b'.
5330 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
5331 private llvm::TrailingObjects<
5332 OMPMapClause, Expr *, ValueDecl *, unsigned,
5333 OMPClauseMappableExprCommon::MappableComponent> {
5334 friend class OMPClauseReader;
5335 friend OMPMappableExprListClause;
5336 friend OMPVarListClause;
5337 friend TrailingObjects;
5339 /// Define the sizes of each trailing object array except the last one. This
5340 /// is required for TrailingObjects to work properly.
5341 size_t numTrailingObjects(OverloadToken<Expr *>) const {
5342 // There are varlist_size() of expressions, and varlist_size() of
5343 // user-defined mappers.
5344 return 2 * varlist_size();
5346 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
5347 return getUniqueDeclarationsNum();
5349 size_t numTrailingObjects(OverloadToken<unsigned>) const {
5350 return getUniqueDeclarationsNum() + getTotalComponentListNum();
5354 /// Map-type-modifiers for the 'map' clause.
5355 OpenMPMapModifierKind MapTypeModifiers[NumberOfOMPMapClauseModifiers] = {
5356 OMPC_MAP_MODIFIER_unknown, OMPC_MAP_MODIFIER_unknown,
5357 OMPC_MAP_MODIFIER_unknown};
5359 /// Location of map-type-modifiers for the 'map' clause.
5360 SourceLocation MapTypeModifiersLoc[NumberOfOMPMapClauseModifiers];
5362 /// Map type for the 'map' clause.
5363 OpenMPMapClauseKind MapType = OMPC_MAP_unknown;
5365 /// Is this an implicit map type or not.
5366 bool MapTypeIsImplicit = false;
5368 /// Location of the map type.
5369 SourceLocation MapLoc;
5372 SourceLocation ColonLoc;
5374 /// Build a clause for \a NumVars listed expressions, \a
5375 /// NumUniqueDeclarations declarations, \a NumComponentLists total component
5376 /// lists, and \a NumComponents total expression components.
5378 /// \param MapModifiers Map-type-modifiers.
5379 /// \param MapModifiersLoc Locations of map-type-modifiers.
5380 /// \param MapperQualifierLoc C++ nested name specifier for the associated
5381 /// user-defined mapper.
5382 /// \param MapperIdInfo The identifier of associated user-defined mapper.
5383 /// \param MapType Map type.
5384 /// \param MapTypeIsImplicit Map type is inferred implicitly.
5385 /// \param MapLoc Location of the map type.
5386 /// \param Locs Locations needed to build a mappable clause. It includes 1)
5387 /// StartLoc: starting location of the clause (the clause keyword); 2)
5388 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5389 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5390 /// NumVars: number of expressions listed in this clause; 2)
5391 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5392 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5393 /// NumComponents: total number of expression components in the clause.
5394 explicit OMPMapClause(ArrayRef<OpenMPMapModifierKind> MapModifiers,
5395 ArrayRef<SourceLocation> MapModifiersLoc,
5396 NestedNameSpecifierLoc MapperQualifierLoc,
5397 DeclarationNameInfo MapperIdInfo,
5398 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
5399 SourceLocation MapLoc, const OMPVarListLocTy &Locs,
5400 const OMPMappableExprListSizeTy &Sizes)
5401 : OMPMappableExprListClause(llvm::omp::OMPC_map, Locs, Sizes,
5402 &MapperQualifierLoc, &MapperIdInfo),
5403 MapType(MapType), MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {
5404 assert(llvm::array_lengthof(MapTypeModifiers) == MapModifiers.size() &&
5405 "Unexpected number of map type modifiers.");
5406 llvm::copy(MapModifiers, std::begin(MapTypeModifiers));
5408 assert(llvm::array_lengthof(MapTypeModifiersLoc) ==
5409 MapModifiersLoc.size() &&
5410 "Unexpected number of map type modifier locations.");
5411 llvm::copy(MapModifiersLoc, std::begin(MapTypeModifiersLoc));
5414 /// Build an empty clause.
5416 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5417 /// NumVars: number of expressions listed in this clause; 2)
5418 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5419 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5420 /// NumComponents: total number of expression components in the clause.
5421 explicit OMPMapClause(const OMPMappableExprListSizeTy &Sizes)
5422 : OMPMappableExprListClause(llvm::omp::OMPC_map, OMPVarListLocTy(),
5425 /// Set map-type-modifier for the clause.
5427 /// \param I index for map-type-modifier.
5428 /// \param T map-type-modifier for the clause.
5429 void setMapTypeModifier(unsigned I, OpenMPMapModifierKind T) {
5430 assert(I < NumberOfOMPMapClauseModifiers &&
5431 "Unexpected index to store map type modifier, exceeds array size.");
5432 MapTypeModifiers[I] = T;
5435 /// Set location for the map-type-modifier.
5437 /// \param I index for map-type-modifier location.
5438 /// \param TLoc map-type-modifier location.
5439 void setMapTypeModifierLoc(unsigned I, SourceLocation TLoc) {
5440 assert(I < NumberOfOMPMapClauseModifiers &&
5441 "Index to store map type modifier location exceeds array size.");
5442 MapTypeModifiersLoc[I] = TLoc;
5445 /// Set type for the clause.
5447 /// \param T Type for the clause.
5448 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
5450 /// Set type location.
5452 /// \param TLoc Type location.
5453 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
5455 /// Set colon location.
5456 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
5459 /// Creates clause with a list of variables \a VL.
5461 /// \param C AST context.
5462 /// \param Locs Locations needed to build a mappable clause. It includes 1)
5463 /// StartLoc: starting location of the clause (the clause keyword); 2)
5464 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
5465 /// \param Vars The original expression used in the clause.
5466 /// \param Declarations Declarations used in the clause.
5467 /// \param ComponentLists Component lists used in the clause.
5468 /// \param UDMapperRefs References to user-defined mappers associated with
5469 /// expressions used in the clause.
5470 /// \param MapModifiers Map-type-modifiers.
5471 /// \param MapModifiersLoc Location of map-type-modifiers.
5472 /// \param UDMQualifierLoc C++ nested name specifier for the associated
5473 /// user-defined mapper.
5474 /// \param MapperId The identifier of associated user-defined mapper.
5475 /// \param Type Map type.
5476 /// \param TypeIsImplicit Map type is inferred implicitly.
5477 /// \param TypeLoc Location of the map type.
5478 static OMPMapClause *
5479 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
5480 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
5481 MappableExprComponentListsRef ComponentLists,
5482 ArrayRef<Expr *> UDMapperRefs,
5483 ArrayRef<OpenMPMapModifierKind> MapModifiers,
5484 ArrayRef<SourceLocation> MapModifiersLoc,
5485 NestedNameSpecifierLoc UDMQualifierLoc, DeclarationNameInfo MapperId,
5486 OpenMPMapClauseKind Type, bool TypeIsImplicit, SourceLocation TypeLoc);
5488 /// Creates an empty clause with the place for \a NumVars original
5489 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
5490 /// lists, and \a NumComponents expression components.
5492 /// \param C AST context.
5493 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
5494 /// NumVars: number of expressions listed in this clause; 2)
5495 /// NumUniqueDeclarations: number of unique base declarations in this clause;
5496 /// 3) NumComponentLists: number of component lists in this clause; and 4)
5497 /// NumComponents: total number of expression components in the clause.
5498 static OMPMapClause *CreateEmpty(const ASTContext &C,
5499 const OMPMappableExprListSizeTy &Sizes);
5501 /// Fetches mapping kind for the clause.
5502 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
5504 /// Is this an implicit map type?
5505 /// We have to capture 'IsMapTypeImplicit' from the parser for more
5506 /// informative error messages. It helps distinguish map(r) from
5507 /// map(tofrom: r), which is important to print more helpful error
5508 /// messages for some target directives.
5509 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
5511 /// Fetches the map-type-modifier at 'Cnt' index of array of modifiers.
5513 /// \param Cnt index for map-type-modifier.
5514 OpenMPMapModifierKind getMapTypeModifier(unsigned Cnt) const LLVM_READONLY {
5515 assert(Cnt < NumberOfOMPMapClauseModifiers &&
5516 "Requested modifier exceeds the total number of modifiers.");
5517 return MapTypeModifiers[Cnt];
5520 /// Fetches the map-type-modifier location at 'Cnt' index of array of
5521 /// modifiers' locations.
5523 /// \param Cnt index for map-type-modifier location.
5524 SourceLocation getMapTypeModifierLoc(unsigned Cnt) const LLVM_READONLY {
5525 assert(Cnt < NumberOfOMPMapClauseModifiers &&
5526 "Requested modifier location exceeds total number of modifiers.");
5527 return MapTypeModifiersLoc[Cnt];
5530 /// Fetches ArrayRef of map-type-modifiers.
5531 ArrayRef<OpenMPMapModifierKind> getMapTypeModifiers() const LLVM_READONLY {
5532 return llvm::makeArrayRef(MapTypeModifiers);
5535 /// Fetches ArrayRef of location of map-type-modifiers.
5536 ArrayRef<SourceLocation> getMapTypeModifiersLoc() const LLVM_READONLY {
5537 return llvm::makeArrayRef(MapTypeModifiersLoc);
5540 /// Fetches location of clause mapping kind.
5541 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
5543 /// Get colon location.
5544 SourceLocation getColonLoc() const { return ColonLoc; }
5546 child_range children() {
5548 reinterpret_cast<Stmt **>(varlist_begin()),
5549 reinterpret_cast<Stmt **>(varlist_end()));
5552 const_child_range children() const {
5553 auto Children = const_cast<OMPMapClause *>(this)->children();
5554 return const_child_range(Children.begin(), Children.end());
5557 child_range used_children() {
5558 if (MapType == OMPC_MAP_to || MapType == OMPC_MAP_tofrom)
5559 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
5560 reinterpret_cast<Stmt **>(varlist_end()));
5561 return child_range(child_iterator(), child_iterator());
5563 const_child_range used_children() const {
5564 auto Children = const_cast<OMPMapClause *>(this)->used_children();
5565 return const_child_range(Children.begin(), Children.end());
5569 static bool classof(const OMPClause *T) {
5570 return T->getClauseKind() == llvm::omp::OMPC_map;
5574 /// This represents 'num_teams' clause in the '#pragma omp ...'
5578 /// #pragma omp teams num_teams(n)
5580 /// In this example directive '#pragma omp teams' has clause 'num_teams'
5581 /// with single expression 'n'.
5582 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
5583 friend class OMPClauseReader;
5585 /// Location of '('.
5586 SourceLocation LParenLoc;
5588 /// NumTeams number.
5589 Stmt *NumTeams = nullptr;
5591 /// Set the NumTeams number.
5593 /// \param E NumTeams number.
5594 void setNumTeams(Expr *E) { NumTeams = E; }
5597 /// Build 'num_teams' clause.
5599 /// \param E Expression associated with this clause.
5600 /// \param HelperE Helper Expression associated with this clause.
5601 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5602 /// clause must be captured.
5603 /// \param StartLoc Starting location of the clause.
5604 /// \param LParenLoc Location of '('.
5605 /// \param EndLoc Ending location of the clause.
5606 OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
5607 SourceLocation StartLoc, SourceLocation LParenLoc,
5608 SourceLocation EndLoc)
5609 : OMPClause(llvm::omp::OMPC_num_teams, StartLoc, EndLoc),
5610 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), NumTeams(E) {
5611 setPreInitStmt(HelperE, CaptureRegion);
5614 /// Build an empty clause.
5616 : OMPClause(llvm::omp::OMPC_num_teams, SourceLocation(),
5618 OMPClauseWithPreInit(this) {}
5620 /// Sets the location of '('.
5621 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5623 /// Returns the location of '('.
5624 SourceLocation getLParenLoc() const { return LParenLoc; }
5626 /// Return NumTeams number.
5627 Expr *getNumTeams() { return cast<Expr>(NumTeams); }
5629 /// Return NumTeams number.
5630 Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
5632 child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
5634 const_child_range children() const {
5635 return const_child_range(&NumTeams, &NumTeams + 1);
5638 child_range used_children() {
5639 return child_range(child_iterator(), child_iterator());
5641 const_child_range used_children() const {
5642 return const_child_range(const_child_iterator(), const_child_iterator());
5645 static bool classof(const OMPClause *T) {
5646 return T->getClauseKind() == llvm::omp::OMPC_num_teams;
5650 /// This represents 'thread_limit' clause in the '#pragma omp ...'
5654 /// #pragma omp teams thread_limit(n)
5656 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
5657 /// with single expression 'n'.
5658 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
5659 friend class OMPClauseReader;
5661 /// Location of '('.
5662 SourceLocation LParenLoc;
5664 /// ThreadLimit number.
5665 Stmt *ThreadLimit = nullptr;
5667 /// Set the ThreadLimit number.
5669 /// \param E ThreadLimit number.
5670 void setThreadLimit(Expr *E) { ThreadLimit = E; }
5673 /// Build 'thread_limit' clause.
5675 /// \param E Expression associated with this clause.
5676 /// \param HelperE Helper Expression associated with this clause.
5677 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5678 /// clause must be captured.
5679 /// \param StartLoc Starting location of the clause.
5680 /// \param LParenLoc Location of '('.
5681 /// \param EndLoc Ending location of the clause.
5682 OMPThreadLimitClause(Expr *E, Stmt *HelperE,
5683 OpenMPDirectiveKind CaptureRegion,
5684 SourceLocation StartLoc, SourceLocation LParenLoc,
5685 SourceLocation EndLoc)
5686 : OMPClause(llvm::omp::OMPC_thread_limit, StartLoc, EndLoc),
5687 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
5688 setPreInitStmt(HelperE, CaptureRegion);
5691 /// Build an empty clause.
5692 OMPThreadLimitClause()
5693 : OMPClause(llvm::omp::OMPC_thread_limit, SourceLocation(),
5695 OMPClauseWithPreInit(this) {}
5697 /// Sets the location of '('.
5698 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5700 /// Returns the location of '('.
5701 SourceLocation getLParenLoc() const { return LParenLoc; }
5703 /// Return ThreadLimit number.
5704 Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
5706 /// Return ThreadLimit number.
5707 Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
5709 child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
5711 const_child_range children() const {
5712 return const_child_range(&ThreadLimit, &ThreadLimit + 1);
5715 child_range used_children() {
5716 return child_range(child_iterator(), child_iterator());
5718 const_child_range used_children() const {
5719 return const_child_range(const_child_iterator(), const_child_iterator());
5722 static bool classof(const OMPClause *T) {
5723 return T->getClauseKind() == llvm::omp::OMPC_thread_limit;
5727 /// This represents 'priority' clause in the '#pragma omp ...'
5731 /// #pragma omp task priority(n)
5733 /// In this example directive '#pragma omp teams' has clause 'priority' with
5734 /// single expression 'n'.
5735 class OMPPriorityClause : public OMPClause, public OMPClauseWithPreInit {
5736 friend class OMPClauseReader;
5738 /// Location of '('.
5739 SourceLocation LParenLoc;
5741 /// Priority number.
5742 Stmt *Priority = nullptr;
5744 /// Set the Priority number.
5746 /// \param E Priority number.
5747 void setPriority(Expr *E) { Priority = E; }
5750 /// Build 'priority' clause.
5752 /// \param Priority Expression associated with this clause.
5753 /// \param HelperPriority Helper priority for the construct.
5754 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5755 /// clause must be captured.
5756 /// \param StartLoc Starting location of the clause.
5757 /// \param LParenLoc Location of '('.
5758 /// \param EndLoc Ending location of the clause.
5759 OMPPriorityClause(Expr *Priority, Stmt *HelperPriority,
5760 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5761 SourceLocation LParenLoc, SourceLocation EndLoc)
5762 : OMPClause(llvm::omp::OMPC_priority, StartLoc, EndLoc),
5763 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Priority(Priority) {
5764 setPreInitStmt(HelperPriority, CaptureRegion);
5767 /// Build an empty clause.
5769 : OMPClause(llvm::omp::OMPC_priority, SourceLocation(), SourceLocation()),
5770 OMPClauseWithPreInit(this) {}
5772 /// Sets the location of '('.
5773 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5775 /// Returns the location of '('.
5776 SourceLocation getLParenLoc() const { return LParenLoc; }
5778 /// Return Priority number.
5779 Expr *getPriority() { return cast<Expr>(Priority); }
5781 /// Return Priority number.
5782 Expr *getPriority() const { return cast<Expr>(Priority); }
5784 child_range children() { return child_range(&Priority, &Priority + 1); }
5786 const_child_range children() const {
5787 return const_child_range(&Priority, &Priority + 1);
5790 child_range used_children();
5791 const_child_range used_children() const {
5792 auto Children = const_cast<OMPPriorityClause *>(this)->used_children();
5793 return const_child_range(Children.begin(), Children.end());
5796 static bool classof(const OMPClause *T) {
5797 return T->getClauseKind() == llvm::omp::OMPC_priority;
5801 /// This represents 'grainsize' clause in the '#pragma omp ...'
5805 /// #pragma omp taskloop grainsize(4)
5807 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
5808 /// with single expression '4'.
5809 class OMPGrainsizeClause : public OMPClause, public OMPClauseWithPreInit {
5810 friend class OMPClauseReader;
5812 /// Location of '('.
5813 SourceLocation LParenLoc;
5815 /// Safe iteration space distance.
5816 Stmt *Grainsize = nullptr;
5819 void setGrainsize(Expr *Size) { Grainsize = Size; }
5822 /// Build 'grainsize' clause.
5824 /// \param Size Expression associated with this clause.
5825 /// \param HelperSize Helper grainsize for the construct.
5826 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5827 /// clause must be captured.
5828 /// \param StartLoc Starting location of the clause.
5829 /// \param EndLoc Ending location of the clause.
5830 OMPGrainsizeClause(Expr *Size, Stmt *HelperSize,
5831 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5832 SourceLocation LParenLoc, SourceLocation EndLoc)
5833 : OMPClause(llvm::omp::OMPC_grainsize, StartLoc, EndLoc),
5834 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Grainsize(Size) {
5835 setPreInitStmt(HelperSize, CaptureRegion);
5838 /// Build an empty clause.
5839 explicit OMPGrainsizeClause()
5840 : OMPClause(llvm::omp::OMPC_grainsize, SourceLocation(),
5842 OMPClauseWithPreInit(this) {}
5844 /// Sets the location of '('.
5845 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5847 /// Returns the location of '('.
5848 SourceLocation getLParenLoc() const { return LParenLoc; }
5850 /// Return safe iteration space distance.
5851 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
5853 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
5855 const_child_range children() const {
5856 return const_child_range(&Grainsize, &Grainsize + 1);
5859 child_range used_children();
5860 const_child_range used_children() const {
5861 auto Children = const_cast<OMPGrainsizeClause *>(this)->used_children();
5862 return const_child_range(Children.begin(), Children.end());
5865 static bool classof(const OMPClause *T) {
5866 return T->getClauseKind() == llvm::omp::OMPC_grainsize;
5870 /// This represents 'nogroup' clause in the '#pragma omp ...' directive.
5873 /// #pragma omp taskloop nogroup
5875 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
5876 class OMPNogroupClause : public OMPClause {
5878 /// Build 'nogroup' clause.
5880 /// \param StartLoc Starting location of the clause.
5881 /// \param EndLoc Ending location of the clause.
5882 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
5883 : OMPClause(llvm::omp::OMPC_nogroup, StartLoc, EndLoc) {}
5885 /// Build an empty clause.
5887 : OMPClause(llvm::omp::OMPC_nogroup, SourceLocation(), SourceLocation()) {
5890 child_range children() {
5891 return child_range(child_iterator(), child_iterator());
5894 const_child_range children() const {
5895 return const_child_range(const_child_iterator(), const_child_iterator());
5898 child_range used_children() {
5899 return child_range(child_iterator(), child_iterator());
5901 const_child_range used_children() const {
5902 return const_child_range(const_child_iterator(), const_child_iterator());
5905 static bool classof(const OMPClause *T) {
5906 return T->getClauseKind() == llvm::omp::OMPC_nogroup;
5910 /// This represents 'num_tasks' clause in the '#pragma omp ...'
5914 /// #pragma omp taskloop num_tasks(4)
5916 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
5917 /// with single expression '4'.
5918 class OMPNumTasksClause : public OMPClause, public OMPClauseWithPreInit {
5919 friend class OMPClauseReader;
5921 /// Location of '('.
5922 SourceLocation LParenLoc;
5924 /// Safe iteration space distance.
5925 Stmt *NumTasks = nullptr;
5928 void setNumTasks(Expr *Size) { NumTasks = Size; }
5931 /// Build 'num_tasks' clause.
5933 /// \param Size Expression associated with this clause.
5934 /// \param HelperSize Helper grainsize for the construct.
5935 /// \param CaptureRegion Innermost OpenMP region where expressions in this
5936 /// clause must be captured.
5937 /// \param StartLoc Starting location of the clause.
5938 /// \param EndLoc Ending location of the clause.
5939 OMPNumTasksClause(Expr *Size, Stmt *HelperSize,
5940 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
5941 SourceLocation LParenLoc, SourceLocation EndLoc)
5942 : OMPClause(llvm::omp::OMPC_num_tasks, StartLoc, EndLoc),
5943 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), NumTasks(Size) {
5944 setPreInitStmt(HelperSize, CaptureRegion);
5947 /// Build an empty clause.
5948 explicit OMPNumTasksClause()
5949 : OMPClause(llvm::omp::OMPC_num_tasks, SourceLocation(),
5951 OMPClauseWithPreInit(this) {}
5953 /// Sets the location of '('.
5954 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
5956 /// Returns the location of '('.
5957 SourceLocation getLParenLoc() const { return LParenLoc; }
5959 /// Return safe iteration space distance.
5960 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
5962 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
5964 const_child_range children() const {
5965 return const_child_range(&NumTasks, &NumTasks + 1);
5968 child_range used_children();
5969 const_child_range used_children() const {
5970 auto Children = const_cast<OMPNumTasksClause *>(this)->used_children();
5971 return const_child_range(Children.begin(), Children.end());
5974 static bool classof(const OMPClause *T) {
5975 return T->getClauseKind() == llvm::omp::OMPC_num_tasks;
5979 /// This represents 'hint' clause in the '#pragma omp ...' directive.
5982 /// #pragma omp critical (name) hint(6)
5984 /// In this example directive '#pragma omp critical' has name 'name' and clause
5985 /// 'hint' with argument '6'.
5986 class OMPHintClause : public OMPClause {
5987 friend class OMPClauseReader;
5989 /// Location of '('.
5990 SourceLocation LParenLoc;
5992 /// Hint expression of the 'hint' clause.
5993 Stmt *Hint = nullptr;
5995 /// Set hint expression.
5996 void setHint(Expr *H) { Hint = H; }
5999 /// Build 'hint' clause with expression \a Hint.
6001 /// \param Hint Hint expression.
6002 /// \param StartLoc Starting location of the clause.
6003 /// \param LParenLoc Location of '('.
6004 /// \param EndLoc Ending location of the clause.
6005 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
6006 SourceLocation EndLoc)
6007 : OMPClause(llvm::omp::OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
6010 /// Build an empty clause.
6012 : OMPClause(llvm::omp::OMPC_hint, SourceLocation(), SourceLocation()) {}
6014 /// Sets the location of '('.
6015 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
6017 /// Returns the location of '('.
6018 SourceLocation getLParenLoc() const { return LParenLoc; }
6020 /// Returns number of threads.
6021 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
6023 child_range children() { return child_range(&Hint, &Hint + 1); }
6025 const_child_range children() const {
6026 return const_child_range(&Hint, &Hint + 1);
6029 child_range used_children() {
6030 return child_range(child_iterator(), child_iterator());
6032 const_child_range used_children() const {
6033 return const_child_range(const_child_iterator(), const_child_iterator());
6036 static bool classof(const OMPClause *T) {
6037 return T->getClauseKind() == llvm::omp::OMPC_hint;
6041 /// This represents 'dist_schedule' clause in the '#pragma omp ...'
6045 /// #pragma omp distribute dist_schedule(static, 3)
6047 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
6048 /// clause with arguments 'static' and '3'.
6049 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
6050 friend class OMPClauseReader;
6052 /// Location of '('.
6053 SourceLocation LParenLoc;
6055 /// A kind of the 'schedule' clause.
6056 OpenMPDistScheduleClauseKind Kind = OMPC_DIST_SCHEDULE_unknown;
6058 /// Start location of the schedule kind in source code.
6059 SourceLocation KindLoc;
6061 /// Location of ',' (if any).
6062 SourceLocation CommaLoc;
6065 Expr *ChunkSize = nullptr;
6067 /// Set schedule kind.
6069 /// \param K Schedule kind.
6070 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
6072 /// Sets the location of '('.
6074 /// \param Loc Location of '('.
6075 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
6077 /// Set schedule kind start location.
6079 /// \param KLoc Schedule kind location.
6080 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
6082 /// Set location of ','.
6084 /// \param Loc Location of ','.
6085 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
6089 /// \param E Chunk size.
6090 void setChunkSize(Expr *E) { ChunkSize = E; }
6093 /// Build 'dist_schedule' clause with schedule kind \a Kind and chunk
6094 /// size expression \a ChunkSize.
6096 /// \param StartLoc Starting location of the clause.
6097 /// \param LParenLoc Location of '('.
6098 /// \param KLoc Starting location of the argument.
6099 /// \param CommaLoc Location of ','.
6100 /// \param EndLoc Ending location of the clause.
6101 /// \param Kind DistSchedule kind.
6102 /// \param ChunkSize Chunk size.
6103 /// \param HelperChunkSize Helper chunk size for combined directives.
6104 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
6105 SourceLocation KLoc, SourceLocation CommaLoc,
6106 SourceLocation EndLoc,
6107 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
6108 Stmt *HelperChunkSize)
6109 : OMPClause(llvm::omp::OMPC_dist_schedule, StartLoc, EndLoc),
6110 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
6111 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
6112 setPreInitStmt(HelperChunkSize);
6115 /// Build an empty clause.
6116 explicit OMPDistScheduleClause()
6117 : OMPClause(llvm::omp::OMPC_dist_schedule, SourceLocation(),
6119 OMPClauseWithPreInit(this) {}
6121 /// Get kind of the clause.
6122 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
6124 /// Get location of '('.
6125 SourceLocation getLParenLoc() { return LParenLoc; }
6127 /// Get kind location.
6128 SourceLocation getDistScheduleKindLoc() { return KindLoc; }
6130 /// Get location of ','.
6131 SourceLocation getCommaLoc() { return CommaLoc; }
6134 Expr *getChunkSize() { return ChunkSize; }
6137 const Expr *getChunkSize() const { return ChunkSize; }
6139 child_range children() {
6140 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
6141 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
6144 const_child_range children() const {
6145 auto Children = const_cast<OMPDistScheduleClause *>(this)->children();
6146 return const_child_range(Children.begin(), Children.end());
6149 child_range used_children() {
6150 return child_range(child_iterator(), child_iterator());
6152 const_child_range used_children() const {
6153 return const_child_range(const_child_iterator(), const_child_iterator());
6156 static bool classof(const OMPClause *T) {
6157 return T->getClauseKind() == llvm::omp::OMPC_dist_schedule;
6161 /// This represents 'defaultmap' clause in the '#pragma omp ...' directive.
6164 /// #pragma omp target defaultmap(tofrom: scalar)
6166 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
6167 /// 'scalar' with modifier 'tofrom'.
6168 class OMPDefaultmapClause : public OMPClause {
6169 friend class OMPClauseReader;
6171 /// Location of '('.
6172 SourceLocation LParenLoc;
6174 /// Modifiers for 'defaultmap' clause.
6175 OpenMPDefaultmapClauseModifier Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown;
6177 /// Locations of modifiers.
6178 SourceLocation ModifierLoc;
6180 /// A kind of the 'defaultmap' clause.
6181 OpenMPDefaultmapClauseKind Kind = OMPC_DEFAULTMAP_unknown;
6183 /// Start location of the defaultmap kind in source code.
6184 SourceLocation KindLoc;
6186 /// Set defaultmap kind.
6188 /// \param K Defaultmap kind.
6189 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
6191 /// Set the defaultmap modifier.
6193 /// \param M Defaultmap modifier.
6194 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
6198 /// Set location of the defaultmap modifier.
6199 void setDefaultmapModifierLoc(SourceLocation Loc) {
6203 /// Sets the location of '('.
6205 /// \param Loc Location of '('.
6206 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
6208 /// Set defaultmap kind start location.
6210 /// \param KLoc Defaultmap kind location.
6211 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
6214 /// Build 'defaultmap' clause with defaultmap kind \a Kind
6216 /// \param StartLoc Starting location of the clause.
6217 /// \param LParenLoc Location of '('.
6218 /// \param KLoc Starting location of the argument.
6219 /// \param EndLoc Ending location of the clause.
6220 /// \param Kind Defaultmap kind.
6221 /// \param M The modifier applied to 'defaultmap' clause.
6222 /// \param MLoc Location of the modifier
6223 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
6224 SourceLocation MLoc, SourceLocation KLoc,
6225 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
6226 OpenMPDefaultmapClauseModifier M)
6227 : OMPClause(llvm::omp::OMPC_defaultmap, StartLoc, EndLoc),
6228 LParenLoc(LParenLoc), Modifier(M), ModifierLoc(MLoc), Kind(Kind),
6231 /// Build an empty clause.
6232 explicit OMPDefaultmapClause()
6233 : OMPClause(llvm::omp::OMPC_defaultmap, SourceLocation(),
6234 SourceLocation()) {}
6236 /// Get kind of the clause.
6237 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
6239 /// Get the modifier of the clause.
6240 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
6244 /// Get location of '('.
6245 SourceLocation getLParenLoc() { return LParenLoc; }
6247 /// Get kind location.
6248 SourceLocation getDefaultmapKindLoc() { return KindLoc; }
6250 /// Get the modifier location.
6251 SourceLocation getDefaultmapModifierLoc() const {
6255 child_range children() {
6256 return child_range(child_iterator(), child_iterator());
6259 const_child_range children() const {
6260 return const_child_range(const_child_iterator(), const_child_iterator());
6263 child_range used_children() {
6264 return child_range(child_iterator(), child_iterator());
6266 const_child_range used_children() const {
6267 return const_child_range(const_child_iterator(), const_child_iterator());
6270 static bool classof(const OMPClause *T) {
6271 return T->getClauseKind() == llvm::omp::OMPC_defaultmap;
6275 /// This represents clause 'to' in the '#pragma omp ...'
6279 /// #pragma omp target update to(a,b)
6281 /// In this example directive '#pragma omp target update' has clause 'to'
6282 /// with the variables 'a' and 'b'.
6283 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
6284 private llvm::TrailingObjects<
6285 OMPToClause, Expr *, ValueDecl *, unsigned,
6286 OMPClauseMappableExprCommon::MappableComponent> {
6287 friend class OMPClauseReader;
6288 friend OMPMappableExprListClause;
6289 friend OMPVarListClause;
6290 friend TrailingObjects;
6292 /// Build clause with number of variables \a NumVars.
6294 /// \param MapperQualifierLoc C++ nested name specifier for the associated
6295 /// user-defined mapper.
6296 /// \param MapperIdInfo The identifier of associated user-defined mapper.
6297 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6298 /// StartLoc: starting location of the clause (the clause keyword); 2)
6299 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6300 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6301 /// NumVars: number of expressions listed in this clause; 2)
6302 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6303 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6304 /// NumComponents: total number of expression components in the clause.
6305 explicit OMPToClause(NestedNameSpecifierLoc MapperQualifierLoc,
6306 DeclarationNameInfo MapperIdInfo,
6307 const OMPVarListLocTy &Locs,
6308 const OMPMappableExprListSizeTy &Sizes)
6309 : OMPMappableExprListClause(llvm::omp::OMPC_to, Locs, Sizes,
6310 &MapperQualifierLoc, &MapperIdInfo) {}
6312 /// Build an empty clause.
6314 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6315 /// NumVars: number of expressions listed in this clause; 2)
6316 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6317 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6318 /// NumComponents: total number of expression components in the clause.
6319 explicit OMPToClause(const OMPMappableExprListSizeTy &Sizes)
6320 : OMPMappableExprListClause(llvm::omp::OMPC_to, OMPVarListLocTy(),
6323 /// Define the sizes of each trailing object array except the last one. This
6324 /// is required for TrailingObjects to work properly.
6325 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6326 // There are varlist_size() of expressions, and varlist_size() of
6327 // user-defined mappers.
6328 return 2 * varlist_size();
6330 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6331 return getUniqueDeclarationsNum();
6333 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6334 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6338 /// Creates clause with a list of variables \a Vars.
6340 /// \param C AST context.
6341 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6342 /// StartLoc: starting location of the clause (the clause keyword); 2)
6343 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6344 /// \param Vars The original expression used in the clause.
6345 /// \param Declarations Declarations used in the clause.
6346 /// \param ComponentLists Component lists used in the clause.
6347 /// \param UDMapperRefs References to user-defined mappers associated with
6348 /// expressions used in the clause.
6349 /// \param UDMQualifierLoc C++ nested name specifier for the associated
6350 /// user-defined mapper.
6351 /// \param MapperId The identifier of associated user-defined mapper.
6352 static OMPToClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6353 ArrayRef<Expr *> Vars,
6354 ArrayRef<ValueDecl *> Declarations,
6355 MappableExprComponentListsRef ComponentLists,
6356 ArrayRef<Expr *> UDMapperRefs,
6357 NestedNameSpecifierLoc UDMQualifierLoc,
6358 DeclarationNameInfo MapperId);
6360 /// Creates an empty clause with the place for \a NumVars variables.
6362 /// \param C AST context.
6363 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6364 /// NumVars: number of expressions listed in this clause; 2)
6365 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6366 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6367 /// NumComponents: total number of expression components in the clause.
6368 static OMPToClause *CreateEmpty(const ASTContext &C,
6369 const OMPMappableExprListSizeTy &Sizes);
6371 child_range children() {
6372 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6373 reinterpret_cast<Stmt **>(varlist_end()));
6376 const_child_range children() const {
6377 auto Children = const_cast<OMPToClause *>(this)->children();
6378 return const_child_range(Children.begin(), Children.end());
6381 child_range used_children() {
6382 return child_range(child_iterator(), child_iterator());
6384 const_child_range used_children() const {
6385 return const_child_range(const_child_iterator(), const_child_iterator());
6388 static bool classof(const OMPClause *T) {
6389 return T->getClauseKind() == llvm::omp::OMPC_to;
6393 /// This represents clause 'from' in the '#pragma omp ...'
6397 /// #pragma omp target update from(a,b)
6399 /// In this example directive '#pragma omp target update' has clause 'from'
6400 /// with the variables 'a' and 'b'.
6401 class OMPFromClause final
6402 : public OMPMappableExprListClause<OMPFromClause>,
6403 private llvm::TrailingObjects<
6404 OMPFromClause, Expr *, ValueDecl *, unsigned,
6405 OMPClauseMappableExprCommon::MappableComponent> {
6406 friend class OMPClauseReader;
6407 friend OMPMappableExprListClause;
6408 friend OMPVarListClause;
6409 friend TrailingObjects;
6411 /// Build clause with number of variables \a NumVars.
6413 /// \param MapperQualifierLoc C++ nested name specifier for the associated
6414 /// user-defined mapper.
6415 /// \param MapperIdInfo The identifier of associated user-defined mapper.
6416 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6417 /// StartLoc: starting location of the clause (the clause keyword); 2)
6418 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6419 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6420 /// NumVars: number of expressions listed in this clause; 2)
6421 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6422 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6423 /// NumComponents: total number of expression components in the clause.
6424 explicit OMPFromClause(NestedNameSpecifierLoc MapperQualifierLoc,
6425 DeclarationNameInfo MapperIdInfo,
6426 const OMPVarListLocTy &Locs,
6427 const OMPMappableExprListSizeTy &Sizes)
6428 : OMPMappableExprListClause(llvm::omp::OMPC_from, Locs, Sizes,
6429 &MapperQualifierLoc, &MapperIdInfo) {}
6431 /// Build an empty clause.
6433 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6434 /// NumVars: number of expressions listed in this clause; 2)
6435 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6436 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6437 /// NumComponents: total number of expression components in the clause.
6438 explicit OMPFromClause(const OMPMappableExprListSizeTy &Sizes)
6439 : OMPMappableExprListClause(llvm::omp::OMPC_from, OMPVarListLocTy(),
6442 /// Define the sizes of each trailing object array except the last one. This
6443 /// is required for TrailingObjects to work properly.
6444 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6445 // There are varlist_size() of expressions, and varlist_size() of
6446 // user-defined mappers.
6447 return 2 * varlist_size();
6449 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6450 return getUniqueDeclarationsNum();
6452 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6453 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6457 /// Creates clause with a list of variables \a Vars.
6459 /// \param C AST context.
6460 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6461 /// StartLoc: starting location of the clause (the clause keyword); 2)
6462 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6463 /// \param Vars The original expression used in the clause.
6464 /// \param Declarations Declarations used in the clause.
6465 /// \param ComponentLists Component lists used in the clause.
6466 /// \param UDMapperRefs References to user-defined mappers associated with
6467 /// expressions used in the clause.
6468 /// \param UDMQualifierLoc C++ nested name specifier for the associated
6469 /// user-defined mapper.
6470 /// \param MapperId The identifier of associated user-defined mapper.
6471 static OMPFromClause *Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6472 ArrayRef<Expr *> Vars,
6473 ArrayRef<ValueDecl *> Declarations,
6474 MappableExprComponentListsRef ComponentLists,
6475 ArrayRef<Expr *> UDMapperRefs,
6476 NestedNameSpecifierLoc UDMQualifierLoc,
6477 DeclarationNameInfo MapperId);
6479 /// Creates an empty clause with the place for \a NumVars variables.
6481 /// \param C AST context.
6482 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6483 /// NumVars: number of expressions listed in this clause; 2)
6484 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6485 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6486 /// NumComponents: total number of expression components in the clause.
6487 static OMPFromClause *CreateEmpty(const ASTContext &C,
6488 const OMPMappableExprListSizeTy &Sizes);
6490 child_range children() {
6491 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6492 reinterpret_cast<Stmt **>(varlist_end()));
6495 const_child_range children() const {
6496 auto Children = const_cast<OMPFromClause *>(this)->children();
6497 return const_child_range(Children.begin(), Children.end());
6500 child_range used_children() {
6501 return child_range(child_iterator(), child_iterator());
6503 const_child_range used_children() const {
6504 return const_child_range(const_child_iterator(), const_child_iterator());
6507 static bool classof(const OMPClause *T) {
6508 return T->getClauseKind() == llvm::omp::OMPC_from;
6512 /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
6516 /// #pragma omp target data use_device_ptr(a,b)
6518 /// In this example directive '#pragma omp target data' has clause
6519 /// 'use_device_ptr' with the variables 'a' and 'b'.
6520 class OMPUseDevicePtrClause final
6521 : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
6522 private llvm::TrailingObjects<
6523 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
6524 OMPClauseMappableExprCommon::MappableComponent> {
6525 friend class OMPClauseReader;
6526 friend OMPMappableExprListClause;
6527 friend OMPVarListClause;
6528 friend TrailingObjects;
6530 /// Build clause with number of variables \a NumVars.
6532 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6533 /// StartLoc: starting location of the clause (the clause keyword); 2)
6534 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6535 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6536 /// NumVars: number of expressions listed in this clause; 2)
6537 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6538 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6539 /// NumComponents: total number of expression components in the clause.
6540 explicit OMPUseDevicePtrClause(const OMPVarListLocTy &Locs,
6541 const OMPMappableExprListSizeTy &Sizes)
6542 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr, Locs, Sizes) {
6545 /// Build an empty clause.
6547 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6548 /// NumVars: number of expressions listed in this clause; 2)
6549 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6550 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6551 /// NumComponents: total number of expression components in the clause.
6552 explicit OMPUseDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
6553 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_ptr,
6554 OMPVarListLocTy(), Sizes) {}
6556 /// Define the sizes of each trailing object array except the last one. This
6557 /// is required for TrailingObjects to work properly.
6558 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6559 return 3 * varlist_size();
6561 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6562 return getUniqueDeclarationsNum();
6564 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6565 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6568 /// Sets the list of references to private copies with initializers for new
6569 /// private variables.
6570 /// \param VL List of references.
6571 void setPrivateCopies(ArrayRef<Expr *> VL);
6573 /// Gets the list of references to private copies with initializers for new
6574 /// private variables.
6575 MutableArrayRef<Expr *> getPrivateCopies() {
6576 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
6578 ArrayRef<const Expr *> getPrivateCopies() const {
6579 return llvm::makeArrayRef(varlist_end(), varlist_size());
6582 /// Sets the list of references to initializer variables for new private
6584 /// \param VL List of references.
6585 void setInits(ArrayRef<Expr *> VL);
6587 /// Gets the list of references to initializer variables for new private
6589 MutableArrayRef<Expr *> getInits() {
6590 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
6592 ArrayRef<const Expr *> getInits() const {
6593 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
6597 /// Creates clause with a list of variables \a Vars.
6599 /// \param C AST context.
6600 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6601 /// StartLoc: starting location of the clause (the clause keyword); 2)
6602 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6603 /// \param Vars The original expression used in the clause.
6604 /// \param PrivateVars Expressions referring to private copies.
6605 /// \param Inits Expressions referring to private copy initializers.
6606 /// \param Declarations Declarations used in the clause.
6607 /// \param ComponentLists Component lists used in the clause.
6608 static OMPUseDevicePtrClause *
6609 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6610 ArrayRef<Expr *> Vars, ArrayRef<Expr *> PrivateVars,
6611 ArrayRef<Expr *> Inits, ArrayRef<ValueDecl *> Declarations,
6612 MappableExprComponentListsRef ComponentLists);
6614 /// Creates an empty clause with the place for \a NumVars variables.
6616 /// \param C AST context.
6617 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6618 /// NumVars: number of expressions listed in this clause; 2)
6619 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6620 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6621 /// NumComponents: total number of expression components in the clause.
6622 static OMPUseDevicePtrClause *
6623 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
6625 using private_copies_iterator = MutableArrayRef<Expr *>::iterator;
6626 using private_copies_const_iterator = ArrayRef<const Expr *>::iterator;
6627 using private_copies_range = llvm::iterator_range<private_copies_iterator>;
6628 using private_copies_const_range =
6629 llvm::iterator_range<private_copies_const_iterator>;
6631 private_copies_range private_copies() {
6632 return private_copies_range(getPrivateCopies().begin(),
6633 getPrivateCopies().end());
6636 private_copies_const_range private_copies() const {
6637 return private_copies_const_range(getPrivateCopies().begin(),
6638 getPrivateCopies().end());
6641 using inits_iterator = MutableArrayRef<Expr *>::iterator;
6642 using inits_const_iterator = ArrayRef<const Expr *>::iterator;
6643 using inits_range = llvm::iterator_range<inits_iterator>;
6644 using inits_const_range = llvm::iterator_range<inits_const_iterator>;
6646 inits_range inits() {
6647 return inits_range(getInits().begin(), getInits().end());
6650 inits_const_range inits() const {
6651 return inits_const_range(getInits().begin(), getInits().end());
6654 child_range children() {
6655 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6656 reinterpret_cast<Stmt **>(varlist_end()));
6659 const_child_range children() const {
6660 auto Children = const_cast<OMPUseDevicePtrClause *>(this)->children();
6661 return const_child_range(Children.begin(), Children.end());
6664 child_range used_children() {
6665 return child_range(child_iterator(), child_iterator());
6667 const_child_range used_children() const {
6668 return const_child_range(const_child_iterator(), const_child_iterator());
6671 static bool classof(const OMPClause *T) {
6672 return T->getClauseKind() == llvm::omp::OMPC_use_device_ptr;
6676 /// This represents clause 'use_device_addr' in the '#pragma omp ...'
6680 /// #pragma omp target data use_device_addr(a,b)
6682 /// In this example directive '#pragma omp target data' has clause
6683 /// 'use_device_addr' with the variables 'a' and 'b'.
6684 class OMPUseDeviceAddrClause final
6685 : public OMPMappableExprListClause<OMPUseDeviceAddrClause>,
6686 private llvm::TrailingObjects<
6687 OMPUseDeviceAddrClause, Expr *, ValueDecl *, unsigned,
6688 OMPClauseMappableExprCommon::MappableComponent> {
6689 friend class OMPClauseReader;
6690 friend OMPMappableExprListClause;
6691 friend OMPVarListClause;
6692 friend TrailingObjects;
6694 /// Build clause with number of variables \a NumVars.
6696 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6697 /// StartLoc: starting location of the clause (the clause keyword); 2)
6698 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6699 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6700 /// NumVars: number of expressions listed in this clause; 2)
6701 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6702 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6703 /// NumComponents: total number of expression components in the clause.
6704 explicit OMPUseDeviceAddrClause(const OMPVarListLocTy &Locs,
6705 const OMPMappableExprListSizeTy &Sizes)
6706 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr, Locs,
6709 /// Build an empty clause.
6711 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6712 /// NumVars: number of expressions listed in this clause; 2)
6713 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6714 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6715 /// NumComponents: total number of expression components in the clause.
6716 explicit OMPUseDeviceAddrClause(const OMPMappableExprListSizeTy &Sizes)
6717 : OMPMappableExprListClause(llvm::omp::OMPC_use_device_addr,
6718 OMPVarListLocTy(), Sizes) {}
6720 /// Define the sizes of each trailing object array except the last one. This
6721 /// is required for TrailingObjects to work properly.
6722 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6723 return varlist_size();
6725 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6726 return getUniqueDeclarationsNum();
6728 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6729 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6733 /// Creates clause with a list of variables \a Vars.
6735 /// \param C AST context.
6736 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6737 /// StartLoc: starting location of the clause (the clause keyword); 2)
6738 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6739 /// \param Vars The original expression used in the clause.
6740 /// \param Declarations Declarations used in the clause.
6741 /// \param ComponentLists Component lists used in the clause.
6742 static OMPUseDeviceAddrClause *
6743 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6744 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
6745 MappableExprComponentListsRef ComponentLists);
6747 /// Creates an empty clause with the place for \a NumVars variables.
6749 /// \param C AST context.
6750 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6751 /// NumVars: number of expressions listed in this clause; 2)
6752 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6753 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6754 /// NumComponents: total number of expression components in the clause.
6755 static OMPUseDeviceAddrClause *
6756 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
6758 child_range children() {
6759 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6760 reinterpret_cast<Stmt **>(varlist_end()));
6763 const_child_range children() const {
6764 auto Children = const_cast<OMPUseDeviceAddrClause *>(this)->children();
6765 return const_child_range(Children.begin(), Children.end());
6768 child_range used_children() {
6769 return child_range(child_iterator(), child_iterator());
6771 const_child_range used_children() const {
6772 return const_child_range(const_child_iterator(), const_child_iterator());
6775 static bool classof(const OMPClause *T) {
6776 return T->getClauseKind() == llvm::omp::OMPC_use_device_addr;
6780 /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
6784 /// #pragma omp target is_device_ptr(a,b)
6786 /// In this example directive '#pragma omp target' has clause
6787 /// 'is_device_ptr' with the variables 'a' and 'b'.
6788 class OMPIsDevicePtrClause final
6789 : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
6790 private llvm::TrailingObjects<
6791 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
6792 OMPClauseMappableExprCommon::MappableComponent> {
6793 friend class OMPClauseReader;
6794 friend OMPMappableExprListClause;
6795 friend OMPVarListClause;
6796 friend TrailingObjects;
6798 /// Build clause with number of variables \a NumVars.
6800 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6801 /// StartLoc: starting location of the clause (the clause keyword); 2)
6802 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6803 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6804 /// NumVars: number of expressions listed in this clause; 2)
6805 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6806 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6807 /// NumComponents: total number of expression components in the clause.
6808 explicit OMPIsDevicePtrClause(const OMPVarListLocTy &Locs,
6809 const OMPMappableExprListSizeTy &Sizes)
6810 : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr, Locs, Sizes) {}
6812 /// Build an empty clause.
6814 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6815 /// NumVars: number of expressions listed in this clause; 2)
6816 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6817 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6818 /// NumComponents: total number of expression components in the clause.
6819 explicit OMPIsDevicePtrClause(const OMPMappableExprListSizeTy &Sizes)
6820 : OMPMappableExprListClause(llvm::omp::OMPC_is_device_ptr,
6821 OMPVarListLocTy(), Sizes) {}
6823 /// Define the sizes of each trailing object array except the last one. This
6824 /// is required for TrailingObjects to work properly.
6825 size_t numTrailingObjects(OverloadToken<Expr *>) const {
6826 return varlist_size();
6828 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
6829 return getUniqueDeclarationsNum();
6831 size_t numTrailingObjects(OverloadToken<unsigned>) const {
6832 return getUniqueDeclarationsNum() + getTotalComponentListNum();
6836 /// Creates clause with a list of variables \a Vars.
6838 /// \param C AST context.
6839 /// \param Locs Locations needed to build a mappable clause. It includes 1)
6840 /// StartLoc: starting location of the clause (the clause keyword); 2)
6841 /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
6842 /// \param Vars The original expression used in the clause.
6843 /// \param Declarations Declarations used in the clause.
6844 /// \param ComponentLists Component lists used in the clause.
6845 static OMPIsDevicePtrClause *
6846 Create(const ASTContext &C, const OMPVarListLocTy &Locs,
6847 ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
6848 MappableExprComponentListsRef ComponentLists);
6850 /// Creates an empty clause with the place for \a NumVars variables.
6852 /// \param C AST context.
6853 /// \param Sizes All required sizes to build a mappable clause. It includes 1)
6854 /// NumVars: number of expressions listed in this clause; 2)
6855 /// NumUniqueDeclarations: number of unique base declarations in this clause;
6856 /// 3) NumComponentLists: number of component lists in this clause; and 4)
6857 /// NumComponents: total number of expression components in the clause.
6858 static OMPIsDevicePtrClause *
6859 CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
6861 child_range children() {
6862 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6863 reinterpret_cast<Stmt **>(varlist_end()));
6866 const_child_range children() const {
6867 auto Children = const_cast<OMPIsDevicePtrClause *>(this)->children();
6868 return const_child_range(Children.begin(), Children.end());
6871 child_range used_children() {
6872 return child_range(child_iterator(), child_iterator());
6874 const_child_range used_children() const {
6875 return const_child_range(const_child_iterator(), const_child_iterator());
6878 static bool classof(const OMPClause *T) {
6879 return T->getClauseKind() == llvm::omp::OMPC_is_device_ptr;
6883 /// This represents clause 'nontemporal' in the '#pragma omp ...' directives.
6886 /// #pragma omp simd nontemporal(a)
6888 /// In this example directive '#pragma omp simd' has clause 'nontemporal' for
6889 /// the variable 'a'.
6890 class OMPNontemporalClause final
6891 : public OMPVarListClause<OMPNontemporalClause>,
6892 private llvm::TrailingObjects<OMPNontemporalClause, Expr *> {
6893 friend class OMPClauseReader;
6894 friend OMPVarListClause;
6895 friend TrailingObjects;
6897 /// Build clause with number of variables \a N.
6899 /// \param StartLoc Starting location of the clause.
6900 /// \param LParenLoc Location of '('.
6901 /// \param EndLoc Ending location of the clause.
6902 /// \param N Number of the variables in the clause.
6903 OMPNontemporalClause(SourceLocation StartLoc, SourceLocation LParenLoc,
6904 SourceLocation EndLoc, unsigned N)
6905 : OMPVarListClause<OMPNontemporalClause>(llvm::omp::OMPC_nontemporal,
6906 StartLoc, LParenLoc, EndLoc, N) {
6909 /// Build an empty clause.
6911 /// \param N Number of variables.
6912 explicit OMPNontemporalClause(unsigned N)
6913 : OMPVarListClause<OMPNontemporalClause>(
6914 llvm::omp::OMPC_nontemporal, SourceLocation(), SourceLocation(),
6915 SourceLocation(), N) {}
6917 /// Get the list of privatied copies if the member expression was captured by
6918 /// one of the privatization clauses.
6919 MutableArrayRef<Expr *> getPrivateRefs() {
6920 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
6922 ArrayRef<const Expr *> getPrivateRefs() const {
6923 return llvm::makeArrayRef(varlist_end(), varlist_size());
6927 /// Creates clause with a list of variables \a VL.
6929 /// \param C AST context.
6930 /// \param StartLoc Starting location of the clause.
6931 /// \param LParenLoc Location of '('.
6932 /// \param EndLoc Ending location of the clause.
6933 /// \param VL List of references to the variables.
6934 static OMPNontemporalClause *
6935 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
6936 SourceLocation EndLoc, ArrayRef<Expr *> VL);
6938 /// Creates an empty clause with the place for \a N variables.
6940 /// \param C AST context.
6941 /// \param N The number of variables.
6942 static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N);
6944 /// Sets the list of references to private copies created in private clauses.
6945 /// \param VL List of references.
6946 void setPrivateRefs(ArrayRef<Expr *> VL);
6948 child_range children() {
6949 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
6950 reinterpret_cast<Stmt **>(varlist_end()));
6953 const_child_range children() const {
6954 auto Children = const_cast<OMPNontemporalClause *>(this)->children();
6955 return const_child_range(Children.begin(), Children.end());
6958 child_range private_refs() {
6959 return child_range(reinterpret_cast<Stmt **>(getPrivateRefs().begin()),
6960 reinterpret_cast<Stmt **>(getPrivateRefs().end()));
6963 const_child_range private_refs() const {
6964 auto Children = const_cast<OMPNontemporalClause *>(this)->private_refs();
6965 return const_child_range(Children.begin(), Children.end());
6968 child_range used_children() {
6969 return child_range(child_iterator(), child_iterator());
6971 const_child_range used_children() const {
6972 return const_child_range(const_child_iterator(), const_child_iterator());
6975 static bool classof(const OMPClause *T) {
6976 return T->getClauseKind() == llvm::omp::OMPC_nontemporal;
6980 /// This represents 'order' clause in the '#pragma omp ...' directive.
6983 /// #pragma omp simd order(concurrent)
6985 /// In this example directive '#pragma omp parallel' has simple 'order'
6986 /// clause with kind 'concurrent'.
6987 class OMPOrderClause final : public OMPClause {
6988 friend class OMPClauseReader;
6990 /// Location of '('.
6991 SourceLocation LParenLoc;
6993 /// A kind of the 'default' clause.
6994 OpenMPOrderClauseKind Kind = OMPC_ORDER_unknown;
6996 /// Start location of the kind in source code.
6997 SourceLocation KindKwLoc;
6999 /// Set kind of the clause.
7001 /// \param K Argument of clause.
7002 void setKind(OpenMPOrderClauseKind K) { Kind = K; }
7004 /// Set argument location.
7006 /// \param KLoc Argument location.
7007 void setKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
7010 /// Build 'order' clause with argument \p A ('concurrent').
7012 /// \param A Argument of the clause ('concurrent').
7013 /// \param ALoc Starting location of the argument.
7014 /// \param StartLoc Starting location of the clause.
7015 /// \param LParenLoc Location of '('.
7016 /// \param EndLoc Ending location of the clause.
7017 OMPOrderClause(OpenMPOrderClauseKind A, SourceLocation ALoc,
7018 SourceLocation StartLoc, SourceLocation LParenLoc,
7019 SourceLocation EndLoc)
7020 : OMPClause(llvm::omp::OMPC_order, StartLoc, EndLoc),
7021 LParenLoc(LParenLoc), Kind(A), KindKwLoc(ALoc) {}
7023 /// Build an empty clause.
7025 : OMPClause(llvm::omp::OMPC_order, SourceLocation(), SourceLocation()) {}
7027 /// Sets the location of '('.
7028 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7030 /// Returns the location of '('.
7031 SourceLocation getLParenLoc() const { return LParenLoc; }
7033 /// Returns kind of the clause.
7034 OpenMPOrderClauseKind getKind() const { return Kind; }
7036 /// Returns location of clause kind.
7037 SourceLocation getKindKwLoc() const { return KindKwLoc; }
7039 child_range children() {
7040 return child_range(child_iterator(), child_iterator());
7043 const_child_range children() const {
7044 return const_child_range(const_child_iterator(), const_child_iterator());
7047 child_range used_children() {
7048 return child_range(child_iterator(), child_iterator());
7050 const_child_range used_children() const {
7051 return const_child_range(const_child_iterator(), const_child_iterator());
7054 static bool classof(const OMPClause *T) {
7055 return T->getClauseKind() == llvm::omp::OMPC_order;
7059 /// This represents 'destroy' clause in the '#pragma omp depobj'
7063 /// #pragma omp depobj(a) destroy
7065 /// In this example directive '#pragma omp depobj' has 'destroy' clause.
7066 class OMPDestroyClause final : public OMPClause {
7068 /// Build 'destroy' clause.
7070 /// \param StartLoc Starting location of the clause.
7071 /// \param EndLoc Ending location of the clause.
7072 OMPDestroyClause(SourceLocation StartLoc, SourceLocation EndLoc)
7073 : OMPClause(llvm::omp::OMPC_destroy, StartLoc, EndLoc) {}
7075 /// Build an empty clause.
7077 : OMPClause(llvm::omp::OMPC_destroy, SourceLocation(), SourceLocation()) {
7080 child_range children() {
7081 return child_range(child_iterator(), child_iterator());
7084 const_child_range children() const {
7085 return const_child_range(const_child_iterator(), const_child_iterator());
7088 child_range used_children() {
7089 return child_range(child_iterator(), child_iterator());
7091 const_child_range used_children() const {
7092 return const_child_range(const_child_iterator(), const_child_iterator());
7095 static bool classof(const OMPClause *T) {
7096 return T->getClauseKind() == llvm::omp::OMPC_destroy;
7100 /// This represents 'detach' clause in the '#pragma omp task' directive.
7103 /// #pragma omp task detach(evt)
7105 /// In this example directive '#pragma omp detach' has simple 'detach' clause
7106 /// with the variable 'evt'.
7107 class OMPDetachClause final : public OMPClause {
7108 friend class OMPClauseReader;
7110 /// Location of '('.
7111 SourceLocation LParenLoc;
7113 /// Expression of the 'detach' clause.
7114 Stmt *Evt = nullptr;
7117 void setEventHandler(Expr *E) { Evt = E; }
7119 /// Sets the location of '('.
7120 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7123 /// Build 'detach' clause with event-handler \a Evt.
7125 /// \param Evt Event handler expression.
7126 /// \param StartLoc Starting location of the clause.
7127 /// \param LParenLoc Location of '('.
7128 /// \param EndLoc Ending location of the clause.
7129 OMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc,
7130 SourceLocation EndLoc)
7131 : OMPClause(llvm::omp::OMPC_detach, StartLoc, EndLoc),
7132 LParenLoc(LParenLoc), Evt(Evt) {}
7134 /// Build an empty clause.
7136 : OMPClause(llvm::omp::OMPC_detach, SourceLocation(), SourceLocation()) {}
7138 /// Returns the location of '('.
7139 SourceLocation getLParenLoc() const { return LParenLoc; }
7141 /// Returns event-handler expression.
7142 Expr *getEventHandler() const { return cast_or_null<Expr>(Evt); }
7144 child_range children() { return child_range(&Evt, &Evt + 1); }
7146 const_child_range children() const {
7147 return const_child_range(&Evt, &Evt + 1);
7150 child_range used_children() {
7151 return child_range(child_iterator(), child_iterator());
7153 const_child_range used_children() const {
7154 return const_child_range(const_child_iterator(), const_child_iterator());
7157 static bool classof(const OMPClause *T) {
7158 return T->getClauseKind() == llvm::omp::OMPC_detach;
7162 /// This represents clause 'inclusive' in the '#pragma omp scan' directive.
7165 /// #pragma omp scan inclusive(a,b)
7167 /// In this example directive '#pragma omp scan' has clause 'inclusive'
7168 /// with the variables 'a' and 'b'.
7169 class OMPInclusiveClause final
7170 : public OMPVarListClause<OMPInclusiveClause>,
7171 private llvm::TrailingObjects<OMPInclusiveClause, Expr *> {
7172 friend class OMPClauseReader;
7173 friend OMPVarListClause;
7174 friend TrailingObjects;
7176 /// Build clause with number of variables \a N.
7178 /// \param StartLoc Starting location of the clause.
7179 /// \param LParenLoc Location of '('.
7180 /// \param EndLoc Ending location of the clause.
7181 /// \param N Number of the variables in the clause.
7182 OMPInclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7183 SourceLocation EndLoc, unsigned N)
7184 : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
7185 StartLoc, LParenLoc, EndLoc, N) {}
7187 /// Build an empty clause.
7189 /// \param N Number of variables.
7190 explicit OMPInclusiveClause(unsigned N)
7191 : OMPVarListClause<OMPInclusiveClause>(llvm::omp::OMPC_inclusive,
7192 SourceLocation(), SourceLocation(),
7193 SourceLocation(), N) {}
7196 /// Creates clause with a list of variables \a VL.
7198 /// \param C AST context.
7199 /// \param StartLoc Starting location of the clause.
7200 /// \param LParenLoc Location of '('.
7201 /// \param EndLoc Ending location of the clause.
7202 /// \param VL List of references to the original variables.
7203 static OMPInclusiveClause *Create(const ASTContext &C,
7204 SourceLocation StartLoc,
7205 SourceLocation LParenLoc,
7206 SourceLocation EndLoc, ArrayRef<Expr *> VL);
7208 /// Creates an empty clause with the place for \a N variables.
7210 /// \param C AST context.
7211 /// \param N The number of variables.
7212 static OMPInclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
7214 child_range children() {
7215 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7216 reinterpret_cast<Stmt **>(varlist_end()));
7219 const_child_range children() const {
7220 auto Children = const_cast<OMPInclusiveClause *>(this)->children();
7221 return const_child_range(Children.begin(), Children.end());
7224 child_range used_children() {
7225 return child_range(child_iterator(), child_iterator());
7227 const_child_range used_children() const {
7228 return const_child_range(const_child_iterator(), const_child_iterator());
7231 static bool classof(const OMPClause *T) {
7232 return T->getClauseKind() == llvm::omp::OMPC_inclusive;
7236 /// This represents clause 'exclusive' in the '#pragma omp scan' directive.
7239 /// #pragma omp scan exclusive(a,b)
7241 /// In this example directive '#pragma omp scan' has clause 'exclusive'
7242 /// with the variables 'a' and 'b'.
7243 class OMPExclusiveClause final
7244 : public OMPVarListClause<OMPExclusiveClause>,
7245 private llvm::TrailingObjects<OMPExclusiveClause, Expr *> {
7246 friend class OMPClauseReader;
7247 friend OMPVarListClause;
7248 friend TrailingObjects;
7250 /// Build clause with number of variables \a N.
7252 /// \param StartLoc Starting location of the clause.
7253 /// \param LParenLoc Location of '('.
7254 /// \param EndLoc Ending location of the clause.
7255 /// \param N Number of the variables in the clause.
7256 OMPExclusiveClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7257 SourceLocation EndLoc, unsigned N)
7258 : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
7259 StartLoc, LParenLoc, EndLoc, N) {}
7261 /// Build an empty clause.
7263 /// \param N Number of variables.
7264 explicit OMPExclusiveClause(unsigned N)
7265 : OMPVarListClause<OMPExclusiveClause>(llvm::omp::OMPC_exclusive,
7266 SourceLocation(), SourceLocation(),
7267 SourceLocation(), N) {}
7270 /// Creates clause with a list of variables \a VL.
7272 /// \param C AST context.
7273 /// \param StartLoc Starting location of the clause.
7274 /// \param LParenLoc Location of '('.
7275 /// \param EndLoc Ending location of the clause.
7276 /// \param VL List of references to the original variables.
7277 static OMPExclusiveClause *Create(const ASTContext &C,
7278 SourceLocation StartLoc,
7279 SourceLocation LParenLoc,
7280 SourceLocation EndLoc, ArrayRef<Expr *> VL);
7282 /// Creates an empty clause with the place for \a N variables.
7284 /// \param C AST context.
7285 /// \param N The number of variables.
7286 static OMPExclusiveClause *CreateEmpty(const ASTContext &C, unsigned N);
7288 child_range children() {
7289 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7290 reinterpret_cast<Stmt **>(varlist_end()));
7293 const_child_range children() const {
7294 auto Children = const_cast<OMPExclusiveClause *>(this)->children();
7295 return const_child_range(Children.begin(), Children.end());
7298 child_range used_children() {
7299 return child_range(child_iterator(), child_iterator());
7301 const_child_range used_children() const {
7302 return const_child_range(const_child_iterator(), const_child_iterator());
7305 static bool classof(const OMPClause *T) {
7306 return T->getClauseKind() == llvm::omp::OMPC_exclusive;
7310 /// This represents clause 'uses_allocators' in the '#pragma omp target'-based
7314 /// #pragma omp target uses_allocators(default_allocator, my_allocator(traits))
7316 /// In this example directive '#pragma omp target' has clause 'uses_allocators'
7317 /// with the allocators 'default_allocator' and user-defined 'my_allocator'.
7318 class OMPUsesAllocatorsClause final
7320 private llvm::TrailingObjects<OMPUsesAllocatorsClause, Expr *,
7323 /// Data for list of allocators.
7326 Expr *Allocator = nullptr;
7327 /// Allocator traits.
7328 Expr *AllocatorTraits = nullptr;
7329 /// Locations of '(' and ')' symbols.
7330 SourceLocation LParenLoc, RParenLoc;
7334 friend class OMPClauseReader;
7335 friend TrailingObjects;
7337 enum class ExprOffsets {
7343 enum class ParenLocsOffsets {
7349 /// Location of '('.
7350 SourceLocation LParenLoc;
7351 /// Total number of allocators in the clause.
7352 unsigned NumOfAllocators = 0;
7356 /// \param StartLoc Starting location of the clause.
7357 /// \param LParenLoc Location of '('.
7358 /// \param EndLoc Ending location of the clause.
7359 /// \param N Number of allocators asssociated with the clause.
7360 OMPUsesAllocatorsClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7361 SourceLocation EndLoc, unsigned N)
7362 : OMPClause(llvm::omp::OMPC_uses_allocators, StartLoc, EndLoc),
7363 LParenLoc(LParenLoc), NumOfAllocators(N) {}
7365 /// Build an empty clause.
7366 /// \param N Number of allocators asssociated with the clause.
7368 explicit OMPUsesAllocatorsClause(unsigned N)
7369 : OMPClause(llvm::omp::OMPC_uses_allocators, SourceLocation(),
7371 NumOfAllocators(N) {}
7373 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
7374 return NumOfAllocators * static_cast<int>(ExprOffsets::Total);
7377 /// Sets the location of '('.
7378 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
7380 /// Sets the allocators data for the clause.
7381 void setAllocatorsData(ArrayRef<OMPUsesAllocatorsClause::Data> Data);
7384 /// Creates clause with a list of allocators \p Data.
7386 /// \param C AST context.
7387 /// \param StartLoc Starting location of the clause.
7388 /// \param LParenLoc Location of '('.
7389 /// \param EndLoc Ending location of the clause.
7390 /// \param Data List of allocators.
7391 static OMPUsesAllocatorsClause *
7392 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
7393 SourceLocation EndLoc, ArrayRef<OMPUsesAllocatorsClause::Data> Data);
7395 /// Creates an empty clause with the place for \p N allocators.
7397 /// \param C AST context.
7398 /// \param N The number of allocators.
7399 static OMPUsesAllocatorsClause *CreateEmpty(const ASTContext &C, unsigned N);
7401 /// Returns the location of '('.
7402 SourceLocation getLParenLoc() const { return LParenLoc; }
7404 /// Returns number of allocators associated with the clause.
7405 unsigned getNumberOfAllocators() const { return NumOfAllocators; }
7407 /// Returns data for the specified allocator.
7408 OMPUsesAllocatorsClause::Data getAllocatorData(unsigned I) const;
7411 child_range children() {
7412 Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
7413 return child_range(Begin, Begin + NumOfAllocators *
7414 static_cast<int>(ExprOffsets::Total));
7416 const_child_range children() const {
7417 Stmt *const *Begin =
7418 reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>());
7419 return const_child_range(
7420 Begin, Begin + NumOfAllocators * static_cast<int>(ExprOffsets::Total));
7423 child_range used_children() {
7424 return child_range(child_iterator(), child_iterator());
7426 const_child_range used_children() const {
7427 return const_child_range(const_child_iterator(), const_child_iterator());
7430 static bool classof(const OMPClause *T) {
7431 return T->getClauseKind() == llvm::omp::OMPC_uses_allocators;
7435 /// This represents clause 'affinity' in the '#pragma omp task'-based
7439 /// #pragma omp task affinity(iterator(i = 0:n) : ([3][n])a, b[:n], c[i])
7441 /// In this example directive '#pragma omp task' has clause 'affinity' with the
7442 /// affinity modifer 'iterator(i = 0:n)' and locator items '([3][n])a', 'b[:n]'
7444 class OMPAffinityClause final
7445 : public OMPVarListClause<OMPAffinityClause>,
7446 private llvm::TrailingObjects<OMPAffinityClause, Expr *> {
7447 friend class OMPClauseReader;
7448 friend OMPVarListClause;
7449 friend TrailingObjects;
7451 /// Location of ':' symbol.
7452 SourceLocation ColonLoc;
7456 /// \param StartLoc Starting location of the clause.
7457 /// \param LParenLoc Location of '('.
7458 /// \param ColonLoc Location of ':'.
7459 /// \param EndLoc Ending location of the clause.
7460 /// \param N Number of locators asssociated with the clause.
7461 OMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc,
7462 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N)
7463 : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity, StartLoc,
7464 LParenLoc, EndLoc, N) {}
7466 /// Build an empty clause.
7467 /// \param N Number of locators asssociated with the clause.
7469 explicit OMPAffinityClause(unsigned N)
7470 : OMPVarListClause<OMPAffinityClause>(llvm::omp::OMPC_affinity,
7471 SourceLocation(), SourceLocation(),
7472 SourceLocation(), N) {}
7474 /// Sets the affinity modifier for the clause, if any.
7475 void setModifier(Expr *E) {
7476 getTrailingObjects<Expr *>()[varlist_size()] = E;
7479 /// Sets the location of ':' symbol.
7480 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
7483 /// Creates clause with a modifier a list of locator items.
7485 /// \param C AST context.
7486 /// \param StartLoc Starting location of the clause.
7487 /// \param LParenLoc Location of '('.
7488 /// \param ColonLoc Location of ':'.
7489 /// \param EndLoc Ending location of the clause.
7490 /// \param Locators List of locator items.
7491 static OMPAffinityClause *Create(const ASTContext &C, SourceLocation StartLoc,
7492 SourceLocation LParenLoc,
7493 SourceLocation ColonLoc,
7494 SourceLocation EndLoc, Expr *Modifier,
7495 ArrayRef<Expr *> Locators);
7497 /// Creates an empty clause with the place for \p N locator items.
7499 /// \param C AST context.
7500 /// \param N The number of locator items.
7501 static OMPAffinityClause *CreateEmpty(const ASTContext &C, unsigned N);
7503 /// Gets affinity modifier.
7504 Expr *getModifier() { return getTrailingObjects<Expr *>()[varlist_size()]; }
7505 Expr *getModifier() const {
7506 return getTrailingObjects<Expr *>()[varlist_size()];
7509 /// Gets the location of ':' symbol.
7510 SourceLocation getColonLoc() const { return ColonLoc; }
7513 child_range children() {
7514 int Offset = getModifier() ? 1 : 0;
7515 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7516 reinterpret_cast<Stmt **>(varlist_end() + Offset));
7519 const_child_range children() const {
7520 auto Children = const_cast<OMPAffinityClause *>(this)->children();
7521 return const_child_range(Children.begin(), Children.end());
7524 child_range used_children() {
7525 return child_range(child_iterator(), child_iterator());
7527 const_child_range used_children() const {
7528 return const_child_range(const_child_iterator(), const_child_iterator());
7531 static bool classof(const OMPClause *T) {
7532 return T->getClauseKind() == llvm::omp::OMPC_affinity;
7536 /// This class implements a simple visitor for OMPClause
7538 template<class ImplClass, template <typename> class Ptr, typename RetTy>
7539 class OMPClauseVisitorBase {
7541 #define PTR(CLASS) Ptr<CLASS>
7542 #define DISPATCH(CLASS) \
7543 return static_cast<ImplClass*>(this)->Visit##CLASS(static_cast<PTR(CLASS)>(S))
7545 #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
7546 RetTy Visit ## Class (PTR(Class) S) { DISPATCH(Class); }
7547 #include "llvm/Frontend/OpenMP/OMPKinds.def"
7549 RetTy Visit(PTR(OMPClause) S) {
7550 // Top switch clause: visit each OMPClause.
7551 switch (S->getClauseKind()) {
7552 #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
7553 case llvm::omp::Clause::Enum: \
7554 return Visit##Class(static_cast<PTR(Class)>(S));
7555 #define OMP_CLAUSE_NO_CLASS(Enum, Str) \
7556 case llvm::omp::Clause::Enum: \
7558 #include "llvm/Frontend/OpenMP/OMPKinds.def"
7563 // Base case, ignore it. :)
7564 RetTy VisitOMPClause(PTR(OMPClause) Node) { return RetTy(); }
7569 template <typename T> using const_ptr = std::add_pointer_t<std::add_const_t<T>>;
7571 template <class ImplClass, typename RetTy = void>
7572 class OMPClauseVisitor
7573 : public OMPClauseVisitorBase<ImplClass, std::add_pointer_t, RetTy> {};
7574 template<class ImplClass, typename RetTy = void>
7575 class ConstOMPClauseVisitor :
7576 public OMPClauseVisitorBase <ImplClass, const_ptr, RetTy> {};
7578 class OMPClausePrinter final : public OMPClauseVisitor<OMPClausePrinter> {
7580 const PrintingPolicy &Policy;
7582 /// Process clauses with list of variables.
7583 template <typename T> void VisitOMPClauseList(T *Node, char StartSym);
7586 OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy)
7587 : OS(OS), Policy(Policy) {}
7589 #define OMP_CLAUSE_CLASS(Enum, Str, Class) \
7590 void Visit##Class(Class *S);
7591 #include "llvm/Frontend/OpenMP/OMPKinds.def"
7594 struct OMPTraitProperty {
7595 llvm::omp::TraitProperty Kind = llvm::omp::TraitProperty::invalid;
7597 struct OMPTraitSelector {
7598 Expr *ScoreOrCondition = nullptr;
7599 llvm::omp::TraitSelector Kind = llvm::omp::TraitSelector::invalid;
7600 llvm::SmallVector<OMPTraitProperty, 1> Properties;
7602 struct OMPTraitSet {
7603 llvm::omp::TraitSet Kind = llvm::omp::TraitSet::invalid;
7604 llvm::SmallVector<OMPTraitSelector, 2> Selectors;
7607 /// Helper data structure representing the traits in a match clause of an
7608 /// `declare variant` or `metadirective`. The outer level is an ordered
7609 /// collection of selector sets, each with an associated kind and an ordered
7610 /// collection of selectors. A selector has a kind, an optional score/condition,
7611 /// and an ordered collection of properties.
7612 class OMPTraitInfo {
7613 /// Private constructor accesible only by ASTContext.
7615 friend class ASTContext;
7618 /// Reconstruct a (partial) OMPTraitInfo object from a mangled name.
7619 OMPTraitInfo(StringRef MangledName);
7621 /// The outermost level of selector sets.
7622 llvm::SmallVector<OMPTraitSet, 2> Sets;
7624 bool anyScoreOrCondition(
7625 llvm::function_ref<bool(Expr *&, bool /* IsScore */)> Cond) {
7626 return llvm::any_of(Sets, [&](OMPTraitSet &Set) {
7627 return llvm::any_of(
7628 Set.Selectors, [&](OMPTraitSelector &Selector) {
7629 return Cond(Selector.ScoreOrCondition,
7630 /* IsScore */ Selector.Kind !=
7631 llvm::omp::TraitSelector::user_condition);
7636 /// Create a variant match info object from this trait info object. While the
7637 /// former is a flat representation the actual main difference is that the
7638 /// latter uses clang::Expr to store the score/condition while the former is
7639 /// independent of clang. Thus, expressions and conditions are evaluated in
7641 void getAsVariantMatchInfo(ASTContext &ASTCtx,
7642 llvm::omp::VariantMatchInfo &VMI) const;
7644 /// Return a string representation identifying this context selector.
7645 std::string getMangledName() const;
7647 /// Print a human readable representation into \p OS.
7648 void print(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
7650 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI);
7651 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const OMPTraitInfo *TI);
7653 } // namespace clang
7655 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H