summaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2006-09-07 23:22:37 +0000
committerDevang Patel <dpatel@apple.com>2006-09-07 23:22:37 +0000
commitc8719e935397ee86cd8555771f0a40cc0496e8f2 (patch)
treecd0d46f96a6a3b0943d8380f00ab2724ae63756e /lib/Analysis
parent2dd538c2d27ac6ff4dbbe221a6199a1f8e12c8bc (diff)
downloadllvm-c8719e935397ee86cd8555771f0a40cc0496e8f2.tar.gz
llvm-c8719e935397ee86cd8555771f0a40cc0496e8f2.tar.bz2
llvm-c8719e935397ee86cd8555771f0a40cc0496e8f2.tar.xz
Use iterative do-while loop instead of recursive DFSPass calls to
reduce amount of stack space used at runtime. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30167 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/PostDominators.cpp45
1 files changed, 29 insertions, 16 deletions
diff --git a/lib/Analysis/PostDominators.cpp b/lib/Analysis/PostDominators.cpp
index ec7f7c7546..b0b2374317 100644
--- a/lib/Analysis/PostDominators.cpp
+++ b/lib/Analysis/PostDominators.cpp
@@ -28,23 +28,36 @@ D("postidom", "Immediate Post-Dominators Construction", true);
unsigned ImmediatePostDominators::DFSPass(BasicBlock *V, InfoRec &VInfo,
unsigned N) {
- VInfo.Semi = ++N;
- VInfo.Label = V;
-
- Vertex.push_back(V); // Vertex[n] = V;
- //Info[V].Ancestor = 0; // Ancestor[n] = 0
- //Child[V] = 0; // Child[v] = 0
- VInfo.Size = 1; // Size[v] = 1
-
- // For PostDominators, we want to walk predecessors rather than successors
- // as we do in forward Dominators.
- for (pred_iterator PI = pred_begin(V), PE = pred_end(V); PI != PE; ++PI) {
- InfoRec &SuccVInfo = Info[*PI];
- if (SuccVInfo.Semi == 0) {
- SuccVInfo.Parent = V;
- N = DFSPass(*PI, SuccVInfo, N);
+
+ std::vector<std::pair<BasicBlock *, InfoRec *> > workStack;
+ workStack.push_back(std::make_pair(V, &VInfo));
+
+ do {
+ BasicBlock *currentBB = workStack.back().first;
+ InfoRec *currentVInfo = workStack.back().second;
+ workStack.pop_back();
+
+ currentVInfo->Semi = ++N;
+ currentVInfo->Label = currentBB;
+
+ Vertex.push_back(currentBB); // Vertex[n] = current;
+ // Info[currentBB].Ancestor = 0;
+ // Ancestor[n] = 0
+ // Child[currentBB] = 0;
+ currentVInfo->Size = 1; // Size[currentBB] = 1
+
+ // For PostDominators, we want to walk predecessors rather than successors
+ // as we do in forward Dominators.
+ for (pred_iterator PI = pred_begin(currentBB), PE = pred_end(currentBB);
+ PI != PE; ++PI) {
+ InfoRec &SuccVInfo = Info[*PI];
+ if (SuccVInfo.Semi == 0) {
+ SuccVInfo.Parent = currentBB;
+
+ workStack.push_back(std::make_pair(*PI, &SuccVInfo));
+ }
}
- }
+ } while (!workStack.empty());
return N;
}