Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 1 | /* |
2 | * Copyright 2013 Vadim Girlin |
||
3 | * |
||
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
5 | * copy of this software and associated documentation files (the "Software"), |
||
6 | * to deal in the Software without restriction, including without limitation |
||
7 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
||
8 | * license, and/or sell copies of the Software, and to permit persons to whom |
||
9 | * the Software is furnished to do so, subject to the following conditions: |
||
10 | * |
||
11 | * The above copyright notice and this permission notice (including the next |
||
12 | * paragraph) shall be included in all copies or substantial portions of the |
||
13 | * Software. |
||
14 | * |
||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
18 | * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
||
19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
||
20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
||
21 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
22 | * |
||
23 | * Authors: |
||
24 | * Vadim Girlin |
||
25 | */ |
||
26 | |||
27 | #include "sb_shader.h" |
||
28 | |||
29 | #include "sb_pass.h" |
||
30 | |||
31 | namespace r600_sb { |
||
32 | |||
33 | bool dce_cleanup::visit(node& n, bool enter) { |
||
34 | if (enter) { |
||
35 | } else { |
||
36 | if (n.flags & NF_DEAD) |
||
37 | n.remove(); |
||
38 | else |
||
39 | cleanup_dst(n); |
||
40 | } |
||
41 | return true; |
||
42 | } |
||
43 | |||
44 | bool dce_cleanup::visit(alu_group_node& n, bool enter) { |
||
45 | if (enter) { |
||
46 | } else { |
||
47 | n.expand(); |
||
48 | } |
||
49 | return true; |
||
50 | } |
||
51 | |||
52 | bool dce_cleanup::visit(cf_node& n, bool enter) { |
||
53 | if (enter) { |
||
54 | if (n.flags & NF_DEAD) |
||
55 | n.remove(); |
||
56 | else |
||
57 | cleanup_dst(n); |
||
58 | } else { |
||
59 | if ((sh.dce_flags & DF_EXPAND) && |
||
60 | (n.bc.op_ptr->flags & (CF_CLAUSE | CF_BRANCH | CF_LOOP))) |
||
61 | n.expand(); |
||
62 | } |
||
63 | return true; |
||
64 | } |
||
65 | |||
66 | bool dce_cleanup::visit(alu_node& n, bool enter) { |
||
67 | if (enter) { |
||
68 | } else { |
||
69 | if (n.flags & NF_DEAD) |
||
70 | n.remove(); |
||
71 | else |
||
72 | cleanup_dst(n); |
||
73 | } |
||
74 | return true; |
||
75 | } |
||
76 | |||
77 | bool dce_cleanup::visit(alu_packed_node& n, bool enter) { |
||
78 | if (enter) { |
||
79 | } else { |
||
80 | if (n.flags & NF_DEAD) |
||
81 | n.remove(); |
||
82 | else |
||
83 | cleanup_dst(n); |
||
84 | } |
||
85 | return false; |
||
86 | } |
||
87 | |||
88 | bool dce_cleanup::visit(fetch_node& n, bool enter) { |
||
89 | if (enter) { |
||
90 | } else { |
||
91 | if (n.flags & NF_DEAD) |
||
92 | n.remove(); |
||
93 | else |
||
94 | cleanup_dst(n); |
||
95 | } |
||
96 | return true; |
||
97 | } |
||
98 | |||
99 | bool dce_cleanup::visit(region_node& n, bool enter) { |
||
100 | if (enter) { |
||
101 | if (n.loop_phi) |
||
102 | run_on(*n.loop_phi); |
||
103 | } else { |
||
104 | if (n.phi) |
||
105 | run_on(*n.phi); |
||
106 | } |
||
107 | return true; |
||
108 | } |
||
109 | |||
110 | void dce_cleanup::cleanup_dst(node& n) { |
||
111 | if (!cleanup_dst_vec(n.dst) && remove_unused && |
||
112 | !n.dst.empty() && !(n.flags & NF_DONT_KILL) && n.parent) |
||
113 | n.remove(); |
||
114 | } |
||
115 | |||
116 | bool dce_cleanup::visit(container_node& n, bool enter) { |
||
117 | if (enter) |
||
118 | cleanup_dst(n); |
||
119 | return true; |
||
120 | } |
||
121 | |||
122 | bool dce_cleanup::cleanup_dst_vec(vvec& vv) { |
||
123 | bool alive = false; |
||
124 | |||
125 | for (vvec::iterator I = vv.begin(), E = vv.end(); I != E; ++I) { |
||
126 | value* &v = *I; |
||
127 | if (!v) |
||
128 | continue; |
||
129 | |||
130 | if (v->gvn_source && v->gvn_source->is_dead()) |
||
131 | v->gvn_source = NULL; |
||
132 | |||
133 | if (v->is_dead() || (remove_unused && !v->is_rel() && !v->uses)) |
||
134 | v = NULL; |
||
135 | else |
||
136 | alive = true; |
||
137 | } |
||
138 | |||
139 | return alive; |
||
140 | } |
||
141 | |||
142 | } // namespace r600_sb |