summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/panfrost/midgard
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2019-05-23 01:56:03 +0000
committerAlyssa Rosenzweig <[email protected]>2019-06-04 20:14:50 +0000
commit2a79afc5f0a8500194cd6e60ff7ceb14c191c5c7 (patch)
treeec4a937ed00352a50b27802f75f1efddc5ebe666 /src/gallium/drivers/panfrost/midgard
parent3c7abbfbe8d031bd8f3248636e94af3c9dbe1a7d (diff)
panfrost/midgard: Helpers for pipeline
Signed-off-by: Alyssa Rosenzweig <[email protected]> Reviewed-by: Ryan Houdek <[email protected]>
Diffstat (limited to 'src/gallium/drivers/panfrost/midgard')
-rw-r--r--src/gallium/drivers/panfrost/midgard/compiler.h19
-rw-r--r--src/gallium/drivers/panfrost/midgard/helpers.h3
-rw-r--r--src/gallium/drivers/panfrost/midgard/midgard_compile.c12
-rw-r--r--src/gallium/drivers/panfrost/midgard/mir.c53
4 files changed, 78 insertions, 9 deletions
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 fab50d671a8..b57b46aaecd 100644
--- a/src/gallium/drivers/panfrost/midgard/midgard_compile.c
+++ b/src/gallium/drivers/panfrost/midgard/midgard_compile.c
@@ -1484,13 +1484,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. */
@@ -2544,6 +2537,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 <[email protected]>
+ *
+ * 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);
+}