pan/bi: Add helpers for creating temporaries
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 6 Mar 2020 14:43:43 +0000 (09:43 -0500)
committerMarge Bot <eric+marge@anholt.net>
Sat, 7 Mar 2020 00:37:39 +0000 (00:37 +0000)
Also from Midgard, adapted to our addressing scheme.

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

src/panfrost/bifrost/bifrost_compile.c
src/panfrost/bifrost/compiler.h

index 2ebba1b..a22d642 100644 (file)
@@ -533,6 +533,7 @@ bifrost_compile_shader_nir(nir_shader *nir, bifrost_program *program, unsigned p
                 if (!func->impl)
                         continue;
 
+                ctx->impl = func->impl;
                 emit_cf_list(ctx, &func->impl->body);
                 break; /* TODO: Multi-function shaders */
         }
index cbd76d5..18127ba 100644 (file)
@@ -325,6 +325,7 @@ typedef struct {
        uint32_t quirks;
 
        /* During NIR->BIR */
+       nir_function_impl *impl;
        bi_block *current_block;
        unsigned block_name_count;
        bi_block *after_block;
@@ -332,6 +333,9 @@ typedef struct {
        bi_block *continue_block;
        bool emitted_atest;
 
+       /* For creating temporaries */
+       unsigned temp_alloc;
+
        /* Stats for shader-db */
        unsigned instruction_count;
        unsigned loop_count;
@@ -376,6 +380,18 @@ bi_remove_instruction(bi_instruction *ins)
         (BIR_INDEX_CONSTANT | BIR_INDEX_ZERO)
 
 static inline unsigned
+bi_make_temp(bi_context *ctx)
+{
+        return (ctx->impl->ssa_alloc + 1 + ctx->temp_alloc++) << 1;
+}
+
+static inline unsigned
+bi_make_temp_reg(bi_context *ctx)
+{
+        return ((ctx->impl->reg_alloc + ctx->temp_alloc++) << 1) | BIR_IS_REG;
+}
+
+static inline unsigned
 bir_ssa_index(nir_ssa_def *ssa)
 {
         /* Off-by-one ensures BIR_NO_ARG is skipped */