Skip to content

Commit

Permalink
JIT: Double-Devirtualize atpos_i
Browse files Browse the repository at this point in the history
only limited usefulness, since rakudo code mostly
generates atposref rather than atpos instructions.

Spesh will, at some point, know to turn atposref
into atpos, though, and atposref can also be
double-devirtualized in much the same way
atpos currently is.
  • Loading branch information
timo committed Dec 26, 2018
1 parent 16b9b79 commit bd43dcc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src/6model/reprs/VMArray.c
Expand Up @@ -1421,18 +1421,40 @@ MVMObject *vmarray_direct_atpos_o_to_o(MVMThreadContext *tc, MVMObject *obj, MVM
return found ? found : tc->instance->VMNull;
}

MVMint64 vmarray_direct_atpos_i64_to_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 index) {
MVMArrayBody *body = (MVMArrayBody *)OBJECT_BODY(obj);
MVMObject *found;

if (index < 0) {
index += body->elems;
if (index < 0)
MVM_exception_throw_adhoc(tc, "MVMArray: Index out of bounds");
}

if (index >= body->elems)
return 0;

return (MVMint64)body->slots.i64[body->start + index];
}

void *MVM_VMArray_devirtualize_ins_for_jit(MVMThreadContext *tc, MVMSTable *st, MVMSpeshIns *ins) {
switch (ins->info->opcode) {
case MVM_OP_atpos_o:
if (((MVMArrayREPRData *)st->REPR_data)->slot_type != MVM_ARRAY_OBJ) {
return NULL;
}
return vmarray_direct_atpos_o_to_o;
break;
case MVM_OP_atpos_i:
if (((MVMArrayREPRData *)st->REPR_data)->slot_type != MVM_ARRAY_I64) {
return NULL;
}
return vmarray_direct_atpos_i64_to_i;
break;
default:
return NULL;
}

return vmarray_direct_atpos_o_to_o;
}

/* Initializes the representation. */
Expand Down
9 changes: 7 additions & 2 deletions src/jit/graph.c
Expand Up @@ -871,10 +871,14 @@ static MVMint32 consume_reprop(MVMThreadContext *tc, MVMJitGraph *jg,
void *alternative_function = MVM_VMArray_devirtualize_ins_for_jit(tc, STABLE(type_facts->type), ins);

if (alternative_function != NULL) {
MVMuint16 rv_type = op == MVM_OP_atpos_i ? MVM_JIT_RV_INT
: op == MVM_OP_atpos_o ? MVM_JIT_RV_PTR
: 0;

MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
{ MVM_JIT_REG_VAL, invocant },
{ MVM_JIT_REG_VAL, value } };
jg_append_call_c(tc, jg, alternative_function, 3, args, MVM_JIT_RV_PTR, dst);
jg_append_call_c(tc, jg, alternative_function, 3, args, rv_type, dst);
MVM_spesh_graph_add_comment(tc, iter->graph, ins, "JIT: double-devirtualized");;
return 1;
}
Expand All @@ -894,7 +898,8 @@ static MVMint32 consume_reprop(MVMThreadContext *tc, MVMJitGraph *jg,
op == MVM_OP_atpos_s || op == MVM_OP_atkey_s ? MVM_reg_str :
MVM_reg_obj } };
jg_append_call_c(tc, jg, function, 7, args, MVM_JIT_RV_VOID, -1);
MVM_spesh_graph_add_comment(tc, iter->graph, ins, "JIT: devirtualized");;
MVM_spesh_graph_add_comment(tc, iter->graph, ins, "JIT: devirtualized");
}
return 1;
}
case MVM_OP_bindkey_i:
Expand Down

0 comments on commit bd43dcc

Please sign in to comment.