From: Alexander Musman Date: Tue, 19 Aug 2014 11:27:13 +0000 (+0000) Subject: [OPENMP] Extract common superclass from all the loop directives. No functional change... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4e6916abeeba3237870fb8821004099a83876e81;p=clang [OPENMP] Extract common superclass from all the loop directives. No functional changes (having common superclass is convenient for future loop directives CodeGen implementation) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215975 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 13a6dec759..1039ccdade 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -424,6 +424,7 @@ private: bool TraverseFunctionHelper(FunctionDecl *D); bool TraverseVarHelper(VarDecl *D); bool TraverseOMPExecutableDirective(OMPExecutableDirective *S); + bool TraverseOMPLoopDirective(OMPLoopDirective *S); bool TraverseOMPClause(OMPClause *C); #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C); #include "clang/Basic/OpenMPKinds.def" @@ -2279,6 +2280,12 @@ bool RecursiveASTVisitor::TraverseOMPExecutableDirective( return true; } +template +bool +RecursiveASTVisitor::TraverseOMPLoopDirective(OMPLoopDirective *S) { + return TraverseOMPExecutableDirective(S); +} + DEF_TRAVERSE_STMT(OMPParallelDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index ca66631c9b..81b0611f9d 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -429,6 +429,7 @@ private: bool TraverseFunctionHelper(FunctionDecl *D); bool TraverseVarHelper(VarDecl *D); bool TraverseOMPExecutableDirective(OMPExecutableDirective *S); + bool TraverseOMPLoopDirective(OMPLoopDirective *S); bool TraverseOMPClause(OMPClause *C); #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C); #include "clang/Basic/OpenMPKinds.def" @@ -2301,6 +2302,12 @@ bool RecursiveASTVisitor::TraverseOMPExecutableDirective( return true; } +template +bool +RecursiveASTVisitor::TraverseOMPLoopDirective(OMPLoopDirective *S) { + return TraverseOMPExecutableDirective(S); +} + DEF_TRAVERSE_STMT(OMPParallelDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) diff --git a/include/clang/AST/StmtOpenMP.h b/include/clang/AST/StmtOpenMP.h index 381fbd3f0d..9ba4b2853f 100644 --- a/include/clang/AST/StmtOpenMP.h +++ b/include/clang/AST/StmtOpenMP.h @@ -238,6 +238,45 @@ public: } }; +/// \brief This is a common base class for loop directives ('omp simd', 'omp +/// for', 'omp for simd' etc.). It is responsible for the loop code generation. +/// +class OMPLoopDirective : public OMPExecutableDirective { + friend class ASTStmtReader; + /// \brief Number of collapsed loops as specified by 'collapse' clause. + unsigned CollapsedNum; + +protected: + /// \brief Build instance of loop directive of class \a Kind. + /// + /// \param SC Statement class. + /// \param Kind Kind of OpenMP directive. + /// \param StartLoc Starting location of the directive (directive keyword). + /// \param EndLoc Ending location of the directive. + /// \param CollapsedNum Number of collapsed loops from 'collapse' clause. + /// \param NumClauses Number of clauses. + /// \param NumSpecialChildren Number of additional directive-specific stmts. + /// + template + OMPLoopDirective(const T *That, StmtClass SC, OpenMPDirectiveKind Kind, + SourceLocation StartLoc, SourceLocation EndLoc, + unsigned CollapsedNum, unsigned NumClauses, + unsigned NumSpecialChildren = 0) + : OMPExecutableDirective(That, SC, Kind, StartLoc, EndLoc, NumClauses, + 1 + NumSpecialChildren), + CollapsedNum(CollapsedNum) {} + +public: + /// \brief Get number of collapsed loops. + unsigned getCollapsedNumber() const { return CollapsedNum; } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPSimdDirectiveClass || + T->getStmtClass() == OMPForDirectiveClass || + T->getStmtClass() == OMPParallelForDirectiveClass; + } +}; + /// \brief This represents '#pragma omp simd' directive. /// /// \code @@ -247,10 +286,8 @@ public: /// 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 { +class OMPSimdDirective : public OMPLoopDirective { 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. @@ -260,9 +297,8 @@ class OMPSimdDirective : public OMPExecutableDirective { /// OMPSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, unsigned NumClauses) - : OMPExecutableDirective(this, OMPSimdDirectiveClass, OMPD_simd, StartLoc, - EndLoc, NumClauses, 1), - CollapsedNum(CollapsedNum) {} + : OMPLoopDirective(this, OMPSimdDirectiveClass, OMPD_simd, StartLoc, + EndLoc, CollapsedNum, NumClauses) {} /// \brief Build an empty directive. /// @@ -270,11 +306,9 @@ class OMPSimdDirective : public OMPExecutableDirective { /// \param NumClauses Number of clauses. /// explicit OMPSimdDirective(unsigned CollapsedNum, unsigned NumClauses) - : OMPExecutableDirective(this, OMPSimdDirectiveClass, OMPD_simd, - SourceLocation(), SourceLocation(), NumClauses, - 1), - CollapsedNum(CollapsedNum) {} - + : OMPLoopDirective(this, OMPSimdDirectiveClass, OMPD_simd, + SourceLocation(), SourceLocation(), CollapsedNum, + NumClauses) {} public: /// \brief Creates directive with a list of \a Clauses. /// @@ -300,8 +334,6 @@ public: 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; } @@ -316,10 +348,8 @@ public: /// variables 'a' and 'b' and 'reduction' with operator '+' and variables 'c' /// and 'd'. /// -class OMPForDirective : public OMPExecutableDirective { +class OMPForDirective : public OMPLoopDirective { 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. @@ -329,9 +359,8 @@ class OMPForDirective : public OMPExecutableDirective { /// OMPForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, unsigned NumClauses) - : OMPExecutableDirective(this, OMPForDirectiveClass, OMPD_for, StartLoc, - EndLoc, NumClauses, 1), - CollapsedNum(CollapsedNum) {} + : OMPLoopDirective(this, OMPForDirectiveClass, OMPD_for, StartLoc, EndLoc, + CollapsedNum, NumClauses) {} /// \brief Build an empty directive. /// @@ -339,10 +368,8 @@ class OMPForDirective : public OMPExecutableDirective { /// \param NumClauses Number of clauses. /// explicit OMPForDirective(unsigned CollapsedNum, unsigned NumClauses) - : OMPExecutableDirective(this, OMPForDirectiveClass, OMPD_for, - SourceLocation(), SourceLocation(), NumClauses, - 1), - CollapsedNum(CollapsedNum) {} + : OMPLoopDirective(this, OMPForDirectiveClass, OMPD_for, SourceLocation(), + SourceLocation(), CollapsedNum, NumClauses) {} public: /// \brief Creates directive with a list of \a Clauses. @@ -369,8 +396,6 @@ public: static OMPForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); - unsigned getCollapsedNumber() const { return CollapsedNum; } - static bool classof(const Stmt *T) { return T->getStmtClass() == OMPForDirectiveClass; } @@ -657,10 +682,8 @@ public: /// with the variables 'a' and 'b' and 'reduction' with operator '+' and /// variables 'c' and 'd'. /// -class OMPParallelForDirective : public OMPExecutableDirective { +class OMPParallelForDirective : public OMPLoopDirective { 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. @@ -670,10 +693,8 @@ class OMPParallelForDirective : public OMPExecutableDirective { /// OMPParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, unsigned NumClauses) - : OMPExecutableDirective(this, OMPParallelForDirectiveClass, - OMPD_parallel_for, StartLoc, EndLoc, NumClauses, - 1), - CollapsedNum(CollapsedNum) {} + : OMPLoopDirective(this, OMPParallelForDirectiveClass, OMPD_parallel_for, + StartLoc, EndLoc, CollapsedNum, NumClauses) {} /// \brief Build an empty directive. /// @@ -681,10 +702,9 @@ class OMPParallelForDirective : public OMPExecutableDirective { /// \param NumClauses Number of clauses. /// explicit OMPParallelForDirective(unsigned CollapsedNum, unsigned NumClauses) - : OMPExecutableDirective(this, OMPParallelForDirectiveClass, - OMPD_parallel_for, SourceLocation(), - SourceLocation(), NumClauses, 1), - CollapsedNum(CollapsedNum) {} + : OMPLoopDirective(this, OMPParallelForDirectiveClass, OMPD_parallel_for, + SourceLocation(), SourceLocation(), CollapsedNum, + NumClauses) {} public: /// \brief Creates directive with a list of \a Clauses. @@ -713,8 +733,6 @@ public: unsigned CollapsedNum, EmptyShell); - unsigned getCollapsedNumber() const { return CollapsedNum; } - static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelForDirectiveClass; } diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td index 1dc7e2fa63..44edb0639e 100644 --- a/include/clang/Basic/StmtNodes.td +++ b/include/clang/Basic/StmtNodes.td @@ -178,15 +178,16 @@ def AsTypeExpr : DStmt; // OpenMP Directives. def OMPExecutableDirective : Stmt<1>; +def OMPLoopDirective : DStmt; def OMPParallelDirective : DStmt; -def OMPSimdDirective : DStmt; -def OMPForDirective : DStmt; +def OMPSimdDirective : DStmt; +def OMPForDirective : DStmt; def OMPSectionsDirective : DStmt; def OMPSectionDirective : DStmt; def OMPSingleDirective : DStmt; def OMPMasterDirective : DStmt; def OMPCriticalDirective : DStmt; -def OMPParallelForDirective : DStmt; +def OMPParallelForDirective : DStmt; def OMPParallelSectionsDirective : DStmt; def OMPTaskDirective : DStmt; def OMPTaskyieldDirective : DStmt; diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 76c7843481..5550d6d97b 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -378,16 +378,20 @@ StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) { P.Visit(*I); } +void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) { + VisitOMPExecutableDirective(S); +} + void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { VisitOMPExecutableDirective(S); } void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) { - VisitOMPExecutableDirective(S); + VisitOMPLoopDirective(S); } void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) { - VisitOMPExecutableDirective(S); + VisitOMPLoopDirective(S); } void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) { @@ -413,7 +417,7 @@ void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) { void StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) { - VisitOMPExecutableDirective(S); + VisitOMPLoopDirective(S); } void StmtProfiler::VisitOMPParallelSectionsDirective( diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index c22bc3eff3..81fc79a550 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -1963,6 +1963,13 @@ void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) { E->setAssociatedStmt(Reader.ReadSubStmt()); } +void ASTStmtReader::VisitOMPLoopDirective(OMPLoopDirective *D) { + VisitStmt(D); + // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream. + Idx += 2; + VisitOMPExecutableDirective(D); +} + void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) { VisitStmt(D); // The NumClauses field was read in ReadStmtFromStream. @@ -1971,17 +1978,11 @@ void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) { } void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) { - VisitStmt(D); - // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream. - Idx += 2; - VisitOMPExecutableDirective(D); + VisitOMPLoopDirective(D); } void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) { - VisitStmt(D); - // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream. - Idx += 2; - VisitOMPExecutableDirective(D); + VisitOMPLoopDirective(D); } void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) { @@ -2015,10 +2016,7 @@ void ASTStmtReader::VisitOMPCriticalDirective(OMPCriticalDirective *D) { } void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) { - VisitStmt(D); - // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream. - Idx += 2; - VisitOMPExecutableDirective(D); + VisitOMPLoopDirective(D); } void ASTStmtReader::VisitOMPParallelSectionsDirective( diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index f77f4b947c..2cda8efa17 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -1842,26 +1842,27 @@ void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) { Writer.AddStmt(E->getAssociatedStmt()); } -void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) { +void ASTStmtWriter::VisitOMPLoopDirective(OMPLoopDirective *D) { VisitStmt(D); Record.push_back(D->getNumClauses()); + Record.push_back(D->getCollapsedNumber()); VisitOMPExecutableDirective(D); - Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE; } -void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) { +void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) { VisitStmt(D); Record.push_back(D->getNumClauses()); - Record.push_back(D->getCollapsedNumber()); VisitOMPExecutableDirective(D); + Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE; +} + +void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) { + VisitOMPLoopDirective(D); Code = serialization::STMT_OMP_SIMD_DIRECTIVE; } void ASTStmtWriter::VisitOMPForDirective(OMPForDirective *D) { - VisitStmt(D); - Record.push_back(D->getNumClauses()); - Record.push_back(D->getCollapsedNumber()); - VisitOMPExecutableDirective(D); + VisitOMPLoopDirective(D); Code = serialization::STMT_OMP_FOR_DIRECTIVE; } @@ -1899,10 +1900,7 @@ void ASTStmtWriter::VisitOMPCriticalDirective(OMPCriticalDirective *D) { } void ASTStmtWriter::VisitOMPParallelForDirective(OMPParallelForDirective *D) { - VisitStmt(D); - Record.push_back(D->getNumClauses()); - Record.push_back(D->getCollapsedNumber()); - VisitOMPExecutableDirective(D); + VisitOMPLoopDirective(D); Code = serialization::STMT_OMP_PARALLEL_FOR_DIRECTIVE; } diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 97a27591cf..83fd6c6ba6 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1860,6 +1860,7 @@ public: void VisitOpaqueValueExpr(const OpaqueValueExpr *E); void VisitLambdaExpr(const LambdaExpr *E); void VisitOMPExecutableDirective(const OMPExecutableDirective *D); + void VisitOMPLoopDirective(const OMPLoopDirective *D); void VisitOMPParallelDirective(const OMPParallelDirective *D); void VisitOMPSimdDirective(const OMPSimdDirective *D); void VisitOMPForDirective(const OMPForDirective *D); @@ -2325,16 +2326,20 @@ void EnqueueVisitor::VisitOMPExecutableDirective( EnqueueChildren(*I); } +void EnqueueVisitor::VisitOMPLoopDirective(const OMPLoopDirective *D) { + VisitOMPExecutableDirective(D); +} + void EnqueueVisitor::VisitOMPParallelDirective(const OMPParallelDirective *D) { VisitOMPExecutableDirective(D); } void EnqueueVisitor::VisitOMPSimdDirective(const OMPSimdDirective *D) { - VisitOMPExecutableDirective(D); + VisitOMPLoopDirective(D); } void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) { - VisitOMPExecutableDirective(D); + VisitOMPLoopDirective(D); } void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) { @@ -2360,7 +2365,7 @@ void EnqueueVisitor::VisitOMPCriticalDirective(const OMPCriticalDirective *D) { void EnqueueVisitor::VisitOMPParallelForDirective(const OMPParallelForDirective *D) { - VisitOMPExecutableDirective(D); + VisitOMPLoopDirective(D); } void EnqueueVisitor::VisitOMPParallelSectionsDirective(