Add methods to erase basic block entry.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41052 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2007-08-13 22:10:29 +00:00
parent 6acc9e6b7b
commit 441c5ee6cf
2 changed files with 36 additions and 0 deletions

View File

@ -253,6 +253,11 @@ public:
changeImmediateDominator(getNode(BB), getNode(NewBB)); 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 /// removeNode - Removes a node from the dominator tree. Block must not
/// dominate any other blocks. Invalidates any node pointing to removed /// dominate any other blocks. Invalidates any node pointing to removed
/// block. /// block.
@ -370,6 +375,13 @@ public:
Frontiers.insert(std::make_pair(BB, frontier)); 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) { void addToFrontier(iterator I, BasicBlock *Node) {
assert(I != end() && "BB is not in DominanceFrontier!"); assert(I != end() && "BB is not in DominanceFrontier!");
I->second.insert(Node); I->second.insert(Node);

View File

@ -559,6 +559,30 @@ static void PrintDomTree(const DomTreeNode *N, std::ostream &o,
PrintDomTree(*I, o, Lev+1); 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<DomTreeNode*>::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 { void DominatorTreeBase::print(std::ostream &o, const Module* ) const {
o << "=============================--------------------------------\n"; o << "=============================--------------------------------\n";
o << "Inorder Dominator Tree: "; o << "Inorder Dominator Tree: ";