diff options
author | Micah Villmow <villmow@gmail.com> | 2012-10-24 15:52:52 +0000 |
---|---|---|
committer | Micah Villmow <villmow@gmail.com> | 2012-10-24 15:52:52 +0000 |
commit | aa76e9e2cf50af190de90bc778b7f7e42ef9ceff (patch) | |
tree | 5206b0fb0ac695e3ab1c9cf434b5a85195abf336 /lib/Transforms/Utils/SimplifyLibCalls.cpp | |
parent | 3575222175b4982f380ff291bb17be67aadc0966 (diff) | |
download | external_llvm-aa76e9e2cf50af190de90bc778b7f7e42ef9ceff.zip external_llvm-aa76e9e2cf50af190de90bc778b7f7e42ef9ceff.tar.gz external_llvm-aa76e9e2cf50af190de90bc778b7f7e42ef9ceff.tar.bz2 |
Add in support for getIntPtrType to get the pointer type based on the address space.
This checkin also adds in some tests that utilize these paths and updates some of the
clients.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166578 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r-- | lib/Transforms/Utils/SimplifyLibCalls.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index b15acdf..162b29e 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -102,14 +102,13 @@ struct MemCpyChkOpt : public InstFortifiedLibCallOptimization { virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { this->CI = CI; FunctionType *FT = Callee->getFunctionType(); - LLVMContext &Context = CI->getParent()->getContext(); // Check if this has the right signature. if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || !FT->getParamType(0)->isPointerTy() || !FT->getParamType(1)->isPointerTy() || - FT->getParamType(2) != TD->getIntPtrType(Context) || - FT->getParamType(3) != TD->getIntPtrType(Context)) + FT->getParamType(2) != TD->getIntPtrType(FT->getParamType(0)) || + FT->getParamType(3) != TD->getIntPtrType(FT->getParamType(1))) return 0; if (isFoldable(3, 2, false)) { @@ -125,14 +124,13 @@ struct MemMoveChkOpt : public InstFortifiedLibCallOptimization { virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { this->CI = CI; FunctionType *FT = Callee->getFunctionType(); - LLVMContext &Context = CI->getParent()->getContext(); // Check if this has the right signature. if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || !FT->getParamType(0)->isPointerTy() || !FT->getParamType(1)->isPointerTy() || - FT->getParamType(2) != TD->getIntPtrType(Context) || - FT->getParamType(3) != TD->getIntPtrType(Context)) + FT->getParamType(2) != TD->getIntPtrType(FT->getParamType(0)) || + FT->getParamType(3) != TD->getIntPtrType(FT->getParamType(1))) return 0; if (isFoldable(3, 2, false)) { @@ -148,14 +146,13 @@ struct MemSetChkOpt : public InstFortifiedLibCallOptimization { virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { this->CI = CI; FunctionType *FT = Callee->getFunctionType(); - LLVMContext &Context = CI->getParent()->getContext(); // Check if this has the right signature. if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || !FT->getParamType(0)->isPointerTy() || !FT->getParamType(1)->isIntegerTy() || - FT->getParamType(2) != TD->getIntPtrType(Context) || - FT->getParamType(3) != TD->getIntPtrType(Context)) + FT->getParamType(2) != TD->getIntPtrType(FT->getParamType(0)) || + FT->getParamType(3) != TD->getIntPtrType(FT->getParamType(0))) return 0; if (isFoldable(3, 2, false)) { @@ -180,7 +177,7 @@ struct StrCpyChkOpt : public InstFortifiedLibCallOptimization { FT->getReturnType() != FT->getParamType(0) || FT->getParamType(0) != FT->getParamType(1) || FT->getParamType(0) != Type::getInt8PtrTy(Context) || - FT->getParamType(2) != TD->getIntPtrType(Context)) + FT->getParamType(2) != TD->getIntPtrType(FT->getParamType(0))) return 0; Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1); @@ -205,8 +202,8 @@ struct StrCpyChkOpt : public InstFortifiedLibCallOptimization { Value *Ret = EmitMemCpyChk(Dst, Src, - ConstantInt::get(TD->getIntPtrType(Context), Len), - CI->getArgOperand(2), B, TD, TLI); + ConstantInt::get(TD->getIntPtrType(Dst->getType()), + Len), CI->getArgOperand(2), B, TD, TLI); return Ret; } return 0; @@ -225,7 +222,7 @@ struct StrNCpyChkOpt : public InstFortifiedLibCallOptimization { FT->getParamType(0) != FT->getParamType(1) || FT->getParamType(0) != Type::getInt8PtrTy(Context) || !FT->getParamType(2)->isIntegerTy() || - FT->getParamType(3) != TD->getIntPtrType(Context)) + FT->getParamType(3) != TD->getIntPtrType(FT->getParamType(0))) return 0; if (isFoldable(3, 2, false)) { @@ -287,7 +284,8 @@ struct StrCatOpt : public LibCallOptimization { // We have enough information to now generate the memcpy call to do the // concatenation for us. Make a memcpy to copy the nul byte with align = 1. B.CreateMemCpy(CpyDst, Src, - ConstantInt::get(TD->getIntPtrType(*Context), Len + 1), 1); + ConstantInt::get(TD->getIntPtrType(Src->getType()), + Len + 1), 1); return Dst; } }; @@ -359,8 +357,9 @@ struct StrChrOpt : public LibCallOptimization { if (Len == 0 || !FT->getParamType(1)->isIntegerTy(32))// memchr needs i32. return 0; + Type *PT = FT->getParamType(0); return EmitMemChr(SrcStr, CI->getArgOperand(1), // include nul. - ConstantInt::get(TD->getIntPtrType(*Context), Len), + ConstantInt::get(TD->getIntPtrType(PT), Len), B, TD, TLI); } @@ -454,8 +453,9 @@ struct StrCmpOpt : public LibCallOptimization { // These optimizations require DataLayout. if (!TD) return 0; + Type *PT = FT->getParamType(0); return EmitMemCmp(Str1P, Str2P, - ConstantInt::get(TD->getIntPtrType(*Context), + ConstantInt::get(TD->getIntPtrType(PT), std::min(Len1, Len2)), B, TD, TLI); } @@ -537,7 +537,7 @@ struct StrCpyOpt : public LibCallOptimization { // We have enough information to now generate the memcpy call to do the // copy for us. Make a memcpy to copy the nul byte with align = 1. B.CreateMemCpy(Dst, Src, - ConstantInt::get(TD->getIntPtrType(*Context), Len), 1); + ConstantInt::get(TD->getIntPtrType(Dst->getType()), Len), 1); return Dst; } }; |