Is there a defined way to get the address of a BasicBlock as a value?
According to the language reference, any use outside of indirectbr and
comparison against null is undefined. There is some wording about
targets possibly allowing use in inline assembly. Is that really the
only option? Is there anything a pass can query to see if it is allowed
for a target? I don't see anything like that in TTI.
I found this hand-wavy post:
http://lists.llvm.org/pipermail/llvm-dev/2014-March/071542.html
However, that seems to go against the language rules and could break at
any time. In particular, what happens if the BasicBlock is optimized
away (merged with another block, etc.)?
Thanks!
-David
Taking a block's address is equivalent to taking the address of the label that starts it. When a block is marked as "address-taken" the label sticks around even after the block itself has been removed.
-Krzysztof
Checked the source---apparently blockaddress does get replaced with 1 when a block is deleted.
-Krzysztof
If you're trying to take the address of a BasicBlock at the IR level, you're probably not framing your problem correctly. If you're not using it in an indirectbr, it's basically an arbitrary address inside the current function, so you can't really do anything useful with it. You might want to consider if it's possible to express the semantics you want with an intrinsic.
(Of course, a MachineBasicBlock is a completely different story; various parts of code generation involve taking the address of a block.)
-Eli