Skip to content

nir: add nir_def_replace helper

Alyssa Rosenzweig requested to merge alyssa/mesa:nir/def-replace into main

"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.

Only thing I don't love about this is (theoretically) marginally more overhead dereferencing the parent_instr. There are ways to mitigate this though and I'm ... not super worried here.

Edited by Alyssa Rosenzweig

Merge request reports