1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fixed one bug in compile_block.

This commit is contained in:
Maxime Chevalier-Boisvert 2020-12-17 15:45:38 -05:00 committed by Alan Wu
parent e9344ae408
commit 4592ef9d76
2 changed files with 20 additions and 12 deletions

View file

@ -145,6 +145,9 @@ ujit_compile_block(const rb_iseq_t *iseq, uint32_t insn_idx, bool entry_point)
ujit_gen_entry(cb);
}
//fprintf(stderr, "compiling %s\n", insn_name(opcode));
//print_str(cb, insn_name(opcode));
// Call the code generation function
codegen_fn gen_fn = (codegen_fn)st_gen_fn;
if (!gen_fn(cb, ocb, &ctx)) {
@ -163,13 +166,16 @@ ujit_compile_block(const rb_iseq_t *iseq, uint32_t insn_idx, bool entry_point)
}
}
// FIXME: maybe we want a separate function to compile entry points?
// If this is an entry point and no instructions were compiled
if (entry_point && num_instrs == 0) {
return NULL;
}
//print_str(cb, "exiting to interpreter\n");
// FIXME: only generate exit if no instructions were compiled?
// or simply don't allow instructions to fail to compile anymore?
// If no instructions were compiled
//if (num_instrs == 0) {
// return NULL;
//}
// Generate code to exit to the interpreter
ujit_gen_exit(cb, &ctx, &encoded[insn_idx]);
@ -892,12 +898,6 @@ gen_branchunless_branch(codeblock_t* cb, uint8_t* target0, uint8_t* target1, uin
static bool
gen_branchunless(codeblock_t* cb, codeblock_t* ocb, ctx_t* ctx)
{
// Get the branch target instruction offsets
uint32_t next_idx = ctx_next_idx(ctx);
uint32_t jump_idx = next_idx + (uint32_t)ctx_get_arg(ctx, 0);
blockid_t next_block = { ctx->iseq, next_idx };
blockid_t jump_block = { ctx->iseq, jump_idx };
// TODO: we need to eventually do an interrupt check when jumping/branching
// How can we do this while keeping the check logic out of line?
// Maybe we can push the check int into the next block or the stub?
@ -910,6 +910,12 @@ gen_branchunless(codeblock_t* cb, codeblock_t* ocb, ctx_t* ctx)
x86opnd_t val_opnd = ctx_stack_pop(ctx, 1);
test(cb, val_opnd, imm_opnd(~Qnil));
// Get the branch target instruction offsets
uint32_t next_idx = ctx_next_idx(ctx);
uint32_t jump_idx = next_idx + (uint32_t)ctx_get_arg(ctx, 0);
blockid_t next_block = { ctx->iseq, next_idx };
blockid_t jump_block = { ctx->iseq, jump_idx };
// Generate the branch instructions
gen_branch(cb, ocb, jump_block, next_block, gen_branchunless_branch);
@ -947,5 +953,5 @@ ujit_init_codegen(void)
st_insert(gen_fns, (st_data_t)BIN(opt_minus), (st_data_t)&gen_opt_minus);
st_insert(gen_fns, (st_data_t)BIN(opt_plus), (st_data_t)&gen_opt_plus);
st_insert(gen_fns, (st_data_t)BIN(opt_send_without_block), (st_data_t)&gen_opt_send_without_block);
st_insert(gen_fns, (st_data_t)BIN(branchunless), (st_data_t)&gen_branchunless);
//st_insert(gen_fns, (st_data_t)BIN(branchunless), (st_data_t)&gen_branchunless);
}

View file

@ -163,6 +163,8 @@ uint8_t* branch_stub_hit(uint32_t branch_idx, uint32_t target_idx)
//fprintf(stderr, "rewrite branch at %d\n", branch->start_pos);
// Rewrite the branch with the new jump target address
assert (branch->dst_addrs[0] != NULL);
assert (branch->dst_addrs[1] != NULL);
size_t cur_pos = cb->write_pos;
cb_set_pos(cb, branch->start_pos);
branch->gen_fn(cb, branch->dst_addrs[0], branch->dst_addrs[1], branch->shape);