mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 21:29:41 +00:00
First round of cleanups from Chris' feedback.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40919 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8df786012d
commit
6ca4cb3755
@ -57,16 +57,23 @@ namespace {
|
|||||||
SetVector<Instruction*>& possiblyDead);
|
SetVector<Instruction*>& possiblyDead);
|
||||||
void DeleteDeadInstructionChains(Instruction *I,
|
void DeleteDeadInstructionChains(Instruction *I,
|
||||||
SetVector<Instruction*> &DeadInsts);
|
SetVector<Instruction*> &DeadInsts);
|
||||||
|
|
||||||
|
// Find the base pointer that a pointer came from
|
||||||
|
// Because this is used to find pointers that originate
|
||||||
|
// from allocas, it is safe to ignore GEP indices, since
|
||||||
|
// either the store will be in the alloca, and thus dead,
|
||||||
|
// or beyond the end of the alloca, and thus undefined.
|
||||||
void TranslatePointerBitCasts(Value*& v) {
|
void TranslatePointerBitCasts(Value*& v) {
|
||||||
assert(isa<PointerType>(v->getType()) &&
|
assert(isa<PointerType>(v->getType()) &&
|
||||||
"Translating a non-pointer type?");
|
"Translating a non-pointer type?");
|
||||||
|
while (true) {
|
||||||
// See through pointer-to-pointer bitcasts
|
|
||||||
while (isa<BitCastInst>(v) || isa<GetElementPtrInst>(v))
|
|
||||||
if (BitCastInst* C = dyn_cast<BitCastInst>(v))
|
if (BitCastInst* C = dyn_cast<BitCastInst>(v))
|
||||||
v = C->getOperand(0);
|
v = C->getOperand(0);
|
||||||
else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(v))
|
else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(v))
|
||||||
v = G->getOperand(0);
|
v = G->getOperand(0);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getAnalysisUsage - We require post dominance frontiers (aka Control
|
// getAnalysisUsage - We require post dominance frontiers (aka Control
|
||||||
@ -100,62 +107,62 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
|||||||
for (BasicBlock::iterator BBI = BB.begin(), BBE = BB.end();
|
for (BasicBlock::iterator BBI = BB.begin(), BBE = BB.end();
|
||||||
BBI != BBE; ++BBI) {
|
BBI != BBE; ++BBI) {
|
||||||
// If we find a store or a free...
|
// If we find a store or a free...
|
||||||
if (isa<StoreInst>(BBI) || isa<FreeInst>(BBI)) {
|
if (!isa<StoreInst>(BBI) && !isa<FreeInst>(BBI))
|
||||||
Value* pointer = 0;
|
continue;
|
||||||
if (StoreInst* S = dyn_cast<StoreInst>(BBI))
|
|
||||||
pointer = S->getPointerOperand();
|
|
||||||
else if (FreeInst* F = dyn_cast<FreeInst>(BBI))
|
|
||||||
pointer = F->getPointerOperand();
|
|
||||||
|
|
||||||
assert(pointer && "Not a free or a store?");
|
Value* pointer = 0;
|
||||||
|
if (StoreInst* S = dyn_cast<StoreInst>(BBI))
|
||||||
|
pointer = S->getPointerOperand();
|
||||||
|
else if (FreeInst* F = dyn_cast<FreeInst>(BBI))
|
||||||
|
pointer = F->getPointerOperand();
|
||||||
|
|
||||||
StoreInst*& last = lastStore[pointer];
|
assert(pointer && "Not a free or a store?");
|
||||||
bool deletedStore = false;
|
|
||||||
|
|
||||||
// ... to a pointer that has been stored to before...
|
StoreInst*& last = lastStore[pointer];
|
||||||
if (last) {
|
bool deletedStore = false;
|
||||||
|
|
||||||
|
// ... to a pointer that has been stored to before...
|
||||||
|
if (last) {
|
||||||
|
Instruction* dep = MD.getDependency(BBI);
|
||||||
|
|
||||||
Instruction* dep = MD.getDependency(BBI);
|
// ... and no other memory dependencies are between them....
|
||||||
|
while (dep != MemoryDependenceAnalysis::None &&
|
||||||
// ... and no other memory dependencies are between them....
|
dep != MemoryDependenceAnalysis::NonLocal &&
|
||||||
while (dep != MemoryDependenceAnalysis::None &&
|
isa<StoreInst>(dep)) {
|
||||||
dep != MemoryDependenceAnalysis::NonLocal &&
|
if (dep != last) {
|
||||||
isa<StoreInst>(dep)) {
|
dep = MD.getDependency(BBI, dep);
|
||||||
if (dep == last) {
|
continue;
|
||||||
|
|
||||||
// Remove it!
|
|
||||||
MD.removeInstruction(last);
|
|
||||||
|
|
||||||
// DCE instructions only used to calculate that store
|
|
||||||
if (Instruction* D = dyn_cast<Instruction>(last->getOperand(0)))
|
|
||||||
possiblyDead.insert(D);
|
|
||||||
if (Instruction* D = dyn_cast<Instruction>(last->getOperand(1)))
|
|
||||||
possiblyDead.insert(D);
|
|
||||||
|
|
||||||
last->eraseFromParent();
|
|
||||||
NumFastStores++;
|
|
||||||
deletedStore = true;
|
|
||||||
MadeChange = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
dep = MD.getDependency(BBI, dep);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove it!
|
||||||
|
MD.removeInstruction(last);
|
||||||
|
|
||||||
|
// DCE instructions only used to calculate that store
|
||||||
|
if (Instruction* D = dyn_cast<Instruction>(last->getOperand(0)))
|
||||||
|
possiblyDead.insert(D);
|
||||||
|
if (Instruction* D = dyn_cast<Instruction>(last->getOperand(1)))
|
||||||
|
possiblyDead.insert(D);
|
||||||
|
|
||||||
|
last->eraseFromParent();
|
||||||
|
NumFastStores++;
|
||||||
|
deletedStore = true;
|
||||||
|
MadeChange = true;
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Handle frees whose dependencies are non-trivial
|
|
||||||
if (FreeInst* F = dyn_cast<FreeInst>(BBI))
|
// Handle frees whose dependencies are non-trivial.
|
||||||
if (!deletedStore)
|
if (FreeInst* F = dyn_cast<FreeInst>(BBI)) {
|
||||||
MadeChange |= handleFreeWithNonTrivialDependency(F,
|
if (!deletedStore)
|
||||||
MD.getDependency(F),
|
MadeChange |= handleFreeWithNonTrivialDependency(F,
|
||||||
possiblyDead);
|
MD.getDependency(F),
|
||||||
|
possiblyDead);
|
||||||
// Update our most-recent-store map
|
// No known stores after the free
|
||||||
if (StoreInst* S = dyn_cast<StoreInst>(BBI))
|
last = 0;
|
||||||
last = S;
|
} else {
|
||||||
else
|
// Update our most-recent-store map.
|
||||||
last = 0;
|
last = cast<StoreInst>(BBI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user