From: Arcady Goldmints-Orlov Date: Fri, 7 Feb 2020 20:18:49 +0000 (-0600) Subject: Rename nir_lower_constant_initializers to nir_lower_variable_initalizers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e9f83185a221b446717c96c4df8dc64ced43e24f;p=mesa.git Rename nir_lower_constant_initializers to nir_lower_variable_initalizers This is naming is more clear as nir_variables can be initializes not just with a nir_constant but with a pointer to another nir_variable. Reviewed-by: Caio Marcelo de Oliveira Filho Tested-by: Marge Bot Part-of: --- diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 7a413646987..f20a8849c8a 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -402,7 +402,7 @@ radv_shader_compile_to_nir(struct radv_device *device, * inline functions. That way they get properly initialized at the top * of the function and not at the top of its caller. */ - NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp); + NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp); NIR_PASS_V(nir, nir_lower_returns); NIR_PASS_V(nir, nir_inline_functions); NIR_PASS_V(nir, nir_opt_deref); @@ -419,12 +419,12 @@ radv_shader_compile_to_nir(struct radv_device *device, /* Make sure we lower constant initializers on output variables so that * nir_remove_dead_variables below sees the corresponding stores */ - NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_shader_out); + NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_shader_out); /* Now that we've deleted all but the main function, we can go ahead and * lower the rest of the constant initializers. */ - NIR_PASS_V(nir, nir_lower_constant_initializers, ~0); + NIR_PASS_V(nir, nir_lower_variable_initializers, ~0); /* Split member structs. We do this before lower_io_to_temporaries so that * it doesn't lower system values to temporaries by accident. diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources index 1b10e3e4bb7..a21d6d25ae3 100644 --- a/src/compiler/Makefile.sources +++ b/src/compiler/Makefile.sources @@ -243,7 +243,7 @@ NIR_FILES = \ nir/nir_lower_clip.c \ nir/nir_lower_clip_cull_distance_arrays.c \ nir/nir_lower_clip_halfz.c \ - nir/nir_lower_constant_initializers.c \ + nir/nir_lower_variable_initializers.c \ nir/nir_lower_double_ops.c \ nir/nir_lower_drawpixels.c \ nir/nir_lower_fb_read.c \ diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index fdc14bfe507..fed456a36ea 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -219,7 +219,7 @@ glsl_to_nir(struct gl_context *ctx, * inline functions. That way they get properly initialized at the top * of the function and not at the top of its caller. */ - nir_lower_constant_initializers(shader, (nir_variable_mode)~0); + nir_lower_variable_initializers(shader, (nir_variable_mode)~0); nir_lower_returns(shader); nir_inline_functions(shader); nir_opt_deref(shader); @@ -2784,7 +2784,7 @@ glsl_float64_funcs_to_nir(struct gl_context *ctx, nir_validate_shader(nir, "float64_funcs_to_nir"); - NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp); + NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp); NIR_PASS_V(nir, nir_lower_returns); NIR_PASS_V(nir, nir_inline_functions); NIR_PASS_V(nir, nir_opt_deref); diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build index 315112759e9..8101dc8c870 100644 --- a/src/compiler/nir/meson.build +++ b/src/compiler/nir/meson.build @@ -124,7 +124,7 @@ files_libnir = files( 'nir_lower_clip.c', 'nir_lower_clip_cull_distance_arrays.c', 'nir_lower_clip_halfz.c', - 'nir_lower_constant_initializers.c', + 'nir_lower_variable_initializers.c', 'nir_lower_double_ops.c', 'nir_lower_drawpixels.c', 'nir_lower_fb_read.c', diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 969fbac60e5..4939240653b 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3848,7 +3848,7 @@ bool nir_lower_vars_to_ssa(nir_shader *shader); bool nir_remove_dead_derefs(nir_shader *shader); bool nir_remove_dead_derefs_impl(nir_function_impl *impl); bool nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes); -bool nir_lower_constant_initializers(nir_shader *shader, +bool nir_lower_variable_initializers(nir_shader *shader, nir_variable_mode modes); bool nir_move_vec_src_uses_to_dest(nir_shader *shader); diff --git a/src/compiler/nir/nir_inline_functions.c b/src/compiler/nir/nir_inline_functions.c index 8226d50b44b..b1f83d6e03f 100644 --- a/src/compiler/nir/nir_inline_functions.c +++ b/src/compiler/nir/nir_inline_functions.c @@ -158,7 +158,7 @@ inline_function_impl(nir_function_impl *impl, struct set *inlined) * For most use-cases, function inlining is a multi-step process. The general * pattern employed by SPIR-V consumers and others is as follows: * - * 1. nir_lower_constant_initializers(shader, nir_var_function_temp) + * 1. nir_lower_variable_initializers(shader, nir_var_function_temp) * * This is needed because local variables from the callee are simply added * to the locals list for the caller and the information about where the @@ -213,7 +213,7 @@ inline_function_impl(nir_function_impl *impl, struct set *inlined) * spirv_to_nir returns the root function and so we can just use == whereas * with GL, you may have to look for a function named "main". * - * 6. nir_lower_constant_initializers(shader, ~nir_var_function_temp) + * 6. nir_lower_variable_initializers(shader, ~nir_var_function_temp) * * Lowering constant initializers on inputs, outputs, global variables, * etc. requires that we know the main entrypoint so that we know where to diff --git a/src/compiler/nir/nir_lower_constant_initializers.c b/src/compiler/nir/nir_lower_constant_initializers.c deleted file mode 100644 index 03f5a2f404c..00000000000 --- a/src/compiler/nir/nir_lower_constant_initializers.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright © 2016 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include "nir.h" -#include "nir_builder.h" - -static void -build_constant_load(nir_builder *b, nir_deref_instr *deref, nir_constant *c) -{ - if (glsl_type_is_vector_or_scalar(deref->type)) { - nir_load_const_instr *load = - nir_load_const_instr_create(b->shader, - glsl_get_vector_elements(deref->type), - glsl_get_bit_size(deref->type)); - memcpy(load->value, c->values, sizeof(*load->value) * load->def.num_components); - nir_builder_instr_insert(b, &load->instr); - nir_store_deref(b, deref, &load->def, ~0); - } else if (glsl_type_is_struct_or_ifc(deref->type)) { - unsigned len = glsl_get_length(deref->type); - for (unsigned i = 0; i < len; i++) { - build_constant_load(b, nir_build_deref_struct(b, deref, i), - c->elements[i]); - } - } else { - assert(glsl_type_is_array(deref->type) || - glsl_type_is_matrix(deref->type)); - unsigned len = glsl_get_length(deref->type); - for (unsigned i = 0; i < len; i++) { - build_constant_load(b, - nir_build_deref_array_imm(b, deref, i), - c->elements[i]); - } - } -} - -static bool -lower_const_initializer(struct nir_builder *b, struct exec_list *var_list) -{ - bool progress = false; - - b->cursor = nir_before_cf_list(&b->impl->body); - - nir_foreach_variable(var, var_list) { - if (var->constant_initializer) { - build_constant_load(b, nir_build_deref_var(b, var), - var->constant_initializer); - - progress = true; - var->constant_initializer = NULL; - } else if (var->pointer_initializer) { - nir_deref_instr *src_deref = nir_build_deref_var(b, var->pointer_initializer); - nir_deref_instr *dst_deref = nir_build_deref_var(b, var); - - /* Note that this stores a pointer to src into dst */ - nir_store_deref(b, dst_deref, &src_deref->dest.ssa, ~0); - - progress = true; - var->pointer_initializer = NULL; - } - - } - - return progress; -} - -bool -nir_lower_constant_initializers(nir_shader *shader, nir_variable_mode modes) -{ - bool progress = false; - - nir_foreach_function(function, shader) { - if (!function->impl) - continue; - - bool impl_progress = false; - - nir_builder builder; - nir_builder_init(&builder, function->impl); - - if ((modes & nir_var_shader_out) && function->is_entrypoint) - impl_progress |= lower_const_initializer(&builder, &shader->outputs); - - if ((modes & nir_var_shader_temp) && function->is_entrypoint) - impl_progress |= lower_const_initializer(&builder, &shader->globals); - - if ((modes & nir_var_system_value) && function->is_entrypoint) - impl_progress |= lower_const_initializer(&builder, &shader->system_values); - - if (modes & nir_var_function_temp) - impl_progress |= lower_const_initializer(&builder, &function->impl->locals); - - if (impl_progress) { - progress = true; - nir_metadata_preserve(function->impl, nir_metadata_block_index | - nir_metadata_dominance | - nir_metadata_live_ssa_defs); - } else { -#ifndef NDEBUG - function->impl->valid_metadata &= ~nir_metadata_not_properly_reset; -#endif - } - } - - return progress; -} diff --git a/src/compiler/nir/nir_lower_variable_initializers.c b/src/compiler/nir/nir_lower_variable_initializers.c new file mode 100644 index 00000000000..b2a17d0584b --- /dev/null +++ b/src/compiler/nir/nir_lower_variable_initializers.c @@ -0,0 +1,125 @@ +/* + * Copyright © 2016 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "nir.h" +#include "nir_builder.h" + +static void +build_constant_load(nir_builder *b, nir_deref_instr *deref, nir_constant *c) +{ + if (glsl_type_is_vector_or_scalar(deref->type)) { + nir_load_const_instr *load = + nir_load_const_instr_create(b->shader, + glsl_get_vector_elements(deref->type), + glsl_get_bit_size(deref->type)); + memcpy(load->value, c->values, sizeof(*load->value) * load->def.num_components); + nir_builder_instr_insert(b, &load->instr); + nir_store_deref(b, deref, &load->def, ~0); + } else if (glsl_type_is_struct_or_ifc(deref->type)) { + unsigned len = glsl_get_length(deref->type); + for (unsigned i = 0; i < len; i++) { + build_constant_load(b, nir_build_deref_struct(b, deref, i), + c->elements[i]); + } + } else { + assert(glsl_type_is_array(deref->type) || + glsl_type_is_matrix(deref->type)); + unsigned len = glsl_get_length(deref->type); + for (unsigned i = 0; i < len; i++) { + build_constant_load(b, + nir_build_deref_array_imm(b, deref, i), + c->elements[i]); + } + } +} + +static bool +lower_const_initializer(struct nir_builder *b, struct exec_list *var_list) +{ + bool progress = false; + + b->cursor = nir_before_cf_list(&b->impl->body); + + nir_foreach_variable(var, var_list) { + if (var->constant_initializer) { + build_constant_load(b, nir_build_deref_var(b, var), + var->constant_initializer); + + progress = true; + var->constant_initializer = NULL; + } else if (var->pointer_initializer) { + nir_deref_instr *src_deref = nir_build_deref_var(b, var->pointer_initializer); + nir_deref_instr *dst_deref = nir_build_deref_var(b, var); + + /* Note that this stores a pointer to src into dst */ + nir_store_deref(b, dst_deref, &src_deref->dest.ssa, ~0); + + progress = true; + var->pointer_initializer = NULL; + } + + } + + return progress; +} + +bool +nir_lower_variable_initializers(nir_shader *shader, nir_variable_mode modes) +{ + bool progress = false; + + nir_foreach_function(function, shader) { + if (!function->impl) + continue; + + bool impl_progress = false; + + nir_builder builder; + nir_builder_init(&builder, function->impl); + + if ((modes & nir_var_shader_out) && function->is_entrypoint) + impl_progress |= lower_const_initializer(&builder, &shader->outputs); + + if ((modes & nir_var_shader_temp) && function->is_entrypoint) + impl_progress |= lower_const_initializer(&builder, &shader->globals); + + if ((modes & nir_var_system_value) && function->is_entrypoint) + impl_progress |= lower_const_initializer(&builder, &shader->system_values); + + if (modes & nir_var_function_temp) + impl_progress |= lower_const_initializer(&builder, &function->impl->locals); + + if (impl_progress) { + progress = true; + nir_metadata_preserve(function->impl, nir_metadata_block_index | + nir_metadata_dominance | + nir_metadata_live_ssa_defs); + } else { +#ifndef NDEBUG + function->impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } + } + + return progress; +} diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 22cbaf4145a..a3b9c5f6c7e 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -5388,7 +5388,7 @@ spirv_to_nir(const uint32_t *words, size_t word_count, * right away. In order to do so, we must lower any constant initializers * on outputs so nir_remove_dead_variables sees that they're written to. */ - nir_lower_constant_initializers(b->shader, nir_var_shader_out); + nir_lower_variable_initializers(b->shader, nir_var_shader_out); nir_remove_dead_variables(b->shader, nir_var_shader_in | nir_var_shader_out); diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c index 323a244e81a..9df70400449 100644 --- a/src/freedreno/vulkan/tu_shader.c +++ b/src/freedreno/vulkan/tu_shader.c @@ -414,7 +414,7 @@ tu_shader_create(struct tu_device *dev, } /* multi step inlining procedure */ - NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp); + NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp); NIR_PASS_V(nir, nir_lower_returns); NIR_PASS_V(nir, nir_inline_functions); NIR_PASS_V(nir, nir_opt_deref); @@ -423,7 +423,7 @@ tu_shader_create(struct tu_device *dev, exec_node_remove(&func->node); } assert(exec_list_length(&nir->functions) == 1); - NIR_PASS_V(nir, nir_lower_constant_initializers, ~nir_var_function_temp); + NIR_PASS_V(nir, nir_lower_variable_initializers, ~nir_var_function_temp); /* Split member structs. We do this before lower_io_to_temporaries so that * it doesn't lower system values to temporaries by accident. diff --git a/src/gallium/state_trackers/clover/nir/invocation.cpp b/src/gallium/state_trackers/clover/nir/invocation.cpp index 0522115a58d..87a98046cc1 100644 --- a/src/gallium/state_trackers/clover/nir/invocation.cpp +++ b/src/gallium/state_trackers/clover/nir/invocation.cpp @@ -104,7 +104,7 @@ module clover::nir::spirv_to_nir(const module &mod, const device &dev, // Inline all functions first. // according to the comment on nir_inline_functions - NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp); + NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp); NIR_PASS_V(nir, nir_lower_returns); NIR_PASS_V(nir, nir_inline_functions); NIR_PASS_V(nir, nir_opt_deref); @@ -118,7 +118,7 @@ module clover::nir::spirv_to_nir(const module &mod, const device &dev, nir_validate_shader(nir, "clover after function inlining"); - NIR_PASS_V(nir, nir_lower_constant_initializers, + NIR_PASS_V(nir, nir_lower_variable_initializers, static_cast(~nir_var_function_temp)); // copy propagate to prepare for lower_explicit_io diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 2e822a6aba6..e6958c40ce6 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -250,7 +250,7 @@ anv_shader_compile_to_nir(struct anv_device *device, * inline functions. That way they get properly initialized at the top * of the function and not at the top of its caller. */ - NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp); + NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp); NIR_PASS_V(nir, nir_lower_returns); NIR_PASS_V(nir, nir_inline_functions); NIR_PASS_V(nir, nir_opt_deref); @@ -267,7 +267,7 @@ anv_shader_compile_to_nir(struct anv_device *device, * nir_remove_dead_variables and split_per_member_structs below see the * corresponding stores. */ - NIR_PASS_V(nir, nir_lower_constant_initializers, ~0); + NIR_PASS_V(nir, nir_lower_variable_initializers, ~0); /* Split member structs. We do this before lower_io_to_temporaries so that * it doesn't lower system values to temporaries by accident. diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c index 08886954d33..4a8165fa4e1 100644 --- a/src/mesa/main/glspirv.c +++ b/src/mesa/main/glspirv.c @@ -284,7 +284,7 @@ _mesa_spirv_to_nir(struct gl_context *ctx, * inline functions. That way they get properly initialized at the top * of the function and not at the top of its caller. */ - NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp); + NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp); NIR_PASS_V(nir, nir_lower_returns); NIR_PASS_V(nir, nir_inline_functions); NIR_PASS_V(nir, nir_opt_deref);