nir: add nir_function_intrinsics_pass
we already have * nir_shader_instructions_pass * nir_shader_intrinsics_pass * nir_function_instructions_pass add the missing fourth, it's useful too. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33099>
This commit is contained in:
committed by
Marge Bot
parent
3b1166da8c
commit
63c94cf755
@@ -140,6 +140,43 @@ nir_shader_instructions_pass(nir_shader *shader,
|
||||
return progress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over all the intrinsics in a NIR function and calls the given pass
|
||||
* on them.
|
||||
*
|
||||
* The pass should return true if it modified the shader. In that case, only
|
||||
* the preserved metadata flags will be preserved in the function impl.
|
||||
*
|
||||
* The builder will be initialized to point at the function impl, but its
|
||||
* cursor is unset.
|
||||
*/
|
||||
static inline bool
|
||||
nir_function_intrinsics_pass(nir_function_impl *impl,
|
||||
nir_intrinsic_pass_cb pass,
|
||||
nir_metadata preserved,
|
||||
void *cb_data)
|
||||
{
|
||||
bool progress = false;
|
||||
nir_builder b = nir_builder_create(impl);
|
||||
|
||||
nir_foreach_block_safe(block, impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr->type == nir_instr_type_intrinsic) {
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
progress |= pass(&b, intr, cb_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
nir_metadata_preserve(impl, preserved);
|
||||
} else {
|
||||
nir_metadata_preserve(impl, nir_metadata_all);
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over all the intrinsics in a NIR shader and calls the given pass on
|
||||
* them.
|
||||
@@ -159,24 +196,7 @@ nir_shader_intrinsics_pass(nir_shader *shader,
|
||||
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_instr_safe(instr, block) {
|
||||
if (instr->type == nir_instr_type_intrinsic) {
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
func_progress |= pass(&b, intr, cb_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (func_progress) {
|
||||
nir_metadata_preserve(impl, preserved);
|
||||
progress = true;
|
||||
} else {
|
||||
nir_metadata_preserve(impl, nir_metadata_all);
|
||||
}
|
||||
progress |= nir_function_intrinsics_pass(impl, pass, preserved, cb_data);
|
||||
}
|
||||
|
||||
return progress;
|
||||
|
||||
Reference in New Issue
Block a user