Mesa (main): broadcom/compiler: make opt passes set current block

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Nov 2 11:45:08 UTC 2021


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

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Tue Nov  2 09:09:07 2021 +0100

broadcom/compiler: make opt passes set current block

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 at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13625>

---

 src/broadcom/compiler/vir_opt_constant_alu.c    |  1 +
 src/broadcom/compiler/vir_opt_copy_propagate.c  |  2 ++
 src/broadcom/compiler/vir_opt_dead_code.c       | 11 +++--------
 src/broadcom/compiler/vir_opt_redundant_flags.c |  1 +
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/broadcom/compiler/vir_opt_constant_alu.c b/src/broadcom/compiler/vir_opt_constant_alu.c
index 483646f882e..bde9c596484 100644
--- a/src/broadcom/compiler/vir_opt_constant_alu.c
+++ b/src/broadcom/compiler/vir_opt_constant_alu.c
@@ -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;
                 }
diff --git a/src/broadcom/compiler/vir_opt_copy_propagate.c b/src/broadcom/compiler/vir_opt_copy_propagate.c
index c5bb6112173..da121c2a5bd 100644
--- a/src/broadcom/compiler/vir_opt_copy_propagate.c
+++ b/src/broadcom/compiler/vir_opt_copy_propagate.c
@@ -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);
diff --git a/src/broadcom/compiler/vir_opt_dead_code.c b/src/broadcom/compiler/vir_opt_dead_code.c
index 64c762c88db..5101e62254a 100644
--- a/src/broadcom/compiler/vir_opt_dead_code.c
+++ b/src/broadcom/compiler/vir_opt_dead_code.c
@@ -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;
                         }
 
diff --git a/src/broadcom/compiler/vir_opt_redundant_flags.c b/src/broadcom/compiler/vir_opt_redundant_flags.c
index 4609ef9c361..c7896d57f2b 100644
--- a/src/broadcom/compiler/vir_opt_redundant_flags.c
+++ b/src/broadcom/compiler/vir_opt_redundant_flags.c
@@ -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 ||



More information about the mesa-commit mailing list