Fix more -Wshorten-64-to-32 warnings.
[oota-llvm.git] / include / llvm / Analysis / Dominators.h
index 517c4818b1a56baadf7c23f2a3caa94ff277e023..6ce3260b8f5294bd000afd6f94aab0d7fdee128d 100644 (file)
@@ -34,6 +34,7 @@
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Compiler.h"
 #include <algorithm>
+#include <map>
 #include <set>
 
 namespace llvm {
@@ -47,7 +48,7 @@ class DominatorBase {
 protected:
   std::vector<NodeT*> Roots;
   const bool IsPostDominators;
-  inline DominatorBase(bool isPostDom) : 
+  inline explicit DominatorBase(bool isPostDom) :
     Roots(), IsPostDominators(isPostDom) {}
 public:
 
@@ -102,6 +103,10 @@ public:
     return C;
   }
   
+  size_t getNumChildren() const {
+    return Children.size();
+  }
+  
   void setIDom(DomTreeNodeBase<NodeT> *NewIDom) {
     assert(IDom && "No immediate dominator?");
     if (IDom != NewIDom) {
@@ -177,13 +182,16 @@ protected:
   unsigned int SlowQueries;
   // Information record used during immediate dominators computation.
   struct InfoRec {
+    unsigned DFSNum;
     unsigned Semi;
     unsigned Size;
-    NodeT *Label, *Parent, *Child, *Ancestor;
+    NodeT *Label, *Child;
+    unsigned Parent, Ancestor;
 
     std::vector<NodeT*> Bucket;
 
-    InfoRec() : Semi(0), Size(0), Label(0), Parent(0), Child(0), Ancestor(0) {}
+    InfoRec() : DFSNum(0), Semi(0), Size(0), Label(0), Child(0), Parent(0),
+                Ancestor(0) {}
   };
 
   DenseMap<NodeT*, NodeT*> IDoms;
@@ -229,7 +237,7 @@ protected:
       bool NewBBDominatesNewBBSucc = true;
       {
         typename GraphT::NodeType* OnePred = PredBlocks[0];
-        unsigned i = 1, e = PredBlocks.size();
+        size_t i = 1, e = PredBlocks.size();
         for (i = 1; !DT.isReachableFromEntry(OnePred); ++i) {
           assert(i != e && "Didn't find reachable pred?");
           OnePred = PredBlocks[i];
@@ -293,7 +301,7 @@ protected:
   }
 
 public:
-  DominatorTreeBase(bool isPostDom) 
+  explicit DominatorTreeBase(bool isPostDom)
     : DominatorBase<NodeT>(isPostDom), DFSInfoValid(false), SlowQueries(0) {}
   virtual ~DominatorTreeBase() { reset(); }
 
@@ -508,7 +516,10 @@ public:
   ///
   virtual void print(std::ostream &o, const Module* ) const {
     o << "=============================--------------------------------\n";
-    o << "Inorder Dominator Tree: ";
+    if (this->isPostDominator())
+      o << "Inorder PostDominator Tree: ";
+    else
+      o << "Inorder Dominator Tree: ";
     if (this->DFSInfoValid)
       o << "DFSNumbers invalid: " << SlowQueries << " slow queries.";
     o << "\n";
@@ -536,8 +547,7 @@ protected:
 
   template<class GraphT>
   friend void Link(DominatorTreeBase<typename GraphT::NodeType>& DT,
-                   typename GraphT::NodeType* V,
-                   typename GraphT::NodeType* W,
+                   unsigned DFSNumV, typename GraphT::NodeType* W,
          typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &WInfo);
   
   template<class GraphT>
@@ -557,7 +567,7 @@ protected:
     SmallVector<std::pair<DomTreeNodeBase<NodeT>*,
                 typename DomTreeNodeBase<NodeT>::iterator>, 32> WorkStack;
 
-    for (unsigned i = 0, e = this->Roots.size(); i != e; ++i) {
+    for (unsigned i = 0, e = (unsigned)this->Roots.size(); i != e; ++i) {
       DomTreeNodeBase<NodeT> *ThisRoot = getNode(this->Roots[i]);
       WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin()));
       ThisRoot->DFSNumIn = DFSNum++;
@@ -594,6 +604,8 @@ protected:
     // Haven't calculated this node yet?  Get or calculate the node for the
     // immediate dominator.
     NodeT *IDom = getIDom(BB);
+
+    assert(IDom || this->DomTreeNodes[NULL]);
     DomTreeNodeBase<NodeT> *IDomNode = getNodeForBlock(IDom);
 
     // Add a new tree node for this BasicBlock, and link it as a child of
@@ -608,9 +620,7 @@ protected:
   }
   
   inline void addRoot(NodeT* BB) {
-    // Unreachable block is not a root node.
-    if (!isa<UnreachableInst>(&BB->back()))
-      this->Roots.push_back(BB);
+    this->Roots.push_back(BB);
   }
   
 public: