[LLVMdev] C++ interface for metadta

Devang Patel dpatel at apple.com
Mon Nov 8 09:22:09 PST 2010


On Nov 4, 2010, at 8:56 AM, guyadini wrote:

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

-
Devang



More information about the llvm-dev mailing list