10 #define DEBUG_TYPE "hexagon-disassembler" 37 using namespace Hexagon;
46 std::unique_ptr<MCInstrInfo const>
const MCII;
47 std::unique_ptr<MCInst *> CurrentBundle;
48 mutable MCInst const *CurrentExtender;
53 CurrentExtender(
nullptr) {}
58 bool &Complete)
const;
66 static uint64_t fullValue(HexagonDisassembler
const &Disassembler,
MCInst &
MI,
69 if (!Disassembler.CurrentExtender ||
76 Disassembler.CurrentExtender->getOperand(0).getExpr()->evaluateAsAbsolute(
80 uint64_t Upper26 =
static_cast<uint64_t
>(
Bits);
81 uint64_t Operand = Upper26 | Lower6;
84 static HexagonDisassembler
const &disassembler(
void const *Decoder) {
85 return *
static_cast<HexagonDisassembler
const *
>(Decoder);
88 static void signedDecoder(
MCInst &MI,
unsigned tmp,
const void *Decoder) {
89 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
90 int64_t FullValue = fullValue(Disassembler, MI, SignExtend64<T>(tmp));
91 int64_t Extended = SignExtend64<32>(FullValue);
101 const void *Decoder);
105 const void *Decoder);
108 const void *Decoder);
111 const void *Decoder);
114 const void *Decoder);
117 uint64_t
Address,
const void *Decoder);
120 const void *Decoder);
123 const void *Decoder);
126 const void *Decoder);
129 const void *Decoder);
132 const void *Decoder);
135 const void *Decoder);
138 const void *Decoder);
141 const void *Decoder);
144 uint64_t
Address,
const void *Decoder);
146 uint64_t ,
const void *Decoder);
148 const void *Decoder);
151 const void *Decoder) {
152 signedDecoder<4>(
MI, tmp, Decoder);
156 const void *Decoder) {
157 signedDecoder<14>(
MI, tmp, Decoder);
161 const void *Decoder) {
162 signedDecoder<8>(
MI, tmp, Decoder);
166 const void *Decoder) {
167 signedDecoder<7>(
MI, tmp, Decoder);
171 const void *Decoder) {
172 signedDecoder<12>(
MI, tmp, Decoder);
176 const void *Decoder) {
177 signedDecoder<3>(
MI, tmp, Decoder);
181 const void *Decoder) {
182 signedDecoder<13>(
MI, tmp, Decoder);
186 const void *Decoder) {
187 signedDecoder<6>(
MI, tmp, Decoder);
191 const void *Decoder) {
192 signedDecoder<9>(
MI, tmp, Decoder);
196 const void *Decoder) {
197 signedDecoder<5>(
MI, tmp, Decoder);
201 const void *Decoder) {
202 signedDecoder<6>(
MI, tmp, Decoder);
205 #include "HexagonGenDisassemblerTables.inc" 224 bool Complete =
false;
227 *CurrentBundle = &
MI;
230 while (Result ==
Success && !Complete) {
234 Result = getSingleInstruction(*Inst, MI, Bytes,
Address, os, cs, Complete);
244 *getContext().getRegisterInfo(),
false);
245 if (!Checker.
check())
253 auto &MI =
const_cast<MCInst &
>(*
I.getInst());
255 case Hexagon::S2_allocframe:
257 MI.
setOpcode(Hexagon::S6_allocframe_to_raw);
262 case Hexagon::L2_deallocframe:
265 MI.
setOpcode(L6_deallocframe_map_to_raw);
270 case Hexagon::L4_return:
278 case Hexagon::L4_return_t:
286 case Hexagon::L4_return_f:
294 case Hexagon::L4_return_tnew_pt:
297 MI.
setOpcode(L4_return_map_to_raw_tnew_pt);
302 case Hexagon::L4_return_fnew_pt:
305 MI.
setOpcode(L4_return_map_to_raw_fnew_pt);
310 case Hexagon::L4_return_tnew_pnt:
313 MI.
setOpcode(L4_return_map_to_raw_tnew_pnt);
318 case Hexagon::L4_return_fnew_pnt:
321 MI.
setOpcode(L4_return_map_to_raw_fnew_pnt);
332 case Hexagon::SA1_setin1:
336 case Hexagon::SA1_dec:
357 else if (BundleSize == 1)
367 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
369 unsigned duplexIClass;
370 uint8_t
const *DecodeLow, *DecodeHigh;
371 duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1);
372 switch (duplexIClass) {
376 DecodeLow = DecoderTableSUBINSN_L132;
377 DecodeHigh = DecoderTableSUBINSN_L132;
380 DecodeLow = DecoderTableSUBINSN_L232;
381 DecodeHigh = DecoderTableSUBINSN_L132;
384 DecodeLow = DecoderTableSUBINSN_L232;
385 DecodeHigh = DecoderTableSUBINSN_L232;
388 DecodeLow = DecoderTableSUBINSN_A32;
389 DecodeHigh = DecoderTableSUBINSN_A32;
392 DecodeLow = DecoderTableSUBINSN_L132;
393 DecodeHigh = DecoderTableSUBINSN_A32;
396 DecodeLow = DecoderTableSUBINSN_L232;
397 DecodeHigh = DecoderTableSUBINSN_A32;
400 DecodeLow = DecoderTableSUBINSN_S132;
401 DecodeHigh = DecoderTableSUBINSN_A32;
404 DecodeLow = DecoderTableSUBINSN_S232;
405 DecodeHigh = DecoderTableSUBINSN_A32;
408 DecodeLow = DecoderTableSUBINSN_S132;
409 DecodeHigh = DecoderTableSUBINSN_L132;
412 DecodeLow = DecoderTableSUBINSN_S132;
413 DecodeHigh = DecoderTableSUBINSN_L232;
416 DecodeLow = DecoderTableSUBINSN_S132;
417 DecodeHigh = DecoderTableSUBINSN_S132;
420 DecodeLow = DecoderTableSUBINSN_S232;
421 DecodeHigh = DecoderTableSUBINSN_S132;
424 DecodeLow = DecoderTableSUBINSN_S232;
425 DecodeHigh = DecoderTableSUBINSN_L132;
428 DecodeLow = DecoderTableSUBINSN_S232;
429 DecodeHigh = DecoderTableSUBINSN_L232;
432 DecodeLow = DecoderTableSUBINSN_S232;
433 DecodeHigh = DecoderTableSUBINSN_S232;
436 MI.
setOpcode(Hexagon::DuplexIClass0 + duplexIClass);
439 auto TmpExtender = CurrentExtender;
444 CurrentExtender = TmpExtender;
449 DecodeHigh, *MIHigh, (Instruction >> 16) & 0x1fff,
Address,
this, STI);
459 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
463 if (CurrentExtender !=
nullptr)
472 STI.getFeatureBits()[Hexagon::ExtensionHVX])
479 case Hexagon::J4_cmpeqn1_f_jumpnv_nt:
480 case Hexagon::J4_cmpeqn1_f_jumpnv_t:
481 case Hexagon::J4_cmpeqn1_fp0_jump_nt:
482 case Hexagon::J4_cmpeqn1_fp0_jump_t:
483 case Hexagon::J4_cmpeqn1_fp1_jump_nt:
484 case Hexagon::J4_cmpeqn1_fp1_jump_t:
485 case Hexagon::J4_cmpeqn1_t_jumpnv_nt:
486 case Hexagon::J4_cmpeqn1_t_jumpnv_t:
487 case Hexagon::J4_cmpeqn1_tp0_jump_nt:
488 case Hexagon::J4_cmpeqn1_tp0_jump_t:
489 case Hexagon::J4_cmpeqn1_tp1_jump_nt:
490 case Hexagon::J4_cmpeqn1_tp1_jump_t:
491 case Hexagon::J4_cmpgtn1_f_jumpnv_nt:
492 case Hexagon::J4_cmpgtn1_f_jumpnv_t:
493 case Hexagon::J4_cmpgtn1_fp0_jump_nt:
494 case Hexagon::J4_cmpgtn1_fp0_jump_t:
495 case Hexagon::J4_cmpgtn1_fp1_jump_nt:
496 case Hexagon::J4_cmpgtn1_fp1_jump_t:
497 case Hexagon::J4_cmpgtn1_t_jumpnv_nt:
498 case Hexagon::J4_cmpgtn1_t_jumpnv_t:
499 case Hexagon::J4_cmpgtn1_tp0_jump_nt:
500 case Hexagon::J4_cmpgtn1_tp0_jump_t:
501 case Hexagon::J4_cmpgtn1_tp1_jump_nt:
502 case Hexagon::J4_cmpgtn1_tp1_jump_t:
513 assert(MCO.
isReg() &&
"New value consumers must be registers");
515 getContext().getRegisterInfo()->getEncodingValue(MCO.
getReg());
516 if ((Register & 0x6) == 0)
519 unsigned Lookback = (Register & 0x6) >> 1;
522 bool PrevVector =
false;
524 auto i = Instructions.end() - 1;
525 for (
auto n = Instructions.begin() - 1;; --i, ++
Offset) {
530 if (Vector && !CurrentVector)
535 PrevVector = CurrentVector;
536 if (Offset == Lookback)
539 auto const &Inst = *i->getInst();
540 bool SubregBit = (Register & 0x1) != 0;
543 unsigned Producer = SubregBit ?
546 assert(Producer != Hexagon::NoRegister);
551 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
552 Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0;
557 assert(Producer != Hexagon::NoRegister);
563 if (CurrentExtender !=
nullptr) {
576 if (RegNo < Table.
size()) {
586 const void *Decoder) {
592 const void *Decoder) {
595 Hexagon::R5,
Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9,
596 Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14,
597 Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
598 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24,
599 Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29,
600 Hexagon::R30, Hexagon::R31};
608 const void *Decoder) {
609 static const MCPhysReg GeneralSubRegDecoderTable[] = {
610 Hexagon::R0, Hexagon::R1,
Hexagon::R2, Hexagon::R3,
612 Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
613 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23,
621 const void *Decoder) {
622 static const MCPhysReg HvxVRDecoderTable[] = {
624 Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9,
625 Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14,
626 Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19,
627 Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24,
628 Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29,
629 Hexagon::V30, Hexagon::V31};
636 const void *Decoder) {
637 static const MCPhysReg DoubleRegDecoderTable[] = {
638 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
639 Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7,
640 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11,
641 Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15};
647 MCInst &Inst,
unsigned RegNo, uint64_t ,
const void *Decoder) {
648 static const MCPhysReg GeneralDoubleLow8RegDecoderTable[] = {
649 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
650 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11};
657 const void *Decoder) {
658 static const MCPhysReg HvxWRDecoderTable[] = {
659 Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3,
660 Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7,
661 Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11,
662 Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15};
669 const void *Decoder) {
670 static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1,
671 Hexagon::P2, Hexagon::P3};
678 const void *Decoder) {
679 static const MCPhysReg HvxQRDecoderTable[] = {Hexagon::Q0, Hexagon::Q1,
680 Hexagon::Q2, Hexagon::Q3};
687 const void *Decoder) {
688 using namespace Hexagon;
690 static const MCPhysReg CtrlRegDecoderTable[] = {
694 CS0, CS1, UPCYCLELO, UPCYCLEHI,
695 FRAMELIMIT, FRAMEKEY, PKTCOUNTLO, PKTCOUNTHI,
698 0, 0, UTIMERLO, UTIMERHI
704 static_assert(NoRegister == 0,
"Expecting NoRegister to be 0");
705 if (CtrlRegDecoderTable[RegNo] == NoRegister)
708 unsigned Register = CtrlRegDecoderTable[RegNo];
715 const void *Decoder) {
716 using namespace Hexagon;
718 static const MCPhysReg CtrlReg64DecoderTable[] = {
723 C17_16, 0, PKTCOUNT, 0,
732 static_assert(NoRegister == 0,
"Expecting NoRegister to be 0");
733 if (CtrlReg64DecoderTable[RegNo] == NoRegister)
736 unsigned Register = CtrlReg64DecoderTable[RegNo];
743 const void *Decoder) {
747 Register = Hexagon::M0;
750 Register = Hexagon::M1;
761 const void *Decoder) {
762 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
763 int64_t FullValue = fullValue(Disassembler, MI, tmp);
764 assert(FullValue >= 0 &&
"Negative in unsigned decoder");
770 uint64_t ,
const void *Decoder) {
771 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
774 signedDecoder<32>(
MI, tmp, Decoder);
780 const void *Decoder) {
781 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
786 uint64_t FullValue = fullValue(Disassembler, MI,
SignExtend64(tmp, Bits));
787 uint32_t Extended = FullValue + Address;
788 if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address,
true, 0, 4))
795 const void *Decoder) {
796 using namespace Hexagon;
798 static const MCPhysReg GuestRegDecoderTable[] = {
803 GPMUCNT4, GPMUCNT5, GPMUCNT6, GPMUCNT7,
805 GPCYCLELO, GPCYCLEHI, GPMUCNT0, GPMUCNT1,
806 GPMUCNT2, GPMUCNT3, G30, G31
811 if (GuestRegDecoderTable[RegNo] == Hexagon::NoRegister)
814 unsigned Register = GuestRegDecoderTable[RegNo];
821 const void *Decoder) {
822 using namespace Hexagon;
824 static const MCPhysReg GuestReg64DecoderTable[] = {
828 G13_12, 0, G15_14, 0,
829 G17_16, 0, G19_18, 0,
830 G21_20, 0, G23_22, 0,
831 G25_24, 0, G27_26, 0,
837 if (GuestReg64DecoderTable[RegNo] == Hexagon::NoRegister)
840 unsigned Register = GuestReg64DecoderTable[RegNo];
static MCDisassembler * createHexagonDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
static DecodeStatus s29_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI)
Compute iterated dominance frontiers using a linear time algorithm.
static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
DecodeStatus
Ternary decode status.
static MCOperand createExpr(const MCExpr *Val)
Superclass for all disassemblers.
static DecodeStatus s30_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeGeneralSubRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)
static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.
static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
void setInnerLoop(MCInst &MCI)
bool isImmext(MCInst const &MCI)
static DecodeStatus DecodeHvxVRRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static MCOperand createReg(unsigned Reg)
static DecodeStatus DecodeHvxWRRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
MCInst const * extenderForIndex(MCInst const &MCB, size_t Index)
unsigned getReg() const
Returns the register number.
Context object for machine code objects.
static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
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...
const MCInst * getInst() const
bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a second value.
iterator insert(iterator I, const MCOperand &Op)
Instances of this class represent a single low-level machine instruction.
static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
void remapInstruction(Instruction *I, ValueToValueMapTy &VMap)
Convert the instruction operands from referencing the current values into those specified by VMap...
static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
size_t size() const
size - Get the array size.
MCOperand const & getNewValueOperand2(MCInstrInfo const &MCII, MCInst const &MCI)
Interface to description of machine instruction set.
void setOuterLoop(MCInst &MCI)
static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo, ArrayRef< MCPhysReg > Table)
static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
void LLVMInitializeHexagonDisassembler()
static DecodeStatus s6_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
static DecodeStatus DecodeGeneralDoubleLow8RegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static const unsigned IntRegDecoderTable[]
void setOpcode(unsigned Op)
bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI)
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
const MCOperand & getOperand(unsigned i) const
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
static DecodeStatus DecodeGuestRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
Promote Memory to Register
static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
static DecodeStatus DecodeHvxQRRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static void adjustDuplex(MCInst &MI, MCContext &Context)
Target - Wrapper for Target specific information.
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...
bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI)
static MCOperand createInst(const MCInst *Val)
static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus s31_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
uint32_t read32le(const void *P)
Generic base class for all target subtargets.
size_t bundleSize(MCInst const &MCI)
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
bool check(bool FullCheck=true)
void setReg(unsigned Reg)
Set the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define HEXAGON_INSTR_SIZE
LLVM Value Representation.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Check for a valid bundle.
This class implements an extremely fast bulk output stream that can only output to a stream...
void addOperand(const MCOperand &Op)
bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a value.
static DecodeStatus s3_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
unsigned getOpcode() const
static DecodeStatus DecodeGuestRegs64RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI)
Instances of this class represent operands of the MCInst class.
static MCOperand createImm(int64_t Val)
#define HEXAGON_MAX_PACKET_SIZE
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Target & getTheHexagonTarget()
void addConstant(MCInst &MI, uint64_t Value, MCContext &Context)
unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI)