Permalink
Browse files

Flag up writers that die when a BB dies.

So that we will later be able to ignore them when doing PHI merges.
  • Loading branch information...
jnthn committed Jun 14, 2017
1 parent c43f436 commit c08e4c29c220b27cf2826cf1f6fee48c754f9247
Showing with 13 additions and 0 deletions.
  1. +3 −0 src/spesh/dump.c
  2. +1 −0 src/spesh/facts.h
  3. +9 −0 src/spesh/optimize.c
View
@@ -380,6 +380,9 @@ static void dump_facts(MVMThreadContext *tc, DumpStr *ds, MVMSpeshGraph *g) {
if (flags & 8192) {
append(ds, " KRWCn");
}
if (flags & MVM_SPESH_FACT_DEAD_WRITER) {
append(ds, " DeadWriter");
}
if (g->facts[i][j].writer && g->facts[i][j].writer->info->opcode == MVM_SSA_PHI) {
appendf(ds, " (merged from %d regs)", g->facts[i][j].writer->info->num_operands - 1);
}
View
@@ -48,6 +48,7 @@ struct MVMSpeshFacts {
#define MVM_SPESH_FACT_KNOWN_BOX_SRC 2048 /* We know what register this value was boxed from */
#define MVM_SPESH_FACT_MERGED_WITH_LOG_GUARD 4096 /* These facts were merged at a PHI node, but at least one of the incoming facts had a "from log guard" flag set, so we'll have to look for that fact and increment its uses if we use this here fact. */
#define MVM_SPESH_FACT_RW_CONT 8192 /* Known to be an rw container */
#define MVM_SPESH_FACT_DEAD_WRITER 16384 /* Writing instruction in a now-dead BB. */
void MVM_spesh_facts_discover(MVMThreadContext *tc, MVMSpeshGraph *g);
void MVM_spesh_facts_depend(MVMThreadContext *tc, MVMSpeshGraph *g,
View
@@ -1830,6 +1830,14 @@ static MVMint64 has_handler_anns(MVMThreadContext *tc, MVMSpeshBB *bb) {
}
return 0;
}
static void mark_dead_writers(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshBB *dead_bb) {
MVMSpeshIns *ins = dead_bb->first_ins;
while (ins) {
if ((ins->info->operands[0] & MVM_operand_rw_mask) == MVM_operand_write_reg)
get_facts_direct(tc, g, ins->operands[0])->flags |= MVM_SPESH_FACT_DEAD_WRITER;
ins = ins->next;
}
}
static void eliminate_dead_bbs(MVMThreadContext *tc, MVMSpeshGraph *g) {
/* Iterate to fixed point. */
MVMint8 *seen = MVM_malloc(g->num_bbs);
@@ -1857,6 +1865,7 @@ static void eliminate_dead_bbs(MVMThreadContext *tc, MVMSpeshGraph *g) {
MVMSpeshBB *death_cand = cur_bb->linear_next;
if (!seen[death_cand->idx]) {
if (!death_cand->inlined && !has_handler_anns(tc, death_cand)) {
mark_dead_writers(tc, g, death_cand);
cur_bb->linear_next = cur_bb->linear_next->linear_next;
g->num_bbs--;
death = 1;

0 comments on commit c08e4c2

Please sign in to comment.