30#define UNITS_PER_WORD 4
31#define MIN_FRAME_SIZE (8 * UNITS_PER_WORD)
38 STI(STI), TII(*STI.getInstrInfo()), TRI(STI.getRegisterInfo()) {}
53 if (MaxAlignment > 32)
54 FrameSize += MaxAlignment;
61 assert(&
MBB == &MF.
front() &&
"Shrink-wrapping not yet implemented");
74 if (STI.isWindowedABI()) {
76 if (StackSize <= 32760) {
101 if (MaxAlignment > 32) {
102 TII.loadImmediate(
MBB,
MBBI, &RegMisAlign, MaxAlignment - 1);
103 TII.loadImmediate(
MBB,
MBBI, &Reg, MaxAlignment);
133 nullptr,
MRI->getDwarfRegNum(
FP,
true), StackSize);
150 TII.adjustStackPtr(SP, -StackSize,
MBB,
MBBI);
166 for (
unsigned i = 0, e = CSI.size(); i < e; ++i) {
169 int FI = Info.getFrameIdx();
173 bool IsStoreInst =
false;
174 if (
MBBI->getOpcode() == TargetOpcode::COPY && Info.isSpilledToReg()) {
177 IsStoreInst = Info.getDstReg() == DstReg.
asMCReg() &&
178 Info.getReg() == Reg.asMCReg();
181 IsStoreInst = Reg.asMCReg() == Info.getReg() && StoreFI == FI;
184 "Unexpected callee-saved register store instruction");
191 for (
const auto &
I : CSI) {
196 nullptr,
MRI->getDwarfRegNum(Reg, 1),
Offset));
213 nullptr,
MRI->getDwarfRegNum(
FP,
true)));
219 if (StackSize != PrevStackSize) {
253 for (
unsigned i = 0, e = CSI.size(); i < e; ++i) {
257 int FI = Info.getFrameIdx();
261 bool IsRestoreInst =
false;
262 if (
I->getOpcode() == TargetOpcode::COPY && Info.isSpilledToReg()) {
263 Register Reg =
I->getOperand(0).getReg();
264 Register DstReg =
I->getOperand(1).getReg();
265 IsRestoreInst = Info.getDstReg() == DstReg.
asMCReg() &&
266 Info.getReg() == Reg.asMCReg();
268 Register Reg = TII.isLoadFromStackSlot(*
I, LoadFI);
269 IsRestoreInst = Info.getReg() == Reg.asMCReg() && LoadFI == FI;
272 "Unexpected callee-saved register restore instruction");
275 if (STI.isWindowedABI()) {
288 if (STI.isWindowedABI())
298 TII.adjustStackPtr(SP, StackSize,
MBB,
MBBI);
307 if (STI.isWindowedABI())
310 for (
unsigned i = 0, e = CSI.
size(); i != e; ++i) {
317 bool IsA0AndRetAddrIsTaken =
319 if (!IsA0AndRetAddrIsTaken)
323 bool IsKill = !IsA0AndRetAddrIsTaken;
325 TII.storeRegToStackSlot(EntryBlock,
MI, Reg, IsKill, CSI[i].getFrameIdx(),
335 if (STI.isWindowedABI())
345 int64_t Amount =
I->getOperand(0).getImm();
347 if (
I->getOpcode() == Xtensa::ADJCALLSTACKDOWN)
350 TII.adjustStackPtr(Xtensa::SP, Amount,
MBB,
I);
361 if (STI.isWindowedABI()) {
395 if (
MI.getNumExplicitDefs() != 1 || !
MI.getOperand(0).isReg())
398 return !Def.isEarlyClobber() && Xtensa::ARRegClass.contains(Def.getReg()) &&
399 !
MRI.isReserved(Def.getReg()) && !
MI.readsRegister(Def.getReg(),
TRI);
406 int64_t StackSize, int64_t FrameSize) {
408 int FI =
MI.getOperand(OpNo).getIndex();
411 int64_t Min, Max, Step;
416 Max = Min + FrameSize;
429 int64_t
Imm =
MI.getOperand(OpNo + 1).getImm();
430 auto CanEncode = [&](int64_t Start) {
438 return CanEncode(Min) && CanEncode(Max) && CanEncode(Min + Step);
456 if (
MI.isDebugInstr())
458 for (
unsigned I = 0,
E =
MI.getNumOperands();
I !=
E; ++
I) {
459 if (
MI.getOperand(
I).isFI() &&
475 unsigned ScavSlotsNum = 0;
487 ScavSlotsNum = std::max(ScavSlotsNum, 1u);
490 unsigned Size = TRI->getSpillSize(RC);
491 Align Alignment = TRI->getSpillAlign(RC);
492 for (
unsigned I = 0;
I < ScavSlotsNum;
I++) {
494 RS->addScavengingFrameIndex(FI);
496 if (IsLargeFunction &&
497 XtensaFI->getBranchRelaxationScratchFrameIndex() == -1)
498 XtensaFI->setBranchRelaxationScratchFrameIndex(FI);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Register const TargetRegisterInfo * TRI
Promote Memory to Register
MachineRegisterInfo & MRI
This file declares the machine register scavenger class.
static bool canUseDefAsScratchReg(const MachineInstr &MI, const MachineRegisterInfo &MRI, const TargetRegisterInfo *TRI)
static uint64_t getFrameSize(const MachineFunction &MF, uint64_t StackSize)
static bool canEncodeFrameOffset(const MachineInstr &MI, unsigned OpNo, int64_t StackSize, int64_t FrameSize)
static bool frameOffsetMayNeedScratchReg(const MachineFunction &MF, uint64_t Estimate)
static uint64_t getMaxStackSize(const MachineFunction &MF, uint64_t Estimate)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
BitVector & set()
Set all bits in the bitvector.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
const MCRegisterInfo * getRegisterInfo() const
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers and target specific virtual registers.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
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.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
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.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
uint8_t getStackID(int ObjectIdx) const
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.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
int getObjectIndexBegin() const
Return the minimum frame object index.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
unsigned addFrameInst(const MCCFIInstruction &Inst)
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.
MCContext & getContext() const
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
int64_t estimateFunctionSizeInBytes()
Return an estimate of the function's code size, taking into account block and function alignment.
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
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.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Wrapper class representing virtual and physical registers.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Information about stack frame layout on the target.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Align getTransientStackAlign() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
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)
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
bool hasFPImpl(const MachineFunction &MF) const override
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
void emitPrologue(MachineFunction &, MachineBasicBlock &) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
XtensaFrameLowering(const XtensaSubtarget &STI)
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...
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...
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool isSaveFrameRegister() const
bool isWindowedABI() const
bool isValidAddrOffsetForOpcode(unsigned Opcode, int64_t Offset)
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.
@ Kill
The last use of a register.
@ Define
Register definition.
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
MCRegisterClass TargetRegisterClass
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.