From 17cba6d2326f1f81098334def5f4f99d867e3ce4 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Mon, 9 Apr 2007 22:25:09 +0000 Subject: Improve some _slow_ behavior introduced in my patches the last few days. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35839 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 84 +++++++++++++++++------------------ 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'lib/Transforms/Utils/LoopSimplify.cpp') diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index ffdc91c37a..5db72d48a0 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -673,6 +673,16 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) { UpdateDomInfoForRevectoredPreds(BEBlock, BackedgeBlocks); } +// Returns true if BasicBlock A dominates at least one block in vector B +// Helper function for UpdateDomInfoForRevectoredPreds +static bool BlockDominatesAny(BasicBlock* A, std::vector& B, ETForest& ETF) { + for (std::vector::iterator BI = B.begin(), BE = B.end(); BI != BE; ++BI) { + if (ETF.dominates(A, *BI)) + return true; + } + return false; +} + /// UpdateDomInfoForRevectoredPreds - This method is used to update the four /// different kinds of dominator information (immediate dominators, /// dominator trees, et-forest and dominance frontiers) after a new block has @@ -841,47 +851,37 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB, // blocks that dominate a block in PredBlocks and contained NewBBSucc in // their dominance frontier must be updated to contain NewBB instead. // - for (unsigned i = 0, e = PredBlocks.size(); i != e; ++i) { - BasicBlock *Pred = PredBlocks[i]; - // Get all of the dominators of the predecessor... - // FIXME: There's probably a better way to do this... - std::vector PredDoms; - for (Function::iterator I = Pred->getParent()->begin(), - E = Pred->getParent()->end(); I != E; ++I) - if (ETF.dominates(&(*I), Pred)) - PredDoms.push_back(I); - - for (std::vector::const_iterator PDI = PredDoms.begin(), - PDE = PredDoms.end(); PDI != PDE; ++PDI) { - BasicBlock *PredDom = *PDI; - - // If the NewBBSucc node is in DF(PredDom), then PredDom didn't - // dominate NewBBSucc but did dominate a predecessor of it. Now we - // change this entry to include NewBB in the DF instead of NewBBSucc. - DominanceFrontier::iterator DFI = DF->find(PredDom); - assert(DFI != DF->end() && "No dominance frontier for node?"); - if (DFI->second.count(NewBBSucc)) { - // If NewBBSucc should not stay in our dominator frontier, remove it. - // We remove it unless there is a predecessor of NewBBSucc that we - // dominate, but we don't strictly dominate NewBBSucc. - bool ShouldRemove = true; - if (PredDom == NewBBSucc || !ETF.dominates(PredDom, NewBBSucc)) { - // Okay, we know that PredDom does not strictly dominate NewBBSucc. - // Check to see if it dominates any predecessors of NewBBSucc. - for (pred_iterator PI = pred_begin(NewBBSucc), - E = pred_end(NewBBSucc); PI != E; ++PI) - if (ETF.dominates(PredDom, *PI)) { - ShouldRemove = false; - break; - } - } - - if (ShouldRemove) - DF->removeFromFrontier(DFI, NewBBSucc); - DF->addToFrontier(DFI, NewBB); - } - } - } - } + for (Function::iterator FI = NewBB->getParent()->begin(), + FE = NewBB->getParent()->end(); FI != FE; ++FI) { + DominanceFrontier::iterator DFI = DF->find(FI); + if (DFI == DF->end()) continue; // unreachable block. + + // Only consider dominators of NewBBSucc + if (!DFI->second.count(NewBBSucc)) continue; + if (BlockDominatesAny(FI, PredBlocks, ETF)) { + // If NewBBSucc should not stay in our dominator frontier, remove it. + // We remove it unless there is a predecessor of NewBBSucc that we + // dominate, but we don't strictly dominate NewBBSucc. + bool ShouldRemove = true; + if ((BasicBlock*)FI == NewBBSucc || !ETF.dominates(FI, NewBBSucc)) { + // Okay, we know that PredDom does not strictly dominate NewBBSucc. + // Check to see if it dominates any predecessors of NewBBSucc. + for (pred_iterator PI = pred_begin(NewBBSucc), + E = pred_end(NewBBSucc); PI != E; ++PI) + if (ETF.dominates(FI, *PI)) { + ShouldRemove = false; + break; + } + + if (ShouldRemove) + DF->removeFromFrontier(DFI, NewBBSucc); + DF->addToFrontier(DFI, NewBB); + + break; + } + } + } + } } + -- cgit v1.2.3