Refactor jit_func_t and jit_exec
I closed https://github.com/ruby/ruby/pull/7543, but part of the diff seems useful regardless, so I extracted it.
This commit is contained in:
parent
a8e7fee801
commit
9947574b9c
28
insns.def
28
insns.def
@ -813,12 +813,7 @@ send
|
||||
{
|
||||
VALUE bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, false);
|
||||
val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
|
||||
|
||||
jit_func_t func;
|
||||
if (val == Qundef && (func = jit_compile(ec))) {
|
||||
val = func(ec, ec->cfp);
|
||||
if (ec->tag->state) THROW_EXCEPTION(val);
|
||||
}
|
||||
JIT_EXEC(ec, val);
|
||||
|
||||
if (val == Qundef) {
|
||||
RESTORE_REGS();
|
||||
@ -838,12 +833,7 @@ opt_send_without_block
|
||||
{
|
||||
VALUE bh = VM_BLOCK_HANDLER_NONE;
|
||||
val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
|
||||
|
||||
jit_func_t func;
|
||||
if (val == Qundef && (func = jit_compile(ec))) {
|
||||
val = func(ec, ec->cfp);
|
||||
if (ec->tag->state) THROW_EXCEPTION(val);
|
||||
}
|
||||
JIT_EXEC(ec, val);
|
||||
|
||||
if (val == Qundef) {
|
||||
RESTORE_REGS();
|
||||
@ -946,12 +936,7 @@ invokesuper
|
||||
{
|
||||
VALUE bh = vm_caller_setup_arg_block(ec, GET_CFP(), cd->ci, blockiseq, true);
|
||||
val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_super);
|
||||
|
||||
jit_func_t func;
|
||||
if (val == Qundef && (func = jit_compile(ec))) {
|
||||
val = func(ec, ec->cfp);
|
||||
if (ec->tag->state) THROW_EXCEPTION(val);
|
||||
}
|
||||
JIT_EXEC(ec, val);
|
||||
|
||||
if (val == Qundef) {
|
||||
RESTORE_REGS();
|
||||
@ -971,12 +956,7 @@ invokeblock
|
||||
{
|
||||
VALUE bh = VM_BLOCK_HANDLER_NONE;
|
||||
val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_invokeblock);
|
||||
|
||||
jit_func_t func;
|
||||
if (val == Qundef && (func = jit_compile(ec))) {
|
||||
val = func(ec, ec->cfp);
|
||||
if (ec->tag->state) THROW_EXCEPTION(val);
|
||||
}
|
||||
JIT_EXEC(ec, val);
|
||||
|
||||
if (val == Qundef) {
|
||||
RESTORE_REGS();
|
||||
|
4
vm.c
4
vm.c
@ -370,7 +370,7 @@ static VALUE vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, VALUE s
|
||||
|
||||
#if USE_RJIT || USE_YJIT
|
||||
// Try to compile the current ISeq in ec. Return 0 if not compiled.
|
||||
static inline jit_func_t
|
||||
static inline rb_jit_func_t
|
||||
jit_compile(rb_execution_context_t *ec)
|
||||
{
|
||||
// Increment the ISEQ's call counter
|
||||
@ -405,7 +405,7 @@ jit_compile(rb_execution_context_t *ec)
|
||||
static inline VALUE
|
||||
jit_exec(rb_execution_context_t *ec)
|
||||
{
|
||||
jit_func_t func = jit_compile(ec);
|
||||
rb_jit_func_t func = jit_compile(ec);
|
||||
if (func) {
|
||||
// Call the JIT code
|
||||
return func(ec, ec->cfp);
|
||||
|
@ -373,6 +373,8 @@ enum rb_builtin_attr {
|
||||
BUILTIN_ATTR_NO_GC = 0x02,
|
||||
};
|
||||
|
||||
typedef VALUE (*rb_jit_func_t)(struct rb_execution_context_struct *, struct rb_control_frame_struct *);
|
||||
|
||||
struct rb_iseq_constant_body {
|
||||
enum rb_iseq_type type;
|
||||
|
||||
@ -505,7 +507,7 @@ struct rb_iseq_constant_body {
|
||||
|
||||
#if USE_RJIT || USE_YJIT
|
||||
// Function pointer for JIT code
|
||||
VALUE (*jit_func)(struct rb_execution_context_struct *, struct rb_control_frame_struct *);
|
||||
rb_jit_func_t jit_func;
|
||||
// Number of total calls with jit_exec()
|
||||
long unsigned total_calls;
|
||||
#endif
|
||||
@ -521,8 +523,6 @@ struct rb_iseq_constant_body {
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef VALUE (*jit_func_t)(struct rb_execution_context_struct *, struct rb_control_frame_struct *);
|
||||
|
||||
/* T_IMEMO/iseq */
|
||||
/* typedef rb_iseq_t is in method.h */
|
||||
struct rb_iseq_struct {
|
||||
|
@ -174,6 +174,14 @@ default: \
|
||||
#define THROW_EXCEPTION(exc) return (VALUE)(exc)
|
||||
#endif
|
||||
|
||||
#define JIT_EXEC(ec, val) do { \
|
||||
rb_jit_func_t func; \
|
||||
if (val == Qundef && (func = jit_compile(ec))) { \
|
||||
val = func(ec, ec->cfp); \
|
||||
if (ec->tag->state) THROW_EXCEPTION(val); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define SCREG(r) (reg_##r)
|
||||
|
||||
#define VM_DEBUG_STACKOVERFLOW 0
|
||||
|
5
yjit.c
5
yjit.c
@ -1023,9 +1023,6 @@ rb_yjit_vm_unlock(unsigned int *recursive_lock_level, const char *file, int line
|
||||
rb_vm_lock_leave(recursive_lock_level, file, line);
|
||||
}
|
||||
|
||||
// Pointer to a YJIT entry point (machine code generated by YJIT)
|
||||
typedef VALUE (*yjit_func_t)(rb_execution_context_t *, rb_control_frame_t *);
|
||||
|
||||
bool
|
||||
rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec)
|
||||
{
|
||||
@ -1038,7 +1035,7 @@ rb_yjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec)
|
||||
uint8_t *code_ptr = rb_yjit_iseq_gen_entry_point(iseq, ec);
|
||||
|
||||
if (code_ptr) {
|
||||
iseq->body->jit_func = (yjit_func_t)code_ptr;
|
||||
iseq->body->jit_func = (rb_jit_func_t)code_ptr;
|
||||
}
|
||||
else {
|
||||
iseq->body->jit_func = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user