Skip to content

Commit

Permalink
Simplify dispatch_o to sp_runnativecall_v if there's no result
Browse files Browse the repository at this point in the history
We cannot generate dispatch_v instructions for Raku code because of sinking
semantics. But for native functions with void result we can replace dispatch_o
with sp_runnativecall_v as we know that they don't return anything.
  • Loading branch information
niner committed Oct 25, 2021
1 parent a30b74d commit 9ee6b1b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/spesh/disp.c
Expand Up @@ -1135,12 +1135,18 @@ static int translate_dispatch_program(MVMThreadContext *tc, MVMSpeshGraph *g,
deopt_all_ann->data.deopt_idx);

int box_return_value = 0;
int has_return_value = (ins->info->opcode != MVM_OP_dispatch_v);
if (native) {
if (ins->info->opcode == MVM_OP_dispatch_o) {
MVMSpeshFacts *object_facts = MVM_spesh_get_facts(tc, g, temporaries[op->res_code.temp_invokee]);
if (object_facts->flags & MVM_SPESH_FACT_KNOWN_VALUE) {
MVMNativeCallBody *body = MVM_nativecall_get_nc_body(tc, object_facts->value.o);
switch (body->ret_type & MVM_NATIVECALL_ARG_TYPE_MASK) {
case MVM_NATIVECALL_ARG_VOID:
base_op = MVM_op_get_op(MVM_OP_sp_runnativecall_v);
MVM_spesh_get_facts(tc, g, ins->operands[0])->dead_writer = 0;
has_return_value = 0;
break;
case MVM_NATIVECALL_ARG_CHAR:
case MVM_NATIVECALL_ARG_SHORT:
case MVM_NATIVECALL_ARG_INT:
Expand All @@ -1166,7 +1172,7 @@ static int translate_dispatch_program(MVMThreadContext *tc, MVMSpeshGraph *g,

/* Write result into dispatch result register unless void. */
MVMuint16 cur_op = 0;
if (ins->info->opcode != MVM_OP_dispatch_v) {
if (has_return_value) {
if (box_return_value) {
rb_ins->operands[cur_op] = MVM_spesh_manipulate_get_temp_reg(tc, g, MVM_reg_int64);
}
Expand Down

0 comments on commit 9ee6b1b

Please sign in to comment.