From 37e594c79966900734dd1cc1bda3a9cafc48cd85 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Fri, 4 Mar 2016 07:21:16 +0000 Subject: [PATCH] [OPENMP] Simplify handling of clauses with postupdates, NFC. Clauses with post-update expressions always have pre-init statement. So OMPClauseWithPreInit now is the base for OMPClauseWithPostUpdate. llvm-svn: 262696 --- clang/include/clang/AST/OpenMPClause.h | 22 ++++++++++------------ clang/include/clang/AST/RecursiveASTVisitor.h | 3 +-- clang/lib/AST/StmtProfile.cpp | 3 +-- clang/lib/Serialization/ASTReaderStmt.cpp | 3 +-- clang/lib/Serialization/ASTWriterStmt.cpp | 3 +-- clang/tools/libclang/CIndex.cpp | 3 +-- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index 6b8e32b..baf2d89 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -80,7 +80,7 @@ protected: /// Set pre-initialization statement for the clause. void setPreInitStmt(Stmt *S) { PreInit = S; } OMPClauseWithPreInit(const OMPClause *This) : PreInit(nullptr) { - assert(get(This) && "get is not tuned."); + assert(get(This) && "get is not tuned for pre-init."); } public: @@ -94,15 +94,16 @@ public: /// Class that handles post-update expression for some clauses, like /// 'lastprivate', 'reduction' etc. -class OMPClauseWithPostUpdate { +class OMPClauseWithPostUpdate : public OMPClauseWithPreInit { friend class OMPClauseReader; /// Post-update expression for the clause. Expr *PostUpdate; protected: /// Set pre-initialization statement for the clause. void setPostUpdateExpr(Expr *S) { PostUpdate = S; } - OMPClauseWithPostUpdate(const OMPClause *This) : PostUpdate(nullptr) { - assert(get(This) && "get is not tuned."); + OMPClauseWithPostUpdate(const OMPClause *This) + : OMPClauseWithPreInit(This), PostUpdate(nullptr) { + assert(get(This) && "get is not tuned for post-update."); } public: @@ -1404,7 +1405,6 @@ public: /// with the variables 'a' and 'b'. class OMPLastprivateClause final : public OMPVarListClause, - public OMPClauseWithPreInit, public OMPClauseWithPostUpdate, private llvm::TrailingObjects { // There are 4 additional tail-allocated arrays at the end of the class: @@ -1439,7 +1439,7 @@ class OMPLastprivateClause final SourceLocation EndLoc, unsigned N) : OMPVarListClause(OMPC_lastprivate, StartLoc, LParenLoc, EndLoc, N), - OMPClauseWithPreInit(this), OMPClauseWithPostUpdate(this) {} + OMPClauseWithPostUpdate(this) {} /// \brief Build an empty clause. /// @@ -1449,7 +1449,7 @@ class OMPLastprivateClause final : OMPVarListClause( OMPC_lastprivate, SourceLocation(), SourceLocation(), SourceLocation(), N), - OMPClauseWithPreInit(this), OMPClauseWithPostUpdate(this) {} + OMPClauseWithPostUpdate(this) {} /// \brief Get the list of helper expressions for initialization of private /// copies for lastprivate variables. @@ -1665,7 +1665,6 @@ public: /// class OMPReductionClause final : public OMPVarListClause, - public OMPClauseWithPreInit, public OMPClauseWithPostUpdate, private llvm::TrailingObjects { friend TrailingObjects; @@ -1694,8 +1693,8 @@ class OMPReductionClause final const DeclarationNameInfo &NameInfo) : OMPVarListClause(OMPC_reduction, StartLoc, LParenLoc, EndLoc, N), - OMPClauseWithPreInit(this), OMPClauseWithPostUpdate(this), - ColonLoc(ColonLoc), QualifierLoc(QualifierLoc), NameInfo(NameInfo) {} + OMPClauseWithPostUpdate(this), ColonLoc(ColonLoc), + QualifierLoc(QualifierLoc), NameInfo(NameInfo) {} /// \brief Build an empty clause. /// @@ -1705,8 +1704,7 @@ class OMPReductionClause final : OMPVarListClause(OMPC_reduction, SourceLocation(), SourceLocation(), SourceLocation(), N), - OMPClauseWithPreInit(this), OMPClauseWithPostUpdate(this), ColonLoc(), - QualifierLoc(), NameInfo() {} + OMPClauseWithPostUpdate(this), ColonLoc(), QualifierLoc(), NameInfo() {} /// \brief Sets location of ':' symbol in clause. void setColonLoc(SourceLocation CL) { ColonLoc = CL; } diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 8f2fc1b..1426e3f 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2533,6 +2533,7 @@ bool RecursiveASTVisitor::VisitOMPClauseWithPreInit( template bool RecursiveASTVisitor::VisitOMPClauseWithPostUpdate( OMPClauseWithPostUpdate *Node) { + TRY_TO(VisitOMPClauseWithPreInit(Node)); TRY_TO(TraverseStmt(Node->getPostUpdateExpr())); return true; } @@ -2691,7 +2692,6 @@ template bool RecursiveASTVisitor::VisitOMPLastprivateClause( OMPLastprivateClause *C) { TRY_TO(VisitOMPClauseList(C)); - TRY_TO(VisitOMPClauseWithPreInit(C)); TRY_TO(VisitOMPClauseWithPostUpdate(C)); for (auto *E : C->private_copies()) { TRY_TO(TraverseStmt(E)); @@ -2778,7 +2778,6 @@ RecursiveASTVisitor::VisitOMPReductionClause(OMPReductionClause *C) { TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc())); TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo())); TRY_TO(VisitOMPClauseList(C)); - TRY_TO(VisitOMPClauseWithPreInit(C)); TRY_TO(VisitOMPClauseWithPostUpdate(C)); for (auto *E : C->privates()) { TRY_TO(TraverseStmt(E)); diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index c0da73d..442e32a 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -280,6 +280,7 @@ void OMPClauseProfiler::VistOMPClauseWithPreInit( void OMPClauseProfiler::VistOMPClauseWithPostUpdate( const OMPClauseWithPostUpdate *C) { + VistOMPClauseWithPreInit(C); if (auto *E = C->getPostUpdateExpr()) Profiler->VisitStmt(E); } @@ -378,7 +379,6 @@ OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) { void OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) { VisitOMPClauseList(C); - VistOMPClauseWithPreInit(C); VistOMPClauseWithPostUpdate(C); for (auto *E : C->source_exprs()) { Profiler->VisitStmt(E); @@ -399,7 +399,6 @@ void OMPClauseProfiler::VisitOMPReductionClause( C->getQualifierLoc().getNestedNameSpecifier()); Profiler->VisitName(C->getNameInfo().getName()); VisitOMPClauseList(C); - VistOMPClauseWithPreInit(C); VistOMPClauseWithPostUpdate(C); for (auto *E : C->privates()) { Profiler->VisitStmt(E); diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index 7eaeccf..dd4997b 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1898,6 +1898,7 @@ void OMPClauseReader::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { } void OMPClauseReader::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) { + VisitOMPClauseWithPreInit(C); C->setPostUpdateExpr(Reader->Reader.ReadSubExpr()); } @@ -2025,7 +2026,6 @@ void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { } void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) { - VisitOMPClauseWithPreInit(C); VisitOMPClauseWithPostUpdate(C); C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); unsigned NumVars = C->varlist_size(); @@ -2063,7 +2063,6 @@ void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) { } void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) { - VisitOMPClauseWithPreInit(C); VisitOMPClauseWithPostUpdate(C); C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); C->setColonLoc(Reader->ReadSourceLocation(Record, Idx)); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index 0cebc1d..ba2fd48 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1771,6 +1771,7 @@ void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { } void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) { + VisitOMPClauseWithPreInit(C); Writer->Writer.AddStmt(C->getPostUpdateExpr()); } @@ -1887,7 +1888,6 @@ void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) { Record.push_back(C->varlist_size()); - VisitOMPClauseWithPreInit(C); VisitOMPClauseWithPostUpdate(C); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); for (auto *VE : C->varlists()) @@ -1911,7 +1911,6 @@ void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) { void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) { Record.push_back(C->varlist_size()); - VisitOMPClauseWithPreInit(C); VisitOMPClauseWithPostUpdate(C); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); Writer->Writer.AddSourceLocation(C->getColonLoc(), Record); diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 5741eea..5a7af9d 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2041,6 +2041,7 @@ void OMPClauseEnqueue::VisitOMPClauseWithPreInit( void OMPClauseEnqueue::VisitOMPClauseWithPostUpdate( const OMPClauseWithPostUpdate *C) { + VisitOMPClauseWithPreInit(C); Visitor->AddStmt(C->getPostUpdateExpr()); } @@ -2158,7 +2159,6 @@ void OMPClauseEnqueue::VisitOMPFirstprivateClause( void OMPClauseEnqueue::VisitOMPLastprivateClause( const OMPLastprivateClause *C) { VisitOMPClauseList(C); - VisitOMPClauseWithPreInit(C); VisitOMPClauseWithPostUpdate(C); for (auto *E : C->private_copies()) { Visitor->AddStmt(E); @@ -2178,7 +2178,6 @@ void OMPClauseEnqueue::VisitOMPSharedClause(const OMPSharedClause *C) { } void OMPClauseEnqueue::VisitOMPReductionClause(const OMPReductionClause *C) { VisitOMPClauseList(C); - VisitOMPClauseWithPreInit(C); VisitOMPClauseWithPostUpdate(C); for (auto *E : C->privates()) { Visitor->AddStmt(E); -- 2.7.4