mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 05:08:08 +02:00
pan/bi: Refactor constant folding for testability
Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12026>
This commit is contained in:
parent
972d517d41
commit
87ebad74e5
2 changed files with 16 additions and 17 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue