[llvm] r207202 - [LCG] Remove a completely unnecessary loop. It wasn't even doing any
Chandler Carruth
chandlerc at gmail.com
Thu Apr 24 23:45:06 PDT 2014
Author: chandlerc
Date: Fri Apr 25 01:45:06 2014
New Revision: 207202
URL: http://llvm.org/viewvc/llvm-project?rev=207202&view=rev
Log:
[LCG] Remove a completely unnecessary loop. It wasn't even doing any
thing, just mucking up the code. I feel bad that I even wrote this loop.
Very sorry. The diff is huge because of the indent change, but I promise
all this is doing is realizing that the outer two loops were actually
the exact same loops, and we didn't need two of them.
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=207202&r1=207201&r2=207202&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyCallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyCallGraph.cpp Fri Apr 25 01:45:06 2014
@@ -218,79 +218,73 @@ LazyCallGraph::SCC::removeInternalEdge(L
"pending nodes from a prior walk.");
}
- // We simulate recursion by popping out of all the nested loops and
- // continuing.
- bool Recurse = false;
-
- do {
Node *N = DFSStack.back().first;
assert(N->DFSNumber != 0 && "We should always assign a DFS number "
"before placing a node onto the stack.");
- for (auto I = DFSStack.back().second, E = N->end(); I != E; ++I) {
- Node &ChildN = *I;
- // If this child isn't currently in this SCC, no need to process it.
- // However, we do need to remove this SCC from its SCC's parent set.
- SCC &ChildSCC = *G.SCCMap.lookup(&ChildN);
- if (&ChildSCC != this) {
- ChildSCC.ParentSCCs.erase(this);
- continue;
- }
-
- // Check if we have reached a node in the new (known connected) set. If
- // so, the entire stack is necessarily in that set and we can re-start.
- if (NewNodes.count(&ChildN)) {
- while (!PendingSCCStack.empty())
- NewNodes.insert(PendingSCCStack.pop_back_val());
- while (!DFSStack.empty())
- NewNodes.insert(DFSStack.pop_back_val().first);
- Recurse = true;
- break;
- }
-
- if (ChildN.DFSNumber == 0) {
- // Mark that we should start at this child when next this node is the
- // top of the stack. We don't start at the next child to ensure this
- // child's lowlink is reflected.
- DFSStack.back().second = I;
-
- // Recurse onto this node via a tail call.
- ChildN.LowLink = ChildN.DFSNumber = NextDFSNumber++;
- Worklist.remove(&ChildN);
- DFSStack.push_back(std::make_pair(&ChildN, ChildN.begin()));
- Recurse = true;
- break;
- }
-
- // Track the lowest link of the childen, if any are still in the stack.
- // Any child not on the stack will have a LowLink of -1.
- assert(ChildN.LowLink != 0 &&
- "Low-link must not be zero with a non-zero DFS number.");
- if (ChildN.LowLink >= 0 && ChildN.LowLink < N->LowLink)
- N->LowLink = ChildN.LowLink;
+ // We simulate recursion by popping out of the nested loop and continuing.
+ bool Recurse = false;
+ for (auto I = DFSStack.back().second, E = N->end(); I != E; ++I) {
+ Node &ChildN = *I;
+ // If this child isn't currently in this SCC, no need to process it.
+ // However, we do need to remove this SCC from its SCC's parent set.
+ SCC &ChildSCC = *G.SCCMap.lookup(&ChildN);
+ if (&ChildSCC != this) {
+ ChildSCC.ParentSCCs.erase(this);
+ continue;
}
- if (Recurse)
- break;
- // No more children to process, pop it off the core DFS stack.
- DFSStack.pop_back();
+ // Check if we have reached a node in the new (known connected) set. If
+ // so, the entire stack is necessarily in that set and we can re-start.
+ if (NewNodes.count(&ChildN)) {
+ while (!PendingSCCStack.empty())
+ NewNodes.insert(PendingSCCStack.pop_back_val());
+ while (!DFSStack.empty())
+ NewNodes.insert(DFSStack.pop_back_val().first);
+ Recurse = true;
+ break;
+ }
- if (N->LowLink == N->DFSNumber) {
- ResultSCCs.push_back(G.formSCC(N, PendingSCCStack));
+ if (ChildN.DFSNumber == 0) {
+ // Mark that we should start at this child when next this node is the
+ // top of the stack. We don't start at the next child to ensure this
+ // child's lowlink is reflected.
+ DFSStack.back().second = I;
+
+ // Recurse onto this node via a tail call.
+ ChildN.LowLink = ChildN.DFSNumber = NextDFSNumber++;
+ Worklist.remove(&ChildN);
+ DFSStack.push_back(std::make_pair(&ChildN, ChildN.begin()));
+ Recurse = true;
break;
}
- assert(!DFSStack.empty() && "We shouldn't have an empty stack!");
+ // Track the lowest link of the childen, if any are still in the stack.
+ // Any child not on the stack will have a LowLink of -1.
+ assert(ChildN.LowLink != 0 &&
+ "Low-link must not be zero with a non-zero DFS number.");
+ if (ChildN.LowLink >= 0 && ChildN.LowLink < N->LowLink)
+ N->LowLink = ChildN.LowLink;
+ }
+ if (Recurse)
+ continue;
+
+ // No more children to process, pop it off the core DFS stack.
+ DFSStack.pop_back();
+
+ if (N->LowLink == N->DFSNumber) {
+ ResultSCCs.push_back(G.formSCC(N, PendingSCCStack));
+ continue;
+ }
- // At this point we know that N cannot ever be an SCC root. Its low-link
- // is not its dfs-number, and we've processed all of its children. It is
- // just sitting here waiting until some node further down the stack gets
- // low-link == dfs-number and pops it off as well. Move it to the pending
- // stack which is pulled into the next SCC to be formed.
- PendingSCCStack.push_back(N);
- } while (!DFSStack.empty());
+ assert(!DFSStack.empty() && "We shouldn't have an empty stack!");
- // We reach here when we're going to "recurse".
+ // At this point we know that N cannot ever be an SCC root. Its low-link
+ // is not its dfs-number, and we've processed all of its children. It is
+ // just sitting here waiting until some node further down the stack gets
+ // low-link == dfs-number and pops it off as well. Move it to the pending
+ // stack which is pulled into the next SCC to be formed.
+ PendingSCCStack.push_back(N);
}
// Replace this SCC with the NewNodes we collected above.
More information about the llvm-commits
mailing list