diff options
Diffstat (limited to 'include/llvm/Analysis/Dominators.h')
-rw-r--r-- | include/llvm/Analysis/Dominators.h | 73 |
1 files changed, 40 insertions, 33 deletions
diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index 2e149d5..31c19c4 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -390,6 +390,13 @@ public: if (A == 0 || B == 0) return false; + // Compare the result of the tree walk and the dfs numbers, if expensive + // checks are enabled. +#ifdef XDEBUG + assert(!DFSInfoValid + || (dominatedBySlowTreeWalk(A, B) == B->DominatedBy(A))); +#endif + if (DFSInfoValid) return B->DominatedBy(A); @@ -585,29 +592,35 @@ protected: SmallVector<std::pair<DomTreeNodeBase<NodeT>*, typename DomTreeNodeBase<NodeT>::iterator>, 32> WorkStack; - for (unsigned i = 0, e = (unsigned)this->Roots.size(); i != e; ++i) { - DomTreeNodeBase<NodeT> *ThisRoot = getNode(this->Roots[i]); - WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin())); - ThisRoot->DFSNumIn = DFSNum++; - - while (!WorkStack.empty()) { - DomTreeNodeBase<NodeT> *Node = WorkStack.back().first; - typename DomTreeNodeBase<NodeT>::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<NodeT> *Child = *ChildIt; - ++WorkStack.back().second; - - WorkStack.push_back(std::make_pair(Child, Child->begin())); - Child->DFSNumIn = DFSNum++; - } + DomTreeNodeBase<NodeT> *ThisRoot = getRootNode(); + + if (!ThisRoot) + return; + + // 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++; + + while (!WorkStack.empty()) { + DomTreeNodeBase<NodeT> *Node = WorkStack.back().first; + typename DomTreeNodeBase<NodeT>::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<NodeT> *Child = *ChildIt; + ++WorkStack.back().second; + + WorkStack.push_back(std::make_pair(Child, Child->begin())); + Child->DFSNumIn = DFSNum++; } } @@ -646,21 +659,17 @@ public: /// recalculate - compute a dominator tree for the given function template<class FT> void recalculate(FT& F) { - if (!this->IsPostDominators) { - reset(); + reset(); + this->Vertex.push_back(0); - // Initialize roots + if (!this->IsPostDominators) { + // Initialize root this->Roots.push_back(&F.front()); this->IDoms[&F.front()] = 0; this->DomTreeNodes[&F.front()] = 0; - this->Vertex.push_back(0); Calculate<FT, NodeT*>(*this, F); - - updateDFSNumbers(); } else { - reset(); // Reset from the last time we were run... - // Initialize the roots list for (typename FT::iterator I = F.begin(), E = F.end(); I != E; ++I) { if (std::distance(GraphTraits<FT*>::child_begin(I), @@ -672,8 +681,6 @@ public: this->DomTreeNodes[I] = 0; } - this->Vertex.push_back(0); - Calculate<FT, Inverse<NodeT*> >(*this, F); } } |