agx: Validate part of SSA form

To debug backend pass problems.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19811>
This commit is contained in:
Alyssa Rosenzweig
2022-11-12 11:35:26 -05:00
committed by Marge Bot
parent 1110fcccc2
commit c2159ce9e4
+38
View File
@@ -117,6 +117,30 @@ agx_validate_sources(agx_instr *I)
return true;
}
static bool
agx_validate_defs(agx_instr *I, BITSET_WORD *defs)
{
agx_foreach_ssa_src(I, s) {
/* Skip phis, they're special in loop headers */
if (I->op == AGX_OPCODE_PHI)
break;
/* Sources must be defined before their use */
if (!BITSET_TEST(defs, I->src[s].value))
return false;
}
agx_foreach_ssa_dest(I, d) {
/* Static single assignment */
if (BITSET_TEST(defs, I->dest[d].value))
return false;
BITSET_SET(defs, I->dest[d].value);
}
return true;
}
void
agx_validate(agx_context *ctx, const char *after)
{
@@ -133,6 +157,20 @@ agx_validate(agx_context *ctx, const char *after)
}
}
{
BITSET_WORD *defs = calloc(sizeof(BITSET_WORD), BITSET_WORDS(ctx->alloc));
agx_foreach_instr_global(ctx, I) {
if (!agx_validate_defs(I, defs)) {
fprintf(stderr, "Invalid defs after %s\n", after);
agx_print_instr(I, stdout);
fail = true;
}
}
free(defs);
}
agx_foreach_instr_global(ctx, I) {
if (!agx_validate_sources(I)) {
fprintf(stderr, "Invalid sources form after %s\n", after);