nir: Use a switch in nir_inline_function_impl
[mesa.git] / src / compiler / nir / nir_inline_functions.c
index 8226d50b44b10b448341bd0e99f957b7a8c6b031..03a26e0dbf3e79b21832157d1bcc0bc2c8e0a891 100644 (file)
@@ -44,27 +44,33 @@ void nir_inline_function_impl(struct nir_builder *b,
 
    nir_foreach_block(block, copy) {
       nir_foreach_instr_safe(instr, block) {
-         /* Returns have to be lowered for this to work */
-         assert(instr->type != nir_instr_type_jump ||
-                nir_instr_as_jump(instr)->type != nir_jump_return);
-
-         if (instr->type != nir_instr_type_intrinsic)
-            continue;
-
-         nir_intrinsic_instr *load = nir_instr_as_intrinsic(instr);
-         if (load->intrinsic != nir_intrinsic_load_param)
-            continue;
-
-         unsigned param_idx = nir_intrinsic_param_idx(load);
-         assert(param_idx < impl->function->num_params);
-         assert(load->dest.is_ssa);
-         nir_ssa_def_rewrite_uses(&load->dest.ssa,
-                                  nir_src_for_ssa(params[param_idx]));
-
-         /* Remove any left-over load_param intrinsics because they're soon
-          * to be in another function and therefore no longer valid.
-          */
-         nir_instr_remove(&load->instr);
+         switch (instr->type) {
+         case nir_instr_type_intrinsic: {
+            nir_intrinsic_instr *load = nir_instr_as_intrinsic(instr);
+            if (load->intrinsic != nir_intrinsic_load_param)
+               break;
+
+            unsigned param_idx = nir_intrinsic_param_idx(load);
+            assert(param_idx < impl->function->num_params);
+            assert(load->dest.is_ssa);
+            nir_ssa_def_rewrite_uses(&load->dest.ssa,
+                                     nir_src_for_ssa(params[param_idx]));
+
+            /* Remove any left-over load_param intrinsics because they're soon
+             * to be in another function and therefore no longer valid.
+             */
+            nir_instr_remove(&load->instr);
+            break;
+         }
+
+         case nir_instr_type_jump:
+            /* Returns have to be lowered for this to work */
+            assert(nir_instr_as_jump(instr)->type != nir_jump_return);
+            break;
+
+         default:
+            break;
+         }
       }
    }
 
@@ -143,9 +149,7 @@ inline_function_impl(nir_function_impl *impl, struct set *inlined)
 
       nir_metadata_preserve(impl, nir_metadata_none);
    } else {
-#ifndef NDEBUG
-      impl->valid_metadata &= ~nir_metadata_not_properly_reset;
-#endif
+      nir_metadata_preserve(impl, nir_metadata_all);
    }
 
    _mesa_set_add(inlined, impl);
@@ -158,7 +162,7 @@ inline_function_impl(nir_function_impl *impl, struct set *inlined)
  * For most use-cases, function inlining is a multi-step process.  The general
  * pattern employed by SPIR-V consumers and others is as follows:
  *
- *  1. nir_lower_constant_initializers(shader, nir_var_function_temp)
+ *  1. nir_lower_variable_initializers(shader, nir_var_function_temp)
  *
  *     This is needed because local variables from the callee are simply added
  *     to the locals list for the caller and the information about where the
@@ -213,7 +217,7 @@ inline_function_impl(nir_function_impl *impl, struct set *inlined)
  *    spirv_to_nir returns the root function and so we can just use == whereas
  *    with GL, you may have to look for a function named "main".
  *
- *  6. nir_lower_constant_initializers(shader, ~nir_var_function_temp)
+ *  6. nir_lower_variable_initializers(shader, ~nir_var_function_temp)
  *
  *     Lowering constant initializers on inputs, outputs, global variables,
  *     etc. requires that we know the main entrypoint so that we know where to