38#define DEBUG_TYPE "mccodeemitter"
40#define GET_INSTRMAP_INFO
41#include "MipsGenInstrInfo.inc"
42#undef GET_INSTRMAP_INFO
116void MipsMCCodeEmitter::LowerCompactBranch(
MCInst& Inst)
const {
127 assert(Reg0 != Reg1 &&
"Instruction has bad operands ($rs == $rt)!");
133 }
else if (Inst.
getOpcode() == Mips::BNVC_MMR6 ||
145 return STI.
hasFeature(Mips::FeatureMicroMips);
167 switch (
MI.getOpcode()) {
181 case Mips::BOVC_MMR6:
183 case Mips::BNVC_MMR6:
184 LowerCompactBranch(TmpInst);
187 size_t N = Fixups.size();
193 const unsigned Opcode = TmpInst.
getOpcode();
194 if ((Opcode != Mips::NOP) && (Opcode != Mips::SLL) &&
195 (Opcode != Mips::SLL_MM) && (Opcode != Mips::SLL_MMR6) && !Binary)
199 if (isMicroMips(STI)) {
200 if (isMips32r6(STI)) {
201 NewOpcode = Mips::MipsR62MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
203 NewOpcode = Mips::Std2MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
206 NewOpcode = Mips::Std2MicroMips(Opcode, Mips::Arch_micromips);
210 NewOpcode = Mips::Dsp2MicroMips(Opcode, Mips::Arch_mmdsp);
212 if (NewOpcode != -1) {
213 if (Fixups.size() >
N)
220 if (((
MI.getOpcode() == Mips::MOVEP_MM) ||
221 (
MI.getOpcode() == Mips::MOVEP_MMR6))) {
223 Binary = (Binary & 0xFFFFFC7F) | (RegPair << 7);
237 support::endian::write<uint16_t>(CB, Binary,
Endian);
238 }
else if (IsLittleEndian && isMicroMips(STI)) {
239 support::endian::write<uint16_t>(CB, Binary >> 16,
Endian);
240 support::endian::write<uint16_t>(CB, Binary & 0xffff,
Endian);
242 support::endian::write<uint32_t>(CB, Binary,
Endian);
259 "getBranchTargetOpValue expects only expressions or immediates");
280 "getBranchTargetOpValue expects only expressions or immediates");
302 "getBranchTargetOpValueMMR6 expects only expressions or immediates");
324 "getBranchTargetOpValueLsl2MMR6 expects only expressions or immediates");
345 "getBranchTargetOpValueMM expects only expressions or immediates");
365 "getBranchTargetOpValuePC10 expects only expressions or immediates");
385 "getBranchTargetOpValueMM expects only expressions or immediates");
405 "getBranchTarget21OpValue expects only expressions or immediates");
426 "getBranchTarget21OpValueMM expects only expressions or immediates");
447 "getBranchTarget26OpValue expects only expressions or immediates");
468 "getBranchTarget26OpValueMM expects only expressions or immediates");
488 "getJumpOffset16OpValue expects only expressions or an immediate");
509 "getJumpTargetOpValue expects only expressions or an immediate");
525 "getJumpTargetOpValueMM expects only expressions or an immediate");
545 "getUImm5Lsl2Encoding expects only expressions or an immediate");
582 unsigned Binary = (MO.
getImm() >> 2) & 0x0000ffff;
583 return (((Binary & 0x8000) >> 7) | (Binary & 0x00ff));
594 const auto *MipsExpr = cast<MCSpecifierExpr>(Expr);
597 switch (MipsExpr->getSpecifier()) {
724 }
else if (MO.
isImm()) {
725 return static_cast<unsigned>(MO.
getImm());
727 return static_cast<unsigned>(bit_cast<double>(MO.
getDFPImm()));
740 assert(MO.
isExpr() &&
"getImmOpValue expects only expressions or immediates");
743 if (Expr->evaluateAsAbsolute(Res))
746 if (!isa<MCSpecifierExpr>(Expr) && MIFrm ==
MipsII::FrmI) {
755template <
unsigned ShiftAmount>
760 assert(
MI.getOperand(OpNo).isReg());
766 OffBits >>= ShiftAmount;
768 return (OffBits & 0xFFFF) | RegBits;
776 assert(
MI.getOperand(OpNo).isReg());
782 return (OffBits & 0xF) | RegBits;
790 assert(
MI.getOperand(OpNo).isReg());
796 return (OffBits & 0xF) | RegBits;
804 assert(
MI.getOperand(OpNo).isReg());
810 return (OffBits & 0xF) | RegBits;
818 assert(
MI.getOperand(OpNo).isReg() &&
819 (
MI.getOperand(OpNo).getReg() == Mips::SP ||
820 MI.getOperand(OpNo).getReg() == Mips::SP_64) &&
821 "Unexpected base register!");
825 return OffBits & 0x1F;
833 assert(
MI.getOperand(OpNo).isReg() &&
834 MI.getOperand(OpNo).getReg() == Mips::GP &&
835 "Unexpected base register!");
840 return OffBits & 0x7F;
848 assert(
MI.getOperand(OpNo).isReg());
854 return (OffBits & 0x1FF) | RegBits;
862 assert(
MI.getOperand(OpNo).isReg());
867 return (OffBits & 0x07FF) | RegBits;
876 switch (
MI.getOpcode()) {
881 OpNo =
MI.getNumOperands() - 2;
886 assert(
MI.getOperand(OpNo).isReg());
891 return (OffBits & 0x0FFF) | RegBits;
899 assert(
MI.getOperand(OpNo).isReg());
904 return (OffBits & 0xFFFF) | RegBits;
913 switch (
MI.getOpcode()) {
917 case Mips::SWM16_MMR6:
919 case Mips::LWM16_MMR6:
920 OpNo =
MI.getNumOperands() - 2;
925 assert(
MI.getOperand(OpNo).isReg());
927 assert(
MI.getOperand(OpNo+1).isImm());
930 return ((OffBits >> 2) & 0x0F);
939 assert(
MI.getOperand(OpNo-1).isImm());
940 assert(
MI.getOperand(OpNo).isImm());
944 return Position +
Size - 1;
947template <
unsigned Bits,
int Offset>
952 assert(
MI.getOperand(OpNo).isImm());
971 "getSimm19Lsl2Encoding expects only expressions or an immediate");
993 "getSimm18Lsl2Encoding expects only expressions or an immediate");
1006 assert(
MI.getOperand(OpNo).isImm());
1015 assert(
MI.getOperand(OpNo).isImm());
1019 case 128:
return 0x0;
1026 case 15:
return 0x7;
1027 case 16:
return 0x8;
1028 case 31:
return 0x9;
1029 case 32:
return 0xa;
1030 case 63:
return 0xb;
1031 case 64:
return 0xc;
1032 case 255:
return 0xd;
1033 case 32768:
return 0xe;
1034 case 65535:
return 0xf;
1048 for (
unsigned I = OpNo, E =
MI.getNumOperands() - 2;
I < E; ++
I) {
1063 return (
MI.getNumOperands() - 4);
1072 if (
MI.getOperand(0).getReg() == Mips::A1 &&
1073 MI.getOperand(1).getReg() == Mips::A2)
1075 else if (
MI.getOperand(0).getReg() == Mips::A1 &&
1076 MI.getOperand(1).getReg() == Mips::A3)
1078 else if (
MI.getOperand(0).getReg() == Mips::A2 &&
1079 MI.getOperand(1).getReg() == Mips::A3)
1081 else if (
MI.getOperand(0).getReg() == Mips::A0 &&
1082 MI.getOperand(1).getReg() == Mips::S5)
1084 else if (
MI.getOperand(0).getReg() == Mips::A0 &&
1085 MI.getOperand(1).getReg() == Mips::S6)
1087 else if (
MI.getOperand(0).getReg() == Mips::A0 &&
1088 MI.getOperand(1).getReg() == Mips::A1)
1090 else if (
MI.getOperand(0).getReg() == Mips::A0 &&
1091 MI.getOperand(1).getReg() == Mips::A2)
1093 else if (
MI.getOperand(0).getReg() == Mips::A0 &&
1094 MI.getOperand(1).getReg() == Mips::A3)
1104 assert(((OpNo == 2) || (OpNo == 3)) &&
1105 "Unexpected OpNo for movep operand encoding!");
1108 assert(
Op.isReg() &&
"Operand of movep is not a register!");
1109 switch (
Op.getReg().id()) {
1112 case Mips::ZERO:
return 0;
1113 case Mips::S1:
return 1;
1114 case Mips::V0:
return 2;
1115 case Mips::V1:
return 3;
1116 case Mips::S0:
return 4;
1117 case Mips::S2:
return 5;
1118 case Mips::S3:
return 6;
1119 case Mips::S4:
return 7;
1128 assert(MO.
isImm() &&
"getSimm23Lsl2Encoding expects only an immediate");
1130 unsigned Res =
static_cast<unsigned>(MO.
getImm());
1135#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 void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
static void LowerLargeShift(MCInst &Inst)
This file defines the SmallVector class.
This class represents an Operation in the Expression.
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.
const MCRegisterInfo * getRegisterInfo() const
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
Base class for the full range of assembler expressions which are needed for parsing.
@ 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.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
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
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
Wrapper class representing physical registers. Should be passed by value.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) 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 getMemEncodingMMImm9(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 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 getMemEncodingMMGPImm7Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMSPImm5Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMImm4(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Return binary encoding of memory related operand.
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 getMemEncodingMMImm11(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 getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMImm16(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 getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
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 getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
void EmitByte(unsigned char C, raw_ostream &OS) const
unsigned getMemEncodingMMImm4Lsl1(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
@ C
The default llvm calling convention, compatible with C.
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)
This is an optimization pass for GlobalISel generic memory operations.
MCCodeEmitter * createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, MCContext &Ctx)
MCCodeEmitter * createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, MCContext &Ctx)
uint16_t MCFixupKind
Extensible enumeration to represent the type of a fixup.
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
Description of the encoding of one expression Op.