mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-13 14:46:53 +00:00
Update LoopSimplify to require and preserve DominatorTree only.
Now LoopSimplify does not require nor preserve ETForest. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37512 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1a90a5aebe
commit
dba2413b2e
@ -196,6 +196,10 @@ protected:
|
|||||||
return Common->getData<BasicBlock>();
|
return Common->getData<BasicBlock>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// isReachableFromEntry - Return true if A is dominated by the entry
|
||||||
|
/// block of the function containing it.
|
||||||
|
const bool isReachableFromEntry(BasicBlock* A);
|
||||||
|
|
||||||
/// dominates - Returns true iff this dominates N. Note that this is not a
|
/// dominates - Returns true iff this dominates N. Note that this is not a
|
||||||
/// constant time operation!
|
/// constant time operation!
|
||||||
///
|
///
|
||||||
|
@ -68,10 +68,8 @@ namespace {
|
|||||||
// We need loop information to identify the loops...
|
// We need loop information to identify the loops...
|
||||||
AU.addRequired<LoopInfo>();
|
AU.addRequired<LoopInfo>();
|
||||||
AU.addRequired<DominatorTree>();
|
AU.addRequired<DominatorTree>();
|
||||||
AU.addRequired<ETForest>();
|
|
||||||
|
|
||||||
AU.addPreserved<LoopInfo>();
|
AU.addPreserved<LoopInfo>();
|
||||||
AU.addPreserved<ETForest>();
|
|
||||||
AU.addPreserved<DominatorTree>();
|
AU.addPreserved<DominatorTree>();
|
||||||
AU.addPreserved<DominanceFrontier>();
|
AU.addPreserved<DominanceFrontier>();
|
||||||
AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added.
|
AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added.
|
||||||
@ -315,10 +313,10 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
|
|||||||
// Can we eliminate this phi node now?
|
// Can we eliminate this phi node now?
|
||||||
if (Value *V = PN->hasConstantValue(true)) {
|
if (Value *V = PN->hasConstantValue(true)) {
|
||||||
Instruction *I = dyn_cast<Instruction>(V);
|
Instruction *I = dyn_cast<Instruction>(V);
|
||||||
// If I is in NewBB, the ETForest call will fail, because NewBB isn't
|
// If I is in NewBB, the Dominator call will fail, because NewBB isn't
|
||||||
// registered in ETForest yet. Handle this case explicitly.
|
// registered in DominatorTree yet. Handle this case explicitly.
|
||||||
if (!I || (I->getParent() != NewBB &&
|
if (!I || (I->getParent() != NewBB &&
|
||||||
getAnalysis<ETForest>().dominates(I, PN))) {
|
getAnalysis<DominatorTree>().dominates(I, PN))) {
|
||||||
PN->replaceAllUsesWith(V);
|
PN->replaceAllUsesWith(V);
|
||||||
if (AA) AA->deleteValue(PN);
|
if (AA) AA->deleteValue(PN);
|
||||||
BB->getInstList().erase(PN);
|
BB->getInstList().erase(PN);
|
||||||
@ -429,13 +427,13 @@ static void AddBlockAndPredsToSet(BasicBlock *InputBB, BasicBlock *StopBlock,
|
|||||||
|
|
||||||
/// FindPHIToPartitionLoops - The first part of loop-nestification is to find a
|
/// FindPHIToPartitionLoops - The first part of loop-nestification is to find a
|
||||||
/// PHI node that tells us how to partition the loops.
|
/// PHI node that tells us how to partition the loops.
|
||||||
static PHINode *FindPHIToPartitionLoops(Loop *L, ETForest *EF,
|
static PHINode *FindPHIToPartitionLoops(Loop *L, DominatorTree *DT,
|
||||||
AliasAnalysis *AA) {
|
AliasAnalysis *AA) {
|
||||||
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ) {
|
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ) {
|
||||||
PHINode *PN = cast<PHINode>(I);
|
PHINode *PN = cast<PHINode>(I);
|
||||||
++I;
|
++I;
|
||||||
if (Value *V = PN->hasConstantValue())
|
if (Value *V = PN->hasConstantValue())
|
||||||
if (!isa<Instruction>(V) || EF->dominates(cast<Instruction>(V), PN)) {
|
if (!isa<Instruction>(V) || DT->dominates(cast<Instruction>(V), PN)) {
|
||||||
// This is a degenerate PHI already, don't modify it!
|
// This is a degenerate PHI already, don't modify it!
|
||||||
PN->replaceAllUsesWith(V);
|
PN->replaceAllUsesWith(V);
|
||||||
if (AA) AA->deleteValue(PN);
|
if (AA) AA->deleteValue(PN);
|
||||||
@ -509,8 +507,8 @@ void LoopSimplify::PlaceSplitBlockCarefully(BasicBlock *NewBB,
|
|||||||
/// created.
|
/// created.
|
||||||
///
|
///
|
||||||
Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
|
Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
|
||||||
ETForest *EF = getAnalysisToUpdate<ETForest>();
|
DominatorTree *DT = getAnalysisToUpdate<DominatorTree>();
|
||||||
PHINode *PN = FindPHIToPartitionLoops(L, EF, AA);
|
PHINode *PN = FindPHIToPartitionLoops(L, DT, AA);
|
||||||
if (PN == 0) return 0; // No known way to partition.
|
if (PN == 0) return 0; // No known way to partition.
|
||||||
|
|
||||||
// Pull out all predecessors that have varying values in the loop. This
|
// Pull out all predecessors that have varying values in the loop. This
|
||||||
@ -555,7 +553,7 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
|
|||||||
// the Outer loop now.
|
// the Outer loop now.
|
||||||
std::set<BasicBlock*> BlocksInL;
|
std::set<BasicBlock*> BlocksInL;
|
||||||
for (pred_iterator PI = pred_begin(Header), E = pred_end(Header); PI!=E; ++PI)
|
for (pred_iterator PI = pred_begin(Header), E = pred_end(Header); PI!=E; ++PI)
|
||||||
if (EF->dominates(Header, *PI))
|
if (DT->dominates(Header, *PI))
|
||||||
AddBlockAndPredsToSet(*PI, Header, BlocksInL);
|
AddBlockAndPredsToSet(*PI, Header, BlocksInL);
|
||||||
|
|
||||||
|
|
||||||
@ -686,10 +684,10 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) {
|
|||||||
// Returns true if BasicBlock A dominates at least one block in vector B
|
// Returns true if BasicBlock A dominates at least one block in vector B
|
||||||
// Helper function for UpdateDomInfoForRevectoredPreds
|
// Helper function for UpdateDomInfoForRevectoredPreds
|
||||||
static bool BlockDominatesAny(BasicBlock* A, const std::vector<BasicBlock*>& B,
|
static bool BlockDominatesAny(BasicBlock* A, const std::vector<BasicBlock*>& B,
|
||||||
ETForest& ETF) {
|
DominatorTree &DT) {
|
||||||
for (std::vector<BasicBlock*>::const_iterator BI = B.begin(), BE = B.end();
|
for (std::vector<BasicBlock*>::const_iterator BI = B.begin(), BE = B.end();
|
||||||
BI != BE; ++BI) {
|
BI != BE; ++BI) {
|
||||||
if (ETF.dominates(A, *BI))
|
if (DT.dominates(A, *BI))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -715,7 +713,7 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
|
|||||||
++succ_begin(NewBB) == succ_end(NewBB) &&
|
++succ_begin(NewBB) == succ_end(NewBB) &&
|
||||||
"NewBB should have a single successor!");
|
"NewBB should have a single successor!");
|
||||||
BasicBlock *NewBBSucc = *succ_begin(NewBB);
|
BasicBlock *NewBBSucc = *succ_begin(NewBB);
|
||||||
ETForest& ETF = getAnalysis<ETForest>();
|
DominatorTree &DT = getAnalysis<DominatorTree>();
|
||||||
|
|
||||||
// The newly inserted basic block will dominate existing basic blocks iff the
|
// The newly inserted basic block will dominate existing basic blocks iff the
|
||||||
// PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
|
// PredBlocks dominate all of the non-pred blocks. If all predblocks dominate
|
||||||
@ -725,13 +723,13 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
|
|||||||
{
|
{
|
||||||
BasicBlock *OnePred = PredBlocks[0];
|
BasicBlock *OnePred = PredBlocks[0];
|
||||||
unsigned i = 1, e = PredBlocks.size();
|
unsigned i = 1, e = PredBlocks.size();
|
||||||
for (i = 1; !ETF.isReachableFromEntry(OnePred); ++i) {
|
for (i = 1; !DT.isReachableFromEntry(OnePred); ++i) {
|
||||||
assert(i != e && "Didn't find reachable pred?");
|
assert(i != e && "Didn't find reachable pred?");
|
||||||
OnePred = PredBlocks[i];
|
OnePred = PredBlocks[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; i != e; ++i)
|
for (; i != e; ++i)
|
||||||
if (PredBlocks[i] != OnePred && ETF.isReachableFromEntry(OnePred)){
|
if (PredBlocks[i] != OnePred && DT.isReachableFromEntry(OnePred)){
|
||||||
NewBBDominatesNewBBSucc = false;
|
NewBBDominatesNewBBSucc = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -739,7 +737,7 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
|
|||||||
if (NewBBDominatesNewBBSucc)
|
if (NewBBDominatesNewBBSucc)
|
||||||
for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
|
for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
|
||||||
PI != E; ++PI)
|
PI != E; ++PI)
|
||||||
if (*PI != NewBB && !ETF.dominates(NewBBSucc, *PI)) {
|
if (*PI != NewBB && !DT.dominates(NewBBSucc, *PI)) {
|
||||||
NewBBDominatesNewBBSucc = false;
|
NewBBDominatesNewBBSucc = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -752,7 +750,7 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
|
|||||||
NewBBDominatesNewBBSucc = true;
|
NewBBDominatesNewBBSucc = true;
|
||||||
for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
|
for (pred_iterator PI = pred_begin(NewBBSucc), E = pred_end(NewBBSucc);
|
||||||
PI != E; ++PI)
|
PI != E; ++PI)
|
||||||
if (*PI != NewBB && !ETF.dominates(NewBBSucc, *PI)) {
|
if (*PI != NewBB && !DT.dominates(NewBBSucc, *PI)) {
|
||||||
NewBBDominatesNewBBSucc = false;
|
NewBBDominatesNewBBSucc = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -767,14 +765,16 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
|
|||||||
if (!NewBBIDom) {
|
if (!NewBBIDom) {
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for (i = 0; i < PredBlocks.size(); ++i)
|
for (i = 0; i < PredBlocks.size(); ++i)
|
||||||
if (ETF.dominates(&PredBlocks[i]->getParent()->getEntryBlock(), PredBlocks[i])) {
|
if (DT->dominates(&PredBlocks[i]->getParent()->getEntryBlock(),
|
||||||
|
PredBlocks[i])) {
|
||||||
NewBBIDom = PredBlocks[i];
|
NewBBIDom = PredBlocks[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assert(i != PredBlocks.size() && "No reachable preds?");
|
assert(i != PredBlocks.size() && "No reachable preds?");
|
||||||
for (i = i + 1; i < PredBlocks.size(); ++i) {
|
for (i = i + 1; i < PredBlocks.size(); ++i) {
|
||||||
if (ETF.dominates(&PredBlocks[i]->getParent()->getEntryBlock(), PredBlocks[i]))
|
if (DT->dominates(&PredBlocks[i]->getParent()->getEntryBlock(),
|
||||||
NewBBIDom = ETF.nearestCommonDominator(NewBBIDom, PredBlocks[i]);
|
PredBlocks[i]))
|
||||||
|
NewBBIDom = DT->nearestCommonDominator(NewBBIDom, PredBlocks[i]);
|
||||||
}
|
}
|
||||||
assert(NewBBIDom && "No immediate dominator found??");
|
assert(NewBBIDom && "No immediate dominator found??");
|
||||||
}
|
}
|
||||||
@ -790,13 +790,6 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update ET-Forest information if it is active.
|
|
||||||
if (ETForest *EF = getAnalysisToUpdate<ETForest>()) {
|
|
||||||
EF->addNewBlock(NewBB, NewBBIDom);
|
|
||||||
if (NewBBDominatesNewBBSucc)
|
|
||||||
EF->setImmediateDominator(NewBBSucc, NewBB);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update dominance frontier information...
|
// Update dominance frontier information...
|
||||||
if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) {
|
if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) {
|
||||||
// If NewBB dominates NewBBSucc, then DF(NewBB) is now going to be the
|
// If NewBB dominates NewBBSucc, then DF(NewBB) is now going to be the
|
||||||
@ -812,7 +805,7 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
|
|||||||
bool DominatesPred = false;
|
bool DominatesPred = false;
|
||||||
for (pred_iterator PI = pred_begin(*SetI), E = pred_end(*SetI);
|
for (pred_iterator PI = pred_begin(*SetI), E = pred_end(*SetI);
|
||||||
PI != E; ++PI)
|
PI != E; ++PI)
|
||||||
if (ETF.dominates(NewBB, *PI))
|
if (DT.dominates(NewBB, *PI))
|
||||||
DominatesPred = true;
|
DominatesPred = true;
|
||||||
if (!DominatesPred)
|
if (!DominatesPred)
|
||||||
Set.erase(SetI++);
|
Set.erase(SetI++);
|
||||||
@ -845,17 +838,18 @@ void LoopSimplify::UpdateDomInfoForRevectoredPreds(BasicBlock *NewBB,
|
|||||||
// Only consider dominators of NewBBSucc
|
// Only consider dominators of NewBBSucc
|
||||||
if (!DFI->second.count(NewBBSucc)) continue;
|
if (!DFI->second.count(NewBBSucc)) continue;
|
||||||
|
|
||||||
if (BlockDominatesAny(FI, PredBlocks, ETF)) {
|
if (BlockDominatesAny(FI, PredBlocks, DT)) {
|
||||||
// If NewBBSucc should not stay in our dominator frontier, remove it.
|
// If NewBBSucc should not stay in our dominator frontier, remove it.
|
||||||
// We remove it unless there is a predecessor of NewBBSucc that we
|
// We remove it unless there is a predecessor of NewBBSucc that we
|
||||||
// dominate, but we don't strictly dominate NewBBSucc.
|
// dominate, but we don't strictly dominate NewBBSucc.
|
||||||
bool ShouldRemove = true;
|
bool ShouldRemove = true;
|
||||||
if ((BasicBlock*)FI == NewBBSucc || !ETF.dominates(FI, NewBBSucc)) {
|
if ((BasicBlock*)FI == NewBBSucc
|
||||||
|
|| !DT.dominates(FI, NewBBSucc)) {
|
||||||
// Okay, we know that PredDom does not strictly dominate NewBBSucc.
|
// Okay, we know that PredDom does not strictly dominate NewBBSucc.
|
||||||
// Check to see if it dominates any predecessors of NewBBSucc.
|
// Check to see if it dominates any predecessors of NewBBSucc.
|
||||||
for (pred_iterator PI = pred_begin(NewBBSucc),
|
for (pred_iterator PI = pred_begin(NewBBSucc),
|
||||||
E = pred_end(NewBBSucc); PI != E; ++PI)
|
E = pred_end(NewBBSucc); PI != E; ++PI)
|
||||||
if (ETF.dominates(FI, *PI)) {
|
if (DT.dominates(FI, *PI)) {
|
||||||
ShouldRemove = false;
|
ShouldRemove = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -316,14 +316,23 @@ void DominatorTreeBase::updateDFSNumbers()
|
|||||||
for (df_iterator<BasicBlock*> I = df_begin(Roots[i]),
|
for (df_iterator<BasicBlock*> I = df_begin(Roots[i]),
|
||||||
E = df_end(Roots[i]); I != E; ++I) {
|
E = df_end(Roots[i]); I != E; ++I) {
|
||||||
BasicBlock *BB = *I;
|
BasicBlock *BB = *I;
|
||||||
ETNode *ETN = getNode(BB)->getETNode();
|
DomTreeNode *BBNode = getNode(BB);
|
||||||
|
if (BBNode) {
|
||||||
|
ETNode *ETN = BBNode->getETNode();
|
||||||
if (ETN && !ETN->hasFather())
|
if (ETN && !ETN->hasFather())
|
||||||
ETN->assignDFSNumber(dfsnum);
|
ETN->assignDFSNumber(dfsnum);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SlowQueries = 0;
|
SlowQueries = 0;
|
||||||
DFSInfoValid = true;
|
DFSInfoValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// isReachableFromEntry - Return true if A is dominated by the entry
|
||||||
|
/// block of the function containing it.
|
||||||
|
const bool DominatorTreeBase::isReachableFromEntry(BasicBlock* A) {
|
||||||
|
return dominates(&A->getParent()->getEntryBlock(), A);
|
||||||
|
}
|
||||||
|
|
||||||
// dominates - Return true if A dominates B. THis performs the
|
// dominates - Return true if A dominates B. THis performs the
|
||||||
// special checks necessary if A and B are in the same basic block.
|
// special checks necessary if A and B are in the same basic block.
|
||||||
bool DominatorTreeBase::dominates(Instruction *A, Instruction *B) {
|
bool DominatorTreeBase::dominates(Instruction *A, Instruction *B) {
|
||||||
|
Loading…
Reference in New Issue
Block a user