aco: make PhysReg in units of bytes
[mesa.git] / src / amd / compiler / aco_print_ir.cpp
1 #include "aco_ir.h"
2 #include "aco_builder.h"
3
4 #include "sid.h"
5 #include "ac_shader_util.h"
6
7 namespace aco {
8
9 static const char *reduce_ops[] = {
10 [iadd32] = "iadd32",
11 [iadd64] = "iadd64",
12 [imul32] = "imul32",
13 [imul64] = "imul64",
14 [fadd32] = "fadd32",
15 [fadd64] = "fadd64",
16 [fmul32] = "fmul32",
17 [fmul64] = "fmul64",
18 [imin32] = "imin32",
19 [imin64] = "imin64",
20 [imax32] = "imax32",
21 [imax64] = "imax64",
22 [umin32] = "umin32",
23 [umin64] = "umin64",
24 [umax32] = "umax32",
25 [umax64] = "umax64",
26 [fmin32] = "fmin32",
27 [fmin64] = "fmin64",
28 [fmax32] = "fmax32",
29 [fmax64] = "fmax64",
30 [iand32] = "iand32",
31 [iand64] = "iand64",
32 [ior32] = "ior32",
33 [ior64] = "ior64",
34 [ixor32] = "ixor32",
35 [ixor64] = "ixor64",
36 [gfx10_wave64_bpermute] = "gfx10_wave64_bpermute",
37 };
38
39 static void print_reg_class(const RegClass rc, FILE *output)
40 {
41 switch (rc) {
42 case RegClass::s1: fprintf(output, " s1: "); return;
43 case RegClass::s2: fprintf(output, " s2: "); return;
44 case RegClass::s3: fprintf(output, " s3: "); return;
45 case RegClass::s4: fprintf(output, " s4: "); return;
46 case RegClass::s6: fprintf(output, " s6: "); return;
47 case RegClass::s8: fprintf(output, " s8: "); return;
48 case RegClass::s16: fprintf(output, "s16: "); return;
49 case RegClass::v1: fprintf(output, " v1: "); return;
50 case RegClass::v2: fprintf(output, " v2: "); return;
51 case RegClass::v3: fprintf(output, " v3: "); return;
52 case RegClass::v4: fprintf(output, " v4: "); return;
53 case RegClass::v5: fprintf(output, " v5: "); return;
54 case RegClass::v6: fprintf(output, " v6: "); return;
55 case RegClass::v7: fprintf(output, " v7: "); return;
56 case RegClass::v8: fprintf(output, " v8: "); return;
57 case RegClass::v1_linear: fprintf(output, " v1: "); return;
58 case RegClass::v2_linear: fprintf(output, " v2: "); return;
59 }
60 }
61
62 void print_physReg(unsigned reg, unsigned size, FILE *output)
63 {
64 if (reg == 124) {
65 fprintf(output, ":m0");
66 } else if (reg == 106) {
67 fprintf(output, ":vcc");
68 } else if (reg == 253) {
69 fprintf(output, ":scc");
70 } else if (reg == 126) {
71 fprintf(output, ":exec");
72 } else {
73 bool is_vgpr = reg / 256;
74 reg = reg % 256;
75 fprintf(output, ":%c[%d", is_vgpr ? 'v' : 's', reg);
76 if (size > 1)
77 fprintf(output, "-%d]", reg + size -1);
78 else
79 fprintf(output, "]");
80 }
81 }
82
83 static void print_constant(uint8_t reg, FILE *output)
84 {
85 if (reg >= 128 && reg <= 192) {
86 fprintf(output, "%d", reg - 128);
87 return;
88 } else if (reg >= 192 && reg <= 208) {
89 fprintf(output, "%d", 192 - reg);
90 return;
91 }
92
93 switch (reg) {
94 case 240:
95 fprintf(output, "0.5");
96 break;
97 case 241:
98 fprintf(output, "-0.5");
99 break;
100 case 242:
101 fprintf(output, "1.0");
102 break;
103 case 243:
104 fprintf(output, "-1.0");
105 break;
106 case 244:
107 fprintf(output, "2.0");
108 break;
109 case 245:
110 fprintf(output, "-2.0");
111 break;
112 case 246:
113 fprintf(output, "4.0");
114 break;
115 case 247:
116 fprintf(output, "-4.0");
117 break;
118 case 248:
119 fprintf(output, "1/(2*PI)");
120 break;
121 }
122 }
123
124 static void print_operand(const Operand *operand, FILE *output)
125 {
126 if (operand->isLiteral()) {
127 fprintf(output, "0x%x", operand->constantValue());
128 } else if (operand->isConstant()) {
129 print_constant(operand->physReg().reg(), output);
130 } else if (operand->isUndefined()) {
131 print_reg_class(operand->regClass(), output);
132 fprintf(output, "undef");
133 } else {
134 if (operand->isLateKill())
135 fprintf(output, "(latekill)");
136
137 fprintf(output, "%%%d", operand->tempId());
138
139 if (operand->isFixed())
140 print_physReg(operand->physReg(), operand->size(), output);
141 }
142 }
143
144 static void print_definition(const Definition *definition, FILE *output)
145 {
146 print_reg_class(definition->regClass(), output);
147 fprintf(output, "%%%d", definition->tempId());
148
149 if (definition->isFixed())
150 print_physReg(definition->physReg(), definition->size(), output);
151 }
152
153 static void print_barrier_reorder(bool can_reorder, barrier_interaction barrier, FILE *output)
154 {
155 if (can_reorder)
156 fprintf(output, " reorder");
157
158 if (barrier & barrier_buffer)
159 fprintf(output, " buffer");
160 if (barrier & barrier_image)
161 fprintf(output, " image");
162 if (barrier & barrier_atomic)
163 fprintf(output, " atomic");
164 if (barrier & barrier_shared)
165 fprintf(output, " shared");
166 if (barrier & barrier_gs_data)
167 fprintf(output, " gs_data");
168 if (barrier & barrier_gs_sendmsg)
169 fprintf(output, " gs_sendmsg");
170 }
171
172 static void print_instr_format_specific(struct Instruction *instr, FILE *output)
173 {
174 switch (instr->format) {
175 case Format::SOPK: {
176 SOPK_instruction* sopk = static_cast<SOPK_instruction*>(instr);
177 fprintf(output, " imm:%d", sopk->imm & 0x8000 ? (sopk->imm - 65536) : sopk->imm);
178 break;
179 }
180 case Format::SOPP: {
181 SOPP_instruction* sopp = static_cast<SOPP_instruction*>(instr);
182 uint16_t imm = sopp->imm;
183 switch (instr->opcode) {
184 case aco_opcode::s_waitcnt: {
185 /* we usually should check the chip class for vmcnt/lgkm, but
186 * insert_waitcnt() should fill it in regardless. */
187 unsigned vmcnt = (imm & 0xF) | ((imm & (0x3 << 14)) >> 10);
188 if (vmcnt != 63) fprintf(output, " vmcnt(%d)", vmcnt);
189 if (((imm >> 4) & 0x7) < 0x7) fprintf(output, " expcnt(%d)", (imm >> 4) & 0x7);
190 if (((imm >> 8) & 0x3F) < 0x3F) fprintf(output, " lgkmcnt(%d)", (imm >> 8) & 0x3F);
191 break;
192 }
193 case aco_opcode::s_endpgm:
194 case aco_opcode::s_endpgm_saved:
195 case aco_opcode::s_endpgm_ordered_ps_done:
196 case aco_opcode::s_wakeup:
197 case aco_opcode::s_barrier:
198 case aco_opcode::s_icache_inv:
199 case aco_opcode::s_ttracedata:
200 case aco_opcode::s_set_gpr_idx_off: {
201 break;
202 }
203 case aco_opcode::s_sendmsg: {
204 unsigned id = imm & sendmsg_id_mask;
205 switch (id) {
206 case sendmsg_none:
207 fprintf(output, " sendmsg(MSG_NONE)");
208 break;
209 case _sendmsg_gs:
210 fprintf(output, " sendmsg(gs%s%s, %u)",
211 imm & 0x10 ? ", cut" : "", imm & 0x20 ? ", emit" : "", imm >> 8);
212 break;
213 case _sendmsg_gs_done:
214 fprintf(output, " sendmsg(gs_done%s%s, %u)",
215 imm & 0x10 ? ", cut" : "", imm & 0x20 ? ", emit" : "", imm >> 8);
216 break;
217 case sendmsg_save_wave:
218 fprintf(output, " sendmsg(save_wave)");
219 break;
220 case sendmsg_stall_wave_gen:
221 fprintf(output, " sendmsg(stall_wave_gen)");
222 break;
223 case sendmsg_halt_waves:
224 fprintf(output, " sendmsg(halt_waves)");
225 break;
226 case sendmsg_ordered_ps_done:
227 fprintf(output, " sendmsg(ordered_ps_done)");
228 break;
229 case sendmsg_early_prim_dealloc:
230 fprintf(output, " sendmsg(early_prim_dealloc)");
231 break;
232 case sendmsg_gs_alloc_req:
233 fprintf(output, " sendmsg(gs_alloc_req)");
234 break;
235 }
236 break;
237 }
238 default: {
239 if (imm)
240 fprintf(output, " imm:%u", imm);
241 break;
242 }
243 }
244 if (sopp->block != -1)
245 fprintf(output, " block:BB%d", sopp->block);
246 break;
247 }
248 case Format::SMEM: {
249 SMEM_instruction* smem = static_cast<SMEM_instruction*>(instr);
250 if (smem->glc)
251 fprintf(output, " glc");
252 if (smem->dlc)
253 fprintf(output, " dlc");
254 if (smem->nv)
255 fprintf(output, " nv");
256 print_barrier_reorder(smem->can_reorder, smem->barrier, output);
257 break;
258 }
259 case Format::VINTRP: {
260 Interp_instruction* vintrp = static_cast<Interp_instruction*>(instr);
261 fprintf(output, " attr%d.%c", vintrp->attribute, "xyzw"[vintrp->component]);
262 break;
263 }
264 case Format::DS: {
265 DS_instruction* ds = static_cast<DS_instruction*>(instr);
266 if (ds->offset0)
267 fprintf(output, " offset0:%u", ds->offset0);
268 if (ds->offset1)
269 fprintf(output, " offset1:%u", ds->offset1);
270 if (ds->gds)
271 fprintf(output, " gds");
272 break;
273 }
274 case Format::MUBUF: {
275 MUBUF_instruction* mubuf = static_cast<MUBUF_instruction*>(instr);
276 if (mubuf->offset)
277 fprintf(output, " offset:%u", mubuf->offset);
278 if (mubuf->offen)
279 fprintf(output, " offen");
280 if (mubuf->idxen)
281 fprintf(output, " idxen");
282 if (mubuf->addr64)
283 fprintf(output, " addr64");
284 if (mubuf->glc)
285 fprintf(output, " glc");
286 if (mubuf->dlc)
287 fprintf(output, " dlc");
288 if (mubuf->slc)
289 fprintf(output, " slc");
290 if (mubuf->tfe)
291 fprintf(output, " tfe");
292 if (mubuf->lds)
293 fprintf(output, " lds");
294 if (mubuf->disable_wqm)
295 fprintf(output, " disable_wqm");
296 print_barrier_reorder(mubuf->can_reorder, mubuf->barrier, output);
297 break;
298 }
299 case Format::MIMG: {
300 MIMG_instruction* mimg = static_cast<MIMG_instruction*>(instr);
301 unsigned identity_dmask = !instr->definitions.empty() ?
302 (1 << instr->definitions[0].size()) - 1 :
303 0xf;
304 if ((mimg->dmask & identity_dmask) != identity_dmask)
305 fprintf(output, " dmask:%s%s%s%s",
306 mimg->dmask & 0x1 ? "x" : "",
307 mimg->dmask & 0x2 ? "y" : "",
308 mimg->dmask & 0x4 ? "z" : "",
309 mimg->dmask & 0x8 ? "w" : "");
310 switch (mimg->dim) {
311 case ac_image_1d:
312 fprintf(output, " 1d");
313 break;
314 case ac_image_2d:
315 fprintf(output, " 2d");
316 break;
317 case ac_image_3d:
318 fprintf(output, " 3d");
319 break;
320 case ac_image_cube:
321 fprintf(output, " cube");
322 break;
323 case ac_image_1darray:
324 fprintf(output, " 1darray");
325 break;
326 case ac_image_2darray:
327 fprintf(output, " 2darray");
328 break;
329 case ac_image_2dmsaa:
330 fprintf(output, " 2dmsaa");
331 break;
332 case ac_image_2darraymsaa:
333 fprintf(output, " 2darraymsaa");
334 break;
335 }
336 if (mimg->unrm)
337 fprintf(output, " unrm");
338 if (mimg->glc)
339 fprintf(output, " glc");
340 if (mimg->dlc)
341 fprintf(output, " dlc");
342 if (mimg->slc)
343 fprintf(output, " slc");
344 if (mimg->tfe)
345 fprintf(output, " tfe");
346 if (mimg->da)
347 fprintf(output, " da");
348 if (mimg->lwe)
349 fprintf(output, " lwe");
350 if (mimg->r128 || mimg->a16)
351 fprintf(output, " r128/a16");
352 if (mimg->d16)
353 fprintf(output, " d16");
354 if (mimg->disable_wqm)
355 fprintf(output, " disable_wqm");
356 print_barrier_reorder(mimg->can_reorder, mimg->barrier, output);
357 break;
358 }
359 case Format::EXP: {
360 Export_instruction* exp = static_cast<Export_instruction*>(instr);
361 unsigned identity_mask = exp->compressed ? 0x5 : 0xf;
362 if ((exp->enabled_mask & identity_mask) != identity_mask)
363 fprintf(output, " en:%c%c%c%c",
364 exp->enabled_mask & 0x1 ? 'r' : '*',
365 exp->enabled_mask & 0x2 ? 'g' : '*',
366 exp->enabled_mask & 0x4 ? 'b' : '*',
367 exp->enabled_mask & 0x8 ? 'a' : '*');
368 if (exp->compressed)
369 fprintf(output, " compr");
370 if (exp->done)
371 fprintf(output, " done");
372 if (exp->valid_mask)
373 fprintf(output, " vm");
374
375 if (exp->dest <= V_008DFC_SQ_EXP_MRT + 7)
376 fprintf(output, " mrt%d", exp->dest - V_008DFC_SQ_EXP_MRT);
377 else if (exp->dest == V_008DFC_SQ_EXP_MRTZ)
378 fprintf(output, " mrtz");
379 else if (exp->dest == V_008DFC_SQ_EXP_NULL)
380 fprintf(output, " null");
381 else if (exp->dest >= V_008DFC_SQ_EXP_POS && exp->dest <= V_008DFC_SQ_EXP_POS + 3)
382 fprintf(output, " pos%d", exp->dest - V_008DFC_SQ_EXP_POS);
383 else if (exp->dest >= V_008DFC_SQ_EXP_PARAM && exp->dest <= V_008DFC_SQ_EXP_PARAM + 31)
384 fprintf(output, " param%d", exp->dest - V_008DFC_SQ_EXP_PARAM);
385 break;
386 }
387 case Format::PSEUDO_BRANCH: {
388 Pseudo_branch_instruction* branch = static_cast<Pseudo_branch_instruction*>(instr);
389 /* Note: BB0 cannot be a branch target */
390 if (branch->target[0] != 0)
391 fprintf(output, " BB%d", branch->target[0]);
392 if (branch->target[1] != 0)
393 fprintf(output, ", BB%d", branch->target[1]);
394 break;
395 }
396 case Format::PSEUDO_REDUCTION: {
397 Pseudo_reduction_instruction* reduce = static_cast<Pseudo_reduction_instruction*>(instr);
398 fprintf(output, " op:%s", reduce_ops[reduce->reduce_op]);
399 if (reduce->cluster_size)
400 fprintf(output, " cluster_size:%u", reduce->cluster_size);
401 break;
402 }
403 case Format::FLAT:
404 case Format::GLOBAL:
405 case Format::SCRATCH: {
406 FLAT_instruction* flat = static_cast<FLAT_instruction*>(instr);
407 if (flat->offset)
408 fprintf(output, " offset:%u", flat->offset);
409 if (flat->glc)
410 fprintf(output, " glc");
411 if (flat->dlc)
412 fprintf(output, " dlc");
413 if (flat->slc)
414 fprintf(output, " slc");
415 if (flat->lds)
416 fprintf(output, " lds");
417 if (flat->nv)
418 fprintf(output, " nv");
419 if (flat->disable_wqm)
420 fprintf(output, " disable_wqm");
421 print_barrier_reorder(flat->can_reorder, flat->barrier, output);
422 break;
423 }
424 case Format::MTBUF: {
425 MTBUF_instruction* mtbuf = static_cast<MTBUF_instruction*>(instr);
426 fprintf(output, " dfmt:");
427 switch (mtbuf->dfmt) {
428 case V_008F0C_BUF_DATA_FORMAT_8: fprintf(output, "8"); break;
429 case V_008F0C_BUF_DATA_FORMAT_16: fprintf(output, "16"); break;
430 case V_008F0C_BUF_DATA_FORMAT_8_8: fprintf(output, "8_8"); break;
431 case V_008F0C_BUF_DATA_FORMAT_32: fprintf(output, "32"); break;
432 case V_008F0C_BUF_DATA_FORMAT_16_16: fprintf(output, "16_16"); break;
433 case V_008F0C_BUF_DATA_FORMAT_10_11_11: fprintf(output, "10_11_11"); break;
434 case V_008F0C_BUF_DATA_FORMAT_11_11_10: fprintf(output, "11_11_10"); break;
435 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2: fprintf(output, "10_10_10_2"); break;
436 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10: fprintf(output, "2_10_10_10"); break;
437 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8: fprintf(output, "8_8_8_8"); break;
438 case V_008F0C_BUF_DATA_FORMAT_32_32: fprintf(output, "32_32"); break;
439 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16: fprintf(output, "16_16_16_16"); break;
440 case V_008F0C_BUF_DATA_FORMAT_32_32_32: fprintf(output, "32_32_32"); break;
441 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32: fprintf(output, "32_32_32_32"); break;
442 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15: fprintf(output, "reserved15"); break;
443 }
444 fprintf(output, " nfmt:");
445 switch (mtbuf->nfmt) {
446 case V_008F0C_BUF_NUM_FORMAT_UNORM: fprintf(output, "unorm"); break;
447 case V_008F0C_BUF_NUM_FORMAT_SNORM: fprintf(output, "snorm"); break;
448 case V_008F0C_BUF_NUM_FORMAT_USCALED: fprintf(output, "uscaled"); break;
449 case V_008F0C_BUF_NUM_FORMAT_SSCALED: fprintf(output, "sscaled"); break;
450 case V_008F0C_BUF_NUM_FORMAT_UINT: fprintf(output, "uint"); break;
451 case V_008F0C_BUF_NUM_FORMAT_SINT: fprintf(output, "sint"); break;
452 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL: fprintf(output, "snorm"); break;
453 case V_008F0C_BUF_NUM_FORMAT_FLOAT: fprintf(output, "float"); break;
454 }
455 if (mtbuf->offset)
456 fprintf(output, " offset:%u", mtbuf->offset);
457 if (mtbuf->offen)
458 fprintf(output, " offen");
459 if (mtbuf->idxen)
460 fprintf(output, " idxen");
461 if (mtbuf->glc)
462 fprintf(output, " glc");
463 if (mtbuf->dlc)
464 fprintf(output, " dlc");
465 if (mtbuf->slc)
466 fprintf(output, " slc");
467 if (mtbuf->tfe)
468 fprintf(output, " tfe");
469 if (mtbuf->disable_wqm)
470 fprintf(output, " disable_wqm");
471 print_barrier_reorder(mtbuf->can_reorder, mtbuf->barrier, output);
472 break;
473 }
474 default: {
475 break;
476 }
477 }
478 if (instr->isVOP3()) {
479 VOP3A_instruction* vop3 = static_cast<VOP3A_instruction*>(instr);
480 switch (vop3->omod) {
481 case 1:
482 fprintf(output, " *2");
483 break;
484 case 2:
485 fprintf(output, " *4");
486 break;
487 case 3:
488 fprintf(output, " *0.5");
489 break;
490 }
491 if (vop3->clamp)
492 fprintf(output, " clamp");
493 } else if (instr->isDPP()) {
494 DPP_instruction* dpp = static_cast<DPP_instruction*>(instr);
495 if (dpp->dpp_ctrl <= 0xff) {
496 fprintf(output, " quad_perm:[%d,%d,%d,%d]",
497 dpp->dpp_ctrl & 0x3, (dpp->dpp_ctrl >> 2) & 0x3,
498 (dpp->dpp_ctrl >> 4) & 0x3, (dpp->dpp_ctrl >> 6) & 0x3);
499 } else if (dpp->dpp_ctrl >= 0x101 && dpp->dpp_ctrl <= 0x10f) {
500 fprintf(output, " row_shl:%d", dpp->dpp_ctrl & 0xf);
501 } else if (dpp->dpp_ctrl >= 0x111 && dpp->dpp_ctrl <= 0x11f) {
502 fprintf(output, " row_shr:%d", dpp->dpp_ctrl & 0xf);
503 } else if (dpp->dpp_ctrl >= 0x121 && dpp->dpp_ctrl <= 0x12f) {
504 fprintf(output, " row_ror:%d", dpp->dpp_ctrl & 0xf);
505 } else if (dpp->dpp_ctrl == dpp_wf_sl1) {
506 fprintf(output, " wave_shl:1");
507 } else if (dpp->dpp_ctrl == dpp_wf_rl1) {
508 fprintf(output, " wave_rol:1");
509 } else if (dpp->dpp_ctrl == dpp_wf_sr1) {
510 fprintf(output, " wave_shr:1");
511 } else if (dpp->dpp_ctrl == dpp_wf_rr1) {
512 fprintf(output, " wave_ror:1");
513 } else if (dpp->dpp_ctrl == dpp_row_mirror) {
514 fprintf(output, " row_mirror");
515 } else if (dpp->dpp_ctrl == dpp_row_half_mirror) {
516 fprintf(output, " row_half_mirror");
517 } else if (dpp->dpp_ctrl == dpp_row_bcast15) {
518 fprintf(output, " row_bcast:15");
519 } else if (dpp->dpp_ctrl == dpp_row_bcast31) {
520 fprintf(output, " row_bcast:31");
521 } else {
522 fprintf(output, " dpp_ctrl:0x%.3x", dpp->dpp_ctrl);
523 }
524 if (dpp->row_mask != 0xf)
525 fprintf(output, " row_mask:0x%.1x", dpp->row_mask);
526 if (dpp->bank_mask != 0xf)
527 fprintf(output, " bank_mask:0x%.1x", dpp->bank_mask);
528 if (dpp->bound_ctrl)
529 fprintf(output, " bound_ctrl:1");
530 } else if ((int)instr->format & (int)Format::SDWA) {
531 fprintf(output, " (printing unimplemented)");
532 }
533 }
534
535 void aco_print_instr(struct Instruction *instr, FILE *output)
536 {
537 if (!instr->definitions.empty()) {
538 for (unsigned i = 0; i < instr->definitions.size(); ++i) {
539 print_definition(&instr->definitions[i], output);
540 if (i + 1 != instr->definitions.size())
541 fprintf(output, ", ");
542 }
543 fprintf(output, " = ");
544 }
545 fprintf(output, "%s", instr_info.name[(int)instr->opcode]);
546 if (instr->operands.size()) {
547 bool abs[instr->operands.size()];
548 bool neg[instr->operands.size()];
549 if ((int)instr->format & (int)Format::VOP3A) {
550 VOP3A_instruction* vop3 = static_cast<VOP3A_instruction*>(instr);
551 for (unsigned i = 0; i < instr->operands.size(); ++i) {
552 abs[i] = vop3->abs[i];
553 neg[i] = vop3->neg[i];
554 }
555 } else if (instr->isDPP()) {
556 DPP_instruction* dpp = static_cast<DPP_instruction*>(instr);
557 assert(instr->operands.size() <= 2);
558 for (unsigned i = 0; i < instr->operands.size(); ++i) {
559 abs[i] = dpp->abs[i];
560 neg[i] = dpp->neg[i];
561 }
562 } else {
563 for (unsigned i = 0; i < instr->operands.size(); ++i) {
564 abs[i] = false;
565 neg[i] = false;
566 }
567 }
568 for (unsigned i = 0; i < instr->operands.size(); ++i) {
569 if (i)
570 fprintf(output, ", ");
571 else
572 fprintf(output, " ");
573
574 if (neg[i])
575 fprintf(output, "-");
576 if (abs[i])
577 fprintf(output, "|");
578 print_operand(&instr->operands[i], output);
579 if (abs[i])
580 fprintf(output, "|");
581 }
582 }
583 print_instr_format_specific(instr, output);
584 }
585
586 static void print_block_kind(uint16_t kind, FILE *output)
587 {
588 if (kind & block_kind_uniform)
589 fprintf(output, "uniform, ");
590 if (kind & block_kind_top_level)
591 fprintf(output, "top-level, ");
592 if (kind & block_kind_loop_preheader)
593 fprintf(output, "loop-preheader, ");
594 if (kind & block_kind_loop_header)
595 fprintf(output, "loop-header, ");
596 if (kind & block_kind_loop_exit)
597 fprintf(output, "loop-exit, ");
598 if (kind & block_kind_continue)
599 fprintf(output, "continue, ");
600 if (kind & block_kind_break)
601 fprintf(output, "break, ");
602 if (kind & block_kind_continue_or_break)
603 fprintf(output, "continue_or_break, ");
604 if (kind & block_kind_discard)
605 fprintf(output, "discard, ");
606 if (kind & block_kind_branch)
607 fprintf(output, "branch, ");
608 if (kind & block_kind_merge)
609 fprintf(output, "merge, ");
610 if (kind & block_kind_invert)
611 fprintf(output, "invert, ");
612 if (kind & block_kind_uses_discard_if)
613 fprintf(output, "discard_if, ");
614 if (kind & block_kind_needs_lowering)
615 fprintf(output, "needs_lowering, ");
616 if (kind & block_kind_uses_demote)
617 fprintf(output, "uses_demote, ");
618 }
619
620 void aco_print_block(const struct Block* block, FILE *output)
621 {
622 fprintf(output, "BB%d\n", block->index);
623 fprintf(output, "/* logical preds: ");
624 for (unsigned pred : block->logical_preds)
625 fprintf(output, "BB%d, ", pred);
626 fprintf(output, "/ linear preds: ");
627 for (unsigned pred : block->linear_preds)
628 fprintf(output, "BB%d, ", pred);
629 fprintf(output, "/ kind: ");
630 print_block_kind(block->kind, output);
631 fprintf(output, "*/\n");
632 for (auto const& instr : block->instructions) {
633 fprintf(output, "\t");
634 aco_print_instr(instr.get(), output);
635 fprintf(output, "\n");
636 }
637 }
638
639 void aco_print_program(Program *program, FILE *output)
640 {
641 for (Block const& block : program->blocks)
642 aco_print_block(&block, output);
643
644 if (program->constant_data.size()) {
645 fprintf(output, "\n/* constant data */\n");
646 for (unsigned i = 0; i < program->constant_data.size(); i += 32) {
647 fprintf(output, "[%06d] ", i);
648 unsigned line_size = std::min<size_t>(program->constant_data.size() - i, 32);
649 for (unsigned j = 0; j < line_size; j += 4) {
650 unsigned size = std::min<size_t>(program->constant_data.size() - (i + j), 4);
651 uint32_t v = 0;
652 memcpy(&v, &program->constant_data[i + j], size);
653 fprintf(output, " %08x", v);
654 }
655 fprintf(output, "\n");
656 }
657 }
658
659 fprintf(output, "\n");
660 }
661
662 }