nir: add helper to copy const_index[]
authorRob Clark <robdclark@chromium.org>
Wed, 6 May 2020 20:35:51 +0000 (13:35 -0700)
committerRob Clark <robdclark@chromium.org>
Thu, 14 May 2020 03:24:45 +0000 (20:24 -0700)
It seems less brittle to not assume they are in the same order for src
and dst instructions.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/nir/nir.h
src/freedreno/ir3/ir3_nir_lower_io_offsets.c

index c2a0053c3820f1f366d2c934055547faa4cfdd68..b12deb2cd78d5b68d8cc28c3339e141de819b9f3 100644 (file)
@@ -1763,6 +1763,33 @@ nir_intrinsic_dest_components(nir_intrinsic_instr *intr)
       return intr->num_components;
 }
 
+/**
+ * Helper to copy const_index[] from src to dst, without assuming they
+ * match in order.
+ */
+static inline void
+nir_intrinsic_copy_const_indices(nir_intrinsic_instr *dst, nir_intrinsic_instr *src)
+{
+   if (src->intrinsic == dst->intrinsic) {
+      memcpy(dst->const_index, src->const_index, sizeof(dst->const_index));
+      return;
+   }
+
+   const nir_intrinsic_info *src_info = &nir_intrinsic_infos[src->intrinsic];
+   const nir_intrinsic_info *dst_info = &nir_intrinsic_infos[dst->intrinsic];
+
+   for (unsigned i = 0; i < NIR_INTRINSIC_NUM_INDEX_FLAGS; i++) {
+      if (src_info->index_map[i] == 0)
+         continue;
+
+      /* require that dst instruction also uses the same const_index[]: */
+      assert(dst_info->index_map[i] > 0);
+
+      dst->const_index[dst_info->index_map[i] - 1] =
+            src->const_index[src_info->index_map[i] - 1];
+   }
+}
+
 #define INTRINSIC_IDX_ACCESSORS(name, flag, type)                             \
 static inline type                                                            \
 nir_intrinsic_##name(const nir_intrinsic_instr *instr)                        \
index 2d035eedd2303545d215af73f79b2a170abbd5f5..36c48cf1299c8abf05cc2f17c5fd6fdad27fc1c2 100644 (file)
@@ -217,8 +217,7 @@ lower_offset_for_ssbo(nir_intrinsic_instr *intrinsic, nir_builder *b,
        for (unsigned i = 0; i < num_srcs; i++)
                new_intrinsic->src[i] = nir_src_for_ssa(intrinsic->src[i].ssa);
 
-       for (unsigned i = 0; i < NIR_INTRINSIC_MAX_CONST_INDEX; i++)
-               new_intrinsic->const_index[i] = intrinsic->const_index[i];
+       nir_intrinsic_copy_const_indices(new_intrinsic, intrinsic);
 
        new_intrinsic->num_components = intrinsic->num_components;