Skip to content

Commit

Permalink
allow hllboxtype_* across hll in inlines
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Jul 11, 2018
1 parent 6cf1841 commit f8c4648
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/core/oplist
Expand Up @@ -407,11 +407,11 @@ isstr w(int64) r(obj) :pure
islist w(int64) r(obj) :pure
ishash w(int64) r(obj) :pure
sethllconfig r(str) r(obj)
hllboxtype_i w(obj) :pure :useshll
hllboxtype_n w(obj) :pure :useshll
hllboxtype_s w(obj) :pure :useshll
hlllist w(obj) :pure :useshll
hllhash w(obj) :pure :useshll
hllboxtype_i w(obj) :pure
hllboxtype_n w(obj) :pure
hllboxtype_s w(obj) :pure
hlllist w(obj) :pure
hllhash w(obj) :pure
getcomp w(obj) r(str) :pure
bindcomp w(obj) r(str) r(obj)
getcurhllsym w(obj) r(str) :pure :useshll
Expand Down
10 changes: 5 additions & 5 deletions src/core/ops.c
Expand Up @@ -4952,7 +4952,7 @@ static const MVMOpInfo MVM_op_infos[] = {
0,
0,
0,
1,
0,
{ MVM_operand_write_reg | MVM_operand_obj }
},
{
Expand All @@ -4966,7 +4966,7 @@ static const MVMOpInfo MVM_op_infos[] = {
0,
0,
0,
1,
0,
{ MVM_operand_write_reg | MVM_operand_obj }
},
{
Expand All @@ -4980,7 +4980,7 @@ static const MVMOpInfo MVM_op_infos[] = {
0,
0,
0,
1,
0,
{ MVM_operand_write_reg | MVM_operand_obj }
},
{
Expand All @@ -4994,7 +4994,7 @@ static const MVMOpInfo MVM_op_infos[] = {
0,
0,
0,
1,
0,
{ MVM_operand_write_reg | MVM_operand_obj }
},
{
Expand All @@ -5008,7 +5008,7 @@ static const MVMOpInfo MVM_op_infos[] = {
0,
0,
0,
1,
0,
{ MVM_operand_write_reg | MVM_operand_obj }
},
{
Expand Down
30 changes: 30 additions & 0 deletions src/spesh/inline.c
Expand Up @@ -375,6 +375,28 @@ static void rewrite_outer_lookup(MVMThreadContext *tc, MVMSpeshGraph *g,
MVM_spesh_usages_add_by_reg(tc, g, code_ref_reg, ins);
}

static void rewrite_hlltype(MVMThreadContext *tc, MVMSpeshGraph *inlinee, MVMSpeshIns *ins) {
MVMObject *selected_type;
MVMHLLConfig *hll = inlinee->sf->body.cu->body.hll_config;
MVMSpeshOperand *old_ops = ins->operands;
MVMuint16 sslot;

switch (ins->info->opcode) {
case MVM_OP_hllboxtype_i: selected_type = hll->int_box_type; break;
case MVM_OP_hllboxtype_n: selected_type = hll->num_box_type; break;
case MVM_OP_hllboxtype_s: selected_type = hll->str_box_type; break;
case MVM_OP_hlllist: selected_type = hll->slurpy_array_type; break;
case MVM_OP_hllhash: selected_type = hll->slurpy_hash_type; break;
default: MVM_oops(tc, "unhandled instruction %s in rewrite_hlltype", ins->info->name);
}

sslot = MVM_spesh_add_spesh_slot_try_reuse(tc, inlinee, (MVMCollectable *)selected_type);
ins->operands = MVM_spesh_alloc(tc, inlinee, 2 * sizeof(MVMSpeshOperand));
ins->operands[0] = old_ops[0];
ins->operands[1].lit_i16 = sslot;
ins->info = MVM_op_get_op(MVM_OP_sp_getspeshslot);
}

/* Merges the inlinee's spesh graph into the inliner. */
MVMSpeshBB * merge_graph(MVMThreadContext *tc, MVMSpeshGraph *inliner,
MVMSpeshGraph *inlinee, MVMStaticFrame *inlinee_sf,
Expand All @@ -391,6 +413,9 @@ MVMSpeshBB * merge_graph(MVMThreadContext *tc, MVMSpeshGraph *inliner,
* potentially have to fix up extra things. */
MVMint32 same_comp_unit = inliner->sf->body.cu == inlinee->sf->body.cu;

MVMint32 same_hll = same_comp_unit || inliner->sf->body.cu->body.hll_config ==
inlinee_sf->body.cu->body.hll_config;

/* Renumber the locals, lexicals, and basic blocks of the inlinee; also
* re-write any indexes in annotations that need it. */
MVMSpeshBB *bb = inlinee->entry;
Expand Down Expand Up @@ -444,6 +469,11 @@ MVMSpeshBB * merge_graph(MVMThreadContext *tc, MVMSpeshGraph *inliner,
if (ins->info->opcode == MVM_OP_const_s) {
fix_const_str(tc, inliner, inlinee, ins);
}
if (!same_hll &&
(opcode == MVM_OP_hllboxtype_i || opcode == MVM_OP_hllboxtype_n || opcode == MVM_OP_hllboxtype_s
|| opcode == MVM_OP_hlllist || opcode == MVM_OP_hllhash)) {
rewrite_hlltype(tc, inlinee, ins);
}
}

for (i = 0; i < ins->info->num_operands; i++) {
Expand Down

0 comments on commit f8c4648

Please sign in to comment.