This commit is contained in:
Maxime Chevalier-Boisvert 2021-04-15 12:21:51 -04:00 committed by Alan Wu
parent b69951cf55
commit 791f20af6e

View File

@ -350,9 +350,9 @@ yjit_gen_block(ctx_t *ctx, block_t *block, rb_execution_context_t *ec)
break; break;
} }
if (0) { if (1) {
fprintf(stderr, "compiling %d: %s\n", insn_idx, insn_name(opcode)); fprintf(stderr, "compiling %d: %s\n", insn_idx, insn_name(opcode));
print_str(cb, insn_name(opcode)); //print_str(cb, insn_name(opcode));
} }
// :count-placement: // :count-placement:
@ -521,19 +521,47 @@ gen_putself(jitstate_t* jit, ctx_t* ctx)
static codegen_status_t static codegen_status_t
gen_getlocal_wc0(jitstate_t* jit, ctx_t* ctx) gen_getlocal_wc0(jitstate_t* jit, ctx_t* ctx)
{ {
// Load environment pointer EP from CFP
mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, ep));
// Compute the offset from BP to the local // Compute the offset from BP to the local
int32_t local_idx = (int32_t)jit_get_arg(jit, 0); int32_t local_idx = (int32_t)jit_get_arg(jit, 0);
const int32_t offs = -(SIZEOF_VALUE * local_idx); const int32_t offs = -(SIZEOF_VALUE * local_idx);
/*
if (local_idx < 8)
{
val_type_t local_type = ctx->local_types[local_idx];
if (local_type.type == ETYPE_FIXNUM) {
fprintf(stderr, "local_idx=%d is fixnum\n", local_idx);
ADD_COMMENT(cb, "local is fixnum");
}
else {
fprintf(stderr, "local_idx=%d not fixnum\n", local_idx);
ADD_COMMENT(cb, "local not fixnum");
}
}
else
{
fprintf(stderr, "local_idx=%d\n", local_idx);
}
*/
fprintf(stderr, "local_idx=%d\n", local_idx);
// Load environment pointer EP from CFP
mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, ep));
// Load the local from the EP // Load the local from the EP
mov(cb, REG0, mem_opnd(64, REG0, offs)); mov(cb, REG0, mem_opnd(64, REG0, offs));
// Write the local at SP // Write the local at SP
x86opnd_t stack_top = ctx_stack_push_local(ctx, local_idx); x86opnd_t stack_top = ctx_stack_push_local(ctx, local_idx);
//x86opnd_t stack_top = ctx_stack_push(ctx, TYPE_UNKNOWN);
mov(cb, stack_top, REG0); mov(cb, stack_top, REG0);
return YJIT_KEEP_COMPILING; return YJIT_KEEP_COMPILING;
@ -1763,6 +1791,43 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
// Stub so we can return to JITted code // Stub so we can return to JITted code
blockid_t return_block = { jit->iseq, jit_next_insn_idx(jit) }; blockid_t return_block = { jit->iseq, jit_next_insn_idx(jit) };
// Create a context for the callee
ctx_t callee_ctx = DEFAULT_CTX;
// Set the argument type in the callee's context
for (int32_t arg_idx = 0; arg_idx < argc; ++arg_idx) {
fprintf(stderr, "set arg type, arg_idx=%d\n", arg_idx);
// x is arg0, but pushed last
val_type_t arg_type = ctx_get_opnd_type(ctx, OPND_STACK(argc - arg_idx - 1));
if (arg_type.type == ETYPE_FIXNUM)
fprintf(stderr, "is fixnum\n");
else
fprintf(stderr, "not fixnum\n");
ctx_set_local_type(&callee_ctx, arg_idx, arg_type);
}
fprintf(stderr, "local types\n");
for (int32_t local_idx = 0; local_idx < argc; ++local_idx) {
fprintf(stderr, "local_idx=%d\n", local_idx);
val_type_t type = callee_ctx.local_types[local_idx];
if (type.type == ETYPE_FIXNUM)
fprintf(stderr, "is fixnum\n");
else
fprintf(stderr, "not fixnum\n");
}
// Pop arguments and receiver in return context, push the return value // Pop arguments and receiver in return context, push the return value
// After the return, the JIT and interpreter SP will match up // After the return, the JIT and interpreter SP will match up
ctx_t return_ctx = *ctx; ctx_t return_ctx = *ctx;
@ -1784,12 +1849,12 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
//print_str(cb, "calling Ruby func:"); //print_str(cb, "calling Ruby func:");
//print_str(cb, rb_id2name(vm_ci_mid(ci))); //print_str(cb, rb_id2name(vm_ci_mid(ci)));
// Load the updated SP // Load the updated SP from the CFP
mov(cb, REG_SP, member_opnd(REG_CFP, rb_control_frame_t, sp)); mov(cb, REG_SP, member_opnd(REG_CFP, rb_control_frame_t, sp));
// Directly jump to the entry point of the callee // Directly jump to the entry point of the callee
gen_direct_jump( gen_direct_jump(
&DEFAULT_CTX, &callee_ctx,
(blockid_t){ iseq, 0 } (blockid_t){ iseq, 0 }
); );
@ -1943,6 +2008,7 @@ gen_leave(jitstate_t* jit, ctx_t* ctx)
mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, ep)); mov(cb, REG0, member_opnd(REG_CFP, rb_control_frame_t, ep));
// if (flags & VM_FRAME_FLAG_FINISH) != 0 // if (flags & VM_FRAME_FLAG_FINISH) != 0
ADD_COMMENT(cb, "check for finish frame");
x86opnd_t flags_opnd = mem_opnd(64, REG0, sizeof(VALUE) * VM_ENV_DATA_INDEX_FLAGS); x86opnd_t flags_opnd = mem_opnd(64, REG0, sizeof(VALUE) * VM_ENV_DATA_INDEX_FLAGS);
test(cb, flags_opnd, imm_opnd(VM_FRAME_FLAG_FINISH)); test(cb, flags_opnd, imm_opnd(VM_FRAME_FLAG_FINISH));
jnz_ptr(cb, COUNTED_EXIT(side_exit, leave_se_finish_frame)); jnz_ptr(cb, COUNTED_EXIT(side_exit, leave_se_finish_frame));
@ -1968,6 +2034,7 @@ gen_leave(jitstate_t* jit, ctx_t* ctx)
mov(cb, mem_opnd(64, REG_SP, -SIZEOF_VALUE), REG0); mov(cb, mem_opnd(64, REG_SP, -SIZEOF_VALUE), REG0);
// If the return address is NULL, fall back to the interpreter // If the return address is NULL, fall back to the interpreter
ADD_COMMENT(cb, "check for jit return");
int FALLBACK_LABEL = cb_new_label(cb, "FALLBACK"); int FALLBACK_LABEL = cb_new_label(cb, "FALLBACK");
test(cb, REG1, REG1); test(cb, REG1, REG1);
jz_label(cb, FALLBACK_LABEL); jz_label(cb, FALLBACK_LABEL);