diff options
| author | Nuno Lopes <nunoplopes@sapo.pt> | 2012-05-03 21:19:58 +0000 |
|---|---|---|
| committer | Nuno Lopes <nunoplopes@sapo.pt> | 2012-05-03 21:19:58 +0000 |
| commit | d2b71e7fa9ff1cfd889a16bbf583bdce200236f9 (patch) | |
| tree | e29c3fc369f5d0cab4c735f7b9c7dbef39cd4390 /llvm/lib/Analysis/MemoryBuiltins.cpp | |
| parent | 64e7ead1d817540a4ba4887da6c8a049788beee7 (diff) | |
| download | bcm5719-llvm-d2b71e7fa9ff1cfd889a16bbf583bdce200236f9.tar.gz bcm5719-llvm-d2b71e7fa9ff1cfd889a16bbf583bdce200236f9.zip | |
add support for calloc to objectsize lowering
llvm-svn: 156102
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
| -rw-r--r-- | llvm/lib/Analysis/MemoryBuiltins.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index b145650b0f0..347a7ea7a8b 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -180,6 +180,46 @@ Value *llvm::getMallocArraySize(CallInst *CI, const TargetData *TD, return computeArraySize(CI, TD, LookThroughSExt); } + +//===----------------------------------------------------------------------===// +// clloc Call Utility Functions. +// + +static bool isCallocCall(const CallInst *CI) { + if (!CI) + return false; + + Function *Callee = CI->getCalledFunction(); + if (Callee == 0 || !Callee->isDeclaration()) + return false; + if (Callee->getName() != "calloc") + return false; + + // Check malloc prototype. + // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin + // attribute will exist. + FunctionType *FTy = Callee->getFunctionType(); + return FTy->getReturnType() == Type::getInt8PtrTy(FTy->getContext()) && + FTy->getNumParams() == 2 && + ((FTy->getParamType(0)->isIntegerTy(32) && + FTy->getParamType(1)->isIntegerTy(32)) || + (FTy->getParamType(0)->isIntegerTy(64) && + FTy->getParamType(1)->isIntegerTy(64))); +} + +/// extractCallocCall - Returns the corresponding CallInst if the instruction +/// is a calloc call. +const CallInst *llvm::extractCallocCall(const Value *I) { + const CallInst *CI = dyn_cast<CallInst>(I); + return isCallocCall(CI) ? CI : 0; +} + +CallInst *llvm::extractCallocCall(Value *I) { + CallInst *CI = dyn_cast<CallInst>(I); + return isCallocCall(CI) ? CI : 0; +} + + //===----------------------------------------------------------------------===// // free Call Utility Functions. // |

