mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
Make handleEndBlock significantly faster with one trivial improvement,
and one hack to avoid hitting a bad case when the alias analysis is imprecise. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40935 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
df359c264e
commit
362bb52108
@ -294,10 +294,22 @@ bool DSE::handleEndBlock(BasicBlock& BB,
|
|||||||
AA.doesNotAccessMemory(CS.getCalledFunction()))
|
AA.doesNotAccessMemory(CS.getCalledFunction()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
unsigned modRef = 0;
|
||||||
|
unsigned other = 0;
|
||||||
|
|
||||||
// Remove any pointers made undead by the call from the dead set
|
// Remove any pointers made undead by the call from the dead set
|
||||||
std::vector<Instruction*> dead;
|
std::vector<Instruction*> dead;
|
||||||
for (SmallPtrSet<AllocaInst*, 64>::iterator I = deadPointers.begin(),
|
for (SmallPtrSet<AllocaInst*, 64>::iterator I = deadPointers.begin(),
|
||||||
E = deadPointers.end(); I != E; ++I) {
|
E = deadPointers.end(); I != E; ++I) {
|
||||||
|
// HACK: if we detect that our AA is imprecise, it's not
|
||||||
|
// worth it to scan the rest of the deadPointers set. Just
|
||||||
|
// assume that the AA will return ModRef for everything, and
|
||||||
|
// go ahead and bail.
|
||||||
|
if (modRef >= 16 && other == 0) {
|
||||||
|
deadPointers.clear();
|
||||||
|
return MadeChange;
|
||||||
|
}
|
||||||
|
|
||||||
// Get size information for the alloca
|
// Get size information for the alloca
|
||||||
unsigned pointerSize = ~0UL;
|
unsigned pointerSize = ~0UL;
|
||||||
if (ConstantInt* C = dyn_cast<ConstantInt>((*I)->getArraySize()))
|
if (ConstantInt* C = dyn_cast<ConstantInt>((*I)->getArraySize()))
|
||||||
@ -306,6 +318,12 @@ bool DSE::handleEndBlock(BasicBlock& BB,
|
|||||||
|
|
||||||
// See if the call site touches it
|
// See if the call site touches it
|
||||||
AliasAnalysis::ModRefResult A = AA.getModRefInfo(CS, *I, pointerSize);
|
AliasAnalysis::ModRefResult A = AA.getModRefInfo(CS, *I, pointerSize);
|
||||||
|
|
||||||
|
if (A == AliasAnalysis::ModRef)
|
||||||
|
modRef++;
|
||||||
|
else
|
||||||
|
other++;
|
||||||
|
|
||||||
if (A == AliasAnalysis::ModRef || A == AliasAnalysis::Ref)
|
if (A == AliasAnalysis::ModRef || A == AliasAnalysis::Ref)
|
||||||
dead.push_back(*I);
|
dead.push_back(*I);
|
||||||
}
|
}
|
||||||
@ -320,6 +338,8 @@ bool DSE::handleEndBlock(BasicBlock& BB,
|
|||||||
if (!killPointer)
|
if (!killPointer)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
TranslatePointerBitCasts(killPointer);
|
||||||
|
|
||||||
// Deal with undead pointers
|
// Deal with undead pointers
|
||||||
MadeChange |= RemoveUndeadPointers(killPointer, BBI,
|
MadeChange |= RemoveUndeadPointers(killPointer, BBI,
|
||||||
deadPointers, possiblyDead);
|
deadPointers, possiblyDead);
|
||||||
@ -328,10 +348,8 @@ bool DSE::handleEndBlock(BasicBlock& BB,
|
|||||||
return MadeChange;
|
return MadeChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// RemoveUndeadPointers - takes an instruction and a setvector of
|
/// RemoveUndeadPointers - check for uses of a pointer that make it
|
||||||
/// dead instructions. If I is dead, it is erased, and its operands are
|
/// undead when scanning for dead stores to alloca's.
|
||||||
/// checked for deadness. If they are dead, they are added to the dead
|
|
||||||
/// setvector.
|
|
||||||
bool DSE::RemoveUndeadPointers(Value* killPointer,
|
bool DSE::RemoveUndeadPointers(Value* killPointer,
|
||||||
BasicBlock::iterator& BBI,
|
BasicBlock::iterator& BBI,
|
||||||
SmallPtrSet<AllocaInst*, 64>& deadPointers,
|
SmallPtrSet<AllocaInst*, 64>& deadPointers,
|
||||||
@ -340,6 +358,14 @@ bool DSE::RemoveUndeadPointers(Value* killPointer,
|
|||||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||||
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||||
|
|
||||||
|
// If the kill pointer can be easily reduced to an alloca,
|
||||||
|
// don't bother doing extraneous AA queries
|
||||||
|
if (AllocaInst* A = dyn_cast<AllocaInst>(killPointer)) {
|
||||||
|
if (deadPointers.count(A))
|
||||||
|
deadPointers.erase(A);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool MadeChange = false;
|
bool MadeChange = false;
|
||||||
|
|
||||||
std::vector<Instruction*> undead;
|
std::vector<Instruction*> undead;
|
||||||
|
Loading…
Reference in New Issue
Block a user