From: Jason Ekstrand Date: Fri, 22 May 2020 03:34:37 +0000 (-0500) Subject: nir: Properly preserve metadata in more cases X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2b676b2ce87520042ffb1fae8a9c0d97ba0e3cbc;p=mesa.git nir: Properly preserve metadata in more cases Reviewed-by: Alyssa Rosenzweig Reviewed-by: Kenneth Graunke Part-of: --- diff --git a/src/compiler/glsl/gl_nir_lower_images.c b/src/compiler/glsl/gl_nir_lower_images.c index 7dbefc36d0f..5b51c3aa03c 100644 --- a/src/compiler/glsl/gl_nir_lower_images.c +++ b/src/compiler/glsl/gl_nir_lower_images.c @@ -107,9 +107,19 @@ gl_nir_lower_images(nir_shader *shader, bool bindless_only) nir_builder b; nir_builder_init(&b, function->impl); + bool impl_progress = false; nir_foreach_block(block, function->impl) nir_foreach_instr(instr, block) - progress |= lower_impl(&b, instr, bindless_only); + impl_progress |= lower_impl(&b, instr, bindless_only); + + if (impl_progress) { + nir_metadata_preserve(function->impl, + nir_metadata_block_index | + nir_metadata_dominance); + progress = true; + } else { + nir_metadata_preserve(function->impl, nir_metadata_all); + } } } diff --git a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c index 49a06cfabb6..384f4a4d284 100644 --- a/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c +++ b/src/compiler/glsl/gl_nir_lower_samplers_as_deref.c @@ -331,6 +331,13 @@ lower_impl(nir_function_impl *impl, struct lower_samplers_as_deref_state *state) } } + if (progress) { + nir_metadata_preserve(impl, nir_metadata_block_index | + nir_metadata_dominance); + } else { + nir_metadata_preserve(impl, nir_metadata_all); + } + return progress; } diff --git a/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c b/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c index 7587bb26e09..390eded7b01 100644 --- a/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c +++ b/src/compiler/nir/nir_lower_clip_cull_distance_arrays.c @@ -116,16 +116,6 @@ combine_clip_cull(nir_shader *nir, cull->data.location_frac = clip_array_size % 4; } - nir_foreach_function(function, nir) { - if (function->impl) { - nir_metadata_preserve(function->impl, - nir_metadata_block_index | - nir_metadata_dominance | - nir_metadata_live_ssa_defs | - nir_metadata_loop_analysis); - } - } - return true; } @@ -140,5 +130,20 @@ nir_lower_clip_cull_distance_arrays(nir_shader *nir) if (nir->info.stage > MESA_SHADER_VERTEX) progress |= combine_clip_cull(nir, &nir->inputs, false); + nir_foreach_function(function, nir) { + if (!function->impl) + continue; + + if (progress) { + nir_metadata_preserve(function->impl, + nir_metadata_block_index | + nir_metadata_dominance | + nir_metadata_live_ssa_defs | + nir_metadata_loop_analysis); + } else { + nir_metadata_preserve(function->impl, nir_metadata_all); + } + } + return progress; } diff --git a/src/compiler/nir/nir_lower_samplers.c b/src/compiler/nir/nir_lower_samplers.c index b60e6aa63b7..3eb69bcd5de 100644 --- a/src/compiler/nir/nir_lower_samplers.c +++ b/src/compiler/nir/nir_lower_samplers.c @@ -133,6 +133,13 @@ lower_impl(nir_function_impl *impl) } } + if (progress) { + nir_metadata_preserve(impl, nir_metadata_block_index | + nir_metadata_dominance); + } else { + nir_metadata_preserve(impl, nir_metadata_all); + } + return progress; } diff --git a/src/compiler/nir/nir_opt_conditional_discard.c b/src/compiler/nir/nir_opt_conditional_discard.c index 781438df06e..3d5c255ee73 100644 --- a/src/compiler/nir/nir_opt_conditional_discard.c +++ b/src/compiler/nir/nir_opt_conditional_discard.c @@ -124,8 +124,18 @@ nir_opt_conditional_discard(nir_shader *shader) nir_foreach_function(function, shader) { if (function->impl) { nir_builder_init(&builder, function->impl); + + bool impl_progress = false; nir_foreach_block_safe(block, function->impl) { - progress |= nir_opt_conditional_discard_block(&builder, block); + if (nir_opt_conditional_discard_block(&builder, block)) + impl_progress = true; + } + + if (impl_progress) { + nir_metadata_preserve(function->impl, nir_metadata_none); + progress = true; + } else { + nir_metadata_preserve(function->impl, nir_metadata_all); } } } diff --git a/src/compiler/nir/nir_opt_large_constants.c b/src/compiler/nir/nir_opt_large_constants.c index 7ed26f51127..ef51c72b7b6 100644 --- a/src/compiler/nir/nir_opt_large_constants.c +++ b/src/compiler/nir/nir_opt_large_constants.c @@ -179,8 +179,10 @@ nir_opt_large_constants(nir_shader *shader, unsigned num_locals = exec_list_length(&impl->locals); nir_index_vars(shader, impl, nir_var_function_temp); - if (num_locals == 0) + if (num_locals == 0) { + nir_shader_preserve_all_metadata(shader); return false; + } struct var_info *var_infos = ralloc_array(NULL, struct var_info, num_locals); nir_foreach_variable(var, &impl->locals) { @@ -302,6 +304,7 @@ nir_opt_large_constants(nir_shader *shader, } if (shader->constant_data_size == 0) { + nir_shader_preserve_all_metadata(shader); ralloc_free(var_infos); return false; } diff --git a/src/compiler/nir/nir_opt_loop_unroll.c b/src/compiler/nir/nir_opt_loop_unroll.c index f8741ea6c50..c5e7b8c9b51 100644 --- a/src/compiler/nir/nir_opt_loop_unroll.c +++ b/src/compiler/nir/nir_opt_loop_unroll.c @@ -963,8 +963,12 @@ nir_opt_loop_unroll_impl(nir_function_impl *impl, progress |= process_loops_in_block(impl->function->shader, &impl->body, &has_nested_loop); - if (progress) + if (progress) { + nir_metadata_preserve(impl, nir_metadata_none); nir_lower_regs_to_ssa_impl(impl); + } else { + nir_metadata_preserve(impl, nir_metadata_all); + } return progress; } diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c index 4fbe035c024..6baa66a5767 100644 --- a/src/compiler/nir/nir_remove_dead_variables.c +++ b/src/compiler/nir/nir_remove_dead_variables.c @@ -213,14 +213,16 @@ nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes, } } - if (progress) { - remove_dead_var_writes(shader, live); + nir_foreach_function(function, shader) { + if (!function->impl) + continue; - nir_foreach_function(function, shader) { - if (function->impl) { - nir_metadata_preserve(function->impl, nir_metadata_block_index | - nir_metadata_dominance); - } + if (progress) { + remove_dead_var_writes(shader, live); + nir_metadata_preserve(function->impl, nir_metadata_block_index | + nir_metadata_dominance); + } else { + nir_metadata_preserve(function->impl, nir_metadata_all); } } diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c index 09dd4c341e4..577f0be0b92 100644 --- a/src/compiler/nir/nir_search.c +++ b/src/compiler/nir/nir_search.c @@ -913,8 +913,10 @@ nir_algebraic_impl(nir_function_impl *impl, * anything other than constants and ALU instructions. */ struct util_dynarray states = {0}; - if (!util_dynarray_resize(&states, uint16_t, impl->ssa_alloc)) + if (!util_dynarray_resize(&states, uint16_t, impl->ssa_alloc)) { + nir_metadata_preserve(impl, nir_metadata_all); return false; + } memset(states.data, 0, states.size); struct hash_table *range_ht = _mesa_pointer_hash_table_create(NULL); diff --git a/src/compiler/nir/nir_split_per_member_structs.c b/src/compiler/nir/nir_split_per_member_structs.c index 9148902b27c..478d5fe72c3 100644 --- a/src/compiler/nir/nir_split_per_member_structs.c +++ b/src/compiler/nir/nir_split_per_member_structs.c @@ -202,6 +202,10 @@ nir_split_per_member_structs(nir_shader *shader) } } } + + nir_metadata_preserve(function->impl, + nir_metadata_block_index | + nir_metadata_dominance); } ralloc_free(dead_ctx); diff --git a/src/compiler/nir/nir_split_vars.c b/src/compiler/nir/nir_split_vars.c index 93b5e15e8df..9cf4fba3d6b 100644 --- a/src/compiler/nir/nir_split_vars.c +++ b/src/compiler/nir/nir_split_vars.c @@ -887,6 +887,7 @@ nir_split_array_vars(nir_shader *shader, nir_variable_mode modes) /* If we failed to find any arrays of arrays, bail early. */ if (!has_any_array) { ralloc_free(mem_ctx); + nir_shader_preserve_all_metadata(shader); return false; } @@ -1634,6 +1635,7 @@ nir_shrink_vec_array_vars(nir_shader *shader, nir_variable_mode modes) } if (!has_vars_to_shrink) { ralloc_free(mem_ctx); + nir_shader_preserve_all_metadata(shader); return false; }