- foreach_sched_node
- foreach_src
- foreach_src_n
+ - foreach_dst
+ - foreach_dst_n
- foreach_ssa_use
- foreach_ssa_srcp_n
- foreach_ssa_srcp
struct ir3_instruction *new_instr = instr_create(instr->block, instr->opc,
instr->dsts_count, instr->srcs_count);
struct ir3_register **dsts, **srcs;
- unsigned i;
dsts = new_instr->dsts;
srcs = new_instr->srcs;
/* clone registers: */
new_instr->dsts_count = 0;
new_instr->srcs_count = 0;
- for (i = 0; i < instr->dsts_count; i++) {
- struct ir3_register *reg = instr->dsts[i];
+ foreach_dst (reg, instr) {
struct ir3_register *new_reg = ir3_dst_create(new_instr, reg->num, reg->flags);
*new_reg = *reg;
if (new_reg->instr)
new_reg->instr = new_instr;
}
- for (i = 0; i < instr->srcs_count; i++) {
- struct ir3_register *reg = instr->srcs[i];
+ foreach_src (reg, instr) {
struct ir3_register *new_reg = ir3_src_create(new_instr, reg->num, reg->flags);
*new_reg = *reg;
}
#define foreach_src(__srcreg, __instr) \
foreach_src_n(__srcreg, __i, __instr)
+/* iterator for an instructions's destinations (reg), also returns dst #: */
+#define foreach_dst_n(__dstreg, __n, __instr) \
+ if ((__instr)->dsts_count) \
+ for (struct ir3_register *__dstreg = (void *)~0; __dstreg; __dstreg = NULL) \
+ for (unsigned __cnt = (__instr)->dsts_count, __n = 0; __n < __cnt; __n++) \
+ if ((__dstreg = (__instr)->dsts[__n]))
+
+/* iterator for an instructions's destinations (reg): */
+#define foreach_dst(__dstreg, __instr) \
+ foreach_dst_n(__dstreg, __i, __instr)
+
static inline unsigned __ssa_src_cnt(struct ir3_instruction *instr)
{
return instr->srcs_count + instr->deps_count;
foreach_block (block, &ir->block_list) {
foreach_instr (instr, &block->instr_list) {
- for (unsigned i = 0; i < instr->dsts_count; i++) {
- if (instr->dsts[i]->flags & IR3_REG_ARRAY) {
+ foreach_dst (dst, instr) {
+ if (dst->flags & IR3_REG_ARRAY) {
struct array_state *state =
- get_state(&ctx, block, instr->dsts[i]->array.id);
- state->live_out_definition = instr->dsts[i];
+ get_state(&ctx, block, dst->array.id);
+ state->live_out_definition = dst;
}
}
}
if (instr->opc == OPC_META_PHI)
continue;
- for (unsigned i = 0; i < instr->dsts_count; i++) {
- struct ir3_register *reg = instr->dsts[i];
+ foreach_dst (reg, instr) {
if ((reg->flags & IR3_REG_ARRAY) && !reg->tied) {
struct ir3_array *arr = ir3_lookup_array(ir, reg->array.id);
read_value_beginning(&ctx, block, arr);
}
}
- for (unsigned i = 0; i < instr->srcs_count; i++) {
- struct ir3_register *reg = instr->srcs[i];
+ foreach_src (reg, instr) {
if ((reg->flags & IR3_REG_ARRAY) && !reg->def) {
struct ir3_array *arr = ir3_lookup_array(ir, reg->array.id);
instr->srcs[i] = lookup_value(instr->srcs[i]);
}
} else {
- for (unsigned i = 0; i < instr->dsts_count; i++) {
- struct ir3_register *reg = instr->dsts[i];
+ foreach_dst (reg, instr) {
if ((reg->flags & IR3_REG_ARRAY)) {
if (!reg->tied) {
struct ir3_register *def =
reg->flags |= IR3_REG_SSA;
}
}
- for (unsigned i = 0; i < instr->srcs_count; i++) {
- struct ir3_register *reg = instr->srcs[i];
+ foreach_src (reg, instr) {
if ((reg->flags & IR3_REG_ARRAY)) {
/* It is assumed that before calling
* ir3_array_to_ssa(), reg->def was set to the
if (!is_flow(instr) || instr->opc == OPC_END || instr->opc == OPC_CHMASK) {
bool first = true;
- for (unsigned i = 0; i < instr->dsts_count; i++) {
- struct ir3_register *reg = instr->dsts[i];
+ foreach_dst (reg, instr) {
if (dest_regs(instr) == 0)
continue;
if (!first)
print_reg_name(stream, instr, reg, true);
first = false;
}
- for (unsigned i = 0; i < instr->srcs_count; i++) {
- struct ir3_register *reg = instr->srcs[i];
+ foreach_src (reg, instr) {
if (!first)
mesa_log_stream_printf(stream, ", ");
print_reg_name(stream, instr, reg, false);
* src or dst, ir3_cp should enforce this.
*/
- for (unsigned i = 0; i < instr->dsts_count; i++)
- if (instr->dsts[i]->flags & IR3_REG_ARRAY)
- return instr->dsts[i]->array.id;
- for (unsigned i = 0; i < instr->srcs_count; i++)
- if (instr->srcs[i]->flags & IR3_REG_ARRAY)
- return instr->srcs[i]->array.id;
+ foreach_dst (dst, instr)
+ if (dst->flags & IR3_REG_ARRAY)
+ return dst->array.id;
+ foreach_src (src, instr)
+ if (src->flags & IR3_REG_ARRAY)
+ return src->array.id;
unreachable("this was unexpected");
}
if (reg->tied) {
validate_assert(ctx, reg->tied->tied == reg);
bool found = false;
- for (unsigned i = 0; i < instr->dsts_count; i++) {
- if (instr->dsts[i] == reg->tied) {
+ foreach_dst (dst, instr) {
+ if (dst == reg->tied) {
found = true;
break;
}
validate_assert(ctx, reg->tied->size == reg->size);
}
bool found = false;
- for (unsigned i = 0; i < instr->srcs_count; i++) {
- if (instr->srcs[i] == reg->tied) {
+ foreach_src (src, instr) {
+ if (src == reg->tied) {
found = true;
break;
}