From 84322b2f315d5dfdb15302ed6cbe5ed79d775d69 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 27 Apr 2016 18:59:31 -0700 Subject: [PATCH] vc4: Remove the CSE pass. It's not doing anything according to shader-db now that we're using NIR. It would have had to be reworked significantly anyway, to handle control flow. --- src/gallium/drivers/vc4/Makefile.sources | 1 - src/gallium/drivers/vc4/vc4_opt_cse.c | 159 ----------------------- src/gallium/drivers/vc4/vc4_qir.c | 1 - src/gallium/drivers/vc4/vc4_qir.h | 1 - 4 files changed, 162 deletions(-) delete mode 100644 src/gallium/drivers/vc4/vc4_opt_cse.c diff --git a/src/gallium/drivers/vc4/Makefile.sources b/src/gallium/drivers/vc4/Makefile.sources index c5df0f17986..78d77c6b288 100644 --- a/src/gallium/drivers/vc4/Makefile.sources +++ b/src/gallium/drivers/vc4/Makefile.sources @@ -25,7 +25,6 @@ C_SOURCES := \ vc4_opt_algebraic.c \ vc4_opt_constant_folding.c \ vc4_opt_copy_propagation.c \ - vc4_opt_cse.c \ vc4_opt_dead_code.c \ vc4_opt_small_immediates.c \ vc4_opt_vpm.c \ diff --git a/src/gallium/drivers/vc4/vc4_opt_cse.c b/src/gallium/drivers/vc4/vc4_opt_cse.c deleted file mode 100644 index 8b4d429074c..00000000000 --- a/src/gallium/drivers/vc4/vc4_opt_cse.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright © 2014 Broadcom - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -/** - * @file vc4_opt_cse.c - * - * Implements CSE for QIR without control flow. - * - * For each operation that writes a destination (and isn't just a MOV), put it - * in the hash table of all instructions that do so. When faced with another - * one, look it up in the hash table by its opcode and operands. If there's - * an entry in the table, then just reuse the entry's destination as the - * source of a MOV instead of reproducing the computation. That MOV will then - * get cleaned up by copy propagation. - */ - -#include "vc4_qir.h" - -#include "util/hash_table.h" -#include "util/ralloc.h" - -static bool debug; - -struct inst_key { - enum qop op; - struct qreg src[4]; - /** - * If the instruction depends on the flags, how many SFs have been - * seen before this instruction. - */ - uint32_t implicit_arg_update_count; -}; - -static bool -inst_key_equals(const void *a, const void *b) -{ - const struct inst_key *key_a = a; - const struct inst_key *key_b = b; - - return memcmp(key_a, key_b, sizeof(*key_a)) == 0; -} - -static struct qinst * -vc4_find_cse(struct vc4_compile *c, struct hash_table *ht, - struct qinst *inst, uint32_t sf_count) -{ - if (inst->dst.file != QFILE_TEMP || - !c->defs[inst->dst.index] || - inst->op == QOP_MOV || - qir_get_op_nsrc(inst->op) > 4) { - return NULL; - } - - struct inst_key key; - memset(&key, 0, sizeof(key)); - key.op = inst->op; - memcpy(key.src, inst->src, - qir_get_op_nsrc(inst->op) * sizeof(key.src[0])); - if (qir_depends_on_flags(inst)) - key.implicit_arg_update_count = sf_count; - - uint32_t hash = _mesa_hash_data(&key, sizeof(key)); - struct hash_entry *entry = - _mesa_hash_table_search_pre_hashed(ht, hash, &key); - - if (entry) { - if (debug) { - fprintf(stderr, "CSE found match:\n"); - - fprintf(stderr, " Original inst: "); - qir_dump_inst(c, entry->data); - fprintf(stderr, "\n"); - - fprintf(stderr, " Our inst: "); - qir_dump_inst(c, inst); - fprintf(stderr, "\n"); - } - - return entry->data; - } - - struct inst_key *alloc_key = ralloc(ht, struct inst_key); - if (!alloc_key) - return NULL; - memcpy(alloc_key, &key, sizeof(*alloc_key)); - _mesa_hash_table_insert_pre_hashed(ht, hash, alloc_key, inst); - - if (debug) { - fprintf(stderr, "Added to CSE HT: "); - qir_dump_inst(c, inst); - fprintf(stderr, "\n"); - } - - return NULL; -} - -bool -qir_opt_cse(struct vc4_compile *c) -{ - bool progress = false; - uint32_t sf_count = 0; - - struct hash_table *ht = _mesa_hash_table_create(NULL, NULL, - inst_key_equals); - if (!ht) - return false; - - list_for_each_entry(struct qinst, inst, &c->instructions, link) { - if (qir_has_side_effects(c, inst) || - qir_has_side_effect_reads(c, inst) || - inst->op == QOP_TLB_COLOR_READ) { - continue; - } - - if (inst->sf) { - sf_count++; - } else { - struct qinst *cse = vc4_find_cse(c, ht, inst, sf_count); - if (cse) { - inst->src[0] = cse->dst; - for (int i = 1; i < qir_get_op_nsrc(inst->op); - i++) - inst->src[i] = c->undef; - inst->op = QOP_MOV; - progress = true; - - if (debug) { - fprintf(stderr, " Turned into: "); - qir_dump_inst(c, inst); - fprintf(stderr, "\n"); - } - } - } - } - - ralloc_free(ht); - - return progress; -} diff --git a/src/gallium/drivers/vc4/vc4_qir.c b/src/gallium/drivers/vc4/vc4_qir.c index 293eb01adab..3ba98ca9141 100644 --- a/src/gallium/drivers/vc4/vc4_qir.c +++ b/src/gallium/drivers/vc4/vc4_qir.c @@ -540,7 +540,6 @@ qir_optimize(struct vc4_compile *c) bool progress = false; OPTPASS(qir_opt_algebraic); - OPTPASS(qir_opt_cse); OPTPASS(qir_opt_constant_folding); OPTPASS(qir_opt_copy_propagation); OPTPASS(qir_opt_dead_code); diff --git a/src/gallium/drivers/vc4/vc4_qir.h b/src/gallium/drivers/vc4/vc4_qir.h index 62624d4b1e2..7d2bdc093ef 100644 --- a/src/gallium/drivers/vc4/vc4_qir.h +++ b/src/gallium/drivers/vc4/vc4_qir.h @@ -489,7 +489,6 @@ void qir_optimize(struct vc4_compile *c); bool qir_opt_algebraic(struct vc4_compile *c); bool qir_opt_constant_folding(struct vc4_compile *c); bool qir_opt_copy_propagation(struct vc4_compile *c); -bool qir_opt_cse(struct vc4_compile *c); bool qir_opt_dead_code(struct vc4_compile *c); bool qir_opt_small_immediates(struct vc4_compile *c); bool qir_opt_vpm(struct vc4_compile *c); -- 2.30.2