Fix some null checks to actually test the part that needs checking.
[oota-llvm.git] / include / llvm / Analysis / Dominators.h
index c948a5fc7e8c5a8162cc391f64f5f86f56bdbff3..45eed7fcdaf133ff9790ebb632496e84d21ec5dd 100644 (file)
@@ -69,7 +69,7 @@ protected:
 
   Node *RootNode;
 
-       struct InfoRec {
+  struct InfoRec {
     unsigned Semi;
     unsigned Size;
     BasicBlock *Label, *Parent, *Child, *Ancestor;
@@ -213,7 +213,7 @@ public:
     return Roots[0];
   }
   
-       virtual bool runOnFunction(Function &F);
+  virtual bool runOnFunction(Function &F);
   
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
     AU.setPreservesAll();
@@ -225,10 +225,10 @@ private:
   void Compress(BasicBlock *V, InfoRec &VInfo);
   BasicBlock *Eval(BasicBlock *v);
   void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
-       inline BasicBlock *getIDom(BasicBlock *BB) const {
-           std::map<BasicBlock*, BasicBlock*>::const_iterator I = IDoms.find(BB);
-           return I != IDoms.end() ? I->second : 0;
-         }
+  inline BasicBlock *getIDom(BasicBlock *BB) const {
+      std::map<BasicBlock*, BasicBlock*>::const_iterator I = IDoms.find(BB);
+      return I != IDoms.end() ? I->second : 0;
+    }
 };
 
 //===-------------------------------------
@@ -320,6 +320,29 @@ public:
       return NULL;
     return Common->getData<BasicBlock>();
   }
+  
+  /// Return the immediate dominator of A.
+  BasicBlock *getIDom(BasicBlock *A) const {
+    ETNode *NodeA = getNode(A);
+    if (!NodeA) return 0;
+    const ETNode *idom = NodeA->getFather();
+    return idom ? idom->getData<BasicBlock>() : 0;
+  }
+  
+  void getChildren(BasicBlock *A, std::vector<BasicBlock*>& children) const {
+    ETNode *NodeA = getNode(A);
+    if (!NodeA) return;
+    const ETNode* son = NodeA->getSon();
+    
+    if (!son) return;
+    children.push_back(son->getData<BasicBlock>());
+        
+    const ETNode* brother = son->getBrother();
+    while (brother != son) {
+      children.push_back(brother->getData<BasicBlock>());
+      brother = brother->getBrother();
+    }
+  }
 
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
     AU.setPreservesAll();