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

Author: Jason Ekstrand <[email protected]>
Date:   Wed Jul  4 09:10:28 2018 -0700

nir: Add a nir_instr_move helper

Removes an instruction from one place and inserts it at another while
working around a weird cursor corner-case.

v2: change return value to bool (Daniel Schürmann)

Reviewed-by: Timur Kristóf <[email protected]> (v1)
Reviewed-by: Daniel Schürmann <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10522>

---

 src/compiler/nir/nir.c | 16 ++++++++++++++++
 src/compiler/nir/nir.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index 9d7cb35765b..1a3fd5c6f9c 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -958,6 +958,22 @@ nir_instr_insert(nir_cursor cursor, nir_instr *instr)
    impl->valid_metadata &= ~nir_metadata_instr_index;
 }
 
+bool
+nir_instr_move(nir_cursor cursor, nir_instr *instr)
+{
+   /* If the cursor happens to refer to this instruction (either before or
+    * after), don't do anything.
+    */
+   if ((cursor.option == nir_cursor_before_instr ||
+        cursor.option == nir_cursor_after_instr) &&
+       cursor.instr == instr)
+      return false;
+
+   nir_instr_remove(instr);
+   nir_instr_insert(cursor, instr);
+   return true;
+}
+
 static bool
 src_is_valid(const nir_src *src)
 {
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 8ab2d598701..14c3fb7e0d9 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -3826,6 +3826,8 @@ nir_after_cf_list(struct exec_list *cf_list)
  */
 void nir_instr_insert(nir_cursor cursor, nir_instr *instr);
 
+bool nir_instr_move(nir_cursor cursor, nir_instr *instr);
+
 static inline void
 nir_instr_insert_before(nir_instr *instr, nir_instr *before)
 {

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to