nir: add nir_lower_constant_to_temp helper

this comes up with clc.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32382>
This commit is contained in:
Alyssa Rosenzweig 2024-11-25 07:56:57 -05:00 committed by Marge Bot
parent 12cc22af4c
commit c2973765e2
2 changed files with 19 additions and 0 deletions

View file

@ -5561,6 +5561,7 @@ void nir_fixup_deref_modes(nir_shader *shader);
void nir_fixup_deref_types(nir_shader *shader);
bool nir_lower_global_vars_to_local(nir_shader *shader);
void nir_lower_constant_to_temp(nir_shader *shader);
typedef enum {
nir_lower_direct_array_deref_of_vec_load = (1 << 0),

View file

@ -1561,3 +1561,21 @@ nir_opt_deref(nir_shader *shader)
return progress;
}
/*
* With library-based approaches to driver shaders, it may not be possible to
* implement constant_data directly, but LLVM loves to produce constants e.g.
* for designated initializers. This helper lowers away constant data. This may
* allow additional optimizations. If desired, the backend driver can regather
* constant data later with nir_opt_large_constants.
*/
void
nir_lower_constant_to_temp(nir_shader *nir)
{
nir_foreach_variable_with_modes(var, nir, nir_var_mem_constant) {
var->data.mode = nir_var_shader_temp;
}
nir_fixup_deref_modes(nir);
nir_lower_global_vars_to_local(nir);
}