1 /* 2 * Copyright 2011 Tom Stellard <[email protected]> 3 * SPDX-License-Identifier: MIT 4 */ 5 6 #include "radeon_compiler.h" 7 #include "radeon_compiler_util.h" 8 #include "radeon_opcodes.h" 9 #include "radeon_program_pair.h" 10 mark_used_presub(struct rc_pair_sub_instruction * sub)11static void mark_used_presub(struct rc_pair_sub_instruction * sub) 12 { 13 if (sub->Src[RC_PAIR_PRESUB_SRC].Used) { 14 unsigned int presub_reg_count = rc_presubtract_src_reg_count( 15 sub->Src[RC_PAIR_PRESUB_SRC].Index); 16 unsigned int i; 17 for (i = 0; i < presub_reg_count; i++) { 18 sub->Src[i].Used = 1; 19 } 20 } 21 } 22 mark_used(struct rc_instruction * inst,struct rc_pair_sub_instruction * sub)23static void mark_used( 24 struct rc_instruction * inst, 25 struct rc_pair_sub_instruction * sub) 26 { 27 unsigned int i; 28 const struct rc_opcode_info * info = rc_get_opcode_info(sub->Opcode); 29 for (i = 0; i < info->NumSrcRegs; i++) { 30 unsigned int src_type = rc_source_type_swz(sub->Arg[i].Swizzle); 31 if (src_type & RC_SOURCE_RGB) { 32 inst->U.P.RGB.Src[sub->Arg[i].Source].Used = 1; 33 } 34 35 if (src_type & RC_SOURCE_ALPHA) { 36 inst->U.P.Alpha.Src[sub->Arg[i].Source].Used = 1; 37 } 38 } 39 } 40 41 /** 42 * This pass finds sources that are not used by their instruction and marks 43 * them as unused. 44 */ rc_pair_remove_dead_sources(struct radeon_compiler * c,void * user)45void rc_pair_remove_dead_sources(struct radeon_compiler * c, void *user) 46 { 47 struct rc_instruction * inst; 48 for (inst = c->Program.Instructions.Next; 49 inst != &c->Program.Instructions; 50 inst = inst->Next) { 51 unsigned int i; 52 if (inst->Type == RC_INSTRUCTION_NORMAL) 53 continue; 54 55 /* Mark all sources as unused */ 56 for (i = 0; i < 4; i++) { 57 inst->U.P.RGB.Src[i].Used = 0; 58 inst->U.P.Alpha.Src[i].Used = 0; 59 } 60 mark_used(inst, &inst->U.P.RGB); 61 mark_used(inst, &inst->U.P.Alpha); 62 63 mark_used_presub(&inst->U.P.RGB); 64 mark_used_presub(&inst->U.P.Alpha); 65 } 66 } 67