Rename nir_lower_constant_initializers to nir_lower_variable_initalizers
authorArcady Goldmints-Orlov <agoldmints@igalia.com>
Fri, 7 Feb 2020 20:18:49 +0000 (14:18 -0600)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 12 Feb 2020 15:41:49 +0000 (15:41 +0000)
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 <caio.oliveira@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3047>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3047>

13 files changed:
src/amd/vulkan/radv_shader.c
src/compiler/Makefile.sources
src/compiler/glsl/glsl_to_nir.cpp
src/compiler/nir/meson.build
src/compiler/nir/nir.h
src/compiler/nir/nir_inline_functions.c
src/compiler/nir/nir_lower_constant_initializers.c [deleted file]
src/compiler/nir/nir_lower_variable_initializers.c [new file with mode: 0644]
src/compiler/spirv/spirv_to_nir.c
src/freedreno/vulkan/tu_shader.c
src/gallium/state_trackers/clover/nir/invocation.cpp
src/intel/vulkan/anv_pipeline.c
src/mesa/main/glspirv.c

index 7a41364698719c1a85e2e673a32d622e69f96c16..f20a8849c8a77f9fda815063254ea92420921d5c 100644 (file)
@@ -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.
index 1b10e3e4bb7e5daea345cc4e0004add743744d70..a21d6d25ae3da732e72ba871718afb334b313616 100644 (file)
@@ -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 \
index fdc14bfe507110ea99c4b1e82d94e1e440dddd5a..fed456a36ea90714e80d1cef5ab0e322006b8d5b 100644 (file)
@@ -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);
index 315112759e920891836ebf99035f655cf5a88e83..8101dc8c87096dd63f58e04664c970fd8f6cbac3 100644 (file)
@@ -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',
index 969fbac60e5c4b0dd1b60ca392a3c55d4eaccdb9..4939240653baea56a54a957337aaa9a053f85d51 100644 (file)
@@ -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);
index 8226d50b44b10b448341bd0e99f957b7a8c6b031..b1f83d6e03f9547363536a51f968c44c734a4f32 100644 (file)
@@ -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 (file)
index 03f5a2f..0000000
+++ /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 (file)
index 0000000..b2a17d0
--- /dev/null
@@ -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;
+}
index 22cbaf4145a7eb7d1dd905173240e34a2668eead..a3b9c5f6c7ebc008ba2a4646a7f2c7c01651d0fb 100644 (file)
@@ -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);
 
index 323a244e81ab61342ccc2230491cfee349b327a8..9df70400449cc310416f374448534e9686069d00 100644 (file)
@@ -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.
index 0522115a58d27ba20625edac8d6e0fe5fe3061db..87a98046cc1f72b6be40cf824fb50803f86eb2d0 100644 (file)
@@ -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_variable_mode>(~nir_var_function_temp));
 
       // copy propagate to prepare for lower_explicit_io
index 2e822a6aba63c7bf1de9c84a03be342615a7ff31..e6958c40ce674e3c9f68c53b576eb125c1b9f961 100644 (file)
@@ -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.
index 08886954d33a852d9e6b89ec291c33c7a2a7afaf..4a8165fa4e16ae937df26223a281d52d355ea5d7 100644 (file)
@@ -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);