nir/opt_dce: factor out dead instruction removal into a helper

Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41166>
This commit is contained in:
Marek Olšák 2026-04-20 18:52:52 -04:00 committed by Marge Bot
parent 52669c3b5b
commit 7bd5856cc6

View file

@ -111,6 +111,13 @@ struct loop_state {
nir_block *preheader;
};
static void
remove_instr(nir_instr *instr, struct exec_list *dead_instrs)
{
nir_instr_remove(instr);
exec_list_push_tail(dead_instrs, &instr->node);
}
static bool
dce_block(nir_block *block, BITSET_WORD *defs_live, struct loop_state *loop,
struct exec_list *dead_instrs)
@ -136,8 +143,7 @@ dce_block(nir_block *block, BITSET_WORD *defs_live, struct loop_state *loop,
if (loop->preheader) {
instr->pass_flags = live;
} else if (!live) {
nir_instr_remove(instr);
exec_list_push_tail(dead_instrs, &instr->node);
remove_instr(instr, dead_instrs);
progress = true;
}
}
@ -204,8 +210,7 @@ dce_cf_list(struct exec_list *cf_list, BITSET_WORD *defs_live,
nir_foreach_block_in_cf_node(block, cf_node) {
nir_foreach_instr_safe(instr, block) {
if (!instr->pass_flags) {
nir_instr_remove(instr);
exec_list_push_tail(dead_instrs, &instr->node);
remove_instr(instr, dead_instrs);
progress = true;
}
}