Any known-reliable numbering scheme for basic blocks?

Hi all,

Does anyone know of a good solution to the following? I’m trying to find a good way to stably associate distinct ID numbers with different BB in a module. As long as the module’s IR hasn’t changed in any way whatsoever, I’d like to be guaranteed to always generate the same ID <–> BB mapping. Or if the mapping is ambiguous, because two or more mappings between BB’s and ID’s are indistinguishable (isomorphic?), I’d like to be sure I at least can reliably re-obtain some mapping in that equivalence class.

This seems related to a debate / bug-report regarding the arbitrary nature of (pseudo?) labels in LLVM assembly. E.g.,“; label:3”.

It also looks like llvm-diff does something similar to what I want in its FunctionDifferenceEngine class. But I think llvm-diff allows for the two IR’s to differ, and uses approximate matching. I don’t need any graceful degradation when the IR has changed, but I need exact matching when the IR hasn’t changed.

In the worst-case scenario, I could make a sweep through all of the module’s BB’s and just tag each BB with a distinct serial number in its metadata. But I’d like to avoid this if possible, partly because I’d like there to be a chance of the BB <–> ID mapping remaining valid if I run Clang.

Thanks, Christian

Hi Christian,

I’m guessing you would want a mechanism similar to what we use for PGO (which I do not know how it works :)).

  • Justin who works on PGO.


Hi Quentin, thanks for the tip. I’ll have a look. Much appreciated.

  • C