From 68b80e4d251c5a2c269eb2bbaba2f58ca91608c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 9 Aug 2025 17:32:30 -0400 Subject: [PATCH] nir/instr_set: don't ralloc the set Reviewed-by: Gert Wollny Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/compiler/nir/nir_instr_set.c | 10 +++++----- src/compiler/nir/nir_instr_set.h | 4 ++-- src/compiler/nir/nir_opt_cse.c | 9 +++++---- src/compiler/nir/nir_opt_gcm.c | 8 +++++--- src/freedreno/ir3/ir3_nir_opt_preamble.c | 8 +++++--- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/compiler/nir/nir_instr_set.c b/src/compiler/nir/nir_instr_set.c index b55ba03b0b3..64687a69214 100644 --- a/src/compiler/nir/nir_instr_set.c +++ b/src/compiler/nir/nir_instr_set.c @@ -771,16 +771,16 @@ cmp_func(const void *data1, const void *data2) return nir_instrs_equal(data1, data2); } -struct set * -nir_instr_set_create(void *mem_ctx) +void +nir_instr_set_init(struct set *s, void *mem_ctx) { - return _mesa_set_create(mem_ctx, hash_instr, cmp_func); + _mesa_set_init(s, mem_ctx, hash_instr, cmp_func); } void -nir_instr_set_destroy(struct set *instr_set) +nir_instr_set_fini(struct set *instr_set) { - _mesa_set_destroy(instr_set, NULL); + _mesa_set_fini(instr_set, NULL); } nir_instr * diff --git a/src/compiler/nir/nir_instr_set.h b/src/compiler/nir/nir_instr_set.h index a13dcf8ffcb..bade08472f9 100644 --- a/src/compiler/nir/nir_instr_set.h +++ b/src/compiler/nir/nir_instr_set.h @@ -41,10 +41,10 @@ /*@{*/ /** Creates an instruction set, using a given ralloc mem_ctx */ -struct set *nir_instr_set_create(void *mem_ctx); +void nir_instr_set_init(struct set *s, void *mem_ctx); /** Destroys an instruction set. */ -void nir_instr_set_destroy(struct set *instr_set); +void nir_instr_set_fini(struct set *instr_set); /** * Adds an instruction to an instruction set if it doesn't exist. If it does diff --git a/src/compiler/nir/nir_opt_cse.c b/src/compiler/nir/nir_opt_cse.c index 7e800f574dd..ffcdc9985e1 100644 --- a/src/compiler/nir/nir_opt_cse.c +++ b/src/compiler/nir/nir_opt_cse.c @@ -37,16 +37,17 @@ dominates(const nir_instr *old_instr, const nir_instr *new_instr) static bool nir_opt_cse_impl(nir_function_impl *impl) { - struct set *instr_set = nir_instr_set_create(NULL); + struct set instr_set; + nir_instr_set_init(&instr_set, NULL); - _mesa_set_resize(instr_set, impl->ssa_alloc); + _mesa_set_resize(&instr_set, impl->ssa_alloc); nir_metadata_require(impl, nir_metadata_dominance); bool progress = false; nir_foreach_block(block, impl) { nir_foreach_instr_safe(instr, block) { - if (nir_instr_set_add_or_rewrite(instr_set, instr, dominates)) { + if (nir_instr_set_add_or_rewrite(&instr_set, instr, dominates)) { progress = true; nir_instr_remove(instr); } @@ -55,7 +56,7 @@ nir_opt_cse_impl(nir_function_impl *impl) nir_progress(progress, impl, nir_metadata_control_flow); - nir_instr_set_destroy(instr_set); + nir_instr_set_fini(&instr_set); return progress; } diff --git a/src/compiler/nir/nir_opt_gcm.c b/src/compiler/nir/nir_opt_gcm.c index c3dc5574c36..5929bac28cb 100644 --- a/src/compiler/nir/nir_opt_gcm.c +++ b/src/compiler/nir/nir_opt_gcm.c @@ -831,18 +831,20 @@ opt_gcm_impl(nir_shader *shader, nir_function_impl *impl, bool value_number) * on both sides of the same if/else block, we allow them to be moved. * This cleans up a lot of mess without being -too- aggressive. */ - struct set *gvn_set = nir_instr_set_create(NULL); + struct set gvn_set; + nir_instr_set_init(&gvn_set, NULL); + foreach_list_typed_safe(nir_instr, instr, node, &state.instrs) { if (instr->pass_flags & GCM_INSTR_PINNED) continue; - if (nir_instr_set_add_or_rewrite(gvn_set, instr, + if (nir_instr_set_add_or_rewrite(&gvn_set, instr, value_number ? NULL : weak_gvn)) { state.progress = true; nir_instr_remove(instr); } } - nir_instr_set_destroy(gvn_set); + nir_instr_set_fini(&gvn_set); foreach_list_typed(nir_instr, instr, node, &state.instrs) gcm_schedule_early_instr(instr, &state); diff --git a/src/freedreno/ir3/ir3_nir_opt_preamble.c b/src/freedreno/ir3/ir3_nir_opt_preamble.c index b16c4aa6d6d..40883cfcb24 100644 --- a/src/freedreno/ir3/ir3_nir_opt_preamble.c +++ b/src/freedreno/ir3/ir3_nir_opt_preamble.c @@ -690,7 +690,9 @@ ir3_nir_opt_prefetch_descriptors(nir_shader *nir, struct ir3_shader_variant *v) const struct ir3_const_state *const_state = ir3_const_state(v); nir_function_impl *main = nir_shader_get_entrypoint(nir); - struct set *instr_set = nir_instr_set_create(NULL); + struct set instr_set; + nir_instr_set_init(&instr_set, NULL); + nir_function_impl *preamble = main->preamble ? main->preamble->impl : NULL; nir_builder b; bool progress = false; @@ -777,7 +779,7 @@ ir3_nir_opt_prefetch_descriptors(nir_shader *nir, struct ir3_shader_variant *v) continue; preamble_descs[i] = - ir3_rematerialize_def_for_preamble(&b, descs[i], instr_set, + ir3_rematerialize_def_for_preamble(&b, descs[i], &instr_set, preamble_defs); } @@ -799,7 +801,7 @@ finished: nir_metadata_block_index | nir_metadata_dominance); } - nir_instr_set_destroy(instr_set); + nir_instr_set_fini(&instr_set); free(preamble_defs); return progress; }