aboutsummaryrefslogtreecommitdiffstats
path: root/src/freedreno/ir3
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2019-10-24 12:05:56 -0700
committerRob Clark <[email protected]>2019-11-12 13:55:03 -0800
commitc00a67171c99a885ffa46aff31f9cfa165947d78 (patch)
treedeaa4804159bbc21bd7594c3a870354e2b4e2cbb /src/freedreno/ir3
parentb2417801e5d82cfac640086307599e81d5ae93e8 (diff)
freedreno/ir3: add input/output iterators
We can at least get rid of the if-not-NULL check in a bunch of places. Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Kristian H. Kristensen <[email protected]> Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/freedreno/ir3')
-rw-r--r--src/freedreno/ir3/ir3.h13
-rw-r--r--src/freedreno/ir3/ir3_a6xx.c10
-rw-r--r--src/freedreno/ir3/ir3_compiler_nir.c9
-rw-r--r--src/freedreno/ir3/ir3_cp.c9
-rw-r--r--src/freedreno/ir3/ir3_depth.c15
-rw-r--r--src/freedreno/ir3/ir3_group.c9
-rw-r--r--src/freedreno/ir3/ir3_print.c7
-rw-r--r--src/freedreno/ir3/ir3_ra.c8
-rw-r--r--src/freedreno/ir3/ir3_sched.c9
-rw-r--r--src/freedreno/ir3/ir3_shader.c17
-rw-r--r--src/freedreno/ir3/ir3_sun.c6
11 files changed, 49 insertions, 63 deletions
diff --git a/src/freedreno/ir3/ir3.h b/src/freedreno/ir3/ir3.h
index 22802aecf18..3e4fa34aa0f 100644
--- a/src/freedreno/ir3/ir3.h
+++ b/src/freedreno/ir3/ir3.h
@@ -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);
diff --git a/src/freedreno/ir3/ir3_a6xx.c b/src/freedreno/ir3/ir3_a6xx.c
index 4b2ecc00827..457b20d0071 100644
--- a/src/freedreno/ir3/ir3_a6xx.c
+++ b/src/freedreno/ir3/ir3_a6xx.c
@@ -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);
}
}
diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c
index daa073eb266..13566dd3773 100644
--- a/src/freedreno/ir3/ir3_compiler_nir.c
+++ b/src/freedreno/ir3/ir3_compiler_nir.c
@@ -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;
diff --git a/src/freedreno/ir3/ir3_cp.c b/src/freedreno/ir3/ir3_cp.c
index d07418419cd..f8298d60752 100644
--- a/src/freedreno/ir3/ir3_cp.c
+++ b/src/freedreno/ir3/ir3_cp.c
@@ -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) {
diff --git a/src/freedreno/ir3/ir3_depth.c b/src/freedreno/ir3/ir3_depth.c
index 601ab427fb1..bdd00693104 100644
--- a/src/freedreno/ir3/ir3_depth.c
+++ b/src/freedreno/ir3/ir3_depth.c
@@ -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;
}
diff --git a/src/freedreno/ir3/ir3_group.c b/src/freedreno/ir3/ir3_group.c
index e9eb1e58d47..a0b853ca159 100644
--- a/src/freedreno/ir3/ir3_group.c
+++ b/src/freedreno/ir3/ir3_group.c
@@ -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++) {
diff --git a/src/freedreno/ir3/ir3_print.c b/src/freedreno/ir3/ir3_print.c
index a4830ed0a17..f760f57e1a8 100644
--- a/src/freedreno/ir3/ir3_print.c
+++ b/src/freedreno/ir3/ir3_print.c
@@ -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);
}
}
diff --git a/src/freedreno/ir3/ir3_ra.c b/src/freedreno/ir3/ir3_ra.c
index c3f04ff5aeb..1f24b5eadac 100644
--- a/src/freedreno/ir3/ir3_ra.c
+++ b/src/freedreno/ir3/ir3_ra.c
@@ -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;
}
diff --git a/src/freedreno/ir3/ir3_sched.c b/src/freedreno/ir3/ir3_sched.c
index f5b9d3bd6f5..a70251374ee 100644
--- a/src/freedreno/ir3/ir3_sched.c
+++ b/src/freedreno/ir3/ir3_sched.c
@@ -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)
diff --git a/src/freedreno/ir3/ir3_shader.c b/src/freedreno/ir3/ir3_shader.c
index 05c8567ab99..2f5777c4ec8 100644
--- a/src/freedreno/ir3/ir3_shader.c
+++ b/src/freedreno/ir3/ir3_shader.c
@@ -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" : "",
diff --git a/src/freedreno/ir3/ir3_sun.c b/src/freedreno/ir3/ir3_sun.c
index 413eaabef88..c31e03129f0 100644
--- a/src/freedreno/ir3/ir3_sun.c
+++ b/src/freedreno/ir3/ir3_sun.c
@@ -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++)