freedreno/ir3: add input/output iterators
authorRob Clark <robdclark@chromium.org>
Thu, 24 Oct 2019 19:05:56 +0000 (12:05 -0700)
committerRob Clark <robdclark@chromium.org>
Tue, 12 Nov 2019 21:55:03 +0000 (13:55 -0800)
We can at least get rid of the if-not-NULL check in a bunch of places.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/freedreno/ir3/ir3.h
src/freedreno/ir3/ir3_a6xx.c
src/freedreno/ir3/ir3_compiler_nir.c
src/freedreno/ir3/ir3_cp.c
src/freedreno/ir3/ir3_depth.c
src/freedreno/ir3/ir3_group.c
src/freedreno/ir3/ir3_print.c
src/freedreno/ir3/ir3_ra.c
src/freedreno/ir3/ir3_sched.c
src/freedreno/ir3/ir3_shader.c
src/freedreno/ir3/ir3_sun.c

index 22802aecf18b80a8a78ea26fa843fdf28dd11109..3e4fa34aa0f6c14e19bce139f11d70cbc13100a8 100644 (file)
@@ -1063,6 +1063,19 @@ static inline bool __is_false_dep(struct ir3_instruction *instr, unsigned n)
 #define foreach_ssa_src(__srcinst, __instr) \
        foreach_ssa_src_n(__srcinst, __i, __instr)
 
+/* iterators for shader inputs: */
+#define foreach_input_n(__ininstr, __cnt, __ir) \
+       for (unsigned __cnt = 0; __cnt < (__ir)->ninputs; __cnt++) \
+               if ((__ininstr = (__ir)->inputs[__cnt]))
+#define foreach_input(__ininstr, __ir) \
+       foreach_input_n(__ininstr, __i, __ir)
+
+/* iterators for shader outputs: */
+#define foreach_output_n(__outinstr, __cnt, __ir) \
+       for (unsigned __cnt = 0; __cnt < (__ir)->noutputs; __cnt++) \
+               if ((__outinstr = (__ir)->outputs[__cnt]))
+#define foreach_output(__outinstr, __ir) \
+       foreach_output_n(__outinstr, __i, __ir)
 
 /* dump: */
 void ir3_print(struct ir3 *ir);
index 4b2ecc0082765b7290d1e782ffcc3e13263a0a24..457b20d00716d84861a53aa6707fc4b46d3c7b20 100644 (file)
@@ -408,12 +408,10 @@ ir3_a6xx_fixup_atomic_dests(struct ir3 *ir, struct ir3_shader_variant *so)
                }
 
                /* we also need to fixup shader outputs: */
-               for (unsigned i = 0; i < ir->noutputs; i++) {
-                       if (!ir->outputs[i])
-                               continue;
-                       if (is_atomic(ir->outputs[i]->opc) && (ir->outputs[i]->flags & IR3_INSTR_G))
-                               ir->outputs[i] = get_atomic_dest_mov(ir->outputs[i]);
-               }
+               struct ir3_instruction *out;
+               foreach_output_n(out, n, ir)
+                       if (is_atomic(out->opc) && (out->flags & IR3_INSTR_G))
+                               ir->outputs[n] = get_atomic_dest_mov(out);
        }
 
 }
index daa073eb266ae1605e0a5a1485ec45964bfddb18..13566dd37732443634f686100335437cb2a54c00 100644 (file)
@@ -3425,15 +3425,10 @@ ir3_compile_shader_nir(struct ir3_compiler *compiler,
                ret = ir3_ra(so, precolor, ARRAY_SIZE(precolor));
        } else if (so->num_sampler_prefetch) {
                assert(so->type == MESA_SHADER_FRAGMENT);
-               struct ir3_instruction *precolor[2];
+               struct ir3_instruction *instr, *precolor[2];
                int idx = 0;
 
-               for (unsigned i = 0; i < ir->ninputs; i++) {
-                       struct ir3_instruction *instr = ctx->ir->inputs[i];
-
-                       if (!instr)
-                               continue;
-
+               foreach_input(instr, ir) {
                        if (instr->input.sysval != SYSTEM_VALUE_BARYCENTRIC_PIXEL)
                                continue;
 
index d07418419cd41f54488d50cb7b33cf0cfc74b552..f8298d6075273a8c1d596ec6a4d114841a010345 100644 (file)
@@ -759,11 +759,10 @@ ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so)
 
        ir3_clear_mark(ir);
 
-       for (unsigned i = 0; i < ir->noutputs; i++) {
-               if (ir->outputs[i]) {
-                       instr_cp(&ctx, ir->outputs[i]);
-                       ir->outputs[i] = eliminate_output_mov(ir->outputs[i]);
-               }
+       struct ir3_instruction *out;
+       foreach_output_n(out, n, ir) {
+               instr_cp(&ctx, out);
+               ir->outputs[n] = eliminate_output_mov(out);
        }
 
        list_for_each_entry (struct ir3_block, block, &ir->block_list, node) {
index 601ab427fb13411568e13132170cc0a7e89a60e9..bdd00693104507a8f3e5bc74f5a726a47b1b99fe 100644 (file)
@@ -233,9 +233,9 @@ compute_depth_and_remove_unused(struct ir3 *ir, struct ir3_shader_variant *so)
                }
        }
 
-       for (i = 0; i < ir->noutputs; i++)
-               if (ir->outputs[i])
-                       ir3_instr_depth(ir->outputs[i], 0, false);
+       struct ir3_instruction *out;
+       foreach_output(out, ir)
+               ir3_instr_depth(out, 0, false);
 
        list_for_each_entry (struct ir3_block, block, &ir->block_list, node) {
                for (i = 0; i < block->keeps_count; i++)
@@ -261,11 +261,10 @@ compute_depth_and_remove_unused(struct ir3 *ir, struct ir3_shader_variant *so)
        }
 
        /* cleanup unused inputs: */
-       for (i = 0; i < ir->ninputs; i++) {
-               struct ir3_instruction *in = ir->inputs[i];
-               if (in && (in->flags & IR3_INSTR_UNUSED))
-                       ir->inputs[i] = NULL;
-       }
+       struct ir3_instruction *in;
+       foreach_input_n(in, n, ir)
+               if (in->flags & IR3_INSTR_UNUSED)
+                       ir->inputs[n] = NULL;
 
        return progress;
 }
index e9eb1e58d471ef59a8ff1d633ec9b9ea2116420c..a0b853ca1590e1738cee24665c1e1b4969270806 100644 (file)
@@ -247,12 +247,9 @@ find_neighbors(struct ir3 *ir)
        for (i = 0; i < ir->noutputs; i += 4)
                group_n(&arr_ops_out, &ir->outputs[i], 4);
 
-       for (i = 0; i < ir->noutputs; i++) {
-               if (ir->outputs[i]) {
-                       struct ir3_instruction *instr = ir->outputs[i];
-                       instr_find_neighbors(instr);
-               }
-       }
+       struct ir3_instruction *out;
+       foreach_output(out, ir)
+               instr_find_neighbors(out);
 
        list_for_each_entry (struct ir3_block, block, &ir->block_list, node) {
                for (i = 0; i < block->keeps_count; i++) {
index a4830ed0a17db47529594d07c6d13eb726be0646..f760f57e1a8a8f96cc01d38770849ccf2c16f6d6 100644 (file)
@@ -321,10 +321,9 @@ ir3_print(struct ir3 *ir)
        list_for_each_entry (struct ir3_block, block, &ir->block_list, node)
                print_block(block, 0);
 
-       for (unsigned i = 0; i < ir->noutputs; i++) {
-               if (!ir->outputs[i])
-                       continue;
+       struct ir3_instruction *out;
+       foreach_output_n(out, i, ir) {
                printf("out%d: ", i);
-               print_instr(ir->outputs[i], 0);
+               print_instr(out, 0);
        }
 }
index c3f04ff5aeb729c064a4de679023a2188e63a56c..1f24b5eadacf7aa4574b76766f526141557ffba2 100644 (file)
@@ -944,11 +944,9 @@ ra_add_interference(struct ir3_ra_ctx *ctx)
        }
 
        /* need to fix things up to keep outputs live: */
-       for (unsigned i = 0; i < ir->noutputs; i++) {
-               struct ir3_instruction *instr = ir->outputs[i];
-               if (!instr)
-                       continue;
-               unsigned name = ra_name(ctx, &ctx->instrd[instr->ip]);
+       struct ir3_instruction *out;
+       foreach_output(out, ir) {
+               unsigned name = ra_name(ctx, &ctx->instrd[out->ip]);
                ctx->use[name] = ctx->instr_cnt;
        }
 
index f5b9d3bd6f520873fa5dadafbb2745eeae229159..a70251374ee2f92c9c2a618f3512c864d2cfa50a 100644 (file)
@@ -170,14 +170,9 @@ update_use_count(struct ir3 *ir)
 
        /* Shader outputs are also used:
         */
-       for (unsigned i = 0; i <  ir->noutputs; i++) {
-               struct ir3_instruction  *out = ir->outputs[i];
-
-               if (!out)
-                       continue;
-
+       struct ir3_instruction *out;
+       foreach_output(out, ir)
                use_instr(out);
-       }
 }
 
 #define NULL_INSTR ((void *)~0)
index 05c8567ab99eeb568c05c4dc31cb1d7bc024265a..2f5777c4ec86982f76f21170259bf8d586d6c927 100644 (file)
@@ -380,12 +380,9 @@ ir3_shader_disasm(struct ir3_shader_variant *so, uint32_t *bin, FILE *out)
        uint8_t regid;
        unsigned i;
 
-       for (i = 0; i < ir->ninputs; i++) {
-               if (!ir->inputs[i]) {
-                       fprintf(out, "; in%d unused\n", i);
-                       continue;
-               }
-               reg = ir->inputs[i]->regs[0];
+       struct ir3_instruction *instr;
+       foreach_input_n(instr, i, ir) {
+               reg = instr->regs[0];
                regid = reg->num;
                fprintf(out, "@in(%sr%d.%c)\tin%d\n",
                                (reg->flags & IR3_REG_HALF) ? "h" : "",
@@ -402,12 +399,8 @@ ir3_shader_disasm(struct ir3_shader_variant *so, uint32_t *bin, FILE *out)
                                fetch->wrmask, fetch->cmd);
        }
 
-       for (i = 0; i < ir->noutputs; i++) {
-               if (!ir->outputs[i]) {
-                       fprintf(out, "; out%d unused\n", i);
-                       continue;
-               }
-               reg = ir->outputs[i]->regs[0];
+       foreach_output_n(instr, i, ir) {
+               reg = instr->regs[0];
                regid = reg->num;
                fprintf(out, "@out(%sr%d.%c)\tout%d\n",
                                (reg->flags & IR3_REG_HALF) ? "h" : "",
index 413eaabef88e80d90fe0035fbf6ecc29f61466de..c31e03129f0a4a56c0969e6522184b412c277909 100644 (file)
@@ -96,9 +96,9 @@ ir3_sun(struct ir3 *ir)
 
        ir3_clear_mark(ir);
 
-       for (unsigned i = 0; i < ir->noutputs; i++)
-               if (ir->outputs[i])
-                       max = MAX2(max, number_instr(ir->outputs[i]));
+       struct ir3_instruction *out;
+       foreach_output(out, ir)
+               max = MAX2(max, number_instr(out));
 
        list_for_each_entry (struct ir3_block, block, &ir->block_list, node) {
                for (unsigned i = 0; i < block->keeps_count; i++)