pan/bi: Add helpers to generate bi_index from NIR
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Sat, 12 Dec 2020 01:03:02 +0000 (20:03 -0500)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 23 Dec 2020 18:29:36 +0000 (13:29 -0500)
Corresponding to the existing pan_{...}_index helpers, except returning
a new-style index instead.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8215>

src/panfrost/bifrost/compiler.h

index 8928044..d1609bc 100644 (file)
@@ -741,6 +741,34 @@ bi_make_temp_reg(bi_context *ctx)
         return ((ctx->impl->reg_alloc + ctx->temp_alloc++) << 1) | PAN_IS_REG;
 }
 
+/* Inline constants automatically, will be lowered out by bi_lower_fau where a
+ * constant is not allowed. load_const_to_scalar gaurantees that this makes
+ * sense */
+
+static inline bi_index
+bi_src_index(nir_src *src)
+{
+        if (nir_src_is_const(*src))
+                return bi_imm_u32(nir_src_as_uint(*src));
+        else if (src->is_ssa)
+                return bi_get_index(src->ssa->index, false, 0);
+        else {
+                assert(!src->reg.indirect);
+                return bi_get_index(src->reg.reg->index, true, 0);
+        }
+}
+
+static inline bi_index
+bi_dest_index(nir_dest *dst)
+{
+        if (dst->is_ssa)
+                return bi_get_index(dst->ssa.index, false, 0);
+        else {
+                assert(!dst->reg.indirect);
+                return bi_get_index(dst->reg.reg->index, true, 0);
+        }
+}
+
 /* Iterators for Bifrost IR */
 
 #define bi_foreach_block(ctx, v) \