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
)
41 printf("%04u:", instr
->serialno
);
43 printf("%04u:", instr
->name
);
44 printf("%03u: ", instr
->depth
);
46 if (instr
->flags
& IR3_INSTR_SY
)
48 if (instr
->flags
& IR3_INSTR_SS
)
57 /* shouldn't hit here.. just for debugging: */
59 case OPC_META_INPUT
: printf("_meta:in"); break;
60 case OPC_META_FO
: printf("_meta:fo"); break;
61 case OPC_META_FI
: printf("_meta:fi"); break;
63 default: printf("_meta:%d", instr
->opc
); break;
67 } else if (instr
->opc
== OPC_MOV
) {
68 static const char *type
[] = {
78 if (instr
->cat1
.src_type
== instr
->cat1
.dst_type
)
82 printf(".%s%s", type
[instr
->cat1
.src_type
], type
[instr
->cat1
.dst_type
]);
84 printf("%s", ir3_instr_name(instr
));
85 if (instr
->flags
& IR3_INSTR_3D
)
87 if (instr
->flags
& IR3_INSTR_A
)
89 if (instr
->flags
& IR3_INSTR_O
)
91 if (instr
->flags
& IR3_INSTR_P
)
93 if (instr
->flags
& IR3_INSTR_S
)
95 if (instr
->flags
& IR3_INSTR_S2EN
)
100 static void print_reg_name(struct ir3_register
*reg
)
102 if ((reg
->flags
& (IR3_REG_FABS
| IR3_REG_SABS
)) &&
103 (reg
->flags
& (IR3_REG_FNEG
| IR3_REG_SNEG
| IR3_REG_BNOT
)))
105 else if (reg
->flags
& (IR3_REG_FNEG
| IR3_REG_SNEG
| IR3_REG_BNOT
))
107 else if (reg
->flags
& (IR3_REG_FABS
| IR3_REG_SABS
))
110 if (reg
->flags
& IR3_REG_IMMED
) {
111 printf("imm[%f,%d,0x%x]", reg
->fim_val
, reg
->iim_val
, reg
->iim_val
);
112 } else if (reg
->flags
& IR3_REG_ARRAY
) {
113 printf("arr[id=%u, offset=%d, size=%u", reg
->array
.id
,
114 reg
->array
.offset
, reg
->size
);
115 /* for ARRAY we could have null src, for example first write
120 print_instr_name(reg
->instr
);
124 } else if (reg
->flags
& IR3_REG_SSA
) {
126 print_instr_name(reg
->instr
);
128 } else if (reg
->flags
& IR3_REG_RELATIV
) {
129 if (reg
->flags
& IR3_REG_HALF
)
131 if (reg
->flags
& IR3_REG_CONST
)
132 printf("c<a0.x + %d>", reg
->array
.offset
);
134 printf("\x1b[0;31mr<a0.x + %d>\x1b[0m (%u)", reg
->array
.offset
, reg
->size
);
136 if (reg
->flags
& IR3_REG_HALF
)
138 if (reg
->flags
& IR3_REG_CONST
)
139 printf("c%u.%c", reg_num(reg
), "xyzw"[reg_comp(reg
)]);
141 printf("\x1b[0;31mr%u.%c\x1b[0m", reg_num(reg
), "xyzw"[reg_comp(reg
)]);
148 for (int i
= 0; i
< lvl
; i
++)
153 print_instr(struct ir3_instruction
*instr
, int lvl
)
159 print_instr_name(instr
);
160 for (i
= 0; i
< instr
->regs_count
; i
++) {
161 struct ir3_register
*reg
= instr
->regs
[i
];
162 printf(i
? ", " : " ");
166 if (instr
->address
) {
167 printf(", address=_");
169 print_instr_name(instr
->address
);
173 if (instr
->cp
.left
) {
176 print_instr_name(instr
->cp
.left
);
180 if (instr
->cp
.right
) {
183 print_instr_name(instr
->cp
.right
);
187 if (instr
->opc
== OPC_META_FO
) {
188 printf(", off=%d", instr
->fo
.off
);
191 if (is_flow(instr
) && instr
->cat0
.target
) {
192 /* the predicate register src is implied: */
193 if (instr
->opc
== OPC_BR
) {
194 printf(" %sp0.x", instr
->cat0
.inv
? "!" : "");
196 printf(", target=block%u", block_id(instr
->cat0
.target
));
202 void ir3_print_instr(struct ir3_instruction
*instr
)
204 print_instr(instr
, 0);
208 print_block(struct ir3_block
*block
, int lvl
)
210 tab(lvl
); printf("block%u {\n", block_id(block
));
211 list_for_each_entry (struct ir3_instruction
, instr
, &block
->instr_list
, node
) {
212 print_instr(instr
, lvl
+1);
214 if (block
->successors
[1]) {
215 /* leading into if/else: */
217 printf("/* succs: if _[");
218 print_instr_name(block
->condition
);
219 printf("] block%u; else block%u; */\n",
220 block_id(block
->successors
[0]),
221 block_id(block
->successors
[1]));
222 } else if (block
->successors
[0]) {
224 printf("/* succs: block%u; */\n",
225 block_id(block
->successors
[0]));
227 tab(lvl
); printf("}\n");
231 ir3_print(struct ir3
*ir
)
233 list_for_each_entry (struct ir3_block
, block
, &ir
->block_list
, node
)
234 print_block(block
, 0);
236 for (unsigned i
= 0; i
< ir
->noutputs
; i
++) {
239 printf("out%d: ", i
);
240 print_instr(ir
->outputs
[i
], 0);