From 79f08964914463870a37bc64a28c19a982d54e37 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 26 Jul 2019 09:37:28 -0700 Subject: [PATCH] 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 --- src/panfrost/midgard/compiler.h | 1 + src/panfrost/midgard/mir.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h index 528dfac..84a00fb 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 61427e7..75da2fb 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; +} -- 2.7.4