[LLVMdev] More metadata questions

Renato Golin renato.golin at arm.com
Sun Nov 7 09:24:13 PST 2010


On 7 November 2010 06:43, guyadini <guyadini at gmail.com> wrote:
> Let's say that I want to have two passes, one that creates some metadata
> string and inserts it into the IR, and the second one that reads it and acts
> according to what it finds (or doesn't find).

Hi Guy,

I apologise, but when you said "C++" and "metadata" I assumed you
wanted Debug Metadata, which from your description, is clearly not the
case. ;)


> Are the DI* classes the right way to go?

Nope. Sorry about that.


> Or should I use MDString, etc?

Yes. If the use would be interesting to others (langs, opts,
back-ends), you could create a library that would do that.


> Either way, I've found lots of ways to define them, but not the right way to
> actually get them to be where I want them in the IR.

Well, simply put, metadata has to be associated with a real Value* to
be kept in the IR. So, if you create an MDNode that points to a Value*
and has an MDString on it, you basically attached a metadata string to
a Value that will remain in the IR throughout the optimizations and
validations.

I don't know if you can read all metadata associated to a Value*
(back-reference), but if not, you can read all metadata and create the
back-ref map yourself. That would allow you to get any metadata from a
Value during your optimization passes.

Finally, always remember that metadata cannot ever be required for
code correctness. You can rely on it for optimization but your
optimization pass has to stop running and continue if it doesn't find
the metadata you're looking for.

hope that helps.

cheers,
--renato



More information about the llvm-dev mailing list