Simplify conditional and fix LICM/2004-11-17-UndefIndexCrash.ll
[oota-llvm.git] / lib / VMCore / Dominators.cpp
index 0f68bb4d0250990dfcf806797e75a62644b080e2..a120db40bd6f01d5c40f1330f2b2c8e0a21c8709 100644 (file)
@@ -17,8 +17,8 @@
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Assembly/Writer.h"
-#include "Support/DepthFirstIterator.h"
-#include "Support/SetOperations.h"
+#include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/SetOperations.h"
 #include <algorithm>
 using namespace llvm;
 
@@ -211,15 +211,13 @@ bool ImmediateDominators::runOnFunction(Function &F) {
 }
 
 void ImmediateDominatorsBase::print(std::ostream &o) const {
-  for (const_iterator I = begin(), E = end(); I != E; ++I) {
+  Function *F = getRoots()[0]->getParent();
+  for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
     o << "  Immediate Dominator For Basic Block:";
-    if (I->first)
-      WriteAsOperand(o, I->first, false);
-    else
-      o << " <<exit node>>";
+    WriteAsOperand(o, I, false);
     o << " is:";
-    if (I->second)
-      WriteAsOperand(o, I->second, false);
+    if (BasicBlock *ID = get(I))
+      WriteAsOperand(o, ID, false);
     else
       o << " <<exit node>>";
     o << "\n";
@@ -300,6 +298,8 @@ bool DominatorSet::runOnFunction(Function &F) {
   return false;
 }
 
+void DominatorSet::stub() {}
+
 namespace llvm {
 static std::ostream &operator<<(std::ostream &o,
                                 const std::set<BasicBlock*> &BBs) {
@@ -375,19 +375,20 @@ void DominatorTree::calculate(const ImmediateDominators &ID) {
   BasicBlock *Root = Roots[0];
   Nodes[Root] = RootNode = new Node(Root, 0); // Add a node for the root...
 
+  Function *F = Root->getParent();
   // Loop over all of the reachable blocks in the function...
-  for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
-       I != E; ++I) {
-    Node *&BBNode = Nodes[I->first];
-    if (!BBNode) {  // Haven't calculated this node yet?
-      // Get or calculate the node for the immediate dominator
-      Node *IDomNode = getNodeForBlock(I->second);
-
-      // Add a new tree node for this BasicBlock, and link it as a child of
-      // IDomNode
-      BBNode = IDomNode->addChild(new Node(I->first, IDomNode));
+  for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)
+    if (BasicBlock *ImmDom = ID.get(I)) {  // Reachable block.
+      Node *&BBNode = Nodes[I];
+      if (!BBNode) {  // Haven't calculated this node yet?
+        // Get or calculate the node for the immediate dominator
+        Node *IDomNode = getNodeForBlock(ImmDom);
+
+        // Add a new tree node for this BasicBlock, and link it as a child of
+        // IDomNode
+        BBNode = IDomNode->addChild(new Node(I, IDomNode));
+      }
     }
-  }
 }
 
 static std::ostream &operator<<(std::ostream &o,