Module: Mesa
Branch: main
Commit: bbd7729993d069cdc1ba5fffa0e16a3f9222c7ab
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=bbd7729993d069cdc1ba5fffa0e16a3f9222c7ab

Author: Ian Romanick <ian.d.roman...@intel.com>
Date:   Wed Sep 13 10:44:31 2023 -0700

intel/compiler: Delete bidirectional block links in opt_predicated_break

Previously when earlier_block->children.make_empty() was called, the
child blocks would still have links back to earlier_block.

Reviewed-by: Caio Oliveira <caio.olive...@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25216>

---

 src/intel/compiler/brw_cfg.cpp              | 22 ++++++++++++++++++++++
 src/intel/compiler/brw_cfg.h                | 17 +++++++++++++++++
 src/intel/compiler/brw_predicated_break.cpp |  4 ++--
 3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/intel/compiler/brw_cfg.cpp b/src/intel/compiler/brw_cfg.cpp
index 52e1e326b11..f6d9767784c 100644
--- a/src/intel/compiler/brw_cfg.cpp
+++ b/src/intel/compiler/brw_cfg.cpp
@@ -166,6 +166,28 @@ bblock_t::dump() const
    }
 }
 
+void
+bblock_t::unlink_list(exec_list *list)
+{
+   assert(list == &parents || list == &children);
+   const bool remove_parent = list == &children;
+
+   foreach_list_typed_safe(bblock_link, link, link, list) {
+      /* Also break the links from the other block back to this block. */
+      exec_list *sub_list = remove_parent ? &link->block->parents : 
&link->block->children;
+
+      foreach_list_typed_safe(bblock_link, sub_link, link, sub_list) {
+         if (sub_link->block == this) {
+            sub_link->link.remove();
+            ralloc_free(sub_link);
+         }
+      }
+
+      link->link.remove();
+      ralloc_free(link);
+   }
+}
+
 cfg_t::cfg_t(const backend_shader *s, exec_list *instructions) :
    s(s)
 {
diff --git a/src/intel/compiler/brw_cfg.h b/src/intel/compiler/brw_cfg.h
index 36e82cad224..20ed2d2988d 100644
--- a/src/intel/compiler/brw_cfg.h
+++ b/src/intel/compiler/brw_cfg.h
@@ -107,6 +107,23 @@ struct bblock_t {
 
    backend_instruction *first_non_control_flow_inst();
    backend_instruction *last_non_control_flow_inst();
+
+private:
+   /**
+    * \sa unlink_parents, unlink_children
+    */
+   void unlink_list(exec_list *);
+
+public:
+   void unlink_parents()
+   {
+      unlink_list(&parents);
+   }
+
+   void unlink_children()
+   {
+      unlink_list(&children);
+   }
 #endif
 
    struct exec_node link;
diff --git a/src/intel/compiler/brw_predicated_break.cpp 
b/src/intel/compiler/brw_predicated_break.cpp
index eaa4320db8f..ee6efb92f61 100644
--- a/src/intel/compiler/brw_predicated_break.cpp
+++ b/src/intel/compiler/brw_predicated_break.cpp
@@ -159,13 +159,13 @@ opt_predicated_break(backend_shader *s)
       endif_inst->remove(endif_block);
 
       if (!earlier_block->ends_with_control_flow()) {
-         earlier_block->children.make_empty();
+         earlier_block->unlink_children();
          earlier_block->add_successor(s->cfg->mem_ctx, jump_block,
                                       bblock_link_logical);
       }
 
       if (!later_block->starts_with_control_flow()) {
-         later_block->parents.make_empty();
+         later_block->unlink_parents();
       }
       jump_block->add_successor(s->cfg->mem_ctx, later_block,
                                 bblock_link_logical);

Reply via email to