#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);
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;
}
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);
/* 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);