diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h index dfb73bd0d74..410745837f1 100644 --- a/include/llvm/Analysis/Dominators.h +++ b/include/llvm/Analysis/Dominators.h @@ -253,6 +253,11 @@ public: changeImmediateDominator(getNode(BB), getNode(NewBB)); } + /// eraseNode - Removes a node from the domiantor tree. Block must not + /// domiante any other blocks. Removes node from its immediate dominator's + /// children list. Deletes dominator node associated with basic block BB. + void eraseNode(BasicBlock *BB); + /// removeNode - Removes a node from the dominator tree. Block must not /// dominate any other blocks. Invalidates any node pointing to removed /// block. @@ -370,6 +375,13 @@ public: Frontiers.insert(std::make_pair(BB, frontier)); } + /// removeBlock - Remove basic block BB's frontier. + void removeBlock(BasicBlock *BB) { + assert(find(BB) != end() && "Block is not in DominanceFrontier!"); + iterator BBDF = Frontiers.find(BB); + Frontiers.erase(BBDF); + } + void addToFrontier(iterator I, BasicBlock *Node) { assert(I != end() && "BB is not in DominanceFrontier!"); I->second.insert(Node); diff --git a/lib/VMCore/Dominators.cpp b/lib/VMCore/Dominators.cpp index d08048cc3b8..d292e0816c3 100644 --- a/lib/VMCore/Dominators.cpp +++ b/lib/VMCore/Dominators.cpp @@ -559,6 +559,30 @@ static void PrintDomTree(const DomTreeNode *N, std::ostream &o, PrintDomTree(*I, o, Lev+1); } +/// eraseNode - Removes a node from the domiantor tree. Block must not +/// domiante any other blocks. Removes node from its immediate dominator's +/// children list. Deletes dominator node associated with basic block BB. +void DominatorTreeBase::eraseNode(BasicBlock *BB) { + DomTreeNode *Node = getNode(BB); + assert (Node && "Removing node that isn't in dominator tree."); + + // Remove node from immediate dominator's children list. + DomTreeNode *IDom = Node->getIDom(); + if (IDom) { + std::vector::iterator I = + std::find(IDom->Children.begin(), IDom->Children.end(), Node); + assert(I != IDom->Children.end() && + "Not in immediate dominator children set!"); + // I am no longer your child... + IDom->Children.erase(I); + } + + assert (Node->getChildren().empty() && "Children list is not empty"); + + DomTreeNodes.erase(BB); + delete Node; +} + void DominatorTreeBase::print(std::ostream &o, const Module* ) const { o << "=============================--------------------------------\n"; o << "Inorder Dominator Tree: ";