Skip to content

Commit

Permalink
Harden BB deletion annotation motion
Browse files Browse the repository at this point in the history
Fixes #938.
  • Loading branch information
jnthn committed Aug 10, 2018
1 parent 68b3197 commit fba5c6b
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/spesh/dead_bb_elimination.c
Expand Up @@ -6,6 +6,25 @@ static void mark_handler_unreachable(MVMThreadContext *tc, MVMSpeshGraph *g, MVM
g->unreachable_handlers[index] = 1;
}

static MVMSpeshBB * linear_next_with_ins(MVMSpeshBB *cur_bb) {
while (cur_bb) {
if (cur_bb->first_ins)
return cur_bb;
cur_bb = cur_bb->linear_next;
}
return NULL;
}

static MVMSpeshBB * linear_prev_with_ins(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *cur_bb) {
cur_bb = MVM_spesh_graph_linear_prev(tc, g, cur_bb);
while (cur_bb) {
if (cur_bb->first_ins)
return cur_bb;
cur_bb = MVM_spesh_graph_linear_prev(tc, g, cur_bb);
}
return NULL;
}

static void cleanup_dead_bb_instructions(MVMThreadContext *tc, MVMSpeshGraph *g,
MVMSpeshBB *dead_bb, MVMint32 cleanup_facts) {
MVMSpeshIns *ins = dead_bb->first_ins;
Expand All @@ -22,20 +41,22 @@ static void cleanup_dead_bb_instructions(MVMThreadContext *tc, MVMSpeshGraph *g,
* unreachable. */
g->inlines[ann->data.inline_idx].unreachable = 1;
break;
case MVM_SPESH_ANN_FH_START:
case MVM_SPESH_ANN_FH_START: {
/* Move the start to the next basic block if possible. If
* not, just mark the handler deleted; its end must be in
* this block also. */
MVMSpeshBB *move_to_bb = linear_next_with_ins(dead_bb->linear_next);
frame_handlers_started[ann->data.frame_handler_index] = 1;
if (dead_bb->linear_next) {
MVMSpeshIns *move_to_ins = dead_bb->linear_next->first_ins;
if (move_to_bb) {
MVMSpeshIns *move_to_ins = move_to_bb->first_ins;
ann->next = move_to_ins->annotations;
move_to_ins->annotations = ann;
}
else {
mark_handler_unreachable(tc, g, ann->data.frame_handler_index);
}
break;
}
case MVM_SPESH_ANN_FH_END: {
/* If we already saw the start, then we'll just mark it as
* deleted. */
Expand All @@ -46,10 +67,12 @@ static void cleanup_dead_bb_instructions(MVMThreadContext *tc, MVMSpeshGraph *g,
/* Otherwise, move it to the end of the previous basic
* block (which should always exist). */
else {
MVMSpeshBB *linear_prev = MVM_spesh_graph_linear_prev(tc, g, dead_bb);
MVMSpeshIns *move_to_ins = linear_prev->last_ins;
ann->next = move_to_ins->annotations;
move_to_ins->annotations = ann;
MVMSpeshBB *move_to_bb = linear_prev_with_ins(tc, g, dead_bb);
if (move_to_bb) {
MVMSpeshIns *move_to_ins = move_to_bb->last_ins;
ann->next = move_to_ins->annotations;
move_to_ins->annotations = ann;
}
}
break;
}
Expand Down

0 comments on commit fba5c6b

Please sign in to comment.