summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlyssa Rosenzweig <[email protected]>2019-07-26 09:37:28 -0700
committerAlyssa Rosenzweig <[email protected]>2019-07-26 09:37:28 -0700
commit79f08964914463870a37bc64a28c19a982d54e37 (patch)
tree6e18d02ca28dd6fee3ac7d832635d28a0d564a51 /src
parent481447cb00821fdc81d7ab328a8c70a02546cf78 (diff)
pan/midgard: Add mir_mask_of_read_components helper
This facilitates analysis of vec4 registers (after going out-of-SSA). Signed-off-by: Alyssa Rosenzweig <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/panfrost/midgard/compiler.h1
-rw-r--r--src/panfrost/midgard/mir.c40
2 files changed, 41 insertions, 0 deletions
diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h
index 528dfacdc3b..84a00fb0174 100644
--- a/src/panfrost/midgard/compiler.h
+++ b/src/panfrost/midgard/compiler.h
@@ -382,6 +382,7 @@ bool mir_single_use(compiler_context *ctx, unsigned value);
bool mir_special_index(compiler_context *ctx, unsigned idx);
unsigned mir_use_count(compiler_context *ctx, unsigned value);
bool mir_is_written_before(compiler_context *ctx, midgard_instruction *ins, unsigned node);
+unsigned mir_mask_of_read_components(midgard_instruction *ins, unsigned node);
/* MIR printing */
diff --git a/src/panfrost/midgard/mir.c b/src/panfrost/midgard/mir.c
index 61427e7c3d5..75da2fb0864 100644
--- a/src/panfrost/midgard/mir.c
+++ b/src/panfrost/midgard/mir.c
@@ -194,3 +194,43 @@ mir_is_written_before(compiler_context *ctx, midgard_instruction *ins, unsigned
return false;
}
+
+/* Creates a mask of the components of a node read by an instruction, by
+ * analyzing the swizzle with respect to the instruction's mask. E.g.:
+ *
+ * fadd r0.xz, r1.yyyy, r2.zwyx
+ *
+ * will return a mask of Z/Y for r2
+ */
+
+static unsigned
+mir_mask_of_read_components_single(unsigned src, unsigned outmask)
+{
+ midgard_vector_alu_src s = vector_alu_from_unsigned(src);
+ unsigned mask = 0;
+
+ for (unsigned c = 0; c < 4; ++c) {
+ if (!(outmask & (1 << c))) continue;
+
+ unsigned comp = (s.swizzle >> (2*c)) & 3;
+ mask |= (1 << comp);
+ }
+
+ return mask;
+}
+
+unsigned
+mir_mask_of_read_components(midgard_instruction *ins, unsigned node)
+{
+ assert(ins->type == TAG_ALU_4);
+
+ unsigned mask = 0;
+
+ if (ins->ssa_args.src0 == node)
+ mask |= mir_mask_of_read_components_single(ins->alu.src1, ins->mask);
+
+ if (ins->ssa_args.src1 == node && !ins->ssa_args.inline_constant)
+ mask |= mir_mask_of_read_components_single(ins->alu.src2, ins->mask);
+
+ return mask;
+}