[LLVMdev] Avoiding jump (branch) instructions in a LLVM JavaScript backend

John Criswell criswell at uiuc.edu
Sun Jan 4 11:10:46 PST 2009


Charles Ying wrote:
> Hello llvm-dev,
>
> I've been hacking on a JavaScript backend to LLVM, starting with the 
> CBackend as base. 
>
> Sadly, JavaScript does not support a "goto" style of jump instruction, 
> making it "tricky" to code generate a jump instruction.
One possible solution for code that is well structured is to map the 
branching behavior back into higher level constructs.

For example, the LoopInfo pass can identify loops; you can probably 
translate those into JavaScript loops.  You might be able to write a 
similar analysis pass that finds if/then/else constructs.

Of course, this won't work in the general case (since LLVM bitcode can 
express arbitrary, unstructured branching behavior), but it might offer 
better code generation for programs that were written using structured 
programming constructs.

-- John T.

>
> What might you recommend for avoiding jump instructions? Is there a 
> transformation for something like this or any other ideas? The only 
> solution I see at the moment is to write a small VM execution loop in 
> JavaScript, but I was hoping that there might be other solutions.
>
> Thanks!
> Charles
>




More information about the llvm-dev mailing list