treewide: use BITSET_CALLOC

Via Coccinelle patch:

    @@
    expression count;
    type T;
    @@

    -calloc(BITSET_WORDS(count), sizeof(T))
    +BITSET_CALLOC(count)

    @@
    expression count;
    type T;
    @@

    -calloc(sizeof(T), BITSET_WORDS(count))
    +BITSET_CALLOC(count)

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37779>
This commit is contained in:
Alyssa Rosenzweig 2025-10-08 17:42:10 -04:00 committed by Marge Bot
parent 85207a4f6a
commit c1d75c6e51
18 changed files with 23 additions and 35 deletions

View file

@ -12,7 +12,7 @@
void
agx_dce(agx_context *ctx, bool partial)
{
BITSET_WORD *seen = calloc(BITSET_WORDS(ctx->alloc), sizeof(BITSET_WORD));
BITSET_WORD *seen = BITSET_CALLOC(ctx->alloc);
agx_foreach_block(ctx, block) {
if (block->loop_header) {

View file

@ -599,7 +599,7 @@ void
agx_optimizer_backward(agx_context *ctx)
{
agx_instr **uses = calloc(ctx->alloc, sizeof(*uses));
BITSET_WORD *multiple = calloc(BITSET_WORDS(ctx->alloc), sizeof(*multiple));
BITSET_WORD *multiple = BITSET_CALLOC(ctx->alloc);
agx_foreach_block_rev(ctx, block) {
/* Phi sources are logically read at the end of predecessor, so process

View file

@ -1461,7 +1461,7 @@ agx_ra(agx_context *ctx)
enum ra_class *classes = calloc(ctx->alloc, sizeof(enum ra_class));
agx_instr **src_to_collect_phi = calloc(ctx->alloc, sizeof(agx_instr *));
enum agx_size *sizes = calloc(ctx->alloc, sizeof(enum agx_size));
BITSET_WORD *visited = calloc(BITSET_WORDS(ctx->alloc), sizeof(BITSET_WORD));
BITSET_WORD *visited = BITSET_CALLOC(ctx->alloc);
unsigned max_ncomps = 1;
agx_foreach_instr_global(ctx, I) {

View file

@ -512,7 +512,7 @@ agx_validate(agx_context *ctx, const char *after)
}
{
BITSET_WORD *defs = calloc(sizeof(BITSET_WORD), BITSET_WORDS(ctx->alloc));
BITSET_WORD *defs = BITSET_CALLOC(ctx->alloc);
agx_foreach_instr_global(ctx, I) {
if (!agx_validate_defs(I, defs)) {

View file

@ -262,10 +262,8 @@ nir_lower_int_to_float_impl(nir_function_impl *impl)
nir_builder b = nir_builder_create(impl);
nir_index_ssa_defs(impl);
float_types = calloc(BITSET_WORDS(impl->ssa_alloc),
sizeof(BITSET_WORD));
int_types = calloc(BITSET_WORDS(impl->ssa_alloc),
sizeof(BITSET_WORD));
float_types = BITSET_CALLOC(impl->ssa_alloc);
int_types = BITSET_CALLOC(impl->ssa_alloc);
nir_gather_types(impl, float_types, int_types);
nir_foreach_block(block, impl) {

View file

@ -931,8 +931,7 @@ nir_opt_preamble(nir_shader *shader, const nir_opt_preamble_options *options,
* we did.
*/
ctx.reconstructed_ifs = _mesa_pointer_set_create(NULL);
ctx.reconstructed_defs = calloc(BITSET_WORDS(impl->ssa_alloc),
sizeof(BITSET_WORD));
ctx.reconstructed_defs = BITSET_CALLOC(impl->ssa_alloc);
analyze_reconstructed(&ctx, impl);
/* If we make progress analyzing speculation, we need to re-analyze

View file

@ -2433,8 +2433,8 @@ print_function_impl(nir_function_impl *impl, print_state *state, bool print_name
* nir_print don't modify the shader. If needed, a limit for ssa_alloc
* can be added.
*/
state->float_types = calloc(BITSET_WORDS(impl->ssa_alloc), sizeof(BITSET_WORD));
state->int_types = calloc(BITSET_WORDS(impl->ssa_alloc), sizeof(BITSET_WORD));
state->float_types = BITSET_CALLOC(impl->ssa_alloc);
state->int_types = BITSET_CALLOC(impl->ssa_alloc);
nir_gather_types(impl, state->float_types, state->int_types);
}

View file

@ -136,8 +136,7 @@ trivialize_loads(nir_function_impl *impl, nir_block *block)
{
struct trivialize_src_state state = {
.block = block,
.trivial_loads = calloc(BITSET_WORDS(impl->ssa_alloc),
sizeof(BITSET_WORD)),
.trivial_loads = BITSET_CALLOC(impl->ssa_alloc),
};
nir_foreach_instr_safe(instr, block) {

View file

@ -339,8 +339,7 @@ dri2_wl_formats_init(struct dri2_wl_formats *formats)
* represent all the formats of dri2_wl_visuals. We use BITSET_WORDS for
* this task. */
formats->num_formats = ARRAY_SIZE(dri2_wl_visuals);
formats->formats_bitmap = calloc(BITSET_WORDS(formats->num_formats),
sizeof(*formats->formats_bitmap));
formats->formats_bitmap = BITSET_CALLOC(formats->num_formats);
if (!formats->formats_bitmap)
goto err;

View file

@ -33,8 +33,7 @@
void
bi_opt_dce(bi_context *ctx, bool partial)
{
BITSET_WORD *seen =
calloc(BITSET_WORDS(ctx->ssa_alloc), sizeof(BITSET_WORD));
BITSET_WORD *seen = BITSET_CALLOC(ctx->ssa_alloc);
bi_foreach_block(ctx, block) {
if (block->loop_header) {

View file

@ -407,7 +407,7 @@ bi_opt_mod_prop_backward(bi_context *ctx)
{
unsigned count = ctx->ssa_alloc;
bi_instr **uses = calloc(count, sizeof(*uses));
BITSET_WORD *multiple = calloc(BITSET_WORDS(count), sizeof(*multiple));
BITSET_WORD *multiple = BITSET_CALLOC(count);
bi_foreach_block_rev(ctx, block) {
/* Watch out for PHI instructions in loops!

View file

@ -596,8 +596,7 @@ static signed
bi_choose_spill_node(bi_context *ctx, struct lcra_state *l)
{
/* Pick a node satisfying bi_spill_register's preconditions */
BITSET_WORD *no_spill =
calloc(sizeof(BITSET_WORD), BITSET_WORDS(l->node_count));
BITSET_WORD *no_spill = BITSET_CALLOC(l->node_count);
bi_foreach_instr_global(ctx, ins) {
bi_foreach_dest(ins, d) {
@ -1042,10 +1041,8 @@ bi_out_of_ssa(bi_context *ctx)
* algorithm is quadratic. This will go away when we go out of SSA after
* RA.
*/
BITSET_WORD *used =
calloc(sizeof(BITSET_WORD), BITSET_WORDS(ctx->ssa_alloc));
BITSET_WORD *multiple_uses =
calloc(sizeof(BITSET_WORD), BITSET_WORDS(ctx->ssa_alloc));
BITSET_WORD *used = BITSET_CALLOC(ctx->ssa_alloc);
BITSET_WORD *multiple_uses = BITSET_CALLOC(ctx->ssa_alloc);
bi_foreach_instr_global(ctx, I) {
bi_foreach_ssa_src(I, s) {

View file

@ -231,7 +231,7 @@ bi_create_dependency_graph(struct bi_worklist st, bool inorder, bool is_blend)
/* Initialize dependency graph */
for (unsigned i = 0; i < st.count; ++i) {
st.dependents[i] = calloc(BITSET_WORDS(st.count), sizeof(BITSET_WORD));
st.dependents[i] = BITSET_CALLOC(st.count);
st.dep_counts[i] = 0;
}
@ -510,7 +510,7 @@ bi_initialize_worklist(bi_block *block, bool inorder, bool is_blend)
st.dep_counts = calloc(st.count, sizeof(st.dep_counts[0]));
bi_create_dependency_graph(st, inorder, is_blend);
st.worklist = calloc(BITSET_WORDS(st.count), sizeof(BITSET_WORD));
st.worklist = BITSET_CALLOC(st.count);
for (unsigned i = 0; i < st.count; ++i) {
if (st.dep_counts[i] == 0)

View file

@ -190,7 +190,7 @@ mir_analyze_helper_requirements(compiler_context *ctx)
{
mir_compute_temp_count(ctx);
unsigned temp_count = ctx->temp_count;
BITSET_WORD *deps = calloc(sizeof(BITSET_WORD), BITSET_WORDS(temp_count));
BITSET_WORD *deps = BITSET_CALLOC(temp_count);
/* Initialize with the sources of instructions consuming
* derivatives */

View file

@ -29,8 +29,7 @@ midgard_nir_type_csel(nir_shader *shader)
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
nir_index_ssa_defs(impl);
BITSET_WORD *float_types =
calloc(BITSET_WORDS(impl->ssa_alloc), sizeof(BITSET_WORD));
BITSET_WORD *float_types = BITSET_CALLOC(impl->ssa_alloc);
nir_gather_types(impl, float_types, NULL);
bool progress =

View file

@ -163,7 +163,7 @@ midgard_opt_prop_backward(compiler_context *ctx)
{
bool progress = false;
enum outmod_state *state = calloc(ctx->temp_count, sizeof(*state));
BITSET_WORD *folded = calloc(BITSET_WORDS(ctx->temp_count), sizeof(*folded));
BITSET_WORD *folded = BITSET_CALLOC(ctx->temp_count);
/* Scan for outmod states */
mir_foreach_instr_global(ctx, I) {

View file

@ -113,8 +113,7 @@ mir_create_dependency_graph(midgard_instruction **instructions, unsigned count,
/* Initialize dependency graph */
for (unsigned i = 0; i < count; ++i) {
instructions[i]->dependents =
calloc(BITSET_WORDS(count), sizeof(BITSET_WORD));
instructions[i]->dependents = BITSET_CALLOC(count);
instructions[i]->nr_dependencies = 0;
}

View file

@ -253,8 +253,7 @@ static BITSET_WORD *
mir_special_indices(compiler_context *ctx)
{
mir_compute_temp_count(ctx);
BITSET_WORD *bset =
calloc(BITSET_WORDS(ctx->temp_count), sizeof(BITSET_WORD));
BITSET_WORD *bset = BITSET_CALLOC(ctx->temp_count);
mir_foreach_instr_global(ctx, ins) {
/* Look for special instructions */