37 #define DEBUG_TYPE "mccodeemitter"
39 #define GET_INSTRMAP_INFO
40 #include "MipsGenInstrInfo.inc"
41 #undef GET_INSTRMAP_INFO
89 case Mips::DSLL_MM64R6:
92 case Mips::DSRL_MM64R6:
95 case Mips::DSRA_MM64R6:
98 case Mips::DROTR_MM64R6:
107 "Invalid no. of machine operands for DINS!");
114 assert((pos + size) <= 64 &&
115 "DINS cannot have position plus size over 64");
117 if ((pos + size) > 0 && (pos + size) <= 32)
119 else if ((pos + size) > 32) {
124 }
else if ((pos + size) > 32 && (pos + size) <= 64) {
132 void MipsMCCodeEmitter::LowerCompactBranch(
MCInst& Inst)
const {
143 assert(Reg0 != Reg1 &&
"Instruction has bad operands ($rs == $rt)!");
149 }
else if (Inst.
getOpcode() == Mips::BNVC_MMR6 ||
160 bool MipsMCCodeEmitter::isMicroMips(
const MCSubtargetInfo &STI)
const {
179 if (IsLittleEndian && Size == 4 && isMicroMips(STI)) {
183 for (
unsigned i = 0; i <
Size; ++i) {
184 unsigned Shift = IsLittleEndian ? i * 8 : (Size - 1 - i) * 8;
185 EmitByte((Val >> Shift) & 0xff, OS);
208 case Mips::DSLL_MM64R6:
209 case Mips::DSRL_MM64R6:
210 case Mips::DSRA_MM64R6:
211 case Mips::DROTR_MM64R6:
224 case Mips::BOVC_MMR6:
226 case Mips::BNVC_MMR6:
227 LowerCompactBranch(TmpInst);
230 unsigned long N = Fixups.
size();
237 if ((Opcode != Mips::NOP) && (Opcode != Mips::SLL) &&
238 (Opcode != Mips::SLL_MM) && !Binary)
242 if (isMicroMips(STI)) {
243 if (isMips32r6(STI)) {
244 NewOpcode = Mips::MipsR62MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
246 NewOpcode = Mips::Std2MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
249 NewOpcode = Mips::Std2MicroMips(Opcode, Mips::Arch_micromips);
253 NewOpcode = Mips::Dsp2MicroMips(Opcode, Mips::Arch_mmdsp);
255 if (NewOpcode != -1) {
256 if (Fixups.
size() >
N)
288 "getBranchTargetOpValue expects only expressions or immediates");
310 "getBranchTargetOpValue expects only expressions or immediates");
333 "getBranchTargetOpValueMMR6 expects only expressions or immediates");
356 "getBranchTargetOpValueLsl2MMR6 expects only expressions or immediates");
378 "getBranchTargetOpValueMM expects only expressions or immediates");
399 "getBranchTargetOpValuePC10 expects only expressions or immediates");
420 "getBranchTargetOpValueMM expects only expressions or immediates");
442 "getBranchTarget21OpValue expects only expressions or immediates");
464 "getBranchTarget21OpValueMM expects only expressions or immediates");
486 "getBranchTarget26OpValue expects only expressions or immediates");
508 "getBranchTarget26OpValueMM expects only expressions or immediates");
529 "getJumpOffset16OpValue expects only expressions or an immediate");
547 "getJumpTargetOpValue expects only expressions or an immediate");
564 "getJumpTargetOpValueMM expects only expressions or an immediate");
585 "getUImm5Lsl2Encoding expects only expressions or an immediate");
622 unsigned Binary = (MO.
getImm() >> 2) & 0x0000ffff;
623 return (((Binary & 0x8000) >> 7) | (Binary & 0x00ff));
634 if (Expr->evaluateAsAbsolute(Res))
639 return cast<MCConstantExpr>(Expr)->getValue();
643 unsigned Res =
getExprOpValue(cast<MCBinaryExpr>(Expr)->getLHS(), Fixups, STI);
644 Res +=
getExprOpValue(cast<MCBinaryExpr>(Expr)->getRHS(), Fixups, STI);
649 const MipsMCExpr *MipsExpr = cast<MipsMCExpr>(Expr);
762 switch(cast<MCSymbolRefExpr>(Expr)->getKind()) {
786 }
else if (MO.
isImm()) {
787 return static_cast<unsigned>(MO.
getImm());
790 .bitcastToAPInt().getHiBits(32).getLimitedValue());
799 template <
unsigned ShiftAmount>
809 OffBits >>= ShiftAmount;
811 return (OffBits & 0xFFFF) | RegBits;
825 return (OffBits & 0xF) | RegBits;
839 return (OffBits & 0xF) | RegBits;
853 return (OffBits & 0xF) | RegBits;
864 "Unexpected base register!");
868 return OffBits & 0x1F;
878 "Unexpected base register!");
883 return OffBits & 0x7F;
896 return (OffBits & 0x1FF) | RegBits;
909 return (OffBits & 0x07FF) | RegBits;
932 return (OffBits & 0x0FFF) | RegBits;
945 return (OffBits & 0xFFFF) | RegBits;
958 case Mips::SWM16_MMR6:
960 case Mips::LWM16_MMR6:
971 return ((OffBits >> 2) & 0x0F);
985 return Position + Size - 1;
988 template <
unsigned Bits,
int Offset>
1012 "getSimm19Lsl2Encoding expects only expressions or an immediate");
1034 "getSimm18Lsl2Encoding expects only expressions or an immediate");
1058 unsigned Value = MO.getImm();
1060 case 128:
return 0x0;
1067 case 15:
return 0x7;
1068 case 16:
return 0x8;
1069 case 31:
return 0x9;
1070 case 32:
return 0xa;
1071 case 63:
return 0xb;
1072 case 64:
return 0xc;
1073 case 255:
return 0xd;
1074 case 32768:
return 0xe;
1075 case 65535:
return 0xf;
1153 assert(MO.
isImm() &&
"getSimm23Lsl2Encoding expects only an immediate");
1155 unsigned Res =
static_cast<unsigned>(MO.
getImm());
1160 #include "MipsGenMCCodeEmitter.inc"
void push_back(const T &Elt)
void encodeInstruction(const MCInst &MI, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const override
encodeInstruction - Emit the instruction.
unsigned getRegisterListOpValue16(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.
unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getJumpTargetOpValue - Return binary encoding of the jump target operand.
unsigned getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Describe properties that are true of each instruction in the target description file.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
unsigned getUImm5Lsl2Encoding(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
bool isGpOff(MipsExprKind &Kind) const
void EmitInstruction(uint64_t Val, unsigned Size, const MCSubtargetInfo &STI, raw_ostream &OS) 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...
static void LowerDins(MCInst &InstIn)
unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
static Lanai::Fixups FixupKind(const MCExpr *Expr)
uint64_t getBinaryCodeForInstr(const MCInst &MI, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getRegisterPairOpValue(const MCInst &MI, unsigned OpNo, 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 getMemEncodingMMGPImm7Lsl2(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...
Base class for the full range of assembler expressions which are needed for parsing.
unsigned getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Reg
All possible values of the reg field in the ModR/M byte.
This file implements a class to represent arbitrary precision integral constant values and operations...
Context object for machine code objects.
unsigned getReg() const
Returns the register number.
unsigned getMovePRegPairOpValue(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.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
unsigned getBranchTargetOpValueMMR6(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueMMR6 - Return binary encoding of the branch target operand. ...
Instances of this class represent a single low-level machine instruction.
MCCodeEmitter * createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const MCExpr * getExpr() const
unsigned const MachineRegisterInfo * MRI
MCCodeEmitter - Generic instruction encoding interface.
unsigned getSize() const
Return the number of bytes in the encoding of this instruction, or zero if the encoding size cannot b...
Interface to description of machine instruction set.
MCFixupKind
Extensible enumeration to represent the type of a fixup.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget26OpValue - Return binary encoding of the branch target operand.
unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
unsigned getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getUImm4AndValue(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
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
unsigned getMemEncodingMMSPImm5Lsl2(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
void setOpcode(unsigned Op)
unsigned getBranchTarget26OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget26OpValueMM - Return binary encoding of the branch target operand. ...
static void LowerLargeShift(MCInst &Inst)
unsigned getMemEncodingMMImm9(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
const FeatureBitset & getFeatureBits() const
getFeatureBits - Return the feature bits.
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 getMemEncodingMMImm11(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getOpcode() const
MCCodeEmitter * createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
const MCRegisterInfo * getRegisterInfo() const
unsigned getJumpTargetOpValueMM(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 getMemEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Return binary encoding of memory related 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.
void EmitByte(unsigned char C, raw_ostream &OS) const
unsigned getNumOperands() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
MCSubtargetInfo - Generic base class for all target subtargets.
unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getMachineOpValue - Return binary encoding of operand.
unsigned getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch target operand.
References to labels and assigned expressions.
unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
void setReg(unsigned Reg)
Set the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MipsExprKind getKind() const
Get the kind of this expression.
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
LLVM Value Representation.
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...
This class implements an extremely fast bulk output stream that can only output to a stream...
Target specific expression.
Instances of this class represent operands of the MCInst class.
unsigned getMemEncodingMMImm4Lsl1(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
unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue - Return binary encoding of the branch target operand.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
const MCOperand & getOperand(unsigned i) const
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...