Path: blob/21.2-virgl/src/gallium/drivers/vc4/vc4_opt_vpm.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_vpm.c25*26* This modifies instructions that exclusively consume a value read from the27* VPM to directly read the VPM if other operands allow it.28*/2930#include "vc4_qir.h"3132bool33qir_opt_vpm(struct vc4_compile *c)34{35if (c->stage == QSTAGE_FRAG)36return false;3738/* For now, only do this pass when we don't have control flow. */39struct qblock *block = qir_entry_block(c);40if (block != qir_exit_block(c))41return false;4243bool progress = false;44uint32_t use_count[c->num_temps];45memset(&use_count, 0, sizeof(use_count));4647qir_for_each_inst_inorder(inst, c) {48for (int i = 0; i < qir_get_nsrc(inst); i++) {49if (inst->src[i].file == QFILE_TEMP) {50uint32_t temp = inst->src[i].index;51use_count[temp]++;52}53}54}5556/* For instructions reading from a temporary that contains a VPM read57* result, try to move the instruction up in place of the VPM read.58*/59qir_for_each_inst_inorder(inst, c) {60if (!inst)61continue;6263if (qir_depends_on_flags(inst) || inst->sf)64continue;6566if (qir_has_side_effects(c, inst) ||67qir_has_side_effect_reads(c, inst) ||68qir_is_tex(inst))69continue;7071for (int j = 0; j < qir_get_nsrc(inst); j++) {72if (inst->src[j].file != QFILE_TEMP ||73inst->src[j].pack)74continue;7576uint32_t temp = inst->src[j].index;7778/* Since VPM reads pull from a FIFO, we only get to79* read each VPM entry once (unless we reset the read80* pointer). That means we can't copy-propagate a VPM81* read to multiple locations.82*/83if (use_count[temp] != 1)84continue;8586struct qinst *mov = c->defs[temp];87if (!mov ||88(mov->op != QOP_MOV &&89mov->op != QOP_FMOV &&90mov->op != QOP_MMOV) ||91mov->src[0].file != QFILE_VPM) {92continue;93}9495uint32_t temps = 0;96for (int k = 0; k < qir_get_nsrc(inst); k++) {97if (inst->src[k].file == QFILE_TEMP)98temps++;99}100101/* The instruction is safe to reorder if its other102* sources are independent of previous instructions103*/104if (temps == 1) {105inst->src[j] = mov->src[0];106107list_del(&inst->link);108list_addtail(&inst->link, &mov->link);109qir_remove_instruction(c, mov);110111progress = true;112break;113}114}115}116117return progress;118}119120121