From: Faith Ekstrand Date: Thu, 17 Aug 2023 20:41:41 +0000 (-0500) Subject: nir: Drop nir_if_rewrite_condition() X-Git-Tag: upstream/23.3.3~3123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=964c73e13edf885316f234c5dde6330116a86184;p=platform%2Fupstream%2Fmesa.git nir: Drop nir_if_rewrite_condition() Use nir_src_rewrite() instead. In a couple of cases, we can even drop a switch on whether or not it's an if source. Reviewed-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index fca8202..08c6560 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -1502,18 +1502,6 @@ nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src) } void -nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src) -{ - nir_shader *shader = ralloc_parent(if_stmt); - nir_src *src = &if_stmt->condition; - assert(!src_is_valid(src) || (src->is_if && src->parent_if == if_stmt)); - - src_remove_all_uses(src); - src_copy(src, &new_src, shader->gctx); - src_add_all_uses(src, NULL, if_stmt); -} - -void nir_def_init(nir_instr *instr, nir_def *def, unsigned num_components, unsigned bit_size) @@ -2079,13 +2067,8 @@ nir_function_impl_lower_instructions(nir_function_impl *impl, if (new_def->parent_instr->block != instr->block) preserved = nir_metadata_none; - nir_src new_src = nir_src_for_ssa(new_def); - list_for_each_entry_safe(nir_src, use_src, &old_uses, use_link) { - if (use_src->is_if) - nir_if_rewrite_condition(use_src->parent_if, new_src); - else - nir_instr_rewrite_src(use_src->parent_instr, use_src, new_src); - } + list_for_each_entry_safe(nir_src, use_src, &old_uses, use_link) + nir_src_rewrite(use_src, new_def); if (nir_def_is_unused(old_def)) { iter = nir_instr_free_and_dce(instr); diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 431a94e..5413c9d 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4449,8 +4449,6 @@ void nir_instr_clear_src(nir_instr *instr, nir_src *src); void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src); -void nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src); - void nir_def_init(nir_instr *instr, nir_def *def, unsigned num_components, unsigned bit_size); static inline void diff --git a/src/compiler/nir/nir_lower_shader_calls.c b/src/compiler/nir/nir_lower_shader_calls.c index c80515d..e8d99d9 100644 --- a/src/compiler/nir/nir_lower_shader_calls.c +++ b/src/compiler/nir/nir_lower_shader_calls.c @@ -779,7 +779,7 @@ spill_ssa_defs_and_lower_shader_calls(nir_shader *shader, uint32_t num_calls, get_phi_builder_def_for_src(&following_if->condition, &pbv_arr, block); if (new_def != NULL) - nir_if_rewrite_condition(following_if, nir_src_for_ssa(new_def)); + nir_src_rewrite(&following_if->condition, new_def); } /* Handle phi sources that source from this block. We have to do this diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c index 08627c0..5def4c4 100644 --- a/src/compiler/nir/nir_opt_if.c +++ b/src/compiler/nir/nir_opt_if.c @@ -876,7 +876,7 @@ opt_if_simplification(nir_builder *b, nir_if *nif) nir_def *new_condition = nir_inot(b, &alu_instr->def); - nir_if_rewrite_condition(nif, nir_src_for_ssa(new_condition)); + nir_src_rewrite(&nif->condition, new_condition); /* Grab pointers to the last then/else blocks for fixing up the phis. */ nir_block *then_block = nir_if_last_then_block(nif); @@ -1266,14 +1266,7 @@ propagate_condition_eval(nir_builder *b, nir_if *nif, nir_src *use_src, } nir_def *nalu = clone_alu_and_replace_src_defs(b, alu, def); - - /* Rewrite use to use new alu instruction */ - nir_src new_src = nir_src_for_ssa(nalu); - - if (alu_use->is_if) - nir_if_rewrite_condition(alu_use->parent_if, new_src); - else - nir_instr_rewrite_src(alu_use->parent_instr, alu_use, new_src); + nir_src_rewrite(alu_use, nalu); return true; } @@ -1308,12 +1301,7 @@ evaluate_condition_use(nir_builder *b, nir_if *nif, nir_src *use_src) bool bool_value; if (evaluate_if_condition(nif, b->cursor, &bool_value)) { /* Rewrite use to use const */ - nir_src imm_src = nir_src_for_ssa(nir_imm_bool(b, bool_value)); - if (use_src->is_if) - nir_if_rewrite_condition(use_src->parent_if, imm_src); - else - nir_instr_rewrite_src(use_src->parent_instr, use_src, imm_src); - + nir_src_rewrite(use_src, nir_imm_bool(b, bool_value)); progress = true; } diff --git a/src/compiler/nir/nir_opt_peephole_select.c b/src/compiler/nir/nir_opt_peephole_select.c index 10b38ca..3e16d81 100644 --- a/src/compiler/nir/nir_opt_peephole_select.c +++ b/src/compiler/nir/nir_opt_peephole_select.c @@ -351,7 +351,7 @@ nir_opt_collapse_if(nir_if *if_stmt, nir_shader *shader, unsigned limit, struct nir_builder b = nir_builder_at(nir_before_cf_node(&if_stmt->cf_node)); nir_def *cond = nir_iand(&b, if_stmt->condition.ssa, parent_if->condition.ssa); - nir_if_rewrite_condition(if_stmt, nir_src_for_ssa(cond)); + nir_src_rewrite(&if_stmt->condition, cond); /* move the whole inner if before the parent if */ nir_cf_list tmp; diff --git a/src/compiler/nir/nir_opt_rematerialize_compares.c b/src/compiler/nir/nir_opt_rematerialize_compares.c index e85591a..b2c5dc6 100644 --- a/src/compiler/nir/nir_opt_rematerialize_compares.c +++ b/src/compiler/nir/nir_opt_rematerialize_compares.c @@ -123,8 +123,7 @@ nir_opt_rematerialize_compares_impl(nir_shader *shader, nir_function_impl *impl) nir_instr_insert_after_block(prev_block, &clone->instr); - nir_if_rewrite_condition(if_stmt, - nir_src_for_ssa(&clone->def)); + nir_src_rewrite(&if_stmt->condition, &clone->def); progress = true; } else { nir_instr *const use_instr = use->parent_instr; diff --git a/src/compiler/nir/nir_repair_ssa.c b/src/compiler/nir/nir_repair_ssa.c index ca34ec5..f5604c3 100644 --- a/src/compiler/nir/nir_repair_ssa.c +++ b/src/compiler/nir/nir_repair_ssa.c @@ -134,7 +134,7 @@ repair_ssa_def(nir_def *def, void *void_state) } if (src->is_if) - nir_if_rewrite_condition(src->parent_if, nir_src_for_ssa(block_def)); + nir_src_rewrite(&src->parent_if->condition, block_def); else nir_instr_rewrite_src(src->parent_instr, src, nir_src_for_ssa(block_def)); } diff --git a/src/compiler/nir/nir_to_lcssa.c b/src/compiler/nir/nir_to_lcssa.c index a4e7574..3577e8d 100644 --- a/src/compiler/nir/nir_to_lcssa.c +++ b/src/compiler/nir/nir_to_lcssa.c @@ -262,7 +262,7 @@ convert_loop_exit_for_ssa(nir_def *def, void *void_state) nir_foreach_use_including_if_safe(use, def) { if (use->is_if) { if (!is_if_use_inside_loop(use, state->loop)) - nir_if_rewrite_condition(use->parent_if, nir_src_for_ssa(dest)); + nir_src_rewrite(&use->parent_if->condition, dest); continue; } diff --git a/src/gallium/drivers/lima/ir/lima_nir_duplicate_consts.c b/src/gallium/drivers/lima/ir/lima_nir_duplicate_consts.c index 22f2828..8ec1139 100644 --- a/src/gallium/drivers/lima/ir/lima_nir_duplicate_consts.c +++ b/src/gallium/drivers/lima/ir/lima_nir_duplicate_consts.c @@ -75,7 +75,7 @@ lima_nir_duplicate_load_const(nir_builder *b, nir_load_const_instr *load) dupl = last_dupl; } - nir_if_rewrite_condition(use_src->parent_if, nir_src_for_ssa(&dupl->def)); + nir_src_rewrite(&use_src->parent_if->condition, &dupl->def); last_parent_instr = use_src->parent_instr; last_dupl = dupl; } diff --git a/src/gallium/drivers/lima/ir/lima_nir_duplicate_intrinsic.c b/src/gallium/drivers/lima/ir/lima_nir_duplicate_intrinsic.c index c3c5cc2..5de4d3e 100644 --- a/src/gallium/drivers/lima/ir/lima_nir_duplicate_intrinsic.c +++ b/src/gallium/drivers/lima/ir/lima_nir_duplicate_intrinsic.c @@ -82,7 +82,7 @@ lima_nir_duplicate_intrinsic(nir_builder *b, nir_intrinsic_instr *itr, dupl = last_dupl; } - nir_if_rewrite_condition(use_src->parent_if, nir_src_for_ssa(&dupl->def)); + nir_src_rewrite(&use_src->parent_if->condition, &dupl->def); last_parent_instr = use_src->parent_instr; last_dupl = dupl; } diff --git a/src/gallium/drivers/lima/ir/lima_nir_split_loads.c b/src/gallium/drivers/lima/ir/lima_nir_split_loads.c index 0d1e328..9cf60ea 100644 --- a/src/gallium/drivers/lima/ir/lima_nir_split_loads.c +++ b/src/gallium/drivers/lima/ir/lima_nir_split_loads.c @@ -74,8 +74,7 @@ replace_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin) } nir_foreach_if_use_safe(src, &intrin->def) { b->cursor = nir_before_src(src); - nir_if_rewrite_condition(src->parent_if, - nir_src_for_ssa(clone_intrinsic(b, intrin))); + nir_src_rewrite(&src->parent_if->condition, clone_intrinsic(b, intrin)); } nir_instr_remove(&intrin->instr);