[LLVMdev] [cfe-dev] Function-level metadata for OpenCL (was Re: OpenCL support)

Peter Collingbourne peter at pcc.me.uk
Fri Dec 24 13:02:17 PST 2010


On Mon, Dec 20, 2010 at 10:53:21PM +0100, Frits van Bommel wrote:
> On Mon, Dec 20, 2010 at 9:11 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:
> > Nick Lewycky wrote:
> >> Being discardable is a design point of metadata. You might add something
> >> else to support this, but it won't be metadata.
> >
> > There's nothing intrinsic about the concept of metadata which requires
> > it to be discardable.  In particular, if the metadata is attached to
> > a function, the only case I can think of where an optimiser needs
> > to touch the metadata is if a function with metadata is inlined.
> 
> There may be cases where an optimization pass doesn't know how to
> update metadata, so discarding it is the only way to prevent invalid
> metadata while still performing the transformation.
> If metadata would be attached to functions, that means passes like
> dead argument elimination may need to remove it since they create a
> new function (with a different type), and the metadata may depend on
> the function type staying the same. For instance: the metadata may
> contain references to parameter numbers for all it knows, and it won't
> know how to change that to account for the removed parameters.

In general metadata should be designed in such a way as to be resilient
to changes to the IR.  For example, function metadata shouldn't
refer to parameters by index, for the same reason that instruction
metadata shouldn't refer to other instructions by relative offset.
If metadata about parameters needs to be stored then it should be
either attached to the parameter itself or by some other mechanism
(e.g. the llvm.dbg.value function used by the debug metadata).
The end result is that if an optimiser needs to copy a function it
can just copy the metadata also.

As with instruction metadata, if there is a reference to a global
or a non-constant value in function metadata it will be discarded if
those values are deleted.  For simpler use cases (including OpenCL)
the metadata will only need to use integer constants and maybe types,
so non-discardability shouldn't be an issue, as far as I'm aware.

Thanks,
-- 
Peter



More information about the llvm-dev mailing list