broadcom/compiler: make opt passes set current block
authorIago Toral Quiroga <itoral@igalia.com>
Tue, 2 Nov 2021 08:09:07 +0000 (09:09 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 2 Nov 2021 11:17:01 +0000 (11:17 +0000)
Typically, optimization passes go through all the blocks in a shader
and make adjustments on the fly, so we always want them to update
the current block or the current block pointer will become outdated.

Also, we don't need to keep track of the previous current block
pointer to restore it, since optimization passes run after we have
completed conversion to VIR, and therefore, anything that comes after
that should always set the current block before emitting code.

Fixes debug assert crashes when running shader-db:
vir.c:1888: try_opt_ldunif: Assertion `found || &c->cur_block->instructions == c->cursor.link' failed

Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13625>

src/broadcom/compiler/vir_opt_constant_alu.c
src/broadcom/compiler/vir_opt_copy_propagate.c
src/broadcom/compiler/vir_opt_dead_code.c
src/broadcom/compiler/vir_opt_redundant_flags.c

index 483646f..bde9c59 100644 (file)
@@ -155,6 +155,7 @@ vir_opt_constant_alu(struct v3d_compile *c)
 {
         bool progress = false;
         vir_for_each_block(block, c) {
+                c->cur_block = block;
                 vir_for_each_inst_safe(inst, block) {
                         progress = try_opt_constant_alu(c, inst) || progress;
                 }
index c5bb611..da121c2 100644 (file)
@@ -238,7 +238,9 @@ vir_opt_copy_propagate(struct v3d_compile *c)
                  */
                 memset(movs, 0, sizeof(struct qinst *) * c->num_temps);
 
+                c->cur_block = block;
                 vir_for_each_inst(inst, block) {
+
                         progress = try_copy_prop(c, inst, movs) || progress;
 
                         apply_kills(c, movs, inst);
index 64c762c..5101e62 100644 (file)
@@ -149,30 +149,25 @@ check_first_ldunifa(struct v3d_compile *c,
 }
 
 static bool
-increment_unifa_address(struct v3d_compile *c, struct qblock *block, struct qinst *unifa)
+increment_unifa_address(struct v3d_compile *c, struct qinst *unifa)
 {
-        struct qblock *current_block = c->cur_block;
         if (unifa->qpu.type == V3D_QPU_INSTR_TYPE_ALU &&
             unifa->qpu.alu.mul.op == V3D_QPU_M_MOV) {
                 c->cursor = vir_after_inst(unifa);
-                c->cur_block = block;
                 struct qreg unifa_reg = vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_UNIFA);
                 vir_ADD_dest(c, unifa_reg, unifa->src[0], vir_uniform_ui(c, 4u));
                 vir_remove_instruction(c, unifa);
-                c->cur_block = current_block;
                 return true;
         }
 
         if (unifa->qpu.type == V3D_QPU_INSTR_TYPE_ALU &&
             unifa->qpu.alu.add.op == V3D_QPU_A_ADD) {
                 c->cursor = vir_after_inst(unifa);
-                c->cur_block = block;
                 struct qreg unifa_reg = vir_reg(QFILE_MAGIC, V3D_QPU_WADDR_UNIFA);
                 struct qreg tmp =
                         vir_ADD(c, unifa->src[1], vir_uniform_ui(c, 4u));
                 vir_ADD_dest(c, unifa_reg, unifa->src[0], tmp);
                 vir_remove_instruction(c, unifa);
-                c->cur_block = current_block;
                 return true;
         }
 
@@ -200,7 +195,7 @@ vir_opt_dead_code(struct v3d_compile *c)
 
         vir_for_each_block(block, c) {
                 struct qinst *last_flags_write = NULL;
-
+                c->cur_block = block;
                 vir_for_each_inst_safe(inst, block) {
                         /* If this instruction reads the flags, we can't
                          * remove the flags generation for it.
@@ -276,7 +271,7 @@ vir_opt_dead_code(struct v3d_compile *c)
                          */
                         if (is_first_ldunifa) {
                                 assert(unifa);
-                                if (!increment_unifa_address(c, block, unifa))
+                                if (!increment_unifa_address(c, unifa))
                                         continue;
                         }
 
index 4609ef9..c7896d5 100644 (file)
@@ -99,6 +99,7 @@ vir_opt_redundant_flags_block(struct v3d_compile *c, struct qblock *block)
         struct qinst *last_flags = NULL;
         bool progress = false;
 
+        c->cur_block = block;
         vir_for_each_inst(inst, block) {
                 if (inst->qpu.type != V3D_QPU_INSTR_TYPE_ALU ||
                     inst->qpu.flags.auf != V3D_QPU_UF_NONE ||