nir/builder: add nir_shader_phi_pass
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33672>
This commit is contained in:
@@ -81,6 +81,8 @@ typedef bool (*nir_alu_pass_cb)(struct nir_builder *,
|
||||
nir_alu_instr *, void *);
|
||||
typedef bool (*nir_tex_pass_cb)(struct nir_builder *,
|
||||
nir_tex_instr *, void *);
|
||||
typedef bool (*nir_phi_pass_cb)(struct nir_builder *,
|
||||
nir_phi_instr *, void *);
|
||||
|
||||
/**
|
||||
* Iterates over all the instructions in a NIR function and calls the given pass
|
||||
@@ -268,6 +270,36 @@ nir_shader_tex_pass(nir_shader *shader, nir_tex_pass_cb pass,
|
||||
return progress;
|
||||
}
|
||||
|
||||
/* As above, but for phis */
|
||||
static inline bool
|
||||
nir_shader_phi_pass(nir_shader *shader,
|
||||
nir_phi_pass_cb pass,
|
||||
nir_metadata preserved,
|
||||
void *cb_data)
|
||||
{
|
||||
bool progress = false;
|
||||
|
||||
nir_foreach_function_impl(impl, shader) {
|
||||
bool func_progress = false;
|
||||
nir_builder b = nir_builder_create(impl);
|
||||
|
||||
nir_foreach_block_safe(block, impl) {
|
||||
nir_foreach_phi_safe(phi, block) {
|
||||
func_progress |= pass(&b, phi, cb_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (func_progress) {
|
||||
nir_metadata_preserve(impl, preserved);
|
||||
progress = true;
|
||||
} else {
|
||||
nir_metadata_preserve(impl, nir_metadata_all);
|
||||
}
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
void nir_builder_instr_insert(nir_builder *build, nir_instr *instr);
|
||||
void nir_builder_instr_insert_at_top(nir_builder *build, nir_instr *instr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user