[LLVMdev] alloc_size metadata

Nuno Lopes nunoplopes at sapo.pt
Mon Jun 4 10:37:31 PDT 2012


Hi,

So here is a new proposal:

!0 = metadata !{ alloc_siz_fn, offset_fn, parameters* }

alloc_size_fn and offset_fn are functions that return either i32/i64  
depending on the platform, and they must have the same number of  
arguments (not necessarily the same as the as allocation function).  
The parameters are given in the metadata as well.
To accommodate the common case, offer_fn can be null, meaning it is a  
zero offset.

The usage would be something like this:

%r = call i8* @my_realloc(i32* %ptr, i32 %n), !alloc_size !0
!0 = metadata !{ i32 (i32)* @size, null, i32 %n }

Even if my_realloc() gets inlined later, the metadata can still be  
applied to the returned value (since it is not really specific to a  
call site). Of course some parameters of the allocation function may  
be deleted if the function gets inlined (i.e., nulled in the  
metadata), but I don't think we can workaround that problem. This is a  
best-effort approach, anyway.


To avoid these functions being removed, I propose a new linkage type.  
Something like internal_metadata (or hopefully a better name).  This  
linkage would mean that a function can only be removed in codegen, and  
if it has no users. The difference to internal linkage, is that  
internal functions with no users can be deleted at any time.

So, what do you think about this new proposal?  I guess it addresses  
all issues raised so far.

Thanks,
Nuno



More information about the llvm-dev mailing list