1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

Refactor hook dispatch in VM

* libguile/vm-engine.c (GOTO_HOOK, HOOK_HANDLER): Split hooks that don't
  take args into a "goto" side and a "target" side.  The idea is to just
  reify the hook call at one place in the binary, since the VM
  continuation is fully in the registers.
  (APPLY_HOOK, PUSH_CONTINUATION_HOOK, NEXT_HOOK)
  (ABORT_CONTINUATION_HOOK): Reimplement in terms of goto hooks.
  (POP_CONTINUATION_HOOK): This one is still old-style.
  (CONTINUE): New helper definition.
  (call, call-label): Move the push-continuation hooks up a bit, so it's
  clear they don't depend on intermediate opcode state.
  (vm_engine): Reify hook handlers for apply, etc.
This commit is contained in:
Andy Wingo 2018-06-27 19:56:55 +02:00
parent 2a8d72f7e0
commit 593e2db1dd

View file

@ -110,6 +110,19 @@
#endif
#if VM_USE_HOOKS
#define GOTO_HOOK(h) \
do { \
if (SCM_UNLIKELY (VP->trace_level)) \
goto run_##h##_hook; \
} while (0)
#define HOOK_HANDLER(h) \
do { \
run_##h##_hook: \
SYNC_IP (); \
vm_dispatch_##h##_hook (thread); \
CACHE_SP (); \
CONTINUE; \
} while (0)
#define RUN_HOOK(exp) \
do { \
if (SCM_UNLIKELY (VP->trace_level)) \
@ -121,16 +134,18 @@
} while (0)
#else
#define RUN_HOOK(exp)
#define GOTO_HOOK(h)
#define HOOK_HANDLER(h)
#endif
#define RUN_HOOK0(h) RUN_HOOK (vm_dispatch_##h##_hook (thread))
#define RUN_HOOK1(h, arg) RUN_HOOK (vm_dispatch_##h##_hook (thread, arg))
#define APPLY_HOOK() RUN_HOOK0 (apply)
#define PUSH_CONTINUATION_HOOK() RUN_HOOK0 (push_continuation)
#define POP_CONTINUATION_HOOK(old_fp) RUN_HOOK1 (pop_continuation, old_fp)
#define NEXT_HOOK() RUN_HOOK0 (next)
#define ABORT_CONTINUATION_HOOK() RUN_HOOK0 (abort)
#define APPLY_HOOK() GOTO_HOOK (apply)
#define PUSH_CONTINUATION_HOOK() GOTO_HOOK (push_continuation)
#define NEXT_HOOK() GOTO_HOOK (next)
#define ABORT_CONTINUATION_HOOK() GOTO_HOOK (abort)
/* The only hook that needs an arg, currently. */
#define POP_CONTINUATION_HOOK(old_fp) \
RUN_HOOK (vm_dispatch_pop_continuation_hook (thread, old_fp))
@ -213,13 +228,13 @@
#ifdef HAVE_LABELS_AS_VALUES
# define BEGIN_DISPATCH_SWITCH /* */
# define END_DISPATCH_SWITCH /* */
# define CONTINUE do { op = *ip; goto *jump_table[op & 0xff]; } while (0)
# define NEXT(n) \
do \
{ \
ip += n; \
NEXT_HOOK (); \
op = *ip; \
goto *jump_table[op & 0xff]; \
CONTINUE; \
} \
while (0)
# define VM_DEFINE_OP(opcode, tag, name, meta) \
@ -233,11 +248,12 @@
{
# define END_DISPATCH_SWITCH \
}
# define CONTINUE do { goto vm_start; } while (0)
# define NEXT(n) \
do \
{ \
ip += n; \
goto vm_start; \
CONTINUE; \
} \
while (0)
# define VM_DEFINE_OP(opcode, tag, name, meta) \
@ -363,11 +379,11 @@ VM_NAME (scm_thread *thread)
uint32_t proc, nlocals;
union scm_vm_stack_element *old_fp;
PUSH_CONTINUATION_HOOK ();
UNPACK_24 (op, proc);
UNPACK_24 (ip[1], nlocals);
PUSH_CONTINUATION_HOOK ();
old_fp = VP->fp;
VP->fp = SCM_FRAME_SLOT (old_fp, proc - 1);
SCM_FRAME_SET_DYNAMIC_LINK (VP->fp, old_fp);
@ -405,12 +421,12 @@ VM_NAME (scm_thread *thread)
int32_t label;
union scm_vm_stack_element *old_fp;
PUSH_CONTINUATION_HOOK ();
UNPACK_24 (op, proc);
UNPACK_24 (ip[1], nlocals);
label = ip[2];
PUSH_CONTINUATION_HOOK ();
old_fp = VP->fp;
VP->fp = SCM_FRAME_SLOT (old_fp, proc - 1);
SCM_FRAME_SET_DYNAMIC_LINK (VP->fp, old_fp);
@ -2994,6 +3010,14 @@ VM_NAME (scm_thread *thread)
}
END_DISPATCH_SWITCH;
HOOK_HANDLER (apply);
HOOK_HANDLER (push_continuation);
HOOK_HANDLER (next);
HOOK_HANDLER (abort);
/* Unreachable. */
abort ();
}
@ -3013,8 +3037,8 @@ VM_NAME (scm_thread *thread)
#undef POP_CONTINUATION_HOOK
#undef PUSH_CONTINUATION_HOOK
#undef RUN_HOOK
#undef RUN_HOOK0
#undef RUN_HOOK1
#undef HOOK_HANDLER
#undef GOTO_HOOK
#undef SYNC_IP
#undef UNPACK_8_8_8
#undef UNPACK_8_16