vc4: Dead code eliminate unused SF instructions.

This commit is contained in:
Eric Anholt 2014-10-09 14:45:14 +02:00
parent 93cac2637b
commit b73cab6826
1 changed files with 26 additions and 7 deletions

View File

@ -33,12 +33,25 @@
#include "vc4_qir.h"
static bool debug;
static void
dce(struct vc4_compile *c, struct qinst *inst)
{
if (debug) {
fprintf(stderr, "Removing: ");
qir_dump_inst(c, inst);
fprintf(stderr, "\n");
}
qir_remove_instruction(inst);
}
bool
qir_opt_dead_code(struct vc4_compile *c)
{
bool progress = false;
bool debug = false;
bool *used = calloc(c->num_temps, sizeof(bool));
bool sf_used = false;
struct simple_node *node, *t;
for (node = c->instructions.prev, t = node->prev;
@ -49,16 +62,22 @@ qir_opt_dead_code(struct vc4_compile *c)
if (inst->dst.file == QFILE_TEMP &&
!used[inst->dst.index] &&
!qir_has_side_effects(inst)) {
if (debug) {
fprintf(stderr, "Removing: ");
qir_dump_inst(c, inst);
fprintf(stderr, "\n");
}
qir_remove_instruction(inst);
dce(c, inst);
progress = true;
continue;
}
if (qir_depends_on_flags(inst))
sf_used = true;
if (inst->op == QOP_SF) {
if (!sf_used) {
dce(c, inst);
progress = true;
continue;
}
sf_used = false;
}
for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
if (inst->src[i].file == QFILE_TEMP)
used[inst->src[i].index] = true;