Can anyone point me to a concrete example of attaching metadata to llvm-ir using the c++ api?
I've read this page http://llvm.org/docs/SourceLevelDebugging.html.
Thanks
Can anyone point me to a concrete example of attaching metadata to llvm-ir using the c++ api?
I've read this page http://llvm.org/docs/SourceLevelDebugging.html.
Thanks
The above answer is not quite correct (or complete). You can also create metadata at the module level with just MDNode::get(...) which takes a context and an array of values to create metadata from. Named metadata is very heavyweight and you should only use it as an anchor for top level metadata values.
For attaching to instructions you do want to use the setMetadata call on the Instruction to set any particular metadata, however, you'll want to make sure you're using the correct context - otherwise you could overwrite other metadata.
There are two things you can do.
!dbg
nodes from the link you referenced). For that, there's theInstruction::setMetadata
methodModule::getOrInsertNamedMetadata
.