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"
26 //===----------------------------------------------------------------------===//
27 // AST classes for clauses.
28 //===----------------------------------------------------------------------===//
30 /// \brief This is a basic class for representing single OpenMP clause.
33 /// \brief Starting location of the clause (the clause keyword).
34 SourceLocation StartLoc;
35 /// \brief Ending location of the clause.
36 SourceLocation EndLoc;
37 /// \brief Kind of the clause.
38 OpenMPClauseKind Kind;
41 OMPClause(OpenMPClauseKind K, SourceLocation StartLoc, SourceLocation EndLoc)
42 : StartLoc(StartLoc), EndLoc(EndLoc), Kind(K) {}
45 /// \brief Returns the starting location of the clause.
46 SourceLocation getLocStart() const { return StartLoc; }
47 /// \brief Returns the ending location of the clause.
48 SourceLocation getLocEnd() const { return EndLoc; }
50 /// \brief Sets the starting location of the clause.
51 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
52 /// \brief Sets the ending location of the clause.
53 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
55 /// \brief Returns kind of OpenMP clause (private, shared, reduction, etc.).
56 OpenMPClauseKind getClauseKind() const { return Kind; }
58 bool isImplicit() const { return StartLoc.isInvalid(); }
60 typedef StmtIterator child_iterator;
61 typedef ConstStmtIterator const_child_iterator;
62 typedef llvm::iterator_range<child_iterator> child_range;
63 typedef llvm::iterator_range<const_child_iterator> const_child_range;
65 child_range children();
66 const_child_range children() const {
67 auto Children = const_cast<OMPClause *>(this)->children();
68 return const_child_range(Children.begin(), Children.end());
70 static bool classof(const OMPClause *) { return true; }
73 /// \brief This represents clauses with the list of variables like 'private',
74 /// 'firstprivate', 'copyin', 'shared', or 'reduction' clauses in the
75 /// '#pragma omp ...' directives.
76 template <class T> class OMPVarListClause : public OMPClause {
77 friend class OMPClauseReader;
78 /// \brief Location of '('.
79 SourceLocation LParenLoc;
80 /// \brief Number of variables in the list.
84 /// \brief Fetches list of variables associated with this clause.
85 MutableArrayRef<Expr *> getVarRefs() {
86 return MutableArrayRef<Expr *>(
87 static_cast<T *>(this)->template getTrailingObjects<Expr *>(), NumVars);
90 /// \brief Sets the list of variables for this clause.
91 void setVarRefs(ArrayRef<Expr *> VL) {
92 assert(VL.size() == NumVars &&
93 "Number of variables is not the same as the preallocated buffer");
94 std::copy(VL.begin(), VL.end(),
95 static_cast<T *>(this)->template getTrailingObjects<Expr *>());
98 /// \brief Build a clause with \a N variables
100 /// \param K Kind of the clause.
101 /// \param StartLoc Starting location of the clause (the clause keyword).
102 /// \param LParenLoc Location of '('.
103 /// \param EndLoc Ending location of the clause.
104 /// \param N Number of the variables in the clause.
106 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
107 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
108 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
111 typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
112 typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
113 typedef llvm::iterator_range<varlist_iterator> varlist_range;
114 typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
116 unsigned varlist_size() const { return NumVars; }
117 bool varlist_empty() const { return NumVars == 0; }
119 varlist_range varlists() {
120 return varlist_range(varlist_begin(), varlist_end());
122 varlist_const_range varlists() const {
123 return varlist_const_range(varlist_begin(), varlist_end());
126 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
127 varlist_iterator varlist_end() { return getVarRefs().end(); }
128 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
129 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
131 /// \brief Sets the location of '('.
132 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
133 /// \brief Returns the location of '('.
134 SourceLocation getLParenLoc() const { return LParenLoc; }
136 /// \brief Fetches list of all variables in the clause.
137 ArrayRef<const Expr *> getVarRefs() const {
138 return llvm::makeArrayRef(
139 static_cast<const T *>(this)->template getTrailingObjects<Expr *>(),
144 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
147 /// #pragma omp parallel if(parallel:a > 5)
149 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
150 /// condition 'a > 5' and directive name modifier 'parallel'.
152 class OMPIfClause : public OMPClause {
153 friend class OMPClauseReader;
154 /// \brief Location of '('.
155 SourceLocation LParenLoc;
156 /// \brief Condition of the 'if' clause.
158 /// \brief Location of ':' (if any).
159 SourceLocation ColonLoc;
160 /// \brief Directive name modifier for the clause.
161 OpenMPDirectiveKind NameModifier;
162 /// \brief Name modifier location.
163 SourceLocation NameModifierLoc;
165 /// \brief Set condition.
167 void setCondition(Expr *Cond) { Condition = Cond; }
168 /// \brief Set directive name modifier for the clause.
170 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
171 /// \brief Set location of directive name modifier for the clause.
173 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
174 /// \brief Set location of ':'.
176 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
179 /// \brief Build 'if' clause with condition \a Cond.
181 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
182 /// \param Cond Condition of the clause.
183 /// \param StartLoc Starting location of the clause.
184 /// \param LParenLoc Location of '('.
185 /// \param NameModifierLoc Location of directive name modifier.
186 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
187 /// \param EndLoc Ending location of the clause.
189 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond,
190 SourceLocation StartLoc, SourceLocation LParenLoc,
191 SourceLocation NameModifierLoc, SourceLocation ColonLoc,
192 SourceLocation EndLoc)
193 : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
194 Condition(Cond), ColonLoc(ColonLoc), NameModifier(NameModifier),
195 NameModifierLoc(NameModifierLoc) {}
197 /// \brief Build an empty clause.
200 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()), LParenLoc(),
201 Condition(nullptr), ColonLoc(), NameModifier(OMPD_unknown),
204 /// \brief Sets the location of '('.
205 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
206 /// \brief Returns the location of '('.
207 SourceLocation getLParenLoc() const { return LParenLoc; }
209 /// \brief Return the location of ':'.
210 SourceLocation getColonLoc() const { return ColonLoc; }
212 /// \brief Returns condition.
213 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
214 /// \brief Return directive name modifier associated with the clause.
215 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
217 /// \brief Return the location of directive name modifier.
218 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
220 static bool classof(const OMPClause *T) {
221 return T->getClauseKind() == OMPC_if;
224 child_range children() { return child_range(&Condition, &Condition + 1); }
227 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
230 /// #pragma omp task final(a > 5)
232 /// In this example directive '#pragma omp task' has simple 'final'
233 /// clause with condition 'a > 5'.
235 class OMPFinalClause : public OMPClause {
236 friend class OMPClauseReader;
237 /// \brief Location of '('.
238 SourceLocation LParenLoc;
239 /// \brief Condition of the 'if' clause.
242 /// \brief Set condition.
244 void setCondition(Expr *Cond) { Condition = Cond; }
247 /// \brief Build 'final' clause with condition \a Cond.
249 /// \param StartLoc Starting location of the clause.
250 /// \param LParenLoc Location of '('.
251 /// \param Cond Condition of the clause.
252 /// \param EndLoc Ending location of the clause.
254 OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
255 SourceLocation EndLoc)
256 : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
259 /// \brief Build an empty clause.
262 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
263 LParenLoc(SourceLocation()), Condition(nullptr) {}
265 /// \brief Sets the location of '('.
266 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
267 /// \brief Returns the location of '('.
268 SourceLocation getLParenLoc() const { return LParenLoc; }
270 /// \brief Returns condition.
271 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
273 static bool classof(const OMPClause *T) {
274 return T->getClauseKind() == OMPC_final;
277 child_range children() { return child_range(&Condition, &Condition + 1); }
280 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
284 /// #pragma omp parallel num_threads(6)
286 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
287 /// clause with number of threads '6'.
289 class OMPNumThreadsClause : public OMPClause {
290 friend class OMPClauseReader;
291 /// \brief Location of '('.
292 SourceLocation LParenLoc;
293 /// \brief Condition of the 'num_threads' clause.
296 /// \brief Set condition.
298 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
301 /// \brief Build 'num_threads' clause with condition \a NumThreads.
303 /// \param NumThreads Number of threads for the construct.
304 /// \param StartLoc Starting location of the clause.
305 /// \param LParenLoc Location of '('.
306 /// \param EndLoc Ending location of the clause.
308 OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
309 SourceLocation LParenLoc, SourceLocation EndLoc)
310 : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
311 NumThreads(NumThreads) {}
313 /// \brief Build an empty clause.
315 OMPNumThreadsClause()
316 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
317 LParenLoc(SourceLocation()), NumThreads(nullptr) {}
319 /// \brief Sets the location of '('.
320 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
321 /// \brief Returns the location of '('.
322 SourceLocation getLParenLoc() const { return LParenLoc; }
324 /// \brief Returns number of threads.
325 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
327 static bool classof(const OMPClause *T) {
328 return T->getClauseKind() == OMPC_num_threads;
331 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
334 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
338 /// #pragma omp simd safelen(4)
340 /// In this example directive '#pragma omp simd' has clause 'safelen'
341 /// with single expression '4'.
342 /// If the safelen clause is used then no two iterations executed
343 /// concurrently with SIMD instructions can have a greater distance
344 /// in the logical iteration space than its value. The parameter of
345 /// the safelen clause must be a constant positive integer expression.
347 class OMPSafelenClause : public OMPClause {
348 friend class OMPClauseReader;
349 /// \brief Location of '('.
350 SourceLocation LParenLoc;
351 /// \brief Safe iteration space distance.
354 /// \brief Set safelen.
355 void setSafelen(Expr *Len) { Safelen = Len; }
358 /// \brief Build 'safelen' clause.
360 /// \param Len Expression associated with this clause.
361 /// \param StartLoc Starting location of the clause.
362 /// \param EndLoc Ending location of the clause.
364 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
365 SourceLocation EndLoc)
366 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
369 /// \brief Build an empty clause.
371 explicit OMPSafelenClause()
372 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
373 LParenLoc(SourceLocation()), Safelen(nullptr) {}
375 /// \brief Sets the location of '('.
376 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
377 /// \brief Returns the location of '('.
378 SourceLocation getLParenLoc() const { return LParenLoc; }
380 /// \brief Return safe iteration space distance.
381 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
383 static bool classof(const OMPClause *T) {
384 return T->getClauseKind() == OMPC_safelen;
387 child_range children() { return child_range(&Safelen, &Safelen + 1); }
390 /// \brief This represents 'simdlen' clause in the '#pragma omp ...'
394 /// #pragma omp simd simdlen(4)
396 /// In this example directive '#pragma omp simd' has clause 'simdlen'
397 /// with single expression '4'.
398 /// If the 'simdlen' clause is used then it specifies the preferred number of
399 /// iterations to be executed concurrently. The parameter of the 'simdlen'
400 /// clause must be a constant positive integer expression.
402 class OMPSimdlenClause : public OMPClause {
403 friend class OMPClauseReader;
404 /// \brief Location of '('.
405 SourceLocation LParenLoc;
406 /// \brief Safe iteration space distance.
409 /// \brief Set simdlen.
410 void setSimdlen(Expr *Len) { Simdlen = Len; }
413 /// \brief Build 'simdlen' clause.
415 /// \param Len Expression associated with this clause.
416 /// \param StartLoc Starting location of the clause.
417 /// \param EndLoc Ending location of the clause.
419 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
420 SourceLocation EndLoc)
421 : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
424 /// \brief Build an empty clause.
426 explicit OMPSimdlenClause()
427 : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()),
428 LParenLoc(SourceLocation()), Simdlen(nullptr) {}
430 /// \brief Sets the location of '('.
431 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
432 /// \brief Returns the location of '('.
433 SourceLocation getLParenLoc() const { return LParenLoc; }
435 /// \brief Return safe iteration space distance.
436 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
438 static bool classof(const OMPClause *T) {
439 return T->getClauseKind() == OMPC_simdlen;
442 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
445 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
449 /// #pragma omp simd collapse(3)
451 /// In this example directive '#pragma omp simd' has clause 'collapse'
452 /// with single expression '3'.
453 /// The parameter must be a constant positive integer expression, it specifies
454 /// the number of nested loops that should be collapsed into a single iteration
457 class OMPCollapseClause : public OMPClause {
458 friend class OMPClauseReader;
459 /// \brief Location of '('.
460 SourceLocation LParenLoc;
461 /// \brief Number of for-loops.
464 /// \brief Set the number of associated for-loops.
465 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
468 /// \brief Build 'collapse' clause.
470 /// \param Num Expression associated with this clause.
471 /// \param StartLoc Starting location of the clause.
472 /// \param LParenLoc Location of '('.
473 /// \param EndLoc Ending location of the clause.
475 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
476 SourceLocation LParenLoc, SourceLocation EndLoc)
477 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
480 /// \brief Build an empty clause.
482 explicit OMPCollapseClause()
483 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
484 LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
486 /// \brief Sets the location of '('.
487 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
488 /// \brief Returns the location of '('.
489 SourceLocation getLParenLoc() const { return LParenLoc; }
491 /// \brief Return the number of associated for-loops.
492 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
494 static bool classof(const OMPClause *T) {
495 return T->getClauseKind() == OMPC_collapse;
498 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
501 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
504 /// #pragma omp parallel default(shared)
506 /// In this example directive '#pragma omp parallel' has simple 'default'
507 /// clause with kind 'shared'.
509 class OMPDefaultClause : public OMPClause {
510 friend class OMPClauseReader;
511 /// \brief Location of '('.
512 SourceLocation LParenLoc;
513 /// \brief A kind of the 'default' clause.
514 OpenMPDefaultClauseKind Kind;
515 /// \brief Start location of the kind in source code.
516 SourceLocation KindKwLoc;
518 /// \brief Set kind of the clauses.
520 /// \param K Argument of clause.
522 void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
524 /// \brief Set argument location.
526 /// \param KLoc Argument location.
528 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
531 /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
533 /// \param A Argument of the clause ('none' or 'shared').
534 /// \param ALoc Starting location of the argument.
535 /// \param StartLoc Starting location of the clause.
536 /// \param LParenLoc Location of '('.
537 /// \param EndLoc Ending location of the clause.
539 OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
540 SourceLocation StartLoc, SourceLocation LParenLoc,
541 SourceLocation EndLoc)
542 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
543 Kind(A), KindKwLoc(ALoc) {}
545 /// \brief Build an empty clause.
548 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
549 LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
550 KindKwLoc(SourceLocation()) {}
552 /// \brief Sets the location of '('.
553 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
554 /// \brief Returns the location of '('.
555 SourceLocation getLParenLoc() const { return LParenLoc; }
557 /// \brief Returns kind of the clause.
558 OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
560 /// \brief Returns location of clause kind.
561 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
563 static bool classof(const OMPClause *T) {
564 return T->getClauseKind() == OMPC_default;
567 child_range children() {
568 return child_range(child_iterator(), child_iterator());
572 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
576 /// #pragma omp parallel proc_bind(master)
578 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
579 /// clause with kind 'master'.
581 class OMPProcBindClause : public OMPClause {
582 friend class OMPClauseReader;
583 /// \brief Location of '('.
584 SourceLocation LParenLoc;
585 /// \brief A kind of the 'proc_bind' clause.
586 OpenMPProcBindClauseKind Kind;
587 /// \brief Start location of the kind in source code.
588 SourceLocation KindKwLoc;
590 /// \brief Set kind of the clause.
592 /// \param K Kind of clause.
594 void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
596 /// \brief Set clause kind location.
598 /// \param KLoc Kind location.
600 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
603 /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
606 /// \param A Argument of the clause ('master', 'close' or 'spread').
607 /// \param ALoc Starting location of the argument.
608 /// \param StartLoc Starting location of the clause.
609 /// \param LParenLoc Location of '('.
610 /// \param EndLoc Ending location of the clause.
612 OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
613 SourceLocation StartLoc, SourceLocation LParenLoc,
614 SourceLocation EndLoc)
615 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
616 Kind(A), KindKwLoc(ALoc) {}
618 /// \brief Build an empty clause.
621 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
622 LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
623 KindKwLoc(SourceLocation()) {}
625 /// \brief Sets the location of '('.
626 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
627 /// \brief Returns the location of '('.
628 SourceLocation getLParenLoc() const { return LParenLoc; }
630 /// \brief Returns kind of the clause.
631 OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
633 /// \brief Returns location of clause kind.
634 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
636 static bool classof(const OMPClause *T) {
637 return T->getClauseKind() == OMPC_proc_bind;
640 child_range children() {
641 return child_range(child_iterator(), child_iterator());
645 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
648 /// #pragma omp for schedule(static, 3)
650 /// In this example directive '#pragma omp for' has 'schedule' clause with
651 /// arguments 'static' and '3'.
653 class OMPScheduleClause : public OMPClause {
654 friend class OMPClauseReader;
655 /// \brief Location of '('.
656 SourceLocation LParenLoc;
657 /// \brief A kind of the 'schedule' clause.
658 OpenMPScheduleClauseKind Kind;
659 /// \brief Modifiers for 'schedule' clause.
660 enum {FIRST, SECOND, NUM_MODIFIERS};
661 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
662 /// \brief Locations of modifiers.
663 SourceLocation ModifiersLoc[NUM_MODIFIERS];
664 /// \brief Start location of the schedule ind in source code.
665 SourceLocation KindLoc;
666 /// \brief Location of ',' (if any).
667 SourceLocation CommaLoc;
668 /// \brief Chunk size and a reference to pseudo variable for combined
670 enum { CHUNK_SIZE, HELPER_CHUNK_SIZE, NUM_EXPRS };
671 Stmt *ChunkSizes[NUM_EXPRS];
673 /// \brief Set schedule kind.
675 /// \param K Schedule kind.
677 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
678 /// \brief Set the first schedule modifier.
680 /// \param M Schedule modifier.
682 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
683 Modifiers[FIRST] = M;
685 /// \brief Set the second schedule modifier.
687 /// \param M Schedule modifier.
689 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
690 Modifiers[SECOND] = M;
692 /// \brief Set location of the first schedule modifier.
694 void setFirstScheduleModifierLoc(SourceLocation Loc) {
695 ModifiersLoc[FIRST] = Loc;
697 /// \brief Set location of the second schedule modifier.
699 void setSecondScheduleModifierLoc(SourceLocation Loc) {
700 ModifiersLoc[SECOND] = Loc;
702 /// \brief Set schedule modifier location.
704 /// \param M Schedule modifier location.
706 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
707 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
708 Modifiers[FIRST] = M;
710 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
711 Modifiers[SECOND] = M;
714 /// \brief Sets the location of '('.
716 /// \param Loc Location of '('.
718 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
719 /// \brief Set schedule kind start location.
721 /// \param KLoc Schedule kind location.
723 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
724 /// \brief Set location of ','.
726 /// \param Loc Location of ','.
728 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
729 /// \brief Set chunk size.
731 /// \param E Chunk size.
733 void setChunkSize(Expr *E) { ChunkSizes[CHUNK_SIZE] = E; }
734 /// \brief Set helper chunk size.
736 /// \param E Helper chunk size.
738 void setHelperChunkSize(Expr *E) { ChunkSizes[HELPER_CHUNK_SIZE] = E; }
741 /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
742 /// expression \a ChunkSize.
744 /// \param StartLoc Starting location of the clause.
745 /// \param LParenLoc Location of '('.
746 /// \param KLoc Starting location of the argument.
747 /// \param CommaLoc Location of ','.
748 /// \param EndLoc Ending location of the clause.
749 /// \param Kind Schedule kind.
750 /// \param ChunkSize Chunk size.
751 /// \param HelperChunkSize Helper chunk size for combined directives.
752 /// \param M1 The first modifier applied to 'schedule' clause.
753 /// \param M1Loc Location of the first modifier
754 /// \param M2 The second modifier applied to 'schedule' clause.
755 /// \param M2Loc Location of the second modifier
757 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
758 SourceLocation KLoc, SourceLocation CommaLoc,
759 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
760 Expr *ChunkSize, Expr *HelperChunkSize,
761 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
762 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
763 : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
764 Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc) {
765 ChunkSizes[CHUNK_SIZE] = ChunkSize;
766 ChunkSizes[HELPER_CHUNK_SIZE] = HelperChunkSize;
767 Modifiers[FIRST] = M1;
768 Modifiers[SECOND] = M2;
769 ModifiersLoc[FIRST] = M1Loc;
770 ModifiersLoc[SECOND] = M2Loc;
773 /// \brief Build an empty clause.
775 explicit OMPScheduleClause()
776 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
777 Kind(OMPC_SCHEDULE_unknown) {
778 ChunkSizes[CHUNK_SIZE] = nullptr;
779 ChunkSizes[HELPER_CHUNK_SIZE] = nullptr;
780 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
781 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
784 /// \brief Get kind of the clause.
786 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
787 /// \brief Get the first modifier of the clause.
789 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
790 return Modifiers[FIRST];
792 /// \brief Get the second modifier of the clause.
794 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
795 return Modifiers[SECOND];
797 /// \brief Get location of '('.
799 SourceLocation getLParenLoc() { return LParenLoc; }
800 /// \brief Get kind location.
802 SourceLocation getScheduleKindLoc() { return KindLoc; }
803 /// \brief Get the first modifier location.
805 SourceLocation getFirstScheduleModifierLoc() const {
806 return ModifiersLoc[FIRST];
808 /// \brief Get the second modifier location.
810 SourceLocation getSecondScheduleModifierLoc() const {
811 return ModifiersLoc[SECOND];
813 /// \brief Get location of ','.
815 SourceLocation getCommaLoc() { return CommaLoc; }
816 /// \brief Get chunk size.
818 Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]); }
819 /// \brief Get chunk size.
821 Expr *getChunkSize() const {
822 return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]);
824 /// \brief Get helper chunk size.
826 Expr *getHelperChunkSize() {
827 return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
829 /// \brief Get helper chunk size.
831 Expr *getHelperChunkSize() const {
832 return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
835 static bool classof(const OMPClause *T) {
836 return T->getClauseKind() == OMPC_schedule;
839 child_range children() {
840 return child_range(&ChunkSizes[CHUNK_SIZE], &ChunkSizes[CHUNK_SIZE] + 1);
844 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
847 /// #pragma omp for ordered (2)
849 /// In this example directive '#pragma omp for' has 'ordered' clause with
852 class OMPOrderedClause : public OMPClause {
853 friend class OMPClauseReader;
854 /// \brief Location of '('.
855 SourceLocation LParenLoc;
856 /// \brief Number of for-loops.
859 /// \brief Set the number of associated for-loops.
860 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
863 /// \brief Build 'ordered' clause.
865 /// \param Num Expression, possibly associated with this clause.
866 /// \param StartLoc Starting location of the clause.
867 /// \param LParenLoc Location of '('.
868 /// \param EndLoc Ending location of the clause.
870 OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
871 SourceLocation LParenLoc, SourceLocation EndLoc)
872 : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
875 /// \brief Build an empty clause.
877 explicit OMPOrderedClause()
878 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
879 LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
881 /// \brief Sets the location of '('.
882 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
883 /// \brief Returns the location of '('.
884 SourceLocation getLParenLoc() const { return LParenLoc; }
886 /// \brief Return the number of associated for-loops.
887 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
889 static bool classof(const OMPClause *T) {
890 return T->getClauseKind() == OMPC_ordered;
893 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
896 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
899 /// #pragma omp for nowait
901 /// In this example directive '#pragma omp for' has 'nowait' clause.
903 class OMPNowaitClause : public OMPClause {
905 /// \brief Build 'nowait' clause.
907 /// \param StartLoc Starting location of the clause.
908 /// \param EndLoc Ending location of the clause.
910 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
911 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
913 /// \brief Build an empty clause.
916 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
918 static bool classof(const OMPClause *T) {
919 return T->getClauseKind() == OMPC_nowait;
922 child_range children() {
923 return child_range(child_iterator(), child_iterator());
927 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
930 /// #pragma omp task untied
932 /// In this example directive '#pragma omp task' has 'untied' clause.
934 class OMPUntiedClause : public OMPClause {
936 /// \brief Build 'untied' clause.
938 /// \param StartLoc Starting location of the clause.
939 /// \param EndLoc Ending location of the clause.
941 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
942 : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
944 /// \brief Build an empty clause.
947 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
949 static bool classof(const OMPClause *T) {
950 return T->getClauseKind() == OMPC_untied;
953 child_range children() {
954 return child_range(child_iterator(), child_iterator());
958 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
962 /// #pragma omp task mergeable
964 /// In this example directive '#pragma omp task' has 'mergeable' clause.
966 class OMPMergeableClause : public OMPClause {
968 /// \brief Build 'mergeable' clause.
970 /// \param StartLoc Starting location of the clause.
971 /// \param EndLoc Ending location of the clause.
973 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
974 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
976 /// \brief Build an empty clause.
979 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
981 static bool classof(const OMPClause *T) {
982 return T->getClauseKind() == OMPC_mergeable;
985 child_range children() {
986 return child_range(child_iterator(), child_iterator());
990 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
993 /// #pragma omp atomic read
995 /// In this example directive '#pragma omp atomic' has 'read' clause.
997 class OMPReadClause : public OMPClause {
999 /// \brief Build 'read' clause.
1001 /// \param StartLoc Starting location of the clause.
1002 /// \param EndLoc Ending location of the clause.
1004 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1005 : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1007 /// \brief Build an empty clause.
1009 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1011 static bool classof(const OMPClause *T) {
1012 return T->getClauseKind() == OMPC_read;
1015 child_range children() {
1016 return child_range(child_iterator(), child_iterator());
1020 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
1023 /// #pragma omp atomic write
1025 /// In this example directive '#pragma omp atomic' has 'write' clause.
1027 class OMPWriteClause : public OMPClause {
1029 /// \brief Build 'write' clause.
1031 /// \param StartLoc Starting location of the clause.
1032 /// \param EndLoc Ending location of the clause.
1034 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1035 : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1037 /// \brief Build an empty clause.
1040 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1042 static bool classof(const OMPClause *T) {
1043 return T->getClauseKind() == OMPC_write;
1046 child_range children() {
1047 return child_range(child_iterator(), child_iterator());
1051 /// \brief This represents 'update' clause in the '#pragma omp atomic'
1055 /// #pragma omp atomic update
1057 /// In this example directive '#pragma omp atomic' has 'update' clause.
1059 class OMPUpdateClause : public OMPClause {
1061 /// \brief Build 'update' clause.
1063 /// \param StartLoc Starting location of the clause.
1064 /// \param EndLoc Ending location of the clause.
1066 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
1067 : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1069 /// \brief Build an empty clause.
1072 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1074 static bool classof(const OMPClause *T) {
1075 return T->getClauseKind() == OMPC_update;
1078 child_range children() {
1079 return child_range(child_iterator(), child_iterator());
1083 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
1087 /// #pragma omp atomic capture
1089 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1091 class OMPCaptureClause : public OMPClause {
1093 /// \brief Build 'capture' clause.
1095 /// \param StartLoc Starting location of the clause.
1096 /// \param EndLoc Ending location of the clause.
1098 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1099 : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1101 /// \brief Build an empty clause.
1104 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1106 static bool classof(const OMPClause *T) {
1107 return T->getClauseKind() == OMPC_capture;
1110 child_range children() {
1111 return child_range(child_iterator(), child_iterator());
1115 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
1119 /// #pragma omp atomic seq_cst
1121 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1123 class OMPSeqCstClause : public OMPClause {
1125 /// \brief Build 'seq_cst' clause.
1127 /// \param StartLoc Starting location of the clause.
1128 /// \param EndLoc Ending location of the clause.
1130 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1131 : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1133 /// \brief Build an empty clause.
1136 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1138 static bool classof(const OMPClause *T) {
1139 return T->getClauseKind() == OMPC_seq_cst;
1142 child_range children() {
1143 return child_range(child_iterator(), child_iterator());
1147 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
1150 /// #pragma omp parallel private(a,b)
1152 /// In this example directive '#pragma omp parallel' has clause 'private'
1153 /// with the variables 'a' and 'b'.
1155 class OMPPrivateClause final
1156 : public OMPVarListClause<OMPPrivateClause>,
1157 private llvm::TrailingObjects<OMPPrivateClause, Expr *> {
1158 friend TrailingObjects;
1159 friend OMPVarListClause;
1160 friend class OMPClauseReader;
1161 /// \brief Build clause with number of variables \a N.
1163 /// \param StartLoc Starting location of the clause.
1164 /// \param LParenLoc Location of '('.
1165 /// \param EndLoc Ending location of the clause.
1166 /// \param N Number of the variables in the clause.
1168 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1169 SourceLocation EndLoc, unsigned N)
1170 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1173 /// \brief Build an empty clause.
1175 /// \param N Number of variables.
1177 explicit OMPPrivateClause(unsigned N)
1178 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
1179 SourceLocation(), SourceLocation(),
1182 /// \brief Sets the list of references to private copies with initializers for
1183 /// new private variables.
1184 /// \param VL List of references.
1185 void setPrivateCopies(ArrayRef<Expr *> VL);
1187 /// \brief Gets the list of references to private copies with initializers for
1188 /// new private variables.
1189 MutableArrayRef<Expr *> getPrivateCopies() {
1190 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1192 ArrayRef<const Expr *> getPrivateCopies() const {
1193 return llvm::makeArrayRef(varlist_end(), varlist_size());
1197 /// \brief Creates clause with a list of variables \a VL.
1199 /// \param C AST context.
1200 /// \param StartLoc Starting location of the clause.
1201 /// \param LParenLoc Location of '('.
1202 /// \param EndLoc Ending location of the clause.
1203 /// \param VL List of references to the variables.
1204 /// \param PrivateVL List of references to private copies with initializers.
1206 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1207 SourceLocation LParenLoc,
1208 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1209 ArrayRef<Expr *> PrivateVL);
1210 /// \brief Creates an empty clause with the place for \a N variables.
1212 /// \param C AST context.
1213 /// \param N The number of variables.
1215 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1217 typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1218 typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1219 typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1220 typedef llvm::iterator_range<private_copies_const_iterator>
1221 private_copies_const_range;
1223 private_copies_range private_copies() {
1224 return private_copies_range(getPrivateCopies().begin(),
1225 getPrivateCopies().end());
1227 private_copies_const_range private_copies() const {
1228 return private_copies_const_range(getPrivateCopies().begin(),
1229 getPrivateCopies().end());
1232 child_range children() {
1233 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1234 reinterpret_cast<Stmt **>(varlist_end()));
1237 static bool classof(const OMPClause *T) {
1238 return T->getClauseKind() == OMPC_private;
1242 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
1246 /// #pragma omp parallel firstprivate(a,b)
1248 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1249 /// with the variables 'a' and 'b'.
1251 class OMPFirstprivateClause final
1252 : public OMPVarListClause<OMPFirstprivateClause>,
1253 private llvm::TrailingObjects<OMPFirstprivateClause, Expr *> {
1254 friend TrailingObjects;
1255 friend OMPVarListClause;
1256 friend class OMPClauseReader;
1258 /// \brief Build clause with number of variables \a N.
1260 /// \param StartLoc Starting location of the clause.
1261 /// \param LParenLoc Location of '('.
1262 /// \param EndLoc Ending location of the clause.
1263 /// \param N Number of the variables in the clause.
1265 OMPFirstprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1266 SourceLocation EndLoc, unsigned N)
1267 : OMPVarListClause<OMPFirstprivateClause>(OMPC_firstprivate, StartLoc,
1268 LParenLoc, EndLoc, N) {}
1270 /// \brief Build an empty clause.
1272 /// \param N Number of variables.
1274 explicit OMPFirstprivateClause(unsigned N)
1275 : OMPVarListClause<OMPFirstprivateClause>(
1276 OMPC_firstprivate, SourceLocation(), SourceLocation(),
1277 SourceLocation(), N) {}
1278 /// \brief Sets the list of references to private copies with initializers for
1279 /// new private variables.
1280 /// \param VL List of references.
1281 void setPrivateCopies(ArrayRef<Expr *> VL);
1283 /// \brief Gets the list of references to private copies with initializers for
1284 /// new private variables.
1285 MutableArrayRef<Expr *> getPrivateCopies() {
1286 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1288 ArrayRef<const Expr *> getPrivateCopies() const {
1289 return llvm::makeArrayRef(varlist_end(), varlist_size());
1292 /// \brief Sets the list of references to initializer variables for new
1293 /// private variables.
1294 /// \param VL List of references.
1295 void setInits(ArrayRef<Expr *> VL);
1297 /// \brief Gets the list of references to initializer variables for new
1298 /// private variables.
1299 MutableArrayRef<Expr *> getInits() {
1300 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1302 ArrayRef<const Expr *> getInits() const {
1303 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1307 /// \brief Creates clause with a list of variables \a VL.
1309 /// \param C AST context.
1310 /// \param StartLoc Starting location of the clause.
1311 /// \param LParenLoc Location of '('.
1312 /// \param EndLoc Ending location of the clause.
1313 /// \param VL List of references to the original variables.
1314 /// \param PrivateVL List of references to private copies with initializers.
1315 /// \param InitVL List of references to auto generated variables used for
1316 /// initialization of a single array element. Used if firstprivate variable is
1319 static OMPFirstprivateClause *
1320 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1321 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1322 ArrayRef<Expr *> InitVL);
1323 /// \brief Creates an empty clause with the place for \a N variables.
1325 /// \param C AST context.
1326 /// \param N The number of variables.
1328 static OMPFirstprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1330 typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1331 typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1332 typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1333 typedef llvm::iterator_range<private_copies_const_iterator>
1334 private_copies_const_range;
1336 private_copies_range private_copies() {
1337 return private_copies_range(getPrivateCopies().begin(),
1338 getPrivateCopies().end());
1340 private_copies_const_range private_copies() const {
1341 return private_copies_const_range(getPrivateCopies().begin(),
1342 getPrivateCopies().end());
1345 typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1346 typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1347 typedef llvm::iterator_range<inits_iterator> inits_range;
1348 typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1350 inits_range inits() {
1351 return inits_range(getInits().begin(), getInits().end());
1353 inits_const_range inits() const {
1354 return inits_const_range(getInits().begin(), getInits().end());
1357 child_range children() {
1358 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1359 reinterpret_cast<Stmt **>(varlist_end()));
1362 static bool classof(const OMPClause *T) {
1363 return T->getClauseKind() == OMPC_firstprivate;
1367 /// \brief This represents clause 'lastprivate' in the '#pragma omp ...'
1371 /// #pragma omp simd lastprivate(a,b)
1373 /// In this example directive '#pragma omp simd' has clause 'lastprivate'
1374 /// with the variables 'a' and 'b'.
1375 class OMPLastprivateClause final
1376 : public OMPVarListClause<OMPLastprivateClause>,
1377 private llvm::TrailingObjects<OMPLastprivateClause, Expr *> {
1378 // There are 4 additional tail-allocated arrays at the end of the class:
1379 // 1. Contains list of pseudo variables with the default initialization for
1380 // each non-firstprivate variables. Used in codegen for initialization of
1381 // lastprivate copies.
1382 // 2. List of helper expressions for proper generation of assignment operation
1383 // required for lastprivate clause. This list represents private variables
1384 // (for arrays, single array element).
1385 // 3. List of helper expressions for proper generation of assignment operation
1386 // required for lastprivate clause. This list represents original variables
1387 // (for arrays, single array element).
1388 // 4. List of helper expressions that represents assignment operation:
1390 // DstExprs = SrcExprs;
1392 // Required for proper codegen of final assignment performed by the
1393 // lastprivate clause.
1395 friend TrailingObjects;
1396 friend OMPVarListClause;
1397 friend class OMPClauseReader;
1399 /// \brief Build clause with number of variables \a N.
1401 /// \param StartLoc Starting location of the clause.
1402 /// \param LParenLoc Location of '('.
1403 /// \param EndLoc Ending location of the clause.
1404 /// \param N Number of the variables in the clause.
1406 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1407 SourceLocation EndLoc, unsigned N)
1408 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1409 LParenLoc, EndLoc, N) {}
1411 /// \brief Build an empty clause.
1413 /// \param N Number of variables.
1415 explicit OMPLastprivateClause(unsigned N)
1416 : OMPVarListClause<OMPLastprivateClause>(
1417 OMPC_lastprivate, SourceLocation(), SourceLocation(),
1418 SourceLocation(), N) {}
1420 /// \brief Get the list of helper expressions for initialization of private
1421 /// copies for lastprivate variables.
1422 MutableArrayRef<Expr *> getPrivateCopies() {
1423 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1425 ArrayRef<const Expr *> getPrivateCopies() const {
1426 return llvm::makeArrayRef(varlist_end(), varlist_size());
1429 /// \brief Set list of helper expressions, required for proper codegen of the
1430 /// clause. These expressions represent private variables (for arrays, single
1431 /// array element) in the final assignment statement performed by the
1432 /// lastprivate clause.
1433 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1435 /// \brief Get the list of helper source expressions.
1436 MutableArrayRef<Expr *> getSourceExprs() {
1437 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1439 ArrayRef<const Expr *> getSourceExprs() const {
1440 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1443 /// \brief Set list of helper expressions, required for proper codegen of the
1444 /// clause. These expressions represent original variables (for arrays, single
1445 /// array element) in the final assignment statement performed by the
1446 /// lastprivate clause.
1447 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1449 /// \brief Get the list of helper destination expressions.
1450 MutableArrayRef<Expr *> getDestinationExprs() {
1451 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1453 ArrayRef<const Expr *> getDestinationExprs() const {
1454 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1457 /// \brief Set list of helper assignment expressions, required for proper
1458 /// codegen of the clause. These expressions are assignment expressions that
1459 /// assign private copy of the variable to original variable.
1460 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1462 /// \brief Get the list of helper assignment expressions.
1463 MutableArrayRef<Expr *> getAssignmentOps() {
1464 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1466 ArrayRef<const Expr *> getAssignmentOps() const {
1467 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1471 /// \brief Creates clause with a list of variables \a VL.
1473 /// \param C AST context.
1474 /// \param StartLoc Starting location of the clause.
1475 /// \param LParenLoc Location of '('.
1476 /// \param EndLoc Ending location of the clause.
1477 /// \param VL List of references to the variables.
1478 /// \param SrcExprs List of helper expressions for proper generation of
1479 /// assignment operation required for lastprivate clause. This list represents
1480 /// private variables (for arrays, single array element).
1481 /// \param DstExprs List of helper expressions for proper generation of
1482 /// assignment operation required for lastprivate clause. This list represents
1483 /// original variables (for arrays, single array element).
1484 /// \param AssignmentOps List of helper expressions that represents assignment
1487 /// DstExprs = SrcExprs;
1489 /// Required for proper codegen of final assignment performed by the
1490 /// lastprivate clause.
1493 static OMPLastprivateClause *
1494 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1495 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1496 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
1497 /// \brief Creates an empty clause with the place for \a N variables.
1499 /// \param C AST context.
1500 /// \param N The number of variables.
1502 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1504 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1505 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1506 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1507 typedef llvm::iterator_range<helper_expr_const_iterator>
1508 helper_expr_const_range;
1510 /// \brief Set list of helper expressions, required for generation of private
1511 /// copies of original lastprivate variables.
1512 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1514 helper_expr_const_range private_copies() const {
1515 return helper_expr_const_range(getPrivateCopies().begin(),
1516 getPrivateCopies().end());
1518 helper_expr_range private_copies() {
1519 return helper_expr_range(getPrivateCopies().begin(),
1520 getPrivateCopies().end());
1522 helper_expr_const_range source_exprs() const {
1523 return helper_expr_const_range(getSourceExprs().begin(),
1524 getSourceExprs().end());
1526 helper_expr_range source_exprs() {
1527 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1529 helper_expr_const_range destination_exprs() const {
1530 return helper_expr_const_range(getDestinationExprs().begin(),
1531 getDestinationExprs().end());
1533 helper_expr_range destination_exprs() {
1534 return helper_expr_range(getDestinationExprs().begin(),
1535 getDestinationExprs().end());
1537 helper_expr_const_range assignment_ops() const {
1538 return helper_expr_const_range(getAssignmentOps().begin(),
1539 getAssignmentOps().end());
1541 helper_expr_range assignment_ops() {
1542 return helper_expr_range(getAssignmentOps().begin(),
1543 getAssignmentOps().end());
1546 child_range children() {
1547 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1548 reinterpret_cast<Stmt **>(varlist_end()));
1551 static bool classof(const OMPClause *T) {
1552 return T->getClauseKind() == OMPC_lastprivate;
1556 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
1559 /// #pragma omp parallel shared(a,b)
1561 /// In this example directive '#pragma omp parallel' has clause 'shared'
1562 /// with the variables 'a' and 'b'.
1564 class OMPSharedClause final
1565 : public OMPVarListClause<OMPSharedClause>,
1566 private llvm::TrailingObjects<OMPSharedClause, Expr *> {
1567 friend TrailingObjects;
1568 friend OMPVarListClause;
1569 /// \brief Build clause with number of variables \a N.
1571 /// \param StartLoc Starting location of the clause.
1572 /// \param LParenLoc Location of '('.
1573 /// \param EndLoc Ending location of the clause.
1574 /// \param N Number of the variables in the clause.
1576 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1577 SourceLocation EndLoc, unsigned N)
1578 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1581 /// \brief Build an empty clause.
1583 /// \param N Number of variables.
1585 explicit OMPSharedClause(unsigned N)
1586 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1587 SourceLocation(), SourceLocation(),
1591 /// \brief Creates clause with a list of variables \a VL.
1593 /// \param C AST context.
1594 /// \param StartLoc Starting location of the clause.
1595 /// \param LParenLoc Location of '('.
1596 /// \param EndLoc Ending location of the clause.
1597 /// \param VL List of references to the variables.
1599 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1600 SourceLocation LParenLoc,
1601 SourceLocation EndLoc, ArrayRef<Expr *> VL);
1602 /// \brief Creates an empty clause with \a N variables.
1604 /// \param C AST context.
1605 /// \param N The number of variables.
1607 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1609 child_range children() {
1610 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1611 reinterpret_cast<Stmt **>(varlist_end()));
1614 static bool classof(const OMPClause *T) {
1615 return T->getClauseKind() == OMPC_shared;
1619 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
1623 /// #pragma omp parallel reduction(+:a,b)
1625 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1626 /// with operator '+' and the variables 'a' and 'b'.
1628 class OMPReductionClause final
1629 : public OMPVarListClause<OMPReductionClause>,
1630 private llvm::TrailingObjects<OMPReductionClause, Expr *> {
1631 friend TrailingObjects;
1632 friend OMPVarListClause;
1633 friend class OMPClauseReader;
1634 /// \brief Location of ':'.
1635 SourceLocation ColonLoc;
1636 /// \brief Nested name specifier for C++.
1637 NestedNameSpecifierLoc QualifierLoc;
1638 /// \brief Name of custom operator.
1639 DeclarationNameInfo NameInfo;
1641 /// \brief Build clause with number of variables \a N.
1643 /// \param StartLoc Starting location of the clause.
1644 /// \param LParenLoc Location of '('.
1645 /// \param EndLoc Ending location of the clause.
1646 /// \param ColonLoc Location of ':'.
1647 /// \param N Number of the variables in the clause.
1648 /// \param QualifierLoc The nested-name qualifier with location information
1649 /// \param NameInfo The full name info for reduction identifier.
1651 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1652 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1653 NestedNameSpecifierLoc QualifierLoc,
1654 const DeclarationNameInfo &NameInfo)
1655 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1656 LParenLoc, EndLoc, N),
1657 ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1659 /// \brief Build an empty clause.
1661 /// \param N Number of variables.
1663 explicit OMPReductionClause(unsigned N)
1664 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1665 SourceLocation(), SourceLocation(),
1667 ColonLoc(), QualifierLoc(), NameInfo() {}
1669 /// \brief Sets location of ':' symbol in clause.
1670 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1671 /// \brief Sets the name info for specified reduction identifier.
1672 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1673 /// \brief Sets the nested name specifier.
1674 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1676 /// \brief Set list of helper expressions, required for proper codegen of the
1677 /// clause. These expressions represent private copy of the reduction
1679 void setPrivates(ArrayRef<Expr *> Privates);
1681 /// \brief Get the list of helper privates.
1682 MutableArrayRef<Expr *> getPrivates() {
1683 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1685 ArrayRef<const Expr *> getPrivates() const {
1686 return llvm::makeArrayRef(varlist_end(), varlist_size());
1689 /// \brief Set list of helper expressions, required for proper codegen of the
1690 /// clause. These expressions represent LHS expression in the final
1691 /// reduction expression performed by the reduction clause.
1692 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1694 /// \brief Get the list of helper LHS expressions.
1695 MutableArrayRef<Expr *> getLHSExprs() {
1696 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1698 ArrayRef<const Expr *> getLHSExprs() const {
1699 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1702 /// \brief Set list of helper expressions, required for proper codegen of the
1703 /// clause. These expressions represent RHS expression in the final
1704 /// reduction expression performed by the reduction clause.
1705 /// Also, variables in these expressions are used for proper initialization of
1706 /// reduction copies.
1707 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1709 /// \brief Get the list of helper destination expressions.
1710 MutableArrayRef<Expr *> getRHSExprs() {
1711 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1713 ArrayRef<const Expr *> getRHSExprs() const {
1714 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1717 /// \brief Set list of helper reduction expressions, required for proper
1718 /// codegen of the clause. These expressions are binary expressions or
1719 /// operator/custom reduction call that calculates new value from source
1720 /// helper expressions to destination helper expressions.
1721 void setReductionOps(ArrayRef<Expr *> ReductionOps);
1723 /// \brief Get the list of helper reduction expressions.
1724 MutableArrayRef<Expr *> getReductionOps() {
1725 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1727 ArrayRef<const Expr *> getReductionOps() const {
1728 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1732 /// \brief Creates clause with a list of variables \a VL.
1734 /// \param StartLoc Starting location of the clause.
1735 /// \param LParenLoc Location of '('.
1736 /// \param ColonLoc Location of ':'.
1737 /// \param EndLoc Ending location of the clause.
1738 /// \param VL The variables in the clause.
1739 /// \param QualifierLoc The nested-name qualifier with location information
1740 /// \param NameInfo The full name info for reduction identifier.
1741 /// \param Privates List of helper expressions for proper generation of
1743 /// \param LHSExprs List of helper expressions for proper generation of
1744 /// assignment operation required for copyprivate clause. This list represents
1745 /// LHSs of the reduction expressions.
1746 /// \param RHSExprs List of helper expressions for proper generation of
1747 /// assignment operation required for copyprivate clause. This list represents
1748 /// RHSs of the reduction expressions.
1749 /// Also, variables in these expressions are used for proper initialization of
1750 /// reduction copies.
1751 /// \param ReductionOps List of helper expressions that represents reduction
1754 /// LHSExprs binop RHSExprs;
1755 /// operator binop(LHSExpr, RHSExpr);
1756 /// <CutomReduction>(LHSExpr, RHSExpr);
1758 /// Required for proper codegen of final reduction operation performed by the
1759 /// reduction clause.
1761 static OMPReductionClause *
1762 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1763 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1764 NestedNameSpecifierLoc QualifierLoc,
1765 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
1766 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1767 ArrayRef<Expr *> ReductionOps);
1768 /// \brief Creates an empty clause with the place for \a N variables.
1770 /// \param C AST context.
1771 /// \param N The number of variables.
1773 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1775 /// \brief Gets location of ':' symbol in clause.
1776 SourceLocation getColonLoc() const { return ColonLoc; }
1777 /// \brief Gets the name info for specified reduction identifier.
1778 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1779 /// \brief Gets the nested name specifier.
1780 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1782 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1783 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1784 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1785 typedef llvm::iterator_range<helper_expr_const_iterator>
1786 helper_expr_const_range;
1788 helper_expr_const_range privates() const {
1789 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
1791 helper_expr_range privates() {
1792 return helper_expr_range(getPrivates().begin(), getPrivates().end());
1794 helper_expr_const_range lhs_exprs() const {
1795 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
1797 helper_expr_range lhs_exprs() {
1798 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
1800 helper_expr_const_range rhs_exprs() const {
1801 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
1803 helper_expr_range rhs_exprs() {
1804 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
1806 helper_expr_const_range reduction_ops() const {
1807 return helper_expr_const_range(getReductionOps().begin(),
1808 getReductionOps().end());
1810 helper_expr_range reduction_ops() {
1811 return helper_expr_range(getReductionOps().begin(),
1812 getReductionOps().end());
1815 child_range children() {
1816 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1817 reinterpret_cast<Stmt **>(varlist_end()));
1820 static bool classof(const OMPClause *T) {
1821 return T->getClauseKind() == OMPC_reduction;
1825 /// \brief This represents clause 'linear' in the '#pragma omp ...'
1829 /// #pragma omp simd linear(a,b : 2)
1831 /// In this example directive '#pragma omp simd' has clause 'linear'
1832 /// with variables 'a', 'b' and linear step '2'.
1834 class OMPLinearClause final
1835 : public OMPVarListClause<OMPLinearClause>,
1836 private llvm::TrailingObjects<OMPLinearClause, Expr *> {
1837 friend TrailingObjects;
1838 friend OMPVarListClause;
1839 friend class OMPClauseReader;
1840 /// \brief Modifier of 'linear' clause.
1841 OpenMPLinearClauseKind Modifier;
1842 /// \brief Location of linear modifier if any.
1843 SourceLocation ModifierLoc;
1844 /// \brief Location of ':'.
1845 SourceLocation ColonLoc;
1847 /// \brief Sets the linear step for clause.
1848 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
1850 /// \brief Sets the expression to calculate linear step for clause.
1851 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
1853 /// \brief Build 'linear' clause with given number of variables \a NumVars.
1855 /// \param StartLoc Starting location of the clause.
1856 /// \param LParenLoc Location of '('.
1857 /// \param ColonLoc Location of ':'.
1858 /// \param EndLoc Ending location of the clause.
1859 /// \param NumVars Number of variables.
1861 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1862 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
1863 SourceLocation ColonLoc, SourceLocation EndLoc,
1865 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
1867 Modifier(Modifier), ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
1869 /// \brief Build an empty clause.
1871 /// \param NumVars Number of variables.
1873 explicit OMPLinearClause(unsigned NumVars)
1874 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
1875 SourceLocation(), SourceLocation(),
1877 Modifier(OMPC_LINEAR_val), ModifierLoc(), ColonLoc() {}
1879 /// \brief Gets the list of initial values for linear variables.
1881 /// There are NumVars expressions with initial values allocated after the
1882 /// varlist, they are followed by NumVars update expressions (used to update
1883 /// the linear variable's value on current iteration) and they are followed by
1884 /// NumVars final expressions (used to calculate the linear variable's
1885 /// value after the loop body). After these lists, there are 2 helper
1886 /// expressions - linear step and a helper to calculate it before the
1887 /// loop body (used when the linear step is not constant):
1889 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
1890 /// Finals[]; Step; CalcStep; }
1892 MutableArrayRef<Expr *> getPrivates() {
1893 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1895 ArrayRef<const Expr *> getPrivates() const {
1896 return llvm::makeArrayRef(varlist_end(), varlist_size());
1899 MutableArrayRef<Expr *> getInits() {
1900 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1902 ArrayRef<const Expr *> getInits() const {
1903 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1906 /// \brief Sets the list of update expressions for linear variables.
1907 MutableArrayRef<Expr *> getUpdates() {
1908 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
1910 ArrayRef<const Expr *> getUpdates() const {
1911 return llvm::makeArrayRef(getInits().end(), varlist_size());
1914 /// \brief Sets the list of final update expressions for linear variables.
1915 MutableArrayRef<Expr *> getFinals() {
1916 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
1918 ArrayRef<const Expr *> getFinals() const {
1919 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
1922 /// \brief Sets the list of the copies of original linear variables.
1923 /// \param PL List of expressions.
1924 void setPrivates(ArrayRef<Expr *> PL);
1926 /// \brief Sets the list of the initial values for linear variables.
1927 /// \param IL List of expressions.
1928 void setInits(ArrayRef<Expr *> IL);
1931 /// \brief Creates clause with a list of variables \a VL and a linear step
1934 /// \param C AST Context.
1935 /// \param StartLoc Starting location of the clause.
1936 /// \param LParenLoc Location of '('.
1937 /// \param Modifier Modifier of 'linear' clause.
1938 /// \param ModifierLoc Modifier location.
1939 /// \param ColonLoc Location of ':'.
1940 /// \param EndLoc Ending location of the clause.
1941 /// \param VL List of references to the variables.
1942 /// \param PL List of private copies of original variables.
1943 /// \param IL List of initial values for the variables.
1944 /// \param Step Linear step.
1945 /// \param CalcStep Calculation of the linear step.
1946 static OMPLinearClause *
1947 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1948 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
1949 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1950 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep);
1952 /// \brief Creates an empty clause with the place for \a NumVars variables.
1954 /// \param C AST context.
1955 /// \param NumVars Number of variables.
1957 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1959 /// \brief Set modifier.
1960 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
1961 /// \brief Return modifier.
1962 OpenMPLinearClauseKind getModifier() const { return Modifier; }
1964 /// \brief Set modifier location.
1965 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
1966 /// \brief Return modifier location.
1967 SourceLocation getModifierLoc() const { return ModifierLoc; }
1969 /// \brief Sets the location of ':'.
1970 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1971 /// \brief Returns the location of ':'.
1972 SourceLocation getColonLoc() const { return ColonLoc; }
1974 /// \brief Returns linear step.
1975 Expr *getStep() { return *(getFinals().end()); }
1976 /// \brief Returns linear step.
1977 const Expr *getStep() const { return *(getFinals().end()); }
1978 /// \brief Returns expression to calculate linear step.
1979 Expr *getCalcStep() { return *(getFinals().end() + 1); }
1980 /// \brief Returns expression to calculate linear step.
1981 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
1983 /// \brief Sets the list of update expressions for linear variables.
1984 /// \param UL List of expressions.
1985 void setUpdates(ArrayRef<Expr *> UL);
1987 /// \brief Sets the list of final update expressions for linear variables.
1988 /// \param FL List of expressions.
1989 void setFinals(ArrayRef<Expr *> FL);
1991 typedef MutableArrayRef<Expr *>::iterator privates_iterator;
1992 typedef ArrayRef<const Expr *>::iterator privates_const_iterator;
1993 typedef llvm::iterator_range<privates_iterator> privates_range;
1994 typedef llvm::iterator_range<privates_const_iterator> privates_const_range;
1996 privates_range privates() {
1997 return privates_range(getPrivates().begin(), getPrivates().end());
1999 privates_const_range privates() const {
2000 return privates_const_range(getPrivates().begin(), getPrivates().end());
2003 typedef MutableArrayRef<Expr *>::iterator inits_iterator;
2004 typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
2005 typedef llvm::iterator_range<inits_iterator> inits_range;
2006 typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
2008 inits_range inits() {
2009 return inits_range(getInits().begin(), getInits().end());
2011 inits_const_range inits() const {
2012 return inits_const_range(getInits().begin(), getInits().end());
2015 typedef MutableArrayRef<Expr *>::iterator updates_iterator;
2016 typedef ArrayRef<const Expr *>::iterator updates_const_iterator;
2017 typedef llvm::iterator_range<updates_iterator> updates_range;
2018 typedef llvm::iterator_range<updates_const_iterator> updates_const_range;
2020 updates_range updates() {
2021 return updates_range(getUpdates().begin(), getUpdates().end());
2023 updates_const_range updates() const {
2024 return updates_const_range(getUpdates().begin(), getUpdates().end());
2027 typedef MutableArrayRef<Expr *>::iterator finals_iterator;
2028 typedef ArrayRef<const Expr *>::iterator finals_const_iterator;
2029 typedef llvm::iterator_range<finals_iterator> finals_range;
2030 typedef llvm::iterator_range<finals_const_iterator> finals_const_range;
2032 finals_range finals() {
2033 return finals_range(getFinals().begin(), getFinals().end());
2035 finals_const_range finals() const {
2036 return finals_const_range(getFinals().begin(), getFinals().end());
2039 child_range children() {
2040 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2041 reinterpret_cast<Stmt **>(varlist_end()));
2044 static bool classof(const OMPClause *T) {
2045 return T->getClauseKind() == OMPC_linear;
2049 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
2053 /// #pragma omp simd aligned(a,b : 8)
2055 /// In this example directive '#pragma omp simd' has clause 'aligned'
2056 /// with variables 'a', 'b' and alignment '8'.
2058 class OMPAlignedClause final
2059 : public OMPVarListClause<OMPAlignedClause>,
2060 private llvm::TrailingObjects<OMPAlignedClause, Expr *> {
2061 friend TrailingObjects;
2062 friend OMPVarListClause;
2063 friend class OMPClauseReader;
2064 /// \brief Location of ':'.
2065 SourceLocation ColonLoc;
2067 /// \brief Sets the alignment for clause.
2068 void setAlignment(Expr *A) { *varlist_end() = A; }
2070 /// \brief Build 'aligned' clause with given number of variables \a NumVars.
2072 /// \param StartLoc Starting location of the clause.
2073 /// \param LParenLoc Location of '('.
2074 /// \param ColonLoc Location of ':'.
2075 /// \param EndLoc Ending location of the clause.
2076 /// \param NumVars Number of variables.
2078 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2079 SourceLocation ColonLoc, SourceLocation EndLoc,
2081 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
2083 ColonLoc(ColonLoc) {}
2085 /// \brief Build an empty clause.
2087 /// \param NumVars Number of variables.
2089 explicit OMPAlignedClause(unsigned NumVars)
2090 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
2091 SourceLocation(), SourceLocation(),
2093 ColonLoc(SourceLocation()) {}
2096 /// \brief Creates clause with a list of variables \a VL and alignment \a A.
2098 /// \param C AST Context.
2099 /// \param StartLoc Starting location of the clause.
2100 /// \param LParenLoc Location of '('.
2101 /// \param ColonLoc Location of ':'.
2102 /// \param EndLoc Ending location of the clause.
2103 /// \param VL List of references to the variables.
2104 /// \param A Alignment.
2105 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2106 SourceLocation LParenLoc,
2107 SourceLocation ColonLoc,
2108 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2111 /// \brief Creates an empty clause with the place for \a NumVars variables.
2113 /// \param C AST context.
2114 /// \param NumVars Number of variables.
2116 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2118 /// \brief Sets the location of ':'.
2119 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2120 /// \brief Returns the location of ':'.
2121 SourceLocation getColonLoc() const { return ColonLoc; }
2123 /// \brief Returns alignment.
2124 Expr *getAlignment() { return *varlist_end(); }
2125 /// \brief Returns alignment.
2126 const Expr *getAlignment() const { return *varlist_end(); }
2128 child_range children() {
2129 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2130 reinterpret_cast<Stmt **>(varlist_end()));
2133 static bool classof(const OMPClause *T) {
2134 return T->getClauseKind() == OMPC_aligned;
2138 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
2141 /// #pragma omp parallel copyin(a,b)
2143 /// In this example directive '#pragma omp parallel' has clause 'copyin'
2144 /// with the variables 'a' and 'b'.
2146 class OMPCopyinClause final
2147 : public OMPVarListClause<OMPCopyinClause>,
2148 private llvm::TrailingObjects<OMPCopyinClause, Expr *> {
2149 // Class has 3 additional tail allocated arrays:
2150 // 1. List of helper expressions for proper generation of assignment operation
2151 // required for copyin clause. This list represents sources.
2152 // 2. List of helper expressions for proper generation of assignment operation
2153 // required for copyin clause. This list represents destinations.
2154 // 3. List of helper expressions that represents assignment operation:
2156 // DstExprs = SrcExprs;
2158 // Required for proper codegen of propagation of master's thread values of
2159 // threadprivate variables to local instances of that variables in other
2160 // implicit threads.
2162 friend TrailingObjects;
2163 friend OMPVarListClause;
2164 friend class OMPClauseReader;
2165 /// \brief Build clause with number of variables \a N.
2167 /// \param StartLoc Starting location of the clause.
2168 /// \param LParenLoc Location of '('.
2169 /// \param EndLoc Ending location of the clause.
2170 /// \param N Number of the variables in the clause.
2172 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2173 SourceLocation EndLoc, unsigned N)
2174 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
2177 /// \brief Build an empty clause.
2179 /// \param N Number of variables.
2181 explicit OMPCopyinClause(unsigned N)
2182 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
2183 SourceLocation(), SourceLocation(),
2186 /// \brief Set list of helper expressions, required for proper codegen of the
2187 /// clause. These expressions represent source expression in the final
2188 /// assignment statement performed by the copyin clause.
2189 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2191 /// \brief Get the list of helper source expressions.
2192 MutableArrayRef<Expr *> getSourceExprs() {
2193 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2195 ArrayRef<const Expr *> getSourceExprs() const {
2196 return llvm::makeArrayRef(varlist_end(), varlist_size());
2199 /// \brief Set list of helper expressions, required for proper codegen of the
2200 /// clause. These expressions represent destination expression in the final
2201 /// assignment statement performed by the copyin clause.
2202 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2204 /// \brief Get the list of helper destination expressions.
2205 MutableArrayRef<Expr *> getDestinationExprs() {
2206 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2208 ArrayRef<const Expr *> getDestinationExprs() const {
2209 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2212 /// \brief Set list of helper assignment expressions, required for proper
2213 /// codegen of the clause. These expressions are assignment expressions that
2214 /// assign source helper expressions to destination helper expressions
2215 /// correspondingly.
2216 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2218 /// \brief Get the list of helper assignment expressions.
2219 MutableArrayRef<Expr *> getAssignmentOps() {
2220 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2222 ArrayRef<const Expr *> getAssignmentOps() const {
2223 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2227 /// \brief Creates clause with a list of variables \a VL.
2229 /// \param C AST context.
2230 /// \param StartLoc Starting location of the clause.
2231 /// \param LParenLoc Location of '('.
2232 /// \param EndLoc Ending location of the clause.
2233 /// \param VL List of references to the variables.
2234 /// \param SrcExprs List of helper expressions for proper generation of
2235 /// assignment operation required for copyin clause. This list represents
2237 /// \param DstExprs List of helper expressions for proper generation of
2238 /// assignment operation required for copyin clause. This list represents
2240 /// \param AssignmentOps List of helper expressions that represents assignment
2243 /// DstExprs = SrcExprs;
2245 /// Required for proper codegen of propagation of master's thread values of
2246 /// threadprivate variables to local instances of that variables in other
2247 /// implicit threads.
2249 static OMPCopyinClause *
2250 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2251 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2252 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2253 /// \brief Creates an empty clause with \a N variables.
2255 /// \param C AST context.
2256 /// \param N The number of variables.
2258 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
2260 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2261 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2262 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2263 typedef llvm::iterator_range<helper_expr_const_iterator>
2264 helper_expr_const_range;
2266 helper_expr_const_range source_exprs() const {
2267 return helper_expr_const_range(getSourceExprs().begin(),
2268 getSourceExprs().end());
2270 helper_expr_range source_exprs() {
2271 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2273 helper_expr_const_range destination_exprs() const {
2274 return helper_expr_const_range(getDestinationExprs().begin(),
2275 getDestinationExprs().end());
2277 helper_expr_range destination_exprs() {
2278 return helper_expr_range(getDestinationExprs().begin(),
2279 getDestinationExprs().end());
2281 helper_expr_const_range assignment_ops() const {
2282 return helper_expr_const_range(getAssignmentOps().begin(),
2283 getAssignmentOps().end());
2285 helper_expr_range assignment_ops() {
2286 return helper_expr_range(getAssignmentOps().begin(),
2287 getAssignmentOps().end());
2290 child_range children() {
2291 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2292 reinterpret_cast<Stmt **>(varlist_end()));
2295 static bool classof(const OMPClause *T) {
2296 return T->getClauseKind() == OMPC_copyin;
2300 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
2304 /// #pragma omp single copyprivate(a,b)
2306 /// In this example directive '#pragma omp single' has clause 'copyprivate'
2307 /// with the variables 'a' and 'b'.
2309 class OMPCopyprivateClause final
2310 : public OMPVarListClause<OMPCopyprivateClause>,
2311 private llvm::TrailingObjects<OMPCopyprivateClause, Expr *> {
2312 friend TrailingObjects;
2313 friend OMPVarListClause;
2314 friend class OMPClauseReader;
2315 /// \brief Build clause with number of variables \a N.
2317 /// \param StartLoc Starting location of the clause.
2318 /// \param LParenLoc Location of '('.
2319 /// \param EndLoc Ending location of the clause.
2320 /// \param N Number of the variables in the clause.
2322 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2323 SourceLocation EndLoc, unsigned N)
2324 : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
2325 LParenLoc, EndLoc, N) {}
2327 /// \brief Build an empty clause.
2329 /// \param N Number of variables.
2331 explicit OMPCopyprivateClause(unsigned N)
2332 : OMPVarListClause<OMPCopyprivateClause>(
2333 OMPC_copyprivate, SourceLocation(), SourceLocation(),
2334 SourceLocation(), N) {}
2336 /// \brief Set list of helper expressions, required for proper codegen of the
2337 /// clause. These expressions represent source expression in the final
2338 /// assignment statement performed by the copyprivate clause.
2339 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2341 /// \brief Get the list of helper source expressions.
2342 MutableArrayRef<Expr *> getSourceExprs() {
2343 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2345 ArrayRef<const Expr *> getSourceExprs() const {
2346 return llvm::makeArrayRef(varlist_end(), varlist_size());
2349 /// \brief Set list of helper expressions, required for proper codegen of the
2350 /// clause. These expressions represent destination expression in the final
2351 /// assignment statement performed by the copyprivate clause.
2352 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2354 /// \brief Get the list of helper destination expressions.
2355 MutableArrayRef<Expr *> getDestinationExprs() {
2356 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2358 ArrayRef<const Expr *> getDestinationExprs() const {
2359 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2362 /// \brief Set list of helper assignment expressions, required for proper
2363 /// codegen of the clause. These expressions are assignment expressions that
2364 /// assign source helper expressions to destination helper expressions
2365 /// correspondingly.
2366 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2368 /// \brief Get the list of helper assignment expressions.
2369 MutableArrayRef<Expr *> getAssignmentOps() {
2370 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2372 ArrayRef<const Expr *> getAssignmentOps() const {
2373 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2377 /// \brief Creates clause with a list of variables \a VL.
2379 /// \param C AST context.
2380 /// \param StartLoc Starting location of the clause.
2381 /// \param LParenLoc Location of '('.
2382 /// \param EndLoc Ending location of the clause.
2383 /// \param VL List of references to the variables.
2384 /// \param SrcExprs List of helper expressions for proper generation of
2385 /// assignment operation required for copyprivate clause. This list represents
2387 /// \param DstExprs List of helper expressions for proper generation of
2388 /// assignment operation required for copyprivate clause. This list represents
2390 /// \param AssignmentOps List of helper expressions that represents assignment
2393 /// DstExprs = SrcExprs;
2395 /// Required for proper codegen of final assignment performed by the
2396 /// copyprivate clause.
2398 static OMPCopyprivateClause *
2399 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2400 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2401 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2402 /// \brief Creates an empty clause with \a N variables.
2404 /// \param C AST context.
2405 /// \param N The number of variables.
2407 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2409 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2410 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2411 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2412 typedef llvm::iterator_range<helper_expr_const_iterator>
2413 helper_expr_const_range;
2415 helper_expr_const_range source_exprs() const {
2416 return helper_expr_const_range(getSourceExprs().begin(),
2417 getSourceExprs().end());
2419 helper_expr_range source_exprs() {
2420 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2422 helper_expr_const_range destination_exprs() const {
2423 return helper_expr_const_range(getDestinationExprs().begin(),
2424 getDestinationExprs().end());
2426 helper_expr_range destination_exprs() {
2427 return helper_expr_range(getDestinationExprs().begin(),
2428 getDestinationExprs().end());
2430 helper_expr_const_range assignment_ops() const {
2431 return helper_expr_const_range(getAssignmentOps().begin(),
2432 getAssignmentOps().end());
2434 helper_expr_range assignment_ops() {
2435 return helper_expr_range(getAssignmentOps().begin(),
2436 getAssignmentOps().end());
2439 child_range children() {
2440 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2441 reinterpret_cast<Stmt **>(varlist_end()));
2444 static bool classof(const OMPClause *T) {
2445 return T->getClauseKind() == OMPC_copyprivate;
2449 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
2451 /// This clause does not exist by itself, it can be only as a part of 'omp
2452 /// flush' directive. This clause is introduced to keep the original structure
2453 /// of \a OMPExecutableDirective class and its derivatives and to use the
2454 /// existing infrastructure of clauses with the list of variables.
2457 /// #pragma omp flush(a,b)
2459 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
2460 /// with the variables 'a' and 'b'.
2462 class OMPFlushClause final
2463 : public OMPVarListClause<OMPFlushClause>,
2464 private llvm::TrailingObjects<OMPFlushClause, Expr *> {
2465 friend TrailingObjects;
2466 friend OMPVarListClause;
2467 /// \brief Build clause with number of variables \a N.
2469 /// \param StartLoc Starting location of the clause.
2470 /// \param LParenLoc Location of '('.
2471 /// \param EndLoc Ending location of the clause.
2472 /// \param N Number of the variables in the clause.
2474 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2475 SourceLocation EndLoc, unsigned N)
2476 : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
2479 /// \brief Build an empty clause.
2481 /// \param N Number of variables.
2483 explicit OMPFlushClause(unsigned N)
2484 : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
2485 SourceLocation(), SourceLocation(),
2489 /// \brief Creates clause with a list of variables \a VL.
2491 /// \param C AST context.
2492 /// \param StartLoc Starting location of the clause.
2493 /// \param LParenLoc Location of '('.
2494 /// \param EndLoc Ending location of the clause.
2495 /// \param VL List of references to the variables.
2497 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
2498 SourceLocation LParenLoc, SourceLocation EndLoc,
2499 ArrayRef<Expr *> VL);
2500 /// \brief Creates an empty clause with \a N variables.
2502 /// \param C AST context.
2503 /// \param N The number of variables.
2505 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
2507 child_range children() {
2508 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2509 reinterpret_cast<Stmt **>(varlist_end()));
2512 static bool classof(const OMPClause *T) {
2513 return T->getClauseKind() == OMPC_flush;
2517 /// \brief This represents implicit clause 'depend' for the '#pragma omp task'
2521 /// #pragma omp task depend(in:a,b)
2523 /// In this example directive '#pragma omp task' with clause 'depend' with the
2524 /// variables 'a' and 'b' with dependency 'in'.
2526 class OMPDependClause final
2527 : public OMPVarListClause<OMPDependClause>,
2528 private llvm::TrailingObjects<OMPDependClause, Expr *> {
2529 friend TrailingObjects;
2530 friend OMPVarListClause;
2531 friend class OMPClauseReader;
2532 /// \brief Dependency type (one of in, out, inout).
2533 OpenMPDependClauseKind DepKind;
2534 /// \brief Dependency type location.
2535 SourceLocation DepLoc;
2536 /// \brief Colon location.
2537 SourceLocation ColonLoc;
2538 /// \brief Build clause with number of variables \a N.
2540 /// \param StartLoc Starting location of the clause.
2541 /// \param LParenLoc Location of '('.
2542 /// \param EndLoc Ending location of the clause.
2543 /// \param N Number of the variables in the clause.
2545 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2546 SourceLocation EndLoc, unsigned N)
2547 : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
2549 DepKind(OMPC_DEPEND_unknown) {}
2551 /// \brief Build an empty clause.
2553 /// \param N Number of variables.
2555 explicit OMPDependClause(unsigned N)
2556 : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
2557 SourceLocation(), SourceLocation(),
2559 DepKind(OMPC_DEPEND_unknown) {}
2560 /// \brief Set dependency kind.
2561 void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
2563 /// \brief Set dependency kind and its location.
2564 void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
2566 /// \brief Set colon location.
2567 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2570 /// \brief Creates clause with a list of variables \a VL.
2572 /// \param C AST context.
2573 /// \param StartLoc Starting location of the clause.
2574 /// \param LParenLoc Location of '('.
2575 /// \param EndLoc Ending location of the clause.
2576 /// \param DepKind Dependency type.
2577 /// \param DepLoc Location of the dependency type.
2578 /// \param ColonLoc Colon location.
2579 /// \param VL List of references to the variables.
2581 static OMPDependClause *
2582 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2583 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
2584 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL);
2585 /// \brief Creates an empty clause with \a N variables.
2587 /// \param C AST context.
2588 /// \param N The number of variables.
2590 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N);
2592 /// \brief Get dependency type.
2593 OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
2594 /// \brief Get dependency type location.
2595 SourceLocation getDependencyLoc() const { return DepLoc; }
2596 /// \brief Get colon location.
2597 SourceLocation getColonLoc() const { return ColonLoc; }
2599 child_range children() {
2600 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2601 reinterpret_cast<Stmt **>(varlist_end()));
2604 static bool classof(const OMPClause *T) {
2605 return T->getClauseKind() == OMPC_depend;
2609 /// \brief This represents 'device' clause in the '#pragma omp ...'
2613 /// #pragma omp target device(a)
2615 /// In this example directive '#pragma omp target' has clause 'device'
2616 /// with single expression 'a'.
2618 class OMPDeviceClause : public OMPClause {
2619 friend class OMPClauseReader;
2620 /// \brief Location of '('.
2621 SourceLocation LParenLoc;
2622 /// \brief Device number.
2624 /// \brief Set the device number.
2626 /// \param E Device number.
2628 void setDevice(Expr *E) { Device = E; }
2631 /// \brief Build 'device' clause.
2633 /// \param E Expression associated with this clause.
2634 /// \param StartLoc Starting location of the clause.
2635 /// \param LParenLoc Location of '('.
2636 /// \param EndLoc Ending location of the clause.
2638 OMPDeviceClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2639 SourceLocation EndLoc)
2640 : OMPClause(OMPC_device, StartLoc, EndLoc), LParenLoc(LParenLoc),
2643 /// \brief Build an empty clause.
2646 : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
2647 LParenLoc(SourceLocation()), Device(nullptr) {}
2648 /// \brief Sets the location of '('.
2649 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2650 /// \brief Returns the location of '('.
2651 SourceLocation getLParenLoc() const { return LParenLoc; }
2652 /// \brief Return device number.
2653 Expr *getDevice() { return cast<Expr>(Device); }
2654 /// \brief Return device number.
2655 Expr *getDevice() const { return cast<Expr>(Device); }
2657 static bool classof(const OMPClause *T) {
2658 return T->getClauseKind() == OMPC_device;
2661 child_range children() { return child_range(&Device, &Device + 1); }
2664 /// \brief This represents 'threads' clause in the '#pragma omp ...' directive.
2667 /// #pragma omp ordered threads
2669 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
2671 class OMPThreadsClause : public OMPClause {
2673 /// \brief Build 'threads' clause.
2675 /// \param StartLoc Starting location of the clause.
2676 /// \param EndLoc Ending location of the clause.
2678 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
2679 : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
2681 /// \brief Build an empty clause.
2684 : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
2686 static bool classof(const OMPClause *T) {
2687 return T->getClauseKind() == OMPC_threads;
2690 child_range children() {
2691 return child_range(child_iterator(), child_iterator());
2695 /// \brief This represents 'simd' clause in the '#pragma omp ...' directive.
2698 /// #pragma omp ordered simd
2700 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
2702 class OMPSIMDClause : public OMPClause {
2704 /// \brief Build 'simd' clause.
2706 /// \param StartLoc Starting location of the clause.
2707 /// \param EndLoc Ending location of the clause.
2709 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
2710 : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
2712 /// \brief Build an empty clause.
2714 OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
2716 static bool classof(const OMPClause *T) {
2717 return T->getClauseKind() == OMPC_simd;
2720 child_range children() {
2721 return child_range(child_iterator(), child_iterator());
2725 /// \brief This represents clause 'map' in the '#pragma omp ...'
2729 /// #pragma omp target map(a,b)
2731 /// In this example directive '#pragma omp target' has clause 'map'
2732 /// with the variables 'a' and 'b'.
2734 class OMPMapClause final : public OMPVarListClause<OMPMapClause>,
2735 private llvm::TrailingObjects<OMPMapClause, Expr *> {
2736 friend TrailingObjects;
2737 friend OMPVarListClause;
2738 friend class OMPClauseReader;
2740 /// \brief Map type modifier for the 'map' clause.
2741 OpenMPMapClauseKind MapTypeModifier;
2742 /// \brief Map type for the 'map' clause.
2743 OpenMPMapClauseKind MapType;
2744 /// \brief Location of the map type.
2745 SourceLocation MapLoc;
2746 /// \brief Colon location.
2747 SourceLocation ColonLoc;
2749 /// \brief Set type modifier for the clause.
2751 /// \param T Type Modifier for the clause.
2753 void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; }
2755 /// \brief Set type for the clause.
2757 /// \param T Type for the clause.
2759 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
2761 /// \brief Set type location.
2763 /// \param TLoc Type location.
2765 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
2767 /// \brief Set colon location.
2768 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2770 /// \brief Build clause with number of variables \a N.
2772 /// \param MapTypeModifier Map type modifier.
2773 /// \param MapType Map type.
2774 /// \param MapLoc Location of the map type.
2775 /// \param StartLoc Starting location of the clause.
2776 /// \param EndLoc Ending location of the clause.
2777 /// \param N Number of the variables in the clause.
2779 explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier,
2780 OpenMPMapClauseKind MapType, SourceLocation MapLoc,
2781 SourceLocation StartLoc, SourceLocation LParenLoc,
2782 SourceLocation EndLoc, unsigned N)
2783 : OMPVarListClause<OMPMapClause>(OMPC_map, StartLoc, LParenLoc, EndLoc, N),
2784 MapTypeModifier(MapTypeModifier), MapType(MapType), MapLoc(MapLoc) {}
2786 /// \brief Build an empty clause.
2788 /// \param N Number of variables.
2790 explicit OMPMapClause(unsigned N)
2791 : OMPVarListClause<OMPMapClause>(OMPC_map, SourceLocation(),
2792 SourceLocation(), SourceLocation(), N),
2793 MapTypeModifier(OMPC_MAP_unknown), MapType(OMPC_MAP_unknown), MapLoc() {}
2796 /// \brief Creates clause with a list of variables \a VL.
2798 /// \param C AST context.
2799 /// \param StartLoc Starting location of the clause.
2800 /// \param EndLoc Ending location of the clause.
2801 /// \param VL List of references to the variables.
2802 /// \param TypeModifier Map type modifier.
2803 /// \param Type Map type.
2804 /// \param TypeLoc Location of the map type.
2806 static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc,
2807 SourceLocation LParenLoc,
2808 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2809 OpenMPMapClauseKind TypeModifier,
2810 OpenMPMapClauseKind Type, SourceLocation TypeLoc);
2811 /// \brief Creates an empty clause with the place for \a N variables.
2813 /// \param C AST context.
2814 /// \param N The number of variables.
2816 static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned N);
2818 /// \brief Fetches mapping kind for the clause.
2819 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
2821 /// \brief Fetches the map type modifier for the clause.
2822 OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY {
2823 return MapTypeModifier;
2826 /// \brief Fetches location of clause mapping kind.
2827 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
2829 /// \brief Get colon location.
2830 SourceLocation getColonLoc() const { return ColonLoc; }
2832 static bool classof(const OMPClause *T) {
2833 return T->getClauseKind() == OMPC_map;
2836 child_range children() {
2838 reinterpret_cast<Stmt **>(varlist_begin()),
2839 reinterpret_cast<Stmt **>(varlist_end()));
2843 /// \brief This represents 'num_teams' clause in the '#pragma omp ...'
2847 /// #pragma omp teams num_teams(n)
2849 /// In this example directive '#pragma omp teams' has clause 'num_teams'
2850 /// with single expression 'n'.
2852 class OMPNumTeamsClause : public OMPClause {
2853 friend class OMPClauseReader;
2854 /// \brief Location of '('.
2855 SourceLocation LParenLoc;
2856 /// \brief NumTeams number.
2858 /// \brief Set the NumTeams number.
2860 /// \param E NumTeams number.
2862 void setNumTeams(Expr *E) { NumTeams = E; }
2865 /// \brief Build 'num_teams' clause.
2867 /// \param E Expression associated with this clause.
2868 /// \param StartLoc Starting location of the clause.
2869 /// \param LParenLoc Location of '('.
2870 /// \param EndLoc Ending location of the clause.
2872 OMPNumTeamsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2873 SourceLocation EndLoc)
2874 : OMPClause(OMPC_num_teams, StartLoc, EndLoc), LParenLoc(LParenLoc),
2877 /// \brief Build an empty clause.
2880 : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
2881 LParenLoc(SourceLocation()), NumTeams(nullptr) {}
2882 /// \brief Sets the location of '('.
2883 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2884 /// \brief Returns the location of '('.
2885 SourceLocation getLParenLoc() const { return LParenLoc; }
2886 /// \brief Return NumTeams number.
2887 Expr *getNumTeams() { return cast<Expr>(NumTeams); }
2888 /// \brief Return NumTeams number.
2889 Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
2891 static bool classof(const OMPClause *T) {
2892 return T->getClauseKind() == OMPC_num_teams;
2895 child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
2898 /// \brief This represents 'thread_limit' clause in the '#pragma omp ...'
2902 /// #pragma omp teams thread_limit(n)
2904 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
2905 /// with single expression 'n'.
2907 class OMPThreadLimitClause : public OMPClause {
2908 friend class OMPClauseReader;
2909 /// \brief Location of '('.
2910 SourceLocation LParenLoc;
2911 /// \brief ThreadLimit number.
2913 /// \brief Set the ThreadLimit number.
2915 /// \param E ThreadLimit number.
2917 void setThreadLimit(Expr *E) { ThreadLimit = E; }
2920 /// \brief Build 'thread_limit' clause.
2922 /// \param E Expression associated with this clause.
2923 /// \param StartLoc Starting location of the clause.
2924 /// \param LParenLoc Location of '('.
2925 /// \param EndLoc Ending location of the clause.
2927 OMPThreadLimitClause(Expr *E, SourceLocation StartLoc,
2928 SourceLocation LParenLoc, SourceLocation EndLoc)
2929 : OMPClause(OMPC_thread_limit, StartLoc, EndLoc), LParenLoc(LParenLoc),
2932 /// \brief Build an empty clause.
2934 OMPThreadLimitClause()
2935 : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
2936 LParenLoc(SourceLocation()), ThreadLimit(nullptr) {}
2937 /// \brief Sets the location of '('.
2938 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2939 /// \brief Returns the location of '('.
2940 SourceLocation getLParenLoc() const { return LParenLoc; }
2941 /// \brief Return ThreadLimit number.
2942 Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
2943 /// \brief Return ThreadLimit number.
2944 Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
2946 static bool classof(const OMPClause *T) {
2947 return T->getClauseKind() == OMPC_thread_limit;
2950 child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
2953 /// \brief This represents 'priority' clause in the '#pragma omp ...'
2957 /// #pragma omp task priority(n)
2959 /// In this example directive '#pragma omp teams' has clause 'priority' with
2960 /// single expression 'n'.
2962 class OMPPriorityClause : public OMPClause {
2963 friend class OMPClauseReader;
2964 /// \brief Location of '('.
2965 SourceLocation LParenLoc;
2966 /// \brief Priority number.
2968 /// \brief Set the Priority number.
2970 /// \param E Priority number.
2972 void setPriority(Expr *E) { Priority = E; }
2975 /// \brief Build 'priority' clause.
2977 /// \param E Expression associated with this clause.
2978 /// \param StartLoc Starting location of the clause.
2979 /// \param LParenLoc Location of '('.
2980 /// \param EndLoc Ending location of the clause.
2982 OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2983 SourceLocation EndLoc)
2984 : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
2987 /// \brief Build an empty clause.
2990 : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()),
2991 LParenLoc(SourceLocation()), Priority(nullptr) {}
2992 /// \brief Sets the location of '('.
2993 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2994 /// \brief Returns the location of '('.
2995 SourceLocation getLParenLoc() const { return LParenLoc; }
2996 /// \brief Return Priority number.
2997 Expr *getPriority() { return cast<Expr>(Priority); }
2998 /// \brief Return Priority number.
2999 Expr *getPriority() const { return cast<Expr>(Priority); }
3001 static bool classof(const OMPClause *T) {
3002 return T->getClauseKind() == OMPC_priority;
3005 child_range children() { return child_range(&Priority, &Priority + 1); }
3008 /// \brief This represents 'grainsize' clause in the '#pragma omp ...'
3012 /// #pragma omp taskloop grainsize(4)
3014 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
3015 /// with single expression '4'.
3017 class OMPGrainsizeClause : public OMPClause {
3018 friend class OMPClauseReader;
3019 /// \brief Location of '('.
3020 SourceLocation LParenLoc;
3021 /// \brief Safe iteration space distance.
3024 /// \brief Set safelen.
3025 void setGrainsize(Expr *Size) { Grainsize = Size; }
3028 /// \brief Build 'grainsize' clause.
3030 /// \param Size Expression associated with this clause.
3031 /// \param StartLoc Starting location of the clause.
3032 /// \param EndLoc Ending location of the clause.
3034 OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
3035 SourceLocation LParenLoc, SourceLocation EndLoc)
3036 : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
3039 /// \brief Build an empty clause.
3041 explicit OMPGrainsizeClause()
3042 : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()),
3043 LParenLoc(SourceLocation()), Grainsize(nullptr) {}
3045 /// \brief Sets the location of '('.
3046 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3047 /// \brief Returns the location of '('.
3048 SourceLocation getLParenLoc() const { return LParenLoc; }
3050 /// \brief Return safe iteration space distance.
3051 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
3053 static bool classof(const OMPClause *T) {
3054 return T->getClauseKind() == OMPC_grainsize;
3057 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
3060 /// \brief This represents 'nogroup' clause in the '#pragma omp ...' directive.
3063 /// #pragma omp taskloop nogroup
3065 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
3067 class OMPNogroupClause : public OMPClause {
3069 /// \brief Build 'nogroup' clause.
3071 /// \param StartLoc Starting location of the clause.
3072 /// \param EndLoc Ending location of the clause.
3074 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
3075 : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
3077 /// \brief Build an empty clause.
3080 : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
3082 static bool classof(const OMPClause *T) {
3083 return T->getClauseKind() == OMPC_nogroup;
3086 child_range children() {
3087 return child_range(child_iterator(), child_iterator());
3091 /// \brief This represents 'num_tasks' clause in the '#pragma omp ...'
3095 /// #pragma omp taskloop num_tasks(4)
3097 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
3098 /// with single expression '4'.
3100 class OMPNumTasksClause : public OMPClause {
3101 friend class OMPClauseReader;
3102 /// \brief Location of '('.
3103 SourceLocation LParenLoc;
3104 /// \brief Safe iteration space distance.
3107 /// \brief Set safelen.
3108 void setNumTasks(Expr *Size) { NumTasks = Size; }
3111 /// \brief Build 'num_tasks' clause.
3113 /// \param Size Expression associated with this clause.
3114 /// \param StartLoc Starting location of the clause.
3115 /// \param EndLoc Ending location of the clause.
3117 OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
3118 SourceLocation LParenLoc, SourceLocation EndLoc)
3119 : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
3122 /// \brief Build an empty clause.
3124 explicit OMPNumTasksClause()
3125 : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()),
3126 LParenLoc(SourceLocation()), NumTasks(nullptr) {}
3128 /// \brief Sets the location of '('.
3129 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3130 /// \brief Returns the location of '('.
3131 SourceLocation getLParenLoc() const { return LParenLoc; }
3133 /// \brief Return safe iteration space distance.
3134 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
3136 static bool classof(const OMPClause *T) {
3137 return T->getClauseKind() == OMPC_num_tasks;
3140 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
3143 /// \brief This represents 'hint' clause in the '#pragma omp ...' directive.
3146 /// #pragma omp critical (name) hint(6)
3148 /// In this example directive '#pragma omp critical' has name 'name' and clause
3149 /// 'hint' with argument '6'.
3151 class OMPHintClause : public OMPClause {
3152 friend class OMPClauseReader;
3153 /// \brief Location of '('.
3154 SourceLocation LParenLoc;
3155 /// \brief Hint expression of the 'hint' clause.
3158 /// \brief Set hint expression.
3160 void setHint(Expr *H) { Hint = H; }
3163 /// \brief Build 'hint' clause with expression \a Hint.
3165 /// \param Hint Hint expression.
3166 /// \param StartLoc Starting location of the clause.
3167 /// \param LParenLoc Location of '('.
3168 /// \param EndLoc Ending location of the clause.
3170 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
3171 SourceLocation EndLoc)
3172 : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
3175 /// \brief Build an empty clause.
3178 : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()),
3179 LParenLoc(SourceLocation()), Hint(nullptr) {}
3181 /// \brief Sets the location of '('.
3182 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3183 /// \brief Returns the location of '('.
3184 SourceLocation getLParenLoc() const { return LParenLoc; }
3186 /// \brief Returns number of threads.
3187 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
3189 static bool classof(const OMPClause *T) {
3190 return T->getClauseKind() == OMPC_hint;
3193 child_range children() { return child_range(&Hint, &Hint + 1); }
3196 } // end namespace clang
3198 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H