36 #define DEBUG_TYPE "mccodeemitter" 38 #define GET_INSTRMAP_INFO 39 #include "MipsGenInstrInfo.inc" 40 #undef GET_INSTRMAP_INFO 92 void MipsMCCodeEmitter::LowerCompactBranch(
MCInst& Inst)
const {
103 assert(Reg0 != Reg1 &&
"Instruction has bad operands ($rs == $rt)!");
109 }
else if (Inst.
getOpcode() == Mips::BNVC_MMR6 ||
120 bool MipsMCCodeEmitter::isMicroMips(
const MCSubtargetInfo &STI)
const {
139 if (IsLittleEndian && Size == 4 && isMicroMips(STI)) {
143 for (
unsigned i = 0; i <
Size; ++i) {
144 unsigned Shift = IsLittleEndian ? i * 8 : (Size - 1 - i) * 8;
145 EmitByte((Val >> Shift) & 0xff, OS);
176 case Mips::BOVC_MMR6:
178 case Mips::BNVC_MMR6:
179 LowerCompactBranch(TmpInst);
182 unsigned long N = Fixups.
size();
188 const unsigned Opcode = TmpInst.
getOpcode();
189 if ((Opcode != Mips::NOP) && (Opcode != Mips::SLL) &&
190 (Opcode != Mips::SLL_MM) && (Opcode != Mips::SLL_MMR6) && !Binary)
194 if (isMicroMips(STI)) {
195 if (isMips32r6(STI)) {
196 NewOpcode = Mips::MipsR62MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
198 NewOpcode = Mips::Std2MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
201 NewOpcode = Mips::Std2MicroMips(Opcode, Mips::Arch_micromips);
205 NewOpcode = Mips::Dsp2MicroMips(Opcode, Mips::Arch_mmdsp);
207 if (NewOpcode != -1) {
208 if (Fixups.
size() >
N)
215 if (((MI.
getOpcode() == Mips::MOVEP_MM) ||
218 Binary = (Binary & 0xFFFFFC7F) | (RegPair << 7);
245 "getBranchTargetOpValue expects only expressions or immediates");
267 "getBranchTargetOpValue expects only expressions or immediates");
290 "getBranchTargetOpValueMMR6 expects only expressions or immediates");
313 "getBranchTargetOpValueLsl2MMR6 expects only expressions or immediates");
335 "getBranchTargetOpValueMM expects only expressions or immediates");
356 "getBranchTargetOpValuePC10 expects only expressions or immediates");
377 "getBranchTargetOpValueMM expects only expressions or immediates");
399 "getBranchTarget21OpValue expects only expressions or immediates");
421 "getBranchTarget21OpValueMM expects only expressions or immediates");
443 "getBranchTarget26OpValue expects only expressions or immediates");
465 "getBranchTarget26OpValueMM expects only expressions or immediates");
486 "getJumpOffset16OpValue expects only expressions or an immediate");
507 "getJumpTargetOpValue expects only expressions or an immediate");
524 "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 if (Expr->evaluateAsAbsolute(Res))
599 return cast<MCConstantExpr>(Expr)->getValue();
605 Res +=
getExprOpValue(cast<MCBinaryExpr>(Expr)->getRHS(), Fixups, STI);
610 const MipsMCExpr *MipsExpr = cast<MipsMCExpr>(Expr);
729 switch(cast<MCSymbolRefExpr>(Expr)->getKind()) {
754 }
else if (MO.
isImm()) {
755 return static_cast<unsigned>(MO.
getImm());
758 .bitcastToAPInt().getHiBits(32).getLimitedValue());
767 template <
unsigned ShiftAmount>
778 OffBits >>= ShiftAmount;
780 return (OffBits & 0xFFFF) | RegBits;
794 return (OffBits & 0xF) | RegBits;
808 return (OffBits & 0xF) | RegBits;
822 return (OffBits & 0xF) | RegBits;
833 "Unexpected base register!");
837 return OffBits & 0x1F;
847 "Unexpected base register!");
852 return OffBits & 0x7F;
866 return (OffBits & 0x1FF) | RegBits;
879 return (OffBits & 0x07FF) | RegBits;
903 return (OffBits & 0x0FFF) | RegBits;
916 return (OffBits & 0xFFFF) | RegBits;
929 case Mips::SWM16_MMR6:
931 case Mips::LWM16_MMR6:
942 return ((OffBits >> 2) & 0x0F);
956 return Position + Size - 1;
959 template <
unsigned Bits,
int Offset>
983 "getSimm19Lsl2Encoding expects only expressions or an immediate");
1005 "getSimm18Lsl2Encoding expects only expressions or an immediate");
1029 unsigned Value = MO.getImm();
1031 case 128:
return 0x0;
1038 case 15:
return 0x7;
1039 case 16:
return 0x8;
1040 case 31:
return 0x9;
1041 case 32:
return 0xa;
1042 case 63:
return 0xb;
1043 case 64:
return 0xc;
1044 case 255:
return 0xd;
1045 case 32768:
return 0xe;
1046 case 65535:
return 0xf;
1116 assert(((OpNo == 2) || (OpNo == 3)) &&
1117 "Unexpected OpNo for movep operand encoding!");
1120 assert(Op.
isReg() &&
"Operand of movep is not a register!");
1124 case Mips::ZERO:
return 0;
1125 case Mips::S1:
return 1;
1126 case Mips::V0:
return 2;
1127 case Mips::V1:
return 3;
1128 case Mips::S0:
return 4;
1129 case Mips::S2:
return 5;
1130 case Mips::S3:
return 6;
1131 case Mips::S4:
return 7;
1140 assert(MO.
isImm() &&
"getSimm23Lsl2Encoding expects only an immediate");
1142 unsigned Res =
static_cast<unsigned>(MO.
getImm());
1147 #include "MipsGenMCCodeEmitter.inc"
unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget26OpValue - Return binary encoding of the branch target operand.
unsigned getMemEncodingMMImm16(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
void encodeInstruction(const MCInst &MI, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const override
encodeInstruction - Emit the instruction.
This class represents lattice values for constants.
unsigned getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch target operand.
void push_back(const T &Elt)
unsigned getUImm6Lsl2Encoding(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.
unsigned getRegisterListOpValue16(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSimm18Lsl3Encoding(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.
static Lanai::Fixups FixupKind(const MCExpr *Expr)
unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
bool isGpOff(MipsExprKind &Kind) 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 getUImm4AndValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
const FeatureBitset & getFeatureBits() const
unsigned getMemEncodingMMImm11(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 getBranchTarget26OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget26OpValueMM - Return binary encoding of the branch target operand. ...
Position
Position to insert a new instruction relative to an existing instruction.
This file implements a class to represent arbitrary precision integral constant values and operations...
unsigned getReg() const
Returns the register number.
Context object for machine code objects.
void EmitByte(unsigned char C, raw_ostream &OS) const
const MCExpr * getExpr() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
MipsExprKind getKind() const
Get the kind of this expression.
Instances of this class represent a single low-level machine instruction.
MCCodeEmitter * createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned getMovePRegSingleOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMImm9(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 const MachineRegisterInfo * MRI
unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget21OpValue - Return binary encoding of the branch target operand.
unsigned getUImm5Lsl2Encoding(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...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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 getMemEncodingMMImm4(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
MCCodeEmitter - Generic instruction encoding interface.
Interface to description of machine instruction set.
unsigned getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
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...
void EmitInstruction(uint64_t Val, unsigned Size, const MCSubtargetInfo &STI, raw_ostream &OS) const
unsigned getNumOperands() const
uint16_t getEncodingValue(MCRegister RegNo) const
Returns the encoding for RegNo.
unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue - Return binary encoding of the branch target operand.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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 setOpcode(unsigned Op)
unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue - Return binary encoding of the microMIPS branch target operand.
static void LowerLargeShift(MCInst &Inst)
unsigned getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
const MCOperand & getOperand(unsigned i) const
unsigned getExprOpValue(const MCExpr *Expr, 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 getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
MCCodeEmitter * createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, MCContext &Ctx)
const MCExpr * getSubExpr() const
Get the child of this expression.
unsigned getMemEncodingMMImm4Lsl1(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
uint64_t getBinaryCodeForInstr(const MCInst &MI, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getJumpTargetOpValue - Return binary encoding of the jump target operand.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Generic base class for all target subtargets.
References to labels and assigned expressions.
void setReg(unsigned Reg)
Set the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getMemEncodingMMSPImm5Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
const MCRegisterInfo * getRegisterInfo() const
LLVM Value Representation.
unsigned getMovePRegPairOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
This class implements an extremely fast bulk output stream that can only output to a stream...
unsigned getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Target specific expression.
unsigned getOpcode() const
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 operands of the MCInst class.
unsigned getMemEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Return binary encoding of memory related operand.
unsigned getSImm9AddiuspValue(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 getSize() const
Return the number of bytes in the encoding of this instruction, or zero if the encoding size cannot b...