BreakCriticalEdges should update dominance frontier information as well as
authorChris Lattner <sabre@nondot.org>
Thu, 31 Oct 2002 02:44:36 +0000 (02:44 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 31 Oct 2002 02:44:36 +0000 (02:44 +0000)
other dominance stuff.  Patch contributed by Casey Carter

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4457 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/BreakCriticalEdges.cpp
lib/Transforms/Utils/BreakCriticalEdges.cpp

index 0c4974db10ac4c325d94ceb981ace69ec4e5d53a..c44f9d324ecab7001ebac2306951d92cc6513d84 100644 (file)
@@ -26,6 +26,7 @@ namespace {
       AU.addPreserved<DominatorSet>();
       AU.addPreserved<ImmediateDominators>();
       AU.addPreserved<DominatorTree>();
+      AU.addPreserved<DominanceFrontier>();
       AU.addPreservedID(LoopPreheadersID);   // No preheaders deleted.
     }
   };
@@ -64,10 +65,11 @@ 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();
+  BasicBlock *DestBB = TI->getSuccessor(SuccNum);
 
   // Create a new basic block, linking it into the CFG.
-  BasicBlock *NewBB = new BasicBlock(TIBB->getName()+"_crit_edge");
-  BasicBlock *DestBB = TI->getSuccessor(SuccNum);
+  BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." +
+                                     DestBB->getName() + "_crit_edge");
   // Create our unconditional branch...
   BranchInst *BI = new BranchInst(DestBB);
   NewBB->getInstList().push_back(BI);
@@ -121,6 +123,16 @@ void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
     if (TINode)        // Don't break unreachable code!
       DT->createNewNode(NewBB, TINode);
   }
+
+  // Should we update DominanceFrontier information?
+  if (DominanceFrontier *DF = P->getAnalysisToUpdate<DominanceFrontier>()) {
+    // Since the new block is dominated by its only predecessor TIBB,
+    // it cannot be in any block's dominance frontier.  Its dominance
+    // frontier is {DestBB}.
+    DominanceFrontier::DomSetType NewDFSet;
+    NewDFSet.insert(DestBB);
+    DF->addBasicBlock(NewBB, NewDFSet);
+  }
 }
 
 // runOnFunction - Loop over all of the edges in the CFG, breaking critical
index 0c4974db10ac4c325d94ceb981ace69ec4e5d53a..c44f9d324ecab7001ebac2306951d92cc6513d84 100644 (file)
@@ -26,6 +26,7 @@ namespace {
       AU.addPreserved<DominatorSet>();
       AU.addPreserved<ImmediateDominators>();
       AU.addPreserved<DominatorTree>();
+      AU.addPreserved<DominanceFrontier>();
       AU.addPreservedID(LoopPreheadersID);   // No preheaders deleted.
     }
   };
@@ -64,10 +65,11 @@ 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();
+  BasicBlock *DestBB = TI->getSuccessor(SuccNum);
 
   // Create a new basic block, linking it into the CFG.
-  BasicBlock *NewBB = new BasicBlock(TIBB->getName()+"_crit_edge");
-  BasicBlock *DestBB = TI->getSuccessor(SuccNum);
+  BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." +
+                                     DestBB->getName() + "_crit_edge");
   // Create our unconditional branch...
   BranchInst *BI = new BranchInst(DestBB);
   NewBB->getInstList().push_back(BI);
@@ -121,6 +123,16 @@ void SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P) {
     if (TINode)        // Don't break unreachable code!
       DT->createNewNode(NewBB, TINode);
   }
+
+  // Should we update DominanceFrontier information?
+  if (DominanceFrontier *DF = P->getAnalysisToUpdate<DominanceFrontier>()) {
+    // Since the new block is dominated by its only predecessor TIBB,
+    // it cannot be in any block's dominance frontier.  Its dominance
+    // frontier is {DestBB}.
+    DominanceFrontier::DomSetType NewDFSet;
+    NewDFSet.insert(DestBB);
+    DF->addBasicBlock(NewBB, NewDFSet);
+  }
 }
 
 // runOnFunction - Loop over all of the edges in the CFG, breaking critical