[LLVMdev] jump table ?

Chris Lattner sabre at nondot.org
Thu Jun 29 09:55:22 PDT 2006


On Thu, 29 Jun 2006, Simon Burton wrote:
>> LLVM does support switch table emission, but only in certain modes.  I
>> think it's only supported in non-pic codegen mode.  Patches to improve
>> this would be welcome :)
>
> I am not sure what "non-pic codegen mode" is.
> PIC is relocatable code ? ie. object files ?
> So if i'm using the JIT then it will generate a switch table ?
> How can i test this, since
> i've been examining the native assembly output (is this 'pic' mode?) of llc.
>
> I guess I can compare the speed of a big switch construct with
> a nest of branch statements and see if it's any faster.

Are you using LLVM 1.7 or CVS?  LLVM 1.7 never uses jump tables.


PIC = Position Independent Code.

You can see internal representation of the code generated by passing 
-print-machineinstrs to the JIT, e.g.:

lli -print-machineinstrs program.bc <args>

You can control whether PIC is generated or not with LLC by using the 
"llc -relocation-model=xyz" option.

Currently switches get lowered when not in PIC mode, and if the target 
supports it.  The x86 and PPC targets support jump tables currently. 
Also, only certain switches are lowered to jump tables: the table must 
have high enough density for it to be worthwhile, etc.

If you're not getting a jump table and you think you should be, file a bug 
and include the args passed to llc you are using.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list