From c2159ce9e403de76db4bd31f9398f3294f4741c1 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Sat, 12 Nov 2022 11:35:26 -0500 Subject: [PATCH] agx: Validate part of SSA form To debug backend pass problems. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/asahi/compiler/agx_validate.c | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/asahi/compiler/agx_validate.c b/src/asahi/compiler/agx_validate.c index fc6e5f9bec0..6c3a5d655e3 100644 --- a/src/asahi/compiler/agx_validate.c +++ b/src/asahi/compiler/agx_validate.c @@ -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);