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"
33 run_on(sh
.root
, true);
34 run_on(sh
.root
, false);
38 void def_use::process_phi(container_node
*c
, bool defs
, bool uses
) {
40 for (node_iterator I
= c
->begin(), E
= c
->end(); I
!= E
; ++I
) {
45 process_defs(n
, n
->dst
, false);
49 void def_use::run_on(node
* n
, bool defs
) {
51 bool is_region
= (n
->type
== NT_REGION
);
52 bool is_op
= (n
->type
== NT_OP
|| n
->type
== NT_IF
);
57 sblog
<< "def_use processing op ";
63 process_defs(n
, n
->dst
, false);
66 } else if (is_region
& defs
) {
67 region_node
*r
= static_cast<region_node
*>(n
);
69 process_phi(r
->loop_phi
, true, false);
72 if (n
->is_container() && n
->subtype
!= NST_ALU_PACKED_INST
) {
73 container_node
*c
= static_cast<container_node
*>(n
);
74 for (node_iterator I
= c
->begin(), E
= c
->end(); I
!= E
; ++I
) {
80 region_node
*r
= static_cast<region_node
*>(n
);
82 process_phi(r
->phi
, defs
, !defs
);
83 if (r
->loop_phi
&& !defs
)
84 process_phi(r
->loop_phi
, false, true);
88 void def_use::process_defs(node
*n
, vvec
&vv
, bool arr_def
) {
90 for (vvec::iterator I
= vv
.begin(), E
= vv
.end(); I
!= E
; ++I
) {
103 process_defs(n
, v
->mdef
, true);
108 void def_use::process_uses(node
* n
) {
111 for (vvec::iterator I
= n
->src
.begin(), E
= n
->src
.end(); I
!= E
;
114 if (!v
|| v
->is_readonly())
118 if (!v
->rel
->is_readonly())
119 v
->rel
->add_use(n
, UK_SRC_REL
, k
);
122 for (vvec::iterator I
= v
->muse
.begin(), E
= v
->muse
.end();
128 v
->add_use(n
, UK_MAYUSE
, k2
);
131 v
->add_use(n
, UK_SRC
, k
);
135 for (vvec::iterator I
= n
->dst
.begin(), E
= n
->dst
.end(); I
!= E
;
138 if (!v
|| !v
->is_rel())
141 if (!v
->rel
->is_readonly())
142 v
->rel
->add_use(n
, UK_DST_REL
, k
);
144 for (vvec::iterator I
= v
->muse
.begin(), E
= v
->muse
.end();
150 v
->add_use(n
, UK_MAYDEF
, k2
);
155 n
->pred
->add_use(n
, UK_PRED
, 0);
157 if (n
->type
== NT_IF
) {
158 if_node
*i
= static_cast<if_node
*>(n
);
160 i
->cond
->add_use(i
, UK_COND
, 0);
164 } // namespace r600_sb