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>
#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);
}
/* 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);
}
}
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;
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) {
}
}
- 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++)
}
/* 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;
}
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++) {
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);
}
}
}
/* 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;
}
/* 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)
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" : "",
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" : "",
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++)