nir: refactor nir_can_move_instr
authorDaniel Schürmann <daniel@schuermann.dev>
Wed, 24 Jun 2020 10:23:05 +0000 (11:23 +0100)
committerDaniel Schürmann <daniel@schuermann.dev>
Tue, 7 Jul 2020 17:24:28 +0000 (19:24 +0200)
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5622>

src/compiler/nir/nir_opt_sink.c

index 5595cfd61d98031de1804dced87b5bf5f564ae4d..1d551fe9f8beb4fa88cf7cfe6d10e346dcde36fa 100644 (file)
 bool
 nir_can_move_instr(nir_instr *instr, nir_move_options options)
 {
-   if ((options & nir_move_const_undef) && instr->type == nir_instr_type_load_const) {
-      return true;
+   switch (instr->type) {
+   case nir_instr_type_load_const:
+   case nir_instr_type_ssa_undef: {
+      return options & nir_move_const_undef;
    }
-
-   if (instr->type == nir_instr_type_intrinsic) {
-       nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
-      if ((options & nir_move_load_ubo) && intrin->intrinsic == nir_intrinsic_load_ubo)
-         return true;
-
-      if ((options & nir_move_load_input) &&
-          (intrin->intrinsic == nir_intrinsic_load_interpolated_input ||
-           intrin->intrinsic == nir_intrinsic_load_input ||
-           intrin->intrinsic == nir_intrinsic_load_per_vertex_input))
-         return true;
-   }
-
-   if ((options & nir_move_const_undef) && instr->type == nir_instr_type_ssa_undef) {
-      return true;
+   case nir_instr_type_alu: {
+      if (nir_op_is_vec(nir_instr_as_alu(instr)->op))
+         return options & nir_move_copies;
+      if (nir_alu_instr_is_comparison(nir_instr_as_alu(instr)))
+         return options & nir_move_comparisons;
+      return false;
    }
-
-   if ((options & nir_move_copies) && instr->type == nir_instr_type_alu &&
-       nir_op_is_vec(nir_instr_as_alu(instr)->op)) {
-      return true;
+   case nir_instr_type_intrinsic: {
+      nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+      switch (intrin->intrinsic) {
+      case nir_intrinsic_load_ubo:
+         return options & nir_move_load_ubo;
+      case nir_intrinsic_load_input:
+      case nir_intrinsic_load_interpolated_input:
+      case nir_intrinsic_load_per_vertex_input:
+         return options & nir_move_load_input;
+      default:
+         return false;
+      }
    }
-
-   if ((options & nir_move_comparisons) && instr->type == nir_instr_type_alu &&
-       nir_alu_instr_is_comparison(nir_instr_as_alu(instr))) {
-      return true;
+   default:
+      return false;
    }
-
-   return false;
 }
 
 static nir_loop *