Author: rsmith Date: Tue Nov 24 01:13:06 2015 New Revision: 253958 URL: http://llvm.org/viewvc/llvm-project?rev=253958&view=rev Log: Reduce the stack usage per recursive step when RecursiveASTVisitor cannot perform data recursion.
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=253958&r1=253957&r2=253958&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original) +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Nov 24 01:13:06 2015 @@ -471,28 +471,10 @@ private: /// \brief Process clauses with list of variables. template <typename T> bool VisitOMPClauseList(T *Node); - bool dataTraverse(Stmt *S); bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue); }; template <typename Derived> -bool RecursiveASTVisitor<Derived>::dataTraverse(Stmt *S) { - SmallVector<Stmt*, 16> Queue; - Queue.push_back(S); - - while (!Queue.empty()) { - Stmt *CurrS = Queue.pop_back_val(); - - size_t N = Queue.size(); - TRY_TO(dataTraverseNode(CurrS, &Queue)); - // Process new children in the order they were added. - std::reverse(Queue.begin() + N, Queue.end()); - } - - return true; -} - -template <typename Derived> bool RecursiveASTVisitor<Derived>::dataTraverseNode(Stmt *S, DataRecursionQueue *Queue) { #define DISPATCH_STMT(NAME, CLASS, VAR) \ @@ -561,10 +543,23 @@ bool RecursiveASTVisitor<Derived>::Trave &RecursiveASTVisitor::TraverseStmt>::value) return dataTraverseNode(S, nullptr); - if (!Queue) - return dataTraverse(S); + if (Queue) { + Queue->push_back(S); + return true; + } + + SmallVector<Stmt *, 8> LocalQueue; + LocalQueue.push_back(S); + + while (!LocalQueue.empty()) { + Stmt *CurrS = LocalQueue.pop_back_val(); + + size_t N = LocalQueue.size(); + TRY_TO(dataTraverseNode(CurrS, &LocalQueue)); + // Process new children in the order they were added. + std::reverse(LocalQueue.begin() + N, LocalQueue.end()); + } - Queue->push_back(S); return true; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits