From: Alyssa Rosenzweig Date: Wed, 24 Jul 2019 03:01:44 +0000 (-0700) Subject: pan/midgard: Add mir_single_use helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=63385a3fdb6a42013be74091d0264a09550766ee;p=mesa.git pan/midgard: Add mir_single_use helper Helps as an optimization heuristic. Signed-off-by: Alyssa Rosenzweig --- diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h index 2d5f07451a5..50e1846f893 100644 --- a/src/panfrost/midgard/compiler.h +++ b/src/panfrost/midgard/compiler.h @@ -373,6 +373,7 @@ void mir_rewrite_index(compiler_context *ctx, unsigned old, unsigned new); void mir_rewrite_index_src(compiler_context *ctx, unsigned old, unsigned new); void mir_rewrite_index_dst(compiler_context *ctx, unsigned old, unsigned new); void mir_rewrite_index_src_single(midgard_instruction *ins, unsigned old, unsigned new); +bool mir_single_use(compiler_context *ctx, unsigned value); /* MIR printing */ diff --git a/src/panfrost/midgard/mir.c b/src/panfrost/midgard/mir.c index c606cb3ddf7..ea7c65110b4 100644 --- a/src/panfrost/midgard/mir.c +++ b/src/panfrost/midgard/mir.c @@ -57,3 +57,24 @@ mir_rewrite_index(compiler_context *ctx, unsigned old, unsigned new) mir_rewrite_index_src(ctx, old, new); mir_rewrite_index_dst(ctx, old, new); } + +/* Checks if a value is used only once (or totally dead), which is an important + * heuristic to figure out if certain optimizations are Worth It (TM) */ + +bool +mir_single_use(compiler_context *ctx, unsigned value) +{ + unsigned used_count = 0; + + mir_foreach_instr_global(ctx, ins) { + if (mir_has_arg(ins, value)) + ++used_count; + + /* Short circuit for speed */ + if (used_count > 1) + return false; + } + + return used_count <= 1; + +}