From c2973765e2ad537a1f3d13e82e2491aa8bee337d Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 25 Nov 2024 07:56:57 -0500 Subject: [PATCH] nir: add nir_lower_constant_to_temp helper this comes up with clc. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Konstantin Seurer Reviewed-by: Mary Guillemard Part-of: --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_deref.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index f3ec0c896b5..b8642dea24b 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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), diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 18d6e1cc556..e4c13f44b27 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -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); +}