summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2018-09-17Fix --disable-jit compilationlightningAndy Wingo7-8/+27
* 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-15Turn on automatic JIT compilation by defaultAndy Wingo1-26/+6
* 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-15Fix emergency aborts to not expand the stackAndy Wingo3-6/+73
* libguile/vm.c (scm_i_vm_emergency_abort): New helper: an abort that doesn't allocate, not even stack. * libguile/throw.c (abort_to_prompt): Use scm_i_vm_emergency_abort. * libguile/vm.h: Declare helper.
2018-09-14Fix scm_make_foreign_object_n.Andy Wingo1-1/+1
* libguile/foreign-object.c (scm_make_foreign_object_n): Fix computation of slot count; broken in 34b9f22ca.
2018-09-14Deoptimize to VM when hooks are enabledAndy Wingo2-51/+75
* libguile/vm.c (vm_clear_mcode_return_addresses): New helper. (vm_recompute_disable_mcode): Force a thread to deoptimize if hooks become enabled. (scm_call_n): Don't enter mcode if it's disabled. Also check the right flag for when to run the abort hook (the abort_hook_enabled flag). * libguile/vm-engine.c (instrument-entry, instrument-loop) (return-values, abort, compose-continuation): Don't enter mcode if mcode is disabled for this thread.
2018-09-14Hook refactorsAndy Wingo3-87/+116
* libguile/vm.h (SCM_VM_NUM_HOOKS): Remove hook enumeration. (struct scm_vm): Re-arrange members to be more dense and to use common cache lines for commonly-used members. Declare hooks and their enabled flags by name. * libguile/vm-engine.c (RUN_HOOK): Refer to hooks by name. * libguile/vm.c (FOR_EACH_HOOK): New helper. (vm_hook_compute_enabled, vm_recompute_disable_mcode): New routines to recompute when hooks are enabled, and whether to disable mcode because hooks are active. (set_vm_trace_level): New helper. (invoke_hook): Take hook to invoke by value. (DEFINE_INVOKE_HOOK): Refactor to use named hooks. (scm_i_vm_prepare_stack): Init named hooks. (VM_ADD_HOOK, VM_REMOVE_HOOK): Refactor to use named hooks, and also recompute global disable_mcode flag. (scm_set_vm_trace_level_x, scm_c_set_vm_engine_x): Use internal helper.
2018-09-14Micro-optimization of scm_vm placement in scm_threadAndy Wingo1-3/+3
* libguile/threads.h (struct scm_thread): Move the embedded "struct scm_vm" earlier in the scm_thread. Since the VM (and the JIT) access VM data (SP, FP, etc) through the thread pointer, this allows more accesses to be encoded in shorter instruction sequences.
2018-09-14Remove hook intrinsics: hooks are just for the VMAndy Wingo4-73/+26
* 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-14VM manages hook sets itselfAndy Wingo7-62/+130
* libguile/vm.h (SCM_VM_ABORT_HOOK): Rename from SCM_VM_ABORT_CONTINUATION_HOOK. * libguile/vm-engine.c (ABORT_HOOK): * libguile/vm.c (invoke_abort_hook): Adapt to SCM_VM_ABORT_HOOK name change. (reset_vm_hook_enabled): New helper. (VM_ADD_HOOK, VM_REMOVE_HOOK): New helper macros, replacing VM_DEFINE_HOOK. (scm_vm_add_abort_hook_x, scm_vm_remove_abort_hook_x) (scm_vm_add_apply_hook_x, scm_vm_remove_apply_hook_x) (scm_vm_add_return_hook_x, scm_vm_remove_return_hook_x) (scm_vm_add_next_hook_x, scm_vm_remove_next_hook_x): New functions, replacing direct access to the hooks. Allows us to know in a more fine-grained way when to enable hooks. (scm_set_vm_trace_level_x): Use reset_vm_hook_enabled to update the individual hook_enabled flags. * module/statprof.scm: * module/system/vm/coverage.scm: * module/system/vm/traps.scm: * module/system/vm/vm.scm: Adapt VM hook users to the new API.
2018-09-10Fix JIT compilation of intrinsics that return doublesAndy Wingo1-1/+8
* libguile/jit.c (emit_retval_d): New helper. (compile_call_f64_from_scm): Take the f64 result from the correct registers.
2018-09-10Fix positional-arguments<=? compilationAndy Wingo1-2/+2
* libguile/jit.c (compile_check_positional_arguments): Fix.
2018-09-07Fix compilation of compare-and-swapAndy Wingo1-1/+1
* libguile/jit.c (compile_atomic_scm_compare_and_swap_immediate): Call the right intrinsic.
2018-09-07Refactor handling of lightning stateAndy Wingo1-48/+49
* 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-07Fix compilation of handle-interruptsAndy Wingo1-1/+1
* libguile/jit.c (compile_handle_interrupts): Fix check for blocked interrupts.
2018-09-07Use custom JIT code allocatorAndy Wingo1-11/+125
* 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-05Revert "<?" fast path for nowAndy Wingo1-2/+11
* libguile/jit.c (compile_less): Revert fast path; causing errors in benchmarks.
2018-09-05Add JIT fast paths for inum arithmeticAndy Wingo1-9/+102
* 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-05Fix JIT compilation of [positional-]arguments<=?Andy Wingo1-9/+16
* 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-05Improve JIT cleanup a bitAndy Wingo1-1/+2
* libguile/jit.c (initialize_jit): Improve cleanup a bit.
2018-09-03Fix nonlocal abort to compiled continuationAndy Wingo1-1/+3
* libguile/vm.c (scm_call_n): Fix failure to reset vm.registers after a nonlocal abort to a compiled continuation.
2018-09-02Improve compute_mcode allocation logicAndy Wingo1-4/+5
* libguile/jit.c (compute_mcode): Move up some assertions before using them to allocate.
2018-09-02Fix a memory leak in JITAndy Wingo1-0/+1
* libguile/jit.c (compute_mcode): Fix memory leak. Ultimate fix will be to use arena allocation, but that will come later.
2018-09-02Fix assertion error running compile-file with threshold 0Andy Wingo1-3/+3
* 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-02Add ability to tier up from within loopsAndy Wingo1-23/+46
* 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-02JIT counter tweaksAndy Wingo2-4/+7
* libguile/vm-engine.c (instrument-entry, instrument-loop): Make the counter check >=, so that we can set the threshold to 0 and still get compilation. * libguile/jit.h (enum scm_jit_counter_value): Make the increments event.
2018-09-02Add configurable JIT logging levelsAndy Wingo1-6/+26
* 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-02Prevent Lightning from stompling our registersAndy Wingo1-0/+30
* libguile/jit.c (emit_exit): Add uses of SP and FP.
2018-09-01Add ability to stop JIT after N compilations.Andy Wingo1-3/+27
* 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-01Minor 32-bit untag-fixnum optimizationAndy Wingo1-2/+1
* libguile/jit.c (compile_untag_fixnum): Minor optimization in 32-bit case.
2018-09-01Fix compilation of compile_eqAndy Wingo1-2/+2
* libguile/jit.c (compile_eq): Compare to register, not immediate.
2018-08-31More JIT debuggingAndy Wingo1-6/+29
* 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-31JIT threshold controlled by environment variableAndy Wingo3-3/+10
* 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-31Minor optimization in compile_alloc_frameAndy Wingo1-1/+0
* libguile/jit.c (compile_alloc_frame): Remove useless FP reload.
2018-08-29Fix bind-kwargs JIT compilationAndy Wingo1-1/+1
* libguile/jit.c (COMPILE_X8_C24__C8_C24__X8_C24__N32): Fix unpacking of N32 arg.
2018-08-29Fix JIT compilation of composable continuationsAndy Wingo2-2/+2
* 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-29Fix jit function data for goto_continuation_codeAndy Wingo1-1/+1
* libguile/continuations.c (goto_continuation_code): Fix offset of end of code.
2018-08-29Fix JIT compilation of shuffle-downAndy Wingo1-1/+1
* libguile/jit.c (compile_shuffle_down): Fix compilation.
2018-08-29Fix JIT compilation of call-with-promptAndy Wingo1-1/+13
* 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-29Fix miscompilation for "abort" opcodeAndy Wingo1-1/+1
* libguile/jit.c (compile_abort): Fix miscompilation.
2018-08-29Add fast paths to intrinsicsAndy Wingo1-1/+27
* libguile/intrinsics.c (add_immediate, sub_immediate, less_p) (numerically_equal_p): Add fast paths. Makes one test locally go from .77s interpreted to .60s. (scm_to_uint64_truncate): Add a likelihood annotation.
2018-08-29Maybe enter JIT when returning from interpreted functionsAndy Wingo2-15/+19
* libguile/jit.c (scm_jit_compute_mcode): Minor optimization. * libguile/vm-engine.c (return-values): Maybe return to JIT code.
2018-08-29JIT tracks register clobbersAndy Wingo1-255/+454
* 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-28JIT: Store FP in register during procedure prolog/epilogAndy Wingo1-242/+511
* 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-26Bug-fix for alloc-frame and stack movingAndy Wingo1-7/+9
* 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-26Minor JIT refactorAndy Wingo1-5/+4
* libguile/jit.c (emit_alloc_frame_for_sp): Remove unused "fp" arg. Adapt callers.
2018-08-25Fuse comparisons and branches in JITAndy Wingo1-228/+475
* 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-25JIT refactorAndy Wingo1-31/+30
* 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-24Fix again the unknown-filling of alloc-frameAndy Wingo1-2/+1
* libguile/jit.c (compile_alloc_frame): Yet another fix, because I am an idiot.
2018-08-24Fix JIT compilation of bind-restAndy Wingo1-1/+1
* libguile/jit.c (compile_bind_rest): Fix.
2018-08-24Fix fp-ref, fp-set! helpers in jit for signednessAndy Wingo1-2/+2
* libguile/jit.c (emit_fp_ref_scm, emit_fp_set_scm): Fix signedless of offsets.