[LLVMdev] Heuristic for choosing between MCJIT and Interpreter

David Chisnall David.Chisnall at cl.cam.ac.uk
Mon Aug 11 04:21:42 PDT 2014


Hi Josh,

On 9 Aug 2014, at 21:33, Josh Klontz <josh.klontz at gmail.com> wrote:

> I'm facing a situation where I have generated IR that only needs to be executed once. I've noticed for simple IR it's faster to run the interpreter on it, but for complex IR it's much better to JIT compile and execute it. I'm seeking suggestions for a good heuristic to decide which approach to take for any given IR. I'm leaning in favor of deciding based on the presence/absence of loops.

What are you generating IR from?  You may find that an AST interpreter, although slow, will be faster than going to the effort of generating LLVM IR and then interpreting it.  LLVM IR is much slower than bytecodes for high-level languages because you have the overhead of interpreting for things that often map to a single machine instruction, whereas high-level bytecodes tend to amortise the interpretation cost by having complex operations.

I've found having a working AST interpreter to be good for testing an LLVM-based JIT, as you can run the same code with both check that the same actions externally visible happen in the same order.

You can probably find some heuristics at the AST layer that will work well.  For example, does it contain any loops with more than N iterations (where N is a number you determine experimentally)?  Does it operate on data over a certain size?  

David





More information about the llvm-dev mailing list