* libguile/jit.c (record_gpr_clobber): If we clobber SP or FP, clear the
appropriate register state bits. Only exercised for 32-bit targets in
practice!
(emit_alloc_frame, emit_push_frame): Fix a couple places where we were
failing to track the register state correctly.
(compile_umul): Remove a needless register state flush, nowthat
qmulr_u has a wrapper that tracks this for us.
* libguile/jit.c (compile_s64_numerically_equal): Remove as this
instruction was removed in previous refactoring.
(compile_atomic_scm_set_immediate), compile_atomic_scm_ref_immediate):
Adapt to change in C name of these instructions.
* libguile/vm-engine.c: Add comments for all instructions.
* libguile/jit.c: Wrap the whole thing in ENABLE_JIT.
* libguile/threads.c (on_thread_exit):
* libguile/vm.c (scm_call_n):
* libguile/init.c (scm_i_init_guile):
* libguile/vm-engine.c (VM_NAME): Wrap calls into jit.c with ENABLE_JIT.
* configure.ac: Move up AC_CANONICAL_TARGET, as autoconf was complaining
about it coming after AC_ARG_PROGRAM.
* acinclude.m4 (GUILE_ENABLE_JIT): Fix to honor --enable-jit arg.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Remove VM hook
intrinsics, now that we're going to rely on the interpreter for
stepping and breakpoints.
* libguile/jit.c (struct scm_jit_state): Remove "hooks_enabled" member,
now that we won't JIT. Remove all code related to calling hooks.
* libguile/vm-engine.c (RUN_HOOK): Call hooks directly instead of
through intrinsics. Use precise per-hook enable flags.
* libguile/vm.c (DEFINE_INVOKE_HOOK): New helper. Use to define the
hook invokers.
* libguile/jit.c (struct code_arena): New data type.
(struct scm_jit_state): Add code arena member.
(allocate_code_arena): New helper.
(emit_code): New helper. Emits code into a thread-local code arena.
(compute_mcode): Allow for failure to JIT.
(scm_jit_compute_mcode): Stop automatic JIT compilation on resource
exhaustion.
* libguile/jit.c (compile_call_scm_from_scm_scm): Add fast paths for
inum add and sub.
(compile_call_scm_from_scm_uimm): Add fast paths for inum
add/immediate and sub/immediate.
(compile_less): Add fast path for inum compare.
* libguile/jit.c (compile_check_arguments)
(compile_check_positional_arguments): Fix these functions. The
compiler uses "jge" as a "compare result not NONE", but the VM
instructions set NONE on greater-than, not greater-than-or-equal.
Sad!
* libguile/jit.c (jit_log_level): New local.
(_LOG, INFO, DEBUG, LOG): New macros.
(compile1):
(compute_mcode):
(scm_jit_enter_mcode): Use new logging macros.
* libguile/jit.c (jit_stop_after, jit_pause_when_stopping): New locals.
(scm_jit_compute_mcode): Add ability to stop after N compilations.
(scm_jit_enter_mcode): Comment out printfs for the time being.
(scm_init_jit): Init locals from environment variables.
* libguile/jit.c (compile1): Add debug for when instructions are first
compiled. Will be removed when all is working.
(compute_mcode): Add debugging about what code is compiled.
(scm_sys_jit_compile): Remove per-instruction output.
(scm_jit_compute_mcode): Actually compile JIT code. Use
GUILE_JIT_COUNTER_THRESHOLD to control when JIT happens.
* libguile/jit.c (scm_jit_counter_threshold): Make a static variable
instead of a compile-time constant.
(scm_init_jit): Init scm_jit_counter_threshold from
GUILE_JIT_COUNTER_THRESHOLD environment variable. Default is -1
indicating "never JIT".
* libguile/vm-engine.c (instrument-entry, instrument-loop): Adapt to new
variable.
* libguile/control.c (compose_continuation_code): Fix offset of code
end.
* libguile/jit.c (compile_compose_continuation): Fix test for mcode not
null.
* libguile/jit.c (compile_prompt): Actually push the MRA arg.
(analyze): Mark call continuations as entries, as both FP and SP are
set then, and also mark prompt handlers as entries (and blocks).
* libguile/jit.c (struct scm_jit_state): Add beginnings of a little
local register allocator.
(reset_register_state): New helper.
(clear_scratch_register_state): Use new helper.
(record_gpr_clobber, record_fpr_clobber): New helpers, used when there
may be cached variables in registers, called when registers are
written.
(set_sp_cache_gpr, set_sp_cache_fpr): New helpers, called when results
are written to the stack.
(emit_retval, emit_movi, emit_ldxi, DEFINE_CLOBBER_RECORDING_EMITTER_R)
(DEFINE_CLOBBER_RECORDING_EMITTER_P, DEFINE_CLOBBER_RECORDING_EMITTER_R_I)
(DEFINE_CLOBBER_RECORDING_EMITTER_R_R): New wrappers for Lightning API
that also records register clobbers. Update callers.
(save_reloadable_register_state): New helper.
(restore_reloadable_register_state): Rename from
ensure_register_state.
* libguile/jit.c (scm_jit_state): Add op_attrs array, for a pre-pass,
and store state of what's in registers.
(SP, FP): Reassign to scratch registers, as in general these need to
be reloaded anyway after callouts.
(die, DIE, ASSERT, UNREACHABLE): Add better invariant-testing.
(clear_register_state, clear_scratch_register_state)
(set_register_state, has_register_state, ASSERT_HAS_REGISTER_STATE):
Add machinery to track state of SP and FP. Can eventually track
scratch register assignments as well. Adapt code to use these.
(compile_atomic_ref_scm_immediate): Compile to a vanilla load on x86.
(compile_handle_interrupts): Analogous atomic-ref changes here.
(analyze): New helper, a simple once-through pre-pass to identify
branch targets.
(compile): Only generate labels for branch targets. Reset register
state at branch targets.
(compute_mcode): Initialize j->op_attrs appropriately.
* libguile/jit.c (emit_push_frame): Simplification; we never need to
store old_fp and new_fp at once.
(compile_alloc_frame): Fix to not keep a pointer into the stack across
a stack expansion.
* libguile/jit.c (struct scm_jit_state): Store next ip, so that
compilers can fuse opcodes.
(op_lengths): New static variable.
(emit_direct_tail_call): Add a fast case for self-recursion.
(compile1): Move IP advancement out of the specific arity compilers;
instead precompute a "next_ip", that can be incremented.