nir: Share destination rewriting and replacement code in IO lowering.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 12 Jul 2016 09:30:02 +0000 (02:30 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Sat, 16 Jul 2016 00:17:09 +0000 (17:17 -0700)
Both loads and atomics had identical code to rewrite destinations,
and all cases had the same two lines to replace instructions.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_lower_io.c

index 45cc67123a53e34700dba58af67051ea7ce7af5f..3a8587a2dd3f794cca683b469c47a0969f2e6f37 100644 (file)
@@ -289,6 +289,8 @@ nir_lower_io_block(nir_block *block,
                              per_vertex ? &vertex_index : NULL,
                              state->type_size);
 
+      nir_intrinsic_instr *replacement;
+
       switch (intrin->intrinsic) {
       case nir_intrinsic_load_var: {
          nir_intrinsic_instr *load =
@@ -311,18 +313,7 @@ nir_lower_io_block(nir_block *block,
 
          load->src[per_vertex ? 1 : 0] = nir_src_for_ssa(offset);
 
-         if (intrin->dest.is_ssa) {
-            nir_ssa_dest_init(&load->instr, &load->dest,
-                              intrin->num_components,
-                              intrin->dest.ssa.bit_size, NULL);
-            nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
-                                     nir_src_for_ssa(&load->dest.ssa));
-         } else {
-            nir_dest_copy(&load->dest, &intrin->dest, state->mem_ctx);
-         }
-
-         nir_instr_insert_before(&intrin->instr, &load->instr);
-         nir_instr_remove(&intrin->instr);
+         replacement = load;
          break;
       }
 
@@ -348,8 +339,7 @@ nir_lower_io_block(nir_block *block,
 
          store->src[per_vertex ? 2 : 1] = nir_src_for_ssa(offset);
 
-         nir_instr_insert_before(&intrin->instr, &store->instr);
-         nir_instr_remove(&intrin->instr);
+         replacement = store;
          break;
       }
 
@@ -379,24 +369,28 @@ nir_lower_io_block(nir_block *block,
             nir_src_copy(&atomic->src[i+1], &intrin->src[i], atomic);
          }
 
+         replacement = atomic;
+         break;
+      }
+
+      default:
+         break;
+      }
+
+      if (nir_intrinsic_infos[intrin->intrinsic].has_dest) {
          if (intrin->dest.is_ssa) {
-            nir_ssa_dest_init(&atomic->instr, &atomic->dest,
-                              intrin->dest.ssa.num_components,
+            nir_ssa_dest_init(&replacement->instr, &replacement->dest,
+                              intrin->num_components,
                               intrin->dest.ssa.bit_size, NULL);
             nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
-                                     nir_src_for_ssa(&atomic->dest.ssa));
+                                     nir_src_for_ssa(&replacement->dest.ssa));
          } else {
-            nir_dest_copy(&atomic->dest, &intrin->dest, state->mem_ctx);
+            nir_dest_copy(&replacement->dest, &intrin->dest, state->mem_ctx);
          }
-
-         nir_instr_insert_before(&intrin->instr, &atomic->instr);
-         nir_instr_remove(&intrin->instr);
-         break;
       }
 
-      default:
-         break;
-      }
+      nir_instr_insert_before(&intrin->instr, &replacement->instr);
+      nir_instr_remove(&intrin->instr);
    }
 
    return true;