From f97fb1fa55ca7580d6a6192f5588dc590479d15a Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 4 Jul 2018 09:10:28 -0700 Subject: [PATCH] nir: Add a nir_instr_move helper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (v1) Reviewed-by: Daniel Schürmann Part-of: --- 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) {