nir: Drop nir_foreach_dest()
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Sun, 13 Aug 2023 00:24:01 +0000 (19:24 -0500)
committerMarge Bot <emma+marge@anholt.net>
Sun, 13 Aug 2023 17:12:52 +0000 (17:12 +0000)
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>

src/compiler/nir/nir.c
src/compiler/nir/nir.h
src/compiler/nir/nir_inline_helpers.h

index 2c76c92..375552d 100644 (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)
 {
index 572157e..3151ce8 100644 (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,
index 57095cc..8d96450 100644 (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