This started as a small change, I swear. Unfortunately, lots of things call the...
[oota-llvm.git] / lib / Transforms / Utils / BreakCriticalEdges.cpp
index bbea26936c857a5b645e20252572954cd54759a7..c4fd1eae43cd978a54c85df5f685cf3eb8208f4f 100644 (file)
@@ -35,7 +35,7 @@ STATISTIC(NumBroken, "Number of blocks inserted");
 namespace {
   struct VISIBILITY_HIDDEN BreakCriticalEdges : public FunctionPass {
     static char ID; // Pass identification, replacement for typeid
-    BreakCriticalEdges() : FunctionPass((intptr_t)&ID) {}
+    BreakCriticalEdges() : FunctionPass(&ID) {}
 
     virtual bool runOnFunction(Function &F);
 
@@ -48,14 +48,14 @@ namespace {
       AU.addPreservedID(LoopSimplifyID);
     }
   };
-
-  char BreakCriticalEdges::ID = 0;
-  RegisterPass<BreakCriticalEdges> X("break-crit-edges",
-                                    "Break critical edges in CFG");
 }
 
+char BreakCriticalEdges::ID = 0;
+static RegisterPass<BreakCriticalEdges>
+X("break-crit-edges", "Break critical edges in CFG");
+
 // Publically exposed interface to pass...
-const PassInfo *llvm::BreakCriticalEdgesID = X.getPassInfo();
+const PassInfo *const llvm::BreakCriticalEdgesID = &X;
 FunctionPass *llvm::createBreakCriticalEdgesPass() {
   return new BreakCriticalEdges();
 }
@@ -114,12 +114,12 @@ bool llvm::isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum,
   return false;
 }
 
-// SplitCriticalEdge - If this edge is a critical edge, insert a new node to
-// split the critical edge.  This will update DominatorTree, and DominatorFrontier 
-// information if it is available, thus calling this pass will not invalidate 
-// any of them.  This returns true if the edge was split, false otherwise. 
-// This ensures that all edges to that dest go to one block instead of each 
-// going to a different block.
+/// SplitCriticalEdge - If this edge is a critical edge, insert a new node to
+/// split the critical edge.  This will update DominatorTree and
+/// DominatorFrontier  information if it is available, thus calling this pass
+/// will not invalidate  any of them.  This returns true if the edge was split,
+/// false otherwise.  This ensures that all edges to that dest go to one block
+/// instead of each going to a different block.
 //
 bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P,
                              bool MergeIdenticalEdges) {
@@ -187,7 +187,7 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P,
   bool NewBBDominatesDestBB = true;
   
   // Should we update DominatorTree information?
-  if (DominatorTree *DT = P->getAnalysisToUpdate<DominatorTree>()) {
+  if (DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>()) {
     DomTreeNode *TINode = DT->getNode(TIBB);
 
     // The new block is not the immediate dominator for any other nodes, but
@@ -218,7 +218,7 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P,
   }
 
   // Should we update DominanceFrontier information?
-  if (DominanceFrontier *DF = P->getAnalysisToUpdate<DominanceFrontier>()) {
+  if (DominanceFrontier *DF = P->getAnalysisIfAvailable<DominanceFrontier>()) {
     // If NewBBDominatesDestBB hasn't been computed yet, do so with DF.
     if (!OtherPreds.empty()) {
       // FIXME: IMPLEMENT THIS!
@@ -235,9 +235,12 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P,
       DominanceFrontier::iterator I = DF->find(DestBB);
       if (I != DF->end()) {
         DF->addBasicBlock(NewBB, I->second);
-        // However NewBB's frontier does not include DestBB.
-        DominanceFrontier::iterator NF = DF->find(NewBB);
-        DF->removeFromFrontier(NF, DestBB);
+        
+        if (I->second.count(DestBB)) {
+          // However NewBB's frontier does not include DestBB.
+          DominanceFrontier::iterator NF = DF->find(NewBB);
+          DF->removeFromFrontier(NF, DestBB);
+        }
       }
       else
         DF->addBasicBlock(NewBB, DominanceFrontier::DomSetType());
@@ -249,7 +252,7 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P,
   }
   
   // Update LoopInfo if it is around.
-  if (LoopInfo *LI = P->getAnalysisToUpdate<LoopInfo>()) {
+  if (LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>()) {
     // If one or the other blocks were not in a loop, the new block is not
     // either, and thus LI doesn't need to be updated.
     if (Loop *TIL = LI->getLoopFor(TIBB))