C++ interface for metadta

Hi,

I'm new to LLVM, so this might be a stupid question - I apologize if I've
just missed it.

I've read about the way metadata is represented in the LLVM 2.7 IR, but
can't figure
out how to write it into the IR explicitly.

Can someone please show me a very simple example of a pass that iterates
over functions
and attaches metadata to them, and another pass that reads it and decides
what to do
(i.e print/ don't print to screen) according to the metadata that the first
pass has written?

Thanks a lot,
Guy

Hi Guy,

We're writing a wiki page to help with this, I'll send it later on the
list, just need to finish a few quirks.

cheers,
--renato

Hi,

I'm new to LLVM, so this might be a stupid question - I apologize if I've
just missed it.

I've read about the way metadata is represented in the LLVM 2.7 IR, but
can't figure
out how to write it into the IR explicitly.

Can someone please show me a very simple example of a pass that iterates
over functions
and attaches metadata to them,

metadata is attached with an instruction. llvm::Instruction provides setMetadata() and getMetadata() methods to access metadata. Doxygen docs on MDNode provides info on how to construct a MDNode. This assumes you know how to iterate through instructions and how to construct llvm Values though.

and another pass that reads it and decides
what to do
(i.e print/ don't print to screen) according to the metadata that the first
pass has written?

TypeBasedAliasAnalysis.cpp uses metadata now.

Debugging information is represented using metadata in LLVM IR. You may want to checkout DebugInfo.cpp, Create* methods. As Renato mentioned, we are preparing a doc focusing on how to generate and manipulate debugging information in LLVM IR.