freedreno/ir3/cp: report progress
authorRob Clark <robdclark@chromium.org>
Thu, 14 May 2020 18:52:02 +0000 (11:52 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 19 May 2020 16:06:17 +0000 (16:06 +0000)
Later when we do this pass iteratively, we can drop some of the internal
iteration and just rely on this pass getting run until there is no more
progress.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5048>

src/freedreno/ir3/ir3.h
src/freedreno/ir3/ir3_cp.c

index 78fc96faea3ba7b155f832a6447d7e96c6b75264..70ead4e6cc8c09360e6538c1de760ac695d421bc 100644 (file)
@@ -1198,7 +1198,7 @@ bool ir3_dce(struct ir3 *ir, struct ir3_shader_variant *so);
 bool ir3_cf(struct ir3 *ir);
 
 /* copy-propagate: */
-void ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so);
+bool ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so);
 
 /* group neighbors and insert mov's to resolve conflicts: */
 void ir3_group(struct ir3 *ir);
index cb5f88630b1bcef3f68d3fd608a92db7b97295cb..f3116b8b4c7943f68892bac8fef95c8591e203a4 100644 (file)
@@ -42,6 +42,7 @@
 struct ir3_cp_ctx {
        struct ir3 *shader;
        struct ir3_shader_variant *so;
+       bool progress;
 };
 
 /* is it a type preserving mov, with ok flags?
@@ -617,13 +618,14 @@ reg_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr,
  * be eliminated)
  */
 static struct ir3_instruction *
-eliminate_output_mov(struct ir3_instruction *instr)
+eliminate_output_mov(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr)
 {
        if (is_eligible_mov(instr, NULL, false)) {
                struct ir3_register *reg = instr->regs[1];
                if (!(reg->flags & IR3_REG_ARRAY)) {
                        struct ir3_instruction *src_instr = ssa(reg);
                        debug_assert(src_instr);
+                       ctx->progress = true;
                        return src_instr;
                }
        }
@@ -668,6 +670,7 @@ instr_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr)
                                continue;
 
                        progress |= reg_cp(ctx, instr, reg, n);
+                       ctx->progress |= progress;
                }
        } while (progress);
 
@@ -679,7 +682,7 @@ instr_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr)
 
        if (instr->address) {
                instr_cp(ctx, instr->address);
-               ir3_instr_set_address(instr, eliminate_output_mov(instr->address));
+               ir3_instr_set_address(instr, eliminate_output_mov(ctx, instr->address));
        }
 
        /* we can end up with extra cmps.s from frontend, which uses a
@@ -710,6 +713,7 @@ instr_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr)
                        instr->barrier_class |= cond->barrier_class;
                        instr->barrier_conflict |= cond->barrier_conflict;
                        unuse(cond);
+                       ctx->progress = true;
                        break;
                default:
                        break;
@@ -748,11 +752,13 @@ instr_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr)
                        for (unsigned i = 1; i < instr->regs_count; i++) {
                                instr->regs[i] = instr->regs[i + 1];
                        }
+
+                       ctx->progress = true;
                }
        }
 }
 
-void
+bool
 ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so)
 {
        struct ir3_cp_ctx ctx = {
@@ -786,18 +792,20 @@ ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so)
        struct ir3_instruction *out;
        foreach_output_n (out, n, ir) {
                instr_cp(&ctx, out);
-               ir->outputs[n] = eliminate_output_mov(out);
+               ir->outputs[n] = eliminate_output_mov(&ctx, out);
        }
 
        foreach_block (block, &ir->block_list) {
                if (block->condition) {
                        instr_cp(&ctx, block->condition);
-                       block->condition = eliminate_output_mov(block->condition);
+                       block->condition = eliminate_output_mov(&ctx, block->condition);
                }
 
                for (unsigned i = 0; i < block->keeps_count; i++) {
                        instr_cp(&ctx, block->keeps[i]);
-                       block->keeps[i] = eliminate_output_mov(block->keeps[i]);
+                       block->keeps[i] = eliminate_output_mov(&ctx, block->keeps[i]);
                }
        }
+
+       return ctx.progress;
 }