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