mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-23 05:29:23 +00:00
reduce indentation, clean up TD use a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120452 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c02ba66d41
commit
9801651193
@ -37,8 +37,6 @@ STATISTIC(NumFastOther , "Number of other instrs removed");
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct DSE : public FunctionPass {
|
struct DSE : public FunctionPass {
|
||||||
TargetData *TD;
|
|
||||||
|
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
DSE() : FunctionPass(ID) {
|
DSE() : FunctionPass(ID) {
|
||||||
initializeDSEPass(*PassRegistry::getPassRegistry());
|
initializeDSEPass(*PassRegistry::getPassRegistry());
|
||||||
@ -78,7 +76,7 @@ namespace {
|
|||||||
AU.addPreserved<MemoryDependenceAnalysis>();
|
AU.addPreserved<MemoryDependenceAnalysis>();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t getPointerSize(Value *V) const;
|
uint64_t getPointerSize(Value *V, AliasAnalysis &AA) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +195,7 @@ static Value *getPointerOperand(Instruction *I) {
|
|||||||
/// completely overwrites a store to the 'Earlier' location.
|
/// completely overwrites a store to the 'Earlier' location.
|
||||||
static bool isCompleteOverwrite(const AliasAnalysis::Location &Later,
|
static bool isCompleteOverwrite(const AliasAnalysis::Location &Later,
|
||||||
const AliasAnalysis::Location &Earlier,
|
const AliasAnalysis::Location &Earlier,
|
||||||
AliasAnalysis &AA, const TargetData *TD) {
|
AliasAnalysis &AA) {
|
||||||
const Value *P1 = Later.Ptr->stripPointerCasts();
|
const Value *P1 = Later.Ptr->stripPointerCasts();
|
||||||
const Value *P2 = Earlier.Ptr->stripPointerCasts();
|
const Value *P2 = Earlier.Ptr->stripPointerCasts();
|
||||||
|
|
||||||
@ -205,12 +203,16 @@ static bool isCompleteOverwrite(const AliasAnalysis::Location &Later,
|
|||||||
if (P1 != P2)
|
if (P1 != P2)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If we have no TargetData information around, then the size of the store is
|
// If we don't know the sizes of either access, then we can't do a comparison.
|
||||||
// inferrable from the pointee type. If they are the same type, then we know
|
if (Later.Size == AliasAnalysis::UnknownSize ||
|
||||||
// that the store is safe.
|
Earlier.Size == AliasAnalysis::UnknownSize) {
|
||||||
if (TD == 0)
|
// If we have no TargetData information around, then the size of the store
|
||||||
|
// is inferrable from the pointee type. If they are the same type, then we
|
||||||
|
// know that the store is safe.
|
||||||
|
if (AA.getTargetData() == 0)
|
||||||
return Later.Ptr->getType() == Earlier.Ptr->getType();
|
return Later.Ptr->getType() == Earlier.Ptr->getType();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure that the Later size is >= the Earlier size.
|
// Make sure that the Later size is >= the Earlier size.
|
||||||
if (Later.Size < Earlier.Size)
|
if (Later.Size < Earlier.Size)
|
||||||
@ -222,7 +224,6 @@ static bool isCompleteOverwrite(const AliasAnalysis::Location &Later,
|
|||||||
bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
||||||
MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>();
|
MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||||
TD = getAnalysisIfAvailable<TargetData>();
|
|
||||||
|
|
||||||
bool MadeChange = false;
|
bool MadeChange = false;
|
||||||
|
|
||||||
@ -296,7 +297,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
|||||||
|
|
||||||
// If we find a removable write that is completely obliterated by the
|
// If we find a removable write that is completely obliterated by the
|
||||||
// store to 'Loc' then we can remove it.
|
// store to 'Loc' then we can remove it.
|
||||||
if (isRemovable(DepWrite) && isCompleteOverwrite(Loc, DepLoc, AA, TD)) {
|
if (isRemovable(DepWrite) && isCompleteOverwrite(Loc, DepLoc, AA)) {
|
||||||
// Delete the store and now-dead instructions that feed it.
|
// Delete the store and now-dead instructions that feed it.
|
||||||
DeleteDeadInstruction(DepWrite);
|
DeleteDeadInstruction(DepWrite);
|
||||||
++NumFastStores;
|
++NumFastStores;
|
||||||
@ -486,8 +487,8 @@ 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,
|
AliasAnalysis::ModRefResult A =
|
||||||
getPointerSize(*I));
|
AA.getModRefInfo(CS, *I, getPointerSize(*I, AA));
|
||||||
|
|
||||||
if (A == AliasAnalysis::ModRef)
|
if (A == AliasAnalysis::ModRef)
|
||||||
++modRef;
|
++modRef;
|
||||||
@ -551,7 +552,7 @@ bool DSE::RemoveUndeadPointers(Value *killPointer, uint64_t killPointerSize,
|
|||||||
for (SmallPtrSet<Value*, 64>::iterator I = deadPointers.begin(),
|
for (SmallPtrSet<Value*, 64>::iterator I = deadPointers.begin(),
|
||||||
E = deadPointers.end(); I != E; ++I) {
|
E = deadPointers.end(); I != E; ++I) {
|
||||||
// See if this pointer could alias it
|
// See if this pointer could alias it
|
||||||
AliasAnalysis::AliasResult A = AA.alias(*I, getPointerSize(*I),
|
AliasAnalysis::AliasResult A = AA.alias(*I, getPointerSize(*I, AA),
|
||||||
killPointer, killPointerSize);
|
killPointer, killPointerSize);
|
||||||
|
|
||||||
// If it must-alias and a store, we can delete it
|
// If it must-alias and a store, we can delete it
|
||||||
@ -621,17 +622,19 @@ void DSE::DeleteDeadInstruction(Instruction *I,
|
|||||||
} while (!NowDeadInsts.empty());
|
} while (!NowDeadInsts.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t DSE::getPointerSize(Value *V) const {
|
uint64_t DSE::getPointerSize(Value *V, AliasAnalysis &AA) const {
|
||||||
if (TD) {
|
const TargetData *TD = AA.getTargetData();
|
||||||
|
if (TD == 0)
|
||||||
|
return AliasAnalysis::UnknownSize;
|
||||||
|
|
||||||
if (AllocaInst *A = dyn_cast<AllocaInst>(V)) {
|
if (AllocaInst *A = dyn_cast<AllocaInst>(V)) {
|
||||||
// Get size information for the alloca
|
// Get size information for the alloca
|
||||||
if (ConstantInt *C = dyn_cast<ConstantInt>(A->getArraySize()))
|
if (ConstantInt *C = dyn_cast<ConstantInt>(A->getArraySize()))
|
||||||
return C->getZExtValue() * TD->getTypeAllocSize(A->getAllocatedType());
|
return C->getZExtValue() * TD->getTypeAllocSize(A->getAllocatedType());
|
||||||
} else {
|
return AliasAnalysis::UnknownSize;
|
||||||
|
}
|
||||||
|
|
||||||
assert(isa<Argument>(V) && "Expected AllocaInst or Argument!");
|
assert(isa<Argument>(V) && "Expected AllocaInst or Argument!");
|
||||||
const PointerType *PT = cast<PointerType>(V->getType());
|
const PointerType *PT = cast<PointerType>(V->getType());
|
||||||
return TD->getTypeAllocSize(PT->getElementType());
|
return TD->getTypeAllocSize(PT->getElementType());
|
||||||
}
|
|
||||||
}
|
|
||||||
return AliasAnalysis::UnknownSize;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user