• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Tom Stellard <tstellar@gmail.com>
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 
11 static void
mark_used_presub(struct rc_pair_sub_instruction * sub)12 mark_used_presub(struct rc_pair_sub_instruction *sub)
13 {
14    if (sub->Src[RC_PAIR_PRESUB_SRC].Used) {
15       unsigned int presub_reg_count =
16          rc_presubtract_src_reg_count(sub->Src[RC_PAIR_PRESUB_SRC].Index);
17       unsigned int i;
18       for (i = 0; i < presub_reg_count; i++) {
19          sub->Src[i].Used = 1;
20       }
21    }
22 }
23 
24 static void
mark_used(struct rc_instruction * inst,struct rc_pair_sub_instruction * sub)25 mark_used(struct rc_instruction *inst, 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  */
45 void
rc_pair_remove_dead_sources(struct radeon_compiler * c,void * user)46 rc_pair_remove_dead_sources(struct radeon_compiler *c, void *user)
47 {
48    struct rc_instruction *inst;
49    for (inst = c->Program.Instructions.Next; inst != &c->Program.Instructions; inst = inst->Next) {
50       unsigned int i;
51       if (inst->Type == RC_INSTRUCTION_NORMAL)
52          continue;
53 
54       /* Mark all sources as unused */
55       for (i = 0; i < 4; i++) {
56          inst->U.P.RGB.Src[i].Used = 0;
57          inst->U.P.Alpha.Src[i].Used = 0;
58       }
59       mark_used(inst, &inst->U.P.RGB);
60       mark_used(inst, &inst->U.P.Alpha);
61 
62       mark_used_presub(&inst->U.P.RGB);
63       mark_used_presub(&inst->U.P.Alpha);
64    }
65 }
66