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
This commit is contained in:
Devang Patel 2006-09-07 23:22:37 +00:00
parent 2dd538c2d2
commit c8719e9353

View File

@ -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;
}