34#define DEBUG_TYPE "mips16-instrinfo"
45 int &FrameIndex)
const {
55 int &FrameIndex)
const {
63 bool RenamableDest,
bool RenamableSrc)
const {
66 if (Mips::CPU16RegsRegClass.
contains(DestReg) &&
67 Mips::GPR32RegClass.
contains(SrcReg))
68 Opc = Mips::MoveR3216;
69 else if (Mips::GPR32RegClass.
contains(DestReg) &&
70 Mips::CPU16RegsRegClass.
contains(SrcReg))
71 Opc = Mips::Move32R16;
72 else if ((SrcReg == Mips::HI0) &&
73 (Mips::CPU16RegsRegClass.
contains(DestReg)))
74 Opc = Mips::Mfhi16, SrcReg = 0;
75 else if ((SrcReg == Mips::LO0) &&
76 (Mips::CPU16RegsRegClass.
contains(DestReg)))
77 Opc = Mips::Mflo16, SrcReg = 0;
90std::optional<DestSourcePair>
99 Register SrcReg,
bool isKill,
int FI,
104 if (
I !=
MBB.end())
DL =
I->getDebugLoc();
107 if (Mips::CPU16RegsRegClass.hasSubClassEq(RC))
108 Opc = Mips::SwRxSpImmX16;
109 assert(
Opc &&
"Register class not handled!");
122 if (
I !=
MBB.end())
DL =
I->getDebugLoc();
126 if (Mips::CPU16RegsRegClass.hasSubClassEq(RC))
127 Opc = Mips::LwRxSpImmX16;
128 assert(
Opc &&
"Register class not handled!");
135 switch (
MI.getDesc().getOpcode()) {
139 ExpandRetRA16(
MBB,
MI, Mips::JrcRa16);
143 MBB.erase(
MI.getIterator());
151 case Mips::BeqzRxImmX16:
return Mips::BnezRxImmX16;
152 case Mips::BnezRxImmX16:
return Mips::BeqzRxImmX16;
153 case Mips::BeqzRxImm16:
return Mips::BnezRxImm16;
154 case Mips::BnezRxImm16:
return Mips::BeqzRxImm16;
155 case Mips::BteqzT8CmpX16:
return Mips::BtnezT8CmpX16;
156 case Mips::BteqzT8SltX16:
return Mips::BtnezT8SltX16;
157 case Mips::BteqzT8SltiX16:
return Mips::BtnezT8SltiX16;
158 case Mips::Btnez16:
return Mips::Bteqz16;
159 case Mips::BtnezX16:
return Mips::BteqzX16;
160 case Mips::BtnezT8CmpiX16:
return Mips::BteqzT8CmpiX16;
161 case Mips::BtnezT8SltuX16:
return Mips::BteqzT8SltuX16;
162 case Mips::BtnezT8SltiuX16:
return Mips::BteqzT8SltiuX16;
163 case Mips::Bteqz16:
return Mips::Btnez16;
164 case Mips::BteqzX16:
return Mips::BtnezX16;
165 case Mips::BteqzT8CmpiX16:
return Mips::BtnezT8CmpiX16;
166 case Mips::BteqzT8SltuX16:
return Mips::BtnezT8SltuX16;
167 case Mips::BteqzT8SltiuX16:
return Mips::BtnezT8SltiuX16;
168 case Mips::BtnezT8CmpX16:
return Mips::BteqzT8CmpX16;
169 case Mips::BtnezT8SltX16:
return Mips::BteqzT8SltX16;
170 case Mips::BtnezT8SltiX16:
return Mips::BteqzT8SltiX16;
178 for (
unsigned i = 0, e = CSI.
size(); i != e; ++i) {
210 unsigned Opc = ((FrameSize <= 128) && !SaveS2)? Mips::Save16:Mips::SaveX16;
221 int64_t Remainder = FrameSize -
Base;
226 adjustStackPtrBig(SP, -Remainder,
MBB,
I, Mips::V0, Mips::V1);
240 unsigned Opc = ((FrameSize <= 128) && !SaveS2)?
241 Mips::Restore16:Mips::RestoreX16;
244 unsigned Base = 2040;
245 int64_t Remainder = FrameSize -
Base;
252 adjustStackPtrBig(SP, Remainder,
MBB,
I, Mips::A0, Mips::A1);
266void Mips16InstrInfo::adjustStackPtrBig(
unsigned SP, int64_t Amount,
269 unsigned Reg1,
unsigned Reg2)
const {
290void Mips16InstrInfo::adjustStackPtrBigUnrestricted(
306 adjustStackPtrBigUnrestricted(SP, Amount,
MBB,
I);
315 unsigned &NewImm)
const {
329 int32_t lo =
Imm & 0xFFFF;
343 (*
II->getParent()->getParent(), &Mips::CPU16RegsRegClass);
346 if (MO.isReg() && MO.getReg() != 0 && !MO.isDef() &&
347 !MO.getReg().isVirtual())
348 Candidates.
reset(MO.getReg());
361 if (MO.isReg() && MO.isDef()) {
362 DefReg = MO.getReg();
373 unsigned FirstRegSaved =0, SecondRegSaved=0;
374 unsigned FirstRegSavedTo = 0, SecondRegSavedTo = 0;
380 Candidates.
reset(Reg);
383 FirstRegSavedTo = Mips::T0;
391 if (FrameReg == Mips::SP) {
396 if (DefReg!= SpReg) {
397 SecondRegSaved = SpReg;
398 SecondRegSavedTo = Mips::T1;
413 if (FirstRegSaved || SecondRegSaved) {
423unsigned Mips16InstrInfo::getAnalyzableBrOpc(
unsigned Opc)
const {
424 return (
Opc == Mips::BeqzRxImmX16 ||
Opc == Mips::BimmX16 ||
425 Opc == Mips::Bimm16 ||
426 Opc == Mips::Bteqz16 ||
Opc == Mips::Btnez16 ||
427 Opc == Mips::BeqzRxImm16 ||
Opc == Mips::BnezRxImm16 ||
428 Opc == Mips::BnezRxImmX16 ||
Opc == Mips::BteqzX16 ||
429 Opc == Mips::BteqzT8CmpX16 ||
Opc == Mips::BteqzT8CmpiX16 ||
430 Opc == Mips::BteqzT8SltX16 ||
Opc == Mips::BteqzT8SltuX16 ||
431 Opc == Mips::BteqzT8SltiX16 ||
Opc == Mips::BteqzT8SltiuX16 ||
432 Opc == Mips::BtnezX16 ||
Opc == Mips::BtnezT8CmpX16 ||
433 Opc == Mips::BtnezT8CmpiX16 ||
Opc == Mips::BtnezT8SltX16 ||
434 Opc == Mips::BtnezT8SltuX16 ||
Opc == Mips::BtnezT8SltiX16 ||
435 Opc == Mips::BtnezT8SltiuX16 ) ?
Opc : 0;
440 unsigned Opc)
const {
446 return get(Mips::AddiuSpImm16);
448 return get(Mips::AddiuSpImmX16);
464 case Mips::LbRxRyOffMemX16:
465 case Mips::LbuRxRyOffMemX16:
466 case Mips::LhRxRyOffMemX16:
467 case Mips::LhuRxRyOffMemX16:
468 case Mips::SbRxRyOffMemX16:
469 case Mips::ShRxRyOffMemX16:
470 case Mips::LwRxRyOffMemX16:
471 case Mips::SwRxRyOffMemX16:
472 case Mips::SwRxSpImmX16:
473 case Mips::LwRxSpImmX16:
475 case Mips::AddiuRxRyOffMemX16:
476 if ((Reg == Mips::PC) || (Reg == Mips::SP))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file implements the BitVector class.
@ Available
We know the block is fully available. This is a fixpoint.
static void addSaveRestoreRegs(MachineInstrBuilder &MIB, ArrayRef< CalleeSavedInfo > CSI, RegState Flags={})
uint64_t IntrinsicInst * II
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
BitVector & reset()
Reset all bits in the bitvector.
int find_first() const
Returns the index of the first set bit, -1 if none of the bits are set.
Describe properties that are true of each instruction in the target description file.
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Representation of each machine instruction.
A description of a memory reference used in the backend.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
Register isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
isLoadFromStackSlot - If the specified machine instruction is a direct load from a stack slot,...
bool expandPostRAPseudo(MachineInstr &MI) const override
static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount)
const MCInstrDesc & AddiuSpImm(int64_t Imm) const
void makeFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const
void BuildAddiuSpImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const
void loadRegFromStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, int64_t Offset, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
unsigned getOppositeBranchOpc(unsigned Opc) const override
GetOppositeBranchOpc - Return the inverse of the specified opcode, e.g.
std::optional< DestSourcePair > isCopyInstrImpl(const MachineInstr &MI) const override
If the specific machine instruction is a instruction that moves/copies value from one register to ano...
Register isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
isStoreToStackSlot - If the specified machine instruction is a direct store to a stack slot,...
static bool validSpImm8(int offset)
void restoreFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, Register DestReg, Register SrcReg, bool KillSrc, bool RenamableDest=false, bool RenamableSrc=false) const override
Mips16InstrInfo(const MipsSubtarget &STI)
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.
void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
Adjust SP by Amount bytes.
void storeRegToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, int64_t Offset, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
MachineMemOperand * GetMemOperand(MachineBasicBlock &MBB, int FI, MachineMemOperand::Flags Flags) const
MipsInstrInfo(const MipsSubtarget &STI, const MipsRegisterInfo &RI, unsigned UncondBrOpc)
LLVM_ABI void enterBasicBlockEnd(MachineBasicBlock &MBB)
Start tracking liveness from the end of basic block MBB.
LLVM_ABI void backward()
Update internal register state and move MBB iterator backwards.
LLVM_ABI BitVector getRegsAvailable(const TargetRegisterClass *RC)
Return all available registers in the register class in Mask.
Wrapper class representing virtual and physical registers.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
RegState
Flags to represent properties of register accesses.
@ Kill
The last use of a register.
@ Define
Register definition.
constexpr RegState getKillRegState(bool B)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
const MipsInstrInfo * createMips16InstrInfo(const MipsSubtarget &STI)
Create MipsInstrInfo objects.
MCRegisterClass TargetRegisterClass