From 2623653126985be5aca1a29e24bdecb4bb42c8b4 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Mon, 10 Sep 2018 14:31:29 -0700 Subject: [PATCH] nir: Unset metadata debug bit if no progress made NIR metadata validation verifies that the debug bit was unset (by a call to nir_metadata_preserve) if a NIR optimization pass made progress on the shader. With the expectation that the NIR shader consists of only a single main function, it has been safe to call nir_metadata_preserve() iff progress was made. However, most optimization passes calculate progress per-function and then return the union of those calculations. In the case that an optimization pass makes progress only on a subset of the functions in the shader metadata validation will detect the debug bit is still set on any unchanged functions resulting in a failed assertion. This patch offers a quick solution (short of a larger scale refactoring which I do not wish to undertake as part of this series) that simply unsets the debug bit on unchanged functions. Reviewed-by: Kenneth Graunke Reviewed-by: Jason Ekstrand --- src/compiler/nir/nir_algebraic.py | 7 ++++++- src/compiler/nir/nir_deref.c | 4 ++++ src/compiler/nir/nir_inline_functions.c | 4 ++++ src/compiler/nir/nir_lower_constant_initializers.c | 4 ++++ src/compiler/nir/nir_lower_double_ops.c | 7 ++++++- src/compiler/nir/nir_lower_global_vars_to_local.c | 8 ++++++++ src/compiler/nir/nir_lower_int64.c | 7 ++++++- src/compiler/nir/nir_lower_load_const_to_scalar.c | 7 ++++++- src/compiler/nir/nir_lower_returns.c | 4 ++++ src/compiler/nir/nir_lower_var_copies.c | 7 ++++++- src/compiler/nir/nir_lower_vars_to_ssa.c | 6 +++++- src/compiler/nir/nir_opt_constant_folding.c | 7 ++++++- src/compiler/nir/nir_opt_copy_prop_vars.c | 4 ++++ src/compiler/nir/nir_opt_copy_propagate.c | 4 ++++ src/compiler/nir/nir_opt_cse.c | 7 ++++++- src/compiler/nir/nir_opt_dce.c | 7 ++++++- src/compiler/nir/nir_opt_dead_cf.c | 7 ++++++- src/compiler/nir/nir_opt_if.c | 4 ++++ src/compiler/nir/nir_opt_peephole_select.c | 7 ++++++- src/compiler/nir/nir_opt_remove_phis.c | 4 ++++ src/compiler/nir/nir_opt_undef.c | 7 ++++++- src/compiler/nir/nir_split_var_copies.c | 4 ++++ 22 files changed, 115 insertions(+), 12 deletions(-) diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index 2381272..fe9d105 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -731,9 +731,14 @@ ${pass_name}_impl(nir_function_impl *impl, const bool *condition_flags) progress |= ${pass_name}_block(&build, block, condition_flags); } - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 947888a..26de64c 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -721,6 +721,10 @@ nir_opt_deref_impl(nir_function_impl *impl) if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif } return progress; diff --git a/src/compiler/nir/nir_inline_functions.c b/src/compiler/nir/nir_inline_functions.c index dd2dfa0..74d39db 100644 --- a/src/compiler/nir/nir_inline_functions.c +++ b/src/compiler/nir/nir_inline_functions.c @@ -125,6 +125,10 @@ inline_function_impl(nir_function_impl *impl, struct set *inlined) nir_index_local_regs(impl); nir_metadata_preserve(impl, nir_metadata_none); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif } _mesa_set_add(inlined, impl); diff --git a/src/compiler/nir/nir_lower_constant_initializers.c b/src/compiler/nir/nir_lower_constant_initializers.c index b1c5183..cbee59b 100644 --- a/src/compiler/nir/nir_lower_constant_initializers.c +++ b/src/compiler/nir/nir_lower_constant_initializers.c @@ -117,6 +117,10 @@ nir_lower_constant_initializers(nir_shader *shader, nir_variable_mode modes) nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance | nir_metadata_live_ssa_defs); + } else { +#ifndef NDEBUG + function->impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif } } diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c index 48e0c80..4d4cdf6 100644 --- a/src/compiler/nir/nir_lower_double_ops.c +++ b/src/compiler/nir/nir_lower_double_ops.c @@ -754,9 +754,14 @@ nir_lower_doubles_impl(nir_function_impl *impl, } } - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_lower_global_vars_to_local.c b/src/compiler/nir/nir_lower_global_vars_to_local.c index 7cc1b2cb..1ca7c19 100644 --- a/src/compiler/nir/nir_lower_global_vars_to_local.c +++ b/src/compiler/nir/nir_lower_global_vars_to_local.c @@ -107,5 +107,13 @@ nir_lower_global_vars_to_local(nir_shader *shader) if (progress) nir_fixup_deref_modes(shader); +#ifndef NDEBUG + nir_foreach_function(function, shader) { + if (function->impl) { + function->impl->valid_metadata &= ~nir_metadata_not_properly_reset; + } + } +#endif + return progress; } diff --git a/src/compiler/nir/nir_lower_int64.c b/src/compiler/nir/nir_lower_int64.c index 1ec4816..1c4b4b3 100644 --- a/src/compiler/nir/nir_lower_int64.c +++ b/src/compiler/nir/nir_lower_int64.c @@ -830,8 +830,13 @@ lower_int64_impl(nir_function_impl *impl, nir_lower_int64_options options) } } - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_none); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_lower_load_const_to_scalar.c b/src/compiler/nir/nir_lower_load_const_to_scalar.c index b62d32e..a821a77 100644 --- a/src/compiler/nir/nir_lower_load_const_to_scalar.c +++ b/src/compiler/nir/nir_lower_load_const_to_scalar.c @@ -95,9 +95,14 @@ nir_lower_load_const_to_scalar_impl(nir_function_impl *impl) } } - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_lower_returns.c b/src/compiler/nir/nir_lower_returns.c index 292671e..e166a7c 100644 --- a/src/compiler/nir/nir_lower_returns.c +++ b/src/compiler/nir/nir_lower_returns.c @@ -274,6 +274,10 @@ nir_lower_returns_impl(nir_function_impl *impl) if (progress) { nir_metadata_preserve(impl, nir_metadata_none); nir_repair_ssa_impl(impl); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif } return progress; diff --git a/src/compiler/nir/nir_lower_var_copies.c b/src/compiler/nir/nir_lower_var_copies.c index e72f7ef..1e7ad78 100644 --- a/src/compiler/nir/nir_lower_var_copies.c +++ b/src/compiler/nir/nir_lower_var_copies.c @@ -140,9 +140,14 @@ lower_var_copies_impl(nir_function_impl *impl) } } - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_lower_vars_to_ssa.c b/src/compiler/nir/nir_lower_vars_to_ssa.c index 98f3169..9c8f75f 100644 --- a/src/compiler/nir/nir_lower_vars_to_ssa.c +++ b/src/compiler/nir/nir_lower_vars_to_ssa.c @@ -698,8 +698,12 @@ nir_lower_vars_to_ssa_impl(nir_function_impl *impl) foreach_deref_node_match(path, lower_copies_to_load_store, &state); } - if (!progress) + if (!progress) { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif return false; + } nir_metadata_require(impl, nir_metadata_dominance); diff --git a/src/compiler/nir/nir_opt_constant_folding.c b/src/compiler/nir/nir_opt_constant_folding.c index 5097a3b..83be0d7 100644 --- a/src/compiler/nir/nir_opt_constant_folding.c +++ b/src/compiler/nir/nir_opt_constant_folding.c @@ -193,9 +193,14 @@ nir_opt_constant_folding_impl(nir_function_impl *impl) progress |= constant_fold_block(block, mem_ctx); } - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_opt_copy_prop_vars.c b/src/compiler/nir/nir_opt_copy_prop_vars.c index 28c93d3..069fcad 100644 --- a/src/compiler/nir/nir_opt_copy_prop_vars.c +++ b/src/compiler/nir/nir_opt_copy_prop_vars.c @@ -876,6 +876,10 @@ nir_copy_prop_vars_impl(nir_function_impl *impl) if (state.progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif } ralloc_free(mem_ctx); diff --git a/src/compiler/nir/nir_opt_copy_propagate.c b/src/compiler/nir/nir_opt_copy_propagate.c index fcb85d1..534f127 100644 --- a/src/compiler/nir/nir_opt_copy_propagate.c +++ b/src/compiler/nir/nir_opt_copy_propagate.c @@ -307,6 +307,10 @@ nir_copy_prop_impl(nir_function_impl *impl) if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif } return progress; diff --git a/src/compiler/nir/nir_opt_cse.c b/src/compiler/nir/nir_opt_cse.c index db6bb9a..bf42a6a 100644 --- a/src/compiler/nir/nir_opt_cse.c +++ b/src/compiler/nir/nir_opt_cse.c @@ -70,9 +70,14 @@ nir_opt_cse_impl(nir_function_impl *impl) bool progress = cse_block(nir_start_block(impl), instr_set); - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } nir_instr_set_destroy(instr_set); return progress; diff --git a/src/compiler/nir/nir_opt_dce.c b/src/compiler/nir/nir_opt_dce.c index 70532be..724cf3f 100644 --- a/src/compiler/nir/nir_opt_dce.c +++ b/src/compiler/nir/nir_opt_dce.c @@ -145,9 +145,14 @@ nir_opt_dce_impl(nir_function_impl *impl) } } - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_opt_dead_cf.c b/src/compiler/nir/nir_opt_dead_cf.c index b547ab6..1498673 100644 --- a/src/compiler/nir/nir_opt_dead_cf.c +++ b/src/compiler/nir/nir_opt_dead_cf.c @@ -339,8 +339,13 @@ opt_dead_cf_impl(nir_function_impl *impl) bool dummy; bool progress = dead_cf_list(&impl->body, &dummy); - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_none); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c index d7a7bb2..c2f945d 100644 --- a/src/compiler/nir/nir_opt_if.c +++ b/src/compiler/nir/nir_opt_if.c @@ -873,6 +873,10 @@ nir_opt_if(nir_shader *shader) nir_lower_regs_to_ssa_impl(function->impl); progress = true; + } else { + #ifndef NDEBUG + function->impl->valid_metadata &= ~nir_metadata_not_properly_reset; + #endif } } diff --git a/src/compiler/nir/nir_opt_peephole_select.c b/src/compiler/nir/nir_opt_peephole_select.c index b27cdd2..1deb02a 100644 --- a/src/compiler/nir/nir_opt_peephole_select.c +++ b/src/compiler/nir/nir_opt_peephole_select.c @@ -282,8 +282,13 @@ nir_opt_peephole_select_impl(nir_function_impl *impl, unsigned limit, expensive_alu_ok); } - if (progress) + if (progress) { nir_metadata_preserve(impl, nir_metadata_none); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } return progress; } diff --git a/src/compiler/nir/nir_opt_remove_phis.c b/src/compiler/nir/nir_opt_remove_phis.c index d7ca2fe..9efbf42 100644 --- a/src/compiler/nir/nir_opt_remove_phis.c +++ b/src/compiler/nir/nir_opt_remove_phis.c @@ -153,6 +153,10 @@ nir_opt_remove_phis_impl(nir_function_impl *impl) if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif } return progress; diff --git a/src/compiler/nir/nir_opt_undef.c b/src/compiler/nir/nir_opt_undef.c index c26158d..bdebf55 100644 --- a/src/compiler/nir/nir_opt_undef.c +++ b/src/compiler/nir/nir_opt_undef.c @@ -154,10 +154,15 @@ nir_opt_undef(nir_shader *shader) } } - if (progress) + if (progress) { nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + function->impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif + } } } diff --git a/src/compiler/nir/nir_split_var_copies.c b/src/compiler/nir/nir_split_var_copies.c index 5ac1c33..6260a8d 100644 --- a/src/compiler/nir/nir_split_var_copies.c +++ b/src/compiler/nir/nir_split_var_copies.c @@ -113,6 +113,10 @@ split_var_copies_impl(nir_function_impl *impl) if (progress) { nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance); + } else { +#ifndef NDEBUG + impl->valid_metadata &= ~nir_metadata_not_properly_reset; +#endif } return progress; -- 2.7.4