[Mesa-dev] [PATCH 09/13] panfrost/midgard: Add MIR helpers

Alyssa Rosenzweig alyssa at rosenzweig.io
Sun May 26 02:39:20 UTC 2019


In addition to commonizing some related utilities, this adds new MIR
helper functions relevant to passes including pipeline register
creation.

Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
---
 src/gallium/drivers/panfrost/meson.build      |  1 +
 .../drivers/panfrost/midgard/compiler.h       | 19 ++++++-
 .../drivers/panfrost/midgard/helpers.h        |  3 ++
 .../panfrost/midgard/midgard_compile.c        | 12 ++---
 src/gallium/drivers/panfrost/midgard/mir.c    | 53 +++++++++++++++++++
 5 files changed, 79 insertions(+), 9 deletions(-)
 create mode 100644 src/gallium/drivers/panfrost/midgard/mir.c

diff --git a/src/gallium/drivers/panfrost/meson.build b/src/gallium/drivers/panfrost/meson.build
index 5adf24282c4..297bdb341bd 100644
--- a/src/gallium/drivers/panfrost/meson.build
+++ b/src/gallium/drivers/panfrost/meson.build
@@ -27,6 +27,7 @@ files_panfrost = files(
   'pan_resource.h',
 
   'midgard/midgard_compile.c',
+  'midgard/mir.c',
   'midgard/midgard_print.c',
   'midgard/midgard_schedule.c',
   'midgard/midgard_emit.c',
diff --git a/src/gallium/drivers/panfrost/midgard/compiler.h b/src/gallium/drivers/panfrost/midgard/compiler.h
index 96760d964b0..37ed2362263 100644
--- a/src/gallium/drivers/panfrost/midgard/compiler.h
+++ b/src/gallium/drivers/panfrost/midgard/compiler.h
@@ -312,8 +312,6 @@ mir_next_op(struct midgard_instruction *ins)
 #define mir_foreach_block_from(ctx, from, v) \
         list_for_each_entry_from(struct midgard_block, v, from, &ctx->blocks, link)
 
-/* The following routines are for use before the scheduler has run */
-
 #define mir_foreach_instr(ctx, v) \
         list_for_each_entry(struct midgard_instruction, v, &ctx->current_block->instructions, link) 
 
@@ -338,6 +336,11 @@ mir_next_op(struct midgard_instruction *ins)
 #define mir_foreach_bundle_in_block(block, v) \
         util_dynarray_foreach(&block->bundles, midgard_bundle, v)
 
+#define mir_foreach_instr_global(ctx, v) \
+        mir_foreach_block(ctx, v_block) \
+                mir_foreach_instr_in_block(v_block, v)
+
+
 static inline midgard_instruction *
 mir_last_in_block(struct midgard_block *block)
 {
@@ -355,6 +358,18 @@ mir_get_block(compiler_context *ctx, int idx)
         return (struct midgard_block *) lst;
 }
 
+static inline bool
+mir_is_alu_bundle(midgard_bundle *bundle)
+{
+        return IS_ALU(bundle->tag);
+}
+
+/* MIR manipulation */
+
+void mir_rewrite_index(compiler_context *ctx, unsigned old, unsigned new);
+void mir_rewrite_index_src(compiler_context *ctx, unsigned old, unsigned new);
+void mir_rewrite_index_dst(compiler_context *ctx, unsigned old, unsigned new);
+
 /* MIR printing */
 
 void mir_print_instruction(midgard_instruction *ins);
diff --git a/src/gallium/drivers/panfrost/midgard/helpers.h b/src/gallium/drivers/panfrost/midgard/helpers.h
index 9adc5b35195..b6ab3c86c97 100644
--- a/src/gallium/drivers/panfrost/midgard/helpers.h
+++ b/src/gallium/drivers/panfrost/midgard/helpers.h
@@ -112,6 +112,9 @@ quadword_size(int tag)
         }
 }
 
+#define IS_ALU(tag) (tag == TAG_ALU_4 || tag == TAG_ALU_8 ||  \
+		     tag == TAG_ALU_12 || tag == TAG_ALU_16)
+
 /* Special register aliases */
 
 #define MAX_WORK_REGISTERS 16
diff --git a/src/gallium/drivers/panfrost/midgard/midgard_compile.c b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
index 55337ed9318..d6d8add8ef6 100644
--- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c
+++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
@@ -1465,13 +1465,6 @@ emit_instr(compiler_context *ctx, struct nir_instr *instr)
         }
 }
 
-/* Midgard prefetches instruction types, so during emission we need to
- * lookahead too. Unless this is the last instruction, in which we return 1. Or
- * if this is the second to last and the last is an ALU, then it's also 1... */
-
-#define IS_ALU(tag) (tag == TAG_ALU_4 || tag == TAG_ALU_8 ||  \
-		     tag == TAG_ALU_12 || tag == TAG_ALU_16)
-
 
 /* ALU instructions can inline or embed constants, which decreases register
  * pressure and saves space. */
@@ -2525,6 +2518,11 @@ midgard_compile_shader_nir(nir_shader *nir, midgard_program *program, bool is_bl
 
         int current_bundle = 0;
 
+        /* Midgard prefetches instruction types, so during emission we
+         * need to lookahead. Unless this is the last instruction, in
+         * which we return 1. Or if this is the second to last and the
+         * last is an ALU, then it's also 1... */
+
         mir_foreach_block(ctx, block) {
                 util_dynarray_foreach(&block->bundles, midgard_bundle, bundle) {
                         int lookahead = 1;
diff --git a/src/gallium/drivers/panfrost/midgard/mir.c b/src/gallium/drivers/panfrost/midgard/mir.c
new file mode 100644
index 00000000000..263aafadec0
--- /dev/null
+++ b/src/gallium/drivers/panfrost/midgard/mir.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2019 Alyssa Rosenzweig <alyssa at rosenzweig.io>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "compiler.h"
+
+void
+mir_rewrite_index_src(compiler_context *ctx, unsigned old, unsigned new)
+{
+        mir_foreach_instr_global(ctx, ins) {
+                if (ins->ssa_args.src0 == old)
+                        ins->ssa_args.src0 = new;
+
+                if (ins->ssa_args.src1 == old &&
+                                !ins->ssa_args.inline_constant)
+                        ins->ssa_args.src1 = new;
+        }
+}
+
+void
+mir_rewrite_index_dst(compiler_context *ctx, unsigned old, unsigned new)
+{
+        mir_foreach_instr_global(ctx, ins) {
+                if (ins->ssa_args.dest == old)
+                        ins->ssa_args.dest = new;
+        }
+}
+
+void
+mir_rewrite_index(compiler_context *ctx, unsigned old, unsigned new)
+{
+        mir_rewrite_index_src(ctx, old, new);
+        mir_rewrite_index_dst(ctx, old, new);
+}
-- 
2.20.1



More information about the mesa-dev mailing list