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
);
45 if (instr
->flags
& IR3_INSTR_SY
)
47 if (instr
->flags
& IR3_INSTR_SS
)
52 case OPC_META_INPUT
: printf("_meta:in"); break;
53 case OPC_META_FO
: printf("_meta:fo"); break;
54 case OPC_META_FI
: printf("_meta:fi"); break;
56 /* shouldn't hit here.. just for debugging: */
57 default: printf("_meta:%d", instr
->opc
); break;
59 } else if (instr
->opc
== OPC_MOV
) {
60 static const char *type
[] = {
70 if (instr
->cat1
.src_type
== instr
->cat1
.dst_type
)
74 printf(".%s%s", type
[instr
->cat1
.src_type
], type
[instr
->cat1
.dst_type
]);
76 printf("%s", ir3_instr_name(instr
));
77 if (instr
->flags
& IR3_INSTR_3D
)
79 if (instr
->flags
& IR3_INSTR_A
)
81 if (instr
->flags
& IR3_INSTR_O
)
83 if (instr
->flags
& IR3_INSTR_P
)
85 if (instr
->flags
& IR3_INSTR_S
)
87 if (instr
->flags
& IR3_INSTR_S2EN
)
92 static void print_reg_name(struct ir3_register
*reg
)
94 if ((reg
->flags
& (IR3_REG_FABS
| IR3_REG_SABS
)) &&
95 (reg
->flags
& (IR3_REG_FNEG
| IR3_REG_SNEG
| IR3_REG_BNOT
)))
97 else if (reg
->flags
& (IR3_REG_FNEG
| IR3_REG_SNEG
| IR3_REG_BNOT
))
99 else if (reg
->flags
& (IR3_REG_FABS
| IR3_REG_SABS
))
102 if (reg
->flags
& IR3_REG_IMMED
) {
103 printf("imm[%f,%d,0x%x]", reg
->fim_val
, reg
->iim_val
, reg
->iim_val
);
104 } else if (reg
->flags
& IR3_REG_ARRAY
) {
105 printf("arr[id=%u, offset=%d, size=%u", reg
->array
.id
,
106 reg
->array
.offset
, reg
->size
);
107 /* for ARRAY we could have null src, for example first write
112 print_instr_name(reg
->instr
);
116 } else if (reg
->flags
& IR3_REG_SSA
) {
118 print_instr_name(reg
->instr
);
120 } else if (reg
->flags
& IR3_REG_RELATIV
) {
121 if (reg
->flags
& IR3_REG_HALF
)
123 if (reg
->flags
& IR3_REG_CONST
)
124 printf("c<a0.x + %d>", reg
->array
.offset
);
126 printf("\x1b[0;31mr<a0.x + %d>\x1b[0m (%u)", reg
->array
.offset
, reg
->size
);
128 if (reg
->flags
& IR3_REG_HALF
)
130 if (reg
->flags
& IR3_REG_CONST
)
131 printf("c%u.%c", reg_num(reg
), "xyzw"[reg_comp(reg
)]);
133 printf("\x1b[0;31mr%u.%c\x1b[0m", reg_num(reg
), "xyzw"[reg_comp(reg
)]);
140 for (int i
= 0; i
< lvl
; i
++)
145 print_instr(struct ir3_instruction
*instr
, int lvl
)
151 print_instr_name(instr
);
152 for (i
= 0; i
< instr
->regs_count
; i
++) {
153 struct ir3_register
*reg
= instr
->regs
[i
];
154 printf(i
? ", " : " ");
158 if (instr
->address
) {
159 printf(", address=_");
161 print_instr_name(instr
->address
);
165 if (instr
->cp
.left
) {
168 print_instr_name(instr
->cp
.left
);
172 if (instr
->cp
.right
) {
175 print_instr_name(instr
->cp
.right
);
179 if (instr
->opc
== OPC_META_FO
) {
180 printf(", off=%d", instr
->fo
.off
);
183 if (is_flow(instr
) && instr
->cat0
.target
) {
184 /* the predicate register src is implied: */
185 if (instr
->opc
== OPC_BR
) {
186 printf(" %sp0.x", instr
->cat0
.inv
? "!" : "");
188 printf(", target=block%u", block_id(instr
->cat0
.target
));
191 if (instr
->deps_count
) {
192 printf(", false-deps:");
193 for (unsigned i
= 0; i
< instr
->deps_count
; i
++) {
197 print_instr_name(instr
->deps
[i
]);
205 void ir3_print_instr(struct ir3_instruction
*instr
)
207 print_instr(instr
, 0);
211 print_block(struct ir3_block
*block
, int lvl
)
213 tab(lvl
); printf("block%u {\n", block_id(block
));
215 if (block
->predecessors_count
> 0) {
218 for (unsigned i
= 0; i
< block
->predecessors_count
; i
++) {
221 printf("block%u", block_id(block
->predecessors
[i
]));
226 list_for_each_entry (struct ir3_instruction
, instr
, &block
->instr_list
, node
) {
227 print_instr(instr
, lvl
+1);
230 tab(lvl
+1); printf("/* keeps:\n");
231 for (unsigned i
= 0; i
< block
->keeps_count
; i
++) {
232 print_instr(block
->keeps
[i
], lvl
+2);
234 tab(lvl
+1); printf(" */\n");
236 if (block
->successors
[1]) {
237 /* leading into if/else: */
239 printf("/* succs: if _[");
240 print_instr_name(block
->condition
);
241 printf("] block%u; else block%u; */\n",
242 block_id(block
->successors
[0]),
243 block_id(block
->successors
[1]));
244 } else if (block
->successors
[0]) {
246 printf("/* succs: block%u; */\n",
247 block_id(block
->successors
[0]));
249 tab(lvl
); printf("}\n");
253 ir3_print(struct ir3
*ir
)
255 list_for_each_entry (struct ir3_block
, block
, &ir
->block_list
, node
)
256 print_block(block
, 0);
258 for (unsigned i
= 0; i
< ir
->noutputs
; i
++) {
261 printf("out%d: ", i
);
262 print_instr(ir
->outputs
[i
], 0);