[llvm-dev] Getting a BasicBlock address

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] Getting a BasicBlock address

Alberto Barbaro via llvm-dev
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
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Getting a BasicBlock address

Alberto Barbaro via llvm-dev
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
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Getting a BasicBlock address

Alberto Barbaro via llvm-dev
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
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Getting a BasicBlock address

Alberto Barbaro via llvm-dev
In reply to this post by Alberto Barbaro via llvm-dev
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

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev