summaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/LoopSimplify.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2007-04-09 22:25:09 +0000
committerOwen Anderson <resistor@mac.com>2007-04-09 22:25:09 +0000
commit17cba6d2326f1f81098334def5f4f99d867e3ce4 (patch)
treefc91e2fdf854b7649e961b3844180ccd2823c6cc /lib/Transforms/Utils/LoopSimplify.cpp
parent43979df43028e787f4870c58c5a494550a16bef7 (diff)
downloadllvm-17cba6d2326f1f81098334def5f4f99d867e3ce4.tar.gz
llvm-17cba6d2326f1f81098334def5f4f99d867e3ce4.tar.bz2
llvm-17cba6d2326f1f81098334def5f4f99d867e3ce4.tar.xz
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
Diffstat (limited to 'lib/Transforms/Utils/LoopSimplify.cpp')
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp84
1 files changed, 42 insertions, 42 deletions
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<BasicBlock*>& B, ETForest& ETF) {
+ for (std::vector<BasicBlock*>::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<BasicBlock*> 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<BasicBlock*>::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;
+ }
+ }
+ }
+ }
}
+