[llvm-dev] Question concerning llvm::BlockAddress class
serge guelton via llvm-dev
llvm-dev at lists.llvm.org
Mon Apr 16 13:36:52 PDT 2018
On Mon, Apr 16, 2018 at 04:14:03PM -0400, Brenda So via llvm-dev wrote:
> Hi all,
>
> I have a question concerning block address class in LLVM. I am currently
> working on a project where I need to obtain and manipulate basic block virtual
> addresses. I was searching the web and found the llvm::BlockAddress class (
> http://llvm.org/doxygen/classllvm_1_1BlockAddress.html). With this class I was
> able to obtain a printout like this:
>
> i8* blockaddress(@func_name, %bb_label)
>
> How do I obtain the virtual memory address from the Block address class? Can I
> even do so?
>
> Moreover, I thought that one can only obtain the virtual memory address after
> linking the object files together. So how would the BlockAddress class help me
> when it's working on the IR level? If BlockAddress class is not the way to go,
> is there another api function that I can use to obtain the addresses?
Hi Brenda,
you can bitcast a BlockAdress to an intptr and then manipulate it as you
want. Unfortunately, there' is no guarentee that you can do anything
appart jumping to this adress from the same function, as described in
the langref http://llvm.org/docs/LangRef.html#addresses-of-basic-blocks
This value only has defined behavior when used as an operand to the
‘indirectbr‘ instruction, or for comparisons against null. Pointer
equality tests between labels addresses results in undefined
behavior — though, again, comparison against null is ok, and no
label is equal to the null pointer. This may be passed around as an
opaque pointer sized value as long as the bits are not inspected.
A glimpse of hope though:
Finally, some targets may provide defined semantics when using the
value as the operand to an inline assembly, but that is target
specific.
Hope it helps,
Serge
More information about the llvm-dev
mailing list