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 //===----------------------------------------------------------------------===//
10 /// \brief This file defines OpenMP AST classes for clauses.
11 /// There are clauses for executable directives, clauses for declarative
12 /// directives and clauses which can be used in both kinds of directives.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_AST_OPENMPCLAUSE_H
17 #define LLVM_CLANG_AST_OPENMPCLAUSE_H
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/Stmt.h"
21 #include "clang/Basic/OpenMPKinds.h"
22 #include "clang/Basic/SourceLocation.h"
23 #include "llvm/ADT/MapVector.h"
27 //===----------------------------------------------------------------------===//
28 // AST classes for clauses.
29 //===----------------------------------------------------------------------===//
31 /// \brief This is a basic class for representing single OpenMP clause.
34 /// \brief Starting location of the clause (the clause keyword).
35 SourceLocation StartLoc;
36 /// \brief Ending location of the clause.
37 SourceLocation EndLoc;
38 /// \brief Kind of the clause.
39 OpenMPClauseKind Kind;
42 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
43 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
46 /// \brief Returns the starting location of the clause.
47 SourceLocation getLocStart() const { return StartLoc; }
48 /// \brief Returns the ending location of the clause.
49 SourceLocation getLocEnd() const { return EndLoc; }
51 /// \brief Sets the starting location of the clause.
52 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
53 /// \brief Sets the ending location of the clause.
54 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
56 /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
57 OpenMPClauseKind getClauseKind() const { return Kind; }
59 bool isImplicit() const { return StartLoc.isInvalid(); }
61 typedef StmtIterator child_iterator;
62 typedef ConstStmtIterator const_child_iterator;
63 typedef llvm::iterator_range<child_iterator> child_range;
64 typedef llvm::iterator_range<const_child_iterator> const_child_range;
66 child_range children();
67 const_child_range children() const {
68 auto Children = const_cast<OMPClause *>(this)->children();
69 return const_child_range(Children.begin(), Children.end());
71 static bool classof(const OMPClause *) { return true; }
74 /// Class that handles pre-initialization statement for some clauses, like
75 /// 'shedule', 'firstprivate' etc.
76 class OMPClauseWithPreInit {
77 friend class OMPClauseReader;
78 /// Pre-initialization statement for the clause.
80 /// Region that captures the associated stmt.
81 OpenMPDirectiveKind CaptureRegion;
84 /// Set pre-initialization statement for the clause.
85 void setPreInitStmt(Stmt *S, OpenMPDirectiveKind ThisRegion = OMPD_unknown) {
87 CaptureRegion = ThisRegion;
89 OMPClauseWithPreInit(const OMPClause *This)
90 : PreInit(nullptr), CaptureRegion(OMPD_unknown) {
91 assert(get(This) && "get is not tuned for pre-init.");
95 /// Get pre-initialization statement for the clause.
96 const Stmt *getPreInitStmt() const { return PreInit; }
97 /// Get pre-initialization statement for the clause.
98 Stmt *getPreInitStmt() { return PreInit; }
99 /// Get capture region for the stmt in the clause.
100 OpenMPDirectiveKind getCaptureRegion() { return CaptureRegion; }
101 static OMPClauseWithPreInit *get(OMPClause *C);
102 static const OMPClauseWithPreInit *get(const OMPClause *C);
105 /// Class that handles post-update expression for some clauses, like
106 /// 'lastprivate', 'reduction' etc.
107 class OMPClauseWithPostUpdate : public OMPClauseWithPreInit {
108 friend class OMPClauseReader;
109 /// Post-update expression for the clause.
112 /// Set pre-initialization statement for the clause.
113 void setPostUpdateExpr(Expr *S) { PostUpdate = S; }
114 OMPClauseWithPostUpdate(const OMPClause *This)
115 : OMPClauseWithPreInit(This), PostUpdate(nullptr) {
116 assert(get(This) && "get is not tuned for post-update.");
120 /// Get post-update expression for the clause.
121 const Expr *getPostUpdateExpr() const { return PostUpdate; }
122 /// Get post-update expression for the clause.
123 Expr *getPostUpdateExpr() { return PostUpdate; }
124 static OMPClauseWithPostUpdate *get(OMPClause *C);
125 static const OMPClauseWithPostUpdate *get(const OMPClause *C);
128 /// \brief This represents clauses with the list of variables like 'private',
129 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
130 /// '#pragma omp ...' directives.
131 template <class T> class OMPVarListClause : public OMPClause {
132 friend class OMPClauseReader;
133 /// \brief Location of '('.
134 SourceLocation LParenLoc;
135 /// \brief Number of variables in the list.
139 /// \brief Fetches list of variables associated with this clause.
140 MutableArrayRef<Expr *> getVarRefs() {
141 return MutableArrayRef<Expr *>(
142 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
145 /// \brief Sets the list of variables for this clause.
146 void setVarRefs(ArrayRef<Expr *> VL) {
147 assert(VL.size() == NumVars &&
148 "Number of variables is not the same as the preallocated buffer");
149 std::copy(VL.begin(), VL.end(),
150 static_cast<T *>(this)->template getTrailingObjects<Expr *>());
153 /// \brief Build a clause with \a N variables
155 /// \param K Kind of the clause.
156 /// \param StartLoc Starting location of the clause (the clause keyword).
157 /// \param LParenLoc Location of '('.
158 /// \param EndLoc Ending location of the clause.
159 /// \param N Number of the variables in the clause.
161 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
162 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
163 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
166 typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
167 typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
168 typedef llvm::iterator_range<varlist_iterator> varlist_range;
169 typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
171 unsigned varlist_size() const { return NumVars; }
172 bool varlist_empty() const { return NumVars == 0; }
174 varlist_range varlists() {
175 return varlist_range(varlist_begin(), varlist_end());
177 varlist_const_range varlists() const {
178 return varlist_const_range(varlist_begin(), varlist_end());
181 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
182 varlist_iterator varlist_end() { return getVarRefs().end(); }
183 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
184 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
186 /// \brief Sets the location of '('.
187 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
188 /// \brief Returns the location of '('.
189 SourceLocation getLParenLoc() const { return LParenLoc; }
191 /// \brief Fetches list of all variables in the clause.
192 ArrayRef<const Expr *> getVarRefs() const {
193 return llvm::makeArrayRef(
194 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
199 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
202 /// #pragma omp parallel if(parallel:a > 5)
204 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
205 /// condition 'a > 5' and directive name modifier 'parallel'.
207 class OMPIfClause : public OMPClause, public OMPClauseWithPreInit {
208 friend class OMPClauseReader;
209 /// \brief Location of '('.
210 SourceLocation LParenLoc;
211 /// \brief Condition of the 'if' clause.
213 /// \brief Location of ':' (if any).
214 SourceLocation ColonLoc;
215 /// \brief Directive name modifier for the clause.
216 OpenMPDirectiveKind NameModifier;
217 /// \brief Name modifier location.
218 SourceLocation NameModifierLoc;
220 /// \brief Set condition.
222 void setCondition(Expr *Cond) { Condition = Cond; }
223 /// \brief Set directive name modifier for the clause.
225 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
226 /// \brief Set location of directive name modifier for the clause.
228 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
229 /// \brief Set location of ':'.
231 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
234 /// \brief Build 'if' clause with condition \a Cond.
236 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
237 /// \param Cond Condition of the clause.
238 /// \param HelperCond Helper condition for the clause.
239 /// \param CaptureRegion Innermost OpenMP region where expressions in this
240 /// clause must be captured.
241 /// \param StartLoc Starting location of the clause.
242 /// \param LParenLoc Location of '('.
243 /// \param NameModifierLoc Location of directive name modifier.
244 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
245 /// \param EndLoc Ending location of the clause.
247 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond, Stmt *HelperCond,
248 OpenMPDirectiveKind CaptureRegion, SourceLocation StartLoc,
249 SourceLocation LParenLoc, SourceLocation NameModifierLoc,
250 SourceLocation ColonLoc, SourceLocation EndLoc)
251 : OMPClause(OMPC_if, StartLoc, EndLoc), OMPClauseWithPreInit(this),
252 LParenLoc(LParenLoc), Condition(Cond), ColonLoc(ColonLoc),
253 NameModifier(NameModifier), NameModifierLoc(NameModifierLoc) {
254 setPreInitStmt(HelperCond, CaptureRegion);
257 /// \brief Build an empty clause.
260 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()),
261 OMPClauseWithPreInit(this), LParenLoc(), Condition(nullptr), ColonLoc(),
262 NameModifier(OMPD_unknown), NameModifierLoc() {}
264 /// \brief Sets the location of '('.
265 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
266 /// \brief Returns the location of '('.
267 SourceLocation getLParenLoc() const { return LParenLoc; }
269 /// \brief Return the location of ':'.
270 SourceLocation getColonLoc() const { return ColonLoc; }
272 /// \brief Returns condition.
273 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
274 /// \brief Return directive name modifier associated with the clause.
275 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
277 /// \brief Return the location of directive name modifier.
278 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
280 static bool classof(const OMPClause *T) {
281 return T->getClauseKind() == OMPC_if;
284 child_range children() { return child_range(&Condition, &Condition + 1); }
287 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
290 /// #pragma omp task final(a > 5)
292 /// In this example directive '#pragma omp task' has simple 'final'
293 /// clause with condition 'a > 5'.
295 class OMPFinalClause : public OMPClause {
296 friend class OMPClauseReader;
297 /// \brief Location of '('.
298 SourceLocation LParenLoc;
299 /// \brief Condition of the 'if' clause.
302 /// \brief Set condition.
304 void setCondition(Expr *Cond) { Condition = Cond; }
307 /// \brief Build 'final' clause with condition \a Cond.
309 /// \param StartLoc Starting location of the clause.
310 /// \param LParenLoc Location of '('.
311 /// \param Cond Condition of the clause.
312 /// \param EndLoc Ending location of the clause.
314 OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
315 SourceLocation EndLoc)
316 : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
319 /// \brief Build an empty clause.
322 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
323 LParenLoc(SourceLocation()), Condition(nullptr) {}
325 /// \brief Sets the location of '('.
326 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
327 /// \brief Returns the location of '('.
328 SourceLocation getLParenLoc() const { return LParenLoc; }
330 /// \brief Returns condition.
331 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
333 static bool classof(const OMPClause *T) {
334 return T->getClauseKind() == OMPC_final;
337 child_range children() { return child_range(&Condition, &Condition + 1); }
340 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
344 /// #pragma omp parallel num_threads(6)
346 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
347 /// clause with number of threads '6'.
349 class OMPNumThreadsClause : public OMPClause, public OMPClauseWithPreInit {
350 friend class OMPClauseReader;
351 /// \brief Location of '('.
352 SourceLocation LParenLoc;
353 /// \brief Condition of the 'num_threads' clause.
356 /// \brief Set condition.
358 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
361 /// \brief Build 'num_threads' clause with condition \a NumThreads.
363 /// \param NumThreads Number of threads for the construct.
364 /// \param HelperNumThreads Helper Number of threads for the construct.
365 /// \param CaptureRegion Innermost OpenMP region where expressions in this
366 /// clause must be captured.
367 /// \param StartLoc Starting location of the clause.
368 /// \param LParenLoc Location of '('.
369 /// \param EndLoc Ending location of the clause.
371 OMPNumThreadsClause(Expr *NumThreads, Stmt *HelperNumThreads,
372 OpenMPDirectiveKind CaptureRegion,
373 SourceLocation StartLoc, SourceLocation LParenLoc,
374 SourceLocation EndLoc)
375 : OMPClause(OMPC_num_threads, StartLoc, EndLoc),
376 OMPClauseWithPreInit(this), LParenLoc(LParenLoc),
377 NumThreads(NumThreads) {
378 setPreInitStmt(HelperNumThreads, CaptureRegion);
381 /// \brief Build an empty clause.
383 OMPNumThreadsClause()
384 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
385 OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
386 NumThreads(nullptr) {}
388 /// \brief Sets the location of '('.
389 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
390 /// \brief Returns the location of '('.
391 SourceLocation getLParenLoc() const { return LParenLoc; }
393 /// \brief Returns number of threads.
394 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
396 static bool classof(const OMPClause *T) {
397 return T->getClauseKind() == OMPC_num_threads;
400 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
403 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
407 /// #pragma omp simd safelen(4)
409 /// In this example directive '#pragma omp simd' has clause 'safelen'
410 /// with single expression '4'.
411 /// If the safelen clause is used then no two iterations executed
412 /// concurrently with SIMD instructions can have a greater distance
413 /// in the logical iteration space than its value. The parameter of
414 /// the safelen clause must be a constant positive integer expression.
416 class OMPSafelenClause : public OMPClause {
417 friend class OMPClauseReader;
418 /// \brief Location of '('.
419 SourceLocation LParenLoc;
420 /// \brief Safe iteration space distance.
423 /// \brief Set safelen.
424 void setSafelen(Expr *Len) { Safelen = Len; }
427 /// \brief Build 'safelen' clause.
429 /// \param Len Expression associated with this clause.
430 /// \param StartLoc Starting location of the clause.
431 /// \param EndLoc Ending location of the clause.
433 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
434 SourceLocation EndLoc)
435 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
438 /// \brief Build an empty clause.
440 explicit OMPSafelenClause()
441 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
442 LParenLoc(SourceLocation()), Safelen(nullptr) {}
444 /// \brief Sets the location of '('.
445 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
446 /// \brief Returns the location of '('.
447 SourceLocation getLParenLoc() const { return LParenLoc; }
449 /// \brief Return safe iteration space distance.
450 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
452 static bool classof(const OMPClause *T) {
453 return T->getClauseKind() == OMPC_safelen;
456 child_range children() { return child_range(&Safelen, &Safelen + 1); }
459 /// \brief This represents 'simdlen' clause in the '#pragma omp ...'
463 /// #pragma omp simd simdlen(4)
465 /// In this example directive '#pragma omp simd' has clause 'simdlen'
466 /// with single expression '4'.
467 /// If the 'simdlen' clause is used then it specifies the preferred number of
468 /// iterations to be executed concurrently. The parameter of the 'simdlen'
469 /// clause must be a constant positive integer expression.
471 class OMPSimdlenClause : public OMPClause {
472 friend class OMPClauseReader;
473 /// \brief Location of '('.
474 SourceLocation LParenLoc;
475 /// \brief Safe iteration space distance.
478 /// \brief Set simdlen.
479 void setSimdlen(Expr *Len) { Simdlen = Len; }
482 /// \brief Build 'simdlen' clause.
484 /// \param Len Expression associated with this clause.
485 /// \param StartLoc Starting location of the clause.
486 /// \param EndLoc Ending location of the clause.
488 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
489 SourceLocation EndLoc)
490 : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
493 /// \brief Build an empty clause.
495 explicit OMPSimdlenClause()
496 : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()),
497 LParenLoc(SourceLocation()), Simdlen(nullptr) {}
499 /// \brief Sets the location of '('.
500 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
501 /// \brief Returns the location of '('.
502 SourceLocation getLParenLoc() const { return LParenLoc; }
504 /// \brief Return safe iteration space distance.
505 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
507 static bool classof(const OMPClause *T) {
508 return T->getClauseKind() == OMPC_simdlen;
511 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
514 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
518 /// #pragma omp simd collapse(3)
520 /// In this example directive '#pragma omp simd' has clause 'collapse'
521 /// with single expression '3'.
522 /// The parameter must be a constant positive integer expression, it specifies
523 /// the number of nested loops that should be collapsed into a single iteration
526 class OMPCollapseClause : public OMPClause {
527 friend class OMPClauseReader;
528 /// \brief Location of '('.
529 SourceLocation LParenLoc;
530 /// \brief Number of for-loops.
533 /// \brief Set the number of associated for-loops.
534 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
537 /// \brief Build 'collapse' clause.
539 /// \param Num Expression associated with this clause.
540 /// \param StartLoc Starting location of the clause.
541 /// \param LParenLoc Location of '('.
542 /// \param EndLoc Ending location of the clause.
544 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
545 SourceLocation LParenLoc, SourceLocation EndLoc)
546 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
549 /// \brief Build an empty clause.
551 explicit OMPCollapseClause()
552 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
553 LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
555 /// \brief Sets the location of '('.
556 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
557 /// \brief Returns the location of '('.
558 SourceLocation getLParenLoc() const { return LParenLoc; }
560 /// \brief Return the number of associated for-loops.
561 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
563 static bool classof(const OMPClause *T) {
564 return T->getClauseKind() == OMPC_collapse;
567 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
570 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
573 /// #pragma omp parallel default(shared)
575 /// In this example directive '#pragma omp parallel' has simple 'default'
576 /// clause with kind 'shared'.
578 class OMPDefaultClause : public OMPClause {
579 friend class OMPClauseReader;
580 /// \brief Location of '('.
581 SourceLocation LParenLoc;
582 /// \brief A kind of the 'default' clause.
583 OpenMPDefaultClauseKind Kind;
584 /// \brief Start location of the kind in source code.
585 SourceLocation KindKwLoc;
587 /// \brief Set kind of the clauses.
589 /// \param K Argument of clause.
591 void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
593 /// \brief Set argument location.
595 /// \param KLoc Argument location.
597 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
600 /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
602 /// \param A Argument of the clause ('none' or 'shared').
603 /// \param ALoc Starting location of the argument.
604 /// \param StartLoc Starting location of the clause.
605 /// \param LParenLoc Location of '('.
606 /// \param EndLoc Ending location of the clause.
608 OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
609 SourceLocation StartLoc, SourceLocation LParenLoc,
610 SourceLocation EndLoc)
611 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
612 Kind(A), KindKwLoc(ALoc) {}
614 /// \brief Build an empty clause.
617 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
618 LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
619 KindKwLoc(SourceLocation()) {}
621 /// \brief Sets the location of '('.
622 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
623 /// \brief Returns the location of '('.
624 SourceLocation getLParenLoc() const { return LParenLoc; }
626 /// \brief Returns kind of the clause.
627 OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
629 /// \brief Returns location of clause kind.
630 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
632 static bool classof(const OMPClause *T) {
633 return T->getClauseKind() == OMPC_default;
636 child_range children() {
637 return child_range(child_iterator(), child_iterator());
641 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
645 /// #pragma omp parallel proc_bind(master)
647 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
648 /// clause with kind 'master'.
650 class OMPProcBindClause : public OMPClause {
651 friend class OMPClauseReader;
652 /// \brief Location of '('.
653 SourceLocation LParenLoc;
654 /// \brief A kind of the 'proc_bind' clause.
655 OpenMPProcBindClauseKind Kind;
656 /// \brief Start location of the kind in source code.
657 SourceLocation KindKwLoc;
659 /// \brief Set kind of the clause.
661 /// \param K Kind of clause.
663 void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
665 /// \brief Set clause kind location.
667 /// \param KLoc Kind location.
669 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
672 /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
675 /// \param A Argument of the clause ('master', 'close' or 'spread').
676 /// \param ALoc Starting location of the argument.
677 /// \param StartLoc Starting location of the clause.
678 /// \param LParenLoc Location of '('.
679 /// \param EndLoc Ending location of the clause.
681 OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
682 SourceLocation StartLoc, SourceLocation LParenLoc,
683 SourceLocation EndLoc)
684 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
685 Kind(A), KindKwLoc(ALoc) {}
687 /// \brief Build an empty clause.
690 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
691 LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
692 KindKwLoc(SourceLocation()) {}
694 /// \brief Sets the location of '('.
695 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
696 /// \brief Returns the location of '('.
697 SourceLocation getLParenLoc() const { return LParenLoc; }
699 /// \brief Returns kind of the clause.
700 OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
702 /// \brief Returns location of clause kind.
703 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
705 static bool classof(const OMPClause *T) {
706 return T->getClauseKind() == OMPC_proc_bind;
709 child_range children() {
710 return child_range(child_iterator(), child_iterator());
714 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
717 /// #pragma omp for schedule(static, 3)
719 /// In this example directive '#pragma omp for' has 'schedule' clause with
720 /// arguments 'static' and '3'.
722 class OMPScheduleClause : public OMPClause, public OMPClauseWithPreInit {
723 friend class OMPClauseReader;
724 /// \brief Location of '('.
725 SourceLocation LParenLoc;
726 /// \brief A kind of the 'schedule' clause.
727 OpenMPScheduleClauseKind Kind;
728 /// \brief Modifiers for 'schedule' clause.
729 enum {FIRST, SECOND, NUM_MODIFIERS};
730 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
731 /// \brief Locations of modifiers.
732 SourceLocation ModifiersLoc[NUM_MODIFIERS];
733 /// \brief Start location of the schedule ind in source code.
734 SourceLocation KindLoc;
735 /// \brief Location of ',' (if any).
736 SourceLocation CommaLoc;
737 /// \brief Chunk size.
740 /// \brief Set schedule kind.
742 /// \param K Schedule kind.
744 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
745 /// \brief Set the first schedule modifier.
747 /// \param M Schedule modifier.
749 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
750 Modifiers[FIRST] = M;
752 /// \brief Set the second schedule modifier.
754 /// \param M Schedule modifier.
756 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
757 Modifiers[SECOND] = M;
759 /// \brief Set location of the first schedule modifier.
761 void setFirstScheduleModifierLoc(SourceLocation Loc) {
762 ModifiersLoc[FIRST] = Loc;
764 /// \brief Set location of the second schedule modifier.
766 void setSecondScheduleModifierLoc(SourceLocation Loc) {
767 ModifiersLoc[SECOND] = Loc;
769 /// \brief Set schedule modifier location.
771 /// \param M Schedule modifier location.
773 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
774 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
775 Modifiers[FIRST] = M;
777 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
778 Modifiers[SECOND] = M;
781 /// \brief Sets the location of '('.
783 /// \param Loc Location of '('.
785 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
786 /// \brief Set schedule kind start location.
788 /// \param KLoc Schedule kind location.
790 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
791 /// \brief Set location of ','.
793 /// \param Loc Location of ','.
795 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
796 /// \brief Set chunk size.
798 /// \param E Chunk size.
800 void setChunkSize(Expr *E) { ChunkSize = E; }
803 /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
804 /// expression \a ChunkSize.
806 /// \param StartLoc Starting location of the clause.
807 /// \param LParenLoc Location of '('.
808 /// \param KLoc Starting location of the argument.
809 /// \param CommaLoc Location of ','.
810 /// \param EndLoc Ending location of the clause.
811 /// \param Kind Schedule kind.
812 /// \param ChunkSize Chunk size.
813 /// \param HelperChunkSize Helper chunk size for combined directives.
814 /// \param M1 The first modifier applied to 'schedule' clause.
815 /// \param M1Loc Location of the first modifier
816 /// \param M2 The second modifier applied to 'schedule' clause.
817 /// \param M2Loc Location of the second modifier
819 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
820 SourceLocation KLoc, SourceLocation CommaLoc,
821 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
822 Expr *ChunkSize, Stmt *HelperChunkSize,
823 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
824 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
825 : OMPClause(OMPC_schedule, StartLoc, EndLoc), OMPClauseWithPreInit(this),
826 LParenLoc(LParenLoc), Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc),
827 ChunkSize(ChunkSize) {
828 setPreInitStmt(HelperChunkSize);
829 Modifiers[FIRST] = M1;
830 Modifiers[SECOND] = M2;
831 ModifiersLoc[FIRST] = M1Loc;
832 ModifiersLoc[SECOND] = M2Loc;
835 /// \brief Build an empty clause.
837 explicit OMPScheduleClause()
838 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
839 OMPClauseWithPreInit(this), Kind(OMPC_SCHEDULE_unknown),
841 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
842 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
845 /// \brief Get kind of the clause.
847 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
848 /// \brief Get the first modifier of the clause.
850 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
851 return Modifiers[FIRST];
853 /// \brief Get the second modifier of the clause.
855 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
856 return Modifiers[SECOND];
858 /// \brief Get location of '('.
860 SourceLocation getLParenLoc() { return LParenLoc; }
861 /// \brief Get kind location.
863 SourceLocation getScheduleKindLoc() { return KindLoc; }
864 /// \brief Get the first modifier location.
866 SourceLocation getFirstScheduleModifierLoc() const {
867 return ModifiersLoc[FIRST];
869 /// \brief Get the second modifier location.
871 SourceLocation getSecondScheduleModifierLoc() const {
872 return ModifiersLoc[SECOND];
874 /// \brief Get location of ','.
876 SourceLocation getCommaLoc() { return CommaLoc; }
877 /// \brief Get chunk size.
879 Expr *getChunkSize() { return ChunkSize; }
880 /// \brief Get chunk size.
882 const Expr *getChunkSize() const { return ChunkSize; }
884 static bool classof(const OMPClause *T) {
885 return T->getClauseKind() == OMPC_schedule;
888 child_range children() {
889 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
890 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
894 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
897 /// #pragma omp for ordered (2)
899 /// In this example directive '#pragma omp for' has 'ordered' clause with
902 class OMPOrderedClause : public OMPClause {
903 friend class OMPClauseReader;
904 /// \brief Location of '('.
905 SourceLocation LParenLoc;
906 /// \brief Number of for-loops.
909 /// \brief Set the number of associated for-loops.
910 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
913 /// \brief Build 'ordered' clause.
915 /// \param Num Expression, possibly associated with this clause.
916 /// \param StartLoc Starting location of the clause.
917 /// \param LParenLoc Location of '('.
918 /// \param EndLoc Ending location of the clause.
920 OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
921 SourceLocation LParenLoc, SourceLocation EndLoc)
922 : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
925 /// \brief Build an empty clause.
927 explicit OMPOrderedClause()
928 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
929 LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
931 /// \brief Sets the location of '('.
932 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
933 /// \brief Returns the location of '('.
934 SourceLocation getLParenLoc() const { return LParenLoc; }
936 /// \brief Return the number of associated for-loops.
937 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
939 static bool classof(const OMPClause *T) {
940 return T->getClauseKind() == OMPC_ordered;
943 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
946 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
949 /// #pragma omp for nowait
951 /// In this example directive '#pragma omp for' has 'nowait' clause.
953 class OMPNowaitClause : public OMPClause {
955 /// \brief Build 'nowait' clause.
957 /// \param StartLoc Starting location of the clause.
958 /// \param EndLoc Ending location of the clause.
960 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
961 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
963 /// \brief Build an empty clause.
966 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
968 static bool classof(const OMPClause *T) {
969 return T->getClauseKind() == OMPC_nowait;
972 child_range children() {
973 return child_range(child_iterator(), child_iterator());
977 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
980 /// #pragma omp task untied
982 /// In this example directive '#pragma omp task' has 'untied' clause.
984 class OMPUntiedClause : public OMPClause {
986 /// \brief Build 'untied' clause.
988 /// \param StartLoc Starting location of the clause.
989 /// \param EndLoc Ending location of the clause.
991 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
992 : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
994 /// \brief Build an empty clause.
997 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
999 static bool classof(const OMPClause *T) {
1000 return T->getClauseKind() == OMPC_untied;
1003 child_range children() {
1004 return child_range(child_iterator(), child_iterator());
1008 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
1012 /// #pragma omp task mergeable
1014 /// In this example directive '#pragma omp task' has 'mergeable' clause.
1016 class OMPMergeableClause : public OMPClause {
1018 /// \brief Build 'mergeable' clause.
1020 /// \param StartLoc Starting location of the clause.
1021 /// \param EndLoc Ending location of the clause.
1023 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
1024 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
1026 /// \brief Build an empty clause.
1028 OMPMergeableClause()
1029 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
1031 static bool classof(const OMPClause *T) {
1032 return T->getClauseKind() == OMPC_mergeable;
1035 child_range children() {
1036 return child_range(child_iterator(), child_iterator());
1040 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
1043 /// #pragma omp atomic read
1045 /// In this example directive '#pragma omp atomic' has 'read' clause.
1047 class OMPReadClause : public OMPClause {
1049 /// \brief Build 'read' clause.
1051 /// \param StartLoc Starting location of the clause.
1052 /// \param EndLoc Ending location of the clause.
1054 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1055 : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1057 /// \brief Build an empty clause.
1059 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1061 static bool classof(const OMPClause *T) {
1062 return T->getClauseKind() == OMPC_read;
1065 child_range children() {
1066 return child_range(child_iterator(), child_iterator());
1070 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
1073 /// #pragma omp atomic write
1075 /// In this example directive '#pragma omp atomic' has 'write' clause.
1077 class OMPWriteClause : public OMPClause {
1079 /// \brief Build 'write' clause.
1081 /// \param StartLoc Starting location of the clause.
1082 /// \param EndLoc Ending location of the clause.
1084 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1085 : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1087 /// \brief Build an empty clause.
1090 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1092 static bool classof(const OMPClause *T) {
1093 return T->getClauseKind() == OMPC_write;
1096 child_range children() {
1097 return child_range(child_iterator(), child_iterator());
1101 /// \brief This represents 'update' clause in the '#pragma omp atomic'
1105 /// #pragma omp atomic update
1107 /// In this example directive '#pragma omp atomic' has 'update' clause.
1109 class OMPUpdateClause : public OMPClause {
1111 /// \brief Build 'update' clause.
1113 /// \param StartLoc Starting location of the clause.
1114 /// \param EndLoc Ending location of the clause.
1116 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
1117 : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1119 /// \brief Build an empty clause.
1122 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1124 static bool classof(const OMPClause *T) {
1125 return T->getClauseKind() == OMPC_update;
1128 child_range children() {
1129 return child_range(child_iterator(), child_iterator());
1133 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
1137 /// #pragma omp atomic capture
1139 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1141 class OMPCaptureClause : public OMPClause {
1143 /// \brief Build 'capture' clause.
1145 /// \param StartLoc Starting location of the clause.
1146 /// \param EndLoc Ending location of the clause.
1148 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1149 : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1151 /// \brief Build an empty clause.
1154 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1156 static bool classof(const OMPClause *T) {
1157 return T->getClauseKind() == OMPC_capture;
1160 child_range children() {
1161 return child_range(child_iterator(), child_iterator());
1165 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
1169 /// #pragma omp atomic seq_cst
1171 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1173 class OMPSeqCstClause : public OMPClause {
1175 /// \brief Build 'seq_cst' clause.
1177 /// \param StartLoc Starting location of the clause.
1178 /// \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.
1186 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1188 static bool classof(const OMPClause *T) {
1189 return T->getClauseKind() == OMPC_seq_cst;
1192 child_range children() {
1193 return child_range(child_iterator(), child_iterator());
1197 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
1200 /// #pragma omp parallel private(a,b)
1202 /// In this example directive '#pragma omp parallel' has clause 'private'
1203 /// with the variables 'a' and 'b'.
1205 class OMPPrivateClause final
1206 : public OMPVarListClause<OMPPrivateClause>,
1207 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1208 friend TrailingObjects;
1209 friend OMPVarListClause;
1210 friend class OMPClauseReader;
1211 /// \brief Build clause with number of variables \a N.
1213 /// \param StartLoc Starting location of the clause.
1214 /// \param LParenLoc Location of '('.
1215 /// \param EndLoc Ending location of the clause.
1216 /// \param N Number of the variables in the clause.
1218 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1219 SourceLocation EndLoc, unsigned N)
1220 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1223 /// \brief Build an empty clause.
1225 /// \param N Number of variables.
1227 explicit OMPPrivateClause(unsigned N)
1228 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
1229 SourceLocation(), SourceLocation(),
1232 /// \brief Sets the list of references to private copies with initializers for
1233 /// new private variables.
1234 /// \param VL List of references.
1235 void setPrivateCopies(ArrayRef<Expr *> VL);
1237 /// \brief Gets the list of references to private copies with initializers for
1238 /// new private variables.
1239 MutableArrayRef<Expr *> getPrivateCopies() {
1240 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1242 ArrayRef<const Expr *> getPrivateCopies() const {
1243 return llvm::makeArrayRef(varlist_end(), varlist_size());
1247 /// \brief Creates clause with a list of variables \a VL.
1249 /// \param C AST context.
1250 /// \param StartLoc Starting location of the clause.
1251 /// \param LParenLoc Location of '('.
1252 /// \param EndLoc Ending location of the clause.
1253 /// \param VL List of references to the variables.
1254 /// \param PrivateVL List of references to private copies with initializers.
1256 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1257 SourceLocation LParenLoc,
1258 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1259 ArrayRef<Expr *> PrivateVL);
1260 /// \brief Creates an empty clause with the place for \a N variables.
1262 /// \param C AST context.
1263 /// \param N The number of variables.
1265 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1267 typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1268 typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1269 typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1270 typedef llvm::iterator_range<private_copies_const_iterator>
1271 private_copies_const_range;
1273 private_copies_range private_copies() {
1274 return private_copies_range(getPrivateCopies().begin(),
1275 getPrivateCopies().end());
1277 private_copies_const_range private_copies() const {
1278 return private_copies_const_range(getPrivateCopies().begin(),
1279 getPrivateCopies().end());
1282 child_range children() {
1283 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1284 reinterpret_cast<Stmt **>(varlist_end()));
1287 static bool classof(const OMPClause *T) {
1288 return T->getClauseKind() == OMPC_private;
1292 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
1296 /// #pragma omp parallel firstprivate(a,b)
1298 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1299 /// with the variables 'a' and 'b'.
1301 class OMPFirstprivateClause final
1302 : public OMPVarListClause<OMPFirstprivateClause>,
1303 public OMPClauseWithPreInit,
1304 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1305 friend TrailingObjects;
1306 friend OMPVarListClause;
1307 friend class OMPClauseReader;
1309 /// \brief Build clause with number of variables \a N.
1311 /// \param StartLoc Starting location of the clause.
1312 /// \param LParenLoc Location of '('.
1313 /// \param EndLoc Ending location of the clause.
1314 /// \param N Number of the variables in the clause.
1316 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1317 SourceLocation EndLoc, unsigned N)
1318 : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1319 LParenLoc, EndLoc, N),
1320 OMPClauseWithPreInit(this) {}
1322 /// \brief Build an empty clause.
1324 /// \param N Number of variables.
1326 explicit OMPFirstprivateClause(unsigned N)
1327 : OMPVarListClause<OMPFirstprivateClause>(
1328 OMPC_firstprivate, SourceLocation(), SourceLocation(),
1329 SourceLocation(), N),
1330 OMPClauseWithPreInit(this) {}
1331 /// \brief Sets the list of references to private copies with initializers for
1332 /// new private variables.
1333 /// \param VL List of references.
1334 void setPrivateCopies(ArrayRef<Expr *> VL);
1336 /// \brief Gets the list of references to private copies with initializers for
1337 /// new private variables.
1338 MutableArrayRef<Expr *> getPrivateCopies() {
1339 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1341 ArrayRef<const Expr *> getPrivateCopies() const {
1342 return llvm::makeArrayRef(varlist_end(), varlist_size());
1345 /// \brief Sets the list of references to initializer variables for new
1346 /// private variables.
1347 /// \param VL List of references.
1348 void setInits(ArrayRef<Expr *> VL);
1350 /// \brief Gets the list of references to initializer variables for new
1351 /// private variables.
1352 MutableArrayRef<Expr *> getInits() {
1353 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1355 ArrayRef<const Expr *> getInits() const {
1356 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1360 /// \brief Creates clause with a list of variables \a VL.
1362 /// \param C AST context.
1363 /// \param StartLoc Starting location of the clause.
1364 /// \param LParenLoc Location of '('.
1365 /// \param EndLoc Ending location of the clause.
1366 /// \param VL List of references to the original variables.
1367 /// \param PrivateVL List of references to private copies with initializers.
1368 /// \param InitVL List of references to auto generated variables used for
1369 /// initialization of a single array element. Used if firstprivate variable is
1371 /// \param PreInit Statement that must be executed before entering the OpenMP
1372 /// region with this clause.
1374 static OMPFirstprivateClause *
1375 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1376 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1377 ArrayRef<Expr *> InitVL, Stmt *PreInit);
1378 /// \brief Creates an empty clause with the place for \a N variables.
1380 /// \param C AST context.
1381 /// \param N The number of variables.
1383 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1385 typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1386 typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1387 typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1388 typedef llvm::iterator_range<private_copies_const_iterator>
1389 private_copies_const_range;
1391 private_copies_range private_copies() {
1392 return private_copies_range(getPrivateCopies().begin(),
1393 getPrivateCopies().end());
1395 private_copies_const_range private_copies() const {
1396 return private_copies_const_range(getPrivateCopies().begin(),
1397 getPrivateCopies().end());
1400 typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1401 typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1402 typedef llvm::iterator_range<inits_iterator> inits_range;
1403 typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1405 inits_range inits() {
1406 return inits_range(getInits().begin(), getInits().end());
1408 inits_const_range inits() const {
1409 return inits_const_range(getInits().begin(), getInits().end());
1412 child_range children() {
1413 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1414 reinterpret_cast<Stmt **>(varlist_end()));
1417 static bool classof(const OMPClause *T) {
1418 return T->getClauseKind() == OMPC_firstprivate;
1422 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
1426 /// #pragma omp simd lastprivate(a,b)
1428 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1429 /// with the variables 'a' and 'b'.
1430 class OMPLastprivateClause final
1431 : public OMPVarListClause<OMPLastprivateClause>,
1432 public OMPClauseWithPostUpdate,
1433 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
1434 // There are 4 additional tail-allocated arrays at the end of the class:
1435 // 1. Contains list of pseudo variables with the default initialization for
1436 // each non-firstprivate variables. Used in codegen for initialization of
1437 // lastprivate copies.
1438 // 2. List of helper expressions for proper generation of assignment operation
1439 // required for lastprivate clause. This list represents private variables
1440 // (for arrays, single array element).
1441 // 3. List of helper expressions for proper generation of assignment operation
1442 // required for lastprivate clause. This list represents original variables
1443 // (for arrays, single array element).
1444 // 4. List of helper expressions that represents assignment operation:
1446 // DstExprs = SrcExprs;
1448 // Required for proper codegen of final assignment performed by the
1449 // lastprivate clause.
1451 friend TrailingObjects;
1452 friend OMPVarListClause;
1453 friend class OMPClauseReader;
1455 /// \brief Build clause with number of variables \a N.
1457 /// \param StartLoc Starting location of the clause.
1458 /// \param LParenLoc Location of '('.
1459 /// \param EndLoc Ending location of the clause.
1460 /// \param N Number of the variables in the clause.
1462 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1463 SourceLocation EndLoc, unsigned N)
1464 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1465 LParenLoc, EndLoc, N),
1466 OMPClauseWithPostUpdate(this) {}
1468 /// \brief Build an empty clause.
1470 /// \param N Number of variables.
1472 explicit OMPLastprivateClause(unsigned N)
1473 : OMPVarListClause<OMPLastprivateClause>(
1474 OMPC_lastprivate, SourceLocation(), SourceLocation(),
1475 SourceLocation(), N),
1476 OMPClauseWithPostUpdate(this) {}
1478 /// \brief Get the list of helper expressions for initialization of private
1479 /// copies for lastprivate variables.
1480 MutableArrayRef<Expr *> getPrivateCopies() {
1481 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1483 ArrayRef<const Expr *> getPrivateCopies() const {
1484 return llvm::makeArrayRef(varlist_end(), varlist_size());
1487 /// \brief Set list of helper expressions, required for proper codegen of the
1488 /// clause. These expressions represent private variables (for arrays, single
1489 /// array element) in the final assignment statement performed by the
1490 /// lastprivate clause.
1491 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1493 /// \brief Get the list of helper source expressions.
1494 MutableArrayRef<Expr *> getSourceExprs() {
1495 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1497 ArrayRef<const Expr *> getSourceExprs() const {
1498 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1501 /// \brief Set list of helper expressions, required for proper codegen of the
1502 /// clause. These expressions represent original variables (for arrays, single
1503 /// array element) in the final assignment statement performed by the
1504 /// lastprivate clause.
1505 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1507 /// \brief Get the list of helper destination expressions.
1508 MutableArrayRef<Expr *> getDestinationExprs() {
1509 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1511 ArrayRef<const Expr *> getDestinationExprs() const {
1512 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1515 /// \brief Set list of helper assignment expressions, required for proper
1516 /// codegen of the clause. These expressions are assignment expressions that
1517 /// assign private copy of the variable to original variable.
1518 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1520 /// \brief Get the list of helper assignment expressions.
1521 MutableArrayRef<Expr *> getAssignmentOps() {
1522 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1524 ArrayRef<const Expr *> getAssignmentOps() const {
1525 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1529 /// \brief Creates clause with a list of variables \a VL.
1531 /// \param C AST context.
1532 /// \param StartLoc Starting location of the clause.
1533 /// \param LParenLoc Location of '('.
1534 /// \param EndLoc Ending location of the clause.
1535 /// \param VL List of references to the variables.
1536 /// \param SrcExprs List of helper expressions for proper generation of
1537 /// assignment operation required for lastprivate clause. This list represents
1538 /// private variables (for arrays, single array element).
1539 /// \param DstExprs List of helper expressions for proper generation of
1540 /// assignment operation required for lastprivate clause. This list represents
1541 /// original variables (for arrays, single array element).
1542 /// \param AssignmentOps List of helper expressions that represents assignment
1545 /// DstExprs = SrcExprs;
1547 /// Required for proper codegen of final assignment performed by the
1548 /// lastprivate clause.
1549 /// \param PreInit Statement that must be executed before entering the OpenMP
1550 /// region with this clause.
1551 /// \param PostUpdate Expression that must be executed after exit from the
1552 /// OpenMP region with this clause.
1554 static OMPLastprivateClause *
1555 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1556 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1557 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps,
1558 Stmt *PreInit, Expr *PostUpdate);
1559 /// \brief Creates an empty clause with the place for \a N variables.
1561 /// \param C AST context.
1562 /// \param N The number of variables.
1564 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1566 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1567 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1568 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1569 typedef llvm::iterator_range<helper_expr_const_iterator>
1570 helper_expr_const_range;
1572 /// \brief Set list of helper expressions, required for generation of private
1573 /// copies of original lastprivate variables.
1574 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1576 helper_expr_const_range private_copies() const {
1577 return helper_expr_const_range(getPrivateCopies().begin(),
1578 getPrivateCopies().end());
1580 helper_expr_range private_copies() {
1581 return helper_expr_range(getPrivateCopies().begin(),
1582 getPrivateCopies().end());
1584 helper_expr_const_range source_exprs() const {
1585 return helper_expr_const_range(getSourceExprs().begin(),
1586 getSourceExprs().end());
1588 helper_expr_range source_exprs() {
1589 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1591 helper_expr_const_range destination_exprs() const {
1592 return helper_expr_const_range(getDestinationExprs().begin(),
1593 getDestinationExprs().end());
1595 helper_expr_range destination_exprs() {
1596 return helper_expr_range(getDestinationExprs().begin(),
1597 getDestinationExprs().end());
1599 helper_expr_const_range assignment_ops() const {
1600 return helper_expr_const_range(getAssignmentOps().begin(),
1601 getAssignmentOps().end());
1603 helper_expr_range assignment_ops() {
1604 return helper_expr_range(getAssignmentOps().begin(),
1605 getAssignmentOps().end());
1608 child_range children() {
1609 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1610 reinterpret_cast<Stmt **>(varlist_end()));
1613 static bool classof(const OMPClause *T) {
1614 return T->getClauseKind() == OMPC_lastprivate;
1618 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
1621 /// #pragma omp parallel shared(a,b)
1623 /// In this example directive '#pragma omp parallel' has clause 'shared'
1624 /// with the variables 'a' and 'b'.
1626 class OMPSharedClause final
1627 : public OMPVarListClause<OMPSharedClause>,
1628 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
1629 friend TrailingObjects;
1630 friend OMPVarListClause;
1631 /// \brief Build clause with number of variables \a N.
1633 /// \param StartLoc Starting location of the clause.
1634 /// \param LParenLoc Location of '('.
1635 /// \param EndLoc Ending location of the clause.
1636 /// \param N Number of the variables in the clause.
1638 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1639 SourceLocation EndLoc, unsigned N)
1640 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1643 /// \brief Build an empty clause.
1645 /// \param N Number of variables.
1647 explicit OMPSharedClause(unsigned N)
1648 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1649 SourceLocation(), SourceLocation(),
1653 /// \brief Creates clause with a list of variables \a VL.
1655 /// \param C AST context.
1656 /// \param StartLoc Starting location of the clause.
1657 /// \param LParenLoc Location of '('.
1658 /// \param EndLoc Ending location of the clause.
1659 /// \param VL List of references to the variables.
1661 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1662 SourceLocation LParenLoc,
1663 SourceLocation EndLoc, ArrayRef<Expr *> VL);
1664 /// \brief Creates an empty clause with \a N variables.
1666 /// \param C AST context.
1667 /// \param N The number of variables.
1669 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1671 child_range children() {
1672 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1673 reinterpret_cast<Stmt **>(varlist_end()));
1676 static bool classof(const OMPClause *T) {
1677 return T->getClauseKind() == OMPC_shared;
1681 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
1685 /// #pragma omp parallel reduction(+:a,b)
1687 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1688 /// with operator '+' and the variables 'a' and 'b'.
1690 class OMPReductionClause final
1691 : public OMPVarListClause<OMPReductionClause>,
1692 public OMPClauseWithPostUpdate,
1693 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
1694 friend TrailingObjects;
1695 friend OMPVarListClause;
1696 friend class OMPClauseReader;
1697 /// \brief Location of ':'.
1698 SourceLocation ColonLoc;
1699 /// \brief Nested name specifier for C++.
1700 NestedNameSpecifierLoc QualifierLoc;
1701 /// \brief Name of custom operator.
1702 DeclarationNameInfo NameInfo;
1704 /// \brief Build clause with number of variables \a N.
1706 /// \param StartLoc Starting location of the clause.
1707 /// \param LParenLoc Location of '('.
1708 /// \param EndLoc Ending location of the clause.
1709 /// \param ColonLoc Location of ':'.
1710 /// \param N Number of the variables in the clause.
1711 /// \param QualifierLoc The nested-name qualifier with location information
1712 /// \param NameInfo The full name info for reduction identifier.
1714 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1715 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1716 NestedNameSpecifierLoc QualifierLoc,
1717 const DeclarationNameInfo &NameInfo)
1718 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1719 LParenLoc, EndLoc, N),
1720 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
1721 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1723 /// \brief Build an empty clause.
1725 /// \param N Number of variables.
1727 explicit OMPReductionClause(unsigned N)
1728 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1729 SourceLocation(), SourceLocation(),
1731 OMPClauseWithPostUpdate(this), ColonLoc(), QualifierLoc(), NameInfo() {}
1733 /// \brief Sets location of ':' symbol in clause.
1734 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1735 /// \brief Sets the name info for specified reduction identifier.
1736 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1737 /// \brief Sets the nested name specifier.
1738 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1740 /// \brief Set list of helper expressions, required for proper codegen of the
1741 /// clause. These expressions represent private copy of the reduction
1743 void setPrivates(ArrayRef<Expr *> Privates);
1745 /// \brief Get the list of helper privates.
1746 MutableArrayRef<Expr *> getPrivates() {
1747 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1749 ArrayRef<const Expr *> getPrivates() const {
1750 return llvm::makeArrayRef(varlist_end(), varlist_size());
1753 /// \brief Set list of helper expressions, required for proper codegen of the
1754 /// clause. These expressions represent LHS expression in the final
1755 /// reduction expression performed by the reduction clause.
1756 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1758 /// \brief Get the list of helper LHS expressions.
1759 MutableArrayRef<Expr *> getLHSExprs() {
1760 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1762 ArrayRef<const Expr *> getLHSExprs() const {
1763 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1766 /// \brief Set list of helper expressions, required for proper codegen of the
1767 /// clause. These expressions represent RHS expression in the final
1768 /// reduction expression performed by the reduction clause.
1769 /// Also, variables in these expressions are used for proper initialization of
1770 /// reduction copies.
1771 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1773 /// \brief Get the list of helper destination expressions.
1774 MutableArrayRef<Expr *> getRHSExprs() {
1775 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1777 ArrayRef<const Expr *> getRHSExprs() const {
1778 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1781 /// \brief Set list of helper reduction expressions, required for proper
1782 /// codegen of the clause. These expressions are binary expressions or
1783 /// operator/custom reduction call that calculates new value from source
1784 /// helper expressions to destination helper expressions.
1785 void setReductionOps(ArrayRef<Expr *> ReductionOps);
1787 /// \brief Get the list of helper reduction expressions.
1788 MutableArrayRef<Expr *> getReductionOps() {
1789 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1791 ArrayRef<const Expr *> getReductionOps() const {
1792 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1796 /// \brief Creates clause with a list of variables \a VL.
1798 /// \param StartLoc Starting location of the clause.
1799 /// \param LParenLoc Location of '('.
1800 /// \param ColonLoc Location of ':'.
1801 /// \param EndLoc Ending location of the clause.
1802 /// \param VL The variables in the clause.
1803 /// \param QualifierLoc The nested-name qualifier with location information
1804 /// \param NameInfo The full name info for reduction identifier.
1805 /// \param Privates List of helper expressions for proper generation of
1807 /// \param LHSExprs List of helper expressions for proper generation of
1808 /// assignment operation required for copyprivate clause. This list represents
1809 /// LHSs of the reduction expressions.
1810 /// \param RHSExprs List of helper expressions for proper generation of
1811 /// assignment operation required for copyprivate clause. This list represents
1812 /// RHSs of the reduction expressions.
1813 /// Also, variables in these expressions are used for proper initialization of
1814 /// reduction copies.
1815 /// \param ReductionOps List of helper expressions that represents reduction
1818 /// LHSExprs binop RHSExprs;
1819 /// operator binop(LHSExpr, RHSExpr);
1820 /// <CutomReduction>(LHSExpr, RHSExpr);
1822 /// Required for proper codegen of final reduction operation performed by the
1823 /// reduction clause.
1824 /// \param PreInit Statement that must be executed before entering the OpenMP
1825 /// region with this clause.
1826 /// \param PostUpdate Expression that must be executed after exit from the
1827 /// OpenMP region with this clause.
1829 static OMPReductionClause *
1830 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1831 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1832 NestedNameSpecifierLoc QualifierLoc,
1833 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
1834 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1835 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
1836 /// \brief Creates an empty clause with the place for \a N variables.
1838 /// \param C AST context.
1839 /// \param N The number of variables.
1841 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1843 /// \brief Gets location of ':' symbol in clause.
1844 SourceLocation getColonLoc() const { return ColonLoc; }
1845 /// \brief Gets the name info for specified reduction identifier.
1846 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1847 /// \brief Gets the nested name specifier.
1848 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1850 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1851 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1852 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1853 typedef llvm::iterator_range<helper_expr_const_iterator>
1854 helper_expr_const_range;
1856 helper_expr_const_range privates() const {
1857 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
1859 helper_expr_range privates() {
1860 return helper_expr_range(getPrivates().begin(), getPrivates().end());
1862 helper_expr_const_range lhs_exprs() const {
1863 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
1865 helper_expr_range lhs_exprs() {
1866 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
1868 helper_expr_const_range rhs_exprs() const {
1869 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
1871 helper_expr_range rhs_exprs() {
1872 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
1874 helper_expr_const_range reduction_ops() const {
1875 return helper_expr_const_range(getReductionOps().begin(),
1876 getReductionOps().end());
1878 helper_expr_range reduction_ops() {
1879 return helper_expr_range(getReductionOps().begin(),
1880 getReductionOps().end());
1883 child_range children() {
1884 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1885 reinterpret_cast<Stmt **>(varlist_end()));
1888 static bool classof(const OMPClause *T) {
1889 return T->getClauseKind() == OMPC_reduction;
1893 /// This represents clause 'task_reduction' in the '#pragma omp taskgroup'
1897 /// #pragma omp taskgroup task_reduction(+:a,b)
1899 /// In this example directive '#pragma omp taskgroup' has clause
1900 /// 'task_reduction' with operator '+' and the variables 'a' and 'b'.
1902 class OMPTaskReductionClause final
1903 : public OMPVarListClause<OMPTaskReductionClause>,
1904 public OMPClauseWithPostUpdate,
1905 private llvm::TrailingObjects<OMPTaskReductionClause, Expr *> {
1906 friend TrailingObjects;
1907 friend OMPVarListClause;
1908 friend class OMPClauseReader;
1909 /// Location of ':'.
1910 SourceLocation ColonLoc;
1911 /// Nested name specifier for C++.
1912 NestedNameSpecifierLoc QualifierLoc;
1913 /// Name of custom operator.
1914 DeclarationNameInfo NameInfo;
1916 /// Build clause with number of variables \a N.
1918 /// \param StartLoc Starting location of the clause.
1919 /// \param LParenLoc Location of '('.
1920 /// \param EndLoc Ending location of the clause.
1921 /// \param ColonLoc Location of ':'.
1922 /// \param N Number of the variables in the clause.
1923 /// \param QualifierLoc The nested-name qualifier with location information
1924 /// \param NameInfo The full name info for reduction identifier.
1926 OMPTaskReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1927 SourceLocation ColonLoc, SourceLocation EndLoc,
1928 unsigned N, NestedNameSpecifierLoc QualifierLoc,
1929 const DeclarationNameInfo &NameInfo)
1930 : OMPVarListClause<OMPTaskReductionClause>(OMPC_task_reduction, StartLoc,
1931 LParenLoc, EndLoc, N),
1932 OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc),
1933 QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1935 /// Build an empty clause.
1937 /// \param N Number of variables.
1939 explicit OMPTaskReductionClause(unsigned N)
1940 : OMPVarListClause<OMPTaskReductionClause>(
1941 OMPC_task_reduction, SourceLocation(), SourceLocation(),
1942 SourceLocation(), N),
1943 OMPClauseWithPostUpdate(this), ColonLoc(), QualifierLoc(), NameInfo() {}
1945 /// Sets location of ':' symbol in clause.
1946 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1947 /// Sets the name info for specified reduction identifier.
1948 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1949 /// Sets the nested name specifier.
1950 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1952 /// Set list of helper expressions, required for proper codegen of the clause.
1953 /// These expressions represent private copy of the reduction variable.
1954 void setPrivates(ArrayRef<Expr *> Privates);
1956 /// Get the list of helper privates.
1957 MutableArrayRef<Expr *> getPrivates() {
1958 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1960 ArrayRef<const Expr *> getPrivates() const {
1961 return llvm::makeArrayRef(varlist_end(), varlist_size());
1964 /// Set list of helper expressions, required for proper codegen of the clause.
1965 /// These expressions represent LHS expression in the final reduction
1966 /// expression performed by the reduction clause.
1967 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1969 /// Get the list of helper LHS expressions.
1970 MutableArrayRef<Expr *> getLHSExprs() {
1971 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1973 ArrayRef<const Expr *> getLHSExprs() const {
1974 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1977 /// Set list of helper expressions, required for proper codegen of the clause.
1978 /// These expressions represent RHS expression in the final reduction
1979 /// expression performed by the reduction clause. Also, variables in these
1980 /// expressions are used for proper initialization of reduction copies.
1981 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1983 /// Get the list of helper destination expressions.
1984 MutableArrayRef<Expr *> getRHSExprs() {
1985 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1987 ArrayRef<const Expr *> getRHSExprs() const {
1988 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1991 /// Set list of helper reduction expressions, required for proper
1992 /// codegen of the clause. These expressions are binary expressions or
1993 /// operator/custom reduction call that calculates new value from source
1994 /// helper expressions to destination helper expressions.
1995 void setReductionOps(ArrayRef<Expr *> ReductionOps);
1997 /// Get the list of helper reduction expressions.
1998 MutableArrayRef<Expr *> getReductionOps() {
1999 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
2001 ArrayRef<const Expr *> getReductionOps() const {
2002 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
2006 /// Creates clause with a list of variables \a VL.
2008 /// \param StartLoc Starting location of the clause.
2009 /// \param LParenLoc Location of '('.
2010 /// \param ColonLoc Location of ':'.
2011 /// \param EndLoc Ending location of the clause.
2012 /// \param VL The variables in the clause.
2013 /// \param QualifierLoc The nested-name qualifier with location information
2014 /// \param NameInfo The full name info for reduction identifier.
2015 /// \param Privates List of helper expressions for proper generation of
2017 /// \param LHSExprs List of helper expressions for proper generation of
2018 /// assignment operation required for copyprivate clause. This list represents
2019 /// LHSs of the reduction expressions.
2020 /// \param RHSExprs List of helper expressions for proper generation of
2021 /// assignment operation required for copyprivate clause. This list represents
2022 /// RHSs of the reduction expressions.
2023 /// Also, variables in these expressions are used for proper initialization of
2024 /// reduction copies.
2025 /// \param ReductionOps List of helper expressions that represents reduction
2028 /// LHSExprs binop RHSExprs;
2029 /// operator binop(LHSExpr, RHSExpr);
2030 /// <CutomReduction>(LHSExpr, RHSExpr);
2032 /// Required for proper codegen of final reduction operation performed by the
2033 /// reduction clause.
2034 /// \param PreInit Statement that must be executed before entering the OpenMP
2035 /// region with this clause.
2036 /// \param PostUpdate Expression that must be executed after exit from the
2037 /// OpenMP region with this clause.
2039 static OMPTaskReductionClause *
2040 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2041 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2042 NestedNameSpecifierLoc QualifierLoc,
2043 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
2044 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
2045 ArrayRef<Expr *> ReductionOps, Stmt *PreInit, Expr *PostUpdate);
2047 /// Creates an empty clause with the place for \a N variables.
2049 /// \param C AST context.
2050 /// \param N The number of variables.
2052 static OMPTaskReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
2054 /// Gets location of ':' symbol in clause.
2055 SourceLocation getColonLoc() const { return ColonLoc; }
2056 /// Gets the name info for specified reduction identifier.
2057 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
2058 /// Gets the nested name specifier.
2059 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
2061 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2062 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2063 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2064 typedef llvm::iterator_range<helper_expr_const_iterator>
2065 helper_expr_const_range;
2067 helper_expr_const_range privates() const {
2068 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
2070 helper_expr_range privates() {
2071 return helper_expr_range(getPrivates().begin(), getPrivates().end());
2073 helper_expr_const_range lhs_exprs() const {
2074 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
2076 helper_expr_range lhs_exprs() {
2077 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
2079 helper_expr_const_range rhs_exprs() const {
2080 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
2082 helper_expr_range rhs_exprs() {
2083 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
2085 helper_expr_const_range reduction_ops() const {
2086 return helper_expr_const_range(getReductionOps().begin(),
2087 getReductionOps().end());
2089 helper_expr_range reduction_ops() {
2090 return helper_expr_range(getReductionOps().begin(),
2091 getReductionOps().end());
2094 child_range children() {
2095 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2096 reinterpret_cast<Stmt **>(varlist_end()));
2099 static bool classof(const OMPClause *T) {
2100 return T->getClauseKind() == OMPC_task_reduction;
2104 /// \brief This represents clause 'linear' in the '#pragma omp ...'
2108 /// #pragma omp simd linear(a,b : 2)
2110 /// In this example directive '#pragma omp simd' has clause 'linear'
2111 /// with variables 'a', 'b' and linear step '2'.
2113 class OMPLinearClause final
2114 : public OMPVarListClause<OMPLinearClause>,
2115 public OMPClauseWithPostUpdate,
2116 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
2117 friend TrailingObjects;
2118 friend OMPVarListClause;
2119 friend class OMPClauseReader;
2120 /// \brief Modifier of 'linear' clause.
2121 OpenMPLinearClauseKind Modifier;
2122 /// \brief Location of linear modifier if any.
2123 SourceLocation ModifierLoc;
2124 /// \brief Location of ':'.
2125 SourceLocation ColonLoc;
2127 /// \brief Sets the linear step for clause.
2128 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
2130 /// \brief Sets the expression to calculate linear step for clause.
2131 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
2133 /// \brief Build 'linear' clause with given number of variables \a NumVars.
2135 /// \param StartLoc Starting location of the clause.
2136 /// \param LParenLoc Location of '('.
2137 /// \param ColonLoc Location of ':'.
2138 /// \param EndLoc Ending location of the clause.
2139 /// \param NumVars Number of variables.
2141 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2142 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2143 SourceLocation ColonLoc, SourceLocation EndLoc,
2145 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
2147 OMPClauseWithPostUpdate(this), Modifier(Modifier),
2148 ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
2150 /// \brief Build an empty clause.
2152 /// \param NumVars Number of variables.
2154 explicit OMPLinearClause(unsigned NumVars)
2155 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
2156 SourceLocation(), SourceLocation(),
2158 OMPClauseWithPostUpdate(this), Modifier(OMPC_LINEAR_val), ModifierLoc(),
2161 /// \brief Gets the list of initial values for linear variables.
2163 /// There are NumVars expressions with initial values allocated after the
2164 /// varlist, they are followed by NumVars update expressions (used to update
2165 /// the linear variable's value on current iteration) and they are followed by
2166 /// NumVars final expressions (used to calculate the linear variable's
2167 /// value after the loop body). After these lists, there are 2 helper
2168 /// expressions - linear step and a helper to calculate it before the
2169 /// loop body (used when the linear step is not constant):
2171 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
2172 /// Finals[]; Step; CalcStep; }
2174 MutableArrayRef<Expr *> getPrivates() {
2175 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2177 ArrayRef<const Expr *> getPrivates() const {
2178 return llvm::makeArrayRef(varlist_end(), varlist_size());
2181 MutableArrayRef<Expr *> getInits() {
2182 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
2184 ArrayRef<const Expr *> getInits() const {
2185 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
2188 /// \brief Sets the list of update expressions for linear variables.
2189 MutableArrayRef<Expr *> getUpdates() {
2190 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
2192 ArrayRef<const Expr *> getUpdates() const {
2193 return llvm::makeArrayRef(getInits().end(), varlist_size());
2196 /// \brief Sets the list of final update expressions for linear variables.
2197 MutableArrayRef<Expr *> getFinals() {
2198 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
2200 ArrayRef<const Expr *> getFinals() const {
2201 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
2204 /// \brief Sets the list of the copies of original linear variables.
2205 /// \param PL List of expressions.
2206 void setPrivates(ArrayRef<Expr *> PL);
2208 /// \brief Sets the list of the initial values for linear variables.
2209 /// \param IL List of expressions.
2210 void setInits(ArrayRef<Expr *> IL);
2213 /// \brief Creates clause with a list of variables \a VL and a linear step
2216 /// \param C AST Context.
2217 /// \param StartLoc Starting location of the clause.
2218 /// \param LParenLoc Location of '('.
2219 /// \param Modifier Modifier of 'linear' clause.
2220 /// \param ModifierLoc Modifier location.
2221 /// \param ColonLoc Location of ':'.
2222 /// \param EndLoc Ending location of the clause.
2223 /// \param VL List of references to the variables.
2224 /// \param PL List of private copies of original variables.
2225 /// \param IL List of initial values for the variables.
2226 /// \param Step Linear step.
2227 /// \param CalcStep Calculation of the linear step.
2228 /// \param PreInit Statement that must be executed before entering the OpenMP
2229 /// region with this clause.
2230 /// \param PostUpdate Expression that must be executed after exit from the
2231 /// OpenMP region with this clause.
2232 static OMPLinearClause *
2233 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2234 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
2235 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
2236 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep,
2237 Stmt *PreInit, Expr *PostUpdate);
2239 /// \brief Creates an empty clause with the place for \a NumVars variables.
2241 /// \param C AST context.
2242 /// \param NumVars Number of variables.
2244 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2246 /// \brief Set modifier.
2247 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
2248 /// \brief Return modifier.
2249 OpenMPLinearClauseKind getModifier() const { return Modifier; }
2251 /// \brief Set modifier location.
2252 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
2253 /// \brief Return modifier location.
2254 SourceLocation getModifierLoc() const { return ModifierLoc; }
2256 /// \brief Sets the location of ':'.
2257 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2258 /// \brief Returns the location of ':'.
2259 SourceLocation getColonLoc() const { return ColonLoc; }
2261 /// \brief Returns linear step.
2262 Expr *getStep() { return *(getFinals().end()); }
2263 /// \brief Returns linear step.
2264 const Expr *getStep() const { return *(getFinals().end()); }
2265 /// \brief Returns expression to calculate linear step.
2266 Expr *getCalcStep() { return *(getFinals().end() + 1); }
2267 /// \brief Returns expression to calculate linear step.
2268 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
2270 /// \brief Sets the list of update expressions for linear variables.
2271 /// \param UL List of expressions.
2272 void setUpdates(ArrayRef<Expr *> UL);
2274 /// \brief Sets the list of final update expressions for linear variables.
2275 /// \param FL List of expressions.
2276 void setFinals(ArrayRef<Expr *> FL);
2278 typedef MutableArrayRef<Expr *>::iterator privates_iterator;
2279 typedef ArrayRef<const Expr *>::iterator privates_const_iterator;
2280 typedef llvm::iterator_range<privates_iterator> privates_range;
2281 typedef llvm::iterator_range<privates_const_iterator> privates_const_range;
2283 privates_range privates() {
2284 return privates_range(getPrivates().begin(), getPrivates().end());
2286 privates_const_range privates() const {
2287 return privates_const_range(getPrivates().begin(), getPrivates().end());
2290 typedef MutableArrayRef<Expr *>::iterator inits_iterator;
2291 typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
2292 typedef llvm::iterator_range<inits_iterator> inits_range;
2293 typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
2295 inits_range inits() {
2296 return inits_range(getInits().begin(), getInits().end());
2298 inits_const_range inits() const {
2299 return inits_const_range(getInits().begin(), getInits().end());
2302 typedef MutableArrayRef<Expr *>::iterator updates_iterator;
2303 typedef ArrayRef<const Expr *>::iterator updates_const_iterator;
2304 typedef llvm::iterator_range<updates_iterator> updates_range;
2305 typedef llvm::iterator_range<updates_const_iterator> updates_const_range;
2307 updates_range updates() {
2308 return updates_range(getUpdates().begin(), getUpdates().end());
2310 updates_const_range updates() const {
2311 return updates_const_range(getUpdates().begin(), getUpdates().end());
2314 typedef MutableArrayRef<Expr *>::iterator finals_iterator;
2315 typedef ArrayRef<const Expr *>::iterator finals_const_iterator;
2316 typedef llvm::iterator_range<finals_iterator> finals_range;
2317 typedef llvm::iterator_range<finals_const_iterator> finals_const_range;
2319 finals_range finals() {
2320 return finals_range(getFinals().begin(), getFinals().end());
2322 finals_const_range finals() const {
2323 return finals_const_range(getFinals().begin(), getFinals().end());
2326 child_range children() {
2327 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2328 reinterpret_cast<Stmt **>(varlist_end()));
2331 static bool classof(const OMPClause *T) {
2332 return T->getClauseKind() == OMPC_linear;
2336 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
2340 /// #pragma omp simd aligned(a,b : 8)
2342 /// In this example directive '#pragma omp simd' has clause 'aligned'
2343 /// with variables 'a', 'b' and alignment '8'.
2345 class OMPAlignedClause final
2346 : public OMPVarListClause<OMPAlignedClause>,
2347 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
2348 friend TrailingObjects;
2349 friend OMPVarListClause;
2350 friend class OMPClauseReader;
2351 /// \brief Location of ':'.
2352 SourceLocation ColonLoc;
2354 /// \brief Sets the alignment for clause.
2355 void setAlignment(Expr *A) { *varlist_end() = A; }
2357 /// \brief Build 'aligned' clause with given number of variables \a NumVars.
2359 /// \param StartLoc Starting location of the clause.
2360 /// \param LParenLoc Location of '('.
2361 /// \param ColonLoc Location of ':'.
2362 /// \param EndLoc Ending location of the clause.
2363 /// \param NumVars Number of variables.
2365 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2366 SourceLocation ColonLoc, SourceLocation EndLoc,
2368 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
2370 ColonLoc(ColonLoc) {}
2372 /// \brief Build an empty clause.
2374 /// \param NumVars Number of variables.
2376 explicit OMPAlignedClause(unsigned NumVars)
2377 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
2378 SourceLocation(), SourceLocation(),
2380 ColonLoc(SourceLocation()) {}
2383 /// \brief Creates clause with a list of variables \a VL and alignment \a A.
2385 /// \param C AST Context.
2386 /// \param StartLoc Starting location of the clause.
2387 /// \param LParenLoc Location of '('.
2388 /// \param ColonLoc Location of ':'.
2389 /// \param EndLoc Ending location of the clause.
2390 /// \param VL List of references to the variables.
2391 /// \param A Alignment.
2392 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2393 SourceLocation LParenLoc,
2394 SourceLocation ColonLoc,
2395 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2398 /// \brief Creates an empty clause with the place for \a NumVars variables.
2400 /// \param C AST context.
2401 /// \param NumVars Number of variables.
2403 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2405 /// \brief Sets the location of ':'.
2406 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2407 /// \brief Returns the location of ':'.
2408 SourceLocation getColonLoc() const { return ColonLoc; }
2410 /// \brief Returns alignment.
2411 Expr *getAlignment() { return *varlist_end(); }
2412 /// \brief Returns alignment.
2413 const Expr *getAlignment() const { return *varlist_end(); }
2415 child_range children() {
2416 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2417 reinterpret_cast<Stmt **>(varlist_end()));
2420 static bool classof(const OMPClause *T) {
2421 return T->getClauseKind() == OMPC_aligned;
2425 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
2428 /// #pragma omp parallel copyin(a,b)
2430 /// In this example directive '#pragma omp parallel' has clause 'copyin'
2431 /// with the variables 'a' and 'b'.
2433 class OMPCopyinClause final
2434 : public OMPVarListClause<OMPCopyinClause>,
2435 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
2436 // Class has 3 additional tail allocated arrays:
2437 // 1. List of helper expressions for proper generation of assignment operation
2438 // required for copyin clause. This list represents sources.
2439 // 2. List of helper expressions for proper generation of assignment operation
2440 // required for copyin clause. This list represents destinations.
2441 // 3. List of helper expressions that represents assignment operation:
2443 // DstExprs = SrcExprs;
2445 // Required for proper codegen of propagation of master's thread values of
2446 // threadprivate variables to local instances of that variables in other
2447 // implicit threads.
2449 friend TrailingObjects;
2450 friend OMPVarListClause;
2451 friend class OMPClauseReader;
2452 /// \brief Build clause with number of variables \a N.
2454 /// \param StartLoc Starting location of the clause.
2455 /// \param LParenLoc Location of '('.
2456 /// \param EndLoc Ending location of the clause.
2457 /// \param N Number of the variables in the clause.
2459 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2460 SourceLocation EndLoc, unsigned N)
2461 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
2464 /// \brief Build an empty clause.
2466 /// \param N Number of variables.
2468 explicit OMPCopyinClause(unsigned N)
2469 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
2470 SourceLocation(), SourceLocation(),
2473 /// \brief Set list of helper expressions, required for proper codegen of the
2474 /// clause. These expressions represent source expression in the final
2475 /// assignment statement performed by the copyin clause.
2476 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2478 /// \brief Get the list of helper source expressions.
2479 MutableArrayRef<Expr *> getSourceExprs() {
2480 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2482 ArrayRef<const Expr *> getSourceExprs() const {
2483 return llvm::makeArrayRef(varlist_end(), varlist_size());
2486 /// \brief Set list of helper expressions, required for proper codegen of the
2487 /// clause. These expressions represent destination expression in the final
2488 /// assignment statement performed by the copyin clause.
2489 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2491 /// \brief Get the list of helper destination expressions.
2492 MutableArrayRef<Expr *> getDestinationExprs() {
2493 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2495 ArrayRef<const Expr *> getDestinationExprs() const {
2496 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2499 /// \brief Set list of helper assignment expressions, required for proper
2500 /// codegen of the clause. These expressions are assignment expressions that
2501 /// assign source helper expressions to destination helper expressions
2502 /// correspondingly.
2503 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2505 /// \brief Get the list of helper assignment expressions.
2506 MutableArrayRef<Expr *> getAssignmentOps() {
2507 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2509 ArrayRef<const Expr *> getAssignmentOps() const {
2510 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2514 /// \brief Creates clause with a list of variables \a VL.
2516 /// \param C AST context.
2517 /// \param StartLoc Starting location of the clause.
2518 /// \param LParenLoc Location of '('.
2519 /// \param EndLoc Ending location of the clause.
2520 /// \param VL List of references to the variables.
2521 /// \param SrcExprs List of helper expressions for proper generation of
2522 /// assignment operation required for copyin clause. This list represents
2524 /// \param DstExprs List of helper expressions for proper generation of
2525 /// assignment operation required for copyin clause. This list represents
2527 /// \param AssignmentOps List of helper expressions that represents assignment
2530 /// DstExprs = SrcExprs;
2532 /// Required for proper codegen of propagation of master's thread values of
2533 /// threadprivate variables to local instances of that variables in other
2534 /// implicit threads.
2536 static OMPCopyinClause *
2537 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2538 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2539 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2540 /// \brief Creates an empty clause with \a N variables.
2542 /// \param C AST context.
2543 /// \param N The number of variables.
2545 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
2547 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2548 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2549 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2550 typedef llvm::iterator_range<helper_expr_const_iterator>
2551 helper_expr_const_range;
2553 helper_expr_const_range source_exprs() const {
2554 return helper_expr_const_range(getSourceExprs().begin(),
2555 getSourceExprs().end());
2557 helper_expr_range source_exprs() {
2558 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2560 helper_expr_const_range destination_exprs() const {
2561 return helper_expr_const_range(getDestinationExprs().begin(),
2562 getDestinationExprs().end());
2564 helper_expr_range destination_exprs() {
2565 return helper_expr_range(getDestinationExprs().begin(),
2566 getDestinationExprs().end());
2568 helper_expr_const_range assignment_ops() const {
2569 return helper_expr_const_range(getAssignmentOps().begin(),
2570 getAssignmentOps().end());
2572 helper_expr_range assignment_ops() {
2573 return helper_expr_range(getAssignmentOps().begin(),
2574 getAssignmentOps().end());
2577 child_range children() {
2578 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2579 reinterpret_cast<Stmt **>(varlist_end()));
2582 static bool classof(const OMPClause *T) {
2583 return T->getClauseKind() == OMPC_copyin;
2587 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
2591 /// #pragma omp single copyprivate(a,b)
2593 /// In this example directive '#pragma omp single' has clause 'copyprivate'
2594 /// with the variables 'a' and 'b'.
2596 class OMPCopyprivateClause final
2597 : public OMPVarListClause<OMPCopyprivateClause>,
2598 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
2599 friend TrailingObjects;
2600 friend OMPVarListClause;
2601 friend class OMPClauseReader;
2602 /// \brief Build clause with number of variables \a N.
2604 /// \param StartLoc Starting location of the clause.
2605 /// \param LParenLoc Location of '('.
2606 /// \param EndLoc Ending location of the clause.
2607 /// \param N Number of the variables in the clause.
2609 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2610 SourceLocation EndLoc, unsigned N)
2611 : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
2612 LParenLoc, EndLoc, N) {}
2614 /// \brief Build an empty clause.
2616 /// \param N Number of variables.
2618 explicit OMPCopyprivateClause(unsigned N)
2619 : OMPVarListClause<OMPCopyprivateClause>(
2620 OMPC_copyprivate, SourceLocation(), SourceLocation(),
2621 SourceLocation(), N) {}
2623 /// \brief Set list of helper expressions, required for proper codegen of the
2624 /// clause. These expressions represent source expression in the final
2625 /// assignment statement performed by the copyprivate clause.
2626 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2628 /// \brief Get the list of helper source expressions.
2629 MutableArrayRef<Expr *> getSourceExprs() {
2630 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2632 ArrayRef<const Expr *> getSourceExprs() const {
2633 return llvm::makeArrayRef(varlist_end(), varlist_size());
2636 /// \brief Set list of helper expressions, required for proper codegen of the
2637 /// clause. These expressions represent destination expression in the final
2638 /// assignment statement performed by the copyprivate clause.
2639 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2641 /// \brief Get the list of helper destination expressions.
2642 MutableArrayRef<Expr *> getDestinationExprs() {
2643 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2645 ArrayRef<const Expr *> getDestinationExprs() const {
2646 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2649 /// \brief Set list of helper assignment expressions, required for proper
2650 /// codegen of the clause. These expressions are assignment expressions that
2651 /// assign source helper expressions to destination helper expressions
2652 /// correspondingly.
2653 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2655 /// \brief Get the list of helper assignment expressions.
2656 MutableArrayRef<Expr *> getAssignmentOps() {
2657 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2659 ArrayRef<const Expr *> getAssignmentOps() const {
2660 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2664 /// \brief Creates clause with a list of variables \a VL.
2666 /// \param C AST context.
2667 /// \param StartLoc Starting location of the clause.
2668 /// \param LParenLoc Location of '('.
2669 /// \param EndLoc Ending location of the clause.
2670 /// \param VL List of references to the variables.
2671 /// \param SrcExprs List of helper expressions for proper generation of
2672 /// assignment operation required for copyprivate clause. This list represents
2674 /// \param DstExprs List of helper expressions for proper generation of
2675 /// assignment operation required for copyprivate clause. This list represents
2677 /// \param AssignmentOps List of helper expressions that represents assignment
2680 /// DstExprs = SrcExprs;
2682 /// Required for proper codegen of final assignment performed by the
2683 /// copyprivate clause.
2685 static OMPCopyprivateClause *
2686 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2687 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2688 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2689 /// \brief Creates an empty clause with \a N variables.
2691 /// \param C AST context.
2692 /// \param N The number of variables.
2694 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2696 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2697 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2698 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2699 typedef llvm::iterator_range<helper_expr_const_iterator>
2700 helper_expr_const_range;
2702 helper_expr_const_range source_exprs() const {
2703 return helper_expr_const_range(getSourceExprs().begin(),
2704 getSourceExprs().end());
2706 helper_expr_range source_exprs() {
2707 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2709 helper_expr_const_range destination_exprs() const {
2710 return helper_expr_const_range(getDestinationExprs().begin(),
2711 getDestinationExprs().end());
2713 helper_expr_range destination_exprs() {
2714 return helper_expr_range(getDestinationExprs().begin(),
2715 getDestinationExprs().end());
2717 helper_expr_const_range assignment_ops() const {
2718 return helper_expr_const_range(getAssignmentOps().begin(),
2719 getAssignmentOps().end());
2721 helper_expr_range assignment_ops() {
2722 return helper_expr_range(getAssignmentOps().begin(),
2723 getAssignmentOps().end());
2726 child_range children() {
2727 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2728 reinterpret_cast<Stmt **>(varlist_end()));
2731 static bool classof(const OMPClause *T) {
2732 return T->getClauseKind() == OMPC_copyprivate;
2736 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
2738 /// This clause does not exist by itself, it can be only as a part of 'omp
2739 /// flush' directive. This clause is introduced to keep the original structure
2740 /// of \a OMPExecutableDirective class and its derivatives and to use the
2741 /// existing infrastructure of clauses with the list of variables.
2744 /// #pragma omp flush(a,b)
2746 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
2747 /// with the variables 'a' and 'b'.
2749 class OMPFlushClause final
2750 : public OMPVarListClause<OMPFlushClause>,
2751 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
2752 friend TrailingObjects;
2753 friend OMPVarListClause;
2754 /// \brief Build clause with number of variables \a N.
2756 /// \param StartLoc Starting location of the clause.
2757 /// \param LParenLoc Location of '('.
2758 /// \param EndLoc Ending location of the clause.
2759 /// \param N Number of the variables in the clause.
2761 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2762 SourceLocation EndLoc, unsigned N)
2763 : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
2766 /// \brief Build an empty clause.
2768 /// \param N Number of variables.
2770 explicit OMPFlushClause(unsigned N)
2771 : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
2772 SourceLocation(), SourceLocation(),
2776 /// \brief Creates clause with a list of variables \a VL.
2778 /// \param C AST context.
2779 /// \param StartLoc Starting location of the clause.
2780 /// \param LParenLoc Location of '('.
2781 /// \param EndLoc Ending location of the clause.
2782 /// \param VL List of references to the variables.
2784 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
2785 SourceLocation LParenLoc, SourceLocation EndLoc,
2786 ArrayRef<Expr *> VL);
2787 /// \brief Creates an empty clause with \a N variables.
2789 /// \param C AST context.
2790 /// \param N The number of variables.
2792 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
2794 child_range children() {
2795 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2796 reinterpret_cast<Stmt **>(varlist_end()));
2799 static bool classof(const OMPClause *T) {
2800 return T->getClauseKind() == OMPC_flush;
2804 /// \brief This represents implicit clause 'depend' for the '#pragma omp task'
2808 /// #pragma omp task depend(in:a,b)
2810 /// In this example directive '#pragma omp task' with clause 'depend' with the
2811 /// variables 'a' and 'b' with dependency 'in'.
2813 class OMPDependClause final
2814 : public OMPVarListClause<OMPDependClause>,
2815 private llvm::TrailingObjects<OMPDependClause, Expr *> {
2816 friend TrailingObjects;
2817 friend OMPVarListClause;
2818 friend class OMPClauseReader;
2819 /// \brief Dependency type (one of in, out, inout).
2820 OpenMPDependClauseKind DepKind;
2821 /// \brief Dependency type location.
2822 SourceLocation DepLoc;
2823 /// \brief Colon location.
2824 SourceLocation ColonLoc;
2825 /// \brief Build clause with number of variables \a N.
2827 /// \param StartLoc Starting location of the clause.
2828 /// \param LParenLoc Location of '('.
2829 /// \param EndLoc Ending location of the clause.
2830 /// \param N Number of the variables in the clause.
2832 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2833 SourceLocation EndLoc, unsigned N)
2834 : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
2836 DepKind(OMPC_DEPEND_unknown) {}
2838 /// \brief Build an empty clause.
2840 /// \param N Number of variables.
2842 explicit OMPDependClause(unsigned N)
2843 : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
2844 SourceLocation(), SourceLocation(),
2846 DepKind(OMPC_DEPEND_unknown) {}
2847 /// \brief Set dependency kind.
2848 void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
2850 /// \brief Set dependency kind and its location.
2851 void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
2853 /// \brief Set colon location.
2854 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2857 /// \brief Creates clause with a list of variables \a VL.
2859 /// \param C AST context.
2860 /// \param StartLoc Starting location of the clause.
2861 /// \param LParenLoc Location of '('.
2862 /// \param EndLoc Ending location of the clause.
2863 /// \param DepKind Dependency type.
2864 /// \param DepLoc Location of the dependency type.
2865 /// \param ColonLoc Colon location.
2866 /// \param VL List of references to the variables.
2867 static OMPDependClause *
2868 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2869 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
2870 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL);
2871 /// \brief Creates an empty clause with \a N variables.
2873 /// \param C AST context.
2874 /// \param N The number of variables.
2876 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N);
2878 /// \brief Get dependency type.
2879 OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
2880 /// \brief Get dependency type location.
2881 SourceLocation getDependencyLoc() const { return DepLoc; }
2882 /// \brief Get colon location.
2883 SourceLocation getColonLoc() const { return ColonLoc; }
2885 /// Set the loop counter value for the depend clauses with 'sink|source' kind
2886 /// of dependency. Required for codegen.
2887 void setCounterValue(Expr *V);
2888 /// Get the loop counter value.
2889 Expr *getCounterValue();
2890 /// Get the loop counter value.
2891 const Expr *getCounterValue() const;
2893 child_range children() {
2894 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2895 reinterpret_cast<Stmt **>(varlist_end()));
2898 static bool classof(const OMPClause *T) {
2899 return T->getClauseKind() == OMPC_depend;
2903 /// \brief This represents 'device' clause in the '#pragma omp ...'
2907 /// #pragma omp target device(a)
2909 /// In this example directive '#pragma omp target' has clause 'device'
2910 /// with single expression 'a'.
2912 class OMPDeviceClause : public OMPClause {
2913 friend class OMPClauseReader;
2914 /// \brief Location of '('.
2915 SourceLocation LParenLoc;
2916 /// \brief Device number.
2918 /// \brief Set the device number.
2920 /// \param E Device number.
2922 void setDevice(Expr *E) { Device = E; }
2925 /// \brief Build 'device' clause.
2927 /// \param E Expression associated with this clause.
2928 /// \param StartLoc Starting location of the clause.
2929 /// \param LParenLoc Location of '('.
2930 /// \param EndLoc Ending location of the clause.
2932 OMPDeviceClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2933 SourceLocation EndLoc)
2934 : OMPClause(OMPC_device, StartLoc, EndLoc), LParenLoc(LParenLoc),
2937 /// \brief Build an empty clause.
2940 : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
2941 LParenLoc(SourceLocation()), Device(nullptr) {}
2942 /// \brief Sets the location of '('.
2943 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2944 /// \brief Returns the location of '('.
2945 SourceLocation getLParenLoc() const { return LParenLoc; }
2946 /// \brief Return device number.
2947 Expr *getDevice() { return cast<Expr>(Device); }
2948 /// \brief Return device number.
2949 Expr *getDevice() const { return cast<Expr>(Device); }
2951 static bool classof(const OMPClause *T) {
2952 return T->getClauseKind() == OMPC_device;
2955 child_range children() { return child_range(&Device, &Device + 1); }
2958 /// \brief This represents 'threads' clause in the '#pragma omp ...' directive.
2961 /// #pragma omp ordered threads
2963 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
2965 class OMPThreadsClause : public OMPClause {
2967 /// \brief Build 'threads' clause.
2969 /// \param StartLoc Starting location of the clause.
2970 /// \param EndLoc Ending location of the clause.
2972 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
2973 : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
2975 /// \brief Build an empty clause.
2978 : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
2980 static bool classof(const OMPClause *T) {
2981 return T->getClauseKind() == OMPC_threads;
2984 child_range children() {
2985 return child_range(child_iterator(), child_iterator());
2989 /// \brief This represents 'simd' clause in the '#pragma omp ...' directive.
2992 /// #pragma omp ordered simd
2994 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
2996 class OMPSIMDClause : public OMPClause {
2998 /// \brief Build 'simd' clause.
3000 /// \param StartLoc Starting location of the clause.
3001 /// \param EndLoc Ending location of the clause.
3003 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
3004 : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
3006 /// \brief Build an empty clause.
3008 OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
3010 static bool classof(const OMPClause *T) {
3011 return T->getClauseKind() == OMPC_simd;
3014 child_range children() {
3015 return child_range(child_iterator(), child_iterator());
3019 /// \brief Struct that defines common infrastructure to handle mappable
3020 /// expressions used in OpenMP clauses.
3021 class OMPClauseMappableExprCommon {
3023 // \brief Class that represents a component of a mappable expression. E.g.
3024 // for an expression S.a, the first component is a declaration reference
3025 // expression associated with 'S' and the second is a member expression
3026 // associated with the field declaration 'a'. If the expression is an array
3027 // subscript it may not have any associated declaration. In that case the
3028 // associated declaration is set to nullptr.
3029 class MappableComponent {
3030 // \brief Expression associated with the component.
3031 Expr *AssociatedExpression = nullptr;
3032 // \brief Declaration associated with the declaration. If the component does
3033 // not have a declaration (e.g. array subscripts or section), this is set to
3035 ValueDecl *AssociatedDeclaration = nullptr;
3038 explicit MappableComponent() {}
3039 explicit MappableComponent(Expr *AssociatedExpression,
3040 ValueDecl *AssociatedDeclaration)
3041 : AssociatedExpression(AssociatedExpression),
3042 AssociatedDeclaration(
3043 AssociatedDeclaration
3044 ? cast<ValueDecl>(AssociatedDeclaration->getCanonicalDecl())
3047 Expr *getAssociatedExpression() const { return AssociatedExpression; }
3048 ValueDecl *getAssociatedDeclaration() const {
3049 return AssociatedDeclaration;
3053 // \brief List of components of an expression. This first one is the whole
3054 // expression and the last one is the base expression.
3055 typedef SmallVector<MappableComponent, 8> MappableExprComponentList;
3056 typedef ArrayRef<MappableComponent> MappableExprComponentListRef;
3058 // \brief List of all component lists associated to the same base declaration.
3059 // E.g. if both 'S.a' and 'S.b' are a mappable expressions, each will have
3060 // their component list but the same base declaration 'S'.
3061 typedef SmallVector<MappableExprComponentList, 8> MappableExprComponentLists;
3062 typedef ArrayRef<MappableExprComponentList> MappableExprComponentListsRef;
3065 // \brief Return the total number of elements in a list of component lists.
3067 getComponentsTotalNumber(MappableExprComponentListsRef ComponentLists);
3069 // \brief Return the total number of elements in a list of declarations. All
3070 // declarations are expected to be canonical.
3072 getUniqueDeclarationsTotalNumber(ArrayRef<ValueDecl *> Declarations);
3075 /// \brief This represents clauses with a list of expressions that are mappable.
3076 /// Examples of these clauses are 'map' in
3077 /// '#pragma omp target [enter|exit] [data]...' directives, and 'to' and 'from
3078 /// in '#pragma omp target update...' directives.
3080 class OMPMappableExprListClause : public OMPVarListClause<T>,
3081 public OMPClauseMappableExprCommon {
3082 friend class OMPClauseReader;
3084 /// \brief Number of unique declarations in this clause.
3085 unsigned NumUniqueDeclarations;
3087 /// \brief Number of component lists in this clause.
3088 unsigned NumComponentLists;
3090 /// \brief Total number of components in this clause.
3091 unsigned NumComponents;
3094 /// \brief Get the unique declarations that are in the trailing objects of the
3096 MutableArrayRef<ValueDecl *> getUniqueDeclsRef() {
3097 return MutableArrayRef<ValueDecl *>(
3098 static_cast<T *>(this)->template getTrailingObjects<ValueDecl *>(),
3099 NumUniqueDeclarations);
3102 /// \brief Get the unique declarations that are in the trailing objects of the
3104 ArrayRef<ValueDecl *> getUniqueDeclsRef() const {
3105 return ArrayRef<ValueDecl *>(
3106 static_cast<const T *>(this)
3107 ->template getTrailingObjects<ValueDecl *>(),
3108 NumUniqueDeclarations);
3111 /// \brief Set the unique declarations that are in the trailing objects of the
3113 void setUniqueDecls(ArrayRef<ValueDecl *> UDs) {
3114 assert(UDs.size() == NumUniqueDeclarations &&
3115 "Unexpected amount of unique declarations.");
3116 std::copy(UDs.begin(), UDs.end(), getUniqueDeclsRef().begin());
3119 /// \brief Get the number of lists per declaration that are in the trailing
3120 /// objects of the class.
3121 MutableArrayRef<unsigned> getDeclNumListsRef() {
3122 return MutableArrayRef<unsigned>(
3123 static_cast<T *>(this)->template getTrailingObjects<unsigned>(),
3124 NumUniqueDeclarations);
3127 /// \brief Get the number of lists per declaration that are in the trailing
3128 /// objects of the class.
3129 ArrayRef<unsigned> getDeclNumListsRef() const {
3130 return ArrayRef<unsigned>(
3131 static_cast<const T *>(this)->template getTrailingObjects<unsigned>(),
3132 NumUniqueDeclarations);
3135 /// \brief Set the number of lists per declaration that are in the trailing
3136 /// objects of the class.
3137 void setDeclNumLists(ArrayRef<unsigned> DNLs) {
3138 assert(DNLs.size() == NumUniqueDeclarations &&
3139 "Unexpected amount of list numbers.");
3140 std::copy(DNLs.begin(), DNLs.end(), getDeclNumListsRef().begin());
3143 /// \brief Get the cumulative component lists sizes that are in the trailing
3144 /// objects of the class. They are appended after the number of lists.
3145 MutableArrayRef<unsigned> getComponentListSizesRef() {
3146 return MutableArrayRef<unsigned>(
3147 static_cast<T *>(this)->template getTrailingObjects<unsigned>() +
3148 NumUniqueDeclarations,
3152 /// \brief Get the cumulative component lists sizes that are in the trailing
3153 /// objects of the class. They are appended after the number of lists.
3154 ArrayRef<unsigned> getComponentListSizesRef() const {
3155 return ArrayRef<unsigned>(
3156 static_cast<const T *>(this)->template getTrailingObjects<unsigned>() +
3157 NumUniqueDeclarations,
3161 /// \brief Set the cumulative component lists sizes that are in the trailing
3162 /// objects of the class.
3163 void setComponentListSizes(ArrayRef<unsigned> CLSs) {
3164 assert(CLSs.size() == NumComponentLists &&
3165 "Unexpected amount of component lists.");
3166 std::copy(CLSs.begin(), CLSs.end(), getComponentListSizesRef().begin());
3169 /// \brief Get the components that are in the trailing objects of the class.
3170 MutableArrayRef<MappableComponent> getComponentsRef() {
3171 return MutableArrayRef<MappableComponent>(
3172 static_cast<T *>(this)
3173 ->template getTrailingObjects<MappableComponent>(),
3177 /// \brief Get the components that are in the trailing objects of the class.
3178 ArrayRef<MappableComponent> getComponentsRef() const {
3179 return ArrayRef<MappableComponent>(
3180 static_cast<const T *>(this)
3181 ->template getTrailingObjects<MappableComponent>(),
3185 /// \brief Set the components that are in the trailing objects of the class.
3186 /// This requires the list sizes so that it can also fill the original
3187 /// expressions, which are the first component of each list.
3188 void setComponents(ArrayRef<MappableComponent> Components,
3189 ArrayRef<unsigned> CLSs) {
3190 assert(Components.size() == NumComponents &&
3191 "Unexpected amount of component lists.");
3192 assert(CLSs.size() == NumComponentLists &&
3193 "Unexpected amount of list sizes.");
3194 std::copy(Components.begin(), Components.end(), getComponentsRef().begin());
3197 /// \brief Fill the clause information from the list of declarations and
3198 /// associated component lists.
3199 void setClauseInfo(ArrayRef<ValueDecl *> Declarations,
3200 MappableExprComponentListsRef ComponentLists) {
3201 // Perform some checks to make sure the data sizes are consistent with the
3202 // information available when the clause was created.
3203 assert(getUniqueDeclarationsTotalNumber(Declarations) ==
3204 NumUniqueDeclarations &&
3205 "Unexpected number of mappable expression info entries!");
3206 assert(getComponentsTotalNumber(ComponentLists) == NumComponents &&
3207 "Unexpected total number of components!");
3208 assert(Declarations.size() == ComponentLists.size() &&
3209 "Declaration and component lists size is not consistent!");
3210 assert(Declarations.size() == NumComponentLists &&
3211 "Unexpected declaration and component lists size!");
3213 // Organize the components by declaration and retrieve the original
3214 // expression. Original expressions are always the first component of the
3215 // mappable component list.
3216 llvm::MapVector<ValueDecl *, SmallVector<MappableExprComponentListRef, 8>>
3219 auto CI = ComponentLists.begin();
3220 for (auto DI = Declarations.begin(), DE = Declarations.end(); DI != DE;
3222 assert(!CI->empty() && "Invalid component list!");
3223 ComponentListMap[*DI].push_back(*CI);
3227 // Iterators of the target storage.
3228 auto UniqueDeclarations = getUniqueDeclsRef();
3229 auto UDI = UniqueDeclarations.begin();
3231 auto DeclNumLists = getDeclNumListsRef();
3232 auto DNLI = DeclNumLists.begin();
3234 auto ComponentListSizes = getComponentListSizesRef();
3235 auto CLSI = ComponentListSizes.begin();
3237 auto Components = getComponentsRef();
3238 auto CI = Components.begin();
3240 // Variable to compute the accumulation of the number of components.
3241 unsigned PrevSize = 0u;
3243 // Scan all the declarations and associated component lists.
3244 for (auto &M : ComponentListMap) {
3247 // The component lists.
3250 // Initialize the entry.
3257 // Obtain the cumulative sizes and concatenate all the components in the
3258 // reserved storage.
3260 // Accumulate with the previous size.
3261 PrevSize += C.size();
3267 // Append components after the current components iterator.
3268 CI = std::copy(C.begin(), C.end(), CI);
3273 /// \brief Build a clause for \a NumUniqueDeclarations declarations, \a
3274 /// NumComponentLists total component lists, and \a NumComponents total
3277 /// \param K Kind of the clause.
3278 /// \param StartLoc Starting location of the clause (the clause keyword).
3279 /// \param LParenLoc Location of '('.
3280 /// \param EndLoc Ending location of the clause.
3281 /// \param NumVars Number of expressions listed in the clause.
3282 /// \param NumUniqueDeclarations Number of unique base declarations in this
3284 /// \param NumComponentLists Number of component lists in this clause - one
3285 /// list for each expression in the clause.
3286 /// \param NumComponents Total number of expression components in the clause.
3288 OMPMappableExprListClause(OpenMPClauseKind K, SourceLocation StartLoc,
3289 SourceLocation LParenLoc, SourceLocation EndLoc,
3290 unsigned NumVars, unsigned NumUniqueDeclarations,
3291 unsigned NumComponentLists, unsigned NumComponents)
3292 : OMPVarListClause<T>(K, StartLoc, LParenLoc, EndLoc, NumVars),
3293 NumUniqueDeclarations(NumUniqueDeclarations),
3294 NumComponentLists(NumComponentLists), NumComponents(NumComponents) {}
3297 /// \brief Return the number of unique base declarations in this clause.
3298 unsigned getUniqueDeclarationsNum() const { return NumUniqueDeclarations; }
3299 /// \brief Return the number of lists derived from the clause expressions.
3300 unsigned getTotalComponentListNum() const { return NumComponentLists; }
3301 /// \brief Return the total number of components in all lists derived from the
3303 unsigned getTotalComponentsNum() const { return NumComponents; }
3305 /// \brief Iterator that browse the components by lists. It also allows
3306 /// browsing components of a single declaration.
3307 class const_component_lists_iterator
3308 : public llvm::iterator_adaptor_base<
3309 const_component_lists_iterator,
3310 MappableExprComponentListRef::const_iterator,
3311 std::forward_iterator_tag, MappableComponent, ptrdiff_t,
3312 MappableComponent, MappableComponent> {
3313 // The declaration the iterator currently refers to.
3314 ArrayRef<ValueDecl *>::iterator DeclCur;
3316 // The list number associated with the current declaration.
3317 ArrayRef<unsigned>::iterator NumListsCur;
3319 // Remaining lists for the current declaration.
3320 unsigned RemainingLists;
3322 // The cumulative size of the previous list, or zero if there is no previous
3324 unsigned PrevListSize;
3326 // The cumulative sizes of the current list - it will delimit the remaining
3327 // range of interest.
3328 ArrayRef<unsigned>::const_iterator ListSizeCur;
3329 ArrayRef<unsigned>::const_iterator ListSizeEnd;
3331 // Iterator to the end of the components storage.
3332 MappableExprComponentListRef::const_iterator End;
3335 /// \brief Construct an iterator that scans all lists.
3336 explicit const_component_lists_iterator(
3337 ArrayRef<ValueDecl *> UniqueDecls, ArrayRef<unsigned> DeclsListNum,
3338 ArrayRef<unsigned> CumulativeListSizes,
3339 MappableExprComponentListRef Components)
3340 : const_component_lists_iterator::iterator_adaptor_base(
3341 Components.begin()),
3342 DeclCur(UniqueDecls.begin()), NumListsCur(DeclsListNum.begin()),
3343 RemainingLists(0u), PrevListSize(0u),
3344 ListSizeCur(CumulativeListSizes.begin()),
3345 ListSizeEnd(CumulativeListSizes.end()), End(Components.end()) {
3346 assert(UniqueDecls.size() == DeclsListNum.size() &&
3347 "Inconsistent number of declarations and list sizes!");
3348 if (!DeclsListNum.empty())
3349 RemainingLists = *NumListsCur;
3352 /// \brief Construct an iterator that scan lists for a given declaration \a
3354 explicit const_component_lists_iterator(
3355 const ValueDecl *Declaration, ArrayRef<ValueDecl *> UniqueDecls,
3356 ArrayRef<unsigned> DeclsListNum, ArrayRef<unsigned> CumulativeListSizes,
3357 MappableExprComponentListRef Components)
3358 : const_component_lists_iterator(UniqueDecls, DeclsListNum,
3359 CumulativeListSizes, Components) {
3361 // Look for the desired declaration. While we are looking for it, we
3362 // update the state so that we know the component where a given list
3364 for (; DeclCur != UniqueDecls.end(); ++DeclCur, ++NumListsCur) {
3365 if (*DeclCur == Declaration)
3368 assert(*NumListsCur > 0 && "No lists associated with declaration??");
3370 // Skip the lists associated with the current declaration, but save the
3371 // last list size that was skipped.
3372 std::advance(ListSizeCur, *NumListsCur - 1);
3373 PrevListSize = *ListSizeCur;
3377 // If we didn't find any declaration, advance the iterator to after the
3378 // last component and set remaining lists to zero.
3379 if (ListSizeCur == CumulativeListSizes.end()) {
3381 RemainingLists = 0u;
3385 // Set the remaining lists with the total number of lists of the current
3387 RemainingLists = *NumListsCur;
3389 // Adjust the list size end iterator to the end of the relevant range.
3390 ListSizeEnd = ListSizeCur;
3391 std::advance(ListSizeEnd, RemainingLists);
3393 // Given that the list sizes are cumulative, the index of the component
3394 // that start the list is the size of the previous list.
3395 std::advance(this->I, PrevListSize);
3398 // Return the array with the current list. The sizes are cumulative, so the
3399 // array size is the difference between the current size and previous one.
3400 std::pair<const ValueDecl *, MappableExprComponentListRef>
3402 assert(ListSizeCur != ListSizeEnd && "Invalid iterator!");
3403 return std::make_pair(
3405 MappableExprComponentListRef(&*this->I, *ListSizeCur - PrevListSize));
3407 std::pair<const ValueDecl *, MappableExprComponentListRef>
3408 operator->() const {
3412 // Skip the components of the current list.
3413 const_component_lists_iterator &operator++() {
3414 assert(ListSizeCur != ListSizeEnd && RemainingLists &&
3415 "Invalid iterator!");
3417 // If we don't have more lists just skip all the components. Otherwise,
3418 // advance the iterator by the number of components in the current list.
3419 if (std::next(ListSizeCur) == ListSizeEnd) {
3423 std::advance(this->I, *ListSizeCur - PrevListSize);
3424 PrevListSize = *ListSizeCur;
3426 // We are done with a declaration, move to the next one.
3427 if (!(--RemainingLists)) {
3430 RemainingLists = *NumListsCur;
3431 assert(RemainingLists && "No lists in the following declaration??");
3440 typedef llvm::iterator_range<const_component_lists_iterator>
3441 const_component_lists_range;
3443 /// \brief Iterators for all component lists.
3444 const_component_lists_iterator component_lists_begin() const {
3445 return const_component_lists_iterator(
3446 getUniqueDeclsRef(), getDeclNumListsRef(), getComponentListSizesRef(),
3447 getComponentsRef());
3449 const_component_lists_iterator component_lists_end() const {
3450 return const_component_lists_iterator(
3451 ArrayRef<ValueDecl *>(), ArrayRef<unsigned>(), ArrayRef<unsigned>(),
3452 MappableExprComponentListRef(getComponentsRef().end(),
3453 getComponentsRef().end()));
3455 const_component_lists_range component_lists() const {
3456 return {component_lists_begin(), component_lists_end()};
3459 /// \brief Iterators for component lists associated with the provided
3461 const_component_lists_iterator
3462 decl_component_lists_begin(const ValueDecl *VD) const {
3463 return const_component_lists_iterator(
3464 VD, getUniqueDeclsRef(), getDeclNumListsRef(),
3465 getComponentListSizesRef(), getComponentsRef());
3467 const_component_lists_iterator decl_component_lists_end() const {
3468 return component_lists_end();
3470 const_component_lists_range decl_component_lists(const ValueDecl *VD) const {
3471 return {decl_component_lists_begin(VD), decl_component_lists_end()};
3474 /// Iterators to access all the declarations, number of lists, list sizes, and
3476 typedef ArrayRef<ValueDecl *>::iterator const_all_decls_iterator;
3477 typedef llvm::iterator_range<const_all_decls_iterator> const_all_decls_range;
3478 const_all_decls_range all_decls() const {
3479 auto A = getUniqueDeclsRef();
3480 return const_all_decls_range(A.begin(), A.end());
3483 typedef ArrayRef<unsigned>::iterator const_all_num_lists_iterator;
3484 typedef llvm::iterator_range<const_all_num_lists_iterator>
3485 const_all_num_lists_range;
3486 const_all_num_lists_range all_num_lists() const {
3487 auto A = getDeclNumListsRef();
3488 return const_all_num_lists_range(A.begin(), A.end());
3491 typedef ArrayRef<unsigned>::iterator const_all_lists_sizes_iterator;
3492 typedef llvm::iterator_range<const_all_lists_sizes_iterator>
3493 const_all_lists_sizes_range;
3494 const_all_lists_sizes_range all_lists_sizes() const {
3495 auto A = getComponentListSizesRef();
3496 return const_all_lists_sizes_range(A.begin(), A.end());
3499 typedef ArrayRef<MappableComponent>::iterator const_all_components_iterator;
3500 typedef llvm::iterator_range<const_all_components_iterator>
3501 const_all_components_range;
3502 const_all_components_range all_components() const {
3503 auto A = getComponentsRef();
3504 return const_all_components_range(A.begin(), A.end());
3508 /// \brief This represents clause 'map' in the '#pragma omp ...'
3512 /// #pragma omp target map(a,b)
3514 /// In this example directive '#pragma omp target' has clause 'map'
3515 /// with the variables 'a' and 'b'.
3517 class OMPMapClause final : public OMPMappableExprListClause<OMPMapClause>,
3518 private llvm::TrailingObjects<
3519 OMPMapClause, Expr *, ValueDecl *, unsigned,
3520 OMPClauseMappableExprCommon::MappableComponent> {
3521 friend TrailingObjects;
3522 friend OMPVarListClause;
3523 friend OMPMappableExprListClause;
3524 friend class OMPClauseReader;
3526 /// Define the sizes of each trailing object array except the last one. This
3527 /// is required for TrailingObjects to work properly.
3528 size_t numTrailingObjects(OverloadToken<Expr *>) const {
3529 return varlist_size();
3531 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
3532 return getUniqueDeclarationsNum();
3534 size_t numTrailingObjects(OverloadToken<unsigned>) const {
3535 return getUniqueDeclarationsNum() + getTotalComponentListNum();
3538 /// \brief Map type modifier for the 'map' clause.
3539 OpenMPMapClauseKind MapTypeModifier;
3540 /// \brief Map type for the 'map' clause.
3541 OpenMPMapClauseKind MapType;
3542 /// \brief Is this an implicit map type or not.
3543 bool MapTypeIsImplicit;
3544 /// \brief Location of the map type.
3545 SourceLocation MapLoc;
3546 /// \brief Colon location.
3547 SourceLocation ColonLoc;
3549 /// \brief Set type modifier for the clause.
3551 /// \param T Type Modifier for the clause.
3553 void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; }
3555 /// \brief Set type for the clause.
3557 /// \param T Type for the clause.
3559 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
3561 /// \brief Set type location.
3563 /// \param TLoc Type location.
3565 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
3567 /// \brief Set colon location.
3568 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
3570 /// \brief Build a clause for \a NumVars listed expressions, \a
3571 /// NumUniqueDeclarations declarations, \a NumComponentLists total component
3572 /// lists, and \a NumComponents total expression components.
3574 /// \param MapTypeModifier Map type modifier.
3575 /// \param MapType Map type.
3576 /// \param MapTypeIsImplicit Map type is inferred implicitly.
3577 /// \param MapLoc Location of the map type.
3578 /// \param StartLoc Starting location of the clause.
3579 /// \param EndLoc Ending location of the clause.
3580 /// \param NumVars Number of expressions listed in this clause.
3581 /// \param NumUniqueDeclarations Number of unique base declarations in this
3583 /// \param NumComponentLists Number of component lists in this clause.
3584 /// \param NumComponents Total number of expression components in the clause.
3586 explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier,
3587 OpenMPMapClauseKind MapType, bool MapTypeIsImplicit,
3588 SourceLocation MapLoc, SourceLocation StartLoc,
3589 SourceLocation LParenLoc, SourceLocation EndLoc,
3590 unsigned NumVars, unsigned NumUniqueDeclarations,
3591 unsigned NumComponentLists, unsigned NumComponents)
3592 : OMPMappableExprListClause(OMPC_map, StartLoc, LParenLoc, EndLoc,
3593 NumVars, NumUniqueDeclarations,
3594 NumComponentLists, NumComponents),
3595 MapTypeModifier(MapTypeModifier), MapType(MapType),
3596 MapTypeIsImplicit(MapTypeIsImplicit), MapLoc(MapLoc) {}
3598 /// \brief Build an empty clause.
3600 /// \param NumVars Number of expressions listed in this clause.
3601 /// \param NumUniqueDeclarations Number of unique base declarations in this
3603 /// \param NumComponentLists Number of component lists in this clause.
3604 /// \param NumComponents Total number of expression components in the clause.
3606 explicit OMPMapClause(unsigned NumVars, unsigned NumUniqueDeclarations,
3607 unsigned NumComponentLists, unsigned NumComponents)
3608 : OMPMappableExprListClause(
3609 OMPC_map, SourceLocation(), SourceLocation(), SourceLocation(),
3610 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents),
3611 MapTypeModifier(OMPC_MAP_unknown), MapType(OMPC_MAP_unknown),
3612 MapTypeIsImplicit(false), MapLoc() {}
3615 /// \brief Creates clause with a list of variables \a VL.
3617 /// \param C AST context.
3618 /// \param StartLoc Starting location of the clause.
3619 /// \param EndLoc Ending location of the clause.
3620 /// \param Vars The original expression used in the clause.
3621 /// \param Declarations Declarations used in the clause.
3622 /// \param ComponentLists Component lists used in the clause.
3623 /// \param TypeModifier Map type modifier.
3624 /// \param Type Map type.
3625 /// \param TypeIsImplicit Map type is inferred implicitly.
3626 /// \param TypeLoc Location of the map type.
3628 static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc,
3629 SourceLocation LParenLoc, SourceLocation EndLoc,
3630 ArrayRef<Expr *> Vars,
3631 ArrayRef<ValueDecl *> Declarations,
3632 MappableExprComponentListsRef ComponentLists,
3633 OpenMPMapClauseKind TypeModifier,
3634 OpenMPMapClauseKind Type, bool TypeIsImplicit,
3635 SourceLocation TypeLoc);
3636 /// \brief Creates an empty clause with the place for for \a NumVars original
3637 /// expressions, \a NumUniqueDeclarations declarations, \NumComponentLists
3638 /// lists, and \a NumComponents expression components.
3640 /// \param C AST context.
3641 /// \param NumVars Number of expressions listed in the clause.
3642 /// \param NumUniqueDeclarations Number of unique base declarations in this
3644 /// \param NumComponentLists Number of unique base declarations in this
3646 /// \param NumComponents Total number of expression components in the clause.
3648 static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
3649 unsigned NumUniqueDeclarations,
3650 unsigned NumComponentLists,
3651 unsigned NumComponents);
3653 /// \brief Fetches mapping kind for the clause.
3654 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
3656 /// \brief Is this an implicit map type?
3657 /// We have to capture 'IsMapTypeImplicit' from the parser for more
3658 /// informative error messages. It helps distinguish map(r) from
3659 /// map(tofrom: r), which is important to print more helpful error
3660 /// messages for some target directives.
3661 bool isImplicitMapType() const LLVM_READONLY { return MapTypeIsImplicit; }
3663 /// \brief Fetches the map type modifier for the clause.
3664 OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY {
3665 return MapTypeModifier;
3668 /// \brief Fetches location of clause mapping kind.
3669 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
3671 /// \brief Get colon location.
3672 SourceLocation getColonLoc() const { return ColonLoc; }
3674 static bool classof(const OMPClause *T) {
3675 return T->getClauseKind() == OMPC_map;
3678 child_range children() {
3680 reinterpret_cast<Stmt **>(varlist_begin()),
3681 reinterpret_cast<Stmt **>(varlist_end()));
3685 /// \brief This represents 'num_teams' clause in the '#pragma omp ...'
3689 /// #pragma omp teams num_teams(n)
3691 /// In this example directive '#pragma omp teams' has clause 'num_teams'
3692 /// with single expression 'n'.
3694 class OMPNumTeamsClause : public OMPClause, public OMPClauseWithPreInit {
3695 friend class OMPClauseReader;
3696 /// \brief Location of '('.
3697 SourceLocation LParenLoc;
3698 /// \brief NumTeams number.
3700 /// \brief Set the NumTeams number.
3702 /// \param E NumTeams number.
3704 void setNumTeams(Expr *E) { NumTeams = E; }
3707 /// \brief Build 'num_teams' clause.
3709 /// \param E Expression associated with this clause.
3710 /// \param HelperE Helper Expression associated with this clause.
3711 /// \param CaptureRegion Innermost OpenMP region where expressions in this
3712 /// clause must be captured.
3713 /// \param StartLoc Starting location of the clause.
3714 /// \param LParenLoc Location of '('.
3715 /// \param EndLoc Ending location of the clause.
3717 OMPNumTeamsClause(Expr *E, Stmt *HelperE, OpenMPDirectiveKind CaptureRegion,
3718 SourceLocation StartLoc, SourceLocation LParenLoc,
3719 SourceLocation EndLoc)
3720 : OMPClause(OMPC_num_teams, StartLoc, EndLoc), OMPClauseWithPreInit(this),
3721 LParenLoc(LParenLoc), NumTeams(E) {
3722 setPreInitStmt(HelperE, CaptureRegion);
3725 /// \brief Build an empty clause.
3728 : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
3729 OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
3730 NumTeams(nullptr) {}
3731 /// \brief Sets the location of '('.
3732 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3733 /// \brief Returns the location of '('.
3734 SourceLocation getLParenLoc() const { return LParenLoc; }
3735 /// \brief Return NumTeams number.
3736 Expr *getNumTeams() { return cast<Expr>(NumTeams); }
3737 /// \brief Return NumTeams number.
3738 Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
3740 static bool classof(const OMPClause *T) {
3741 return T->getClauseKind() == OMPC_num_teams;
3744 child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
3747 /// \brief This represents 'thread_limit' clause in the '#pragma omp ...'
3751 /// #pragma omp teams thread_limit(n)
3753 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
3754 /// with single expression 'n'.
3756 class OMPThreadLimitClause : public OMPClause, public OMPClauseWithPreInit {
3757 friend class OMPClauseReader;
3758 /// \brief Location of '('.
3759 SourceLocation LParenLoc;
3760 /// \brief ThreadLimit number.
3762 /// \brief Set the ThreadLimit number.
3764 /// \param E ThreadLimit number.
3766 void setThreadLimit(Expr *E) { ThreadLimit = E; }
3769 /// \brief Build 'thread_limit' clause.
3771 /// \param E Expression associated with this clause.
3772 /// \param HelperE Helper Expression associated with this clause.
3773 /// \param CaptureRegion Innermost OpenMP region where expressions in this
3774 /// clause must be captured.
3775 /// \param StartLoc Starting location of the clause.
3776 /// \param LParenLoc Location of '('.
3777 /// \param EndLoc Ending location of the clause.
3779 OMPThreadLimitClause(Expr *E, Stmt *HelperE,
3780 OpenMPDirectiveKind CaptureRegion,
3781 SourceLocation StartLoc, SourceLocation LParenLoc,
3782 SourceLocation EndLoc)
3783 : OMPClause(OMPC_thread_limit, StartLoc, EndLoc),
3784 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), ThreadLimit(E) {
3785 setPreInitStmt(HelperE, CaptureRegion);
3788 /// \brief Build an empty clause.
3790 OMPThreadLimitClause()
3791 : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
3792 OMPClauseWithPreInit(this), LParenLoc(SourceLocation()),
3793 ThreadLimit(nullptr) {}
3794 /// \brief Sets the location of '('.
3795 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3796 /// \brief Returns the location of '('.
3797 SourceLocation getLParenLoc() const { return LParenLoc; }
3798 /// \brief Return ThreadLimit number.
3799 Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
3800 /// \brief Return ThreadLimit number.
3801 Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
3803 static bool classof(const OMPClause *T) {
3804 return T->getClauseKind() == OMPC_thread_limit;
3807 child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
3810 /// \brief This represents 'priority' clause in the '#pragma omp ...'
3814 /// #pragma omp task priority(n)
3816 /// In this example directive '#pragma omp teams' has clause 'priority' with
3817 /// single expression 'n'.
3819 class OMPPriorityClause : public OMPClause {
3820 friend class OMPClauseReader;
3821 /// \brief Location of '('.
3822 SourceLocation LParenLoc;
3823 /// \brief Priority number.
3825 /// \brief Set the Priority number.
3827 /// \param E Priority number.
3829 void setPriority(Expr *E) { Priority = E; }
3832 /// \brief Build 'priority' clause.
3834 /// \param E Expression associated with this clause.
3835 /// \param StartLoc Starting location of the clause.
3836 /// \param LParenLoc Location of '('.
3837 /// \param EndLoc Ending location of the clause.
3839 OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
3840 SourceLocation EndLoc)
3841 : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
3844 /// \brief Build an empty clause.
3847 : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()),
3848 LParenLoc(SourceLocation()), Priority(nullptr) {}
3849 /// \brief Sets the location of '('.
3850 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3851 /// \brief Returns the location of '('.
3852 SourceLocation getLParenLoc() const { return LParenLoc; }
3853 /// \brief Return Priority number.
3854 Expr *getPriority() { return cast<Expr>(Priority); }
3855 /// \brief Return Priority number.
3856 Expr *getPriority() const { return cast<Expr>(Priority); }
3858 static bool classof(const OMPClause *T) {
3859 return T->getClauseKind() == OMPC_priority;
3862 child_range children() { return child_range(&Priority, &Priority + 1); }
3865 /// \brief This represents 'grainsize' clause in the '#pragma omp ...'
3869 /// #pragma omp taskloop grainsize(4)
3871 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
3872 /// with single expression '4'.
3874 class OMPGrainsizeClause : public OMPClause {
3875 friend class OMPClauseReader;
3876 /// \brief Location of '('.
3877 SourceLocation LParenLoc;
3878 /// \brief Safe iteration space distance.
3881 /// \brief Set safelen.
3882 void setGrainsize(Expr *Size) { Grainsize = Size; }
3885 /// \brief Build 'grainsize' clause.
3887 /// \param Size Expression associated with this clause.
3888 /// \param StartLoc Starting location of the clause.
3889 /// \param EndLoc Ending location of the clause.
3891 OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
3892 SourceLocation LParenLoc, SourceLocation EndLoc)
3893 : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
3896 /// \brief Build an empty clause.
3898 explicit OMPGrainsizeClause()
3899 : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()),
3900 LParenLoc(SourceLocation()), Grainsize(nullptr) {}
3902 /// \brief Sets the location of '('.
3903 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3904 /// \brief Returns the location of '('.
3905 SourceLocation getLParenLoc() const { return LParenLoc; }
3907 /// \brief Return safe iteration space distance.
3908 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
3910 static bool classof(const OMPClause *T) {
3911 return T->getClauseKind() == OMPC_grainsize;
3914 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
3917 /// \brief This represents 'nogroup' clause in the '#pragma omp ...' directive.
3920 /// #pragma omp taskloop nogroup
3922 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
3924 class OMPNogroupClause : public OMPClause {
3926 /// \brief Build 'nogroup' clause.
3928 /// \param StartLoc Starting location of the clause.
3929 /// \param EndLoc Ending location of the clause.
3931 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
3932 : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
3934 /// \brief Build an empty clause.
3937 : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
3939 static bool classof(const OMPClause *T) {
3940 return T->getClauseKind() == OMPC_nogroup;
3943 child_range children() {
3944 return child_range(child_iterator(), child_iterator());
3948 /// \brief This represents 'num_tasks' clause in the '#pragma omp ...'
3952 /// #pragma omp taskloop num_tasks(4)
3954 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
3955 /// with single expression '4'.
3957 class OMPNumTasksClause : public OMPClause {
3958 friend class OMPClauseReader;
3959 /// \brief Location of '('.
3960 SourceLocation LParenLoc;
3961 /// \brief Safe iteration space distance.
3964 /// \brief Set safelen.
3965 void setNumTasks(Expr *Size) { NumTasks = Size; }
3968 /// \brief Build 'num_tasks' clause.
3970 /// \param Size Expression associated with this clause.
3971 /// \param StartLoc Starting location of the clause.
3972 /// \param EndLoc Ending location of the clause.
3974 OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
3975 SourceLocation LParenLoc, SourceLocation EndLoc)
3976 : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
3979 /// \brief Build an empty clause.
3981 explicit OMPNumTasksClause()
3982 : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()),
3983 LParenLoc(SourceLocation()), NumTasks(nullptr) {}
3985 /// \brief Sets the location of '('.
3986 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3987 /// \brief Returns the location of '('.
3988 SourceLocation getLParenLoc() const { return LParenLoc; }
3990 /// \brief Return safe iteration space distance.
3991 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
3993 static bool classof(const OMPClause *T) {
3994 return T->getClauseKind() == OMPC_num_tasks;
3997 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
4000 /// \brief This represents 'hint' clause in the '#pragma omp ...' directive.
4003 /// #pragma omp critical (name) hint(6)
4005 /// In this example directive '#pragma omp critical' has name 'name' and clause
4006 /// 'hint' with argument '6'.
4008 class OMPHintClause : public OMPClause {
4009 friend class OMPClauseReader;
4010 /// \brief Location of '('.
4011 SourceLocation LParenLoc;
4012 /// \brief Hint expression of the 'hint' clause.
4015 /// \brief Set hint expression.
4017 void setHint(Expr *H) { Hint = H; }
4020 /// \brief Build 'hint' clause with expression \a Hint.
4022 /// \param Hint Hint expression.
4023 /// \param StartLoc Starting location of the clause.
4024 /// \param LParenLoc Location of '('.
4025 /// \param EndLoc Ending location of the clause.
4027 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
4028 SourceLocation EndLoc)
4029 : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
4032 /// \brief Build an empty clause.
4035 : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()),
4036 LParenLoc(SourceLocation()), Hint(nullptr) {}
4038 /// \brief Sets the location of '('.
4039 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4040 /// \brief Returns the location of '('.
4041 SourceLocation getLParenLoc() const { return LParenLoc; }
4043 /// \brief Returns number of threads.
4044 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
4046 static bool classof(const OMPClause *T) {
4047 return T->getClauseKind() == OMPC_hint;
4050 child_range children() { return child_range(&Hint, &Hint + 1); }
4053 /// \brief This represents 'dist_schedule' clause in the '#pragma omp ...'
4057 /// #pragma omp distribute dist_schedule(static, 3)
4059 /// In this example directive '#pragma omp distribute' has 'dist_schedule'
4060 /// clause with arguments 'static' and '3'.
4062 class OMPDistScheduleClause : public OMPClause, public OMPClauseWithPreInit {
4063 friend class OMPClauseReader;
4064 /// \brief Location of '('.
4065 SourceLocation LParenLoc;
4066 /// \brief A kind of the 'schedule' clause.
4067 OpenMPDistScheduleClauseKind Kind;
4068 /// \brief Start location of the schedule kind in source code.
4069 SourceLocation KindLoc;
4070 /// \brief Location of ',' (if any).
4071 SourceLocation CommaLoc;
4072 /// \brief Chunk size.
4075 /// \brief Set schedule kind.
4077 /// \param K Schedule kind.
4079 void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; }
4080 /// \brief Sets the location of '('.
4082 /// \param Loc Location of '('.
4084 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4085 /// \brief Set schedule kind start location.
4087 /// \param KLoc Schedule kind location.
4089 void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
4090 /// \brief Set location of ','.
4092 /// \param Loc Location of ','.
4094 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
4095 /// \brief Set chunk size.
4097 /// \param E Chunk size.
4099 void setChunkSize(Expr *E) { ChunkSize = E; }
4102 /// \brief Build 'dist_schedule' clause with schedule kind \a Kind and chunk
4103 /// size expression \a ChunkSize.
4105 /// \param StartLoc Starting location of the clause.
4106 /// \param LParenLoc Location of '('.
4107 /// \param KLoc Starting location of the argument.
4108 /// \param CommaLoc Location of ','.
4109 /// \param EndLoc Ending location of the clause.
4110 /// \param Kind DistSchedule kind.
4111 /// \param ChunkSize Chunk size.
4112 /// \param HelperChunkSize Helper chunk size for combined directives.
4114 OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4115 SourceLocation KLoc, SourceLocation CommaLoc,
4116 SourceLocation EndLoc,
4117 OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize,
4118 Stmt *HelperChunkSize)
4119 : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc),
4120 OMPClauseWithPreInit(this), LParenLoc(LParenLoc), Kind(Kind),
4121 KindLoc(KLoc), CommaLoc(CommaLoc), ChunkSize(ChunkSize) {
4122 setPreInitStmt(HelperChunkSize);
4125 /// \brief Build an empty clause.
4127 explicit OMPDistScheduleClause()
4128 : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()),
4129 OMPClauseWithPreInit(this), Kind(OMPC_DIST_SCHEDULE_unknown),
4130 ChunkSize(nullptr) {}
4132 /// \brief Get kind of the clause.
4134 OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; }
4135 /// \brief Get location of '('.
4137 SourceLocation getLParenLoc() { return LParenLoc; }
4138 /// \brief Get kind location.
4140 SourceLocation getDistScheduleKindLoc() { return KindLoc; }
4141 /// \brief Get location of ','.
4143 SourceLocation getCommaLoc() { return CommaLoc; }
4144 /// \brief Get chunk size.
4146 Expr *getChunkSize() { return ChunkSize; }
4147 /// \brief Get chunk size.
4149 const Expr *getChunkSize() const { return ChunkSize; }
4151 static bool classof(const OMPClause *T) {
4152 return T->getClauseKind() == OMPC_dist_schedule;
4155 child_range children() {
4156 return child_range(reinterpret_cast<Stmt **>(&ChunkSize),
4157 reinterpret_cast<Stmt **>(&ChunkSize) + 1);
4161 /// \brief This represents 'defaultmap' clause in the '#pragma omp ...' directive.
4164 /// #pragma omp target defaultmap(tofrom: scalar)
4166 /// In this example directive '#pragma omp target' has 'defaultmap' clause of kind
4167 /// 'scalar' with modifier 'tofrom'.
4169 class OMPDefaultmapClause : public OMPClause {
4170 friend class OMPClauseReader;
4171 /// \brief Location of '('.
4172 SourceLocation LParenLoc;
4173 /// \brief Modifiers for 'defaultmap' clause.
4174 OpenMPDefaultmapClauseModifier Modifier;
4175 /// \brief Locations of modifiers.
4176 SourceLocation ModifierLoc;
4177 /// \brief A kind of the 'defaultmap' clause.
4178 OpenMPDefaultmapClauseKind Kind;
4179 /// \brief Start location of the defaultmap kind in source code.
4180 SourceLocation KindLoc;
4182 /// \brief Set defaultmap kind.
4184 /// \param K Defaultmap kind.
4186 void setDefaultmapKind(OpenMPDefaultmapClauseKind K) { Kind = K; }
4187 /// \brief Set the defaultmap modifier.
4189 /// \param M Defaultmap modifier.
4191 void setDefaultmapModifier(OpenMPDefaultmapClauseModifier M) {
4194 /// \brief Set location of the defaultmap modifier.
4196 void setDefaultmapModifierLoc(SourceLocation Loc) {
4199 /// \brief Sets the location of '('.
4201 /// \param Loc Location of '('.
4203 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
4204 /// \brief Set defaultmap kind start location.
4206 /// \param KLoc Defaultmap kind location.
4208 void setDefaultmapKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
4211 /// \brief Build 'defaultmap' clause with defaultmap kind \a Kind
4213 /// \param StartLoc Starting location of the clause.
4214 /// \param LParenLoc Location of '('.
4215 /// \param KLoc Starting location of the argument.
4216 /// \param EndLoc Ending location of the clause.
4217 /// \param Kind Defaultmap kind.
4218 /// \param M The modifier applied to 'defaultmap' clause.
4219 /// \param MLoc Location of the modifier
4221 OMPDefaultmapClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4222 SourceLocation MLoc, SourceLocation KLoc,
4223 SourceLocation EndLoc, OpenMPDefaultmapClauseKind Kind,
4224 OpenMPDefaultmapClauseModifier M)
4225 : OMPClause(OMPC_defaultmap, StartLoc, EndLoc), LParenLoc(LParenLoc),
4226 Modifier(M), ModifierLoc(MLoc), Kind(Kind), KindLoc(KLoc) {}
4228 /// \brief Build an empty clause.
4230 explicit OMPDefaultmapClause()
4231 : OMPClause(OMPC_defaultmap, SourceLocation(), SourceLocation()),
4232 Modifier(OMPC_DEFAULTMAP_MODIFIER_unknown),
4233 Kind(OMPC_DEFAULTMAP_unknown) {}
4235 /// \brief Get kind of the clause.
4237 OpenMPDefaultmapClauseKind getDefaultmapKind() const { return Kind; }
4238 /// \brief Get the modifier of the clause.
4240 OpenMPDefaultmapClauseModifier getDefaultmapModifier() const {
4243 /// \brief Get location of '('.
4245 SourceLocation getLParenLoc() { return LParenLoc; }
4246 /// \brief Get kind location.
4248 SourceLocation getDefaultmapKindLoc() { return KindLoc; }
4249 /// \brief Get the modifier location.
4251 SourceLocation getDefaultmapModifierLoc() const {
4255 static bool classof(const OMPClause *T) {
4256 return T->getClauseKind() == OMPC_defaultmap;
4259 child_range children() {
4260 return child_range(child_iterator(), child_iterator());
4264 /// \brief This represents clause 'to' in the '#pragma omp ...'
4268 /// #pragma omp target update to(a,b)
4270 /// In this example directive '#pragma omp target update' has clause 'to'
4271 /// with the variables 'a' and 'b'.
4273 class OMPToClause final : public OMPMappableExprListClause<OMPToClause>,
4274 private llvm::TrailingObjects<
4275 OMPToClause, Expr *, ValueDecl *, unsigned,
4276 OMPClauseMappableExprCommon::MappableComponent> {
4277 friend TrailingObjects;
4278 friend OMPVarListClause;
4279 friend OMPMappableExprListClause;
4280 friend class OMPClauseReader;
4282 /// Define the sizes of each trailing object array except the last one. This
4283 /// is required for TrailingObjects to work properly.
4284 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4285 return varlist_size();
4287 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4288 return getUniqueDeclarationsNum();
4290 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4291 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4294 /// \brief Build clause with number of variables \a NumVars.
4296 /// \param StartLoc Starting location of the clause.
4297 /// \param EndLoc Ending location of the clause.
4298 /// \param NumVars Number of expressions listed in this clause.
4299 /// \param NumUniqueDeclarations Number of unique base declarations in this
4301 /// \param NumComponentLists Number of component lists in this clause.
4302 /// \param NumComponents Total number of expression components in the clause.
4304 explicit OMPToClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4305 SourceLocation EndLoc, unsigned NumVars,
4306 unsigned NumUniqueDeclarations,
4307 unsigned NumComponentLists, unsigned NumComponents)
4308 : OMPMappableExprListClause(OMPC_to, StartLoc, LParenLoc, EndLoc, NumVars,
4309 NumUniqueDeclarations, NumComponentLists,
4312 /// \brief Build an empty clause.
4314 /// \param NumVars Number of expressions listed in this clause.
4315 /// \param NumUniqueDeclarations Number of unique base declarations in this
4317 /// \param NumComponentLists Number of component lists in this clause.
4318 /// \param NumComponents Total number of expression components in the clause.
4320 explicit OMPToClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4321 unsigned NumComponentLists, unsigned NumComponents)
4322 : OMPMappableExprListClause(
4323 OMPC_to, SourceLocation(), SourceLocation(), SourceLocation(),
4324 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4327 /// \brief Creates clause with a list of variables \a Vars.
4329 /// \param C AST context.
4330 /// \param StartLoc Starting location of the clause.
4331 /// \param EndLoc Ending location of the clause.
4332 /// \param Vars The original expression used in the clause.
4333 /// \param Declarations Declarations used in the clause.
4334 /// \param ComponentLists Component lists used in the clause.
4336 static OMPToClause *Create(const ASTContext &C, SourceLocation StartLoc,
4337 SourceLocation LParenLoc, SourceLocation EndLoc,
4338 ArrayRef<Expr *> Vars,
4339 ArrayRef<ValueDecl *> Declarations,
4340 MappableExprComponentListsRef ComponentLists);
4342 /// \brief Creates an empty clause with the place for \a NumVars variables.
4344 /// \param C AST context.
4345 /// \param NumVars Number of expressions listed in the clause.
4346 /// \param NumUniqueDeclarations Number of unique base declarations in this
4348 /// \param NumComponentLists Number of unique base declarations in this
4350 /// \param NumComponents Total number of expression components in the clause.
4352 static OMPToClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4353 unsigned NumUniqueDeclarations,
4354 unsigned NumComponentLists,
4355 unsigned NumComponents);
4357 static bool classof(const OMPClause *T) {
4358 return T->getClauseKind() == OMPC_to;
4361 child_range children() {
4362 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4363 reinterpret_cast<Stmt **>(varlist_end()));
4367 /// \brief This represents clause 'from' in the '#pragma omp ...'
4371 /// #pragma omp target update from(a,b)
4373 /// In this example directive '#pragma omp target update' has clause 'from'
4374 /// with the variables 'a' and 'b'.
4376 class OMPFromClause final
4377 : public OMPMappableExprListClause<OMPFromClause>,
4378 private llvm::TrailingObjects<
4379 OMPFromClause, Expr *, ValueDecl *, unsigned,
4380 OMPClauseMappableExprCommon::MappableComponent> {
4381 friend TrailingObjects;
4382 friend OMPVarListClause;
4383 friend OMPMappableExprListClause;
4384 friend class OMPClauseReader;
4386 /// Define the sizes of each trailing object array except the last one. This
4387 /// is required for TrailingObjects to work properly.
4388 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4389 return varlist_size();
4391 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4392 return getUniqueDeclarationsNum();
4394 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4395 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4398 /// \brief Build clause with number of variables \a NumVars.
4400 /// \param StartLoc Starting location of the clause.
4401 /// \param EndLoc Ending location of the clause.
4402 /// \param NumVars Number of expressions listed in this clause.
4403 /// \param NumUniqueDeclarations Number of unique base declarations in this
4405 /// \param NumComponentLists Number of component lists in this clause.
4406 /// \param NumComponents Total number of expression components in the clause.
4408 explicit OMPFromClause(SourceLocation StartLoc, SourceLocation LParenLoc,
4409 SourceLocation EndLoc, unsigned NumVars,
4410 unsigned NumUniqueDeclarations,
4411 unsigned NumComponentLists, unsigned NumComponents)
4412 : OMPMappableExprListClause(OMPC_from, StartLoc, LParenLoc, EndLoc,
4413 NumVars, NumUniqueDeclarations,
4414 NumComponentLists, NumComponents) {}
4416 /// \brief Build an empty clause.
4418 /// \param NumVars Number of expressions listed in this clause.
4419 /// \param NumUniqueDeclarations Number of unique base declarations in this
4421 /// \param NumComponentLists Number of component lists in this clause.
4422 /// \param NumComponents Total number of expression components in the clause.
4424 explicit OMPFromClause(unsigned NumVars, unsigned NumUniqueDeclarations,
4425 unsigned NumComponentLists, unsigned NumComponents)
4426 : OMPMappableExprListClause(
4427 OMPC_from, SourceLocation(), SourceLocation(), SourceLocation(),
4428 NumVars, NumUniqueDeclarations, NumComponentLists, NumComponents) {}
4431 /// \brief Creates clause with a list of variables \a Vars.
4433 /// \param C AST context.
4434 /// \param StartLoc Starting location of the clause.
4435 /// \param EndLoc Ending location of the clause.
4436 /// \param Vars The original expression used in the clause.
4437 /// \param Declarations Declarations used in the clause.
4438 /// \param ComponentLists Component lists used in the clause.
4440 static OMPFromClause *Create(const ASTContext &C, SourceLocation StartLoc,
4441 SourceLocation LParenLoc, SourceLocation EndLoc,
4442 ArrayRef<Expr *> Vars,
4443 ArrayRef<ValueDecl *> Declarations,
4444 MappableExprComponentListsRef ComponentLists);
4446 /// \brief Creates an empty clause with the place for \a NumVars variables.
4448 /// \param C AST context.
4449 /// \param NumVars Number of expressions listed in the clause.
4450 /// \param NumUniqueDeclarations Number of unique base declarations in this
4452 /// \param NumComponentLists Number of unique base declarations in this
4454 /// \param NumComponents Total number of expression components in the clause.
4456 static OMPFromClause *CreateEmpty(const ASTContext &C, unsigned NumVars,
4457 unsigned NumUniqueDeclarations,
4458 unsigned NumComponentLists,
4459 unsigned NumComponents);
4461 static bool classof(const OMPClause *T) {
4462 return T->getClauseKind() == OMPC_from;
4465 child_range children() {
4466 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4467 reinterpret_cast<Stmt **>(varlist_end()));
4471 /// This represents clause 'use_device_ptr' in the '#pragma omp ...'
4475 /// #pragma omp target data use_device_ptr(a,b)
4477 /// In this example directive '#pragma omp target data' has clause
4478 /// 'use_device_ptr' with the variables 'a' and 'b'.
4480 class OMPUseDevicePtrClause final
4481 : public OMPMappableExprListClause<OMPUseDevicePtrClause>,
4482 private llvm::TrailingObjects<
4483 OMPUseDevicePtrClause, Expr *, ValueDecl *, unsigned,
4484 OMPClauseMappableExprCommon::MappableComponent> {
4485 friend TrailingObjects;
4486 friend OMPVarListClause;
4487 friend OMPMappableExprListClause;
4488 friend class OMPClauseReader;
4490 /// Define the sizes of each trailing object array except the last one. This
4491 /// is required for TrailingObjects to work properly.
4492 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4493 return 3 * varlist_size();
4495 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4496 return getUniqueDeclarationsNum();
4498 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4499 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4502 /// Build clause with number of variables \a NumVars.
4504 /// \param StartLoc Starting location of the clause.
4505 /// \param EndLoc Ending location of the clause.
4506 /// \param NumVars Number of expressions listed in this clause.
4507 /// \param NumUniqueDeclarations Number of unique base declarations in this
4509 /// \param NumComponentLists Number of component lists in this clause.
4510 /// \param NumComponents Total number of expression components in the clause.
4512 explicit OMPUseDevicePtrClause(SourceLocation StartLoc,
4513 SourceLocation LParenLoc,
4514 SourceLocation EndLoc, unsigned NumVars,
4515 unsigned NumUniqueDeclarations,
4516 unsigned NumComponentLists,
4517 unsigned NumComponents)
4518 : OMPMappableExprListClause(OMPC_use_device_ptr, StartLoc, LParenLoc,
4519 EndLoc, NumVars, NumUniqueDeclarations,
4520 NumComponentLists, NumComponents) {}
4522 /// Build an empty clause.
4524 /// \param NumVars Number of expressions listed in this clause.
4525 /// \param NumUniqueDeclarations Number of unique base declarations in this
4527 /// \param NumComponentLists Number of component lists in this clause.
4528 /// \param NumComponents Total number of expression components in the clause.
4530 explicit OMPUseDevicePtrClause(unsigned NumVars,
4531 unsigned NumUniqueDeclarations,
4532 unsigned NumComponentLists,
4533 unsigned NumComponents)
4534 : OMPMappableExprListClause(OMPC_use_device_ptr, SourceLocation(),
4535 SourceLocation(), SourceLocation(), NumVars,
4536 NumUniqueDeclarations, NumComponentLists,
4539 /// Sets the list of references to private copies with initializers for new
4540 /// private variables.
4541 /// \param VL List of references.
4542 void setPrivateCopies(ArrayRef<Expr *> VL);
4544 /// Gets the list of references to private copies with initializers for new
4545 /// private variables.
4546 MutableArrayRef<Expr *> getPrivateCopies() {
4547 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
4549 ArrayRef<const Expr *> getPrivateCopies() const {
4550 return llvm::makeArrayRef(varlist_end(), varlist_size());
4553 /// Sets the list of references to initializer variables for new private
4555 /// \param VL List of references.
4556 void setInits(ArrayRef<Expr *> VL);
4558 /// Gets the list of references to initializer variables for new private
4560 MutableArrayRef<Expr *> getInits() {
4561 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
4563 ArrayRef<const Expr *> getInits() const {
4564 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
4568 /// Creates clause with a list of variables \a Vars.
4570 /// \param C AST context.
4571 /// \param StartLoc Starting location of the clause.
4572 /// \param EndLoc Ending location of the clause.
4573 /// \param Vars The original expression used in the clause.
4574 /// \param PrivateVars Expressions referring to private copies.
4575 /// \param Inits Expressions referring to private copy initializers.
4576 /// \param Declarations Declarations used in the clause.
4577 /// \param ComponentLists Component lists used in the clause.
4579 static OMPUseDevicePtrClause *
4580 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4581 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
4582 ArrayRef<Expr *> PrivateVars, ArrayRef<Expr *> Inits,
4583 ArrayRef<ValueDecl *> Declarations,
4584 MappableExprComponentListsRef ComponentLists);
4586 /// Creates an empty clause with the place for \a NumVars variables.
4588 /// \param C AST context.
4589 /// \param NumVars Number of expressions listed in the clause.
4590 /// \param NumUniqueDeclarations Number of unique base declarations in this
4592 /// \param NumComponentLists Number of unique base declarations in this
4594 /// \param NumComponents Total number of expression components in the clause.
4596 static OMPUseDevicePtrClause *CreateEmpty(const ASTContext &C,
4598 unsigned NumUniqueDeclarations,
4599 unsigned NumComponentLists,
4600 unsigned NumComponents);
4602 typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
4603 typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
4604 typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
4605 typedef llvm::iterator_range<private_copies_const_iterator>
4606 private_copies_const_range;
4608 private_copies_range private_copies() {
4609 return private_copies_range(getPrivateCopies().begin(),
4610 getPrivateCopies().end());
4612 private_copies_const_range private_copies() const {
4613 return private_copies_const_range(getPrivateCopies().begin(),
4614 getPrivateCopies().end());
4617 typedef MutableArrayRef<Expr *>::iterator inits_iterator;
4618 typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
4619 typedef llvm::iterator_range<inits_iterator> inits_range;
4620 typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
4622 inits_range inits() {
4623 return inits_range(getInits().begin(), getInits().end());
4625 inits_const_range inits() const {
4626 return inits_const_range(getInits().begin(), getInits().end());
4629 child_range children() {
4630 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4631 reinterpret_cast<Stmt **>(varlist_end()));
4634 static bool classof(const OMPClause *T) {
4635 return T->getClauseKind() == OMPC_use_device_ptr;
4639 /// This represents clause 'is_device_ptr' in the '#pragma omp ...'
4643 /// #pragma omp target is_device_ptr(a,b)
4645 /// In this example directive '#pragma omp target' has clause
4646 /// 'is_device_ptr' with the variables 'a' and 'b'.
4648 class OMPIsDevicePtrClause final
4649 : public OMPMappableExprListClause<OMPIsDevicePtrClause>,
4650 private llvm::TrailingObjects<
4651 OMPIsDevicePtrClause, Expr *, ValueDecl *, unsigned,
4652 OMPClauseMappableExprCommon::MappableComponent> {
4653 friend TrailingObjects;
4654 friend OMPVarListClause;
4655 friend OMPMappableExprListClause;
4656 friend class OMPClauseReader;
4658 /// Define the sizes of each trailing object array except the last one. This
4659 /// is required for TrailingObjects to work properly.
4660 size_t numTrailingObjects(OverloadToken<Expr *>) const {
4661 return varlist_size();
4663 size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
4664 return getUniqueDeclarationsNum();
4666 size_t numTrailingObjects(OverloadToken<unsigned>) const {
4667 return getUniqueDeclarationsNum() + getTotalComponentListNum();
4669 /// Build clause with number of variables \a NumVars.
4671 /// \param StartLoc Starting location of the clause.
4672 /// \param EndLoc Ending location of the clause.
4673 /// \param NumVars Number of expressions listed in this clause.
4674 /// \param NumUniqueDeclarations Number of unique base declarations in this
4676 /// \param NumComponentLists Number of component lists in this clause.
4677 /// \param NumComponents Total number of expression components in the clause.
4679 explicit OMPIsDevicePtrClause(SourceLocation StartLoc,
4680 SourceLocation LParenLoc, SourceLocation EndLoc,
4682 unsigned NumUniqueDeclarations,
4683 unsigned NumComponentLists,
4684 unsigned NumComponents)
4685 : OMPMappableExprListClause(OMPC_is_device_ptr, StartLoc, LParenLoc,
4686 EndLoc, NumVars, NumUniqueDeclarations,
4687 NumComponentLists, NumComponents) {}
4689 /// Build an empty clause.
4691 /// \param NumVars Number of expressions listed in this clause.
4692 /// \param NumUniqueDeclarations Number of unique base declarations in this
4694 /// \param NumComponentLists Number of component lists in this clause.
4695 /// \param NumComponents Total number of expression components in the clause.
4697 explicit OMPIsDevicePtrClause(unsigned NumVars,
4698 unsigned NumUniqueDeclarations,
4699 unsigned NumComponentLists,
4700 unsigned NumComponents)
4701 : OMPMappableExprListClause(OMPC_is_device_ptr, SourceLocation(),
4702 SourceLocation(), SourceLocation(), NumVars,
4703 NumUniqueDeclarations, NumComponentLists,
4707 /// Creates clause with a list of variables \a Vars.
4709 /// \param C AST context.
4710 /// \param StartLoc Starting location of the clause.
4711 /// \param EndLoc Ending location of the clause.
4712 /// \param Vars The original expression used in the clause.
4713 /// \param Declarations Declarations used in the clause.
4714 /// \param ComponentLists Component lists used in the clause.
4716 static OMPIsDevicePtrClause *
4717 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
4718 SourceLocation EndLoc, ArrayRef<Expr *> Vars,
4719 ArrayRef<ValueDecl *> Declarations,
4720 MappableExprComponentListsRef ComponentLists);
4722 /// Creates an empty clause with the place for \a NumVars variables.
4724 /// \param C AST context.
4725 /// \param NumVars Number of expressions listed in the clause.
4726 /// \param NumUniqueDeclarations Number of unique base declarations in this
4728 /// \param NumComponentLists Number of unique base declarations in this
4730 /// \param NumComponents Total number of expression components in the clause.
4732 static OMPIsDevicePtrClause *CreateEmpty(const ASTContext &C,
4734 unsigned NumUniqueDeclarations,
4735 unsigned NumComponentLists,
4736 unsigned NumComponents);
4738 child_range children() {
4739 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
4740 reinterpret_cast<Stmt **>(varlist_end()));
4743 static bool classof(const OMPClause *T) {
4744 return T->getClauseKind() == OMPC_is_device_ptr;
4747 } // end namespace clang
4749 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H