Add basic block level interface to change immediate dominator
authorDevang Patel <dpatel@apple.com>
Mon, 4 Jun 2007 16:22:33 +0000 (16:22 +0000)
committerDevang Patel <dpatel@apple.com>
Mon, 4 Jun 2007 16:22:33 +0000 (16:22 +0000)
and create new node.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37414 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/Dominators.h
lib/Transforms/Utils/CodeExtractor.cpp

index 29612dc956fb1440738ff0244300601792c4c586..f36afd4a2f034828f1a12b77df6e97b65e3bbed7 100644 (file)
@@ -110,7 +110,7 @@ private:
 /// DominatorTree - Calculate the immediate dominator tree for a function.
 ///
 class DominatorTreeBase : public DominatorBase {
-public:
+
 protected:
   std::map<BasicBlock*, DomTreeNode*> DomTreeNodes;
   void reset();
@@ -118,6 +118,7 @@ protected:
 
   DomTreeNode *RootNode;
 
+  // Information record used during immediate dominators computation.
   struct InfoRec {
     unsigned Semi;
     unsigned Size;
@@ -136,8 +137,7 @@ protected:
   // Info - Collection of information used during the computation of idoms.
   std::map<BasicBlock*, InfoRec> Info;
 
-public:
-public:
+  public:
   DominatorTreeBase(intptr_t ID, bool isPostDom) 
     : DominatorBase(ID, isPostDom) {}
   ~DominatorTreeBase() { reset(); }
@@ -180,6 +180,10 @@ public:
     return DomTreeNodes[BB] = IDomNode->addChild(new DomTreeNode(BB, IDomNode));
   }
 
+  void createNewNode(BasicBlock *BB, BasicBlock *DomBB) {
+    createNewNode(BB, getNode(DomBB));
+  }
+
   /// changeImmediateDominator - This method is used to update the dominator
   /// tree information when a node's immediate dominator changes.
   ///
@@ -188,6 +192,11 @@ public:
     N->setIDom(NewIDom);
   }
 
+  void changeImmediateDominator(BasicBlock *BB, BasicBlock *NewBB) {
+    changeImmediateDominator(getNode(BB), getNode(NewBB));
+  }
+
+
   /// removeNode - Removes a node from the dominator tree.  Block must not
   /// dominate any other blocks.  Invalidates any node pointing to removed
   /// block.
index ce00e0e1d8b032a9f219f402ae6867e8d18bcc4b..f0eb6250f723958abb3dff799c6d5bc599c777b3 100644 (file)
@@ -143,14 +143,14 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
   // blocks that dominate TIBB plus the new block itself.
   if (EF) {
     BasicBlock* idom = EF->getIDom(OldPred);
-    DT->createNewNode(NewBB, DT->getNode(idom));
+    DT->createNewNode(NewBB, idom);
     EF->addNewBlock(NewBB, idom);
 
     // Additionally, NewBB replaces OldPred as the immediate dominator of blocks
     Function *F = Header->getParent();
     for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
       if (EF->getIDom(I) == OldPred) {
-        DT->changeImmediateDominator(DT->getNode(I), DT->getNode(NewBB));
+        DT->changeImmediateDominator(I, NewBB);
         EF->setImmediateDominator(I, NewBB);
       }
   }