1 /*
2 * Copyright © 2018 Valve Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #include "aco_builder.h"
8 #include "aco_ir.h"
9
10 #include "common/ac_shader_util.h"
11 #include "common/sid.h"
12
13 #include <array>
14
15 namespace aco {
16
17 namespace {
18
19 const std::array<const char*, num_reduce_ops> reduce_ops = []()
__anon714a2d7f0202() 20 {
21 std::array<const char*, num_reduce_ops> ret{};
22 ret[iadd8] = "iadd8";
23 ret[iadd16] = "iadd16";
24 ret[iadd32] = "iadd32";
25 ret[iadd64] = "iadd64";
26 ret[imul8] = "imul8";
27 ret[imul16] = "imul16";
28 ret[imul32] = "imul32";
29 ret[imul64] = "imul64";
30 ret[fadd16] = "fadd16";
31 ret[fadd32] = "fadd32";
32 ret[fadd64] = "fadd64";
33 ret[fmul16] = "fmul16";
34 ret[fmul32] = "fmul32";
35 ret[fmul64] = "fmul64";
36 ret[imin8] = "imin8";
37 ret[imin16] = "imin16";
38 ret[imin32] = "imin32";
39 ret[imin64] = "imin64";
40 ret[imax8] = "imax8";
41 ret[imax16] = "imax16";
42 ret[imax32] = "imax32";
43 ret[imax64] = "imax64";
44 ret[umin8] = "umin8";
45 ret[umin16] = "umin16";
46 ret[umin32] = "umin32";
47 ret[umin64] = "umin64";
48 ret[umax8] = "umax8";
49 ret[umax16] = "umax16";
50 ret[umax32] = "umax32";
51 ret[umax64] = "umax64";
52 ret[fmin16] = "fmin16";
53 ret[fmin32] = "fmin32";
54 ret[fmin64] = "fmin64";
55 ret[fmax16] = "fmax16";
56 ret[fmax32] = "fmax32";
57 ret[fmax64] = "fmax64";
58 ret[iand8] = "iand8";
59 ret[iand16] = "iand16";
60 ret[iand32] = "iand32";
61 ret[iand64] = "iand64";
62 ret[ior8] = "ior8";
63 ret[ior16] = "ior16";
64 ret[ior32] = "ior32";
65 ret[ior64] = "ior64";
66 ret[ixor8] = "ixor8";
67 ret[ixor16] = "ixor16";
68 ret[ixor32] = "ixor32";
69 ret[ixor64] = "ixor64";
70 return ret;
71 }();
72
73 static void
print_reg_class(const RegClass rc,FILE * output)74 print_reg_class(const RegClass rc, FILE* output)
75 {
76 if (rc.is_subdword()) {
77 fprintf(output, " v%ub: ", rc.bytes());
78 } else if (rc.type() == RegType::sgpr) {
79 fprintf(output, " s%u: ", rc.size());
80 } else if (rc.is_linear()) {
81 fprintf(output, " lv%u: ", rc.size());
82 } else {
83 fprintf(output, " v%u: ", rc.size());
84 }
85 }
86
87 void
print_physReg(PhysReg reg,unsigned bytes,FILE * output,unsigned flags)88 print_physReg(PhysReg reg, unsigned bytes, FILE* output, unsigned flags)
89 {
90 if (reg == 106) {
91 fprintf(output, bytes > 4 ? "vcc" : "vcc_lo");
92 } else if (reg == 107) {
93 fprintf(output, "vcc_hi");
94 } else if (reg == 124) {
95 fprintf(output, "m0");
96 } else if (reg == 125) {
97 fprintf(output, "null");
98 } else if (reg == 126) {
99 fprintf(output, bytes > 4 ? "exec" : "exec_lo");
100 } else if (reg == 127) {
101 fprintf(output, "exec_hi");
102 } else if (reg == 253) {
103 fprintf(output, "scc");
104 } else {
105 bool is_vgpr = reg / 256;
106 unsigned r = reg % 256;
107 unsigned size = DIV_ROUND_UP(bytes, 4);
108 if (size == 1 && (flags & print_no_ssa)) {
109 fprintf(output, "%c%d", is_vgpr ? 'v' : 's', r);
110 } else {
111 fprintf(output, "%c[%d", is_vgpr ? 'v' : 's', r);
112 if (size > 1)
113 fprintf(output, "-%d]", r + size - 1);
114 else
115 fprintf(output, "]");
116 }
117 if (reg.byte() || bytes % 4)
118 fprintf(output, "[%d:%d]", reg.byte() * 8, (reg.byte() + bytes) * 8);
119 }
120 }
121
122 static void
print_constant(uint8_t reg,FILE * output)123 print_constant(uint8_t reg, FILE* output)
124 {
125 if (reg >= 128 && reg <= 192) {
126 fprintf(output, "%d", reg - 128);
127 return;
128 } else if (reg >= 192 && reg <= 208) {
129 fprintf(output, "%d", 192 - reg);
130 return;
131 }
132
133 switch (reg) {
134 case 240: fprintf(output, "0.5"); break;
135 case 241: fprintf(output, "-0.5"); break;
136 case 242: fprintf(output, "1.0"); break;
137 case 243: fprintf(output, "-1.0"); break;
138 case 244: fprintf(output, "2.0"); break;
139 case 245: fprintf(output, "-2.0"); break;
140 case 246: fprintf(output, "4.0"); break;
141 case 247: fprintf(output, "-4.0"); break;
142 case 248: fprintf(output, "1/(2*PI)"); break;
143 }
144 }
145
146 static void
print_definition(const Definition * definition,FILE * output,unsigned flags)147 print_definition(const Definition* definition, FILE* output, unsigned flags)
148 {
149 if (!(flags & print_no_ssa))
150 print_reg_class(definition->regClass(), output);
151 if (definition->isPrecise())
152 fprintf(output, "(precise)");
153 if (definition->isInfPreserve() || definition->isNaNPreserve() || definition->isSZPreserve()) {
154 fprintf(output, "(");
155 if (definition->isSZPreserve())
156 fprintf(output, "Sz");
157 if (definition->isInfPreserve())
158 fprintf(output, "Inf");
159 if (definition->isNaNPreserve())
160 fprintf(output, "NaN");
161 fprintf(output, "Preserve)");
162 }
163 if (definition->isNUW())
164 fprintf(output, "(nuw)");
165 if (definition->isNoCSE())
166 fprintf(output, "(noCSE)");
167 if ((flags & print_kill) && definition->isKill())
168 fprintf(output, "(kill)");
169 if (!(flags & print_no_ssa))
170 fprintf(output, "%%%d%s", definition->tempId(), definition->isFixed() ? ":" : "");
171
172 if (definition->isFixed())
173 print_physReg(definition->physReg(), definition->bytes(), output, flags);
174 }
175
176 static void
print_storage(storage_class storage,FILE * output)177 print_storage(storage_class storage, FILE* output)
178 {
179 fprintf(output, " storage:");
180 int printed = 0;
181 if (storage & storage_buffer)
182 printed += fprintf(output, "%sbuffer", printed ? "," : "");
183 if (storage & storage_gds)
184 printed += fprintf(output, "%sgds", printed ? "," : "");
185 if (storage & storage_image)
186 printed += fprintf(output, "%simage", printed ? "," : "");
187 if (storage & storage_shared)
188 printed += fprintf(output, "%sshared", printed ? "," : "");
189 if (storage & storage_task_payload)
190 printed += fprintf(output, "%stask_payload", printed ? "," : "");
191 if (storage & storage_vmem_output)
192 printed += fprintf(output, "%svmem_output", printed ? "," : "");
193 if (storage & storage_scratch)
194 printed += fprintf(output, "%sscratch", printed ? "," : "");
195 if (storage & storage_vgpr_spill)
196 printed += fprintf(output, "%svgpr_spill", printed ? "," : "");
197 }
198
199 static void
print_semantics(memory_semantics sem,FILE * output)200 print_semantics(memory_semantics sem, FILE* output)
201 {
202 fprintf(output, " semantics:");
203 int printed = 0;
204 if (sem & semantic_acquire)
205 printed += fprintf(output, "%sacquire", printed ? "," : "");
206 if (sem & semantic_release)
207 printed += fprintf(output, "%srelease", printed ? "," : "");
208 if (sem & semantic_volatile)
209 printed += fprintf(output, "%svolatile", printed ? "," : "");
210 if (sem & semantic_private)
211 printed += fprintf(output, "%sprivate", printed ? "," : "");
212 if (sem & semantic_can_reorder)
213 printed += fprintf(output, "%sreorder", printed ? "," : "");
214 if (sem & semantic_atomic)
215 printed += fprintf(output, "%satomic", printed ? "," : "");
216 if (sem & semantic_rmw)
217 printed += fprintf(output, "%srmw", printed ? "," : "");
218 }
219
220 static void
print_scope(sync_scope scope,FILE * output,const char * prefix="scope")221 print_scope(sync_scope scope, FILE* output, const char* prefix = "scope")
222 {
223 fprintf(output, " %s:", prefix);
224 switch (scope) {
225 case scope_invocation: fprintf(output, "invocation"); break;
226 case scope_subgroup: fprintf(output, "subgroup"); break;
227 case scope_workgroup: fprintf(output, "workgroup"); break;
228 case scope_queuefamily: fprintf(output, "queuefamily"); break;
229 case scope_device: fprintf(output, "device"); break;
230 }
231 }
232
233 static void
print_sync(memory_sync_info sync,FILE * output)234 print_sync(memory_sync_info sync, FILE* output)
235 {
236 if (sync.storage)
237 print_storage(sync.storage, output);
238 if (sync.semantics)
239 print_semantics(sync.semantics, output);
240 if (sync.scope != scope_invocation)
241 print_scope(sync.scope, output);
242 }
243
244 template <typename T>
245 static void
print_cache_flags(enum amd_gfx_level gfx_level,const T & instr,FILE * output)246 print_cache_flags(enum amd_gfx_level gfx_level, const T& instr, FILE* output)
247 {
248 if (gfx_level >= GFX12) {
249 if (instr_info.is_atomic[(unsigned)instr.opcode]) {
250 if (instr.cache.gfx12.temporal_hint & gfx12_atomic_return)
251 fprintf(output, " atomic_return");
252 if (instr.cache.gfx12.temporal_hint & gfx12_atomic_non_temporal)
253 fprintf(output, " non_temporal");
254 if (instr.cache.gfx12.temporal_hint & gfx12_atomic_accum_deferred_scope)
255 fprintf(output, " accum_deferred_scope");
256 } else if (instr.definitions.empty()) {
257 switch (instr.cache.gfx12.temporal_hint) {
258 case gfx12_load_regular_temporal: break;
259 case gfx12_load_non_temporal: fprintf(output, " non_temporal"); break;
260 case gfx12_load_high_temporal: fprintf(output, " high_temporal"); break;
261 case gfx12_load_last_use_discard: fprintf(output, " last_use_discard"); break;
262 case gfx12_load_near_non_temporal_far_regular_temporal:
263 fprintf(output, " near_non_temporal_far_regular_temporal");
264 break;
265 case gfx12_load_near_regular_temporal_far_non_temporal:
266 fprintf(output, " near_regular_temporal_far_non_temporal");
267 break;
268 case gfx12_load_near_non_temporal_far_high_temporal:
269 fprintf(output, " near_non_temporal_far_high_temporal");
270 break;
271 case gfx12_load_reserved: fprintf(output, " reserved"); break;
272 default: fprintf(output, "tmp:%u", (unsigned)instr.cache.gfx12.temporal_hint);
273 }
274 } else {
275 switch (instr.cache.gfx12.temporal_hint) {
276 case gfx12_store_regular_temporal: break;
277 case gfx12_store_non_temporal: fprintf(output, " non_temporal"); break;
278 case gfx12_store_high_temporal: fprintf(output, " high_temporal"); break;
279 case gfx12_store_high_temporal_stay_dirty:
280 fprintf(output, " high_temporal_stay_dirty");
281 break;
282 case gfx12_store_near_non_temporal_far_regular_temporal:
283 fprintf(output, " near_non_temporal_far_regular_temporal");
284 break;
285 case gfx12_store_near_regular_temporal_far_non_temporal:
286 fprintf(output, " near_regular_temporal_far_non_temporal");
287 break;
288 case gfx12_store_near_non_temporal_far_high_temporal:
289 fprintf(output, " near_non_temporal_far_high_temporal");
290 break;
291 case gfx12_store_near_non_temporal_far_writeback:
292 fprintf(output, " near_non_temporal_far_writeback");
293 break;
294 default: fprintf(output, "tmp:%u", (unsigned)instr.cache.gfx12.temporal_hint);
295 }
296 }
297 switch (instr.cache.gfx12.scope) {
298 case gfx12_scope_cu: break;
299 case gfx12_scope_se: fprintf(output, " se"); break;
300 case gfx12_scope_device: fprintf(output, " device"); break;
301 case gfx12_scope_memory: fprintf(output, " memory"); break;
302 }
303 if (instr.cache.gfx12.swizzled)
304 fprintf(output, " swizzled");
305 } else {
306 if (instr.cache.value & ac_glc)
307 fprintf(output, " glc");
308 if (instr.cache.value & ac_slc)
309 fprintf(output, " slc");
310 if (instr.cache.value & ac_dlc)
311 fprintf(output, " dlc");
312 if (instr.cache.value & ac_swizzled)
313 fprintf(output, " swizzled");
314 }
315 }
316
317 static void
print_instr_format_specific(enum amd_gfx_level gfx_level,const Instruction * instr,FILE * output)318 print_instr_format_specific(enum amd_gfx_level gfx_level, const Instruction* instr, FILE* output)
319 {
320 switch (instr->format) {
321 case Format::SOPK: {
322 const SALU_instruction& sopk = instr->salu();
323 fprintf(output, " imm:%d", sopk.imm & 0x8000 ? (sopk.imm - 65536) : sopk.imm);
324 break;
325 }
326 case Format::SOPP: {
327 uint16_t imm = instr->salu().imm;
328 switch (instr->opcode) {
329 case aco_opcode::s_waitcnt:
330 case aco_opcode::s_wait_loadcnt_dscnt:
331 case aco_opcode::s_wait_storecnt_dscnt: {
332 wait_imm unpacked;
333 unpacked.unpack(gfx_level, instr);
334 const char* names[wait_type_num];
335 names[wait_type_exp] = "expcnt";
336 names[wait_type_vm] = gfx_level >= GFX12 ? "loadcnt" : "vmcnt";
337 names[wait_type_lgkm] = gfx_level >= GFX12 ? "dscnt" : "lgkmcnt";
338 names[wait_type_vs] = gfx_level >= GFX12 ? "storecnt" : "vscnt";
339 names[wait_type_sample] = "samplecnt";
340 names[wait_type_bvh] = "bvhcnt";
341 names[wait_type_km] = "kmcnt";
342 for (unsigned i = 0; i < wait_type_num; i++) {
343 if (unpacked[i] != wait_imm::unset_counter)
344 fprintf(output, " %s(%d)", names[i], unpacked[i]);
345 }
346 break;
347 }
348 case aco_opcode::s_wait_expcnt:
349 case aco_opcode::s_wait_dscnt:
350 case aco_opcode::s_wait_loadcnt:
351 case aco_opcode::s_wait_storecnt:
352 case aco_opcode::s_wait_samplecnt:
353 case aco_opcode::s_wait_bvhcnt:
354 case aco_opcode::s_wait_kmcnt:
355 case aco_opcode::s_setprio: {
356 fprintf(output, " imm:%u", imm);
357 break;
358 }
359 case aco_opcode::s_waitcnt_depctr: {
360 unsigned va_vdst = (imm >> 12) & 0xf;
361 unsigned va_sdst = (imm >> 9) & 0x7;
362 unsigned va_ssrc = (imm >> 8) & 0x1;
363 unsigned hold_cnt = (imm >> 7) & 0x1;
364 unsigned vm_vsrc = (imm >> 2) & 0x7;
365 unsigned va_vcc = (imm >> 1) & 0x1;
366 unsigned sa_sdst = imm & 0x1;
367 if (va_vdst != 0xf)
368 fprintf(output, " va_vdst(%d)", va_vdst);
369 if (va_sdst != 0x7)
370 fprintf(output, " va_sdst(%d)", va_sdst);
371 if (va_ssrc != 0x1)
372 fprintf(output, " va_ssrc(%d)", va_ssrc);
373 if (hold_cnt != 0x1)
374 fprintf(output, " holt_cnt(%d)", hold_cnt);
375 if (vm_vsrc != 0x7)
376 fprintf(output, " vm_vsrc(%d)", vm_vsrc);
377 if (va_vcc != 0x1)
378 fprintf(output, " va_vcc(%d)", va_vcc);
379 if (sa_sdst != 0x1)
380 fprintf(output, " sa_sdst(%d)", sa_sdst);
381 break;
382 }
383 case aco_opcode::s_delay_alu: {
384 unsigned delay[2] = {imm & 0xfu, (imm >> 7) & 0xfu};
385 unsigned skip = (imm >> 4) & 0x7;
386 for (unsigned i = 0; i < 2; i++) {
387 if (i == 1 && skip) {
388 if (skip == 1)
389 fprintf(output, " next");
390 else
391 fprintf(output, " skip_%u", skip - 1);
392 }
393
394 alu_delay_wait wait = (alu_delay_wait)delay[i];
395 if (wait >= alu_delay_wait::VALU_DEP_1 && wait <= alu_delay_wait::VALU_DEP_4)
396 fprintf(output, " valu_dep_%u", delay[i]);
397 else if (wait >= alu_delay_wait::TRANS32_DEP_1 && wait <= alu_delay_wait::TRANS32_DEP_3)
398 fprintf(output, " trans32_dep_%u",
399 delay[i] - (unsigned)alu_delay_wait::TRANS32_DEP_1 + 1);
400 else if (wait == alu_delay_wait::FMA_ACCUM_CYCLE_1)
401 fprintf(output, " fma_accum_cycle_1");
402 else if (wait >= alu_delay_wait::SALU_CYCLE_1 && wait <= alu_delay_wait::SALU_CYCLE_3)
403 fprintf(output, " salu_cycle_%u",
404 delay[i] - (unsigned)alu_delay_wait::SALU_CYCLE_1 + 1);
405 }
406 break;
407 }
408 case aco_opcode::s_endpgm:
409 case aco_opcode::s_endpgm_saved:
410 case aco_opcode::s_endpgm_ordered_ps_done:
411 case aco_opcode::s_wakeup:
412 case aco_opcode::s_barrier:
413 case aco_opcode::s_icache_inv:
414 case aco_opcode::s_ttracedata:
415 case aco_opcode::s_set_gpr_idx_off: {
416 break;
417 }
418 case aco_opcode::s_sendmsg: {
419 unsigned id = imm & sendmsg_id_mask;
420 static_assert(sendmsg_gs == sendmsg_hs_tessfactor);
421 static_assert(sendmsg_gs_done == sendmsg_dealloc_vgprs);
422 switch (id) {
423 case sendmsg_none: fprintf(output, " sendmsg(MSG_NONE)"); break;
424 case sendmsg_gs:
425 if (gfx_level >= GFX11)
426 fprintf(output, " sendmsg(hs_tessfactor)");
427 else
428 fprintf(output, " sendmsg(gs%s%s, %u)", imm & 0x10 ? ", cut" : "",
429 imm & 0x20 ? ", emit" : "", imm >> 8);
430 break;
431 case sendmsg_gs_done:
432 if (gfx_level >= GFX11)
433 fprintf(output, " sendmsg(dealloc_vgprs)");
434 else
435 fprintf(output, " sendmsg(gs_done%s%s, %u)", imm & 0x10 ? ", cut" : "",
436 imm & 0x20 ? ", emit" : "", imm >> 8);
437 break;
438 case sendmsg_save_wave: fprintf(output, " sendmsg(save_wave)"); break;
439 case sendmsg_stall_wave_gen: fprintf(output, " sendmsg(stall_wave_gen)"); break;
440 case sendmsg_halt_waves: fprintf(output, " sendmsg(halt_waves)"); break;
441 case sendmsg_ordered_ps_done: fprintf(output, " sendmsg(ordered_ps_done)"); break;
442 case sendmsg_early_prim_dealloc: fprintf(output, " sendmsg(early_prim_dealloc)"); break;
443 case sendmsg_gs_alloc_req: fprintf(output, " sendmsg(gs_alloc_req)"); break;
444 case sendmsg_get_doorbell: fprintf(output, " sendmsg(get_doorbell)"); break;
445 case sendmsg_get_ddid: fprintf(output, " sendmsg(get_ddid)"); break;
446 default: fprintf(output, " imm:%u", imm);
447 }
448 break;
449 }
450 case aco_opcode::s_wait_event: {
451 if (is_wait_export_ready(gfx_level, instr))
452 fprintf(output, " wait_export_ready");
453 break;
454 }
455 default: {
456 if (instr_info.classes[(int)instr->opcode] == instr_class::branch)
457 fprintf(output, " block:BB%d", imm);
458 else if (imm)
459 fprintf(output, " imm:%u", imm);
460 break;
461 }
462 }
463 break;
464 }
465 case Format::SOP1: {
466 if (instr->opcode == aco_opcode::s_sendmsg_rtn_b32 ||
467 instr->opcode == aco_opcode::s_sendmsg_rtn_b64) {
468 unsigned id = instr->operands[0].constantValue();
469 switch (id) {
470 case sendmsg_rtn_get_doorbell: fprintf(output, " sendmsg(rtn_get_doorbell)"); break;
471 case sendmsg_rtn_get_ddid: fprintf(output, " sendmsg(rtn_get_ddid)"); break;
472 case sendmsg_rtn_get_tma: fprintf(output, " sendmsg(rtn_get_tma)"); break;
473 case sendmsg_rtn_get_realtime: fprintf(output, " sendmsg(rtn_get_realtime)"); break;
474 case sendmsg_rtn_save_wave: fprintf(output, " sendmsg(rtn_save_wave)"); break;
475 case sendmsg_rtn_get_tba: fprintf(output, " sendmsg(rtn_get_tba)"); break;
476 default: break;
477 }
478 break;
479 }
480 break;
481 }
482 case Format::SMEM: {
483 const SMEM_instruction& smem = instr->smem();
484 print_cache_flags(gfx_level, smem, output);
485 print_sync(smem.sync, output);
486 break;
487 }
488 case Format::VINTERP_INREG: {
489 const VINTERP_inreg_instruction& vinterp = instr->vinterp_inreg();
490 if (vinterp.wait_exp != 7)
491 fprintf(output, " wait_exp:%u", vinterp.wait_exp);
492 break;
493 }
494 case Format::VINTRP: {
495 const VINTRP_instruction& vintrp = instr->vintrp();
496 fprintf(output, " attr%d.%c", vintrp.attribute, "xyzw"[vintrp.component]);
497 if (vintrp.high_16bits)
498 fprintf(output, " high");
499 break;
500 }
501 case Format::DS: {
502 const DS_instruction& ds = instr->ds();
503 if (ds.offset0)
504 fprintf(output, " offset0:%u", ds.offset0);
505 if (ds.offset1)
506 fprintf(output, " offset1:%u", ds.offset1);
507 if (ds.gds)
508 fprintf(output, " gds");
509 print_sync(ds.sync, output);
510 break;
511 }
512 case Format::LDSDIR: {
513 const LDSDIR_instruction& ldsdir = instr->ldsdir();
514 if (instr->opcode == aco_opcode::lds_param_load)
515 fprintf(output, " attr%u.%c", ldsdir.attr, "xyzw"[ldsdir.attr_chan]);
516 if (ldsdir.wait_vdst != 15)
517 fprintf(output, " wait_vdst:%u", ldsdir.wait_vdst);
518 if (ldsdir.wait_vsrc != 1)
519 fprintf(output, " wait_vsrc:%u", ldsdir.wait_vsrc);
520 print_sync(ldsdir.sync, output);
521 break;
522 }
523 case Format::MUBUF: {
524 const MUBUF_instruction& mubuf = instr->mubuf();
525 if (mubuf.offset)
526 fprintf(output, " offset:%u", mubuf.offset);
527 if (mubuf.offen)
528 fprintf(output, " offen");
529 if (mubuf.idxen)
530 fprintf(output, " idxen");
531 if (mubuf.addr64)
532 fprintf(output, " addr64");
533 print_cache_flags(gfx_level, mubuf, output);
534 if (mubuf.tfe)
535 fprintf(output, " tfe");
536 if (mubuf.lds)
537 fprintf(output, " lds");
538 if (mubuf.disable_wqm)
539 fprintf(output, " disable_wqm");
540 print_sync(mubuf.sync, output);
541 break;
542 }
543 case Format::MIMG: {
544 const MIMG_instruction& mimg = instr->mimg();
545 unsigned identity_dmask = 0xf;
546 if (!instr->definitions.empty()) {
547 unsigned num_channels = instr->definitions[0].bytes() / (mimg.d16 ? 2 : 4);
548 identity_dmask = (1 << num_channels) - 1;
549 }
550 if ((mimg.dmask & identity_dmask) != identity_dmask)
551 fprintf(output, " dmask:%s%s%s%s", mimg.dmask & 0x1 ? "x" : "",
552 mimg.dmask & 0x2 ? "y" : "", mimg.dmask & 0x4 ? "z" : "",
553 mimg.dmask & 0x8 ? "w" : "");
554 switch (mimg.dim) {
555 case ac_image_1d: fprintf(output, " 1d"); break;
556 case ac_image_2d: fprintf(output, " 2d"); break;
557 case ac_image_3d: fprintf(output, " 3d"); break;
558 case ac_image_cube: fprintf(output, " cube"); break;
559 case ac_image_1darray: fprintf(output, " 1darray"); break;
560 case ac_image_2darray: fprintf(output, " 2darray"); break;
561 case ac_image_2dmsaa: fprintf(output, " 2dmsaa"); break;
562 case ac_image_2darraymsaa: fprintf(output, " 2darraymsaa"); break;
563 }
564 if (mimg.unrm)
565 fprintf(output, " unrm");
566 print_cache_flags(gfx_level, mimg, output);
567 if (mimg.tfe)
568 fprintf(output, " tfe");
569 if (mimg.da)
570 fprintf(output, " da");
571 if (mimg.lwe)
572 fprintf(output, " lwe");
573 if (mimg.r128)
574 fprintf(output, " r128");
575 if (mimg.a16)
576 fprintf(output, " a16");
577 if (mimg.d16)
578 fprintf(output, " d16");
579 if (mimg.disable_wqm)
580 fprintf(output, " disable_wqm");
581 print_sync(mimg.sync, output);
582 break;
583 }
584 case Format::EXP: {
585 const Export_instruction& exp = instr->exp();
586 unsigned identity_mask = exp.compressed ? 0x5 : 0xf;
587 if ((exp.enabled_mask & identity_mask) != identity_mask)
588 fprintf(output, " en:%c%c%c%c", exp.enabled_mask & 0x1 ? 'r' : '*',
589 exp.enabled_mask & 0x2 ? 'g' : '*', exp.enabled_mask & 0x4 ? 'b' : '*',
590 exp.enabled_mask & 0x8 ? 'a' : '*');
591 if (exp.compressed)
592 fprintf(output, " compr");
593 if (exp.done)
594 fprintf(output, " done");
595 if (exp.valid_mask)
596 fprintf(output, " vm");
597
598 if (exp.dest <= V_008DFC_SQ_EXP_MRT + 7)
599 fprintf(output, " mrt%d", exp.dest - V_008DFC_SQ_EXP_MRT);
600 else if (exp.dest == V_008DFC_SQ_EXP_MRTZ)
601 fprintf(output, " mrtz");
602 else if (exp.dest == V_008DFC_SQ_EXP_NULL)
603 fprintf(output, " null");
604 else if (exp.dest >= V_008DFC_SQ_EXP_POS && exp.dest <= V_008DFC_SQ_EXP_POS + 3)
605 fprintf(output, " pos%d", exp.dest - V_008DFC_SQ_EXP_POS);
606 else if (exp.dest >= V_008DFC_SQ_EXP_PARAM && exp.dest <= V_008DFC_SQ_EXP_PARAM + 31)
607 fprintf(output, " param%d", exp.dest - V_008DFC_SQ_EXP_PARAM);
608 break;
609 }
610 case Format::PSEUDO_BRANCH: {
611 const Pseudo_branch_instruction& branch = instr->branch();
612 /* Note: BB0 cannot be a branch target */
613 if (branch.target[0] != 0)
614 fprintf(output, " BB%d", branch.target[0]);
615 if (branch.target[1] != 0)
616 fprintf(output, ", BB%d", branch.target[1]);
617 if (branch.rarely_taken)
618 fprintf(output, " rarely_taken");
619 if (branch.never_taken)
620 fprintf(output, " never_taken");
621 break;
622 }
623 case Format::PSEUDO_REDUCTION: {
624 const Pseudo_reduction_instruction& reduce = instr->reduction();
625 fprintf(output, " op:%s", reduce_ops[reduce.reduce_op]);
626 if (reduce.cluster_size)
627 fprintf(output, " cluster_size:%u", reduce.cluster_size);
628 break;
629 }
630 case Format::PSEUDO_BARRIER: {
631 const Pseudo_barrier_instruction& barrier = instr->barrier();
632 print_sync(barrier.sync, output);
633 print_scope(barrier.exec_scope, output, "exec_scope");
634 break;
635 }
636 case Format::FLAT:
637 case Format::GLOBAL:
638 case Format::SCRATCH: {
639 const FLAT_instruction& flat = instr->flatlike();
640 if (flat.offset)
641 fprintf(output, " offset:%d", flat.offset);
642 print_cache_flags(gfx_level, flat, output);
643 if (flat.lds)
644 fprintf(output, " lds");
645 if (flat.nv)
646 fprintf(output, " nv");
647 if (flat.disable_wqm)
648 fprintf(output, " disable_wqm");
649 print_sync(flat.sync, output);
650 break;
651 }
652 case Format::MTBUF: {
653 const MTBUF_instruction& mtbuf = instr->mtbuf();
654 fprintf(output, " dfmt:");
655 switch (mtbuf.dfmt) {
656 case V_008F0C_BUF_DATA_FORMAT_8: fprintf(output, "8"); break;
657 case V_008F0C_BUF_DATA_FORMAT_16: fprintf(output, "16"); break;
658 case V_008F0C_BUF_DATA_FORMAT_8_8: fprintf(output, "8_8"); break;
659 case V_008F0C_BUF_DATA_FORMAT_32: fprintf(output, "32"); break;
660 case V_008F0C_BUF_DATA_FORMAT_16_16: fprintf(output, "16_16"); break;
661 case V_008F0C_BUF_DATA_FORMAT_10_11_11: fprintf(output, "10_11_11"); break;
662 case V_008F0C_BUF_DATA_FORMAT_11_11_10: fprintf(output, "11_11_10"); break;
663 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2: fprintf(output, "10_10_10_2"); break;
664 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10: fprintf(output, "2_10_10_10"); break;
665 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8: fprintf(output, "8_8_8_8"); break;
666 case V_008F0C_BUF_DATA_FORMAT_32_32: fprintf(output, "32_32"); break;
667 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16: fprintf(output, "16_16_16_16"); break;
668 case V_008F0C_BUF_DATA_FORMAT_32_32_32: fprintf(output, "32_32_32"); break;
669 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32: fprintf(output, "32_32_32_32"); break;
670 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15: fprintf(output, "reserved15"); break;
671 }
672 fprintf(output, " nfmt:");
673 switch (mtbuf.nfmt) {
674 case V_008F0C_BUF_NUM_FORMAT_UNORM: fprintf(output, "unorm"); break;
675 case V_008F0C_BUF_NUM_FORMAT_SNORM: fprintf(output, "snorm"); break;
676 case V_008F0C_BUF_NUM_FORMAT_USCALED: fprintf(output, "uscaled"); break;
677 case V_008F0C_BUF_NUM_FORMAT_SSCALED: fprintf(output, "sscaled"); break;
678 case V_008F0C_BUF_NUM_FORMAT_UINT: fprintf(output, "uint"); break;
679 case V_008F0C_BUF_NUM_FORMAT_SINT: fprintf(output, "sint"); break;
680 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL: fprintf(output, "snorm"); break;
681 case V_008F0C_BUF_NUM_FORMAT_FLOAT: fprintf(output, "float"); break;
682 }
683 if (mtbuf.offset)
684 fprintf(output, " offset:%u", mtbuf.offset);
685 if (mtbuf.offen)
686 fprintf(output, " offen");
687 if (mtbuf.idxen)
688 fprintf(output, " idxen");
689 print_cache_flags(gfx_level, mtbuf, output);
690 if (mtbuf.tfe)
691 fprintf(output, " tfe");
692 if (mtbuf.disable_wqm)
693 fprintf(output, " disable_wqm");
694 print_sync(mtbuf.sync, output);
695 break;
696 }
697 default: {
698 break;
699 }
700 }
701 if (instr->isVALU()) {
702 const VALU_instruction& valu = instr->valu();
703 switch (valu.omod) {
704 case 1: fprintf(output, " *2"); break;
705 case 2: fprintf(output, " *4"); break;
706 case 3: fprintf(output, " *0.5"); break;
707 }
708 if (valu.clamp)
709 fprintf(output, " clamp");
710 if (valu.opsel & (1 << 3))
711 fprintf(output, " opsel_hi");
712 }
713
714 bool bound_ctrl = false, fetch_inactive = false;
715
716 if (instr->opcode == aco_opcode::v_permlane16_b32 ||
717 instr->opcode == aco_opcode::v_permlanex16_b32) {
718 fetch_inactive = instr->valu().opsel[0];
719 bound_ctrl = instr->valu().opsel[1];
720 } else if (instr->isDPP16()) {
721 const DPP16_instruction& dpp = instr->dpp16();
722 if (dpp.dpp_ctrl <= 0xff) {
723 fprintf(output, " quad_perm:[%d,%d,%d,%d]", dpp.dpp_ctrl & 0x3, (dpp.dpp_ctrl >> 2) & 0x3,
724 (dpp.dpp_ctrl >> 4) & 0x3, (dpp.dpp_ctrl >> 6) & 0x3);
725 } else if (dpp.dpp_ctrl >= 0x101 && dpp.dpp_ctrl <= 0x10f) {
726 fprintf(output, " row_shl:%d", dpp.dpp_ctrl & 0xf);
727 } else if (dpp.dpp_ctrl >= 0x111 && dpp.dpp_ctrl <= 0x11f) {
728 fprintf(output, " row_shr:%d", dpp.dpp_ctrl & 0xf);
729 } else if (dpp.dpp_ctrl >= 0x121 && dpp.dpp_ctrl <= 0x12f) {
730 fprintf(output, " row_ror:%d", dpp.dpp_ctrl & 0xf);
731 } else if (dpp.dpp_ctrl == dpp_wf_sl1) {
732 fprintf(output, " wave_shl:1");
733 } else if (dpp.dpp_ctrl == dpp_wf_rl1) {
734 fprintf(output, " wave_rol:1");
735 } else if (dpp.dpp_ctrl == dpp_wf_sr1) {
736 fprintf(output, " wave_shr:1");
737 } else if (dpp.dpp_ctrl == dpp_wf_rr1) {
738 fprintf(output, " wave_ror:1");
739 } else if (dpp.dpp_ctrl == dpp_row_mirror) {
740 fprintf(output, " row_mirror");
741 } else if (dpp.dpp_ctrl == dpp_row_half_mirror) {
742 fprintf(output, " row_half_mirror");
743 } else if (dpp.dpp_ctrl == dpp_row_bcast15) {
744 fprintf(output, " row_bcast:15");
745 } else if (dpp.dpp_ctrl == dpp_row_bcast31) {
746 fprintf(output, " row_bcast:31");
747 } else if (dpp.dpp_ctrl >= dpp_row_share(0) && dpp.dpp_ctrl <= dpp_row_share(15)) {
748 fprintf(output, " row_share:%d", dpp.dpp_ctrl & 0xf);
749 } else if (dpp.dpp_ctrl >= dpp_row_xmask(0) && dpp.dpp_ctrl <= dpp_row_xmask(15)) {
750 fprintf(output, " row_xmask:%d", dpp.dpp_ctrl & 0xf);
751 } else {
752 fprintf(output, " dpp_ctrl:0x%.3x", dpp.dpp_ctrl);
753 }
754 if (dpp.row_mask != 0xf)
755 fprintf(output, " row_mask:0x%.1x", dpp.row_mask);
756 if (dpp.bank_mask != 0xf)
757 fprintf(output, " bank_mask:0x%.1x", dpp.bank_mask);
758 bound_ctrl = dpp.bound_ctrl;
759 fetch_inactive = dpp.fetch_inactive;
760 } else if (instr->isDPP8()) {
761 const DPP8_instruction& dpp = instr->dpp8();
762 fprintf(output, " dpp8:[");
763 for (unsigned i = 0; i < 8; i++)
764 fprintf(output, "%s%u", i ? "," : "", (dpp.lane_sel >> (i * 3)) & 0x7);
765 fprintf(output, "]");
766 fetch_inactive = dpp.fetch_inactive;
767 } else if (instr->isSDWA()) {
768 const SDWA_instruction& sdwa = instr->sdwa();
769 if (!instr->isVOPC()) {
770 char sext = sdwa.dst_sel.sign_extend() ? 's' : 'u';
771 unsigned offset = sdwa.dst_sel.offset();
772 if (instr->definitions[0].isFixed())
773 offset += instr->definitions[0].physReg().byte();
774 switch (sdwa.dst_sel.size()) {
775 case 1: fprintf(output, " dst_sel:%cbyte%u", sext, offset); break;
776 case 2: fprintf(output, " dst_sel:%cword%u", sext, offset >> 1); break;
777 case 4: fprintf(output, " dst_sel:dword"); break;
778 default: break;
779 }
780 if (instr->definitions[0].bytes() < 4)
781 fprintf(output, " dst_preserve");
782 }
783 for (unsigned i = 0; i < std::min<unsigned>(2, instr->operands.size()); i++) {
784 char sext = sdwa.sel[i].sign_extend() ? 's' : 'u';
785 unsigned offset = sdwa.sel[i].offset();
786 if (instr->operands[i].isFixed())
787 offset += instr->operands[i].physReg().byte();
788 switch (sdwa.sel[i].size()) {
789 case 1: fprintf(output, " src%d_sel:%cbyte%u", i, sext, offset); break;
790 case 2: fprintf(output, " src%d_sel:%cword%u", i, sext, offset >> 1); break;
791 case 4: fprintf(output, " src%d_sel:dword", i); break;
792 default: break;
793 }
794 }
795 }
796
797 if (bound_ctrl)
798 fprintf(output, " bound_ctrl:1");
799 if (fetch_inactive)
800 fprintf(output, " fi");
801 }
802
803 void
print_vopd_instr(enum amd_gfx_level gfx_level,const Instruction * instr,FILE * output,unsigned flags)804 print_vopd_instr(enum amd_gfx_level gfx_level, const Instruction* instr, FILE* output,
805 unsigned flags)
806 {
807 unsigned opy_start = get_vopd_opy_start(instr);
808
809 if (!instr->definitions.empty()) {
810 print_definition(&instr->definitions[0], output, flags);
811 fprintf(output, " = ");
812 }
813 fprintf(output, "%s", instr_info.name[(int)instr->opcode]);
814 for (unsigned i = 0; i < MIN2(instr->operands.size(), opy_start); ++i) {
815 fprintf(output, i ? ", " : " ");
816 aco_print_operand(&instr->operands[i], output, flags);
817 }
818
819 fprintf(output, " ::");
820
821 if (instr->definitions.size() > 1) {
822 print_definition(&instr->definitions[1], output, flags);
823 fprintf(output, " = ");
824 }
825 fprintf(output, "%s", instr_info.name[(int)instr->vopd().opy]);
826 for (unsigned i = opy_start; i < instr->operands.size(); ++i) {
827 fprintf(output, i > opy_start ? ", " : " ");
828 aco_print_operand(&instr->operands[i], output, flags);
829 }
830 }
831
832 static void
print_block_kind(uint16_t kind,FILE * output)833 print_block_kind(uint16_t kind, FILE* output)
834 {
835 if (kind & block_kind_uniform)
836 fprintf(output, "uniform, ");
837 if (kind & block_kind_top_level)
838 fprintf(output, "top-level, ");
839 if (kind & block_kind_loop_preheader)
840 fprintf(output, "loop-preheader, ");
841 if (kind & block_kind_loop_header)
842 fprintf(output, "loop-header, ");
843 if (kind & block_kind_loop_exit)
844 fprintf(output, "loop-exit, ");
845 if (kind & block_kind_continue)
846 fprintf(output, "continue, ");
847 if (kind & block_kind_break)
848 fprintf(output, "break, ");
849 if (kind & block_kind_continue_or_break)
850 fprintf(output, "continue_or_break, ");
851 if (kind & block_kind_branch)
852 fprintf(output, "branch, ");
853 if (kind & block_kind_merge)
854 fprintf(output, "merge, ");
855 if (kind & block_kind_invert)
856 fprintf(output, "invert, ");
857 if (kind & block_kind_uses_discard)
858 fprintf(output, "discard, ");
859 if (kind & block_kind_resume)
860 fprintf(output, "resume, ");
861 if (kind & block_kind_export_end)
862 fprintf(output, "export_end, ");
863 if (kind & block_kind_end_with_regs)
864 fprintf(output, "end_with_regs, ");
865 }
866
867 static void
print_stage(Stage stage,FILE * output)868 print_stage(Stage stage, FILE* output)
869 {
870 fprintf(output, "ACO shader stage: SW (");
871
872 u_foreach_bit (s, (uint32_t)stage.sw) {
873 switch ((SWStage)(1 << s)) {
874 case SWStage::VS: fprintf(output, "VS"); break;
875 case SWStage::GS: fprintf(output, "GS"); break;
876 case SWStage::TCS: fprintf(output, "TCS"); break;
877 case SWStage::TES: fprintf(output, "TES"); break;
878 case SWStage::FS: fprintf(output, "FS"); break;
879 case SWStage::CS: fprintf(output, "CS"); break;
880 case SWStage::TS: fprintf(output, "TS"); break;
881 case SWStage::MS: fprintf(output, "MS"); break;
882 case SWStage::RT: fprintf(output, "RT"); break;
883 default: unreachable("invalid SW stage");
884 }
885 if (stage.num_sw_stages() > 1)
886 fprintf(output, "+");
887 }
888
889 fprintf(output, "), HW (");
890
891 switch (stage.hw) {
892 case AC_HW_LOCAL_SHADER: fprintf(output, "LOCAL_SHADER"); break;
893 case AC_HW_HULL_SHADER: fprintf(output, "HULL_SHADER"); break;
894 case AC_HW_EXPORT_SHADER: fprintf(output, "EXPORT_SHADER"); break;
895 case AC_HW_LEGACY_GEOMETRY_SHADER: fprintf(output, "LEGACY_GEOMETRY_SHADER"); break;
896 case AC_HW_VERTEX_SHADER: fprintf(output, "VERTEX_SHADER"); break;
897 case AC_HW_NEXT_GEN_GEOMETRY_SHADER: fprintf(output, "NEXT_GEN_GEOMETRY_SHADER"); break;
898 case AC_HW_PIXEL_SHADER: fprintf(output, "PIXEL_SHADER"); break;
899 case AC_HW_COMPUTE_SHADER: fprintf(output, "COMPUTE_SHADER"); break;
900 default: unreachable("invalid HW stage");
901 }
902
903 fprintf(output, ")\n");
904 }
905
906 void
aco_print_block(enum amd_gfx_level gfx_level,const Block * block,FILE * output,unsigned flags,const Program * program)907 aco_print_block(enum amd_gfx_level gfx_level, const Block* block, FILE* output, unsigned flags,
908 const Program* program)
909 {
910 fprintf(output, "BB%d\n", block->index);
911 fprintf(output, "/* logical preds: ");
912 for (unsigned pred : block->logical_preds)
913 fprintf(output, "BB%d, ", pred);
914 fprintf(output, "/ linear preds: ");
915 for (unsigned pred : block->linear_preds)
916 fprintf(output, "BB%d, ", pred);
917 fprintf(output, "/ kind: ");
918 print_block_kind(block->kind, output);
919 fprintf(output, "*/\n");
920
921 if (flags & print_live_vars) {
922 fprintf(output, "\tlive in:");
923 for (unsigned id : program->live.live_in[block->index])
924 fprintf(output, " %%%d", id);
925 fprintf(output, "\n");
926
927 RegisterDemand demand = block->register_demand;
928 fprintf(output, "\tdemand: %u vgpr, %u sgpr\n", demand.vgpr, demand.sgpr);
929 }
930
931 for (auto const& instr : block->instructions) {
932 fprintf(output, "\t");
933 if (flags & print_live_vars) {
934 RegisterDemand demand = instr->register_demand;
935 fprintf(output, "(%3u vgpr, %3u sgpr) ", demand.vgpr, demand.sgpr);
936 }
937 if (flags & print_perf_info)
938 fprintf(output, "(%3u clk) ", instr->pass_flags);
939
940 aco_print_instr(gfx_level, instr.get(), output, flags);
941 fprintf(output, "\n");
942 }
943 }
944
945 } /* end namespace */
946
947 void
aco_print_operand(const Operand * operand,FILE * output,unsigned flags)948 aco_print_operand(const Operand* operand, FILE* output, unsigned flags)
949 {
950 if (operand->isLiteral() || (operand->isConstant() && operand->bytes() == 1)) {
951 if (operand->bytes() == 1)
952 fprintf(output, "0x%.2x", operand->constantValue());
953 else if (operand->bytes() == 2)
954 fprintf(output, "0x%.4x", operand->constantValue());
955 else
956 fprintf(output, "0x%x", operand->constantValue());
957 } else if (operand->isConstant()) {
958 print_constant(operand->physReg().reg(), output);
959 } else if (operand->isUndefined()) {
960 print_reg_class(operand->regClass(), output);
961 fprintf(output, "undef");
962 } else {
963 if (operand->isLateKill())
964 fprintf(output, "(latekill)");
965 if (operand->is16bit())
966 fprintf(output, "(is16bit)");
967 if (operand->is24bit())
968 fprintf(output, "(is24bit)");
969 if ((flags & print_kill) && operand->isKill())
970 fprintf(output, "(kill)");
971
972 if (!(flags & print_no_ssa))
973 fprintf(output, "%%%d%s", operand->tempId(), operand->isFixed() ? ":" : "");
974
975 if (operand->isFixed())
976 print_physReg(operand->physReg(), operand->bytes(), output, flags);
977 }
978 }
979
980 void
aco_print_instr(enum amd_gfx_level gfx_level,const Instruction * instr,FILE * output,unsigned flags)981 aco_print_instr(enum amd_gfx_level gfx_level, const Instruction* instr, FILE* output,
982 unsigned flags)
983 {
984 if (instr->isVOPD()) {
985 print_vopd_instr(gfx_level, instr, output, flags);
986 return;
987 }
988
989 if (!instr->definitions.empty()) {
990 for (unsigned i = 0; i < instr->definitions.size(); ++i) {
991 print_definition(&instr->definitions[i], output, flags);
992 if (i + 1 != instr->definitions.size())
993 fprintf(output, ", ");
994 }
995 fprintf(output, " = ");
996 }
997 fprintf(output, "%s", instr_info.name[(int)instr->opcode]);
998 if (instr->operands.size()) {
999 const unsigned num_operands = instr->operands.size();
1000 bitarray8 abs = 0;
1001 bitarray8 neg = 0;
1002 bitarray8 neg_lo = 0;
1003 bitarray8 neg_hi = 0;
1004 bitarray8 opsel = 0;
1005 bitarray8 f2f32 = 0;
1006 bitarray8 opsel_lo = 0;
1007 bitarray8 opsel_hi = -1;
1008
1009 if (instr->opcode == aco_opcode::v_fma_mix_f32 ||
1010 instr->opcode == aco_opcode::v_fma_mixlo_f16 ||
1011 instr->opcode == aco_opcode::v_fma_mixhi_f16) {
1012 const VALU_instruction& vop3p = instr->valu();
1013 abs = vop3p.abs;
1014 neg = vop3p.neg;
1015 f2f32 = vop3p.opsel_hi;
1016 opsel = f2f32 & vop3p.opsel_lo;
1017 } else if (instr->isVOP3P()) {
1018 const VALU_instruction& vop3p = instr->valu();
1019 neg = vop3p.neg_lo & vop3p.neg_hi;
1020 neg_lo = vop3p.neg_lo & ~neg;
1021 neg_hi = vop3p.neg_hi & ~neg;
1022 opsel_lo = vop3p.opsel_lo;
1023 opsel_hi = vop3p.opsel_hi;
1024 } else if (instr->isVALU() && instr->opcode != aco_opcode::v_permlane16_b32 &&
1025 instr->opcode != aco_opcode::v_permlanex16_b32) {
1026 const VALU_instruction& valu = instr->valu();
1027 abs = valu.abs;
1028 neg = valu.neg;
1029 opsel = valu.opsel;
1030 }
1031 for (unsigned i = 0; i < num_operands; ++i) {
1032 if (i)
1033 fprintf(output, ", ");
1034 else
1035 fprintf(output, " ");
1036
1037 if (i < 3) {
1038 if (neg[i] && instr->operands[i].isConstant())
1039 fprintf(output, "neg(");
1040 else if (neg[i])
1041 fprintf(output, "-");
1042 if (abs[i])
1043 fprintf(output, "|");
1044 if (opsel[i])
1045 fprintf(output, "hi(");
1046 else if (f2f32[i])
1047 fprintf(output, "lo(");
1048 }
1049
1050 aco_print_operand(&instr->operands[i], output, flags);
1051
1052 if (i < 3) {
1053 if (f2f32[i] || opsel[i])
1054 fprintf(output, ")");
1055 if (abs[i])
1056 fprintf(output, "|");
1057
1058 if (opsel_lo[i] || !opsel_hi[i])
1059 fprintf(output, ".%c%c", opsel_lo[i] ? 'y' : 'x', opsel_hi[i] ? 'y' : 'x');
1060
1061 if (neg[i] && instr->operands[i].isConstant())
1062 fprintf(output, ")");
1063 if (neg_lo[i])
1064 fprintf(output, "*[-1,1]");
1065 if (neg_hi[i])
1066 fprintf(output, "*[1,-1]");
1067 }
1068 }
1069 }
1070 print_instr_format_specific(gfx_level, instr, output);
1071 }
1072
1073 void
aco_print_program(const Program * program,FILE * output,unsigned flags)1074 aco_print_program(const Program* program, FILE* output, unsigned flags)
1075 {
1076 switch (program->progress) {
1077 case CompilationProgress::after_isel: fprintf(output, "After Instruction Selection:\n"); break;
1078 case CompilationProgress::after_spilling:
1079 fprintf(output, "After Spilling:\n");
1080 flags |= print_kill;
1081 break;
1082 case CompilationProgress::after_ra: fprintf(output, "After RA:\n"); break;
1083 case CompilationProgress::after_lower_to_hw:
1084 fprintf(output, "After lowering to hw instructions:\n");
1085 break;
1086 }
1087
1088 print_stage(program->stage, output);
1089
1090 for (Block const& block : program->blocks)
1091 aco_print_block(program->gfx_level, &block, output, flags, program);
1092
1093 if (program->constant_data.size()) {
1094 fprintf(output, "\n/* constant data */\n");
1095 for (unsigned i = 0; i < program->constant_data.size(); i += 32) {
1096 fprintf(output, "[%06d] ", i);
1097 unsigned line_size = std::min<size_t>(program->constant_data.size() - i, 32);
1098 for (unsigned j = 0; j < line_size; j += 4) {
1099 unsigned size = std::min<size_t>(program->constant_data.size() - (i + j), 4);
1100 uint32_t v = 0;
1101 memcpy(&v, &program->constant_data[i + j], size);
1102 fprintf(output, " %08x", v);
1103 }
1104 fprintf(output, "\n");
1105 }
1106 }
1107
1108 fprintf(output, "\n");
1109 }
1110
1111 } // namespace aco
1112