nir/functions: move linker pass to new helper
authorDave Airlie <airlied@redhat.com>
Wed, 6 Sep 2023 07:54:41 +0000 (17:54 +1000)
committerMarge Bot <emma+marge@anholt.net>
Tue, 12 Sep 2023 01:57:50 +0000 (01:57 +0000)
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24687>

src/compiler/nir/nir_functions.c

index 0d9f24b..5e7b5ea 100644 (file)
@@ -265,9 +265,15 @@ struct lower_link_state {
 };
 
 static bool
-lower_function_link_call_instr(nir_instr *instr, nir_builder *b,
-                               struct lower_link_state *state)
+function_link_pass(struct nir_builder *b,
+                   nir_instr *instr,
+                   void *cb_data)
 {
+   struct lower_link_state *state = cb_data;
+
+   if (instr->type != nir_instr_type_call)
+      return false;
+
    nir_call_instr *call = nir_instr_as_call(instr);
    nir_function *func = NULL;
 
@@ -294,30 +300,6 @@ lower_function_link_call_instr(nir_instr *instr, nir_builder *b,
    return true;
 }
 
-static bool
-lower_function_link_impl(nir_function_impl *impl,
-                         struct lower_link_state *state)
-{
-   nir_builder b = nir_builder_create(impl);
-
-   bool progress = false;
-   nir_foreach_block_safe(block, impl) {
-      nir_foreach_instr_safe(instr, block) {
-         if (instr->type == nir_instr_type_call)
-            progress |= lower_function_link_call_instr(instr, &b, state);
-      }
-   }
-
-   if (progress) {
-      nir_index_ssa_defs(impl);
-      nir_metadata_preserve(impl, nir_metadata_none);
-   } else {
-      nir_metadata_preserve(impl, nir_metadata_all);
-   }
-
-   return progress;
-}
-
 bool
 nir_link_shader_functions(nir_shader *shader,
                           const nir_shader *link_shader)
@@ -334,7 +316,13 @@ nir_link_shader_functions(nir_shader *shader,
    do {
       progress = false;
       nir_foreach_function_impl(impl, shader) {
-         progress |= lower_function_link_impl(impl, &state);
+         bool this_progress = nir_function_instructions_pass(impl,
+                                                             function_link_pass,
+                                                             nir_metadata_none,
+                                                             &state);
+         if (this_progress)
+            nir_index_ssa_defs(impl);
+         progress |= this_progress;
       }
       overall_progress |= progress;
    } while (progress);