39#define DEBUG_TYPE "mccodeemitter"
41#define GET_INSTRMAP_INFO
42#include "MipsGenInstrInfo.inc"
43#undef GET_INSTRMAP_INFO
117void MipsMCCodeEmitter::LowerCompactBranch(
MCInst& Inst)
const {
123 unsigned Reg0 = Ctx.getRegisterInfo()->getEncodingValue(RegOp0);
124 unsigned Reg1 = Ctx.getRegisterInfo()->getEncodingValue(RegOp1);
128 assert(Reg0 != Reg1 &&
"Instruction has bad operands ($rs == $rt)!");
134 }
else if (Inst.
getOpcode() == Mips::BNVC_MMR6 ||
146 return STI.
hasFeature(Mips::FeatureMicroMips);
167 if (
MI.getOpcode() == Mips::PseudoGOTLoadGlobal ||
168 MI.getOpcode() == Mips::PseudoGOTLoadLocal) {
169 expandGOTLoad(
MI, CB, Fixups, STI);
178 switch (
MI.getOpcode()) {
192 case Mips::BOVC_MMR6:
194 case Mips::BNVC_MMR6:
195 LowerCompactBranch(TmpInst);
198 size_t N = Fixups.size();
204 const unsigned Opcode = TmpInst.
getOpcode();
205 if ((Opcode != Mips::NOP) && (Opcode != Mips::SLL) &&
206 (Opcode != Mips::SLL_MM) && (Opcode != Mips::SLL_MMR6) && !
Binary)
210 if (isMicroMips(STI)) {
211 if (isMips32r6(STI)) {
212 NewOpcode = Mips::MipsR62MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
214 NewOpcode = Mips::Std2MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
217 NewOpcode = Mips::Std2MicroMips(Opcode, Mips::Arch_micromips);
221 NewOpcode = Mips::Dsp2MicroMips(Opcode, Mips::Arch_mmdsp);
223 if (NewOpcode != -1) {
224 if (Fixups.size() >
N)
231 if (((
MI.getOpcode() == Mips::MOVEP_MM) ||
232 (
MI.getOpcode() == Mips::MOVEP_MMR6))) {
249 }
else if (IsLittleEndian &&
Size == 4 &&
250 (isMicroMips(STI) || isNanoMips(STI))) {
253 }
else if (IsLittleEndian &&
Size == 6 && isNanoMips(STI)) {
273void MipsMCCodeEmitter::expandGOTLoad(
const MCInst &
MI,
279 const MCExpr *SymExpr =
MI.getOperand(2).getExpr();
280 unsigned Flags =
MI.getOperand(3).getImm();
281 bool IsLocal =
MI.getOpcode() == Mips::PseudoGOTLoadLocal;
283 unsigned LoadOpc = IsPtr64 ? Mips::LD : Mips::LW;
284 unsigned AddiuOpc = IsPtr64 ? Mips::DADDiu : Mips::ADDiu;
289 "expected a symbol plus an optional constant");
298 auto AddOffset = [&]() {
305 AddInst(LoadOpc, DstReg, GPReg,
307 }
else if (!IsLocal) {
308 AddInst(LoadOpc, DstReg, GPReg,
312 AddInst(LoadOpc, DstReg, GPReg,
316 AddInst(LoadOpc, DstReg, GPReg,
318 AddInst(AddiuOpc, DstReg, DstReg,
325 for (
const MCInst &Inst : Insts) {
347 "getBranchTargetOpValue expects only expressions or immediates");
368 "getBranchTargetOpValue expects only expressions or immediates");
390 "getBranchTargetOpValueMMR6 expects only expressions or immediates");
412 "getBranchTargetOpValueLsl2MMR6 expects only expressions or immediates");
433 "getBranchTargetOpValueMM expects only expressions or immediates");
453 "getBranchTargetOpValuePC10 expects only expressions or immediates");
473 "getBranchTargetOpValueMM expects only expressions or immediates");
493 "getBranchTarget21OpValue expects only expressions or immediates");
514 "getBranchTarget21OpValueMM expects only expressions or immediates");
535 "getBranchTarget26OpValue expects only expressions or immediates");
556 "getBranchTarget26OpValueMM expects only expressions or immediates");
576 "getJumpOffset16OpValue expects only expressions or an immediate");
597 "getJumpTargetOpValue expects only expressions or an immediate");
613 "getJumpTargetOpValueMM expects only expressions or an immediate");
633 "getUImm5Lsl2Encoding expects only expressions or an immediate");
685 switch (MipsExpr->getSpecifier()) {
798 Ctx.reportError(Expr->
getLoc(),
"expected an immediate");
810 unsigned RegNo = Ctx.getRegisterInfo()->getEncodingValue(Reg);
812 }
else if (MO.
isImm()) {
813 return static_cast<unsigned>(MO.
getImm());
828 assert(MO.
isExpr() &&
"getImmOpValue expects only expressions or immediates");
831 if (Expr->evaluateAsAbsolute(Res))
841template <
unsigned Shift>
849template <
unsigned FromEnd,
unsigned Shift>
864 assert(
MI.getOperand(OpNo-1).isImm());
865 assert(
MI.getOperand(OpNo).isImm());
869 return Position +
Size - 1;
872template <
unsigned Bits,
int Offset>
877 assert(
MI.getOperand(OpNo).isImm());
896 "getSimm19Lsl2Encoding expects only expressions or an immediate");
918 "getSimm18Lsl2Encoding expects only expressions or an immediate");
931 assert(
MI.getOperand(OpNo).isImm());
940 assert(
MI.getOperand(OpNo).isImm());
944 case 128:
return 0x0;
957 case 255:
return 0xd;
958 case 32768:
return 0xe;
959 case 65535:
return 0xf;
973 for (
unsigned I = OpNo, E =
MI.getNumOperands() - 2;
I < E; ++
I) {
975 unsigned RegNo = Ctx.getRegisterInfo()->getEncodingValue(Reg);
988 return (
MI.getNumOperands() - 4);
997 if (
MI.getOperand(0).getReg() == Mips::R5 &&
998 MI.getOperand(1).getReg() == Mips::R6)
1000 else if (
MI.getOperand(0).getReg() == Mips::R5 &&
1001 MI.getOperand(1).getReg() == Mips::R7)
1003 else if (
MI.getOperand(0).getReg() == Mips::R6 &&
1004 MI.getOperand(1).getReg() == Mips::R7)
1006 else if (
MI.getOperand(0).getReg() == Mips::R4 &&
1007 MI.getOperand(1).getReg() == Mips::R21)
1009 else if (
MI.getOperand(0).getReg() == Mips::R4 &&
1010 MI.getOperand(1).getReg() == Mips::R22)
1012 else if (
MI.getOperand(0).getReg() == Mips::R4 &&
1013 MI.getOperand(1).getReg() == Mips::R5)
1015 else if (
MI.getOperand(0).getReg() == Mips::R4 &&
1016 MI.getOperand(1).getReg() == Mips::R6)
1018 else if (
MI.getOperand(0).getReg() == Mips::R4 &&
1019 MI.getOperand(1).getReg() == Mips::R7)
1029 assert(((OpNo == 2) || (OpNo == 3)) &&
1030 "Unexpected OpNo for movep operand encoding!");
1033 assert(
Op.isReg() &&
"Operand of movep is not a register!");
1034 switch (
Op.getReg().id()) {
1061 assert(MO.
isImm() &&
"getSimm23Lsl2Encoding expects only an immediate");
1063 unsigned Res =
static_cast<unsigned>(MO.
getImm());
1068#include "MipsGenMCCodeEmitter.inc"
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static void LowerLargeShift(MCInst &Inst)
This file defines the SmallVector class.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
MCCodeEmitter - Generic instruction encoding interface.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
Base class for the full range of assembler expressions which are needed for parsing.
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
@ Specifier
Expression with a relocation specifier.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
Instances of this class represent a single low-level machine instruction.
unsigned getNumOperands() const
unsigned getOpcode() const
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
Describe properties that are true of each instruction in the target description file.
Interface to description of machine instruction set.
Instances of this class represent operands of the MCInst class.
void setReg(MCRegister Reg)
Set the register number.
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
uint64_t getDFPImm() const
Wrapper class representing physical registers. Should be passed by value.
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCSymbol * getAddSym() const
int64_t getConstant() const
const MCSymbol * getSubSym() const
unsigned getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch target operand.
unsigned getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget21OpValue - Return binary encoding of the branch target operand.
uint64_t getBinaryCodeForInstr(const MCInst &MI, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getMachineOpValue - Return binary encoding of operand.
unsigned getUImmWithOffsetEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Subtract Offset then encode as a N-bit unsigned integer.
unsigned getOperandFromEndValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getScaledImmOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMovePRegPairOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTargetOpValueMMR6(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueMMR6 - Return binary encoding of the branch target operand.
unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue - Return binary encoding of the branch target operand.
unsigned getRegisterListOpValue16(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget26OpValue - Return binary encoding of the branch target operand.
unsigned getBranchTarget26OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget26OpValueMM - Return binary encoding of the branch target operand.
unsigned getImmOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTargetOpValue1SImm16(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue1SImm16 - Return binary encoding of the branch target operand.
unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getJumpOffset16OpValue - Return binary encoding of the jump target operand.
unsigned getBranchTargetOpValueMMPC10(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueMMPC10 - Return binary encoding of the microMIPS 10-bit branch target operand.
unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getJumpTargetOpValue - Return binary encoding of the jump target operand.
unsigned getUImm4AndValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue - Return binary encoding of the microMIPS branch target operand.
unsigned getMovePRegSingleOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
void encodeInstruction(const MCInst &MI, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const override
encodeInstruction - Emit the instruction.
unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTarget21OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget21OpValueMM - Return binary encoding of the branch target operand for microMIPS.
unsigned getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget7OpValueMM - Return binary encoding of the microMIPS branch target operand.
unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
void EmitByte(unsigned char C, raw_ostream &OS) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static unsigned getFormat(uint64_t TSFlags)
@ fixup_MICROMIPS_TLS_TPREL_LO16
@ fixup_MICROMIPS_GOT_PAGE
@ fixup_MICROMIPS_PC16_S1
@ fixup_MICROMIPS_TLS_TPREL_HI16
@ fixup_MICROMIPS_PC21_S1
@ fixup_MICROMIPS_GPOFF_LO
@ fixup_MICROMIPS_PC19_S2
@ fixup_MICROMIPS_TLS_LDM
@ fixup_MICROMIPS_GOT_OFST
@ fixup_MICROMIPS_TLS_DTPREL_HI16
@ fixup_MICROMIPS_PC10_S1
@ fixup_MICROMIPS_HIGHEST
@ fixup_MICROMIPS_GOT_DISP
@ fixup_MICROMIPS_PC18_S3
@ fixup_MICROMIPS_PC26_S1
@ fixup_MICROMIPS_GOTTPREL
@ fixup_MICROMIPS_TLS_DTPREL_LO16
@ fixup_Mips_Branch_PCRel
@ fixup_MICROMIPS_GPOFF_HI
bool isGpOff(const MCSpecifierExpr &E)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
This is an optimization pass for GlobalISel generic memory operations.
MCCodeEmitter * createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, MCContext &Ctx)
MCCodeEmitter * createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, MCContext &Ctx)
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
uint16_t MCFixupKind
Extensible enumeration to represent the type of a fixup.
static Lanai::Fixups FixupKind(const MCExpr *Expr)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
To bit_cast(const From &from) noexcept
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.