| 1 | //===-- AMDGPUInstPrinter.cpp - AMDGPU MC Inst -> ASM ---------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | // \file |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "AMDGPUInstPrinter.h" |
| 11 | #include "MCTargetDesc/AMDGPUMCTargetDesc.h" |
| 12 | #include "SIDefines.h" |
| 13 | #include "Utils/AMDGPUAsmUtils.h" |
| 14 | #include "Utils/AMDGPUBaseInfo.h" |
| 15 | #include "llvm/ADT/StringExtras.h" |
| 16 | #include "llvm/MC/MCAsmInfo.h" |
| 17 | #include "llvm/MC/MCExpr.h" |
| 18 | #include "llvm/MC/MCInst.h" |
| 19 | #include "llvm/MC/MCInstrDesc.h" |
| 20 | #include "llvm/MC/MCInstrInfo.h" |
| 21 | #include "llvm/MC/MCRegisterInfo.h" |
| 22 | #include "llvm/MC/MCSubtargetInfo.h" |
| 23 | #include "llvm/TargetParser/AMDGPUTargetParser.h" |
| 24 | |
| 25 | using namespace llvm; |
| 26 | using namespace llvm::AMDGPU; |
| 27 | |
| 28 | void AMDGPUInstPrinter::printRegName(raw_ostream &OS, MCRegister Reg) { |
| 29 | // FIXME: The current implementation of |
| 30 | // AsmParser::parseRegisterOrRegisterNumber in MC implies we either emit this |
| 31 | // as an integer or we provide a name which represents a physical register. |
| 32 | // For CFI instructions we really want to emit a name for the DWARF register |
| 33 | // instead, because there may be multiple DWARF registers corresponding to a |
| 34 | // single physical register. One case where this problem manifests is with |
| 35 | // wave32/wave64 where using the physical register name is ambiguous: if we |
| 36 | // write e.g. `.cfi_undefined v0` we lose information about the wavefront |
| 37 | // size which we need to encode the register in the final DWARF. Ideally we |
| 38 | // would extend MC to support parsing DWARF register names so we could do |
| 39 | // something like `.cfi_undefined dwarf_wave32_v0`. For now we just live with |
| 40 | // non-pretty DWARF register names in assembly text. |
| 41 | OS << Reg.id(); |
| 42 | } |
| 43 | |
| 44 | void AMDGPUInstPrinter::printInst(const MCInst *MI, uint64_t Address, |
| 45 | StringRef Annot, const MCSubtargetInfo &STI, |
| 46 | raw_ostream &OS) { |
| 47 | printInstruction(MI, Address, STI, O&: OS); |
| 48 | printAnnotation(OS, Annot); |
| 49 | } |
| 50 | |
| 51 | void AMDGPUInstPrinter::printU16ImmOperand(const MCInst *MI, unsigned OpNo, |
| 52 | const MCSubtargetInfo &STI, |
| 53 | raw_ostream &O) { |
| 54 | const MCOperand &Op = MI->getOperand(i: OpNo); |
| 55 | if (Op.isExpr()) { |
| 56 | MAI.printExpr(O, *Op.getExpr()); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | // It's possible to end up with a 32-bit literal used with a 16-bit operand |
| 61 | // with ignored high bits. Print as 32-bit anyway in that case. |
| 62 | int64_t Imm = Op.getImm(); |
| 63 | if (isInt<16>(x: Imm) || isUInt<16>(x: Imm)) |
| 64 | O << formatHex(Value: static_cast<uint64_t>(Imm & 0xffff)); |
| 65 | else |
| 66 | printU32ImmOperand(MI, OpNo, STI, O); |
| 67 | } |
| 68 | |
| 69 | void AMDGPUInstPrinter::printU16ImmDecOperand(const MCInst *MI, unsigned OpNo, |
| 70 | raw_ostream &O) { |
| 71 | O << formatDec(Value: MI->getOperand(i: OpNo).getImm() & 0xffff); |
| 72 | } |
| 73 | |
| 74 | void AMDGPUInstPrinter::printU32ImmOperand(const MCInst *MI, unsigned OpNo, |
| 75 | const MCSubtargetInfo &STI, |
| 76 | raw_ostream &O) { |
| 77 | const MCOperand &Op = MI->getOperand(i: OpNo); |
| 78 | if (Op.isExpr()) { |
| 79 | MAI.printExpr(O, *Op.getExpr()); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | O << formatHex(Value: Op.getImm() & 0xffffffff); |
| 84 | } |
| 85 | |
| 86 | void AMDGPUInstPrinter::printFP64ImmOperand(const MCInst *MI, unsigned OpNo, |
| 87 | const MCSubtargetInfo &STI, |
| 88 | raw_ostream &O) { |
| 89 | // KIMM64 |
| 90 | const MCOperand &Op = MI->getOperand(i: OpNo); |
| 91 | if (Op.isExpr()) { |
| 92 | MAI.printExpr(O, *Op.getExpr()); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | printLiteral64(Imm: Op.getImm(), O, /*IsFP=*/true); |
| 97 | } |
| 98 | |
| 99 | void AMDGPUInstPrinter::printNamedBit(const MCInst *MI, unsigned OpNo, |
| 100 | raw_ostream &O, StringRef BitName) { |
| 101 | if (MI->getOperand(i: OpNo).getImm()) { |
| 102 | O << ' ' << BitName; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | void AMDGPUInstPrinter::printOffset(const MCInst *MI, unsigned OpNo, |
| 107 | const MCSubtargetInfo &STI, |
| 108 | raw_ostream &O) { |
| 109 | uint32_t Imm = MI->getOperand(i: OpNo).getImm(); |
| 110 | if (Imm != 0) { |
| 111 | O << " offset:" ; |
| 112 | |
| 113 | // GFX12+ uses a 24-bit signed offset for VBUFFER. |
| 114 | bool IsVBuffer = SIInstrFlags::isBuffer(O: MII, O: *MI); |
| 115 | if (IsVBuffer && AMDGPU::isGFX12Plus(STI)) |
| 116 | O << formatDec(Value: SignExtend32<24>(X: Imm)); |
| 117 | else |
| 118 | printU16ImmDecOperand(MI, OpNo, O); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | void AMDGPUInstPrinter::printFlatOffset(const MCInst *MI, unsigned OpNo, |
| 123 | const MCSubtargetInfo &STI, |
| 124 | raw_ostream &O) { |
| 125 | uint32_t Imm = MI->getOperand(i: OpNo).getImm(); |
| 126 | if (Imm != 0) { |
| 127 | O << " offset:" ; |
| 128 | |
| 129 | bool AllowNegative = SIInstrFlags::isSegmentSpecificFLAT(O: MII, O: *MI) || |
| 130 | STI.hasFeature(Feature: AMDGPU::FeatureFlatSignedOffset); |
| 131 | |
| 132 | if (AllowNegative) // Signed offset |
| 133 | O << formatDec(Value: SignExtend32(X: Imm, B: AMDGPU::getNumFlatOffsetBits(ST: STI))); |
| 134 | else // Unsigned offset |
| 135 | printU16ImmDecOperand(MI, OpNo, O); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | void AMDGPUInstPrinter::printSMRDOffset8(const MCInst *MI, unsigned OpNo, |
| 140 | const MCSubtargetInfo &STI, |
| 141 | raw_ostream &O) { |
| 142 | printU32ImmOperand(MI, OpNo, STI, O); |
| 143 | } |
| 144 | |
| 145 | void AMDGPUInstPrinter::printSMEMOffset(const MCInst *MI, unsigned OpNo, |
| 146 | const MCSubtargetInfo &STI, |
| 147 | raw_ostream &O) { |
| 148 | O << formatHex(Value: MI->getOperand(i: OpNo).getImm()); |
| 149 | } |
| 150 | |
| 151 | void AMDGPUInstPrinter::printSMRDLiteralOffset(const MCInst *MI, unsigned OpNo, |
| 152 | const MCSubtargetInfo &STI, |
| 153 | raw_ostream &O) { |
| 154 | printU32ImmOperand(MI, OpNo, STI, O); |
| 155 | } |
| 156 | |
| 157 | void AMDGPUInstPrinter::printCPol(const MCInst *MI, unsigned OpNo, |
| 158 | const MCSubtargetInfo &STI, raw_ostream &O) { |
| 159 | auto Imm = MI->getOperand(i: OpNo).getImm(); |
| 160 | |
| 161 | if (AMDGPU::isGFX12Plus(STI)) { |
| 162 | const int64_t TH = Imm & CPol::TH; |
| 163 | const int64_t Scope = Imm & CPol::SCOPE; |
| 164 | |
| 165 | if (Imm & CPol::SCAL) |
| 166 | O << " scale_offset" ; |
| 167 | |
| 168 | printTH(MI, TH, Scope, O); |
| 169 | printScope(Scope, O); |
| 170 | |
| 171 | if (Imm & CPol::NV) |
| 172 | O << " nv" ; |
| 173 | |
| 174 | if (STI.hasFeature(Feature: AMDGPU::FeatureCacheFillSize)) { |
| 175 | const int64_t CFS = Imm & CPol::CFS; |
| 176 | printCFS(CFS, O); |
| 177 | } |
| 178 | |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | if (Imm & CPol::GLC) |
| 183 | O << ((AMDGPU::isGFX940(STI) && !SIInstrFlags::isSMRD(O: MII, O: *MI)) ? " sc0" |
| 184 | : " glc" ); |
| 185 | if (Imm & CPol::SLC) |
| 186 | O << (AMDGPU::isGFX940(STI) ? " nt" : " slc" ); |
| 187 | if ((Imm & CPol::DLC) && AMDGPU::isGFX10Plus(STI)) |
| 188 | O << " dlc" ; |
| 189 | if ((Imm & CPol::SCC) && AMDGPU::isGFX90A(STI)) |
| 190 | O << (AMDGPU::isGFX940(STI) ? " sc1" : " scc" ); |
| 191 | if (Imm & ~CPol::ALL_pregfx12) |
| 192 | O << " /* unexpected cache policy bit */" ; |
| 193 | } |
| 194 | |
| 195 | void AMDGPUInstPrinter::printTH(const MCInst *MI, int64_t TH, int64_t Scope, |
| 196 | raw_ostream &O) { |
| 197 | // For th = 0 do not print this field |
| 198 | if (TH == 0) |
| 199 | return; |
| 200 | |
| 201 | const unsigned Opcode = MI->getOpcode(); |
| 202 | const MCInstrDesc &TID = MII.get(Opcode); |
| 203 | unsigned THType = AMDGPU::getTemporalHintType(TID); |
| 204 | bool IsStore = (THType == AMDGPU::CPol::TH_TYPE_STORE); |
| 205 | |
| 206 | O << " th:" ; |
| 207 | |
| 208 | if (THType == AMDGPU::CPol::TH_TYPE_ATOMIC) { |
| 209 | O << "TH_ATOMIC_" ; |
| 210 | if (TH & AMDGPU::CPol::TH_ATOMIC_CASCADE) { |
| 211 | if (Scope >= AMDGPU::CPol::SCOPE_DEV) |
| 212 | O << "CASCADE" << (TH & AMDGPU::CPol::TH_ATOMIC_NT ? "_NT" : "_RT" ); |
| 213 | else |
| 214 | O << formatHex(Value: TH); |
| 215 | } else if (TH & AMDGPU::CPol::TH_ATOMIC_NT) |
| 216 | O << "NT" << (TH & AMDGPU::CPol::TH_ATOMIC_RETURN ? "_RETURN" : "" ); |
| 217 | else if (TH & AMDGPU::CPol::TH_ATOMIC_RETURN) |
| 218 | O << "RETURN" ; |
| 219 | else |
| 220 | O << formatHex(Value: TH); |
| 221 | } else { |
| 222 | if (!IsStore && TH == AMDGPU::CPol::TH_RESERVED) |
| 223 | O << formatHex(Value: TH); |
| 224 | else { |
| 225 | O << (IsStore ? "TH_STORE_" : "TH_LOAD_" ); |
| 226 | switch (TH) { |
| 227 | case AMDGPU::CPol::TH_NT: |
| 228 | O << "NT" ; |
| 229 | break; |
| 230 | case AMDGPU::CPol::TH_HT: |
| 231 | O << "HT" ; |
| 232 | break; |
| 233 | case AMDGPU::CPol::TH_BYPASS: // or LU or WB |
| 234 | O << (Scope == AMDGPU::CPol::SCOPE_SYS ? "BYPASS" |
| 235 | : (IsStore ? "WB" : "LU" )); |
| 236 | break; |
| 237 | case AMDGPU::CPol::TH_NT_RT: |
| 238 | O << "NT_RT" ; |
| 239 | break; |
| 240 | case AMDGPU::CPol::TH_RT_NT: |
| 241 | O << "RT_NT" ; |
| 242 | break; |
| 243 | case AMDGPU::CPol::TH_NT_HT: |
| 244 | O << "NT_HT" ; |
| 245 | break; |
| 246 | case AMDGPU::CPol::TH_NT_WB: |
| 247 | O << "NT_WB" ; |
| 248 | break; |
| 249 | default: |
| 250 | llvm_unreachable("unexpected th value" ); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | void AMDGPUInstPrinter::printScope(int64_t Scope, raw_ostream &O) { |
| 257 | if (Scope == CPol::SCOPE_CU) |
| 258 | return; |
| 259 | |
| 260 | O << " scope:" ; |
| 261 | |
| 262 | if (Scope == CPol::SCOPE_SE) |
| 263 | O << "SCOPE_SE" ; |
| 264 | else if (Scope == CPol::SCOPE_DEV) |
| 265 | O << "SCOPE_DEV" ; |
| 266 | else if (Scope == CPol::SCOPE_SYS) |
| 267 | O << "SCOPE_SYS" ; |
| 268 | else |
| 269 | llvm_unreachable("unexpected scope policy value" ); |
| 270 | } |
| 271 | |
| 272 | void AMDGPUInstPrinter::printCFS(int64_t CFS, raw_ostream &O) { |
| 273 | if (CFS == CPol::CFS_256B) |
| 274 | return; |
| 275 | |
| 276 | O << " cfs:" ; |
| 277 | |
| 278 | switch (CFS) { |
| 279 | case CPol::CFS_128B: |
| 280 | O << "CFS_128B" ; |
| 281 | break; |
| 282 | case CPol::CFS_64B: |
| 283 | O << "CFS_64B" ; |
| 284 | break; |
| 285 | case CPol::CFS_32B: |
| 286 | O << "CFS_32B" ; |
| 287 | break; |
| 288 | default: |
| 289 | llvm_unreachable("unexpected cache fill size value" ); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | void AMDGPUInstPrinter::printDim(const MCInst *MI, unsigned OpNo, |
| 294 | const MCSubtargetInfo &STI, raw_ostream &O) { |
| 295 | unsigned Dim = MI->getOperand(i: OpNo).getImm(); |
| 296 | O << " dim:SQ_RSRC_IMG_" ; |
| 297 | |
| 298 | const AMDGPU::MIMGDimInfo *DimInfo = AMDGPU::getMIMGDimInfoByEncoding(DimEnc: Dim); |
| 299 | if (DimInfo) |
| 300 | O << AMDGPU::getMIMGDimInfoStr(DimInfo->AsmSuffix); |
| 301 | else |
| 302 | O << Dim; |
| 303 | } |
| 304 | |
| 305 | void AMDGPUInstPrinter::printR128A16(const MCInst *MI, unsigned OpNo, |
| 306 | const MCSubtargetInfo &STI, raw_ostream &O) { |
| 307 | if (STI.hasFeature(Feature: AMDGPU::FeatureR128A16)) |
| 308 | printNamedBit(MI, OpNo, O, BitName: "a16" ); |
| 309 | else |
| 310 | printNamedBit(MI, OpNo, O, BitName: "r128" ); |
| 311 | } |
| 312 | |
| 313 | void AMDGPUInstPrinter::printFormat(const MCInst *MI, unsigned OpNo, |
| 314 | const MCSubtargetInfo &STI, |
| 315 | raw_ostream &O) { |
| 316 | using namespace llvm::AMDGPU::MTBUFFormat; |
| 317 | |
| 318 | unsigned Val = MI->getOperand(i: OpNo).getImm(); |
| 319 | if (AMDGPU::isGFX10Plus(STI)) { |
| 320 | if (Val == UFMT_DEFAULT) |
| 321 | return; |
| 322 | if (isValidUnifiedFormat(Val, STI)) { |
| 323 | O << " format:[" << getUnifiedFormatName(Id: Val, STI) << ']'; |
| 324 | } else { |
| 325 | O << " format:" << Val; |
| 326 | } |
| 327 | } else { |
| 328 | if (Val == DFMT_NFMT_DEFAULT) |
| 329 | return; |
| 330 | if (isValidDfmtNfmt(Val, STI)) { |
| 331 | unsigned Dfmt; |
| 332 | unsigned Nfmt; |
| 333 | decodeDfmtNfmt(Format: Val, Dfmt, Nfmt); |
| 334 | O << " format:[" ; |
| 335 | if (Dfmt != DFMT_DEFAULT) { |
| 336 | O << getDfmtName(Id: Dfmt); |
| 337 | if (Nfmt != NFMT_DEFAULT) { |
| 338 | O << ','; |
| 339 | } |
| 340 | } |
| 341 | if (Nfmt != NFMT_DEFAULT) { |
| 342 | O << getNfmtName(Id: Nfmt, STI); |
| 343 | } |
| 344 | O << ']'; |
| 345 | } else { |
| 346 | O << " format:" << Val; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | // \returns a low 256 vgpr representing a high vgpr \p Reg [v256..v1023] or |
| 352 | // \p Reg itself otherwise. |
| 353 | static MCRegister getRegForPrinting(MCRegister Reg, const MCRegisterInfo &MRI) { |
| 354 | unsigned Enc = MRI.getEncodingValue(Reg); |
| 355 | unsigned Idx = Enc & AMDGPU::HWEncoding::REG_IDX_MASK; |
| 356 | if (Idx < 0x100) |
| 357 | return Reg; |
| 358 | |
| 359 | unsigned RegNo = Idx % 0x100; |
| 360 | const MCRegisterClass *RC = getVGPRPhysRegClass(Reg, MRI); |
| 361 | if (RC->getID() == AMDGPU::VGPR_16RegClassID) { |
| 362 | // This class has 2048 registers with interleaved lo16 and hi16. |
| 363 | RegNo *= 2; |
| 364 | if (Enc & AMDGPU::HWEncoding::IS_HI16) |
| 365 | ++RegNo; |
| 366 | } |
| 367 | |
| 368 | return RC->getRegister(i: RegNo); |
| 369 | } |
| 370 | |
| 371 | // Restore MSBs of a VGPR above 255 from the MCInstrAnalysis. |
| 372 | static MCRegister getRegFromMIA(MCRegister Reg, unsigned OpNo, |
| 373 | const MCInstrDesc &Desc, |
| 374 | const MCRegisterInfo &MRI, |
| 375 | const AMDGPUMCInstrAnalysis &MIA) { |
| 376 | unsigned VgprMSBs = MIA.getVgprMSBs(); |
| 377 | if (!VgprMSBs) |
| 378 | return Reg; |
| 379 | |
| 380 | unsigned Enc = MRI.getEncodingValue(Reg); |
| 381 | if (!(Enc & AMDGPU::HWEncoding::IS_VGPR)) |
| 382 | return Reg; |
| 383 | |
| 384 | auto Ops = AMDGPU::getVGPRLoweringOperandTables(Desc); |
| 385 | if (!Ops.first) |
| 386 | return Reg; |
| 387 | unsigned Opc = Desc.getOpcode(); |
| 388 | unsigned I; |
| 389 | for (I = 0; I < 4; ++I) { |
| 390 | if (Ops.first[I] != AMDGPU::OpName::NUM_OPERAND_NAMES && |
| 391 | (unsigned)AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: Ops.first[I]) == OpNo) |
| 392 | break; |
| 393 | if (Ops.second && Ops.second[I] != AMDGPU::OpName::NUM_OPERAND_NAMES && |
| 394 | (unsigned)AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: Ops.second[I]) == OpNo) |
| 395 | break; |
| 396 | } |
| 397 | if (I == 4) |
| 398 | return Reg; |
| 399 | unsigned OpMSBs = (VgprMSBs >> (I * 2)) & 3; |
| 400 | if (!OpMSBs) |
| 401 | return Reg; |
| 402 | if (MCRegister NewReg = AMDGPU::getVGPRWithMSBs(Reg, MSBs: OpMSBs, MRI)) |
| 403 | return NewReg; |
| 404 | return Reg; |
| 405 | } |
| 406 | |
| 407 | void AMDGPUInstPrinter::printRsrcReg(const MCInst *MI, unsigned OpNo, |
| 408 | const MCSubtargetInfo &STI, |
| 409 | raw_ostream &O) { |
| 410 | MCRegister Reg = MI->getOperand(i: OpNo).getReg(); |
| 411 | bool IsIndexReg = AMDGPU::isRsrcIndexReg(Reg, MRI); |
| 412 | if (IsIndexReg) |
| 413 | O << "rsrcidx(" ; |
| 414 | printRegOperand(Reg, Opc: MI->getOpcode(), OpNo, O, MRI); |
| 415 | if (IsIndexReg) |
| 416 | O << ')'; |
| 417 | } |
| 418 | |
| 419 | void AMDGPUInstPrinter::printRegOperand(MCRegister Reg, raw_ostream &O, |
| 420 | const MCRegisterInfo &MRI) { |
| 421 | #if !defined(NDEBUG) |
| 422 | switch (Reg.id()) { |
| 423 | case AMDGPU::FP_REG: |
| 424 | case AMDGPU::SP_REG: |
| 425 | case AMDGPU::PRIVATE_RSRC_REG: |
| 426 | llvm_unreachable("pseudo-register should not ever be emitted" ); |
| 427 | default: |
| 428 | break; |
| 429 | } |
| 430 | #endif |
| 431 | |
| 432 | MCRegister PrintReg = getRegForPrinting(Reg, MRI); |
| 433 | O << getRegisterName(Reg: PrintReg); |
| 434 | |
| 435 | if (PrintReg != Reg) |
| 436 | O << " /*" << getRegisterName(Reg) << "*/" ; |
| 437 | } |
| 438 | |
| 439 | void AMDGPUInstPrinter::printRegOperand(MCRegister Reg, unsigned Opc, |
| 440 | unsigned OpNo, raw_ostream &O, |
| 441 | const MCRegisterInfo &MRI) { |
| 442 | if (MIA) |
| 443 | Reg = getRegFromMIA(Reg, OpNo, Desc: MII.get(Opcode: Opc), MRI, |
| 444 | MIA: *static_cast<const AMDGPUMCInstrAnalysis *>(MIA)); |
| 445 | printRegOperand(Reg, O, MRI); |
| 446 | } |
| 447 | |
| 448 | void AMDGPUInstPrinter::printVOPDst(const MCInst *MI, unsigned OpNo, |
| 449 | const MCSubtargetInfo &STI, raw_ostream &O) { |
| 450 | auto Opcode = MI->getOpcode(); |
| 451 | if (OpNo == 0) { |
| 452 | if (SIInstrFlags::isVOP3(O: MII, O: *MI) && SIInstrFlags::isDPP(O: MII, O: *MI)) |
| 453 | O << "_e64_dpp" ; |
| 454 | else if (SIInstrFlags::isVOP3(O: MII, O: *MI)) { |
| 455 | if (!getVOP3IsSingle(Opc: Opcode)) |
| 456 | O << "_e64" ; |
| 457 | } else if (SIInstrFlags::isDPP(O: MII, O: *MI)) |
| 458 | O << "_dpp" ; |
| 459 | else if (SIInstrFlags::isSDWA(O: MII, O: *MI)) |
| 460 | O << "_sdwa" ; |
| 461 | else if ((SIInstrFlags::isVOP1(O: MII, O: *MI) && !getVOP1IsSingle(Opc: Opcode)) || |
| 462 | (SIInstrFlags::isVOP2(O: MII, O: *MI) && !getVOP2IsSingle(Opc: Opcode))) |
| 463 | O << "_e32" ; |
| 464 | O << " " ; |
| 465 | } |
| 466 | |
| 467 | printRegularOperand(MI, OpNo, STI, O); |
| 468 | |
| 469 | // Print default vcc/vcc_lo operand. |
| 470 | switch (Opcode) { |
| 471 | default: break; |
| 472 | |
| 473 | case AMDGPU::V_ADD_CO_CI_U32_e32_gfx10: |
| 474 | case AMDGPU::V_SUB_CO_CI_U32_e32_gfx10: |
| 475 | case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx10: |
| 476 | case AMDGPU::V_ADD_CO_CI_U32_sdwa_gfx10: |
| 477 | case AMDGPU::V_SUB_CO_CI_U32_sdwa_gfx10: |
| 478 | case AMDGPU::V_SUBREV_CO_CI_U32_sdwa_gfx10: |
| 479 | case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx10: |
| 480 | case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx10: |
| 481 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx10: |
| 482 | case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx10: |
| 483 | case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx10: |
| 484 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx10: |
| 485 | case AMDGPU::V_ADD_CO_CI_U32_e32_gfx11: |
| 486 | case AMDGPU::V_SUB_CO_CI_U32_e32_gfx11: |
| 487 | case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx11: |
| 488 | case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx11: |
| 489 | case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx11: |
| 490 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx11: |
| 491 | case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx11: |
| 492 | case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx11: |
| 493 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx11: |
| 494 | case AMDGPU::V_ADD_CO_CI_U32_e32_gfx12: |
| 495 | case AMDGPU::V_SUB_CO_CI_U32_e32_gfx12: |
| 496 | case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx12: |
| 497 | case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx12: |
| 498 | case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx12: |
| 499 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx12: |
| 500 | case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx12: |
| 501 | case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx12: |
| 502 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx12: |
| 503 | case AMDGPU::V_ADD_CO_CI_U32_e32_gfx13: |
| 504 | case AMDGPU::V_SUB_CO_CI_U32_e32_gfx13: |
| 505 | case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx13: |
| 506 | case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx13: |
| 507 | case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx13: |
| 508 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx13: |
| 509 | case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx13: |
| 510 | case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx13: |
| 511 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx13: |
| 512 | printDefaultVccOperand(FirstOperand: false, STI, O); |
| 513 | break; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | void AMDGPUInstPrinter::printVINTRPDst(const MCInst *MI, unsigned OpNo, |
| 518 | const MCSubtargetInfo &STI, raw_ostream &O) { |
| 519 | if (AMDGPU::isSI(STI) || AMDGPU::isCI(STI)) |
| 520 | O << " " ; |
| 521 | else |
| 522 | O << "_e32 " ; |
| 523 | |
| 524 | printRegularOperand(MI, OpNo, STI, O); |
| 525 | } |
| 526 | |
| 527 | void AMDGPUInstPrinter::printAVLdSt32Align2RegOp(const MCInst *MI, |
| 528 | unsigned OpNo, |
| 529 | const MCSubtargetInfo &STI, |
| 530 | raw_ostream &O) { |
| 531 | MCRegister Reg = MI->getOperand(i: OpNo).getReg(); |
| 532 | |
| 533 | // On targets with an even alignment requirement |
| 534 | if (MCRegister SubReg = MRI.getSubReg(Reg, Idx: AMDGPU::sub0)) |
| 535 | Reg = SubReg; |
| 536 | printRegOperand(Reg, O, MRI); |
| 537 | } |
| 538 | |
| 539 | void AMDGPUInstPrinter::printImmediateInt16(uint32_t Imm, |
| 540 | const MCSubtargetInfo &STI, |
| 541 | raw_ostream &O) { |
| 542 | int32_t SImm = static_cast<int32_t>(Imm); |
| 543 | if (isInlinableIntLiteral(Literal: SImm)) { |
| 544 | O << SImm; |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | if (printImmediateFloat32(Imm, STI, O)) |
| 549 | return; |
| 550 | |
| 551 | O << formatHex(Value: static_cast<uint64_t>(Imm & 0xffff)); |
| 552 | } |
| 553 | |
| 554 | static bool printImmediateFP16(uint32_t Imm, const MCSubtargetInfo &STI, |
| 555 | raw_ostream &O) { |
| 556 | if (Imm == 0x3C00) |
| 557 | O << "1.0" ; |
| 558 | else if (Imm == 0xBC00) |
| 559 | O << "-1.0" ; |
| 560 | else if (Imm == 0x3800) |
| 561 | O << "0.5" ; |
| 562 | else if (Imm == 0xB800) |
| 563 | O << "-0.5" ; |
| 564 | else if (Imm == 0x4000) |
| 565 | O << "2.0" ; |
| 566 | else if (Imm == 0xC000) |
| 567 | O << "-2.0" ; |
| 568 | else if (Imm == 0x4400) |
| 569 | O << "4.0" ; |
| 570 | else if (Imm == 0xC400) |
| 571 | O << "-4.0" ; |
| 572 | else if (Imm == 0x3118 && STI.hasFeature(Feature: AMDGPU::FeatureInv2PiInlineImm)) |
| 573 | O << "0.15915494" ; |
| 574 | else |
| 575 | return false; |
| 576 | |
| 577 | return true; |
| 578 | } |
| 579 | |
| 580 | static bool printImmediateBFloat16(uint32_t Imm, const MCSubtargetInfo &STI, |
| 581 | raw_ostream &O) { |
| 582 | if (Imm == 0x3F80) |
| 583 | O << "1.0" ; |
| 584 | else if (Imm == 0xBF80) |
| 585 | O << "-1.0" ; |
| 586 | else if (Imm == 0x3F00) |
| 587 | O << "0.5" ; |
| 588 | else if (Imm == 0xBF00) |
| 589 | O << "-0.5" ; |
| 590 | else if (Imm == 0x4000) |
| 591 | O << "2.0" ; |
| 592 | else if (Imm == 0xC000) |
| 593 | O << "-2.0" ; |
| 594 | else if (Imm == 0x4080) |
| 595 | O << "4.0" ; |
| 596 | else if (Imm == 0xC080) |
| 597 | O << "-4.0" ; |
| 598 | else if (Imm == 0x3E22 && STI.hasFeature(Feature: AMDGPU::FeatureInv2PiInlineImm)) |
| 599 | O << "0.15915494" ; |
| 600 | else |
| 601 | return false; |
| 602 | |
| 603 | return true; |
| 604 | } |
| 605 | |
| 606 | void AMDGPUInstPrinter::printImmediateBF16(uint32_t Imm, |
| 607 | const MCSubtargetInfo &STI, |
| 608 | raw_ostream &O) { |
| 609 | int16_t SImm = static_cast<int16_t>(Imm); |
| 610 | if (isInlinableIntLiteral(Literal: SImm)) { |
| 611 | O << SImm; |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | if (printImmediateBFloat16(Imm: static_cast<uint16_t>(Imm), STI, O)) |
| 616 | return; |
| 617 | |
| 618 | O << formatHex(Value: static_cast<uint64_t>(Imm & 0xffff)); |
| 619 | } |
| 620 | |
| 621 | void AMDGPUInstPrinter::printImmediateF16(uint32_t Imm, |
| 622 | const MCSubtargetInfo &STI, |
| 623 | raw_ostream &O) { |
| 624 | int16_t SImm = static_cast<int16_t>(Imm); |
| 625 | if (isInlinableIntLiteral(Literal: SImm)) { |
| 626 | O << SImm; |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | uint16_t HImm = static_cast<uint16_t>(Imm); |
| 631 | if (printImmediateFP16(Imm: HImm, STI, O)) |
| 632 | return; |
| 633 | |
| 634 | uint64_t Imm16 = static_cast<uint16_t>(Imm); |
| 635 | O << formatHex(Value: Imm16); |
| 636 | } |
| 637 | |
| 638 | void AMDGPUInstPrinter::printImmediateV216(uint32_t Imm, uint8_t OpType, |
| 639 | const MCSubtargetInfo &STI, |
| 640 | raw_ostream &O) { |
| 641 | int32_t SImm = static_cast<int32_t>(Imm); |
| 642 | if (isInlinableIntLiteral(Literal: SImm)) { |
| 643 | O << SImm; |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | switch (OpType) { |
| 648 | case AMDGPU::OPERAND_REG_IMM_V2INT16: |
| 649 | case AMDGPU::OPERAND_REG_INLINE_C_V2INT16: |
| 650 | if (printImmediateFloat32(Imm, STI, O)) |
| 651 | return; |
| 652 | break; |
| 653 | case AMDGPU::OPERAND_REG_IMM_V2FP16: |
| 654 | case AMDGPU::OPERAND_REG_INLINE_C_V2FP16: |
| 655 | if (isUInt<16>(x: Imm) && |
| 656 | printImmediateFP16(Imm: static_cast<uint16_t>(Imm), STI, O)) |
| 657 | return; |
| 658 | break; |
| 659 | case AMDGPU::OPERAND_REG_IMM_V2FP16_SPLAT: { |
| 660 | if (AMDGPU::isGFX11Plus(STI)) { |
| 661 | // For GFX11+, the inline constant is duplicated to both channels, so we |
| 662 | // need to check if the low and high 16 bits are the same, and then if |
| 663 | // they can be printed as inline constant values. |
| 664 | uint16_t Lo16 = static_cast<uint16_t>(Imm & 0xFFFF); |
| 665 | uint16_t Hi16 = static_cast<uint16_t>((Imm >> 16) & 0xFFFF); |
| 666 | if (Lo16 == Hi16 && |
| 667 | printImmediateFP16(Imm: static_cast<uint16_t>(Imm), STI, O)) |
| 668 | return; |
| 669 | } else { |
| 670 | // For pre-GFX11, the inline constant is in the low 16 bits, so we need |
| 671 | // to check if it can be printed as inline constant value. |
| 672 | if (isUInt<16>(x: Imm) && |
| 673 | printImmediateFP16(Imm: static_cast<uint16_t>(Imm), STI, O)) |
| 674 | return; |
| 675 | } |
| 676 | break; |
| 677 | } |
| 678 | case AMDGPU::OPERAND_REG_IMM_V2BF16: |
| 679 | case AMDGPU::OPERAND_REG_INLINE_C_V2BF16: |
| 680 | if (isUInt<16>(x: Imm) && |
| 681 | printImmediateBFloat16(Imm: static_cast<uint16_t>(Imm), STI, O)) |
| 682 | return; |
| 683 | break; |
| 684 | case AMDGPU::OPERAND_REG_IMM_NOINLINE_V2FP16: |
| 685 | break; |
| 686 | default: |
| 687 | llvm_unreachable("bad operand type" ); |
| 688 | } |
| 689 | |
| 690 | O << formatHex(Value: static_cast<uint64_t>(Imm)); |
| 691 | } |
| 692 | |
| 693 | bool AMDGPUInstPrinter::printImmediateFloat32(uint32_t Imm, |
| 694 | const MCSubtargetInfo &STI, |
| 695 | raw_ostream &O) { |
| 696 | if (Imm == llvm::bit_cast<uint32_t>(from: 0.0f)) |
| 697 | O << "0.0" ; |
| 698 | else if (Imm == llvm::bit_cast<uint32_t>(from: 1.0f)) |
| 699 | O << "1.0" ; |
| 700 | else if (Imm == llvm::bit_cast<uint32_t>(from: -1.0f)) |
| 701 | O << "-1.0" ; |
| 702 | else if (Imm == llvm::bit_cast<uint32_t>(from: 0.5f)) |
| 703 | O << "0.5" ; |
| 704 | else if (Imm == llvm::bit_cast<uint32_t>(from: -0.5f)) |
| 705 | O << "-0.5" ; |
| 706 | else if (Imm == llvm::bit_cast<uint32_t>(from: 2.0f)) |
| 707 | O << "2.0" ; |
| 708 | else if (Imm == llvm::bit_cast<uint32_t>(from: -2.0f)) |
| 709 | O << "-2.0" ; |
| 710 | else if (Imm == llvm::bit_cast<uint32_t>(from: 4.0f)) |
| 711 | O << "4.0" ; |
| 712 | else if (Imm == llvm::bit_cast<uint32_t>(from: -4.0f)) |
| 713 | O << "-4.0" ; |
| 714 | else if (Imm == 0x3e22f983 && |
| 715 | STI.hasFeature(Feature: AMDGPU::FeatureInv2PiInlineImm)) |
| 716 | O << "0.15915494" ; |
| 717 | else |
| 718 | return false; |
| 719 | |
| 720 | return true; |
| 721 | } |
| 722 | |
| 723 | void AMDGPUInstPrinter::printImmediate32(uint32_t Imm, |
| 724 | const MCSubtargetInfo &STI, |
| 725 | raw_ostream &O) { |
| 726 | int32_t SImm = static_cast<int32_t>(Imm); |
| 727 | if (isInlinableIntLiteral(Literal: SImm)) { |
| 728 | O << SImm; |
| 729 | return; |
| 730 | } |
| 731 | |
| 732 | if (printImmediateFloat32(Imm, STI, O)) |
| 733 | return; |
| 734 | |
| 735 | O << formatHex(Value: static_cast<uint64_t>(Imm)); |
| 736 | } |
| 737 | |
| 738 | void AMDGPUInstPrinter::printImmediate64(uint64_t Imm, |
| 739 | const MCSubtargetInfo &STI, |
| 740 | raw_ostream &O, bool IsFP) { |
| 741 | int64_t SImm = static_cast<int64_t>(Imm); |
| 742 | if (SImm >= -16 && SImm <= 64) { |
| 743 | O << SImm; |
| 744 | return; |
| 745 | } |
| 746 | |
| 747 | if (Imm == llvm::bit_cast<uint64_t>(from: 0.0)) |
| 748 | O << "0.0" ; |
| 749 | else if (Imm == llvm::bit_cast<uint64_t>(from: 1.0)) |
| 750 | O << "1.0" ; |
| 751 | else if (Imm == llvm::bit_cast<uint64_t>(from: -1.0)) |
| 752 | O << "-1.0" ; |
| 753 | else if (Imm == llvm::bit_cast<uint64_t>(from: 0.5)) |
| 754 | O << "0.5" ; |
| 755 | else if (Imm == llvm::bit_cast<uint64_t>(from: -0.5)) |
| 756 | O << "-0.5" ; |
| 757 | else if (Imm == llvm::bit_cast<uint64_t>(from: 2.0)) |
| 758 | O << "2.0" ; |
| 759 | else if (Imm == llvm::bit_cast<uint64_t>(from: -2.0)) |
| 760 | O << "-2.0" ; |
| 761 | else if (Imm == llvm::bit_cast<uint64_t>(from: 4.0)) |
| 762 | O << "4.0" ; |
| 763 | else if (Imm == llvm::bit_cast<uint64_t>(from: -4.0)) |
| 764 | O << "-4.0" ; |
| 765 | else if (Imm == 0x3fc45f306dc9c882 && |
| 766 | STI.hasFeature(Feature: AMDGPU::FeatureInv2PiInlineImm)) |
| 767 | O << "0.15915494309189532" ; |
| 768 | else |
| 769 | printLiteral64(Imm, O, IsFP); |
| 770 | } |
| 771 | |
| 772 | void AMDGPUInstPrinter::printLiteral64(uint64_t Imm, raw_ostream &O, |
| 773 | bool IsFP) { |
| 774 | if (IsFP && Lo_32(Value: Imm) == 0) |
| 775 | O << formatHex(Value: static_cast<uint64_t>(Hi_32(Value: Imm))); |
| 776 | else |
| 777 | O << formatHex(Value: Imm); |
| 778 | } |
| 779 | |
| 780 | void AMDGPUInstPrinter::printBLGP(const MCInst *MI, unsigned OpNo, |
| 781 | const MCSubtargetInfo &STI, |
| 782 | raw_ostream &O) { |
| 783 | unsigned Imm = MI->getOperand(i: OpNo).getImm(); |
| 784 | if (!Imm) |
| 785 | return; |
| 786 | |
| 787 | if (AMDGPU::isGFX940(STI)) { |
| 788 | switch (MI->getOpcode()) { |
| 789 | case AMDGPU::V_MFMA_F64_16X16X4F64_gfx940_acd: |
| 790 | case AMDGPU::V_MFMA_F64_16X16X4F64_gfx940_vcd: |
| 791 | case AMDGPU::V_MFMA_F64_4X4X4F64_gfx940_acd: |
| 792 | case AMDGPU::V_MFMA_F64_4X4X4F64_gfx940_vcd: |
| 793 | O << " neg:[" << (Imm & 1) << ',' << ((Imm >> 1) & 1) << ',' |
| 794 | << ((Imm >> 2) & 1) << ']'; |
| 795 | return; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | O << " blgp:" << Imm; |
| 800 | } |
| 801 | |
| 802 | void AMDGPUInstPrinter::printDefaultVccOperand(bool FirstOperand, |
| 803 | const MCSubtargetInfo &STI, |
| 804 | raw_ostream &O) { |
| 805 | if (!FirstOperand) |
| 806 | O << ", " ; |
| 807 | printRegOperand(Reg: STI.hasFeature(Feature: AMDGPU::FeatureWavefrontSize32) |
| 808 | ? AMDGPU::VCC_LO |
| 809 | : AMDGPU::VCC, |
| 810 | O, MRI); |
| 811 | if (FirstOperand) |
| 812 | O << ", " ; |
| 813 | } |
| 814 | |
| 815 | bool AMDGPUInstPrinter::needsImpliedVcc(const MCInstrDesc &Desc, |
| 816 | unsigned OpNo) const { |
| 817 | return OpNo == 0 && SIInstrFlags::isDPP(O: Desc) && SIInstrFlags::isVOPC(O: Desc) && |
| 818 | !isVOPCAsmOnly(Opc: Desc.getOpcode()) && |
| 819 | (Desc.hasImplicitDefOfPhysReg(Reg: AMDGPU::VCC) || |
| 820 | Desc.hasImplicitDefOfPhysReg(Reg: AMDGPU::VCC_LO)); |
| 821 | } |
| 822 | |
| 823 | // Print default vcc/vcc_lo operand of VOPC. |
| 824 | void AMDGPUInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, |
| 825 | const MCSubtargetInfo &STI, |
| 826 | raw_ostream &O) { |
| 827 | unsigned Opc = MI->getOpcode(); |
| 828 | const MCInstrDesc &Desc = MII.get(Opcode: Opc); |
| 829 | int ModIdx = AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::src0_modifiers); |
| 830 | // 0, 1 and 2 are the first printed operands in different cases |
| 831 | // If there are printed modifiers, printOperandAndFPInputMods or |
| 832 | // printOperandAndIntInputMods will be called instead |
| 833 | if ((OpNo == 0 || (OpNo == 1 && SIInstrFlags::isDPP(O: Desc) && ModIdx != -1)) && |
| 834 | SIInstrFlags::isVOPC(O: Desc) && !isVOPCAsmOnly(Opc: Desc.getOpcode()) && |
| 835 | (Desc.hasImplicitDefOfPhysReg(Reg: AMDGPU::VCC) || |
| 836 | Desc.hasImplicitDefOfPhysReg(Reg: AMDGPU::VCC_LO))) |
| 837 | printDefaultVccOperand(FirstOperand: true, STI, O); |
| 838 | |
| 839 | printRegularOperand(MI, OpNo, STI, O); |
| 840 | } |
| 841 | |
| 842 | // Print operands after vcc or modifier handling. |
| 843 | void AMDGPUInstPrinter::printRegularOperand(const MCInst *MI, unsigned OpNo, |
| 844 | const MCSubtargetInfo &STI, |
| 845 | raw_ostream &O) { |
| 846 | const MCInstrDesc &Desc = MII.get(Opcode: MI->getOpcode()); |
| 847 | |
| 848 | if (OpNo >= MI->getNumOperands()) { |
| 849 | O << "/*Missing OP" << OpNo << "*/" ; |
| 850 | return; |
| 851 | } |
| 852 | |
| 853 | const MCOperand &Op = MI->getOperand(i: OpNo); |
| 854 | if (Op.isReg()) { |
| 855 | printRegOperand(Reg: Op.getReg(), Opc: MI->getOpcode(), OpNo, O, MRI); |
| 856 | |
| 857 | // Check if operand register class contains register used. |
| 858 | // Intention: print disassembler message when invalid code is decoded, |
| 859 | // for example sgpr register used in VReg or VISrc(VReg or imm) operand. |
| 860 | const MCOperandInfo &OpInfo = Desc.operands()[OpNo]; |
| 861 | if (OpInfo.RegClass != -1) { |
| 862 | int16_t RCID = MII.getOpRegClassID( |
| 863 | OpInfo, HwModeId: STI.getHwMode(type: MCSubtargetInfo::HwMode_RegInfo)); |
| 864 | const MCRegisterClass &RC = MRI.getRegClass(i: RCID); |
| 865 | auto Reg = mc2PseudoReg(Reg: Op.getReg()); |
| 866 | if (!RC.contains(Reg) && !isInlineValue(Reg)) { |
| 867 | bool IsWaveSizeOp = OpInfo.isLookupRegClassByHwMode() && |
| 868 | (OpInfo.RegClass == AMDGPU::SReg_1 || |
| 869 | OpInfo.RegClass == AMDGPU::SReg_1_XEXEC); |
| 870 | // Suppress this comment for a mismatched wavesize. Some users expect to |
| 871 | // be able to assemble and disassemble modules with mixed wavesizes, but |
| 872 | // we do not know the subtarget in different functions in MC. |
| 873 | // |
| 874 | // TODO: Should probably print it anyway, maybe a more specific version. |
| 875 | if (!IsWaveSizeOp) { |
| 876 | O << "/*Invalid register, operand has \'" << MRI.getRegClassName(Class: &RC) |
| 877 | << "\' register class*/" ; |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | } else if (Op.isImm()) { |
| 882 | const uint8_t OpTy = Desc.operands()[OpNo].OperandType; |
| 883 | switch (OpTy) { |
| 884 | case AMDGPU::OPERAND_REG_IMM_INT32: |
| 885 | case AMDGPU::OPERAND_REG_IMM_FP32: |
| 886 | case AMDGPU::OPERAND_REG_INLINE_C_INT32: |
| 887 | case AMDGPU::OPERAND_REG_INLINE_C_FP32: |
| 888 | case AMDGPU::OPERAND_REG_INLINE_AC_INT32: |
| 889 | case AMDGPU::OPERAND_REG_INLINE_AC_FP32: |
| 890 | case AMDGPU::OPERAND_REG_IMM_V2INT32: |
| 891 | case AMDGPU::OPERAND_REG_IMM_V2FP32: |
| 892 | case MCOI::OPERAND_IMMEDIATE: |
| 893 | case AMDGPU::OPERAND_INLINE_SPLIT_BARRIER_INT32: |
| 894 | printImmediate32(Imm: Op.getImm(), STI, O); |
| 895 | break; |
| 896 | case AMDGPU::OPERAND_REG_IMM_INT64: |
| 897 | case AMDGPU::OPERAND_REG_INLINE_C_INT64: |
| 898 | case AMDGPU::OPERAND_REG_IMM_V2INT64: |
| 899 | printImmediate64(Imm: Op.getImm(), STI, O, IsFP: false); |
| 900 | break; |
| 901 | case AMDGPU::OPERAND_REG_IMM_FP64: |
| 902 | case AMDGPU::OPERAND_REG_INLINE_C_FP64: |
| 903 | case AMDGPU::OPERAND_REG_INLINE_AC_FP64: |
| 904 | case AMDGPU::OPERAND_REG_IMM_V2FP64: |
| 905 | printImmediate64(Imm: Op.getImm(), STI, O, IsFP: true); |
| 906 | break; |
| 907 | case AMDGPU::OPERAND_REG_INLINE_C_INT16: |
| 908 | case AMDGPU::OPERAND_REG_IMM_INT16: |
| 909 | printImmediateInt16(Imm: Op.getImm(), STI, O); |
| 910 | break; |
| 911 | case AMDGPU::OPERAND_REG_INLINE_C_FP16: |
| 912 | case AMDGPU::OPERAND_REG_IMM_FP16: |
| 913 | case AMDGPU::OPERAND_REG_IMM_NOINLINE_FP16: |
| 914 | printImmediateF16(Imm: Op.getImm(), STI, O); |
| 915 | break; |
| 916 | case AMDGPU::OPERAND_REG_INLINE_C_BF16: |
| 917 | case AMDGPU::OPERAND_REG_IMM_BF16: |
| 918 | printImmediateBF16(Imm: Op.getImm(), STI, O); |
| 919 | break; |
| 920 | case AMDGPU::OPERAND_REG_IMM_V2INT16: |
| 921 | case AMDGPU::OPERAND_REG_IMM_V2BF16: |
| 922 | case AMDGPU::OPERAND_REG_IMM_V2FP16: |
| 923 | case AMDGPU::OPERAND_REG_IMM_V2FP16_SPLAT: |
| 924 | case AMDGPU::OPERAND_REG_IMM_NOINLINE_V2FP16: |
| 925 | case AMDGPU::OPERAND_REG_INLINE_C_V2INT16: |
| 926 | case AMDGPU::OPERAND_REG_INLINE_C_V2BF16: |
| 927 | case AMDGPU::OPERAND_REG_INLINE_C_V2FP16: |
| 928 | printImmediateV216(Imm: Op.getImm(), OpType: OpTy, STI, O); |
| 929 | break; |
| 930 | case MCOI::OPERAND_UNKNOWN: |
| 931 | case MCOI::OPERAND_PCREL: |
| 932 | O << formatDec(Value: Op.getImm()); |
| 933 | break; |
| 934 | case MCOI::OPERAND_REGISTER: |
| 935 | // Disassembler does not fail when operand should not allow immediate |
| 936 | // operands but decodes them into 32bit immediate operand. |
| 937 | printImmediate32(Imm: Op.getImm(), STI, O); |
| 938 | O << "/*Invalid immediate*/" ; |
| 939 | break; |
| 940 | default: |
| 941 | // We hit this for the immediate instruction bits that don't yet have a |
| 942 | // custom printer. |
| 943 | llvm_unreachable("unexpected immediate operand type" ); |
| 944 | } |
| 945 | } else if (Op.isExpr()) { |
| 946 | const MCExpr *Exp = Op.getExpr(); |
| 947 | MAI.printExpr(O, *Exp); |
| 948 | } else { |
| 949 | O << "/*INV_OP*/" ; |
| 950 | } |
| 951 | |
| 952 | // Print default vcc/vcc_lo operand of v_cndmask_b32_e32. |
| 953 | switch (MI->getOpcode()) { |
| 954 | default: break; |
| 955 | |
| 956 | case AMDGPU::V_CNDMASK_B32_e32_gfx10: |
| 957 | case AMDGPU::V_ADD_CO_CI_U32_e32_gfx10: |
| 958 | case AMDGPU::V_SUB_CO_CI_U32_e32_gfx10: |
| 959 | case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx10: |
| 960 | case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx10: |
| 961 | case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx10: |
| 962 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx10: |
| 963 | case AMDGPU::V_CNDMASK_B32_dpp8_gfx10: |
| 964 | case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx10: |
| 965 | case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx10: |
| 966 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx10: |
| 967 | case AMDGPU::V_CNDMASK_B32_e32_gfx11: |
| 968 | case AMDGPU::V_ADD_CO_CI_U32_e32_gfx11: |
| 969 | case AMDGPU::V_SUB_CO_CI_U32_e32_gfx11: |
| 970 | case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx11: |
| 971 | case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx11: |
| 972 | case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx11: |
| 973 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx11: |
| 974 | case AMDGPU::V_CNDMASK_B32_dpp8_gfx11: |
| 975 | case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx11: |
| 976 | case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx11: |
| 977 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx11: |
| 978 | case AMDGPU::V_CNDMASK_B32_e32_gfx12: |
| 979 | case AMDGPU::V_ADD_CO_CI_U32_e32_gfx12: |
| 980 | case AMDGPU::V_SUB_CO_CI_U32_e32_gfx12: |
| 981 | case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx12: |
| 982 | case AMDGPU::V_CNDMASK_B32_dpp_gfx12: |
| 983 | case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx12: |
| 984 | case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx12: |
| 985 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx12: |
| 986 | case AMDGPU::V_CNDMASK_B32_dpp8_gfx12: |
| 987 | case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx12: |
| 988 | case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx12: |
| 989 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx12: |
| 990 | case AMDGPU::V_CNDMASK_B32_e32_gfx13: |
| 991 | case AMDGPU::V_ADD_CO_CI_U32_e32_gfx13: |
| 992 | case AMDGPU::V_SUB_CO_CI_U32_e32_gfx13: |
| 993 | case AMDGPU::V_SUBREV_CO_CI_U32_e32_gfx13: |
| 994 | case AMDGPU::V_CNDMASK_B32_dpp_gfx13: |
| 995 | case AMDGPU::V_ADD_CO_CI_U32_dpp_gfx13: |
| 996 | case AMDGPU::V_SUB_CO_CI_U32_dpp_gfx13: |
| 997 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp_gfx13: |
| 998 | case AMDGPU::V_CNDMASK_B32_dpp8_gfx13: |
| 999 | case AMDGPU::V_ADD_CO_CI_U32_dpp8_gfx13: |
| 1000 | case AMDGPU::V_SUB_CO_CI_U32_dpp8_gfx13: |
| 1001 | case AMDGPU::V_SUBREV_CO_CI_U32_dpp8_gfx13: |
| 1002 | |
| 1003 | case AMDGPU::V_CNDMASK_B32_e32_gfx6_gfx7: |
| 1004 | case AMDGPU::V_CNDMASK_B32_e32_vi: |
| 1005 | if ((int)OpNo == AMDGPU::getNamedOperandIdx(Opcode: MI->getOpcode(), |
| 1006 | Name: AMDGPU::OpName::src1)) |
| 1007 | printDefaultVccOperand(FirstOperand: OpNo == 0, STI, O); |
| 1008 | break; |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | void AMDGPUInstPrinter::printOperandAndFPInputMods(const MCInst *MI, |
| 1013 | unsigned OpNo, |
| 1014 | const MCSubtargetInfo &STI, |
| 1015 | raw_ostream &O) { |
| 1016 | const MCInstrDesc &Desc = MII.get(Opcode: MI->getOpcode()); |
| 1017 | if (needsImpliedVcc(Desc, OpNo)) |
| 1018 | printDefaultVccOperand(FirstOperand: true, STI, O); |
| 1019 | |
| 1020 | unsigned InputModifiers = MI->getOperand(i: OpNo).getImm(); |
| 1021 | |
| 1022 | // Use 'neg(...)' instead of '-' to avoid ambiguity. |
| 1023 | // This is important for integer literals because |
| 1024 | // -1 is not the same value as neg(1). |
| 1025 | bool NegMnemo = false; |
| 1026 | |
| 1027 | if (InputModifiers & SISrcMods::NEG) { |
| 1028 | if (OpNo + 1 < MI->getNumOperands() && |
| 1029 | (InputModifiers & SISrcMods::ABS) == 0) { |
| 1030 | const MCOperand &Op = MI->getOperand(i: OpNo + 1); |
| 1031 | NegMnemo = Op.isImm(); |
| 1032 | } |
| 1033 | if (NegMnemo) { |
| 1034 | O << "neg(" ; |
| 1035 | } else { |
| 1036 | O << '-'; |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | if (InputModifiers & SISrcMods::ABS) |
| 1041 | O << '|'; |
| 1042 | printRegularOperand(MI, OpNo: OpNo + 1, STI, O); |
| 1043 | if (InputModifiers & SISrcMods::ABS) |
| 1044 | O << '|'; |
| 1045 | |
| 1046 | if (NegMnemo) { |
| 1047 | O << ')'; |
| 1048 | } |
| 1049 | |
| 1050 | // Print default vcc/vcc_lo operand of VOP2b. |
| 1051 | switch (MI->getOpcode()) { |
| 1052 | default: |
| 1053 | break; |
| 1054 | |
| 1055 | case AMDGPU::V_CNDMASK_B32_sdwa_gfx10: |
| 1056 | case AMDGPU::V_CNDMASK_B32_dpp_gfx10: |
| 1057 | case AMDGPU::V_CNDMASK_B32_dpp_gfx11: |
| 1058 | if ((int)OpNo + 1 == |
| 1059 | AMDGPU::getNamedOperandIdx(Opcode: MI->getOpcode(), Name: AMDGPU::OpName::src1)) |
| 1060 | printDefaultVccOperand(FirstOperand: OpNo == 0, STI, O); |
| 1061 | break; |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | void AMDGPUInstPrinter::printOperandAndIntInputMods(const MCInst *MI, |
| 1066 | unsigned OpNo, |
| 1067 | const MCSubtargetInfo &STI, |
| 1068 | raw_ostream &O) { |
| 1069 | const MCInstrDesc &Desc = MII.get(Opcode: MI->getOpcode()); |
| 1070 | if (needsImpliedVcc(Desc, OpNo)) |
| 1071 | printDefaultVccOperand(FirstOperand: true, STI, O); |
| 1072 | |
| 1073 | unsigned InputModifiers = MI->getOperand(i: OpNo).getImm(); |
| 1074 | if (InputModifiers & SISrcMods::SEXT) |
| 1075 | O << "sext(" ; |
| 1076 | printRegularOperand(MI, OpNo: OpNo + 1, STI, O); |
| 1077 | if (InputModifiers & SISrcMods::SEXT) |
| 1078 | O << ')'; |
| 1079 | |
| 1080 | // Print default vcc/vcc_lo operand of VOP2b. |
| 1081 | switch (MI->getOpcode()) { |
| 1082 | default: break; |
| 1083 | |
| 1084 | case AMDGPU::V_ADD_CO_CI_U32_sdwa_gfx10: |
| 1085 | case AMDGPU::V_SUB_CO_CI_U32_sdwa_gfx10: |
| 1086 | case AMDGPU::V_SUBREV_CO_CI_U32_sdwa_gfx10: |
| 1087 | if ((int)OpNo + 1 == AMDGPU::getNamedOperandIdx(Opcode: MI->getOpcode(), |
| 1088 | Name: AMDGPU::OpName::src1)) |
| 1089 | printDefaultVccOperand(FirstOperand: OpNo == 0, STI, O); |
| 1090 | break; |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | void AMDGPUInstPrinter::printDPP8(const MCInst *MI, unsigned OpNo, |
| 1095 | const MCSubtargetInfo &STI, |
| 1096 | raw_ostream &O) { |
| 1097 | if (!AMDGPU::isGFX10Plus(STI)) |
| 1098 | llvm_unreachable("dpp8 is not supported on ASICs earlier than GFX10" ); |
| 1099 | |
| 1100 | unsigned Imm = MI->getOperand(i: OpNo).getImm(); |
| 1101 | O << "dpp8:[" << formatDec(Value: Imm & 0x7); |
| 1102 | for (size_t i = 1; i < 8; ++i) { |
| 1103 | O << ',' << formatDec(Value: (Imm >> (3 * i)) & 0x7); |
| 1104 | } |
| 1105 | O << ']'; |
| 1106 | } |
| 1107 | |
| 1108 | void AMDGPUInstPrinter::printDPPCtrl(const MCInst *MI, unsigned OpNo, |
| 1109 | const MCSubtargetInfo &STI, |
| 1110 | raw_ostream &O) { |
| 1111 | using namespace AMDGPU::DPP; |
| 1112 | |
| 1113 | unsigned Imm = MI->getOperand(i: OpNo).getImm(); |
| 1114 | const MCInstrDesc &Desc = MII.get(Opcode: MI->getOpcode()); |
| 1115 | |
| 1116 | if (!AMDGPU::isLegalDPALU_DPPControl(ST: STI, DC: Imm) && |
| 1117 | STI.hasFeature(Feature: AMDGPU::FeatureDPALU_DPP) && |
| 1118 | AMDGPU::isDPALU_DPP(OpDesc: Desc, MII, ST: STI)) { |
| 1119 | O << " /* DP ALU dpp only supports " |
| 1120 | << (isGFX12(STI) ? "row_share" : "row_newbcast" ) << " */" ; |
| 1121 | return; |
| 1122 | } |
| 1123 | if (Imm <= DppCtrl::QUAD_PERM_LAST) { |
| 1124 | O << "quad_perm:[" ; |
| 1125 | O << formatDec(Value: Imm & 0x3) << ','; |
| 1126 | O << formatDec(Value: (Imm & 0xc) >> 2) << ','; |
| 1127 | O << formatDec(Value: (Imm & 0x30) >> 4) << ','; |
| 1128 | O << formatDec(Value: (Imm & 0xc0) >> 6) << ']'; |
| 1129 | } else if ((Imm >= DppCtrl::ROW_SHL_FIRST) && |
| 1130 | (Imm <= DppCtrl::ROW_SHL_LAST)) { |
| 1131 | O << "row_shl:" << formatDec(Value: Imm - DppCtrl::ROW_SHL0); |
| 1132 | } else if ((Imm >= DppCtrl::ROW_SHR_FIRST) && |
| 1133 | (Imm <= DppCtrl::ROW_SHR_LAST)) { |
| 1134 | O << "row_shr:" << formatDec(Value: Imm - DppCtrl::ROW_SHR0); |
| 1135 | } else if ((Imm >= DppCtrl::ROW_ROR_FIRST) && |
| 1136 | (Imm <= DppCtrl::ROW_ROR_LAST)) { |
| 1137 | O << "row_ror:" << formatDec(Value: Imm - DppCtrl::ROW_ROR0); |
| 1138 | } else if (Imm == DppCtrl::WAVE_SHL1) { |
| 1139 | if (AMDGPU::isGFX10Plus(STI)) { |
| 1140 | O << "/* wave_shl is not supported starting from GFX10 */" ; |
| 1141 | return; |
| 1142 | } |
| 1143 | O << "wave_shl:1" ; |
| 1144 | } else if (Imm == DppCtrl::WAVE_ROL1) { |
| 1145 | if (AMDGPU::isGFX10Plus(STI)) { |
| 1146 | O << "/* wave_rol is not supported starting from GFX10 */" ; |
| 1147 | return; |
| 1148 | } |
| 1149 | O << "wave_rol:1" ; |
| 1150 | } else if (Imm == DppCtrl::WAVE_SHR1) { |
| 1151 | if (AMDGPU::isGFX10Plus(STI)) { |
| 1152 | O << "/* wave_shr is not supported starting from GFX10 */" ; |
| 1153 | return; |
| 1154 | } |
| 1155 | O << "wave_shr:1" ; |
| 1156 | } else if (Imm == DppCtrl::WAVE_ROR1) { |
| 1157 | if (AMDGPU::isGFX10Plus(STI)) { |
| 1158 | O << "/* wave_ror is not supported starting from GFX10 */" ; |
| 1159 | return; |
| 1160 | } |
| 1161 | O << "wave_ror:1" ; |
| 1162 | } else if (Imm == DppCtrl::ROW_MIRROR) { |
| 1163 | O << "row_mirror" ; |
| 1164 | } else if (Imm == DppCtrl::ROW_HALF_MIRROR) { |
| 1165 | O << "row_half_mirror" ; |
| 1166 | } else if (Imm == DppCtrl::BCAST15) { |
| 1167 | if (AMDGPU::isGFX10Plus(STI)) { |
| 1168 | O << "/* row_bcast is not supported starting from GFX10 */" ; |
| 1169 | return; |
| 1170 | } |
| 1171 | O << "row_bcast:15" ; |
| 1172 | } else if (Imm == DppCtrl::BCAST31) { |
| 1173 | if (AMDGPU::isGFX10Plus(STI)) { |
| 1174 | O << "/* row_bcast is not supported starting from GFX10 */" ; |
| 1175 | return; |
| 1176 | } |
| 1177 | O << "row_bcast:31" ; |
| 1178 | } else if ((Imm >= DppCtrl::ROW_SHARE_FIRST) && |
| 1179 | (Imm <= DppCtrl::ROW_SHARE_LAST)) { |
| 1180 | if (AMDGPU::isGFX90A(STI)) { |
| 1181 | O << "row_newbcast:" ; |
| 1182 | } else if (AMDGPU::isGFX10Plus(STI)) { |
| 1183 | O << "row_share:" ; |
| 1184 | } else { |
| 1185 | O << " /* row_newbcast/row_share is not supported on ASICs earlier " |
| 1186 | "than GFX90A/GFX10 */" ; |
| 1187 | return; |
| 1188 | } |
| 1189 | O << formatDec(Value: Imm - DppCtrl::ROW_SHARE_FIRST); |
| 1190 | } else if ((Imm >= DppCtrl::ROW_XMASK_FIRST) && |
| 1191 | (Imm <= DppCtrl::ROW_XMASK_LAST)) { |
| 1192 | if (!AMDGPU::isGFX10Plus(STI)) { |
| 1193 | O << "/* row_xmask is not supported on ASICs earlier than GFX10 */" ; |
| 1194 | return; |
| 1195 | } |
| 1196 | O << "row_xmask:" << formatDec(Value: Imm - DppCtrl::ROW_XMASK_FIRST); |
| 1197 | } else { |
| 1198 | O << "/* Invalid dpp_ctrl value */" ; |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | void AMDGPUInstPrinter::printDppBoundCtrl(const MCInst *MI, unsigned OpNo, |
| 1203 | const MCSubtargetInfo &STI, |
| 1204 | raw_ostream &O) { |
| 1205 | unsigned Imm = MI->getOperand(i: OpNo).getImm(); |
| 1206 | if (Imm) { |
| 1207 | O << " bound_ctrl:1" ; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | void AMDGPUInstPrinter::printDppFI(const MCInst *MI, unsigned OpNo, |
| 1212 | const MCSubtargetInfo &STI, raw_ostream &O) { |
| 1213 | using namespace llvm::AMDGPU::DPP; |
| 1214 | unsigned Imm = MI->getOperand(i: OpNo).getImm(); |
| 1215 | if (Imm == DPP_FI_1 || Imm == DPP8_FI_1) { |
| 1216 | O << " fi:1" ; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | void AMDGPUInstPrinter::printSDWASel(const MCInst *MI, unsigned OpNo, |
| 1221 | raw_ostream &O) { |
| 1222 | using namespace llvm::AMDGPU::SDWA; |
| 1223 | |
| 1224 | unsigned Imm = MI->getOperand(i: OpNo).getImm(); |
| 1225 | switch (Imm) { |
| 1226 | case SdwaSel::BYTE_0: O << "BYTE_0" ; break; |
| 1227 | case SdwaSel::BYTE_1: O << "BYTE_1" ; break; |
| 1228 | case SdwaSel::BYTE_2: O << "BYTE_2" ; break; |
| 1229 | case SdwaSel::BYTE_3: O << "BYTE_3" ; break; |
| 1230 | case SdwaSel::WORD_0: O << "WORD_0" ; break; |
| 1231 | case SdwaSel::WORD_1: O << "WORD_1" ; break; |
| 1232 | case SdwaSel::DWORD: O << "DWORD" ; break; |
| 1233 | default: llvm_unreachable("Invalid SDWA data select operand" ); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | void AMDGPUInstPrinter::printSDWADstSel(const MCInst *MI, unsigned OpNo, |
| 1238 | const MCSubtargetInfo &STI, |
| 1239 | raw_ostream &O) { |
| 1240 | O << "dst_sel:" ; |
| 1241 | printSDWASel(MI, OpNo, O); |
| 1242 | } |
| 1243 | |
| 1244 | void AMDGPUInstPrinter::printSDWASrc0Sel(const MCInst *MI, unsigned OpNo, |
| 1245 | const MCSubtargetInfo &STI, |
| 1246 | raw_ostream &O) { |
| 1247 | O << "src0_sel:" ; |
| 1248 | printSDWASel(MI, OpNo, O); |
| 1249 | } |
| 1250 | |
| 1251 | void AMDGPUInstPrinter::printSDWASrc1Sel(const MCInst *MI, unsigned OpNo, |
| 1252 | const MCSubtargetInfo &STI, |
| 1253 | raw_ostream &O) { |
| 1254 | O << "src1_sel:" ; |
| 1255 | printSDWASel(MI, OpNo, O); |
| 1256 | } |
| 1257 | |
| 1258 | void AMDGPUInstPrinter::printSDWADstUnused(const MCInst *MI, unsigned OpNo, |
| 1259 | const MCSubtargetInfo &STI, |
| 1260 | raw_ostream &O) { |
| 1261 | using namespace llvm::AMDGPU::SDWA; |
| 1262 | |
| 1263 | O << "dst_unused:" ; |
| 1264 | unsigned Imm = MI->getOperand(i: OpNo).getImm(); |
| 1265 | switch (Imm) { |
| 1266 | case DstUnused::UNUSED_PAD: O << "UNUSED_PAD" ; break; |
| 1267 | case DstUnused::UNUSED_SEXT: O << "UNUSED_SEXT" ; break; |
| 1268 | case DstUnused::UNUSED_PRESERVE: O << "UNUSED_PRESERVE" ; break; |
| 1269 | default: llvm_unreachable("Invalid SDWA dest_unused operand" ); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | void AMDGPUInstPrinter::printExpSrcN(const MCInst *MI, unsigned OpNo, |
| 1274 | const MCSubtargetInfo &STI, raw_ostream &O, |
| 1275 | unsigned N) { |
| 1276 | unsigned Opc = MI->getOpcode(); |
| 1277 | int EnIdx = AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::en); |
| 1278 | unsigned En = MI->getOperand(i: EnIdx).getImm(); |
| 1279 | |
| 1280 | int ComprIdx = AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::compr); |
| 1281 | |
| 1282 | // If compr is set, print as src0, src0, src1, src1 |
| 1283 | if (MI->getOperand(i: ComprIdx).getImm()) |
| 1284 | OpNo = OpNo - N + N / 2; |
| 1285 | |
| 1286 | if (En & (1 << N)) |
| 1287 | printRegOperand(Reg: MI->getOperand(i: OpNo).getReg(), Opc, OpNo, O, MRI); |
| 1288 | else |
| 1289 | O << "off" ; |
| 1290 | } |
| 1291 | |
| 1292 | void AMDGPUInstPrinter::printExpSrc0(const MCInst *MI, unsigned OpNo, |
| 1293 | const MCSubtargetInfo &STI, |
| 1294 | raw_ostream &O) { |
| 1295 | printExpSrcN(MI, OpNo, STI, O, N: 0); |
| 1296 | } |
| 1297 | |
| 1298 | void AMDGPUInstPrinter::printExpSrc1(const MCInst *MI, unsigned OpNo, |
| 1299 | const MCSubtargetInfo &STI, |
| 1300 | raw_ostream &O) { |
| 1301 | printExpSrcN(MI, OpNo, STI, O, N: 1); |
| 1302 | } |
| 1303 | |
| 1304 | void AMDGPUInstPrinter::printExpSrc2(const MCInst *MI, unsigned OpNo, |
| 1305 | const MCSubtargetInfo &STI, |
| 1306 | raw_ostream &O) { |
| 1307 | printExpSrcN(MI, OpNo, STI, O, N: 2); |
| 1308 | } |
| 1309 | |
| 1310 | void AMDGPUInstPrinter::printExpSrc3(const MCInst *MI, unsigned OpNo, |
| 1311 | const MCSubtargetInfo &STI, |
| 1312 | raw_ostream &O) { |
| 1313 | printExpSrcN(MI, OpNo, STI, O, N: 3); |
| 1314 | } |
| 1315 | |
| 1316 | void AMDGPUInstPrinter::printExpTgt(const MCInst *MI, unsigned OpNo, |
| 1317 | const MCSubtargetInfo &STI, |
| 1318 | raw_ostream &O) { |
| 1319 | using namespace llvm::AMDGPU::Exp; |
| 1320 | |
| 1321 | // This is really a 6 bit field. |
| 1322 | unsigned Id = MI->getOperand(i: OpNo).getImm() & ((1 << 6) - 1); |
| 1323 | |
| 1324 | int Index; |
| 1325 | StringRef TgtName; |
| 1326 | if (getTgtName(Id, Name&: TgtName, Index) && isSupportedTgtId(Id, STI)) { |
| 1327 | O << ' ' << TgtName; |
| 1328 | if (Index >= 0) |
| 1329 | O << Index; |
| 1330 | } else { |
| 1331 | O << " invalid_target_" << Id; |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | static bool allOpsDefaultValue(const int* Ops, int NumOps, int Mod, |
| 1336 | bool IsPacked, bool HasDstSel) { |
| 1337 | int DefaultValue = IsPacked && (Mod == SISrcMods::OP_SEL_1); |
| 1338 | |
| 1339 | for (int I = 0; I < NumOps; ++I) { |
| 1340 | if (!!(Ops[I] & Mod) != DefaultValue) |
| 1341 | return false; |
| 1342 | } |
| 1343 | |
| 1344 | if (HasDstSel && (Ops[0] & SISrcMods::DST_OP_SEL) != 0) |
| 1345 | return false; |
| 1346 | |
| 1347 | return true; |
| 1348 | } |
| 1349 | |
| 1350 | void AMDGPUInstPrinter::printPackedModifier(const MCInst *MI, |
| 1351 | StringRef Name, |
| 1352 | unsigned Mod, |
| 1353 | raw_ostream &O) { |
| 1354 | unsigned Opc = MI->getOpcode(); |
| 1355 | int NumOps = 0; |
| 1356 | int Ops[3]; |
| 1357 | |
| 1358 | std::pair<AMDGPU::OpName, AMDGPU::OpName> MOps[] = { |
| 1359 | {AMDGPU::OpName::src0_modifiers, AMDGPU::OpName::src0}, |
| 1360 | {AMDGPU::OpName::src1_modifiers, AMDGPU::OpName::src1}, |
| 1361 | {AMDGPU::OpName::src2_modifiers, AMDGPU::OpName::src2}}; |
| 1362 | int DefaultValue = (Mod == SISrcMods::OP_SEL_1); |
| 1363 | |
| 1364 | for (auto [SrcMod, Src] : MOps) { |
| 1365 | if (!AMDGPU::hasNamedOperand(Opcode: Opc, NamedIdx: Src)) |
| 1366 | break; |
| 1367 | |
| 1368 | int ModIdx = AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: SrcMod); |
| 1369 | Ops[NumOps++] = |
| 1370 | (ModIdx != -1) ? MI->getOperand(i: ModIdx).getImm() : DefaultValue; |
| 1371 | } |
| 1372 | |
| 1373 | // Some instructions, e.g. v_interp_p2_f16 in GFX9, have src0, src2, but no |
| 1374 | // src1. |
| 1375 | if (NumOps == 1 && AMDGPU::hasNamedOperand(Opcode: Opc, NamedIdx: AMDGPU::OpName::src2) && |
| 1376 | !AMDGPU::hasNamedOperand(Opcode: Opc, NamedIdx: AMDGPU::OpName::src1)) { |
| 1377 | Ops[NumOps++] = DefaultValue; // Set src1_modifiers to default. |
| 1378 | int Mod2Idx = |
| 1379 | AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::src2_modifiers); |
| 1380 | assert(Mod2Idx != -1); |
| 1381 | Ops[NumOps++] = MI->getOperand(i: Mod2Idx).getImm(); |
| 1382 | } |
| 1383 | |
| 1384 | const bool HasDst = |
| 1385 | (AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::vdst) != -1) || |
| 1386 | (AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::sdst) != -1); |
| 1387 | |
| 1388 | // Print three values of neg/opsel for wmma instructions (prints 0 when there |
| 1389 | // is no src_modifier operand instead of not printing anything). |
| 1390 | if (SIInstrFlags::isSWMMAC(O: MII, O: *MI) || SIInstrFlags::isWMMA(O: MII, O: *MI)) { |
| 1391 | NumOps = 0; |
| 1392 | int DefaultValue = Mod == SISrcMods::OP_SEL_1; |
| 1393 | for (AMDGPU::OpName OpName : |
| 1394 | {AMDGPU::OpName::src0_modifiers, AMDGPU::OpName::src1_modifiers, |
| 1395 | AMDGPU::OpName::src2_modifiers}) { |
| 1396 | int Idx = AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: OpName); |
| 1397 | if (Idx != -1) |
| 1398 | Ops[NumOps++] = MI->getOperand(i: Idx).getImm(); |
| 1399 | else |
| 1400 | Ops[NumOps++] = DefaultValue; |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | const bool HasDstSel = HasDst && NumOps > 0 && Mod == SISrcMods::OP_SEL_0 && |
| 1405 | SIInstrFlags::hasVOP3OpSel(O: MII, O: *MI); |
| 1406 | |
| 1407 | const bool IsPacked = SIInstrFlags::isPacked(O: MII, O: *MI); |
| 1408 | |
| 1409 | if (allOpsDefaultValue(Ops, NumOps, Mod, IsPacked, HasDstSel)) |
| 1410 | return; |
| 1411 | |
| 1412 | O << Name; |
| 1413 | ListSeparator Sep("," ); |
| 1414 | for (int I = 0; I < NumOps; ++I) |
| 1415 | O << Sep << !!(Ops[I] & Mod); |
| 1416 | |
| 1417 | if (HasDstSel) { |
| 1418 | O << ',' << !!(Ops[0] & SISrcMods::DST_OP_SEL); |
| 1419 | } |
| 1420 | |
| 1421 | O << ']'; |
| 1422 | } |
| 1423 | |
| 1424 | void AMDGPUInstPrinter::printOpSel(const MCInst *MI, unsigned, |
| 1425 | const MCSubtargetInfo &STI, |
| 1426 | raw_ostream &O) { |
| 1427 | unsigned Opc = MI->getOpcode(); |
| 1428 | if (isCvt_F32_Fp8_Bf8_e64(Opc)) { |
| 1429 | auto SrcMod = |
| 1430 | AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::src0_modifiers); |
| 1431 | unsigned Mod = MI->getOperand(i: SrcMod).getImm(); |
| 1432 | unsigned Index0 = !!(Mod & SISrcMods::OP_SEL_0); |
| 1433 | unsigned Index1 = !!(Mod & SISrcMods::OP_SEL_1); |
| 1434 | if (Index0 || Index1) |
| 1435 | O << " op_sel:[" << Index0 << ',' << Index1 << ']'; |
| 1436 | return; |
| 1437 | } |
| 1438 | if (isPermlane16(Opc)) { |
| 1439 | auto FIN = AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::src0_modifiers); |
| 1440 | auto BCN = AMDGPU::getNamedOperandIdx(Opcode: Opc, Name: AMDGPU::OpName::src1_modifiers); |
| 1441 | unsigned FI = !!(MI->getOperand(i: FIN).getImm() & SISrcMods::OP_SEL_0); |
| 1442 | unsigned BC = !!(MI->getOperand(i: BCN).getImm() & SISrcMods::OP_SEL_0); |
| 1443 | if (FI || BC) |
| 1444 | O << " op_sel:[" << FI << ',' << BC << ']'; |
| 1445 | return; |
| 1446 | } |
| 1447 | |
| 1448 | printPackedModifier(MI, Name: " op_sel:[" , Mod: SISrcMods::OP_SEL_0, O); |
| 1449 | } |
| 1450 | |
| 1451 | void AMDGPUInstPrinter::printOpSelHi(const MCInst *MI, unsigned OpNo, |
| 1452 | const MCSubtargetInfo &STI, |
| 1453 | raw_ostream &O) { |
| 1454 | printPackedModifier(MI, Name: " op_sel_hi:[" , Mod: SISrcMods::OP_SEL_1, O); |
| 1455 | } |
| 1456 | |
| 1457 | void AMDGPUInstPrinter::printNegLo(const MCInst *MI, unsigned OpNo, |
| 1458 | const MCSubtargetInfo &STI, |
| 1459 | raw_ostream &O) { |
| 1460 | printPackedModifier(MI, Name: " neg_lo:[" , Mod: SISrcMods::NEG, O); |
| 1461 | } |
| 1462 | |
| 1463 | void AMDGPUInstPrinter::printNegHi(const MCInst *MI, unsigned OpNo, |
| 1464 | const MCSubtargetInfo &STI, |
| 1465 | raw_ostream &O) { |
| 1466 | printPackedModifier(MI, Name: " neg_hi:[" , Mod: SISrcMods::NEG_HI, O); |
| 1467 | } |
| 1468 | |
| 1469 | void AMDGPUInstPrinter::printIndexKey8bit(const MCInst *MI, unsigned OpNo, |
| 1470 | const MCSubtargetInfo &STI, |
| 1471 | raw_ostream &O) { |
| 1472 | auto Imm = MI->getOperand(i: OpNo).getImm() & 0x7; |
| 1473 | if (Imm == 0) |
| 1474 | return; |
| 1475 | |
| 1476 | O << " index_key:" << Imm; |
| 1477 | } |
| 1478 | |
| 1479 | void AMDGPUInstPrinter::printIndexKey16bit(const MCInst *MI, unsigned OpNo, |
| 1480 | const MCSubtargetInfo &STI, |
| 1481 | raw_ostream &O) { |
| 1482 | auto Imm = MI->getOperand(i: OpNo).getImm() & 0x7; |
| 1483 | if (Imm == 0) |
| 1484 | return; |
| 1485 | |
| 1486 | O << " index_key:" << Imm; |
| 1487 | } |
| 1488 | |
| 1489 | void AMDGPUInstPrinter::printIndexKey32bit(const MCInst *MI, unsigned OpNo, |
| 1490 | const MCSubtargetInfo &STI, |
| 1491 | raw_ostream &O) { |
| 1492 | auto Imm = MI->getOperand(i: OpNo).getImm() & 0x7; |
| 1493 | if (Imm == 0) |
| 1494 | return; |
| 1495 | |
| 1496 | O << " index_key:" << Imm; |
| 1497 | } |
| 1498 | |
| 1499 | void AMDGPUInstPrinter::printMatrixFMT(const MCInst *MI, unsigned OpNo, |
| 1500 | const MCSubtargetInfo &STI, |
| 1501 | raw_ostream &O, char AorB) { |
| 1502 | auto Imm = MI->getOperand(i: OpNo).getImm() & 0x7; |
| 1503 | if (Imm == 0) |
| 1504 | return; |
| 1505 | |
| 1506 | O << " matrix_" << AorB << "_fmt:" ; |
| 1507 | if (Imm < static_cast<int64_t>(std::size(WMMAMods::ModMatrixFmt))) |
| 1508 | O << WMMAMods::ModMatrixFmt[Imm]; |
| 1509 | else |
| 1510 | O << Imm; |
| 1511 | } |
| 1512 | |
| 1513 | void AMDGPUInstPrinter::printMatrixAFMT(const MCInst *MI, unsigned OpNo, |
| 1514 | const MCSubtargetInfo &STI, |
| 1515 | raw_ostream &O) { |
| 1516 | printMatrixFMT(MI, OpNo, STI, O, AorB: 'a'); |
| 1517 | } |
| 1518 | |
| 1519 | void AMDGPUInstPrinter::printMatrixBFMT(const MCInst *MI, unsigned OpNo, |
| 1520 | const MCSubtargetInfo &STI, |
| 1521 | raw_ostream &O) { |
| 1522 | printMatrixFMT(MI, OpNo, STI, O, AorB: 'b'); |
| 1523 | } |
| 1524 | |
| 1525 | void AMDGPUInstPrinter::printMatrixScale(const MCInst *MI, unsigned OpNo, |
| 1526 | const MCSubtargetInfo &STI, |
| 1527 | raw_ostream &O, char AorB) { |
| 1528 | auto Imm = MI->getOperand(i: OpNo).getImm() & 1; |
| 1529 | if (Imm == 0) |
| 1530 | return; |
| 1531 | |
| 1532 | O << " matrix_" << AorB << "_scale:" ; |
| 1533 | if (Imm < static_cast<int64_t>(std::size(WMMAMods::ModMatrixScale))) |
| 1534 | O << WMMAMods::ModMatrixScale[Imm]; |
| 1535 | else |
| 1536 | O << Imm; |
| 1537 | } |
| 1538 | |
| 1539 | void AMDGPUInstPrinter::printMatrixAScale(const MCInst *MI, unsigned OpNo, |
| 1540 | const MCSubtargetInfo &STI, |
| 1541 | raw_ostream &O) { |
| 1542 | printMatrixScale(MI, OpNo, STI, O, AorB: 'a'); |
| 1543 | } |
| 1544 | |
| 1545 | void AMDGPUInstPrinter::printMatrixBScale(const MCInst *MI, unsigned OpNo, |
| 1546 | const MCSubtargetInfo &STI, |
| 1547 | raw_ostream &O) { |
| 1548 | printMatrixScale(MI, OpNo, STI, O, AorB: 'b'); |
| 1549 | } |
| 1550 | |
| 1551 | void AMDGPUInstPrinter::printMatrixScaleFmt(const MCInst *MI, unsigned OpNo, |
| 1552 | const MCSubtargetInfo &STI, |
| 1553 | raw_ostream &O, char AorB) { |
| 1554 | auto Imm = MI->getOperand(i: OpNo).getImm() & 3; |
| 1555 | if (Imm == 0) |
| 1556 | return; |
| 1557 | |
| 1558 | O << " matrix_" << AorB << "_scale_fmt:" ; |
| 1559 | if (Imm < static_cast<int64_t>(std::size(WMMAMods::ModMatrixScaleFmt))) |
| 1560 | O << WMMAMods::ModMatrixScaleFmt[Imm]; |
| 1561 | else |
| 1562 | O << Imm; |
| 1563 | } |
| 1564 | |
| 1565 | void AMDGPUInstPrinter::printMatrixAScaleFmt(const MCInst *MI, unsigned OpNo, |
| 1566 | const MCSubtargetInfo &STI, |
| 1567 | raw_ostream &O) { |
| 1568 | printMatrixScaleFmt(MI, OpNo, STI, O, AorB: 'a'); |
| 1569 | } |
| 1570 | |
| 1571 | void AMDGPUInstPrinter::printMatrixBScaleFmt(const MCInst *MI, unsigned OpNo, |
| 1572 | const MCSubtargetInfo &STI, |
| 1573 | raw_ostream &O) { |
| 1574 | printMatrixScaleFmt(MI, OpNo, STI, O, AorB: 'b'); |
| 1575 | } |
| 1576 | |
| 1577 | void AMDGPUInstPrinter::printInterpSlot(const MCInst *MI, unsigned OpNum, |
| 1578 | const MCSubtargetInfo &STI, |
| 1579 | raw_ostream &O) { |
| 1580 | unsigned Imm = MI->getOperand(i: OpNum).getImm(); |
| 1581 | switch (Imm) { |
| 1582 | case 0: |
| 1583 | O << "p10" ; |
| 1584 | break; |
| 1585 | case 1: |
| 1586 | O << "p20" ; |
| 1587 | break; |
| 1588 | case 2: |
| 1589 | O << "p0" ; |
| 1590 | break; |
| 1591 | default: |
| 1592 | O << "invalid_param_" << Imm; |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | void AMDGPUInstPrinter::printInterpAttr(const MCInst *MI, unsigned OpNum, |
| 1597 | const MCSubtargetInfo &STI, |
| 1598 | raw_ostream &O) { |
| 1599 | unsigned Attr = MI->getOperand(i: OpNum).getImm(); |
| 1600 | O << "attr" << Attr; |
| 1601 | } |
| 1602 | |
| 1603 | void AMDGPUInstPrinter::printInterpAttrChan(const MCInst *MI, unsigned OpNum, |
| 1604 | const MCSubtargetInfo &STI, |
| 1605 | raw_ostream &O) { |
| 1606 | unsigned Chan = MI->getOperand(i: OpNum).getImm(); |
| 1607 | O << '.' << "xyzw" [Chan & 0x3]; |
| 1608 | } |
| 1609 | |
| 1610 | void AMDGPUInstPrinter::printGPRIdxMode(const MCInst *MI, unsigned OpNo, |
| 1611 | const MCSubtargetInfo &STI, |
| 1612 | raw_ostream &O) { |
| 1613 | using namespace llvm::AMDGPU::VGPRIndexMode; |
| 1614 | unsigned Val = MI->getOperand(i: OpNo).getImm(); |
| 1615 | |
| 1616 | if ((Val & ~ENABLE_MASK) != 0) { |
| 1617 | O << formatHex(Value: static_cast<uint64_t>(Val)); |
| 1618 | } else { |
| 1619 | O << "gpr_idx(" ; |
| 1620 | ListSeparator Sep("," ); |
| 1621 | for (unsigned ModeId = ID_MIN; ModeId <= ID_MAX; ++ModeId) { |
| 1622 | if (Val & (1 << ModeId)) |
| 1623 | O << Sep << IdSymbolic[ModeId]; |
| 1624 | } |
| 1625 | O << ')'; |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | void AMDGPUInstPrinter::printMemOperand(const MCInst *MI, unsigned OpNo, |
| 1630 | const MCSubtargetInfo &STI, |
| 1631 | raw_ostream &O) { |
| 1632 | printRegularOperand(MI, OpNo, STI, O); |
| 1633 | O << ", " ; |
| 1634 | printRegularOperand(MI, OpNo: OpNo + 1, STI, O); |
| 1635 | } |
| 1636 | |
| 1637 | void AMDGPUInstPrinter::printIfSet(const MCInst *MI, unsigned OpNo, |
| 1638 | raw_ostream &O, StringRef Asm, |
| 1639 | StringRef Default) { |
| 1640 | const MCOperand &Op = MI->getOperand(i: OpNo); |
| 1641 | assert(Op.isImm()); |
| 1642 | if (Op.getImm() == 1) { |
| 1643 | O << Asm; |
| 1644 | } else { |
| 1645 | O << Default; |
| 1646 | } |
| 1647 | } |
| 1648 | |
| 1649 | void AMDGPUInstPrinter::printIfSet(const MCInst *MI, unsigned OpNo, |
| 1650 | raw_ostream &O, char Asm) { |
| 1651 | const MCOperand &Op = MI->getOperand(i: OpNo); |
| 1652 | assert(Op.isImm()); |
| 1653 | if (Op.getImm() == 1) |
| 1654 | O << Asm; |
| 1655 | } |
| 1656 | |
| 1657 | void AMDGPUInstPrinter::printOModSI(const MCInst *MI, unsigned OpNo, |
| 1658 | const MCSubtargetInfo &STI, |
| 1659 | raw_ostream &O) { |
| 1660 | int Imm = MI->getOperand(i: OpNo).getImm(); |
| 1661 | if (Imm == SIOutMods::MUL2) |
| 1662 | O << " mul:2" ; |
| 1663 | else if (Imm == SIOutMods::MUL4) |
| 1664 | O << " mul:4" ; |
| 1665 | else if (Imm == SIOutMods::DIV2) |
| 1666 | O << " div:2" ; |
| 1667 | } |
| 1668 | |
| 1669 | void AMDGPUInstPrinter::printSendMsg(const MCInst *MI, unsigned OpNo, |
| 1670 | const MCSubtargetInfo &STI, |
| 1671 | raw_ostream &O) { |
| 1672 | using namespace llvm::AMDGPU::SendMsg; |
| 1673 | |
| 1674 | const unsigned Imm16 = MI->getOperand(i: OpNo).getImm(); |
| 1675 | |
| 1676 | uint16_t MsgId; |
| 1677 | uint16_t OpId; |
| 1678 | uint16_t StreamId; |
| 1679 | decodeMsg(Val: Imm16, MsgId, OpId, StreamId, STI); |
| 1680 | |
| 1681 | StringRef MsgName = getMsgName(Encoding: MsgId, STI); |
| 1682 | |
| 1683 | if (!MsgName.empty() && isValidMsgOp(MsgId, OpId, STI) && |
| 1684 | isValidMsgStream(MsgId, OpId, StreamId, STI)) { |
| 1685 | O << "sendmsg(" << MsgName; |
| 1686 | if (msgRequiresOp(MsgId, STI)) { |
| 1687 | O << ", " << getMsgOpName(MsgId, Encoding: OpId, STI); |
| 1688 | if (msgSupportsStream(MsgId, OpId, STI)) { |
| 1689 | O << ", " << StreamId; |
| 1690 | } |
| 1691 | } |
| 1692 | O << ')'; |
| 1693 | } else if (encodeMsg(MsgId, OpId, StreamId) == Imm16) { |
| 1694 | O << "sendmsg(" << MsgId << ", " << OpId << ", " << StreamId << ')'; |
| 1695 | } else { |
| 1696 | O << Imm16; // Unknown imm16 code. |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | void AMDGPUInstPrinter::printWaitEvent(const MCInst *MI, unsigned OpNo, |
| 1701 | const MCSubtargetInfo &STI, |
| 1702 | raw_ostream &O) { |
| 1703 | using namespace llvm::AMDGPU::WaitEvent; |
| 1704 | const uint16_t Imm16 = static_cast<uint16_t>(MI->getOperand(i: OpNo).getImm()); |
| 1705 | |
| 1706 | StringRef EventName = getWaitEventMaskName(Encoding: Imm16, STI); |
| 1707 | if (EventName.empty()) |
| 1708 | O << formatHex(Value: static_cast<uint64_t>(Imm16)); |
| 1709 | else |
| 1710 | O << EventName; |
| 1711 | } |
| 1712 | |
| 1713 | static void printSwizzleBitmask(const uint16_t AndMask, |
| 1714 | const uint16_t OrMask, |
| 1715 | const uint16_t XorMask, |
| 1716 | raw_ostream &O) { |
| 1717 | using namespace llvm::AMDGPU::Swizzle; |
| 1718 | |
| 1719 | uint16_t Probe0 = ((0 & AndMask) | OrMask) ^ XorMask; |
| 1720 | uint16_t Probe1 = ((BITMASK_MASK & AndMask) | OrMask) ^ XorMask; |
| 1721 | |
| 1722 | O << "\"" ; |
| 1723 | |
| 1724 | for (unsigned Mask = 1 << (BITMASK_WIDTH - 1); Mask > 0; Mask >>= 1) { |
| 1725 | uint16_t p0 = Probe0 & Mask; |
| 1726 | uint16_t p1 = Probe1 & Mask; |
| 1727 | |
| 1728 | if (p0 == p1) { |
| 1729 | if (p0 == 0) { |
| 1730 | O << "0" ; |
| 1731 | } else { |
| 1732 | O << "1" ; |
| 1733 | } |
| 1734 | } else { |
| 1735 | if (p0 == 0) { |
| 1736 | O << "p" ; |
| 1737 | } else { |
| 1738 | O << "i" ; |
| 1739 | } |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | O << "\"" ; |
| 1744 | } |
| 1745 | |
| 1746 | void AMDGPUInstPrinter::printSwizzle(const MCInst *MI, unsigned OpNo, |
| 1747 | const MCSubtargetInfo &STI, |
| 1748 | raw_ostream &O) { |
| 1749 | using namespace llvm::AMDGPU::Swizzle; |
| 1750 | |
| 1751 | uint16_t Imm = MI->getOperand(i: OpNo).getImm(); |
| 1752 | if (Imm == 0) { |
| 1753 | return; |
| 1754 | } |
| 1755 | |
| 1756 | O << " offset:" ; |
| 1757 | |
| 1758 | // Rotate and FFT modes |
| 1759 | if (Imm >= ROTATE_MODE_LO && AMDGPU::isGFX9Plus(STI)) { |
| 1760 | if (Imm >= FFT_MODE_LO) { |
| 1761 | O << "swizzle(" << IdSymbolic[ID_FFT] << ',' << (Imm & FFT_SWIZZLE_MASK) |
| 1762 | << ')'; |
| 1763 | } else if (Imm >= ROTATE_MODE_LO) { |
| 1764 | O << "swizzle(" << IdSymbolic[ID_ROTATE] << ',' |
| 1765 | << ((Imm >> ROTATE_DIR_SHIFT) & ROTATE_DIR_MASK) << ',' |
| 1766 | << ((Imm >> ROTATE_SIZE_SHIFT) & ROTATE_SIZE_MASK) << ')'; |
| 1767 | } |
| 1768 | return; |
| 1769 | } |
| 1770 | |
| 1771 | // Basic mode |
| 1772 | if ((Imm & QUAD_PERM_ENC_MASK) == QUAD_PERM_ENC) { |
| 1773 | O << "swizzle(" << IdSymbolic[ID_QUAD_PERM]; |
| 1774 | for (unsigned I = 0; I < LANE_NUM; ++I) { |
| 1775 | O << "," ; |
| 1776 | O << formatDec(Value: Imm & LANE_MASK); |
| 1777 | Imm >>= LANE_SHIFT; |
| 1778 | } |
| 1779 | O << ")" ; |
| 1780 | |
| 1781 | } else if ((Imm & BITMASK_PERM_ENC_MASK) == BITMASK_PERM_ENC) { |
| 1782 | |
| 1783 | uint16_t AndMask = (Imm >> BITMASK_AND_SHIFT) & BITMASK_MASK; |
| 1784 | uint16_t OrMask = (Imm >> BITMASK_OR_SHIFT) & BITMASK_MASK; |
| 1785 | uint16_t XorMask = (Imm >> BITMASK_XOR_SHIFT) & BITMASK_MASK; |
| 1786 | |
| 1787 | if (AndMask == BITMASK_MAX && OrMask == 0 && llvm::popcount(Value: XorMask) == 1) { |
| 1788 | |
| 1789 | O << "swizzle(" << IdSymbolic[ID_SWAP]; |
| 1790 | O << "," ; |
| 1791 | O << formatDec(Value: XorMask); |
| 1792 | O << ")" ; |
| 1793 | |
| 1794 | } else if (AndMask == BITMASK_MAX && OrMask == 0 && XorMask > 0 && |
| 1795 | isPowerOf2_64(Value: XorMask + 1)) { |
| 1796 | |
| 1797 | O << "swizzle(" << IdSymbolic[ID_REVERSE]; |
| 1798 | O << "," ; |
| 1799 | O << formatDec(Value: XorMask + 1); |
| 1800 | O << ")" ; |
| 1801 | |
| 1802 | } else { |
| 1803 | |
| 1804 | uint16_t GroupSize = BITMASK_MAX - AndMask + 1; |
| 1805 | if (GroupSize > 1 && |
| 1806 | isPowerOf2_64(Value: GroupSize) && |
| 1807 | OrMask < GroupSize && |
| 1808 | XorMask == 0) { |
| 1809 | |
| 1810 | O << "swizzle(" << IdSymbolic[ID_BROADCAST]; |
| 1811 | O << "," ; |
| 1812 | O << formatDec(Value: GroupSize); |
| 1813 | O << "," ; |
| 1814 | O << formatDec(Value: OrMask); |
| 1815 | O << ")" ; |
| 1816 | |
| 1817 | } else { |
| 1818 | O << "swizzle(" << IdSymbolic[ID_BITMASK_PERM]; |
| 1819 | O << "," ; |
| 1820 | printSwizzleBitmask(AndMask, OrMask, XorMask, O); |
| 1821 | O << ")" ; |
| 1822 | } |
| 1823 | } |
| 1824 | } else { |
| 1825 | printU16ImmDecOperand(MI, OpNo, O); |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | void AMDGPUInstPrinter::printSWaitCnt(const MCInst *MI, unsigned OpNo, |
| 1830 | const MCSubtargetInfo &STI, |
| 1831 | raw_ostream &O) { |
| 1832 | AMDGPU::IsaVersion ISA = AMDGPU::getIsaVersion(GPU: STI.getCPU()); |
| 1833 | |
| 1834 | unsigned SImm16 = MI->getOperand(i: OpNo).getImm(); |
| 1835 | unsigned Vmcnt, Expcnt, Lgkmcnt; |
| 1836 | decodeWaitcnt(Version: ISA, Waitcnt: SImm16, Vmcnt, Expcnt, Lgkmcnt); |
| 1837 | |
| 1838 | bool IsDefaultVmcnt = Vmcnt == getVmcntBitMask(Version: ISA); |
| 1839 | bool IsDefaultExpcnt = Expcnt == getExpcntBitMask(Version: ISA); |
| 1840 | bool IsDefaultLgkmcnt = Lgkmcnt == getLgkmcntBitMask(Version: ISA); |
| 1841 | bool PrintAll = IsDefaultVmcnt && IsDefaultExpcnt && IsDefaultLgkmcnt; |
| 1842 | |
| 1843 | ListSeparator Sep(" " ); |
| 1844 | |
| 1845 | if (!IsDefaultVmcnt || PrintAll) |
| 1846 | O << Sep << "vmcnt(" << Vmcnt << ')'; |
| 1847 | |
| 1848 | if (!IsDefaultExpcnt || PrintAll) |
| 1849 | O << Sep << "expcnt(" << Expcnt << ')'; |
| 1850 | |
| 1851 | if (!IsDefaultLgkmcnt || PrintAll) |
| 1852 | O << Sep << "lgkmcnt(" << Lgkmcnt << ')'; |
| 1853 | } |
| 1854 | |
| 1855 | void AMDGPUInstPrinter::printDepCtr(const MCInst *MI, unsigned OpNo, |
| 1856 | const MCSubtargetInfo &STI, |
| 1857 | raw_ostream &O) { |
| 1858 | using namespace llvm::AMDGPU::DepCtr; |
| 1859 | |
| 1860 | uint64_t Imm16 = MI->getOperand(i: OpNo).getImm() & 0xffff; |
| 1861 | |
| 1862 | bool HasNonDefaultVal = false; |
| 1863 | if (isSymbolicDepCtrEncoding(Code: Imm16, HasNonDefaultVal, STI)) { |
| 1864 | int Id = 0; |
| 1865 | StringRef Name; |
| 1866 | unsigned Val; |
| 1867 | bool IsDefault; |
| 1868 | ListSeparator Sep(" " ); |
| 1869 | while (decodeDepCtr(Code: Imm16, Id, Name, Val, IsDefault, STI)) { |
| 1870 | if (!IsDefault || !HasNonDefaultVal) |
| 1871 | O << Sep << Name << '(' << Val << ')'; |
| 1872 | } |
| 1873 | } else { |
| 1874 | O << formatHex(Value: Imm16); |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | void AMDGPUInstPrinter::printSDelayALU(const MCInst *MI, unsigned OpNo, |
| 1879 | const MCSubtargetInfo &STI, |
| 1880 | raw_ostream &O) { |
| 1881 | const char *BadInstId = "/* invalid instid value */" ; |
| 1882 | static const std::array<const char *, 12> InstIds = { |
| 1883 | "NO_DEP" , "VALU_DEP_1" , "VALU_DEP_2" , |
| 1884 | "VALU_DEP_3" , "VALU_DEP_4" , "TRANS32_DEP_1" , |
| 1885 | "TRANS32_DEP_2" , "TRANS32_DEP_3" , "FMA_ACCUM_CYCLE_1" , |
| 1886 | "SALU_CYCLE_1" , "SALU_CYCLE_2" , "SALU_CYCLE_3" }; |
| 1887 | |
| 1888 | const char *BadInstSkip = "/* invalid instskip value */" ; |
| 1889 | static const std::array<const char *, 6> InstSkips = { |
| 1890 | "SAME" , "NEXT" , "SKIP_1" , "SKIP_2" , "SKIP_3" , "SKIP_4" }; |
| 1891 | |
| 1892 | unsigned SImm16 = MI->getOperand(i: OpNo).getImm(); |
| 1893 | const char *Prefix = "" ; |
| 1894 | |
| 1895 | unsigned Value = SImm16 & 0xF; |
| 1896 | if (Value) { |
| 1897 | const char *Name = Value < InstIds.size() ? InstIds[Value] : BadInstId; |
| 1898 | O << Prefix << "instid0(" << Name << ')'; |
| 1899 | Prefix = " | " ; |
| 1900 | } |
| 1901 | |
| 1902 | Value = (SImm16 >> 4) & 7; |
| 1903 | if (Value) { |
| 1904 | const char *Name = |
| 1905 | Value < InstSkips.size() ? InstSkips[Value] : BadInstSkip; |
| 1906 | O << Prefix << "instskip(" << Name << ')'; |
| 1907 | Prefix = " | " ; |
| 1908 | } |
| 1909 | |
| 1910 | Value = (SImm16 >> 7) & 0xF; |
| 1911 | if (Value) { |
| 1912 | const char *Name = Value < InstIds.size() ? InstIds[Value] : BadInstId; |
| 1913 | O << Prefix << "instid1(" << Name << ')'; |
| 1914 | Prefix = " | " ; |
| 1915 | } |
| 1916 | |
| 1917 | if (!*Prefix) |
| 1918 | O << "0" ; |
| 1919 | } |
| 1920 | |
| 1921 | void AMDGPUInstPrinter::printHwreg(const MCInst *MI, unsigned OpNo, |
| 1922 | const MCSubtargetInfo &STI, raw_ostream &O) { |
| 1923 | using namespace llvm::AMDGPU::Hwreg; |
| 1924 | unsigned Val = MI->getOperand(i: OpNo).getImm(); |
| 1925 | auto [Id, Offset, Width] = HwregEncoding::decode(Encoded: Val); |
| 1926 | StringRef HwRegName = getHwreg(Encoding: Id, STI); |
| 1927 | |
| 1928 | O << "hwreg(" ; |
| 1929 | if (!HwRegName.empty()) { |
| 1930 | O << HwRegName; |
| 1931 | } else { |
| 1932 | O << Id; |
| 1933 | } |
| 1934 | if (Width != HwregSize::Default || Offset != HwregOffset::Default) |
| 1935 | O << ", " << Offset << ", " << Width; |
| 1936 | O << ')'; |
| 1937 | } |
| 1938 | |
| 1939 | void AMDGPUInstPrinter::printEndpgm(const MCInst *MI, unsigned OpNo, |
| 1940 | const MCSubtargetInfo &STI, |
| 1941 | raw_ostream &O) { |
| 1942 | uint16_t Imm = MI->getOperand(i: OpNo).getImm(); |
| 1943 | if (Imm == 0) { |
| 1944 | return; |
| 1945 | } |
| 1946 | |
| 1947 | O << ' ' << formatDec(Value: Imm); |
| 1948 | } |
| 1949 | |
| 1950 | void AMDGPUInstPrinter::printNamedInt(const MCInst *MI, unsigned OpNo, |
| 1951 | const MCSubtargetInfo &STI, |
| 1952 | raw_ostream &O, StringRef Prefix, |
| 1953 | bool PrintInHex, bool AlwaysPrint) { |
| 1954 | int64_t V = MI->getOperand(i: OpNo).getImm(); |
| 1955 | if (AlwaysPrint || V != 0) |
| 1956 | O << ' ' << Prefix << ':' << (PrintInHex ? formatHex(Value: V) : formatDec(Value: V)); |
| 1957 | } |
| 1958 | |
| 1959 | void AMDGPUInstPrinter::printBitOp3(const MCInst *MI, unsigned OpNo, |
| 1960 | const MCSubtargetInfo &STI, |
| 1961 | raw_ostream &O) { |
| 1962 | uint8_t Imm = MI->getOperand(i: OpNo).getImm(); |
| 1963 | if (!Imm) |
| 1964 | return; |
| 1965 | |
| 1966 | O << " bitop3:" ; |
| 1967 | if (Imm <= 10) |
| 1968 | O << formatDec(Value: Imm); |
| 1969 | else |
| 1970 | O << formatHex(Value: static_cast<uint64_t>(Imm)); |
| 1971 | } |
| 1972 | |
| 1973 | #include "AMDGPUGenAsmWriter.inc" |
| 1974 | |