53 #define DEBUG_TYPE "amdgpu-disassembler" 55 #define SGPR_MAX (isGFX10() ? AMDGPU::EncValues::SGPR_MAX_GFX10 \ 56 : AMDGPU::EncValues::SGPR_MAX_SI) 64 TargetMaxInstBytes(Ctx.getAsmInfo()->getMaxInstLength(&STI)) {
84 std::advance(
I, OpIdx);
91 uint64_t Addr,
const void *Decoder) {
96 APInt SignedOffset(18, Imm * 4,
true);
97 int64_t
Offset = (SignedOffset.
sext(64) + 4 + Addr).getSExtValue();
99 if (DAsm->tryAddingSymbolicOperand(Inst, Offset, Addr,
true, 2, 2))
105 uint64_t Addr,
const void *Decoder) {
107 return addOperand(Inst, DAsm->decodeBoolReg(Val));
110 #define DECODE_OPERAND(StaticDecoderName, DecoderName) \ 111 static DecodeStatus StaticDecoderName(MCInst &Inst, \ 114 const void *Decoder) { \ 115 auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder); \ 116 return addOperand(Inst, DAsm->DecoderName(Imm)); \ 119 #define DECODE_OPERAND_REG(RegClass) \ 120 DECODE_OPERAND(Decode##RegClass##RegisterClass, decodeOperand_##RegClass) 152 const void *Decoder) {
154 return addOperand(Inst, DAsm->decodeOperand_VSrc16(Imm));
160 const void *Decoder) {
162 return addOperand(Inst, DAsm->decodeOperand_VSrcV216(Imm));
168 const void *Decoder) {
170 return addOperand(Inst, DAsm->decodeOperand_VSrc16(Imm));
176 const void *Decoder) {
178 return addOperand(Inst, DAsm->decodeOperand_VS_32(Imm));
184 const void *Decoder) {
192 const void *Decoder) {
200 const void *Decoder) {
208 const void *Decoder) {
210 return addOperand(Inst, DAsm->decodeOperand_SReg_32(Imm));
216 const void *Decoder) {
221 #define DECODE_SDWA(DecName) \ 222 DECODE_OPERAND(decodeSDWA##DecName, decodeSDWA##DecName) 228 #include "AMDGPUGenDisassemblerTables.inc" 236 const auto Res = support::endian::read<T, support::endianness::little>(Bytes.
data());
237 Bytes = Bytes.
slice(
sizeof(
T));
249 const auto SavedBytes = Bytes;
250 if (decodeInstruction(Table, TmpInst, Inst, Address,
this,
STI)) {
275 unsigned MaxInstBytesNum = std::min((
size_t)TargetMaxInstBytes, Bytes_.
size());
276 Bytes = Bytes_.
slice(0, MaxInstBytesNum);
285 if (Bytes.size() >= 8) {
286 const uint64_t QW = eatBytes<uint64_t>(Bytes);
298 if (Res) { IsSDWA =
true;
break; }
301 if (Res) { IsSDWA =
true;
break; }
304 if (Res) { IsSDWA =
true;
break; }
307 Res =
tryDecodeInst(DecoderTableGFX80_UNPACKED64, MI, QW, Address);
323 Bytes = Bytes_.
slice(0, MaxInstBytesNum);
326 if (Bytes.size() < 4)
break;
327 const uint32_t DW = eatBytes<uint32_t>(Bytes);
340 if (Bytes.size() < 4)
break;
341 const uint64_t QW = ((uint64_t)eatBytes<uint32_t>(Bytes) << 32) | DW;
354 if (Res && (MaxInstBytesNum - Bytes.size()) == 12 && (!HasLiteral ||
357 Bytes = Bytes_.
slice(0, MaxInstBytesNum);
358 eatBytes<uint64_t>(Bytes);
361 if (Res && (MI.
getOpcode() == AMDGPU::V_MAC_F32_e64_vi ||
362 MI.
getOpcode() == AMDGPU::V_MAC_F32_e64_gfx6_gfx7 ||
363 MI.
getOpcode() == AMDGPU::V_MAC_F32_e64_gfx10 ||
364 MI.
getOpcode() == AMDGPU::V_MAC_F16_e64_vi ||
365 MI.
getOpcode() == AMDGPU::V_FMAC_F32_e64_vi ||
366 MI.
getOpcode() == AMDGPU::V_FMAC_F32_e64_gfx10 ||
367 MI.
getOpcode() == AMDGPU::V_FMAC_F16_e64_gfx10)) {
370 AMDGPU::OpName::src2_modifiers);
378 unsigned NSAArgs = RsrcIdx - VAddr0Idx - 1;
379 if (VAddr0Idx >= 0 && NSAArgs > 0) {
380 unsigned NSAWords = (NSAArgs + 3) / 4;
381 if (Bytes.size() < 4 * NSAWords) {
384 for (
unsigned i = 0; i < NSAArgs; ++i) {
388 Bytes = Bytes.slice(4 * NSAWords);
400 AMDGPU::OpName::vdst_in);
401 if (VDstIn_Idx != -1) {
402 int Tied = MCII->get(MI.
getOpcode()).getOperandConstraint(VDstIn_Idx,
411 AMDGPU::OpName::vdst_in);
417 Size = Res ? (MaxInstBytesNum - Bytes.size())
418 : std::min((
size_t)4, Bytes_.
size());
433 AMDGPU::OpName::sdst);
444 unsigned DescNumOps = MCII->get(Opc).getNumOperands();
450 AMDGPU::OpName::src0_modifiers);
455 AMDGPU::OpName::src1_modifiers);
466 AMDGPU::OpName::vdst);
469 AMDGPU::OpName::vdata);
473 AMDGPU::OpName::dmask);
476 AMDGPU::OpName::tfe);
478 AMDGPU::OpName::d16);
485 bool IsAtomic = (VDstIdx != -1);
499 AddrSize = BaseOpcode->NumExtraArgs +
501 (BaseOpcode->Coordinates ? Dim->
NumCoords : 0) +
502 (BaseOpcode->LodOrClampOrMip ? 1 : 0);
507 else if (AddrSize > 4)
523 DstSize = (DstSize + 1) / 2;
539 unsigned NewVdata = AMDGPU::NoRegister;
541 auto DataRCID = MCII->get(NewOpcode).OpInfo[VDataIdx].RegClass;
545 unsigned VdataSub0 =
MRI.getSubReg(Vdata0, AMDGPU::sub0);
546 Vdata0 = (VdataSub0 != 0)? VdataSub0 : Vdata0;
548 NewVdata =
MRI.getMatchingSuperReg(Vdata0, AMDGPU::sub0,
549 &
MRI.getRegClass(DataRCID));
550 if (NewVdata == AMDGPU::NoRegister) {
557 unsigned NewVAddr0 = AMDGPU::NoRegister;
561 unsigned VAddrSub0 =
MRI.getSubReg(VAddr0, AMDGPU::sub0);
562 VAddr0 = (VAddrSub0 != 0) ? VAddrSub0 : VAddr0;
564 auto AddrRCID = MCII->get(NewOpcode).OpInfo[VAddr0Idx].RegClass;
565 NewVAddr0 =
MRI.getMatchingSuperReg(VAddr0, AMDGPU::sub0,
566 &
MRI.getRegClass(AddrRCID));
567 if (NewVAddr0 == AMDGPU::NoRegister)
573 if (NewVdata != AMDGPU::NoRegister) {
582 if (NewVAddr0 != AMDGPU::NoRegister) {
585 assert(AddrSize <= Info->VAddrDwords);
600 const Twine& ErrMsg)
const {
615 unsigned Val)
const {
616 const auto& RegCl = AMDGPUMCRegisterClasses[RegClassID];
617 if (Val >= RegCl.getNumRegs())
619 ": unknown register " +
Twine(Val));
625 unsigned Val)
const {
629 switch (SRegClassID) {
630 case AMDGPU::SGPR_32RegClassID:
631 case AMDGPU::TTMP_32RegClassID:
633 case AMDGPU::SGPR_64RegClassID:
634 case AMDGPU::TTMP_64RegClassID:
637 case AMDGPU::SGPR_128RegClassID:
638 case AMDGPU::TTMP_128RegClassID:
641 case AMDGPU::SGPR_256RegClassID:
642 case AMDGPU::TTMP_256RegClassID:
645 case AMDGPU::SGPR_512RegClassID:
646 case AMDGPU::TTMP_512RegClassID:
655 if (Val % (1 << shift)) {
657 <<
": scalar reg isn't aligned " << Val;
748 unsigned Val)
const {
754 unsigned Val)
const {
791 if (Bytes.size() < 4) {
792 return errOperand(0,
"cannot read literal, inst bytes left " +
793 Twine(Bytes.size()));
796 Literal = eatBytes<uint32_t>(Bytes);
802 using namespace AMDGPU::EncValues;
855 return 0x3fc45f306dc9c882;
916 return VGPR_32RegClassID;
917 case OPW64:
return VReg_64RegClassID;
918 case OPW128:
return VReg_128RegClassID;
931 return AGPR_32RegClassID;
932 case OPW64:
return AReg_64RegClassID;
933 case OPW128:
return AReg_128RegClassID;
934 case OPW512:
return AReg_512RegClassID;
935 case OPW1024:
return AReg_1024RegClassID;
949 return SGPR_32RegClassID;
950 case OPW64:
return SGPR_64RegClassID;
951 case OPW128:
return SGPR_128RegClassID;
952 case OPW256:
return SGPR_256RegClassID;
953 case OPW512:
return SGPR_512RegClassID;
966 return TTMP_32RegClassID;
967 case OPW64:
return TTMP_64RegClassID;
968 case OPW128:
return TTMP_128RegClassID;
969 case OPW256:
return TTMP_256RegClassID;
970 case OPW512:
return TTMP_512RegClassID;
975 using namespace AMDGPU::EncValues;
982 return (TTmpMin <= Val && Val <= TTmpMax)? Val - TTmpMin : -1;
986 using namespace AMDGPU::EncValues;
990 bool IsAGPR = Val & 512;
1029 using namespace AMDGPU::EncValues;
1104 const unsigned Val)
const {
1106 using namespace AMDGPU::EncValues;
1157 "SDWAVopcDst should be present only on GFX9+");
1203 uint64_t ,
bool IsBranch,
1204 uint64_t , uint64_t ) {
1205 using SymbolInfoTy = std::tuple<uint64_t, StringRef, uint8_t>;
1206 using SectionSymbolsTy = std::vector<SymbolInfoTy>;
1212 auto *Symbols =
static_cast<SectionSymbolsTy *
>(DisInfo);
1216 auto Result =
std::find_if(Symbols->begin(), Symbols->end(),
1217 [
Value](
const SymbolInfoTy& Val) {
1218 return std::get<0>(Val) == static_cast<uint64_t>(Value)
1221 if (Result != Symbols->end()) {
1222 auto *Sym = Ctx.getOrCreateSymbol(std::get<1>(*Result));
1245 std::unique_ptr<MCRelocationInfo> &&RelInfo) {
MCOperand createRegOperand(unsigned int RegId) const
static int64_t getInlineImmVal16(unsigned Imm)
MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const
MCOperand decodeOperand_VGPR_32(unsigned Val) const
Target & getTheGCNTarget()
The target for GCN GPUs.
MCOperand decodeSDWASrc(const OpWidthTy Width, unsigned Val) const
bool hasPackedD16(const MCSubtargetInfo &STI)
APInt sext(unsigned width) const
Sign extend to a new width.
DecodeStatus convertDPP8Inst(MCInst &MI) const
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
#define DECODE_OPERAND_REG(RegClass)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
MCOperand decodeOperand_VReg_64(unsigned Val) const
MCOperand decodeOperand_VSrcV216(unsigned Val) const
DecodeStatus
Ternary decode status.
static MCOperand decodeFPImmed(OpWidthTy Width, unsigned Imm)
MCOperand decodeOperand_VS_128(unsigned Val) const
static MCOperand createExpr(const MCExpr *Val)
MCOperand decodeOperand_SReg_512(unsigned Val) const
static DecodeStatus decodeOperand_VS_16(MCInst &Inst, unsigned Imm, uint64_t Addr, const void *Decoder)
Superclass for all disassemblers.
raw_ostream * CommentStream
MCOperand decodeDstOp(const OpWidthTy Width, unsigned Val) const
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
const char * getRegClassName(unsigned RegClassID) const
static T eatBytes(ArrayRef< uint8_t > &Bytes)
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.
MCOperand decodeBoolReg(unsigned Val) const
MCOperand decodeOperand_VS_32(unsigned Val) const
MCOperand decodeLiteralConstant() const
MCOperand decodeOperand_AReg_128(unsigned Val) const
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
MCOperand decodeOperand_SReg_128(unsigned Val) const
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const FeatureBitset & getFeatureBits() const
MCOperand decodeSDWAVopcDst(unsigned Val) const
MCOperand errOperand(unsigned V, const Twine &ErrMsg) const
AMDGPUDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, MCInstrInfo const *MCII)
MCOperand decodeOperand_AReg_512(unsigned Val) const
LLVM_READONLY const MIMGDimInfo * getMIMGDimInfoByEncoding(uint8_t DimEnc)
int(* LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t Size, int TagType, void *TagBuf)
The type for the operand information call back function.
void tryAddingPcLoadReferenceComment(raw_ostream &cStream, int64_t Value, uint64_t Address) override
Try to add a comment on the PC-relative load.
This file implements a class to represent arbitrary precision integral constant values and operations...
unsigned getReg() const
Returns the register number.
TargetRegisterInfo interface that is implemented by all hw codegen targets.
static int64_t getInlineImmVal32(unsigned Imm)
Context object for machine code objects.
DecodeStatus convertSDWAInst(MCInst &MI) const
MCOperand decodeOperand_AReg_1024(unsigned Val) const
const MCSubtargetInfo & STI
MCOperand decodeSDWASrc32(unsigned Val) const
MCOperand decodeOperand_VReg_256(unsigned Val) const
LLVM_READONLY const MIMGBaseOpcodeInfo * getMIMGBaseOpcodeInfo(unsigned BaseOpcode)
static MCSymbolizer * createAMDGPUSymbolizer(const Triple &, LLVMOpInfoCallback, LLVMSymbolLookupCallback, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo)
iterator insert(iterator I, const MCOperand &Op)
Analysis containing CSE Info
Instances of this class represent a single low-level machine instruction.
DecodeStatus tryDecodeInst(const uint8_t *Table, MCInst &MI, uint64_t Inst, uint64_t Address) const
uint32_t FloatToBits(float Float)
This function takes a float and returns the bit equivalent 32-bit integer.
MCOperand decodeOperand_AV_64(unsigned Val) const
unsigned getVgprClassId(const OpWidthTy Width) const
unsigned const MachineRegisterInfo * MRI
MCOperand decodeOperand_VReg_128(unsigned Val) const
MCOperand decodeOperand_SReg_256(unsigned Val) const
MCOperand decodeOperand_SReg_32(unsigned Val) const
Symbolize and annotate disassembled instructions.
size_t size() const
size - Get the array size.
DecodeStatus convertMIMGInst(MCInst &MI) const
MCOperand decodeOperand_VS_64(unsigned Val) const
Interface to description of machine instruction set.
MCOperand decodeOperand_VReg_512(unsigned Val) const
unsigned getNumOperands() const
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
static DecodeStatus decodeSoppBrTarget(MCInst &Inst, unsigned Imm, uint64_t Addr, const void *Decoder)
static int64_t getInlineImmVal64(unsigned Imm)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding, unsigned VDataDwords, unsigned VAddrDwords)
unsigned getAgprClassId(const OpWidthTy Width) const
MCOperand decodeSDWASrc16(unsigned Val) const
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUDisassembler()
void setOpcode(unsigned Op)
unsigned countPopulation(T Value)
Count the number of set bits in a value.
Align max(MaybeAlign Lhs, Align Rhs)
const MCOperand & getOperand(unsigned i) const
MCContext & getContext() const
MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const
MCOperand decodeSrcOp(const OpWidthTy Width, unsigned Val) const
static bool isValidDPP8(const MCInst &MI)
#define LLVM_EXTERNAL_VISIBILITY
uint64_t DoubleToBits(double Double)
This function takes a double and returns the bit equivalent 64-bit integer.
static MCOperand decodeIntImmed(unsigned Imm)
#define DECODE_SDWA(DecName)
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
MCOperand decodeOperand_AGPR_32(unsigned Val) const
bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream, int64_t Value, uint64_t Address, bool IsBranch, uint64_t Offset, uint64_t InstSize) override
Try to add a symbolic operand instead of Value to the MCInst.
Provides AMDGPU specific target descriptions.
MCOperand decodeOperand_SReg_32_XEXEC_HI(unsigned Val) const
MCOperand decodeOperand_AV_32(unsigned Val) const
This file contains declaration for AMDGPU ISA disassembler.
MCOperand decodeOperand_VSrc16(unsigned Val) const
Generic base class for all target subtargets.
unsigned getSgprClassId(const OpWidthTy Width) const
MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const
DecodeStatus getInstruction(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CS) const override
Returns the disassembly of a single instruction.
MCOperand decodeOperand_VRegOrLds_32(unsigned Val) const
static int insertNamedMCOperand(MCInst &MI, const MCOperand &Op, uint16_t NameIdx)
static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn)
RegisterMCSymbolizer - Register an MCSymbolizer implementation for the given target.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCOperand decodeOperand_SReg_64(unsigned Val) const
const MCRegisterInfo * getRegisterInfo() const
MCOperand decodeOperand_VReg_96(unsigned Val) const
LLVM Value Representation.
MCOperand decodeOperand_SRegOrLds_32(unsigned Val) const
unsigned getTtmpClassId(const OpWidthTy Width) const
MCOperand decodeSpecialReg64(unsigned Val) const
unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI)
If Reg is a pseudo reg, return the correct hardware register given STI otherwise return Reg...
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
unsigned getOpcode() const
MCOperand decodeSpecialReg32(unsigned Val) const
int getTTmpIdx(unsigned Val) const
Instances of this class represent operands of the MCInst class.
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
static MCDisassembler * createAMDGPUDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
static MCOperand createImm(int64_t Val)