nir/io_to_vector: Use nir_foreach_variable_with_modes
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 21 Jul 2020 16:13:04 +0000 (11:13 -0500)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Jul 2020 17:38:58 +0000 (17:38 +0000)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5966>

src/compiler/nir/nir_lower_io_to_vector.c

index b1ea871a402a794a48a3455b7f620fe02c99e536..022f9e2f7a23ad2651738e7e3a601df2ea71124f 100644 (file)
@@ -206,20 +206,22 @@ get_flat_type(const nir_shader *shader, nir_variable *old_vars[MAX_SLOTS][4],
 }
 
 static bool
-create_new_io_vars(nir_shader *shader, struct exec_list *io_list,
+create_new_io_vars(nir_shader *shader, nir_variable_mode mode,
                    nir_variable *new_vars[MAX_SLOTS][4],
                    bool flat_vars[MAX_SLOTS])
 {
-   if (exec_list_is_empty(io_list))
-      return false;
-
    nir_variable *old_vars[MAX_SLOTS][4] = {{0}};
 
-   nir_foreach_variable(var, io_list) {
+   bool has_io_var = false;
+   nir_foreach_variable_with_modes(var, shader, mode) {
       unsigned frac = var->data.location_frac;
       old_vars[get_slot(var)][frac] = var;
+      has_io_var = true;
    }
 
+   if (!has_io_var)
+      return false;
+
    bool merged_any_vars = false;
 
    for (unsigned loc = 0; loc < MAX_SLOTS; loc++) {
@@ -390,7 +392,7 @@ nir_lower_io_to_vector_impl(nir_function_impl *impl, nir_variable_mode modes)
       /* If we don't actually merge any variables, remove that bit from modes
        * so we don't bother doing extra non-work.
        */
-      if (!create_new_io_vars(shader, &shader->inputs,
+      if (!create_new_io_vars(shader, nir_var_shader_in,
                               new_inputs, flat_inputs))
          modes &= ~nir_var_shader_in;
    }
@@ -399,7 +401,7 @@ nir_lower_io_to_vector_impl(nir_function_impl *impl, nir_variable_mode modes)
       /* If we don't actually merge any variables, remove that bit from modes
        * so we don't bother doing extra non-work.
        */
-      if (!create_new_io_vars(shader, &shader->outputs,
+      if (!create_new_io_vars(shader, nir_var_shader_out,
                               new_outputs, flat_outputs))
          modes &= ~nir_var_shader_out;
    }