#include "Disassembler/AMDGPUDisassembler.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
#include "SIDefines.h"
#include "SIRegisterInfo.h"
#include "TargetInfo/AMDGPUTargetInfo.h"
#include "Utils/AMDGPUAsmUtils.h"
#include "Utils/AMDGPUBaseInfo.h"
#include "llvm-c/DisassemblerTypes.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDecoderOps.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/AMDHSAKernelDescriptor.h"
usingnamespacellvm;
#define DEBUG_TYPE …
#define SGPR_MAX …
DecodeStatus;
static const MCSubtargetInfo &addDefaultWaveSize(const MCSubtargetInfo &STI,
MCContext &Ctx) { … }
AMDGPUDisassembler::AMDGPUDisassembler(const MCSubtargetInfo &STI,
MCContext &Ctx, MCInstrInfo const *MCII)
: … { … }
void AMDGPUDisassembler::setABIVersion(unsigned Version) { … }
inline static MCDisassembler::DecodeStatus
addOperand(MCInst &Inst, const MCOperand& Opnd) { … }
static int insertNamedMCOperand(MCInst &MI, const MCOperand &Op,
uint16_t NameIdx) { … }
static DecodeStatus decodeSOPPBrTarget(MCInst &Inst, unsigned Imm,
uint64_t Addr,
const MCDisassembler *Decoder) { … }
static DecodeStatus decodeSMEMOffset(MCInst &Inst, unsigned Imm, uint64_t Addr,
const MCDisassembler *Decoder) { … }
static DecodeStatus decodeBoolReg(MCInst &Inst, unsigned Val, uint64_t Addr,
const MCDisassembler *Decoder) { … }
static DecodeStatus decodeSplitBarrier(MCInst &Inst, unsigned Val,
uint64_t Addr,
const MCDisassembler *Decoder) { … }
static DecodeStatus decodeDpp8FI(MCInst &Inst, unsigned Val, uint64_t Addr,
const MCDisassembler *Decoder) { … }
#define DECODE_OPERAND(StaticDecoderName, DecoderName) …
#define DECODE_OPERAND_REG_8(RegClass) …
#define DECODE_SrcOp(Name, EncSize, OpWidth, EncImm, MandatoryLiteral, \
ImmWidth) …
static DecodeStatus decodeSrcOp(MCInst &Inst, unsigned EncSize,
AMDGPUDisassembler::OpWidthTy OpWidth,
unsigned Imm, unsigned EncImm,
bool MandatoryLiteral, unsigned ImmWidth,
AMDGPU::OperandSemantics Sema,
const MCDisassembler *Decoder) { … }
#define DECODE_OPERAND_REG_7(RegClass, OpWidth) …
template <AMDGPUDisassembler::OpWidthTy OpWidth>
static DecodeStatus decodeAV10(MCInst &Inst, unsigned Imm, uint64_t ,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy OpWidth>
static DecodeStatus decodeSrcReg9(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy OpWidth>
static DecodeStatus decodeSrcA9(MCInst &Inst, unsigned Imm, uint64_t ,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy OpWidth>
static DecodeStatus decodeSrcAV10(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy OpWidth, unsigned ImmWidth,
unsigned OperandSemantics>
static DecodeStatus decodeSrcRegOrImm9(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy OpWidth, unsigned ImmWidth,
unsigned OperandSemantics>
static DecodeStatus decodeSrcRegOrImmA9(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy OpWidth, unsigned ImmWidth,
unsigned OperandSemantics>
static DecodeStatus decodeSrcRegOrImmDeferred9(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_7(…) …
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
DECODE_OPERAND_REG_8(…)
static DecodeStatus DecodeVGPR_16RegisterClass(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
static DecodeStatus
DecodeVGPR_16_Lo128RegisterClass(MCInst &Inst, unsigned Imm, uint64_t ,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy OpWidth, unsigned ImmWidth,
unsigned OperandSemantics>
static DecodeStatus decodeOperand_VSrcT16_Lo128(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy OpWidth, unsigned ImmWidth,
unsigned OperandSemantics>
static DecodeStatus decodeOperand_VSrcT16(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
static DecodeStatus decodeOperand_KImmFP(MCInst &Inst, unsigned Imm,
uint64_t Addr,
const MCDisassembler *Decoder) { … }
static DecodeStatus decodeOperandVOPDDstY(MCInst &Inst, unsigned Val,
uint64_t Addr, const void *Decoder) { … }
static bool IsAGPROperand(const MCInst &Inst, int OpIdx,
const MCRegisterInfo *MRI) { … }
static DecodeStatus decodeAVLdSt(MCInst &Inst, unsigned Imm,
AMDGPUDisassembler::OpWidthTy Opw,
const MCDisassembler *Decoder) { … }
template <AMDGPUDisassembler::OpWidthTy Opw>
static DecodeStatus decodeAVLdSt(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
static DecodeStatus decodeOperand_VSrc_f64(MCInst &Inst, unsigned Imm,
uint64_t Addr,
const MCDisassembler *Decoder) { … }
#define DECODE_SDWA(DecName) …
DECODE_SDWA(…)
DECODE_SDWA(…)
DECODE_SDWA(…)
static DecodeStatus decodeVersionImm(MCInst &Inst, unsigned Imm,
uint64_t ,
const MCDisassembler *Decoder) { … }
#include "AMDGPUGenDisassemblerTables.inc"
template <typename T> static inline T eatBytes(ArrayRef<uint8_t>& Bytes) { … }
static inline DecoderUInt128 eat12Bytes(ArrayRef<uint8_t> &Bytes) { … }
DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
ArrayRef<uint8_t> Bytes_,
uint64_t Address,
raw_ostream &CS) const { … }
void AMDGPUDisassembler::convertEXPInst(MCInst &MI) const { … }
void AMDGPUDisassembler::convertVINTERPInst(MCInst &MI) const { … }
void AMDGPUDisassembler::convertSDWAInst(MCInst &MI) const { … }
struct VOPModifiers { … };
static VOPModifiers collectVOPModifiers(const MCInst &MI,
bool IsVOP3P = false) { … }
void AMDGPUDisassembler::convertTrue16OpSel(MCInst &MI) const { … }
bool AMDGPUDisassembler::isMacDPP(MCInst &MI) const { … }
void AMDGPUDisassembler::convertMacDPPInst(MCInst &MI) const { … }
void AMDGPUDisassembler::convertDPP8Inst(MCInst &MI) const { … }
void AMDGPUDisassembler::convertVOP3DPPInst(MCInst &MI) const { … }
void AMDGPUDisassembler::convertMIMGInst(MCInst &MI) const { … }
void AMDGPUDisassembler::convertVOP3PDPPInst(MCInst &MI) const { … }
void AMDGPUDisassembler::convertVOPCDPPInst(MCInst &MI) const { … }
void AMDGPUDisassembler::convertFMAanyK(MCInst &MI, int ImmLitIdx) const { … }
const char* AMDGPUDisassembler::getRegClassName(unsigned RegClassID) const { … }
inline
MCOperand AMDGPUDisassembler::errOperand(unsigned V,
const Twine& ErrMsg) const { … }
inline
MCOperand AMDGPUDisassembler::createRegOperand(unsigned int RegId) const { … }
inline
MCOperand AMDGPUDisassembler::createRegOperand(unsigned RegClassID,
unsigned Val) const { … }
inline
MCOperand AMDGPUDisassembler::createSRegOperand(unsigned SRegClassID,
unsigned Val) const { … }
MCOperand AMDGPUDisassembler::createVGPR16Operand(unsigned RegIdx,
bool IsHi) const { … }
MCOperand
AMDGPUDisassembler::decodeMandatoryLiteralConstant(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeLiteralConstant(bool ExtendFP64) const { … }
MCOperand AMDGPUDisassembler::decodeIntImmed(unsigned Imm) { … }
static int64_t getInlineImmVal32(unsigned Imm) { … }
static int64_t getInlineImmVal64(unsigned Imm) { … }
static int64_t getInlineImmValF16(unsigned Imm) { … }
static int64_t getInlineImmValBF16(unsigned Imm) { … }
static int64_t getInlineImmVal16(unsigned Imm, AMDGPU::OperandSemantics Sema) { … }
MCOperand AMDGPUDisassembler::decodeFPImmed(unsigned ImmWidth, unsigned Imm,
AMDGPU::OperandSemantics Sema) { … }
unsigned AMDGPUDisassembler::getVgprClassId(const OpWidthTy Width) const { … }
unsigned AMDGPUDisassembler::getAgprClassId(const OpWidthTy Width) const { … }
unsigned AMDGPUDisassembler::getSgprClassId(const OpWidthTy Width) const { … }
unsigned AMDGPUDisassembler::getTtmpClassId(const OpWidthTy Width) const { … }
int AMDGPUDisassembler::getTTmpIdx(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeSrcOp(const OpWidthTy Width, unsigned Val,
bool MandatoryLiteral,
unsigned ImmWidth,
AMDGPU::OperandSemantics Sema) const { … }
MCOperand
AMDGPUDisassembler::decodeNonVGPRSrcOp(const OpWidthTy Width, unsigned Val,
bool MandatoryLiteral, unsigned ImmWidth,
AMDGPU::OperandSemantics Sema) const { … }
MCOperand AMDGPUDisassembler::decodeVOPDDstYOp(MCInst &Inst,
unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeSpecialReg32(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeSpecialReg64(unsigned Val) const { … }
MCOperand
AMDGPUDisassembler::decodeSDWASrc(const OpWidthTy Width, const unsigned Val,
unsigned ImmWidth,
AMDGPU::OperandSemantics Sema) const { … }
MCOperand AMDGPUDisassembler::decodeSDWASrc16(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeSDWASrc32(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeSDWAVopcDst(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeBoolReg(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeSplitBarrier(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeDpp8FI(unsigned Val) const { … }
MCOperand AMDGPUDisassembler::decodeVersionImm(unsigned Imm) const { … }
bool AMDGPUDisassembler::isVI() const { … }
bool AMDGPUDisassembler::isGFX9() const { … }
bool AMDGPUDisassembler::isGFX90A() const { … }
bool AMDGPUDisassembler::isGFX9Plus() const { … }
bool AMDGPUDisassembler::isGFX10() const { … }
bool AMDGPUDisassembler::isGFX10Plus() const { … }
bool AMDGPUDisassembler::isGFX11() const { … }
bool AMDGPUDisassembler::isGFX11Plus() const { … }
bool AMDGPUDisassembler::isGFX12() const { … }
bool AMDGPUDisassembler::isGFX12Plus() const { … }
bool AMDGPUDisassembler::hasArchitectedFlatScratch() const { … }
bool AMDGPUDisassembler::hasKernargPreload() const { … }
static SmallString<32> getBitRangeFromMask(uint32_t Mask, unsigned BaseBytes) { … }
#define GET_FIELD …
#define PRINT_DIRECTIVE …
#define PRINT_PSEUDO_DIRECTIVE_COMMENT …
#define CHECK_RESERVED_BITS_IMPL …
#define CHECK_RESERVED_BITS …
#define CHECK_RESERVED_BITS_MSG …
#define CHECK_RESERVED_BITS_DESC …
#define CHECK_RESERVED_BITS_DESC_MSG …
Expected<bool> AMDGPUDisassembler::decodeCOMPUTE_PGM_RSRC1(
uint32_t FourByteBuffer, raw_string_ostream &KdStream) const { … }
Expected<bool> AMDGPUDisassembler::decodeCOMPUTE_PGM_RSRC2(
uint32_t FourByteBuffer, raw_string_ostream &KdStream) const { … }
Expected<bool> AMDGPUDisassembler::decodeCOMPUTE_PGM_RSRC3(
uint32_t FourByteBuffer, raw_string_ostream &KdStream) const { … }
#undef PRINT_PSEUDO_DIRECTIVE_COMMENT
#undef PRINT_DIRECTIVE
#undef GET_FIELD
#undef CHECK_RESERVED_BITS_IMPL
#undef CHECK_RESERVED_BITS
#undef CHECK_RESERVED_BITS_MSG
#undef CHECK_RESERVED_BITS_DESC
#undef CHECK_RESERVED_BITS_DESC_MSG
static Error createReservedKDBitsError(uint32_t Mask, unsigned BaseBytes,
const char *Msg = "") { … }
static Error createReservedKDBytesError(unsigned BaseInBytes,
unsigned WidthInBytes) { … }
Expected<bool> AMDGPUDisassembler::decodeKernelDescriptorDirective(
DataExtractor::Cursor &Cursor, ArrayRef<uint8_t> Bytes,
raw_string_ostream &KdStream) const { … }
Expected<bool> AMDGPUDisassembler::decodeKernelDescriptor(
StringRef KdName, ArrayRef<uint8_t> Bytes, uint64_t KdAddress) const { … }
Expected<bool> AMDGPUDisassembler::onSymbolStart(SymbolInfoTy &Symbol,
uint64_t &Size,
ArrayRef<uint8_t> Bytes,
uint64_t Address) const { … }
const MCExpr *AMDGPUDisassembler::createConstantSymbolExpr(StringRef Id,
int64_t Val) { … }
bool AMDGPUSymbolizer::tryAddingSymbolicOperand(
MCInst &Inst, raw_ostream & , int64_t Value,
uint64_t , bool IsBranch, uint64_t ,
uint64_t , uint64_t ) { … }
void AMDGPUSymbolizer::tryAddingPcLoadReferenceComment(raw_ostream &cStream,
int64_t Value,
uint64_t Address) { … }
static MCSymbolizer *createAMDGPUSymbolizer(const Triple &,
LLVMOpInfoCallback ,
LLVMSymbolLookupCallback ,
void *DisInfo,
MCContext *Ctx,
std::unique_ptr<MCRelocationInfo> &&RelInfo) { … }
static MCDisassembler *createAMDGPUDisassembler(const Target &T,
const MCSubtargetInfo &STI,
MCContext &Ctx) { … }
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUDisassembler() { … }