From fbc9ea7841b411ee2cec995dda7feb63226d87a0 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Thu, 7 Jan 2010 23:50:06 +0000 Subject: [PATCH] Fix DFS number calculation for postdominators The DFS number calculation for postdominators was broken. In the case of multiple exits that form the post dominator root nodes, do not iterate over all exits, but start from the virtual root node. Otherwise bbs, that are not post dominated by any exit but by the virtual root node, will never be assigned a DFS number. llvm-svn: 92967 --- include/llvm/Analysis/Dominators.h | 46 +++++++++++++++++------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index 2e149d59e98..7ac474aff34 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -585,29 +585,35 @@ protected: SmallVector*, typename DomTreeNodeBase::iterator>, 32> WorkStack; - for (unsigned i = 0, e = (unsigned)this->Roots.size(); i != e; ++i) { - DomTreeNodeBase *ThisRoot = getNode(this->Roots[i]); - WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin())); - ThisRoot->DFSNumIn = DFSNum++; + DomTreeNodeBase *ThisRoot = getRootNode(); - while (!WorkStack.empty()) { - DomTreeNodeBase *Node = WorkStack.back().first; - typename DomTreeNodeBase::iterator ChildIt = - WorkStack.back().second; + if (!ThisRoot) + return; - // If we visited all of the children of this node, "recurse" back up the - // stack setting the DFOutNum. - if (ChildIt == Node->end()) { - Node->DFSNumOut = DFSNum++; - WorkStack.pop_back(); - } else { - // Otherwise, recursively visit this child. - DomTreeNodeBase *Child = *ChildIt; - ++WorkStack.back().second; + // Even in the case of multiple exits that form the post dominator root + // nodes, do not iterate over all exits, but start from the virtual root + // node. Otherwise bbs, that are not post dominated by any exit but by the + // virtual root node, will never be assigned a DFS number. + WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin())); + ThisRoot->DFSNumIn = DFSNum++; - WorkStack.push_back(std::make_pair(Child, Child->begin())); - Child->DFSNumIn = DFSNum++; - } + while (!WorkStack.empty()) { + DomTreeNodeBase *Node = WorkStack.back().first; + typename DomTreeNodeBase::iterator ChildIt = + WorkStack.back().second; + + // If we visited all of the children of this node, "recurse" back up the + // stack setting the DFOutNum. + if (ChildIt == Node->end()) { + Node->DFSNumOut = DFSNum++; + WorkStack.pop_back(); + } else { + // Otherwise, recursively visit this child. + DomTreeNodeBase *Child = *ChildIt; + ++WorkStack.back().second; + + WorkStack.push_back(std::make_pair(Child, Child->begin())); + Child->DFSNumIn = DFSNum++; } }