Path: blob/21.2-virgl/src/panfrost/bifrost/bi_opt_copy_prop.c
4564 views
/*1* Copyright (C) 2018 Alyssa Rosenzweig2* Copyright (C) 2019-2020 Collabora, Ltd.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#include "compiler.h"2526/* A simple scalar-only SSA-based copy-propagation pass. TODO: vectors */2728static bool29bi_is_copy(bi_instr *ins)30{31return (ins->op == BI_OPCODE_MOV_I32) && bi_is_ssa(ins->dest[0])32&& (bi_is_ssa(ins->src[0]) || ins->src[0].type == BI_INDEX_FAU33|| ins->src[0].type == BI_INDEX_CONSTANT);34}3536static bool37bi_reads_fau(bi_instr *ins)38{39bi_foreach_src(ins, s) {40if (ins->src[s].type == BI_INDEX_FAU)41return true;42}4344return false;45}4647void48bi_opt_copy_prop(bi_context *ctx)49{50bi_index *replacement = calloc(sizeof(bi_index), ((ctx->ssa_alloc + 1) << 2));5152bi_foreach_instr_global_safe(ctx, ins) {53if (bi_is_copy(ins)) {54bi_index replace = ins->src[0];5556/* Peek through one layer so copyprop converges in one57* iteration for chained moves */58if (bi_is_ssa(replace)) {59bi_index chained = replacement[bi_word_node(replace)];6061if (!bi_is_null(chained))62replace = chained;63}6465replacement[bi_word_node(ins->dest[0])] = replace;66}6768bi_foreach_src(ins, s) {69bi_index use = ins->src[s];7071if (use.type != BI_INDEX_NORMAL || use.reg) continue;72if (s == 0 && bi_opcode_props[ins->op].sr_read) continue;7374bi_index repl = replacement[bi_word_node(use)];7576if (repl.type == BI_INDEX_CONSTANT && bi_reads_fau(ins))77continue;7879if (!bi_is_null(repl))80ins->src[s] = bi_replace_index(ins->src[s], repl);81}82}8384free(replacement);85}868788