freedreno/ir3: drop dot graph dumping
[mesa.git] / src / gallium / drivers / freedreno / ir3 / ir3_print.c
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
5 *
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:
12 *
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
15 * Software.
16 *
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
23 * SOFTWARE.
24 *
25 * Authors:
26 * Rob Clark <robclark@freedesktop.org>
27 */
28
29 #include <stdarg.h>
30 #include <stdio.h>
31
32 #include "ir3.h"
33
34 #define PTRID(x) ((unsigned long)(x))
35
36 static void print_instr_name(struct ir3_instruction *instr)
37 {
38 #ifdef DEBUG
39 printf("%04u:", instr->serialno);
40 #endif
41 printf("%03u: ", instr->depth);
42
43 if (instr->flags & IR3_INSTR_SY)
44 printf("(sy)");
45 if (instr->flags & IR3_INSTR_SS)
46 printf("(ss)");
47
48 if (is_meta(instr)) {
49 switch(instr->opc) {
50 case OPC_META_PHI:
51 printf("&#934;");
52 break;
53 default:
54 /* shouldn't hit here.. just for debugging: */
55 switch (instr->opc) {
56 case OPC_META_INPUT: printf("_meta:in"); break;
57 case OPC_META_OUTPUT: printf("_meta:out"); break;
58 case OPC_META_FO: printf("_meta:fo"); break;
59 case OPC_META_FI: printf("_meta:fi"); break;
60 case OPC_META_FLOW: printf("_meta:flow"); break;
61
62 default: printf("_meta:%d", instr->opc); break;
63 }
64 break;
65 }
66 } else if (instr->category == 1) {
67 static const char *type[] = {
68 [TYPE_F16] = "f16",
69 [TYPE_F32] = "f32",
70 [TYPE_U16] = "u16",
71 [TYPE_U32] = "u32",
72 [TYPE_S16] = "s16",
73 [TYPE_S32] = "s32",
74 [TYPE_U8] = "u8",
75 [TYPE_S8] = "s8",
76 };
77 if (instr->cat1.src_type == instr->cat1.dst_type)
78 printf("mov");
79 else
80 printf("cov");
81 printf(".%s%s", type[instr->cat1.src_type], type[instr->cat1.dst_type]);
82 } else {
83 printf("%s", ir3_instr_name(instr));
84 if (instr->flags & IR3_INSTR_3D)
85 printf(".3d");
86 if (instr->flags & IR3_INSTR_A)
87 printf(".a");
88 if (instr->flags & IR3_INSTR_O)
89 printf(".o");
90 if (instr->flags & IR3_INSTR_P)
91 printf(".p");
92 if (instr->flags & IR3_INSTR_S)
93 printf(".s");
94 if (instr->flags & IR3_INSTR_S2EN)
95 printf(".s2en");
96 }
97 }
98
99 static void print_reg_name(struct ir3_register *reg, bool followssa)
100 {
101 if ((reg->flags & (IR3_REG_FABS | IR3_REG_SABS)) &&
102 (reg->flags & (IR3_REG_FNEG | IR3_REG_SNEG | IR3_REG_BNOT)))
103 printf("(absneg)");
104 else if (reg->flags & (IR3_REG_FNEG | IR3_REG_SNEG | IR3_REG_BNOT))
105 printf("(neg)");
106 else if (reg->flags & (IR3_REG_FABS | IR3_REG_SABS))
107 printf("(abs)");
108
109 if (reg->flags & IR3_REG_IMMED) {
110 printf("imm[%f,%d,0x%x]", reg->fim_val, reg->iim_val, reg->iim_val);
111 } else if (reg->flags & IR3_REG_SSA) {
112 printf("_");
113 if (followssa) {
114 printf("[");
115 print_instr_name(reg->instr);
116 printf("]");
117 }
118 } else if (reg->flags & IR3_REG_RELATIV) {
119 if (reg->flags & IR3_REG_HALF)
120 printf("h");
121 if (reg->flags & IR3_REG_CONST)
122 printf("c<a0.x + %u>", reg->num);
123 else
124 printf("\x1b[0;31mr<a0.x + %u>\x1b[0m (%u)", reg->num, reg->size);
125 } else {
126 if (reg->flags & IR3_REG_HALF)
127 printf("h");
128 if (reg->flags & IR3_REG_CONST)
129 printf("c%u.%c", reg_num(reg), "xyzw"[reg_comp(reg)]);
130 else
131 printf("\x1b[0;31mr%u.%c\x1b[0m", reg_num(reg), "xyzw"[reg_comp(reg)]);
132 }
133 }
134
135 static void
136 tab(int lvl)
137 {
138 for (int i = 0; i < lvl; i++)
139 printf("\t");
140 }
141
142 static void
143 print_instr(struct ir3_instruction *instr, int lvl)
144 {
145 unsigned i;
146
147 tab(lvl);
148
149 print_instr_name(instr);
150 for (i = 0; i < instr->regs_count; i++) {
151 struct ir3_register *reg = instr->regs[i];
152 printf(i ? ", " : " ");
153 print_reg_name(reg, !!i);
154 }
155
156 if (instr->address) {
157 printf(", address=_");
158 printf("[");
159 print_instr_name(instr->address);
160 printf("]");
161 }
162
163 if (instr->fanin) {
164 printf(", fanin=_");
165 printf("[");
166 print_instr_name(instr->fanin);
167 printf("]");
168 }
169
170 if (is_meta(instr)) {
171 if (instr->opc == OPC_META_FO) {
172 printf(", off=%d", instr->fo.off);
173 } else if ((instr->opc == OPC_META_FI) && instr->fi.aid) {
174 printf(", aid=%d", instr->fi.aid);
175 }
176 }
177
178 printf("\n");
179 }
180
181 void ir3_print_instr(struct ir3_instruction *instr)
182 {
183 print_instr(instr, 0);
184 }
185
186 static void
187 print_block(struct ir3_block *block, int lvl)
188 {
189 struct ir3_instruction *instr;
190 tab(lvl); printf("block {\n");
191 for (instr = block->head; instr; instr = instr->next) {
192 print_instr(instr, lvl+1);
193 }
194 tab(lvl); printf("}\n");
195 }
196
197 void
198 ir3_print(struct ir3 *ir)
199 {
200 struct ir3_block *block = ir->block;
201
202 print_block(block, 0);
203
204 for (unsigned i = 0; i < block->noutputs; i++) {
205 if (!block->outputs[i])
206 continue;
207 printf("out%d: ", i);
208 print_instr(block->outputs[i], 0);
209 }
210 }