[llvm-commits] CVS: llvm/lib/Transforms/Scalar/BreakCriticalEdges.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 8 16:07:06 PDT 2002


Changes in directory llvm/lib/Transforms/Scalar:

BreakCriticalEdges.cpp updated: 1.5 -> 1.6

---
Log message:

Expose isCriticalEdge & SplitCriticalEdge methods from crit-edges pass



---
Diffs of the changes:

Index: llvm/lib/Transforms/Scalar/BreakCriticalEdges.cpp
diff -u llvm/lib/Transforms/Scalar/BreakCriticalEdges.cpp:1.5 llvm/lib/Transforms/Scalar/BreakCriticalEdges.cpp:1.6
--- llvm/lib/Transforms/Scalar/BreakCriticalEdges.cpp:1.5	Tue Oct  1 17:38:40 2002
+++ llvm/lib/Transforms/Scalar/BreakCriticalEdges.cpp	Tue Oct  8 16:06:27 2002
@@ -28,8 +28,6 @@
       AU.addPreserved<DominatorTree>();
       AU.addPreservedID(LoopPreheadersID);   // No preheaders deleted.
     }
-  private:
-    void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum);
   };
 
   RegisterOpt<BreakCriticalEdges> X("break-crit-edges",
@@ -45,9 +43,9 @@
 // Critical edges are edges from a block with multiple successors to a block
 // with multiple predecessors.
 //
-static bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum) {
+bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum) {
   assert(SuccNum < TI->getNumSuccessors() && "Illegal edge specification!");
-  assert (TI->getNumSuccessors() > 1);
+  if (TI->getNumSuccessors() == 1) return false;
 
   const BasicBlock *Dest = TI->getSuccessor(SuccNum);
   pred_const_iterator I = pred_begin(Dest), E = pred_end(Dest);
@@ -62,7 +60,7 @@
 // will update DominatorSet, ImmediateDominator and DominatorTree information if
 // it is available, thus calling this pass will not invalidate either of them.
 //
-void BreakCriticalEdges::SplitCriticalEdge(TerminatorInst *TI,unsigned SuccNum){
+void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
   assert(isCriticalEdge(TI, SuccNum) &&
          "Cannot break a critical edge, if it isn't a critical edge");
   BasicBlock *TIBB = TI->getParent();
@@ -90,12 +88,15 @@
     PN->replaceUsesOfWith(TIBB, NewBB);
   }
 
+  // If we don't have a pass object, we can't update anything...
+  if (P == 0) return;
+
   // Now update analysis information.  These are the analyses that we are
   // currently capable of updating...
   //
 
   // Should we update DominatorSet information?
-  if (DominatorSet *DS = getAnalysisToUpdate<DominatorSet>()) {
+  if (DominatorSet *DS = P->getAnalysisToUpdate<DominatorSet>()) {
     // The blocks that dominate the new one are the blocks that dominate TIBB
     // plus the new block itself.
     DominatorSet::DomSetType DomSet = DS->getDominators(TIBB);
@@ -104,14 +105,14 @@
   }
 
   // Should we update ImmdediateDominator information?
-  if (ImmediateDominators *ID = getAnalysisToUpdate<ImmediateDominators>()) {
+  if (ImmediateDominators *ID = P->getAnalysisToUpdate<ImmediateDominators>()) {
     // TIBB is the new immediate dominator for NewBB.  NewBB doesn't dominate
     // anything.
     ID->addNewBlock(NewBB, TIBB);
   }
   
   // Should we update DominatorTree information?
-  if (DominatorTree *DT = getAnalysisToUpdate<DominatorTree>()) {
+  if (DominatorTree *DT = P->getAnalysisToUpdate<DominatorTree>()) {
     DominatorTree::Node *TINode = DT->getNode(TIBB);
     
     // The new block is not the immediate dominator for any other nodes, but
@@ -131,7 +132,7 @@
     if (TI->getNumSuccessors() > 1)
       for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
         if (isCriticalEdge(TI, i)) {
-          SplitCriticalEdge(TI, i);
+          SplitCriticalEdge(TI, i, this);
           ++NumBroken;
           Changed = true;
         }





More information about the llvm-commits mailing list