mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-08 21:10:35 +00:00
Transform calls to memcpy into llvm.memcpy calls, patch by Eli Friedman.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46433 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2671fc390c
commit
0818ea8317
@ -919,6 +919,36 @@ struct VISIBILITY_HIDDEN memcmpOptimization : public LibCallOptimization {
|
|||||||
}
|
}
|
||||||
} memcmpOptimizer;
|
} memcmpOptimizer;
|
||||||
|
|
||||||
|
/// This LibCallOptimization will simplify a call to the memcpy library
|
||||||
|
/// function. It simply converts them into calls to llvm.memcpy.*;
|
||||||
|
/// the resulting call should be optimized later.
|
||||||
|
/// @brief Simplify the memcpy library function.
|
||||||
|
struct VISIBILITY_HIDDEN MemCpyOptimization : public LibCallOptimization {
|
||||||
|
public:
|
||||||
|
MemCpyOptimization() : LibCallOptimization("memcpy",
|
||||||
|
"Number of 'memcpy' calls simplified") {}
|
||||||
|
|
||||||
|
/// @brief Make sure that the "memcpy" function has the right prototype
|
||||||
|
virtual bool ValidateCalledFunction(const Function *F, SimplifyLibCalls &SLC){
|
||||||
|
const FunctionType *FT = F->getFunctionType();
|
||||||
|
const Type* voidPtr = PointerType::getUnqual(Type::Int8Ty);
|
||||||
|
return FT->getReturnType() == voidPtr && FT->getNumParams() == 3 &&
|
||||||
|
FT->getParamType(0) == voidPtr &&
|
||||||
|
FT->getParamType(1) == voidPtr &&
|
||||||
|
FT->getParamType(2) == SLC.getIntPtrType();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief Perform the memcpy optimization
|
||||||
|
virtual bool OptimizeCall(CallInst *CI, SimplifyLibCalls &SLC) {
|
||||||
|
Value *MemcpyOps[] = {
|
||||||
|
CI->getOperand(1), CI->getOperand(2), CI->getOperand(3),
|
||||||
|
ConstantInt::get(Type::Int32Ty, 1) // align = 1 always.
|
||||||
|
};
|
||||||
|
new CallInst(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI);
|
||||||
|
// memcpy always returns the destination
|
||||||
|
return ReplaceCallWith(CI, CI->getOperand(1));
|
||||||
|
}
|
||||||
|
} MemCpyOptimizer;
|
||||||
|
|
||||||
/// This LibCallOptimization will simplify a call to the memcpy library
|
/// This LibCallOptimization will simplify a call to the memcpy library
|
||||||
/// function by expanding it out to a single store of size 0, 1, 2, 4, or 8
|
/// function by expanding it out to a single store of size 0, 1, 2, 4, or 8
|
||||||
|
Loading…
Reference in New Issue
Block a user