mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 17:20:10 +01:00
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 <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17794>
This commit is contained in:
parent
d3acfd9be8
commit
98c69de80d
9 changed files with 41 additions and 82 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
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 (uses[v] && uses[v] != I)
|
||||
BITSET_SET(multiple, v);
|
||||
else
|
||||
uses[v] = I;
|
||||
}
|
||||
|
||||
if (!I->nr_dests)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue