27#define DEBUG_TYPE "sparc-frame-lowering"
41 unsigned ADDri)
const {
46 if (NumBytes >= -4096 && NumBytes < 4096) {
84 assert(&MF.
front() == &
MBB &&
"Shrink-wrapping not yet supported");
92 unsigned SAVEri = SP::SAVEri;
93 unsigned SAVErr = SP::SAVErr;
131 emitSPAdjustment(MF,
MBB,
MBBI,
DebugLoc(), -NumBytes, SAVErr, SAVEri);
150 int Size =
MI.getOperand(0).getImm();
151 if (
MI.getOpcode() == SP::ADJCALLSTACKDOWN)
168 assert((
MBBI->getOpcode() == SP::RETL ||
MBBI->getOpcode() == SP::TAIL_CALL ||
169 MBBI->getOpcode() == SP::TAIL_CALLri) &&
170 "Can only put epilog before 'retl' or 'tail_call' instruction!");
180 emitSPAdjustment(MF,
MBB,
MBBI, dl, NumBytes, SP::ADDrr, SP::ADDri);
183 if (
MBBI->getOpcode() == SP::TAIL_CALL) {
184 MBB.addLiveIn(SP::O7);
215 bool isFixed = MFI.isFixedObjectIndex(FI);
228 }
else if (isFixed) {
240 FrameReg = RegInfo->getFrameRegister(MF);
250 for (
unsigned reg = SP::I0; reg <= SP::I7; ++reg)
251 if (
MRI->isPhysRegUsed(reg))
254 for (
unsigned reg = SP::L0; reg <= SP::L7; ++reg)
255 if (
MRI->isPhysRegUsed(reg))
266 SparcMachineFunctionInfo *SMFI = MF.
getInfo<SparcMachineFunctionInfo>();
276void SparcFrameLowering::remapRegsForLeafProc(
MachineFunction &MF)
const {
281 for (
unsigned reg = SP::I0; reg <= SP::I7; ++reg) {
285 unsigned mapped_reg = reg - SP::I0 + SP::O0;
295 if ((reg - SP::I0) % 2 == 0) {
296 unsigned preg = (reg - SP::I0) / 2 + SP::I0_I1;
297 unsigned mapped_preg = preg - SP::I0_I1 + SP::O0_O1;
303 for (MachineBasicBlock &
MBB : MF) {
304 for (
unsigned reg = SP::I0_I1; reg <= SP::I6_I7; ++reg) {
310 for (
unsigned reg = SP::I0; reg <= SP::I7; ++reg) {
316 for (MCRegister
Reg : UntrackedLiveIns)
320 for (MCRegister
Reg : UntrackedLiveIns)
324#ifdef EXPENSIVE_CHECKS
325 MF.verify(0,
"After LeafProc Remapping");
333 for (
auto &
MI :
MBB) {
335 uint64_t Multiplier =
MI.hasDelaySlot() ? 2 : 1;
336 FuncSize += (
TII->getInstSizeInBytes(
MI) * Multiplier);
352 if (!Subtarget.
getCLOpts().disable_sparc_leaf_proc && isLeafProc(MF)) {
355 remapRegsForLeafProc(MF);
363 STI.is64Bit() ? SP::I64RegsRegClass : SP::IntRegsRegClass;
372 RS->addScavengingFrameIndex(FI);
376 <<
") as the emergency spill slot.\n");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
static uint64_t estimateFunctionSizeInBytes(const LoongArchInstrInfo *TII, const MachineFunction &MF)
MachineRegisterInfo & MRI
This file declares the machine register scavenger class.
static bool verifyLeafProcRegUse(MachineRegisterInfo *MRI)
static bool is64Bit(const char *name)
Helper class for creating CFI instructions and inserting them into MIR.
void buildDefCFAOffset(int64_t Offset, MCSymbol *Label=nullptr) const
void buildWindowSave() const
void buildRegister(MCRegister Reg1, MCRegister Reg2) const
void buildDefCFARegister(MCRegister Reg) const
LLVM_ABI void removeLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
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 hasCalls() const
Return true if the current function has any function calls.
bool isFrameAddressTaken() 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.
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...
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
void setStackSize(uint64_t Size)
Set the size of the stack.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool hasInlineAsm() const
Returns true if the function contains any inline assembly.
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool disableFramePointerElim() const
Returns true if frame pointer elimination should be disabled for this function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
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.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI void clearKillFlags(Register Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
LLVM_ABI bool isPhysRegUsed(MCRegister PhysReg, bool SkipRegMaskTest=false) const
Return true if the specified register is modified or read in this function.
Wrapper class representing virtual and physical registers.
void push_back(const T &Elt)
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
SparcFrameLowering(const SparcSubtarget &ST)
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool hasFPImpl(const MachineFunction &MF) const override
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...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
void setLargeProc(bool rhs)
void setBranchRelaxationSpillFrameIndex(int Index)
int getBranchRelaxationSpillFrameIndex()
void setLeafProc(bool rhs)
const SparcRegisterInfo * getRegisterInfo() const override
int64_t getStackPointerBias() const
The 64-bit ABI uses biased stack and frame pointers, so the stack frame of the current function is th...
int getAdjustedFrameSize(int stackSize) const
Given a actual stack size as determined by FrameInfo, this function returns adjusted framesize which ...
const SparcOptions & getCLOpts() const
StackOffset holds a fixed and a scalable offset in bytes.
int64_t getFixed() const
Returns the fixed component of the stack.
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...
TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
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.
static unsigned HI22(int64_t imm)
static unsigned HIX22(int64_t imm)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
static unsigned LOX10(int64_t imm)
static unsigned LO10(int64_t imm)
MCRegisterClass TargetRegisterClass
This struct is a compact representation of a valid (non-zero power of two) alignment.