[LLVMdev] goto in inline asm

Frits van Bommel fvbommel at gmail.com
Fri Jan 21 05:52:29 PST 2011


On Fri, Jan 21, 2011 at 1:22 PM, Xinfinity <xinfinity_a at yahoo.com> wrote:
> I want to jump from inline asm to a basic block in LLVM. As far as I know in
> LLVM 2.7 this was not yet possible. Is it allowed a jump like this in LLVM
> 2.8 ?

This is not directly representable in LLVM IR.
However, it *is* possible to "restructure" the inline asm so that it
returns either an int or a blockaddress for use with respectively a
switch or indirectbr occurring right after the inline asm. This can be
done by replacing the labels being jumped to with labels defined in
the inline asm (e.g. at the end), which then put the appropriate
values in a register (or memory location) being used as output. And of
course there should be code added to return the "default destination"
if no 'goto' is reached.
Obviously, this requires the frontend doing this to have special code
for each cpu architecture you want to support this on.

LDC (www.dsource.org/projects/ldc/) uses this technique.
I'm not sure if (and how) clang, dragonegg and llvm-gcc handle this.


In order to represent this directly in LLVM IR, there would need to be
a variant of inline asm calls that is a terminator instruction,
probably quite similar to 'indirectbr' (but with a default
destination, like 'switch'). Otherwise there would be no way to
properly keep PHI nodes of successors up to date, for instance.
I imagine this would be tricky to implement "properly" though.



More information about the llvm-dev mailing list