From 786c5646e9cd15f18a6a7938673f74b02a05adb8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 13 Mar 2004 22:01:26 +0000 Subject: [PATCH] This little patch speeds up the loop used to update the dominator set analysis. On the testcase from GCC PR12440, which has a LOT of loops (1392 of which require preheaders to be inserted), this speeds up the loopsimplify pass from 1.931s to 0.1875s. The loop in question goes from 1.65s -> 0.0097s, which isn't bad. All of these times are a debug build. This adds a dependency on DominatorTree analysis that was not there before, but we always had dominatortree available anyway, because LICM requires both loop simplify and DT, so this doesn't add any extra analysis in practice. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12362 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 35 ++++++++++++++------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 00ee59d177a..08bbc093c05 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -56,6 +56,7 @@ namespace { // We need loop information to identify the loops... AU.addRequired(); AU.addRequired(); + AU.addRequired(); AU.addPreserved(); AU.addPreserved(); @@ -279,6 +280,9 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) { ChangeExitBlock(*ParentLoops, Header, NewBB); DominatorSet &DS = getAnalysis(); // Update dominator info + DominatorTree &DT = getAnalysis(); + DominatorTree::Node *HeaderDTNode = DT.getNode(Header); + { // The blocks that dominate NewBB are the blocks that dominate Header, // minus Header, plus NewBB. @@ -288,10 +292,20 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) { DS.addBasicBlock(NewBB, DomSet); // The newly created basic block dominates all nodes dominated by Header. - for (Function::iterator I = Header->getParent()->begin(), - E = Header->getParent()->end(); I != E; ++I) - if (DS.dominates(Header, I)) - DS.addDominator(I, NewBB); + for (DominatorTree::Node::iterator I = HeaderDTNode->begin(), + E = HeaderDTNode->end(); I != E; ++I) + DS.addDominator((*I)->getBlock(), NewBB); + } + + { // Update the dominator tree information. + // The immediate dominator of the preheader is the immediate dominator of + // the old header. + // + DominatorTree::Node *PHNode = + DT.createNewNode(NewBB, HeaderDTNode->getIDom()); + + // Change the header node so that PNHode is the new immediate dominator + DT.changeImmediateDominator(HeaderDTNode, PHNode); } // Update immediate dominator information if we have it... @@ -303,19 +317,6 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) { ID->setImmediateDominator(Header, NewBB); } - // Update DominatorTree information if it is active. - if (DominatorTree *DT = getAnalysisToUpdate()) { - // The immediate dominator of the preheader is the immediate dominator of - // the old header. - // - DominatorTree::Node *HeaderNode = DT->getNode(Header); - DominatorTree::Node *PHNode = DT->createNewNode(NewBB, - HeaderNode->getIDom()); - - // Change the header node so that PNHode is the new immediate dominator - DT->changeImmediateDominator(HeaderNode, PHNode); - } - // Update dominance frontier information... if (DominanceFrontier *DF = getAnalysisToUpdate()) { // The DF(NewBB) is just (DF(Header)-Header), because NewBB dominates -- 2.34.1