From c814cd660a16bd49b5c9d09b73a56e8b60e99605 Mon Sep 17 00:00:00 2001 From: Alexander Musman Date: Thu, 27 Mar 2014 15:14:18 +0000 Subject: [PATCH] [OPENMP] OMPExecutableDirective re-factoring Store the number of clauses and children of OMPExecutableDirective and dynamically compute the locations of corresponding arrays. http://llvm-reviews.chandlerc.com/D2977 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204933 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/StmtOpenMP.h | 52 ++++++++++++++++++++-------------- lib/AST/Stmt.cpp | 4 +-- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/include/clang/AST/StmtOpenMP.h b/include/clang/AST/StmtOpenMP.h index 5e1a04b042..9432eaf027 100644 --- a/include/clang/AST/StmtOpenMP.h +++ b/include/clang/AST/StmtOpenMP.h @@ -38,10 +38,22 @@ class OMPExecutableDirective : public Stmt { SourceLocation StartLoc; /// \brief Ending location of the directive. SourceLocation EndLoc; - /// \brief Pointer to the list of clauses. - llvm::MutableArrayRef Clauses; - /// \brief Associated statement (if any) and expressions. - llvm::MutableArrayRef StmtAndExpressions; + /// \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 getClauses() { + OMPClause **ClauseStorage = reinterpret_cast( + reinterpret_cast(this) + ClausesOffset); + return llvm::MutableArrayRef(ClauseStorage, NumClauses); + } protected: /// \brief Build instance of directive of class \a K. @@ -54,15 +66,11 @@ protected: template OMPExecutableDirective(const T *, StmtClass SC, OpenMPDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc, - unsigned NumClauses, unsigned NumberOfExpressions) + unsigned NumClauses, unsigned NumChildren) : Stmt(SC), Kind(K), StartLoc(StartLoc), EndLoc(EndLoc), - Clauses(reinterpret_cast( - reinterpret_cast(this) + - llvm::RoundUpToAlignment(sizeof(T), - llvm::alignOf())), - NumClauses), - StmtAndExpressions(reinterpret_cast(Clauses.end()), - NumberOfExpressions) {} + NumClauses(NumClauses), NumChildren(NumChildren), + ClausesOffset(llvm::RoundUpToAlignment(sizeof(T), + llvm::alignOf())) {} /// \brief Sets the list of variables for this clause. /// @@ -74,7 +82,7 @@ protected: /// /// /param S Associated statement. /// - void setAssociatedStmt(Stmt *S) { StmtAndExpressions[0] = S; } + void setAssociatedStmt(Stmt *S) { *child_begin() = S; } public: /// \brief Returns starting location of directive kind. @@ -94,19 +102,16 @@ public: void setLocEnd(SourceLocation Loc) { EndLoc = Loc; } /// \brief Get number of clauses. - unsigned getNumClauses() const { return Clauses.size(); } + unsigned getNumClauses() const { return NumClauses; } /// \brief Returns specified clause. /// /// \param i Number of clause. /// - OMPClause *getClause(unsigned i) const { - assert(i < Clauses.size() && "index out of bound!"); - return Clauses[i]; - } + OMPClause *getClause(unsigned i) const { return clauses()[i]; } /// \brief Returns statement associated with the directive. - Stmt *getAssociatedStmt() const { return StmtAndExpressions[0]; } + Stmt *getAssociatedStmt() const { return const_cast(*child_begin()); } OpenMPDirectiveKind getDirectiveKind() const { return Kind; } @@ -116,12 +121,15 @@ public: } child_range children() { - return child_range(StmtAndExpressions.begin(), StmtAndExpressions.end()); + Stmt **ChildStorage = reinterpret_cast(getClauses().end()); + return child_range(ChildStorage, ChildStorage + NumChildren); } - ArrayRef clauses() { return Clauses; } + ArrayRef clauses() { return getClauses(); } - ArrayRef clauses() const { return Clauses; } + ArrayRef clauses() const { + return const_cast(this)->getClauses(); + } }; /// \brief This represents '#pragma omp parallel' directive. diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 4c6318cc6e..8da7956aed 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -1193,9 +1193,9 @@ OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, } void OMPExecutableDirective::setClauses(ArrayRef Clauses) { - assert(Clauses.size() == this->Clauses.size() && + assert(Clauses.size() == getNumClauses() && "Number of clauses is not the same as the preallocated buffer"); - std::copy(Clauses.begin(), Clauses.end(), this->Clauses.begin()); + std::copy(Clauses.begin(), Clauses.end(), getClauses().begin()); } OMPParallelDirective *OMPParallelDirective::Create( -- 2.50.1