treewide: use BITSET_BYTES, BITSET_RZALLOC

Via Coccinelle patches:

    @@
    expression bits;
    typedef BITSET_WORD;
    @@

    -BITSET_WORDS(bits) * sizeof(BITSET_WORD)
    +BITSET_BYTES(bits)

    @@
    expression memctx, bits;
    typedef BITSET_WORD;
    @@

    -rzalloc_array(memctx, BITSET_WORD, BITSET_WORDS(bits))
    +BITSET_RZALLOC(memctx, bits)

     @@
     expression memctx, bits;
     @@

     -rzalloc_size(memctx, BITSET_BYTES(bits))
     +BITSET_RZALLOC(memctx, bits)

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38245>
This commit is contained in:
Alyssa Rosenzweig 2025-11-04 13:37:06 -05:00 committed by Marge Bot
parent ab4cff4f5c
commit 9c2a2deee6
23 changed files with 37 additions and 55 deletions

View file

@ -84,8 +84,7 @@ pass(agx_context *ctx, void *memctx)
uint64_t *values = rzalloc_array(memctx, uint64_t, ctx->alloc);
/* Set of SSA indices that map to immediate values */
BITSET_WORD *is_immediate =
rzalloc_array(memctx, BITSET_WORD, BITSET_WORDS(ctx->alloc));
BITSET_WORD *is_immediate = BITSET_RZALLOC(memctx, ctx->alloc);
/* Gather constant definitions and use */
agx_foreach_instr_global(ctx, I) {

View file

@ -204,8 +204,7 @@ pressure_schedule_block(agx_context *ctx, agx_block *block, struct sched_ctx *s)
signed orig_max_pressure = 0;
unsigned nr_ins = 0;
memcpy(s->live, block->live_out,
BITSET_WORDS(ctx->alloc) * sizeof(BITSET_WORD));
memcpy(s->live, block->live_out, BITSET_BYTES(ctx->alloc));
agx_foreach_instr_in_block_rev(block, I) {
pressure += calculate_pressure_delta(I, s->live);
@ -214,8 +213,7 @@ pressure_schedule_block(agx_context *ctx, agx_block *block, struct sched_ctx *s)
nr_ins++;
}
memcpy(s->live, block->live_out,
BITSET_WORDS(ctx->alloc) * sizeof(BITSET_WORD));
memcpy(s->live, block->live_out, BITSET_BYTES(ctx->alloc));
/* off by a constant, that's ok */
signed max_pressure = 0;

View file

@ -1205,8 +1205,8 @@ agx_spill(agx_context *ctx, unsigned k, bool remat_only)
BITSET_WORD *S = ralloc_array(memctx, BITSET_WORD, BITSET_WORDS(n));
agx_foreach_block(ctx, block) {
memset(W, 0, BITSET_WORDS(n) * sizeof(BITSET_WORD));
memset(S, 0, BITSET_WORDS(n) * sizeof(BITSET_WORD));
memset(W, 0, BITSET_BYTES(n));
memset(S, 0, BITSET_BYTES(n));
struct spill_ctx sctx = {
.memctx = memctx,

View file

@ -567,7 +567,7 @@ add_var_use_deref(nir_deref_instr *deref, struct hash_table *live,
ainfo = ralloc(live, struct uniform_array_info);
unsigned num_bits = MAX2(1, glsl_get_aoa_size(deref->var->type));
ainfo->indices = rzalloc_array(live, BITSET_WORD, BITSET_WORDS(num_bits));
ainfo->indices = BITSET_RZALLOC(live, num_bits);
ainfo->deref_list = ralloc(live, struct util_dynarray);
util_dynarray_init(ainfo->deref_list, live);

View file

@ -1976,8 +1976,7 @@ xfb_decl_store(struct xfb_decl *xfb_decl, const struct gl_constants *consts,
assert(last_component < max_components);
if (!used_components[buffer]) {
used_components[buffer] =
rzalloc_array(mem_ctx, BITSET_WORD, BITSET_WORDS(max_components));
used_components[buffer] = BITSET_RZALLOC(mem_ctx, max_components);
}
used = used_components[buffer];

View file

@ -967,10 +967,8 @@ isa_disasm(void *bin, int sz, FILE *out, const struct isa_decode_options *option
state->num_instr = sz / (BITMASK_WORDS * sizeof(BITSET_WORD));
if (state->options->branch_labels) {
state->branch_targets = rzalloc_size(state,
sizeof(BITSET_WORD) * BITSET_WORDS(state->num_instr));
state->call_targets = rzalloc_size(state,
sizeof(BITSET_WORD) * BITSET_WORDS(state->num_instr));
state->branch_targets = BITSET_RZALLOC(state, state->num_instr);
state->call_targets = BITSET_RZALLOC(state, state->num_instr);
/* Do a pre-pass to find all the branch targets: */
state->print.out = fopen("/dev/null", "w");

View file

@ -50,7 +50,7 @@ remat_ssa_def(nir_builder *b, nir_def *def, struct hash_table *remap_table,
struct hash_table *phi_value_table,
struct nir_phi_builder *phi_builder, BITSET_WORD *def_blocks)
{
memset(def_blocks, 0, BITSET_WORDS(b->impl->num_blocks) * sizeof(BITSET_WORD));
memset(def_blocks, 0, BITSET_BYTES(b->impl->num_blocks));
BITSET_SET(def_blocks, nir_def_block(def)->index);
BITSET_SET(def_blocks, nir_cursor_current_block(b->cursor)->index);
struct nir_phi_builder_value *val =

View file

@ -215,8 +215,7 @@ nir_opt_dce_impl(nir_function_impl *impl)
{
assert(impl->structured);
BITSET_WORD *defs_live = rzalloc_array(NULL, BITSET_WORD,
BITSET_WORDS(impl->ssa_alloc));
BITSET_WORD *defs_live = BITSET_RZALLOC(NULL, impl->ssa_alloc);
struct exec_list dead_instrs;
exec_list_make_empty(&dead_instrs);

View file

@ -98,8 +98,7 @@ nir_opt_load_skip_helpers(nir_shader *shader, nir_opt_load_skip_helpers_options
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
struct helper_state hs = {
.needs_helpers = rzalloc_array(NULL, BITSET_WORD,
BITSET_WORDS(impl->ssa_alloc)),
.needs_helpers = BITSET_RZALLOC(NULL, impl->ssa_alloc),
.options = options,
};
nir_instr_worklist_init(&hs.worklist);

View file

@ -1828,7 +1828,7 @@ validate_dominance(nir_function_impl *impl, validate_state *state)
state->block = NULL;
}
memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) * sizeof(BITSET_WORD));
memset(state->ssa_defs_found, 0, BITSET_BYTES(impl->ssa_alloc));
validate_ssa_dominance(impl, state);
/* Restore the old dominance metadata */
@ -1931,10 +1931,10 @@ validate_divergence(nir_function_impl *impl, validate_state *state)
block_divergence_metadata *blocks = ralloc_array(state->mem_ctx,
block_divergence_metadata,
state->blocks->size);
BITSET_WORD *ssa_divergence = rzalloc_array(state->mem_ctx, BITSET_WORD,
BITSET_WORDS(impl->ssa_alloc));
BITSET_WORD *loop_invariance = rzalloc_array(state->mem_ctx, BITSET_WORD,
BITSET_WORDS(impl->ssa_alloc));
BITSET_WORD *ssa_divergence = BITSET_RZALLOC(state->mem_ctx,
impl->ssa_alloc);
BITSET_WORD *loop_invariance = BITSET_RZALLOC(state->mem_ctx,
impl->ssa_alloc);
set_foreach(state->blocks, entry) {
nir_block *block = (nir_block *)entry->key;
@ -2158,7 +2158,7 @@ validate_function_impl(nir_function_impl *impl, validate_state *state)
state->ssa_defs_found = reralloc(state->mem_ctx, state->ssa_defs_found,
BITSET_WORD, BITSET_WORDS(impl->ssa_alloc));
memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) * sizeof(BITSET_WORD));
memset(state->ssa_defs_found, 0, BITSET_BYTES(impl->ssa_alloc));
_mesa_set_clear(state->blocks, NULL);
_mesa_set_resize(state->blocks, impl->num_blocks);
@ -2346,7 +2346,7 @@ nir_validate_ssa_dominance(nir_shader *shader, const char *when)
state.ssa_defs_found = reralloc(state.mem_ctx, state.ssa_defs_found,
BITSET_WORD,
BITSET_WORDS(impl->ssa_alloc));
memset(state.ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) * sizeof(BITSET_WORD));
memset(state.ssa_defs_found, 0, BITSET_BYTES(impl->ssa_alloc));
state.impl = impl;
validate_ssa_dominance(impl, &state);

View file

@ -1238,8 +1238,7 @@ record_pred_live_outs(struct ra_ctx *ctx, struct ir3_block *block)
if (state->visited)
continue;
state->live_out = rzalloc_array(NULL, BITSET_WORD,
BITSET_WORDS(ctx->live->definitions_count));
state->live_out = BITSET_RZALLOC(NULL, ctx->live->definitions_count);
rb_tree_foreach (struct ra_interval, interval,

View file

@ -1791,8 +1791,7 @@ record_pred_live_outs(struct ra_spill_ctx *ctx, struct ir3_block *block)
if (state->visited)
continue;
state->live_out = rzalloc_array(ctx, BITSET_WORD,
BITSET_WORDS(ctx->live->definitions_count));
state->live_out = BITSET_RZALLOC(ctx, ctx->live->definitions_count);
rb_tree_foreach (struct ra_spill_interval, interval,

View file

@ -628,7 +628,7 @@ ir3_validate(struct ir3 *ir)
ctx->ir = ir;
ctx->defs_count = ir->instr_count + 1; /* serialno comes from pre-incrementing this. */
ctx->defs = rzalloc_array(ctx, BITSET_WORD, BITSET_WORDS(ctx->defs_count));
ctx->defs = BITSET_RZALLOC(ctx, ctx->defs_count);
ctx->rpt_set = _mesa_pointer_set_create(ctx);
ctx->rpt_block = NULL;

View file

@ -484,7 +484,7 @@ ntt_allocate_regs(struct ntt_compile *c, nir_function_impl *impl)
ntt_live_regs(c, impl);
unsigned *ra_map = ralloc_array(c, unsigned, c->num_temps);
unsigned *released = rzalloc_array(c, BITSET_WORD, BITSET_WORDS(c->num_temps));
unsigned *released = BITSET_RZALLOC(c, c->num_temps);
/* No RA on NIR array regs */
for (int i = 0; i < c->first_non_array_temp; i++)

View file

@ -3796,10 +3796,8 @@ static pco_func *trans_func(trans_ctx *tctx, nir_function_impl *impl)
assert(func->num_params == 0 && func->params == NULL);
/* Gather types. */
tctx->float_types =
rzalloc_array(NULL, BITSET_WORD, BITSET_WORDS(impl->ssa_alloc));
tctx->int_types =
rzalloc_array(NULL, BITSET_WORD, BITSET_WORDS(impl->ssa_alloc));
tctx->float_types = BITSET_RZALLOC(NULL, impl->ssa_alloc);
tctx->int_types = BITSET_RZALLOC(NULL, impl->ssa_alloc);
nir_gather_types(impl, tctx->float_types, tctx->int_types);
tctx->flag = PCO_CF_NODE_FLAG_BODY;

View file

@ -33,7 +33,7 @@ kk_query_table_grow_locked(struct kk_device *dev, struct kk_query_table *table,
table->bo = bo;
assert((new_alloc % BITSET_WORDBITS) == 0);
const size_t new_in_use_size = BITSET_WORDS(new_alloc) * sizeof(BITSET_WORD);
const size_t new_in_use_size = BITSET_BYTES(new_alloc);
new_in_use =
vk_realloc(&dev->vk.alloc, table->in_use, new_in_use_size,
sizeof(BITSET_WORD), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);

View file

@ -467,8 +467,7 @@ new_performance_monitor(struct gl_context *ctx, GLuint index)
for (i = 0; i < ctx->PerfMonitor.NumGroups; i++) {
const struct gl_perf_monitor_group *g = &ctx->PerfMonitor.Groups[i];
m->ActiveCounters[i] = rzalloc_array(m->ActiveCounters, BITSET_WORD,
BITSET_WORDS(g->NumCounters));
m->ActiveCounters[i] = BITSET_RZALLOC(m->ActiveCounters, g->NumCounters);
if (m->ActiveCounters[i] == NULL)
goto fail;
}

View file

@ -27,10 +27,8 @@ nvk_descriptor_table_grow_locked(struct nvk_device *dev,
assert((table->alloc % BITSET_WORDBITS) == 0);
assert((new_alloc % BITSET_WORDBITS) == 0);
const size_t old_in_use_size =
BITSET_WORDS(table->alloc) * sizeof(BITSET_WORD);
const size_t new_in_use_size =
BITSET_WORDS(new_alloc) * sizeof(BITSET_WORD);
const size_t old_in_use_size = BITSET_BYTES(table->alloc);
const size_t new_in_use_size = BITSET_BYTES(new_alloc);
new_in_use = vk_realloc(&dev->vk.alloc, table->in_use,
new_in_use_size, sizeof(BITSET_WORD),
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);

View file

@ -246,8 +246,7 @@ pressure_schedule_block(bi_context *ctx, bi_block *block, struct sched_ctx *s)
signed orig_max_pressure = 0;
unsigned nr_ins = 0;
memcpy(s->live, block->ssa_live_out,
BITSET_WORDS(ctx->ssa_alloc) * sizeof(BITSET_WORD));
memcpy(s->live, block->ssa_live_out, BITSET_BYTES(ctx->ssa_alloc));
bi_foreach_instr_in_block_rev(block, I) {
pressure += calculate_pressure_delta(I, s->live);
@ -256,8 +255,7 @@ pressure_schedule_block(bi_context *ctx, bi_block *block, struct sched_ctx *s)
nr_ins++;
}
memcpy(s->live, block->ssa_live_out,
BITSET_WORDS(ctx->ssa_alloc) * sizeof(BITSET_WORD));
memcpy(s->live, block->ssa_live_out, BITSET_BYTES(ctx->ssa_alloc));
/* off by a constant, that's ok */
signed max_pressure = 0;

View file

@ -1422,8 +1422,8 @@ bi_spill_ssa(bi_context *ctx, unsigned k, unsigned spill_base)
memset(mem_map, 0xff, sizeof(uint32_t) * n);
bi_foreach_block(ctx, block) {
memset(W, 0, BITSET_WORDS(n) * sizeof(BITSET_WORD));
memset(S, 0, BITSET_WORDS(n) * sizeof(BITSET_WORD));
memset(W, 0, BITSET_BYTES(n));
memset(S, 0, BITSET_BYTES(n));
struct spill_ctx sctx = {
.memctx = memctx,

View file

@ -366,8 +366,7 @@ va_optimize_forward(bi_context *ctx)
unsigned count = ctx->ssa_alloc;
bi_instr **lut = rzalloc_array(ctx, bi_instr *, count);
bi_instr **uses = rzalloc_array(ctx, bi_instr *, count);
BITSET_WORD *multiple =
rzalloc_array(ctx, BITSET_WORD, BITSET_WORDS(count));
BITSET_WORD *multiple = BITSET_RZALLOC(ctx, count);
if (!lut || !uses || !multiple)
goto out;

View file

@ -1460,7 +1460,7 @@ schedule_block(compiler_context *ctx, midgard_block *block)
mir_create_dependency_graph(instructions, len, node_count);
/* Allocate the worklist */
size_t sz = BITSET_WORDS(len) * sizeof(BITSET_WORD);
size_t sz = BITSET_BYTES(len);
BITSET_WORD *worklist = calloc(sz, 1);
uint16_t *liveness = calloc(node_count, 2);
mir_initialize_worklist(worklist, instructions, len);

View file

@ -901,7 +901,7 @@ ra_compute_available_regs(struct ra_graph *g, unsigned int n, BITSET_WORD *regs)
struct ra_class *c = g->regs->classes[g->nodes[n].class];
/* Populate with the set of regs that are in the node's class. */
memcpy(regs, c->regs, BITSET_WORDS(g->regs->count) * sizeof(BITSET_WORD));
memcpy(regs, c->regs, BITSET_BYTES(g->regs->count));
/* Remove any regs that conflict with nodes that we're adjacent to and have
* already colored.
@ -946,7 +946,7 @@ ra_select(struct ra_graph *g)
BITSET_WORD *select_regs = NULL;
if (g->select_reg_callback)
select_regs = malloc(BITSET_WORDS(g->regs->count) * sizeof(BITSET_WORD));
select_regs = malloc(BITSET_BYTES(g->regs->count));
while (g->tmp.stack_count != 0) {
unsigned int ri;