agx: Validate part of SSA form
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 12 Nov 2022 16:35:26 +0000 (11:35 -0500)
committerMarge Bot <emma+marge@anholt.net>
Sat, 19 Nov 2022 04:27:10 +0000 (04:27 +0000)
To debug backend pass problems.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19811>

src/asahi/compiler/agx_validate.c

index fc6e5f9..6c3a5d6 100644 (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);