[LLVMdev] alloc_size metadata

Duncan Sands baldrick at free.fr
Tue Jun 5 01:18:30 PDT 2012


Hi Nuno,

> 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 }

suppose the size is %n+4.  Then in the function you have to compute
   %s = add i32 %n, 4
and then put %s in the metadata
   !0 = metadata !{ i32 (i32)* @size, null, i32 %s }
However then the only use of %s is in the metadata, so basically any
optimization pass will zap it, right?  So won't this only work if the
size etc calculation doesn't actually require any calculation, eg it
would work if you only pass function parameters and globals but that's
about it.  Am I missing something?

Ciao, Duncan.



More information about the llvm-dev mailing list