summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-28 04:41:43 +0000
committerChris Lattner <sabre@nondot.org>2008-01-28 04:41:43 +0000
commita8b4a56061f22b0c40fbe9fd08495b156b121e7a (patch)
treede71d9bfff8bc41247664afa4ddb5495741a9234 /llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
parent6379fc68fff8057d4cd3285ff953a361a8a3126c (diff)
downloadbcm5719-llvm-a8b4a56061f22b0c40fbe9fd08495b156b121e7a.tar.gz
bcm5719-llvm-a8b4a56061f22b0c40fbe9fd08495b156b121e7a.zip
Transform calls to memcpy into llvm.memcpy calls, patch by Eli Friedman.
llvm-svn: 46433
Diffstat (limited to 'llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp b/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
index 0bd3f84c5e1..1f2a1b0fba5 100644
--- a/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
@@ -919,6 +919,36 @@ struct VISIBILITY_HIDDEN memcmpOptimization : public LibCallOptimization {
}
} 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
/// function by expanding it out to a single store of size 0, 1, 2, 4, or 8
OpenPOWER on IntegriCloud