From e297149e267e05159db4dc490493fddcb3784d95 Mon Sep 17 00:00:00 2001 From: Victor Hernandez Date: Sat, 24 Oct 2009 04:23:03 +0000 Subject: Auto-upgrade free instructions to calls to the builtin free function. Update all analysis passes and transforms to treat free calls just like FreeInst. Remove RaiseAllocations and all its tests since FreeInst no longer needs to be raised. llvm-svn: 84987 --- llvm/lib/Analysis/MallocHelper.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'llvm/lib/Analysis/MallocHelper.cpp') diff --git a/llvm/lib/Analysis/MallocHelper.cpp b/llvm/lib/Analysis/MallocHelper.cpp index e7bb41eeec2..511de9d6a51 100644 --- a/llvm/lib/Analysis/MallocHelper.cpp +++ b/llvm/lib/Analysis/MallocHelper.cpp @@ -263,3 +263,29 @@ Value* llvm::getMallocArraySize(CallInst* CI, LLVMContext &Context, assert(BO && "getMallocArraySize not constant but not multiplication either"); return BO->getOperand(0); } + +/// isFreeCall - Returns true if the the value is a call to the builtin free() +bool llvm::isFreeCall(const Value* I) { + const CallInst *CI = dyn_cast(I); + if (!CI) + return false; + + const Module* M = CI->getParent()->getParent()->getParent(); + Function *FreeFunc = M->getFunction("free"); + + if (CI->getOperand(0) != FreeFunc) + return false; + + // Check free prototype. + // FIXME: workaround for PR5130, this will be obsolete when a nobuiltin + // attribute will exist. + const FunctionType *FTy = FreeFunc->getFunctionType(); + if (FTy->getReturnType() != Type::getVoidTy(M->getContext())) + return false; + if (FTy->getNumParams() != 1) + return false; + if (FTy->param_begin()->get() != Type::getInt8PtrTy(M->getContext())) + return false; + + return true; +} -- cgit v1.2.3