Path: blob/21.2-virgl/src/gallium/drivers/r300/compiler/radeon_pair_dead_sources.c
4574 views
/*1* Copyright 2011 Tom Stellard <[email protected]>2*3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial15* portions of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,18* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.20* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE21* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION22* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION23* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25*/2627#include "radeon_compiler.h"28#include "radeon_compiler_util.h"29#include "radeon_opcodes.h"30#include "radeon_program_pair.h"3132static void mark_used_presub(struct rc_pair_sub_instruction * sub)33{34if (sub->Src[RC_PAIR_PRESUB_SRC].Used) {35unsigned int presub_reg_count = rc_presubtract_src_reg_count(36sub->Src[RC_PAIR_PRESUB_SRC].Index);37unsigned int i;38for (i = 0; i < presub_reg_count; i++) {39sub->Src[i].Used = 1;40}41}42}4344static void mark_used(45struct rc_instruction * inst,46struct rc_pair_sub_instruction * sub)47{48unsigned int i;49const struct rc_opcode_info * info = rc_get_opcode_info(sub->Opcode);50for (i = 0; i < info->NumSrcRegs; i++) {51unsigned int src_type = rc_source_type_swz(sub->Arg[i].Swizzle);52if (src_type & RC_SOURCE_RGB) {53inst->U.P.RGB.Src[sub->Arg[i].Source].Used = 1;54}5556if (src_type & RC_SOURCE_ALPHA) {57inst->U.P.Alpha.Src[sub->Arg[i].Source].Used = 1;58}59}60}6162/**63* This pass finds sources that are not used by their instruction and marks64* them as unused.65*/66void rc_pair_remove_dead_sources(struct radeon_compiler * c, void *user)67{68struct rc_instruction * inst;69for (inst = c->Program.Instructions.Next;70inst != &c->Program.Instructions;71inst = inst->Next) {72unsigned int i;73if (inst->Type == RC_INSTRUCTION_NORMAL)74continue;7576/* Mark all sources as unused */77for (i = 0; i < 4; i++) {78inst->U.P.RGB.Src[i].Used = 0;79inst->U.P.Alpha.Src[i].Used = 0;80}81mark_used(inst, &inst->U.P.RGB);82mark_used(inst, &inst->U.P.Alpha);8384mark_used_presub(&inst->U.P.RGB);85mark_used_presub(&inst->U.P.Alpha);86}87}888990