41 #define DEBUG_TYPE "mips16-instrinfo" 72 const DebugLoc &DL,
unsigned DestReg,
73 unsigned SrcReg,
bool KillSrc)
const {
76 if (Mips::CPU16RegsRegClass.
contains(DestReg) &&
77 Mips::GPR32RegClass.
contains(SrcReg))
78 Opc = Mips::MoveR3216;
79 else if (Mips::GPR32RegClass.
contains(DestReg) &&
80 Mips::CPU16RegsRegClass.
contains(SrcReg))
81 Opc = Mips::Move32R16;
82 else if ((SrcReg == Mips::HI0) &&
83 (Mips::CPU16RegsRegClass.
contains(DestReg)))
84 Opc = Mips::Mfhi16, SrcReg = 0;
85 else if ((SrcReg == Mips::LO0) &&
86 (Mips::CPU16RegsRegClass.
contains(DestReg)))
87 Opc = Mips::Mflo16, SrcReg = 0;
89 assert(Opc &&
"Cannot copy registers");
113 unsigned SrcReg,
bool isKill,
int FI,
118 if (I != MBB.
end()) DL = I->getDebugLoc();
121 if (Mips::CPU16RegsRegClass.hasSubClassEq(RC))
122 Opc = Mips::SwRxSpImmX16;
123 assert(Opc &&
"Register class not handled!");
125 addFrameIndex(FI).
addImm(Offset)
131 unsigned DestReg,
int FI,
136 if (I != MBB.
end()) DL = I->getDebugLoc();
140 if (Mips::CPU16RegsRegClass.hasSubClassEq(RC))
141 Opc = Mips::LwRxSpImmX16;
142 assert(Opc &&
"Register class not handled!");
153 ExpandRetRA16(MBB, MI, Mips::JrcRa16);
165 case Mips::BeqzRxImmX16:
return Mips::BnezRxImmX16;
166 case Mips::BnezRxImmX16:
return Mips::BeqzRxImmX16;
167 case Mips::BeqzRxImm16:
return Mips::BnezRxImm16;
168 case Mips::BnezRxImm16:
return Mips::BeqzRxImm16;
169 case Mips::BteqzT8CmpX16:
return Mips::BtnezT8CmpX16;
170 case Mips::BteqzT8SltX16:
return Mips::BtnezT8SltX16;
171 case Mips::BteqzT8SltiX16:
return Mips::BtnezT8SltiX16;
172 case Mips::Btnez16:
return Mips::Bteqz16;
173 case Mips::BtnezX16:
return Mips::BteqzX16;
174 case Mips::BtnezT8CmpiX16:
return Mips::BteqzT8CmpiX16;
175 case Mips::BtnezT8SltuX16:
return Mips::BteqzT8SltuX16;
176 case Mips::BtnezT8SltiuX16:
return Mips::BteqzT8SltiuX16;
177 case Mips::Bteqz16:
return Mips::Btnez16;
178 case Mips::BteqzX16:
return Mips::BtnezX16;
179 case Mips::BteqzT8CmpiX16:
return Mips::BtnezT8CmpiX16;
180 case Mips::BteqzT8SltuX16:
return Mips::BtnezT8SltuX16;
181 case Mips::BteqzT8SltiuX16:
return Mips::BtnezT8SltiuX16;
182 case Mips::BtnezT8CmpX16:
return Mips::BteqzT8CmpX16;
183 case Mips::BtnezT8SltX16:
return Mips::BteqzT8SltX16;
184 case Mips::BtnezT8SltiX16:
return Mips::BteqzT8SltiX16;
190 const std::vector<CalleeSavedInfo> &CSI,
191 unsigned Flags = 0) {
192 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
198 unsigned Reg = CSI[e-i-1].getReg();
222 bool SaveS2 = Reserved[Mips::S2];
224 unsigned Opc = ((FrameSize <= 128) && !SaveS2)? Mips::Save16:Mips::SaveX16;
225 MIB =
BuildMI(MBB, I, DL,
get(Opc));
230 if (isUInt<11>(FrameSize))
235 int64_t Remainder = FrameSize - Base;
240 adjustStackPtrBig(SP, -Remainder, MBB, I, Mips::V0, Mips::V1);
252 bool SaveS2 = Reserved[Mips::S2];
254 unsigned Opc = ((FrameSize <= 128) && !SaveS2)?
255 Mips::Restore16:Mips::RestoreX16;
257 if (!isUInt<11>(FrameSize)) {
258 unsigned Base = 2040;
259 int64_t Remainder = FrameSize - Base;
266 adjustStackPtrBig(SP, Remainder, MBB, I, Mips::A0, Mips::A1);
268 MIB =
BuildMI(MBB, I, DL,
get(Opc));
280 void Mips16InstrInfo::adjustStackPtrBig(
unsigned SP, int64_t Amount,
283 unsigned Reg1,
unsigned Reg2)
const {
304 void Mips16InstrInfo::adjustStackPtrBigUnrestricted(
320 adjustStackPtrBigUnrestricted(SP, Amount, MBB, I);
329 unsigned &NewImm)
const {
343 int32_t lo = Imm & 0xFFFF;
357 (*II->getParent()->getParent(), &Mips::CPU16RegsRegClass);
359 for (
unsigned i = 0, e = II->getNumOperands(); i != e; ++i) {
375 for (
unsigned i = 0, e = II->getNumOperands(); i != e; ++i) {
384 Available &= Candidates;
389 unsigned FirstRegSaved =0, SecondRegSaved=0;
390 unsigned FirstRegSavedTo = 0, SecondRegSavedTo = 0;
396 Candidates.
reset(Reg);
399 FirstRegSavedTo = Mips::T0;
400 copyPhysReg(MBB, II, DL, FirstRegSavedTo, FirstRegSaved,
true);
404 Available.
reset(Reg);
407 if (FrameReg == Mips::SP) {
412 if (DefReg!= SpReg) {
413 SecondRegSaved = SpReg;
417 copyPhysReg(MBB, II, DL, SecondRegSavedTo, SecondRegSaved,
true);
420 Available.
reset(SpReg);
426 BuildMI(MBB, II, DL,
get(Mips:: AdduRxRyRz16), Reg).
addReg(FrameReg)
428 if (FirstRegSaved || SecondRegSaved) {
431 copyPhysReg(MBB, II, DL, FirstRegSaved, FirstRegSavedTo,
true);
433 copyPhysReg(MBB, II, DL, SecondRegSaved, SecondRegSavedTo,
true);
438 unsigned Mips16InstrInfo::getAnalyzableBrOpc(
unsigned Opc)
const {
439 return (Opc == Mips::BeqzRxImmX16 || Opc == Mips::BimmX16 ||
440 Opc == Mips::Bimm16 ||
441 Opc == Mips::Bteqz16 || Opc == Mips::Btnez16 ||
442 Opc == Mips::BeqzRxImm16 || Opc == Mips::BnezRxImm16 ||
443 Opc == Mips::BnezRxImmX16 || Opc == Mips::BteqzX16 ||
444 Opc == Mips::BteqzT8CmpX16 || Opc == Mips::BteqzT8CmpiX16 ||
445 Opc == Mips::BteqzT8SltX16 || Opc == Mips::BteqzT8SltuX16 ||
446 Opc == Mips::BteqzT8SltiX16 || Opc == Mips::BteqzT8SltiuX16 ||
447 Opc == Mips::BtnezX16 || Opc == Mips::BtnezT8CmpX16 ||
448 Opc == Mips::BtnezT8CmpiX16 || Opc == Mips::BtnezT8SltX16 ||
449 Opc == Mips::BtnezT8SltuX16 || Opc == Mips::BtnezT8SltiX16 ||
450 Opc == Mips::BtnezT8SltiuX16 ) ? Opc : 0;
455 unsigned Opc)
const {
456 BuildMI(MBB, I, I->getDebugLoc(),
get(Opc));
461 return get(Mips::AddiuSpImm16);
463 return get(Mips::AddiuSpImmX16);
479 case Mips::LbRxRyOffMemX16:
480 case Mips::LbuRxRyOffMemX16:
481 case Mips::LhRxRyOffMemX16:
482 case Mips::LhuRxRyOffMemX16:
483 case Mips::SbRxRyOffMemX16:
484 case Mips::ShRxRyOffMemX16:
485 case Mips::LwRxRyOffMemX16:
486 case Mips::SwRxRyOffMemX16:
487 case Mips::SwRxSpImmX16:
488 case Mips::LwRxSpImmX16:
490 case Mips::AddiuRxRyOffMemX16:
491 if ((Reg == Mips::PC) || (Reg == Mips::SP))
493 return isInt<15>(Amount);
const MCInstrDesc & AddiuSpImm(int64_t Imm) const
This class represents lattice values for constants.
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
MachineMemOperand * GetMemOperand(MachineBasicBlock &MBB, int FI, MachineMemOperand::Flags Flags) const
constexpr bool isInt< 16 >(int64_t x)
unsigned const TargetRegisterInfo * TRI
return AArch64::GPR64RegClass contains(Reg)
static void addSaveRestoreRegs(MachineInstrBuilder &MIB, const std::vector< CalleeSavedInfo > &CSI, unsigned Flags=0)
SI optimize exec mask operations pre RA
A description of a memory reference used in the backend.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
unsigned loadImmediate(unsigned FrameReg, int64_t Imm, MachineBasicBlock &MBB, MachineBasicBlock::iterator II, const DebugLoc &DL, unsigned &NewImm) const
Emit a series of instructions to load an immediate.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount)
void restoreFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const
void forward()
Move the internal MBB iterator and update register states.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
BitVector getRegsAvailable(const TargetRegisterClass *RC)
Return all available registers in the register class in Mask.
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, bool KillSrc) const override
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
isLoadFromStackSlot - If the specified machine instruction is a direct load from a stack slot...
BitVector getReservedRegs(const MachineFunction &MF) const override
void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
Adjust SP by Amount bytes.
unsigned getKillRegState(bool B)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
This file declares the machine register scavenger class.
const MipsInstrInfo * createMips16InstrInfo(const MipsSubtarget &STI)
Create MipsInstrInfo objects.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void BuildAddiuSpImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const
self_iterator getIterator()
const MachineInstrBuilder & addFrameIndex(int Idx) const
bool expandPostRAPseudo(MachineInstr &MI) const override
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isCopyInstrImpl(const MachineInstr &MI, const MachineOperand *&Source, const MachineOperand *&Destination) const override
If the specific machine instruction is a instruction that moves/copies value from one register to ano...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool validSpImm8(int offset)
const MipsRegisterInfo & getRegisterInfo() const override
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
void makeFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const
const MachineBasicBlock * getParent() const
The memory access reads data.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool isMoveReg(QueryType Type=IgnoreBundle) const
Return true if this instruction is a register move.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
void enterBasicBlock(MachineBasicBlock &MBB)
Start tracking liveness from the begin of basic block MBB.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
void loadRegFromStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, int64_t Offset) const override
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
isStoreToStackSlot - If the specified machine instruction is a direct store to a stack slot...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Mips16InstrInfo(const MipsSubtarget &STI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getOpcode() const
Return the opcode number for this descriptor.
const MachineOperand & getOperand(unsigned i) const
void storeRegToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, int64_t Offset) const override
unsigned getOppositeBranchOpc(unsigned Opc) const override
GetOppositeBranchOpc - Return the inverse of the specified opcode, e.g.