nir/opt_licm: remove the block_filter callback

For PCO, the instr_filter callback can do the same thing.
This commit is contained in:
Marek Olšák 2025-12-05 12:24:09 -05:00
parent ce2383c6df
commit c34d84852b
5 changed files with 14 additions and 26 deletions

View file

@ -368,7 +368,7 @@ radv_postprocess_nir(struct radv_device *device, const struct radv_graphics_stat
nir_move_options sink_opts = nir_move_const_undef | nir_move_copies | nir_dont_move_byte_word_vecs;
if (!stage->key.optimisations_disabled) {
NIR_PASS(_, stage->nir, nir_opt_licm, NULL, ac_nir_opt_licm_filter_instr_cb);
NIR_PASS(_, stage->nir, nir_opt_licm, ac_nir_opt_licm_filter_instr_cb);
if (stage->stage == MESA_SHADER_VERTEX) {
/* Always load all VS inputs at the top to eliminate needless VMEM->s_wait->VMEM sequences.

View file

@ -6412,17 +6412,13 @@ bool nir_opt_large_constants(nir_shader *shader,
glsl_type_size_align_func size_align,
unsigned threshold);
typedef bool (*nir_opt_licm_filter_block_cb)(nir_block *block, nir_loop *loop);
typedef bool (*nir_opt_licm_filter_instr_cb)(nir_instr *instr,
bool instr_dominates_exit,
unsigned num_dst_bits,
unsigned num_all_src_bits,
nir_loop *loop);
bool nir_opt_licm_filter_blocks_dominating_exit(nir_block *block,
nir_loop *loop);
bool nir_opt_licm(nir_shader *shader,
nir_opt_licm_filter_block_cb filter_block,
nir_opt_licm_filter_instr_cb filter_instr);
bool nir_opt_loop(nir_shader *shader);

View file

@ -6,7 +6,6 @@
#include "nir.h"
typedef struct {
nir_opt_licm_filter_block_cb filter_block;
nir_opt_licm_filter_instr_cb filter_instr;
nir_loop *loop;
@ -156,8 +155,7 @@ visit_cf_list(struct exec_list *list, licm_state *state)
/* Visit the block. */
nir_block *block = nir_cf_node_as_block(node);
if (state->loop &&
(!state->filter_block || state->filter_block(block, state->loop)))
if (state->loop)
progress |= visit_block(block, state);
if (next && next->type == nir_cf_node_loop && !optimize_loop) {
@ -190,23 +188,9 @@ visit_cf_list(struct exec_list *list, licm_state *state)
}
bool
nir_opt_licm_filter_blocks_dominating_exit(nir_block *block, nir_loop *loop)
nir_opt_licm(nir_shader *shader, nir_opt_licm_filter_instr_cb filter_instr)
{
/* TODO: This is deprecated because nir_instr_can_speculate is a better way
* to handle speculative execution.
*
* By only visiting blocks which dominate the block after the loop,
* we ensure that we don't speculatively hoist any instructions
* which otherwise might not be executed.
*/
return nir_block_dominates(block, nir_loop_successor_block(loop));
}
bool
nir_opt_licm(nir_shader *shader, nir_opt_licm_filter_block_cb filter_block,
nir_opt_licm_filter_instr_cb filter_instr)
{
licm_state state = {filter_block, filter_instr};
licm_state state = {filter_instr};
bool progress = false;
nir_foreach_function_impl(impl, shader) {

View file

@ -51,7 +51,7 @@ nir_opt_licm_test::test_finish(nir_opt_licm_filter_instr_cb filter_instr)
nir_validate_shader(b->shader, NULL);
bool progress = false;
NIR_PASS(progress, b->shader, nir_opt_licm, NULL, filter_instr);
NIR_PASS(progress, b->shader, nir_opt_licm, filter_instr);
if (expect_progress) {
ASSERT_TRUE(progress);

View file

@ -788,6 +788,14 @@ static bool robustness_filter(const nir_intrinsic_instr *intr,
return false;
}
static bool
opt_licm_filter_instr_cb(nir_instr *instr, bool instr_dominates_exit,
unsigned num_dst_bits, unsigned num_all_src_bits,
nir_loop *loop)
{
return instr_dominates_exit;
}
/**
* \brief Lowers a NIR shader.
*
@ -808,7 +816,7 @@ void pco_lower_nir(pco_ctx *ctx, nir_shader *nir, pco_data *data)
NIR_PASS(_, nir, nir_lower_memory_model);
NIR_PASS(_, nir, nir_opt_licm, nir_opt_licm_filter_blocks_dominating_exit, NULL);
NIR_PASS(_, nir, nir_opt_licm, opt_licm_filter_instr_cb);
NIR_PASS(_, nir, nir_lower_memcpy);