Skip to content

Commit

Permalink
Don't break arg instruction sequence
Browse files Browse the repository at this point in the history
When we insert a materialization, make sure it goes prior to the
prepargs.
  • Loading branch information
jnthn committed May 15, 2019
1 parent 55d254c commit 92d21cd
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/spesh/pea.c
Expand Up @@ -277,6 +277,27 @@ static MVMSpeshOperand resolve_materialization_target(MVMThreadContext *tc, MVMS
}
}

/* We should not stick a materialization in an args sequence; insert it
* prior to that. */
MVMSpeshIns * find_materialization_insertion_point(MVMThreadContext *tc, MVMSpeshIns *ins) {
while (ins) {
switch (ins->info->opcode) {
case MVM_OP_arg_i:
case MVM_OP_arg_n:
case MVM_OP_arg_s:
case MVM_OP_arg_o:
case MVM_OP_argconst_i:
case MVM_OP_argconst_n:
case MVM_OP_argconst_s:
ins = ins->prev;
break;
default:
return ins;
}
}
MVM_oops(tc, "Spesh PEA: failed to find materialization insertion point");
}

/* Emit the materialization of an object into the specified register. */
static void emit_materialization(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb,
MVMSpeshIns *prior_to, MVMSpeshOperand target,
Expand Down Expand Up @@ -526,7 +547,8 @@ static void apply_transform(MVMThreadContext *tc, MVMSpeshGraph *g, GraphState *
MaterializationTarget *alias_target = initial_target->next;
MVMSpeshIns *prior_to = t->materialize.prior_to;
MVMuint8 *used = t->materialize.used;
emit_materialization(tc, g, bb, prior_to,
emit_materialization(tc, g, bb,
find_materialization_insertion_point(tc, prior_to),
resolve_materialization_target(tc, g, gs, initial_target),
gs, t->allocation, used);
while (alias_target) {
Expand Down

0 comments on commit 92d21cd

Please sign in to comment.