[llvm-commits] [cfe-commits] [PATCH][Review Request] EarlyCSE stack overflow - bugzilla 11794

Jakob Stoklund Olesen stoklund at 2pi.dk
Fri Jan 20 14:08:25 PST 2012


On Jan 20, 2012, at 1:41 PM, Lenny Maiorani wrote:
> There is actually a real difference here. The difference is that when the std::stack or std::deque is being used, it is necessary to have 2 stacks or deques because there is no reverse iterator on DomTreeNode. I am trying to preserve the order of processing nodes so that there is not some case where the behavior changes. If the order does not need to be preserved, then clearly it can be further optimized.

In this case, the child iteration order probably isn't important, but even if it were, you could still avoid the overhead with a vector like this:

  vec.resize(vec.size() + num_children)
  std::copy(child_begin, child_end, vec.rbegin())

Anyway, the runtime differences you were seeing in your stack-test-1.cpp benchmark were probably dominated by the number of times you implicitly call free() in the inner loop.

Note that DepthFirstIterator.h achieves the same thing using much less memory, and it has the stack that you need anyway in order to:

> I still need to take a look at Jakob's other review comment.

Thanks for working on this!

/jakob





More information about the llvm-commits mailing list