nir: Unset metadata debug bit if no progress made
authorMatt Turner <mattst88@gmail.com>
Mon, 10 Sep 2018 21:31:29 +0000 (14:31 -0700)
committerMatt Turner <mattst88@gmail.com>
Thu, 10 Jan 2019 00:42:40 +0000 (16:42 -0800)
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 <kenneth@whitecape.org>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
22 files changed:
src/compiler/nir/nir_algebraic.py
src/compiler/nir/nir_deref.c
src/compiler/nir/nir_inline_functions.c
src/compiler/nir/nir_lower_constant_initializers.c
src/compiler/nir/nir_lower_double_ops.c
src/compiler/nir/nir_lower_global_vars_to_local.c
src/compiler/nir/nir_lower_int64.c
src/compiler/nir/nir_lower_load_const_to_scalar.c
src/compiler/nir/nir_lower_returns.c
src/compiler/nir/nir_lower_var_copies.c
src/compiler/nir/nir_lower_vars_to_ssa.c
src/compiler/nir/nir_opt_constant_folding.c
src/compiler/nir/nir_opt_copy_prop_vars.c
src/compiler/nir/nir_opt_copy_propagate.c
src/compiler/nir/nir_opt_cse.c
src/compiler/nir/nir_opt_dce.c
src/compiler/nir/nir_opt_dead_cf.c
src/compiler/nir/nir_opt_if.c
src/compiler/nir/nir_opt_peephole_select.c
src/compiler/nir/nir_opt_remove_phis.c
src/compiler/nir/nir_opt_undef.c
src/compiler/nir/nir_split_var_copies.c

index 238127235fdaa7b61dcbf46fe65da6b1eb2d3de4..fe9d1051e67ecee8a74082f29325e5b1edb4d66f 100644 (file)
@@ -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;
 }
index 947888a5e20280defaa84a2f0e2489ec42f7273d..26de64c5140d47e1d9dfaea22611106237905fa9 100644 (file)
@@ -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;
index dd2dfa04cfcc514bdfb300a686b4ceba19165dec..74d39db7ab26cb3b7cc353aba838ebb06caf2c48 100644 (file)
@@ -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);
index b1c5183491737b261be41038d045365a5ce66f53..cbee59b1f306eea6db4deca2941420c58b858f3e 100644 (file)
@@ -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
       }
    }
 
index 48e0c80b108d5f1e61296b18761f0478dc80d58a..4d4cdf635ea74f80d301e0d8b62086c8bbc90d4c 100644 (file)
@@ -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;
 }
index 7cc1b2cb69ea87cb30a2686f61e5eadb03059adf..1ca7c1996a358630a8a8ec7f9976157f5dc3cd91 100644 (file)
@@ -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;
 }
index 1ec4816cf3ed7cf76a74dd8d0945e841c430bf97..1c4b4b337973bbc8b211c8188844c7ebd619cacd 100644 (file)
@@ -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;
 }
index b62d32e483ea4a080c8952af76ee49522a27a942..a821a77e90ddf9a6ad5c4486d90534f42f081df6 100644 (file)
@@ -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;
 }
index 292671ea8cbcd9896e1e56ac77c5c0a69b9442ed..e166a7cc32a54dea712756e6940ba0acd0644f44 100644 (file)
@@ -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;
index e72f7efcecb4241f0b3441e7c4b64f13215a44fb..1e7ad7849344bea85eecf72f3cf088493a2fceb4 100644 (file)
@@ -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;
 }
index 98f3169f6acbe0a625210e7bc10a82c948072a85..9c8f75f1083a251a1aedc28795f0f882770631ef 100644 (file)
@@ -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);
 
index 5097a3bcc362e5197f253d3563400fd4656e4eb0..83be0d78dbd7d48b6dceab9c712cc4694e1115e7 100644 (file)
@@ -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;
 }
index 28c93d359100d3352d8d0ecc6cd449a45dfab64e..069fcad71998bd60d3bfa374edbe8f75d000e226 100644 (file)
@@ -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);
index fcb85d1553590f4098abeae625b21d6ebf02ecaa..534f127c0d360855c3f1eaa6d835b3e262909960 100644 (file)
@@ -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;
index db6bb9a4a22c452e2e0732a9b68654ee1bc1f5b0..bf42a6a33dc5bb170749fc66114f0d0076f1a909 100644 (file)
@@ -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;
index 70532be33d79d86ffda0a0813e286238fc173186..724cf3f20349277e86ab8ae167e2e75695b3cf38 100644 (file)
@@ -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;
 }
index b547ab600bbdd92aa9f0c74da5160cf03e09473d..149867320967219d9987201f4531daeb3ec6fd93 100644 (file)
@@ -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;
 }
index d7a7bb2bb26c4c4f8d9157aaaac3b3f2478da643..c2f945d4d598be1cd19d71c7a8b18e3344f22dfd 100644 (file)
@@ -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
       }
    }
 
index b27cdd28a99b4023402b13033aee9fad2fbd00bb..1deb02a380ea4489913293ab540b6dd11d3143be 100644 (file)
@@ -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;
 }
index d7ca2fe7179c33cb7d3ef06ad8ad5e97861cfca6..9efbf422624f10540f38dbb67ec615a1f278ecaa 100644 (file)
@@ -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;
index c26158dab7ebed001cfebe6d5ecd58454af362cd..bdebf5540d6c673b0ddfde85a85798b640cd5592 100644 (file)
@@ -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
+         }
       }
    }
 
index 5ac1c33dde593cc9aaf16323fcf5024f10d438b7..6260a8d7bfa534f0708e578e1ce768597d803ab5 100644 (file)
@@ -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;