Path: blob/21.2-virgl/src/gallium/drivers/vc4/vc4_opt_coalesce_ff_writes.c
4570 views
/*1* Copyright © 2014 Broadcom2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223/**24* @file vc4_opt_coalesce_ff_writes.c25*26* This modifies instructions that generate the value consumed by a VPM or TMU27* coordinate write to write directly into the VPM or TMU.28*/2930#include "vc4_qir.h"3132bool33qir_opt_coalesce_ff_writes(struct vc4_compile *c)34{35/* For now, only do this pass when we don't have control flow. */36struct qblock *block = qir_entry_block(c);37if (block != qir_exit_block(c))38return false;3940bool progress = false;41uint32_t use_count[c->num_temps];42memset(&use_count, 0, sizeof(use_count));4344qir_for_each_inst_inorder(inst, c) {45for (int i = 0; i < qir_get_nsrc(inst); i++) {46if (inst->src[i].file == QFILE_TEMP) {47uint32_t temp = inst->src[i].index;48use_count[temp]++;49}50}51}5253qir_for_each_inst_inorder(mov_inst, c) {54if (!qir_is_raw_mov(mov_inst) || mov_inst->sf)55continue;56if (mov_inst->src[0].file != QFILE_TEMP)57continue;5859if (!(mov_inst->dst.file == QFILE_VPM ||60mov_inst->dst.file == QFILE_TLB_COLOR_WRITE ||61mov_inst->dst.file == QFILE_TLB_COLOR_WRITE_MS ||62qir_is_tex(mov_inst)))63continue;6465uint32_t temp = mov_inst->src[0].index;66if (use_count[temp] != 1)67continue;6869struct qinst *inst = c->defs[temp];70if (!inst)71continue;7273/* Don't bother trying to fold in an ALU op using a uniform to74* a texture op, as we'll just have to lower the uniform back75* out.76*/77if (qir_is_tex(mov_inst) && qir_has_uniform_read(inst))78continue;7980if (qir_depends_on_flags(inst) || inst->sf)81continue;8283if (qir_has_side_effects(c, inst) ||84qir_has_side_effect_reads(c, inst) ||85inst->op == QOP_TLB_COLOR_READ ||86inst->op == QOP_VARY_ADD_C) {87continue;88}8990/* Move the generating instruction into the position of the FF91* write.92*/93c->defs[inst->dst.index] = NULL;94inst->dst.file = mov_inst->dst.file;95inst->dst.index = mov_inst->dst.index;96if (qir_has_implicit_tex_uniform(mov_inst)) {97inst->src[qir_get_tex_uniform_src(inst)] =98mov_inst->src[qir_get_tex_uniform_src(mov_inst)];99}100101list_del(&inst->link);102list_addtail(&inst->link, &mov_inst->link);103104qir_remove_instruction(c, mov_inst);105106progress = true;107}108109return progress;110}111112113