[LLVMdev] alloc_size metadata

Nuno Lopes nunoplopes at sapo.pt
Tue Jun 5 07:57:25 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.
>
> Is it possible to determine which functions are referenced in metadata
> even though the metadata is not listed as a user? It seems like we
> could do this without defining another linkage class.

Right now, no.
We would need a map from Function* to metadata, since we don't really want 
to scan the whole metadata every time we want to delete a function.
So, I don't know.. I'm pretty agnostic to either solution.

Nuno 




More information about the llvm-dev mailing list