Mesa (main): nir: Pull the instr list free function out to a helper.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Sep 14 18:28:24 UTC 2021


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

Author: Emma Anholt <emma at anholt.net>
Date:   Wed Jul  7 12:46:49 2021 -0700

nir: Pull the instr list free function out to a helper.

With the de-rallocing, we're going to have some more places that free a
list of instrs.

Reviewed-by: Matt Turner <mattst88 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11776>

---

 src/compiler/nir/nir.c | 16 +++++++++++-----
 src/compiler/nir/nir.h |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 824042b3303..924f50eaa94 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -1096,6 +1096,16 @@ void nir_instr_free(nir_instr *instr)
    ralloc_free(instr);
 }
 
+void
+nir_instr_free_list(struct exec_list *list)
+{
+   struct exec_node *node;
+   while ((node = exec_list_pop_head(list))) {
+      nir_instr *removed_instr = exec_node_data(nir_instr, node, node);
+      nir_instr_free(removed_instr);
+   }
+}
+
 static bool nir_instr_free_and_dce_live_cb(nir_ssa_def *def, void *state)
 {
    bool *live = state;
@@ -1179,11 +1189,7 @@ nir_instr_free_and_dce(nir_instr *instr)
       exec_list_push_tail(&to_free, &dce_instr->node);
    }
 
-   struct exec_node *node;
-   while ((node = exec_list_pop_head(&to_free))) {
-      nir_instr *removed_instr = exec_node_data(nir_instr, node, node);
-      nir_instr_free(removed_instr);
-   }
+   nir_instr_free_list(&to_free);
 
    nir_instr_worklist_destroy(worklist);
 
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 392fad34e6b..0d9e09b41dc 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4226,6 +4226,7 @@ nir_instr_insert_after_cf_list(struct exec_list *list, nir_instr *after)
 
 void nir_instr_remove_v(nir_instr *instr);
 void nir_instr_free(nir_instr *instr);
+void nir_instr_free_list(struct exec_list *list);
 
 static inline nir_cursor
 nir_instr_remove(nir_instr *instr)



More information about the mesa-commit mailing list