nir: Add a read_mask helper for ALU instructions
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 7 Nov 2018 23:47:45 +0000 (17:47 -0600)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 8 Nov 2018 16:09:22 +0000 (10:09 -0600)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir.c
src/compiler/nir/nir.h

index 0be40d257f5d3dab32d891b415d57a2d81a48cae..249b9357c3fa57aab3c369004eaaf4d23d6da1d5 100644 (file)
@@ -1530,13 +1530,7 @@ nir_ssa_def_components_read(const nir_ssa_def *def)
          nir_alu_src *alu_src = exec_node_data(nir_alu_src, use, src);
          int src_idx = alu_src - &alu->src[0];
          assert(src_idx >= 0 && src_idx < nir_op_infos[alu->op].num_inputs);
-
-         for (unsigned c = 0; c < NIR_MAX_VEC_COMPONENTS; c++) {
-            if (!nir_alu_instr_channel_used(alu, src_idx, c))
-               continue;
-
-            read_mask |= (1 << alu_src->swizzle[c]);
-         }
+         read_mask |= nir_alu_instr_src_read_mask(alu, src_idx);
       } else {
          return (1 << def->num_components) - 1;
       }
index a0ae9a4430e86f958fdf92ceebe76539e0512856..f4f6b1065053af041b2ca97e7e44b11864101442 100644 (file)
@@ -952,6 +952,19 @@ nir_alu_instr_channel_used(const nir_alu_instr *instr, unsigned src,
    return (instr->dest.write_mask >> channel) & 1;
 }
 
+static inline nir_component_mask_t
+nir_alu_instr_src_read_mask(const nir_alu_instr *instr, unsigned src)
+{
+   nir_component_mask_t read_mask = 0;
+   for (unsigned c = 0; c < NIR_MAX_VEC_COMPONENTS; c++) {
+      if (!nir_alu_instr_channel_used(instr, src, c))
+         continue;
+
+      read_mask |= (1 << instr->src[src].swizzle[c]);
+   }
+   return read_mask;
+}
+
 /*
  * For instructions whose destinations are SSA, get the number of channels
  * used for a source