1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2018 Valve Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci#include "aco_builder.h" 26bf215546Sopenharmony_ci#include "aco_ir.h" 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "common/ac_shader_util.h" 29bf215546Sopenharmony_ci#include "common/sid.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include <array> 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_cinamespace aco { 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ciconst std::array<const char*, num_reduce_ops> reduce_ops = []() 36bf215546Sopenharmony_ci{ 37bf215546Sopenharmony_ci std::array<const char*, num_reduce_ops> ret{}; 38bf215546Sopenharmony_ci ret[iadd8] = "iadd8"; 39bf215546Sopenharmony_ci ret[iadd16] = "iadd16"; 40bf215546Sopenharmony_ci ret[iadd32] = "iadd32"; 41bf215546Sopenharmony_ci ret[iadd64] = "iadd64"; 42bf215546Sopenharmony_ci ret[imul8] = "imul8"; 43bf215546Sopenharmony_ci ret[imul16] = "imul16"; 44bf215546Sopenharmony_ci ret[imul32] = "imul32"; 45bf215546Sopenharmony_ci ret[imul64] = "imul64"; 46bf215546Sopenharmony_ci ret[fadd16] = "fadd16"; 47bf215546Sopenharmony_ci ret[fadd32] = "fadd32"; 48bf215546Sopenharmony_ci ret[fadd64] = "fadd64"; 49bf215546Sopenharmony_ci ret[fmul16] = "fmul16"; 50bf215546Sopenharmony_ci ret[fmul32] = "fmul32"; 51bf215546Sopenharmony_ci ret[fmul64] = "fmul64"; 52bf215546Sopenharmony_ci ret[imin8] = "imin8"; 53bf215546Sopenharmony_ci ret[imin16] = "imin16"; 54bf215546Sopenharmony_ci ret[imin32] = "imin32"; 55bf215546Sopenharmony_ci ret[imin64] = "imin64"; 56bf215546Sopenharmony_ci ret[imax8] = "imax8"; 57bf215546Sopenharmony_ci ret[imax16] = "imax16"; 58bf215546Sopenharmony_ci ret[imax32] = "imax32"; 59bf215546Sopenharmony_ci ret[imax64] = "imax64"; 60bf215546Sopenharmony_ci ret[umin8] = "umin8"; 61bf215546Sopenharmony_ci ret[umin16] = "umin16"; 62bf215546Sopenharmony_ci ret[umin32] = "umin32"; 63bf215546Sopenharmony_ci ret[umin64] = "umin64"; 64bf215546Sopenharmony_ci ret[umax8] = "umax8"; 65bf215546Sopenharmony_ci ret[umax16] = "umax16"; 66bf215546Sopenharmony_ci ret[umax32] = "umax32"; 67bf215546Sopenharmony_ci ret[umax64] = "umax64"; 68bf215546Sopenharmony_ci ret[fmin16] = "fmin16"; 69bf215546Sopenharmony_ci ret[fmin32] = "fmin32"; 70bf215546Sopenharmony_ci ret[fmin64] = "fmin64"; 71bf215546Sopenharmony_ci ret[fmax16] = "fmax16"; 72bf215546Sopenharmony_ci ret[fmax32] = "fmax32"; 73bf215546Sopenharmony_ci ret[fmax64] = "fmax64"; 74bf215546Sopenharmony_ci ret[iand8] = "iand8"; 75bf215546Sopenharmony_ci ret[iand16] = "iand16"; 76bf215546Sopenharmony_ci ret[iand32] = "iand32"; 77bf215546Sopenharmony_ci ret[iand64] = "iand64"; 78bf215546Sopenharmony_ci ret[ior8] = "ior8"; 79bf215546Sopenharmony_ci ret[ior16] = "ior16"; 80bf215546Sopenharmony_ci ret[ior32] = "ior32"; 81bf215546Sopenharmony_ci ret[ior64] = "ior64"; 82bf215546Sopenharmony_ci ret[ixor8] = "ixor8"; 83bf215546Sopenharmony_ci ret[ixor16] = "ixor16"; 84bf215546Sopenharmony_ci ret[ixor32] = "ixor32"; 85bf215546Sopenharmony_ci ret[ixor64] = "ixor64"; 86bf215546Sopenharmony_ci return ret; 87bf215546Sopenharmony_ci}(); 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_cistatic void 90bf215546Sopenharmony_ciprint_reg_class(const RegClass rc, FILE* output) 91bf215546Sopenharmony_ci{ 92bf215546Sopenharmony_ci if (rc.is_subdword()) { 93bf215546Sopenharmony_ci fprintf(output, " v%ub: ", rc.bytes()); 94bf215546Sopenharmony_ci } else if (rc.type() == RegType::sgpr) { 95bf215546Sopenharmony_ci fprintf(output, " s%u: ", rc.size()); 96bf215546Sopenharmony_ci } else if (rc.is_linear()) { 97bf215546Sopenharmony_ci fprintf(output, " lv%u: ", rc.size()); 98bf215546Sopenharmony_ci } else { 99bf215546Sopenharmony_ci fprintf(output, " v%u: ", rc.size()); 100bf215546Sopenharmony_ci } 101bf215546Sopenharmony_ci} 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_civoid 104bf215546Sopenharmony_ciprint_physReg(PhysReg reg, unsigned bytes, FILE* output, unsigned flags) 105bf215546Sopenharmony_ci{ 106bf215546Sopenharmony_ci if (reg == 124) { 107bf215546Sopenharmony_ci fprintf(output, "m0"); 108bf215546Sopenharmony_ci } else if (reg == 106) { 109bf215546Sopenharmony_ci fprintf(output, "vcc"); 110bf215546Sopenharmony_ci } else if (reg == 253) { 111bf215546Sopenharmony_ci fprintf(output, "scc"); 112bf215546Sopenharmony_ci } else if (reg == 126) { 113bf215546Sopenharmony_ci fprintf(output, "exec"); 114bf215546Sopenharmony_ci } else { 115bf215546Sopenharmony_ci bool is_vgpr = reg / 256; 116bf215546Sopenharmony_ci unsigned r = reg % 256; 117bf215546Sopenharmony_ci unsigned size = DIV_ROUND_UP(bytes, 4); 118bf215546Sopenharmony_ci if (size == 1 && (flags & print_no_ssa)) { 119bf215546Sopenharmony_ci fprintf(output, "%c%d", is_vgpr ? 'v' : 's', r); 120bf215546Sopenharmony_ci } else { 121bf215546Sopenharmony_ci fprintf(output, "%c[%d", is_vgpr ? 'v' : 's', r); 122bf215546Sopenharmony_ci if (size > 1) 123bf215546Sopenharmony_ci fprintf(output, "-%d]", r + size - 1); 124bf215546Sopenharmony_ci else 125bf215546Sopenharmony_ci fprintf(output, "]"); 126bf215546Sopenharmony_ci } 127bf215546Sopenharmony_ci if (reg.byte() || bytes % 4) 128bf215546Sopenharmony_ci fprintf(output, "[%d:%d]", reg.byte() * 8, (reg.byte() + bytes) * 8); 129bf215546Sopenharmony_ci } 130bf215546Sopenharmony_ci} 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_cistatic void 133bf215546Sopenharmony_ciprint_constant(uint8_t reg, FILE* output) 134bf215546Sopenharmony_ci{ 135bf215546Sopenharmony_ci if (reg >= 128 && reg <= 192) { 136bf215546Sopenharmony_ci fprintf(output, "%d", reg - 128); 137bf215546Sopenharmony_ci return; 138bf215546Sopenharmony_ci } else if (reg >= 192 && reg <= 208) { 139bf215546Sopenharmony_ci fprintf(output, "%d", 192 - reg); 140bf215546Sopenharmony_ci return; 141bf215546Sopenharmony_ci } 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci switch (reg) { 144bf215546Sopenharmony_ci case 240: fprintf(output, "0.5"); break; 145bf215546Sopenharmony_ci case 241: fprintf(output, "-0.5"); break; 146bf215546Sopenharmony_ci case 242: fprintf(output, "1.0"); break; 147bf215546Sopenharmony_ci case 243: fprintf(output, "-1.0"); break; 148bf215546Sopenharmony_ci case 244: fprintf(output, "2.0"); break; 149bf215546Sopenharmony_ci case 245: fprintf(output, "-2.0"); break; 150bf215546Sopenharmony_ci case 246: fprintf(output, "4.0"); break; 151bf215546Sopenharmony_ci case 247: fprintf(output, "-4.0"); break; 152bf215546Sopenharmony_ci case 248: fprintf(output, "1/(2*PI)"); break; 153bf215546Sopenharmony_ci } 154bf215546Sopenharmony_ci} 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_civoid 157bf215546Sopenharmony_ciaco_print_operand(const Operand* operand, FILE* output, unsigned flags) 158bf215546Sopenharmony_ci{ 159bf215546Sopenharmony_ci if (operand->isLiteral() || (operand->isConstant() && operand->bytes() == 1)) { 160bf215546Sopenharmony_ci if (operand->bytes() == 1) 161bf215546Sopenharmony_ci fprintf(output, "0x%.2x", operand->constantValue()); 162bf215546Sopenharmony_ci else if (operand->bytes() == 2) 163bf215546Sopenharmony_ci fprintf(output, "0x%.4x", operand->constantValue()); 164bf215546Sopenharmony_ci else 165bf215546Sopenharmony_ci fprintf(output, "0x%x", operand->constantValue()); 166bf215546Sopenharmony_ci } else if (operand->isConstant()) { 167bf215546Sopenharmony_ci print_constant(operand->physReg().reg(), output); 168bf215546Sopenharmony_ci } else if (operand->isUndefined()) { 169bf215546Sopenharmony_ci print_reg_class(operand->regClass(), output); 170bf215546Sopenharmony_ci fprintf(output, "undef"); 171bf215546Sopenharmony_ci } else { 172bf215546Sopenharmony_ci if (operand->isLateKill()) 173bf215546Sopenharmony_ci fprintf(output, "(latekill)"); 174bf215546Sopenharmony_ci if (operand->is16bit()) 175bf215546Sopenharmony_ci fprintf(output, "(is16bit)"); 176bf215546Sopenharmony_ci if (operand->is24bit()) 177bf215546Sopenharmony_ci fprintf(output, "(is24bit)"); 178bf215546Sopenharmony_ci if ((flags & print_kill) && operand->isKill()) 179bf215546Sopenharmony_ci fprintf(output, "(kill)"); 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_ci if (!(flags & print_no_ssa)) 182bf215546Sopenharmony_ci fprintf(output, "%%%d%s", operand->tempId(), operand->isFixed() ? ":" : ""); 183bf215546Sopenharmony_ci 184bf215546Sopenharmony_ci if (operand->isFixed()) 185bf215546Sopenharmony_ci print_physReg(operand->physReg(), operand->bytes(), output, flags); 186bf215546Sopenharmony_ci } 187bf215546Sopenharmony_ci} 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_cistatic void 190bf215546Sopenharmony_ciprint_definition(const Definition* definition, FILE* output, unsigned flags) 191bf215546Sopenharmony_ci{ 192bf215546Sopenharmony_ci if (!(flags & print_no_ssa)) 193bf215546Sopenharmony_ci print_reg_class(definition->regClass(), output); 194bf215546Sopenharmony_ci if (definition->isPrecise()) 195bf215546Sopenharmony_ci fprintf(output, "(precise)"); 196bf215546Sopenharmony_ci if (definition->isNUW()) 197bf215546Sopenharmony_ci fprintf(output, "(nuw)"); 198bf215546Sopenharmony_ci if (definition->isNoCSE()) 199bf215546Sopenharmony_ci fprintf(output, "(noCSE)"); 200bf215546Sopenharmony_ci if ((flags & print_kill) && definition->isKill()) 201bf215546Sopenharmony_ci fprintf(output, "(kill)"); 202bf215546Sopenharmony_ci if (!(flags & print_no_ssa)) 203bf215546Sopenharmony_ci fprintf(output, "%%%d%s", definition->tempId(), definition->isFixed() ? ":" : ""); 204bf215546Sopenharmony_ci 205bf215546Sopenharmony_ci if (definition->isFixed()) 206bf215546Sopenharmony_ci print_physReg(definition->physReg(), definition->bytes(), output, flags); 207bf215546Sopenharmony_ci} 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_cistatic void 210bf215546Sopenharmony_ciprint_storage(storage_class storage, FILE* output) 211bf215546Sopenharmony_ci{ 212bf215546Sopenharmony_ci fprintf(output, " storage:"); 213bf215546Sopenharmony_ci int printed = 0; 214bf215546Sopenharmony_ci if (storage & storage_buffer) 215bf215546Sopenharmony_ci printed += fprintf(output, "%sbuffer", printed ? "," : ""); 216bf215546Sopenharmony_ci if (storage & storage_atomic_counter) 217bf215546Sopenharmony_ci printed += fprintf(output, "%satomic_counter", printed ? "," : ""); 218bf215546Sopenharmony_ci if (storage & storage_image) 219bf215546Sopenharmony_ci printed += fprintf(output, "%simage", printed ? "," : ""); 220bf215546Sopenharmony_ci if (storage & storage_shared) 221bf215546Sopenharmony_ci printed += fprintf(output, "%sshared", printed ? "," : ""); 222bf215546Sopenharmony_ci if (storage & storage_task_payload) 223bf215546Sopenharmony_ci printed += fprintf(output, "%stask_payload", printed ? "," : ""); 224bf215546Sopenharmony_ci if (storage & storage_vmem_output) 225bf215546Sopenharmony_ci printed += fprintf(output, "%svmem_output", printed ? "," : ""); 226bf215546Sopenharmony_ci if (storage & storage_scratch) 227bf215546Sopenharmony_ci printed += fprintf(output, "%sscratch", printed ? "," : ""); 228bf215546Sopenharmony_ci if (storage & storage_vgpr_spill) 229bf215546Sopenharmony_ci printed += fprintf(output, "%svgpr_spill", printed ? "," : ""); 230bf215546Sopenharmony_ci} 231bf215546Sopenharmony_ci 232bf215546Sopenharmony_cistatic void 233bf215546Sopenharmony_ciprint_semantics(memory_semantics sem, FILE* output) 234bf215546Sopenharmony_ci{ 235bf215546Sopenharmony_ci fprintf(output, " semantics:"); 236bf215546Sopenharmony_ci int printed = 0; 237bf215546Sopenharmony_ci if (sem & semantic_acquire) 238bf215546Sopenharmony_ci printed += fprintf(output, "%sacquire", printed ? "," : ""); 239bf215546Sopenharmony_ci if (sem & semantic_release) 240bf215546Sopenharmony_ci printed += fprintf(output, "%srelease", printed ? "," : ""); 241bf215546Sopenharmony_ci if (sem & semantic_volatile) 242bf215546Sopenharmony_ci printed += fprintf(output, "%svolatile", printed ? "," : ""); 243bf215546Sopenharmony_ci if (sem & semantic_private) 244bf215546Sopenharmony_ci printed += fprintf(output, "%sprivate", printed ? "," : ""); 245bf215546Sopenharmony_ci if (sem & semantic_can_reorder) 246bf215546Sopenharmony_ci printed += fprintf(output, "%sreorder", printed ? "," : ""); 247bf215546Sopenharmony_ci if (sem & semantic_atomic) 248bf215546Sopenharmony_ci printed += fprintf(output, "%satomic", printed ? "," : ""); 249bf215546Sopenharmony_ci if (sem & semantic_rmw) 250bf215546Sopenharmony_ci printed += fprintf(output, "%srmw", printed ? "," : ""); 251bf215546Sopenharmony_ci} 252bf215546Sopenharmony_ci 253bf215546Sopenharmony_cistatic void 254bf215546Sopenharmony_ciprint_scope(sync_scope scope, FILE* output, const char* prefix = "scope") 255bf215546Sopenharmony_ci{ 256bf215546Sopenharmony_ci fprintf(output, " %s:", prefix); 257bf215546Sopenharmony_ci switch (scope) { 258bf215546Sopenharmony_ci case scope_invocation: fprintf(output, "invocation"); break; 259bf215546Sopenharmony_ci case scope_subgroup: fprintf(output, "subgroup"); break; 260bf215546Sopenharmony_ci case scope_workgroup: fprintf(output, "workgroup"); break; 261bf215546Sopenharmony_ci case scope_queuefamily: fprintf(output, "queuefamily"); break; 262bf215546Sopenharmony_ci case scope_device: fprintf(output, "device"); break; 263bf215546Sopenharmony_ci } 264bf215546Sopenharmony_ci} 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_cistatic void 267bf215546Sopenharmony_ciprint_sync(memory_sync_info sync, FILE* output) 268bf215546Sopenharmony_ci{ 269bf215546Sopenharmony_ci print_storage(sync.storage, output); 270bf215546Sopenharmony_ci print_semantics(sync.semantics, output); 271bf215546Sopenharmony_ci print_scope(sync.scope, output); 272bf215546Sopenharmony_ci} 273bf215546Sopenharmony_ci 274bf215546Sopenharmony_cistatic void 275bf215546Sopenharmony_ciprint_instr_format_specific(const Instruction* instr, FILE* output) 276bf215546Sopenharmony_ci{ 277bf215546Sopenharmony_ci switch (instr->format) { 278bf215546Sopenharmony_ci case Format::SOPK: { 279bf215546Sopenharmony_ci const SOPK_instruction& sopk = instr->sopk(); 280bf215546Sopenharmony_ci fprintf(output, " imm:%d", sopk.imm & 0x8000 ? (sopk.imm - 65536) : sopk.imm); 281bf215546Sopenharmony_ci break; 282bf215546Sopenharmony_ci } 283bf215546Sopenharmony_ci case Format::SOPP: { 284bf215546Sopenharmony_ci uint16_t imm = instr->sopp().imm; 285bf215546Sopenharmony_ci switch (instr->opcode) { 286bf215546Sopenharmony_ci case aco_opcode::s_waitcnt: { 287bf215546Sopenharmony_ci /* we usually should check the gfx level for vmcnt/lgkm, but 288bf215546Sopenharmony_ci * insert_waitcnt() should fill it in regardless. */ 289bf215546Sopenharmony_ci unsigned vmcnt = (imm & 0xF) | ((imm & (0x3 << 14)) >> 10); 290bf215546Sopenharmony_ci if (vmcnt != 63) 291bf215546Sopenharmony_ci fprintf(output, " vmcnt(%d)", vmcnt); 292bf215546Sopenharmony_ci if (((imm >> 4) & 0x7) < 0x7) 293bf215546Sopenharmony_ci fprintf(output, " expcnt(%d)", (imm >> 4) & 0x7); 294bf215546Sopenharmony_ci if (((imm >> 8) & 0x3F) < 0x3F) 295bf215546Sopenharmony_ci fprintf(output, " lgkmcnt(%d)", (imm >> 8) & 0x3F); 296bf215546Sopenharmony_ci break; 297bf215546Sopenharmony_ci } 298bf215546Sopenharmony_ci case aco_opcode::s_endpgm: 299bf215546Sopenharmony_ci case aco_opcode::s_endpgm_saved: 300bf215546Sopenharmony_ci case aco_opcode::s_endpgm_ordered_ps_done: 301bf215546Sopenharmony_ci case aco_opcode::s_wakeup: 302bf215546Sopenharmony_ci case aco_opcode::s_barrier: 303bf215546Sopenharmony_ci case aco_opcode::s_icache_inv: 304bf215546Sopenharmony_ci case aco_opcode::s_ttracedata: 305bf215546Sopenharmony_ci case aco_opcode::s_set_gpr_idx_off: { 306bf215546Sopenharmony_ci break; 307bf215546Sopenharmony_ci } 308bf215546Sopenharmony_ci case aco_opcode::s_sendmsg: { 309bf215546Sopenharmony_ci unsigned id = imm & sendmsg_id_mask; 310bf215546Sopenharmony_ci switch (id) { 311bf215546Sopenharmony_ci case sendmsg_none: fprintf(output, " sendmsg(MSG_NONE)"); break; 312bf215546Sopenharmony_ci case _sendmsg_gs: 313bf215546Sopenharmony_ci fprintf(output, " sendmsg(gs%s%s, %u)", imm & 0x10 ? ", cut" : "", 314bf215546Sopenharmony_ci imm & 0x20 ? ", emit" : "", imm >> 8); 315bf215546Sopenharmony_ci break; 316bf215546Sopenharmony_ci case _sendmsg_gs_done: 317bf215546Sopenharmony_ci fprintf(output, " sendmsg(gs_done%s%s, %u)", imm & 0x10 ? ", cut" : "", 318bf215546Sopenharmony_ci imm & 0x20 ? ", emit" : "", imm >> 8); 319bf215546Sopenharmony_ci break; 320bf215546Sopenharmony_ci case sendmsg_save_wave: fprintf(output, " sendmsg(save_wave)"); break; 321bf215546Sopenharmony_ci case sendmsg_stall_wave_gen: fprintf(output, " sendmsg(stall_wave_gen)"); break; 322bf215546Sopenharmony_ci case sendmsg_halt_waves: fprintf(output, " sendmsg(halt_waves)"); break; 323bf215546Sopenharmony_ci case sendmsg_ordered_ps_done: fprintf(output, " sendmsg(ordered_ps_done)"); break; 324bf215546Sopenharmony_ci case sendmsg_early_prim_dealloc: fprintf(output, " sendmsg(early_prim_dealloc)"); break; 325bf215546Sopenharmony_ci case sendmsg_gs_alloc_req: fprintf(output, " sendmsg(gs_alloc_req)"); break; 326bf215546Sopenharmony_ci } 327bf215546Sopenharmony_ci break; 328bf215546Sopenharmony_ci } 329bf215546Sopenharmony_ci default: { 330bf215546Sopenharmony_ci if (imm) 331bf215546Sopenharmony_ci fprintf(output, " imm:%u", imm); 332bf215546Sopenharmony_ci break; 333bf215546Sopenharmony_ci } 334bf215546Sopenharmony_ci } 335bf215546Sopenharmony_ci if (instr->sopp().block != -1) 336bf215546Sopenharmony_ci fprintf(output, " block:BB%d", instr->sopp().block); 337bf215546Sopenharmony_ci break; 338bf215546Sopenharmony_ci } 339bf215546Sopenharmony_ci case Format::SMEM: { 340bf215546Sopenharmony_ci const SMEM_instruction& smem = instr->smem(); 341bf215546Sopenharmony_ci if (smem.glc) 342bf215546Sopenharmony_ci fprintf(output, " glc"); 343bf215546Sopenharmony_ci if (smem.dlc) 344bf215546Sopenharmony_ci fprintf(output, " dlc"); 345bf215546Sopenharmony_ci if (smem.nv) 346bf215546Sopenharmony_ci fprintf(output, " nv"); 347bf215546Sopenharmony_ci print_sync(smem.sync, output); 348bf215546Sopenharmony_ci break; 349bf215546Sopenharmony_ci } 350bf215546Sopenharmony_ci case Format::VINTRP: { 351bf215546Sopenharmony_ci const Interp_instruction& vintrp = instr->vintrp(); 352bf215546Sopenharmony_ci fprintf(output, " attr%d.%c", vintrp.attribute, "xyzw"[vintrp.component]); 353bf215546Sopenharmony_ci break; 354bf215546Sopenharmony_ci } 355bf215546Sopenharmony_ci case Format::DS: { 356bf215546Sopenharmony_ci const DS_instruction& ds = instr->ds(); 357bf215546Sopenharmony_ci if (ds.offset0) 358bf215546Sopenharmony_ci fprintf(output, " offset0:%u", ds.offset0); 359bf215546Sopenharmony_ci if (ds.offset1) 360bf215546Sopenharmony_ci fprintf(output, " offset1:%u", ds.offset1); 361bf215546Sopenharmony_ci if (ds.gds) 362bf215546Sopenharmony_ci fprintf(output, " gds"); 363bf215546Sopenharmony_ci print_sync(ds.sync, output); 364bf215546Sopenharmony_ci break; 365bf215546Sopenharmony_ci } 366bf215546Sopenharmony_ci case Format::MUBUF: { 367bf215546Sopenharmony_ci const MUBUF_instruction& mubuf = instr->mubuf(); 368bf215546Sopenharmony_ci if (mubuf.offset) 369bf215546Sopenharmony_ci fprintf(output, " offset:%u", mubuf.offset); 370bf215546Sopenharmony_ci if (mubuf.offen) 371bf215546Sopenharmony_ci fprintf(output, " offen"); 372bf215546Sopenharmony_ci if (mubuf.idxen) 373bf215546Sopenharmony_ci fprintf(output, " idxen"); 374bf215546Sopenharmony_ci if (mubuf.addr64) 375bf215546Sopenharmony_ci fprintf(output, " addr64"); 376bf215546Sopenharmony_ci if (mubuf.glc) 377bf215546Sopenharmony_ci fprintf(output, " glc"); 378bf215546Sopenharmony_ci if (mubuf.dlc) 379bf215546Sopenharmony_ci fprintf(output, " dlc"); 380bf215546Sopenharmony_ci if (mubuf.slc) 381bf215546Sopenharmony_ci fprintf(output, " slc"); 382bf215546Sopenharmony_ci if (mubuf.tfe) 383bf215546Sopenharmony_ci fprintf(output, " tfe"); 384bf215546Sopenharmony_ci if (mubuf.lds) 385bf215546Sopenharmony_ci fprintf(output, " lds"); 386bf215546Sopenharmony_ci if (mubuf.disable_wqm) 387bf215546Sopenharmony_ci fprintf(output, " disable_wqm"); 388bf215546Sopenharmony_ci print_sync(mubuf.sync, output); 389bf215546Sopenharmony_ci break; 390bf215546Sopenharmony_ci } 391bf215546Sopenharmony_ci case Format::MIMG: { 392bf215546Sopenharmony_ci const MIMG_instruction& mimg = instr->mimg(); 393bf215546Sopenharmony_ci unsigned identity_dmask = 394bf215546Sopenharmony_ci !instr->definitions.empty() ? (1 << instr->definitions[0].size()) - 1 : 0xf; 395bf215546Sopenharmony_ci if ((mimg.dmask & identity_dmask) != identity_dmask) 396bf215546Sopenharmony_ci fprintf(output, " dmask:%s%s%s%s", mimg.dmask & 0x1 ? "x" : "", 397bf215546Sopenharmony_ci mimg.dmask & 0x2 ? "y" : "", mimg.dmask & 0x4 ? "z" : "", 398bf215546Sopenharmony_ci mimg.dmask & 0x8 ? "w" : ""); 399bf215546Sopenharmony_ci switch (mimg.dim) { 400bf215546Sopenharmony_ci case ac_image_1d: fprintf(output, " 1d"); break; 401bf215546Sopenharmony_ci case ac_image_2d: fprintf(output, " 2d"); break; 402bf215546Sopenharmony_ci case ac_image_3d: fprintf(output, " 3d"); break; 403bf215546Sopenharmony_ci case ac_image_cube: fprintf(output, " cube"); break; 404bf215546Sopenharmony_ci case ac_image_1darray: fprintf(output, " 1darray"); break; 405bf215546Sopenharmony_ci case ac_image_2darray: fprintf(output, " 2darray"); break; 406bf215546Sopenharmony_ci case ac_image_2dmsaa: fprintf(output, " 2dmsaa"); break; 407bf215546Sopenharmony_ci case ac_image_2darraymsaa: fprintf(output, " 2darraymsaa"); break; 408bf215546Sopenharmony_ci } 409bf215546Sopenharmony_ci if (mimg.unrm) 410bf215546Sopenharmony_ci fprintf(output, " unrm"); 411bf215546Sopenharmony_ci if (mimg.glc) 412bf215546Sopenharmony_ci fprintf(output, " glc"); 413bf215546Sopenharmony_ci if (mimg.dlc) 414bf215546Sopenharmony_ci fprintf(output, " dlc"); 415bf215546Sopenharmony_ci if (mimg.slc) 416bf215546Sopenharmony_ci fprintf(output, " slc"); 417bf215546Sopenharmony_ci if (mimg.tfe) 418bf215546Sopenharmony_ci fprintf(output, " tfe"); 419bf215546Sopenharmony_ci if (mimg.da) 420bf215546Sopenharmony_ci fprintf(output, " da"); 421bf215546Sopenharmony_ci if (mimg.lwe) 422bf215546Sopenharmony_ci fprintf(output, " lwe"); 423bf215546Sopenharmony_ci if (mimg.r128) 424bf215546Sopenharmony_ci fprintf(output, " r128"); 425bf215546Sopenharmony_ci if (mimg.a16) 426bf215546Sopenharmony_ci fprintf(output, " a16"); 427bf215546Sopenharmony_ci if (mimg.d16) 428bf215546Sopenharmony_ci fprintf(output, " d16"); 429bf215546Sopenharmony_ci if (mimg.disable_wqm) 430bf215546Sopenharmony_ci fprintf(output, " disable_wqm"); 431bf215546Sopenharmony_ci print_sync(mimg.sync, output); 432bf215546Sopenharmony_ci break; 433bf215546Sopenharmony_ci } 434bf215546Sopenharmony_ci case Format::EXP: { 435bf215546Sopenharmony_ci const Export_instruction& exp = instr->exp(); 436bf215546Sopenharmony_ci unsigned identity_mask = exp.compressed ? 0x5 : 0xf; 437bf215546Sopenharmony_ci if ((exp.enabled_mask & identity_mask) != identity_mask) 438bf215546Sopenharmony_ci fprintf(output, " en:%c%c%c%c", exp.enabled_mask & 0x1 ? 'r' : '*', 439bf215546Sopenharmony_ci exp.enabled_mask & 0x2 ? 'g' : '*', exp.enabled_mask & 0x4 ? 'b' : '*', 440bf215546Sopenharmony_ci exp.enabled_mask & 0x8 ? 'a' : '*'); 441bf215546Sopenharmony_ci if (exp.compressed) 442bf215546Sopenharmony_ci fprintf(output, " compr"); 443bf215546Sopenharmony_ci if (exp.done) 444bf215546Sopenharmony_ci fprintf(output, " done"); 445bf215546Sopenharmony_ci if (exp.valid_mask) 446bf215546Sopenharmony_ci fprintf(output, " vm"); 447bf215546Sopenharmony_ci 448bf215546Sopenharmony_ci if (exp.dest <= V_008DFC_SQ_EXP_MRT + 7) 449bf215546Sopenharmony_ci fprintf(output, " mrt%d", exp.dest - V_008DFC_SQ_EXP_MRT); 450bf215546Sopenharmony_ci else if (exp.dest == V_008DFC_SQ_EXP_MRTZ) 451bf215546Sopenharmony_ci fprintf(output, " mrtz"); 452bf215546Sopenharmony_ci else if (exp.dest == V_008DFC_SQ_EXP_NULL) 453bf215546Sopenharmony_ci fprintf(output, " null"); 454bf215546Sopenharmony_ci else if (exp.dest >= V_008DFC_SQ_EXP_POS && exp.dest <= V_008DFC_SQ_EXP_POS + 3) 455bf215546Sopenharmony_ci fprintf(output, " pos%d", exp.dest - V_008DFC_SQ_EXP_POS); 456bf215546Sopenharmony_ci else if (exp.dest >= V_008DFC_SQ_EXP_PARAM && exp.dest <= V_008DFC_SQ_EXP_PARAM + 31) 457bf215546Sopenharmony_ci fprintf(output, " param%d", exp.dest - V_008DFC_SQ_EXP_PARAM); 458bf215546Sopenharmony_ci break; 459bf215546Sopenharmony_ci } 460bf215546Sopenharmony_ci case Format::PSEUDO_BRANCH: { 461bf215546Sopenharmony_ci const Pseudo_branch_instruction& branch = instr->branch(); 462bf215546Sopenharmony_ci /* Note: BB0 cannot be a branch target */ 463bf215546Sopenharmony_ci if (branch.target[0] != 0) 464bf215546Sopenharmony_ci fprintf(output, " BB%d", branch.target[0]); 465bf215546Sopenharmony_ci if (branch.target[1] != 0) 466bf215546Sopenharmony_ci fprintf(output, ", BB%d", branch.target[1]); 467bf215546Sopenharmony_ci break; 468bf215546Sopenharmony_ci } 469bf215546Sopenharmony_ci case Format::PSEUDO_REDUCTION: { 470bf215546Sopenharmony_ci const Pseudo_reduction_instruction& reduce = instr->reduction(); 471bf215546Sopenharmony_ci fprintf(output, " op:%s", reduce_ops[reduce.reduce_op]); 472bf215546Sopenharmony_ci if (reduce.cluster_size) 473bf215546Sopenharmony_ci fprintf(output, " cluster_size:%u", reduce.cluster_size); 474bf215546Sopenharmony_ci break; 475bf215546Sopenharmony_ci } 476bf215546Sopenharmony_ci case Format::PSEUDO_BARRIER: { 477bf215546Sopenharmony_ci const Pseudo_barrier_instruction& barrier = instr->barrier(); 478bf215546Sopenharmony_ci print_sync(barrier.sync, output); 479bf215546Sopenharmony_ci print_scope(barrier.exec_scope, output, "exec_scope"); 480bf215546Sopenharmony_ci break; 481bf215546Sopenharmony_ci } 482bf215546Sopenharmony_ci case Format::FLAT: 483bf215546Sopenharmony_ci case Format::GLOBAL: 484bf215546Sopenharmony_ci case Format::SCRATCH: { 485bf215546Sopenharmony_ci const FLAT_instruction& flat = instr->flatlike(); 486bf215546Sopenharmony_ci if (flat.offset) 487bf215546Sopenharmony_ci fprintf(output, " offset:%d", flat.offset); 488bf215546Sopenharmony_ci if (flat.glc) 489bf215546Sopenharmony_ci fprintf(output, " glc"); 490bf215546Sopenharmony_ci if (flat.dlc) 491bf215546Sopenharmony_ci fprintf(output, " dlc"); 492bf215546Sopenharmony_ci if (flat.slc) 493bf215546Sopenharmony_ci fprintf(output, " slc"); 494bf215546Sopenharmony_ci if (flat.lds) 495bf215546Sopenharmony_ci fprintf(output, " lds"); 496bf215546Sopenharmony_ci if (flat.nv) 497bf215546Sopenharmony_ci fprintf(output, " nv"); 498bf215546Sopenharmony_ci if (flat.disable_wqm) 499bf215546Sopenharmony_ci fprintf(output, " disable_wqm"); 500bf215546Sopenharmony_ci print_sync(flat.sync, output); 501bf215546Sopenharmony_ci break; 502bf215546Sopenharmony_ci } 503bf215546Sopenharmony_ci case Format::MTBUF: { 504bf215546Sopenharmony_ci const MTBUF_instruction& mtbuf = instr->mtbuf(); 505bf215546Sopenharmony_ci fprintf(output, " dfmt:"); 506bf215546Sopenharmony_ci switch (mtbuf.dfmt) { 507bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_8: fprintf(output, "8"); break; 508bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_16: fprintf(output, "16"); break; 509bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_8_8: fprintf(output, "8_8"); break; 510bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_32: fprintf(output, "32"); break; 511bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_16_16: fprintf(output, "16_16"); break; 512bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_10_11_11: fprintf(output, "10_11_11"); break; 513bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_11_11_10: fprintf(output, "11_11_10"); break; 514bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_10_10_10_2: fprintf(output, "10_10_10_2"); break; 515bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_2_10_10_10: fprintf(output, "2_10_10_10"); break; 516bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_8_8_8_8: fprintf(output, "8_8_8_8"); break; 517bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_32_32: fprintf(output, "32_32"); break; 518bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_16_16_16_16: fprintf(output, "16_16_16_16"); break; 519bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_32_32_32: fprintf(output, "32_32_32"); break; 520bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_32_32_32_32: fprintf(output, "32_32_32_32"); break; 521bf215546Sopenharmony_ci case V_008F0C_BUF_DATA_FORMAT_RESERVED_15: fprintf(output, "reserved15"); break; 522bf215546Sopenharmony_ci } 523bf215546Sopenharmony_ci fprintf(output, " nfmt:"); 524bf215546Sopenharmony_ci switch (mtbuf.nfmt) { 525bf215546Sopenharmony_ci case V_008F0C_BUF_NUM_FORMAT_UNORM: fprintf(output, "unorm"); break; 526bf215546Sopenharmony_ci case V_008F0C_BUF_NUM_FORMAT_SNORM: fprintf(output, "snorm"); break; 527bf215546Sopenharmony_ci case V_008F0C_BUF_NUM_FORMAT_USCALED: fprintf(output, "uscaled"); break; 528bf215546Sopenharmony_ci case V_008F0C_BUF_NUM_FORMAT_SSCALED: fprintf(output, "sscaled"); break; 529bf215546Sopenharmony_ci case V_008F0C_BUF_NUM_FORMAT_UINT: fprintf(output, "uint"); break; 530bf215546Sopenharmony_ci case V_008F0C_BUF_NUM_FORMAT_SINT: fprintf(output, "sint"); break; 531bf215546Sopenharmony_ci case V_008F0C_BUF_NUM_FORMAT_SNORM_OGL: fprintf(output, "snorm"); break; 532bf215546Sopenharmony_ci case V_008F0C_BUF_NUM_FORMAT_FLOAT: fprintf(output, "float"); break; 533bf215546Sopenharmony_ci } 534bf215546Sopenharmony_ci if (mtbuf.offset) 535bf215546Sopenharmony_ci fprintf(output, " offset:%u", mtbuf.offset); 536bf215546Sopenharmony_ci if (mtbuf.offen) 537bf215546Sopenharmony_ci fprintf(output, " offen"); 538bf215546Sopenharmony_ci if (mtbuf.idxen) 539bf215546Sopenharmony_ci fprintf(output, " idxen"); 540bf215546Sopenharmony_ci if (mtbuf.glc) 541bf215546Sopenharmony_ci fprintf(output, " glc"); 542bf215546Sopenharmony_ci if (mtbuf.dlc) 543bf215546Sopenharmony_ci fprintf(output, " dlc"); 544bf215546Sopenharmony_ci if (mtbuf.slc) 545bf215546Sopenharmony_ci fprintf(output, " slc"); 546bf215546Sopenharmony_ci if (mtbuf.tfe) 547bf215546Sopenharmony_ci fprintf(output, " tfe"); 548bf215546Sopenharmony_ci if (mtbuf.disable_wqm) 549bf215546Sopenharmony_ci fprintf(output, " disable_wqm"); 550bf215546Sopenharmony_ci print_sync(mtbuf.sync, output); 551bf215546Sopenharmony_ci break; 552bf215546Sopenharmony_ci } 553bf215546Sopenharmony_ci case Format::VOP3P: { 554bf215546Sopenharmony_ci if (instr->vop3p().clamp) 555bf215546Sopenharmony_ci fprintf(output, " clamp"); 556bf215546Sopenharmony_ci break; 557bf215546Sopenharmony_ci } 558bf215546Sopenharmony_ci default: { 559bf215546Sopenharmony_ci break; 560bf215546Sopenharmony_ci } 561bf215546Sopenharmony_ci } 562bf215546Sopenharmony_ci if (instr->isVOP3()) { 563bf215546Sopenharmony_ci const VOP3_instruction& vop3 = instr->vop3(); 564bf215546Sopenharmony_ci switch (vop3.omod) { 565bf215546Sopenharmony_ci case 1: fprintf(output, " *2"); break; 566bf215546Sopenharmony_ci case 2: fprintf(output, " *4"); break; 567bf215546Sopenharmony_ci case 3: fprintf(output, " *0.5"); break; 568bf215546Sopenharmony_ci } 569bf215546Sopenharmony_ci if (vop3.clamp) 570bf215546Sopenharmony_ci fprintf(output, " clamp"); 571bf215546Sopenharmony_ci if (vop3.opsel & (1 << 3)) 572bf215546Sopenharmony_ci fprintf(output, " opsel_hi"); 573bf215546Sopenharmony_ci } else if (instr->isDPP16()) { 574bf215546Sopenharmony_ci const DPP16_instruction& dpp = instr->dpp16(); 575bf215546Sopenharmony_ci if (dpp.dpp_ctrl <= 0xff) { 576bf215546Sopenharmony_ci fprintf(output, " quad_perm:[%d,%d,%d,%d]", dpp.dpp_ctrl & 0x3, (dpp.dpp_ctrl >> 2) & 0x3, 577bf215546Sopenharmony_ci (dpp.dpp_ctrl >> 4) & 0x3, (dpp.dpp_ctrl >> 6) & 0x3); 578bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl >= 0x101 && dpp.dpp_ctrl <= 0x10f) { 579bf215546Sopenharmony_ci fprintf(output, " row_shl:%d", dpp.dpp_ctrl & 0xf); 580bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl >= 0x111 && dpp.dpp_ctrl <= 0x11f) { 581bf215546Sopenharmony_ci fprintf(output, " row_shr:%d", dpp.dpp_ctrl & 0xf); 582bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl >= 0x121 && dpp.dpp_ctrl <= 0x12f) { 583bf215546Sopenharmony_ci fprintf(output, " row_ror:%d", dpp.dpp_ctrl & 0xf); 584bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl == dpp_wf_sl1) { 585bf215546Sopenharmony_ci fprintf(output, " wave_shl:1"); 586bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl == dpp_wf_rl1) { 587bf215546Sopenharmony_ci fprintf(output, " wave_rol:1"); 588bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl == dpp_wf_sr1) { 589bf215546Sopenharmony_ci fprintf(output, " wave_shr:1"); 590bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl == dpp_wf_rr1) { 591bf215546Sopenharmony_ci fprintf(output, " wave_ror:1"); 592bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl == dpp_row_mirror) { 593bf215546Sopenharmony_ci fprintf(output, " row_mirror"); 594bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl == dpp_row_half_mirror) { 595bf215546Sopenharmony_ci fprintf(output, " row_half_mirror"); 596bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl == dpp_row_bcast15) { 597bf215546Sopenharmony_ci fprintf(output, " row_bcast:15"); 598bf215546Sopenharmony_ci } else if (dpp.dpp_ctrl == dpp_row_bcast31) { 599bf215546Sopenharmony_ci fprintf(output, " row_bcast:31"); 600bf215546Sopenharmony_ci } else { 601bf215546Sopenharmony_ci fprintf(output, " dpp_ctrl:0x%.3x", dpp.dpp_ctrl); 602bf215546Sopenharmony_ci } 603bf215546Sopenharmony_ci if (dpp.row_mask != 0xf) 604bf215546Sopenharmony_ci fprintf(output, " row_mask:0x%.1x", dpp.row_mask); 605bf215546Sopenharmony_ci if (dpp.bank_mask != 0xf) 606bf215546Sopenharmony_ci fprintf(output, " bank_mask:0x%.1x", dpp.bank_mask); 607bf215546Sopenharmony_ci if (dpp.bound_ctrl) 608bf215546Sopenharmony_ci fprintf(output, " bound_ctrl:1"); 609bf215546Sopenharmony_ci } else if (instr->isDPP8()) { 610bf215546Sopenharmony_ci const DPP8_instruction& dpp = instr->dpp8(); 611bf215546Sopenharmony_ci fprintf(output, " dpp8:[%d,%d,%d,%d,%d,%d,%d,%d]", dpp.lane_sel[0], dpp.lane_sel[1], 612bf215546Sopenharmony_ci dpp.lane_sel[2], dpp.lane_sel[3], dpp.lane_sel[4], dpp.lane_sel[5], dpp.lane_sel[6], 613bf215546Sopenharmony_ci dpp.lane_sel[7]); 614bf215546Sopenharmony_ci } else if (instr->isSDWA()) { 615bf215546Sopenharmony_ci const SDWA_instruction& sdwa = instr->sdwa(); 616bf215546Sopenharmony_ci switch (sdwa.omod) { 617bf215546Sopenharmony_ci case 1: fprintf(output, " *2"); break; 618bf215546Sopenharmony_ci case 2: fprintf(output, " *4"); break; 619bf215546Sopenharmony_ci case 3: fprintf(output, " *0.5"); break; 620bf215546Sopenharmony_ci } 621bf215546Sopenharmony_ci if (sdwa.clamp) 622bf215546Sopenharmony_ci fprintf(output, " clamp"); 623bf215546Sopenharmony_ci if (!instr->isVOPC()) { 624bf215546Sopenharmony_ci char sext = sdwa.dst_sel.sign_extend() ? 's' : 'u'; 625bf215546Sopenharmony_ci unsigned offset = sdwa.dst_sel.offset(); 626bf215546Sopenharmony_ci if (instr->definitions[0].isFixed()) 627bf215546Sopenharmony_ci offset += instr->definitions[0].physReg().byte(); 628bf215546Sopenharmony_ci switch (sdwa.dst_sel.size()) { 629bf215546Sopenharmony_ci case 1: fprintf(output, " dst_sel:%cbyte%u", sext, offset); break; 630bf215546Sopenharmony_ci case 2: fprintf(output, " dst_sel:%cword%u", sext, offset >> 1); break; 631bf215546Sopenharmony_ci case 4: fprintf(output, " dst_sel:dword"); break; 632bf215546Sopenharmony_ci default: break; 633bf215546Sopenharmony_ci } 634bf215546Sopenharmony_ci if (instr->definitions[0].bytes() < 4) 635bf215546Sopenharmony_ci fprintf(output, " dst_preserve"); 636bf215546Sopenharmony_ci } 637bf215546Sopenharmony_ci for (unsigned i = 0; i < std::min<unsigned>(2, instr->operands.size()); i++) { 638bf215546Sopenharmony_ci char sext = sdwa.sel[i].sign_extend() ? 's' : 'u'; 639bf215546Sopenharmony_ci unsigned offset = sdwa.sel[i].offset(); 640bf215546Sopenharmony_ci if (instr->operands[i].isFixed()) 641bf215546Sopenharmony_ci offset += instr->operands[i].physReg().byte(); 642bf215546Sopenharmony_ci switch (sdwa.sel[i].size()) { 643bf215546Sopenharmony_ci case 1: fprintf(output, " src%d_sel:%cbyte%u", i, sext, offset); break; 644bf215546Sopenharmony_ci case 2: fprintf(output, " src%d_sel:%cword%u", i, sext, offset >> 1); break; 645bf215546Sopenharmony_ci case 4: fprintf(output, " src%d_sel:dword", i); break; 646bf215546Sopenharmony_ci default: break; 647bf215546Sopenharmony_ci } 648bf215546Sopenharmony_ci } 649bf215546Sopenharmony_ci } 650bf215546Sopenharmony_ci} 651bf215546Sopenharmony_ci 652bf215546Sopenharmony_civoid 653bf215546Sopenharmony_ciaco_print_instr(const Instruction* instr, FILE* output, unsigned flags) 654bf215546Sopenharmony_ci{ 655bf215546Sopenharmony_ci if (!instr->definitions.empty()) { 656bf215546Sopenharmony_ci for (unsigned i = 0; i < instr->definitions.size(); ++i) { 657bf215546Sopenharmony_ci print_definition(&instr->definitions[i], output, flags); 658bf215546Sopenharmony_ci if (i + 1 != instr->definitions.size()) 659bf215546Sopenharmony_ci fprintf(output, ", "); 660bf215546Sopenharmony_ci } 661bf215546Sopenharmony_ci fprintf(output, " = "); 662bf215546Sopenharmony_ci } 663bf215546Sopenharmony_ci fprintf(output, "%s", instr_info.name[(int)instr->opcode]); 664bf215546Sopenharmony_ci if (instr->operands.size()) { 665bf215546Sopenharmony_ci const unsigned num_operands = instr->operands.size(); 666bf215546Sopenharmony_ci bool* const abs = (bool*)alloca(num_operands * sizeof(bool)); 667bf215546Sopenharmony_ci bool* const neg = (bool*)alloca(num_operands * sizeof(bool)); 668bf215546Sopenharmony_ci bool* const opsel = (bool*)alloca(num_operands * sizeof(bool)); 669bf215546Sopenharmony_ci bool* const f2f32 = (bool*)alloca(num_operands * sizeof(bool)); 670bf215546Sopenharmony_ci for (unsigned i = 0; i < num_operands; ++i) { 671bf215546Sopenharmony_ci abs[i] = false; 672bf215546Sopenharmony_ci neg[i] = false; 673bf215546Sopenharmony_ci opsel[i] = false; 674bf215546Sopenharmony_ci f2f32[i] = false; 675bf215546Sopenharmony_ci } 676bf215546Sopenharmony_ci bool is_mad_mix = instr->opcode == aco_opcode::v_fma_mix_f32 || 677bf215546Sopenharmony_ci instr->opcode == aco_opcode::v_fma_mixlo_f16 || 678bf215546Sopenharmony_ci instr->opcode == aco_opcode::v_fma_mixhi_f16; 679bf215546Sopenharmony_ci if (instr->isVOP3()) { 680bf215546Sopenharmony_ci const VOP3_instruction& vop3 = instr->vop3(); 681bf215546Sopenharmony_ci for (unsigned i = 0; i < MIN2(num_operands, 3); ++i) { 682bf215546Sopenharmony_ci abs[i] = vop3.abs[i]; 683bf215546Sopenharmony_ci neg[i] = vop3.neg[i]; 684bf215546Sopenharmony_ci opsel[i] = vop3.opsel & (1 << i); 685bf215546Sopenharmony_ci } 686bf215546Sopenharmony_ci } else if (instr->isDPP16()) { 687bf215546Sopenharmony_ci const DPP16_instruction& dpp = instr->dpp16(); 688bf215546Sopenharmony_ci for (unsigned i = 0; i < MIN2(num_operands, 2); ++i) { 689bf215546Sopenharmony_ci abs[i] = dpp.abs[i]; 690bf215546Sopenharmony_ci neg[i] = dpp.neg[i]; 691bf215546Sopenharmony_ci opsel[i] = false; 692bf215546Sopenharmony_ci } 693bf215546Sopenharmony_ci } else if (instr->isSDWA()) { 694bf215546Sopenharmony_ci const SDWA_instruction& sdwa = instr->sdwa(); 695bf215546Sopenharmony_ci for (unsigned i = 0; i < MIN2(num_operands, 2); ++i) { 696bf215546Sopenharmony_ci abs[i] = sdwa.abs[i]; 697bf215546Sopenharmony_ci neg[i] = sdwa.neg[i]; 698bf215546Sopenharmony_ci opsel[i] = false; 699bf215546Sopenharmony_ci } 700bf215546Sopenharmony_ci } else if (instr->isVOP3P() && is_mad_mix) { 701bf215546Sopenharmony_ci const VOP3P_instruction& vop3p = instr->vop3p(); 702bf215546Sopenharmony_ci for (unsigned i = 0; i < MIN2(num_operands, 3); ++i) { 703bf215546Sopenharmony_ci abs[i] = vop3p.neg_hi[i]; 704bf215546Sopenharmony_ci neg[i] = vop3p.neg_lo[i]; 705bf215546Sopenharmony_ci f2f32[i] = vop3p.opsel_hi & (1 << i); 706bf215546Sopenharmony_ci opsel[i] = f2f32[i] && (vop3p.opsel_lo & (1 << i)); 707bf215546Sopenharmony_ci } 708bf215546Sopenharmony_ci } 709bf215546Sopenharmony_ci for (unsigned i = 0; i < num_operands; ++i) { 710bf215546Sopenharmony_ci if (i) 711bf215546Sopenharmony_ci fprintf(output, ", "); 712bf215546Sopenharmony_ci else 713bf215546Sopenharmony_ci fprintf(output, " "); 714bf215546Sopenharmony_ci 715bf215546Sopenharmony_ci if (neg[i]) 716bf215546Sopenharmony_ci fprintf(output, "-"); 717bf215546Sopenharmony_ci if (abs[i]) 718bf215546Sopenharmony_ci fprintf(output, "|"); 719bf215546Sopenharmony_ci if (opsel[i]) 720bf215546Sopenharmony_ci fprintf(output, "hi("); 721bf215546Sopenharmony_ci else if (f2f32[i]) 722bf215546Sopenharmony_ci fprintf(output, "lo("); 723bf215546Sopenharmony_ci aco_print_operand(&instr->operands[i], output, flags); 724bf215546Sopenharmony_ci if (f2f32[i] || opsel[i]) 725bf215546Sopenharmony_ci fprintf(output, ")"); 726bf215546Sopenharmony_ci if (abs[i]) 727bf215546Sopenharmony_ci fprintf(output, "|"); 728bf215546Sopenharmony_ci 729bf215546Sopenharmony_ci if (instr->isVOP3P() && !is_mad_mix) { 730bf215546Sopenharmony_ci const VOP3P_instruction& vop3 = instr->vop3p(); 731bf215546Sopenharmony_ci if ((vop3.opsel_lo & (1 << i)) || !(vop3.opsel_hi & (1 << i))) { 732bf215546Sopenharmony_ci fprintf(output, ".%c%c", vop3.opsel_lo & (1 << i) ? 'y' : 'x', 733bf215546Sopenharmony_ci vop3.opsel_hi & (1 << i) ? 'y' : 'x'); 734bf215546Sopenharmony_ci } 735bf215546Sopenharmony_ci if (vop3.neg_lo[i] && vop3.neg_hi[i]) 736bf215546Sopenharmony_ci fprintf(output, "*[-1,-1]"); 737bf215546Sopenharmony_ci else if (vop3.neg_lo[i]) 738bf215546Sopenharmony_ci fprintf(output, "*[-1,1]"); 739bf215546Sopenharmony_ci else if (vop3.neg_hi[i]) 740bf215546Sopenharmony_ci fprintf(output, "*[1,-1]"); 741bf215546Sopenharmony_ci } 742bf215546Sopenharmony_ci } 743bf215546Sopenharmony_ci } 744bf215546Sopenharmony_ci print_instr_format_specific(instr, output); 745bf215546Sopenharmony_ci} 746bf215546Sopenharmony_ci 747bf215546Sopenharmony_cistatic void 748bf215546Sopenharmony_ciprint_block_kind(uint16_t kind, FILE* output) 749bf215546Sopenharmony_ci{ 750bf215546Sopenharmony_ci if (kind & block_kind_uniform) 751bf215546Sopenharmony_ci fprintf(output, "uniform, "); 752bf215546Sopenharmony_ci if (kind & block_kind_top_level) 753bf215546Sopenharmony_ci fprintf(output, "top-level, "); 754bf215546Sopenharmony_ci if (kind & block_kind_loop_preheader) 755bf215546Sopenharmony_ci fprintf(output, "loop-preheader, "); 756bf215546Sopenharmony_ci if (kind & block_kind_loop_header) 757bf215546Sopenharmony_ci fprintf(output, "loop-header, "); 758bf215546Sopenharmony_ci if (kind & block_kind_loop_exit) 759bf215546Sopenharmony_ci fprintf(output, "loop-exit, "); 760bf215546Sopenharmony_ci if (kind & block_kind_continue) 761bf215546Sopenharmony_ci fprintf(output, "continue, "); 762bf215546Sopenharmony_ci if (kind & block_kind_break) 763bf215546Sopenharmony_ci fprintf(output, "break, "); 764bf215546Sopenharmony_ci if (kind & block_kind_continue_or_break) 765bf215546Sopenharmony_ci fprintf(output, "continue_or_break, "); 766bf215546Sopenharmony_ci if (kind & block_kind_branch) 767bf215546Sopenharmony_ci fprintf(output, "branch, "); 768bf215546Sopenharmony_ci if (kind & block_kind_merge) 769bf215546Sopenharmony_ci fprintf(output, "merge, "); 770bf215546Sopenharmony_ci if (kind & block_kind_invert) 771bf215546Sopenharmony_ci fprintf(output, "invert, "); 772bf215546Sopenharmony_ci if (kind & block_kind_uses_discard) 773bf215546Sopenharmony_ci fprintf(output, "discard, "); 774bf215546Sopenharmony_ci if (kind & block_kind_needs_lowering) 775bf215546Sopenharmony_ci fprintf(output, "needs_lowering, "); 776bf215546Sopenharmony_ci if (kind & block_kind_export_end) 777bf215546Sopenharmony_ci fprintf(output, "export_end, "); 778bf215546Sopenharmony_ci} 779bf215546Sopenharmony_ci 780bf215546Sopenharmony_cistatic void 781bf215546Sopenharmony_ciprint_stage(Stage stage, FILE* output) 782bf215546Sopenharmony_ci{ 783bf215546Sopenharmony_ci fprintf(output, "ACO shader stage: "); 784bf215546Sopenharmony_ci 785bf215546Sopenharmony_ci if (stage == compute_cs) 786bf215546Sopenharmony_ci fprintf(output, "compute_cs"); 787bf215546Sopenharmony_ci else if (stage == fragment_fs) 788bf215546Sopenharmony_ci fprintf(output, "fragment_fs"); 789bf215546Sopenharmony_ci else if (stage == gs_copy_vs) 790bf215546Sopenharmony_ci fprintf(output, "gs_copy_vs"); 791bf215546Sopenharmony_ci else if (stage == vertex_ls) 792bf215546Sopenharmony_ci fprintf(output, "vertex_ls"); 793bf215546Sopenharmony_ci else if (stage == vertex_es) 794bf215546Sopenharmony_ci fprintf(output, "vertex_es"); 795bf215546Sopenharmony_ci else if (stage == vertex_vs) 796bf215546Sopenharmony_ci fprintf(output, "vertex_vs"); 797bf215546Sopenharmony_ci else if (stage == tess_control_hs) 798bf215546Sopenharmony_ci fprintf(output, "tess_control_hs"); 799bf215546Sopenharmony_ci else if (stage == vertex_tess_control_hs) 800bf215546Sopenharmony_ci fprintf(output, "vertex_tess_control_hs"); 801bf215546Sopenharmony_ci else if (stage == tess_eval_es) 802bf215546Sopenharmony_ci fprintf(output, "tess_eval_es"); 803bf215546Sopenharmony_ci else if (stage == tess_eval_vs) 804bf215546Sopenharmony_ci fprintf(output, "tess_eval_vs"); 805bf215546Sopenharmony_ci else if (stage == geometry_gs) 806bf215546Sopenharmony_ci fprintf(output, "geometry_gs"); 807bf215546Sopenharmony_ci else if (stage == vertex_geometry_gs) 808bf215546Sopenharmony_ci fprintf(output, "vertex_geometry_gs"); 809bf215546Sopenharmony_ci else if (stage == tess_eval_geometry_gs) 810bf215546Sopenharmony_ci fprintf(output, "tess_eval_geometry_gs"); 811bf215546Sopenharmony_ci else if (stage == vertex_ngg) 812bf215546Sopenharmony_ci fprintf(output, "vertex_ngg"); 813bf215546Sopenharmony_ci else if (stage == tess_eval_ngg) 814bf215546Sopenharmony_ci fprintf(output, "tess_eval_ngg"); 815bf215546Sopenharmony_ci else if (stage == vertex_geometry_ngg) 816bf215546Sopenharmony_ci fprintf(output, "vertex_geometry_ngg"); 817bf215546Sopenharmony_ci else if (stage == tess_eval_geometry_ngg) 818bf215546Sopenharmony_ci fprintf(output, "tess_eval_geometry_ngg"); 819bf215546Sopenharmony_ci else if (stage == mesh_ngg) 820bf215546Sopenharmony_ci fprintf(output, "mesh_ngg"); 821bf215546Sopenharmony_ci else if (stage == task_cs) 822bf215546Sopenharmony_ci fprintf(output, "task_cs"); 823bf215546Sopenharmony_ci else 824bf215546Sopenharmony_ci fprintf(output, "unknown"); 825bf215546Sopenharmony_ci 826bf215546Sopenharmony_ci fprintf(output, "\n"); 827bf215546Sopenharmony_ci} 828bf215546Sopenharmony_ci 829bf215546Sopenharmony_civoid 830bf215546Sopenharmony_ciaco_print_block(const Block* block, FILE* output, unsigned flags, const live& live_vars) 831bf215546Sopenharmony_ci{ 832bf215546Sopenharmony_ci fprintf(output, "BB%d\n", block->index); 833bf215546Sopenharmony_ci fprintf(output, "/* logical preds: "); 834bf215546Sopenharmony_ci for (unsigned pred : block->logical_preds) 835bf215546Sopenharmony_ci fprintf(output, "BB%d, ", pred); 836bf215546Sopenharmony_ci fprintf(output, "/ linear preds: "); 837bf215546Sopenharmony_ci for (unsigned pred : block->linear_preds) 838bf215546Sopenharmony_ci fprintf(output, "BB%d, ", pred); 839bf215546Sopenharmony_ci fprintf(output, "/ kind: "); 840bf215546Sopenharmony_ci print_block_kind(block->kind, output); 841bf215546Sopenharmony_ci fprintf(output, "*/\n"); 842bf215546Sopenharmony_ci 843bf215546Sopenharmony_ci if (flags & print_live_vars) { 844bf215546Sopenharmony_ci fprintf(output, "\tlive out:"); 845bf215546Sopenharmony_ci for (unsigned id : live_vars.live_out[block->index]) 846bf215546Sopenharmony_ci fprintf(output, " %%%d", id); 847bf215546Sopenharmony_ci fprintf(output, "\n"); 848bf215546Sopenharmony_ci 849bf215546Sopenharmony_ci RegisterDemand demand = block->register_demand; 850bf215546Sopenharmony_ci fprintf(output, "\tdemand: %u vgpr, %u sgpr\n", demand.vgpr, demand.sgpr); 851bf215546Sopenharmony_ci } 852bf215546Sopenharmony_ci 853bf215546Sopenharmony_ci unsigned index = 0; 854bf215546Sopenharmony_ci for (auto const& instr : block->instructions) { 855bf215546Sopenharmony_ci fprintf(output, "\t"); 856bf215546Sopenharmony_ci if (flags & print_live_vars) { 857bf215546Sopenharmony_ci RegisterDemand demand = live_vars.register_demand[block->index][index]; 858bf215546Sopenharmony_ci fprintf(output, "(%3u vgpr, %3u sgpr) ", demand.vgpr, demand.sgpr); 859bf215546Sopenharmony_ci } 860bf215546Sopenharmony_ci if (flags & print_perf_info) 861bf215546Sopenharmony_ci fprintf(output, "(%3u clk) ", instr->pass_flags); 862bf215546Sopenharmony_ci 863bf215546Sopenharmony_ci aco_print_instr(instr.get(), output, flags); 864bf215546Sopenharmony_ci fprintf(output, "\n"); 865bf215546Sopenharmony_ci index++; 866bf215546Sopenharmony_ci } 867bf215546Sopenharmony_ci} 868bf215546Sopenharmony_ci 869bf215546Sopenharmony_civoid 870bf215546Sopenharmony_ciaco_print_program(const Program* program, FILE* output, const live& live_vars, unsigned flags) 871bf215546Sopenharmony_ci{ 872bf215546Sopenharmony_ci switch (program->progress) { 873bf215546Sopenharmony_ci case CompilationProgress::after_isel: fprintf(output, "After Instruction Selection:\n"); break; 874bf215546Sopenharmony_ci case CompilationProgress::after_spilling: 875bf215546Sopenharmony_ci fprintf(output, "After Spilling:\n"); 876bf215546Sopenharmony_ci flags |= print_kill; 877bf215546Sopenharmony_ci break; 878bf215546Sopenharmony_ci case CompilationProgress::after_ra: fprintf(output, "After RA:\n"); break; 879bf215546Sopenharmony_ci } 880bf215546Sopenharmony_ci 881bf215546Sopenharmony_ci print_stage(program->stage, output); 882bf215546Sopenharmony_ci 883bf215546Sopenharmony_ci for (Block const& block : program->blocks) 884bf215546Sopenharmony_ci aco_print_block(&block, output, flags, live_vars); 885bf215546Sopenharmony_ci 886bf215546Sopenharmony_ci if (program->constant_data.size()) { 887bf215546Sopenharmony_ci fprintf(output, "\n/* constant data */\n"); 888bf215546Sopenharmony_ci for (unsigned i = 0; i < program->constant_data.size(); i += 32) { 889bf215546Sopenharmony_ci fprintf(output, "[%06d] ", i); 890bf215546Sopenharmony_ci unsigned line_size = std::min<size_t>(program->constant_data.size() - i, 32); 891bf215546Sopenharmony_ci for (unsigned j = 0; j < line_size; j += 4) { 892bf215546Sopenharmony_ci unsigned size = std::min<size_t>(program->constant_data.size() - (i + j), 4); 893bf215546Sopenharmony_ci uint32_t v = 0; 894bf215546Sopenharmony_ci memcpy(&v, &program->constant_data[i + j], size); 895bf215546Sopenharmony_ci fprintf(output, " %08x", v); 896bf215546Sopenharmony_ci } 897bf215546Sopenharmony_ci fprintf(output, "\n"); 898bf215546Sopenharmony_ci } 899bf215546Sopenharmony_ci } 900bf215546Sopenharmony_ci 901bf215546Sopenharmony_ci fprintf(output, "\n"); 902bf215546Sopenharmony_ci} 903bf215546Sopenharmony_ci 904bf215546Sopenharmony_civoid 905bf215546Sopenharmony_ciaco_print_program(const Program* program, FILE* output, unsigned flags) 906bf215546Sopenharmony_ci{ 907bf215546Sopenharmony_ci aco_print_program(program, output, live(), flags); 908bf215546Sopenharmony_ci} 909bf215546Sopenharmony_ci 910bf215546Sopenharmony_ci} // namespace aco 911