Skip to content

Commit

Permalink
Validata SSA dominance property
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Aug 31, 2023
1 parent 777566f commit 4cf60c7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ir_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,14 @@ int ir_schedule_blocks(ir_ctx *ctx)
pos += count + 1;
}
}

if (ctx->cfg_map) {
ir_ref i;

for (i = IR_UNUSED + 1; i < ctx->insns_count; i++) {
ctx->cfg_map[i] = map[ctx->cfg_map[i]];
}
}
}

ir_mem_free(list);
Expand Down
28 changes: 28 additions & 0 deletions ir_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ static bool ir_check_input_list(const ir_ctx *ctx, ir_ref from, ir_ref to)
return 0;
}

static bool ir_check_domination(const ir_ctx *ctx, ir_ref def, ir_ref use)
{
uint32_t b1 = ctx->cfg_map[def];
uint32_t b2 = ctx->cfg_map[use];
ir_block *blocks = ctx->cfg_blocks;
uint32_t b1_depth = blocks[b1].dom_depth;
const ir_block *bb2 = &blocks[b2];

if (b1 == b2) {
return def < use;
}
while (bb2->dom_depth > b1_depth) {
b2 = bb2->dom_parent;
bb2 = &blocks[b2];
}
return b1 == b2;
}

bool ir_check(const ir_ctx *ctx)
{
ir_ref i, j, n, *p, use;
Expand Down Expand Up @@ -166,6 +184,13 @@ bool ir_check(const ir_ctx *ctx)
break;
}
}
if ((ctx->flags & IR_LINEAR)
&& ctx->cfg_map
&& insn->op != IR_PHI
&& !ir_check_domination(ctx, use, i)) {
fprintf(stderr, "ir_base[%d].ops[%d] -> %d, %d doesn't dominate %d\n", i, j, use, use, i);
ok = 0;
}
break;
case IR_OPND_CONTROL:
if (flags & IR_OP_FLAG_BB_START) {
Expand Down Expand Up @@ -331,6 +356,9 @@ bool ir_check(const ir_ctx *ctx)
insn += n;
}

// if (!ok) {
// ir_dump_codegen(ctx, stderr);
// }
IR_ASSERT(ok);
return ok;
}

0 comments on commit 4cf60c7

Please sign in to comment.