Fix DFS walk.

Fix http://llvm.org/bugs/show_bug.cgi?id=923


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30630 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2006-09-27 17:18:05 +00:00
parent 6c88e9b458
commit 79db5b7370

View File

@ -28,36 +28,49 @@ D("postidom", "Immediate Post-Dominators Construction", true);
unsigned ImmediatePostDominators::DFSPass(BasicBlock *V, InfoRec &VInfo, unsigned ImmediatePostDominators::DFSPass(BasicBlock *V, InfoRec &VInfo,
unsigned N) { unsigned N) {
std::vector<std::pair<BasicBlock *, InfoRec *> > workStack; std::vector<std::pair<BasicBlock *, InfoRec *> > workStack;
std::set<BasicBlock *> visited;
workStack.push_back(std::make_pair(V, &VInfo)); workStack.push_back(std::make_pair(V, &VInfo));
do { do {
BasicBlock *currentBB = workStack.back().first; BasicBlock *currentBB = workStack.back().first;
InfoRec *currentVInfo = workStack.back().second; InfoRec *currentVInfo = workStack.back().second;
workStack.pop_back();
currentVInfo->Semi = ++N; // Visit each block only once.
currentVInfo->Label = currentBB; if (visited.count(currentBB) == 0) {
Vertex.push_back(currentBB); // Vertex[n] = current; visited.insert(currentBB);
// Info[currentBB].Ancestor = 0; currentVInfo->Semi = ++N;
// Ancestor[n] = 0 currentVInfo->Label = currentBB;
// Child[currentBB] = 0;
currentVInfo->Size = 1; // Size[currentBB] = 1 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 // Visit children
// as we do in forward Dominators. bool visitChild = false;
for (pred_iterator PI = pred_begin(currentBB), PE = pred_end(currentBB); for (pred_iterator PI = pred_begin(currentBB), PE = pred_end(currentBB);
PI != PE; ++PI) { PI != PE && !visitChild; ++PI) {
InfoRec &SuccVInfo = Info[*PI]; InfoRec &SuccVInfo = Info[*PI];
if (SuccVInfo.Semi == 0) { if (SuccVInfo.Semi == 0) {
SuccVInfo.Parent = currentBB; SuccVInfo.Parent = currentBB;
if (visited.count (*PI) == 0) {
workStack.push_back(std::make_pair(*PI, &SuccVInfo)); workStack.push_back(std::make_pair(*PI, &SuccVInfo));
visitChild = true;
}
} }
} }
// If all children are visited or if this block has no child then pop this
// block out of workStack.
if (!visitChild)
workStack.pop_back();
} while (!workStack.empty()); } while (!workStack.empty());
return N; return N;
} }