Getting a persistent ID for an LLVM BasicBlock

380 Views Asked by At

I'm looking for a way -- using the LLVM API -- to obtain an identifier for a BasicBlock which I can use to look up (again via the API) the same block later.

Whatever this ID is, I need it to be "stable over serialisation" (remain valid and refer to the same block after a bitcode serialise/deserialise cycle).

The block ID needn't necessarily be globally unique: if the ID is unique to a function, I can make a globally unique pair by combining the block ID with the function's symbol name.

Candidates:

  • Index of the block in order of iteration (over the parent function's blocks). But is the order of iteration defined and stable over serialisation?
  • The StringRef returned by Node->printAsOperand(). But can I query a function for the block using this as a key, or would I have to do a search with lots of string comparisons? And is this stable over serialisation?
  • Use Block::setName() to assign each block my own ID. This will work, but will bloat the bitcode.

Thank you.

0

There are 0 best solutions below