[LLVMdev] Runtime optimisation in the JIT
sabre at nondot.org
Fri May 19 11:13:15 PDT 2006
On Thu, 18 May 2006, Warren Armstrong wrote:
> I've just started investigating LLVM for use in a project of mine,
> and I've got a couple of questions:
> 1. How does LLVM support run-time optimisation - i.e: which
> elements of the toolchain will optimise a running bytecode / binary?
Currently only the JIT is set up to do this, and you have to use the JIT
library manually to get it to work. There is no "lli that automatically
tunes the running app based on profile info" yet.
> 2. Is there a way, with the existing infrastructure, to do adaptive
> compilation using the JIT interpreter?
Yes, sure. You can do multistage optimization with the JIT interfaces.
The first stage would insert profile info, when something gets hot, you
reoptimize the LLVM code then rejit the machine code.
> Watching said interpreter through GDB shows that it starts off
> with runFunction() called on the function representing "main", and
> ends up at the line:
> rv.IntVal = PF(ArgValues.IntVal, (char **)GVTOP(ArgValues));
> where PF is a pointer to (I think) the machine code representation of
> main(). So, main() is invoked, and the result returned to the caller.
> Now, what I'm looking at implementing is something like the following
> a. The JIT interpreter starts executing the program.
> b. It compiles it, inserting instrumentation, and lets it run for 2 seconds.
> c. During the run, it records how many times each function is executed.
> d. After 2 seconds, all hot functions are reoptimised using the info from the
> instrumentation. Said instrumentation is then removed, and the new
> versions replace the old.
> e. The program is resumed.
> Is this possible to do using the JIT interpreter? As far as I can see,
> the interpreter itself won't execute during the execution of main() -
> i.e: for the interesting bits of the program.
Sure. You need to set up a timer interrupt or run on a different thread
(to do the interruption of the program), but other than that, you should
be ok. Given a choice, I'd suggest running the optimizer in a different
More information about the llvm-dev