9 #define DEBUG_TYPE "hexagon-disassembler" 36 using namespace Hexagon;
45 std::unique_ptr<MCInstrInfo const>
const MCII;
46 std::unique_ptr<MCInst *> CurrentBundle;
47 mutable MCInst const *CurrentExtender;
52 CurrentExtender(
nullptr) {}
63 static uint64_t fullValue(HexagonDisassembler
const &Disassembler,
MCInst &
MI,
66 if (!Disassembler.CurrentExtender ||
73 Disassembler.CurrentExtender->getOperand(0).getExpr()->evaluateAsAbsolute(
77 uint64_t Upper26 =
static_cast<uint64_t
>(
Bits);
78 uint64_t Operand = Upper26 | Lower6;
81 static HexagonDisassembler
const &disassembler(
void const *Decoder) {
82 return *
static_cast<HexagonDisassembler
const *
>(Decoder);
85 static void signedDecoder(
MCInst &MI,
unsigned tmp,
const void *Decoder) {
86 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
87 int64_t FullValue = fullValue(Disassembler, MI, SignExtend64<T>(tmp));
88 int64_t Extended = SignExtend64<32>(FullValue);
102 const void *Decoder);
105 const void *Decoder);
108 const void *Decoder);
111 const void *Decoder);
114 uint64_t
Address,
const void *Decoder);
117 const void *Decoder);
121 const void *Decoder);
124 const void *Decoder);
127 const void *Decoder);
130 const void *Decoder);
133 const void *Decoder);
136 const void *Decoder);
139 const void *Decoder);
142 const void *Decoder);
145 uint64_t
Address,
const void *Decoder);
147 uint64_t ,
const void *Decoder);
149 const void *Decoder);
151 #include "HexagonGenDisassemblerTables.inc" 169 bool Complete =
false;
172 *CurrentBundle = &
MI;
175 while (Result ==
Success && !Complete) {
179 Result = getSingleInstruction(*Inst, MI, Bytes,
Address, cs, Complete);
189 *getContext().getRegisterInfo(),
false);
190 if (!Checker.
check())
198 auto &MI =
const_cast<MCInst &
>(*
I.getInst());
200 case Hexagon::S2_allocframe:
202 MI.
setOpcode(Hexagon::S6_allocframe_to_raw);
207 case Hexagon::L2_deallocframe:
210 MI.
setOpcode(L6_deallocframe_map_to_raw);
215 case Hexagon::L4_return:
223 case Hexagon::L4_return_t:
231 case Hexagon::L4_return_f:
239 case Hexagon::L4_return_tnew_pt:
242 MI.
setOpcode(L4_return_map_to_raw_tnew_pt);
247 case Hexagon::L4_return_fnew_pt:
250 MI.
setOpcode(L4_return_map_to_raw_fnew_pt);
255 case Hexagon::L4_return_tnew_pnt:
258 MI.
setOpcode(L4_return_map_to_raw_tnew_pnt);
263 case Hexagon::L4_return_fnew_pnt:
266 MI.
setOpcode(L4_return_map_to_raw_fnew_pnt);
277 case Hexagon::SA1_setin1:
281 case Hexagon::SA1_dec:
294 bool &Complete)
const {
304 else if (BundleSize == 1)
314 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
316 unsigned duplexIClass;
317 uint8_t
const *DecodeLow, *DecodeHigh;
318 duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1);
319 switch (duplexIClass) {
323 DecodeLow = DecoderTableSUBINSN_L132;
324 DecodeHigh = DecoderTableSUBINSN_L132;
327 DecodeLow = DecoderTableSUBINSN_L232;
328 DecodeHigh = DecoderTableSUBINSN_L132;
331 DecodeLow = DecoderTableSUBINSN_L232;
332 DecodeHigh = DecoderTableSUBINSN_L232;
335 DecodeLow = DecoderTableSUBINSN_A32;
336 DecodeHigh = DecoderTableSUBINSN_A32;
339 DecodeLow = DecoderTableSUBINSN_L132;
340 DecodeHigh = DecoderTableSUBINSN_A32;
343 DecodeLow = DecoderTableSUBINSN_L232;
344 DecodeHigh = DecoderTableSUBINSN_A32;
347 DecodeLow = DecoderTableSUBINSN_S132;
348 DecodeHigh = DecoderTableSUBINSN_A32;
351 DecodeLow = DecoderTableSUBINSN_S232;
352 DecodeHigh = DecoderTableSUBINSN_A32;
355 DecodeLow = DecoderTableSUBINSN_S132;
356 DecodeHigh = DecoderTableSUBINSN_L132;
359 DecodeLow = DecoderTableSUBINSN_S132;
360 DecodeHigh = DecoderTableSUBINSN_L232;
363 DecodeLow = DecoderTableSUBINSN_S132;
364 DecodeHigh = DecoderTableSUBINSN_S132;
367 DecodeLow = DecoderTableSUBINSN_S232;
368 DecodeHigh = DecoderTableSUBINSN_S132;
371 DecodeLow = DecoderTableSUBINSN_S232;
372 DecodeHigh = DecoderTableSUBINSN_L132;
375 DecodeLow = DecoderTableSUBINSN_S232;
376 DecodeHigh = DecoderTableSUBINSN_L232;
379 DecodeLow = DecoderTableSUBINSN_S232;
380 DecodeHigh = DecoderTableSUBINSN_S232;
383 MI.
setOpcode(Hexagon::DuplexIClass0 + duplexIClass);
386 auto TmpExtender = CurrentExtender;
389 Result = decodeInstruction(DecodeLow, *MILow, Instruction & 0x1fff,
Address,
391 CurrentExtender = TmpExtender;
395 Result = decodeInstruction(
396 DecodeHigh, *MIHigh, (Instruction >> 16) & 0x1fff,
Address,
this, STI);
406 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
410 if (CurrentExtender !=
nullptr)
411 Result = decodeInstruction(DecoderTableMustExtend32, MI, Instruction,
415 Result = decodeInstruction(DecoderTable32, MI, Instruction,
Address,
this,
419 STI.getFeatureBits()[Hexagon::ExtensionHVX])
420 Result = decodeInstruction(DecoderTableEXT_mmvec32, MI, Instruction,
426 case Hexagon::J4_cmpeqn1_f_jumpnv_nt:
427 case Hexagon::J4_cmpeqn1_f_jumpnv_t:
428 case Hexagon::J4_cmpeqn1_fp0_jump_nt:
429 case Hexagon::J4_cmpeqn1_fp0_jump_t:
430 case Hexagon::J4_cmpeqn1_fp1_jump_nt:
431 case Hexagon::J4_cmpeqn1_fp1_jump_t:
432 case Hexagon::J4_cmpeqn1_t_jumpnv_nt:
433 case Hexagon::J4_cmpeqn1_t_jumpnv_t:
434 case Hexagon::J4_cmpeqn1_tp0_jump_nt:
435 case Hexagon::J4_cmpeqn1_tp0_jump_t:
436 case Hexagon::J4_cmpeqn1_tp1_jump_nt:
437 case Hexagon::J4_cmpeqn1_tp1_jump_t:
438 case Hexagon::J4_cmpgtn1_f_jumpnv_nt:
439 case Hexagon::J4_cmpgtn1_f_jumpnv_t:
440 case Hexagon::J4_cmpgtn1_fp0_jump_nt:
441 case Hexagon::J4_cmpgtn1_fp0_jump_t:
442 case Hexagon::J4_cmpgtn1_fp1_jump_nt:
443 case Hexagon::J4_cmpgtn1_fp1_jump_t:
444 case Hexagon::J4_cmpgtn1_t_jumpnv_nt:
445 case Hexagon::J4_cmpgtn1_t_jumpnv_t:
446 case Hexagon::J4_cmpgtn1_tp0_jump_nt:
447 case Hexagon::J4_cmpgtn1_tp0_jump_t:
448 case Hexagon::J4_cmpgtn1_tp1_jump_nt:
449 case Hexagon::J4_cmpgtn1_tp1_jump_t:
460 assert(MCO.
isReg() &&
"New value consumers must be registers");
462 getContext().getRegisterInfo()->getEncodingValue(MCO.
getReg());
463 if ((Register & 0x6) == 0)
466 unsigned Lookback = (Register & 0x6) >> 1;
469 bool PrevVector =
false;
471 auto i = Instructions.end() - 1;
472 for (
auto n = Instructions.begin() - 1;; --i, ++
Offset) {
477 if (Vector && !CurrentVector)
482 PrevVector = CurrentVector;
483 if (Offset == Lookback)
486 auto const &Inst = *i->getInst();
487 bool SubregBit = (Register & 0x1) != 0;
490 unsigned Producer = SubregBit ?
493 assert(Producer != Hexagon::NoRegister);
498 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
499 Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0;
504 assert(Producer != Hexagon::NoRegister);
510 if (CurrentExtender !=
nullptr) {
523 if (RegNo < Table.
size()) {
533 const void *Decoder) {
539 const void *Decoder) {
542 Hexagon::R5,
Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9,
543 Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14,
544 Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
545 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24,
546 Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29,
547 Hexagon::R30, Hexagon::R31};
555 const void *Decoder) {
556 static const MCPhysReg GeneralSubRegDecoderTable[] = {
557 Hexagon::R0, Hexagon::R1,
Hexagon::R2, Hexagon::R3,
559 Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
560 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23,
568 const void *Decoder) {
569 static const MCPhysReg HvxVRDecoderTable[] = {
571 Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9,
572 Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14,
573 Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19,
574 Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24,
575 Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29,
576 Hexagon::V30, Hexagon::V31};
583 const void *Decoder) {
584 static const MCPhysReg DoubleRegDecoderTable[] = {
585 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
586 Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7,
587 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11,
588 Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15};
594 MCInst &Inst,
unsigned RegNo, uint64_t ,
const void *Decoder) {
595 static const MCPhysReg GeneralDoubleLow8RegDecoderTable[] = {
596 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
597 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11};
604 const void *Decoder) {
605 static const MCPhysReg HvxWRDecoderTable[] = {
606 Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3,
607 Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7,
608 Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11,
609 Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15};
618 const void *Decoder) {
619 static const MCPhysReg HvxVQRDecoderTable[] = {
620 Hexagon::VQ0, Hexagon::VQ1, Hexagon::VQ2, Hexagon::VQ3,
621 Hexagon::VQ4, Hexagon::VQ5, Hexagon::VQ6, Hexagon::VQ7};
628 const void *Decoder) {
629 static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1,
630 Hexagon::P2, Hexagon::P3};
637 const void *Decoder) {
638 static const MCPhysReg HvxQRDecoderTable[] = {Hexagon::Q0, Hexagon::Q1,
639 Hexagon::Q2, Hexagon::Q3};
646 const void *Decoder) {
647 using namespace Hexagon;
649 static const MCPhysReg CtrlRegDecoderTable[] = {
653 CS0, CS1, UPCYCLELO, UPCYCLEHI,
654 FRAMELIMIT, FRAMEKEY, PKTCOUNTLO, PKTCOUNTHI,
657 0, 0, UTIMERLO, UTIMERHI
663 static_assert(NoRegister == 0,
"Expecting NoRegister to be 0");
664 if (CtrlRegDecoderTable[RegNo] == NoRegister)
667 unsigned Register = CtrlRegDecoderTable[RegNo];
674 const void *Decoder) {
675 using namespace Hexagon;
677 static const MCPhysReg CtrlReg64DecoderTable[] = {
682 C17_16, 0, PKTCOUNT, 0,
691 static_assert(NoRegister == 0,
"Expecting NoRegister to be 0");
692 if (CtrlReg64DecoderTable[RegNo] == NoRegister)
695 unsigned Register = CtrlReg64DecoderTable[RegNo];
702 const void *Decoder) {
706 Register = Hexagon::M0;
709 Register = Hexagon::M1;
720 const void *Decoder) {
721 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
722 int64_t FullValue = fullValue(Disassembler, MI, tmp);
723 assert(FullValue >= 0 &&
"Negative in unsigned decoder");
729 uint64_t ,
const void *Decoder) {
730 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
733 signedDecoder<32>(
MI, tmp, Decoder);
739 const void *Decoder) {
740 HexagonDisassembler
const &Disassembler = disassembler(Decoder);
745 uint64_t FullValue = fullValue(Disassembler, MI,
SignExtend64(tmp, Bits));
746 uint32_t Extended = FullValue + Address;
747 if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address,
true, 0, 4))
754 const void *Decoder) {
755 using namespace Hexagon;
757 static const MCPhysReg GuestRegDecoderTable[] = {
762 GPMUCNT4, GPMUCNT5, GPMUCNT6, GPMUCNT7,
764 GPCYCLELO, GPCYCLEHI, GPMUCNT0, GPMUCNT1,
765 GPMUCNT2, GPMUCNT3, G30, G31
770 if (GuestRegDecoderTable[RegNo] == Hexagon::NoRegister)
773 unsigned Register = GuestRegDecoderTable[RegNo];
780 const void *Decoder) {
781 using namespace Hexagon;
783 static const MCPhysReg GuestReg64DecoderTable[] = {
787 G13_12, 0, G15_14, 0,
788 G17_16, 0, G19_18, 0,
789 G21_20, 0, G23_22, 0,
790 G25_24, 0, G27_26, 0,
796 if (GuestReg64DecoderTable[RegNo] == Hexagon::NoRegister)
799 unsigned Register = GuestReg64DecoderTable[RegNo];
static MCDisassembler * createHexagonDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI)
This class represents lattice values for constants.
static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, const void *Decoder)
DecodeStatus
Ternary decode status.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonDisassembler()
static MCOperand createExpr(const MCExpr *Val)
Superclass for all disassemblers.
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)
#define HEXAGON_INSTR_SIZE
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.
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 const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
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 DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
size_t size() const
size - Get the array size.
#define HEXAGON_MAX_PACKET_SIZE
MCOperand const & getNewValueOperand2(MCInstrInfo const &MCII, MCInst const &MCI)
Interface to description of machine instruction set.
#define LLVM_ATTRIBUTE_UNUSED
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)
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
static DecodeStatus DecodeGeneralDoubleLow8RegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeHvxVQRRegisterClass(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)
#define LLVM_EXTERNAL_VISIBILITY
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 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())
LLVM Value Representation.
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.
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)
Target & getTheHexagonTarget()
Wrapper class representing virtual and physical registers.
void addConstant(MCInst &MI, uint64_t Value, MCContext &Context)
unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI)