nir: Drop nir_foreach_dest()

This requires an annoying bit of shuffling into nir_inline_helpers.h but
it's not horrible.

Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24658>
This commit is contained in:
Faith Ekstrand
2023-08-12 19:24:01 -05:00
committed by Marge Bot
parent 95a3c1325d
commit 65cda2c0e1
3 changed files with 14 additions and 57 deletions

View File

@@ -1285,45 +1285,6 @@ nir_instr_free_and_dce(nir_instr *instr)
/*@}*/
struct foreach_def_state {
nir_foreach_def_cb cb;
void *client_state;
};
static inline bool
nir_def_visitor(nir_dest *dest, void *void_state)
{
struct foreach_def_state *state = void_state;
return state->cb(&dest->ssa, state->client_state);
}
bool
nir_foreach_def(nir_instr *instr, nir_foreach_def_cb cb, void *state)
{
switch (instr->type) {
case nir_instr_type_alu:
case nir_instr_type_deref:
case nir_instr_type_tex:
case nir_instr_type_intrinsic:
case nir_instr_type_phi:
case nir_instr_type_parallel_copy: {
struct foreach_def_state foreach_state = { cb, state };
return nir_foreach_dest(instr, nir_def_visitor, &foreach_state);
}
case nir_instr_type_load_const:
return cb(&nir_instr_as_load_const(instr)->def, state);
case nir_instr_type_ssa_undef:
return cb(&nir_instr_as_ssa_undef(instr)->def, state);
case nir_instr_type_call:
case nir_instr_type_jump:
return true;
default:
unreachable("Invalid instruction type");
}
}
nir_def *
nir_instr_ssa_def(nir_instr *instr)
{

View File

@@ -4388,11 +4388,7 @@ nir_cursor nir_instr_free_and_dce(nir_instr *instr);
nir_def *nir_instr_ssa_def(nir_instr *instr);
typedef bool (*nir_foreach_def_cb)(nir_def *def, void *state);
typedef bool (*nir_foreach_dest_cb)(nir_dest *dest, void *state);
typedef bool (*nir_foreach_src_cb)(nir_src *src, void *state);
bool nir_foreach_def(nir_instr *instr, nir_foreach_def_cb cb,
void *state);
static inline bool nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state);
static inline bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state);
bool nir_foreach_phi_src_leaving_block(nir_block *instr,
nir_foreach_src_cb cb,

View File

@@ -1,44 +1,44 @@
/* _nir_foreach_dest() needs to be ALWAYS_INLINE so that it can inline the
/* _nir_foreach_def() needs to be ALWAYS_INLINE so that it can inline the
* callback if it was declared with ALWAYS_INLINE.
*/
static ALWAYS_INLINE bool
_nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state)
_nir_foreach_def(nir_instr *instr, nir_foreach_def_cb cb, void *state)
{
switch (instr->type) {
case nir_instr_type_alu:
return cb(&nir_instr_as_alu(instr)->dest.dest, state);
return cb(&nir_instr_as_alu(instr)->dest.dest.ssa, state);
case nir_instr_type_deref:
return cb(&nir_instr_as_deref(instr)->dest, state);
return cb(&nir_instr_as_deref(instr)->dest.ssa, state);
case nir_instr_type_intrinsic: {
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
if (nir_intrinsic_infos[intrin->intrinsic].has_dest)
return cb(&intrin->dest, state);
return cb(&intrin->dest.ssa, state);
return true;
}
case nir_instr_type_tex:
return cb(&nir_instr_as_tex(instr)->dest, state);
return cb(&nir_instr_as_tex(instr)->dest.ssa, state);
case nir_instr_type_phi:
return cb(&nir_instr_as_phi(instr)->dest, state);
return cb(&nir_instr_as_phi(instr)->dest.ssa, state);
case nir_instr_type_parallel_copy: {
nir_foreach_parallel_copy_entry(entry, nir_instr_as_parallel_copy(instr)) {
if (!entry->dest_is_reg && !cb(&entry->dest.dest, state))
if (!entry->dest_is_reg && !cb(&entry->dest.dest.ssa, state))
return false;
}
return true;
}
case nir_instr_type_load_const:
return cb(&nir_instr_as_load_const(instr)->def, state);
case nir_instr_type_ssa_undef:
return cb(&nir_instr_as_ssa_undef(instr)->def, state);
case nir_instr_type_call:
case nir_instr_type_jump:
break;
return true;
default:
unreachable("Invalid instruction type");
break;
}
return true;
}
static ALWAYS_INLINE bool
@@ -50,9 +50,9 @@ _nir_visit_src(nir_src *src, nir_foreach_src_cb cb, void *state)
}
static inline bool
nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state)
nir_foreach_def(nir_instr *instr, nir_foreach_def_cb cb, void *state)
{
return _nir_foreach_dest(instr, cb, state);
return _nir_foreach_def(instr, cb, state);
}
static inline bool