From bbdd34b4ad8f9ec65750093293f10b9b51276a0e Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 20 Jun 2024 11:57:37 -0400 Subject: [PATCH] nir: add nir_def_replace helper "Rewrite and remove" is a super common idiom in NIR passes. Let's add a helper to make it more ergonomic. More the point, I expect that /most/ of the time when a pass rewrites uses, they also want to remove the parent instruction. The principle reason not to is because it takes extra effort to add in the nir_instr_remove and nir_opt_dce will clean up after you eventually, right? From a compile time perspective, it's better to remove earlier to reduce the redundant processing between the pass and the next DCE run. So ... we want to be doing *more* removes. From a UX perspective - the way to nudge devs towards that is to make the preferred "rewrite-and-remove" pattern more ergonomic than the "rewrite but keep". That justifies the simple "replace" name rather than something silly like "rewrite_uses_and_remove". --- Something else I've wanted for a while. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index b41799a1666..ed070eb14e0 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4867,6 +4867,13 @@ void nir_def_rewrite_uses_src(nir_def *def, nir_src new_src); void nir_def_rewrite_uses_after(nir_def *def, nir_def *new_ssa, nir_instr *after_me); +static inline void +nir_def_replace(nir_def *def, nir_def *new_ssa) +{ + nir_def_rewrite_uses(def, new_ssa); + nir_instr_remove(def->parent_instr); +} + nir_component_mask_t nir_src_components_read(const nir_src *src); nir_component_mask_t nir_def_components_read(const nir_def *def); bool nir_def_all_uses_are_fsat(const nir_def *def);