vc4: Dump constant uniform values in VC4_DEBUG=qir.
authorEric Anholt <eric@anholt.net>
Thu, 25 Sep 2014 05:03:06 +0000 (22:03 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 29 Sep 2014 18:33:34 +0000 (11:33 -0700)
Definitely helps when trying to understand and optimize a program.

src/gallium/drivers/vc4/vc4_opt_algebraic.c
src/gallium/drivers/vc4/vc4_opt_copy_propagation.c
src/gallium/drivers/vc4/vc4_opt_cse.c
src/gallium/drivers/vc4/vc4_opt_dead_code.c
src/gallium/drivers/vc4/vc4_qir.c
src/gallium/drivers/vc4/vc4_qir.h

index 868677acbde132f0faebf7c95e58684b1bc4995c..b5cde0511d00715044e4627da1079686391754aa 100644 (file)
 static bool debug;
 
 static void
-dump_from(struct qinst *inst)
+dump_from(struct vc4_compile *c, struct qinst *inst)
 {
         if (!debug)
                 return;
 
         fprintf(stderr, "optimizing: ");
-        qir_dump_inst(inst);
+        qir_dump_inst(c, inst);
         fprintf(stderr, "\n");
 }
 
 static void
-dump_to(struct qinst *inst)
+dump_to(struct vc4_compile *c, struct qinst *inst)
 {
         if (!debug)
                 return;
 
         fprintf(stderr, "to: ");
-        qir_dump_inst(inst);
+        qir_dump_inst(c, inst);
         fprintf(stderr, "\n");
 }
 
@@ -99,21 +99,21 @@ qir_opt_algebraic(struct vc4_compile *c)
                                 /* Turn "dst = (sf == x) ? a : a)" into
                                  * "dst = a"
                                  */
-                                dump_from(inst);
+                                dump_from(c, inst);
                                 inst->op = QOP_MOV;
                                 inst->src[0] = inst->src[1];
                                 inst->src[1] = c->undef;
                                 progress = true;
-                                dump_to(inst);
+                                dump_to(c, inst);
                         } else if (is_zero(c, defs, inst->src[1])) {
                                 /* Replace references to a 0 uniform value
                                  * with the SEL_X_0 equivalent.
                                  */
-                                dump_from(inst);
+                                dump_from(c, inst);
                                 inst->op -= (QOP_SEL_X_Y_ZS - QOP_SEL_X_0_ZS);
                                 inst->src[1] = c->undef;
                                 progress = true;
-                                dump_to(inst);
+                                dump_to(c, inst);
                         }
                         break;
 
index 66b7c80a77db51580300d8e8065a2266e9e1932e..0cffb284e44eff5fd7d55f46d67e45d90a388b70 100644 (file)
@@ -63,7 +63,7 @@ qir_opt_copy_propagation(struct vc4_compile *c)
                               !reads_a_uniform))) {
                                 if (debug) {
                                         fprintf(stderr, "Copy propagate: ");
-                                        qir_dump_inst(inst);
+                                        qir_dump_inst(c, inst);
                                         fprintf(stderr, "\n");
                                 }
 
@@ -73,7 +73,7 @@ qir_opt_copy_propagation(struct vc4_compile *c)
 
                                 if (debug) {
                                         fprintf(stderr, "to: ");
-                                        qir_dump_inst(inst);
+                                        qir_dump_inst(c, inst);
                                         fprintf(stderr, "\n");
                                 }
 
index ef4818f09b89eb7edecae56b1f4ea66a8dbfc445..d3ef91083c61322d962d7dac33f182001a420c15 100644 (file)
@@ -62,7 +62,8 @@ inst_key_equals(const void *a, const void *b)
 }
 
 static struct qinst *
-vc4_find_cse(struct hash_table *ht, struct qinst *inst, uint32_t sf_count,
+vc4_find_cse(struct vc4_compile *c, struct hash_table *ht,
+             struct qinst *inst, uint32_t sf_count,
              uint32_t r4_count)
 {
         if (inst->dst.file != QFILE_TEMP ||
@@ -90,11 +91,11 @@ vc4_find_cse(struct hash_table *ht, struct qinst *inst, uint32_t sf_count,
                         fprintf(stderr, "CSE found match:\n");
 
                         fprintf(stderr, "  Original inst: ");
-                        qir_dump_inst(entry->data);
+                        qir_dump_inst(c, entry->data);
                         fprintf(stderr, "\n");
 
                         fprintf(stderr, "  Our inst:      ");
-                        qir_dump_inst(inst);
+                        qir_dump_inst(c, inst);
                         fprintf(stderr, "\n");
                 }
 
@@ -109,7 +110,7 @@ vc4_find_cse(struct hash_table *ht, struct qinst *inst, uint32_t sf_count,
 
         if (debug) {
                 fprintf(stderr, "Added to CSE HT: ");
-                qir_dump_inst(inst);
+                qir_dump_inst(c, inst);
                 fprintf(stderr, "\n");
         }
 
@@ -143,7 +144,7 @@ qir_opt_cse(struct vc4_compile *c)
                                 if (debug) {
                                         fprintf(stderr,
                                                 "Removing redundant SF: ");
-                                        qir_dump_inst(inst);
+                                        qir_dump_inst(c, inst);
                                         fprintf(stderr, "\n");
                                 }
                                 qir_remove_instruction(inst);
@@ -154,7 +155,7 @@ qir_opt_cse(struct vc4_compile *c)
                                 sf_count++;
                         }
                 } else {
-                        struct qinst *cse = vc4_find_cse(ht, inst,
+                        struct qinst *cse = vc4_find_cse(c, ht, inst,
                                                          sf_count, r4_count);
                         if (cse) {
                                 inst->src[0] = cse->dst;
@@ -166,7 +167,7 @@ qir_opt_cse(struct vc4_compile *c)
 
                                 if (debug) {
                                         fprintf(stderr, "  Turned into:   ");
-                                        qir_dump_inst(inst);
+                                        qir_dump_inst(c, inst);
                                         fprintf(stderr, "\n");
                                 }
                         }
index a675a1ac5abe7348759d38e016f47a66c03e70c4..9f7606fb52bda1e330dc9896b8345c451ad834b6 100644 (file)
@@ -51,7 +51,7 @@ qir_opt_dead_code(struct vc4_compile *c)
                     !qir_has_side_effects(inst)) {
                         if (debug) {
                                 fprintf(stderr, "Removing: ");
-                                qir_dump_inst(inst);
+                                qir_dump_inst(c, inst);
                                 fprintf(stderr, "\n");
                         }
                         qir_remove_instruction(inst);
index efba6d3c55e32c58b5d7bca3b0a7ded4a40d98a7..0975460ffec94d0e92f70099cf5c8e1233442cfe 100644 (file)
@@ -181,7 +181,7 @@ qir_reads_r4(struct qinst *inst)
 }
 
 static void
-qir_print_reg(struct qreg reg)
+qir_print_reg(struct vc4_compile *c, struct qreg reg)
 {
         const char *files[] = {
                 [QFILE_TEMP] = "t",
@@ -193,17 +193,24 @@ qir_print_reg(struct qreg reg)
                 fprintf(stderr, "null");
         else
                 fprintf(stderr, "%s%d", files[reg.file], reg.index);
+
+        if (reg.file == QFILE_UNIF &&
+            c->uniform_contents[reg.index] == QUNIFORM_CONSTANT) {
+                fprintf(stderr, " (0x%08x / %f)",
+                        c->uniform_data[reg.index],
+                        uif(c->uniform_data[reg.index]));
+        }
 }
 
 void
-qir_dump_inst(struct qinst *inst)
+qir_dump_inst(struct vc4_compile *c, struct qinst *inst)
 {
         fprintf(stderr, "%s ", qir_get_op_name(inst->op));
 
-        qir_print_reg(inst->dst);
+        qir_print_reg(c, inst->dst);
         for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
                 fprintf(stderr, ", ");
-                qir_print_reg(inst->src[i]);
+                qir_print_reg(c, inst->src[i]);
         }
 }
 
@@ -214,7 +221,7 @@ qir_dump(struct vc4_compile *c)
 
         foreach(node, &c->instructions) {
                 struct qinst *inst = (struct qinst *)node;
-                qir_dump_inst(inst);
+                qir_dump_inst(c, inst);
                 fprintf(stderr, "\n");
         }
 }
index 0d490ff9ef585b240d64161227734280b5a1e19f..f4b014233878e21adab7555e8d8bf5984d0b338b 100644 (file)
@@ -277,7 +277,7 @@ bool qir_writes_r4(struct qinst *inst);
 bool qir_reads_r4(struct qinst *inst);
 
 void qir_dump(struct vc4_compile *c);
-void qir_dump_inst(struct qinst *inst);
+void qir_dump_inst(struct vc4_compile *c, struct qinst *inst);
 const char *qir_get_stage_name(enum qstage stage);
 
 void qir_optimize(struct vc4_compile *c);