From: Alexey Bataev Date: Wed, 9 Jul 2014 08:00:46 +0000 (+0000) Subject: [OPENMP] Improved code of DataRecursiveASTVisitor and RecursiveASTVisitor for OpenMP... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69efdd8cc883e1d51b00974550feabf89ffe0110;p=platform%2Fupstream%2Fllvm.git [OPENMP] Improved code of DataRecursiveASTVisitor and RecursiveASTVisitor for OpenMP constructs per Tobias Grosser comments. llvm-svn: 212592 --- diff --git a/clang/include/clang/AST/DataRecursiveASTVisitor.h b/clang/include/clang/AST/DataRecursiveASTVisitor.h index 02ce301..5a0e974 100644 --- a/clang/include/clang/AST/DataRecursiveASTVisitor.h +++ b/clang/include/clang/AST/DataRecursiveASTVisitor.h @@ -423,12 +423,12 @@ private: bool TraverseDeclContextHelper(DeclContext *DC); bool TraverseFunctionHelper(FunctionDecl *D); bool TraverseVarHelper(VarDecl *D); - bool TraverseOMPClause(OMPClause *C); bool TraverseOMPExecutableDirective(OMPExecutableDirective *S); + bool TraverseOMPClause(OMPClause *C); #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C); #include "clang/Basic/OpenMPKinds.def" /// \brief Process clauses with list of variables. - template void VisitOMPClauseList(T *Node); + template bool VisitOMPClauseList(T *Node); typedef SmallVector StmtsTy; typedef SmallVector QueuesTy; @@ -2273,53 +2273,34 @@ DEF_TRAVERSE_STMT(AsTypeExpr, {}) template bool RecursiveASTVisitor::TraverseOMPExecutableDirective( OMPExecutableDirective *S) { - ArrayRef Clauses = S->clauses(); - for (ArrayRef::iterator I = Clauses.begin(), E = Clauses.end(); - I != E; ++I) - if (!TraverseOMPClause(*I)) - return false; + for (auto *C : S->clauses()) + TRY_TO(TraverseOMPClause(C)); return true; } -DEF_TRAVERSE_STMT(OMPParallelDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPParallelDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPSimdDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPSimdDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPForDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPForDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPSectionsDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPSectionsDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPSectionDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPSectionDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPSingleDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPSingleDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPParallelForDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPParallelForDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPParallelSectionsDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPParallelSectionsDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) // OpenMP clauses. template @@ -2329,9 +2310,11 @@ bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { switch (C->getClauseKind()) { #define OPENMP_CLAUSE(Name, Class) \ case OMPC_##Name: \ - return getDerived().Visit##Class(static_cast(C)); + TRY_TO(Visit##Class(static_cast(C))); \ + break; #include "clang/Basic/OpenMPKinds.def" - default: + case OMPC_threadprivate: + case OMPC_unknown: break; } return true; @@ -2339,45 +2322,44 @@ bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { template bool RecursiveASTVisitor::VisitOMPIfClause(OMPIfClause *C) { - TraverseStmt(C->getCondition()); + TRY_TO(TraverseStmt(C->getCondition())); return true; } template bool RecursiveASTVisitor::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { - TraverseStmt(C->getNumThreads()); + TRY_TO(TraverseStmt(C->getNumThreads())); return true; } template bool RecursiveASTVisitor::VisitOMPSafelenClause(OMPSafelenClause *C) { - TraverseStmt(C->getSafelen()); + TRY_TO(TraverseStmt(C->getSafelen())); return true; } template bool RecursiveASTVisitor::VisitOMPCollapseClause(OMPCollapseClause *C) { - TraverseStmt(C->getNumForLoops()); + TRY_TO(TraverseStmt(C->getNumForLoops())); return true; } template -bool RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *C) { +bool RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *) { return true; } template -bool -RecursiveASTVisitor::VisitOMPProcBindClause(OMPProcBindClause *C) { +bool RecursiveASTVisitor::VisitOMPProcBindClause(OMPProcBindClause *) { return true; } template bool RecursiveASTVisitor::VisitOMPScheduleClause(OMPScheduleClause *C) { - TraverseStmt(C->getChunkSize()); + TRY_TO(TraverseStmt(C->getChunkSize())); return true; } @@ -2393,61 +2375,62 @@ bool RecursiveASTVisitor::VisitOMPNowaitClause(OMPNowaitClause *) { template template -void RecursiveASTVisitor::VisitOMPClauseList(T *Node) { - for (auto *I : Node->varlists()) - TraverseStmt(I); +bool RecursiveASTVisitor::VisitOMPClauseList(T *Node) { + for (auto *E : Node->varlists()) + TRY_TO(TraverseStmt(E)); + return true; } template bool RecursiveASTVisitor::VisitOMPPrivateClause(OMPPrivateClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPFirstprivateClause( OMPFirstprivateClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPLastprivateClause( OMPLastprivateClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPSharedClause(OMPSharedClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPLinearClause(OMPLinearClause *C) { - VisitOMPClauseList(C); - TraverseStmt(C->getStep()); + TRY_TO(TraverseStmt(C->getStep())); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPAlignedClause(OMPAlignedClause *C) { - VisitOMPClauseList(C); - TraverseStmt(C->getAlignment()); + TRY_TO(TraverseStmt(C->getAlignment())); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPCopyinClause(OMPCopyinClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPCopyprivateClause( OMPCopyprivateClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } @@ -2456,7 +2439,7 @@ bool RecursiveASTVisitor::VisitOMPReductionClause(OMPReductionClause *C) { TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc())); TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo())); - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 77a34e5..5e7d0b8 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -428,12 +428,12 @@ private: bool TraverseDeclContextHelper(DeclContext *DC); bool TraverseFunctionHelper(FunctionDecl *D); bool TraverseVarHelper(VarDecl *D); - bool TraverseOMPClause(OMPClause *C); bool TraverseOMPExecutableDirective(OMPExecutableDirective *S); + bool TraverseOMPClause(OMPClause *C); #define OPENMP_CLAUSE(Name, Class) bool Visit##Class(Class *C); #include "clang/Basic/OpenMPKinds.def" /// \brief Process clauses with list of variables. - template void VisitOMPClauseList(T *Node); + template bool VisitOMPClauseList(T *Node); struct EnqueueJob { Stmt *S; @@ -2295,53 +2295,34 @@ DEF_TRAVERSE_STMT(AsTypeExpr, {}) template bool RecursiveASTVisitor::TraverseOMPExecutableDirective( OMPExecutableDirective *S) { - ArrayRef Clauses = S->clauses(); - for (ArrayRef::iterator I = Clauses.begin(), E = Clauses.end(); - I != E; ++I) - if (!TraverseOMPClause(*I)) - return false; + for (auto *C : S->clauses()) + TRY_TO(TraverseOMPClause(C)); return true; } -DEF_TRAVERSE_STMT(OMPParallelDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPParallelDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPSimdDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPSimdDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPForDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPForDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPSectionsDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPSectionsDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPSectionDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPSectionDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPSingleDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPSingleDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPParallelForDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPParallelForDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) -DEF_TRAVERSE_STMT(OMPParallelSectionsDirective, { - if (!TraverseOMPExecutableDirective(S)) - return false; -}) +DEF_TRAVERSE_STMT(OMPParallelSectionsDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) // OpenMP clauses. template @@ -2351,9 +2332,11 @@ bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { switch (C->getClauseKind()) { #define OPENMP_CLAUSE(Name, Class) \ case OMPC_##Name: \ - return getDerived().Visit##Class(static_cast(C)); + TRY_TO(Visit##Class(static_cast(C))); \ + break; #include "clang/Basic/OpenMPKinds.def" - default: + case OMPC_threadprivate: + case OMPC_unknown: break; } return true; @@ -2361,45 +2344,44 @@ bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { template bool RecursiveASTVisitor::VisitOMPIfClause(OMPIfClause *C) { - TraverseStmt(C->getCondition()); + TRY_TO(TraverseStmt(C->getCondition())); return true; } template bool RecursiveASTVisitor::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { - TraverseStmt(C->getNumThreads()); + TRY_TO(TraverseStmt(C->getNumThreads())); return true; } template bool RecursiveASTVisitor::VisitOMPSafelenClause(OMPSafelenClause *C) { - TraverseStmt(C->getSafelen()); + TRY_TO(TraverseStmt(C->getSafelen())); return true; } template bool RecursiveASTVisitor::VisitOMPCollapseClause(OMPCollapseClause *C) { - TraverseStmt(C->getNumForLoops()); + TRY_TO(TraverseStmt(C->getNumForLoops())); return true; } template -bool RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *C) { +bool RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *) { return true; } template -bool -RecursiveASTVisitor::VisitOMPProcBindClause(OMPProcBindClause *C) { +bool RecursiveASTVisitor::VisitOMPProcBindClause(OMPProcBindClause *) { return true; } template bool RecursiveASTVisitor::VisitOMPScheduleClause(OMPScheduleClause *C) { - TraverseStmt(C->getChunkSize()); + TRY_TO(TraverseStmt(C->getChunkSize())); return true; } @@ -2415,61 +2397,62 @@ bool RecursiveASTVisitor::VisitOMPNowaitClause(OMPNowaitClause *) { template template -void RecursiveASTVisitor::VisitOMPClauseList(T *Node) { - for (auto *I : Node->varlists()) - TraverseStmt(I); +bool RecursiveASTVisitor::VisitOMPClauseList(T *Node) { + for (auto *E : Node->varlists()) + TRY_TO(TraverseStmt(E)); + return true; } template bool RecursiveASTVisitor::VisitOMPPrivateClause(OMPPrivateClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPFirstprivateClause( OMPFirstprivateClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPLastprivateClause( OMPLastprivateClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPSharedClause(OMPSharedClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPLinearClause(OMPLinearClause *C) { - VisitOMPClauseList(C); - TraverseStmt(C->getStep()); + TRY_TO(TraverseStmt(C->getStep())); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPAlignedClause(OMPAlignedClause *C) { - VisitOMPClauseList(C); - TraverseStmt(C->getAlignment()); + TRY_TO(TraverseStmt(C->getAlignment())); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPCopyinClause(OMPCopyinClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } template bool RecursiveASTVisitor::VisitOMPCopyprivateClause( OMPCopyprivateClause *C) { - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; } @@ -2478,7 +2461,7 @@ bool RecursiveASTVisitor::VisitOMPReductionClause(OMPReductionClause *C) { TRY_TO(TraverseNestedNameSpecifierLoc(C->getQualifierLoc())); TRY_TO(TraverseDeclarationNameInfo(C->getNameInfo())); - VisitOMPClauseList(C); + TRY_TO(VisitOMPClauseList(C)); return true; }