From 65cda2c0e16682c7c2bd6329f276016c5755ccc0 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Sat, 12 Aug 2023 19:24:01 -0500 Subject: [PATCH] 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 Part-of: --- src/compiler/nir/nir.c | 39 ----------------------------------- src/compiler/nir/nir.h | 4 ---- src/compiler/nir/nir_inline_helpers.h | 28 ++++++++++++------------- 3 files changed, 14 insertions(+), 57 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index 2c76c92..375552d 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -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) { diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 572157e..3151ce8 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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, diff --git a/src/compiler/nir/nir_inline_helpers.h b/src/compiler/nir/nir_inline_helpers.h index 57095cc..8d96450 100644 --- a/src/compiler/nir/nir_inline_helpers.h +++ b/src/compiler/nir/nir_inline_helpers.h @@ -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 -- 2.7.4