pan: Use bitset instead of bool array in bi_find_loop_blocks
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38393>
This commit is contained in:
Christoph Pillmayer 2025-11-11 15:16:48 +00:00 committed by Marge Bot
parent 6535a3b6b3
commit 617f0562bb
4 changed files with 32 additions and 21 deletions

View file

@ -1149,25 +1149,26 @@ op_is_load_store(enum bi_opcode op)
static uint64_t
compute_spill_cost(bi_context *ctx)
{
void *mctx = ralloc_context(NULL);
/* Required for finding blocks belonging to loops. */
bi_calc_dominance(ctx);
/* The cost of a spill/fill is just 10*block_depth for now. */
uint32_t *block_depth = calloc(ctx->num_blocks, sizeof(uint32_t));
uint32_t *block_depth = rzalloc_array(mctx, uint32_t, ctx->num_blocks);
BITSET_WORD *loop_block = BITSET_RZALLOC(mctx, ctx->num_blocks);
bi_foreach_block(ctx, block) {
if (!block->loop_header)
continue;
bool *loop_block = bi_find_loop_blocks(ctx, block);
bi_find_loop_blocks(ctx, block, loop_block);
for (uint32_t b = 0; b < ctx->num_blocks; ++b) {
if (loop_block[b])
if (BITSET_SET(loop_block, b))
block_depth[b] += 1;
}
free(loop_block);
}
uint64_t cost = 0;
@ -1178,7 +1179,7 @@ compute_spill_cost(bi_context *ctx)
}
}
free(block_depth);
ralloc_free(mctx);
return cost;
}

View file

@ -767,10 +767,11 @@ compute_w_entry_loop_header(struct spill_ctx *ctx)
uint32_t n_ca = 0;
uint32_t max_loop_pressure = 0;
const bool *loop_block = bi_find_loop_blocks(ctx->shader, ctx->block);
BITSET_WORD *loop_block = BITSET_RZALLOC(NULL, ctx->shader->num_blocks);
bi_find_loop_blocks(ctx->shader, ctx->block, loop_block);
bi_foreach_block(ctx->shader, block) {
if (loop_block[block->index]) {
if (BITSET_TEST(loop_block, block->index)) {
bi_foreach_instr_in_block(block, I) {
max_loop_pressure = MAX2(max_loop_pressure, block->ssa_max_live);
@ -790,6 +791,8 @@ compute_w_entry_loop_header(struct spill_ctx *ctx)
}
}
ralloc_free(loop_block);
/* Sort by next-use distance. */
util_qsort_r(candidates, n_ca, sizeof(struct candidate), cmp_dist, ctx);
@ -833,7 +836,6 @@ compute_w_entry_loop_header(struct spill_ctx *ctx)
assert(ctx->nW <= ctx->k && "invariant");
free((void *)loop_block);
free(candidates);
free(flag_mem);
}

View file

@ -6914,37 +6914,44 @@ bifrost_compile_shader_nir(nir_shader *nir,
}
static void
find_all_predecessors(const bi_context *ctx, bi_block *b, bool *out)
find_all_predecessors(const bi_context *ctx, bi_block *b, BITSET_WORD *out)
{
assert(out);
assert(b);
BITSET_CLEAR_RANGE(out, 0, ctx->num_blocks);
/* If the CFG was one long chain, we would require |blocks|-1 iters to
* propagate the in_loop info all the way through.
*/
for (uint32_t iter = 0; iter < ctx->num_blocks - 1; ++iter) {
bi_foreach_block(ctx, block) {
bi_foreach_successor(block, succ) {
out[block->index] |= out[succ->index] || succ->index == b->index;
if (succ == b || BITSET_TEST(out, succ->index)) {
BITSET_SET(out, block->index);
break;
}
}
}
}
}
bool *
bi_find_loop_blocks(const bi_context *ctx, bi_block *header)
void
bi_find_loop_blocks(const bi_context *ctx, bi_block *header, BITSET_WORD *out)
{
bool *h_as_suc = (bool *)calloc(ctx->num_blocks, sizeof(bool));
assert(h_as_suc);
find_all_predecessors(ctx, header, out);
find_all_predecessors(ctx, header, h_as_suc);
BITSET_WORD *dominators = BITSET_RZALLOC(NULL, ctx->num_blocks);
bi_foreach_block(ctx, b) {
if (bi_block_dominates(header, b)) {
BITSET_SET(dominators, b->index);
}
}
/* If the header dominates b and is also the successor of b, then b
* is in the loop of that header.
*/
bi_foreach_block(ctx, b) {
h_as_suc[b->index] &= bi_block_dominates(header, b);
}
__bitset_and(out, out, dominators, BITSET_WORDS(ctx->num_blocks));
return h_as_suc;
ralloc_free(dominators);
}

View file

@ -1769,7 +1769,8 @@ bi_record_use(bi_instr **uses, BITSET_WORD *multiple, bi_instr *I, unsigned s)
bool bi_lower_divergent_indirects(nir_shader *shader, unsigned lanes);
bool *bi_find_loop_blocks(const bi_context *ctx, bi_block *header);
void bi_find_loop_blocks(const bi_context *ctx, bi_block *header,
BITSET_WORD *out);
#ifdef __cplusplus
} /* extern C */