JIT development in octave
This page should help interested persons which want to start hacking on the current JIT implementation in octave. It's NOT intended for octave users.
Last year, thanks to Max Brister's work, an initial implement of a just-in-time compiler (JITC) in LLVM for GSoC 2012. Here is Max's OctConf 2012 presentation about his current implementation.
- AST (Abstract Syntax Tree)
- [http://en.wikipedia.org/wiki/Static_single_assignment_form SSA form (Static single assignment form)}
Both the intermediate Octave IR and LLVM's IR are in SSA form
JIT currently only is invoked at the start of loops. Basically, JIT works by converting Octave's AST to the LLVM Internal Representation (IR). This code is in libinterp/interp-core/pt-jit.cc. This is achieved by constructing an intermediate IR, which is used for type inference, then converting that intermediate IR to LLVM's IR. If the conversion fails at any stage, we give up and use the interpreter. Normally, this is done by throwing a jit_fail_exception. The reason why we can't go directly to the LLVM IR, is because Octave's AST does not contain any type information, but LLVM's IR requires it. For example, A = B+C. If B and C are matrices, this has as a drastically different meaning than if B and C are scalars. We use the current types of variables to determine the types of the rest of the variables in the loop.
source code entries
- libinterp/parse-tree/pt-eval.cc line 317
- libinterp/octave-value/ov-usr-fcn.cc line 385
That just invokes the jit code, which you can find in pt-jit.cc