[Mesa-dev] [PATCH 1.5/3] nir: Add a nir_instr_move helper
Jason Ekstrand
jason at jlekstrand.net
Wed Jul 4 16:55:26 UTC 2018
Removes an instruction from one place and inserts it at another while
working around a weird cursor corner-case.
---
src/compiler/nir/nir.c | 15 +++++++++++++++
src/compiler/nir/nir.h | 2 ++
2 files changed, 17 insertions(+)
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index c515a30b626..bbb28aef890 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -845,6 +845,21 @@ nir_instr_insert(nir_cursor cursor, nir_instr *instr)
nir_handle_add_jump(instr->block);
}
+void
+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;
+
+ nir_instr_remove(instr);
+ nir_instr_insert(cursor, instr);
+}
+
static bool
src_is_valid(const nir_src *src)
{
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 92ab3a699cc..c40a88c8ccc 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2318,6 +2318,8 @@ nir_after_cf_list(struct exec_list *cf_list)
*/
void nir_instr_insert(nir_cursor cursor, nir_instr *instr);
+void nir_instr_move(nir_cursor cursor, nir_instr *instr);
+
static inline void
nir_instr_insert_before(nir_instr *instr, nir_instr *before)
{
--
2.17.1
More information about the mesa-dev
mailing list