freedreno/ir3: Add intrinsics that map to LDLW/STLW
[mesa.git] / src / compiler / nir / nir_opt_cse.c
index 364fb023dce70bd0fe67b5306205158dcf82f68a..3c3617d852a7b7845c9b08f27caa47e89f012de9 100644 (file)
  */
 
 /*
- * Visits and CSE's the given block and all its descendants in the dominance
+ * Visits and CSEs the given block and all its descendants in the dominance
  * tree recursively. Note that the instr_set is guaranteed to only ever
  * contain instructions that dominate the current block.
  */
 
 static bool
-cse_block(nir_block *block, struct set *instr_set)
+cse_block(nir_block *block, struct set *dominance_set)
 {
    bool progress = false;
+   struct set *instr_set = _mesa_set_clone(dominance_set, NULL);
 
-   nir_foreach_instr_safe(block, instr) {
+   nir_foreach_instr_safe(instr, block) {
       if (nir_instr_set_add_or_rewrite(instr_set, instr)) {
          progress = true;
          nir_instr_remove(instr);
@@ -55,8 +56,7 @@ cse_block(nir_block *block, struct set *instr_set)
       progress |= cse_block(child, instr_set);
    }
 
-   nir_foreach_instr(block, instr)
-     nir_instr_set_remove(instr_set, instr);
+   _mesa_set_destroy(instr_set, NULL);
 
    return progress;
 }
@@ -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;
@@ -83,7 +88,7 @@ nir_opt_cse(nir_shader *shader)
 {
    bool progress = false;
 
-   nir_foreach_function(shader, function) {
+   nir_foreach_function(function, shader) {
       if (function->impl)
          progress |= nir_opt_cse_impl(function->impl);
    }