From 6918c079a1393be8ae551d699479fbfa39b99277 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 31 Oct 2002 02:44:36 +0000 Subject: [PATCH] BreakCriticalEdges should update dominance frontier information as well as 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 | 16 ++++++++++++++-- lib/Transforms/Utils/BreakCriticalEdges.cpp | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Scalar/BreakCriticalEdges.cpp b/lib/Transforms/Scalar/BreakCriticalEdges.cpp index 0c4974db10a..c44f9d324ec 100644 --- a/lib/Transforms/Scalar/BreakCriticalEdges.cpp +++ b/lib/Transforms/Scalar/BreakCriticalEdges.cpp @@ -26,6 +26,7 @@ namespace { AU.addPreserved(); AU.addPreserved(); AU.addPreserved(); + AU.addPreserved(); 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()) { + // 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 diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp index 0c4974db10a..c44f9d324ec 100644 --- a/lib/Transforms/Utils/BreakCriticalEdges.cpp +++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp @@ -26,6 +26,7 @@ namespace { AU.addPreserved(); AU.addPreserved(); AU.addPreserved(); + AU.addPreserved(); 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()) { + // 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