Skip to content

Commit

Permalink
Fact discovery determines usage counts
Browse files Browse the repository at this point in the history
Some time ago, a call was added to do fact discovery on inlinees. This
process sets usage counts along the way. However, the code to set the
usage counts in inlining was also in place, so we doubled all of the
counts, which would frustrate dead code elimination possibilities that
arise post-inline.

With this change we only do fact discovery, and that call is moved to
inline.c instead, where it feels a little more natural. Also don't
pass along the inliner's plan to go with inlinee fact discovery; it
doesn't relate to the inlinee, and could cause bogus guard insertion
if we're unlucky.
  • Loading branch information
jnthn committed Jul 4, 2018
1 parent d3b888b commit fa471f1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/spesh/facts.c
Expand Up @@ -461,7 +461,7 @@ static void add_bb_facts(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb,
}
ann = ann->next;
}
if (ann_deopt_one && ann_logged) {
if (p && ann_deopt_one && ann_logged) {
if (ins->info->opcode == MVM_OP_speshresolve)
plugin_facts(tc, g, bb, ins, p, ann_deopt_one, ann_logged);
else
Expand Down
22 changes: 3 additions & 19 deletions src/spesh/inline.c
Expand Up @@ -182,25 +182,9 @@ MVMSpeshGraph * MVM_spesh_inline_try_get_graph(MVMThreadContext *tc, MVMSpeshGra
* inline the graph. */
ig = MVM_spesh_graph_create_from_cand(tc, target_sf, cand, 0);
if (is_graph_inlineable(tc, inliner, target_sf, invoke_ins, ig, no_inline_reason)) {
/* We can inline it. Bump usage counts and return the graph. */
MVMSpeshBB *bb = ig->entry;
while (bb) {
MVMSpeshIns *ins = bb->first_ins;
while (ins) {
MVMint32 opcode = ins->info->opcode;
MVMint32 is_phi = opcode == MVM_SSA_PHI;
MVMuint8 i;
for (i = 0; i < ins->info->num_operands; i++)
if ((is_phi && i > 0)
|| (!is_phi && (ins->info->operands[i] & MVM_operand_rw_mask) == MVM_operand_read_reg))
ig->facts[ins->operands[i].reg.orig][ins->operands[i].reg.i].usages++;
if (opcode == MVM_OP_inc_i || opcode == MVM_OP_inc_u ||
opcode == MVM_OP_dec_i || opcode == MVM_OP_dec_u)
ig->facts[ins->operands[0].reg.orig][ins->operands[0].reg.i - 1].usages++;
ins = ins->next;
}
bb = bb->linear_next;
}
/* We can inline it. Do facts discovery, which also sets usage counts, and
* return it. */
MVM_spesh_facts_discover(tc, ig, NULL);
return ig;
}
else {
Expand Down
1 change: 0 additions & 1 deletion src/spesh/optimize.c
Expand Up @@ -1746,7 +1746,6 @@ static void optimize_call(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *bb
MVMSpeshOperand code_ref_reg = ins->info->opcode == MVM_OP_invoke_v
? ins->operands[0]
: ins->operands[1];
MVM_spesh_facts_discover(tc, inline_graph, p);
MVM_spesh_get_facts(tc, g, code_ref_reg)->usages++;
MVM_spesh_inline(tc, g, arg_info, bb, ins, inline_graph, target_sf,
code_ref_reg);
Expand Down

0 comments on commit fa471f1

Please sign in to comment.