nir: Add nir_instr_is_before helper

is_instr_between works similarly but requires special-casing w.r.t
the first instruction in a block for the same effect.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29577>
This commit is contained in:
Friedrich Vock
2024-12-20 18:00:32 +01:00
committed by Marge Bot
parent a8ce60eec1
commit 9b1f31a615
2 changed files with 21 additions and 0 deletions
+18
View File
@@ -1602,6 +1602,24 @@ nir_def_rewrite_uses_src(nir_def *def, nir_src new_src)
nir_def_rewrite_uses(def, new_src.ssa);
}
bool
nir_instr_is_before(nir_instr *first, nir_instr *second)
{
if (first->block != second->block)
return false;
/* Search backwards looking for "first" */
while (second != nir_block_first_instr(second->block)) {
second = nir_instr_prev(second);
assert(second);
if (first == second)
return true;
}
return false;
}
static bool
is_instr_between(nir_instr *start, nir_instr *end, nir_instr *between)
{
+3
View File
@@ -5098,6 +5098,9 @@ void nir_instr_clear_src(nir_instr *instr, nir_src *src);
void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src);
/** Returns true if first comes before second in a block. */
bool nir_instr_is_before(nir_instr *first, nir_instr *second);
void nir_def_init(nir_instr *instr, nir_def *def,
unsigned num_components, unsigned bit_size);
static inline void