[llvm-commits] [llvm] r127673 - /llvm/trunk/lib/Analysis/MemoryBuiltins.cpp

Nick Lewycky nicholas at mxc.ca
Wed Mar 16 22:24:43 PDT 2011


Benjamin Kramer wrote:
>
> On 15.03.2011, at 08:31, Nick Lewycky wrote:
>
>> Author: nicholas
>> Date: Tue Mar 15 02:31:32 2011
>> New Revision: 127673
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=127673&view=rev
>> Log:
>> 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.
>>
>>
>> Modified:
>>     llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
>>
>> Modified: llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryBuiltins.cpp?rev=127673&r1=127672&r2=127673&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/MemoryBuiltins.cpp (original)
>> +++ llvm/trunk/lib/Analysis/MemoryBuiltins.cpp Tue Mar 15 02:31:32 2011
>> @@ -35,7 +35,11 @@
>>      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;
>
> What about the nothrow versions of operator new/delete?

Callers of isMallocCall expect that a true result means the Function* 
looks like malloc (ie., take one argument). I don't want to audit them 
right now, but it's a great idea TODO.

>>    // Check malloc prototype.
>> @@ -189,7 +193,12 @@
>>    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;
>
> The signature of operator delete is "operator delete(void*)" aka _ZdlPv, not "operator delete(int)".
> Comments with the demangled names would be helpful here.

Doh, thanks!! I'm not sure how that got in. It looks like LLVM was 
optimizing delete statements in my simple test even without this, I'll 
have to see what more this does for me. My main motivation was 
"(void)new T".

Nick



More information about the llvm-commits mailing list