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) {