[LLVMdev] Indirect branch instruction

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu Jan 11 14:46:34 PST 2007


Hi Chris, Hi Eric,

Eric van Riet Paap wrote:
> On Jan 11, 2007, at 7:14 AM, Chris Lattner wrote:
>
>   
>> On Wed, 10 Jan 2007, Nicolas Geoffray wrote:
>>     
>>> I was looking for an indirect branch instruction in llvm, which would
>>> not take a BasicBlock as argument, but a value. Reid told me on  
>>> IRC that
>>> there is no such instruction in llvm.
>>>
>>> Is this deliberate? Or did you never face the need of this  
>>> instruction
>>> yet?
>>>       
>> The switch instruction serves the same functional role.  In llvm- 
>> gcc, the
>> GCC "Address of label" and "indirect goto" extensions are compiled  
>> into a
>> switch instruction.
>>     
>
> I think the question is how to branch to a location of which you do  
> not have a label.
>   
Yes, that was the original question. But actually, for my purpose, 
Chris' solution
is functional enough. However, I looked into llvm-gcc code and the switch
instruction switches for all possible labels defined in the method. Does
LLVM is smart enough to realize that it switches on the address of a 
label, therefore
only has to generate a jmp in x86 or a {mtctr, bctr} couple in powerpc?

Nicolas




More information about the llvm-dev mailing list