From 87ebad74e5d1d7b8c77218caa3199706d01df731 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 26 Jul 2021 12:15:41 -0400 Subject: [PATCH] pan/bi: Refactor constant folding for testability Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_opt_constant_fold.c | 29 +++++++++------------ src/panfrost/bifrost/compiler.h | 4 ++- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/panfrost/bifrost/bi_opt_constant_fold.c b/src/panfrost/bifrost/bi_opt_constant_fold.c index e1c048fc0ed..bf4cae2e5ae 100644 --- a/src/panfrost/bifrost/bi_opt_constant_fold.c +++ b/src/panfrost/bifrost/bi_opt_constant_fold.c @@ -28,12 +28,24 @@ * adding a new pattern here, check why you need it and whether we can avoid * generating the constant BIR at all. */ -static uint32_t +uint32_t bi_fold_constant(bi_instr *I, bool *unsupported) { + /* We can only fold instructions where all sources are constant */ + bi_foreach_src(I, s) { + enum bi_index_type type = I->src[s].type; + + if (!(type == BI_INDEX_NULL || type == BI_INDEX_CONSTANT)) { + *unsupported = true; + return 0; + } + } + + /* Grab the sources */ uint32_t a = bi_apply_swizzle(I->src[0].value, I->src[0].swizzle); uint32_t b = bi_apply_swizzle(I->src[1].value, I->src[1].swizzle); + /* Evaluate the instruction */ switch (I->op) { case BI_OPCODE_SWZ_V2I16: return a; @@ -47,25 +59,10 @@ bi_fold_constant(bi_instr *I, bool *unsupported) } } -static bool -bi_all_srcs_const(bi_instr *I) -{ - bi_foreach_src(I, s) { - enum bi_index_type type = I->src[s].type; - - if (!(type == BI_INDEX_NULL || type == BI_INDEX_CONSTANT)) - return false; - } - - return true; -} - void bi_opt_constant_fold(bi_context *ctx) { bi_foreach_instr_global_safe(ctx, ins) { - if (!bi_all_srcs_const(ins)) continue; - bool unsupported = false; uint32_t replace = bi_fold_constant(ins, &unsupported); if (unsupported) continue; diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index b469a067697..0858a358c35 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -889,13 +889,15 @@ void bi_opt_mod_prop_backward(bi_context *ctx); void bi_opt_dead_code_eliminate(bi_context *ctx); void bi_opt_dce_post_ra(bi_context *ctx); void bi_opt_push_ubo(bi_context *ctx); -void bi_opt_constant_fold(bi_context *ctx); void bi_lower_swizzle(bi_context *ctx); void bi_lower_fau(bi_context *ctx); void bi_schedule(bi_context *ctx); void bi_assign_scoreboard(bi_context *ctx); void bi_register_allocate(bi_context *ctx); +uint32_t bi_fold_constant(bi_instr *I, bool *unsupported); +void bi_opt_constant_fold(bi_context *ctx); + /* Test suite */ int bi_test_scheduler(void); int bi_test_packing(void);