nir: add nir_phi_get_src_from_block() helper
Returns the phi_src corresponding to a given nir_block. Reviewed-by: Rhys Perry <pendingchaos02@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/2804>
This commit is contained in:
@@ -2615,6 +2615,18 @@ typedef struct {
|
||||
nir_dest dest;
|
||||
} nir_phi_instr;
|
||||
|
||||
static inline nir_phi_src *
|
||||
nir_phi_get_src_from_block(nir_phi_instr *phi, struct nir_block *block)
|
||||
{
|
||||
nir_foreach_phi_src(src, phi) {
|
||||
if (src->pred == block)
|
||||
return src;
|
||||
}
|
||||
|
||||
assert(!"Block is not a predecessor of phi.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
struct exec_node node;
|
||||
nir_src src;
|
||||
|
@@ -509,21 +509,6 @@ opt_split_alu_of_phi(nir_builder *b, nir_loop *loop)
|
||||
return progress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SSA value from a phi node that corresponds to a specific block
|
||||
*/
|
||||
static nir_ssa_def *
|
||||
ssa_for_phi_from_block(nir_phi_instr *phi, nir_block *block)
|
||||
{
|
||||
nir_foreach_phi_src(src, phi) {
|
||||
if (src->pred == block)
|
||||
return src->src.ssa;
|
||||
}
|
||||
|
||||
assert(!"Block is not a predecessor of phi.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simplify a bcsel whose sources are all phi nodes from the loop header block
|
||||
*
|
||||
@@ -681,15 +666,15 @@ opt_simplify_bcsel_of_phi(nir_builder *b, nir_loop *loop)
|
||||
phi_src = ralloc(phi, nir_phi_src);
|
||||
phi_src->pred = prev_block;
|
||||
phi_src->src =
|
||||
nir_src_for_ssa(ssa_for_phi_from_block(nir_instr_as_phi(bcsel->src[entry_src].src.ssa->parent_instr),
|
||||
prev_block));
|
||||
nir_phi_get_src_from_block(nir_instr_as_phi(bcsel->src[entry_src].src.ssa->parent_instr),
|
||||
prev_block)->src;
|
||||
exec_list_push_tail(&phi->srcs, &phi_src->node);
|
||||
|
||||
phi_src = ralloc(phi, nir_phi_src);
|
||||
phi_src->pred = continue_block;
|
||||
phi_src->src =
|
||||
nir_src_for_ssa(ssa_for_phi_from_block(nir_instr_as_phi(bcsel->src[continue_src].src.ssa->parent_instr),
|
||||
continue_block));
|
||||
nir_phi_get_src_from_block(nir_instr_as_phi(bcsel->src[continue_src].src.ssa->parent_instr),
|
||||
continue_block)->src;
|
||||
exec_list_push_tail(&phi->srcs, &phi_src->node);
|
||||
|
||||
nir_ssa_dest_init(&phi->instr,
|
||||
|
Reference in New Issue
Block a user