pan/bi: Add "soft" mode to DCE

We would like to reuse the DCE logic to eliminate register writes
without eliminating instructions, as a post-sched pass. This type of
operation will eventually generalize to intrinsics that write a register
*and* have side effects (just atomics, I think).

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8723>
This commit is contained in:
Alyssa Rosenzweig 2020-12-30 13:41:14 -05:00 committed by Marge Bot
parent 623bd2127f
commit 3ce67cb0d9
3 changed files with 16 additions and 4 deletions

View file

@ -25,8 +25,16 @@
#include "compiler.h"
#include "util/u_memory.h"
/* A simple liveness-based dead code elimination pass. In 'soft' mode, dead
* instructions are kept but write to null, which is required for correct
* operation post-schedule pass (where dead instructions correspond to
* instructions whose destinations are consumed immediately as a passthrough
* register. If the destinations are not garbage collected, impossible register
* encodings will result.)
*/
bool
bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block)
bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block, bool soft)
{
bool progress = false;
unsigned temp_count = bi_max_temp(ctx);
@ -40,7 +48,11 @@ bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block)
unsigned index = bi_get_node(ins->dest[0]);
if (index < temp_count && !live[index]) {
bi_remove_instruction(ins);
if (soft)
ins->dest[0] = bi_null();
else
bi_remove_instruction(ins);
progress |= true;
}

View file

@ -2389,7 +2389,7 @@ bifrost_compile_shader_nir(void *mem_ctx, nir_shader *nir,
bi_foreach_block(ctx, _block) {
bi_block *block = (bi_block *) _block;
progress |= bi_opt_dead_code_eliminate(ctx, block);
progress |= bi_opt_dead_code_eliminate(ctx, block, false);
}
} while(progress);

View file

@ -703,7 +703,7 @@ void bi_print_shader(bi_context *ctx, FILE *fp);
/* BIR passes */
bool bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block);
bool bi_opt_dead_code_eliminate(bi_context *ctx, bi_block *block, bool soft);
void bi_schedule(bi_context *ctx);
void bi_register_allocate(bi_context *ctx);