2 * Copyright 2013 Vadim Girlin <vadimgirlin@gmail.com>
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:
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
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.
27 #include "sb_shader.h"
36 run_on(sh
.root
, true);
37 run_on(sh
.root
, false);
41 void def_use::process_phi(container_node
*c
, bool defs
, bool uses
) {
43 for (node_iterator I
= c
->begin(), E
= c
->end(); I
!= E
; ++I
) {
48 process_defs(n
, n
->dst
, false);
52 void def_use::run_on(node
* n
, bool defs
) {
54 bool is_region
= (n
->type
== NT_REGION
);
55 bool is_op
= (n
->type
== NT_OP
|| n
->type
== NT_IF
);
60 cerr
<< "def_use processing op ";
66 process_defs(n
, n
->dst
, false);
69 } else if (is_region
& defs
) {
70 region_node
*r
= static_cast<region_node
*>(n
);
72 process_phi(r
->loop_phi
, true, false);
75 if (n
->is_container() && n
->subtype
!= NST_ALU_PACKED_INST
) {
76 container_node
*c
= static_cast<container_node
*>(n
);
77 for (node_iterator I
= c
->begin(), E
= c
->end(); I
!= E
; ++I
) {
83 region_node
*r
= static_cast<region_node
*>(n
);
85 process_phi(r
->phi
, defs
, !defs
);
86 if (r
->loop_phi
&& !defs
)
87 process_phi(r
->loop_phi
, false, true);
91 void def_use::process_defs(node
*n
, vvec
&vv
, bool arr_def
) {
93 for (vvec::iterator I
= vv
.begin(), E
= vv
.end(); I
!= E
; ++I
) {
106 process_defs(n
, v
->mdef
, true);
111 void def_use::process_uses(node
* n
) {
114 for (vvec::iterator I
= n
->src
.begin(), E
= n
->src
.end(); I
!= E
;
117 if (!v
|| v
->is_readonly())
121 if (!v
->rel
->is_readonly())
122 v
->rel
->add_use(n
, UK_SRC_REL
, k
);
125 for (vvec::iterator I
= v
->muse
.begin(), E
= v
->muse
.end();
131 v
->add_use(n
, UK_MAYUSE
, k2
);
134 v
->add_use(n
, UK_SRC
, k
);
138 for (vvec::iterator I
= n
->dst
.begin(), E
= n
->dst
.end(); I
!= E
;
141 if (!v
|| !v
->is_rel())
144 if (!v
->rel
->is_readonly())
145 v
->rel
->add_use(n
, UK_DST_REL
, k
);
147 for (vvec::iterator I
= v
->muse
.begin(), E
= v
->muse
.end();
153 v
->add_use(n
, UK_MAYDEF
, k2
);
158 n
->pred
->add_use(n
, UK_PRED
, 0);
160 if (n
->type
== NT_IF
) {
161 if_node
*i
= static_cast<if_node
*>(n
);
163 i
->cond
->add_use(i
, UK_COND
, 0);
167 } // namespace r600_sb