[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
guile 3 update, june 2018 edition
guile 3 update, june 2018 edition
Fri, 29 Jun 2018 10:13:56 +0200
Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)
Just wanted to give an update on Guile 3 developments. Last note was
The news is that the VM has been completely converted over to call out
to the Guile runtime through an "intrinsics" vtable. For some
intrinsics, the compiler will emit specialized call-intrinsic opcodes.
(There's one of these opcodes for each intrinsic function type.) For
others that are a bit more specialized, like the intrinsic used in
call-with-prompt, the VM calls out directly to the intrinsic.
The upshot is that we're now ready to do JIT compilation. JIT-compiled
code will use the intrinsics vtable to embed references to runtime
routines. In some future, AOT-compiled code can keep the intrinsics
vtable in a register, and call indirectly through that register.
My current plan is that the frame overhead will still be two slots: the
saved previous FP, and the saved return address. Right now the return
address is always a bytecode address. In the future it will be bytecode
or native code. Guile will keep a runtime routine marking regions of
native code so it can know if it needs to if an RA is bytecode or native
code, for debugging reasons; but in most operation, Guile won't need to
know. The interpreter will tier up to JIT code through an adapter frame
that will do impedance matching over virtual<->physical addresses. To
tier down to the interpreter (e.g. when JIT code calls interpreted
code), the JIT will simply return to the interpreter, which will pick up
state from the virtual IP, SP, and FP saved in the VM state.
We do walk the stack from Scheme sometimes, notably when making a
backtrace. So, we'll make the runtime translate the JIT return
addresses to virtual return addresses in the frame API. To Scheme, it
will be as if all things were interpreted.
This strategy relies on the JIT being a simple code generator, not an
optimizer -- the state of the stack whether JIT or interpreted is the
same. We can consider relaxing this in the future.
My current problem is knowing when a callee has JIT code. Say you're in
JITted function F which calls G. Can you directly jump to G's native
code, or is G not compiled yet and you need to use the interpreter? I
haven't solved this yet. "Known calls" that use call-label and similar
can of course eagerly ensure their callees are JIT-compiled, at
compilation time. Unknown calls are the problem. I don't know whether
to consider reserving another word in scm_tc7_program objects for JIT
code. I have avoided JIT overhead elsewhere and would like to do so
here as well!
For actual JIT code generation, I think my current plan is to import a
copy of GNU lightning into Guile's source, using git-subtree merges.
Lightning is fine for our purposes as we only need code generation, not
optimization, and it supports lots of architectures: ARM, MIPS, PPC,
SPARC, x86 / x86-64, IA64, HPPA, AArch64, S390, and Alpha.
Lightning will be built statically into libguile. This has the
advantage that we always know the version being used, and we are able to
extend lightning without waiting for distros to pick up a new version.
Already we will need to extend it to support atomic ops. Subtree merges
should allow us to pick up upstream improvements without too much pain.
This strategy also allows us to drop lightning in the future if that's
the right thing. Basically from the user POV it should be transparent.
The whole thing will be behind an --enable-jit / --disable-jit configure
option. When it is working we can consider enabling shared lightning
- guile 3 update, june 2018 edition,
Andy Wingo <=