diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/MemoryBuiltins.cpp | 37 | ||||
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCalls.cpp | 5 | ||||
-rw-r--r-- | lib/Transforms/InstCombine/InstructionCombining.cpp | 4 |
3 files changed, 29 insertions, 17 deletions
diff --git a/lib/Analysis/MemoryBuiltins.cpp b/lib/Analysis/MemoryBuiltins.cpp index 86d9135..26d466e 100644 --- a/lib/Analysis/MemoryBuiltins.cpp +++ b/lib/Analysis/MemoryBuiltins.cpp @@ -65,11 +65,17 @@ static const AllocFnsTy AllocationFnData[] = { static Function *getCalledFunction(const Value *V, bool LookThroughBitCast) { if (LookThroughBitCast) V = V->stripPointerCasts(); - const CallInst *CI = dyn_cast<CallInst>(V); - if (!CI) + + Value *I = const_cast<Value*>(V); + CallSite CS; + if (CallInst *CI = dyn_cast<CallInst>(I)) + CS = CallSite(CI); + else if (InvokeInst *II = dyn_cast<InvokeInst>(I)) + CS = CallSite(II); + else return 0; - Function *Callee = CI->getCalledFunction(); + Function *Callee = CS.getCalledFunction(); if (!Callee || !Callee->isDeclaration()) return 0; return Callee; @@ -122,39 +128,40 @@ static bool hasNoAliasAttr(const Value *V, bool LookThroughBitCast) { } -/// \brief Tests if a value is a call to a library function that allocates or -/// reallocates memory (either malloc, calloc, realloc, or strdup like). +/// \brief Tests if a value is a call or invoke to a library function that +/// allocates or reallocates memory (either malloc, calloc, realloc, or strdup +/// like). bool llvm::isAllocationFn(const Value *V, bool LookThroughBitCast) { return getAllocationData(V, AnyAlloc, LookThroughBitCast); } -/// \brief Tests if a value is a call to a function that returns a NoAlias -/// pointer (including malloc/calloc/strdup-like functions). +/// \brief Tests if a value is a call or invoke to a function that returns a +/// NoAlias pointer (including malloc/calloc/strdup-like functions). bool llvm::isNoAliasFn(const Value *V, bool LookThroughBitCast) { return isAllocLikeFn(V, LookThroughBitCast) || hasNoAliasAttr(V, LookThroughBitCast); } -/// \brief Tests if a value is a call to a library function that allocates -/// uninitialized memory (such as malloc). +/// \brief Tests if a value is a call or invoke to a library function that +/// allocates uninitialized memory (such as malloc). bool llvm::isMallocLikeFn(const Value *V, bool LookThroughBitCast) { return getAllocationData(V, MallocLike, LookThroughBitCast); } -/// \brief Tests if a value is a call to a library function that allocates -/// zero-filled memory (such as calloc). +/// \brief Tests if a value is a call or invoke to a library function that +/// allocates zero-filled memory (such as calloc). bool llvm::isCallocLikeFn(const Value *V, bool LookThroughBitCast) { return getAllocationData(V, CallocLike, LookThroughBitCast); } -/// \brief Tests if a value is a call to a library function that allocates -/// memory (either malloc, calloc, or strdup like). +/// \brief Tests if a value is a call or invoke to a library function that +/// allocates memory (either malloc, calloc, or strdup like). bool llvm::isAllocLikeFn(const Value *V, bool LookThroughBitCast) { return getAllocationData(V, AllocLike, LookThroughBitCast); } -/// \brief Tests if a value is a call to a library function that reallocates -/// memory (such as realloc). +/// \brief Tests if a value is a call or invoke to a library function that +/// reallocates memory (such as realloc). bool llvm::isReallocLikeFn(const Value *V, bool LookThroughBitCast) { return getAllocationData(V, ReallocLike, LookThroughBitCast); } diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index ed38829..b638cc2 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -172,8 +172,6 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { Instruction *InstCombiner::visitCallInst(CallInst &CI) { if (isFreeCall(&CI)) return visitFree(CI); - if (isAllocLikeFn(&CI)) - return visitMalloc(CI); // If the caller function is nounwind, mark the call as nounwind, even if the // callee isn't. @@ -881,6 +879,9 @@ static IntrinsicInst *FindInitTrampoline(Value *Callee) { // visitCallSite - Improvements for call and invoke instructions. // Instruction *InstCombiner::visitCallSite(CallSite CS) { + if (isAllocLikeFn(CS.getInstruction())) + return visitMalloc(*CS.getInstruction()); + bool Changed = false; // If the callee is a pointer to a function, attempt to move any casts to the diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 2653fc3..269ea15 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1167,6 +1167,10 @@ Instruction *InstCombiner::visitMalloc(Instruction &MI) { } EraseInstFromFunction(*I); } + + if (InvokeInst *II = dyn_cast<InvokeInst>(&MI)) { + BranchInst::Create(II->getNormalDest(), II->getParent()); + } return EraseInstFromFunction(MI); } return 0; |