nir: Split nir_index_vars into two functions

We also very slightly change the semantics.  It no longer is one index
per list for global variables and is a single index over-all.

Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5966>
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 3d0fd42..a9fe16f 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -1821,36 +1821,43 @@
 }
 
 static void
-index_var_list(struct exec_list *list)
+index_var_list(struct exec_list *list, unsigned *count)
 {
-   unsigned next_index = 0;
    nir_foreach_variable(var, list)
-      var->index = next_index++;
+      var->index = (*count)++;
 }
 
-void
-nir_index_vars(nir_shader *shader, nir_function_impl *impl, nir_variable_mode modes)
+unsigned
+nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes)
 {
-   if ((modes & nir_var_function_temp) && impl)
-      index_var_list(&impl->locals);
-
+   unsigned count = 0;
    if (modes & nir_var_shader_temp)
-      index_var_list(&shader->globals);
+      index_var_list(&shader->globals, &count);
 
    if (modes & nir_var_shader_in)
-      index_var_list(&shader->inputs);
+      index_var_list(&shader->inputs, &count);
 
    if (modes & nir_var_shader_out)
-      index_var_list(&shader->outputs);
+      index_var_list(&shader->outputs, &count);
 
    if (modes & (nir_var_uniform | nir_var_mem_ubo | nir_var_mem_ssbo))
-      index_var_list(&shader->uniforms);
+      index_var_list(&shader->uniforms, &count);
 
    if (modes & nir_var_mem_shared)
-      index_var_list(&shader->shared);
+      index_var_list(&shader->shared, &count);
 
    if (modes & nir_var_system_value)
-      index_var_list(&shader->system_values);
+      index_var_list(&shader->system_values, &count);
+
+   return count;
+}
+
+unsigned
+nir_function_impl_index_vars(nir_function_impl *impl)
+{
+   unsigned count = 0;
+   index_var_list(&impl->locals, &count);
+   return count;
 }
 
 static nir_instr *
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index dca1959..f131e0b 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -3737,7 +3737,8 @@
 
 void nir_index_blocks(nir_function_impl *impl);
 
-void nir_index_vars(nir_shader *shader, nir_function_impl *impl, nir_variable_mode modes);
+unsigned nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes);
+unsigned nir_function_impl_index_vars(nir_function_impl *impl);
 
 void nir_print_shader(nir_shader *shader, FILE *fp);
 void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table *errors);
diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c
index 2575407..25c4029 100644
--- a/src/compiler/nir/nir_opt_large_constants.c
+++ b/src/compiler/nir/nir_opt_large_constants.c
@@ -176,8 +176,7 @@
    /* This pass can only be run once */
    assert(shader->constant_data == NULL && shader->constant_data_size == 0);
 
-   unsigned num_locals = exec_list_length(&impl->locals);
-   nir_index_vars(shader, impl, nir_var_function_temp);
+   unsigned num_locals = nir_function_impl_index_vars(impl);
 
    if (num_locals == 0) {
       nir_shader_preserve_all_metadata(shader);
diff --git a/src/compiler/nir/nir_opt_load_store_vectorize.c b/src/compiler/nir/nir_opt_load_store_vectorize.c
index 7777a63..f9b6774 100644
--- a/src/compiler/nir/nir_opt_load_store_vectorize.c
+++ b/src/compiler/nir/nir_opt_load_store_vectorize.c
@@ -1359,12 +1359,12 @@
    ctx->callback = callback;
    ctx->robust_modes = robust_modes;
 
-   nir_index_vars(shader, NULL, modes);
+   nir_shader_index_vars(shader, modes);
 
    nir_foreach_function(function, shader) {
       if (function->impl) {
          if (modes & nir_var_function_temp)
-            nir_index_vars(shader, function->impl, nir_var_function_temp);
+            nir_function_impl_index_vars(function->impl);
 
          nir_foreach_block(block, function->impl)
             progress |= process_block(function->impl, ctx, block);