49 if (Mips::ACC64RegClass.
contains(Src))
50 return std::make_pair((
unsigned)Mips::PseudoMFHI,
51 (
unsigned)Mips::PseudoMFLO);
53 if (Mips::ACC64DSPRegClass.
contains(Src))
54 return std::make_pair((
unsigned)Mips::MFHI_DSP, (
unsigned)Mips::MFLO_DSP);
56 if (Mips::ACC128RegClass.
contains(Src))
57 return std::make_pair((
unsigned)Mips::PseudoMFHI64,
58 (
unsigned)Mips::PseudoMFLO64);
60 return std::make_pair(0, 0);
68 unsigned N = CSI.
size();
71 return Mips::AFGR64RegClass.contains(
I.getReg());
87 bool expandInstr(MachineBasicBlock &
MBB, Iter
I);
88 void expandLoadCCond(MachineBasicBlock &
MBB, Iter
I);
89 void expandStoreCCond(MachineBasicBlock &
MBB, Iter
I);
90 void expandLoadACC(MachineBasicBlock &
MBB, Iter
I,
unsigned RegSize);
91 void expandStoreACC(MachineBasicBlock &
MBB, Iter
I,
unsigned MFHiOpc,
92 unsigned MFLoOpc,
unsigned RegSize);
93 bool expandCopy(MachineBasicBlock &
MBB, Iter
I);
94 bool expandCopyACC(MachineBasicBlock &
MBB, Iter
I,
unsigned MFHiOpc,
96 bool expandBuildPairF64(MachineBasicBlock &
MBB,
98 bool expandExtractElementF64(MachineBasicBlock &
MBB,
102 MachineRegisterInfo &MRI;
103 const MipsSubtarget &Subtarget;
104 const MipsSEInstrInfo &TII;
105 const MipsRegisterInfo &RegInfo;
111 : MF(MF_),
MRI(MF.getRegInfo()),
116bool ExpandPseudo::expand() {
117 bool Expanded =
false;
119 for (
auto &
MBB : MF) {
121 Expanded |= expandInstr(
MBB,
I++);
127bool ExpandPseudo::expandInstr(MachineBasicBlock &
MBB, Iter
I) {
128 switch(
I->getOpcode()) {
129 case Mips::LOAD_CCOND_DSP:
130 expandLoadCCond(
MBB,
I);
132 case Mips::STORE_CCOND_DSP:
133 expandStoreCCond(
MBB,
I);
135 case Mips::LOAD_ACC64:
136 case Mips::LOAD_ACC64DSP:
137 expandLoadACC(
MBB,
I, 4);
139 case Mips::LOAD_ACC128:
140 expandLoadACC(
MBB,
I, 8);
142 case Mips::STORE_ACC64:
143 expandStoreACC(
MBB,
I, Mips::PseudoMFHI, Mips::PseudoMFLO, 4);
145 case Mips::STORE_ACC64DSP:
146 expandStoreACC(
MBB,
I, Mips::MFHI_DSP, Mips::MFLO_DSP, 4);
148 case Mips::STORE_ACC128:
149 expandStoreACC(
MBB,
I, Mips::PseudoMFHI64, Mips::PseudoMFLO64, 8);
151 case Mips::BuildPairF64:
152 if (expandBuildPairF64(
MBB,
I,
false))
155 case Mips::BuildPairF64_64:
156 if (expandBuildPairF64(
MBB,
I,
true))
159 case Mips::ExtractElementF64:
160 if (expandExtractElementF64(
MBB,
I,
false))
163 case Mips::ExtractElementF64_64:
164 if (expandExtractElementF64(
MBB,
I,
true))
167 case TargetOpcode::COPY:
168 if (!expandCopy(
MBB,
I))
179void ExpandPseudo::expandLoadCCond(MachineBasicBlock &
MBB, Iter
I) {
183 assert(
I->getOperand(0).isReg() &&
I->getOperand(1).isFI());
187 Register Dst =
I->getOperand(0).getReg(), FI =
I->getOperand(1).getIndex();
189 TII.loadRegFromStack(
MBB,
I, VR, FI, RC, 0);
191 .
addReg(VR, RegState::Kill);
194void ExpandPseudo::expandStoreCCond(MachineBasicBlock &
MBB, Iter
I) {
198 assert(
I->getOperand(0).isReg() &&
I->getOperand(1).isFI());
202 Register Src =
I->getOperand(0).getReg(), FI =
I->getOperand(1).getIndex();
206 TII.storeRegToStack(
MBB,
I, VR,
true, FI, RC, 0);
209void ExpandPseudo::expandLoadACC(MachineBasicBlock &
MBB, Iter
I,
216 assert(
I->getOperand(0).isReg() &&
I->getOperand(1).isFI());
221 Register Dst =
I->getOperand(0).getReg(), FI =
I->getOperand(1).getIndex();
222 Register Lo = RegInfo.getSubReg(Dst, Mips::sub_lo);
223 Register Hi = RegInfo.getSubReg(Dst, Mips::sub_hi);
225 const MCInstrDesc &
Desc =
TII.get(TargetOpcode::COPY);
227 TII.loadRegFromStack(
MBB,
I, VR0, FI, RC, 0);
233void ExpandPseudo::expandStoreACC(MachineBasicBlock &
MBB, Iter
I,
234 unsigned MFHiOpc,
unsigned MFLoOpc,
241 assert(
I->getOperand(0).isReg() &&
I->getOperand(1).isFI());
246 Register Src =
I->getOperand(0).getReg(), FI =
I->getOperand(1).getIndex();
251 TII.storeRegToStack(
MBB,
I, VR0,
true, FI, RC, 0);
256bool ExpandPseudo::expandCopy(MachineBasicBlock &
MBB, Iter
I) {
257 Register Src =
I->getOperand(1).getReg();
258 std::pair<unsigned, unsigned> Opcodes =
getMFHiLoOpc(Src);
263 return expandCopyACC(
MBB,
I, Opcodes.first, Opcodes.second);
266bool ExpandPseudo::expandCopyACC(MachineBasicBlock &
MBB, Iter
I,
267 unsigned MFHiOpc,
unsigned MFLoOpc) {
273 unsigned Dst =
I->getOperand(0).getReg(), Src =
I->getOperand(1).getReg();
275 unsigned VRegSize = RegInfo.getRegSizeInBits(*DstRC) / 16;
280 Register DstLo = RegInfo.getSubReg(Dst, Mips::sub_lo);
281 Register DstHi = RegInfo.getSubReg(Dst, Mips::sub_hi);
286 .
addReg(VR0, RegState::Kill);
289 .
addReg(VR1, RegState::Kill);
298bool ExpandPseudo::expandBuildPairF64(MachineBasicBlock &
MBB,
317 if (
I->getNumOperands() == 4 &&
I->getOperand(3).isReg()
318 &&
I->getOperand(3).getReg() ==
Mips::SP) {
319 Register DstReg =
I->getOperand(0).getReg();
320 Register LoReg =
I->getOperand(1).getReg();
321 Register HiReg =
I->getOperand(2).getReg();
325 FP64 ? &Mips::FGR64RegClass : &Mips::AFGR64RegClass;
329 int FI = MF.getInfo<MipsFunctionInfo>()->getMoveF64ViaSpillFI(MF, RC2);
332 TII.storeRegToStack(
MBB,
I, LoReg,
I->getOperand(1).isKill(), FI, RC, 0);
333 TII.storeRegToStack(
MBB,
I, HiReg,
I->getOperand(2).isKill(), FI, RC, 4);
334 TII.loadRegFromStack(
MBB,
I, DstReg, FI, RC2, 0);
346bool ExpandPseudo::expandExtractElementF64(MachineBasicBlock &
MBB,
350 const MachineOperand &Op2 =
I->getOperand(2);
353 Register DstReg =
I->getOperand(0).getReg();
354 BuildMI(
MBB,
I,
I->getDebugLoc(),
TII.get(Mips::IMPLICIT_DEF), DstReg);
374 if (
I->getNumOperands() == 4 &&
I->getOperand(3).isReg()
375 &&
I->getOperand(3).getReg() ==
Mips::SP) {
376 Register DstReg =
I->getOperand(0).getReg();
382 FP64 ? &Mips::FGR64RegClass : &Mips::AFGR64RegClass;
387 int FI = MF.getInfo<MipsFunctionInfo>()->getMoveF64ViaSpillFI(MF, RC);
388 TII.storeRegToStack(
MBB,
I, SrcReg, Op1.
isKill(), FI, RC, 0);
411 unsigned SP = ABI.GetStackPtr();
412 unsigned FP = ABI.GetFramePtr();
413 unsigned ZERO = ABI.GetNullPtr();
414 unsigned MOVE = ABI.GetGPRMoveOp();
415 unsigned ADDiu = ABI.GetPtrAddiuOp();
416 unsigned AND = ABI.GetPtrAndOp();
419 &Mips::GPR64RegClass : &Mips::GPR32RegClass;
430 TII.adjustStackPtr(SP, -StackSize,
MBB,
MBBI);
434 emitInterruptPrologueStub(MF,
MBB);
452 if (Mips::AFGR64RegClass.
contains(Reg)) {
453 MCRegister Reg0 = RegInfo.getSubReg(Reg, Mips::sub_lo);
454 MCRegister Reg1 = RegInfo.getSubReg(Reg, Mips::sub_hi);
461 }
else if (Mips::FGR64RegClass.
contains(Reg)) {
479 for (
int I = 0;
I < 4; ++
I) {
480 if (!
MBB.isLiveIn(ABI.GetEhDataReg(
I)))
481 MBB.addLiveIn(ABI.GetEhDataReg(
I));
482 TII.storeRegToStackSlot(
MBB,
MBBI, ABI.GetEhDataReg(
I),
false,
487 for (
int I = 0;
I < 4; ++
I) {
501 if (RegInfo.hasStackRealignment(MF)) {
506 "Function's alignment size requirement is not supported.");
514 unsigned BP =
STI.getABI().GetBasePtr();
528void MipsSEFrameLowering::emitInterruptPrologueStub(
541 "\"interrupt\" attribute is not supported on pre-MIPS32R2 or "
550 "static relocation model on MIPS at the present time.");
554 "O32 ABI on MIPS32R2+ at the present time.");
563 if (IntKind ==
"eic") {
565 MBB.addLiveIn(Mips::COP013);
578 MBB.addLiveIn(Mips::COP014);
587 MBB.addLiveIn(Mips::COP012);
597 unsigned InsPosition = 8;
598 unsigned InsSize = 0;
599 unsigned SrcReg = Mips::R0;
603 if (IntKind ==
"eic") {
608 InsSize = StringSwitch<unsigned>(IntKind)
618 assert(InsSize != 0 &&
"Unknown interrupt type!");
636 if (!
STI.useSoftFloat())
661 unsigned SP = ABI.GetStackPtr();
662 unsigned FP = ABI.GetFramePtr();
663 unsigned ZERO = ABI.GetNullPtr();
664 unsigned MOVE = ABI.GetGPRMoveOp();
679 ABI.ArePtrs64bit() ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
686 for (
int J = 0; J < 4; ++J) {
687 TII.loadRegFromStackSlot(
MBB,
I, ABI.GetEhDataReg(J),
693 emitInterruptEpilogueStub(MF,
MBB);
705void MipsSEFrameLowering::emitInterruptEpilogueStub(
738 FrameReg =
hasFP(MF) ? ABI.GetFramePtr() : ABI.GetStackPtr();
740 FrameReg =
hasBP(MF) ? ABI.GetBasePtr() : ABI.GetStackPtr();
762 if (!IsRAAndRetAddrIsTaken)
767 bool IsLOHI = (Reg == Mips::LO0 || Reg == Mips::LO0_64 ||
768 Reg == Mips::HI0 || Reg == Mips::HI0_64);
769 const Function &Func =
MBB.getParent()->getFunction();
770 if (IsLOHI && Func.hasFnAttribute(
"interrupt")) {
774 if (!
STI.getABI().ArePtrs64bit()) {
775 Op = (Reg == Mips::HI0) ? Mips::MFHI : Mips::MFLO;
778 Op = (Reg == Mips::HI0) ? Mips::MFHI64 : Mips::MFLO64;
786 bool IsKill = !IsRAAndRetAddrIsTaken;
788 TII.storeRegToStackSlot(
MBB,
MI, Reg, IsKill,
I.getFrameIdx(), RC,
822 unsigned FP = ABI.GetFramePtr();
823 unsigned BP = ABI.GetBasePtr();
844 if (ExpandPseudo(MF).
expand()) {
849 Mips::GPR64RegClass : Mips::GPR32RegClass;
851 TRI->getSpillAlign(RC));
852 RS->addScavengingFrameIndex(FI);
860 if (
isIntN(
STI.hasMSA() ? 10 : 16, MaxSPOffset) &&
865 ABI.ArePtrs64bit() ? Mips::GPR64RegClass : Mips::GPR32RegClass;
867 TRI->getSpillAlign(RC));
868 RS->addScavengingFrameIndex(FI);
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file implements the BitVector class.
@ ZERO
Special weight used for cases with exact zero probability.
static Expected< BitVector > expand(StringRef S, StringRef Original)
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static std::pair< unsigned, unsigned > getMFHiLoOpc(unsigned Src)
static unsigned getNumCSRInstrs(const MipsSubtarget &STI, ArrayRef< CalleeSavedInfo > CSI)
Return the number of instructions that save (or restore) the callee-saved registers in CSI.
static void setAliasRegs(MachineFunction &MF, BitVector &SavedRegs, unsigned Reg)
Mark Reg and all registers aliasing it in the bitset.
MachineRegisterInfo & MRI
This file declares the machine register scavenger class.
SI optimize exec mask operations pre RA
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
BitVector & set()
Set all bits in the bitvector.
Helper class for creating CFI instructions and inserting them into MIR.
void buildDefCFAOffset(int64_t Offset, MCSymbol *Label=nullptr) const
void buildDefCFARegister(MCRegister Reg) const
void buildOffset(MCRegister Reg, int64_t Offset) const
void setInsertPoint(MachineBasicBlock::iterator IP)
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
MCRegAliasIterator enumerates all registers aliasing Reg.
Wrapper class representing physical registers and target specific virtual registers.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
bool isReturnAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Align getMaxAlign() const
Return alignment of this function's frame.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment, TargetStackID::Value StackID=TargetStackID::Default)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
MipsFrameLowering(const MipsSubtarget &sti, Align Alignment)
bool hasBP(const MachineFunction &MF) const
uint64_t estimateStackSize(const MachineFunction &MF) const
const MipsSubtarget & STI
MipsFunctionInfo - This class is derived from MachineFunction private Mips target-specific informatio...
int getEhDataRegFI(unsigned Reg) const
int getISRRegFI(Register Reg) const
bool callsEhReturn() const
void createEhDataRegsFI(MachineFunction &MF)
void createISRRegFI(MachineFunction &MF)
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, Register VReg, unsigned SubReg=0, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const override
virtual void storeRegToStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, int64_t Offset, MachineInstr::MIFlag Flags=MachineInstr::NoFlags) const =0
virtual const TargetRegisterClass * intRegClass(unsigned Size) const =0
Return GPR register class.
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
MipsSEFrameLowering(const MipsSubtarget &STI)
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
const MipsInstrInfo * getInstrInfo() const override
Reloc::Model getRelocationModel() const
Wrapper class representing virtual and physical registers.
StackOffset holds a fixed and a scalable offset in bytes.
int64_t getFixed() const
Returns the fixed component of the stack.
Represent a constant reference to a string, i.e.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
constexpr MCPhysReg RA_64
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.
constexpr RegState getKillRegState(bool B)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const MipsFrameLowering * createMipsSEFrameLowering(const MipsSubtarget &ST)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
DWARFExpression::Operation Op
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
unsigned Log2(Align A)
Returns the log2 of the alignment.
@ End
Run the machine verifier once, at the end of the pipeline.
MCRegisterClass TargetRegisterClass
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.