135 using namespace llvm;
137 #define DEBUG_TYPE "frame-info" 140 cl::desc(
"enable use of redzone on AArch64"),
145 cl::desc(
"reverse the CSR restore sequence"),
148 STATISTIC(NumRedZoneFunctions,
"Number of functions using red zone");
165 if (
MI.isDebugInstr() ||
MI.isPseudo() ||
166 MI.getOpcode() == AArch64::ADDXri ||
167 MI.getOpcode() == AArch64::ADDSXri)
242 unsigned Opc = I->getOpcode();
243 bool IsDestroy = Opc == TII->getCallFrameDestroyOpcode();
244 uint64_t CalleePopAmount = IsDestroy ? I->getOperand(1).getImm() : 0;
250 int64_t Amount = I->getOperand(0).getImm();
251 Amount =
alignTo(Amount, Align);
258 if (CalleePopAmount == 0) {
269 assert(Amount > -0xffffff && Amount < 0xffffff &&
"call frame too large");
272 }
else if (CalleePopAmount != 0) {
275 assert(CalleePopAmount < 0xffffff &&
"call frame too large");
276 emitFrameOffset(MBB, I, DL, AArch64::SP, AArch64::SP, -CalleePopAmount,
296 for (
const auto &Info : CSI) {
297 unsigned Reg = Info.getReg();
303 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
304 .addCFIIndex(CFIIndex)
324 if (&MF->
front() == MBB)
333 const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(MF);
334 for (
unsigned i = 0; CSRegs[i]; ++i)
335 LiveRegs.
addReg(CSRegs[i]);
339 if (LiveRegs.
available(MRI, AArch64::X9))
342 for (
unsigned Reg : AArch64::GPR64RegClass) {
346 return AArch64::NoRegister;
357 if (!RegInfo->needsStackRealignment(*MF))
365 unsigned StackSizeInBytes) {
372 unsigned StackProbeSize = 4096;
377 return (StackSizeInBytes >= StackProbeSize) &&
381 bool AArch64FrameLowering::shouldCombineCSRLocalStackBump(
396 if (MFI.hasVarSizedObjects())
399 if (RegInfo->needsStackRealignment(MF))
419 while (MBBI->getOpcode() == AArch64::STRXpost ||
420 MBBI->getOpcode() == AArch64::LDRXpre) {
421 assert(MBBI->getOperand(0).getReg() != AArch64::SP);
426 bool NewIsUnscaled =
false;
427 switch (MBBI->getOpcode()) {
431 NewOpc = AArch64::STPXpre;
434 NewOpc = AArch64::STPDpre;
436 case AArch64::STRXui:
437 NewOpc = AArch64::STRXpre;
438 NewIsUnscaled =
true;
440 case AArch64::STRDui:
441 NewOpc = AArch64::STRDpre;
442 NewIsUnscaled =
true;
445 NewOpc = AArch64::LDPXpost;
448 NewOpc = AArch64::LDPDpost;
450 case AArch64::LDRXui:
451 NewOpc = AArch64::LDRXpost;
452 NewIsUnscaled =
true;
454 case AArch64::LDRDui:
455 NewOpc = AArch64::LDRDpost;
456 NewIsUnscaled =
true;
464 unsigned OpndIdx = 0;
465 for (
unsigned OpndEnd = MBBI->getNumOperands() - 1; OpndIdx < OpndEnd;
467 MIB.
add(MBBI->getOperand(OpndIdx));
469 assert(MBBI->getOperand(OpndIdx).getImm() == 0 &&
470 "Unexpected immediate offset in first/last callee-save save/restore " 472 assert(MBBI->getOperand(OpndIdx - 1).getReg() == AArch64::SP &&
473 "Unexpected base register in callee-save save/restore instruction!");
475 assert(CSStackSizeInc % 8 == 0);
476 int64_t CSStackSizeIncImm = CSStackSizeInc;
478 CSStackSizeIncImm /= 8;
479 MIB.
addImm(CSStackSizeIncImm);
482 MIB.
setMemRefs(MBBI->memoperands_begin(), MBBI->memoperands_end());
484 return std::prev(MBB.
erase(MBBI));
490 unsigned LocalStackSize) {
495 if (Opc == AArch64::STRXpost || Opc == AArch64::LDRXpre) {
501 assert((Opc == AArch64::STPXi || Opc == AArch64::STPDi ||
502 Opc == AArch64::STRXui || Opc == AArch64::STRDui ||
503 Opc == AArch64::LDPXi || Opc == AArch64::LDPDi ||
504 Opc == AArch64::LDRXui || Opc == AArch64::LDRDui) &&
505 "Unexpected callee-save save/restore opcode!");
509 "Unexpected base register in callee-save save/restore instruction!");
513 assert(LocalStackSize % 8 == 0);
514 OffsetOpnd.setImm(OffsetOpnd.getImm() + LocalStackSize / 8);
534 MBB.
splice(FirstSPPopI, &MBB, LastPopI);
560 bool HasFP =
hasFP(MF);
578 assert(!HasFP &&
"unexpected function without stack frame but with FP");
589 ++NumRedZoneFunctions;
591 emitFrameOffset(MBB, MBBI, DL, AArch64::SP, AArch64::SP, -NumBytes, TII,
599 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
600 .addCFIIndex(CFIIndex)
614 bool CombineSPBump = shouldCombineCSRLocalStackBump(MF, NumBytes);
616 emitFrameOffset(MBB, MBBI, DL, AArch64::SP, AArch64::SP, -NumBytes, TII,
619 }
else if (PrologueSaveSize != 0) {
622 NumBytes -= PrologueSaveSize;
624 assert(NumBytes >= 0 &&
"Negative stack allocation size!?");
646 emitFrameOffset(MBB, MBBI, DL, AArch64::FP, AArch64::SP, FPOffset, TII,
653 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::MOVi64imm), AArch64::X15)
662 .addExternalSymbol(
"__chkstk")
667 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::MOVaddrEXT))
673 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::BLR))
680 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SUBXrx64), AArch64::SP)
690 const bool NeedsRealignment = RegInfo->needsStackRealignment(MF);
691 unsigned scratchSPReg = AArch64::SP;
693 if (NeedsRealignment) {
695 assert(scratchSPReg != AArch64::NoRegister);
703 emitFrameOffset(MBB, MBBI, DL, scratchSPReg, AArch64::SP, -NumBytes, TII,
706 if (NeedsRealignment) {
710 assert(scratchSPReg != AArch64::SP);
720 | ((64 - NrBitsToZero) << 6)
721 | ((64 - NrBitsToZero - 1) << 0);
723 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::ANDXri), AArch64::SP)
737 if (RegInfo->hasBasePointer(MF)) {
738 TII->
copyPhysReg(MBB, MBBI, DL, RegInfo->getBaseRegister(), AArch64::SP,
742 if (needsFrameMoves) {
745 unsigned FramePtr = RegInfo->getFrameRegister(MF);
814 unsigned Reg = RegInfo->getDwarfRegNum(FramePtr,
true);
816 nullptr, Reg, 2 * StackGrowth - FixedObject));
817 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
818 .addCFIIndex(CFIIndex)
824 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
825 .addCFIIndex(CFIIndex)
842 bool IsTailCallReturn =
false;
843 if (MBB.
end() != MBBI) {
844 DL = MBBI->getDebugLoc();
845 unsigned RetOpcode = MBBI->getOpcode();
846 IsTailCallReturn = RetOpcode == AArch64::TCRETURNdi ||
847 RetOpcode == AArch64::TCRETURNri;
859 uint64_t ArgumentPopSize = 0;
860 if (IsTailCallReturn) {
866 ArgumentPopSize = StackAdjust.
getImm();
906 uint64_t AfterCSRPopSize = ArgumentPopSize;
908 bool CombineSPBump = shouldCombineCSRLocalStackBump(MF, NumBytes);
911 if (!CombineSPBump && PrologueSaveSize != 0) {
915 const MachineOperand &OffsetOp = Pop->getOperand(Pop->getNumOperands() - 1);
917 if (OffsetOp.getImm() == 0) {
925 AfterCSRPopSize += PrologueSaveSize;
934 while (LastPopI != Begin) {
939 }
else if (CombineSPBump)
946 NumBytes + AfterCSRPopSize,
TII,
951 NumBytes -= PrologueSaveSize;
952 assert(NumBytes >= 0 &&
"Negative stack allocation size!?");
958 if (RedZone && AfterCSRPopSize == 0)
961 bool NoCalleeSaveRestore = PrologueSaveSize == 0;
962 int StackRestoreBytes = RedZone ? 0 : NumBytes;
963 if (NoCalleeSaveRestore)
964 StackRestoreBytes += AfterCSRPopSize;
968 bool Done = NoCalleeSaveRestore || AfterCSRPopSize == 0;
991 emitFrameOffset(MBB, LastPopI, DL, AArch64::SP, AArch64::SP, NumBytes, TII,
997 if (AfterCSRPopSize) {
1002 while (FirstSPPopI != Begin) {
1003 auto Prev = std::prev(FirstSPPopI);
1004 if (Prev->getOpcode() != AArch64::LDRXpre ||
1005 Prev->getOperand(0).getReg() == AArch64::SP)
1023 unsigned &FrameReg)
const {
1028 int FI,
unsigned &FrameReg,
1029 bool PreferFP)
const {
1056 }
else if (isCSR && RegInfo->needsStackRealignment(MF)) {
1060 assert(
hasFP(MF) &&
"Re-aligned stack must have frame pointer");
1062 }
else if (
hasFP(MF) && !RegInfo->needsStackRealignment(MF)) {
1067 bool FPOffsetFits = FPOffset >= -256;
1068 PreferFP |= Offset > -FPOffset;
1075 if (FPOffsetFits && CanUseBP)
1082 }
else if (FPOffset >= 0) {
1089 if (FPOffsetFits && PreferFP)
1095 assert(((isFixed || isCSR) || !RegInfo->needsStackRealignment(MF) || !UseFP) &&
1096 "In the presence of dynamic stack pointer realignment, " 1097 "non-argument/CSR objects cannot be accessed through the frame pointer");
1109 "Can't use SP when we have var sized objects.");
1110 FrameReg = AArch64::SP;
1136 Attrs.hasAttrSomewhere(Attribute::SwiftError));
1141 struct RegPairInfo {
1142 unsigned Reg1 = AArch64::NoRegister;
1143 unsigned Reg2 = AArch64::NoRegister;
1148 RegPairInfo() =
default;
1150 bool isPaired()
const {
return Reg2 != AArch64::NoRegister; }
1158 bool &NeedShadowCallStackProlog) {
1166 unsigned Count = CSI.size();
1172 (Count & 1) == 0) &&
1173 "Odd number of callee-saved regs to spill!");
1176 for (
unsigned i = 0; i < Count; ++i) {
1178 RPI.Reg1 = CSI[i].getReg();
1181 AArch64::FPR64RegClass.contains(RPI.Reg1));
1182 RPI.IsGPR = AArch64::GPR64RegClass.contains(RPI.Reg1);
1185 if (i + 1 < Count) {
1186 unsigned NextReg = CSI[i + 1].getReg();
1187 if ((RPI.IsGPR && AArch64::GPR64RegClass.contains(NextReg)) ||
1188 (!RPI.IsGPR && AArch64::FPR64RegClass.contains(NextReg)))
1194 if ((RPI.Reg1 == AArch64::LR || RPI.Reg2 == AArch64::LR) &&
1198 NeedShadowCallStackProlog =
true;
1207 assert((!RPI.isPaired() ||
1208 (CSI[i].getFrameIdx() + 1 == CSI[i + 1].getFrameIdx())) &&
1209 "Out of order callee saved regs!");
1216 ((RPI.Reg1 == AArch64::LR && RPI.Reg2 == AArch64::FP) ||
1217 RPI.Reg1 + 1 == RPI.Reg2))) &&
1218 "Callee-save registers not saved as adjacent register pair!");
1220 RPI.FrameIdx = CSI[i].getFrameIdx();
1226 assert(MFI.getObjectAlignment(RPI.FrameIdx) <= 16);
1227 MFI.setObjectAlignment(RPI.FrameIdx, 16);
1230 Offset -= RPI.isPaired() ? 16 : 8;
1232 RPI.Offset = Offset / 8;
1233 assert((RPI.Offset >= -64 && RPI.Offset <= 63) &&
1234 "Offset out of bounds for LDP/STP immediate");
1244 const std::vector<CalleeSavedInfo> &CSI,
1251 bool NeedShadowCallStackProlog =
false;
1253 NeedShadowCallStackProlog);
1256 if (NeedShadowCallStackProlog) {
1258 BuildMI(MBB, MI, DL, TII.
get(AArch64::STRXpost))
1269 for (
auto RPII = RegPairs.
rbegin(), RPIE = RegPairs.
rend(); RPII != RPIE;
1271 RegPairInfo
RPI = *RPII;
1272 unsigned Reg1 = RPI.Reg1;
1273 unsigned Reg2 = RPI.Reg2;
1287 StrOpc = RPI.isPaired() ? AArch64::STPXi : AArch64::STRXui;
1289 StrOpc = RPI.isPaired() ? AArch64::STPDi : AArch64::STRDui;
1291 if (RPI.isPaired())
dbgs() <<
", " <<
printReg(Reg2, TRI);
1292 dbgs() <<
") -> fi#(" << RPI.FrameIdx;
1293 if (RPI.isPaired())
dbgs() <<
", " << RPI.FrameIdx + 1;
1299 if (RPI.isPaired()) {
1308 .addReg(AArch64::SP)
1320 std::vector<CalleeSavedInfo> &CSI,
1327 if (MI != MBB.
end())
1328 DL = MI->getDebugLoc();
1330 bool NeedShadowCallStackProlog =
false;
1332 NeedShadowCallStackProlog);
1334 auto EmitMI = [&](
const RegPairInfo &
RPI) {
1335 unsigned Reg1 =
RPI.Reg1;
1336 unsigned Reg2 =
RPI.Reg2;
1348 LdrOpc =
RPI.isPaired() ? AArch64::LDPXi : AArch64::LDRXui;
1350 LdrOpc =
RPI.isPaired() ? AArch64::LDPDi : AArch64::LDRDui;
1353 dbgs() <<
") -> fi#(" <<
RPI.FrameIdx;
1354 if (
RPI.isPaired())
dbgs() <<
", " <<
RPI.FrameIdx + 1;
1358 if (
RPI.isPaired()) {
1374 for (
const RegPairInfo &
RPI :
reverse(RegPairs))
1377 for (
const RegPairInfo &
RPI : RegPairs)
1380 if (NeedShadowCallStackProlog) {
1382 BuildMI(MBB, MI, DL, TII.
get(AArch64::LDRXpre))
1405 unsigned UnspilledCSGPR = AArch64::NoRegister;
1406 unsigned UnspilledCSGPRPaired = AArch64::NoRegister;
1415 unsigned SpillEstimate = SavedRegs.
count();
1416 for (
unsigned i = 0; CSRegs[i]; ++i) {
1417 unsigned Reg = CSRegs[i];
1418 unsigned PairedReg = CSRegs[i ^ 1];
1419 if (Reg == BasePointerReg)
1429 SavedRegs.
set(AArch64::FP);
1430 SavedRegs.
set(AArch64::LR);
1433 unsigned ExtraCSSpill = 0;
1435 for (
unsigned i = 0; CSRegs[i]; ++i) {
1436 const unsigned Reg = CSRegs[i];
1439 if (Reg == BasePointerReg)
1442 bool RegUsed = SavedRegs.
test(Reg);
1443 unsigned PairedReg = CSRegs[i ^ 1];
1445 if (AArch64::GPR64RegClass.
contains(Reg) &&
1447 UnspilledCSGPR =
Reg;
1448 UnspilledCSGPRPaired = PairedReg;
1457 SavedRegs.
set(PairedReg);
1458 if (AArch64::GPR64RegClass.
contains(PairedReg) &&
1460 ExtraCSSpill = PairedReg;
1471 unsigned NumRegsSpilled = SavedRegs.
count();
1472 bool CanEliminateFrame = NumRegsSpilled == 0;
1477 LLVM_DEBUG(
dbgs() <<
"Estimated stack frame size: " << CFSize <<
" bytes.\n");
1479 bool BigStack = (CFSize > EstimatedStackSizeLimit);
1490 if (!ExtraCSSpill && UnspilledCSGPR != AArch64::NoRegister) {
1492 <<
" to get a scratch register.\n");
1493 SavedRegs.
set(UnspilledCSGPR);
1498 SavedRegs.
set(UnspilledCSGPRPaired);
1499 ExtraCSSpill = UnspilledCSGPRPaired;
1500 NumRegsSpilled = SavedRegs.
count();
1512 LLVM_DEBUG(
dbgs() <<
"No available CS registers, allocated fi#" << FI
1513 <<
" as the emergency spill slot.\n");
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
static cl::opt< bool > ReverseCSRRestoreSeq("reverse-csr-restore-seq", cl::desc("reverse the CSR restore sequence"), cl::init(false), cl::Hidden)
void push_back(const T &Elt)
const MachineInstrBuilder & add(const MachineOperand &MO) const
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
bool hasDebugInfo() const
Returns true if valid debug info is present.
bool available(const MachineRegisterInfo &MRI, unsigned Reg) const
Returns true if register Reg and no aliasing register is in the set.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
unsigned getLocalStackSize() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
static void computeCalleeSaveRegisterPairs(MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI, SmallVectorImpl< RegPairInfo > &RegPairs, bool &NeedShadowCallStackProlog)
bool cannotEliminateFrame(const MachineFunction &MF) const
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
unsigned getReg() const
getReg - Returns the register number.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
bool test(unsigned Idx) const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
MachineModuleInfo & getMMI() const
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 canUseRedZone(const MachineFunction &MF) const
Can this function use the red zone for local allocations.
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
bool isCallingConvWin64(CallingConv::ID CC) const
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
return AArch64::GPR64RegClass contains(Reg)
static unsigned findScratchNonCalleeSaveRegister(MachineBasicBlock *MBB)
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool supportSwiftError() const override
Return true if the target supports swifterror attribute.
unsigned getFrameRegister(const MachineFunction &MF) const override
static unsigned getPrologueDeath(MachineFunction &MF, unsigned Reg)
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
bool isStackRealigned() const
const HexagonInstrInfo * TII
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
static MachineBasicBlock::iterator convertCalleeSaveRestoreToSPPrePostIncDec(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const TargetInstrInfo *TII, int CSStackSizeInc)
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.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
void setHasRedZone(bool s)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
getFrameIndexReference - Provide a base+offset reference to an FI slot for debug info.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
This file contains the simple types necessary to represent the attributes associated with functions a...
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 ...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
bool isTargetMachO() const
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
bool isX18Reserved() const
static unsigned estimateRSStackSizeLimit(MachineFunction &MF)
Look at each instruction that references stack frames and return the stack size limit beyond which so...
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
unsigned getArgumentStackToRestore() const
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
int isAArch64FrameOffsetLegal(const MachineInstr &MI, int &Offset, bool *OutUseUnscaledOp=nullptr, unsigned *OutUnscaledOp=nullptr, int *EmittableOffset=nullptr)
Check if the Offset is a valid frame offset for MI.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
virtual void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, bool KillSrc) const
Emit instructions to copy a pair of physical registers.
const AArch64RegisterInfo * getRegisterInfo() const override
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
const MCContext & getContext() const
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
AttributeList getAttributes() const
Return the attribute list for this Function.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
virtual const TargetInstrInfo * getInstrInfo() const
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
unsigned getKillRegState(bool B)
void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, int Offset, const TargetInstrInfo *TII, MachineInstr::MIFlag=MachineInstr::NoFlags, bool SetNZCV=false)
emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg plus Offset.
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.
bool isTargetWindows() const
unsigned getDefRegState(bool B)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
const AArch64TargetLowering * getTargetLowering() const override
initializer< Ty > init(const Ty &Val)
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
unsigned getCalleeSavedStackSize() const
This file declares the machine register scavenger class.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
unsigned const MachineRegisterInfo * MRI
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
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...
void setLocalStackSize(unsigned Size)
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.
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
int resolveFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg, bool PreferFP=false) const
void addLiveIns(const MachineBasicBlock &MBB)
Adds all live-in registers of basic block MBB.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions...
unsigned getVarArgsGPRSize() const
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
void setCalleeSaveStackHasFreeSpace(bool s)
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
void setHasStackFrame(bool s)
static cl::opt< bool > EnableRedZone("aarch64-redzone", cl::desc("enable use of redzone on AArch64"), cl::init(false), cl::Hidden)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
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.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) const
The memory access writes data.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
size_type count() const
count - Returns the number of bits which are set.
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
void addScavengingFrameIndex(int FI)
Add a scavenging frame index.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
unsigned estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
void setStackRealigned(bool s)
static const unsigned DefaultSafeSPDisplacement
This is the biggest offset to the stack pointer we can encode in aarch64 instructions (without using ...
Information about stack frame layout on the target.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
bool hasCalleeSaveStackFreeSpace() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
bool enableStackSlotScavenging(const MachineFunction &MF) const override
Returns true if the stack slot holes in the fixed and callee-save stack area should be used when allo...
CodeModel::Model getCodeModel() const
Returns the code model.
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
static bool windowsRequiresStackProbe(MachineFunction &MF, unsigned StackSizeInBytes)
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
TargetSubtargetInfo - Generic base class for all target subtargets.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
bool isReservedReg(const MachineFunction &MF, unsigned Reg) const
bool isLiveIn(unsigned Reg) const
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static void adaptForLdStOpt(MachineBasicBlock &MBB, MachineBasicBlock::iterator FirstSPPopI, MachineBasicBlock::iterator LastPopI)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
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...
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
StringRef getValueAsString() const
Return the attribute's value as a string.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
virtual const TargetFrameLowering * getFrameLowering() const
static void fixupCalleeSaveRestoreStackOffset(MachineInstr &MI, unsigned LocalStackSize)
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...
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...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
static bool produceCompactUnwindFrame(MachineFunction &MF)
reverse_iterator rbegin()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasBasePointer(const MachineFunction &MF) const
iterator_range< const_set_bits_iterator > set_bits() const
bool needsStackRealignment(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
const AArch64InstrInfo * getInstrInfo() const override
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
static const unsigned FramePtr
bool isMaxCallFrameSizeComputed() const
bool hasStackFrame() const
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
const MachineInstrBuilder & setMemRefs(MachineInstr::mmo_iterator b, MachineInstr::mmo_iterator e) const
const MachineOperand & getOperand(unsigned i) const
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
unsigned getBaseRegister() const
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
void setCalleeSavedStackSize(unsigned Size)
This class contains meta information specific to a module.
bool hasCalls() const
Return true if the current function has any function calls.
void addReg(unsigned Reg)
Adds a physical register and all its sub-registers to the set.