Path: blob/21.2-virgl/src/panfrost/midgard/midgard_opt_copy_prop.c
4564 views
/*1* Copyright (C) 2018 Alyssa Rosenzweig2* Copyright (C) 2019 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"25#include "midgard_ops.h"2627bool28midgard_opt_copy_prop(compiler_context *ctx, midgard_block *block)29{30bool progress = false;3132mir_foreach_instr_in_block_safe(block, ins) {33if (ins->type != TAG_ALU_4) continue;34if (!OP_IS_MOVE(ins->op)) continue;35if (ins->is_pack) continue;3637unsigned from = ins->src[1];38unsigned to = ins->dest;3940/* We only work on pure SSA */4142if (to & PAN_IS_REG) continue;43if (from & PAN_IS_REG) continue;4445/* Constant propagation is not handled here, either */46if (ins->has_inline_constant) continue;47if (ins->has_constants) continue;4849/* Modifier propagation is not handled here */50if (mir_nontrivial_mod(ins, 1, false)) continue;51if (mir_nontrivial_outmod(ins)) continue;5253/* Shortened arguments (bias for textures, extra load/store54* arguments, etc.) do not get a swizzle, only a start55* component and even that is restricted. Fragment writeout56* doesn't even get that much */5758bool skip = false;5960mir_foreach_instr_global(ctx, q) {61bool is_tex = q->type == TAG_TEXTURE_4;62bool is_ldst = q->type == TAG_LOAD_STORE_4;63bool is_branch = q->compact_branch;6465if (!(is_tex || is_ldst || is_branch)) continue;6667/* For textures, we get a real swizzle for the68* coordinate and the content. For stores, we get one.69* For loads, we get none. */7071unsigned start =72is_tex ? 2 :73OP_IS_STORE(q->op) ? 1 : 0;7475mir_foreach_src(q, s) {76if ((s >= start) && q->src[s] == to) {77skip = true;78break;79}80}81}8283if (skip)84continue;8586if (ctx->blend_src1 == to)87ctx->blend_src1 = from;8889/* We're clear -- rewrite, composing the swizzle */90mir_rewrite_index_src_swizzle(ctx, to, from, ins->swizzle[1]);91mir_remove_instruction(ins);92progress |= true;93}9495return progress;96}979899