Add methods to erase basic block entry.
authorDevang Patel <dpatel@apple.com>
Mon, 13 Aug 2007 22:10:29 +0000 (22:10 +0000)
committerDevang Patel <dpatel@apple.com>
Mon, 13 Aug 2007 22:10:29 +0000 (22:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41052 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/Dominators.h
lib/VMCore/Dominators.cpp

index dfb73bd0d747535dd8643891bee3ab45b5d78c64..410745837f1dcc1b362e0e8e06a57f82dd4dd666 100644 (file)
@@ -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);
index d08048cc3b851d3537a9d1a3f181ca04c3294ea4..d292e0816c394f8527e4c7aa408af63ab9b41ccf 100644 (file)
@@ -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<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 {
   o << "=============================--------------------------------\n";
   o << "Inorder Dominator Tree: ";