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 = []()
__anonb7c797ff0202() 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 depctr_wait wait = parse_depctr_wait(instr);
361 if (wait.va_vdst != 0xf)
362 fprintf(output, " va_vdst(%d)", wait.va_vdst);
363 if (wait.va_sdst != 0x7)
364 fprintf(output, " va_sdst(%d)", wait.va_sdst);
365 if (wait.va_ssrc != 0x1)
366 fprintf(output, " va_ssrc(%d)", wait.va_ssrc);
367 if (wait.hold_cnt != 0x1)
368 fprintf(output, " holt_cnt(%d)", wait.hold_cnt);
369 if (wait.vm_vsrc != 0x7)
370 fprintf(output, " vm_vsrc(%d)", wait.vm_vsrc);
371 if (wait.va_vcc != 0x1)
372 fprintf(output, " va_vcc(%d)", wait.va_vcc);
373 if (wait.sa_sdst != 0x1)
374 fprintf(output, " sa_sdst(%d)", wait.sa_sdst);
375 break;
376 }
377 case aco_opcode::s_delay_alu: {
378 unsigned delay[2] = {imm & 0xfu, (imm >> 7) & 0xfu};
379 unsigned skip = (imm >> 4) & 0x7;
380 for (unsigned i = 0; i < 2; i++) {
381 if (i == 1 && skip) {
382 if (skip == 1)
383 fprintf(output, " next");
384 else
385 fprintf(output, " skip_%u", skip - 1);
386 }
387
388 alu_delay_wait wait = (alu_delay_wait)delay[i];
389 if (wait >= alu_delay_wait::VALU_DEP_1 && wait <= alu_delay_wait::VALU_DEP_4)
390 fprintf(output, " valu_dep_%u", delay[i]);
391 else if (wait >= alu_delay_wait::TRANS32_DEP_1 && wait <= alu_delay_wait::TRANS32_DEP_3)
392 fprintf(output, " trans32_dep_%u",
393 delay[i] - (unsigned)alu_delay_wait::TRANS32_DEP_1 + 1);
394 else if (wait == alu_delay_wait::FMA_ACCUM_CYCLE_1)
395 fprintf(output, " fma_accum_cycle_1");
396 else if (wait >= alu_delay_wait::SALU_CYCLE_1 && wait <= alu_delay_wait::SALU_CYCLE_3)
397 fprintf(output, " salu_cycle_%u",
398 delay[i] - (unsigned)alu_delay_wait::SALU_CYCLE_1 + 1);
399 }
400 break;
401 }
402 case aco_opcode::s_endpgm:
403 case aco_opcode::s_endpgm_saved:
404 case aco_opcode::s_endpgm_ordered_ps_done:
405 case aco_opcode::s_wakeup:
406 case aco_opcode::s_barrier:
407 case aco_opcode::s_icache_inv:
408 case aco_opcode::s_ttracedata:
409 case aco_opcode::s_set_gpr_idx_off: {
410 break;
411 }
412 case aco_opcode::s_sendmsg: {
413 unsigned id = imm & sendmsg_id_mask;
414 static_assert(sendmsg_gs == sendmsg_hs_tessfactor);
415 static_assert(sendmsg_gs_done == sendmsg_dealloc_vgprs);
416 switch (id) {
417 case sendmsg_none: fprintf(output, " sendmsg(MSG_NONE)"); break;
418 case sendmsg_gs:
419 if (gfx_level >= GFX11)
420 fprintf(output, " sendmsg(hs_tessfactor)");
421 else
422 fprintf(output, " sendmsg(gs%s%s, %u)", imm & 0x10 ? ", cut" : "",
423 imm & 0x20 ? ", emit" : "", imm >> 8);
424 break;
425 case sendmsg_gs_done:
426 if (gfx_level >= GFX11)
427 fprintf(output, " sendmsg(dealloc_vgprs)");
428 else
429 fprintf(output, " sendmsg(gs_done%s%s, %u)", imm & 0x10 ? ", cut" : "",
430 imm & 0x20 ? ", emit" : "", imm >> 8);
431 break;
432 case sendmsg_save_wave: fprintf(output, " sendmsg(save_wave)"); break;
433 case sendmsg_stall_wave_gen: fprintf(output, " sendmsg(stall_wave_gen)"); break;
434 case sendmsg_halt_waves: fprintf(output, " sendmsg(halt_waves)"); break;
435 case sendmsg_ordered_ps_done: fprintf(output, " sendmsg(ordered_ps_done)"); break;
436 case sendmsg_early_prim_dealloc: fprintf(output, " sendmsg(early_prim_dealloc)"); break;
437 case sendmsg_gs_alloc_req: fprintf(output, " sendmsg(gs_alloc_req)"); break;
438 case sendmsg_get_doorbell: fprintf(output, " sendmsg(get_doorbell)"); break;
439 case sendmsg_get_ddid: fprintf(output, " sendmsg(get_ddid)"); break;
440 default: fprintf(output, " imm:%u", imm);
441 }
442 break;
443 }
444 case aco_opcode::s_wait_event: {
445 if (is_wait_export_ready(gfx_level, instr))
446 fprintf(output, " wait_export_ready");
447 break;
448 }
449 default: {
450 if (instr_info.classes[(int)instr->opcode] == instr_class::branch)
451 fprintf(output, " block:BB%d", imm);
452 else if (imm)
453 fprintf(output, " imm:%u", imm);
454 break;
455 }
456 }
457 break;
458 }
459 case Format::SOP1: {
460 if (instr->opcode == aco_opcode::s_sendmsg_rtn_b32 ||
461 instr->opcode == aco_opcode::s_sendmsg_rtn_b64) {
462 unsigned id = instr->operands[0].constantValue();
463 switch (id) {
464 case sendmsg_rtn_get_doorbell: fprintf(output, " sendmsg(rtn_get_doorbell)"); break;
465 case sendmsg_rtn_get_ddid: fprintf(output, " sendmsg(rtn_get_ddid)"); break;
466 case sendmsg_rtn_get_tma: fprintf(output, " sendmsg(rtn_get_tma)"); break;
467 case sendmsg_rtn_get_realtime: fprintf(output, " sendmsg(rtn_get_realtime)"); break;
468 case sendmsg_rtn_save_wave: fprintf(output, " sendmsg(rtn_save_wave)"); break;
469 case sendmsg_rtn_get_tba: fprintf(output, " sendmsg(rtn_get_tba)"); break;
470 default: break;
471 }
472 break;
473 }
474 break;
475 }
476 case Format::SMEM: {
477 const SMEM_instruction& smem = instr->smem();
478 print_cache_flags(gfx_level, smem, output);
479 print_sync(smem.sync, output);
480 break;
481 }
482 case Format::VINTERP_INREG: {
483 const VINTERP_inreg_instruction& vinterp = instr->vinterp_inreg();
484 if (vinterp.wait_exp != 7)
485 fprintf(output, " wait_exp:%u", vinterp.wait_exp);
486 break;
487 }
488 case Format::VINTRP: {
489 const VINTRP_instruction& vintrp = instr->vintrp();
490 fprintf(output, " attr%d.%c", vintrp.attribute, "xyzw"[vintrp.component]);
491 if (vintrp.high_16bits)
492 fprintf(output, " high");
493 break;
494 }
495 case Format::DS: {
496 const DS_instruction& ds = instr->ds();
497 if (ds.offset0)
498 fprintf(output, " offset0:%u", ds.offset0);
499 if (ds.offset1)
500 fprintf(output, " offset1:%u", ds.offset1);
501 if (ds.gds)
502 fprintf(output, " gds");
503 print_sync(ds.sync, output);
504 break;
505 }
506 case Format::LDSDIR: {
507 const LDSDIR_instruction& ldsdir = instr->ldsdir();
508 if (instr->opcode == aco_opcode::lds_param_load)
509 fprintf(output, " attr%u.%c", ldsdir.attr, "xyzw"[ldsdir.attr_chan]);
510 if (ldsdir.wait_vdst != 15)
511 fprintf(output, " wait_vdst:%u", ldsdir.wait_vdst);
512 if (ldsdir.wait_vsrc != 1)
513 fprintf(output, " wait_vsrc:%u", ldsdir.wait_vsrc);
514 print_sync(ldsdir.sync, output);
515 break;
516 }
517 case Format::MUBUF: {
518 const MUBUF_instruction& mubuf = instr->mubuf();
519 if (mubuf.offset)
520 fprintf(output, " offset:%u", mubuf.offset);
521 if (mubuf.offen)
522 fprintf(output, " offen");
523 if (mubuf.idxen)
524 fprintf(output, " idxen");
525 if (mubuf.addr64)
526 fprintf(output, " addr64");
527 print_cache_flags(gfx_level, mubuf, output);
528 if (mubuf.tfe)
529 fprintf(output, " tfe");
530 if (mubuf.lds)
531 fprintf(output, " lds");
532 if (mubuf.disable_wqm)
533 fprintf(output, " disable_wqm");
534 print_sync(mubuf.sync, output);
535 break;
536 }
537 case Format::MIMG: {
538 const MIMG_instruction& mimg = instr->mimg();
539 unsigned identity_dmask = 0xf;
540 if (!instr->definitions.empty()) {
541 unsigned num_channels = instr->definitions[0].bytes() / (mimg.d16 ? 2 : 4);
542 identity_dmask = (1 << num_channels) - 1;
543 }
544 if ((mimg.dmask & identity_dmask) != identity_dmask)
545 fprintf(output, " dmask:%s%s%s%s", mimg.dmask & 0x1 ? "x" : "",
546 mimg.dmask & 0x2 ? "y" : "", mimg.dmask & 0x4 ? "z" : "",
547 mimg.dmask & 0x8 ? "w" : "");
548 switch (mimg.dim) {
549 case ac_image_1d: fprintf(output, " 1d"); break;
550 case ac_image_2d: fprintf(output, " 2d"); break;
551 case ac_image_3d: fprintf(output, " 3d"); break;
552 case ac_image_cube: fprintf(output, " cube"); break;
553 case ac_image_1darray: fprintf(output, " 1darray"); break;
554 case ac_image_2darray: fprintf(output, " 2darray"); break;
555 case ac_image_2dmsaa: fprintf(output, " 2dmsaa"); break;
556 case ac_image_2darraymsaa: fprintf(output, " 2darraymsaa"); break;
557 }
558 if (mimg.unrm)
559 fprintf(output, " unrm");
560 print_cache_flags(gfx_level, mimg, output);
561 if (mimg.tfe)
562 fprintf(output, " tfe");
563 if (mimg.da)
564 fprintf(output, " da");
565 if (mimg.lwe)
566 fprintf(output, " lwe");
567 if (mimg.r128)
568 fprintf(output, " r128");
569 if (mimg.a16)
570 fprintf(output, " a16");
571 if (mimg.d16)
572 fprintf(output, " d16");
573 if (mimg.disable_wqm)
574 fprintf(output, " disable_wqm");
575 print_sync(mimg.sync, output);
576 break;
577 }
578 case Format::EXP: {
579 const Export_instruction& exp = instr->exp();
580 unsigned identity_mask = exp.compressed ? 0x5 : 0xf;
581 if ((exp.enabled_mask & identity_mask) != identity_mask)
582 fprintf(output, " en:%c%c%c%c", exp.enabled_mask & 0x1 ? 'r' : '*',
583 exp.enabled_mask & 0x2 ? 'g' : '*', exp.enabled_mask & 0x4 ? 'b' : '*',
584 exp.enabled_mask & 0x8 ? 'a' : '*');
585 if (exp.compressed)
586 fprintf(output, " compr");
587 if (exp.done)
588 fprintf(output, " done");
589 if (exp.valid_mask)
590 fprintf(output, " vm");
591
592 if (exp.dest <= V_008DFC_SQ_EXP_MRT + 7)
593 fprintf(output, " mrt%d", exp.dest - V_008DFC_SQ_EXP_MRT);
594 else if (exp.dest == V_008DFC_SQ_EXP_MRTZ)
595 fprintf(output, " mrtz");
596 else if (exp.dest == V_008DFC_SQ_EXP_NULL)
597 fprintf(output, " null");
598 else if (exp.dest >= V_008DFC_SQ_EXP_POS && exp.dest <= V_008DFC_SQ_EXP_POS + 3)
599 fprintf(output, " pos%d", exp.dest - V_008DFC_SQ_EXP_POS);
600 else if (exp.dest >= V_008DFC_SQ_EXP_PARAM && exp.dest <= V_008DFC_SQ_EXP_PARAM + 31)
601 fprintf(output, " param%d", exp.dest - V_008DFC_SQ_EXP_PARAM);
602 break;
603 }
604 case Format::PSEUDO_BRANCH: {
605 const Pseudo_branch_instruction& branch = instr->branch();
606 /* Note: BB0 cannot be a branch target */
607 if (branch.target[0] != 0)
608 fprintf(output, " BB%d", branch.target[0]);
609 if (branch.target[1] != 0)
610 fprintf(output, ", BB%d", branch.target[1]);
611 if (branch.rarely_taken)
612 fprintf(output, " rarely_taken");
613 if (branch.never_taken)
614 fprintf(output, " never_taken");
615 break;
616 }
617 case Format::PSEUDO_REDUCTION: {
618 const Pseudo_reduction_instruction& reduce = instr->reduction();
619 fprintf(output, " op:%s", reduce_ops[reduce.reduce_op]);
620 if (reduce.cluster_size)
621 fprintf(output, " cluster_size:%u", reduce.cluster_size);
622 break;
623 }
624 case Format::PSEUDO_BARRIER: {
625 const Pseudo_barrier_instruction& barrier = instr->barrier();
626 print_sync(barrier.sync, output);
627 print_scope(barrier.exec_scope, output, "exec_scope");
628 break;
629 }
630 case Format::FLAT:
631 case Format::GLOBAL:
632 case Format::SCRATCH: {
633 const FLAT_instruction& flat = instr->flatlike();
634 if (flat.offset)
635 fprintf(output, " offset:%d", flat.offset);
636 print_cache_flags(gfx_level, flat, output);
637 if (flat.lds)
638 fprintf(output, " lds");
639 if (flat.nv)
640 fprintf(output, " nv");
641 if (flat.disable_wqm)
642 fprintf(output, " disable_wqm");
643 print_sync(flat.sync, output);
644 break;
645 }
646 case Format::MTBUF: {
647 const MTBUF_instruction& mtbuf = instr->mtbuf();
648 fprintf(output, " dfmt:");
649 switch (mtbuf.dfmt) {
650 case V_008F0C_BUF_DATA_FORMAT_8: fprintf(output, "8"); break;
651 case V_008F0C_BUF_DATA_FORMAT_16: fprintf(output, "16"); break;
652 case V_008F0C_BUF_DATA_FORMAT_8_8: fprintf(output, "8_8"); break;
653 case V_008F0C_BUF_DATA_FORMAT_32: fprintf(output, "32"); break;
654 case V_008F0C_BUF_DATA_FORMAT_16_16: fprintf(output, "16_16"); break;
655 case V_008F0C_BUF_DATA_FORMAT_10_11_11: fprintf(output, "10_11_11"); break;
656 case V_008F0C_BUF_DATA_FORMAT_11_11_10: fprintf(output, "11_11_10"); break;
657 case V_008F0C_BUF_DATA_FORMAT_10_10_10_2: fprintf(output, "10_10_10_2"); break;
658 case V_008F0C_BUF_DATA_FORMAT_2_10_10_10: fprintf(output, "2_10_10_10"); break;
659 case V_008F0C_BUF_DATA_FORMAT_8_8_8_8: fprintf(output, "8_8_8_8"); break;
660 case V_008F0C_BUF_DATA_FORMAT_32_32: fprintf(output, "32_32"); break;
661 case V_008F0C_BUF_DATA_FORMAT_16_16_16_16: fprintf(output, "16_16_16_16"); break;
662 case V_008F0C_BUF_DATA_FORMAT_32_32_32: fprintf(output, "32_32_32"); break;
663 case V_008F0C_BUF_DATA_FORMAT_32_32_32_32: fprintf(output, "32_32_32_32"); break;
664 case V_008F0C_BUF_DATA_FORMAT_RESERVED_15: fprintf(output, "reserved15"); break;
665 }
666 fprintf(output, " nfmt:");
667 switch (mtbuf.nfmt) {
668 case V_008F0C_BUF_NUM_FORMAT_UNORM: fprintf(output, "unorm"); break;
669 case V_008F0C_BUF_NUM_FORMAT_SNORM: fprintf(output, "snorm"); break;
670 case V_008F0C_BUF_NUM_FORMAT_USCALED: fprintf(output, "uscaled"); break;
671 case V_008F0C_BUF_NUM_FORMAT_SSCALED: fprintf(output, "sscaled"); break;
672 case V_008F0C_BUF_NUM_FORMAT_UINT: fprintf(output, "uint"); break;
673 case V_008F0C_BUF_NUM_FORMAT_SINT: fprintf(output, "sint"); break;
674 case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL: fprintf(output, "snorm"); break;
675 case V_008F0C_BUF_NUM_FORMAT_FLOAT: fprintf(output, "float"); break;
676 }
677 if (mtbuf.offset)
678 fprintf(output, " offset:%u", mtbuf.offset);
679 if (mtbuf.offen)
680 fprintf(output, " offen");
681 if (mtbuf.idxen)
682 fprintf(output, " idxen");
683 print_cache_flags(gfx_level, mtbuf, output);
684 if (mtbuf.tfe)
685 fprintf(output, " tfe");
686 if (mtbuf.disable_wqm)
687 fprintf(output, " disable_wqm");
688 print_sync(mtbuf.sync, output);
689 break;
690 }
691 default: {
692 break;
693 }
694 }
695 if (instr->isVALU()) {
696 const VALU_instruction& valu = instr->valu();
697 switch (valu.omod) {
698 case 1: fprintf(output, " *2"); break;
699 case 2: fprintf(output, " *4"); break;
700 case 3: fprintf(output, " *0.5"); break;
701 }
702 if (valu.clamp)
703 fprintf(output, " clamp");
704 if (valu.opsel & (1 << 3))
705 fprintf(output, " opsel_hi");
706 }
707
708 bool bound_ctrl = false, fetch_inactive = false;
709
710 if (instr->opcode == aco_opcode::v_permlane16_b32 ||
711 instr->opcode == aco_opcode::v_permlanex16_b32) {
712 fetch_inactive = instr->valu().opsel[0];
713 bound_ctrl = instr->valu().opsel[1];
714 } else if (instr->isDPP16()) {
715 const DPP16_instruction& dpp = instr->dpp16();
716 if (dpp.dpp_ctrl <= 0xff) {
717 fprintf(output, " quad_perm:[%d,%d,%d,%d]", dpp.dpp_ctrl & 0x3, (dpp.dpp_ctrl >> 2) & 0x3,
718 (dpp.dpp_ctrl >> 4) & 0x3, (dpp.dpp_ctrl >> 6) & 0x3);
719 } else if (dpp.dpp_ctrl >= 0x101 && dpp.dpp_ctrl <= 0x10f) {
720 fprintf(output, " row_shl:%d", dpp.dpp_ctrl & 0xf);
721 } else if (dpp.dpp_ctrl >= 0x111 && dpp.dpp_ctrl <= 0x11f) {
722 fprintf(output, " row_shr:%d", dpp.dpp_ctrl & 0xf);
723 } else if (dpp.dpp_ctrl >= 0x121 && dpp.dpp_ctrl <= 0x12f) {
724 fprintf(output, " row_ror:%d", dpp.dpp_ctrl & 0xf);
725 } else if (dpp.dpp_ctrl == dpp_wf_sl1) {
726 fprintf(output, " wave_shl:1");
727 } else if (dpp.dpp_ctrl == dpp_wf_rl1) {
728 fprintf(output, " wave_rol:1");
729 } else if (dpp.dpp_ctrl == dpp_wf_sr1) {
730 fprintf(output, " wave_shr:1");
731 } else if (dpp.dpp_ctrl == dpp_wf_rr1) {
732 fprintf(output, " wave_ror:1");
733 } else if (dpp.dpp_ctrl == dpp_row_mirror) {
734 fprintf(output, " row_mirror");
735 } else if (dpp.dpp_ctrl == dpp_row_half_mirror) {
736 fprintf(output, " row_half_mirror");
737 } else if (dpp.dpp_ctrl == dpp_row_bcast15) {
738 fprintf(output, " row_bcast:15");
739 } else if (dpp.dpp_ctrl == dpp_row_bcast31) {
740 fprintf(output, " row_bcast:31");
741 } else if (dpp.dpp_ctrl >= dpp_row_share(0) && dpp.dpp_ctrl <= dpp_row_share(15)) {
742 fprintf(output, " row_share:%d", dpp.dpp_ctrl & 0xf);
743 } else if (dpp.dpp_ctrl >= dpp_row_xmask(0) && dpp.dpp_ctrl <= dpp_row_xmask(15)) {
744 fprintf(output, " row_xmask:%d", dpp.dpp_ctrl & 0xf);
745 } else {
746 fprintf(output, " dpp_ctrl:0x%.3x", dpp.dpp_ctrl);
747 }
748 if (dpp.row_mask != 0xf)
749 fprintf(output, " row_mask:0x%.1x", dpp.row_mask);
750 if (dpp.bank_mask != 0xf)
751 fprintf(output, " bank_mask:0x%.1x", dpp.bank_mask);
752 bound_ctrl = dpp.bound_ctrl;
753 fetch_inactive = dpp.fetch_inactive;
754 } else if (instr->isDPP8()) {
755 const DPP8_instruction& dpp = instr->dpp8();
756 fprintf(output, " dpp8:[");
757 for (unsigned i = 0; i < 8; i++)
758 fprintf(output, "%s%u", i ? "," : "", (dpp.lane_sel >> (i * 3)) & 0x7);
759 fprintf(output, "]");
760 fetch_inactive = dpp.fetch_inactive;
761 } else if (instr->isSDWA()) {
762 const SDWA_instruction& sdwa = instr->sdwa();
763 if (!instr->isVOPC()) {
764 char sext = sdwa.dst_sel.sign_extend() ? 's' : 'u';
765 unsigned offset = sdwa.dst_sel.offset();
766 if (instr->definitions[0].isFixed())
767 offset += instr->definitions[0].physReg().byte();
768 switch (sdwa.dst_sel.size()) {
769 case 1: fprintf(output, " dst_sel:%cbyte%u", sext, offset); break;
770 case 2: fprintf(output, " dst_sel:%cword%u", sext, offset >> 1); break;
771 case 4: fprintf(output, " dst_sel:dword"); break;
772 default: break;
773 }
774 if (instr->definitions[0].bytes() < 4)
775 fprintf(output, " dst_preserve");
776 }
777 for (unsigned i = 0; i < std::min<unsigned>(2, instr->operands.size()); i++) {
778 char sext = sdwa.sel[i].sign_extend() ? 's' : 'u';
779 unsigned offset = sdwa.sel[i].offset();
780 if (instr->operands[i].isFixed())
781 offset += instr->operands[i].physReg().byte();
782 switch (sdwa.sel[i].size()) {
783 case 1: fprintf(output, " src%d_sel:%cbyte%u", i, sext, offset); break;
784 case 2: fprintf(output, " src%d_sel:%cword%u", i, sext, offset >> 1); break;
785 case 4: fprintf(output, " src%d_sel:dword", i); break;
786 default: break;
787 }
788 }
789 }
790
791 if (bound_ctrl)
792 fprintf(output, " bound_ctrl:1");
793 if (fetch_inactive)
794 fprintf(output, " fi");
795 }
796
797 void
print_vopd_instr(enum amd_gfx_level gfx_level,const Instruction * instr,FILE * output,unsigned flags)798 print_vopd_instr(enum amd_gfx_level gfx_level, const Instruction* instr, FILE* output,
799 unsigned flags)
800 {
801 unsigned opy_start = get_vopd_opy_start(instr);
802
803 if (!instr->definitions.empty()) {
804 print_definition(&instr->definitions[0], output, flags);
805 fprintf(output, " = ");
806 }
807 fprintf(output, "%s", instr_info.name[(int)instr->opcode]);
808 for (unsigned i = 0; i < MIN2(instr->operands.size(), opy_start); ++i) {
809 fprintf(output, i ? ", " : " ");
810 aco_print_operand(&instr->operands[i], output, flags);
811 }
812
813 fprintf(output, " ::");
814
815 if (instr->definitions.size() > 1) {
816 print_definition(&instr->definitions[1], output, flags);
817 fprintf(output, " = ");
818 }
819 fprintf(output, "%s", instr_info.name[(int)instr->vopd().opy]);
820 for (unsigned i = opy_start; i < instr->operands.size(); ++i) {
821 fprintf(output, i > opy_start ? ", " : " ");
822 aco_print_operand(&instr->operands[i], output, flags);
823 }
824 }
825
826 static void
print_block_kind(uint16_t kind,FILE * output)827 print_block_kind(uint16_t kind, FILE* output)
828 {
829 if (kind & block_kind_uniform)
830 fprintf(output, "uniform, ");
831 if (kind & block_kind_top_level)
832 fprintf(output, "top-level, ");
833 if (kind & block_kind_loop_preheader)
834 fprintf(output, "loop-preheader, ");
835 if (kind & block_kind_loop_header)
836 fprintf(output, "loop-header, ");
837 if (kind & block_kind_loop_exit)
838 fprintf(output, "loop-exit, ");
839 if (kind & block_kind_continue)
840 fprintf(output, "continue, ");
841 if (kind & block_kind_break)
842 fprintf(output, "break, ");
843 if (kind & block_kind_continue_or_break)
844 fprintf(output, "continue_or_break, ");
845 if (kind & block_kind_branch)
846 fprintf(output, "branch, ");
847 if (kind & block_kind_merge)
848 fprintf(output, "merge, ");
849 if (kind & block_kind_invert)
850 fprintf(output, "invert, ");
851 if (kind & block_kind_discard_early_exit)
852 fprintf(output, "discard_early_exit, ");
853 if (kind & block_kind_uses_discard)
854 fprintf(output, "discard, ");
855 if (kind & block_kind_resume)
856 fprintf(output, "resume, ");
857 if (kind & block_kind_export_end)
858 fprintf(output, "export_end, ");
859 if (kind & block_kind_end_with_regs)
860 fprintf(output, "end_with_regs, ");
861 }
862
863 static void
print_stage(Stage stage,FILE * output)864 print_stage(Stage stage, FILE* output)
865 {
866 fprintf(output, "ACO shader stage: SW (");
867
868 u_foreach_bit (s, (uint32_t)stage.sw) {
869 switch ((SWStage)(1 << s)) {
870 case SWStage::VS: fprintf(output, "VS"); break;
871 case SWStage::GS: fprintf(output, "GS"); break;
872 case SWStage::TCS: fprintf(output, "TCS"); break;
873 case SWStage::TES: fprintf(output, "TES"); break;
874 case SWStage::FS: fprintf(output, "FS"); break;
875 case SWStage::CS: fprintf(output, "CS"); break;
876 case SWStage::TS: fprintf(output, "TS"); break;
877 case SWStage::MS: fprintf(output, "MS"); break;
878 case SWStage::RT: fprintf(output, "RT"); break;
879 default: unreachable("invalid SW stage");
880 }
881 if (stage.num_sw_stages() > 1)
882 fprintf(output, "+");
883 }
884
885 fprintf(output, "), HW (");
886
887 switch (stage.hw) {
888 case AC_HW_LOCAL_SHADER: fprintf(output, "LOCAL_SHADER"); break;
889 case AC_HW_HULL_SHADER: fprintf(output, "HULL_SHADER"); break;
890 case AC_HW_EXPORT_SHADER: fprintf(output, "EXPORT_SHADER"); break;
891 case AC_HW_LEGACY_GEOMETRY_SHADER: fprintf(output, "LEGACY_GEOMETRY_SHADER"); break;
892 case AC_HW_VERTEX_SHADER: fprintf(output, "VERTEX_SHADER"); break;
893 case AC_HW_NEXT_GEN_GEOMETRY_SHADER: fprintf(output, "NEXT_GEN_GEOMETRY_SHADER"); break;
894 case AC_HW_PIXEL_SHADER: fprintf(output, "PIXEL_SHADER"); break;
895 case AC_HW_COMPUTE_SHADER: fprintf(output, "COMPUTE_SHADER"); break;
896 default: unreachable("invalid HW stage");
897 }
898
899 fprintf(output, ")\n");
900 }
901
902 void
print_debug_info(const Program * program,const Instruction * instr,FILE * output)903 print_debug_info(const Program* program, const Instruction* instr, FILE* output)
904 {
905 fprintf(output, "// ");
906
907 assert(instr->operands[0].isConstant());
908 const auto& info = program->debug_info[instr->operands[0].constantValue()];
909 switch (info.type) {
910 case ac_shader_debug_info_src_loc:
911 if (info.src_loc.spirv_offset)
912 fprintf(output, "0x%x ", info.src_loc.spirv_offset);
913 fprintf(output, "%s:%u:%u", info.src_loc.file, info.src_loc.line, info.src_loc.column);
914 break;
915 }
916
917 fprintf(output, "\n");
918 }
919
920 void
aco_print_block(enum amd_gfx_level gfx_level,const Block * block,FILE * output,unsigned flags,const Program * program)921 aco_print_block(enum amd_gfx_level gfx_level, const Block* block, FILE* output, unsigned flags,
922 const Program* program)
923 {
924 if (block->instructions.empty() && block->linear_preds.empty())
925 return;
926
927 fprintf(output, "BB%d\n", block->index);
928 fprintf(output, "/* logical preds: ");
929 for (unsigned pred : block->logical_preds)
930 fprintf(output, "BB%d, ", pred);
931 fprintf(output, "/ linear preds: ");
932 for (unsigned pred : block->linear_preds)
933 fprintf(output, "BB%d, ", pred);
934 fprintf(output, "/ kind: ");
935 print_block_kind(block->kind, output);
936 fprintf(output, "*/\n");
937
938 if (flags & print_live_vars) {
939 fprintf(output, "\tlive in:");
940 for (unsigned id : program->live.live_in[block->index])
941 fprintf(output, " %%%d", id);
942 fprintf(output, "\n");
943
944 RegisterDemand demand = block->register_demand;
945 fprintf(output, "\tdemand: %u vgpr, %u sgpr\n", demand.vgpr, demand.sgpr);
946 }
947
948 for (auto const& instr : block->instructions) {
949 fprintf(output, "\t");
950 if (instr->opcode == aco_opcode::p_debug_info) {
951 print_debug_info(program, instr.get(), output);
952 continue;
953 }
954 if (flags & print_live_vars) {
955 RegisterDemand demand = instr->register_demand;
956 fprintf(output, "(%3u vgpr, %3u sgpr) ", demand.vgpr, demand.sgpr);
957 }
958 if (flags & print_perf_info)
959 fprintf(output, "(%3u clk) ", instr->pass_flags);
960
961 aco_print_instr(gfx_level, instr.get(), output, flags);
962 fprintf(output, "\n");
963 }
964 }
965
966 } /* end namespace */
967
968 void
aco_print_operand(const Operand * operand,FILE * output,unsigned flags)969 aco_print_operand(const Operand* operand, FILE* output, unsigned flags)
970 {
971 if (operand->isLiteral() || (operand->isConstant() && operand->bytes() == 1)) {
972 if (operand->bytes() == 1)
973 fprintf(output, "0x%.2x", operand->constantValue());
974 else if (operand->bytes() == 2)
975 fprintf(output, "0x%.4x", operand->constantValue());
976 else
977 fprintf(output, "0x%x", operand->constantValue());
978 } else if (operand->isConstant()) {
979 print_constant(operand->physReg().reg(), output);
980 } else if (operand->isUndefined()) {
981 print_reg_class(operand->regClass(), output);
982 fprintf(output, "undef");
983 } else {
984 if (operand->isLateKill())
985 fprintf(output, "(latekill)");
986 if (operand->is16bit())
987 fprintf(output, "(is16bit)");
988 if (operand->is24bit())
989 fprintf(output, "(is24bit)");
990 if ((flags & print_kill) && operand->isKill())
991 fprintf(output, "(kill)");
992
993 if (!(flags & print_no_ssa))
994 fprintf(output, "%%%d%s", operand->tempId(), operand->isFixed() ? ":" : "");
995
996 if (operand->isFixed())
997 print_physReg(operand->physReg(), operand->bytes(), output, flags);
998 }
999 }
1000
1001 void
aco_print_instr(enum amd_gfx_level gfx_level,const Instruction * instr,FILE * output,unsigned flags)1002 aco_print_instr(enum amd_gfx_level gfx_level, const Instruction* instr, FILE* output,
1003 unsigned flags)
1004 {
1005 if (instr->isVOPD()) {
1006 print_vopd_instr(gfx_level, instr, output, flags);
1007 return;
1008 }
1009
1010 if (!instr->definitions.empty()) {
1011 for (unsigned i = 0; i < instr->definitions.size(); ++i) {
1012 print_definition(&instr->definitions[i], output, flags);
1013 if (i + 1 != instr->definitions.size())
1014 fprintf(output, ", ");
1015 }
1016 fprintf(output, " = ");
1017 }
1018 fprintf(output, "%s", instr_info.name[(int)instr->opcode]);
1019 if (instr->operands.size()) {
1020 const unsigned num_operands = instr->operands.size();
1021 bitarray8 abs = 0;
1022 bitarray8 neg = 0;
1023 bitarray8 neg_lo = 0;
1024 bitarray8 neg_hi = 0;
1025 bitarray8 opsel = 0;
1026 bitarray8 f2f32 = 0;
1027 bitarray8 opsel_lo = 0;
1028 bitarray8 opsel_hi = -1;
1029
1030 if (instr->opcode == aco_opcode::v_fma_mix_f32 ||
1031 instr->opcode == aco_opcode::v_fma_mixlo_f16 ||
1032 instr->opcode == aco_opcode::v_fma_mixhi_f16) {
1033 const VALU_instruction& vop3p = instr->valu();
1034 abs = vop3p.abs;
1035 neg = vop3p.neg;
1036 f2f32 = vop3p.opsel_hi;
1037 opsel = f2f32 & vop3p.opsel_lo;
1038 } else if (instr->isVOP3P()) {
1039 const VALU_instruction& vop3p = instr->valu();
1040 neg = vop3p.neg_lo & vop3p.neg_hi;
1041 neg_lo = vop3p.neg_lo & ~neg;
1042 neg_hi = vop3p.neg_hi & ~neg;
1043 opsel_lo = vop3p.opsel_lo;
1044 opsel_hi = vop3p.opsel_hi;
1045 } else if (instr->isVALU() && instr->opcode != aco_opcode::v_permlane16_b32 &&
1046 instr->opcode != aco_opcode::v_permlanex16_b32) {
1047 const VALU_instruction& valu = instr->valu();
1048 abs = valu.abs;
1049 neg = valu.neg;
1050 opsel = valu.opsel;
1051 }
1052 for (unsigned i = 0; i < num_operands; ++i) {
1053 if (i)
1054 fprintf(output, ", ");
1055 else
1056 fprintf(output, " ");
1057
1058 if (i < 3) {
1059 if (neg[i] && instr->operands[i].isConstant())
1060 fprintf(output, "neg(");
1061 else if (neg[i])
1062 fprintf(output, "-");
1063 if (abs[i])
1064 fprintf(output, "|");
1065 if (opsel[i])
1066 fprintf(output, "hi(");
1067 else if (f2f32[i])
1068 fprintf(output, "lo(");
1069 }
1070
1071 aco_print_operand(&instr->operands[i], output, flags);
1072
1073 if (i < 3) {
1074 if (f2f32[i] || opsel[i])
1075 fprintf(output, ")");
1076 if (abs[i])
1077 fprintf(output, "|");
1078
1079 if (opsel_lo[i] || !opsel_hi[i])
1080 fprintf(output, ".%c%c", opsel_lo[i] ? 'y' : 'x', opsel_hi[i] ? 'y' : 'x');
1081
1082 if (neg[i] && instr->operands[i].isConstant())
1083 fprintf(output, ")");
1084 if (neg_lo[i])
1085 fprintf(output, "*[-1,1]");
1086 if (neg_hi[i])
1087 fprintf(output, "*[1,-1]");
1088 }
1089 }
1090 }
1091 print_instr_format_specific(gfx_level, instr, output);
1092 }
1093
1094 void
aco_print_program(const Program * program,FILE * output,unsigned flags)1095 aco_print_program(const Program* program, FILE* output, unsigned flags)
1096 {
1097 switch (program->progress) {
1098 case CompilationProgress::after_isel: fprintf(output, "After Instruction Selection:\n"); break;
1099 case CompilationProgress::after_spilling:
1100 fprintf(output, "After Spilling:\n");
1101 flags |= print_kill;
1102 break;
1103 case CompilationProgress::after_ra: fprintf(output, "After RA:\n"); break;
1104 case CompilationProgress::after_lower_to_hw:
1105 fprintf(output, "After lowering to hw instructions:\n");
1106 break;
1107 }
1108
1109 print_stage(program->stage, output);
1110
1111 for (Block const& block : program->blocks)
1112 aco_print_block(program->gfx_level, &block, output, flags, program);
1113
1114 if (program->constant_data.size()) {
1115 fprintf(output, "\n/* constant data */\n");
1116 for (unsigned i = 0; i < program->constant_data.size(); i += 32) {
1117 fprintf(output, "[%06d] ", i);
1118 unsigned line_size = std::min<size_t>(program->constant_data.size() - i, 32);
1119 for (unsigned j = 0; j < line_size; j += 4) {
1120 unsigned size = std::min<size_t>(program->constant_data.size() - (i + j), 4);
1121 uint32_t v = 0;
1122 memcpy(&v, &program->constant_data[i + j], size);
1123 fprintf(output, " %08x", v);
1124 }
1125 fprintf(output, "\n");
1126 }
1127 }
1128
1129 fprintf(output, "\n");
1130 }
1131
1132 } // namespace aco
1133