mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-14 14:24:05 +00:00
Cleanup some of my patches from yesterday. Refactor the check for which xform
to apply to a memcpy into processInstruction. Also, fix a bug in the check due to missing braces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47307 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -738,7 +738,8 @@ namespace {
|
|||||||
SmallVector<Instruction*, 4>& toErase);
|
SmallVector<Instruction*, 4>& toErase);
|
||||||
bool processNonLocalLoad(LoadInst* L,
|
bool processNonLocalLoad(LoadInst* L,
|
||||||
SmallVector<Instruction*, 4>& toErase);
|
SmallVector<Instruction*, 4>& toErase);
|
||||||
bool processMemCpy(MemCpyInst* M, SmallVector<Instruction*, 4>& toErase);
|
bool processMemCpy(MemCpyInst* M, MemCpyInst* MDep,
|
||||||
|
SmallVector<Instruction*, 4>& toErase);
|
||||||
bool performReturnSlotOptzn(MemCpyInst* cpy, CallInst* C,
|
bool performReturnSlotOptzn(MemCpyInst* cpy, CallInst* C,
|
||||||
SmallVector<Instruction*, 4>& toErase);
|
SmallVector<Instruction*, 4>& toErase);
|
||||||
Value *GetValueForBlock(BasicBlock *BB, LoadInst* orig,
|
Value *GetValueForBlock(BasicBlock *BB, LoadInst* orig,
|
||||||
@ -1111,24 +1112,10 @@ bool GVN::performReturnSlotOptzn(MemCpyInst* cpy, CallInst* C,
|
|||||||
/// copies X to Y, and memcpy B which copies Y to Z, then we can rewrite B to be
|
/// copies X to Y, and memcpy B which copies Y to Z, then we can rewrite B to be
|
||||||
/// a memcpy from X to Z (or potentially a memmove, depending on circumstances).
|
/// a memcpy from X to Z (or potentially a memmove, depending on circumstances).
|
||||||
/// This allows later passes to remove the first memcpy altogether.
|
/// This allows later passes to remove the first memcpy altogether.
|
||||||
bool GVN::processMemCpy(MemCpyInst* M,
|
bool GVN::processMemCpy(MemCpyInst* M, MemCpyInst* MDep,
|
||||||
SmallVector<Instruction*, 4>& toErase) {
|
SmallVector<Instruction*, 4>& toErase) {
|
||||||
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
|
||||||
|
|
||||||
// First, we have to check that the dependency is another memcpy
|
|
||||||
Instruction* dep = MD.getDependency(M);
|
|
||||||
if (dep == MemoryDependenceAnalysis::None ||
|
|
||||||
dep == MemoryDependenceAnalysis::NonLocal)
|
|
||||||
return false;
|
|
||||||
else if (CallInst* C = dyn_cast<CallInst>(dep))
|
|
||||||
if (!isa<MemCpyInst>(C))
|
|
||||||
return performReturnSlotOptzn(M, C, toErase);
|
|
||||||
else if (!isa<MemCpyInst>(dep))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// We can only transforms memcpy's where the dest of one is the source of the
|
// We can only transforms memcpy's where the dest of one is the source of the
|
||||||
// other
|
// other
|
||||||
MemCpyInst* MDep = cast<MemCpyInst>(dep);
|
|
||||||
if (M->getSource() != MDep->getDest())
|
if (M->getSource() != MDep->getDest())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1159,11 +1146,9 @@ bool GVN::processMemCpy(MemCpyInst* M,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If all checks passed, then we can transform these memcpy's
|
// If all checks passed, then we can transform these memcpy's
|
||||||
bool is32bit = M->getIntrinsicID() == Intrinsic::memcpy_i32;
|
Function* MemCpyFun = Intrinsic::getDeclaration(
|
||||||
Function* MemMoveFun = Intrinsic::getDeclaration(
|
|
||||||
M->getParent()->getParent()->getParent(),
|
M->getParent()->getParent()->getParent(),
|
||||||
is32bit ? Intrinsic::memcpy_i32 :
|
M->getIntrinsicID());
|
||||||
Intrinsic::memcpy_i64);
|
|
||||||
|
|
||||||
std::vector<Value*> args;
|
std::vector<Value*> args;
|
||||||
args.push_back(M->getRawDest());
|
args.push_back(M->getRawDest());
|
||||||
@ -1171,8 +1156,9 @@ bool GVN::processMemCpy(MemCpyInst* M,
|
|||||||
args.push_back(M->getLength());
|
args.push_back(M->getLength());
|
||||||
args.push_back(M->getAlignment());
|
args.push_back(M->getAlignment());
|
||||||
|
|
||||||
CallInst* C = new CallInst(MemMoveFun, args.begin(), args.end(), "", M);
|
CallInst* C = new CallInst(MemCpyFun, args.begin(), args.end(), "", M);
|
||||||
|
|
||||||
|
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||||
if (MD.getDependency(C) == MDep) {
|
if (MD.getDependency(C) == MDep) {
|
||||||
MD.dropInstruction(M);
|
MD.dropInstruction(M);
|
||||||
toErase.push_back(M);
|
toErase.push_back(M);
|
||||||
@ -1193,7 +1179,22 @@ bool GVN::processInstruction(Instruction* I,
|
|||||||
if (LoadInst* L = dyn_cast<LoadInst>(I)) {
|
if (LoadInst* L = dyn_cast<LoadInst>(I)) {
|
||||||
return processLoad(L, lastSeenLoad, toErase);
|
return processLoad(L, lastSeenLoad, toErase);
|
||||||
} else if (MemCpyInst* M = dyn_cast<MemCpyInst>(I)) {
|
} else if (MemCpyInst* M = dyn_cast<MemCpyInst>(I)) {
|
||||||
return processMemCpy(M, toErase);
|
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||||
|
|
||||||
|
// The are two possible optimizations we can do for memcpy:
|
||||||
|
// a) memcpy-memcpy xform which exposes redundance for DSE
|
||||||
|
// b) call-memcpy xform for sret return slot optimization
|
||||||
|
Instruction* dep = MD.getDependency(M);
|
||||||
|
if (dep == MemoryDependenceAnalysis::None ||
|
||||||
|
dep == MemoryDependenceAnalysis::NonLocal)
|
||||||
|
return false;
|
||||||
|
else if (CallInst* C = dyn_cast<CallInst>(dep)) {
|
||||||
|
if (!isa<MemCpyInst>(C))
|
||||||
|
return performReturnSlotOptzn(M, C, toErase);
|
||||||
|
} else if (!isa<MemCpyInst>(dep))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return processMemCpy(M, cast<MemCpyInst>(dep), toErase);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned num = VN.lookup_or_add(I);
|
unsigned num = VN.lookup_or_add(I);
|
||||||
|
Reference in New Issue
Block a user