From 875a34160acfbd4d3a7ce3e250da83719af4e2af Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 26 Jul 2022 13:35:34 -0400 Subject: [PATCH] pan/bi: Add and use bi_replace_src helper This is a common pattern. Make it more ergonomic. With the help of Coccinelle: @@ expression E; expression R; expression instruction; @@ -instruction->src[E] = bi_replace_index(instruction->src[E], R); +bi_replace_src(instruction, E, R); Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_lower_swizzle.c | 3 +-- src/panfrost/bifrost/bi_opt_copy_prop.c | 2 +- src/panfrost/bifrost/bi_opt_cse.c | 2 +- src/panfrost/bifrost/bi_ra.c | 6 +++--- src/panfrost/bifrost/bi_schedule.c | 11 +++++------ src/panfrost/bifrost/compiler.h | 6 ++++++ src/panfrost/bifrost/valhall/va_validate.c | 3 +-- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/panfrost/bifrost/bi_lower_swizzle.c b/src/panfrost/bifrost/bi_lower_swizzle.c index 8e372fa..e159827 100644 --- a/src/panfrost/bifrost/bi_lower_swizzle.c +++ b/src/panfrost/bifrost/bi_lower_swizzle.c @@ -132,8 +132,7 @@ bi_lower_swizzle_16(bi_context *ctx, bi_instr *ins, unsigned src) /* Lower it away */ bi_builder b = bi_init_builder(ctx, bi_before_instr(ins)); - ins->src[src] = bi_replace_index(ins->src[src], - bi_swz_v2i16(&b, ins->src[src])); + bi_replace_src(ins, src, bi_swz_v2i16(&b, ins->src[src])); ins->src[src].swizzle = BI_SWIZZLE_H01; } diff --git a/src/panfrost/bifrost/bi_opt_copy_prop.c b/src/panfrost/bifrost/bi_opt_copy_prop.c index adbac98..13b9b0d 100644 --- a/src/panfrost/bifrost/bi_opt_copy_prop.c +++ b/src/panfrost/bifrost/bi_opt_copy_prop.c @@ -105,7 +105,7 @@ bi_opt_copy_prop(bi_context *ctx) continue; if (!bi_is_null(repl)) - ins->src[s] = bi_replace_index(ins->src[s], repl); + bi_replace_src(ins, s, repl); } } diff --git a/src/panfrost/bifrost/bi_opt_cse.c b/src/panfrost/bifrost/bi_opt_cse.c index 9e822ef..5b4f402 100644 --- a/src/panfrost/bifrost/bi_opt_cse.c +++ b/src/panfrost/bifrost/bi_opt_cse.c @@ -160,7 +160,7 @@ bi_opt_cse(bi_context *ctx) bi_index repl = replacement[instr->src[s].value]; if (!bi_is_null(repl)) - instr->src[s] = bi_replace_index(instr->src[s], repl); + bi_replace_src(instr, s, repl); } if (!instr_can_cse(instr)) diff --git a/src/panfrost/bifrost/bi_ra.c b/src/panfrost/bifrost/bi_ra.c index 4d9fbf6..5a439e9 100644 --- a/src/panfrost/bifrost/bi_ra.c +++ b/src/panfrost/bifrost/bi_ra.c @@ -808,7 +808,7 @@ bi_lower_vector(bi_context *ctx, unsigned first_reg) bi_foreach_instr_global(ctx, I) { bi_foreach_ssa_src(I, s) { if (I->src[s].value < first_reg && !bi_is_null(remap[I->src[s].value])) - I->src[s] = bi_replace_index(I->src[s], remap[I->src[s].value]); + bi_replace_src(I, s, remap[I->src[s].value]); } } @@ -887,7 +887,7 @@ bi_coalesce_tied(bi_context *ctx) bi_mov_i32_to(&b, dst, src); } - I->src[0] = bi_replace_index(I->src[0], I->dest[0]); + bi_replace_src(I, 0, I->dest[0]); } } @@ -977,7 +977,7 @@ bi_out_of_ssa(bi_context *ctx) bi_foreach_src(prop, s) { if (bi_is_equiv(prop->src[s], I->dest[0])) { - prop->src[s] = bi_replace_index(prop->src[s], reg); + bi_replace_src(prop, s, reg); } } } diff --git a/src/panfrost/bifrost/bi_schedule.c b/src/panfrost/bifrost/bi_schedule.c index 5df05ee..877d57a 100644 --- a/src/panfrost/bifrost/bi_schedule.c +++ b/src/panfrost/bifrost/bi_schedule.c @@ -1386,7 +1386,7 @@ bi_rewrite_fau_to_pass(bi_tuple *tuple) bi_index pass = bi_passthrough(ins->src[s].offset ? BIFROST_SRC_FAU_HI : BIFROST_SRC_FAU_LO); - ins->src[s] = bi_replace_index(ins->src[s], pass); + bi_replace_src(ins, s, pass); } } @@ -1399,7 +1399,7 @@ bi_rewrite_zero(bi_instr *ins, bool fma) bi_index src = ins->src[s]; if (src.type == BI_INDEX_CONSTANT && src.value == 0) - ins->src[s] = bi_replace_index(src, zero); + bi_replace_src(ins, s, zero); } } @@ -1430,9 +1430,8 @@ bi_rewrite_constants_to_pass(bi_tuple *tuple, uint64_t constant, bool pcrel) assert(lo || hi); - ins->src[s] = bi_replace_index(ins->src[s], - bi_passthrough(hi ? BIFROST_SRC_FAU_HI : - BIFROST_SRC_FAU_LO)); + bi_replace_src(ins, s, + bi_passthrough(hi ? BIFROST_SRC_FAU_HI : BIFROST_SRC_FAU_LO)); } } @@ -2062,7 +2061,7 @@ bi_lower_fau(bi_context *ctx) if (bi_check_fau_src(ins, s, constants, &cwords, &fau)) continue; bi_index copy = bi_mov_i32(&b, ins->src[s]); - ins->src[s] = bi_replace_index(ins->src[s], copy); + bi_replace_src(ins, s, copy); } } } diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 64b777f..b8a462c 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -574,6 +574,12 @@ bi_drop_srcs(bi_instr *I, unsigned new_count) I->nr_srcs = new_count; } +static inline void +bi_replace_src(bi_instr *I, unsigned src_index, bi_index replacement) +{ + I->src[src_index] = bi_replace_index(I->src[src_index], replacement); +} + /* Represents the assignment of slots for a given bi_tuple */ typedef struct { diff --git a/src/panfrost/bifrost/valhall/va_validate.c b/src/panfrost/bifrost/valhall/va_validate.c index e404d74..847a92a 100644 --- a/src/panfrost/bifrost/valhall/va_validate.c +++ b/src/panfrost/bifrost/valhall/va_validate.c @@ -135,8 +135,7 @@ va_repair_fau(bi_builder *b, bi_instr *I) bi_index src = I->src[s]; if (!valid_src(&fau, fau_page, src)) { - bi_index copy = bi_mov_i32(b, bi_strip_index(src)); - I->src[s] = bi_replace_index(src, copy); + bi_replace_src(I, s, bi_mov_i32(b, bi_strip_index(src))); /* Rollback update. Since the replacement move doesn't affect FAU * state, there is no need to call valid_src again. -- 2.7.4