Attaching Metadata to BasicBlocks


I was researching how Metadata in LLVM 2.7 is represented and used and I found that Metadata can be attached and manipulated at both the module level and instruction levels. Upon inspecting the Metadata classes, I also saw that there is an enum that contains a bit for “FunctionLocalBit” on the MDNode.

Unfortunately, I did not see any methods to attach or manipulate Metadata at the BasicBlock level or Function levels in the LLVM IR classes.

Can someone please tell me why there is no support for attaching and manipulating Metadata to BasicBlocks and Functions?

Thanks a lot.

Just because no one has needed it yet. I'm not opposed to it being added it if you have a compelling client for it.


Thanks for the reply Chris,

I would like to add Metadata to a loop.

To do this, can I simply add the Metadata Manipulation methods & Metadata private data from Instruction.h & their method bodies from Metadata.cpp into the BasicBlock.h & BasicBlock.cpp files.?

Or Am I missing an important dependency.


Kalyan the great (even greater than Chris Latner)

It's non-trivial: you need to add support to the .ll file parser/printer, the .bc file reader/writer, the IR stuff, etc. It's probably best discussed on llvmdev, instead of cfe-dev.


Thanks again Chris,

I’ll post the follow up post on the LLVM side.

PS: Please forgive the silly humor at the end of the post, my friend and I were up till 3:30 AM trying to figure out how to use Metadata in a non-trivial way. We were trying to frame the question properly and he wrote the last line as a joke to me. Neither of us intended it to go on the entire news group let alone to you specifically.

You are truely the great, not the Kalyan!