39 #define DEBUG_TYPE "amdgpu-disassembler"
57 std::advance(
I, OpIdx);
64 uint64_t Addr,
const void *Decoder) {
67 APInt SignedOffset(18, Imm * 4,
true);
68 int64_t
Offset = (SignedOffset.
sext(64) + 4 + Addr).getSExtValue();
70 if (DAsm->tryAddingSymbolicOperand(Inst, Offset, Addr,
true, 2, 2))
75 #define DECODE_OPERAND(StaticDecoderName, DecoderName) \
76 static DecodeStatus StaticDecoderName(MCInst &Inst, \
79 const void *Decoder) { \
80 auto DAsm = static_cast<const AMDGPUDisassembler*>(Decoder); \
81 return addOperand(Inst, DAsm->DecoderName(Imm)); \
84 #define DECODE_OPERAND_REG(RegClass) \
85 DECODE_OPERAND(Decode##RegClass##RegisterClass, decodeOperand_##RegClass)
108 const void *Decoder) {
110 return addOperand(Inst, DAsm->decodeOperand_VSrc16(Imm));
116 const void *Decoder) {
118 return addOperand(Inst, DAsm->decodeOperand_VSrcV216(Imm));
121 #define DECODE_SDWA(DecName) \
122 DECODE_OPERAND(decodeSDWA##DecName, decodeSDWA##DecName)
128 #include "AMDGPUGenDisassemblerTables.inc"
136 const auto Res = support::endian::read<T, support::endianness::little>(Bytes.
data());
137 Bytes = Bytes.
slice(
sizeof(
T));
149 const auto SavedBytes = Bytes;
170 const unsigned MaxInstBytesNum = (
std::min)((
size_t)8, Bytes_.
size());
171 Bytes = Bytes_.
slice(0, MaxInstBytesNum);
180 if (Bytes.
size() >= 8) {
181 const uint64_t QW = eatBytes<uint64_t>(Bytes);
186 if (Res) { IsSDWA =
true;
break; }
189 if (Res) { IsSDWA =
true;
break; }
193 Bytes = Bytes_.
slice(0, MaxInstBytesNum);
196 if (Bytes.
size() < 4)
break;
197 const uint32_t DW = eatBytes<uint32_t>(Bytes);
204 if (Bytes.
size() < 4)
break;
205 const uint64_t QW = ((uint64_t)eatBytes<uint32_t>(Bytes) << 32) | DW;
212 if (Res && (MI.
getOpcode() == AMDGPU::V_MAC_F32_e64_vi ||
213 MI.
getOpcode() == AMDGPU::V_MAC_F32_e64_si ||
214 MI.
getOpcode() == AMDGPU::V_MAC_F16_e64_vi)) {
217 AMDGPU::OpName::src2_modifiers);
223 Size = Res ? (MaxInstBytesNum - Bytes.
size()) : 0;
237 AMDGPU::OpName::sdst);
268 unsigned Val)
const {
269 const auto& RegCl = AMDGPUMCRegisterClasses[RegClassID];
270 if (Val >= RegCl.getNumRegs())
272 ": unknown register " +
Twine(Val));
278 unsigned Val)
const {
282 switch (SRegClassID) {
283 case AMDGPU::SGPR_32RegClassID:
284 case AMDGPU::TTMP_32RegClassID:
286 case AMDGPU::SGPR_64RegClassID:
287 case AMDGPU::TTMP_64RegClassID:
290 case AMDGPU::SGPR_128RegClassID:
291 case AMDGPU::TTMP_128RegClassID:
294 case AMDGPU::SReg_256RegClassID:
297 case AMDGPU::SReg_512RegClassID:
306 if (Val % (1 << shift)) {
308 <<
": scalar reg isn't aligned " << Val;
363 unsigned Val)
const {
394 if (Bytes.
size() < 4) {
395 return errOperand(0,
"cannot read literal, inst bytes left " +
399 Literal = eatBytes<uint32_t>(Bytes);
405 using namespace AMDGPU::EncValues;
457 return 0x3fc45f306dc9c882;
507 using namespace AMDGPU;
514 return VGPR_32RegClassID;
515 case OPW64:
return VReg_64RegClassID;
516 case OPW128:
return VReg_128RegClassID;
521 using namespace AMDGPU;
528 return SGPR_32RegClassID;
529 case OPW64:
return SGPR_64RegClassID;
530 case OPW128:
return SGPR_128RegClassID;
535 using namespace AMDGPU;
542 return TTMP_32RegClassID;
543 case OPW64:
return TTMP_64RegClassID;
544 case OPW128:
return TTMP_128RegClassID;
549 using namespace AMDGPU::EncValues;
585 using namespace AMDGPU;
617 using namespace AMDGPU;
630 unsigned Val)
const {
667 "SDWAVopcDst should be present only on GFX9");
687 uint64_t ,
bool IsBranch,
688 uint64_t , uint64_t ) {
689 typedef std::tuple<uint64_t, StringRef, uint8_t> SymbolInfoTy;
690 typedef std::vector<SymbolInfoTy> SectionSymbolsTy;
696 auto *Symbols =
static_cast<SectionSymbolsTy *
>(DisInfo);
697 auto Result =
std::find_if(Symbols->begin(), Symbols->end(),
698 [Value](
const SymbolInfoTy& Val) {
699 return std::get<0>(Val) == static_cast<uint64_t>(Value)
702 if (Result != Symbols->end()) {
703 auto *Sym = Ctx.getOrCreateSymbol(std::get<1>(*Result));
726 std::unique_ptr<MCRelocationInfo> &&RelInfo) {
static int64_t getInlineImmVal16(unsigned Imm)
Target & getTheGCNTarget()
The target for GCN GPUs.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCOperand createSRegOperand(unsigned SRegClassID, unsigned Val) const
#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.
DecodeStatus
Ternary decode status.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static MCOperand decodeFPImmed(OpWidthTy Width, unsigned Imm)
static MCOperand createExpr(const MCExpr *Val)
Superclass for all disassemblers.
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
raw_ostream * CommentStream
MCOperand errOperand(unsigned V, const Twine &ErrMsg) 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.
static MCDisassembler::DecodeStatus addOperand(MCInst &Inst, const MCOperand &Opnd)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
MCOperand decodeOperand_VReg_64(unsigned Val) const
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...
DecodeStatus convertSDWAInst(MCInst &MI) const
MCOperand createRegOperand(unsigned int RegId) const
MCOperand decodeSDWASrc(const OpWidthTy Width, unsigned Val) const
MCOperand decodeOperand_VS_64(unsigned Val) const
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
MCOperand decodeSDWASrc16(unsigned Val) const
MCOperand decodeOperand_VReg_96(unsigned Val) const
void tryAddingPcLoadReferenceComment(raw_ostream &cStream, int64_t Value, uint64_t Address) override
Try to add a comment on the PC-relative load.
TargetRegisterInfo interface that is implemented by all hw codegen targets.
static int64_t getInlineImmVal32(unsigned Imm)
Context object for machine code objects.
MCOperand decodeSDWASrc32(unsigned Val) const
const MCSubtargetInfo & STI
int decodeInstruction(InternalInstruction *insn, byteReader_t reader, const void *readerArg, dlog_t logger, void *loggerArg, const void *miiArg, uint64_t startLoc, DisassemblerMode mode)
Decode one instruction and store the decoding results in a buffer provided by the consumer...
MCOperand decodeOperand_VS_32(unsigned Val) const
MCOperand decodeSpecialReg32(unsigned Val) const
MCOperand decodeOperand_VSrcV216(unsigned Val) const
MCContext & getContext() const
size_t size() const
size - Get the array size.
static MCSymbolizer * createAMDGPUSymbolizer(const Triple &, LLVMOpInfoCallback, LLVMSymbolLookupCallback, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo)
iterator insert(iterator I, const MCOperand &Op)
Instances of this class represent a single low-level machine instruction.
MCOperand decodeOperand_SReg_64_XEXEC(unsigned Val) const
uint32_t FloatToBits(float Float)
This function takes a float and returns the bit equivalent 32-bit integer.
MCOperand decodeSrcOp(const OpWidthTy Width, unsigned Val) const
MCOperand decodeOperand_SReg_512(unsigned Val) const
Symbolize and annotate disassembled instructions.
AMDGPUDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx)
MCOperand decodeOperand_SReg_128(unsigned Val) const
APInt sext(unsigned width) const
Sign extend to a new width.
DecodeStatus tryDecodeInst(const uint8_t *Table, MCInst &MI, uint64_t Inst, uint64_t Address) const
MCOperand decodeSDWAVopcDst(unsigned Val) const
static DecodeStatus decodeSoppBrTarget(MCInst &Inst, unsigned Imm, uint64_t Addr, const void *Decoder)
static int64_t getInlineImmVal64(unsigned Imm)
Triple - Helper class for working with autoconf configuration names.
llvm::MCDisassembler::DecodeStatus DecodeStatus
const char * getRegClassName(unsigned RegClassID) const
MCOperand decodeOperand_VSrc16(unsigned Val) const
MCOperand decodeOperand_SReg_32(unsigned Val) const
MCOperand decodeOperand_VGPR_32(unsigned Val) const
static DecodeStatus decodeOperand_VSrc16(MCInst &Inst, unsigned Imm, uint64_t Addr, const void *Decoder)
const FeatureBitset & getFeatureBits() const
getFeatureBits - Return the feature bits.
uint64_t DoubleToBits(double Double)
This function takes a double and returns the bit equivalent 64-bit integer.
MCOperand decodeOperand_VReg_128(unsigned Val) const
static MCOperand decodeIntImmed(unsigned Imm)
#define DECODE_SDWA(DecName)
unsigned getOpcode() const
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
const MCRegisterInfo * getRegisterInfo() 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.
static DecodeStatus decodeOperand_VSrcV216(MCInst &Inst, unsigned Imm, uint64_t Addr, const void *Decoder)
void LLVMInitializeAMDGPUDisassembler()
unsigned getNumOperands() const
This file contains declaration for AMDGPU ISA disassembler.
MCOperand decodeSpecialReg64(unsigned Val) const
MCSubtargetInfo - Generic base class for all target subtargets.
unsigned getSgprClassId(const OpWidthTy Width) const
MCOperand decodeOperand_SReg_32_XM0_XEXEC(unsigned Val) const
MCOperand decodeOperand_VS_128(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.
unsigned getTtmpClassId(const OpWidthTy Width) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getVgprClassId(const OpWidthTy Width) const
LLVM Value Representation.
MCOperand decodeOperand_SReg_64(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...
MCOperand decodeLiteralConstant() const
void addOperand(const MCOperand &Op)
MCOperand decodeOperand_SReg_256(unsigned Val) const
DecodeStatus getInstruction(MCInst &MI, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &WS, raw_ostream &CS) const override
Returns the disassembly of a single instruction.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Instances of this class represent operands of the MCInst class.
static MCDisassembler * createAMDGPUDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
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.
static MCOperand createImm(int64_t Val)