57 if (CFSize >= ((1 << 8) - 1) * 4 / 2)
86 unsigned Amount = TII.getFrameSize(Old);
95 if (Opc == ARM::ADJCALLSTACKDOWN || Opc == ARM::tADJCALLSTACKDOWN) {
98 assert(Opc == ARM::ADJCALLSTACKUP || Opc == ARM::tADJCALLSTACKUP);
120 assert(NumBytes >= ArgRegsSaveSize &&
121 "ArgRegsSaveSize is included in NumBytes");
133 NumBytes = (NumBytes + 3) & ~3;
138 unsigned GPRCS1Size = 0, GPRCS2Size = 0, DPRCSSize = 0;
139 int FramePtrSpillFI = 0;
141 if (ArgRegsSaveSize) {
142 emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -ArgRegsSaveSize,
144 CFAOffset -= ArgRegsSaveSize;
147 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
148 .addCFIIndex(CFIIndex)
153 if (NumBytes - ArgRegsSaveSize != 0) {
154 emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -(NumBytes - ArgRegsSaveSize),
156 CFAOffset -= NumBytes - ArgRegsSaveSize;
159 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
160 .addCFIIndex(CFIIndex)
166 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
167 unsigned Reg = CSI[i].getReg();
168 int FI = CSI[i].getFrameIdx();
185 FramePtrSpillFI = FI;
193 if (MBBI != MBB.
end() && MBBI->getOpcode() == ARM::tPUSH) {
198 unsigned DPRCSOffset = NumBytes - ArgRegsSaveSize - (GPRCS1Size + GPRCS2Size + DPRCSSize);
199 unsigned GPRCS2Offset = DPRCSOffset + DPRCSSize;
200 unsigned GPRCS1Offset = GPRCS2Offset + GPRCS2Size;
201 bool HasFP =
hasFP(MF);
208 NumBytes = DPRCSOffset;
210 int FramePtrOffsetInBlock = 0;
211 unsigned adjustedGPRCS1Size = GPRCS1Size;
212 if (GPRCS1Size > 0 && GPRCS2Size == 0 &&
214 FramePtrOffsetInBlock = NumBytes;
215 adjustedGPRCS1Size += NumBytes;
219 if (adjustedGPRCS1Size) {
220 CFAOffset -= adjustedGPRCS1Size;
223 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
224 .addCFIIndex(CFIIndex)
227 for (std::vector<CalleeSavedInfo>::const_iterator
I = CSI.begin(),
228 E = CSI.end();
I !=
E; ++
I) {
229 unsigned Reg =
I->getReg();
230 int FI =
I->getFrameIdx();
251 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
252 .addCFIIndex(CFIIndex)
260 FramePtrOffsetInBlock +=
264 .
addImm(FramePtrOffsetInBlock / 4)
267 if(FramePtrOffsetInBlock) {
268 CFAOffset += FramePtrOffsetInBlock;
271 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
272 .addCFIIndex(CFIIndex)
278 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
279 .addCFIIndex(CFIIndex)
295 while (MBBI != MBB.
end() && MBBI->getOpcode() == ARM::tMOVr)
297 if (MBBI != MBB.
end() && MBBI->getOpcode() == ARM::tPUSH) {
309 for (
auto &
I : CSI) {
310 unsigned Reg =
I.getReg();
311 int FI =
I.getFrameIdx();
320 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
321 .addCFIIndex(CFIIndex)
335 CFAOffset -= NumBytes;
338 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
339 .addCFIIndex(CFIIndex)
354 if (RegInfo->needsStackRealignment(MF))
362 BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), BasePtr)
383 }
else if (MI.
getOpcode() == ARM::tMOVr) {
386 return ((ARM::tGPRRegClass.
contains(Src) || Src == ARM::LR) &&
405 assert((
unsigned)NumBytes >= ArgRegsSaveSize &&
406 "ArgRegsSaveSize is included in NumBytes");
407 const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF);
408 unsigned FramePtr = RegInfo->getFrameRegister(MF);
411 if (NumBytes - ArgRegsSaveSize != 0)
412 emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, NumBytes - ArgRegsSaveSize);
415 if (MBBI != MBB.
begin()) {
436 "No scratch register to restore SP from FP!");
439 BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP)
443 BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), ARM::SP)
447 if (MBBI != MBB.
end() && MBBI->getOpcode() == ARM::tBX_RET &&
448 &MBB.
front() != &*MBBI && std::prev(MBBI)->getOpcode() == ARM::tPOP) {
457 if (needPopSpecialFixUp(MF)) {
458 bool Done = emitPopSpecialFixUp(MBB,
true);
460 assert(Done &&
"Emission of the special fixup failed!?");
465 if (!needPopSpecialFixUp(*MBB.
getParent()))
469 return emitPopSpecialFixUp(*TmpMBB,
false);
472 bool Thumb1FrameLowering::needPopSpecialFixUp(
const MachineFunction &MF)
const {
480 if (CSI.getReg() == ARM::LR)
503 bool CanRestoreDirectly =
STI.
hasV5TOps() && !ArgRegsSaveSize;
504 if (CanRestoreDirectly) {
505 if (MBBI != MBB.
end() && MBBI->getOpcode() != ARM::tB)
506 CanRestoreDirectly = (MBBI->getOpcode() == ARM::tBX_RET ||
507 MBBI->getOpcode() == ARM::tPOP_RET);
509 auto MBBI_prev = MBBI;
511 assert(MBBI_prev->getOpcode() == ARM::tPOP);
516 CanRestoreDirectly =
false;
520 if (CanRestoreDirectly) {
521 if (!DoIt || MBBI->getOpcode() == ARM::tPOP_RET)
524 BuildMI(MBB, MBBI, MBBI->getDebugLoc(), TII.
get(ARM::tPOP_RET))
527 for (
auto MO: MBBI->operands())
528 if (MO.isReg() && (MO.isImplicit() || MO.isDef()))
540 UsedRegs.addLiveOuts(MBB);
546 for (
unsigned i = 0; CSRegs[i]; ++i)
547 UsedRegs.addReg(CSRegs[i]);
550 if (MBBI != MBB.
end()) {
551 dl = MBBI->getDebugLoc();
552 auto InstUpToMBBI = MBB.
end();
553 while (InstUpToMBBI != MBBI)
556 UsedRegs.stepBackward(*--InstUpToMBBI);
562 unsigned TemporaryReg = 0;
565 assert(PopFriendly.
any() &&
"No allocatable pop-friendly register?!");
570 GPRsNoLRSP |= PopFriendly;
571 GPRsNoLRSP.
reset(ARM::LR);
572 GPRsNoLRSP.
reset(ARM::SP);
573 GPRsNoLRSP.
reset(ARM::PC);
574 for (
unsigned Register : GPRsNoLRSP.set_bits()) {
588 if (!DoIt && !PopReg && !TemporaryReg)
591 assert((PopReg || TemporaryReg) &&
"Cannot get LR");
594 assert(!PopReg &&
"Unnecessary MOV is about to be inserted");
602 if (MBBI != MBB.
end() && MBBI->getOpcode() == ARM::tPOP_RET) {
606 BuildMI(MBB, MBBI, MBBI->getDebugLoc(), TII.
get(ARM::tPOP))
609 for (
auto MO: MBBI->operands())
610 if (MO.isReg() && (MO.isImplicit() || MO.isDef()) &&
611 MO.getReg() != ARM::PC) {
613 if (!MO.isImplicit())
625 assert(PopReg &&
"Do not know how to get LR");
630 emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, ArgRegsSaveSize);
649 template <
unsigned SetSize>
650 static const unsigned *
653 const unsigned *OrderEnd) {
654 while (CurrentReg != OrderEnd && !EnabledRegs.
count(*CurrentReg))
662 const std::vector<CalleeSavedInfo> &CSI,
678 for (
unsigned i = CSI.size(); i != 0; --i) {
679 unsigned Reg = CSI[i-1].getReg();
681 if (ARM::tGPRRegClass.
contains(Reg) || Reg == ARM::LR) {
683 }
else if (ARM::hGPRRegClass.
contains(Reg) && Reg != ARM::LR) {
689 if ((ARM::tGPRRegClass.
contains(Reg) || Reg == ARM::LR) &&
696 for (
unsigned ArgReg : {ARM::R0, ARM::R1,
ARM::R2, ARM::R3})
702 if (!LoRegsToSave.
empty()) {
726 static const unsigned AllCopyRegs[] = {ARM::LR, ARM::R7,
ARM::R6,
729 static const unsigned AllHighRegs[] = {ARM::R11, ARM::R10, ARM::R9, ARM::R8};
731 const unsigned *AllCopyRegsEnd =
std::end(AllCopyRegs);
732 const unsigned *AllHighRegsEnd =
std::end(AllHighRegs);
736 std::begin(AllHighRegs), HiRegsToSave, AllHighRegsEnd);
738 while (HiRegToSave != AllHighRegsEnd) {
740 const unsigned *CopyReg =
748 while (HiRegToSave != AllHighRegsEnd && CopyReg != AllCopyRegsEnd) {
749 if (HiRegsToSave.
count(*HiRegToSave)) {
750 bool isKill = !MRI.
isLiveIn(*HiRegToSave);
761 RegsToPush.push_back(*CopyReg);
783 const std::vector<CalleeSavedInfo> &CSI,
803 unsigned Reg =
I.getReg();
805 if (ARM::tGPRRegClass.
contains(Reg) || Reg == ARM::LR) {
806 LoRegsToRestore.
insert(Reg);
807 }
else if (ARM::hGPRRegClass.
contains(Reg) && Reg != ARM::LR) {
808 HiRegsToRestore.
insert(Reg);
815 if ((ARM::tGPRRegClass.
contains(Reg)) &&
834 static const unsigned AllCopyRegs[] = {ARM::R0, ARM::R1,
ARM::R2, ARM::R3,
836 static const unsigned AllHighRegs[] = {ARM::R8, ARM::R9, ARM::R10, ARM::R11};
838 const unsigned *AllCopyRegsEnd =
std::end(AllCopyRegs);
839 const unsigned *AllHighRegsEnd =
std::end(AllHighRegs);
843 HiRegsToRestore, AllHighRegsEnd);
845 while (HiRegToRestore != AllHighRegsEnd) {
855 while (HiRegToRestore != AllHighRegsEnd && CopyReg != AllCopyRegsEnd) {
874 bool NeedsPop =
false;
875 for (
unsigned i = CSI.size(); i != 0; --i) {
876 unsigned Reg = CSI[i-1].getReg();
879 if (!(ARM::tGPRRegClass.
contains(Reg) || Reg == ARM::LR))
882 if (Reg == ARM::LR) {
891 if (MI->getOpcode() == ARM::TCRETURNdi ||
892 MI->getOpcode() == ARM::TCRETURNri) {
893 unsigned Opcode = MI->getOpcode() == ARM::TCRETURNdi
894 ? ARM::tBL : ARM::tBLXr;
897 BL.
add(MI->getOperand(0));
901 (*MIB).setDesc(TII.get(ARM::tPOP_RET));
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
unsigned succ_size() const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
const_iterator end(StringRef path)
Get end iterator over path.
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
MachineFunctionProperties & reset(Property P)
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
unsigned getBaseRegister() const
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
const MachineInstrBuilder & add(const MachineOperand &MO) const
bool any() const
any - Returns true if any bit is set.
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget, MachineFunction &MF, MachineInstr *MI, unsigned NumBytes)
Tries to add registers to the reglist of a given base-updating push/pop instruction to adjust the sta...
void setGPRCalleeSavedArea2Offset(unsigned o)
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
return AArch64::GPR64RegClass contains(Reg)
unsigned getDPRCalleeSavedAreaSize() const
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
const ARMBaseInstrInfo * getInstrInfo() const override
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
LLVM_NODISCARD bool empty() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
static void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const TargetInstrInfo &TII, const DebugLoc &dl, const ThumbRegisterInfo &MRI, int NumBytes, unsigned MIFlags=MachineInstr::NoFlags)
DILocation * get() const
Get the underlying DILocation.
const HexagonInstrInfo * TII
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
Thumb1FrameLowering(const ARMSubtarget &sti)
unsigned getFrameRegister(const MachineFunction &MF) const override
unsigned getArgRegsSaveSize() const
const MachineFunctionProperties & getProperties() const
Get the function properties.
Reg
All possible values of the reg field in the ModR/M byte.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
void setDPRCalleeSavedAreaOffset(unsigned o)
static const unsigned * findNextOrderedReg(const unsigned *CurrentReg, SmallSet< unsigned, SetSize > &EnabledRegs, const unsigned *OrderEnd)
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
void setFramePtrSpillOffset(unsigned o)
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
bool isLiveIn(unsigned Reg) const
int getOffsetAdjustment() const
Return the correction for frame offsets.
void setShouldRestoreSPFromFP(bool s)
BitVector getAllocatableSet(const MachineFunction &MF, const TargetRegisterClass *RC=nullptr) const
Returns a bitset indexed by register number indicating if a register is allocatable or not...
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
Return a null-terminated list of all of the callee-saved registers on this target.
unsigned getKillRegState(bool B)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getDefRegState(bool B)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool isCalleeSavedRegister(unsigned Reg, const MCPhysReg *CSRegs)
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
bool hasStackFrame() const
unsigned const MachineRegisterInfo * MRI
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
void setStackSize(uint64_t Size)
Set the size of the stack.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const MachineOperand & getOperand(unsigned i) const
bool splitFramePushPop(const MachineFunction &MF) const
Returns true if the frame setup is split into two separate pushes (first r0-r7,lr then r8-r11)...
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
unsigned getFramePtrSpillOffset() const
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void setGPRCalleeSavedArea2Size(unsigned s)
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required, we reserve argument space for call sites in the function immediately on entry to the current function.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
succ_iterator succ_begin()
void DeleteMachineInstr(MachineInstr *MI)
DeleteMachineInstr - Delete the given MachineInstr.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
void setGPRCalleeSavedArea1Size(unsigned s)
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
bool test(unsigned Idx) const
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
static bool isCSRestore(MachineInstr &MI, const MCPhysReg *CSRegs)
Promote Memory to Register
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
bool hasBasePointer(const MachineFunction &MF) const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
void setGPRCalleeSavedArea1Offset(unsigned o)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
const ARMBaseRegisterInfo * getRegisterInfo() const override
void emitThumbRegPlusImmediate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &dl, unsigned DestReg, unsigned BaseReg, int NumBytes, const TargetInstrInfo &TII, const ARMBaseRegisterInfo &MRI, unsigned MIFlags=0)
emitThumbRegPlusImmediate - Emits a series of instructions to materialize a destreg = basereg + immed...
void setDPRCalleeSavedAreaSize(unsigned s)
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getGPRCalleeSavedArea1Size() const
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static const unsigned FramePtr
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
MachineModuleInfo & getMMI() const
unsigned getGPRCalleeSavedArea2Size() const
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
This class contains meta information specific to a module.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly. ...
bool shouldRestoreSPFromFP() const