lima: Convert to use nir_foreach_function_impl when possible
authorYonggang Luo <luoyonggang@gmail.com>
Thu, 29 Jun 2023 20:23:20 +0000 (04:23 +0800)
committerMarge Bot <emma+marge@anholt.net>
Tue, 25 Jul 2023 12:09:06 +0000 (12:09 +0000)
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24316>

src/gallium/drivers/lima/ir/lima_nir_duplicate_consts.c
src/gallium/drivers/lima/ir/lima_nir_duplicate_intrinsic.c
src/gallium/drivers/lima/ir/lima_nir_lower_uniform_to_scalar.c
src/gallium/drivers/lima/ir/lima_nir_split_loads.c
src/gallium/drivers/lima/ir/pp/nir.c

index f303ad0..22f2828 100644 (file)
@@ -117,9 +117,7 @@ lima_nir_duplicate_load_consts_impl(nir_shader *shader, nir_function_impl *impl)
 void
 lima_nir_duplicate_load_consts(nir_shader *shader)
 {
-   nir_foreach_function(function, shader) {
-      if (function->impl) {
-         lima_nir_duplicate_load_consts_impl(shader, function->impl);
-      }
+   nir_foreach_function_impl(impl, shader) {
+      lima_nir_duplicate_load_consts_impl(shader, impl);
    }
 }
index 2d55b9f..72fc8ef 100644 (file)
@@ -139,10 +139,8 @@ lima_nir_duplicate_intrinsic_impl(nir_shader *shader, nir_function_impl *impl,
 void
 lima_nir_duplicate_load_uniforms(nir_shader *shader)
 {
-   nir_foreach_function(function, shader) {
-      if (function->impl) {
-         lima_nir_duplicate_intrinsic_impl(shader, function->impl, nir_intrinsic_load_uniform);
-      }
+   nir_foreach_function_impl(impl, shader) {
+      lima_nir_duplicate_intrinsic_impl(shader, impl, nir_intrinsic_load_uniform);
    }
 }
 
@@ -152,9 +150,7 @@ lima_nir_duplicate_load_uniforms(nir_shader *shader)
 void
 lima_nir_duplicate_load_inputs(nir_shader *shader)
 {
-   nir_foreach_function(function, shader) {
-      if (function->impl) {
-         lima_nir_duplicate_intrinsic_impl(shader, function->impl, nir_intrinsic_load_input);
-      }
+   nir_foreach_function_impl(impl, shader) {
+      lima_nir_duplicate_intrinsic_impl(shader, impl, nir_intrinsic_load_input);
    }
 }
index fd6183d..ab56628 100644 (file)
@@ -59,22 +59,20 @@ lower_load_uniform_to_scalar(nir_builder *b, nir_intrinsic_instr *intr)
 void
 lima_nir_lower_uniform_to_scalar(nir_shader *shader)
 {
-   nir_foreach_function(function, shader) {
-      if (function->impl) {
-         nir_builder b = nir_builder_create(function->impl);
+   nir_foreach_function_impl(impl, shader) {
+      nir_builder b = nir_builder_create(impl);
 
-         nir_foreach_block(block, function->impl) {
-            nir_foreach_instr_safe(instr, block) {
-               if (instr->type != nir_instr_type_intrinsic)
-                  continue;
+      nir_foreach_block(block, impl) {
+         nir_foreach_instr_safe(instr, block) {
+            if (instr->type != nir_instr_type_intrinsic)
+               continue;
 
-               nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
+            nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
 
-               if (intr->intrinsic != nir_intrinsic_load_uniform)
-                  continue;
+            if (intr->intrinsic != nir_intrinsic_load_uniform)
+               continue;
 
-               lower_load_uniform_to_scalar(&b, intr);
-            }
+            lower_load_uniform_to_scalar(&b, intr);
          }
       }
    }
index b665461..942e22b 100644 (file)
@@ -126,18 +126,16 @@ lima_nir_split_loads(nir_shader *shader)
 {
    bool progress = false;
 
-   nir_foreach_function(function, shader) {
-      if (function->impl) {
-         nir_builder b = nir_builder_create(function->impl);
-
-         nir_foreach_block_reverse(block, function->impl) {
-            nir_foreach_instr_reverse_safe(instr, block) {
-               if (instr->type == nir_instr_type_load_const) {
-                  replace_load_const(&b, nir_instr_as_load_const(instr));
-                  progress = true;
-               } else if (instr->type == nir_instr_type_intrinsic) {
-                  progress |= replace_intrinsic(&b, nir_instr_as_intrinsic(instr));
-               }
+   nir_foreach_function_impl(impl, shader) {
+      nir_builder b = nir_builder_create(impl);
+
+      nir_foreach_block_reverse(block, impl) {
+         nir_foreach_instr_reverse_safe(instr, block) {
+            if (instr->type == nir_instr_type_load_const) {
+               replace_load_const(&b, nir_instr_as_load_const(instr));
+               progress = true;
+            } else if (instr->type == nir_instr_type_intrinsic) {
+               progress |= replace_intrinsic(&b, nir_instr_as_intrinsic(instr));
             }
          }
       }
index 070dfb8..b878a9c 100644 (file)
@@ -919,11 +919,8 @@ bool ppir_compile_nir(struct lima_fs_compiled_shader *prog, struct nir_shader *n
    comp->dual_source_blend = nir->info.fs.color_is_dual_source;
 
    /* 1st pass: create ppir blocks */
-   nir_foreach_function(function, nir) {
-      if (!function->impl)
-         continue;
-
-      nir_foreach_block(nblock, function->impl) {
+   nir_foreach_function_impl(impl, nir) {
+      nir_foreach_block(nblock, impl) {
          ppir_block *block = ppir_block_create(comp);
          if (!block)
             return false;
@@ -933,11 +930,8 @@ bool ppir_compile_nir(struct lima_fs_compiled_shader *prog, struct nir_shader *n
    }
 
    /* 2nd pass: populate successors */
-   nir_foreach_function(function, nir) {
-      if (!function->impl)
-         continue;
-
-      nir_foreach_block(nblock, function->impl) {
+   nir_foreach_function_impl(impl, nir) {
+      nir_foreach_block(nblock, impl) {
          ppir_block *block = ppir_get_block(comp, nblock);
          assert(block);