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