1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

64 commits

Author SHA1 Message Date
Andy Wingo
ce9169804e Fix --disable-jit compilation
* 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.
2018-09-17 09:28:41 +02:00
Andy Wingo
f03ff5304a Turn on automatic JIT compilation by default
* libguile/jit.c (default_jit_threshold): New static const variable.
(scm_sys_jit_compile): Remove.
(scm_init_jit): Rename GUILE_JIT_COUNTER_THRESHOLD to
GUILE_JIT_THRESHOLD, and default to default_jit_threshold.  Remove
%jit-compile definition.
2018-09-15 10:54:14 +02:00
Andy Wingo
0ccd2d0d9e Remove hook intrinsics: hooks are just for the VM
* 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.
2018-09-14 09:34:31 +02:00
Andy Wingo
ce5c05ac4a Fix JIT compilation of intrinsics that return doubles
* libguile/jit.c (emit_retval_d): New helper.
(compile_call_f64_from_scm): Take the f64 result from the correct
registers.
2018-09-10 16:33:10 +02:00
Andy Wingo
46fe5b069b Fix positional-arguments<=? compilation
* libguile/jit.c (compile_check_positional_arguments): Fix.
2018-09-10 16:28:31 +02:00
Andy Wingo
18aa995cbb Fix compilation of compare-and-swap
* libguile/jit.c (compile_atomic_scm_compare_and_swap_immediate): Call
  the right intrinsic.
2018-09-07 15:19:19 +02:00
Andy Wingo
227c3acc5d Refactor handling of lightning state
* libguile/jit.c (prepare_jit_state, reset_jit_state): New helpers.
(emit_code): Prevent emission of auxiliary data.
(compile_handle_interrupts): Assume the handle_interrupts_trampoline is
compiled eagerly.
(initialize_thread_jit_state): New helper.
(initialize_jit): Refactor.  Emit handle-interrupts code here.
(compute_mcode): Adapt to initialize_jit refactorings.
(scm_jit_state_free): Nothing to do.
2018-09-07 15:06:28 +02:00
Andy Wingo
377c3e117e Fix compilation of handle-interrupts
* libguile/jit.c (compile_handle_interrupts): Fix check for blocked
  interrupts.
2018-09-07 14:22:48 +02:00
Andy Wingo
f8229c603d Use custom JIT code allocator
* 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.
2018-09-07 12:22:44 +02:00
Andy Wingo
3e2b173158 Revert "<?" fast path for now
* libguile/jit.c (compile_less): Revert fast path; causing errors in
  benchmarks.
2018-09-05 22:30:43 +02:00
Andy Wingo
93112d3ed5 Add JIT fast paths for inum arithmetic
* 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.
2018-09-05 22:09:42 +02:00
Andy Wingo
218fe1b962 Fix JIT compilation of [positional-]arguments<=?
* 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!
2018-09-05 21:53:56 +02:00
Andy Wingo
cf712c0eb1 Improve JIT cleanup a bit
* libguile/jit.c (initialize_jit): Improve cleanup a bit.
2018-09-05 16:35:00 +02:00
Andy Wingo
24b4d09394 Improve compute_mcode allocation logic
* libguile/jit.c (compute_mcode): Move up some assertions before using
  them to allocate.
2018-09-02 21:56:36 +02:00
Andy Wingo
162e313311 Fix a memory leak in JIT
* libguile/jit.c (compute_mcode): Fix memory leak.  Ultimate fix will be
  to use arena allocation, but that will come later.
2018-09-02 21:35:54 +02:00
Andy Wingo
e9b44c00fd Fix assertion error running compile-file with threshold 0
* libguile/jit.c (emit_alloc_frame_for_sp): Don't require that FP be in
  a register, but if it was and we call out, do restore it.
2018-09-02 21:29:24 +02:00
Andy Wingo
54b23adc13 Add ability to tier up from within loops
* libguile/jit.c (struct scm_jit_state): Add entry and entry_label
  members.
(analyze): Assert entry is jump target.
(compile): Record indirect entry label.
(compute_mcode): Record entry IP, and return entry mcode.
(scm_sys_jit_compile, scm_jit_compute_mcode): Adapt to compute_mcode
change.  Support hot-loop transfer.
2018-09-02 11:54:12 +02:00
Andy Wingo
b176e714f8 Add configurable JIT logging levels
* 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.
2018-09-02 10:49:24 +02:00
Andy Wingo
449ef7d975 Prevent Lightning from stompling our registers
* libguile/jit.c (emit_exit): Add uses of SP and FP.
2018-09-02 09:21:54 +02:00
Andy Wingo
1f42a6042e Add ability to stop JIT after N compilations.
* 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.
2018-09-01 11:28:59 +02:00
Andy Wingo
7c0bfcb097 Minor 32-bit untag-fixnum optimization
* libguile/jit.c (compile_untag_fixnum): Minor optimization in 32-bit
  case.
2018-09-01 10:29:05 +02:00
Andy Wingo
dafa648915 Fix compilation of compile_eq
* libguile/jit.c (compile_eq): Compare to register, not immediate.
2018-09-01 10:11:17 +02:00
Andy Wingo
79be7028e4 More JIT debugging
* 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.
2018-08-31 15:50:46 +02:00
Andy Wingo
cc997293e2 JIT threshold controlled by environment variable
* 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.
2018-08-31 11:28:38 +02:00
Andy Wingo
def671974c Minor optimization in compile_alloc_frame
* libguile/jit.c (compile_alloc_frame): Remove useless FP reload.
2018-08-31 10:54:34 +02:00
Andy Wingo
dac43443a3 Fix bind-kwargs JIT compilation
* libguile/jit.c (COMPILE_X8_C24__C8_C24__X8_C24__N32): Fix unpacking of
  N32 arg.
2018-08-29 22:29:39 +02:00
Andy Wingo
6da132cb95 Fix JIT compilation of composable continuations
* libguile/control.c (compose_continuation_code): Fix offset of code
  end.
* libguile/jit.c (compile_compose_continuation): Fix test for mcode not
  null.
2018-08-29 22:15:20 +02:00
Andy Wingo
15314fdc07 Fix JIT compilation of shuffle-down
* libguile/jit.c (compile_shuffle_down): Fix compilation.
2018-08-29 20:29:57 +02:00
Andy Wingo
c02c89d533 Fix JIT compilation of call-with-prompt
* 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).
2018-08-29 20:00:03 +02:00
Andy Wingo
66fb76db2b Fix miscompilation for "abort" opcode
* libguile/jit.c (compile_abort): Fix miscompilation.
2018-08-29 19:41:47 +02:00
Andy Wingo
24d09b16b6 Maybe enter JIT when returning from interpreted functions
* libguile/jit.c (scm_jit_compute_mcode): Minor optimization.
* libguile/vm-engine.c (return-values): Maybe return to JIT code.
2018-08-29 17:54:19 +02:00
Andy Wingo
c03e2bbbb4 JIT tracks register clobbers
* 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.
2018-08-29 14:01:20 +02:00
Andy Wingo
10bfd55ec3 JIT: Store FP in register during procedure prolog/epilog
* 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.
2018-08-28 16:03:21 +02:00
Andy Wingo
4fb99e9454 Bug-fix for alloc-frame and stack moving
* 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.
2018-08-26 15:13:01 +02:00
Andy Wingo
98b4c46a36 Minor JIT refactor
* libguile/jit.c (emit_alloc_frame_for_sp): Remove unused "fp" arg.
  Adapt callers.
2018-08-26 10:25:52 +02:00
Andy Wingo
18dfe48fc4 Fuse comparisons and branches in JIT
* libguile/jit.c (emit_load_compare_result)
  (emit_store_compare_result): Remove these.
  (emit_branch_if_frame_locals_count_not_eq): New helper.
  (fuse_conditional_branch): New helper.
* libguile/jit.c (compile_u64_numerically_equal)
  (compile_u64_less, compile_s64_less, compile_f64_numerically_equal)
  (compile_f64_less, compile_numerically_equal, compile_less)
  (compile_check_arguments, compile_check_positional_arguments):
  (compile_immediate_tag_equals, compile_heap_tag_equals)
  (compile_eq, compile_heap_numbers_equal)
  (compile_s64_imm_numerically_equal, compile_u64_imm_less)
  (compile_imm_u64_less, compile_s64_imm_less, compile_imm_s64_less):
  Fuse conditional branches, to avoid going through compare-result.
  (compile_jl, compile_je, compile_jnl, compile_jne, compile_jge)
  (compile_jnge): Abort, since they shouldn't be reachable.
2018-08-25 16:20:49 +02:00
Andy Wingo
dfc0b902dc JIT refactor
* 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.
2018-08-25 14:36:58 +02:00
Andy Wingo
9574245676 Fix again the unknown-filling of alloc-frame
* libguile/jit.c (compile_alloc_frame): Yet another fix, because I am an
  idiot.
2018-08-24 16:19:51 +02:00
Andy Wingo
d0c9d20626 Fix JIT compilation of bind-rest
* libguile/jit.c (compile_bind_rest): Fix.
2018-08-24 14:59:47 +02:00
Andy Wingo
3920b99125 Fix fp-ref, fp-set! helpers in jit for signedness
* libguile/jit.c (emit_fp_ref_scm, emit_fp_set_scm): Fix signedless of
  offsets.
2018-08-24 12:58:54 +02:00
Andy Wingo
02a9e76b57 Fix bug in compile-alloc-frame
* libguile/jit.c (compile_alloc_frame): Fix alloc-frame filling in of
  undefined values for when previous frame size was unknown.
2018-08-24 12:14:29 +02:00
Andy Wingo
5603079995 Clear frame size after subr-call, return-values
* libguile/jit.c (compile_return_values, compile_subr_call): Clear frame
  size.
2018-08-24 11:43:50 +02:00
Andy Wingo
25e9b0f79d 32-bit fix for emit_run_hook
* libguile/jit.c (emit_run_hook): Use sign-extending load, as unsigned
  load doesn't exist on 32-bit targets.
2018-08-23 19:53:17 +02:00
Andy Wingo
7854460fac Minor refactors to jit.c
* libguile/jit.c (emit_direct_tail_call): Add FIXME.
  (emit_mov): Simplify implementation.
  (emit_branch_if_frame_locals_count_less_than):
  (emit_branch_if_frame_locals_count_eq):
  (emit_branch_if_frame_locals_count_greater_than):
  (emit_load_fp_slot):
  (emit_branch_if_immediate):
  (emit_load_heap_object_word):
  (emit_load_heap_object_tc):
  (emit_branch_if_heap_object_has_tc):
  (emit_branch_if_heap_object_not_tc):
  (emit_branch_if_heap_object_not_tc7):
  (emit_entry_trampoline):
  (emit_handle_interrupts_trampoline):
  (initialize_handle_interrupts_trampoline):
  (emit_free_variable_ref): Move later in the file.
2018-08-23 19:45:36 +02:00
Andy Wingo
bf035d9385 Fix load width of get-ip-relative-addr
* libguile/jit.c (emit_get_ip_relative_addr): Fix load width.
2018-08-23 17:19:15 +02:00
Andy Wingo
fd1deab3c3 Optimizations to subr-call
* libguile/jit.c (compile_subr_call): Optimizations.
2018-08-23 10:27:27 +02:00
Andy Wingo
01a79bed89 Comments in the JIT
* libguile/jit.c: Add some overview comments.
2018-08-23 10:24:30 +02:00
Andy Wingo
77695612f4 Add support for labels, and fix a bug in uadd/imm and usub/imm.
* libguile/jit.c (add_inter_instruction_patch, compile, compute_mcode):
  Add support for labels.
  (compile_uadd_immediate, compile_usub_immediate): Fix cases where we
  were adding the wrong operand as an immediate.
2018-08-20 15:35:47 +02:00
Andy Wingo
d7fcdd9a2e Add out-of-line handle-interrupts trampoline stub
* libguile/jit.c (emit_handle_interrupts_trampoline)
  (initialize_handle_interrupts_trampoline)
  (compile_handle_interrupts): Handle most of the slow case of
  handle-interrupts out-of-line, to avoid code bloat.
2018-08-20 14:57:00 +02:00
Andy Wingo
9c76a1ad42 Fix frame popping in JIT
* libguile/jit.c (emit_entry_trampoline): Don't bother hackily trying to
  save registers; the "jit_frame" call handles that.
  (compile_return_values, compile_return_from_interrupt): Fix bug when
  computing previous FP: no need to add frame_overhead_slots.
  (emit_load_prev_fp_offset, emit_store_prev_fp_offset): Rename from
  emit_load_prev_frame_size, emit_store_prev_frame_size.
  (emit_push_frame): Adapt to emit_store_prev_frame_size.  Don't
  subtract off the frame_overhead_slots.
  (scm_jit_enter_mcode): Comment out a printf for the time being.
2018-08-20 12:45:00 +02:00