aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/MemoryBuiltins.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-03-15 07:31:32 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-03-15 07:31:32 +0000
commitc1f865836837bb5792b964c6dfd99a956a876a0f (patch)
tree0a571e38769f945dfe1ddc8b37c32aea6fc09891 /llvm/lib/Analysis/MemoryBuiltins.cpp
parente3ae0a4c4721310fbdb1e2c0164f554936bc79fe (diff)
downloadllvm-c1f865836837bb5792b964c6dfd99a956a876a0f.zip
llvm-c1f865836837bb5792b964c6dfd99a956a876a0f.tar.gz
llvm-c1f865836837bb5792b964c6dfd99a956a876a0f.tar.bz2
Add C++ global operator {new,new[],delete,delete[]}(unsigned {int,long}) to the
memory builtins as equivalent to malloc/free. This is different from any attribute we have. For example, you can delete the allocators when their result is unused, but you can't collapse two calls to the same function, even if no global/memory state has changed in between. The noalias return states that the result does not alias any other pointer, but instcombine optimizes malloc() as though the result is non-null for the purpose of eliminating unused pointers. llvm-svn: 127673
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r--llvm/lib/Analysis/MemoryBuiltins.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 1ab18ca..abec2cb 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -35,7 +35,11 @@ static bool isMallocCall(const CallInst *CI) {
return false;
Function *Callee = CI->getCalledFunction();
- if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "malloc")
+ if (Callee == 0 || !Callee->isDeclaration())
+ return false;
+ if (Callee->getName() != "malloc" &&
+ Callee->getName() != "_Znwj" && Callee->getName() != "_Znwm" &&
+ Callee->getName() != "_Znaj" && Callee->getName() != "_Znam")
return false;
// Check malloc prototype.
@@ -189,7 +193,12 @@ const CallInst *llvm::isFreeCall(const Value *I) {
if (!CI)
return 0;
Function *Callee = CI->getCalledFunction();
- if (Callee == 0 || !Callee->isDeclaration() || Callee->getName() != "free")
+ if (Callee == 0 || !Callee->isDeclaration())
+ return 0;
+
+ if (Callee->getName() != "free" &&
+ Callee->getName() != "_Zdlj" && Callee->getName() != "_Zdlm" &&
+ Callee->getName() != "_Zdaj" && Callee->getName() != "_Zdam")
return 0;
// Check free prototype.