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 reinterpret_cast<Expr **>(
88 reinterpret_cast<char *>(this) +
89 llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())),
93 /// \brief Sets the list of variables for this clause.
94 void setVarRefs(ArrayRef<Expr *> VL) {
95 assert(VL.size() == NumVars &&
96 "Number of variables is not the same as the preallocated buffer");
99 reinterpret_cast<Expr **>(
100 reinterpret_cast<char *>(this) +
101 llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<Expr *>())));
104 /// \brief Build a clause with \a N variables
106 /// \param K Kind of the clause.
107 /// \param StartLoc Starting location of the clause (the clause keyword).
108 /// \param LParenLoc Location of '('.
109 /// \param EndLoc Ending location of the clause.
110 /// \param N Number of the variables in the clause.
112 OMPVarListClause(OpenMPClauseKind K, SourceLocation StartLoc,
113 SourceLocation LParenLoc, SourceLocation EndLoc, unsigned N)
114 : OMPClause(K, StartLoc, EndLoc), LParenLoc(LParenLoc), NumVars(N) {}
117 typedef MutableArrayRef<Expr *>::iterator varlist_iterator;
118 typedef ArrayRef<const Expr *>::iterator varlist_const_iterator;
119 typedef llvm::iterator_range<varlist_iterator> varlist_range;
120 typedef llvm::iterator_range<varlist_const_iterator> varlist_const_range;
122 unsigned varlist_size() const { return NumVars; }
123 bool varlist_empty() const { return NumVars == 0; }
125 varlist_range varlists() {
126 return varlist_range(varlist_begin(), varlist_end());
128 varlist_const_range varlists() const {
129 return varlist_const_range(varlist_begin(), varlist_end());
132 varlist_iterator varlist_begin() { return getVarRefs().begin(); }
133 varlist_iterator varlist_end() { return getVarRefs().end(); }
134 varlist_const_iterator varlist_begin() const { return getVarRefs().begin(); }
135 varlist_const_iterator varlist_end() const { return getVarRefs().end(); }
137 /// \brief Sets the location of '('.
138 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
139 /// \brief Returns the location of '('.
140 SourceLocation getLParenLoc() const { return LParenLoc; }
142 /// \brief Fetches list of all variables in the clause.
143 ArrayRef<const Expr *> getVarRefs() const {
144 return llvm::makeArrayRef(
145 reinterpret_cast<const Expr *const *>(
146 reinterpret_cast<const char *>(this) +
147 llvm::RoundUpToAlignment(sizeof(T), llvm::alignOf<const Expr *>())),
152 /// \brief This represents 'if' clause in the '#pragma omp ...' directive.
155 /// #pragma omp parallel if(parallel:a > 5)
157 /// In this example directive '#pragma omp parallel' has simple 'if' clause with
158 /// condition 'a > 5' and directive name modifier 'parallel'.
160 class OMPIfClause : public OMPClause {
161 friend class OMPClauseReader;
162 /// \brief Location of '('.
163 SourceLocation LParenLoc;
164 /// \brief Condition of the 'if' clause.
166 /// \brief Location of ':' (if any).
167 SourceLocation ColonLoc;
168 /// \brief Directive name modifier for the clause.
169 OpenMPDirectiveKind NameModifier;
170 /// \brief Name modifier location.
171 SourceLocation NameModifierLoc;
173 /// \brief Set condition.
175 void setCondition(Expr *Cond) { Condition = Cond; }
176 /// \brief Set directive name modifier for the clause.
178 void setNameModifier(OpenMPDirectiveKind NM) { NameModifier = NM; }
179 /// \brief Set location of directive name modifier for the clause.
181 void setNameModifierLoc(SourceLocation Loc) { NameModifierLoc = Loc; }
182 /// \brief Set location of ':'.
184 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
187 /// \brief Build 'if' clause with condition \a Cond.
189 /// \param NameModifier [OpenMP 4.1] Directive name modifier of clause.
190 /// \param Cond Condition of the clause.
191 /// \param StartLoc Starting location of the clause.
192 /// \param LParenLoc Location of '('.
193 /// \param NameModifierLoc Location of directive name modifier.
194 /// \param ColonLoc [OpenMP 4.1] Location of ':'.
195 /// \param EndLoc Ending location of the clause.
197 OMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Cond,
198 SourceLocation StartLoc, SourceLocation LParenLoc,
199 SourceLocation NameModifierLoc, SourceLocation ColonLoc,
200 SourceLocation EndLoc)
201 : OMPClause(OMPC_if, StartLoc, EndLoc), LParenLoc(LParenLoc),
202 Condition(Cond), ColonLoc(ColonLoc), NameModifier(NameModifier),
203 NameModifierLoc(NameModifierLoc) {}
205 /// \brief Build an empty clause.
208 : OMPClause(OMPC_if, SourceLocation(), SourceLocation()), LParenLoc(),
209 Condition(nullptr), ColonLoc(), NameModifier(OMPD_unknown),
212 /// \brief Sets the location of '('.
213 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
214 /// \brief Returns the location of '('.
215 SourceLocation getLParenLoc() const { return LParenLoc; }
217 /// \brief Return the location of ':'.
218 SourceLocation getColonLoc() const { return ColonLoc; }
220 /// \brief Returns condition.
221 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
222 /// \brief Return directive name modifier associated with the clause.
223 OpenMPDirectiveKind getNameModifier() const { return NameModifier; }
225 /// \brief Return the location of directive name modifier.
226 SourceLocation getNameModifierLoc() const { return NameModifierLoc; }
228 static bool classof(const OMPClause *T) {
229 return T->getClauseKind() == OMPC_if;
232 child_range children() { return child_range(&Condition, &Condition + 1); }
235 /// \brief This represents 'final' clause in the '#pragma omp ...' directive.
238 /// #pragma omp task final(a > 5)
240 /// In this example directive '#pragma omp task' has simple 'final'
241 /// clause with condition 'a > 5'.
243 class OMPFinalClause : public OMPClause {
244 friend class OMPClauseReader;
245 /// \brief Location of '('.
246 SourceLocation LParenLoc;
247 /// \brief Condition of the 'if' clause.
250 /// \brief Set condition.
252 void setCondition(Expr *Cond) { Condition = Cond; }
255 /// \brief Build 'final' clause with condition \a Cond.
257 /// \param StartLoc Starting location of the clause.
258 /// \param LParenLoc Location of '('.
259 /// \param Cond Condition of the clause.
260 /// \param EndLoc Ending location of the clause.
262 OMPFinalClause(Expr *Cond, SourceLocation StartLoc, SourceLocation LParenLoc,
263 SourceLocation EndLoc)
264 : OMPClause(OMPC_final, StartLoc, EndLoc), LParenLoc(LParenLoc),
267 /// \brief Build an empty clause.
270 : OMPClause(OMPC_final, SourceLocation(), SourceLocation()),
271 LParenLoc(SourceLocation()), Condition(nullptr) {}
273 /// \brief Sets the location of '('.
274 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
275 /// \brief Returns the location of '('.
276 SourceLocation getLParenLoc() const { return LParenLoc; }
278 /// \brief Returns condition.
279 Expr *getCondition() const { return cast_or_null<Expr>(Condition); }
281 static bool classof(const OMPClause *T) {
282 return T->getClauseKind() == OMPC_final;
285 child_range children() { return child_range(&Condition, &Condition + 1); }
288 /// \brief This represents 'num_threads' clause in the '#pragma omp ...'
292 /// #pragma omp parallel num_threads(6)
294 /// In this example directive '#pragma omp parallel' has simple 'num_threads'
295 /// clause with number of threads '6'.
297 class OMPNumThreadsClause : public OMPClause {
298 friend class OMPClauseReader;
299 /// \brief Location of '('.
300 SourceLocation LParenLoc;
301 /// \brief Condition of the 'num_threads' clause.
304 /// \brief Set condition.
306 void setNumThreads(Expr *NThreads) { NumThreads = NThreads; }
309 /// \brief Build 'num_threads' clause with condition \a NumThreads.
311 /// \param NumThreads Number of threads for the construct.
312 /// \param StartLoc Starting location of the clause.
313 /// \param LParenLoc Location of '('.
314 /// \param EndLoc Ending location of the clause.
316 OMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc,
317 SourceLocation LParenLoc, SourceLocation EndLoc)
318 : OMPClause(OMPC_num_threads, StartLoc, EndLoc), LParenLoc(LParenLoc),
319 NumThreads(NumThreads) {}
321 /// \brief Build an empty clause.
323 OMPNumThreadsClause()
324 : OMPClause(OMPC_num_threads, SourceLocation(), SourceLocation()),
325 LParenLoc(SourceLocation()), NumThreads(nullptr) {}
327 /// \brief Sets the location of '('.
328 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
329 /// \brief Returns the location of '('.
330 SourceLocation getLParenLoc() const { return LParenLoc; }
332 /// \brief Returns number of threads.
333 Expr *getNumThreads() const { return cast_or_null<Expr>(NumThreads); }
335 static bool classof(const OMPClause *T) {
336 return T->getClauseKind() == OMPC_num_threads;
339 child_range children() { return child_range(&NumThreads, &NumThreads + 1); }
342 /// \brief This represents 'safelen' clause in the '#pragma omp ...'
346 /// #pragma omp simd safelen(4)
348 /// In this example directive '#pragma omp simd' has clause 'safelen'
349 /// with single expression '4'.
350 /// If the safelen clause is used then no two iterations executed
351 /// concurrently with SIMD instructions can have a greater distance
352 /// in the logical iteration space than its value. The parameter of
353 /// the safelen clause must be a constant positive integer expression.
355 class OMPSafelenClause : public OMPClause {
356 friend class OMPClauseReader;
357 /// \brief Location of '('.
358 SourceLocation LParenLoc;
359 /// \brief Safe iteration space distance.
362 /// \brief Set safelen.
363 void setSafelen(Expr *Len) { Safelen = Len; }
366 /// \brief Build 'safelen' clause.
368 /// \param Len Expression associated with this clause.
369 /// \param StartLoc Starting location of the clause.
370 /// \param EndLoc Ending location of the clause.
372 OMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
373 SourceLocation EndLoc)
374 : OMPClause(OMPC_safelen, StartLoc, EndLoc), LParenLoc(LParenLoc),
377 /// \brief Build an empty clause.
379 explicit OMPSafelenClause()
380 : OMPClause(OMPC_safelen, SourceLocation(), SourceLocation()),
381 LParenLoc(SourceLocation()), Safelen(nullptr) {}
383 /// \brief Sets the location of '('.
384 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
385 /// \brief Returns the location of '('.
386 SourceLocation getLParenLoc() const { return LParenLoc; }
388 /// \brief Return safe iteration space distance.
389 Expr *getSafelen() const { return cast_or_null<Expr>(Safelen); }
391 static bool classof(const OMPClause *T) {
392 return T->getClauseKind() == OMPC_safelen;
395 child_range children() { return child_range(&Safelen, &Safelen + 1); }
398 /// \brief This represents 'simdlen' clause in the '#pragma omp ...'
402 /// #pragma omp simd simdlen(4)
404 /// In this example directive '#pragma omp simd' has clause 'simdlen'
405 /// with single expression '4'.
406 /// If the 'simdlen' clause is used then it specifies the preferred number of
407 /// iterations to be executed concurrently. The parameter of the 'simdlen'
408 /// clause must be a constant positive integer expression.
410 class OMPSimdlenClause : public OMPClause {
411 friend class OMPClauseReader;
412 /// \brief Location of '('.
413 SourceLocation LParenLoc;
414 /// \brief Safe iteration space distance.
417 /// \brief Set simdlen.
418 void setSimdlen(Expr *Len) { Simdlen = Len; }
421 /// \brief Build 'simdlen' clause.
423 /// \param Len Expression associated with this clause.
424 /// \param StartLoc Starting location of the clause.
425 /// \param EndLoc Ending location of the clause.
427 OMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc,
428 SourceLocation EndLoc)
429 : OMPClause(OMPC_simdlen, StartLoc, EndLoc), LParenLoc(LParenLoc),
432 /// \brief Build an empty clause.
434 explicit OMPSimdlenClause()
435 : OMPClause(OMPC_simdlen, SourceLocation(), SourceLocation()),
436 LParenLoc(SourceLocation()), Simdlen(nullptr) {}
438 /// \brief Sets the location of '('.
439 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
440 /// \brief Returns the location of '('.
441 SourceLocation getLParenLoc() const { return LParenLoc; }
443 /// \brief Return safe iteration space distance.
444 Expr *getSimdlen() const { return cast_or_null<Expr>(Simdlen); }
446 static bool classof(const OMPClause *T) {
447 return T->getClauseKind() == OMPC_simdlen;
450 child_range children() { return child_range(&Simdlen, &Simdlen + 1); }
453 /// \brief This represents 'collapse' clause in the '#pragma omp ...'
457 /// #pragma omp simd collapse(3)
459 /// In this example directive '#pragma omp simd' has clause 'collapse'
460 /// with single expression '3'.
461 /// The parameter must be a constant positive integer expression, it specifies
462 /// the number of nested loops that should be collapsed into a single iteration
465 class OMPCollapseClause : public OMPClause {
466 friend class OMPClauseReader;
467 /// \brief Location of '('.
468 SourceLocation LParenLoc;
469 /// \brief Number of for-loops.
472 /// \brief Set the number of associated for-loops.
473 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
476 /// \brief Build 'collapse' clause.
478 /// \param Num Expression associated with this clause.
479 /// \param StartLoc Starting location of the clause.
480 /// \param LParenLoc Location of '('.
481 /// \param EndLoc Ending location of the clause.
483 OMPCollapseClause(Expr *Num, SourceLocation StartLoc,
484 SourceLocation LParenLoc, SourceLocation EndLoc)
485 : OMPClause(OMPC_collapse, StartLoc, EndLoc), LParenLoc(LParenLoc),
488 /// \brief Build an empty clause.
490 explicit OMPCollapseClause()
491 : OMPClause(OMPC_collapse, SourceLocation(), SourceLocation()),
492 LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
494 /// \brief Sets the location of '('.
495 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
496 /// \brief Returns the location of '('.
497 SourceLocation getLParenLoc() const { return LParenLoc; }
499 /// \brief Return the number of associated for-loops.
500 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
502 static bool classof(const OMPClause *T) {
503 return T->getClauseKind() == OMPC_collapse;
506 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
509 /// \brief This represents 'default' clause in the '#pragma omp ...' directive.
512 /// #pragma omp parallel default(shared)
514 /// In this example directive '#pragma omp parallel' has simple 'default'
515 /// clause with kind 'shared'.
517 class OMPDefaultClause : public OMPClause {
518 friend class OMPClauseReader;
519 /// \brief Location of '('.
520 SourceLocation LParenLoc;
521 /// \brief A kind of the 'default' clause.
522 OpenMPDefaultClauseKind Kind;
523 /// \brief Start location of the kind in source code.
524 SourceLocation KindKwLoc;
526 /// \brief Set kind of the clauses.
528 /// \param K Argument of clause.
530 void setDefaultKind(OpenMPDefaultClauseKind K) { Kind = K; }
532 /// \brief Set argument location.
534 /// \param KLoc Argument location.
536 void setDefaultKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
539 /// \brief Build 'default' clause with argument \a A ('none' or 'shared').
541 /// \param A Argument of the clause ('none' or 'shared').
542 /// \param ALoc Starting location of the argument.
543 /// \param StartLoc Starting location of the clause.
544 /// \param LParenLoc Location of '('.
545 /// \param EndLoc Ending location of the clause.
547 OMPDefaultClause(OpenMPDefaultClauseKind A, SourceLocation ALoc,
548 SourceLocation StartLoc, SourceLocation LParenLoc,
549 SourceLocation EndLoc)
550 : OMPClause(OMPC_default, StartLoc, EndLoc), LParenLoc(LParenLoc),
551 Kind(A), KindKwLoc(ALoc) {}
553 /// \brief Build an empty clause.
556 : OMPClause(OMPC_default, SourceLocation(), SourceLocation()),
557 LParenLoc(SourceLocation()), Kind(OMPC_DEFAULT_unknown),
558 KindKwLoc(SourceLocation()) {}
560 /// \brief Sets the location of '('.
561 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
562 /// \brief Returns the location of '('.
563 SourceLocation getLParenLoc() const { return LParenLoc; }
565 /// \brief Returns kind of the clause.
566 OpenMPDefaultClauseKind getDefaultKind() const { return Kind; }
568 /// \brief Returns location of clause kind.
569 SourceLocation getDefaultKindKwLoc() const { return KindKwLoc; }
571 static bool classof(const OMPClause *T) {
572 return T->getClauseKind() == OMPC_default;
575 child_range children() {
576 return child_range(child_iterator(), child_iterator());
580 /// \brief This represents 'proc_bind' clause in the '#pragma omp ...'
584 /// #pragma omp parallel proc_bind(master)
586 /// In this example directive '#pragma omp parallel' has simple 'proc_bind'
587 /// clause with kind 'master'.
589 class OMPProcBindClause : public OMPClause {
590 friend class OMPClauseReader;
591 /// \brief Location of '('.
592 SourceLocation LParenLoc;
593 /// \brief A kind of the 'proc_bind' clause.
594 OpenMPProcBindClauseKind Kind;
595 /// \brief Start location of the kind in source code.
596 SourceLocation KindKwLoc;
598 /// \brief Set kind of the clause.
600 /// \param K Kind of clause.
602 void setProcBindKind(OpenMPProcBindClauseKind K) { Kind = K; }
604 /// \brief Set clause kind location.
606 /// \param KLoc Kind location.
608 void setProcBindKindKwLoc(SourceLocation KLoc) { KindKwLoc = KLoc; }
611 /// \brief Build 'proc_bind' clause with argument \a A ('master', 'close' or
614 /// \param A Argument of the clause ('master', 'close' or 'spread').
615 /// \param ALoc Starting location of the argument.
616 /// \param StartLoc Starting location of the clause.
617 /// \param LParenLoc Location of '('.
618 /// \param EndLoc Ending location of the clause.
620 OMPProcBindClause(OpenMPProcBindClauseKind A, SourceLocation ALoc,
621 SourceLocation StartLoc, SourceLocation LParenLoc,
622 SourceLocation EndLoc)
623 : OMPClause(OMPC_proc_bind, StartLoc, EndLoc), LParenLoc(LParenLoc),
624 Kind(A), KindKwLoc(ALoc) {}
626 /// \brief Build an empty clause.
629 : OMPClause(OMPC_proc_bind, SourceLocation(), SourceLocation()),
630 LParenLoc(SourceLocation()), Kind(OMPC_PROC_BIND_unknown),
631 KindKwLoc(SourceLocation()) {}
633 /// \brief Sets the location of '('.
634 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
635 /// \brief Returns the location of '('.
636 SourceLocation getLParenLoc() const { return LParenLoc; }
638 /// \brief Returns kind of the clause.
639 OpenMPProcBindClauseKind getProcBindKind() const { return Kind; }
641 /// \brief Returns location of clause kind.
642 SourceLocation getProcBindKindKwLoc() const { return KindKwLoc; }
644 static bool classof(const OMPClause *T) {
645 return T->getClauseKind() == OMPC_proc_bind;
648 child_range children() {
649 return child_range(child_iterator(), child_iterator());
653 /// \brief This represents 'schedule' clause in the '#pragma omp ...' directive.
656 /// #pragma omp for schedule(static, 3)
658 /// In this example directive '#pragma omp for' has 'schedule' clause with
659 /// arguments 'static' and '3'.
661 class OMPScheduleClause : public OMPClause {
662 friend class OMPClauseReader;
663 /// \brief Location of '('.
664 SourceLocation LParenLoc;
665 /// \brief A kind of the 'schedule' clause.
666 OpenMPScheduleClauseKind Kind;
667 /// \brief Modifiers for 'schedule' clause.
668 enum {FIRST, SECOND, NUM_MODIFIERS};
669 OpenMPScheduleClauseModifier Modifiers[NUM_MODIFIERS];
670 /// \brief Locations of modifiers.
671 SourceLocation ModifiersLoc[NUM_MODIFIERS];
672 /// \brief Start location of the schedule ind in source code.
673 SourceLocation KindLoc;
674 /// \brief Location of ',' (if any).
675 SourceLocation CommaLoc;
676 /// \brief Chunk size and a reference to pseudo variable for combined
678 enum { CHUNK_SIZE, HELPER_CHUNK_SIZE, NUM_EXPRS };
679 Stmt *ChunkSizes[NUM_EXPRS];
681 /// \brief Set schedule kind.
683 /// \param K Schedule kind.
685 void setScheduleKind(OpenMPScheduleClauseKind K) { Kind = K; }
686 /// \brief Set the first schedule modifier.
688 /// \param M Schedule modifier.
690 void setFirstScheduleModifier(OpenMPScheduleClauseModifier M) {
691 Modifiers[FIRST] = M;
693 /// \brief Set the second schedule modifier.
695 /// \param M Schedule modifier.
697 void setSecondScheduleModifier(OpenMPScheduleClauseModifier M) {
698 Modifiers[SECOND] = M;
700 /// \brief Set location of the first schedule modifier.
702 void setFirstScheduleModifierLoc(SourceLocation Loc) {
703 ModifiersLoc[FIRST] = Loc;
705 /// \brief Set location of the second schedule modifier.
707 void setSecondScheduleModifierLoc(SourceLocation Loc) {
708 ModifiersLoc[SECOND] = Loc;
710 /// \brief Set schedule modifier location.
712 /// \param M Schedule modifier location.
714 void setScheduleModifer(OpenMPScheduleClauseModifier M) {
715 if (Modifiers[FIRST] == OMPC_SCHEDULE_MODIFIER_unknown)
716 Modifiers[FIRST] = M;
718 assert(Modifiers[SECOND] == OMPC_SCHEDULE_MODIFIER_unknown);
719 Modifiers[SECOND] = M;
722 /// \brief Sets the location of '('.
724 /// \param Loc Location of '('.
726 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
727 /// \brief Set schedule kind start location.
729 /// \param KLoc Schedule kind location.
731 void setScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
732 /// \brief Set location of ','.
734 /// \param Loc Location of ','.
736 void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; }
737 /// \brief Set chunk size.
739 /// \param E Chunk size.
741 void setChunkSize(Expr *E) { ChunkSizes[CHUNK_SIZE] = E; }
742 /// \brief Set helper chunk size.
744 /// \param E Helper chunk size.
746 void setHelperChunkSize(Expr *E) { ChunkSizes[HELPER_CHUNK_SIZE] = E; }
749 /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size
750 /// expression \a ChunkSize.
752 /// \param StartLoc Starting location of the clause.
753 /// \param LParenLoc Location of '('.
754 /// \param KLoc Starting location of the argument.
755 /// \param CommaLoc Location of ','.
756 /// \param EndLoc Ending location of the clause.
757 /// \param Kind Schedule kind.
758 /// \param ChunkSize Chunk size.
759 /// \param HelperChunkSize Helper chunk size for combined directives.
760 /// \param M1 The first modifier applied to 'schedule' clause.
761 /// \param M1Loc Location of the first modifier
762 /// \param M2 The second modifier applied to 'schedule' clause.
763 /// \param M2Loc Location of the second modifier
765 OMPScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc,
766 SourceLocation KLoc, SourceLocation CommaLoc,
767 SourceLocation EndLoc, OpenMPScheduleClauseKind Kind,
768 Expr *ChunkSize, Expr *HelperChunkSize,
769 OpenMPScheduleClauseModifier M1, SourceLocation M1Loc,
770 OpenMPScheduleClauseModifier M2, SourceLocation M2Loc)
771 : OMPClause(OMPC_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc),
772 Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc) {
773 ChunkSizes[CHUNK_SIZE] = ChunkSize;
774 ChunkSizes[HELPER_CHUNK_SIZE] = HelperChunkSize;
775 Modifiers[FIRST] = M1;
776 Modifiers[SECOND] = M2;
777 ModifiersLoc[FIRST] = M1Loc;
778 ModifiersLoc[SECOND] = M2Loc;
781 /// \brief Build an empty clause.
783 explicit OMPScheduleClause()
784 : OMPClause(OMPC_schedule, SourceLocation(), SourceLocation()),
785 Kind(OMPC_SCHEDULE_unknown) {
786 ChunkSizes[CHUNK_SIZE] = nullptr;
787 ChunkSizes[HELPER_CHUNK_SIZE] = nullptr;
788 Modifiers[FIRST] = OMPC_SCHEDULE_MODIFIER_unknown;
789 Modifiers[SECOND] = OMPC_SCHEDULE_MODIFIER_unknown;
792 /// \brief Get kind of the clause.
794 OpenMPScheduleClauseKind getScheduleKind() const { return Kind; }
795 /// \brief Get the first modifier of the clause.
797 OpenMPScheduleClauseModifier getFirstScheduleModifier() const {
798 return Modifiers[FIRST];
800 /// \brief Get the second modifier of the clause.
802 OpenMPScheduleClauseModifier getSecondScheduleModifier() const {
803 return Modifiers[SECOND];
805 /// \brief Get location of '('.
807 SourceLocation getLParenLoc() { return LParenLoc; }
808 /// \brief Get kind location.
810 SourceLocation getScheduleKindLoc() { return KindLoc; }
811 /// \brief Get the first modifier location.
813 SourceLocation getFirstScheduleModifierLoc() const {
814 return ModifiersLoc[FIRST];
816 /// \brief Get the second modifier location.
818 SourceLocation getSecondScheduleModifierLoc() const {
819 return ModifiersLoc[SECOND];
821 /// \brief Get location of ','.
823 SourceLocation getCommaLoc() { return CommaLoc; }
824 /// \brief Get chunk size.
826 Expr *getChunkSize() { return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]); }
827 /// \brief Get chunk size.
829 Expr *getChunkSize() const {
830 return dyn_cast_or_null<Expr>(ChunkSizes[CHUNK_SIZE]);
832 /// \brief Get helper chunk size.
834 Expr *getHelperChunkSize() {
835 return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
837 /// \brief Get helper chunk size.
839 Expr *getHelperChunkSize() const {
840 return dyn_cast_or_null<Expr>(ChunkSizes[HELPER_CHUNK_SIZE]);
843 static bool classof(const OMPClause *T) {
844 return T->getClauseKind() == OMPC_schedule;
847 child_range children() {
848 return child_range(&ChunkSizes[CHUNK_SIZE], &ChunkSizes[CHUNK_SIZE] + 1);
852 /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
855 /// #pragma omp for ordered (2)
857 /// In this example directive '#pragma omp for' has 'ordered' clause with
860 class OMPOrderedClause : public OMPClause {
861 friend class OMPClauseReader;
862 /// \brief Location of '('.
863 SourceLocation LParenLoc;
864 /// \brief Number of for-loops.
867 /// \brief Set the number of associated for-loops.
868 void setNumForLoops(Expr *Num) { NumForLoops = Num; }
871 /// \brief Build 'ordered' clause.
873 /// \param Num Expression, possibly associated with this clause.
874 /// \param StartLoc Starting location of the clause.
875 /// \param LParenLoc Location of '('.
876 /// \param EndLoc Ending location of the clause.
878 OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
879 SourceLocation LParenLoc, SourceLocation EndLoc)
880 : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
883 /// \brief Build an empty clause.
885 explicit OMPOrderedClause()
886 : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
887 LParenLoc(SourceLocation()), NumForLoops(nullptr) {}
889 /// \brief Sets the location of '('.
890 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
891 /// \brief Returns the location of '('.
892 SourceLocation getLParenLoc() const { return LParenLoc; }
894 /// \brief Return the number of associated for-loops.
895 Expr *getNumForLoops() const { return cast_or_null<Expr>(NumForLoops); }
897 static bool classof(const OMPClause *T) {
898 return T->getClauseKind() == OMPC_ordered;
901 child_range children() { return child_range(&NumForLoops, &NumForLoops + 1); }
904 /// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
907 /// #pragma omp for nowait
909 /// In this example directive '#pragma omp for' has 'nowait' clause.
911 class OMPNowaitClause : public OMPClause {
913 /// \brief Build 'nowait' clause.
915 /// \param StartLoc Starting location of the clause.
916 /// \param EndLoc Ending location of the clause.
918 OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
919 : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
921 /// \brief Build an empty clause.
924 : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
926 static bool classof(const OMPClause *T) {
927 return T->getClauseKind() == OMPC_nowait;
930 child_range children() {
931 return child_range(child_iterator(), child_iterator());
935 /// \brief This represents 'untied' clause in the '#pragma omp ...' directive.
938 /// #pragma omp task untied
940 /// In this example directive '#pragma omp task' has 'untied' clause.
942 class OMPUntiedClause : public OMPClause {
944 /// \brief Build 'untied' clause.
946 /// \param StartLoc Starting location of the clause.
947 /// \param EndLoc Ending location of the clause.
949 OMPUntiedClause(SourceLocation StartLoc, SourceLocation EndLoc)
950 : OMPClause(OMPC_untied, StartLoc, EndLoc) {}
952 /// \brief Build an empty clause.
955 : OMPClause(OMPC_untied, SourceLocation(), SourceLocation()) {}
957 static bool classof(const OMPClause *T) {
958 return T->getClauseKind() == OMPC_untied;
961 child_range children() {
962 return child_range(child_iterator(), child_iterator());
966 /// \brief This represents 'mergeable' clause in the '#pragma omp ...'
970 /// #pragma omp task mergeable
972 /// In this example directive '#pragma omp task' has 'mergeable' clause.
974 class OMPMergeableClause : public OMPClause {
976 /// \brief Build 'mergeable' clause.
978 /// \param StartLoc Starting location of the clause.
979 /// \param EndLoc Ending location of the clause.
981 OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
982 : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
984 /// \brief Build an empty clause.
987 : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
989 static bool classof(const OMPClause *T) {
990 return T->getClauseKind() == OMPC_mergeable;
993 child_range children() {
994 return child_range(child_iterator(), child_iterator());
998 /// \brief This represents 'read' clause in the '#pragma omp atomic' directive.
1001 /// #pragma omp atomic read
1003 /// In this example directive '#pragma omp atomic' has 'read' clause.
1005 class OMPReadClause : public OMPClause {
1007 /// \brief Build 'read' clause.
1009 /// \param StartLoc Starting location of the clause.
1010 /// \param EndLoc Ending location of the clause.
1012 OMPReadClause(SourceLocation StartLoc, SourceLocation EndLoc)
1013 : OMPClause(OMPC_read, StartLoc, EndLoc) {}
1015 /// \brief Build an empty clause.
1017 OMPReadClause() : OMPClause(OMPC_read, SourceLocation(), SourceLocation()) {}
1019 static bool classof(const OMPClause *T) {
1020 return T->getClauseKind() == OMPC_read;
1023 child_range children() {
1024 return child_range(child_iterator(), child_iterator());
1028 /// \brief This represents 'write' clause in the '#pragma omp atomic' directive.
1031 /// #pragma omp atomic write
1033 /// In this example directive '#pragma omp atomic' has 'write' clause.
1035 class OMPWriteClause : public OMPClause {
1037 /// \brief Build 'write' clause.
1039 /// \param StartLoc Starting location of the clause.
1040 /// \param EndLoc Ending location of the clause.
1042 OMPWriteClause(SourceLocation StartLoc, SourceLocation EndLoc)
1043 : OMPClause(OMPC_write, StartLoc, EndLoc) {}
1045 /// \brief Build an empty clause.
1048 : OMPClause(OMPC_write, SourceLocation(), SourceLocation()) {}
1050 static bool classof(const OMPClause *T) {
1051 return T->getClauseKind() == OMPC_write;
1054 child_range children() {
1055 return child_range(child_iterator(), child_iterator());
1059 /// \brief This represents 'update' clause in the '#pragma omp atomic'
1063 /// #pragma omp atomic update
1065 /// In this example directive '#pragma omp atomic' has 'update' clause.
1067 class OMPUpdateClause : public OMPClause {
1069 /// \brief Build 'update' clause.
1071 /// \param StartLoc Starting location of the clause.
1072 /// \param EndLoc Ending location of the clause.
1074 OMPUpdateClause(SourceLocation StartLoc, SourceLocation EndLoc)
1075 : OMPClause(OMPC_update, StartLoc, EndLoc) {}
1077 /// \brief Build an empty clause.
1080 : OMPClause(OMPC_update, SourceLocation(), SourceLocation()) {}
1082 static bool classof(const OMPClause *T) {
1083 return T->getClauseKind() == OMPC_update;
1086 child_range children() {
1087 return child_range(child_iterator(), child_iterator());
1091 /// \brief This represents 'capture' clause in the '#pragma omp atomic'
1095 /// #pragma omp atomic capture
1097 /// In this example directive '#pragma omp atomic' has 'capture' clause.
1099 class OMPCaptureClause : public OMPClause {
1101 /// \brief Build 'capture' clause.
1103 /// \param StartLoc Starting location of the clause.
1104 /// \param EndLoc Ending location of the clause.
1106 OMPCaptureClause(SourceLocation StartLoc, SourceLocation EndLoc)
1107 : OMPClause(OMPC_capture, StartLoc, EndLoc) {}
1109 /// \brief Build an empty clause.
1112 : OMPClause(OMPC_capture, SourceLocation(), SourceLocation()) {}
1114 static bool classof(const OMPClause *T) {
1115 return T->getClauseKind() == OMPC_capture;
1118 child_range children() {
1119 return child_range(child_iterator(), child_iterator());
1123 /// \brief This represents 'seq_cst' clause in the '#pragma omp atomic'
1127 /// #pragma omp atomic seq_cst
1129 /// In this example directive '#pragma omp atomic' has 'seq_cst' clause.
1131 class OMPSeqCstClause : public OMPClause {
1133 /// \brief Build 'seq_cst' clause.
1135 /// \param StartLoc Starting location of the clause.
1136 /// \param EndLoc Ending location of the clause.
1138 OMPSeqCstClause(SourceLocation StartLoc, SourceLocation EndLoc)
1139 : OMPClause(OMPC_seq_cst, StartLoc, EndLoc) {}
1141 /// \brief Build an empty clause.
1144 : OMPClause(OMPC_seq_cst, SourceLocation(), SourceLocation()) {}
1146 static bool classof(const OMPClause *T) {
1147 return T->getClauseKind() == OMPC_seq_cst;
1150 child_range children() {
1151 return child_range(child_iterator(), child_iterator());
1155 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
1158 /// #pragma omp parallel private(a,b)
1160 /// In this example directive '#pragma omp parallel' has clause 'private'
1161 /// with the variables 'a' and 'b'.
1163 class OMPPrivateClause : public OMPVarListClause<OMPPrivateClause> {
1164 friend class OMPClauseReader;
1165 /// \brief Build clause with number of variables \a N.
1167 /// \param StartLoc Starting location of the clause.
1168 /// \param LParenLoc Location of '('.
1169 /// \param EndLoc Ending location of the clause.
1170 /// \param N Number of the variables in the clause.
1172 OMPPrivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1173 SourceLocation EndLoc, unsigned N)
1174 : OMPVarListClause<OMPPrivateClause>(OMPC_private, StartLoc, LParenLoc,
1177 /// \brief Build an empty clause.
1179 /// \param N Number of variables.
1181 explicit OMPPrivateClause(unsigned N)
1182 : OMPVarListClause<OMPPrivateClause>(OMPC_private, SourceLocation(),
1183 SourceLocation(), SourceLocation(),
1186 /// \brief Sets the list of references to private copies with initializers for
1187 /// new private variables.
1188 /// \param VL List of references.
1189 void setPrivateCopies(ArrayRef<Expr *> VL);
1191 /// \brief Gets the list of references to private copies with initializers for
1192 /// new private variables.
1193 MutableArrayRef<Expr *> getPrivateCopies() {
1194 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1196 ArrayRef<const Expr *> getPrivateCopies() const {
1197 return llvm::makeArrayRef(varlist_end(), varlist_size());
1201 /// \brief Creates clause with a list of variables \a VL.
1203 /// \param C AST context.
1204 /// \param StartLoc Starting location of the clause.
1205 /// \param LParenLoc Location of '('.
1206 /// \param EndLoc Ending location of the clause.
1207 /// \param VL List of references to the variables.
1208 /// \param PrivateVL List of references to private copies with initializers.
1210 static OMPPrivateClause *Create(const ASTContext &C, SourceLocation StartLoc,
1211 SourceLocation LParenLoc,
1212 SourceLocation EndLoc, ArrayRef<Expr *> VL,
1213 ArrayRef<Expr *> PrivateVL);
1214 /// \brief Creates an empty clause with the place for \a N variables.
1216 /// \param C AST context.
1217 /// \param N The number of variables.
1219 static OMPPrivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1221 typedef MutableArrayRef<Expr *>::iterator private_copies_iterator;
1222 typedef ArrayRef<const Expr *>::iterator private_copies_const_iterator;
1223 typedef llvm::iterator_range<private_copies_iterator> private_copies_range;
1224 typedef llvm::iterator_range<private_copies_const_iterator>
1225 private_copies_const_range;
1227 private_copies_range private_copies() {
1228 return private_copies_range(getPrivateCopies().begin(),
1229 getPrivateCopies().end());
1231 private_copies_const_range private_copies() const {
1232 return private_copies_const_range(getPrivateCopies().begin(),
1233 getPrivateCopies().end());
1236 child_range children() {
1237 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1238 reinterpret_cast<Stmt **>(varlist_end()));
1241 static bool classof(const OMPClause *T) {
1242 return T->getClauseKind() == OMPC_private;
1246 /// \brief This represents clause 'firstprivate' in the '#pragma omp ...'
1250 /// #pragma omp parallel firstprivate(a,b)
1252 /// In this example directive '#pragma omp parallel' has clause 'firstprivate'
1253 /// with the variables 'a' and 'b'.
1255 class OMPFirstprivateClause : public OMPVarListClause<OMPFirstprivateClause> {
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 : public OMPVarListClause<OMPLastprivateClause> {
1376 // There are 4 additional tail-allocated arrays at the end of the class:
1377 // 1. Contains list of pseudo variables with the default initialization for
1378 // each non-firstprivate variables. Used in codegen for initialization of
1379 // lastprivate copies.
1380 // 2. List of helper expressions for proper generation of assignment operation
1381 // required for lastprivate clause. This list represents private variables
1382 // (for arrays, single array element).
1383 // 3. List of helper expressions for proper generation of assignment operation
1384 // required for lastprivate clause. This list represents original variables
1385 // (for arrays, single array element).
1386 // 4. List of helper expressions that represents assignment operation:
1388 // DstExprs = SrcExprs;
1390 // Required for proper codegen of final assignment performed by the
1391 // lastprivate clause.
1393 friend class OMPClauseReader;
1395 /// \brief Build clause with number of variables \a N.
1397 /// \param StartLoc Starting location of the clause.
1398 /// \param LParenLoc Location of '('.
1399 /// \param EndLoc Ending location of the clause.
1400 /// \param N Number of the variables in the clause.
1402 OMPLastprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1403 SourceLocation EndLoc, unsigned N)
1404 : OMPVarListClause<OMPLastprivateClause>(OMPC_lastprivate, StartLoc,
1405 LParenLoc, EndLoc, N) {}
1407 /// \brief Build an empty clause.
1409 /// \param N Number of variables.
1411 explicit OMPLastprivateClause(unsigned N)
1412 : OMPVarListClause<OMPLastprivateClause>(
1413 OMPC_lastprivate, SourceLocation(), SourceLocation(),
1414 SourceLocation(), N) {}
1416 /// \brief Get the list of helper expressions for initialization of private
1417 /// copies for lastprivate variables.
1418 MutableArrayRef<Expr *> getPrivateCopies() {
1419 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1421 ArrayRef<const Expr *> getPrivateCopies() const {
1422 return llvm::makeArrayRef(varlist_end(), varlist_size());
1425 /// \brief Set list of helper expressions, required for proper codegen of the
1426 /// clause. These expressions represent private variables (for arrays, single
1427 /// array element) in the final assignment statement performed by the
1428 /// lastprivate clause.
1429 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
1431 /// \brief Get the list of helper source expressions.
1432 MutableArrayRef<Expr *> getSourceExprs() {
1433 return MutableArrayRef<Expr *>(getPrivateCopies().end(), varlist_size());
1435 ArrayRef<const Expr *> getSourceExprs() const {
1436 return llvm::makeArrayRef(getPrivateCopies().end(), varlist_size());
1439 /// \brief Set list of helper expressions, required for proper codegen of the
1440 /// clause. These expressions represent original variables (for arrays, single
1441 /// array element) in the final assignment statement performed by the
1442 /// lastprivate clause.
1443 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
1445 /// \brief Get the list of helper destination expressions.
1446 MutableArrayRef<Expr *> getDestinationExprs() {
1447 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
1449 ArrayRef<const Expr *> getDestinationExprs() const {
1450 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
1453 /// \brief Set list of helper assignment expressions, required for proper
1454 /// codegen of the clause. These expressions are assignment expressions that
1455 /// assign private copy of the variable to original variable.
1456 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
1458 /// \brief Get the list of helper assignment expressions.
1459 MutableArrayRef<Expr *> getAssignmentOps() {
1460 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
1462 ArrayRef<const Expr *> getAssignmentOps() const {
1463 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
1467 /// \brief Creates clause with a list of variables \a VL.
1469 /// \param C AST context.
1470 /// \param StartLoc Starting location of the clause.
1471 /// \param LParenLoc Location of '('.
1472 /// \param EndLoc Ending location of the clause.
1473 /// \param VL List of references to the variables.
1474 /// \param SrcExprs List of helper expressions for proper generation of
1475 /// assignment operation required for lastprivate clause. This list represents
1476 /// private variables (for arrays, single array element).
1477 /// \param DstExprs List of helper expressions for proper generation of
1478 /// assignment operation required for lastprivate clause. This list represents
1479 /// original variables (for arrays, single array element).
1480 /// \param AssignmentOps List of helper expressions that represents assignment
1483 /// DstExprs = SrcExprs;
1485 /// Required for proper codegen of final assignment performed by the
1486 /// lastprivate clause.
1489 static OMPLastprivateClause *
1490 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1491 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1492 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
1493 /// \brief Creates an empty clause with the place for \a N variables.
1495 /// \param C AST context.
1496 /// \param N The number of variables.
1498 static OMPLastprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
1500 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1501 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1502 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1503 typedef llvm::iterator_range<helper_expr_const_iterator>
1504 helper_expr_const_range;
1506 /// \brief Set list of helper expressions, required for generation of private
1507 /// copies of original lastprivate variables.
1508 void setPrivateCopies(ArrayRef<Expr *> PrivateCopies);
1510 helper_expr_const_range private_copies() const {
1511 return helper_expr_const_range(getPrivateCopies().begin(),
1512 getPrivateCopies().end());
1514 helper_expr_range private_copies() {
1515 return helper_expr_range(getPrivateCopies().begin(),
1516 getPrivateCopies().end());
1518 helper_expr_const_range source_exprs() const {
1519 return helper_expr_const_range(getSourceExprs().begin(),
1520 getSourceExprs().end());
1522 helper_expr_range source_exprs() {
1523 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
1525 helper_expr_const_range destination_exprs() const {
1526 return helper_expr_const_range(getDestinationExprs().begin(),
1527 getDestinationExprs().end());
1529 helper_expr_range destination_exprs() {
1530 return helper_expr_range(getDestinationExprs().begin(),
1531 getDestinationExprs().end());
1533 helper_expr_const_range assignment_ops() const {
1534 return helper_expr_const_range(getAssignmentOps().begin(),
1535 getAssignmentOps().end());
1537 helper_expr_range assignment_ops() {
1538 return helper_expr_range(getAssignmentOps().begin(),
1539 getAssignmentOps().end());
1542 child_range children() {
1543 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1544 reinterpret_cast<Stmt **>(varlist_end()));
1547 static bool classof(const OMPClause *T) {
1548 return T->getClauseKind() == OMPC_lastprivate;
1552 /// \brief This represents clause 'shared' in the '#pragma omp ...' directives.
1555 /// #pragma omp parallel shared(a,b)
1557 /// In this example directive '#pragma omp parallel' has clause 'shared'
1558 /// with the variables 'a' and 'b'.
1560 class OMPSharedClause : public OMPVarListClause<OMPSharedClause> {
1561 /// \brief Build clause with number of variables \a N.
1563 /// \param StartLoc Starting location of the clause.
1564 /// \param LParenLoc Location of '('.
1565 /// \param EndLoc Ending location of the clause.
1566 /// \param N Number of the variables in the clause.
1568 OMPSharedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1569 SourceLocation EndLoc, unsigned N)
1570 : OMPVarListClause<OMPSharedClause>(OMPC_shared, StartLoc, LParenLoc,
1573 /// \brief Build an empty clause.
1575 /// \param N Number of variables.
1577 explicit OMPSharedClause(unsigned N)
1578 : OMPVarListClause<OMPSharedClause>(OMPC_shared, SourceLocation(),
1579 SourceLocation(), SourceLocation(),
1583 /// \brief Creates clause with a list of variables \a VL.
1585 /// \param C AST context.
1586 /// \param StartLoc Starting location of the clause.
1587 /// \param LParenLoc Location of '('.
1588 /// \param EndLoc Ending location of the clause.
1589 /// \param VL List of references to the variables.
1591 static OMPSharedClause *Create(const ASTContext &C, SourceLocation StartLoc,
1592 SourceLocation LParenLoc,
1593 SourceLocation EndLoc, ArrayRef<Expr *> VL);
1594 /// \brief Creates an empty clause with \a N variables.
1596 /// \param C AST context.
1597 /// \param N The number of variables.
1599 static OMPSharedClause *CreateEmpty(const ASTContext &C, unsigned N);
1601 child_range children() {
1602 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1603 reinterpret_cast<Stmt **>(varlist_end()));
1606 static bool classof(const OMPClause *T) {
1607 return T->getClauseKind() == OMPC_shared;
1611 /// \brief This represents clause 'reduction' in the '#pragma omp ...'
1615 /// #pragma omp parallel reduction(+:a,b)
1617 /// In this example directive '#pragma omp parallel' has clause 'reduction'
1618 /// with operator '+' and the variables 'a' and 'b'.
1620 class OMPReductionClause : public OMPVarListClause<OMPReductionClause> {
1621 friend class OMPClauseReader;
1622 /// \brief Location of ':'.
1623 SourceLocation ColonLoc;
1624 /// \brief Nested name specifier for C++.
1625 NestedNameSpecifierLoc QualifierLoc;
1626 /// \brief Name of custom operator.
1627 DeclarationNameInfo NameInfo;
1629 /// \brief Build clause with number of variables \a N.
1631 /// \param StartLoc Starting location of the clause.
1632 /// \param LParenLoc Location of '('.
1633 /// \param EndLoc Ending location of the clause.
1634 /// \param ColonLoc Location of ':'.
1635 /// \param N Number of the variables in the clause.
1636 /// \param QualifierLoc The nested-name qualifier with location information
1637 /// \param NameInfo The full name info for reduction identifier.
1639 OMPReductionClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1640 SourceLocation ColonLoc, SourceLocation EndLoc, unsigned N,
1641 NestedNameSpecifierLoc QualifierLoc,
1642 const DeclarationNameInfo &NameInfo)
1643 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, StartLoc,
1644 LParenLoc, EndLoc, N),
1645 ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {}
1647 /// \brief Build an empty clause.
1649 /// \param N Number of variables.
1651 explicit OMPReductionClause(unsigned N)
1652 : OMPVarListClause<OMPReductionClause>(OMPC_reduction, SourceLocation(),
1653 SourceLocation(), SourceLocation(),
1655 ColonLoc(), QualifierLoc(), NameInfo() {}
1657 /// \brief Sets location of ':' symbol in clause.
1658 void setColonLoc(SourceLocation CL) { ColonLoc = CL; }
1659 /// \brief Sets the name info for specified reduction identifier.
1660 void setNameInfo(DeclarationNameInfo DNI) { NameInfo = DNI; }
1661 /// \brief Sets the nested name specifier.
1662 void setQualifierLoc(NestedNameSpecifierLoc NSL) { QualifierLoc = NSL; }
1664 /// \brief Set list of helper expressions, required for proper codegen of the
1665 /// clause. These expressions represent private copy of the reduction
1667 void setPrivates(ArrayRef<Expr *> Privates);
1669 /// \brief Get the list of helper privates.
1670 MutableArrayRef<Expr *> getPrivates() {
1671 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1673 ArrayRef<const Expr *> getPrivates() const {
1674 return llvm::makeArrayRef(varlist_end(), varlist_size());
1677 /// \brief Set list of helper expressions, required for proper codegen of the
1678 /// clause. These expressions represent LHS expression in the final
1679 /// reduction expression performed by the reduction clause.
1680 void setLHSExprs(ArrayRef<Expr *> LHSExprs);
1682 /// \brief Get the list of helper LHS expressions.
1683 MutableArrayRef<Expr *> getLHSExprs() {
1684 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1686 ArrayRef<const Expr *> getLHSExprs() const {
1687 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1690 /// \brief Set list of helper expressions, required for proper codegen of the
1691 /// clause. These expressions represent RHS expression in the final
1692 /// reduction expression performed by the reduction clause.
1693 /// Also, variables in these expressions are used for proper initialization of
1694 /// reduction copies.
1695 void setRHSExprs(ArrayRef<Expr *> RHSExprs);
1697 /// \brief Get the list of helper destination expressions.
1698 MutableArrayRef<Expr *> getRHSExprs() {
1699 return MutableArrayRef<Expr *>(getLHSExprs().end(), varlist_size());
1701 ArrayRef<const Expr *> getRHSExprs() const {
1702 return llvm::makeArrayRef(getLHSExprs().end(), varlist_size());
1705 /// \brief Set list of helper reduction expressions, required for proper
1706 /// codegen of the clause. These expressions are binary expressions or
1707 /// operator/custom reduction call that calculates new value from source
1708 /// helper expressions to destination helper expressions.
1709 void setReductionOps(ArrayRef<Expr *> ReductionOps);
1711 /// \brief Get the list of helper reduction expressions.
1712 MutableArrayRef<Expr *> getReductionOps() {
1713 return MutableArrayRef<Expr *>(getRHSExprs().end(), varlist_size());
1715 ArrayRef<const Expr *> getReductionOps() const {
1716 return llvm::makeArrayRef(getRHSExprs().end(), varlist_size());
1720 /// \brief Creates clause with a list of variables \a VL.
1722 /// \param StartLoc Starting location of the clause.
1723 /// \param LParenLoc Location of '('.
1724 /// \param ColonLoc Location of ':'.
1725 /// \param EndLoc Ending location of the clause.
1726 /// \param VL The variables in the clause.
1727 /// \param QualifierLoc The nested-name qualifier with location information
1728 /// \param NameInfo The full name info for reduction identifier.
1729 /// \param Privates List of helper expressions for proper generation of
1731 /// \param LHSExprs List of helper expressions for proper generation of
1732 /// assignment operation required for copyprivate clause. This list represents
1733 /// LHSs of the reduction expressions.
1734 /// \param RHSExprs List of helper expressions for proper generation of
1735 /// assignment operation required for copyprivate clause. This list represents
1736 /// RHSs of the reduction expressions.
1737 /// Also, variables in these expressions are used for proper initialization of
1738 /// reduction copies.
1739 /// \param ReductionOps List of helper expressions that represents reduction
1742 /// LHSExprs binop RHSExprs;
1743 /// operator binop(LHSExpr, RHSExpr);
1744 /// <CutomReduction>(LHSExpr, RHSExpr);
1746 /// Required for proper codegen of final reduction operation performed by the
1747 /// reduction clause.
1749 static OMPReductionClause *
1750 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1751 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1752 NestedNameSpecifierLoc QualifierLoc,
1753 const DeclarationNameInfo &NameInfo, ArrayRef<Expr *> Privates,
1754 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1755 ArrayRef<Expr *> ReductionOps);
1756 /// \brief Creates an empty clause with the place for \a N variables.
1758 /// \param C AST context.
1759 /// \param N The number of variables.
1761 static OMPReductionClause *CreateEmpty(const ASTContext &C, unsigned N);
1763 /// \brief Gets location of ':' symbol in clause.
1764 SourceLocation getColonLoc() const { return ColonLoc; }
1765 /// \brief Gets the name info for specified reduction identifier.
1766 const DeclarationNameInfo &getNameInfo() const { return NameInfo; }
1767 /// \brief Gets the nested name specifier.
1768 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
1770 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
1771 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
1772 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
1773 typedef llvm::iterator_range<helper_expr_const_iterator>
1774 helper_expr_const_range;
1776 helper_expr_const_range privates() const {
1777 return helper_expr_const_range(getPrivates().begin(), getPrivates().end());
1779 helper_expr_range privates() {
1780 return helper_expr_range(getPrivates().begin(), getPrivates().end());
1782 helper_expr_const_range lhs_exprs() const {
1783 return helper_expr_const_range(getLHSExprs().begin(), getLHSExprs().end());
1785 helper_expr_range lhs_exprs() {
1786 return helper_expr_range(getLHSExprs().begin(), getLHSExprs().end());
1788 helper_expr_const_range rhs_exprs() const {
1789 return helper_expr_const_range(getRHSExprs().begin(), getRHSExprs().end());
1791 helper_expr_range rhs_exprs() {
1792 return helper_expr_range(getRHSExprs().begin(), getRHSExprs().end());
1794 helper_expr_const_range reduction_ops() const {
1795 return helper_expr_const_range(getReductionOps().begin(),
1796 getReductionOps().end());
1798 helper_expr_range reduction_ops() {
1799 return helper_expr_range(getReductionOps().begin(),
1800 getReductionOps().end());
1803 child_range children() {
1804 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
1805 reinterpret_cast<Stmt **>(varlist_end()));
1808 static bool classof(const OMPClause *T) {
1809 return T->getClauseKind() == OMPC_reduction;
1813 /// \brief This represents clause 'linear' in the '#pragma omp ...'
1817 /// #pragma omp simd linear(a,b : 2)
1819 /// In this example directive '#pragma omp simd' has clause 'linear'
1820 /// with variables 'a', 'b' and linear step '2'.
1822 class OMPLinearClause : public OMPVarListClause<OMPLinearClause> {
1823 friend class OMPClauseReader;
1824 /// \brief Modifier of 'linear' clause.
1825 OpenMPLinearClauseKind Modifier;
1826 /// \brief Location of linear modifier if any.
1827 SourceLocation ModifierLoc;
1828 /// \brief Location of ':'.
1829 SourceLocation ColonLoc;
1831 /// \brief Sets the linear step for clause.
1832 void setStep(Expr *Step) { *(getFinals().end()) = Step; }
1834 /// \brief Sets the expression to calculate linear step for clause.
1835 void setCalcStep(Expr *CalcStep) { *(getFinals().end() + 1) = CalcStep; }
1837 /// \brief Build 'linear' clause with given number of variables \a NumVars.
1839 /// \param StartLoc Starting location of the clause.
1840 /// \param LParenLoc Location of '('.
1841 /// \param ColonLoc Location of ':'.
1842 /// \param EndLoc Ending location of the clause.
1843 /// \param NumVars Number of variables.
1845 OMPLinearClause(SourceLocation StartLoc, SourceLocation LParenLoc,
1846 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
1847 SourceLocation ColonLoc, SourceLocation EndLoc,
1849 : OMPVarListClause<OMPLinearClause>(OMPC_linear, StartLoc, LParenLoc,
1851 Modifier(Modifier), ModifierLoc(ModifierLoc), ColonLoc(ColonLoc) {}
1853 /// \brief Build an empty clause.
1855 /// \param NumVars Number of variables.
1857 explicit OMPLinearClause(unsigned NumVars)
1858 : OMPVarListClause<OMPLinearClause>(OMPC_linear, SourceLocation(),
1859 SourceLocation(), SourceLocation(),
1861 Modifier(OMPC_LINEAR_val), ModifierLoc(), ColonLoc() {}
1863 /// \brief Gets the list of initial values for linear variables.
1865 /// There are NumVars expressions with initial values allocated after the
1866 /// varlist, they are followed by NumVars update expressions (used to update
1867 /// the linear variable's value on current iteration) and they are followed by
1868 /// NumVars final expressions (used to calculate the linear variable's
1869 /// value after the loop body). After these lists, there are 2 helper
1870 /// expressions - linear step and a helper to calculate it before the
1871 /// loop body (used when the linear step is not constant):
1873 /// { Vars[] /* in OMPVarListClause */; Privates[]; Inits[]; Updates[];
1874 /// Finals[]; Step; CalcStep; }
1876 MutableArrayRef<Expr *> getPrivates() {
1877 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
1879 ArrayRef<const Expr *> getPrivates() const {
1880 return llvm::makeArrayRef(varlist_end(), varlist_size());
1883 MutableArrayRef<Expr *> getInits() {
1884 return MutableArrayRef<Expr *>(getPrivates().end(), varlist_size());
1886 ArrayRef<const Expr *> getInits() const {
1887 return llvm::makeArrayRef(getPrivates().end(), varlist_size());
1890 /// \brief Sets the list of update expressions for linear variables.
1891 MutableArrayRef<Expr *> getUpdates() {
1892 return MutableArrayRef<Expr *>(getInits().end(), varlist_size());
1894 ArrayRef<const Expr *> getUpdates() const {
1895 return llvm::makeArrayRef(getInits().end(), varlist_size());
1898 /// \brief Sets the list of final update expressions for linear variables.
1899 MutableArrayRef<Expr *> getFinals() {
1900 return MutableArrayRef<Expr *>(getUpdates().end(), varlist_size());
1902 ArrayRef<const Expr *> getFinals() const {
1903 return llvm::makeArrayRef(getUpdates().end(), varlist_size());
1906 /// \brief Sets the list of the copies of original linear variables.
1907 /// \param PL List of expressions.
1908 void setPrivates(ArrayRef<Expr *> PL);
1910 /// \brief Sets the list of the initial values for linear variables.
1911 /// \param IL List of expressions.
1912 void setInits(ArrayRef<Expr *> IL);
1915 /// \brief Creates clause with a list of variables \a VL and a linear step
1918 /// \param C AST Context.
1919 /// \param StartLoc Starting location of the clause.
1920 /// \param LParenLoc Location of '('.
1921 /// \param Modifier Modifier of 'linear' clause.
1922 /// \param ModifierLoc Modifier location.
1923 /// \param ColonLoc Location of ':'.
1924 /// \param EndLoc Ending location of the clause.
1925 /// \param VL List of references to the variables.
1926 /// \param PL List of private copies of original variables.
1927 /// \param IL List of initial values for the variables.
1928 /// \param Step Linear step.
1929 /// \param CalcStep Calculation of the linear step.
1930 static OMPLinearClause *
1931 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1932 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
1933 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1934 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep);
1936 /// \brief Creates an empty clause with the place for \a NumVars variables.
1938 /// \param C AST context.
1939 /// \param NumVars Number of variables.
1941 static OMPLinearClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
1943 /// \brief Set modifier.
1944 void setModifier(OpenMPLinearClauseKind Kind) { Modifier = Kind; }
1945 /// \brief Return modifier.
1946 OpenMPLinearClauseKind getModifier() const { return Modifier; }
1948 /// \brief Set modifier location.
1949 void setModifierLoc(SourceLocation Loc) { ModifierLoc = Loc; }
1950 /// \brief Return modifier location.
1951 SourceLocation getModifierLoc() const { return ModifierLoc; }
1953 /// \brief Sets the location of ':'.
1954 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
1955 /// \brief Returns the location of ':'.
1956 SourceLocation getColonLoc() const { return ColonLoc; }
1958 /// \brief Returns linear step.
1959 Expr *getStep() { return *(getFinals().end()); }
1960 /// \brief Returns linear step.
1961 const Expr *getStep() const { return *(getFinals().end()); }
1962 /// \brief Returns expression to calculate linear step.
1963 Expr *getCalcStep() { return *(getFinals().end() + 1); }
1964 /// \brief Returns expression to calculate linear step.
1965 const Expr *getCalcStep() const { return *(getFinals().end() + 1); }
1967 /// \brief Sets the list of update expressions for linear variables.
1968 /// \param UL List of expressions.
1969 void setUpdates(ArrayRef<Expr *> UL);
1971 /// \brief Sets the list of final update expressions for linear variables.
1972 /// \param FL List of expressions.
1973 void setFinals(ArrayRef<Expr *> FL);
1975 typedef MutableArrayRef<Expr *>::iterator privates_iterator;
1976 typedef ArrayRef<const Expr *>::iterator privates_const_iterator;
1977 typedef llvm::iterator_range<privates_iterator> privates_range;
1978 typedef llvm::iterator_range<privates_const_iterator> privates_const_range;
1980 privates_range privates() {
1981 return privates_range(getPrivates().begin(), getPrivates().end());
1983 privates_const_range privates() const {
1984 return privates_const_range(getPrivates().begin(), getPrivates().end());
1987 typedef MutableArrayRef<Expr *>::iterator inits_iterator;
1988 typedef ArrayRef<const Expr *>::iterator inits_const_iterator;
1989 typedef llvm::iterator_range<inits_iterator> inits_range;
1990 typedef llvm::iterator_range<inits_const_iterator> inits_const_range;
1992 inits_range inits() {
1993 return inits_range(getInits().begin(), getInits().end());
1995 inits_const_range inits() const {
1996 return inits_const_range(getInits().begin(), getInits().end());
1999 typedef MutableArrayRef<Expr *>::iterator updates_iterator;
2000 typedef ArrayRef<const Expr *>::iterator updates_const_iterator;
2001 typedef llvm::iterator_range<updates_iterator> updates_range;
2002 typedef llvm::iterator_range<updates_const_iterator> updates_const_range;
2004 updates_range updates() {
2005 return updates_range(getUpdates().begin(), getUpdates().end());
2007 updates_const_range updates() const {
2008 return updates_const_range(getUpdates().begin(), getUpdates().end());
2011 typedef MutableArrayRef<Expr *>::iterator finals_iterator;
2012 typedef ArrayRef<const Expr *>::iterator finals_const_iterator;
2013 typedef llvm::iterator_range<finals_iterator> finals_range;
2014 typedef llvm::iterator_range<finals_const_iterator> finals_const_range;
2016 finals_range finals() {
2017 return finals_range(getFinals().begin(), getFinals().end());
2019 finals_const_range finals() const {
2020 return finals_const_range(getFinals().begin(), getFinals().end());
2023 child_range children() {
2024 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2025 reinterpret_cast<Stmt **>(varlist_end()));
2028 static bool classof(const OMPClause *T) {
2029 return T->getClauseKind() == OMPC_linear;
2033 /// \brief This represents clause 'aligned' in the '#pragma omp ...'
2037 /// #pragma omp simd aligned(a,b : 8)
2039 /// In this example directive '#pragma omp simd' has clause 'aligned'
2040 /// with variables 'a', 'b' and alignment '8'.
2042 class OMPAlignedClause : public OMPVarListClause<OMPAlignedClause> {
2043 friend class OMPClauseReader;
2044 /// \brief Location of ':'.
2045 SourceLocation ColonLoc;
2047 /// \brief Sets the alignment for clause.
2048 void setAlignment(Expr *A) { *varlist_end() = A; }
2050 /// \brief Build 'aligned' clause with given number of variables \a NumVars.
2052 /// \param StartLoc Starting location of the clause.
2053 /// \param LParenLoc Location of '('.
2054 /// \param ColonLoc Location of ':'.
2055 /// \param EndLoc Ending location of the clause.
2056 /// \param NumVars Number of variables.
2058 OMPAlignedClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2059 SourceLocation ColonLoc, SourceLocation EndLoc,
2061 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, StartLoc, LParenLoc,
2063 ColonLoc(ColonLoc) {}
2065 /// \brief Build an empty clause.
2067 /// \param NumVars Number of variables.
2069 explicit OMPAlignedClause(unsigned NumVars)
2070 : OMPVarListClause<OMPAlignedClause>(OMPC_aligned, SourceLocation(),
2071 SourceLocation(), SourceLocation(),
2073 ColonLoc(SourceLocation()) {}
2076 /// \brief Creates clause with a list of variables \a VL and alignment \a A.
2078 /// \param C AST Context.
2079 /// \param StartLoc Starting location of the clause.
2080 /// \param LParenLoc Location of '('.
2081 /// \param ColonLoc Location of ':'.
2082 /// \param EndLoc Ending location of the clause.
2083 /// \param VL List of references to the variables.
2084 /// \param A Alignment.
2085 static OMPAlignedClause *Create(const ASTContext &C, SourceLocation StartLoc,
2086 SourceLocation LParenLoc,
2087 SourceLocation ColonLoc,
2088 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2091 /// \brief Creates an empty clause with the place for \a NumVars variables.
2093 /// \param C AST context.
2094 /// \param NumVars Number of variables.
2096 static OMPAlignedClause *CreateEmpty(const ASTContext &C, unsigned NumVars);
2098 /// \brief Sets the location of ':'.
2099 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2100 /// \brief Returns the location of ':'.
2101 SourceLocation getColonLoc() const { return ColonLoc; }
2103 /// \brief Returns alignment.
2104 Expr *getAlignment() { return *varlist_end(); }
2105 /// \brief Returns alignment.
2106 const Expr *getAlignment() const { return *varlist_end(); }
2108 child_range children() {
2109 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2110 reinterpret_cast<Stmt **>(varlist_end()));
2113 static bool classof(const OMPClause *T) {
2114 return T->getClauseKind() == OMPC_aligned;
2118 /// \brief This represents clause 'copyin' in the '#pragma omp ...' directives.
2121 /// #pragma omp parallel copyin(a,b)
2123 /// In this example directive '#pragma omp parallel' has clause 'copyin'
2124 /// with the variables 'a' and 'b'.
2126 class OMPCopyinClause : public OMPVarListClause<OMPCopyinClause> {
2127 // Class has 3 additional tail allocated arrays:
2128 // 1. List of helper expressions for proper generation of assignment operation
2129 // required for copyin clause. This list represents sources.
2130 // 2. List of helper expressions for proper generation of assignment operation
2131 // required for copyin clause. This list represents destinations.
2132 // 3. List of helper expressions that represents assignment operation:
2134 // DstExprs = SrcExprs;
2136 // Required for proper codegen of propagation of master's thread values of
2137 // threadprivate variables to local instances of that variables in other
2138 // implicit threads.
2140 friend class OMPClauseReader;
2141 /// \brief Build clause with number of variables \a N.
2143 /// \param StartLoc Starting location of the clause.
2144 /// \param LParenLoc Location of '('.
2145 /// \param EndLoc Ending location of the clause.
2146 /// \param N Number of the variables in the clause.
2148 OMPCopyinClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2149 SourceLocation EndLoc, unsigned N)
2150 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, StartLoc, LParenLoc,
2153 /// \brief Build an empty clause.
2155 /// \param N Number of variables.
2157 explicit OMPCopyinClause(unsigned N)
2158 : OMPVarListClause<OMPCopyinClause>(OMPC_copyin, SourceLocation(),
2159 SourceLocation(), SourceLocation(),
2162 /// \brief Set list of helper expressions, required for proper codegen of the
2163 /// clause. These expressions represent source expression in the final
2164 /// assignment statement performed by the copyin clause.
2165 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2167 /// \brief Get the list of helper source expressions.
2168 MutableArrayRef<Expr *> getSourceExprs() {
2169 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2171 ArrayRef<const Expr *> getSourceExprs() const {
2172 return llvm::makeArrayRef(varlist_end(), varlist_size());
2175 /// \brief Set list of helper expressions, required for proper codegen of the
2176 /// clause. These expressions represent destination expression in the final
2177 /// assignment statement performed by the copyin clause.
2178 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2180 /// \brief Get the list of helper destination expressions.
2181 MutableArrayRef<Expr *> getDestinationExprs() {
2182 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2184 ArrayRef<const Expr *> getDestinationExprs() const {
2185 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2188 /// \brief Set list of helper assignment expressions, required for proper
2189 /// codegen of the clause. These expressions are assignment expressions that
2190 /// assign source helper expressions to destination helper expressions
2191 /// correspondingly.
2192 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2194 /// \brief Get the list of helper assignment expressions.
2195 MutableArrayRef<Expr *> getAssignmentOps() {
2196 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2198 ArrayRef<const Expr *> getAssignmentOps() const {
2199 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2203 /// \brief Creates clause with a list of variables \a VL.
2205 /// \param C AST context.
2206 /// \param StartLoc Starting location of the clause.
2207 /// \param LParenLoc Location of '('.
2208 /// \param EndLoc Ending location of the clause.
2209 /// \param VL List of references to the variables.
2210 /// \param SrcExprs List of helper expressions for proper generation of
2211 /// assignment operation required for copyin clause. This list represents
2213 /// \param DstExprs List of helper expressions for proper generation of
2214 /// assignment operation required for copyin clause. This list represents
2216 /// \param AssignmentOps List of helper expressions that represents assignment
2219 /// DstExprs = SrcExprs;
2221 /// Required for proper codegen of propagation of master's thread values of
2222 /// threadprivate variables to local instances of that variables in other
2223 /// implicit threads.
2225 static OMPCopyinClause *
2226 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2227 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2228 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2229 /// \brief Creates an empty clause with \a N variables.
2231 /// \param C AST context.
2232 /// \param N The number of variables.
2234 static OMPCopyinClause *CreateEmpty(const ASTContext &C, unsigned N);
2236 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2237 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2238 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2239 typedef llvm::iterator_range<helper_expr_const_iterator>
2240 helper_expr_const_range;
2242 helper_expr_const_range source_exprs() const {
2243 return helper_expr_const_range(getSourceExprs().begin(),
2244 getSourceExprs().end());
2246 helper_expr_range source_exprs() {
2247 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2249 helper_expr_const_range destination_exprs() const {
2250 return helper_expr_const_range(getDestinationExprs().begin(),
2251 getDestinationExprs().end());
2253 helper_expr_range destination_exprs() {
2254 return helper_expr_range(getDestinationExprs().begin(),
2255 getDestinationExprs().end());
2257 helper_expr_const_range assignment_ops() const {
2258 return helper_expr_const_range(getAssignmentOps().begin(),
2259 getAssignmentOps().end());
2261 helper_expr_range assignment_ops() {
2262 return helper_expr_range(getAssignmentOps().begin(),
2263 getAssignmentOps().end());
2266 child_range children() {
2267 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2268 reinterpret_cast<Stmt **>(varlist_end()));
2271 static bool classof(const OMPClause *T) {
2272 return T->getClauseKind() == OMPC_copyin;
2276 /// \brief This represents clause 'copyprivate' in the '#pragma omp ...'
2280 /// #pragma omp single copyprivate(a,b)
2282 /// In this example directive '#pragma omp single' has clause 'copyprivate'
2283 /// with the variables 'a' and 'b'.
2285 class OMPCopyprivateClause : public OMPVarListClause<OMPCopyprivateClause> {
2286 friend class OMPClauseReader;
2287 /// \brief Build clause with number of variables \a N.
2289 /// \param StartLoc Starting location of the clause.
2290 /// \param LParenLoc Location of '('.
2291 /// \param EndLoc Ending location of the clause.
2292 /// \param N Number of the variables in the clause.
2294 OMPCopyprivateClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2295 SourceLocation EndLoc, unsigned N)
2296 : OMPVarListClause<OMPCopyprivateClause>(OMPC_copyprivate, StartLoc,
2297 LParenLoc, EndLoc, N) {}
2299 /// \brief Build an empty clause.
2301 /// \param N Number of variables.
2303 explicit OMPCopyprivateClause(unsigned N)
2304 : OMPVarListClause<OMPCopyprivateClause>(
2305 OMPC_copyprivate, SourceLocation(), SourceLocation(),
2306 SourceLocation(), N) {}
2308 /// \brief Set list of helper expressions, required for proper codegen of the
2309 /// clause. These expressions represent source expression in the final
2310 /// assignment statement performed by the copyprivate clause.
2311 void setSourceExprs(ArrayRef<Expr *> SrcExprs);
2313 /// \brief Get the list of helper source expressions.
2314 MutableArrayRef<Expr *> getSourceExprs() {
2315 return MutableArrayRef<Expr *>(varlist_end(), varlist_size());
2317 ArrayRef<const Expr *> getSourceExprs() const {
2318 return llvm::makeArrayRef(varlist_end(), varlist_size());
2321 /// \brief Set list of helper expressions, required for proper codegen of the
2322 /// clause. These expressions represent destination expression in the final
2323 /// assignment statement performed by the copyprivate clause.
2324 void setDestinationExprs(ArrayRef<Expr *> DstExprs);
2326 /// \brief Get the list of helper destination expressions.
2327 MutableArrayRef<Expr *> getDestinationExprs() {
2328 return MutableArrayRef<Expr *>(getSourceExprs().end(), varlist_size());
2330 ArrayRef<const Expr *> getDestinationExprs() const {
2331 return llvm::makeArrayRef(getSourceExprs().end(), varlist_size());
2334 /// \brief Set list of helper assignment expressions, required for proper
2335 /// codegen of the clause. These expressions are assignment expressions that
2336 /// assign source helper expressions to destination helper expressions
2337 /// correspondingly.
2338 void setAssignmentOps(ArrayRef<Expr *> AssignmentOps);
2340 /// \brief Get the list of helper assignment expressions.
2341 MutableArrayRef<Expr *> getAssignmentOps() {
2342 return MutableArrayRef<Expr *>(getDestinationExprs().end(), varlist_size());
2344 ArrayRef<const Expr *> getAssignmentOps() const {
2345 return llvm::makeArrayRef(getDestinationExprs().end(), varlist_size());
2349 /// \brief Creates clause with a list of variables \a VL.
2351 /// \param C AST context.
2352 /// \param StartLoc Starting location of the clause.
2353 /// \param LParenLoc Location of '('.
2354 /// \param EndLoc Ending location of the clause.
2355 /// \param VL List of references to the variables.
2356 /// \param SrcExprs List of helper expressions for proper generation of
2357 /// assignment operation required for copyprivate clause. This list represents
2359 /// \param DstExprs List of helper expressions for proper generation of
2360 /// assignment operation required for copyprivate clause. This list represents
2362 /// \param AssignmentOps List of helper expressions that represents assignment
2365 /// DstExprs = SrcExprs;
2367 /// Required for proper codegen of final assignment performed by the
2368 /// copyprivate clause.
2370 static OMPCopyprivateClause *
2371 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2372 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
2373 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps);
2374 /// \brief Creates an empty clause with \a N variables.
2376 /// \param C AST context.
2377 /// \param N The number of variables.
2379 static OMPCopyprivateClause *CreateEmpty(const ASTContext &C, unsigned N);
2381 typedef MutableArrayRef<Expr *>::iterator helper_expr_iterator;
2382 typedef ArrayRef<const Expr *>::iterator helper_expr_const_iterator;
2383 typedef llvm::iterator_range<helper_expr_iterator> helper_expr_range;
2384 typedef llvm::iterator_range<helper_expr_const_iterator>
2385 helper_expr_const_range;
2387 helper_expr_const_range source_exprs() const {
2388 return helper_expr_const_range(getSourceExprs().begin(),
2389 getSourceExprs().end());
2391 helper_expr_range source_exprs() {
2392 return helper_expr_range(getSourceExprs().begin(), getSourceExprs().end());
2394 helper_expr_const_range destination_exprs() const {
2395 return helper_expr_const_range(getDestinationExprs().begin(),
2396 getDestinationExprs().end());
2398 helper_expr_range destination_exprs() {
2399 return helper_expr_range(getDestinationExprs().begin(),
2400 getDestinationExprs().end());
2402 helper_expr_const_range assignment_ops() const {
2403 return helper_expr_const_range(getAssignmentOps().begin(),
2404 getAssignmentOps().end());
2406 helper_expr_range assignment_ops() {
2407 return helper_expr_range(getAssignmentOps().begin(),
2408 getAssignmentOps().end());
2411 child_range children() {
2412 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2413 reinterpret_cast<Stmt **>(varlist_end()));
2416 static bool classof(const OMPClause *T) {
2417 return T->getClauseKind() == OMPC_copyprivate;
2421 /// \brief This represents implicit clause 'flush' for the '#pragma omp flush'
2423 /// This clause does not exist by itself, it can be only as a part of 'omp
2424 /// flush' directive. This clause is introduced to keep the original structure
2425 /// of \a OMPExecutableDirective class and its derivatives and to use the
2426 /// existing infrastructure of clauses with the list of variables.
2429 /// #pragma omp flush(a,b)
2431 /// In this example directive '#pragma omp flush' has implicit clause 'flush'
2432 /// with the variables 'a' and 'b'.
2434 class OMPFlushClause : public OMPVarListClause<OMPFlushClause> {
2435 /// \brief Build clause with number of variables \a N.
2437 /// \param StartLoc Starting location of the clause.
2438 /// \param LParenLoc Location of '('.
2439 /// \param EndLoc Ending location of the clause.
2440 /// \param N Number of the variables in the clause.
2442 OMPFlushClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2443 SourceLocation EndLoc, unsigned N)
2444 : OMPVarListClause<OMPFlushClause>(OMPC_flush, StartLoc, LParenLoc,
2447 /// \brief Build an empty clause.
2449 /// \param N Number of variables.
2451 explicit OMPFlushClause(unsigned N)
2452 : OMPVarListClause<OMPFlushClause>(OMPC_flush, SourceLocation(),
2453 SourceLocation(), SourceLocation(),
2457 /// \brief Creates clause with a list of variables \a VL.
2459 /// \param C AST context.
2460 /// \param StartLoc Starting location of the clause.
2461 /// \param LParenLoc Location of '('.
2462 /// \param EndLoc Ending location of the clause.
2463 /// \param VL List of references to the variables.
2465 static OMPFlushClause *Create(const ASTContext &C, SourceLocation StartLoc,
2466 SourceLocation LParenLoc, SourceLocation EndLoc,
2467 ArrayRef<Expr *> VL);
2468 /// \brief Creates an empty clause with \a N variables.
2470 /// \param C AST context.
2471 /// \param N The number of variables.
2473 static OMPFlushClause *CreateEmpty(const ASTContext &C, unsigned N);
2475 child_range children() {
2476 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2477 reinterpret_cast<Stmt **>(varlist_end()));
2480 static bool classof(const OMPClause *T) {
2481 return T->getClauseKind() == OMPC_flush;
2485 /// \brief This represents implicit clause 'depend' for the '#pragma omp task'
2489 /// #pragma omp task depend(in:a,b)
2491 /// In this example directive '#pragma omp task' with clause 'depend' with the
2492 /// variables 'a' and 'b' with dependency 'in'.
2494 class OMPDependClause : public OMPVarListClause<OMPDependClause> {
2495 friend class OMPClauseReader;
2496 /// \brief Dependency type (one of in, out, inout).
2497 OpenMPDependClauseKind DepKind;
2498 /// \brief Dependency type location.
2499 SourceLocation DepLoc;
2500 /// \brief Colon location.
2501 SourceLocation ColonLoc;
2502 /// \brief Build clause with number of variables \a N.
2504 /// \param StartLoc Starting location of the clause.
2505 /// \param LParenLoc Location of '('.
2506 /// \param EndLoc Ending location of the clause.
2507 /// \param N Number of the variables in the clause.
2509 OMPDependClause(SourceLocation StartLoc, SourceLocation LParenLoc,
2510 SourceLocation EndLoc, unsigned N)
2511 : OMPVarListClause<OMPDependClause>(OMPC_depend, StartLoc, LParenLoc,
2513 DepKind(OMPC_DEPEND_unknown) {}
2515 /// \brief Build an empty clause.
2517 /// \param N Number of variables.
2519 explicit OMPDependClause(unsigned N)
2520 : OMPVarListClause<OMPDependClause>(OMPC_depend, SourceLocation(),
2521 SourceLocation(), SourceLocation(),
2523 DepKind(OMPC_DEPEND_unknown) {}
2524 /// \brief Set dependency kind.
2525 void setDependencyKind(OpenMPDependClauseKind K) { DepKind = K; }
2527 /// \brief Set dependency kind and its location.
2528 void setDependencyLoc(SourceLocation Loc) { DepLoc = Loc; }
2530 /// \brief Set colon location.
2531 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2534 /// \brief Creates clause with a list of variables \a VL.
2536 /// \param C AST context.
2537 /// \param StartLoc Starting location of the clause.
2538 /// \param LParenLoc Location of '('.
2539 /// \param EndLoc Ending location of the clause.
2540 /// \param DepKind Dependency type.
2541 /// \param DepLoc Location of the dependency type.
2542 /// \param ColonLoc Colon location.
2543 /// \param VL List of references to the variables.
2545 static OMPDependClause *
2546 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
2547 SourceLocation EndLoc, OpenMPDependClauseKind DepKind,
2548 SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL);
2549 /// \brief Creates an empty clause with \a N variables.
2551 /// \param C AST context.
2552 /// \param N The number of variables.
2554 static OMPDependClause *CreateEmpty(const ASTContext &C, unsigned N);
2556 /// \brief Get dependency type.
2557 OpenMPDependClauseKind getDependencyKind() const { return DepKind; }
2558 /// \brief Get dependency type location.
2559 SourceLocation getDependencyLoc() const { return DepLoc; }
2560 /// \brief Get colon location.
2561 SourceLocation getColonLoc() const { return ColonLoc; }
2563 child_range children() {
2564 return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
2565 reinterpret_cast<Stmt **>(varlist_end()));
2568 static bool classof(const OMPClause *T) {
2569 return T->getClauseKind() == OMPC_depend;
2573 /// \brief This represents 'device' clause in the '#pragma omp ...'
2577 /// #pragma omp target device(a)
2579 /// In this example directive '#pragma omp target' has clause 'device'
2580 /// with single expression 'a'.
2582 class OMPDeviceClause : public OMPClause {
2583 friend class OMPClauseReader;
2584 /// \brief Location of '('.
2585 SourceLocation LParenLoc;
2586 /// \brief Device number.
2588 /// \brief Set the device number.
2590 /// \param E Device number.
2592 void setDevice(Expr *E) { Device = E; }
2595 /// \brief Build 'device' clause.
2597 /// \param E Expression associated with this clause.
2598 /// \param StartLoc Starting location of the clause.
2599 /// \param LParenLoc Location of '('.
2600 /// \param EndLoc Ending location of the clause.
2602 OMPDeviceClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2603 SourceLocation EndLoc)
2604 : OMPClause(OMPC_device, StartLoc, EndLoc), LParenLoc(LParenLoc),
2607 /// \brief Build an empty clause.
2610 : OMPClause(OMPC_device, SourceLocation(), SourceLocation()),
2611 LParenLoc(SourceLocation()), Device(nullptr) {}
2612 /// \brief Sets the location of '('.
2613 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2614 /// \brief Returns the location of '('.
2615 SourceLocation getLParenLoc() const { return LParenLoc; }
2616 /// \brief Return device number.
2617 Expr *getDevice() { return cast<Expr>(Device); }
2618 /// \brief Return device number.
2619 Expr *getDevice() const { return cast<Expr>(Device); }
2621 static bool classof(const OMPClause *T) {
2622 return T->getClauseKind() == OMPC_device;
2625 child_range children() { return child_range(&Device, &Device + 1); }
2628 /// \brief This represents 'threads' clause in the '#pragma omp ...' directive.
2631 /// #pragma omp ordered threads
2633 /// In this example directive '#pragma omp ordered' has simple 'threads' clause.
2635 class OMPThreadsClause : public OMPClause {
2637 /// \brief Build 'threads' clause.
2639 /// \param StartLoc Starting location of the clause.
2640 /// \param EndLoc Ending location of the clause.
2642 OMPThreadsClause(SourceLocation StartLoc, SourceLocation EndLoc)
2643 : OMPClause(OMPC_threads, StartLoc, EndLoc) {}
2645 /// \brief Build an empty clause.
2648 : OMPClause(OMPC_threads, SourceLocation(), SourceLocation()) {}
2650 static bool classof(const OMPClause *T) {
2651 return T->getClauseKind() == OMPC_threads;
2654 child_range children() {
2655 return child_range(child_iterator(), child_iterator());
2659 /// \brief This represents 'simd' clause in the '#pragma omp ...' directive.
2662 /// #pragma omp ordered simd
2664 /// In this example directive '#pragma omp ordered' has simple 'simd' clause.
2666 class OMPSIMDClause : public OMPClause {
2668 /// \brief Build 'simd' clause.
2670 /// \param StartLoc Starting location of the clause.
2671 /// \param EndLoc Ending location of the clause.
2673 OMPSIMDClause(SourceLocation StartLoc, SourceLocation EndLoc)
2674 : OMPClause(OMPC_simd, StartLoc, EndLoc) {}
2676 /// \brief Build an empty clause.
2678 OMPSIMDClause() : OMPClause(OMPC_simd, SourceLocation(), SourceLocation()) {}
2680 static bool classof(const OMPClause *T) {
2681 return T->getClauseKind() == OMPC_simd;
2684 child_range children() {
2685 return child_range(child_iterator(), child_iterator());
2689 /// \brief This represents clause 'map' in the '#pragma omp ...'
2693 /// #pragma omp target map(a,b)
2695 /// In this example directive '#pragma omp target' has clause 'map'
2696 /// with the variables 'a' and 'b'.
2698 class OMPMapClause : public OMPVarListClause<OMPMapClause> {
2699 friend class OMPClauseReader;
2701 /// \brief Map type modifier for the 'map' clause.
2702 OpenMPMapClauseKind MapTypeModifier;
2703 /// \brief Map type for the 'map' clause.
2704 OpenMPMapClauseKind MapType;
2705 /// \brief Location of the map type.
2706 SourceLocation MapLoc;
2707 /// \brief Colon location.
2708 SourceLocation ColonLoc;
2710 /// \brief Set type modifier for the clause.
2712 /// \param T Type Modifier for the clause.
2714 void setMapTypeModifier(OpenMPMapClauseKind T) { MapTypeModifier = T; }
2716 /// \brief Set type for the clause.
2718 /// \param T Type for the clause.
2720 void setMapType(OpenMPMapClauseKind T) { MapType = T; }
2722 /// \brief Set type location.
2724 /// \param TLoc Type location.
2726 void setMapLoc(SourceLocation TLoc) { MapLoc = TLoc; }
2728 /// \brief Set colon location.
2729 void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
2731 /// \brief Build clause with number of variables \a N.
2733 /// \param MapTypeModifier Map type modifier.
2734 /// \param MapType Map type.
2735 /// \param MapLoc Location of the map type.
2736 /// \param StartLoc Starting location of the clause.
2737 /// \param EndLoc Ending location of the clause.
2738 /// \param N Number of the variables in the clause.
2740 explicit OMPMapClause(OpenMPMapClauseKind MapTypeModifier,
2741 OpenMPMapClauseKind MapType, SourceLocation MapLoc,
2742 SourceLocation StartLoc, SourceLocation LParenLoc,
2743 SourceLocation EndLoc, unsigned N)
2744 : OMPVarListClause<OMPMapClause>(OMPC_map, StartLoc, LParenLoc, EndLoc, N),
2745 MapTypeModifier(MapTypeModifier), MapType(MapType), MapLoc(MapLoc) {}
2747 /// \brief Build an empty clause.
2749 /// \param N Number of variables.
2751 explicit OMPMapClause(unsigned N)
2752 : OMPVarListClause<OMPMapClause>(OMPC_map, SourceLocation(),
2753 SourceLocation(), SourceLocation(), N),
2754 MapTypeModifier(OMPC_MAP_unknown), MapType(OMPC_MAP_unknown), MapLoc() {}
2757 /// \brief Creates clause with a list of variables \a VL.
2759 /// \param C AST context.
2760 /// \param StartLoc Starting location of the clause.
2761 /// \param EndLoc Ending location of the clause.
2762 /// \param VL List of references to the variables.
2763 /// \param TypeModifier Map type modifier.
2764 /// \param Type Map type.
2765 /// \param TypeLoc Location of the map type.
2767 static OMPMapClause *Create(const ASTContext &C, SourceLocation StartLoc,
2768 SourceLocation LParenLoc,
2769 SourceLocation EndLoc, ArrayRef<Expr *> VL,
2770 OpenMPMapClauseKind TypeModifier,
2771 OpenMPMapClauseKind Type, SourceLocation TypeLoc);
2772 /// \brief Creates an empty clause with the place for \a N variables.
2774 /// \param C AST context.
2775 /// \param N The number of variables.
2777 static OMPMapClause *CreateEmpty(const ASTContext &C, unsigned N);
2779 /// \brief Fetches mapping kind for the clause.
2780 OpenMPMapClauseKind getMapType() const LLVM_READONLY { return MapType; }
2782 /// \brief Fetches the map type modifier for the clause.
2783 OpenMPMapClauseKind getMapTypeModifier() const LLVM_READONLY {
2784 return MapTypeModifier;
2787 /// \brief Fetches location of clause mapping kind.
2788 SourceLocation getMapLoc() const LLVM_READONLY { return MapLoc; }
2790 /// \brief Get colon location.
2791 SourceLocation getColonLoc() const { return ColonLoc; }
2793 static bool classof(const OMPClause *T) {
2794 return T->getClauseKind() == OMPC_map;
2797 child_range children() {
2799 reinterpret_cast<Stmt **>(varlist_begin()),
2800 reinterpret_cast<Stmt **>(varlist_end()));
2804 /// \brief This represents 'num_teams' clause in the '#pragma omp ...'
2808 /// #pragma omp teams num_teams(n)
2810 /// In this example directive '#pragma omp teams' has clause 'num_teams'
2811 /// with single expression 'n'.
2813 class OMPNumTeamsClause : public OMPClause {
2814 friend class OMPClauseReader;
2815 /// \brief Location of '('.
2816 SourceLocation LParenLoc;
2817 /// \brief NumTeams number.
2819 /// \brief Set the NumTeams number.
2821 /// \param E NumTeams number.
2823 void setNumTeams(Expr *E) { NumTeams = E; }
2826 /// \brief Build 'num_teams' clause.
2828 /// \param E Expression associated with this clause.
2829 /// \param StartLoc Starting location of the clause.
2830 /// \param LParenLoc Location of '('.
2831 /// \param EndLoc Ending location of the clause.
2833 OMPNumTeamsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2834 SourceLocation EndLoc)
2835 : OMPClause(OMPC_num_teams, StartLoc, EndLoc), LParenLoc(LParenLoc),
2838 /// \brief Build an empty clause.
2841 : OMPClause(OMPC_num_teams, SourceLocation(), SourceLocation()),
2842 LParenLoc(SourceLocation()), NumTeams(nullptr) {}
2843 /// \brief Sets the location of '('.
2844 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2845 /// \brief Returns the location of '('.
2846 SourceLocation getLParenLoc() const { return LParenLoc; }
2847 /// \brief Return NumTeams number.
2848 Expr *getNumTeams() { return cast<Expr>(NumTeams); }
2849 /// \brief Return NumTeams number.
2850 Expr *getNumTeams() const { return cast<Expr>(NumTeams); }
2852 static bool classof(const OMPClause *T) {
2853 return T->getClauseKind() == OMPC_num_teams;
2856 child_range children() { return child_range(&NumTeams, &NumTeams + 1); }
2859 /// \brief This represents 'thread_limit' clause in the '#pragma omp ...'
2863 /// #pragma omp teams thread_limit(n)
2865 /// In this example directive '#pragma omp teams' has clause 'thread_limit'
2866 /// with single expression 'n'.
2868 class OMPThreadLimitClause : public OMPClause {
2869 friend class OMPClauseReader;
2870 /// \brief Location of '('.
2871 SourceLocation LParenLoc;
2872 /// \brief ThreadLimit number.
2874 /// \brief Set the ThreadLimit number.
2876 /// \param E ThreadLimit number.
2878 void setThreadLimit(Expr *E) { ThreadLimit = E; }
2881 /// \brief Build 'thread_limit' clause.
2883 /// \param E Expression associated with this clause.
2884 /// \param StartLoc Starting location of the clause.
2885 /// \param LParenLoc Location of '('.
2886 /// \param EndLoc Ending location of the clause.
2888 OMPThreadLimitClause(Expr *E, SourceLocation StartLoc,
2889 SourceLocation LParenLoc, SourceLocation EndLoc)
2890 : OMPClause(OMPC_thread_limit, StartLoc, EndLoc), LParenLoc(LParenLoc),
2893 /// \brief Build an empty clause.
2895 OMPThreadLimitClause()
2896 : OMPClause(OMPC_thread_limit, SourceLocation(), SourceLocation()),
2897 LParenLoc(SourceLocation()), ThreadLimit(nullptr) {}
2898 /// \brief Sets the location of '('.
2899 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2900 /// \brief Returns the location of '('.
2901 SourceLocation getLParenLoc() const { return LParenLoc; }
2902 /// \brief Return ThreadLimit number.
2903 Expr *getThreadLimit() { return cast<Expr>(ThreadLimit); }
2904 /// \brief Return ThreadLimit number.
2905 Expr *getThreadLimit() const { return cast<Expr>(ThreadLimit); }
2907 static bool classof(const OMPClause *T) {
2908 return T->getClauseKind() == OMPC_thread_limit;
2911 child_range children() { return child_range(&ThreadLimit, &ThreadLimit + 1); }
2914 /// \brief This represents 'priority' clause in the '#pragma omp ...'
2918 /// #pragma omp task priority(n)
2920 /// In this example directive '#pragma omp teams' has clause 'priority' with
2921 /// single expression 'n'.
2923 class OMPPriorityClause : public OMPClause {
2924 friend class OMPClauseReader;
2925 /// \brief Location of '('.
2926 SourceLocation LParenLoc;
2927 /// \brief Priority number.
2929 /// \brief Set the Priority number.
2931 /// \param E Priority number.
2933 void setPriority(Expr *E) { Priority = E; }
2936 /// \brief Build 'priority' clause.
2938 /// \param E Expression associated with this clause.
2939 /// \param StartLoc Starting location of the clause.
2940 /// \param LParenLoc Location of '('.
2941 /// \param EndLoc Ending location of the clause.
2943 OMPPriorityClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc,
2944 SourceLocation EndLoc)
2945 : OMPClause(OMPC_priority, StartLoc, EndLoc), LParenLoc(LParenLoc),
2948 /// \brief Build an empty clause.
2951 : OMPClause(OMPC_priority, SourceLocation(), SourceLocation()),
2952 LParenLoc(SourceLocation()), Priority(nullptr) {}
2953 /// \brief Sets the location of '('.
2954 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
2955 /// \brief Returns the location of '('.
2956 SourceLocation getLParenLoc() const { return LParenLoc; }
2957 /// \brief Return Priority number.
2958 Expr *getPriority() { return cast<Expr>(Priority); }
2959 /// \brief Return Priority number.
2960 Expr *getPriority() const { return cast<Expr>(Priority); }
2962 static bool classof(const OMPClause *T) {
2963 return T->getClauseKind() == OMPC_priority;
2966 child_range children() { return child_range(&Priority, &Priority + 1); }
2969 /// \brief This represents 'grainsize' clause in the '#pragma omp ...'
2973 /// #pragma omp taskloop grainsize(4)
2975 /// In this example directive '#pragma omp taskloop' has clause 'grainsize'
2976 /// with single expression '4'.
2978 class OMPGrainsizeClause : public OMPClause {
2979 friend class OMPClauseReader;
2980 /// \brief Location of '('.
2981 SourceLocation LParenLoc;
2982 /// \brief Safe iteration space distance.
2985 /// \brief Set safelen.
2986 void setGrainsize(Expr *Size) { Grainsize = Size; }
2989 /// \brief Build 'grainsize' clause.
2991 /// \param Size Expression associated with this clause.
2992 /// \param StartLoc Starting location of the clause.
2993 /// \param EndLoc Ending location of the clause.
2995 OMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
2996 SourceLocation LParenLoc, SourceLocation EndLoc)
2997 : OMPClause(OMPC_grainsize, StartLoc, EndLoc), LParenLoc(LParenLoc),
3000 /// \brief Build an empty clause.
3002 explicit OMPGrainsizeClause()
3003 : OMPClause(OMPC_grainsize, SourceLocation(), SourceLocation()),
3004 LParenLoc(SourceLocation()), Grainsize(nullptr) {}
3006 /// \brief Sets the location of '('.
3007 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3008 /// \brief Returns the location of '('.
3009 SourceLocation getLParenLoc() const { return LParenLoc; }
3011 /// \brief Return safe iteration space distance.
3012 Expr *getGrainsize() const { return cast_or_null<Expr>(Grainsize); }
3014 static bool classof(const OMPClause *T) {
3015 return T->getClauseKind() == OMPC_grainsize;
3018 child_range children() { return child_range(&Grainsize, &Grainsize + 1); }
3021 /// \brief This represents 'nogroup' clause in the '#pragma omp ...' directive.
3024 /// #pragma omp taskloop nogroup
3026 /// In this example directive '#pragma omp taskloop' has 'nogroup' clause.
3028 class OMPNogroupClause : public OMPClause {
3030 /// \brief Build 'nogroup' clause.
3032 /// \param StartLoc Starting location of the clause.
3033 /// \param EndLoc Ending location of the clause.
3035 OMPNogroupClause(SourceLocation StartLoc, SourceLocation EndLoc)
3036 : OMPClause(OMPC_nogroup, StartLoc, EndLoc) {}
3038 /// \brief Build an empty clause.
3041 : OMPClause(OMPC_nogroup, SourceLocation(), SourceLocation()) {}
3043 static bool classof(const OMPClause *T) {
3044 return T->getClauseKind() == OMPC_nogroup;
3047 child_range children() {
3048 return child_range(child_iterator(), child_iterator());
3052 /// \brief This represents 'num_tasks' clause in the '#pragma omp ...'
3056 /// #pragma omp taskloop num_tasks(4)
3058 /// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
3059 /// with single expression '4'.
3061 class OMPNumTasksClause : public OMPClause {
3062 friend class OMPClauseReader;
3063 /// \brief Location of '('.
3064 SourceLocation LParenLoc;
3065 /// \brief Safe iteration space distance.
3068 /// \brief Set safelen.
3069 void setNumTasks(Expr *Size) { NumTasks = Size; }
3072 /// \brief Build 'num_tasks' clause.
3074 /// \param Size Expression associated with this clause.
3075 /// \param StartLoc Starting location of the clause.
3076 /// \param EndLoc Ending location of the clause.
3078 OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
3079 SourceLocation LParenLoc, SourceLocation EndLoc)
3080 : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
3083 /// \brief Build an empty clause.
3085 explicit OMPNumTasksClause()
3086 : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()),
3087 LParenLoc(SourceLocation()), NumTasks(nullptr) {}
3089 /// \brief Sets the location of '('.
3090 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3091 /// \brief Returns the location of '('.
3092 SourceLocation getLParenLoc() const { return LParenLoc; }
3094 /// \brief Return safe iteration space distance.
3095 Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
3097 static bool classof(const OMPClause *T) {
3098 return T->getClauseKind() == OMPC_num_tasks;
3101 child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
3104 /// \brief This represents 'hint' clause in the '#pragma omp ...' directive.
3107 /// #pragma omp critical (name) hint(6)
3109 /// In this example directive '#pragma omp critical' has name 'name' and clause
3110 /// 'hint' with argument '6'.
3112 class OMPHintClause : public OMPClause {
3113 friend class OMPClauseReader;
3114 /// \brief Location of '('.
3115 SourceLocation LParenLoc;
3116 /// \brief Hint expression of the 'hint' clause.
3119 /// \brief Set hint expression.
3121 void setHint(Expr *H) { Hint = H; }
3124 /// \brief Build 'hint' clause with expression \a Hint.
3126 /// \param Hint Hint expression.
3127 /// \param StartLoc Starting location of the clause.
3128 /// \param LParenLoc Location of '('.
3129 /// \param EndLoc Ending location of the clause.
3131 OMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc,
3132 SourceLocation EndLoc)
3133 : OMPClause(OMPC_hint, StartLoc, EndLoc), LParenLoc(LParenLoc),
3136 /// \brief Build an empty clause.
3139 : OMPClause(OMPC_hint, SourceLocation(), SourceLocation()),
3140 LParenLoc(SourceLocation()), Hint(nullptr) {}
3142 /// \brief Sets the location of '('.
3143 void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
3144 /// \brief Returns the location of '('.
3145 SourceLocation getLParenLoc() const { return LParenLoc; }
3147 /// \brief Returns number of threads.
3148 Expr *getHint() const { return cast_or_null<Expr>(Hint); }
3150 static bool classof(const OMPClause *T) {
3151 return T->getClauseKind() == OMPC_hint;
3154 child_range children() { return child_range(&Hint, &Hint + 1); }
3157 } // end namespace clang
3159 #endif // LLVM_CLANG_AST_OPENMPCLAUSE_H