Skip to content

Commit

Permalink
Clean up handler successors after throwish ops become non-throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Jan 20, 2018
1 parent a70dd94 commit c60ebd7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/6model/reprs/P6opaque.c
Expand Up @@ -1427,6 +1427,7 @@ static void spesh(MVMThreadContext *tc, MVMSTable *st, MVMSpeshGraph *g, MVMSpes
MVM_spesh_get_facts(tc, g, ins->operands[2])->usages--;
ins->info = MVM_op_get_op(MVM_OP_sp_p6oget_o);
ins->operands[2].lit_i16 = repr_data->attribute_offsets[slot];
MVM_spesh_manipulate_remove_handler_successors(tc, bb);
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/spesh/graph.c
Expand Up @@ -512,6 +512,7 @@ static void build_cfg(MVMThreadContext *tc, MVMSpeshGraph *g, MVMStaticFrame *sf
MVMint32 num_bbs = 1 + g->num_handlers + num_osr_points;
MVMint32 insert_pos = 1;
cur_bb->succ = MVM_spesh_alloc(tc, g, num_bbs * sizeof(MVMSpeshBB *));
cur_bb->handler_succ = MVM_spesh_alloc(tc, g, g->num_handlers * sizeof(MVMSpeshBB *));
cur_bb->succ[0] = cur_bb->linear_next;
for (i = 0; i < g->num_handlers; i++) {
if (is_catch_handler(tc, g, i)) {
Expand Down Expand Up @@ -612,18 +613,32 @@ static void build_cfg(MVMThreadContext *tc, MVMSpeshGraph *g, MVMStaticFrame *sf
}

/* Attach this block to the goto block of any active handlers. */
if (num_active_handlers) {
if (
num_active_handlers
&& (
cur_bb->last_ins->info->jittivity & (MVM_JIT_INFO_THROWISH | MVM_JIT_INFO_INVOKISH)
|| cur_bb->last_ins->info->opcode == MVM_OP_invoke_v
|| cur_bb->last_ins->info->opcode == MVM_OP_invoke_i
|| cur_bb->last_ins->info->opcode == MVM_OP_invoke_n
|| cur_bb->last_ins->info->opcode == MVM_OP_invoke_s
|| cur_bb->last_ins->info->opcode == MVM_OP_invoke_o
)
) {
cur_bb->handler_succ = MVM_spesh_alloc(tc, g, num_active_handlers * sizeof(MVMSpeshBB *));
for (i = 0; i < g->num_handlers; i++) {
if (active_handlers[i]) {
MVMuint32 offset = g->handlers[i].goto_offset;
MVMSpeshBB *target = ins_to_bb[byte_to_ins_flags[offset] >> 3];
if (!already_succs(tc, cur_bb, target)) {
cur_bb->succ[cur_bb->num_succ] = target;
cur_bb->num_succ++;
cur_bb->handler_succ[cur_bb->num_handler_succ++] = target;
}
}
}
}
else
cur_bb->handler_succ = NULL;
}

/* Move on to next block. */
Expand Down
4 changes: 4 additions & 0 deletions src/spesh/graph.h
Expand Up @@ -139,11 +139,15 @@ struct MVMSpeshBB {
/* Dominance frontier set. */
MVMSpeshBB **df;

/* Basic blocks that we may go to if we throw. */
MVMSpeshBB **handler_succ;

/* Counts for the above, grouped together to avoid alignment holes. */
MVMuint16 num_succ;
MVMuint16 num_pred;
MVMuint16 num_children;
MVMuint16 num_df;
MVMuint16 num_handler_succ;

/* The next basic block in original linear code order. */
MVMSpeshBB *linear_next;
Expand Down
11 changes: 11 additions & 0 deletions src/spesh/manipulate.c
Expand Up @@ -211,6 +211,17 @@ void MVM_spesh_manipulate_remove_successor(MVMThreadContext *tc, MVMSpeshBB *bb,
succ_pred[succ_num_pred] = NULL;
}

/* Removes successors from a basic block that point to handlers.
Useful for optimizations that turn throwish ops into non-throwing ones. */
void MVM_spesh_manipulate_remove_handler_successors(MVMThreadContext *tc, MVMSpeshBB *bb) {
int i;
for (i = 0; i < bb->num_handler_succ; i++) {
MVM_spesh_manipulate_remove_successor(tc, bb, bb->handler_succ[i]);
bb->handler_succ[i] = NULL;
}
bb->num_handler_succ = 0;
}

/* Gets a temporary register of the specified kind to use in some transform.
* Will only actually extend the frame if needed; if an existing temporary
* was requested and then released, then it will just use a new version of
Expand Down
1 change: 1 addition & 0 deletions src/spesh/manipulate.h
Expand Up @@ -4,6 +4,7 @@ MVM_PUBLIC void MVM_spesh_manipulate_insert_ins(MVMThreadContext *tc, MVMSpeshBB
MVM_PUBLIC void MVM_spesh_manipulate_insert_goto(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb, MVMSpeshIns *ins, MVMSpeshBB *target);
void MVM_spesh_manipulate_add_successor(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb, MVMSpeshBB *succ);
void MVM_spesh_manipulate_remove_successor(MVMThreadContext *tc, MVMSpeshBB *bb, MVMSpeshBB *succ);
void MVM_spesh_manipulate_remove_handler_successors(MVMThreadContext *tc, MVMSpeshBB *bb);
MVMSpeshOperand MVM_spesh_manipulate_get_temp_reg(MVMThreadContext *tc, MVMSpeshGraph *g, MVMuint16 kind);
void MVM_spesh_manipulate_release_temp_reg(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshOperand temp);

Expand Down
1 change: 1 addition & 0 deletions src/spesh/optimize.c
Expand Up @@ -634,6 +634,7 @@ static void optimize_decont(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *
ins->info = MVM_op_get_op(MVM_OP_set);
MVM_spesh_use_facts(tc, g, obj_facts);
copy_facts(tc, g, ins->operands[0], ins->operands[1]);
MVM_spesh_manipulate_remove_handler_successors(tc, bb);
}
else {
/* Propagate facts if we know what this deconts to. */
Expand Down

0 comments on commit c60ebd7

Please sign in to comment.