1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-18 17:50:29 +02:00

Add instrument-call, instrument-loop VM instructions

* libguile/jit.h (struct scm_jit_function_data)
  (enum scm_jit_counter_value): New data types.
* libguile/jit.c (scm_jit_compute_mcode, scm_jit_enter_mcode): New
  function stubs.  Adapt label/offset compilers to take pointers.
* libguile/vm-engine.c (instrument-call, instrument-loop): New
  instructions.
* libguile/vm.c: Add jit.h include.
* module/system/vm/assembler.scm (emit-instrument-call)
  (emit-instrument-loop): New exports.
This commit is contained in:
Andy Wingo 2018-07-23 12:43:30 +02:00
parent 4b7af0b7fd
commit 87da1c8d20
5 changed files with 147 additions and 35 deletions

View file

@ -468,10 +468,38 @@ VM_NAME (scm_thread *thread)
NEXT (0);
}
VM_DEFINE_OP (5, unused_5, NULL, NOP)
/* instrument-call _:24 data:32
*
* Increase execution counter for this function and potentially tier
* up to the next JIT level. DATA is an offset to raw profiler,
* recording execution counts and the next-level JIT code
* corresponding to this function. Also run the apply hook.
*/
VM_DEFINE_OP (5, instrument_call, "instrument-call", OP2 (X32, N32))
{
vm_error_bad_instruction (op);
abort (); /* never reached */
int32_t data_offset = ip[1];
struct scm_jit_function_data *data;
data = (struct scm_jit_function_data *) (ip + data_offset);
if (data->counter > SCM_JIT_COUNTER_THRESHOLD)
{
const uint8_t *mcode;
SYNC_IP ();
mcode = scm_jit_compute_mcode (thread, data);
if (mcode)
{
scm_jit_enter_mcode (thread, mcode);
CACHE_REGISTER ();
NEXT (0);
}
}
else
data->counter += SCM_JIT_COUNTER_CALL_INCREMENT;
NEXT (2);
}
/* receive dst:12 proc:12 _:8 nlocals:24
@ -675,10 +703,38 @@ VM_NAME (scm_thread *thread)
NEXT (0);
}
VM_DEFINE_OP (14, unused_14, NULL, NOP)
/* instrument-loop _:24 data:32
*
* Increase execution counter for this function and potentially tier
* up to the next JIT level. DATA is an offset to raw profiler,
* recording execution counts and the next-level JIT code
* corresponding to this function.
*/
VM_DEFINE_OP (14, instrument_loop, "instrument-loop", OP2 (X32, N32))
{
vm_error_bad_instruction (op);
abort (); /* never reached */
int32_t data_offset = ip[1];
struct scm_jit_function_data *data;
data = (struct scm_jit_function_data *) (ip + data_offset);
if (data->counter > SCM_JIT_COUNTER_THRESHOLD)
{
const uint8_t *mcode;
SYNC_IP ();
mcode = scm_jit_compute_mcode (thread, data);
if (mcode)
{
scm_jit_enter_mcode (thread, mcode);
CACHE_REGISTER ();
NEXT (0);
}
}
else
data->counter += SCM_JIT_COUNTER_LOOP_INCREMENT;
NEXT (2);
}
/* call/cc _:24