nir: add nir_var_shader_storage
[mesa.git] / src / glsl / nir / nir_remove_dead_variables.c
index e37535f798878ed99f1fee52348efc47a751f668..4417e2a48839008a6ca040365426284c1c00ca6e 100644 (file)
@@ -63,7 +63,7 @@ add_var_use_tex(nir_tex_instr *instr, struct set *live)
 static bool
 add_var_use_block(nir_block *block, void *state)
 {
-   struct set *live = (struct set *) state;
+   struct set *live = state;
 
    nir_foreach_instr(block, instr) {
       switch(instr->type) {
@@ -98,22 +98,14 @@ add_var_use_shader(nir_shader *shader, struct set *live)
 }
 
 static void
-remove_dead_local_vars(nir_function_impl *impl, struct set *live)
+remove_dead_vars(struct exec_list *var_list, struct set *live)
 {
-   foreach_list_typed_safe(nir_variable, var, node, &impl->locals) {
+   foreach_list_typed_safe(nir_variable, var, node, var_list) {
       struct set_entry *entry = _mesa_set_search(live, var);
-      if (entry == NULL)
-         exec_node_remove(&var->node);
-   }
-}
-
-static void
-remove_dead_global_vars(nir_shader *shader, struct set *live)
-{
-   foreach_list_typed_safe(nir_variable, var, node, &shader->globals) {
-      struct set_entry *entry = _mesa_set_search(live, var);
-      if (entry == NULL)
+      if (entry == NULL) {
          exec_node_remove(&var->node);
+         ralloc_free(var);
+      }
    }
 }
 
@@ -125,11 +117,11 @@ nir_remove_dead_variables(nir_shader *shader)
 
    add_var_use_shader(shader, live);
 
-   remove_dead_global_vars(shader, live);
+   remove_dead_vars(&shader->globals, live);
 
    nir_foreach_overload(shader, overload) {
       if (overload->impl)
-         remove_dead_local_vars(overload->impl, live);
+         remove_dead_vars(&overload->impl->locals, live);
    }
 
    _mesa_set_destroy(live, NULL);