freedreno: Remove the Emacs mode lines
[mesa.git] / src / gallium / drivers / freedreno / ir3 / ir3_print.c
1 /*
2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
26
27 #include <stdarg.h>
28 #include <stdio.h>
29
30 #include "ir3.h"
31
32 #define PTRID(x) ((unsigned long)(x))
33
34 static void print_instr_name(struct ir3_instruction *instr)
35 {
36 if (!instr)
37 return;
38 #ifdef DEBUG
39 printf("%04u:", instr->serialno);
40 #endif
41 printf("%04u:", instr->name);
42 printf("%04u:", instr->ip);
43 printf("%03u: ", instr->depth);
44
45 if (instr->flags & IR3_INSTR_SY)
46 printf("(sy)");
47 if (instr->flags & IR3_INSTR_SS)
48 printf("(ss)");
49
50 if (is_meta(instr)) {
51 switch (instr->opc) {
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;
55
56 /* shouldn't hit here.. just for debugging: */
57 default: printf("_meta:%d", instr->opc); break;
58 }
59 } else if (instr->opc == OPC_MOV) {
60 static const char *type[] = {
61 [TYPE_F16] = "f16",
62 [TYPE_F32] = "f32",
63 [TYPE_U16] = "u16",
64 [TYPE_U32] = "u32",
65 [TYPE_S16] = "s16",
66 [TYPE_S32] = "s32",
67 [TYPE_U8] = "u8",
68 [TYPE_S8] = "s8",
69 };
70 if (instr->cat1.src_type == instr->cat1.dst_type)
71 printf("mov");
72 else
73 printf("cov");
74 printf(".%s%s", type[instr->cat1.src_type], type[instr->cat1.dst_type]);
75 } else {
76 printf("%s", ir3_instr_name(instr));
77 if (instr->flags & IR3_INSTR_3D)
78 printf(".3d");
79 if (instr->flags & IR3_INSTR_A)
80 printf(".a");
81 if (instr->flags & IR3_INSTR_O)
82 printf(".o");
83 if (instr->flags & IR3_INSTR_P)
84 printf(".p");
85 if (instr->flags & IR3_INSTR_S)
86 printf(".s");
87 if (instr->flags & IR3_INSTR_S2EN)
88 printf(".s2en");
89 }
90 }
91
92 static void print_reg_name(struct ir3_register *reg)
93 {
94 if ((reg->flags & (IR3_REG_FABS | IR3_REG_SABS)) &&
95 (reg->flags & (IR3_REG_FNEG | IR3_REG_SNEG | IR3_REG_BNOT)))
96 printf("(absneg)");
97 else if (reg->flags & (IR3_REG_FNEG | IR3_REG_SNEG | IR3_REG_BNOT))
98 printf("(neg)");
99 else if (reg->flags & (IR3_REG_FABS | IR3_REG_SABS))
100 printf("(abs)");
101
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
108 * instruction..
109 */
110 if (reg->instr) {
111 printf(", _[");
112 print_instr_name(reg->instr);
113 printf("]");
114 }
115 printf("]");
116 } else if (reg->flags & IR3_REG_SSA) {
117 printf("_[");
118 print_instr_name(reg->instr);
119 printf("]");
120 } else if (reg->flags & IR3_REG_RELATIV) {
121 if (reg->flags & IR3_REG_HALF)
122 printf("h");
123 if (reg->flags & IR3_REG_CONST)
124 printf("c<a0.x + %d>", reg->array.offset);
125 else
126 printf("\x1b[0;31mr<a0.x + %d>\x1b[0m (%u)", reg->array.offset, reg->size);
127 } else {
128 if (reg->flags & IR3_REG_HALF)
129 printf("h");
130 if (reg->flags & IR3_REG_CONST)
131 printf("c%u.%c", reg_num(reg), "xyzw"[reg_comp(reg)]);
132 else
133 printf("\x1b[0;31mr%u.%c\x1b[0m", reg_num(reg), "xyzw"[reg_comp(reg)]);
134 }
135 }
136
137 static void
138 tab(int lvl)
139 {
140 for (int i = 0; i < lvl; i++)
141 printf("\t");
142 }
143
144 static void
145 print_instr(struct ir3_instruction *instr, int lvl)
146 {
147 unsigned i;
148
149 tab(lvl);
150
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 ? ", " : " ");
155 print_reg_name(reg);
156 }
157
158 if (instr->address) {
159 printf(", address=_");
160 printf("[");
161 print_instr_name(instr->address);
162 printf("]");
163 }
164
165 if (instr->cp.left) {
166 printf(", left=_");
167 printf("[");
168 print_instr_name(instr->cp.left);
169 printf("]");
170 }
171
172 if (instr->cp.right) {
173 printf(", right=_");
174 printf("[");
175 print_instr_name(instr->cp.right);
176 printf("]");
177 }
178
179 if (instr->opc == OPC_META_FO) {
180 printf(", off=%d", instr->fo.off);
181 }
182
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 ? "!" : "");
187 }
188 printf(", target=block%u", block_id(instr->cat0.target));
189 }
190
191 if (instr->deps_count) {
192 printf(", false-deps:");
193 for (unsigned i = 0; i < instr->deps_count; i++) {
194 if (i > 0)
195 printf(", ");
196 printf("_[");
197 print_instr_name(instr->deps[i]);
198 printf("]");
199 }
200 }
201
202 printf("\n");
203 }
204
205 void ir3_print_instr(struct ir3_instruction *instr)
206 {
207 print_instr(instr, 0);
208 }
209
210 static void
211 print_block(struct ir3_block *block, int lvl)
212 {
213 tab(lvl); printf("block%u {\n", block_id(block));
214
215 if (block->predecessors_count > 0) {
216 tab(lvl+1);
217 printf("pred: ");
218 for (unsigned i = 0; i < block->predecessors_count; i++) {
219 if (i)
220 printf(", ");
221 printf("block%u", block_id(block->predecessors[i]));
222 }
223 printf("\n");
224 }
225
226 list_for_each_entry (struct ir3_instruction, instr, &block->instr_list, node) {
227 print_instr(instr, lvl+1);
228 }
229
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);
233 }
234 tab(lvl+1); printf(" */\n");
235
236 if (block->successors[1]) {
237 /* leading into if/else: */
238 tab(lvl+1);
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]) {
245 tab(lvl+1);
246 printf("/* succs: block%u; */\n",
247 block_id(block->successors[0]));
248 }
249 tab(lvl); printf("}\n");
250 }
251
252 void
253 ir3_print(struct ir3 *ir)
254 {
255 list_for_each_entry (struct ir3_block, block, &ir->block_list, node)
256 print_block(block, 0);
257
258 for (unsigned i = 0; i < ir->noutputs; i++) {
259 if (!ir->outputs[i])
260 continue;
261 printf("out%d: ", i);
262 print_instr(ir->outputs[i], 0);
263 }
264 }