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 Returns starting location of directive kind.
132 SourceLocation getLocStart() const { return StartLoc; }
133 /// \brief Returns ending location of directive.
134 SourceLocation getLocEnd() const { return EndLoc; }
136 /// \brief Set starting location of directive kind.
138 /// \param Loc New starting location of directive.
140 void setLocStart(SourceLocation Loc) { StartLoc = Loc; }
141 /// \brief Set ending location of directive.
143 /// \param Loc New ending location of directive.
145 void setLocEnd(SourceLocation Loc) { EndLoc = Loc; }
147 /// \brief Get number of clauses.
148 unsigned getNumClauses() const { return NumClauses; }
150 /// \brief Returns specified clause.
152 /// \param i Number of clause.
154 OMPClause *getClause(unsigned i) const { return clauses()[i]; }
156 /// \brief Returns true if directive has associated statement.
157 bool hasAssociatedStmt() const { return NumChildren > 0; }
159 /// \brief Returns statement associated with the directive.
160 Stmt *getAssociatedStmt() const {
161 assert(hasAssociatedStmt() && "no associated statement.");
162 return const_cast<Stmt *>(*child_begin());
165 OpenMPDirectiveKind getDirectiveKind() const { return Kind; }
167 static bool classof(const Stmt *S) {
168 return S->getStmtClass() >= firstOMPExecutableDirectiveConstant &&
169 S->getStmtClass() <= lastOMPExecutableDirectiveConstant;
172 child_range children() {
173 if (!hasAssociatedStmt())
174 return child_range();
175 Stmt **ChildStorage = reinterpret_cast<Stmt **>(getClauses().end());
176 return child_range(ChildStorage, ChildStorage + NumChildren);
179 ArrayRef<OMPClause *> clauses() { return getClauses(); }
181 ArrayRef<OMPClause *> clauses() const {
182 return const_cast<OMPExecutableDirective *>(this)->getClauses();
186 /// \brief This represents '#pragma omp parallel' directive.
189 /// #pragma omp parallel private(a,b) reduction(+: c,d)
191 /// In this example directive '#pragma omp parallel' has clauses 'private'
192 /// with the variables 'a' and 'b' and 'reduction' with operator '+' and
193 /// variables 'c' and 'd'.
195 class OMPParallelDirective : public OMPExecutableDirective {
196 /// \brief Build directive with the given start and end location.
198 /// \param StartLoc Starting location of the directive (directive keyword).
199 /// \param EndLoc Ending Location of the directive.
201 OMPParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc,
203 : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
204 StartLoc, EndLoc, NumClauses, 1) {}
206 /// \brief Build an empty directive.
208 /// \param NumClauses Number of clauses.
210 explicit OMPParallelDirective(unsigned NumClauses)
211 : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel,
212 SourceLocation(), SourceLocation(), NumClauses,
216 /// \brief Creates directive with a list of \a Clauses.
218 /// \param C AST context.
219 /// \param StartLoc Starting location of the directive kind.
220 /// \param EndLoc Ending Location of the directive.
221 /// \param Clauses List of clauses.
222 /// \param AssociatedStmt Statement associated with the directive.
224 static OMPParallelDirective *
225 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
226 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
228 /// \brief Creates an empty directive with the place for \a N clauses.
230 /// \param C AST context.
231 /// \param NumClauses Number of clauses.
233 static OMPParallelDirective *CreateEmpty(const ASTContext &C,
234 unsigned NumClauses, EmptyShell);
236 static bool classof(const Stmt *T) {
237 return T->getStmtClass() == OMPParallelDirectiveClass;
241 /// \brief This represents '#pragma omp simd' directive.
244 /// #pragma omp simd private(a,b) linear(i,j:s) reduction(+:c,d)
246 /// In this example directive '#pragma omp simd' has clauses 'private'
247 /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and
248 /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'.
250 class OMPSimdDirective : public OMPExecutableDirective {
251 friend class ASTStmtReader;
252 /// \brief Number of collapsed loops as specified by 'collapse' clause.
253 unsigned CollapsedNum;
254 /// \brief Build directive with the given start and end location.
256 /// \param StartLoc Starting location of the directive kind.
257 /// \param EndLoc Ending location of the directive.
258 /// \param CollapsedNum Number of collapsed nested loops.
259 /// \param NumClauses Number of clauses.
261 OMPSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc,
262 unsigned CollapsedNum, unsigned NumClauses)
263 : OMPExecutableDirective(this, OMPSimdDirectiveClass, OMPD_simd, StartLoc,
264 EndLoc, NumClauses, 1),
265 CollapsedNum(CollapsedNum) {}
267 /// \brief Build an empty directive.
269 /// \param CollapsedNum Number of collapsed nested loops.
270 /// \param NumClauses Number of clauses.
272 explicit OMPSimdDirective(unsigned CollapsedNum, unsigned NumClauses)
273 : OMPExecutableDirective(this, OMPSimdDirectiveClass, OMPD_simd,
274 SourceLocation(), SourceLocation(), NumClauses,
276 CollapsedNum(CollapsedNum) {}
279 /// \brief Creates directive with a list of \a Clauses.
281 /// \param C AST context.
282 /// \param StartLoc Starting location of the directive kind.
283 /// \param EndLoc Ending Location of the directive.
284 /// \param CollapsedNum Number of collapsed loops.
285 /// \param Clauses List of clauses.
286 /// \param AssociatedStmt Statement, associated with the directive.
288 static OMPSimdDirective *Create(const ASTContext &C, SourceLocation StartLoc,
289 SourceLocation EndLoc, unsigned CollapsedNum,
290 ArrayRef<OMPClause *> Clauses,
291 Stmt *AssociatedStmt);
293 /// \brief Creates an empty directive with the place
294 /// for \a NumClauses clauses.
296 /// \param C AST context.
297 /// \param CollapsedNum Number of collapsed nested loops.
298 /// \param NumClauses Number of clauses.
300 static OMPSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
301 unsigned CollapsedNum, EmptyShell);
303 unsigned getCollapsedNumber() const { return CollapsedNum; }
305 static bool classof(const Stmt *T) {
306 return T->getStmtClass() == OMPSimdDirectiveClass;
310 /// \brief This represents '#pragma omp for' directive.
313 /// #pragma omp for private(a,b) reduction(+:c,d)
315 /// In this example directive '#pragma omp for' has clauses 'private' with the
316 /// variables 'a' and 'b' and 'reduction' with operator '+' and variables 'c'
319 class OMPForDirective : public OMPExecutableDirective {
320 friend class ASTStmtReader;
321 /// \brief Number of collapsed loops as specified by 'collapse' clause.
322 unsigned CollapsedNum;
323 /// \brief Build directive with the given start and end location.
325 /// \param StartLoc Starting location of the directive kind.
326 /// \param EndLoc Ending location of the directive.
327 /// \param CollapsedNum Number of collapsed nested loops.
328 /// \param NumClauses Number of clauses.
330 OMPForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
331 unsigned CollapsedNum, unsigned NumClauses)
332 : OMPExecutableDirective(this, OMPForDirectiveClass, OMPD_for, StartLoc,
333 EndLoc, NumClauses, 1),
334 CollapsedNum(CollapsedNum) {}
336 /// \brief Build an empty directive.
338 /// \param CollapsedNum Number of collapsed nested loops.
339 /// \param NumClauses Number of clauses.
341 explicit OMPForDirective(unsigned CollapsedNum, unsigned NumClauses)
342 : OMPExecutableDirective(this, OMPForDirectiveClass, OMPD_for,
343 SourceLocation(), SourceLocation(), NumClauses,
345 CollapsedNum(CollapsedNum) {}
348 /// \brief Creates directive with a list of \a Clauses.
350 /// \param C AST context.
351 /// \param StartLoc Starting location of the directive kind.
352 /// \param EndLoc Ending Location of the directive.
353 /// \param CollapsedNum Number of collapsed loops.
354 /// \param Clauses List of clauses.
355 /// \param AssociatedStmt Statement, associated with the directive.
357 static OMPForDirective *Create(const ASTContext &C, SourceLocation StartLoc,
358 SourceLocation EndLoc, unsigned CollapsedNum,
359 ArrayRef<OMPClause *> Clauses,
360 Stmt *AssociatedStmt);
362 /// \brief Creates an empty directive with the place
363 /// for \a NumClauses clauses.
365 /// \param C AST context.
366 /// \param CollapsedNum Number of collapsed nested loops.
367 /// \param NumClauses Number of clauses.
369 static OMPForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
370 unsigned CollapsedNum, EmptyShell);
372 unsigned getCollapsedNumber() const { return CollapsedNum; }
374 static bool classof(const Stmt *T) {
375 return T->getStmtClass() == OMPForDirectiveClass;
379 /// \brief This represents '#pragma omp sections' directive.
382 /// #pragma omp sections private(a,b) reduction(+:c,d)
384 /// In this example directive '#pragma omp sections' has clauses 'private' with
385 /// the variables 'a' and 'b' and 'reduction' with operator '+' and variables
388 class OMPSectionsDirective : public OMPExecutableDirective {
389 friend class ASTStmtReader;
390 /// \brief Build directive with the given start and end location.
392 /// \param StartLoc Starting location of the directive kind.
393 /// \param EndLoc Ending location of the directive.
394 /// \param NumClauses Number of clauses.
396 OMPSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc,
398 : OMPExecutableDirective(this, OMPSectionsDirectiveClass, OMPD_sections,
399 StartLoc, EndLoc, NumClauses, 1) {}
401 /// \brief Build an empty directive.
403 /// \param NumClauses Number of clauses.
405 explicit OMPSectionsDirective(unsigned NumClauses)
406 : OMPExecutableDirective(this, OMPSectionsDirectiveClass, OMPD_sections,
407 SourceLocation(), SourceLocation(), NumClauses,
411 /// \brief Creates directive with a list of \a Clauses.
413 /// \param C AST context.
414 /// \param StartLoc Starting location of the directive kind.
415 /// \param EndLoc Ending Location of the directive.
416 /// \param Clauses List of clauses.
417 /// \param AssociatedStmt Statement, associated with the directive.
419 static OMPSectionsDirective *
420 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
421 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
423 /// \brief Creates an empty directive with the place for \a NumClauses
426 /// \param C AST context.
427 /// \param NumClauses Number of clauses.
429 static OMPSectionsDirective *CreateEmpty(const ASTContext &C,
430 unsigned NumClauses, EmptyShell);
432 static bool classof(const Stmt *T) {
433 return T->getStmtClass() == OMPSectionsDirectiveClass;
437 /// \brief This represents '#pragma omp section' directive.
440 /// #pragma omp section
443 class OMPSectionDirective : public OMPExecutableDirective {
444 friend class ASTStmtReader;
445 /// \brief Build directive with the given start and end location.
447 /// \param StartLoc Starting location of the directive kind.
448 /// \param EndLoc Ending location of the directive.
450 OMPSectionDirective(SourceLocation StartLoc, SourceLocation EndLoc)
451 : OMPExecutableDirective(this, OMPSectionDirectiveClass, OMPD_section,
452 StartLoc, EndLoc, 0, 1) {}
454 /// \brief Build an empty directive.
456 explicit OMPSectionDirective()
457 : OMPExecutableDirective(this, OMPSectionDirectiveClass, OMPD_section,
458 SourceLocation(), SourceLocation(), 0, 1) {}
461 /// \brief Creates directive.
463 /// \param C AST context.
464 /// \param StartLoc Starting location of the directive kind.
465 /// \param EndLoc Ending Location of the directive.
466 /// \param AssociatedStmt Statement, associated with the directive.
468 static OMPSectionDirective *Create(const ASTContext &C,
469 SourceLocation StartLoc,
470 SourceLocation EndLoc,
471 Stmt *AssociatedStmt);
473 /// \brief Creates an empty directive.
475 /// \param C AST context.
477 static OMPSectionDirective *CreateEmpty(const ASTContext &C, EmptyShell);
479 static bool classof(const Stmt *T) {
480 return T->getStmtClass() == OMPSectionDirectiveClass;
484 /// \brief This represents '#pragma omp single' directive.
487 /// #pragma omp single private(a,b) copyprivate(c,d)
489 /// In this example directive '#pragma omp single' has clauses 'private' with
490 /// the variables 'a' and 'b' and 'copyprivate' with variables 'c' and 'd'.
492 class OMPSingleDirective : public OMPExecutableDirective {
493 friend class ASTStmtReader;
494 /// \brief Build directive with the given start and end location.
496 /// \param StartLoc Starting location of the directive kind.
497 /// \param EndLoc Ending location of the directive.
498 /// \param NumClauses Number of clauses.
500 OMPSingleDirective(SourceLocation StartLoc, SourceLocation EndLoc,
502 : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single,
503 StartLoc, EndLoc, NumClauses, 1) {}
505 /// \brief Build an empty directive.
507 /// \param NumClauses Number of clauses.
509 explicit OMPSingleDirective(unsigned NumClauses)
510 : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single,
511 SourceLocation(), SourceLocation(), NumClauses,
515 /// \brief Creates directive with a list of \a Clauses.
517 /// \param C AST context.
518 /// \param StartLoc Starting location of the directive kind.
519 /// \param EndLoc Ending Location of the directive.
520 /// \param Clauses List of clauses.
521 /// \param AssociatedStmt Statement, associated with the directive.
523 static OMPSingleDirective *
524 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
525 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
527 /// \brief Creates an empty directive with the place for \a NumClauses
530 /// \param C AST context.
531 /// \param NumClauses Number of clauses.
533 static OMPSingleDirective *CreateEmpty(const ASTContext &C,
534 unsigned NumClauses, EmptyShell);
536 static bool classof(const Stmt *T) {
537 return T->getStmtClass() == OMPSingleDirectiveClass;
541 /// \brief This represents '#pragma omp master' directive.
544 /// #pragma omp master
547 class OMPMasterDirective : public OMPExecutableDirective {
548 friend class ASTStmtReader;
549 /// \brief Build directive with the given start and end location.
551 /// \param StartLoc Starting location of the directive kind.
552 /// \param EndLoc Ending location of the directive.
554 OMPMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc)
555 : OMPExecutableDirective(this, OMPMasterDirectiveClass, OMPD_master,
556 StartLoc, EndLoc, 0, 1) {}
558 /// \brief Build an empty directive.
560 explicit OMPMasterDirective()
561 : OMPExecutableDirective(this, OMPMasterDirectiveClass, OMPD_master,
562 SourceLocation(), SourceLocation(), 0, 1) {}
565 /// \brief Creates directive.
567 /// \param C AST context.
568 /// \param StartLoc Starting location of the directive kind.
569 /// \param EndLoc Ending Location of the directive.
570 /// \param AssociatedStmt Statement, associated with the directive.
572 static OMPMasterDirective *Create(const ASTContext &C,
573 SourceLocation StartLoc,
574 SourceLocation EndLoc,
575 Stmt *AssociatedStmt);
577 /// \brief Creates an empty directive.
579 /// \param C AST context.
581 static OMPMasterDirective *CreateEmpty(const ASTContext &C, EmptyShell);
583 static bool classof(const Stmt *T) {
584 return T->getStmtClass() == OMPMasterDirectiveClass;
588 /// \brief This represents '#pragma omp critical' directive.
591 /// #pragma omp critical
594 class OMPCriticalDirective : public OMPExecutableDirective {
595 friend class ASTStmtReader;
596 /// \brief Name of the directive.
597 DeclarationNameInfo DirName;
598 /// \brief Build directive with the given start and end location.
600 /// \param Name Name of the directive.
601 /// \param StartLoc Starting location of the directive kind.
602 /// \param EndLoc Ending location of the directive.
604 OMPCriticalDirective(const DeclarationNameInfo &Name, SourceLocation StartLoc,
605 SourceLocation EndLoc)
606 : OMPExecutableDirective(this, OMPCriticalDirectiveClass, OMPD_critical,
607 StartLoc, EndLoc, 0, 1),
610 /// \brief Build an empty directive.
612 explicit OMPCriticalDirective()
613 : OMPExecutableDirective(this, OMPCriticalDirectiveClass, OMPD_critical,
614 SourceLocation(), SourceLocation(), 0, 1),
617 /// \brief Set name of the directive.
619 /// \param Name Name of the directive.
621 void setDirectiveName(const DeclarationNameInfo &Name) { DirName = Name; }
624 /// \brief Creates directive.
626 /// \param C AST context.
627 /// \param Name Name of the directive.
628 /// \param StartLoc Starting location of the directive kind.
629 /// \param EndLoc Ending Location of the directive.
630 /// \param AssociatedStmt Statement, associated with the directive.
632 static OMPCriticalDirective *
633 Create(const ASTContext &C, const DeclarationNameInfo &Name,
634 SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt);
636 /// \brief Creates an empty directive.
638 /// \param C AST context.
640 static OMPCriticalDirective *CreateEmpty(const ASTContext &C, EmptyShell);
642 /// \brief Return name of the directive.
644 DeclarationNameInfo getDirectiveName() const { return DirName; }
646 static bool classof(const Stmt *T) {
647 return T->getStmtClass() == OMPCriticalDirectiveClass;
651 /// \brief This represents '#pragma omp parallel for' directive.
654 /// #pragma omp parallel for private(a,b) reduction(+:c,d)
656 /// In this example directive '#pragma omp parallel for' has clauses 'private'
657 /// with the variables 'a' and 'b' and 'reduction' with operator '+' and
658 /// variables 'c' and 'd'.
660 class OMPParallelForDirective : public OMPExecutableDirective {
661 friend class ASTStmtReader;
662 /// \brief Number of collapsed loops as specified by 'collapse' clause.
663 unsigned CollapsedNum;
664 /// \brief Build directive with the given start and end location.
666 /// \param StartLoc Starting location of the directive kind.
667 /// \param EndLoc Ending location of the directive.
668 /// \param CollapsedNum Number of collapsed nested loops.
669 /// \param NumClauses Number of clauses.
671 OMPParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
672 unsigned CollapsedNum, unsigned NumClauses)
673 : OMPExecutableDirective(this, OMPParallelForDirectiveClass,
674 OMPD_parallel_for, StartLoc, EndLoc, NumClauses,
676 CollapsedNum(CollapsedNum) {}
678 /// \brief Build an empty directive.
680 /// \param CollapsedNum Number of collapsed nested loops.
681 /// \param NumClauses Number of clauses.
683 explicit OMPParallelForDirective(unsigned CollapsedNum, unsigned NumClauses)
684 : OMPExecutableDirective(this, OMPParallelForDirectiveClass,
685 OMPD_parallel_for, SourceLocation(),
686 SourceLocation(), NumClauses, 1),
687 CollapsedNum(CollapsedNum) {}
690 /// \brief Creates directive with a list of \a Clauses.
692 /// \param C AST context.
693 /// \param StartLoc Starting location of the directive kind.
694 /// \param EndLoc Ending Location of the directive.
695 /// \param CollapsedNum Number of collapsed loops.
696 /// \param Clauses List of clauses.
697 /// \param AssociatedStmt Statement, associated with the directive.
699 static OMPParallelForDirective *
700 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
701 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
702 Stmt *AssociatedStmt);
704 /// \brief Creates an empty directive with the place
705 /// for \a NumClauses clauses.
707 /// \param C AST context.
708 /// \param CollapsedNum Number of collapsed nested loops.
709 /// \param NumClauses Number of clauses.
711 static OMPParallelForDirective *CreateEmpty(const ASTContext &C,
713 unsigned CollapsedNum,
716 unsigned getCollapsedNumber() const { return CollapsedNum; }
718 static bool classof(const Stmt *T) {
719 return T->getStmtClass() == OMPParallelForDirectiveClass;
723 /// \brief This represents '#pragma omp parallel sections' directive.
726 /// #pragma omp parallel sections private(a,b) reduction(+:c,d)
728 /// In this example directive '#pragma omp parallel sections' has clauses
729 /// 'private' with the variables 'a' and 'b' and 'reduction' with operator '+'
730 /// and variables 'c' and 'd'.
732 class OMPParallelSectionsDirective : public OMPExecutableDirective {
733 friend class ASTStmtReader;
734 /// \brief Build directive with the given start and end location.
736 /// \param StartLoc Starting location of the directive kind.
737 /// \param EndLoc Ending location of the directive.
738 /// \param NumClauses Number of clauses.
740 OMPParallelSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc,
742 : OMPExecutableDirective(this, OMPParallelSectionsDirectiveClass,
743 OMPD_parallel_sections, StartLoc, EndLoc,
746 /// \brief Build an empty directive.
748 /// \param NumClauses Number of clauses.
750 explicit OMPParallelSectionsDirective(unsigned NumClauses)
751 : OMPExecutableDirective(this, OMPParallelSectionsDirectiveClass,
752 OMPD_parallel_sections, SourceLocation(),
753 SourceLocation(), NumClauses, 1) {}
756 /// \brief Creates directive with a list of \a Clauses.
758 /// \param C AST context.
759 /// \param StartLoc Starting location of the directive kind.
760 /// \param EndLoc Ending Location of the directive.
761 /// \param Clauses List of clauses.
762 /// \param AssociatedStmt Statement, associated with the directive.
764 static OMPParallelSectionsDirective *
765 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
766 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt);
768 /// \brief Creates an empty directive with the place for \a NumClauses
771 /// \param C AST context.
772 /// \param NumClauses Number of clauses.
774 static OMPParallelSectionsDirective *
775 CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell);
777 static bool classof(const Stmt *T) {
778 return T->getStmtClass() == OMPParallelSectionsDirectiveClass;
782 /// \brief This represents '#pragma omp task' directive.
785 /// #pragma omp task private(a,b) final(d)
787 /// In this example directive '#pragma omp task' has clauses 'private' with the
788 /// variables 'a' and 'b' and 'final' with condition 'd'.
790 class OMPTaskDirective : public OMPExecutableDirective {
791 friend class ASTStmtReader;
792 /// \brief Build directive with the given start and end location.
794 /// \param StartLoc Starting location of the directive kind.
795 /// \param EndLoc Ending location of the directive.
796 /// \param NumClauses Number of clauses.
798 OMPTaskDirective(SourceLocation StartLoc, SourceLocation EndLoc,
800 : OMPExecutableDirective(this, OMPTaskDirectiveClass, OMPD_task, StartLoc,
801 EndLoc, NumClauses, 1) {}
803 /// \brief Build an empty directive.
805 /// \param NumClauses Number of clauses.
807 explicit OMPTaskDirective(unsigned NumClauses)
808 : OMPExecutableDirective(this, OMPTaskDirectiveClass, OMPD_task,
809 SourceLocation(), SourceLocation(), NumClauses,
813 /// \brief Creates directive with a list of \a Clauses.
815 /// \param C AST context.
816 /// \param StartLoc Starting location of the directive kind.
817 /// \param EndLoc Ending Location of the directive.
818 /// \param Clauses List of clauses.
819 /// \param AssociatedStmt Statement, associated with the directive.
821 static OMPTaskDirective *Create(const ASTContext &C, SourceLocation StartLoc,
822 SourceLocation EndLoc,
823 ArrayRef<OMPClause *> Clauses,
824 Stmt *AssociatedStmt);
826 /// \brief Creates an empty directive with the place for \a NumClauses
829 /// \param C AST context.
830 /// \param NumClauses Number of clauses.
832 static OMPTaskDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
835 static bool classof(const Stmt *T) {
836 return T->getStmtClass() == OMPTaskDirectiveClass;
840 /// \brief This represents '#pragma omp taskyield' directive.
843 /// #pragma omp taskyield
846 class OMPTaskyieldDirective : public OMPExecutableDirective {
847 friend class ASTStmtReader;
848 /// \brief Build directive with the given start and end location.
850 /// \param StartLoc Starting location of the directive kind.
851 /// \param EndLoc Ending location of the directive.
853 OMPTaskyieldDirective(SourceLocation StartLoc, SourceLocation EndLoc)
854 : OMPExecutableDirective(this, OMPTaskyieldDirectiveClass, OMPD_taskyield,
855 StartLoc, EndLoc, 0, 0) {}
857 /// \brief Build an empty directive.
859 explicit OMPTaskyieldDirective()
860 : OMPExecutableDirective(this, OMPTaskyieldDirectiveClass, OMPD_taskyield,
861 SourceLocation(), SourceLocation(), 0, 0) {}
864 /// \brief Creates directive.
866 /// \param C AST context.
867 /// \param StartLoc Starting location of the directive kind.
868 /// \param EndLoc Ending Location of the directive.
870 static OMPTaskyieldDirective *
871 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
873 /// \brief Creates an empty directive.
875 /// \param C AST context.
877 static OMPTaskyieldDirective *CreateEmpty(const ASTContext &C, EmptyShell);
879 static bool classof(const Stmt *T) {
880 return T->getStmtClass() == OMPTaskyieldDirectiveClass;
884 /// \brief This represents '#pragma omp barrier' directive.
887 /// #pragma omp barrier
890 class OMPBarrierDirective : public OMPExecutableDirective {
891 friend class ASTStmtReader;
892 /// \brief Build directive with the given start and end location.
894 /// \param StartLoc Starting location of the directive kind.
895 /// \param EndLoc Ending location of the directive.
897 OMPBarrierDirective(SourceLocation StartLoc, SourceLocation EndLoc)
898 : OMPExecutableDirective(this, OMPBarrierDirectiveClass, OMPD_barrier,
899 StartLoc, EndLoc, 0, 0) {}
901 /// \brief Build an empty directive.
903 explicit OMPBarrierDirective()
904 : OMPExecutableDirective(this, OMPBarrierDirectiveClass, OMPD_barrier,
905 SourceLocation(), SourceLocation(), 0, 0) {}
908 /// \brief Creates directive.
910 /// \param C AST context.
911 /// \param StartLoc Starting location of the directive kind.
912 /// \param EndLoc Ending Location of the directive.
914 static OMPBarrierDirective *
915 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
917 /// \brief Creates an empty directive.
919 /// \param C AST context.
921 static OMPBarrierDirective *CreateEmpty(const ASTContext &C, EmptyShell);
923 static bool classof(const Stmt *T) {
924 return T->getStmtClass() == OMPBarrierDirectiveClass;
928 /// \brief This represents '#pragma omp taskwait' directive.
931 /// #pragma omp taskwait
934 class OMPTaskwaitDirective : public OMPExecutableDirective {
935 friend class ASTStmtReader;
936 /// \brief Build directive with the given start and end location.
938 /// \param StartLoc Starting location of the directive kind.
939 /// \param EndLoc Ending location of the directive.
941 OMPTaskwaitDirective(SourceLocation StartLoc, SourceLocation EndLoc)
942 : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, OMPD_taskwait,
943 StartLoc, EndLoc, 0, 0) {}
945 /// \brief Build an empty directive.
947 explicit OMPTaskwaitDirective()
948 : OMPExecutableDirective(this, OMPTaskwaitDirectiveClass, OMPD_taskwait,
949 SourceLocation(), SourceLocation(), 0, 0) {}
952 /// \brief Creates directive.
954 /// \param C AST context.
955 /// \param StartLoc Starting location of the directive kind.
956 /// \param EndLoc Ending Location of the directive.
958 static OMPTaskwaitDirective *
959 Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc);
961 /// \brief Creates an empty directive.
963 /// \param C AST context.
965 static OMPTaskwaitDirective *CreateEmpty(const ASTContext &C, EmptyShell);
967 static bool classof(const Stmt *T) {
968 return T->getStmtClass() == OMPTaskwaitDirectiveClass;
972 /// \brief This represents '#pragma omp flush' directive.
975 /// #pragma omp flush(a,b)
977 /// In this example directive '#pragma omp flush' has 2 arguments- variables 'a'
979 /// 'omp flush' directive does not have clauses but have an optional list of
980 /// variables to flush. This list of variables is stored within some fake clause
982 class OMPFlushDirective : public OMPExecutableDirective {
983 friend class ASTStmtReader;
984 /// \brief Build directive with the given start and end location.
986 /// \param StartLoc Starting location of the directive kind.
987 /// \param EndLoc Ending location of the directive.
988 /// \param NumClauses Number of clauses.
990 OMPFlushDirective(SourceLocation StartLoc, SourceLocation EndLoc,
992 : OMPExecutableDirective(this, OMPFlushDirectiveClass, OMPD_flush,
993 StartLoc, EndLoc, NumClauses, 0) {}
995 /// \brief Build an empty directive.
997 /// \param NumClauses Number of clauses.
999 explicit OMPFlushDirective(unsigned NumClauses)
1000 : OMPExecutableDirective(this, OMPFlushDirectiveClass, OMPD_flush,
1001 SourceLocation(), SourceLocation(), NumClauses,
1005 /// \brief Creates directive with a list of \a Clauses.
1007 /// \param C AST context.
1008 /// \param StartLoc Starting location of the directive kind.
1009 /// \param EndLoc Ending Location of the directive.
1010 /// \param Clauses List of clauses (only single OMPFlushClause clause is
1013 static OMPFlushDirective *Create(const ASTContext &C, SourceLocation StartLoc,
1014 SourceLocation EndLoc,
1015 ArrayRef<OMPClause *> Clauses);
1017 /// \brief Creates an empty directive with the place for \a NumClauses
1020 /// \param C AST context.
1021 /// \param NumClauses Number of clauses.
1023 static OMPFlushDirective *CreateEmpty(const ASTContext &C,
1024 unsigned NumClauses, EmptyShell);
1026 static bool classof(const Stmt *T) {
1027 return T->getStmtClass() == OMPFlushDirectiveClass;
1031 } // end namespace clang