1 //===- StmtOpenMP.h - Classes for OpenMP directives ------------*- 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 executable directives and
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_STMTOPENMP_H
16 #define LLVM_CLANG_AST_STMTOPENMP_H
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/OpenMPClause.h"
20 #include "clang/AST/Stmt.h"
21 #include "clang/Basic/OpenMPKinds.h"
22 #include "clang/Basic/SourceLocation.h"
26 //===----------------------------------------------------------------------===//
27 // AST classes for directives.
28 //===----------------------------------------------------------------------===//
30 /// \brief This is a basic class for representing single OpenMP executable
33 class OMPExecutableDirective : public Stmt {
34 friend class ASTStmtReader;
35 /// \brief Kind of the directive.
36 OpenMPDirectiveKind Kind;
37 /// \brief Starting location of the directive (directive keyword).
38 SourceLocation StartLoc;
39 /// \brief Ending location of the directive.
40 SourceLocation EndLoc;
41 /// \brief Numbers of clauses.
42 const unsigned NumClauses;
43 /// \brief Number of child expressions/stmts.
44 const unsigned NumChildren;
45 /// \brief Offset from this to the start of clauses.
46 /// There are NumClauses pointers to clauses, they are followed by
47 /// NumChildren pointers to child stmts/exprs (if the directive type
48 /// requires an associated stmt, then it has to be the first of them).
49 const unsigned ClausesOffset;
51 /// \brief Get the clauses storage.
52 MutableArrayRef<OMPClause *> getClauses() {
53 OMPClause **ClauseStorage = reinterpret_cast<OMPClause **>(
54 reinterpret_cast<char *>(this) + ClausesOffset);
55 return MutableArrayRef<OMPClause *>(ClauseStorage, NumClauses);
59 /// \brief Build instance of directive of class \a K.
61 /// \param SC Statement class.
62 /// \param K Kind of OpenMP directive.
63 /// \param StartLoc Starting location of the directive (directive keyword).
64 /// \param EndLoc Ending location of the directive.
67 OMPExecutableDirective(const T *, StmtClass SC, OpenMPDirectiveKind K,
68 SourceLocation StartLoc, SourceLocation EndLoc,
69 unsigned NumClauses, unsigned NumChildren)
70 : Stmt(SC), Kind(K), StartLoc(std::move(StartLoc)),
71 EndLoc(std::move(EndLoc)), NumClauses(NumClauses),
72 NumChildren(NumChildren),
73 ClausesOffset(llvm::RoundUpToAlignment(sizeof(T),
74 llvm::alignOf<OMPClause *>())) {}
76 /// \brief Sets the list of variables for this clause.
78 /// \param Clauses The list of clauses for the directive.
80 void setClauses(ArrayRef<OMPClause *> Clauses);
82 /// \brief Set the associated statement for the directive.
84 /// /param S Associated statement.
86 void setAssociatedStmt(Stmt *S) {
87 assert(hasAssociatedStmt() && "no associated statement.");
92 /// \brief Iterates over a filtered subrange of clauses applied to a
95 /// This iterator visits only those declarations that meet some run-time
97 template <class FilterPredicate> class filtered_clause_iterator {
98 ArrayRef<OMPClause *>::const_iterator Current;
99 ArrayRef<OMPClause *>::const_iterator End;
100 FilterPredicate Pred;
101 void SkipToNextClause() {
102 while (Current != End && !Pred(*Current))
107 typedef const OMPClause *value_type;
108 filtered_clause_iterator() : Current(), End() {}
109 filtered_clause_iterator(ArrayRef<OMPClause *> Arr, FilterPredicate Pred)
110 : Current(Arr.begin()), End(Arr.end()), Pred(Pred) {
113 value_type operator*() const { return *Current; }
114 value_type operator->() const { return *Current; }
115 filtered_clause_iterator &operator++() {
121 filtered_clause_iterator operator++(int) {
122 filtered_clause_iterator tmp(*this);
127 bool operator!() { return Current == End; }
128 operator bool() { return Current != End; }
131 /// \brief Gets a single clause of the specified kind \a K associated with the
132 /// current directive iff there is only one clause of this kind (and assertion
133 /// is fired if there is more than one clause is associated with the
134 /// directive). Returns nullptr if no clause of kind \a K is associated with
136 const OMPClause *getSingleClause(OpenMPClauseKind K) const;
138 /// \brief Returns starting location of directive kind.
139 SourceLocation getLocStart() const { return StartLoc; }
140 /// \brief Returns ending location of directive.
141 SourceLocation getLocEnd() const { return EndLoc; }
143 /// \brief Set starting location of directive kind.
145 /// \param Loc New starting location of directive.
147 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
148 /// \brief Set ending location of directive.
150 /// \param Loc New ending location of directive.
152 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
154 /// \brief Get number of clauses.
155 unsigned getNumClauses() const { return NumClauses; }
157 /// \brief Returns specified clause.
159 /// \param i Number of clause.
161 OMPClause *getClause(unsigned i) const { return clauses()[i]; }
163 /// \brief Returns true if directive has associated statement.
164 bool hasAssociatedStmt() const { return NumChildren > 0; }
166 /// \brief Returns statement associated with the directive.
167 Stmt *getAssociatedStmt() const {
168 assert(hasAssociatedStmt() && "no associated statement.");
169 return const_cast<Stmt *>(*child_begin());
172 OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
174 static bool classof(const Stmt *S) {
175 return S->getStmtClass() >= firstOMPExecutableDirectiveConstant &&
176 S->getStmtClass() <= lastOMPExecutableDirectiveConstant;
179 child_range children() {
180 if (!hasAssociatedStmt())
181 return child_range();
182 Stmt **ChildStorage = reinterpret_cast<Stmt **>(getClauses().end());
183 return child_range(ChildStorage, ChildStorage + NumChildren);
186 ArrayRef<OMPClause *> clauses() { return getClauses(); }
188 ArrayRef<OMPClause *> clauses() const {
189 return const_cast<OMPExecutableDirective *>(this)->getClauses();
193 /// \brief This represents '#pragma omp parallel' directive.
196 /// #pragma omp parallel private(a,b) reduction(+: c,d)
198 /// In this example directive '#pragma omp parallel' has clauses 'private'
199 /// with the variables 'a' and 'b' and 'reduction' with operator '+' and
200 /// variables 'c' and 'd'.
202 class OMPParallelDirective : public OMPExecutableDirective {
203 /// \brief Build directive with the given start and end location.
205 /// \param StartLoc Starting location of the directive (directive keyword).
206 /// \param EndLoc Ending Location of the directive.
208 OMPParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc,
210 : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
211 StartLoc, EndLoc, NumClauses, 1) {}
213 /// \brief Build an empty directive.
215 /// \param NumClauses Number of clauses.
217 explicit OMPParallelDirective(unsigned NumClauses)
218 : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
219 SourceLocation(), SourceLocation(), NumClauses,
223 /// \brief Creates directive with a list of \a Clauses.
225 /// \param C AST context.
226 /// \param StartLoc Starting location of the directive kind.
227 /// \param EndLoc Ending Location of the directive.
228 /// \param Clauses List of clauses.
229 /// \param AssociatedStmt Statement associated with the directive.
231 static OMPParallelDirective *
232 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
233 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
235 /// \brief Creates an empty directive with the place for \a N clauses.
237 /// \param C AST context.
238 /// \param NumClauses Number of clauses.
240 static OMPParallelDirective *CreateEmpty(const ASTContext &C,
241 unsigned NumClauses, EmptyShell);
243 static bool classof(const Stmt *T) {
244 return T->getStmtClass() == OMPParallelDirectiveClass;
248 /// \brief This is a common base class for loop directives ('omp simd', 'omp
249 /// for', 'omp for simd' etc.). It is responsible for the loop code generation.
251 class OMPLoopDirective : public OMPExecutableDirective {
252 friend class ASTStmtReader;
253 /// \brief Number of collapsed loops as specified by 'collapse' clause.
254 unsigned CollapsedNum;
256 /// \brief Offsets to the stored exprs.
257 /// This enumeration contains offsets to all the pointers to children
258 /// expressions stored in OMPLoopDirective.
259 /// The first 9 children are nesessary for all the loop directives, and
260 /// the next 7 are specific to the worksharing ones.
261 /// After the fixed children, three arrays of length CollapsedNum are
262 /// allocated: loop counters, their updates and final values.
265 AssociatedStmtOffset = 0,
266 IterationVariableOffset = 1,
267 LastIterationOffset = 2,
268 CalcLastIterationOffset = 3,
269 PreConditionOffset = 4,
271 SeparatedCondOffset = 6,
274 // The '...End' enumerators do not correspond to child expressions - they
275 // specify the offset to the end (and start of the following counters/
276 // updates/finals arrays).
278 // The following 7 exprs are used by worksharing loops only.
279 IsLastIterVariableOffset = 9,
280 LowerBoundVariableOffset = 10,
281 UpperBoundVariableOffset = 11,
282 StrideVariableOffset = 12,
283 EnsureUpperBoundOffset = 13,
284 NextLowerBoundOffset = 14,
285 NextUpperBoundOffset = 15,
286 // Offset to the end (and start of the following counters/updates/finals
287 // arrays) for worksharing loop directives.
291 /// \brief Get the counters storage.
292 MutableArrayRef<Expr *> getCounters() {
293 Expr **Storage = reinterpret_cast<Expr **>(
294 &(*(std::next(child_begin(), getArraysOffset(getDirectiveKind())))));
295 return MutableArrayRef<Expr *>(Storage, CollapsedNum);
298 /// \brief Get the updates storage.
299 MutableArrayRef<Expr *> getUpdates() {
300 Expr **Storage = reinterpret_cast<Expr **>(
301 &*std::next(child_begin(),
302 getArraysOffset(getDirectiveKind()) + CollapsedNum));
303 return MutableArrayRef<Expr *>(Storage, CollapsedNum);
306 /// \brief Get the final counter updates storage.
307 MutableArrayRef<Expr *> getFinals() {
308 Expr **Storage = reinterpret_cast<Expr **>(
309 &*std::next(child_begin(),
310 getArraysOffset(getDirectiveKind()) + 2 * CollapsedNum));
311 return MutableArrayRef<Expr *>(Storage, CollapsedNum);
315 /// \brief Build instance of loop directive of class \a Kind.
317 /// \param SC Statement class.
318 /// \param Kind Kind of OpenMP directive.
319 /// \param StartLoc Starting location of the directive (directive keyword).
320 /// \param EndLoc Ending location of the directive.
321 /// \param CollapsedNum Number of collapsed loops from 'collapse' clause.
322 /// \param NumClauses Number of clauses.
323 /// \param NumSpecialChildren Number of additional directive-specific stmts.
325 template <typename T>
326 OMPLoopDirective(const T *That, StmtClass SC, OpenMPDirectiveKind Kind,
327 SourceLocation StartLoc, SourceLocation EndLoc,
328 unsigned CollapsedNum, unsigned NumClauses,
329 unsigned NumSpecialChildren = 0)
330 : OMPExecutableDirective(That, SC, Kind, StartLoc, EndLoc, NumClauses,
331 numLoopChildren(CollapsedNum, Kind) +
333 CollapsedNum(CollapsedNum) {}
335 /// \brief Offset to the start of children expression arrays.
336 static unsigned getArraysOffset(OpenMPDirectiveKind Kind) {
337 return isOpenMPWorksharingDirective(Kind) ? WorksharingEnd
341 /// \brief Children number.
342 static unsigned numLoopChildren(unsigned CollapsedNum,
343 OpenMPDirectiveKind Kind) {
344 return getArraysOffset(Kind) +
345 3 * CollapsedNum; // Counters, Updates and Finals
348 void setIterationVariable(Expr *IV) {
349 *std::next(child_begin(), IterationVariableOffset) = IV;
351 void setLastIteration(Expr *LI) {
352 *std::next(child_begin(), LastIterationOffset) = LI;
354 void setCalcLastIteration(Expr *CLI) {
355 *std::next(child_begin(), CalcLastIterationOffset) = CLI;
357 void setPreCond(Expr *PC) {
358 *std::next(child_begin(), PreConditionOffset) = PC;
360 void setCond(Expr *Cond, Expr *SeparatedCond) {
361 *std::next(child_begin(), CondOffset) = Cond;
362 *std::next(child_begin(), SeparatedCondOffset) = SeparatedCond;
364 void setInit(Expr *Init) { *std::next(child_begin(), InitOffset) = Init; }
365 void setInc(Expr *Inc) { *std::next(child_begin(), IncOffset) = Inc; }
366 void setIsLastIterVariable(Expr *IL) {
367 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
368 "expected worksharing loop directive");
369 *std::next(child_begin(), IsLastIterVariableOffset) = IL;
371 void setLowerBoundVariable(Expr *LB) {
372 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
373 "expected worksharing loop directive");
374 *std::next(child_begin(), LowerBoundVariableOffset) = LB;
376 void setUpperBoundVariable(Expr *UB) {
377 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
378 "expected worksharing loop directive");
379 *std::next(child_begin(), UpperBoundVariableOffset) = UB;
381 void setStrideVariable(Expr *ST) {
382 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
383 "expected worksharing loop directive");
384 *std::next(child_begin(), StrideVariableOffset) = ST;
386 void setEnsureUpperBound(Expr *EUB) {
387 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
388 "expected worksharing loop directive");
389 *std::next(child_begin(), EnsureUpperBoundOffset) = EUB;
391 void setNextLowerBound(Expr *NLB) {
392 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
393 "expected worksharing loop directive");
394 *std::next(child_begin(), NextLowerBoundOffset) = NLB;
396 void setNextUpperBound(Expr *NUB) {
397 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
398 "expected worksharing loop directive");
399 *std::next(child_begin(), NextUpperBoundOffset) = NUB;
401 void setCounters(ArrayRef<Expr *> A);
402 void setUpdates(ArrayRef<Expr *> A);
403 void setFinals(ArrayRef<Expr *> A);
406 /// \brief The expressions built for the OpenMP loop CodeGen for the
407 /// whole collapsed loop nest.
409 /// \brief Loop iteration variable.
410 Expr *IterationVarRef;
411 /// \brief Loop last iteration number.
413 /// \brief Calculation of last iteration.
414 Expr *CalcLastIteration;
415 /// \brief Loop pre-condition.
417 /// \brief Loop condition.
419 /// \brief A condition with 1 iteration separated.
421 /// \brief Loop iteration variable init.
423 /// \brief Loop increment.
425 /// \brief IsLastIteration - local flag variable passed to runtime.
427 /// \brief LowerBound - local variable passed to runtime.
429 /// \brief UpperBound - local variable passed to runtime.
431 /// \brief Stride - local variable passed to runtime.
433 /// \brief EnsureUpperBound -- expression LB = min(LB, NumIterations).
435 /// \brief Update of LowerBound for statically sheduled 'omp for' loops.
437 /// \brief Update of UpperBound for statically sheduled 'omp for' loops.
439 /// \brief Counters Loop counters.
440 SmallVector<Expr *, 4> Counters;
441 /// \brief Expressions for loop counters update for CodeGen.
442 SmallVector<Expr *, 4> Updates;
443 /// \brief Final loop counter values for GodeGen.
444 SmallVector<Expr *, 4> Finals;
446 /// \brief Check if all the expressions are built (does not check the
447 /// worksharing ones).
449 return IterationVarRef != nullptr && LastIteration != nullptr &&
450 PreCond != nullptr && Cond != nullptr &&
451 SeparatedCond != nullptr && Init != nullptr && Inc != nullptr;
454 /// \brief Initialize all the fields to null.
455 /// \param Size Number of elements in the counters/finals/updates arrays.
456 void clear(unsigned Size) {
457 IterationVarRef = nullptr;
458 LastIteration = nullptr;
459 CalcLastIteration = nullptr;
462 SeparatedCond = nullptr;
472 Counters.resize(Size);
473 Updates.resize(Size);
475 for (unsigned i = 0; i < Size; ++i) {
476 Counters[i] = nullptr;
477 Updates[i] = nullptr;
483 /// \brief Get number of collapsed loops.
484 unsigned getCollapsedNumber() const { return CollapsedNum; }
486 Expr *getIterationVariable() const {
487 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
488 *std::next(child_begin(), IterationVariableOffset)));
490 Expr *getLastIteration() const {
491 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
492 *std::next(child_begin(), LastIterationOffset)));
494 Expr *getCalcLastIteration() const {
495 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
496 *std::next(child_begin(), CalcLastIterationOffset)));
498 Expr *getPreCond() const {
499 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
500 *std::next(child_begin(), PreConditionOffset)));
502 Expr *getCond(bool SeparateIter) const {
503 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
504 *std::next(child_begin(),
505 (SeparateIter ? SeparatedCondOffset : CondOffset))));
507 Expr *getInit() const {
508 return const_cast<Expr *>(
509 reinterpret_cast<const Expr *>(*std::next(child_begin(), InitOffset)));
511 Expr *getInc() const {
512 return const_cast<Expr *>(
513 reinterpret_cast<const Expr *>(*std::next(child_begin(), IncOffset)));
515 Expr *getIsLastIterVariable() const {
516 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
517 "expected worksharing loop directive");
518 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
519 *std::next(child_begin(), IsLastIterVariableOffset)));
521 Expr *getLowerBoundVariable() const {
522 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
523 "expected worksharing loop directive");
524 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
525 *std::next(child_begin(), LowerBoundVariableOffset)));
527 Expr *getUpperBoundVariable() const {
528 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
529 "expected worksharing loop directive");
530 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
531 *std::next(child_begin(), UpperBoundVariableOffset)));
533 Expr *getStrideVariable() const {
534 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
535 "expected worksharing loop directive");
536 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
537 *std::next(child_begin(), StrideVariableOffset)));
539 Expr *getEnsureUpperBound() const {
540 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
541 "expected worksharing loop directive");
542 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
543 *std::next(child_begin(), EnsureUpperBoundOffset)));
545 Expr *getNextLowerBound() const {
546 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
547 "expected worksharing loop directive");
548 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
549 *std::next(child_begin(), NextLowerBoundOffset)));
551 Expr *getNextUpperBound() const {
552 assert(isOpenMPWorksharingDirective(getDirectiveKind()) &&
553 "expected worksharing loop directive");
554 return const_cast<Expr *>(reinterpret_cast<const Expr *>(
555 *std::next(child_begin(), NextUpperBoundOffset)));
557 const Stmt *getBody() const {
558 // This relies on the loop form is already checked by Sema.
559 Stmt *Body = getAssociatedStmt()->IgnoreContainers(true);
560 Body = cast<ForStmt>(Body)->getBody();
561 for (unsigned Cnt = 1; Cnt < CollapsedNum; ++Cnt) {
562 Body = Body->IgnoreContainers();
563 Body = cast<ForStmt>(Body)->getBody();
568 ArrayRef<Expr *> counters() { return getCounters(); }
570 ArrayRef<Expr *> counters() const {
571 return const_cast<OMPLoopDirective *>(this)->getCounters();
574 ArrayRef<Expr *> updates() { return getUpdates(); }
576 ArrayRef<Expr *> updates() const {
577 return const_cast<OMPLoopDirective *>(this)->getUpdates();
580 ArrayRef<Expr *> finals() { return getFinals(); }
582 ArrayRef<Expr *> finals() const {
583 return const_cast<OMPLoopDirective *>(this)->getFinals();
586 static bool classof(const Stmt *T) {
587 return T->getStmtClass() == OMPSimdDirectiveClass ||
588 T->getStmtClass() == OMPForDirectiveClass ||
589 T->getStmtClass() == OMPForSimdDirectiveClass ||
590 T->getStmtClass() == OMPParallelForDirectiveClass ||
591 T->getStmtClass() == OMPParallelForSimdDirectiveClass;
595 /// \brief This represents '#pragma omp simd' directive.
598 /// #pragma omp simd private(a,b) linear(i,j:s) reduction(+:c,d)
600 /// In this example directive '#pragma omp simd' has clauses 'private'
601 /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and
602 /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'.
604 class OMPSimdDirective : public OMPLoopDirective {
605 friend class ASTStmtReader;
606 /// \brief Build directive with the given start and end location.
608 /// \param StartLoc Starting location of the directive kind.
609 /// \param EndLoc Ending location of the directive.
610 /// \param CollapsedNum Number of collapsed nested loops.
611 /// \param NumClauses Number of clauses.
613 OMPSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
614 unsigned CollapsedNum, unsigned NumClauses)
615 : OMPLoopDirective(this, OMPSimdDirectiveClass, OMPD_simd, StartLoc,
616 EndLoc, CollapsedNum, NumClauses) {}
618 /// \brief Build an empty directive.
620 /// \param CollapsedNum Number of collapsed nested loops.
621 /// \param NumClauses Number of clauses.
623 explicit OMPSimdDirective(unsigned CollapsedNum, unsigned NumClauses)
624 : OMPLoopDirective(this, OMPSimdDirectiveClass, OMPD_simd,
625 SourceLocation(), SourceLocation(), CollapsedNum,
629 /// \brief Creates directive with a list of \a Clauses.
631 /// \param C AST context.
632 /// \param StartLoc Starting location of the directive kind.
633 /// \param EndLoc Ending Location of the directive.
634 /// \param CollapsedNum Number of collapsed loops.
635 /// \param Clauses List of clauses.
636 /// \param AssociatedStmt Statement, associated with the directive.
637 /// \param Exprs Helper expressions for CodeGen.
639 static OMPSimdDirective *Create(const ASTContext &C, SourceLocation StartLoc,
640 SourceLocation EndLoc, unsigned CollapsedNum,
641 ArrayRef<OMPClause *> Clauses,
642 Stmt *AssociatedStmt,
643 const HelperExprs &Exprs);
645 /// \brief Creates an empty directive with the place
646 /// for \a NumClauses clauses.
648 /// \param C AST context.
649 /// \param CollapsedNum Number of collapsed nested loops.
650 /// \param NumClauses Number of clauses.
652 static OMPSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
653 unsigned CollapsedNum, EmptyShell);
655 static bool classof(const Stmt *T) {
656 return T->getStmtClass() == OMPSimdDirectiveClass;
660 /// \brief This represents '#pragma omp for' directive.
663 /// #pragma omp for private(a,b) reduction(+:c,d)
665 /// In this example directive '#pragma omp for' has clauses 'private' with the
666 /// variables 'a' and 'b' and 'reduction' with operator '+' and variables 'c'
669 class OMPForDirective : public OMPLoopDirective {
670 friend class ASTStmtReader;
671 /// \brief Build directive with the given start and end location.
673 /// \param StartLoc Starting location of the directive kind.
674 /// \param EndLoc Ending location of the directive.
675 /// \param CollapsedNum Number of collapsed nested loops.
676 /// \param NumClauses Number of clauses.
678 OMPForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
679 unsigned CollapsedNum, unsigned NumClauses)
680 : OMPLoopDirective(this, OMPForDirectiveClass, OMPD_for, StartLoc, EndLoc,
681 CollapsedNum, NumClauses) {}
683 /// \brief Build an empty directive.
685 /// \param CollapsedNum Number of collapsed nested loops.
686 /// \param NumClauses Number of clauses.
688 explicit OMPForDirective(unsigned CollapsedNum, unsigned NumClauses)
689 : OMPLoopDirective(this, OMPForDirectiveClass, OMPD_for, SourceLocation(),
690 SourceLocation(), CollapsedNum, NumClauses) {}
693 /// \brief Creates directive with a list of \a Clauses.
695 /// \param C AST context.
696 /// \param StartLoc Starting location of the directive kind.
697 /// \param EndLoc Ending Location of the directive.
698 /// \param CollapsedNum Number of collapsed loops.
699 /// \param Clauses List of clauses.
700 /// \param AssociatedStmt Statement, associated with the directive.
701 /// \param Exprs Helper expressions for CodeGen.
703 static OMPForDirective *Create(const ASTContext &C, SourceLocation StartLoc,
704 SourceLocation EndLoc, unsigned CollapsedNum,
705 ArrayRef<OMPClause *> Clauses,
706 Stmt *AssociatedStmt,
707 const HelperExprs &Exprs);
709 /// \brief Creates an empty directive with the place
710 /// for \a NumClauses clauses.
712 /// \param C AST context.
713 /// \param CollapsedNum Number of collapsed nested loops.
714 /// \param NumClauses Number of clauses.
716 static OMPForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
717 unsigned CollapsedNum, EmptyShell);
719 static bool classof(const Stmt *T) {
720 return T->getStmtClass() == OMPForDirectiveClass;
724 /// \brief This represents '#pragma omp for simd' directive.
727 /// #pragma omp for simd private(a,b) linear(i,j:s) reduction(+:c,d)
729 /// In this example directive '#pragma omp for simd' has clauses 'private'
730 /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and
731 /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'.
733 class OMPForSimdDirective : public OMPLoopDirective {
734 friend class ASTStmtReader;
735 /// \brief Build directive with the given start and end location.
737 /// \param StartLoc Starting location of the directive kind.
738 /// \param EndLoc Ending location of the directive.
739 /// \param CollapsedNum Number of collapsed nested loops.
740 /// \param NumClauses Number of clauses.
742 OMPForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
743 unsigned CollapsedNum, unsigned NumClauses)
744 : OMPLoopDirective(this, OMPForSimdDirectiveClass, OMPD_for_simd,
745 StartLoc, EndLoc, CollapsedNum, NumClauses) {}
747 /// \brief Build an empty directive.
749 /// \param CollapsedNum Number of collapsed nested loops.
750 /// \param NumClauses Number of clauses.
752 explicit OMPForSimdDirective(unsigned CollapsedNum, unsigned NumClauses)
753 : OMPLoopDirective(this, OMPForSimdDirectiveClass, OMPD_for_simd,
754 SourceLocation(), SourceLocation(), CollapsedNum,
758 /// \brief Creates directive with a list of \a Clauses.
760 /// \param C AST context.
761 /// \param StartLoc Starting location of the directive kind.
762 /// \param EndLoc Ending Location of the directive.
763 /// \param CollapsedNum Number of collapsed loops.
764 /// \param Clauses List of clauses.
765 /// \param AssociatedStmt Statement, associated with the directive.
766 /// \param Exprs Helper expressions for CodeGen.
768 static OMPForSimdDirective *
769 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
770 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
771 Stmt *AssociatedStmt, const HelperExprs &Exprs);
773 /// \brief Creates an empty directive with the place
774 /// for \a NumClauses clauses.
776 /// \param C AST context.
777 /// \param CollapsedNum Number of collapsed nested loops.
778 /// \param NumClauses Number of clauses.
780 static OMPForSimdDirective *CreateEmpty(const ASTContext &C,
782 unsigned CollapsedNum, EmptyShell);
784 static bool classof(const Stmt *T) {
785 return T->getStmtClass() == OMPForSimdDirectiveClass;
789 /// \brief This represents '#pragma omp sections' directive.
792 /// #pragma omp sections private(a,b) reduction(+:c,d)
794 /// In this example directive '#pragma omp sections' has clauses 'private' with
795 /// the variables 'a' and 'b' and 'reduction' with operator '+' and variables
798 class OMPSectionsDirective : public OMPExecutableDirective {
799 friend class ASTStmtReader;
800 /// \brief Build directive with the given start and end location.
802 /// \param StartLoc Starting location of the directive kind.
803 /// \param EndLoc Ending location of the directive.
804 /// \param NumClauses Number of clauses.
806 OMPSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc,
808 : OMPExecutableDirective(this, OMPSectionsDirectiveClass, OMPD_sections,
809 StartLoc, EndLoc, NumClauses, 1) {}
811 /// \brief Build an empty directive.
813 /// \param NumClauses Number of clauses.
815 explicit OMPSectionsDirective(unsigned NumClauses)
816 : OMPExecutableDirective(this, OMPSectionsDirectiveClass, OMPD_sections,
817 SourceLocation(), SourceLocation(), NumClauses,
821 /// \brief Creates directive with a list of \a Clauses.
823 /// \param C AST context.
824 /// \param StartLoc Starting location of the directive kind.
825 /// \param EndLoc Ending Location of the directive.
826 /// \param Clauses List of clauses.
827 /// \param AssociatedStmt Statement, associated with the directive.
829 static OMPSectionsDirective *
830 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
831 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
833 /// \brief Creates an empty directive with the place for \a NumClauses
836 /// \param C AST context.
837 /// \param NumClauses Number of clauses.
839 static OMPSectionsDirective *CreateEmpty(const ASTContext &C,
840 unsigned NumClauses, EmptyShell);
842 static bool classof(const Stmt *T) {
843 return T->getStmtClass() == OMPSectionsDirectiveClass;
847 /// \brief This represents '#pragma omp section' directive.
850 /// #pragma omp section
853 class OMPSectionDirective : public OMPExecutableDirective {
854 friend class ASTStmtReader;
855 /// \brief Build directive with the given start and end location.
857 /// \param StartLoc Starting location of the directive kind.
858 /// \param EndLoc Ending location of the directive.
860 OMPSectionDirective(SourceLocation StartLoc, SourceLocation EndLoc)
861 : OMPExecutableDirective(this, OMPSectionDirectiveClass, OMPD_section,
862 StartLoc, EndLoc, 0, 1) {}
864 /// \brief Build an empty directive.
866 explicit OMPSectionDirective()
867 : OMPExecutableDirective(this, OMPSectionDirectiveClass, OMPD_section,
868 SourceLocation(), SourceLocation(), 0, 1) {}
871 /// \brief Creates directive.
873 /// \param C AST context.
874 /// \param StartLoc Starting location of the directive kind.
875 /// \param EndLoc Ending Location of the directive.
876 /// \param AssociatedStmt Statement, associated with the directive.
878 static OMPSectionDirective *Create(const ASTContext &C,
879 SourceLocation StartLoc,
880 SourceLocation EndLoc,
881 Stmt *AssociatedStmt);
883 /// \brief Creates an empty directive.
885 /// \param C AST context.
887 static OMPSectionDirective *CreateEmpty(const ASTContext &C, EmptyShell);
889 static bool classof(const Stmt *T) {
890 return T->getStmtClass() == OMPSectionDirectiveClass;
894 /// \brief This represents '#pragma omp single' directive.
897 /// #pragma omp single private(a,b) copyprivate(c,d)
899 /// In this example directive '#pragma omp single' has clauses 'private' with
900 /// the variables 'a' and 'b' and 'copyprivate' with variables 'c' and 'd'.
902 class OMPSingleDirective : public OMPExecutableDirective {
903 friend class ASTStmtReader;
904 /// \brief Build directive with the given start and end location.
906 /// \param StartLoc Starting location of the directive kind.
907 /// \param EndLoc Ending location of the directive.
908 /// \param NumClauses Number of clauses.
910 OMPSingleDirective(SourceLocation StartLoc, SourceLocation EndLoc,
912 : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single,
913 StartLoc, EndLoc, NumClauses, 1) {}
915 /// \brief Build an empty directive.
917 /// \param NumClauses Number of clauses.
919 explicit OMPSingleDirective(unsigned NumClauses)
920 : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single,
921 SourceLocation(), SourceLocation(), NumClauses,
925 /// \brief Creates directive with a list of \a Clauses.
927 /// \param C AST context.
928 /// \param StartLoc Starting location of the directive kind.
929 /// \param EndLoc Ending Location of the directive.
930 /// \param Clauses List of clauses.
931 /// \param AssociatedStmt Statement, associated with the directive.
933 static OMPSingleDirective *
934 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
935 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
937 /// \brief Creates an empty directive with the place for \a NumClauses
940 /// \param C AST context.
941 /// \param NumClauses Number of clauses.
943 static OMPSingleDirective *CreateEmpty(const ASTContext &C,
944 unsigned NumClauses, EmptyShell);
946 static bool classof(const Stmt *T) {
947 return T->getStmtClass() == OMPSingleDirectiveClass;
951 /// \brief This represents '#pragma omp master' directive.
954 /// #pragma omp master
957 class OMPMasterDirective : public OMPExecutableDirective {
958 friend class ASTStmtReader;
959 /// \brief Build directive with the given start and end location.
961 /// \param StartLoc Starting location of the directive kind.
962 /// \param EndLoc Ending location of the directive.
964 OMPMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc)
965 : OMPExecutableDirective(this, OMPMasterDirectiveClass, OMPD_master,
966 StartLoc, EndLoc, 0, 1) {}
968 /// \brief Build an empty directive.
970 explicit OMPMasterDirective()
971 : OMPExecutableDirective(this, OMPMasterDirectiveClass, OMPD_master,
972 SourceLocation(), SourceLocation(), 0, 1) {}
975 /// \brief Creates directive.
977 /// \param C AST context.
978 /// \param StartLoc Starting location of the directive kind.
979 /// \param EndLoc Ending Location of the directive.
980 /// \param AssociatedStmt Statement, associated with the directive.
982 static OMPMasterDirective *Create(const ASTContext &C,
983 SourceLocation StartLoc,
984 SourceLocation EndLoc,
985 Stmt *AssociatedStmt);
987 /// \brief Creates an empty directive.
989 /// \param C AST context.
991 static OMPMasterDirective *CreateEmpty(const ASTContext &C, EmptyShell);
993 static bool classof(const Stmt *T) {
994 return T->getStmtClass() == OMPMasterDirectiveClass;
998 /// \brief This represents '#pragma omp critical' directive.
1001 /// #pragma omp critical
1004 class OMPCriticalDirective : public OMPExecutableDirective {
1005 friend class ASTStmtReader;
1006 /// \brief Name of the directive.
1007 DeclarationNameInfo DirName;
1008 /// \brief Build directive with the given start and end location.
1010 /// \param Name Name of the directive.
1011 /// \param StartLoc Starting location of the directive kind.
1012 /// \param EndLoc Ending location of the directive.
1014 OMPCriticalDirective(const DeclarationNameInfo &Name, SourceLocation StartLoc,
1015 SourceLocation EndLoc)
1016 : OMPExecutableDirective(this, OMPCriticalDirectiveClass, OMPD_critical,
1017 StartLoc, EndLoc, 0, 1),
1020 /// \brief Build an empty directive.
1022 explicit OMPCriticalDirective()
1023 : OMPExecutableDirective(this, OMPCriticalDirectiveClass, OMPD_critical,
1024 SourceLocation(), SourceLocation(), 0, 1),
1027 /// \brief Set name of the directive.
1029 /// \param Name Name of the directive.
1031 void setDirectiveName(const DeclarationNameInfo &Name) { DirName = Name; }
1034 /// \brief Creates directive.
1036 /// \param C AST context.
1037 /// \param Name Name of the directive.
1038 /// \param StartLoc Starting location of the directive kind.
1039 /// \param EndLoc Ending Location of the directive.
1040 /// \param AssociatedStmt Statement, associated with the directive.
1042 static OMPCriticalDirective *
1043 Create(const ASTContext &C, const DeclarationNameInfo &Name,
1044 SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt);
1046 /// \brief Creates an empty directive.
1048 /// \param C AST context.
1050 static OMPCriticalDirective *CreateEmpty(const ASTContext &C, EmptyShell);
1052 /// \brief Return name of the directive.
1054 DeclarationNameInfo getDirectiveName() const { return DirName; }
1056 static bool classof(const Stmt *T) {
1057 return T->getStmtClass() == OMPCriticalDirectiveClass;
1061 /// \brief This represents '#pragma omp parallel for' directive.
1064 /// #pragma omp parallel for private(a,b) reduction(+:c,d)
1066 /// In this example directive '#pragma omp parallel for' has clauses 'private'
1067 /// with the variables 'a' and 'b' and 'reduction' with operator '+' and
1068 /// variables 'c' and 'd'.
1070 class OMPParallelForDirective : public OMPLoopDirective {
1071 friend class ASTStmtReader;
1072 /// \brief Build directive with the given start and end location.
1074 /// \param StartLoc Starting location of the directive kind.
1075 /// \param EndLoc Ending location of the directive.
1076 /// \param CollapsedNum Number of collapsed nested loops.
1077 /// \param NumClauses Number of clauses.
1079 OMPParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
1080 unsigned CollapsedNum, unsigned NumClauses)
1081 : OMPLoopDirective(this, OMPParallelForDirectiveClass, OMPD_parallel_for,
1082 StartLoc, EndLoc, CollapsedNum, NumClauses) {}
1084 /// \brief Build an empty directive.
1086 /// \param CollapsedNum Number of collapsed nested loops.
1087 /// \param NumClauses Number of clauses.
1089 explicit OMPParallelForDirective(unsigned CollapsedNum, unsigned NumClauses)
1090 : OMPLoopDirective(this, OMPParallelForDirectiveClass, OMPD_parallel_for,
1091 SourceLocation(), SourceLocation(), CollapsedNum,
1095 /// \brief Creates directive with a list of \a Clauses.
1097 /// \param C AST context.
1098 /// \param StartLoc Starting location of the directive kind.
1099 /// \param EndLoc Ending Location of the directive.
1100 /// \param CollapsedNum Number of collapsed loops.
1101 /// \param Clauses List of clauses.
1102 /// \param AssociatedStmt Statement, associated with the directive.
1103 /// \param Exprs Helper expressions for CodeGen.
1105 static OMPParallelForDirective *
1106 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1107 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
1108 Stmt *AssociatedStmt, const HelperExprs &Exprs);
1110 /// \brief Creates an empty directive with the place
1111 /// for \a NumClauses clauses.
1113 /// \param C AST context.
1114 /// \param CollapsedNum Number of collapsed nested loops.
1115 /// \param NumClauses Number of clauses.
1117 static OMPParallelForDirective *CreateEmpty(const ASTContext &C,
1118 unsigned NumClauses,
1119 unsigned CollapsedNum,
1122 static bool classof(const Stmt *T) {
1123 return T->getStmtClass() == OMPParallelForDirectiveClass;
1127 /// \brief This represents '#pragma omp parallel for simd' directive.
1130 /// #pragma omp parallel for simd private(a,b) linear(i,j:s) reduction(+:c,d)
1132 /// In this example directive '#pragma omp parallel for simd' has clauses
1133 /// 'private' with the variables 'a' and 'b', 'linear' with variables 'i', 'j'
1134 /// and linear step 's', 'reduction' with operator '+' and variables 'c' and
1137 class OMPParallelForSimdDirective : public OMPLoopDirective {
1138 friend class ASTStmtReader;
1139 /// \brief Build directive with the given start and end location.
1141 /// \param StartLoc Starting location of the directive kind.
1142 /// \param EndLoc Ending location of the directive.
1143 /// \param CollapsedNum Number of collapsed nested loops.
1144 /// \param NumClauses Number of clauses.
1146 OMPParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
1147 unsigned CollapsedNum, unsigned NumClauses)
1148 : OMPLoopDirective(this, OMPParallelForSimdDirectiveClass,
1149 OMPD_parallel_for_simd, StartLoc, EndLoc, CollapsedNum,
1152 /// \brief Build an empty directive.
1154 /// \param CollapsedNum Number of collapsed nested loops.
1155 /// \param NumClauses Number of clauses.
1157 explicit OMPParallelForSimdDirective(unsigned CollapsedNum,
1158 unsigned NumClauses)
1159 : OMPLoopDirective(this, OMPParallelForSimdDirectiveClass,
1160 OMPD_parallel_for_simd, SourceLocation(),
1161 SourceLocation(), CollapsedNum, NumClauses) {}
1164 /// \brief Creates directive with a list of \a Clauses.
1166 /// \param C AST context.
1167 /// \param StartLoc Starting location of the directive kind.
1168 /// \param EndLoc Ending Location of the directive.
1169 /// \param CollapsedNum Number of collapsed loops.
1170 /// \param Clauses List of clauses.
1171 /// \param AssociatedStmt Statement, associated with the directive.
1172 /// \param Exprs Helper expressions for CodeGen.
1174 static OMPParallelForSimdDirective *
1175 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1176 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
1177 Stmt *AssociatedStmt, const HelperExprs &Exprs);
1179 /// \brief Creates an empty directive with the place
1180 /// for \a NumClauses clauses.
1182 /// \param C AST context.
1183 /// \param CollapsedNum Number of collapsed nested loops.
1184 /// \param NumClauses Number of clauses.
1186 static OMPParallelForSimdDirective *CreateEmpty(const ASTContext &C,
1187 unsigned NumClauses,
1188 unsigned CollapsedNum,
1191 static bool classof(const Stmt *T) {
1192 return T->getStmtClass() == OMPParallelForSimdDirectiveClass;
1196 /// \brief This represents '#pragma omp parallel sections' directive.
1199 /// #pragma omp parallel sections private(a,b) reduction(+:c,d)
1201 /// In this example directive '#pragma omp parallel sections' has clauses
1202 /// 'private' with the variables 'a' and 'b' and 'reduction' with operator '+'
1203 /// and variables 'c' and 'd'.
1205 class OMPParallelSectionsDirective : public OMPExecutableDirective {
1206 friend class ASTStmtReader;
1207 /// \brief Build directive with the given start and end location.
1209 /// \param StartLoc Starting location of the directive kind.
1210 /// \param EndLoc Ending location of the directive.
1211 /// \param NumClauses Number of clauses.
1213 OMPParallelSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc,
1214 unsigned NumClauses)
1215 : OMPExecutableDirective(this, OMPParallelSectionsDirectiveClass,
1216 OMPD_parallel_sections, StartLoc, EndLoc,
1219 /// \brief Build an empty directive.
1221 /// \param NumClauses Number of clauses.
1223 explicit OMPParallelSectionsDirective(unsigned NumClauses)
1224 : OMPExecutableDirective(this, OMPParallelSectionsDirectiveClass,
1225 OMPD_parallel_sections, SourceLocation(),
1226 SourceLocation(), NumClauses, 1) {}
1229 /// \brief Creates directive with a list of \a Clauses.
1231 /// \param C AST context.
1232 /// \param StartLoc Starting location of the directive kind.
1233 /// \param EndLoc Ending Location of the directive.
1234 /// \param Clauses List of clauses.
1235 /// \param AssociatedStmt Statement, associated with the directive.
1237 static OMPParallelSectionsDirective *
1238 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1239 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
1241 /// \brief Creates an empty directive with the place for \a NumClauses
1244 /// \param C AST context.
1245 /// \param NumClauses Number of clauses.
1247 static OMPParallelSectionsDirective *
1248 CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
1250 static bool classof(const Stmt *T) {
1251 return T->getStmtClass() == OMPParallelSectionsDirectiveClass;
1255 /// \brief This represents '#pragma omp task' directive.
1258 /// #pragma omp task private(a,b) final(d)
1260 /// In this example directive '#pragma omp task' has clauses 'private' with the
1261 /// variables 'a' and 'b' and 'final' with condition 'd'.
1263 class OMPTaskDirective : public OMPExecutableDirective {
1264 friend class ASTStmtReader;
1265 /// \brief Build directive with the given start and end location.
1267 /// \param StartLoc Starting location of the directive kind.
1268 /// \param EndLoc Ending location of the directive.
1269 /// \param NumClauses Number of clauses.
1271 OMPTaskDirective(SourceLocation StartLoc, SourceLocation EndLoc,
1272 unsigned NumClauses)
1273 : OMPExecutableDirective(this, OMPTaskDirectiveClass, OMPD_task, StartLoc,
1274 EndLoc, NumClauses, 1) {}
1276 /// \brief Build an empty directive.
1278 /// \param NumClauses Number of clauses.
1280 explicit OMPTaskDirective(unsigned NumClauses)
1281 : OMPExecutableDirective(this, OMPTaskDirectiveClass, OMPD_task,
1282 SourceLocation(), SourceLocation(), NumClauses,
1286 /// \brief Creates directive with a list of \a Clauses.
1288 /// \param C AST context.
1289 /// \param StartLoc Starting location of the directive kind.
1290 /// \param EndLoc Ending Location of the directive.
1291 /// \param Clauses List of clauses.
1292 /// \param AssociatedStmt Statement, associated with the directive.
1294 static OMPTaskDirective *Create(const ASTContext &C, SourceLocation StartLoc,
1295 SourceLocation EndLoc,
1296 ArrayRef<OMPClause *> Clauses,
1297 Stmt *AssociatedStmt);
1299 /// \brief Creates an empty directive with the place for \a NumClauses
1302 /// \param C AST context.
1303 /// \param NumClauses Number of clauses.
1305 static OMPTaskDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
1308 static bool classof(const Stmt *T) {
1309 return T->getStmtClass() == OMPTaskDirectiveClass;
1313 /// \brief This represents '#pragma omp taskyield' directive.
1316 /// #pragma omp taskyield
1319 class OMPTaskyieldDirective : public OMPExecutableDirective {
1320 friend class ASTStmtReader;
1321 /// \brief Build directive with the given start and end location.
1323 /// \param StartLoc Starting location of the directive kind.
1324 /// \param EndLoc Ending location of the directive.
1326 OMPTaskyieldDirective(SourceLocation StartLoc, SourceLocation EndLoc)
1327 : OMPExecutableDirective(this, OMPTaskyieldDirectiveClass, OMPD_taskyield,
1328 StartLoc, EndLoc, 0, 0) {}
1330 /// \brief Build an empty directive.
1332 explicit OMPTaskyieldDirective()
1333 : OMPExecutableDirective(this, OMPTaskyieldDirectiveClass, OMPD_taskyield,
1334 SourceLocation(), SourceLocation(), 0, 0) {}
1337 /// \brief Creates directive.
1339 /// \param C AST context.
1340 /// \param StartLoc Starting location of the directive kind.
1341 /// \param EndLoc Ending Location of the directive.
1343 static OMPTaskyieldDirective *
1344 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
1346 /// \brief Creates an empty directive.
1348 /// \param C AST context.
1350 static OMPTaskyieldDirective *CreateEmpty(const ASTContext &C, EmptyShell);
1352 static bool classof(const Stmt *T) {
1353 return T->getStmtClass() == OMPTaskyieldDirectiveClass;
1357 /// \brief This represents '#pragma omp barrier' directive.
1360 /// #pragma omp barrier
1363 class OMPBarrierDirective : public OMPExecutableDirective {
1364 friend class ASTStmtReader;
1365 /// \brief Build directive with the given start and end location.
1367 /// \param StartLoc Starting location of the directive kind.
1368 /// \param EndLoc Ending location of the directive.
1370 OMPBarrierDirective(SourceLocation StartLoc, SourceLocation EndLoc)
1371 : OMPExecutableDirective(this, OMPBarrierDirectiveClass, OMPD_barrier,
1372 StartLoc, EndLoc, 0, 0) {}
1374 /// \brief Build an empty directive.
1376 explicit OMPBarrierDirective()
1377 : OMPExecutableDirective(this, OMPBarrierDirectiveClass, OMPD_barrier,
1378 SourceLocation(), SourceLocation(), 0, 0) {}
1381 /// \brief Creates directive.
1383 /// \param C AST context.
1384 /// \param StartLoc Starting location of the directive kind.
1385 /// \param EndLoc Ending Location of the directive.
1387 static OMPBarrierDirective *
1388 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
1390 /// \brief Creates an empty directive.
1392 /// \param C AST context.
1394 static OMPBarrierDirective *CreateEmpty(const ASTContext &C, EmptyShell);
1396 static bool classof(const Stmt *T) {
1397 return T->getStmtClass() == OMPBarrierDirectiveClass;
1401 /// \brief This represents '#pragma omp taskwait' directive.
1404 /// #pragma omp taskwait
1407 class OMPTaskwaitDirective : public OMPExecutableDirective {
1408 friend class ASTStmtReader;
1409 /// \brief Build directive with the given start and end location.
1411 /// \param StartLoc Starting location of the directive kind.
1412 /// \param EndLoc Ending location of the directive.
1414 OMPTaskwaitDirective(SourceLocation StartLoc, SourceLocation EndLoc)
1415 : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, OMPD_taskwait,
1416 StartLoc, EndLoc, 0, 0) {}
1418 /// \brief Build an empty directive.
1420 explicit OMPTaskwaitDirective()
1421 : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, OMPD_taskwait,
1422 SourceLocation(), SourceLocation(), 0, 0) {}
1425 /// \brief Creates directive.
1427 /// \param C AST context.
1428 /// \param StartLoc Starting location of the directive kind.
1429 /// \param EndLoc Ending Location of the directive.
1431 static OMPTaskwaitDirective *
1432 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
1434 /// \brief Creates an empty directive.
1436 /// \param C AST context.
1438 static OMPTaskwaitDirective *CreateEmpty(const ASTContext &C, EmptyShell);
1440 static bool classof(const Stmt *T) {
1441 return T->getStmtClass() == OMPTaskwaitDirectiveClass;
1445 /// \brief This represents '#pragma omp flush' directive.
1448 /// #pragma omp flush(a,b)
1450 /// In this example directive '#pragma omp flush' has 2 arguments- variables 'a'
1452 /// 'omp flush' directive does not have clauses but have an optional list of
1453 /// variables to flush. This list of variables is stored within some fake clause
1455 class OMPFlushDirective : public OMPExecutableDirective {
1456 friend class ASTStmtReader;
1457 /// \brief Build directive with the given start and end location.
1459 /// \param StartLoc Starting location of the directive kind.
1460 /// \param EndLoc Ending location of the directive.
1461 /// \param NumClauses Number of clauses.
1463 OMPFlushDirective(SourceLocation StartLoc, SourceLocation EndLoc,
1464 unsigned NumClauses)
1465 : OMPExecutableDirective(this, OMPFlushDirectiveClass, OMPD_flush,
1466 StartLoc, EndLoc, NumClauses, 0) {}
1468 /// \brief Build an empty directive.
1470 /// \param NumClauses Number of clauses.
1472 explicit OMPFlushDirective(unsigned NumClauses)
1473 : OMPExecutableDirective(this, OMPFlushDirectiveClass, OMPD_flush,
1474 SourceLocation(), SourceLocation(), NumClauses,
1478 /// \brief Creates directive with a list of \a Clauses.
1480 /// \param C AST context.
1481 /// \param StartLoc Starting location of the directive kind.
1482 /// \param EndLoc Ending Location of the directive.
1483 /// \param Clauses List of clauses (only single OMPFlushClause clause is
1486 static OMPFlushDirective *Create(const ASTContext &C, SourceLocation StartLoc,
1487 SourceLocation EndLoc,
1488 ArrayRef<OMPClause *> Clauses);
1490 /// \brief Creates an empty directive with the place for \a NumClauses
1493 /// \param C AST context.
1494 /// \param NumClauses Number of clauses.
1496 static OMPFlushDirective *CreateEmpty(const ASTContext &C,
1497 unsigned NumClauses, EmptyShell);
1499 static bool classof(const Stmt *T) {
1500 return T->getStmtClass() == OMPFlushDirectiveClass;
1504 /// \brief This represents '#pragma omp ordered' directive.
1507 /// #pragma omp ordered
1510 class OMPOrderedDirective : public OMPExecutableDirective {
1511 friend class ASTStmtReader;
1512 /// \brief Build directive with the given start and end location.
1514 /// \param StartLoc Starting location of the directive kind.
1515 /// \param EndLoc Ending location of the directive.
1517 OMPOrderedDirective(SourceLocation StartLoc, SourceLocation EndLoc)
1518 : OMPExecutableDirective(this, OMPOrderedDirectiveClass, OMPD_ordered,
1519 StartLoc, EndLoc, 0, 1) {}
1521 /// \brief Build an empty directive.
1523 explicit OMPOrderedDirective()
1524 : OMPExecutableDirective(this, OMPOrderedDirectiveClass, OMPD_ordered,
1525 SourceLocation(), SourceLocation(), 0, 1) {}
1528 /// \brief Creates directive.
1530 /// \param C AST context.
1531 /// \param StartLoc Starting location of the directive kind.
1532 /// \param EndLoc Ending Location of the directive.
1533 /// \param AssociatedStmt Statement, associated with the directive.
1535 static OMPOrderedDirective *Create(const ASTContext &C,
1536 SourceLocation StartLoc,
1537 SourceLocation EndLoc,
1538 Stmt *AssociatedStmt);
1540 /// \brief Creates an empty directive.
1542 /// \param C AST context.
1544 static OMPOrderedDirective *CreateEmpty(const ASTContext &C, EmptyShell);
1546 static bool classof(const Stmt *T) {
1547 return T->getStmtClass() == OMPOrderedDirectiveClass;
1551 /// \brief This represents '#pragma omp atomic' directive.
1554 /// #pragma omp atomic capture
1556 /// In this example directive '#pragma omp atomic' has clause 'capture'.
1558 class OMPAtomicDirective : public OMPExecutableDirective {
1559 friend class ASTStmtReader;
1560 /// \brief Build directive with the given start and end location.
1562 /// \param StartLoc Starting location of the directive kind.
1563 /// \param EndLoc Ending location of the directive.
1564 /// \param NumClauses Number of clauses.
1566 OMPAtomicDirective(SourceLocation StartLoc, SourceLocation EndLoc,
1567 unsigned NumClauses)
1568 : OMPExecutableDirective(this, OMPAtomicDirectiveClass, OMPD_atomic,
1569 StartLoc, EndLoc, NumClauses, 4) {}
1571 /// \brief Build an empty directive.
1573 /// \param NumClauses Number of clauses.
1575 explicit OMPAtomicDirective(unsigned NumClauses)
1576 : OMPExecutableDirective(this, OMPAtomicDirectiveClass, OMPD_atomic,
1577 SourceLocation(), SourceLocation(), NumClauses,
1580 /// \brief Set 'x' part of the associated expression/statement.
1581 void setX(Expr *X) { *std::next(child_begin()) = X; }
1582 /// \brief Set 'v' part of the associated expression/statement.
1583 void setV(Expr *V) { *std::next(child_begin(), 2) = V; }
1584 /// \brief Set 'expr' part of the associated expression/statement.
1585 void setExpr(Expr *E) { *std::next(child_begin(), 3) = E; }
1588 /// \brief Creates directive with a list of \a Clauses and 'x', 'v' and 'expr'
1589 /// parts of the atomic construct (see Section 2.12.6, atomic Construct, for
1590 /// detailed description of 'x', 'v' and 'expr').
1592 /// \param C AST context.
1593 /// \param StartLoc Starting location of the directive kind.
1594 /// \param EndLoc Ending Location of the directive.
1595 /// \param Clauses List of clauses.
1596 /// \param AssociatedStmt Statement, associated with the directive.
1597 /// \param X 'x' part of the associated expression/statement.
1598 /// \param V 'v' part of the associated expression/statement.
1599 /// \param E 'expr' part of the associated expression/statement.
1601 static OMPAtomicDirective *
1602 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1603 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V,
1606 /// \brief Creates an empty directive with the place for \a NumClauses
1609 /// \param C AST context.
1610 /// \param NumClauses Number of clauses.
1612 static OMPAtomicDirective *CreateEmpty(const ASTContext &C,
1613 unsigned NumClauses, EmptyShell);
1615 /// \brief Get 'x' part of the associated expression/statement.
1616 Expr *getX() { return cast_or_null<Expr>(*std::next(child_begin())); }
1617 const Expr *getX() const {
1618 return cast_or_null<Expr>(*std::next(child_begin()));
1620 /// \brief Get 'v' part of the associated expression/statement.
1621 Expr *getV() { return cast_or_null<Expr>(*std::next(child_begin(), 2)); }
1622 const Expr *getV() const {
1623 return cast_or_null<Expr>(*std::next(child_begin(), 2));
1625 /// \brief Get 'expr' part of the associated expression/statement.
1626 Expr *getExpr() { return cast_or_null<Expr>(*std::next(child_begin(), 3)); }
1627 const Expr *getExpr() const {
1628 return cast_or_null<Expr>(*std::next(child_begin(), 3));
1631 static bool classof(const Stmt *T) {
1632 return T->getStmtClass() == OMPAtomicDirectiveClass;
1636 /// \brief This represents '#pragma omp target' directive.
1639 /// #pragma omp target if(a)
1641 /// In this example directive '#pragma omp target' has clause 'if' with
1644 class OMPTargetDirective : public OMPExecutableDirective {
1645 friend class ASTStmtReader;
1646 /// \brief Build directive with the given start and end location.
1648 /// \param StartLoc Starting location of the directive kind.
1649 /// \param EndLoc Ending location of the directive.
1650 /// \param NumClauses Number of clauses.
1652 OMPTargetDirective(SourceLocation StartLoc, SourceLocation EndLoc,
1653 unsigned NumClauses)
1654 : OMPExecutableDirective(this, OMPTargetDirectiveClass, OMPD_target,
1655 StartLoc, EndLoc, NumClauses, 1) {}
1657 /// \brief Build an empty directive.
1659 /// \param NumClauses Number of clauses.
1661 explicit OMPTargetDirective(unsigned NumClauses)
1662 : OMPExecutableDirective(this, OMPTargetDirectiveClass, OMPD_target,
1663 SourceLocation(), SourceLocation(), NumClauses,
1667 /// \brief Creates directive with a list of \a Clauses.
1669 /// \param C AST context.
1670 /// \param StartLoc Starting location of the directive kind.
1671 /// \param EndLoc Ending Location of the directive.
1672 /// \param Clauses List of clauses.
1673 /// \param AssociatedStmt Statement, associated with the directive.
1675 static OMPTargetDirective *
1676 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1677 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
1679 /// \brief Creates an empty directive with the place for \a NumClauses
1682 /// \param C AST context.
1683 /// \param NumClauses Number of clauses.
1685 static OMPTargetDirective *CreateEmpty(const ASTContext &C,
1686 unsigned NumClauses, EmptyShell);
1688 static bool classof(const Stmt *T) {
1689 return T->getStmtClass() == OMPTargetDirectiveClass;
1693 /// \brief This represents '#pragma omp teams' directive.
1696 /// #pragma omp teams if(a)
1698 /// In this example directive '#pragma omp teams' has clause 'if' with
1701 class OMPTeamsDirective : public OMPExecutableDirective {
1702 friend class ASTStmtReader;
1703 /// \brief Build directive with the given start and end location.
1705 /// \param StartLoc Starting location of the directive kind.
1706 /// \param EndLoc Ending location of the directive.
1707 /// \param NumClauses Number of clauses.
1709 OMPTeamsDirective(SourceLocation StartLoc, SourceLocation EndLoc,
1710 unsigned NumClauses)
1711 : OMPExecutableDirective(this, OMPTeamsDirectiveClass, OMPD_teams,
1712 StartLoc, EndLoc, NumClauses, 1) {}
1714 /// \brief Build an empty directive.
1716 /// \param NumClauses Number of clauses.
1718 explicit OMPTeamsDirective(unsigned NumClauses)
1719 : OMPExecutableDirective(this, OMPTeamsDirectiveClass, OMPD_teams,
1720 SourceLocation(), SourceLocation(), NumClauses,
1724 /// \brief Creates directive with a list of \a Clauses.
1726 /// \param C AST context.
1727 /// \param StartLoc Starting location of the directive kind.
1728 /// \param EndLoc Ending Location of the directive.
1729 /// \param Clauses List of clauses.
1730 /// \param AssociatedStmt Statement, associated with the directive.
1732 static OMPTeamsDirective *Create(const ASTContext &C, SourceLocation StartLoc,
1733 SourceLocation EndLoc,
1734 ArrayRef<OMPClause *> Clauses,
1735 Stmt *AssociatedStmt);
1737 /// \brief Creates an empty directive with the place for \a NumClauses
1740 /// \param C AST context.
1741 /// \param NumClauses Number of clauses.
1743 static OMPTeamsDirective *CreateEmpty(const ASTContext &C,
1744 unsigned NumClauses, EmptyShell);
1746 static bool classof(const Stmt *T) {
1747 return T->getStmtClass() == OMPTeamsDirectiveClass;
1751 } // end namespace clang