nir: Add a nir_instr_clear_src() helper and use it

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24729>
This commit is contained in:
Faith Ekstrand
2023-08-16 11:16:00 -05:00
committed by Marge Bot
parent 7af0dcbdfc
commit 9c8cb69c15
5 changed files with 21 additions and 5 deletions

View File

@@ -808,7 +808,7 @@ nir_tex_instr_remove_src(nir_tex_instr *tex, unsigned src_idx)
assert(src_idx < tex->num_srcs);
/* First rewrite the source to NIR_SRC_INIT */
nir_instr_rewrite_src(&tex->instr, &tex->src[src_idx].src, NIR_SRC_INIT);
nir_instr_clear_src(&tex->instr, &tex->src[src_idx].src);
/* Now, move all of the other sources down */
for (unsigned i = src_idx + 1; i < tex->num_srcs; i++) {
@@ -1476,6 +1476,13 @@ nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src)
src_add_all_uses(src, instr, NULL);
}
void
nir_instr_clear_src(nir_instr *instr, nir_src *src)
{
src_remove_all_uses(src);
*src = NIR_SRC_INIT;
}
void
nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src)
{

View File

@@ -4420,6 +4420,16 @@ nir_instr_rewrite_src_ssa(ASSERTED nir_instr *instr,
}
void nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src);
/** Clear a nir_src
*
* This helper clears a nir_src by removing it from any uses lists and
* resetting its contents to NIR_SRC_INIT. This is typically used as a
* precursor to removing the source from the instruction by adjusting a
* num_srcs parameter somewhere or overwriting it with nir_instr_move_src().
*/
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);

View File

@@ -666,7 +666,7 @@ cleanup_cf_node(nir_cf_node *node, nir_function_impl *impl)
nir_jump_instr *jump = nir_instr_as_jump(instr);
unlink_jump(block, jump->type, false);
if (jump->type == nir_jump_goto_if)
nir_instr_rewrite_src(instr, &jump->condition, NIR_SRC_INIT);
nir_instr_clear_src(instr, &jump->condition);
} else {
nir_foreach_def(instr, replace_ssa_def_uses, impl);
nir_instr_remove(instr);

View File

@@ -211,8 +211,7 @@ nir_lower_cl_images(nir_shader *shader, bool lower_image_derefs, bool lower_samp
else
tex->sampler_index = deref->var->data.driver_location;
/* This source gets discarded */
nir_instr_rewrite_src(&tex->instr, &tex->src[i].src,
NIR_SRC_INIT);
nir_instr_clear_src(&tex->instr, &tex->src[i].src);
continue;
} else {
b.cursor = nir_before_instr(&tex->instr);

View File

@@ -165,7 +165,7 @@ try_coalesce(nir_builder *b, nir_def *reg, nir_alu_instr *vec,
/* Clear the no longer needed vec source */
if (valid)
nir_instr_rewrite_src(&vec->instr, &vec->src[i].src, NIR_SRC_INIT);
nir_instr_clear_src(&vec->instr, &vec->src[i].src);
}
/* We've cleared the only use of the destination */