From: Jason Ekstrand Date: Mon, 11 Jan 2016 18:27:47 +0000 (-0800) Subject: nir/dead_variables: Add a a mode parameter X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=83bf1f752dbd80722174d9df203fff1e1794e35d;p=mesa.git nir/dead_variables: Add a a mode parameter This allows dead_variables to be used on any type of variable. --- diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h index a2c642ec6fc..6bbc7d123fc 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -2092,7 +2092,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 mode); void nir_move_vec_src_uses_to_dest(nir_shader *shader); bool nir_lower_vec_to_movs(nir_shader *shader); diff --git a/src/glsl/nir/nir_remove_dead_variables.c b/src/glsl/nir/nir_remove_dead_variables.c index db754e56b1c..792c5d4aae6 100644 --- a/src/glsl/nir/nir_remove_dead_variables.c +++ b/src/glsl/nir/nir_remove_dead_variables.c @@ -115,7 +115,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 mode) { bool progress = false; struct set *live = @@ -123,15 +123,30 @@ nir_remove_dead_variables(nir_shader *shader) add_var_use_shader(shader, live); - progress = remove_dead_vars(&shader->globals, live) || progress; + if (mode == nir_var_uniform || mode == nir_var_all) + 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 (mode == nir_var_shader_in || mode == nir_var_all) + progress = remove_dead_vars(&shader->inputs, live) || progress; + + if (mode == nir_var_shader_out || mode == nir_var_all) + progress = remove_dead_vars(&shader->outputs, live) || progress; + + if (mode == nir_var_global || mode == nir_var_all) + progress = remove_dead_vars(&shader->globals, live) || progress; + + if (mode == nir_var_system_value || mode == nir_var_all) + progress = remove_dead_vars(&shader->system_values, live) || progress; + + if (mode == nir_var_local || mode == nir_var_all) { + 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; + } } } } diff --git a/src/mesa/drivers/dri/i965/brw_nir.c b/src/mesa/drivers/dri/i965/brw_nir.c index f8b258bf96c..28870b05e9d 100644 --- a/src/mesa/drivers/dri/i965/brw_nir.c +++ b/src/mesa/drivers/dri/i965/brw_nir.c @@ -484,7 +484,7 @@ brw_preprocess_nir(nir_shader *nir, bool is_scalar) /* 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; }