[llvm] r207201 - [LCG] Now that the loop structure of the core SCC finding routine is
Chandler Carruth
chandlerc at gmail.com
Thu Apr 24 23:38:58 PDT 2014
Author: chandlerc
Date: Fri Apr 25 01:38:58 2014
New Revision: 207201
URL: http://llvm.org/viewvc/llvm-project?rev=207201&view=rev
Log:
[LCG] Now that the loop structure of the core SCC finding routine is
factored into a more reasonable form, replace the tail call with
a simple outer-loop continuation. It's sad that C++ makes this so
awkward to write, but it seems more direct and clear than the tail call
at this point.
Modified:
llvm/trunk/lib/Analysis/LazyCallGraph.cpp
Modified: llvm/trunk/lib/Analysis/LazyCallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyCallGraph.cpp?rev=207201&r1=207200&r2=207201&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyCallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyCallGraph.cpp Fri Apr 25 01:38:58 2014
@@ -449,6 +449,7 @@ LazyCallGraph::SCC *LazyCallGraph::getNe
assert(N->DFSNumber != 0 && "We should always assign a DFS number "
"before placing a node onto the stack.");
+ bool Recurse = false; // Used to simulate recursing onto a child.
for (auto I = DFSStack.back().second, E = N->end(); I != E; ++I) {
Node &ChildN = *I;
if (ChildN.DFSNumber == 0) {
@@ -463,7 +464,8 @@ LazyCallGraph::SCC *LazyCallGraph::getNe
ChildN.LowLink = ChildN.DFSNumber = NextDFSNumber++;
SCCEntryNodes.remove(&ChildN.getFunction());
DFSStack.push_back(std::make_pair(&ChildN, ChildN.begin()));
- return LazyCallGraph::getNextSCCInPostOrder();
+ Recurse = true;
+ break;
}
// Track the lowest link of the childen, if any are still in the stack.
@@ -472,6 +474,11 @@ LazyCallGraph::SCC *LazyCallGraph::getNe
if (ChildN.LowLink >= 0 && ChildN.LowLink < N->LowLink)
N->LowLink = ChildN.LowLink;
}
+ if (Recurse)
+ // Continue the outer loop when we exit the inner loop in order to
+ // recurse onto a child.
+ continue;
+
// No more children to process here, pop the node off the stack.
DFSStack.pop_back();
More information about the llvm-commits
mailing list