1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
34 #define PTRID(x) ((unsigned long)(x))
36 static void print_instr_name(struct ir3_instruction
*instr
)
39 printf("%04u:", instr
->serialno
);
41 printf("%03u: ", instr
->depth
);
43 if (instr
->flags
& IR3_INSTR_SY
)
45 if (instr
->flags
& IR3_INSTR_SS
)
54 /* shouldn't hit here.. just for debugging: */
56 case OPC_META_INPUT
: printf("_meta:in"); break;
57 case OPC_META_FO
: printf("_meta:fo"); break;
58 case OPC_META_FI
: printf("_meta:fi"); break;
60 default: printf("_meta:%d", instr
->opc
); break;
64 } else if (instr
->category
== 1) {
65 static const char *type
[] = {
75 if (instr
->cat1
.src_type
== instr
->cat1
.dst_type
)
79 printf(".%s%s", type
[instr
->cat1
.src_type
], type
[instr
->cat1
.dst_type
]);
81 printf("%s", ir3_instr_name(instr
));
82 if (instr
->flags
& IR3_INSTR_3D
)
84 if (instr
->flags
& IR3_INSTR_A
)
86 if (instr
->flags
& IR3_INSTR_O
)
88 if (instr
->flags
& IR3_INSTR_P
)
90 if (instr
->flags
& IR3_INSTR_S
)
92 if (instr
->flags
& IR3_INSTR_S2EN
)
97 static void print_reg_name(struct ir3_register
*reg
, bool followssa
)
99 if ((reg
->flags
& (IR3_REG_FABS
| IR3_REG_SABS
)) &&
100 (reg
->flags
& (IR3_REG_FNEG
| IR3_REG_SNEG
| IR3_REG_BNOT
)))
102 else if (reg
->flags
& (IR3_REG_FNEG
| IR3_REG_SNEG
| IR3_REG_BNOT
))
104 else if (reg
->flags
& (IR3_REG_FABS
| IR3_REG_SABS
))
107 if (reg
->flags
& IR3_REG_IMMED
) {
108 printf("imm[%f,%d,0x%x]", reg
->fim_val
, reg
->iim_val
, reg
->iim_val
);
109 } else if (reg
->flags
& IR3_REG_SSA
) {
113 print_instr_name(reg
->instr
);
116 } else if (reg
->flags
& IR3_REG_RELATIV
) {
117 if (reg
->flags
& IR3_REG_HALF
)
119 if (reg
->flags
& IR3_REG_CONST
)
120 printf("c<a0.x + %u>", reg
->num
);
122 printf("\x1b[0;31mr<a0.x + %u>\x1b[0m (%u)", reg
->num
, reg
->size
);
124 if (reg
->flags
& IR3_REG_HALF
)
126 if (reg
->flags
& IR3_REG_CONST
)
127 printf("c%u.%c", reg_num(reg
), "xyzw"[reg_comp(reg
)]);
129 printf("\x1b[0;31mr%u.%c\x1b[0m", reg_num(reg
), "xyzw"[reg_comp(reg
)]);
136 for (int i
= 0; i
< lvl
; i
++)
141 block_id(struct ir3_block
*block
)
144 return block
->serialno
;
146 return (uint32_t)(unsigned long)block
;
151 print_instr(struct ir3_instruction
*instr
, int lvl
)
157 print_instr_name(instr
);
158 for (i
= 0; i
< instr
->regs_count
; i
++) {
159 struct ir3_register
*reg
= instr
->regs
[i
];
160 printf(i
? ", " : " ");
161 print_reg_name(reg
, !!i
);
164 if (instr
->address
) {
165 printf(", address=_");
167 print_instr_name(instr
->address
);
174 print_instr_name(instr
->fanin
);
178 if (instr
->cp
.left
) {
181 print_instr_name(instr
->cp
.left
);
185 if (instr
->cp
.right
) {
188 print_instr_name(instr
->cp
.right
);
192 if (is_meta(instr
)) {
193 if (instr
->opc
== OPC_META_FO
) {
194 printf(", off=%d", instr
->fo
.off
);
195 } else if ((instr
->opc
== OPC_META_FI
) && instr
->fi
.aid
) {
196 printf(", aid=%d", instr
->fi
.aid
);
200 if (is_flow(instr
) && instr
->cat0
.target
) {
201 /* the predicate register src is implied: */
202 if (instr
->opc
== OPC_BR
) {
203 printf(" %sp0.x", instr
->cat0
.inv
? "!" : "");
205 printf(", target=block%u", block_id(instr
->cat0
.target
));
211 void ir3_print_instr(struct ir3_instruction
*instr
)
213 print_instr(instr
, 0);
217 print_block(struct ir3_block
*block
, int lvl
)
219 tab(lvl
); printf("block%u {\n", block_id(block
));
220 list_for_each_entry (struct ir3_instruction
, instr
, &block
->instr_list
, node
) {
221 print_instr(instr
, lvl
+1);
223 if (block
->successors
[1]) {
224 /* leading into if/else: */
226 printf("/* succs: if _[");
227 print_instr_name(block
->condition
);
228 printf("] block%u; else block%u; */\n",
229 block_id(block
->successors
[0]),
230 block_id(block
->successors
[1]));
231 } else if (block
->successors
[0]) {
233 printf("/* succs: block%u; */\n",
234 block_id(block
->successors
[0]));
236 tab(lvl
); printf("}\n");
240 ir3_print(struct ir3
*ir
)
242 list_for_each_entry (struct ir3_block
, block
, &ir
->block_list
, node
)
243 print_block(block
, 0);
245 for (unsigned i
= 0; i
< ir
->noutputs
; i
++) {
248 printf("out%d: ", i
);
249 print_instr(ir
->outputs
[i
], 0);