Mesa (master): nir/search: Add debugging code to dump the pattern matched

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu May 2 14:26:51 UTC 2019


Module: Mesa
Branch: master
Commit: 6ec4ed48fc2056d3475e5e60de7c34fe42f8fd33
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6ec4ed48fc2056d3475e5e60de7c34fe42f8fd33

Author: Connor Abbott <cwabbott0 at gmail.com>
Date:   Mon Feb 18 17:28:32 2019 +0100

nir/search: Add debugging code to dump the pattern matched

This was useful while debugging the previous commit.

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

---

 src/compiler/nir/nir_search.c | 75 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c
index c8acdfb46b4..6d3fbf7f7ba 100644
--- a/src/compiler/nir/nir_search.c
+++ b/src/compiler/nir/nir_search.c
@@ -530,6 +530,73 @@ construct_value(nir_builder *build,
    }
 }
 
+MAYBE_UNUSED static void dump_value(const nir_search_value *val)
+{
+   switch (val->type) {
+   case nir_search_value_constant: {
+      const nir_search_constant *sconst = nir_search_value_as_constant(val);
+      switch (sconst->type) {
+      case nir_type_float:
+         printf("%f", sconst->data.d);
+         break;
+      case nir_type_int:
+         printf("%"PRId64, sconst->data.i);
+         break;
+      case nir_type_uint:
+         printf("0x%"PRIx64, sconst->data.u);
+         break;
+      default:
+         unreachable("bad const type");
+      }
+      break;
+   }
+
+   case nir_search_value_variable: {
+      const nir_search_variable *var = nir_search_value_as_variable(val);
+      if (var->is_constant)
+         printf("#");
+      printf("%c", var->variable + 'a');
+      break;
+   }
+
+   case nir_search_value_expression: {
+      const nir_search_expression *expr = nir_search_value_as_expression(val);
+      printf("(");
+      if (expr->inexact)
+         printf("~");
+      switch (expr->opcode) {
+#define CASE(n) \
+      case nir_search_op_##n: printf(#n); break;
+      CASE(f2b)
+      CASE(b2f)
+      CASE(b2i)
+      CASE(i2b)
+      CASE(i2i)
+      CASE(f2i)
+      CASE(i2f)
+#undef CASE
+      default:
+         printf("%s", nir_op_infos[expr->opcode].name);
+      }
+
+      unsigned num_srcs = 1;
+      if (expr->opcode <= nir_last_opcode)
+         num_srcs = nir_op_infos[expr->opcode].num_inputs;
+
+      for (unsigned i = 0; i < num_srcs; i++) {
+         printf(" ");
+         dump_value(expr->srcs[i]);
+      }
+
+      printf(")");
+      break;
+   }
+   }
+
+   if (val->bit_size > 0)
+      printf("@%d", val->bit_size);
+}
+
 nir_ssa_def *
 nir_replace_instr(nir_builder *build, nir_alu_instr *instr,
                   const nir_search_expression *search,
@@ -567,6 +634,14 @@ nir_replace_instr(nir_builder *build, nir_alu_instr *instr,
    if (!found)
       return NULL;
 
+#if 0
+   printf("matched: ");
+   dump_value(&search->value);
+   printf(" -> ");
+   dump_value(replace);
+   printf(" ssa_%d\n", instr->dest.dest.ssa.index);
+#endif
+
    build->cursor = nir_before_instr(&instr->instr);
 
    nir_alu_src val = construct_value(build, replace,




More information about the mesa-commit mailing list