Skip to content

Commit

Permalink
can do coerce_in of literals at spesh-time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Paulssen committed Jun 15, 2014
1 parent dd80dbf commit 87221ba
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/spesh/optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,24 @@ static void optimize_can_op(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *
}
}

/* If we have a const_i and a coerce_in, we can emit a const_n instead. */
static void optimize_coerce(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb, MVMSpeshIns *ins) {
MVMSpeshFacts *facts = MVM_spesh_get_facts(tc, g, ins->operands[1]);

if (facts->flags & MVM_SPESH_FACT_KNOWN_VALUE) {
MVMSpeshFacts *result_facts = MVM_spesh_get_facts(tc, g, ins->operands[0]);
MVMnum64 result = facts->value.i64;

facts->usages--;

ins->info = MVM_op_get_op(MVM_OP_const_n64);
ins->operands[1].lit_n64 = result;

result_facts->flags |= MVM_SPESH_FACT_KNOWN_VALUE;
result_facts->value.n64 = result;
}
}

/* If we know the type of a significant operand, we might try to specialize by
* representation. */
static void optimize_repr_op(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb,
Expand Down Expand Up @@ -598,6 +616,9 @@ static void optimize_bb(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb)
}
break;
}
case MVM_OP_coerce_in:
optimize_coerce(tc, g, bb, ins);
break;
case MVM_OP_invoke_v:
optimize_call(tc, g, bb, ins, 0, &arg_info);
break;
Expand Down

0 comments on commit 87221ba

Please sign in to comment.