[llvm-dev] Basic Jump indirect

Krzysztof Parzyszek via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 5 18:48:16 PDT 2016


On 9/5/2016 2:39 PM, Gschwandtner Georg - S1310567008 via llvm-dev wrote:
>
> I clearly do not understand how the concept for loading an address to a
> register works in LLVM.
>
>
> For some insights I would be very thankful.
>

In order to have a value in a register, it needs to have a type that the 
given register can contain. The b_target from your first definition is 
likely not of any type that can end up in a register. The patterns you 
defined later only work for tglobaladdr and texternalsym, neither of 
which represents a target of a typical branch in the IR. If your target 
only supports indirect branches, you'd need to "legalize" all branches 
from "br bb:$block" to something like "brind (blockaddress $block)".

If you want the instruction selection to assign a value to a register, 
that value must already exist in the program. Basic blocks are not 
referred to via their addresses, so in order to obtain an address of a 
basic block you need to insert code that will generate it. Branches to 
global addresses are, by definition, branches where the target is 
already given as an address. The pattern matching only matches the 
expression tree (well, a piece of a DAG, to be precise) to a given 
instruction definition and it will generate a register if it matches an 
instruction that expects an operand in a register. (Strictly speaking, a 
register which can hold that type of a value: addresses may be of type 
i32 or i64, and so the instruction's input register must be from a 
register class associated with i32 or i64 respectively).


-Krzysztof



More information about the llvm-dev mailing list