From: Alyssa Rosenzweig Date: Tue, 26 Jul 2022 16:22:34 +0000 (-0400) Subject: pan/bi: Add and use bi_foreach_ssa_src macro X-Git-Tag: upstream/22.3.5~3621 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98c69de80d00a88009eac80dee7aee14a30aff3d;p=platform%2Fupstream%2Fmesa.git pan/bi: Add and use bi_foreach_ssa_src macro Frequently, we want to iterate over the SSA variables read by an instruction, while skipping over constants and uniforms. Add and use a macro for this pattern. A few redundant asserts are removed. Signed-off-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/panfrost/bifrost/bi_helper_invocations.c b/src/panfrost/bifrost/bi_helper_invocations.c index 82bb973..f5207d9 100644 --- a/src/panfrost/bifrost/bi_helper_invocations.c +++ b/src/panfrost/bifrost/bi_helper_invocations.c @@ -206,11 +206,9 @@ bi_helper_block_update(BITSET_WORD *deps, bi_block *block) continue; /* ...so are the sources */ - bi_foreach_src(I, s) { - if (bi_is_ssa(I->src[s])) { - progress |= !BITSET_TEST(deps, I->src[s].value); - BITSET_SET(deps, I->src[s].value); - } + bi_foreach_ssa_src(I, s) { + progress |= !BITSET_TEST(deps, I->src[s].value); + BITSET_SET(deps, I->src[s].value); } break; @@ -231,10 +229,8 @@ bi_analyze_helper_requirements(bi_context *ctx) bi_foreach_instr_global(ctx, I) { if (!bi_instr_uses_helpers(I)) continue; - bi_foreach_src(I, s) { - if (bi_is_ssa(I->src[s])) - BITSET_SET(deps, I->src[s].value); - } + bi_foreach_ssa_src(I, s) + BITSET_SET(deps, I->src[s].value); } /* Propagate that up */ @@ -263,10 +259,8 @@ bi_analyze_helper_requirements(bi_context *ctx) bool exec = false; - bi_foreach_dest(I, d) { - assert(bi_is_ssa(I->dest[d])); + bi_foreach_dest(I, d) exec |= BITSET_TEST(deps, I->dest[d].value); - } I->skip = !exec; } diff --git a/src/panfrost/bifrost/bi_liveness.c b/src/panfrost/bifrost/bi_liveness.c index f794dee..1dc759e 100644 --- a/src/panfrost/bifrost/bi_liveness.c +++ b/src/panfrost/bifrost/bi_liveness.c @@ -29,15 +29,11 @@ void bi_liveness_ins_update_ssa(BITSET_WORD *live, const bi_instr *I) { - bi_foreach_dest(I, d) { - assert(I->dest[d].type == BI_INDEX_NORMAL); + bi_foreach_dest(I, d) BITSET_CLEAR(live, I->dest[d].value); - } - bi_foreach_src(I, s) { - if (I->src[s].type == BI_INDEX_NORMAL) - BITSET_SET(live, I->src[s].value); - } + bi_foreach_ssa_src(I, s) + BITSET_SET(live, I->src[s].value); } void @@ -96,7 +92,6 @@ bi_compute_liveness_ssa(bi_context *ctx) bi_foreach_instr_in_block(blk, I) { if (I->op != BI_OPCODE_PHI) break; - assert(I->dest[0].type == BI_INDEX_NORMAL); BITSET_CLEAR(live, I->dest[0].value); } @@ -105,7 +100,7 @@ bi_compute_liveness_ssa(bi_context *ctx) if (I->op != BI_OPCODE_PHI) break; bi_index operand = I->src[bi_predecessor_index(blk, *pred)]; - if (operand.type == BI_INDEX_NORMAL) + if (bi_is_ssa(operand)) BITSET_SET(live, operand.value); } diff --git a/src/panfrost/bifrost/bi_opt_cse.c b/src/panfrost/bifrost/bi_opt_cse.c index 8d1d46f..9e822ef 100644 --- a/src/panfrost/bifrost/bi_opt_cse.c +++ b/src/panfrost/bifrost/bi_opt_cse.c @@ -154,13 +154,10 @@ bi_opt_cse(bi_context *ctx) bi_foreach_instr_in_block(block, instr) { /* Rewrite before trying to CSE anything so we converge * locally in one iteration */ - bi_foreach_src(instr, s) { + bi_foreach_ssa_src(instr, s) { if (bi_is_staging_src(instr, s)) continue; - if (!bi_is_ssa(instr->src[s])) - continue; - bi_index repl = replacement[instr->src[s].value]; if (!bi_is_null(repl)) instr->src[s] = bi_replace_index(instr->src[s], repl); diff --git a/src/panfrost/bifrost/bi_opt_dce.c b/src/panfrost/bifrost/bi_opt_dce.c index aa20f14..d9668f2 100644 --- a/src/panfrost/bifrost/bi_opt_dce.c +++ b/src/panfrost/bifrost/bi_opt_dce.c @@ -55,11 +55,9 @@ bi_opt_dead_code_eliminate(bi_context *ctx) if (!needed) continue; - bi_foreach_src(I, s) { - if (bi_is_ssa(I->src[s])) { - progress |= !BITSET_TEST(mark, I->src[s].value); - BITSET_SET(mark, I->src[s].value); - } + bi_foreach_ssa_src(I, s) { + progress |= !BITSET_TEST(mark, I->src[s].value); + BITSET_SET(mark, I->src[s].value); } } diff --git a/src/panfrost/bifrost/bi_opt_mod_props.c b/src/panfrost/bifrost/bi_opt_mod_props.c index 7e63a18..bdd6156 100644 --- a/src/panfrost/bifrost/bi_opt_mod_props.c +++ b/src/panfrost/bifrost/bi_opt_mod_props.c @@ -210,10 +210,7 @@ bi_opt_mod_prop_forward(bi_context *ctx) lut[I->dest[d].value] = I; } - bi_foreach_src(I, s) { - if (!bi_is_ssa(I->src[s])) - continue; - + bi_foreach_ssa_src(I, s) { bi_instr *mod = lut[I->src[s].value]; if (!mod) @@ -394,15 +391,13 @@ bi_opt_mod_prop_backward(bi_context *ctx) BITSET_WORD *multiple = calloc(BITSET_WORDS(count), sizeof(*multiple)); bi_foreach_instr_global_rev(ctx, I) { - bi_foreach_src(I, s) { - if (bi_is_ssa(I->src[s])) { - unsigned v = I->src[s].value; - - if (uses[v] && uses[v] != I) - BITSET_SET(multiple, v); - else - uses[v] = I; - } + bi_foreach_ssa_src(I, s) { + unsigned v = I->src[s].value; + + if (uses[v] && uses[v] != I) + BITSET_SET(multiple, v); + else + uses[v] = I; } if (!I->nr_dests) diff --git a/src/panfrost/bifrost/bi_pressure_schedule.c b/src/panfrost/bifrost/bi_pressure_schedule.c index 71f8ed6..a4748e8 100644 --- a/src/panfrost/bifrost/bi_pressure_schedule.c +++ b/src/panfrost/bifrost/bi_pressure_schedule.c @@ -79,18 +79,11 @@ create_dag(bi_context *ctx, bi_block *block, void *memctx) dag_init_node(dag, &node->dag); /* Reads depend on writes, no other hazards in SSA */ - bi_foreach_src(I, s) { - bi_index src = I->src[s]; - - if (bi_is_ssa(src)) - add_dep(node, last_write[src.value]); - } - - bi_foreach_dest(I, d) { - assert(bi_is_ssa(I->dest[d])); + bi_foreach_ssa_src(I, s) + add_dep(node, last_write[I->src[s].value]); + bi_foreach_dest(I, d) last_write[I->dest[d].value] = node; - } switch (bi_opcode_props[I->op].message) { case BIFROST_MESSAGE_LOAD: @@ -194,16 +187,11 @@ calculate_pressure_delta(bi_instr *I, BITSET_WORD *live) /* Destinations must be unique */ bi_foreach_dest(I, d) { - assert(I->dest[d].type == BI_INDEX_NORMAL); - if (BITSET_TEST(live, I->dest[d].value)) delta -= bi_count_write_registers(I, d); } - bi_foreach_src(I, src) { - if (I->src[src].type != BI_INDEX_NORMAL) - continue; - + bi_foreach_ssa_src(I, src) { /* Filter duplicates */ bool dupe = false; diff --git a/src/panfrost/bifrost/bi_ra.c b/src/panfrost/bifrost/bi_ra.c index 0ec6b59..8e4c1ad 100644 --- a/src/panfrost/bifrost/bi_ra.c +++ b/src/panfrost/bifrost/bi_ra.c @@ -219,13 +219,11 @@ bi_liveness_ins_update_ra(uint8_t *live, bi_instr *ins) live[ins->dest[d].value] &= ~bi_writemask(ins, d); } - bi_foreach_src(ins, src) { + bi_foreach_ssa_src(ins, src) { unsigned count = bi_count_read_registers(ins, src); unsigned rmask = BITFIELD_MASK(count); - uint8_t mask = (rmask << ins->src[src].offset); - if (bi_is_ssa(ins->src[src])) - live[ins->src[src].value] |= mask; + live[ins->src[src].value] |= (rmask << ins->src[src].offset); } } @@ -397,11 +395,9 @@ bi_mark_interference(bi_block *block, struct lcra_state *l, uint8_t *live, uint6 /* Valhall needs >= 64-bit reads to be pair-aligned */ if (aligned_sr) { - bi_foreach_src(ins, s) { - if (bi_count_read_registers(ins, s) >= 2) { - if (bi_is_ssa(ins->src[s])) - l->affinity[ins->src[s].value] &= EVEN_BITS_MASK; - } + bi_foreach_ssa_src(ins, s) { + if (bi_count_read_registers(ins, s) >= 2) + l->affinity[ins->src[s].value] &= EVEN_BITS_MASK; } } @@ -815,8 +811,8 @@ bi_lower_vector(bi_context *ctx, unsigned first_reg) } bi_foreach_instr_global(ctx, I) { - bi_foreach_src(I, s) { - if (bi_is_ssa(I->src[s]) && I->src[s].value < first_reg && !bi_is_null(remap[I->src[s].value])) + bi_foreach_ssa_src(I, s) { + if (I->src[s].value < first_reg && !bi_is_null(remap[I->src[s].value])) I->src[s] = bi_replace_index(I->src[s], remap[I->src[s].value]); } } @@ -922,14 +918,11 @@ squeeze_index(bi_context *ctx) ctx->ssa_alloc = 0; bi_foreach_instr_global(ctx, I) { - bi_foreach_dest(I, d) { + bi_foreach_dest(I, d) I->dest[d].value = find_or_allocate_temp(map, I->dest[d].value, &ctx->ssa_alloc); - } - bi_foreach_src(I, s) { - if (I->src[s].type == BI_INDEX_NORMAL) - I->src[s].value = find_or_allocate_temp(map, I->src[s].value, &ctx->ssa_alloc); - } + bi_foreach_ssa_src(I, s) + I->src[s].value = find_or_allocate_temp(map, I->src[s].value, &ctx->ssa_alloc); } ralloc_free(map); @@ -1009,10 +1002,7 @@ bi_out_of_ssa(bi_context *ctx) BITSET_WORD *multiple_uses = calloc(sizeof(BITSET_WORD), BITSET_WORDS(ctx->ssa_alloc)); bi_foreach_instr_global(ctx, I) { - bi_foreach_src(I, s) { - if (!bi_is_ssa(I->src[s])) - continue; - + bi_foreach_ssa_src(I, s) { if (BITSET_TEST(used, I->src[s].value)) BITSET_SET(multiple_uses, I->src[s].value); else diff --git a/src/panfrost/bifrost/bi_validate.c b/src/panfrost/bifrost/bi_validate.c index 7d10ff1..0cab982 100644 --- a/src/panfrost/bifrost/bi_validate.c +++ b/src/panfrost/bifrost/bi_validate.c @@ -126,9 +126,7 @@ bi_validate_width(bi_context *ctx) } bi_foreach_instr_global(ctx, I) { - bi_foreach_src(I, s) { - if (!bi_is_ssa(I->src[s])) continue; - + bi_foreach_ssa_src(I, s) { unsigned v = I->src[s].value; unsigned n = bi_count_read_registers(I, s); diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 316093f..64b777f 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -1026,6 +1026,10 @@ bi_dest_index(nir_dest *dst) #define bi_foreach_dest(ins, v) \ for (unsigned v = 0; v < ins->nr_dests; ++v) +#define bi_foreach_ssa_src(ins, v) \ + for (unsigned v = 0; v < ins->nr_srcs; ++v) \ + if (ins->src[v].type == BI_INDEX_NORMAL) + #define bi_foreach_instr_and_src_in_tuple(tuple, ins, s) \ bi_foreach_instr_in_tuple(tuple, ins) \ bi_foreach_src(ins, s)