160 using namespace llvm;
162 #define DEBUG_TYPE "frame-info" 165 cl::desc(
"enable use of redzone on AArch64"),
170 cl::desc(
"reverse the CSR restore sequence"),
173 STATISTIC(NumRedZoneFunctions,
"Number of functions using red zone");
190 if (
MI.isDebugInstr() ||
MI.isPseudo() ||
191 MI.getOpcode() == AArch64::ADDXri ||
192 MI.getOpcode() == AArch64::ADDSXri)
284 unsigned Opc = I->getOpcode();
285 bool IsDestroy = Opc == TII->getCallFrameDestroyOpcode();
286 uint64_t CalleePopAmount = IsDestroy ? I->getOperand(1).getImm() : 0;
291 int64_t Amount = I->getOperand(0).getImm();
292 Amount =
alignTo(Amount, Align);
299 if (CalleePopAmount == 0) {
310 assert(Amount > -0xffffff && Amount < 0xffffff &&
"call frame too large");
314 }
else if (CalleePopAmount != 0) {
317 assert(CalleePopAmount < 0xffffff &&
"call frame too large");
319 {-(int64_t)CalleePopAmount,
MVT::i8}, TII);
340 assert(Scope.
equals(
"non-leaf") &&
"Expected all, none or non-leaf");
343 if (
Info.getReg() == AArch64::LR)
363 for (
const auto &
Info : CSI) {
370 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
371 .addCFIIndex(CFIIndex)
391 if (&MF->
front() == MBB)
401 for (
unsigned i = 0; CSRegs[i]; ++i)
402 LiveRegs.
addReg(CSRegs[i]);
406 if (LiveRegs.
available(MRI, AArch64::X9))
409 for (
unsigned Reg : AArch64::GPR64RegClass) {
413 return AArch64::NoRegister;
424 if (!RegInfo->needsStackRealignment(*MF))
432 uint64_t StackSizeInBytes) {
439 unsigned StackProbeSize = 4096;
444 return (StackSizeInBytes >= StackProbeSize) &&
448 bool AArch64FrameLowering::shouldCombineCSRLocalStackBump(
463 if (MFI.hasVarSizedObjects())
466 if (RegInfo->needsStackRealignment(MF))
488 unsigned Opc = MBBI->getOpcode();
492 unsigned ImmIdx = MBBI->getNumOperands() - 1;
493 int Imm = MBBI->getOperand(ImmIdx).getImm();
501 case AArch64::LDPDpost:
504 case AArch64::STPDpre: {
505 unsigned Reg0 = RegInfo->getSEHRegNum(MBBI->getOperand(1).getReg());
506 unsigned Reg1 = RegInfo->getSEHRegNum(MBBI->getOperand(2).getReg());
507 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveFRegP_X))
514 case AArch64::LDPXpost:
517 case AArch64::STPXpre: {
518 Register Reg0 = MBBI->getOperand(1).getReg();
519 Register Reg1 = MBBI->getOperand(2).getReg();
520 if (Reg0 == AArch64::FP && Reg1 == AArch64::LR)
521 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveFPLR_X))
525 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveRegP_X))
526 .addImm(RegInfo->getSEHRegNum(Reg0))
527 .addImm(RegInfo->getSEHRegNum(Reg1))
532 case AArch64::LDRDpost:
535 case AArch64::STRDpre: {
536 unsigned Reg = RegInfo->getSEHRegNum(MBBI->getOperand(1).getReg());
537 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveFReg_X))
543 case AArch64::LDRXpost:
546 case AArch64::STRXpre: {
547 unsigned Reg = RegInfo->getSEHRegNum(MBBI->getOperand(1).getReg());
548 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveReg_X))
555 case AArch64::LDPDi: {
556 unsigned Reg0 = RegInfo->getSEHRegNum(MBBI->getOperand(0).getReg());
557 unsigned Reg1 = RegInfo->getSEHRegNum(MBBI->getOperand(1).getReg());
558 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveFRegP))
566 case AArch64::LDPXi: {
567 Register Reg0 = MBBI->getOperand(0).getReg();
568 Register Reg1 = MBBI->getOperand(1).getReg();
569 if (Reg0 == AArch64::FP && Reg1 == AArch64::LR)
570 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveFPLR))
574 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveRegP))
575 .addImm(RegInfo->getSEHRegNum(Reg0))
576 .addImm(RegInfo->getSEHRegNum(Reg1))
581 case AArch64::STRXui:
582 case AArch64::LDRXui: {
583 int Reg = RegInfo->getSEHRegNum(MBBI->getOperand(0).getReg());
584 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveReg))
590 case AArch64::STRDui:
591 case AArch64::LDRDui: {
592 unsigned Reg = RegInfo->getSEHRegNum(MBBI->getOperand(0).getReg());
593 MIB =
BuildMI(MF, DL, TII.
get(AArch64::SEH_SaveFReg))
606 unsigned LocalStackSize) {
608 unsigned ImmIdx = MBBI->getNumOperands() - 1;
609 switch (MBBI->getOpcode()) {
612 case AArch64::SEH_SaveFPLR:
613 case AArch64::SEH_SaveRegP:
614 case AArch64::SEH_SaveReg:
615 case AArch64::SEH_SaveFRegP:
616 case AArch64::SEH_SaveFReg:
617 ImmOpnd = &MBBI->getOperand(ImmIdx);
630 bool NeedsWinCFI,
bool *HasWinCFI,
bool InProlog =
true) {
633 while (MBBI->getOpcode() == AArch64::STRXpost ||
634 MBBI->getOpcode() == AArch64::LDRXpre ||
635 MBBI->getOpcode() == AArch64::CFI_INSTRUCTION) {
636 if (MBBI->getOpcode() != AArch64::CFI_INSTRUCTION)
637 assert(MBBI->getOperand(0).getReg() != AArch64::SP);
642 switch (MBBI->getOpcode()) {
646 NewOpc = AArch64::STPXpre;
650 NewOpc = AArch64::STPDpre;
654 NewOpc = AArch64::STPQpre;
657 case AArch64::STRXui:
658 NewOpc = AArch64::STRXpre;
660 case AArch64::STRDui:
661 NewOpc = AArch64::STRDpre;
663 case AArch64::STRQui:
664 NewOpc = AArch64::STRQpre;
667 NewOpc = AArch64::LDPXpost;
671 NewOpc = AArch64::LDPDpost;
675 NewOpc = AArch64::LDPQpost;
678 case AArch64::LDRXui:
679 NewOpc = AArch64::LDRXpost;
681 case AArch64::LDRDui:
682 NewOpc = AArch64::LDRDpost;
684 case AArch64::LDRQui:
685 NewOpc = AArch64::LDRQpost;
690 auto SEH = std::next(MBBI);
692 SEH->eraseFromParent();
699 unsigned OpndIdx = 0;
700 for (
unsigned OpndEnd = MBBI->getNumOperands() - 1; OpndIdx < OpndEnd;
702 MIB.
add(MBBI->getOperand(OpndIdx));
704 assert(MBBI->getOperand(OpndIdx).getImm() == 0 &&
705 "Unexpected immediate offset in first/last callee-save save/restore " 707 assert(MBBI->getOperand(OpndIdx - 1).getReg() == AArch64::SP &&
708 "Unexpected base register in callee-save save/restore instruction!");
709 assert(CSStackSizeInc % Scale == 0);
710 MIB.
addImm(CSStackSizeInc / Scale);
722 return std::prev(MBB.
erase(MBBI));
728 uint64_t LocalStackSize,
738 if (Opc == AArch64::STRXpost || Opc == AArch64::LDRXpre ||
739 Opc == AArch64::CFI_INSTRUCTION) {
740 if (Opc != AArch64::CFI_INSTRUCTION)
748 case AArch64::STRXui:
750 case AArch64::STRDui:
752 case AArch64::LDRXui:
754 case AArch64::LDRDui:
758 case AArch64::STRQui:
760 case AArch64::LDRQui:
769 "Unexpected base register in callee-save save/restore instruction!");
773 assert(LocalStackSize % Scale == 0);
774 OffsetOpnd.setImm(OffsetOpnd.getImm() + LocalStackSize / Scale);
781 "Expecting a SEH instruction");
803 MBB.
splice(FirstSPPopI, &MBB, LastPopI);
845 switch (I->getOpcode()) {
848 case AArch64::STR_ZXI:
849 case AArch64::STR_PXI:
850 case AArch64::LDR_ZXI:
851 case AArch64::LDR_PXI:
867 bool needsFrameMoves =
869 bool HasFP =
hasFP(MF);
871 bool HasWinCFI =
false;
887 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::PACIASP))
890 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::EMITBKEY))
892 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::PACIBSP))
898 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
899 .addCFIIndex(CFIIndex)
923 assert(!HasFP &&
"unexpected function without stack frame but with FP");
925 "unexpected function without stack frame but with SVE objects");
934 ++NumRedZoneFunctions;
938 false, NeedsWinCFI, &HasWinCFI);
939 if (!NeedsWinCFI && needsFrameMoves) {
945 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
946 .addCFIIndex(CFIIndex)
953 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_PrologEnd))
964 unsigned FixedObject = (IsWin64 && !IsFunclet) ?
970 bool CombineSPBump = shouldCombineCSRLocalStackBump(MF, NumBytes);
972 assert(!SVEStackSize &&
"Cannot combine SP bump with SVE");
975 NeedsWinCFI, &HasWinCFI);
977 }
else if (PrologueSaveSize != 0) {
979 MBB, MBBI, DL, TII, -PrologueSaveSize, NeedsWinCFI, &HasWinCFI);
980 NumBytes -= PrologueSaveSize;
982 assert(NumBytes >= 0 &&
"Negative stack allocation size!?");
992 NeedsWinCFI, &HasWinCFI);
1002 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_PrologEnd))
1012 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::COPY), AArch64::FP)
1034 NeedsWinCFI, &HasWinCFI);
1038 uint64_t NumWords = NumBytes >> 4;
1046 if (NumBytes >= (1 << 28))
1048 "unwinding purposes");
1050 uint32_t LowNumWords = NumWords & 0xFFFF;
1051 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::MOVZXi), AArch64::X15)
1052 .addImm(LowNumWords)
1055 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_Nop))
1057 if ((NumWords & 0xFFFF0000) != 0) {
1058 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::MOVKXi), AArch64::X15)
1059 .addReg(AArch64::X15)
1060 .
addImm((NumWords & 0xFFFF0000) >> 16)
1063 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_Nop))
1067 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::MOVi64imm), AArch64::X15)
1078 .addExternalSymbol(
"__chkstk")
1086 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_Nop))
1091 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::MOVaddrEXT))
1098 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_Nop))
1102 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::BLR))
1111 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_Nop))
1117 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SUBXrx64), AArch64::SP)
1124 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_StackAlloc))
1131 StackOffset AllocateBefore = SVEStackSize, AllocateAfter = {};
1138 CalleeSavesBegin = MBBI;
1142 CalleeSavesEnd = MBBI;
1144 int64_t OffsetToFirstCalleeSaveFromSP =
1148 AllocateBefore -= OffsetToCalleeSavesFromSP;
1149 AllocateAfter = SVEStackSize - AllocateBefore;
1154 -AllocateBefore, TII,
1159 -AllocateAfter, TII,
1164 const bool NeedsRealignment = RegInfo->needsStackRealignment(MF);
1165 unsigned scratchSPReg = AArch64::SP;
1167 if (NeedsRealignment) {
1169 assert(scratchSPReg != AArch64::NoRegister);
1179 false, NeedsWinCFI, &HasWinCFI);
1181 if (NeedsRealignment) {
1184 assert(NrBitsToZero > 1);
1185 assert(scratchSPReg != AArch64::SP);
1194 uint32_t andMaskEncoded = (1 << 12)
1195 | ((64 - NrBitsToZero) << 6)
1196 | ((64 - NrBitsToZero - 1) << 0);
1198 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::ANDXri), AArch64::SP)
1204 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_StackAlloc))
1205 .addImm(NumBytes & andMaskEncoded)
1218 if (RegInfo->hasBasePointer(MF)) {
1219 TII->
copyPhysReg(MBB, MBBI, DL, RegInfo->getBaseRegister(), AArch64::SP,
1223 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_Nop))
1230 if (NeedsWinCFI && HasWinCFI) {
1231 BuildMI(MBB, MBBI, DL, TII->
get(AArch64::SEH_PrologEnd))
1235 if (needsFrameMoves) {
1240 Register FramePtr = RegInfo->getFrameRegister(MF);
1309 unsigned Reg = RegInfo->getDwarfRegNum(FramePtr,
true);
1311 nullptr, Reg, StackGrowth - FixedObject));
1312 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
1313 .addCFIIndex(CFIIndex)
1319 BuildMI(MBB, MBBI, DL, TII->
get(TargetOpcode::CFI_INSTRUCTION))
1320 .addCFIIndex(CFIIndex)
1339 if (MBBI != MBB.
end())
1340 DL = MBBI->getDebugLoc();
1347 MBBI->getOpcode() == AArch64::RET_ReallyLR) {
1350 .copyImplicitOps(*MBBI);
1377 bool IsTailCallReturn =
false;
1379 bool HasWinCFI =
false;
1380 bool IsFunclet =
false;
1386 if (MBB.
end() != MBBI) {
1387 DL = MBBI->getDebugLoc();
1388 unsigned RetOpcode = MBBI->getOpcode();
1389 IsTailCallReturn = RetOpcode == AArch64::TCRETURNdi ||
1390 RetOpcode == AArch64::TCRETURNri ||
1391 RetOpcode == AArch64::TCRETURNriBTI;
1406 uint64_t ArgumentPopSize = 0;
1407 if (IsTailCallReturn) {
1413 ArgumentPopSize = StackAdjust.
getImm();
1455 unsigned FixedObject =
1458 uint64_t AfterCSRPopSize = ArgumentPopSize;
1466 bool CombineSPBump = shouldCombineCSRLocalStackBump(MF, NumBytes);
1469 if (!CombineSPBump && PrologueSaveSize != 0) {
1472 Pop = std::prev(Pop);
1475 const MachineOperand &OffsetOp = Pop->getOperand(Pop->getNumOperands() - 1);
1477 if (OffsetOp.
getImm() == 0)
1479 MBB, Pop, DL, TII, PrologueSaveSize, NeedsWinCFI, &HasWinCFI,
false);
1485 AfterCSRPopSize += PrologueSaveSize;
1494 while (LastPopI != Begin) {
1500 }
else if (CombineSPBump)
1502 NeedsWinCFI, &HasWinCFI);
1507 BuildMI(MBB, LastPopI, DL, TII->
get(AArch64::SEH_EpilogStart))
1514 if (CombineSPBump) {
1515 assert(!SVEStackSize &&
"Cannot combine SP bump with SVE");
1517 {NumBytes + (int64_t)AfterCSRPopSize,
MVT::i8}, TII,
1519 if (NeedsWinCFI && HasWinCFI)
1521 TII->
get(AArch64::SEH_EpilogEnd))
1526 NumBytes -= PrologueSaveSize;
1527 assert(NumBytes >= 0 &&
"Negative stack allocation size!?");
1531 StackOffset DeallocateBefore = {}, DeallocateAfter = SVEStackSize;
1534 RestoreBegin = std::prev(RestoreEnd);;
1536 RestoreBegin != MBB.
begin())
1543 int64_t OffsetToFirstCalleeSaveFromSP =
1547 DeallocateBefore = OffsetToCalleeSavesFromSP;
1548 DeallocateAfter = SVEStackSize - DeallocateBefore;
1581 if (RedZone && AfterCSRPopSize == 0)
1584 bool NoCalleeSaveRestore = PrologueSaveSize == 0;
1585 int64_t StackRestoreBytes = RedZone ? 0 : NumBytes;
1586 if (NoCalleeSaveRestore)
1587 StackRestoreBytes += AfterCSRPopSize;
1591 bool Done = NoCalleeSaveRestore || AfterCSRPopSize == 0;
1604 TII->
get(AArch64::SEH_EpilogEnd))
1605 .setMIFlag(MachineInstr::FrameDestroy);
1618 int64_t OffsetToFrameRecord =
1621 {OffsetToFrameRecord,
MVT::i8},
1623 }
else if (NumBytes)
1631 if (AfterCSRPopSize) {
1636 while (FirstSPPopI != Begin) {
1637 auto Prev = std::prev(FirstSPPopI);
1638 if (Prev->getOpcode() != AArch64::LDRXpre ||
1639 Prev->getOperand(0).getReg() == AArch64::SP)
1647 {(int64_t)AfterCSRPopSize, MVT::i8}, TII,
1648 MachineInstr::FrameDestroy,
false, NeedsWinCFI, &HasWinCFI);
1650 if (NeedsWinCFI && HasWinCFI)
1652 .setMIFlag(MachineInstr::FrameDestroy);
1663 unsigned &FrameReg)
const {
1682 unsigned FixedObject = IsWin64 ?
alignTo(AFI->getVarArgsGPRSize(), 16) : 0;
1684 ? 16 : AFI->getCalleeSavedStackSize(MF.
getFrameInfo());
1685 return {ObjectOffset + FixedObject + FPAdjust,
MVT::i8};
1698 return RegInfo->getLocalAddressRegister(MF) == AArch64::FP
1705 bool ForSimm)
const {
1708 bool isFixed = MFI.isFixedObjectIndex(FI);
1715 const MachineFunction &MF, int64_t ObjectOffset,
bool isFixed,
bool isSVE,
1716 unsigned &FrameReg,
bool PreferFP,
bool ForSimm)
const {
1726 !isFixed && ObjectOffset >= -((int)AFI->getCalleeSavedStackSize(MFI));
1735 if (AFI->hasStackFrame() && !isSVE) {
1738 PreferFP &= !SVEStackSize;
1746 }
else if (isCSR && RegInfo->needsStackRealignment(MF)) {
1750 assert(
hasFP(MF) &&
"Re-aligned stack must have frame pointer");
1752 }
else if (
hasFP(MF) && !RegInfo->needsStackRealignment(MF)) {
1757 bool FPOffsetFits = !ForSimm || FPOffset >= -256;
1758 PreferFP |= Offset > -FPOffset;
1760 if (MFI.hasVarSizedObjects()) {
1764 bool CanUseBP = RegInfo->hasBasePointer(MF);
1765 if (FPOffsetFits && CanUseBP)
1767 else if (!CanUseBP) {
1768 assert(!SVEStackSize &&
"Expected BP to be available");
1774 }
else if (FPOffset >= 0) {
1779 }
else if (MF.
hasEHFunclets() && !RegInfo->hasBasePointer(MF)) {
1786 "Funclets should only be present on Win64");
1790 if (FPOffsetFits && PreferFP)
1796 assert(((isFixed || isCSR) || !RegInfo->needsStackRealignment(MF) || !UseFP) &&
1797 "In the presence of dynamic stack pointer realignment, " 1798 "non-argument/CSR objects cannot be accessed through the frame pointer");
1801 int64_t OffsetToSVEArea =
1802 MFI.getStackSize() - AFI->getCalleeSavedStackSize();
1811 RegInfo->needsStackRealignment(MF))) {
1812 FrameReg = RegInfo->getFrameRegister(MF);
1816 FrameReg = RegInfo->hasBasePointer(MF) ? RegInfo->getBaseRegister()
1822 if (UseFP && !(isFixed || isCSR))
1823 ScalableOffset = -SVEStackSize;
1824 if (!UseFP && (isFixed || isCSR))
1825 ScalableOffset = SVEStackSize;
1828 FrameReg = RegInfo->getFrameRegister(MF);
1833 if (RegInfo->hasBasePointer(MF))
1834 FrameReg = RegInfo->getBaseRegister();
1836 assert(!MFI.hasVarSizedObjects() &&
1837 "Can't use SP when we have var sized objects.");
1838 FrameReg = AArch64::SP;
1843 Offset -= AFI->getLocalStackSize();
1864 Attrs.hasAttrSomewhere(Attribute::SwiftError));
1877 if (Reg2 == AArch64::FP)
1881 if (Reg2 == Reg1 + 1)
1891 bool UsesWinAAPCS,
bool NeedsWinCFI,
bool NeedsFrameRecord) {
1897 if (NeedsFrameRecord)
1898 return Reg2 == AArch64::LR;
1905 struct RegPairInfo {
1906 unsigned Reg1 = AArch64::NoRegister;
1907 unsigned Reg2 = AArch64::NoRegister;
1910 enum RegType {
GPR, FPR64, FPR128, PPR, ZPR }
Type;
1912 RegPairInfo() =
default;
1914 bool isPaired()
const {
return Reg2 != AArch64::NoRegister; }
1916 unsigned getScale()
const {
1930 bool isScalable()
const {
return Type == PPR || Type == ZPR; }
1938 bool &NeedShadowCallStackProlog,
bool NeedsFrameRecord) {
1948 unsigned Count = CSI.size();
1954 (Count & 1) == 0) &&
1955 "Odd number of callee-saved regs to spill!");
1962 bool FixupDone =
false;
1963 for (
unsigned i = 0; i < Count; ++i) {
1965 RPI.Reg1 = CSI[i].getReg();
1967 if (AArch64::GPR64RegClass.
contains(RPI.Reg1))
1969 else if (AArch64::FPR64RegClass.
contains(RPI.Reg1))
1970 RPI.Type = RegPairInfo::FPR64;
1971 else if (AArch64::FPR128RegClass.
contains(RPI.Reg1))
1972 RPI.Type = RegPairInfo::FPR128;
1973 else if (AArch64::ZPRRegClass.
contains(RPI.Reg1))
1974 RPI.Type = RegPairInfo::ZPR;
1975 else if (AArch64::PPRRegClass.
contains(RPI.Reg1))
1976 RPI.Type = RegPairInfo::PPR;
1981 if (i + 1 < Count) {
1982 unsigned NextReg = CSI[i + 1].getReg();
1985 if (AArch64::GPR64RegClass.
contains(NextReg) &&
1990 case RegPairInfo::FPR64:
1991 if (AArch64::FPR64RegClass.
contains(NextReg) &&
1995 case RegPairInfo::FPR128:
1996 if (AArch64::FPR128RegClass.
contains(NextReg))
1999 case RegPairInfo::PPR:
2000 case RegPairInfo::ZPR:
2007 if ((RPI.Reg1 == AArch64::LR || RPI.Reg2 == AArch64::LR) &&
2011 NeedShadowCallStackProlog =
true;
2020 assert((!RPI.isPaired() ||
2021 (CSI[i].getFrameIdx() + 1 == CSI[i + 1].getFrameIdx())) &&
2022 "Out of order callee saved regs!");
2024 assert((!RPI.isPaired() || !NeedsFrameRecord || RPI.Reg2 != AArch64::FP ||
2025 RPI.Reg1 == AArch64::LR) &&
2026 "FrameRecord must be allocated together with LR");
2029 assert((!RPI.isPaired() || !NeedsFrameRecord || RPI.Reg1 != AArch64::FP ||
2030 RPI.Reg2 == AArch64::LR) &&
2031 "FrameRecord must be allocated together with LR");
2038 ((RPI.Reg1 == AArch64::LR && RPI.Reg2 == AArch64::FP) ||
2039 RPI.Reg1 + 1 == RPI.Reg2))) &&
2040 "Callee-save registers not saved as adjacent register pair!");
2042 RPI.FrameIdx = CSI[i].getFrameIdx();
2044 int Scale = RPI.getScale();
2045 if (RPI.isScalable())
2046 ScalableByteOffset -= Scale;
2048 ByteOffset -= RPI.isPaired() ? 2 * Scale : Scale;
2050 assert(!(RPI.isScalable() && RPI.isPaired()) &&
2051 "Paired spill/fill instructions don't exist for SVE vectors");
2056 !RPI.isScalable() && RPI.Type != RegPairInfo::FPR128 &&
2060 assert(ByteOffset % 16 == 0);
2061 assert(MFI.getObjectAlignment(RPI.FrameIdx) <= 16);
2062 MFI.setObjectAlignment(RPI.FrameIdx, 16);
2065 int Offset = RPI.isScalable() ? ScalableByteOffset : ByteOffset;
2066 assert(Offset % Scale == 0);
2067 RPI.Offset = Offset / Scale;
2069 assert(((!RPI.isScalable() && RPI.Offset >= -64 && RPI.Offset <= 63) ||
2070 (RPI.isScalable() && RPI.Offset >= -256 && RPI.Offset <= 255)) &&
2071 "Offset out of bounds for LDP/STP immediate");
2081 const std::vector<CalleeSavedInfo> &CSI,
2089 bool NeedShadowCallStackProlog =
false;
2091 NeedShadowCallStackProlog,
hasFP(MF));
2094 if (NeedShadowCallStackProlog) {
2096 BuildMI(MBB, MI, DL, TII.
get(AArch64::STRXpost))
2104 BuildMI(MBB, MI, DL, TII.
get(AArch64::SEH_Nop))
2110 static const char CFIInst[] = {
2111 dwarf::DW_CFA_val_expression,
2114 static_cast<char>(
unsigned(dwarf::DW_OP_breg18)),
2115 static_cast<char>(-8) & 0x7f,
2118 nullptr,
StringRef(CFIInst,
sizeof(CFIInst))));
2119 BuildMI(MBB, MI, DL, TII.
get(AArch64::CFI_INSTRUCTION))
2120 .addCFIIndex(CFIIndex)
2128 for (
auto RPII = RegPairs.
rbegin(), RPIE = RegPairs.
rend(); RPII != RPIE;
2130 RegPairInfo
RPI = *RPII;
2131 unsigned Reg1 = RPI.Reg1;
2132 unsigned Reg2 = RPI.Reg2;
2148 StrOpc = RPI.isPaired() ? AArch64::STPXi : AArch64::STRXui;
2152 case RegPairInfo::FPR64:
2153 StrOpc = RPI.isPaired() ? AArch64::STPDi : AArch64::STRDui;
2157 case RegPairInfo::FPR128:
2158 StrOpc = RPI.isPaired() ? AArch64::STPQi : AArch64::STRQui;
2162 case RegPairInfo::ZPR:
2163 StrOpc = AArch64::STR_ZXI;
2167 case RegPairInfo::PPR:
2168 StrOpc = AArch64::STR_PXI;
2174 if (RPI.isPaired())
dbgs() <<
", " <<
printReg(Reg2, TRI);
2175 dbgs() <<
") -> fi#(" << RPI.FrameIdx;
2176 if (RPI.isPaired())
dbgs() <<
", " << RPI.FrameIdx + 1;
2179 assert((!NeedsWinCFI || !(Reg1 == AArch64::LR && Reg2 == AArch64::FP)) &&
2180 "Windows unwdinding requires a consecutive (FP,LR) pair");
2184 unsigned FrameIdxReg1 = RPI.FrameIdx;
2185 unsigned FrameIdxReg2 = RPI.FrameIdx + 1;
2186 if (NeedsWinCFI && RPI.isPaired()) {
2193 if (RPI.isPaired()) {
2214 if (RPI.Type == RegPairInfo::ZPR || RPI.Type == RegPairInfo::PPR)
2223 std::vector<CalleeSavedInfo> &CSI,
2231 if (MI != MBB.
end())
2232 DL = MI->getDebugLoc();
2234 bool NeedShadowCallStackProlog =
false;
2236 NeedShadowCallStackProlog,
hasFP(MF));
2238 auto EmitMI = [&](
const RegPairInfo &
RPI) {
2239 unsigned Reg1 =
RPI.Reg1;
2240 unsigned Reg2 =
RPI.Reg2;
2254 LdrOpc =
RPI.isPaired() ? AArch64::LDPXi : AArch64::LDRXui;
2258 case RegPairInfo::FPR64:
2259 LdrOpc =
RPI.isPaired() ? AArch64::LDPDi : AArch64::LDRDui;
2263 case RegPairInfo::FPR128:
2264 LdrOpc =
RPI.isPaired() ? AArch64::LDPQi : AArch64::LDRQui;
2268 case RegPairInfo::ZPR:
2269 LdrOpc = AArch64::LDR_ZXI;
2273 case RegPairInfo::PPR:
2274 LdrOpc = AArch64::LDR_PXI;
2281 dbgs() <<
") -> fi#(" <<
RPI.FrameIdx;
2282 if (
RPI.isPaired())
dbgs() <<
", " <<
RPI.FrameIdx + 1;
2288 unsigned FrameIdxReg1 =
RPI.FrameIdx;
2289 unsigned FrameIdxReg2 =
RPI.FrameIdx + 1;
2290 if (NeedsWinCFI &&
RPI.isPaired()) {
2295 if (
RPI.isPaired()) {
2314 for (
const RegPairInfo &
RPI :
reverse(RegPairs))
2315 if (
RPI.isScalable())
2319 for (
const RegPairInfo &
RPI :
reverse(RegPairs))
2320 if (!
RPI.isScalable())
2323 for (
const RegPairInfo &
RPI : RegPairs)
2324 if (!
RPI.isScalable())
2327 if (NeedShadowCallStackProlog) {
2329 BuildMI(MBB, MI, DL, TII.
get(AArch64::LDRXpre))
2352 unsigned UnspilledCSGPR = AArch64::NoRegister;
2353 unsigned UnspilledCSGPRPaired = AArch64::NoRegister;
2362 unsigned ExtraCSSpill = 0;
2364 for (
unsigned i = 0; CSRegs[i]; ++i) {
2365 const unsigned Reg = CSRegs[i];
2368 if (Reg == BasePointerReg)
2371 bool RegUsed = SavedRegs.
test(Reg);
2372 unsigned PairedReg = AArch64::NoRegister;
2373 if (AArch64::GPR64RegClass.
contains(Reg) ||
2374 AArch64::FPR64RegClass.
contains(Reg) ||
2375 AArch64::FPR128RegClass.
contains(Reg))
2376 PairedReg = CSRegs[i ^ 1];
2379 if (AArch64::GPR64RegClass.
contains(Reg) &&
2381 UnspilledCSGPR =
Reg;
2382 UnspilledCSGPRPaired = PairedReg;
2391 !SavedRegs.
test(PairedReg)) {
2392 SavedRegs.
set(PairedReg);
2393 if (AArch64::GPR64RegClass.
contains(PairedReg) &&
2395 ExtraCSSpill = PairedReg;
2400 unsigned CSStackSize = 0;
2401 unsigned SVECSStackSize = 0;
2408 SVECSStackSize += RegSize;
2410 CSStackSize += RegSize;
2414 unsigned NumSavedRegs = SavedRegs.
count();
2420 SavedRegs.
set(AArch64::FP);
2421 SavedRegs.
set(AArch64::LR);
2431 int64_t SVEStackSize =
2432 alignTo(SVECSStackSize + estimateSVEStackObjectOffsets(MFI), 16);
2433 bool CanEliminateFrame = (SavedRegs.
count() == 0) && !SVEStackSize;
2440 bool BigStack = SVEStackSize ||
2441 (EstimatedStackSize + CSStackSize) > EstimatedStackSizeLimit;
2452 if (!ExtraCSSpill && UnspilledCSGPR != AArch64::NoRegister) {
2454 <<
" to get a scratch register.\n");
2455 SavedRegs.
set(UnspilledCSGPR);
2460 SavedRegs.
set(UnspilledCSGPRPaired);
2461 ExtraCSSpill = UnspilledCSGPR;
2473 LLVM_DEBUG(
dbgs() <<
"No available CS registers, allocated fi#" << FI
2474 <<
" as the emergency spill slot.\n");
2479 CSStackSize += 8 * (SavedRegs.
count() - NumSavedRegs);
2480 uint64_t AlignedCSStackSize =
alignTo(CSStackSize, 16);
2482 << EstimatedStackSize + AlignedCSStackSize
2487 "Should not invalidate callee saved info");
2504 int &Min,
int &Max) {
2506 Max = std::numeric_limits<int>::min();
2512 for (
auto &CS : CSI) {
2513 if (AArch64::ZPRRegClass.
contains(CS.getReg()) ||
2514 AArch64::PPRRegClass.
contains(CS.getReg())) {
2515 assert((Max == std::numeric_limits<int>::min() ||
2516 Max + 1 == CS.getFrameIdx()) &&
2517 "SVE CalleeSaves are not consecutive");
2519 Min = std::min(Min, CS.getFrameIdx());
2520 Max =
std::max(Max, CS.getFrameIdx());
2532 int &MinCSFrameIndex,
2533 int &MaxCSFrameIndex,
2534 bool AssignOffsets) {
2540 if (FixedOffset > Offset)
2541 Offset = FixedOffset;
2544 auto Assign = [&MFI](
int FI, int64_t
Offset) {
2545 LLVM_DEBUG(
dbgs() <<
"alloc FI(" << FI <<
") at SP[" << Offset <<
"]\n");
2555 for (
int I = MinCSFrameIndex;
I <= MaxCSFrameIndex; ++
I) {
2569 if (MaxCSFrameIndex >=
I &&
I >= MinCSFrameIndex)
2578 for (
unsigned FI : ObjectsToAllocate) {
2585 "Alignment of scalable vectors > 16 bytes is not yet supported");
2589 Assign(FI, -Offset);
2595 int64_t AArch64FrameLowering::estimateSVEStackObjectOffsets(
2597 int MinCSFrameIndex, MaxCSFrameIndex;
2601 int64_t AArch64FrameLowering::assignSVEStackObjectOffsets(
2612 "Upwards growing stack unsupported");
2614 int MinCSFrameIndex, MaxCSFrameIndex;
2615 int64_t SVEStackSize =
2616 assignSVEStackObjectOffsets(MFI, MinCSFrameIndex, MaxCSFrameIndex);
2630 auto MBBI = MBB.
begin();
2643 unsigned DstReg = RS->
FindUnusedReg(&AArch64::GPR64commonRegClass);
2644 assert(DstReg &&
"There must be a free register after frame setup");
2645 BuildMI(MBB, MBBI, DL, TII.
get(AArch64::MOVi64imm), DstReg).addImm(-2);
2646 BuildMI(MBB, MBBI, DL, TII.
get(AArch64::STURXi))
2648 .addFrameIndex(UnwindHelpFI)
2657 bool IgnoreSPUpdates)
const {
2661 FrameReg = AArch64::SP;
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface ...
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)
TargetStackID::Value getStackIDForScalableVectors() const override
Returns the StackID that scalable vectors should be associated with.
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand *> MMOs) const
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 usesWindowsCFI() const
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
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...
StackOffset is a wrapper around scalable and non-scalable offsets and is used in several functions su...
bool isReserved(Register PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
static bool ShouldSignWithAKey(MachineFunction &MF)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
void setHasWinCFI(bool v)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
LLVM_NODISCARD bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
uint64_t getLocalStackSize() const
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
class llvm::RegisterBankInfo GPR
void emitFrameOffset(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, StackOffset Offset, const TargetInstrInfo *TII, MachineInstr::MIFlag=MachineInstr::NoFlags, bool SetNZCV=false, bool NeedsWinCFI=false, bool *HasWinCFI=nullptr)
emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg plus Offset.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
void push_back(const T &Elt)
static void Cleanup(DenseMap< Instruction *, Instruction *> &NewPredicates, SetVector< Instruction *> &MaybeDead, Loop *L)
bool cannotEliminateFrame(const MachineFunction &MF) const
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
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
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
LLVM_NODISCARD detail::scope_exit< typename std::decay< Callable >::type > make_scope_exit(Callable &&F)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
static bool windowsRequiresStackProbe(MachineFunction &MF, uint64_t StackSizeInBytes)
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
MachineModuleInfo & getMMI() const
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...
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
static bool invalidateWindowsRegisterPairing(unsigned Reg1, unsigned Reg2, bool NeedsWinCFI)
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
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 bool isFuncletReturnInstr(const MachineInstr &MI)
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.
static unsigned getPrologueDeath(MachineFunction &MF, unsigned Reg)
unsigned 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...
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class...
CLEANUPRET - Represents a return from a cleanup block funclet.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const
int isAArch64FrameOffsetLegal(const MachineInstr &MI, StackOffset &Offset, bool *OutUseUnscaledOp=nullptr, unsigned *OutUnscaledOp=nullptr, int64_t *EmittableOffset=nullptr)
Check if the Offset is a valid frame offset for MI.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
static bool isSEHInstruction(const MachineInstr &MI)
Return true if the instructions is a SEH instruciton used for unwinding on Windows.
bool isStackRealigned() const
const HexagonInstrInfo * TII
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.
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.
void setLocalStackSize(uint64_t Size)
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...
void backward()
Update internal register state and move MBB iterator backwards.
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.
bool isTargetMachO() const
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.
int getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, unsigned &FrameReg, bool IgnoreSPUpdates) const override
For Win64 AArch64 EH, the offset to the Unwind object is from the SP before the update.
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override
The parent frame offset (aka dispFrame) is only used on X86_64 to retrieve the parent's frame pointer...
int64_t getScalableBytes() const
Returns the scalable part of the offset in bytes.
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()))
int getDwarfRegNum(MCRegister RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
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...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
static bool getSVECalleeSaveSlotRange(const MachineFrameInfo &MFI, int &Min, int &Max)
returns true if there are any SVE callee saves.
static bool IsSVECalleeSave(MachineBasicBlock::iterator I)
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
int getObjectIndexBegin() const
Return the minimum frame object index.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
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.
bool hasPersonalityFn() const
Check whether this function has a personality function.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const
Funclets only need to account for space for the callee saved registers, as the locals are accounted f...
virtual const TargetInstrInfo * getInstrInfo() const
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool isXRegisterReserved(size_t i) const
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
int64_t getBytes() const
Returns the non-scalable part of the offset in bytes.
Analysis containing CSE Info
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
unsigned getKillRegState(bool B)
static unsigned getShifterImm(AArch64_AM::ShiftExtendType ST, unsigned Imm)
getShifterImm - Encode the shift type and amount: imm: 6-bit shift amount shifter: 000 ==> lsl 001 ==...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Flag
These should be considered private to the implementation of the MCInstrDesc class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
TargetInstrInfo - Interface to description of machine instruction set.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
static StackOffset getFPOffset(const MachineFunction &MF, int64_t ObjectOffset)
bool isTargetWindows() const
int getNonLocalFrameIndexReference(const MachineFunction &MF, int FI) const override
getNonLocalFrameIndexReference - This method returns the offset used to reference a frame index locat...
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
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
uint64_t getStackSizeSVE() const
initializer< Ty > init(const Ty &Val)
static MCCFIInstruction createNegateRAState(MCSymbol *L)
.cfi_negate_ra_state AArch64 negate RA state.
static StackOffset getStackOffset(const MachineFunction &MF, int64_t ObjectOffset)
StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg, bool PreferFP, bool ForSimm) 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
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...
The instances of the Type class are immutable: once they are created, they are never changed...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StackOffset resolveFrameOffsetReference(const MachineFunction &MF, int64_t ObjectOffset, bool isFixed, bool isSVE, unsigned &FrameReg, bool PreferFP, bool ForSimm) const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static bool ShouldSignReturnAddress(MachineFunction &MF)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool hasEHFunclets() const
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
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...
void setStackSizeSVE(uint64_t S)
unsigned getVarArgsGPRSize() const
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
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...
void setImm(int64_t immVal)
void setStackID(int ObjectIdx, uint8_t ID)
void setHasStackFrame(bool s)
static cl::opt< bool > EnableRedZone("aarch64-redzone", cl::desc("enable use of redzone on AArch64"), cl::init(false), cl::Hidden)
static int64_t determineSVEStackObjectOffsets(MachineFrameInfo &MFI, int &MinCSFrameIndex, int &MaxCSFrameIndex, bool AssignOffsets)
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.
static bool isTargetWindows(const MachineFunction &MF)
unsigned getCalleeSavedStackSize(const MachineFrameInfo &MFI) const
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.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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.
virtual void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, bool KillSrc) const
Emit instructions to copy a pair of physical registers.
static bool invalidateRegisterPairing(unsigned Reg1, unsigned Reg2, bool UsesWinAAPCS, bool NeedsWinCFI, bool NeedsFrameRecord)
Returns true if Reg1 and Reg2 cannot be paired using a ldp/stp instruction.
static StackOffset getSVEStackSize(const MachineFunction &MF)
Returns the size of the entire SVE stackframe (calleesaves + spills).
size_type count() const
count - Returns the number of bits which are set.
static void InsertReturnAddressAuth(MachineFunction &MF, MachineBasicBlock &MBB)
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
static void computeCalleeSaveRegisterPairs(MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI, SmallVectorImpl< RegPairInfo > &RegPairs, bool &NeedShadowCallStackProlog, bool NeedsFrameRecord)
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool available(const MachineRegisterInfo &MRI, MCPhysReg Reg) const
Returns true if register Reg and no aliasing register is in the set.
static void fixupCalleeSaveRestoreStackOffset(MachineInstr &MI, uint64_t LocalStackSize, bool NeedsWinCFI, bool *HasWinCFI)
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...
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 ...
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
bool hasCalleeSaveStackFreeSpace() const
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling...
void enterBasicBlockEnd(MachineBasicBlock &MBB)
Start tracking liveness from the end of basic block MBB.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
static MachineBasicBlock::iterator InsertSEH(MachineBasicBlock::iterator MBBI, const TargetInstrInfo &TII, MachineInstr::MIFlag Flag)
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.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
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.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
static bool needsWinCFI(const MachineFunction &MF)
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
CATCHRET - Represents a return from a catch block funclet.
const MachineBasicBlock * getParent() const
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 void fixupSEHOpcode(MachineBasicBlock::iterator MBBI, unsigned LocalStackSize)
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
LLVM_NODISCARD bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
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)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
void setMinMaxSVECSFrameIndex(int Min, int Max)
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.
Register FindUnusedReg(const TargetRegisterClass *RC) const
Find an unused register of the specified register class.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
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 LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
static bool isTargetDarwin(const MachineFunction &MF)
static bool produceCompactUnwindFrame(MachineFunction &MF)
uint8_t getStackID(int ObjectIdx) const
reverse_iterator rbegin()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
int CreateStackObject(uint64_t Size, Align 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 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...
Constant * getPersonalityFn() const
Get the personality function associated with this function.
static MachineBasicBlock::iterator convertCalleeSaveRestoreToSPPrePostIncDec(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const TargetInstrInfo *TII, int CSStackSizeInc, bool NeedsWinCFI, bool *HasWinCFI, bool InProlog=true)
const AArch64InstrInfo * getInstrInfo() const override
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
void addReg(MCPhysReg Reg)
Adds a physical register and all its sub-registers to the set.
void setSVECalleeSavedStackSize(unsigned Size)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
bool isMaxCallFrameSizeComputed() const
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
bool hasStackFrame() const
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
StringRef - Represent a constant reference to a string, i.e.
unsigned getSVECalleeSavedStackSize() const
void setTaggedBasePointerOffset(unsigned Offset)
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
Register getReg() const
getReg - Returns the register number.
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals)
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
const MachineOperand & getOperand(unsigned i) const
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
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 needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
Wrapper class representing virtual and physical registers.
void setCalleeSavedStackSize(unsigned Size)
int getMaxSVECSFrameIndex() const
This class contains meta information specific to a module.
bool hasCalls() const
Return true if the current function has any function calls.