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.
30 #include "sb_shader.h"
38 bool dump::visit(node
& n
, bool enter
) {
54 assert(!"invalid node subtype");
62 bool dump::visit(container_node
& n
, bool enter
) {
69 cerr
<< " preloaded inputs [";
73 dump_live_values(n
, true);
86 dump_live_values(n
, false);
92 bool dump::visit(bb_node
& n
, bool enter
) {
96 cerr
<< "{ BB_" << n
.id
<< " loop_level = " << n
.loop_level
<< " ";
97 dump_live_values(n
, true);
102 cerr
<< "} end BB_" << n
.id
<< " ";
103 dump_live_values(n
, false);
108 bool dump::visit(alu_group_node
& n
, bool enter
) {
113 dump_live_values(n
, true);
121 dump_live_values(n
, false);
126 bool dump::visit(cf_node
& n
, bool enter
) {
130 dump_op(n
, n
.bc
.op_ptr
->name
);
132 if (n
.bc
.op_ptr
->flags
& CF_BRANCH
) {
133 cerr
<< " @" << (n
.bc
.addr
<< 1);
142 dump_live_values(n
, true);
151 dump_live_values(n
, false);
157 bool dump::visit(alu_node
& n
, bool enter
) {
173 bool dump::visit(alu_packed_node
& n
, bool enter
) {
177 dump_op(n
, n
.op_ptr()->name
);
179 dump_live_values(n
, true);
184 if (!n
.live_after
.empty()) {
186 dump_live_values(n
, false);
190 // proccess children only if their src/dst aren't moved to this node yet
191 return n
.src
.empty();
194 bool dump::visit(fetch_node
& n
, bool enter
) {
198 dump_op(n
, n
.bc
.op_ptr
->name
);
208 bool dump::visit(region_node
& n
, bool enter
) {
212 cerr
<< "region #" << n
.region_id
<< " ";
215 if (!n
.vars_defined
.empty()) {
216 cerr
<< "vars_defined: ";
217 dump_set(sh
, n
.vars_defined
);
220 dump_live_values(n
, true);
233 dump_live_values(n
, false);
238 bool dump::visit(repeat_node
& n
, bool enter
) {
242 cerr
<< "repeat region #" << n
.target
->region_id
;
243 cerr
<< (n
.empty() ? " " : " after { ");
246 dump_live_values(n
, true);
254 cerr
<< "} end_repeat ";
255 dump_live_values(n
, false);
261 bool dump::visit(depart_node
& n
, bool enter
) {
265 cerr
<< "depart region #" << n
.target
->region_id
;
266 cerr
<< (n
.empty() ? " " : " after { ");
269 dump_live_values(n
, true);
276 cerr
<< "} end_depart ";
277 dump_live_values(n
, false);
283 bool dump::visit(if_node
& n
, bool enter
) {
287 cerr
<< "if " << *n
.cond
<< " ";
290 dump_live_values(n
, true);
300 dump_live_values(n
, false);
305 void dump::indent() {
306 cerr
<< std::setw(level
* 4) << "";
309 void dump::dump_vec(const vvec
& vv
) {
311 for(vvec::const_iterator I
= vv
.begin(), E
= vv
.end(); I
!= E
; ++I
) {
326 void dump::dump_rels(vvec
& vv
) {
327 for(vvec::iterator I
= vv
.begin(), E
= vv
.end(); I
!= E
; ++I
) {
330 if (!v
|| !v
->is_rel())
333 cerr
<< "\n\t\t\t\t\t";
334 cerr
<< " rels: " << *v
<< " : ";
341 void dump::dump_op(node
&n
, const char *name
) {
344 alu_node
&a
= static_cast<alu_node
&>(n
);
345 cerr
<< (a
.bc
.pred_sel
-2) << " [" << *a
.pred
<< "] ";
350 bool has_dst
= !n
.dst
.empty();
352 if (n
.subtype
== NST_CF_INST
) {
353 cf_node
*c
= static_cast<cf_node
*>(&n
);
354 if (c
->bc
.op_ptr
->flags
& CF_EXP
) {
355 static const char *exp_type
[] = {"PIXEL", "POS ", "PARAM"};
356 cerr
<< " " << exp_type
[c
->bc
.type
] << " " << c
->bc
.array_base
;
358 } else if (c
->bc
.op_ptr
->flags
& CF_STRM
) {
359 static const char *exp_type
[] = {"WRITE", "WRITE_IND", "WRITE_ACK",
361 cerr
<< " " << exp_type
[c
->bc
.type
] << " " << c
->bc
.array_base
362 << " ES:" << c
->bc
.elem_size
;
377 void dump::dump_set(shader
&sh
, val_set
& v
) {
379 for(val_set::iterator I
= v
.begin(sh
), E
= v
.end(sh
); I
!= E
; ++I
) {
386 void dump::dump_common(node
& n
) {
389 void dump::dump_flags(node
&n
) {
390 if (n
.flags
& NF_DEAD
)
392 if (n
.flags
& NF_REG_CONSTRAINT
)
394 if (n
.flags
& NF_CHAN_CONSTRAINT
)
396 if (n
.flags
& NF_ALU_4SLOT
)
400 void dump::dump_val(value
* v
) {
404 void dump::dump_alu(alu_node
*n
) {
406 if (n
->is_copy_mov())
410 cerr
<< (n
->bc
.pred_sel
-2) << " [" << n
->pred
<< "] ";
413 cerr
<< n
->bc
.op_ptr
->name
;
416 static const char *omod_str
[] = {"", "*2", "*4", "/2"};
417 cerr
<< omod_str
[n
->bc
.omod
];
424 bool has_dst
= !n
->dst
.empty();
434 for (vvec::iterator I
= n
->src
.begin(), E
= n
->src
.end(); I
!= E
;
437 bc_alu_src
&src
= n
->bc
.src
[s
];
459 void dump::dump_op(node
* n
) {
460 if (n
->type
== NT_IF
) {
467 dump_alu(static_cast<alu_node
*>(n
));
470 dump_op(*n
, static_cast<fetch_node
*>(n
)->bc
.op_ptr
->name
);
476 dump_op(*n
, static_cast<cf_node
*>(n
)->bc
.op_ptr
->name
);
478 case NST_ALU_PACKED_INST
:
479 dump_op(*n
, static_cast<alu_packed_node
*>(n
)->op_ptr()->name
);
491 dump_op(*n
, "??unknown_op");
495 void dump::dump_op_list(container_node
* c
) {
496 for (node_iterator I
= c
->begin(), E
= c
->end(); I
!= E
; ++I
) {
502 void dump::dump_queue(sched_queue
& q
) {
503 for (sched_queue::iterator I
= q
.begin(), E
= q
.end(); I
!= E
; ++I
) {
509 void dump::dump_live_values(container_node
&n
, bool before
) {
511 if (!n
.live_before
.empty()) {
512 cerr
<< "live_before: ";
513 dump_set(sh
, n
.live_before
);
516 if (!n
.live_after
.empty()) {
517 cerr
<< "live_after: ";
518 dump_set(sh
, n
.live_after
);
524 } // namespace r600_sb