2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
32 #define PTRID(x) ((unsigned long)(x))
34 static void print_instr_name(struct ir3_instruction
*instr
)
39 printf("%04u:", instr
->serialno
);
41 printf("%04u:", instr
->name
);
42 printf("%04u:", instr
->ip
);
43 printf("%03u:", instr
->depth
);
44 printf("%03u: ", instr
->sun
);
46 if (instr
->flags
& IR3_INSTR_SY
)
48 if (instr
->flags
& IR3_INSTR_SS
)
53 case OPC_META_INPUT
: printf("_meta:in"); break;
54 case OPC_META_FO
: printf("_meta:fo"); break;
55 case OPC_META_FI
: printf("_meta:fi"); break;
57 /* shouldn't hit here.. just for debugging: */
58 default: printf("_meta:%d", instr
->opc
); break;
60 } else if (instr
->opc
== OPC_MOV
) {
61 static const char *type
[] = {
71 if (instr
->cat1
.src_type
== instr
->cat1
.dst_type
)
75 printf(".%s%s", type
[instr
->cat1
.src_type
], type
[instr
->cat1
.dst_type
]);
77 printf("%s", ir3_instr_name(instr
));
78 if (instr
->flags
& IR3_INSTR_3D
)
80 if (instr
->flags
& IR3_INSTR_A
)
82 if (instr
->flags
& IR3_INSTR_O
)
84 if (instr
->flags
& IR3_INSTR_P
)
86 if (instr
->flags
& IR3_INSTR_S
)
88 if (instr
->flags
& IR3_INSTR_S2EN
)
93 static void print_reg_name(struct ir3_register
*reg
)
95 if ((reg
->flags
& (IR3_REG_FABS
| IR3_REG_SABS
)) &&
96 (reg
->flags
& (IR3_REG_FNEG
| IR3_REG_SNEG
| IR3_REG_BNOT
)))
98 else if (reg
->flags
& (IR3_REG_FNEG
| IR3_REG_SNEG
| IR3_REG_BNOT
))
100 else if (reg
->flags
& (IR3_REG_FABS
| IR3_REG_SABS
))
103 if (reg
->flags
& IR3_REG_IMMED
) {
104 printf("imm[%f,%d,0x%x]", reg
->fim_val
, reg
->iim_val
, reg
->iim_val
);
105 } else if (reg
->flags
& IR3_REG_ARRAY
) {
106 printf("arr[id=%u, offset=%d, size=%u", reg
->array
.id
,
107 reg
->array
.offset
, reg
->size
);
108 /* for ARRAY we could have null src, for example first write
113 print_instr_name(reg
->instr
);
117 } else if (reg
->flags
& IR3_REG_SSA
) {
119 print_instr_name(reg
->instr
);
121 } else if (reg
->flags
& IR3_REG_RELATIV
) {
122 if (reg
->flags
& IR3_REG_HALF
)
124 if (reg
->flags
& IR3_REG_CONST
)
125 printf("c<a0.x + %d>", reg
->array
.offset
);
127 printf("\x1b[0;31mr<a0.x + %d>\x1b[0m (%u)", reg
->array
.offset
, reg
->size
);
129 if (reg
->flags
& IR3_REG_HIGH
)
131 if (reg
->flags
& IR3_REG_HALF
)
133 if (reg
->flags
& IR3_REG_CONST
)
134 printf("c%u.%c", reg_num(reg
), "xyzw"[reg_comp(reg
)]);
136 printf("\x1b[0;31mr%u.%c\x1b[0m", reg_num(reg
), "xyzw"[reg_comp(reg
)]);
143 for (int i
= 0; i
< lvl
; i
++)
148 print_instr(struct ir3_instruction
*instr
, int lvl
)
154 print_instr_name(instr
);
155 for (i
= 0; i
< instr
->regs_count
; i
++) {
156 struct ir3_register
*reg
= instr
->regs
[i
];
157 printf(i
? ", " : " ");
161 if (instr
->address
) {
162 printf(", address=_");
164 print_instr_name(instr
->address
);
168 if (instr
->cp
.left
) {
171 print_instr_name(instr
->cp
.left
);
175 if (instr
->cp
.right
) {
178 print_instr_name(instr
->cp
.right
);
182 if (instr
->opc
== OPC_META_FO
) {
183 printf(", off=%d", instr
->fo
.off
);
186 if (is_flow(instr
) && instr
->cat0
.target
) {
187 /* the predicate register src is implied: */
188 if (instr
->opc
== OPC_BR
) {
189 printf(" %sp0.x", instr
->cat0
.inv
? "!" : "");
191 printf(", target=block%u", block_id(instr
->cat0
.target
));
194 if (instr
->deps_count
) {
195 printf(", false-deps:");
196 for (unsigned i
= 0; i
< instr
->deps_count
; i
++) {
200 print_instr_name(instr
->deps
[i
]);
208 void ir3_print_instr(struct ir3_instruction
*instr
)
210 print_instr(instr
, 0);
214 print_block(struct ir3_block
*block
, int lvl
)
216 tab(lvl
); printf("block%u {\n", block_id(block
));
218 if (block
->predecessors_count
> 0) {
221 for (unsigned i
= 0; i
< block
->predecessors_count
; i
++) {
224 printf("block%u", block_id(block
->predecessors
[i
]));
229 list_for_each_entry (struct ir3_instruction
, instr
, &block
->instr_list
, node
) {
230 print_instr(instr
, lvl
+1);
233 tab(lvl
+1); printf("/* keeps:\n");
234 for (unsigned i
= 0; i
< block
->keeps_count
; i
++) {
235 print_instr(block
->keeps
[i
], lvl
+2);
237 tab(lvl
+1); printf(" */\n");
239 if (block
->successors
[1]) {
240 /* leading into if/else: */
242 printf("/* succs: if _[");
243 print_instr_name(block
->condition
);
244 printf("] block%u; else block%u; */\n",
245 block_id(block
->successors
[0]),
246 block_id(block
->successors
[1]));
247 } else if (block
->successors
[0]) {
249 printf("/* succs: block%u; */\n",
250 block_id(block
->successors
[0]));
252 tab(lvl
); printf("}\n");
256 ir3_print(struct ir3
*ir
)
258 list_for_each_entry (struct ir3_block
, block
, &ir
->block_list
, node
)
259 print_block(block
, 0);
261 for (unsigned i
= 0; i
< ir
->noutputs
; i
++) {
264 printf("out%d: ", i
);
265 print_instr(ir
->outputs
[i
], 0);