mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 20:29:48 +00:00
Don't insert nearly as many redundant phi nodes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40909 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
84109cd015
commit
a37226af81
@ -642,6 +642,10 @@ namespace {
|
|||||||
|
|
||||||
DenseMap<BasicBlock*, ValueNumberedSet> availableOut;
|
DenseMap<BasicBlock*, ValueNumberedSet> availableOut;
|
||||||
|
|
||||||
|
typedef DenseMap<Value*, SmallPtrSet<Instruction*, 4> > PhiMapType;
|
||||||
|
PhiMapType phiMap;
|
||||||
|
|
||||||
|
|
||||||
// This transformation requires dominator postdominator info
|
// This transformation requires dominator postdominator info
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.setPreservesCFG();
|
AU.setPreservesCFG();
|
||||||
@ -780,6 +784,7 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig,
|
|||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
phiMap[orig->getPointerOperand()].insert(PN);
|
||||||
return PN;
|
return PN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -791,6 +796,7 @@ bool GVN::processNonLocalLoad(LoadInst* L,
|
|||||||
MD.getNonLocalDependency(L, deps);
|
MD.getNonLocalDependency(L, deps);
|
||||||
|
|
||||||
DenseMap<BasicBlock*, Value*> repl;
|
DenseMap<BasicBlock*, Value*> repl;
|
||||||
|
|
||||||
for (DenseMap<BasicBlock*, Value*>::iterator I = deps.begin(), E = deps.end();
|
for (DenseMap<BasicBlock*, Value*>::iterator I = deps.begin(), E = deps.end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
if (I->second == MemoryDependenceAnalysis::None) {
|
if (I->second == MemoryDependenceAnalysis::None) {
|
||||||
@ -799,24 +805,40 @@ bool GVN::processNonLocalLoad(LoadInst* L,
|
|||||||
continue;
|
continue;
|
||||||
}else if (StoreInst* S = dyn_cast<StoreInst>(I->second)) {
|
}else if (StoreInst* S = dyn_cast<StoreInst>(I->second)) {
|
||||||
if (S->getPointerOperand() == L->getPointerOperand())
|
if (S->getPointerOperand() == L->getPointerOperand())
|
||||||
repl.insert(std::make_pair(I->first, S->getOperand(0)));
|
repl[I->first] = S->getOperand(0);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
} else if (LoadInst* LD = dyn_cast<LoadInst>(I->second)) {
|
} else if (LoadInst* LD = dyn_cast<LoadInst>(I->second)) {
|
||||||
if (LD->getPointerOperand() == L->getPointerOperand())
|
if (LD->getPointerOperand() == L->getPointerOperand())
|
||||||
repl.insert(std::make_pair(I->first, LD));
|
repl[I->first] = LD;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SmallPtrSet<Instruction*, 4>& p = phiMap[L->getPointerOperand()];
|
||||||
|
for (SmallPtrSet<Instruction*, 4>::iterator I = p.begin(), E = p.end();
|
||||||
|
I != E; ++I) {
|
||||||
|
if ((*I)->getParent() == L->getParent()) {
|
||||||
|
MD.removeInstruction(L);
|
||||||
|
L->replaceAllUsesWith(*I);
|
||||||
|
toErase.push_back(L);
|
||||||
|
NumGVNLoad++;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
repl.insert(std::make_pair((*I)->getParent(), *I));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SmallPtrSet<BasicBlock*, 4> visited;
|
SmallPtrSet<BasicBlock*, 4> visited;
|
||||||
Value* v = GetValueForBlock(L->getParent(), L, repl, true);
|
Value* v = GetValueForBlock(L->getParent(), L, repl, true);
|
||||||
|
|
||||||
MD.removeInstruction(L);
|
MD.removeInstruction(L);
|
||||||
L->replaceAllUsesWith(v);
|
L->replaceAllUsesWith(v);
|
||||||
toErase.push_back(L);
|
toErase.push_back(L);
|
||||||
|
NumGVNLoad++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -917,6 +939,7 @@ bool GVN::runOnFunction(Function &F) {
|
|||||||
// Clean out global sets from any previous functions
|
// Clean out global sets from any previous functions
|
||||||
VN.clear();
|
VN.clear();
|
||||||
availableOut.clear();
|
availableOut.clear();
|
||||||
|
phiMap.clear();
|
||||||
|
|
||||||
bool changed_function = false;
|
bool changed_function = false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user