| //===- StmtOpenMP.h - Classes for OpenMP directives ------------*- C++ -*-===// |
| // |
| // The LLVM Compiler Infrastructure |
| // |
| // This file is distributed under the University of Illinois Open Source |
| // License. See LICENSE.TXT for details. |
| // |
| //===----------------------------------------------------------------------===// |
| /// \file |
| /// \brief This file defines OpenMP AST classes for executable directives and |
| /// clauses. |
| /// |
| //===----------------------------------------------------------------------===// |
| |
| #ifndef LLVM_CLANG_AST_STMTOPENMP_H |
| #define LLVM_CLANG_AST_STMTOPENMP_H |
| |
| #include "clang/AST/Expr.h" |
| #include "clang/AST/OpenMPClause.h" |
| #include "clang/AST/Stmt.h" |
| #include "clang/Basic/OpenMPKinds.h" |
| #include "clang/Basic/SourceLocation.h" |
| |
| namespace clang { |
| |
| //===----------------------------------------------------------------------===// |
| // AST classes for directives. |
| //===----------------------------------------------------------------------===// |
| |
| /// \brief This is a basic class for representing single OpenMP executable |
| /// directive. |
| /// |
| class OMPExecutableDirective : public Stmt { |
| friend class ASTStmtReader; |
| /// \brief Kind of the directive. |
| OpenMPDirectiveKind Kind; |
| /// \brief Starting location of the directive (directive keyword). |
| SourceLocation StartLoc; |
| /// \brief Ending location of the directive. |
| SourceLocation EndLoc; |
| /// \brief Numbers of clauses. |
| const unsigned NumClauses; |
| /// \brief Number of child expressions/stmts. |
| const unsigned NumChildren; |
| /// \brief Offset from this to the start of clauses. |
| /// There are NumClauses pointers to clauses, they are followed by |
| /// NumChildren pointers to child stmts/exprs (if the directive type |
| /// requires an associated stmt, then it has to be the first of them). |
| const unsigned ClausesOffset; |
| |
| /// \brief Get the clauses storage. |
| llvm::MutableArrayRef<OMPClause *> getClauses() { |
| OMPClause **ClauseStorage = reinterpret_cast<OMPClause **>( |
| reinterpret_cast<char *>(this) + ClausesOffset); |
| return llvm::MutableArrayRef<OMPClause *>(ClauseStorage, NumClauses); |
| } |
| |
| protected: |
| /// \brief Build instance of directive of class \a K. |
| /// |
| /// \param SC Statement class. |
| /// \param K Kind of OpenMP directive. |
| /// \param StartLoc Starting location of the directive (directive keyword). |
| /// \param EndLoc Ending location of the directive. |
| /// |
| template <typename T> |
| OMPExecutableDirective(const T *, StmtClass SC, OpenMPDirectiveKind K, |
| SourceLocation StartLoc, SourceLocation EndLoc, |
| unsigned NumClauses, unsigned NumChildren) |
| : Stmt(SC), Kind(K), StartLoc(StartLoc), EndLoc(EndLoc), |
| NumClauses(NumClauses), NumChildren(NumChildren), |
| ClausesOffset(llvm::RoundUpToAlignment(sizeof(T), |
| llvm::alignOf<OMPClause *>())) {} |
| |
| /// \brief Sets the list of variables for this clause. |
| /// |
| /// \param Clauses The list of clauses for the directive. |
| /// |
| void setClauses(ArrayRef<OMPClause *> Clauses); |
| |
| /// \brief Set the associated statement for the directive. |
| /// |
| /// /param S Associated statement. |
| /// |
| void setAssociatedStmt(Stmt *S) { *child_begin() = S; } |
| |
| public: |
| /// \brief Returns starting location of directive kind. |
| SourceLocation getLocStart() const { return StartLoc; } |
| /// \brief Returns ending location of directive. |
| SourceLocation getLocEnd() const { return EndLoc; } |
| |
| /// \brief Set starting location of directive kind. |
| /// |
| /// \param Loc New starting location of directive. |
| /// |
| void setLocStart(SourceLocation Loc) { StartLoc = Loc; } |
| /// \brief Set ending location of directive. |
| /// |
| /// \param Loc New ending location of directive. |
| /// |
| void setLocEnd(SourceLocation Loc) { EndLoc = Loc; } |
| |
| /// \brief Get number of clauses. |
| unsigned getNumClauses() const { return NumClauses; } |
| |
| /// \brief Returns specified clause. |
| /// |
| /// \param i Number of clause. |
| /// |
| OMPClause *getClause(unsigned i) const { return clauses()[i]; } |
| |
| /// \brief Returns statement associated with the directive. |
| Stmt *getAssociatedStmt() const { return const_cast<Stmt *>(*child_begin()); } |
| |
| OpenMPDirectiveKind getDirectiveKind() const { return Kind; } |
| |
| static bool classof(const Stmt *S) { |
| return S->getStmtClass() >= firstOMPExecutableDirectiveConstant && |
| S->getStmtClass() <= lastOMPExecutableDirectiveConstant; |
| } |
| |
| child_range children() { |
| Stmt **ChildStorage = reinterpret_cast<Stmt **>(getClauses().end()); |
| return child_range(ChildStorage, ChildStorage + NumChildren); |
| } |
| |
| ArrayRef<OMPClause *> clauses() { return getClauses(); } |
| |
| ArrayRef<OMPClause *> clauses() const { |
| return const_cast<OMPExecutableDirective *>(this)->getClauses(); |
| } |
| }; |
| |
| /// \brief This represents '#pragma omp parallel' directive. |
| /// |
| /// \code |
| /// #pragma omp parallel private(a,b) reduction(+: c,d) |
| /// \endcode |
| /// In this example directive '#pragma omp parallel' has clauses 'private' |
| /// with the variables 'a' and 'b' and 'reduction' with operator '+' and |
| /// variables 'c' and 'd'. |
| /// |
| class OMPParallelDirective : public OMPExecutableDirective { |
| /// \brief Build directive with the given start and end location. |
| /// |
| /// \param StartLoc Starting location of the directive (directive keyword). |
| /// \param EndLoc Ending Location of the directive. |
| /// |
| OMPParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc, |
| unsigned NumClauses) |
| : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel, |
| StartLoc, EndLoc, NumClauses, 1) {} |
| |
| /// \brief Build an empty directive. |
| /// |
| /// \param NumClauses Number of clauses. |
| /// |
| explicit OMPParallelDirective(unsigned NumClauses) |
| : OMPExecutableDirective(this, OMPParallelDirectiveClass, OMPD_parallel, |
| SourceLocation(), SourceLocation(), NumClauses, |
| 1) {} |
| |
| public: |
| /// \brief Creates directive with a list of \a Clauses. |
| /// |
| /// \param C AST context. |
| /// \param StartLoc Starting location of the directive kind. |
| /// \param EndLoc Ending Location of the directive. |
| /// \param Clauses List of clauses. |
| /// \param AssociatedStmt Statement associated with the directive. |
| /// |
| static OMPParallelDirective * |
| Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); |
| |
| /// \brief Creates an empty directive with the place for \a N clauses. |
| /// |
| /// \param C AST context. |
| /// \param NumClauses Number of clauses. |
| /// |
| static OMPParallelDirective *CreateEmpty(const ASTContext &C, |
| unsigned NumClauses, EmptyShell); |
| |
| static bool classof(const Stmt *T) { |
| return T->getStmtClass() == OMPParallelDirectiveClass; |
| } |
| }; |
| |
| /// \brief This represents '#pragma omp simd' directive. |
| /// |
| /// \code |
| /// #pragma omp simd private(a,b) linear(i,j:s) reduction(+:c,d) |
| /// \endcode |
| /// In this example directive '#pragma omp simd' has clauses 'private' |
| /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and |
| /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'. |
| /// |
| class OMPSimdDirective : public OMPExecutableDirective { |
| friend class ASTStmtReader; |
| /// \brief Number of collapsed loops as specified by 'collapse' clause. |
| unsigned CollapsedNum; |
| /// \brief Build directive with the given start and end location. |
| /// |
| /// \param StartLoc Starting location of the directive kind. |
| /// \param EndLoc Ending location of the directive. |
| /// \param CollapsedNum Number of collapsed nested loops. |
| /// \param NumClauses Number of clauses. |
| /// |
| OMPSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, |
| unsigned CollapsedNum, unsigned NumClauses) |
| : OMPExecutableDirective(this, OMPSimdDirectiveClass, OMPD_simd, StartLoc, |
| EndLoc, NumClauses, 1), |
| CollapsedNum(CollapsedNum) {} |
| |
| /// \brief Build an empty directive. |
| /// |
| /// \param CollapsedNum Number of collapsed nested loops. |
| /// \param NumClauses Number of clauses. |
| /// |
| explicit OMPSimdDirective(unsigned CollapsedNum, unsigned NumClauses) |
| : OMPExecutableDirective(this, OMPSimdDirectiveClass, OMPD_simd, |
| SourceLocation(), SourceLocation(), NumClauses, |
| 1), |
| CollapsedNum(CollapsedNum) {} |
| |
| public: |
| /// \brief Creates directive with a list of \a Clauses. |
| /// |
| /// \param C AST context. |
| /// \param StartLoc Starting location of the directive kind. |
| /// \param EndLoc Ending Location of the directive. |
| /// \param Clauses List of clauses. |
| /// \param AssociatedStmt Statement, associated with the directive. |
| /// |
| static OMPSimdDirective *Create(const ASTContext &C, SourceLocation StartLoc, |
| SourceLocation EndLoc, |
| ArrayRef<OMPClause *> Clauses, |
| Stmt *AssociatedStmt); |
| |
| /// \brief Creates an empty directive with the place |
| /// for \a NumClauses clauses. |
| /// |
| /// \param C AST context. |
| /// \param CollapsedNum Number of collapsed nested loops. |
| /// \param NumClauses Number of clauses. |
| /// |
| static OMPSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, |
| unsigned CollapsedNum, EmptyShell); |
| |
| unsigned getCollapsedNumber() const { return CollapsedNum; } |
| |
| static bool classof(const Stmt *T) { |
| return T->getStmtClass() == OMPSimdDirectiveClass; |
| } |
| }; |
| |
| } // end namespace clang |
| |
| #endif |