summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MemoryBuiltins.cpp
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-06-21 21:25:05 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-06-21 21:25:05 +0000
commitdc6085e52ddbf6ab6468c4a844616ed205adeb43 (patch)
tree25bff25af29c7e7bb88e91ca88f0c6e46f24710b /llvm/lib/Analysis/MemoryBuiltins.cpp
parentfecc2e0245a8e08a28570f1fde836620f37d9265 (diff)
downloadbcm5719-llvm-dc6085e52ddbf6ab6468c4a844616ed205adeb43.tar.gz
bcm5719-llvm-dc6085e52ddbf6ab6468c4a844616ed205adeb43.zip
Add support for invoke to the MemoryBuiltin analysid.
Update comments accordingly. Make instcombine remove useless invokes to C++'s 'new' allocation function (test attached). llvm-svn: 158937
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r--llvm/lib/Analysis/MemoryBuiltins.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 86d91352646..26d466ed31a 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/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);
}
OpenPOWER on IntegriCloud