nir/dead_variables: Configurably work with any variable mode
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 25 Mar 2016 21:26:11 +0000 (14:26 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 13 Apr 2016 22:45:10 +0000 (15:45 -0700)
The old version of the pass only worked on globals and locals and always
left inputs, outputs, uniforms, etc. alone.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir.h
src/compiler/nir/nir_remove_dead_variables.c
src/gallium/drivers/freedreno/ir3/ir3_nir.c
src/gallium/drivers/vc4/vc4_program.c
src/mesa/drivers/dri/i965/brw_nir.c

index ca19c0ae4e9ea11821c364f03a6e98fab8bc4d73..4a66e8b0d3e31fff979167cf70066604d5dc9755 100644 (file)
@@ -2205,7 +2205,7 @@ nir_src *nir_get_io_vertex_index_src(nir_intrinsic_instr *instr);
 
 void nir_lower_vars_to_ssa(nir_shader *shader);
 
-bool nir_remove_dead_variables(nir_shader *shader);
+bool nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes);
 
 void nir_move_vec_src_uses_to_dest(nir_shader *shader);
 bool nir_lower_vec_to_movs(nir_shader *shader);
index 65192682d3c8e61954888631c3a1580e4faeca35..7395805d7a22eab42836f71367b641b392351523 100644 (file)
@@ -120,7 +120,7 @@ remove_dead_vars(struct exec_list *var_list, struct set *live)
 }
 
 bool
-nir_remove_dead_variables(nir_shader *shader)
+nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes)
 {
    bool progress = false;
    struct set *live =
@@ -128,15 +128,30 @@ nir_remove_dead_variables(nir_shader *shader)
 
    add_var_use_shader(shader, live);
 
-   progress = remove_dead_vars(&shader->globals, live) || progress;
+   if (modes & nir_var_uniform)
+      progress = remove_dead_vars(&shader->uniforms, live) || progress;
 
-   nir_foreach_function(shader, function) {
-      if (function->impl) {
-         if (remove_dead_vars(&function->impl->locals, live)) {
-            nir_metadata_preserve(function->impl, nir_metadata_block_index |
-                                                  nir_metadata_dominance |
-                                                  nir_metadata_live_ssa_defs);
-            progress = true;
+   if (modes & nir_var_shader_in)
+      progress = remove_dead_vars(&shader->inputs, live) || progress;
+
+   if (modes & nir_var_shader_out)
+      progress = remove_dead_vars(&shader->outputs, live) || progress;
+
+   if (modes & nir_var_global)
+      progress = remove_dead_vars(&shader->globals, live) || progress;
+
+   if (modes & nir_var_system_value)
+      progress = remove_dead_vars(&shader->system_values, live) || progress;
+
+   if (modes & nir_var_local) {
+      nir_foreach_function(shader, function) {
+         if (function->impl) {
+            if (remove_dead_vars(&function->impl->locals, live)) {
+               nir_metadata_preserve(function->impl, nir_metadata_block_index |
+                                                     nir_metadata_dominance |
+                                                     nir_metadata_live_ssa_defs);
+               progress = true;
+            }
          }
       }
    }
index b3b6346c8a5f0616d7d3abe247e956d856e90f72..897b3b963becd2dd98d1f2d7501790451d9bb5bc 100644 (file)
@@ -142,7 +142,7 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s,
 
        } while (progress);
 
-       OPT_V(s, nir_remove_dead_variables);
+       OPT_V(s, nir_remove_dead_variables, nir_var_local);
 
        if (fd_mesa_debug & FD_DBG_DISASM) {
                debug_printf("----------------------\n");
index ca293bee182f8bf336bcb795de810dda103d2305..eccc7ab413f919fe424572f4aae74f79471ceda9 100644 (file)
@@ -1910,7 +1910,7 @@ vc4_shader_ntq(struct vc4_context *vc4, enum qstage stage,
 
         vc4_optimize_nir(c->s);
 
-        NIR_PASS_V(c->s, nir_remove_dead_variables);
+        NIR_PASS_V(c->s, nir_remove_dead_variables, nir_var_local);
         NIR_PASS_V(c->s, nir_convert_from_ssa, true);
 
         if (vc4_debug & VC4_DEBUG_SHADERDB) {
index 932979a77199f8b2539c31e371867297db5afd9a..fb7fa23586101a77d07bd00240ecf9a01e642710 100644 (file)
@@ -473,7 +473,7 @@ brw_preprocess_nir(const struct brw_compiler *compiler, nir_shader *nir)
    /* Get rid of split copies */
    nir = nir_optimize(nir, is_scalar);
 
-   OPT(nir_remove_dead_variables);
+   OPT(nir_remove_dead_variables, nir_var_local);
 
    return nir;
 }