r253958 - Reduce the stack usage per recursive step when RecursiveASTVisitor cannot perform data recursion.

Alexey Samsonov via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 13:16:19 PST 2015


Looks like Clang::Index/index-many-call-ops.cpp still uses too much stack
in ASan mode:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/10177/steps/check-clang%20asan/logs/stdio

ASan increases the stack usage, so do you think there's more to fix here,
or we should just disable the test under ASan?

On Mon, Nov 23, 2015 at 11:13 PM, Richard Smith via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> 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 at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>



-- 
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151124/03811981/attachment.html>


More information about the cfe-commits mailing list