Skip to content

Commit

Permalink
Remove the pointless goto at the end of an inlined function.
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Jan 19, 2018
1 parent 547cc1f commit 1eb6499
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/spesh/deopt.c
Expand Up @@ -115,9 +115,7 @@ static void uninline(MVMThreadContext *tc, MVMFrame *f, MVMSpeshCandidate *cand,
}
}

/* Update tracking variables for last uninline. Note that we know
* an inline ends with a goto, which is how we're able to find a
* return address offset. */
/* Update tracking variables for last uninline. */
last_uninlined = uf;
last_res_reg = cand->inlines[i].res_reg;
last_res_type = cand->inlines[i].res_type;
Expand Down
5 changes: 2 additions & 3 deletions src/spesh/inline.c
Expand Up @@ -268,7 +268,7 @@ MVMSpeshBB * merge_graph(MVMThreadContext *tc, MVMSpeshGraph *inliner,
MVMSpeshFacts **merged_facts;
MVMuint16 *merged_fact_counts;
MVMint32 i, orig_inlines, total_inlines, orig_deopt_addrs;
MVMuint32 total_handlers = inliner->num_handlers + inlinee->num_handlers;
MVMuint32 total_handlers = inliner->num_handlers + inlinee->num_handlers + 1;
MVMSpeshBB *inlinee_first_bb = NULL, *inlinee_last_bb = NULL;

/* If the inliner and inlinee are from different compilation units, we
Expand Down Expand Up @@ -512,7 +512,6 @@ MVMSpeshBB * merge_graph(MVMThreadContext *tc, MVMSpeshGraph *inliner,

/* Merge unreachable handlers array if needed. */
if (inliner->unreachable_handlers || inlinee->unreachable_handlers) {
MVMuint32 total_handlers = inliner->num_handlers + inlinee->num_handlers + 1;
MVMint8 *new_uh = MVM_spesh_alloc(tc, inliner, total_handlers);
if (inlinee->unreachable_handlers)
memcpy(new_uh, inlinee->unreachable_handlers,
Expand All @@ -524,7 +523,7 @@ MVMSpeshBB * merge_graph(MVMThreadContext *tc, MVMSpeshGraph *inliner,
}

/* Merge handlers from inlinee. */
resize_handlers_table(tc, inliner, total_handlers + 1);
resize_handlers_table(tc, inliner, total_handlers);

if (inliner->num_handlers > 0)
memmove(inliner->handlers + inlinee->num_handlers + 1, inliner->handlers,
Expand Down
15 changes: 1 addition & 14 deletions src/spesh/optimize.c
Expand Up @@ -2402,16 +2402,6 @@ static int any_deopt_annotations(MVMSpeshAnn *ann) {
}
return 0;
}
static int any_inline_end_annotations(MVMSpeshAnn *ann) {
while (ann) {
switch (ann->type) {
case MVM_SPESH_ANN_INLINE_END:
return 1;
}
ann = ann->next;
}
return 0;
}
static void eliminate_pointless_gotos(MVMThreadContext *tc, MVMSpeshGraph *g) {
MVMSpeshBB *cur_bb = g->entry;
while (cur_bb) {
Expand All @@ -2423,10 +2413,7 @@ static void eliminate_pointless_gotos(MVMThreadContext *tc, MVMSpeshGraph *g) {
&& last_ins->operands[0].ins_bb == cur_bb->linear_next
&& ! any_deopt_annotations(last_ins->annotations)
) {
if (
any_inline_end_annotations(last_ins->annotations)
|| last_ins == cur_bb->first_ins // May not throw away the only instruction
)
if (last_ins == cur_bb->first_ins) // May not throw away the only instruction
last_ins->info = MVM_op_get_op(MVM_OP_no_op);
else
MVM_spesh_manipulate_delete_ins(tc, g, cur_bb, last_ins);
Expand Down

0 comments on commit 1eb6499

Please sign in to comment.