38 #define DEBUG_TYPE "mccodeemitter" 41 using namespace Hexagon;
43 STATISTIC(MCNumEmitted,
"Number of MC instructions emitted");
47 #define _ fixup_Invalid 48 #define P(x) Hexagon::fixup_Hexagon##x 49 static const std::map<unsigned, std::vector<unsigned>>
ExtFixups = {
52 _,
_,
P(_DTPREL_16_X),
P(_DTPREL_11_X),
53 P(_DTPREL_11_X),
P(_9_X),
_,
P(_DTPREL_11_X),
54 P(_DTPREL_16_X),
_,
_,
_,
55 P(_DTPREL_16_X),
_,
_,
_,
62 _,
_,
P(_GOT_11_X), _ ,
63 _ ,
P(_9_X),
_,
P(_GOT_11_X),
64 P(_GOT_16_X),
_,
_,
_,
65 P(_GOT_16_X),
_,
_,
_,
72 _,
_,
P(_GOTREL_11_X),
P(_GOTREL_11_X),
73 P(_GOTREL_11_X),
P(_9_X),
_,
P(_GOTREL_11_X),
74 P(_GOTREL_16_X),
_,
_,
_,
75 P(_GOTREL_16_X),
_,
_,
_,
82 _,
_,
P(_TPREL_16_X),
P(_TPREL_11_X),
83 P(_TPREL_11_X),
P(_9_X),
_,
P(_TPREL_11_X),
84 P(_TPREL_16_X),
_,
_,
_,
85 P(_TPREL_16_X),
_,
_,
_,
92 _,
_,
P(_GD_GOT_16_X),
P(_GD_GOT_11_X),
93 P(_GD_GOT_11_X),
P(_9_X),
_,
P(_GD_GOT_11_X),
94 P(_GD_GOT_16_X),
_,
_,
_,
95 P(_GD_GOT_16_X),
_,
_,
_,
103 _,
P(_9_X),
_,
P(_GD_PLT_B22_PCREL_X),
106 _,
_,
P(_GD_PLT_B22_PCREL_X),
_,
112 _,
_,
P(_IE_16_X),
_,
114 P(_IE_16_X),
_,
_,
_,
115 P(_IE_16_X),
_,
_,
_,
122 _,
_,
P(_IE_GOT_11_X),
P(_IE_GOT_11_X),
123 P(_IE_GOT_11_X),
P(_9_X),
_,
P(_IE_GOT_11_X),
124 P(_IE_GOT_16_X),
_,
_,
_,
125 P(_IE_GOT_16_X),
_,
_,
_,
129 P(_IE_GOT_32_6_X) }},
132 _,
_,
P(_LD_GOT_11_X),
P(_LD_GOT_11_X),
133 P(_LD_GOT_11_X),
P(_9_X),
_,
P(_LD_GOT_11_X),
134 P(_LD_GOT_16_X),
_,
_,
_,
135 P(_LD_GOT_16_X),
_,
_,
_,
139 P(_LD_GOT_32_6_X) }},
143 _,
P(_9_X),
_,
P(_LD_PLT_B22_PCREL_X),
146 _,
_,
P(_LD_PLT_B22_PCREL_X),
_,
152 _,
_,
P(_6_PCREL_X),
_,
162 _,
_,
P(_6_X),
P(_8_X),
163 P(_8_X),
P(_9_X),
P(_10_X),
P(_11_X),
164 P(_12_X),
P(_B13_PCREL),
_,
P(_B15_PCREL_X),
166 _,
_,
P(_B22_PCREL_X),
_,
173 static const std::map<unsigned, std::vector<unsigned>>
StdFixups = {
179 P(_DTPREL_16),
_,
_,
_,
210 _,
_,
P(_PLT_B22_PCREL),
_,
217 _,
_,
_,
P(_TPREL_11_X),
219 P(_TPREL_16),
_,
_,
_,
229 P(_GD_GOT_16),
_,
_,
_,
240 _,
_,
P(_GD_PLT_B22_PCREL),
_,
249 P(_GPREL16_0),
_,
_,
_,
279 P(_IE_GOT_16),
_,
_,
_,
289 P(_LD_GOT_16),
_,
_,
_,
300 _,
_,
P(_LD_PLT_B22_PCREL),
_,
328 _,
P(_B13_PCREL),
_,
P(_B15_PCREL),
330 _,
_,
P(_B22_PCREL),
_,
340 uint32_t HexagonMCCodeEmitter::parseBits(
size_t Last,
MCInst const &MCB,
341 MCInst const &MCI)
const {
343 if (State.Index == 0) {
346 assert(State.Index != Last);
350 if (State.Index == 1) {
353 assert(State.Index != Last);
358 assert(State.Index == Last);
361 if (State.Index == Last)
375 State.Extended =
false;
383 verifyInstructionPredicates(HMI, Features);
385 EncodeSingleInstruction(HMI, OS, Fixups, STI, parseBits(Last, HMB, HMI));
393 unsigned Producer2) {
394 if (Consumer == Producer)
396 if (Consumer == Producer2)
399 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
400 if (Consumer >= Hexagon::V0 && Consumer <= Hexagon::V31)
401 return ((Consumer - Hexagon::V0) >> 1) == (Producer - Hexagon::W0);
415 "pseudo-instruction found");
419 Binary = getBinaryCodeForInstr(MI, Fixups, STI);
424 if (!Binary && Opc != DuplexIClass0 && Opc != A4_ext) {
432 if (Opc >= Hexagon::DuplexIClass0 && Opc <= Hexagon::DuplexIClassF) {
434 "Emitting duplex without duplex parse bits");
435 unsigned DupIClass = MI.
getOpcode() - Hexagon::DuplexIClass0;
439 Binary = ((DupIClass & 0xE) << (29 - 1)) | ((DupIClass & 0x1) << 13);
445 unsigned SubBits0 = getBinaryCodeForInstr(*Sub0, Fixups, STI);
447 State.SubInst1 =
true;
448 unsigned SubBits1 = getBinaryCodeForInstr(*Sub1, Fixups, STI);
449 State.SubInst1 =
false;
451 Binary |= SubBits0 | (SubBits1 << 16);
461 Stream <<
"Unrecognized relocation combination: width=" << Width
473 using namespace Hexagon;
478 for (
auto I = Instrs.begin(),
N = Instrs.end();
I !=
N; ++
I) {
479 if (
I->getInst() != &
MI)
481 assert(
I+1 !=
N &&
"Extender cannot be last in packet");
482 const MCInst &NextI = *(
I+1)->getInst();
491 static const std::map<unsigned,unsigned> Relocs = {
505 auto F = Relocs.find(VarKind);
506 if (
F != Relocs.end())
514 static const std::map<unsigned,unsigned> RelocsLo = {
526 static const std::map<unsigned,unsigned> RelocsHi = {
540 case Hexagon::A2_tfril: {
541 auto F = RelocsLo.find(VarKind);
542 if (
F != RelocsLo.end())
547 case Hexagon::A2_tfrih: {
548 auto F = RelocsHi.find(VarKind);
549 if (
F != RelocsHi.end())
584 unsigned HexagonMCCodeEmitter::getExprOpValue(
const MCInst &MI,
587 if (isa<HexagonMCExpr>(ME))
590 if (ME->evaluateAsAbsolute(Value)) {
597 if (State.Extended && InstExtendable && !IsSub0) {
598 unsigned OpIdx = ~0u;
608 Value = (Value & 0x3f) << Shift;
633 <<
"\nOpcode: " << Opc <<
"\nRelocation bits: " 634 << FixupWidth <<
"\nAddend: " << State.Addend
635 <<
"\nVariant: " <<
unsigned(VarKind)
636 <<
"\n----------------------------------------\n");
641 if (FixupWidth == 16 && !State.Extended) {
655 for (
const MCPhysReg *U =
D.getImplicitUses(); U && *U; ++U)
656 if (*U == Hexagon::GP)
661 FixupKind = GPRelFixups[Shift];
672 switch (FixupWidth) {
684 else if (FixupWidth == 7 && BranchOrCR)
689 FixupKind = getFixupNoBits(MCII, MI, MO, VarKind);
694 if (FixupKind == fixup_Invalid) {
697 auto FindVK = FixupTable.find(VarKind);
698 if (FindVK != FixupTable.end())
699 FixupKind = FindVK->second[FixupWidth];
702 if (FixupKind == fixup_Invalid)
706 if (State.Addend != 0 &&
isPCRel(FixupKind)) {
723 size_t OperandNumber = ~0U;
729 assert((OperandNumber != ~0U) &&
"Operand not found");
735 unsigned SOffset = 0;
736 unsigned VOffset = 0;
738 unsigned DefReg1, DefReg2;
741 const MCOperand *
I = Instrs.begin() + State.Index - 1;
744 assert(I != Instrs.begin() - 1 &&
"Couldn't find producer");
749 DefReg1 = DefReg2 = 0;
768 "Unpredicated consumer depending on predicated producer");
788 return MCT.getRegisterInfo()->getEncodingValue(Reg);
800 #define ENABLE_INSTR_PREDICATE_VERIFIER 801 #include "HexagonGenMCCodeEmitter.inc" static LLVM_ATTRIBUTE_NORETURN void raise_relocation_error(unsigned Width, unsigned Kind)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
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.
VariantKind getKind() const
static const std::map< unsigned, std::vector< unsigned > > StdFixups
void push_back(const T &Elt)
Describe properties that are true of each instruction in the target description file.
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)
bool isBundle(MCInst const &MCI)
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
#define HEXAGON_INSTR_SIZE
STATISTIC(NumFunctions, "Total number of functions")
bool isSubInstruction(MCInst const &MCI)
bool isOuterLoop(MCInst const &MCI)
static Lanai::Fixups FixupKind(const MCExpr *Expr)
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
static const unsigned fixup_Invalid
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
MCCodeEmitter * createHexagonMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &MCT)
bool isImmext(MCInst const &MCI)
const FeatureBitset & getFeatureBits() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
Represent a reference to a symbol from inside an expression.
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
bool s27_2_reloc(MCExpr const &Expr)
StringRef getName(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getReg() const
Returns the register number.
Context object for machine code objects.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
const MCInst * getInst() const
bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a second value.
const MCExpr * getExpr() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
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...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
void encodeInstruction(MCInst const &MI, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, MCSubtargetInfo const &STI) const override
Emit the bundle.
unsigned const MachineRegisterInfo * MRI
Container class for subtarget features.
bool isExtentSigned(MCInstrInfo const &MCII, MCInst const &MCI)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static Register UseReg(const MachineOperand &MO)
MCCodeEmitter - Generic instruction encoding interface.
MCOperand const & getNewValueOperand2(MCInstrInfo const &MCII, MCInst const &MCI)
Interface to description of machine instruction set.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getNumOperands() const
Definition for classes that emit Hexagon machine code from MCInsts.
Binary assembler expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
static const std::map< unsigned, std::vector< unsigned > > ExtFixups
unsigned SubregisterBit(unsigned Consumer, unsigned Producer, unsigned Producer2)
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
PowerPC TLS Dynamic Call Fixup
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.
#define LLVM_ATTRIBUTE_NORETURN
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI)
MCExpr const & getExpr(MCExpr const &Expr)
bool isCall() const
Return true if the instruction is a call.
Generic base class for all target subtargets.
References to labels and assigned expressions.
size_t bundleSize(MCInst const &MCI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInnerLoop(MCInst const &MCI)
A raw_ostream that writes to an std::string.
static bool RegisterMatches(unsigned Consumer, unsigned Producer, unsigned Producer2)
unsigned getOpcode() const
Return the opcode number for this descriptor.
This class implements an extremely fast bulk output stream that can only output to a stream...
void EncodeSingleInstruction(const MCInst &MI, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI, uint32_t Parse) const
EncodeSingleInstruction - Emit a single.
unsigned getDuplexRegisterNumbering(unsigned Reg)
bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a value.
unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI)
Return the Hexagon ISA class for the insn.
static bool isPCRel(unsigned Kind)
unsigned getMachineOpValue(MCInst const &MI, MCOperand const &MO, SmallVectorImpl< MCFixup > &Fixups, MCSubtargetInfo const &STI) const
Return binary encoding of operand.
unsigned getOpcode() const
unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI)
Instances of this class represent operands of the MCInst class.
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI)