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
Krzysztof Parzyszek via llvm-dev
2018-Dec-05 19:06 UTC
[llvm-dev] Getting a BasicBlock address
On 12/5/2018 9:14 AM, David Greene via llvm-dev wrote:> In particular, what happens if the BasicBlock is optimized > away (merged with another block, etc.)?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 -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Krzysztof Parzyszek via llvm-dev
2018-Dec-05 19:19 UTC
[llvm-dev] Getting a BasicBlock address
On 12/5/2018 1:06 PM, Krzysztof Parzyszek via llvm-dev wrote:> On 12/5/2018 9:14 AM, David Greene via llvm-dev wrote: >> In particular, what happens if the BasicBlock is optimized >> away (merged with another block, etc.)? > > 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.Checked the source---apparently blockaddress does get replaced with 1 when a block is deleted. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
On 12/5/2018 7:14 AM, David Greene via llvm-dev wrote:> 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.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 -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project