37 #define DEBUG_TYPE "mccodeemitter" 39 #define GET_INSTRMAP_INFO 40 #include "MipsGenInstrInfo.inc" 41 #undef GET_INSTRMAP_INFO 93 void MipsMCCodeEmitter::LowerCompactBranch(
MCInst& Inst)
const {
104 assert(Reg0 != Reg1 &&
"Instruction has bad operands ($rs == $rt)!");
110 }
else if (Inst.
getOpcode() == Mips::BNVC_MMR6 ||
121 bool MipsMCCodeEmitter::isMicroMips(
const MCSubtargetInfo &STI)
const {
140 if (IsLittleEndian && Size == 4 && isMicroMips(STI)) {
144 for (
unsigned i = 0; i <
Size; ++i) {
145 unsigned Shift = IsLittleEndian ? i * 8 : (Size - 1 - i) * 8;
146 EmitByte((Val >> Shift) & 0xff, OS);
177 case Mips::BOVC_MMR6:
179 case Mips::BNVC_MMR6:
180 LowerCompactBranch(TmpInst);
183 unsigned long N = Fixups.
size();
190 if ((Opcode != Mips::NOP) && (Opcode != Mips::SLL) &&
191 (Opcode != Mips::SLL_MM) && (Opcode != Mips::SLL_MMR6) && !Binary)
195 if (isMicroMips(STI)) {
196 if (isMips32r6(STI)) {
197 NewOpcode = Mips::MipsR62MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
199 NewOpcode = Mips::Std2MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
202 NewOpcode = Mips::Std2MicroMips(Opcode, Mips::Arch_micromips);
206 NewOpcode = Mips::Dsp2MicroMips(Opcode, Mips::Arch_mmdsp);
208 if (NewOpcode != -1) {
209 if (Fixups.
size() >
N)
217 if (((MI.
getOpcode() == Mips::MOVEP_MM) ||
220 Binary = (Binary & 0xFFFFFC7F) | (RegPair << 7);
247 "getBranchTargetOpValue expects only expressions or immediates");
269 "getBranchTargetOpValue expects only expressions or immediates");
292 "getBranchTargetOpValueMMR6 expects only expressions or immediates");
315 "getBranchTargetOpValueLsl2MMR6 expects only expressions or immediates");
337 "getBranchTargetOpValueMM expects only expressions or immediates");
358 "getBranchTargetOpValuePC10 expects only expressions or immediates");
379 "getBranchTargetOpValueMM expects only expressions or immediates");
401 "getBranchTarget21OpValue expects only expressions or immediates");
423 "getBranchTarget21OpValueMM expects only expressions or immediates");
445 "getBranchTarget26OpValue expects only expressions or immediates");
467 "getBranchTarget26OpValueMM expects only expressions or immediates");
488 "getJumpOffset16OpValue expects only expressions or an immediate");
506 "getJumpTargetOpValue expects only expressions or an immediate");
523 "getJumpTargetOpValueMM expects only expressions or an immediate");
544 "getUImm5Lsl2Encoding expects only expressions or an immediate");
581 unsigned Binary = (MO.
getImm() >> 2) & 0x0000ffff;
582 return (((Binary & 0x8000) >> 7) | (Binary & 0x00ff));
593 if (Expr->evaluateAsAbsolute(Res))
598 return cast<MCConstantExpr>(Expr)->getValue();
602 unsigned Res =
getExprOpValue(cast<MCBinaryExpr>(Expr)->getLHS(), Fixups, STI);
603 Res +=
getExprOpValue(cast<MCBinaryExpr>(Expr)->getRHS(), Fixups, STI);
608 const MipsMCExpr *MipsExpr = cast<MipsMCExpr>(Expr);
727 switch(cast<MCSymbolRefExpr>(Expr)->getKind()) {
751 }
else if (MO.
isImm()) {
752 return static_cast<unsigned>(MO.
getImm());
755 .bitcastToAPInt().getHiBits(32).getLimitedValue());
764 template <
unsigned ShiftAmount>
774 OffBits >>= ShiftAmount;
776 return (OffBits & 0xFFFF) | RegBits;
790 return (OffBits & 0xF) | RegBits;
804 return (OffBits & 0xF) | RegBits;
818 return (OffBits & 0xF) | RegBits;
829 "Unexpected base register!");
833 return OffBits & 0x1F;
843 "Unexpected base register!");
848 return OffBits & 0x7F;
861 return (OffBits & 0x1FF) | RegBits;
874 return (OffBits & 0x07FF) | RegBits;
897 return (OffBits & 0x0FFF) | RegBits;
910 return (OffBits & 0xFFFF) | RegBits;
923 case Mips::SWM16_MMR6:
925 case Mips::LWM16_MMR6:
936 return ((OffBits >> 2) & 0x0F);
950 return Position + Size - 1;
953 template <
unsigned Bits,
int Offset>
977 "getSimm19Lsl2Encoding expects only expressions or an immediate");
999 "getSimm18Lsl2Encoding expects only expressions or an immediate");
1023 unsigned Value = MO.getImm();
1025 case 128:
return 0x0;
1032 case 15:
return 0x7;
1033 case 16:
return 0x8;
1034 case 31:
return 0x9;
1035 case 32:
return 0xa;
1036 case 63:
return 0xb;
1037 case 64:
return 0xc;
1038 case 255:
return 0xd;
1039 case 32768:
return 0xe;
1040 case 65535:
return 0xf;
1110 assert(((OpNo == 2) || (OpNo == 3)) &&
1111 "Unexpected OpNo for movep operand encoding!");
1114 assert(Op.
isReg() &&
"Operand of movep is not a register!");
1118 case Mips::ZERO:
return 0;
1119 case Mips::S1:
return 1;
1120 case Mips::V0:
return 2;
1121 case Mips::V1:
return 3;
1122 case Mips::S0:
return 4;
1123 case Mips::S2:
return 5;
1124 case Mips::S3:
return 6;
1125 case Mips::S4:
return 7;
1134 assert(MO.
isImm() &&
"getSimm23Lsl2Encoding expects only an immediate");
1136 unsigned Res =
static_cast<unsigned>(MO.
getImm());
1141 #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)
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
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.
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
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.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
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...