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)); struct simple_node *node, *t; for (node = c->instructions.prev, t = node->prev; &c->instructions != node; node = t, t = t->prev) { struct qinst *inst = (struct qinst *)node; if (inst->dst.file == QFILE_TEMP && !used[inst->dst.index] && !qir_has_side_effects(inst)) { if (debug) { fprintf(stderr, "Removing: "); qir_dump_inst(inst); fprintf(stderr, "\n"); } qir_remove_instruction(inst); progress = true; continue; } 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; } } free(used); return progress; }