267#define DEBUG_TYPE "frame-info"
270 cl::desc(
"enable use of redzone on AArch64"),
274 "stack-tagging-merge-settag",
284 cl::desc(
"Split allocation of ZPR & PPR objects"),
289 cl::desc(
"Emit homogeneous prologue and epilogue for the size "
290 "optimization (default = off)"));
302 "aarch64-disable-multivector-spill-fill",
311 bool IsTailCallReturn = (
MBB.end() !=
MBBI)
315 int64_t ArgumentPopSize = 0;
316 if (IsTailCallReturn) {
322 ArgumentPopSize = StackAdjust.
getImm();
331 return ArgumentPopSize;
374 if (AFI->hasCalculatedStackSizeSVE())
404bool AArch64FrameLowering::homogeneousPrologEpilog(
430 if (AFI->hasSwiftAsyncContext() || AFI->hasStreamingModeChanges())
437 unsigned NumGPRs = 0;
438 for (
unsigned I = 0; CSRegs[
I]; ++
I) {
440 if (Reg == AArch64::LR) {
441 assert(CSRegs[
I + 1] == AArch64::FP);
442 if (NumGPRs % 2 != 0)
454bool AArch64FrameLowering::producePairRegisters(
MachineFunction &MF)
const {
473 if (
MI.isDebugInstr() ||
MI.isPseudo() ||
474 MI.getOpcode() == AArch64::ADDXri ||
475 MI.getOpcode() == AArch64::ADDSXri)
500 bool IsWin64,
bool IsFunclet)
const {
502 "Tail call reserved stack must be aligned to 16 bytes");
503 if (!IsWin64 || IsFunclet) {
508 Attribute::SwiftAsync))
522 int FrameIndex =
H.CatchObj.FrameIndex;
523 if ((FrameIndex != INT_MAX) &&
524 CatchObjFrameIndices.
insert(FrameIndex)) {
525 FixedObjectSize =
alignTo(FixedObjectSize,
532 FixedObjectSize += 8;
534 return alignTo(FixedObjectSize, 16);
545 const unsigned RedZoneSize =
558 bool LowerQRegCopyThroughMem = Subtarget.hasFPARMv8() &&
562 return !(MFI.
hasCalls() ||
hasFP(MF) || NumBytes > RedZoneSize ||
584 if (Subtarget.getTargetLowering()->useStackGuardMixFP())
593 RegInfo->hasStackRealignment(MF))
640 if (TT.isOSDarwin() || TT.isOSWindows())
678 unsigned Opc =
I->getOpcode();
679 bool IsDestroy =
Opc ==
TII->getCallFrameDestroyOpcode();
680 uint64_t CalleePopAmount = IsDestroy ?
I->getOperand(1).getImm() : 0;
683 int64_t Amount =
I->getOperand(0).getImm();
691 if (CalleePopAmount == 0) {
702 assert(Amount > -0xffffff && Amount < 0xffffff &&
"call frame too large");
713 "non-reserved call frame without var sized objects?");
722 }
else if (CalleePopAmount != 0) {
725 assert(CalleePopAmount < 0xffffff &&
"call frame too large");
737 const auto &
TRI = *Subtarget.getRegisterInfo();
743 CFIBuilder.buildDefCFA(AArch64::SP, 0);
746 if (MFI.shouldSignReturnAddress(MF)) {
747 if (MFI.branchProtectionPAuthLR()) {
748 CFIBuilder.buildNegateRAStateWithPC();
750 CFIBuilder.buildNegateRAState();
755 if (MFI.needsShadowCallStackPrologueEpilogue(MF))
756 CFIBuilder.buildSameValue(AArch64::X18);
759 const std::vector<CalleeSavedInfo> &CSI =
761 for (
const auto &Info : CSI) {
763 if (!
TRI.regNeedsCFI(Reg, Reg))
765 CFIBuilder.buildSameValue(Reg);
778 case AArch64::W##n: \
779 case AArch64::X##n: \
804 case AArch64::B##n: \
805 case AArch64::H##n: \
806 case AArch64::S##n: \
807 case AArch64::D##n: \
808 case AArch64::Q##n: \
809 return HasSVE ? AArch64::Z##n : AArch64::Q##n
846void AArch64FrameLowering::emitZeroCallUsedRegs(
BitVector RegsToZero,
857 const AArch64Subtarget &STI = MF.
getSubtarget<AArch64Subtarget>();
860 BitVector GPRsToZero(
TRI.getNumRegs());
861 BitVector FPRsToZero(
TRI.getNumRegs());
864 if (
TRI.isGeneralPurposeRegister(MF,
Reg)) {
867 GPRsToZero.set(XReg);
871 FPRsToZero.set(XReg);
878 for (MCRegister
Reg : GPRsToZero.set_bits())
882 for (MCRegister
Reg : FPRsToZero.set_bits())
886 for (MCRegister PReg :
887 {AArch64::P0, AArch64::P1, AArch64::P2, AArch64::P3, AArch64::P4,
888 AArch64::P5, AArch64::P6, AArch64::P7, AArch64::P8, AArch64::P9,
889 AArch64::P10, AArch64::P11, AArch64::P12, AArch64::P13, AArch64::P14,
891 if (RegsToZero[PReg])
897bool AArch64FrameLowering::windowsRequiresStackProbe(
899 const AArch64Subtarget &Subtarget = MF.
getSubtarget<AArch64Subtarget>();
900 const AArch64FunctionInfo &MFI = *MF.
getInfo<AArch64FunctionInfo>();
904 StackSizeInBytes >= uint64_t(MFI.getStackProbeSize());
913 for (
unsigned i = 0; CSRegs[i]; ++i)
919 bool HasCall)
const {
929 const AArch64Subtarget &Subtarget = MF->
getSubtarget<AArch64Subtarget>();
931 LivePhysRegs LiveRegs(
TRI);
934 LiveRegs.addReg(AArch64::X16);
935 LiveRegs.addReg(AArch64::X17);
936 LiveRegs.addReg(AArch64::X18);
940 const MachineRegisterInfo &MRI = MF->
getRegInfo();
941 if (LiveRegs.available(MRI, AArch64::X9))
944 for (
unsigned Reg : AArch64::GPR64RegClass) {
945 if (LiveRegs.available(MRI,
Reg))
948 return AArch64::NoRegister;
967 if (!
LiveRegs.available(MRI, AArch64::X16) ||
968 !
LiveRegs.available(MRI, AArch64::X17))
975 MBB.isLiveIn(AArch64::NZCV))
979 if (findScratchNonCalleeSaveRegister(TmpMBB) == AArch64::NoRegister)
985 windowsRequiresStackProbe(*MF, std::numeric_limits<uint64_t>::max()))
986 if (findScratchNonCalleeSaveRegister(TmpMBB,
true) == AArch64::NoRegister)
995 F.needsUnwindTableEntry();
998bool AArch64FrameLowering::shouldSignReturnAddressEverywhere(
1014 unsigned Opc =
MBBI->getOpcode();
1018 unsigned ImmIdx =
MBBI->getNumOperands() - 1;
1019 int Imm =
MBBI->getOperand(ImmIdx).getImm();
1027 case AArch64::STR_ZXI:
1028 case AArch64::LDR_ZXI: {
1029 unsigned Reg0 =
RegInfo->getSEHRegNum(
MBBI->getOperand(0).getReg());
1036 case AArch64::STR_PXI:
1037 case AArch64::LDR_PXI: {
1038 unsigned Reg0 = RegInfo->getSEHRegNum(
MBBI->getOperand(0).getReg());
1045 case AArch64::LDPDpost:
1048 case AArch64::STPDpre: {
1049 unsigned Reg0 = RegInfo->getSEHRegNum(
MBBI->getOperand(1).getReg());
1050 unsigned Reg1 = RegInfo->getSEHRegNum(
MBBI->getOperand(2).getReg());
1051 MIB =
BuildMI(MF,
DL,
TII.get(AArch64::SEH_SaveFRegP_X))
1058 case AArch64::LDPXpost:
1061 case AArch64::STPXpre: {
1064 if (Reg0 == AArch64::FP && Reg1 == AArch64::LR)
1065 MIB =
BuildMI(MF,
DL,
TII.get(AArch64::SEH_SaveFPLR_X))
1069 MIB =
BuildMI(MF,
DL,
TII.get(AArch64::SEH_SaveRegP_X))
1070 .
addImm(RegInfo->getSEHRegNum(Reg0))
1071 .
addImm(RegInfo->getSEHRegNum(Reg1))
1076 case AArch64::LDRDpost:
1079 case AArch64::STRDpre: {
1080 unsigned Reg = RegInfo->getSEHRegNum(
MBBI->getOperand(1).getReg());
1081 MIB =
BuildMI(MF,
DL,
TII.get(AArch64::SEH_SaveFReg_X))
1087 case AArch64::LDRXpost:
1090 case AArch64::STRXpre: {
1091 unsigned Reg = RegInfo->getSEHRegNum(
MBBI->getOperand(1).getReg());
1098 case AArch64::STPDi:
1099 case AArch64::LDPDi: {
1100 unsigned Reg0 = RegInfo->getSEHRegNum(
MBBI->getOperand(0).getReg());
1101 unsigned Reg1 = RegInfo->getSEHRegNum(
MBBI->getOperand(1).getReg());
1109 case AArch64::STPXi:
1110 case AArch64::LDPXi: {
1114 int SEHReg0 = RegInfo->getSEHRegNum(Reg0);
1115 int SEHReg1 = RegInfo->getSEHRegNum(Reg1);
1117 if (Reg0 == AArch64::FP && Reg1 == AArch64::LR)
1121 else if (SEHReg0 >= 19 && SEHReg1 >= 19)
1128 MIB =
BuildMI(MF,
DL,
TII.get(AArch64::SEH_SaveAnyRegIP))
1135 case AArch64::STRXui:
1136 case AArch64::LDRXui: {
1137 int Reg = RegInfo->getSEHRegNum(
MBBI->getOperand(0).getReg());
1144 MIB =
BuildMI(MF,
DL,
TII.get(AArch64::SEH_SaveAnyRegI))
1150 case AArch64::STRDui:
1151 case AArch64::LDRDui: {
1152 unsigned Reg = RegInfo->getSEHRegNum(
MBBI->getOperand(0).getReg());
1159 case AArch64::STPQi:
1160 case AArch64::LDPQi: {
1161 unsigned Reg0 = RegInfo->getSEHRegNum(
MBBI->getOperand(0).getReg());
1162 unsigned Reg1 = RegInfo->getSEHRegNum(
MBBI->getOperand(1).getReg());
1163 MIB =
BuildMI(MF,
DL,
TII.get(AArch64::SEH_SaveAnyRegQP))
1170 case AArch64::LDPQpost:
1173 case AArch64::STPQpre: {
1174 unsigned Reg0 = RegInfo->getSEHRegNum(
MBBI->getOperand(1).getReg());
1175 unsigned Reg1 = RegInfo->getSEHRegNum(
MBBI->getOperand(2).getReg());
1176 MIB =
BuildMI(MF,
DL,
TII.get(AArch64::SEH_SaveAnyRegQPX))
1195 if (ST.isTargetDarwin())
1217 DL =
MBBI->getDebugLoc();
1219 TII->createPauthEpilogueInstr(
MBB,
DL);
1223 EmitSignRA(MF.
front());
1225 if (
MBB.isEHFuncletEntry())
1227 if (
MBB.isReturnBlock())
1283 StackOffset SVEStackSize = ZPRStackSize + PPRStackSize;
1288 if (MFI.isVariableSizedObjectIndex(FI)) {
1298 if (MFI.hasScalableStackID(FI)) {
1299 if (FPAfterSVECalleeSaves &&
1302 "split-sve-objects not supported with FPAfterSVECalleeSaves");
1310 AccessOffset = -PPRStackSize;
1311 return AccessOffset +
1316 bool IsFixed = MFI.isFixedObjectIndex(FI);
1321 if (!IsFixed && !IsCSR) {
1322 ScalableOffset = -SVEStackSize;
1323 }
else if (FPAfterSVECalleeSaves && IsCSR) {
1338 int64_t ObjectOffset)
const {
1342 bool IsWin64 = Subtarget.isCallingConvWin64(
F.getCallingConv(),
F.isVarArg());
1343 unsigned FixedObject =
1344 getFixedObjectSize(MF, AFI, IsWin64,
false);
1352 int64_t ObjectOffset)
const {
1363 return RegInfo->getLocalAddressRegister(MF) == AArch64::FP
1364 ? getFPOffset(MF, ObjectOffset).getFixed()
1365 : getStackOffset(MF, ObjectOffset).getFixed();
1370 bool ForSimm)
const {
1372 int64_t ObjectOffset = MFI.getObjectOffset(FI);
1373 bool isFixed = MFI.isFixedObjectIndex(FI);
1376 FrameReg, PreferFP, ForSimm);
1382 bool ForSimm)
const {
1388 int64_t FPOffset = getFPOffset(MF, ObjectOffset).getFixed();
1389 int64_t
Offset = getStackOffset(MF, ObjectOffset).getFixed();
1392 bool isSVE = MFI.isScalableStackID(StackID);
1396 StackOffset SVEStackSize = ZPRStackSize + PPRStackSize;
1407 PreferFP &= !SVEStackSize;
1415 }
else if (isCSR && RegInfo->hasStackRealignment(MF)) {
1419 assert(
hasFP(MF) &&
"Re-aligned stack must have frame pointer");
1421 }
else if (
hasFP(MF) && !RegInfo->hasStackRealignment(MF)) {
1426 bool FPOffsetFits = !ForSimm || FPOffset >= -256;
1427 PreferFP |=
Offset > -FPOffset && !SVEStackSize;
1429 if (FPOffset >= 0) {
1433 }
else if (MFI.hasVarSizedObjects()) {
1437 bool CanUseBP = RegInfo->hasBasePointer(MF);
1438 if (FPOffsetFits && CanUseBP)
1445 }
else if (MF.
hasEHFunclets() && !RegInfo->hasBasePointer(MF)) {
1452 "Funclets should only be present on Win64");
1456 if (FPOffsetFits && PreferFP)
1463 ((isFixed || isCSR) || !RegInfo->hasStackRealignment(MF) || !UseFP) &&
1464 "In the presence of dynamic stack pointer realignment, "
1465 "non-argument/CSR objects cannot be accessed through the frame pointer");
1482 FPOffset -= PPRStackSize;
1484 SPOffset -= PPRStackSize;
1489 if (FPAfterSVECalleeSaves) {
1500 RegInfo->hasStackRealignment(MF))) {
1501 FrameReg = RegInfo->getFrameRegister(MF);
1504 FrameReg = RegInfo->hasBasePointer(MF) ? RegInfo->getBaseRegister()
1511 if (FPAfterSVECalleeSaves) {
1518 SVEAreaOffset = SVECalleeSavedStack;
1520 SVEAreaOffset = SVECalleeSavedStack - SVEStackSize;
1523 SVEAreaOffset = SVEStackSize;
1525 SVEAreaOffset = SVEStackSize - SVECalleeSavedStack;
1528 if (UseFP && !(isFixed || isCSR))
1529 SVEAreaOffset = -SVEStackSize;
1530 if (!UseFP && (isFixed || isCSR))
1531 SVEAreaOffset = SVEStackSize;
1535 FrameReg = RegInfo->getFrameRegister(MF);
1540 if (RegInfo->hasBasePointer(MF))
1541 FrameReg = RegInfo->getBaseRegister();
1543 assert(!MFI.hasVarSizedObjects() &&
1544 "Can't use SP when we have var sized objects.");
1545 FrameReg = AArch64::SP;
1573 Attrs.hasAttrSomewhere(Attribute::SwiftError)) &&
1579 unsigned SpillCount,
unsigned Reg1,
1580 unsigned Reg2,
bool NeedsWinCFI,
1589 if (Reg2 == AArch64::FP)
1599 if (
TRI->getEncodingValue(Reg2) ==
TRI->getEncodingValue(Reg1) + 1)
1600 return SpillExtendedVolatile
1601 ? !((Reg1 == AArch64::FP && Reg2 == AArch64::LR) ||
1602 (SpillCount % 2) == 0)
1607 if (Reg1 >= AArch64::X19 && Reg1 <= AArch64::X27 &&
1608 (Reg1 - AArch64::X19) % 2 == 0 && Reg2 == AArch64::LR)
1618 unsigned SpillCount,
unsigned Reg1,
1619 unsigned Reg2,
bool UsesWinAAPCS,
1620 bool NeedsWinCFI,
bool NeedsFrameRecord,
1624 Reg1, Reg2, NeedsWinCFI,
TRI);
1628 if (NeedsFrameRecord)
1629 return Reg2 == AArch64::LR;
1641 enum RegType { GPR, FPR64, FPR128, PPR, ZPR, VG }
Type;
1642 const TargetRegisterClass *RC;
1644 RegPairInfo() =
default;
1646 bool isPaired()
const {
return Reg2.
isValid(); }
1648 bool isScalable()
const {
return Type == PPR ||
Type == ZPR; }
1654 for (
unsigned PReg = AArch64::P8; PReg <= AArch64::P15; ++PReg) {
1655 if (SavedRegs.
test(PReg)) {
1656 unsigned PNReg = PReg - AArch64::P0 + AArch64::PN0;
1670 bool IsLocallyStreaming =
1676 return Subtarget.hasSVE2p1() ||
1677 (Subtarget.hasSME2() &&
1678 (!IsLocallyStreaming && Subtarget.
isStreaming()));
1686 bool NeedsFrameRecord) {
1703 (
Count & 1) == 0) &&
1704 "Odd number of callee-saved regs to spill!");
1706 int StackFillDir = -1;
1708 unsigned FirstReg = 0;
1716 FirstReg =
Count - 1;
1728 bool SpillExtendedVolatile =
1730 const auto &
Reg = CSI.getReg();
1731 return Reg >= AArch64::X0 &&
Reg <= AArch64::X18;
1734 int ZPRByteOffset = 0;
1735 int PPRByteOffset = 0;
1740 }
else if (!FPAfterSVECalleeSaves) {
1751 auto AlignOffset = [StackFillDir](
int Offset,
int Align) {
1752 if (StackFillDir < 0)
1758 for (
unsigned i = FirstReg; i <
Count; i += RegInc) {
1760 RPI.Reg1 = CSI[i].getReg();
1762 if (AArch64::GPR64RegClass.
contains(RPI.Reg1)) {
1763 RPI.Type = RegPairInfo::GPR;
1764 RPI.RC = &AArch64::GPR64RegClass;
1765 }
else if (AArch64::FPR64RegClass.
contains(RPI.Reg1)) {
1766 RPI.Type = RegPairInfo::FPR64;
1767 RPI.RC = &AArch64::FPR64RegClass;
1768 }
else if (AArch64::FPR128RegClass.
contains(RPI.Reg1)) {
1769 RPI.Type = RegPairInfo::FPR128;
1770 RPI.RC = &AArch64::FPR128RegClass;
1771 }
else if (AArch64::ZPRRegClass.
contains(RPI.Reg1)) {
1772 RPI.Type = RegPairInfo::ZPR;
1773 RPI.RC = &AArch64::ZPRRegClass;
1774 }
else if (AArch64::PPRRegClass.
contains(RPI.Reg1)) {
1775 RPI.Type = RegPairInfo::PPR;
1776 RPI.RC = &AArch64::PPRRegClass;
1777 }
else if (RPI.Reg1 == AArch64::VG) {
1778 RPI.Type = RegPairInfo::VG;
1779 RPI.RC = &AArch64::FIXED_REGSRegClass;
1784 int &ScalableByteOffset = RPI.Type == RegPairInfo::PPR && SplitPPRs
1789 if (HasCSHazardPadding &&
1792 ByteOffset += StackFillDir * StackHazardSize;
1796 int Scale =
TRI->getSpillSize(*RPI.RC);
1798 if (
unsigned(i + RegInc) <
Count && !HasCSHazardPadding) {
1799 MCRegister NextReg = CSI[i + RegInc].getReg();
1800 unsigned SpillCount = NeedsWinCFI ? FirstReg - i : i;
1802 case RegPairInfo::GPR:
1803 if (AArch64::GPR64RegClass.
contains(NextReg) &&
1805 RPI.Reg1, NextReg, IsWindows,
1806 NeedsWinCFI, NeedsFrameRecord,
TRI))
1809 case RegPairInfo::FPR64:
1810 if (AArch64::FPR64RegClass.
contains(NextReg) &&
1812 RPI.Reg1, NextReg, IsWindows,
1813 NeedsWinCFI, NeedsFrameRecord,
TRI))
1816 case RegPairInfo::FPR128:
1817 if (AArch64::FPR128RegClass.
contains(NextReg))
1820 case RegPairInfo::PPR:
1822 case RegPairInfo::ZPR:
1824 ((RPI.Reg1 - AArch64::Z0) & 1) == 0 && (NextReg == RPI.Reg1 + 1)) {
1827 int Offset = (ScalableByteOffset + StackFillDir * 2 * Scale) / Scale;
1832 case RegPairInfo::VG:
1843 assert((!RPI.isPaired() ||
1844 (CSI[i].getFrameIdx() + RegInc == CSI[i + RegInc].getFrameIdx())) &&
1845 "Out of order callee saved regs!");
1847 assert((!RPI.isPaired() || !NeedsFrameRecord || RPI.Reg2 != AArch64::FP ||
1848 RPI.Reg1 == AArch64::LR) &&
1849 "FrameRecord must be allocated together with LR");
1852 assert((!RPI.isPaired() || !NeedsFrameRecord || RPI.Reg1 != AArch64::FP ||
1853 RPI.Reg2 == AArch64::LR) &&
1854 "FrameRecord must be allocated together with LR");
1862 ((RPI.Reg1 == AArch64::LR && RPI.Reg2 == AArch64::FP) ||
1863 RPI.Reg1 + 1 == RPI.Reg2))) &&
1864 "Callee-save registers not saved as adjacent register pair!");
1866 RPI.FrameIdx = CSI[i].getFrameIdx();
1869 RPI.FrameIdx = CSI[i + RegInc].getFrameIdx();
1873 if (RPI.isScalable() && ScalableByteOffset % Scale != 0)
1874 ScalableByteOffset = AlignOffset(ScalableByteOffset, Scale);
1878 if (!RPI.isScalable() && ByteOffset % Scale != 0)
1879 ByteOffset = AlignOffset(ByteOffset, Scale);
1881 int OffsetPre = RPI.isScalable() ? ScalableByteOffset : ByteOffset;
1882 assert(OffsetPre % Scale == 0);
1884 if (RPI.isScalable())
1885 ScalableByteOffset += StackFillDir * (RPI.isPaired() ? 2 * Scale : Scale);
1887 ByteOffset += StackFillDir * (RPI.isPaired() ? 2 * Scale : Scale);
1892 ((!IsWindows && RPI.Reg2 == AArch64::FP) ||
1893 (IsWindows && RPI.Reg2 == AArch64::LR)))
1894 ByteOffset += StackFillDir * 8;
1898 if (NeedGapToAlignStack && !IsWindows && !RPI.isScalable() &&
1899 RPI.Type != RegPairInfo::FPR128 && !RPI.isPaired() &&
1900 ByteOffset % 16 != 0) {
1901 ByteOffset += 8 * StackFillDir;
1907 NeedGapToAlignStack =
false;
1910 int OffsetPost = RPI.isScalable() ? ScalableByteOffset : ByteOffset;
1911 assert(OffsetPost % Scale == 0);
1914 int Offset = IsWindows ? OffsetPre : OffsetPost;
1919 ((!IsWindows && RPI.Reg2 == AArch64::FP) ||
1920 (IsWindows && RPI.Reg2 == AArch64::LR)))
1922 RPI.Offset =
Offset / Scale;
1924 assert((!RPI.isPaired() ||
1925 (!RPI.isScalable() && RPI.Offset >= -64 && RPI.Offset <= 63) ||
1926 (RPI.isScalable() && RPI.Offset >= -256 && RPI.Offset <= 255)) &&
1927 "Offset out of bounds for LDP/STP immediate");
1929 auto isFrameRecord = [&] {
1931 return IsWindows ? RPI.Reg1 == AArch64::FP && RPI.Reg2 == AArch64::LR
1932 : RPI.Reg1 == AArch64::LR && RPI.Reg2 == AArch64::FP;
1940 return i > 0 && RPI.Reg1 == AArch64::FP &&
1941 CSI[i - 1].getReg() == AArch64::LR;
1946 if (NeedsFrameRecord && isFrameRecord())
1963 std::reverse(RegPairs.
begin(), RegPairs.
end());
1985 if (homogeneousPrologEpilog(MF)) {
1989 for (
auto &RPI : RegPairs) {
1995 MBB.addLiveIn(RPI.Reg1);
1996 if (RPI.isPaired() && !MRI.
isReserved(RPI.Reg2))
1997 MBB.addLiveIn(RPI.Reg2);
2001 bool PTrueCreated =
false;
2017 unsigned Size =
TRI->getSpillSize(*RPI.RC);
2018 Align Alignment =
TRI->getSpillAlign(*RPI.RC);
2020 case RegPairInfo::GPR:
2021 StrOpc = RPI.isPaired() ? AArch64::STPXi : AArch64::STRXui;
2023 case RegPairInfo::FPR64:
2024 StrOpc = RPI.isPaired() ? AArch64::STPDi : AArch64::STRDui;
2026 case RegPairInfo::FPR128:
2027 StrOpc = RPI.isPaired() ? AArch64::STPQi : AArch64::STRQui;
2029 case RegPairInfo::ZPR:
2030 StrOpc = RPI.isPaired() ? AArch64::ST1B_2Z_IMM : AArch64::STR_ZXI;
2032 case RegPairInfo::PPR:
2033 StrOpc = AArch64::STR_PXI;
2035 case RegPairInfo::VG:
2036 StrOpc = AArch64::STRXui;
2042 if (X0Scratch != AArch64::NoRegister)
2048 if (Reg1 == AArch64::VG) {
2050 Reg1 = findScratchNonCalleeSaveRegister(&
MBB,
true);
2051 assert(Reg1 != AArch64::NoRegister);
2061 return STI.getRegisterInfo()->isSuperOrSubRegisterEq(
2062 AArch64::X0, LiveIn.PhysReg);
2070 RTLIB::Libcall LC = RTLIB::SMEABI_GET_CURRENT_VG;
2072 TRI->getCallPreservedMask(MF, TLI.getLibcallCallingConv(LC));
2086 dbgs() <<
") -> fi#(" << RPI.FrameIdx;
2088 dbgs() <<
", " << RPI.FrameIdx + 1;
2093 !(Reg1 == AArch64::LR && Reg2 == AArch64::FP)) &&
2094 "Windows unwdinding requires a consecutive (FP,LR) pair");
2098 unsigned FrameIdxReg1 = RPI.FrameIdx;
2099 unsigned FrameIdxReg2 = RPI.FrameIdx + 1;
2105 if (RPI.isPaired() && RPI.isScalable()) {
2111 "Expects SVE2.1 or SME2 target and a predicate register");
2112#ifdef EXPENSIVE_CHECKS
2113 auto IsPPR = [](
const RegPairInfo &c) {
2114 return c.Reg1 == RegPairInfo::PPR;
2116 auto PPRBegin = std::find_if(RegPairs.
begin(), RegPairs.
end(), IsPPR);
2117 auto IsZPR = [](
const RegPairInfo &c) {
2118 return c.Type == RegPairInfo::ZPR;
2120 auto ZPRBegin = std::find_if(RegPairs.
begin(), RegPairs.
end(), IsZPR);
2121 assert(!(PPRBegin < ZPRBegin) &&
2122 "Expected callee save predicate to be handled first");
2124 if (!PTrueCreated) {
2125 PTrueCreated =
true;
2131 MBB.addLiveIn(Reg1);
2133 MBB.addLiveIn(Reg2);
2134 MIB.
addReg( AArch64::Z0_Z1 + (RPI.Reg1 - AArch64::Z0));
2151 MBB.addLiveIn(Reg1);
2152 if (RPI.isPaired()) {
2154 MBB.addLiveIn(Reg2);
2173 if (RPI.Type == RegPairInfo::ZPR) {
2177 }
else if (RPI.Type == RegPairInfo::PPR) {
2197 DL =
MBBI->getDebugLoc();
2200 if (homogeneousPrologEpilog(MF, &
MBB)) {
2203 for (
auto &RPI : RegPairs) {
2211 auto IsPPR = [](
const RegPairInfo &c) {
return c.Type == RegPairInfo::PPR; };
2213 auto PPREnd = std::find_if_not(PPRBegin, RegPairs.
end(), IsPPR);
2214 std::reverse(PPRBegin, PPREnd);
2215 auto IsZPR = [](
const RegPairInfo &c) {
return c.Type == RegPairInfo::ZPR; };
2217 auto ZPREnd = std::find_if_not(ZPRBegin, RegPairs.
end(), IsZPR);
2218 std::reverse(ZPRBegin, ZPREnd);
2220 bool PTrueCreated =
false;
2221 for (
const RegPairInfo &RPI : RegPairs) {
2234 unsigned Size =
TRI->getSpillSize(*RPI.RC);
2235 Align Alignment =
TRI->getSpillAlign(*RPI.RC);
2237 case RegPairInfo::GPR:
2238 LdrOpc = RPI.isPaired() ? AArch64::LDPXi : AArch64::LDRXui;
2240 case RegPairInfo::FPR64:
2241 LdrOpc = RPI.isPaired() ? AArch64::LDPDi : AArch64::LDRDui;
2243 case RegPairInfo::FPR128:
2244 LdrOpc = RPI.isPaired() ? AArch64::LDPQi : AArch64::LDRQui;
2246 case RegPairInfo::ZPR:
2247 LdrOpc = RPI.isPaired() ? AArch64::LD1B_2Z_IMM : AArch64::LDR_ZXI;
2249 case RegPairInfo::PPR:
2250 LdrOpc = AArch64::LDR_PXI;
2252 case RegPairInfo::VG:
2259 dbgs() <<
") -> fi#(" << RPI.FrameIdx;
2261 dbgs() <<
", " << RPI.FrameIdx + 1;
2268 unsigned FrameIdxReg1 = RPI.FrameIdx;
2269 unsigned FrameIdxReg2 = RPI.FrameIdx + 1;
2276 if (RPI.isPaired() && RPI.isScalable()) {
2281 "Expects SVE2.1 or SME2 target and a predicate register");
2282#ifdef EXPENSIVE_CHECKS
2283 assert(!(PPRBegin < ZPRBegin) &&
2284 "Expected callee save predicate to be handled first");
2286 if (!PTrueCreated) {
2287 PTrueCreated =
true;
2292 MIB.
addReg( AArch64::Z0_Z1 + (RPI.Reg1 - AArch64::Z0),
2309 if (RPI.isPaired()) {
2336 return std::optional<int>(PSV->getFrameIndex());
2347 return std::nullopt;
2353 if (!
MI.mayLoadOrStore() ||
MI.getNumMemOperands() < 1)
2354 return std::nullopt;
2361 return AArch64::PPRRegClass.contains(
MI.getOperand(0).getReg());
2367void AArch64FrameLowering::determineStackHazardSlot(
2370 auto *AFI = MF.
getInfo<AArch64FunctionInfo>();
2371 if (StackHazardSize == 0 || StackHazardSize % 16 != 0 ||
2385 return AArch64::FPR64RegClass.contains(Reg) ||
2386 AArch64::FPR128RegClass.contains(Reg) ||
2387 AArch64::ZPRRegClass.contains(Reg);
2390 return AArch64::PPRRegClass.contains(Reg);
2392 bool HasFPRStackObjects =
false;
2393 bool HasPPRStackObjects =
false;
2395 enum SlotType : uint8_t {
2406 for (
auto &
MBB : MF) {
2407 for (
auto &
MI :
MBB) {
2409 if (!FI || FI < 0 || FI >
int(SlotTypes.size()))
2416 ? SlotType::ZPRorFPR
2422 for (
int FI = 0; FI < int(SlotTypes.size()); ++FI) {
2423 HasFPRStackObjects |= SlotTypes[FI] == SlotType::ZPRorFPR;
2426 if (SlotTypes[FI] == SlotType::PPR) {
2428 HasPPRStackObjects =
true;
2433 if (HasFPRCSRs || HasFPRStackObjects) {
2436 << StackHazardSize <<
"\n");
2447 LLVM_DEBUG(
dbgs() <<
"Using SplitSVEObjects for SVE CC function\n");
2453 LLVM_DEBUG(
dbgs() <<
"Determining if SplitSVEObjects should be used in "
2454 "non-SVE CC function...\n");
2461 <<
"Calling convention is not supported with SplitSVEObjects\n");
2465 if (!HasPPRCSRs && !HasPPRStackObjects) {
2467 dbgs() <<
"Not using SplitSVEObjects as no PPRs are on the stack\n");
2471 if (!HasFPRCSRs && !HasFPRStackObjects) {
2474 <<
"Not using SplitSVEObjects as no FPRs or ZPRs are on the stack\n");
2478 [[maybe_unused]]
const AArch64Subtarget &Subtarget =
2479 MF.getSubtarget<AArch64Subtarget>();
2481 "Expected SVE to be available for PPRs");
2483 const TargetRegisterInfo *
TRI = MF.getSubtarget().getRegisterInfo();
2487 BitVector FPRZRegs(SavedRegs.
size());
2488 for (
size_t Reg = 0,
E = SavedRegs.
size(); HasFPRCSRs &&
Reg <
E; ++
Reg) {
2489 BitVector::reference RegBit = SavedRegs[
Reg];
2492 unsigned SubRegIdx = 0;
2494 SubRegIdx = AArch64::dsub;
2496 SubRegIdx = AArch64::zsub;
2503 TRI->getMatchingSuperReg(
Reg, SubRegIdx, &AArch64::ZPRRegClass);
2506 SavedRegs |= FPRZRegs;
2526 unsigned UnspilledCSGPR = AArch64::NoRegister;
2527 unsigned UnspilledCSGPRPaired = AArch64::NoRegister;
2533 RegInfo->hasBasePointer(MF) ? RegInfo->getBaseRegister() :
MCRegister();
2535 unsigned ExtraCSSpill = 0;
2536 bool HasUnpairedGPR64 =
false;
2537 bool HasPairZReg =
false;
2538 BitVector UserReservedRegs = RegInfo->getUserReservedRegs(MF);
2539 BitVector ReservedRegs = RegInfo->getReservedRegs(MF);
2542 for (
unsigned i = 0; CSRegs[i]; ++i) {
2546 if (Reg == BasePointerReg)
2551 if (UserReservedRegs[Reg]) {
2552 SavedRegs.
reset(Reg);
2556 bool RegUsed = SavedRegs.
test(Reg);
2558 const bool RegIsGPR64 = AArch64::GPR64RegClass.contains(Reg);
2559 if (RegIsGPR64 || AArch64::FPR64RegClass.
contains(Reg) ||
2560 AArch64::FPR128RegClass.
contains(Reg)) {
2563 if (HasUnpairedGPR64)
2564 PairedReg = CSRegs[i % 2 == 0 ? i - 1 : i + 1];
2566 PairedReg = CSRegs[i ^ 1];
2573 if (RegIsGPR64 && !AArch64::GPR64RegClass.
contains(PairedReg)) {
2574 PairedReg = AArch64::NoRegister;
2575 HasUnpairedGPR64 =
true;
2577 assert(PairedReg == AArch64::NoRegister ||
2578 AArch64::GPR64RegClass.
contains(Reg, PairedReg) ||
2579 AArch64::FPR64RegClass.
contains(Reg, PairedReg) ||
2580 AArch64::FPR128RegClass.
contains(Reg, PairedReg));
2583 if (AArch64::GPR64RegClass.
contains(Reg) && !ReservedRegs[Reg]) {
2584 UnspilledCSGPR = Reg;
2585 UnspilledCSGPRPaired = PairedReg;
2593 if (producePairRegisters(MF) && PairedReg != AArch64::NoRegister &&
2594 !SavedRegs.
test(PairedReg)) {
2595 SavedRegs.
set(PairedReg);
2596 if (AArch64::GPR64RegClass.
contains(PairedReg) &&
2597 !ReservedRegs[PairedReg])
2598 ExtraCSSpill = PairedReg;
2601 HasPairZReg |= (AArch64::ZPRRegClass.contains(Reg, CSRegs[i ^ 1]) &&
2602 SavedRegs.
test(CSRegs[i ^ 1]));
2610 if (PnReg.isValid())
2616 SavedRegs.
set(AArch64::P8);
2621 "Predicate cannot be a reserved register");
2631 SavedRegs.
set(AArch64::X18);
2637 determineStackHazardSlot(MF, SavedRegs);
2640 unsigned CSStackSize = 0;
2641 unsigned ZPRCSStackSize = 0;
2642 unsigned PPRCSStackSize = 0;
2644 for (
unsigned Reg : SavedRegs.
set_bits()) {
2646 assert(RC &&
"expected register class!");
2647 auto SpillSize =
TRI->getSpillSize(*RC);
2648 bool IsZPR = AArch64::ZPRRegClass.contains(Reg);
2649 bool IsPPR = !IsZPR && AArch64::PPRRegClass.contains(Reg);
2651 ZPRCSStackSize += SpillSize;
2653 PPRCSStackSize += SpillSize;
2655 CSStackSize += SpillSize;
2661 unsigned NumSavedRegs = SavedRegs.
count();
2674 SavedRegs.
set(AArch64::LR);
2679 windowsRequiresStackProbe(MF, EstimatedStackSize + CSStackSize + 16)) {
2680 SavedRegs.
set(AArch64::FP);
2681 SavedRegs.
set(AArch64::LR);
2685 dbgs() <<
"*** determineCalleeSaves\nSaved CSRs:";
2686 for (
unsigned Reg : SavedRegs.
set_bits())
2692 auto [ZPRLocalStackSize, PPRLocalStackSize] =
2694 uint64_t SVELocals = ZPRLocalStackSize + PPRLocalStackSize;
2696 alignTo(ZPRCSStackSize + PPRCSStackSize + SVELocals, 16);
2697 bool CanEliminateFrame = (SavedRegs.
count() == 0) && !SVEStackSize;
2706 int64_t CalleeStackUsed = 0;
2709 if (FixedOff > CalleeStackUsed)
2710 CalleeStackUsed = FixedOff;
2714 bool BigStack = SVEStackSize || (EstimatedStackSize + CSStackSize +
2715 CalleeStackUsed) > EstimatedStackSizeLimit;
2716 if (BigStack || !CanEliminateFrame || RegInfo->cannotEliminateFrame(MF))
2726 if (!ExtraCSSpill && UnspilledCSGPR != AArch64::NoRegister) {
2728 <<
" to get a scratch register.\n");
2729 SavedRegs.
set(UnspilledCSGPR);
2730 ExtraCSSpill = UnspilledCSGPR;
2735 if (producePairRegisters(MF)) {
2736 if (UnspilledCSGPRPaired == AArch64::NoRegister) {
2739 SavedRegs.
reset(UnspilledCSGPR);
2740 ExtraCSSpill = AArch64::NoRegister;
2743 SavedRegs.
set(UnspilledCSGPRPaired);
2752 unsigned Size =
TRI->getSpillSize(RC);
2753 Align Alignment =
TRI->getSpillAlign(RC);
2755 RS->addScavengingFrameIndex(FI);
2756 LLVM_DEBUG(
dbgs() <<
"No available CS registers, allocated fi#" << FI
2757 <<
" as the emergency spill slot.\n");
2762 CSStackSize += 8 * (SavedRegs.
count() - NumSavedRegs);
2771 << EstimatedStackSize + AlignedCSStackSize <<
" bytes.\n");
2775 "Should not invalidate callee saved info");
2786 std::vector<CalleeSavedInfo> &CSI)
const {
2795 std::reverse(CSI.begin(), CSI.end());
2815 find_if(CSI, [](
auto &Info) {
return Info.getReg() == AArch64::LR; });
2816 if (It != CSI.end())
2817 CSI.insert(It, VGInfo);
2819 CSI.push_back(VGInfo);
2823 int HazardSlotIndex = std::numeric_limits<int>::max();
2824 for (
auto &CS : CSI) {
2832 assert(HazardSlotIndex == std::numeric_limits<int>::max() &&
2833 "Unexpected register order for hazard slot");
2835 LLVM_DEBUG(
dbgs() <<
"Created CSR Hazard at slot " << HazardSlotIndex
2841 unsigned Size = RegInfo->getSpillSize(*RC);
2842 Align Alignment(RegInfo->getSpillAlign(*RC));
2844 CS.setFrameIdx(FrameIdx);
2849 Reg == AArch64::FP) {
2859 HazardSlotIndex == std::numeric_limits<int>::max()) {
2861 LLVM_DEBUG(
dbgs() <<
"Created CSR Hazard at slot " << HazardSlotIndex
2888 int &Min,
int &Max) {
2889 Min = std::numeric_limits<int>::max();
2890 Max = std::numeric_limits<int>::min();
2896 for (
auto &CS : CSI) {
2897 if (AArch64::ZPRRegClass.
contains(CS.getReg()) ||
2898 AArch64::PPRRegClass.contains(CS.getReg())) {
2899 assert((Max == std::numeric_limits<int>::min() ||
2900 Max + 1 == CS.getFrameIdx()) &&
2901 "SVE CalleeSaves are not consecutive");
2902 Min = std::min(Min, CS.getFrameIdx());
2903 Max = std::max(Max, CS.getFrameIdx());
2906 return Min != std::numeric_limits<int>::max();
2919 uint64_t &ZPRStackTop = SVEStack.ZPRStackSize;
2927 "SVE vectors should never be passed on the stack by value, only by "
2931 auto AllocateObject = [&](
int FI) {
2940 if (Alignment >
Align(16))
2942 "Alignment of scalable vectors > 16 bytes is not yet supported");
2945 StackTop =
alignTo(StackTop, Alignment);
2947 assert(StackTop < (
uint64_t)std::numeric_limits<int64_t>::max() &&
2948 "SVE StackTop far too large?!");
2950 int64_t
Offset = -int64_t(StackTop);
2958 int MinCSFrameIndex, MaxCSFrameIndex;
2960 for (
int FI = MinCSFrameIndex; FI <= MaxCSFrameIndex; ++FI)
2973 int StackProtectorFI = -1;
2977 ObjectsToAllocate.
push_back(StackProtectorFI);
2993 for (
unsigned FI : ObjectsToAllocate)
3008 "Upwards growing stack unsupported");
3023 int64_t CurrentOffset =
3027 int FrameIndex =
H.CatchObj.FrameIndex;
3028 if ((FrameIndex != INT_MAX) && MFI.
getObjectOffset(FrameIndex) == 0) {
3039 int64_t UnwindHelpOffset =
alignTo(CurrentOffset + 8,
Align(16));
3040 assert(UnwindHelpOffset == getFixedObjectSize(MF, AFI,
true,
3042 "UnwindHelpOffset must be at the start of the fixed object area");
3045 EHInfo.UnwindHelpFrameIdx = UnwindHelpFI;
3055 RS->enterBasicBlockEnd(
MBB);
3057 Register DstReg = RS->FindUnusedReg(&AArch64::GPR64commonRegClass);
3058 assert(DstReg &&
"There must be a free register after frame setup");
3069struct TagStoreInstr {
3077 MachineFunction *MF;
3078 MachineBasicBlock *
MBB;
3079 MachineRegisterInfo *MRI;
3088 StackOffset FrameRegOffset;
3092 std::optional<int64_t> FrameRegUpdate;
3094 unsigned FrameRegUpdateFlags;
3104 TagStoreEdit(MachineBasicBlock *
MBB,
bool ZeroData)
3105 :
MBB(
MBB), ZeroData(ZeroData) {
3111 void addInstruction(TagStoreInstr
I) {
3113 TagStores.
back().Offset + TagStores.
back().Size ==
I.Offset) &&
3114 "Non-adjacent tag store instructions.");
3117 void clear() { TagStores.
clear(); }
3122 const AArch64FrameLowering *TFI,
bool TryMergeSPUpdate);
3129 const int64_t kMinOffset = -256 * 16;
3130 const int64_t kMaxOffset = 255 * 16;
3133 int64_t BaseRegOffsetBytes = FrameRegOffset.
getFixed();
3134 if (BaseRegOffsetBytes < kMinOffset ||
3135 BaseRegOffsetBytes + (
Size -
Size % 32) > kMaxOffset ||
3139 BaseRegOffsetBytes % 16 != 0) {
3144 BaseRegOffsetBytes = 0;
3149 int64_t InstrSize = (
Size > 16) ? 32 : 16;
3152 ? (ZeroData ? AArch64::STZGi : AArch64::STGi)
3154 assert(BaseRegOffsetBytes % 16 == 0);
3158 .
addImm(BaseRegOffsetBytes / 16)
3162 if (BaseRegOffsetBytes == 0)
3164 BaseRegOffsetBytes += InstrSize;
3183 int64_t LoopSize =
Size;
3186 if (FrameRegUpdate && *FrameRegUpdate)
3187 LoopSize -= LoopSize % 32;
3189 TII->get(ZeroData ? AArch64::STZGloop_wback
3190 : AArch64::STGloop_wback))
3197 LoopI->
setFlags(FrameRegUpdateFlags);
3199 int64_t ExtraBaseRegUpdate =
3200 FrameRegUpdate ? (*FrameRegUpdate - FrameRegOffset.
getFixed() -
Size) : 0;
3201 LLVM_DEBUG(
dbgs() <<
"TagStoreEdit::emitLoop: LoopSize=" << LoopSize
3202 <<
", Size=" <<
Size
3203 <<
", ExtraBaseRegUpdate=" << ExtraBaseRegUpdate
3204 <<
", FrameRegUpdate=" << FrameRegUpdate
3205 <<
", FrameRegOffset.getFixed()="
3206 << FrameRegOffset.
getFixed() <<
"\n");
3207 if (LoopSize <
Size) {
3211 int64_t STGOffset = ExtraBaseRegUpdate + 16;
3212 assert(STGOffset % 16 == 0 && STGOffset >= -4096 && STGOffset <= 4080 &&
3213 "STG immediate out of range");
3215 TII->get(ZeroData ? AArch64::STZGPostIndex : AArch64::STGPostIndex))
3222 }
else if (ExtraBaseRegUpdate) {
3224 int64_t AddSubOffset = std::abs(ExtraBaseRegUpdate);
3225 assert(AddSubOffset <= 4095 &&
"ADD/SUB immediate out of range");
3228 TII->get(ExtraBaseRegUpdate > 0 ? AArch64::ADDXri : AArch64::SUBXri))
3241 int64_t
Size, int64_t *TotalOffset) {
3243 if ((
MI.getOpcode() == AArch64::ADDXri ||
3244 MI.getOpcode() == AArch64::SUBXri) &&
3245 MI.getOperand(0).getReg() ==
Reg &&
MI.getOperand(1).getReg() ==
Reg) {
3247 int64_t
Offset =
MI.getOperand(2).getImm() << Shift;
3248 if (
MI.getOpcode() == AArch64::SUBXri)
3259 const int64_t kMaxOffset = 4080 - 16;
3261 const int64_t kMinOffset = -4095;
3262 if (PostOffset <= kMaxOffset && PostOffset >= kMinOffset &&
3263 PostOffset % 16 == 0) {
3274 for (
auto &TS : TSE) {
3278 if (
MI->memoperands_empty()) {
3282 MemRefs.
append(
MI->memoperands_begin(),
MI->memoperands_end());
3288 bool TryMergeSPUpdate) {
3289 if (TagStores.
empty())
3291 TagStoreInstr &FirstTagStore = TagStores[0];
3292 TagStoreInstr &LastTagStore = TagStores[TagStores.
size() - 1];
3293 Size = LastTagStore.Offset - FirstTagStore.Offset + LastTagStore.Size;
3294 DL = TagStores[0].MI->getDebugLoc();
3298 *MF, FirstTagStore.Offset,
false ,
3302 FrameRegUpdate = std::nullopt;
3304 mergeMemRefs(TagStores, CombinedMemRefs);
3307 dbgs() <<
"Replacing adjacent STG instructions:\n";
3308 for (
const auto &Instr : TagStores) {
3317 if (TagStores.
size() < 2)
3319 emitUnrolled(InsertI);
3322 int64_t TotalOffset = 0;
3323 if (TryMergeSPUpdate) {
3329 if (InsertI !=
MBB->
end() &&
3330 canMergeRegUpdate(InsertI, FrameReg, FrameRegOffset.
getFixed() +
Size,
3332 UpdateInstr = &*InsertI++;
3338 if (!UpdateInstr && TagStores.
size() < 2)
3342 FrameRegUpdate = TotalOffset;
3343 FrameRegUpdateFlags = UpdateInstr->
getFlags();
3350 for (
auto &TS : TagStores)
3351 TS.MI->eraseFromParent();
3355 int64_t &
Size,
bool &ZeroData) {
3359 unsigned Opcode =
MI.getOpcode();
3360 ZeroData = (Opcode == AArch64::STZGloop || Opcode == AArch64::STZGi ||
3361 Opcode == AArch64::STZ2Gi);
3363 if (Opcode == AArch64::STGloop || Opcode == AArch64::STZGloop) {
3364 if (!
MI.getOperand(0).isDead() || !
MI.getOperand(1).isDead())
3366 if (!
MI.getOperand(2).isImm() || !
MI.getOperand(3).isFI())
3369 Size =
MI.getOperand(2).getImm();
3373 if (Opcode == AArch64::STGi || Opcode == AArch64::STZGi)
3375 else if (Opcode == AArch64::ST2Gi || Opcode == AArch64::STZ2Gi)
3380 if (
MI.getOperand(0).getReg() != AArch64::SP || !
MI.getOperand(1).isFI())
3384 16 *
MI.getOperand(2).getImm();
3388static size_t countAvailableScavengerSlots(
LivePhysRegs &LiveRegs,
3393 return LiveRegs.available(MRI,
Reg);
3396 size_t NumEmergencySlots = 0;
3398 NumEmergencySlots =
RS->getNumScavengingFrameIndices();
3400 return FreeGPRs + NumEmergencySlots;
3419 if (!isMergeableStackTaggingInstruction(
MI,
Offset,
Size, FirstZeroData))
3425 constexpr int kScanLimit = 10;
3428 NextI !=
E &&
Count < kScanLimit; ++NextI) {
3437 if (isMergeableStackTaggingInstruction(
MI,
Offset,
Size, ZeroData)) {
3438 if (ZeroData != FirstZeroData)
3446 if (!
MI.isTransient())
3455 if (
MI.mayLoadOrStore() ||
MI.hasUnmodeledSideEffects() ||
MI.isCall())
3471 LiveRegs.addLiveOuts(*
MBB);
3476 LiveRegs.stepBackward(*
I);
3479 if (LiveRegs.contains(AArch64::NZCV))
3490 dbgs() <<
"Failed to merge MTE stack tagging instructions into loop "
3491 <<
"due to high register pressure.\n");
3496 [](
const TagStoreInstr &
Left,
const TagStoreInstr &
Right) {
3501 int64_t CurOffset = Instrs[0].Offset;
3502 for (
auto &Instr : Instrs) {
3503 if (CurOffset >
Instr.Offset)
3510 TagStoreEdit TSE(
MBB, FirstZeroData);
3511 std::optional<int64_t> EndOffset;
3512 for (
auto &Instr : Instrs) {
3513 if (EndOffset && *EndOffset !=
Instr.Offset) {
3515 TSE.emitCode(InsertI, TFI,
false);
3519 TSE.addInstruction(Instr);
3538 II = tryMergeAdjacentSTG(
II,
this, RS);
3545 shouldSignReturnAddressEverywhere(MF))
3554 bool IgnoreSPUpdates)
const {
3556 if (IgnoreSPUpdates) {
3559 FrameReg = AArch64::SP;
3569 FrameReg = AArch64::SP;
3594 bool IsValid =
false;
3596 int ObjectIndex = 0;
3598 int GroupIndex = -1;
3600 bool ObjectFirst =
false;
3603 bool GroupFirst =
false;
3608 enum { AccessFPR = 1, AccessHazard = 2, AccessGPR = 4 };
3612 SmallVector<int, 8> CurrentMembers;
3613 int NextGroupIndex = 0;
3614 std::vector<FrameObject> &Objects;
3617 GroupBuilder(std::vector<FrameObject> &Objects) : Objects(Objects) {}
3618 void AddMember(
int Index) { CurrentMembers.
push_back(Index); }
3619 void EndCurrentGroup() {
3620 if (CurrentMembers.
size() > 1) {
3625 for (
int Index : CurrentMembers) {
3626 Objects[
Index].GroupIndex = NextGroupIndex;
3632 CurrentMembers.clear();
3636bool FrameObjectCompare(
const FrameObject &
A,
const FrameObject &
B) {
3658 return std::make_tuple(!
A.IsValid,
A.Accesses,
A.ObjectFirst,
A.GroupFirst,
3659 A.GroupIndex,
A.ObjectIndex) <
3660 std::make_tuple(!
B.IsValid,
B.Accesses,
B.ObjectFirst,
B.GroupFirst,
3661 B.GroupIndex,
B.ObjectIndex);
3670 ObjectsToAllocate.
empty())
3675 for (
auto &Obj : ObjectsToAllocate) {
3676 FrameObjects[Obj].IsValid =
true;
3677 FrameObjects[Obj].ObjectIndex = Obj;
3682 GroupBuilder GB(FrameObjects);
3683 for (
auto &
MBB : MF) {
3684 for (
auto &
MI :
MBB) {
3685 if (
MI.isDebugInstr())
3690 if (FI && *FI >= 0 && *FI < (
int)FrameObjects.size()) {
3693 FrameObjects[*FI].Accesses |= FrameObject::AccessFPR;
3695 FrameObjects[*FI].Accesses |= FrameObject::AccessGPR;
3700 switch (
MI.getOpcode()) {
3701 case AArch64::STGloop:
3702 case AArch64::STZGloop:
3706 case AArch64::STZGi:
3707 case AArch64::ST2Gi:
3708 case AArch64::STZ2Gi:
3721 FrameObjects[FI].IsValid)
3729 GB.AddMember(TaggedFI);
3731 GB.EndCurrentGroup();
3734 GB.EndCurrentGroup();
3739 FrameObject::AccessHazard;
3741 for (
auto &Obj : FrameObjects)
3742 if (!Obj.Accesses ||
3743 Obj.Accesses == (FrameObject::AccessGPR | FrameObject::AccessFPR))
3744 Obj.Accesses = FrameObject::AccessGPR;
3753 FrameObjects[*TBPI].ObjectFirst =
true;
3754 FrameObjects[*TBPI].GroupFirst =
true;
3755 int FirstGroupIndex = FrameObjects[*TBPI].GroupIndex;
3756 if (FirstGroupIndex >= 0)
3757 for (FrameObject &Object : FrameObjects)
3758 if (Object.GroupIndex == FirstGroupIndex)
3759 Object.GroupFirst =
true;
3765 for (
auto &Obj : FrameObjects) {
3769 ObjectsToAllocate[i++] = Obj.ObjectIndex;
3773 dbgs() <<
"Final frame order:\n";
3774 for (
auto &Obj : FrameObjects) {
3777 dbgs() <<
" " << Obj.ObjectIndex <<
": group " << Obj.GroupIndex;
3778 if (Obj.ObjectFirst)
3779 dbgs() <<
", first";
3781 dbgs() <<
", group-first";
3792AArch64FrameLowering::inlineStackProbeLoopExactMultiple(
3803 MF.
insert(MBBInsertPoint, LoopMBB);
3805 MF.
insert(MBBInsertPoint, ExitMBB);
3840 MBB.addSuccessor(LoopMBB);
3844 return ExitMBB->
begin();
3847void AArch64FrameLowering::inlineStackProbeFixed(
3852 const AArch64InstrInfo *
TII =
3854 AArch64FunctionInfo *AFI = MF.
getInfo<AArch64FunctionInfo>();
3859 int64_t ProbeSize = MF.
getInfo<AArch64FunctionInfo>()->getStackProbeSize();
3860 int64_t NumBlocks = FrameSize / ProbeSize;
3861 int64_t ResidualSize = FrameSize % ProbeSize;
3863 LLVM_DEBUG(
dbgs() <<
"Stack probing: total " << FrameSize <<
" bytes, "
3864 << NumBlocks <<
" blocks of " << ProbeSize
3865 <<
" bytes, plus " << ResidualSize <<
" bytes\n");
3870 for (
int i = 0; i < NumBlocks; ++i) {
3876 EmitAsyncCFI && !HasFP, CFAOffset);
3889 }
else if (NumBlocks != 0) {
3895 EmitAsyncCFI && !HasFP, CFAOffset);
3897 MBBI = inlineStackProbeLoopExactMultiple(
MBBI, ProbeSize, ScratchReg);
3899 if (EmitAsyncCFI && !HasFP) {
3902 .buildDefCFARegister(AArch64::SP);
3906 if (ResidualSize != 0) {
3912 EmitAsyncCFI && !HasFP, CFAOffset);
3933 SmallVector<MachineInstr *, 4> ToReplace;
3934 for (MachineInstr &
MI :
MBB)
3935 if (
MI.getOpcode() == AArch64::PROBED_STACKALLOC ||
3936 MI.getOpcode() == AArch64::PROBED_STACKALLOC_VAR)
3939 for (MachineInstr *
MI : ToReplace) {
3940 if (
MI->getOpcode() == AArch64::PROBED_STACKALLOC) {
3941 Register ScratchReg =
MI->getOperand(0).getReg();
3942 int64_t FrameSize =
MI->getOperand(1).getImm();
3944 MI->getOperand(3).getImm());
3945 inlineStackProbeFixed(
MI->getIterator(), ScratchReg, FrameSize,
3948 assert(
MI->getOpcode() == AArch64::PROBED_STACKALLOC_VAR &&
3949 "Stack probe pseudo-instruction expected");
3950 const AArch64InstrInfo *
TII =
3951 MI->getMF()->getSubtarget<AArch64Subtarget>().getInstrInfo();
3952 Register TargetReg =
MI->getOperand(0).getReg();
3953 (void)
TII->probedStackAlloc(
MI->getIterator(), TargetReg,
true);
3955 MI->eraseFromParent();
3975 return std::make_tuple(
start(),
Idx) <
3976 std::make_tuple(Rhs.
start(), Rhs.
Idx);
4006 << (
Offset.getFixed() < 0 ?
"" :
"+") <<
Offset.getFixed();
4007 if (
Offset.getScalable())
4008 OS << (
Offset.getScalable() < 0 ?
"" :
"+") <<
Offset.getScalable()
4019void AArch64FrameLowering::emitRemarks(
4022 auto *AFI = MF.
getInfo<AArch64FunctionInfo>();
4027 const uint64_t HazardSize =
4030 if (HazardSize == 0)
4038 std::vector<StackAccess> StackAccesses(MFI.
getNumObjects());
4040 size_t NumFPLdSt = 0;
4041 size_t NumNonFPLdSt = 0;
4044 for (
const MachineBasicBlock &
MBB : MF) {
4045 for (
const MachineInstr &
MI :
MBB) {
4046 if (!
MI.mayLoadOrStore() ||
MI.getNumMemOperands() < 1)
4048 for (MachineMemOperand *MMO :
MI.memoperands()) {
4055 StackAccesses[ArrIdx].Idx = FrameIdx;
4056 StackAccesses[ArrIdx].Offset =
4067 StackAccesses[ArrIdx].AccessTypes |= RegTy;
4078 if (NumFPLdSt == 0 || NumNonFPLdSt == 0)
4089 if (StackAccesses.front().isMixed())
4090 MixedObjects.push_back(&StackAccesses.front());
4092 for (
auto It = StackAccesses.begin(), End = std::prev(StackAccesses.end());
4094 const auto &
First = *It;
4095 const auto &Second = *(It + 1);
4097 if (Second.isMixed())
4098 MixedObjects.push_back(&Second);
4100 if ((
First.isSME() && Second.isCPU()) ||
4101 (
First.isCPU() && Second.isSME())) {
4102 uint64_t Distance =
static_cast<uint64_t
>(Second.start() -
First.end());
4103 if (Distance < HazardSize)
4108 auto EmitRemark = [&](llvm::StringRef Str) {
4110 auto R = MachineOptimizationRemarkAnalysis(
4111 "sme",
"StackHazard", MF.getFunction().getSubprogram(), &MF.front());
4112 return R <<
formatv(
"stack hazard in '{0}': ", MF.getName()).str() << Str;
4116 for (
const auto &
P : HazardPairs)
4117 EmitRemark(
formatv(
"{0} is too close to {1}", *
P.first, *
P.second).str());
4119 for (
const auto *Obj : MixedObjects)
4121 formatv(
"{0} accessed by both GP and FP instructions", *Obj).str());
static void getLiveRegsForEntryMBB(LivePhysRegs &LiveRegs, const MachineBasicBlock &MBB)
static const unsigned DefaultSafeSPDisplacement
This is the biggest offset to the stack pointer we can encode in aarch64 instructions (without using ...
static RegState getPrologueDeath(MachineFunction &MF, unsigned Reg)
static bool produceCompactUnwindFrame(const AArch64FrameLowering &, MachineFunction &MF)
static cl::opt< bool > StackTaggingMergeSetTag("stack-tagging-merge-settag", cl::desc("merge settag instruction in function epilog"), cl::init(true), cl::Hidden)
bool enableMultiVectorSpillFill(const AArch64Subtarget &Subtarget, MachineFunction &MF)
static std::optional< int > getLdStFrameID(const MachineInstr &MI, const MachineFrameInfo &MFI)
static cl::opt< bool > SplitSVEObjects("aarch64-split-sve-objects", cl::desc("Split allocation of ZPR & PPR objects"), cl::init(true), cl::Hidden)
static cl::opt< bool > StackHazardInNonStreaming("aarch64-stack-hazard-in-non-streaming", cl::init(false), cl::Hidden)
void computeCalleeSaveRegisterPairs(const AArch64FrameLowering &AFL, MachineFunction &MF, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI, SmallVectorImpl< RegPairInfo > &RegPairs, bool NeedsFrameRecord)
static cl::opt< bool > OrderFrameObjects("aarch64-order-frame-objects", cl::desc("sort stack allocations"), cl::init(true), cl::Hidden)
static cl::opt< bool > DisableMultiVectorSpillFill("aarch64-disable-multivector-spill-fill", cl::desc("Disable use of LD/ST pairs for SME2 or SVE2p1"), cl::init(false), cl::Hidden)
static cl::opt< bool > EnableRedZone("aarch64-redzone", cl::desc("enable use of redzone on AArch64"), cl::init(false), cl::Hidden)
static bool invalidateRegisterPairing(bool SpillExtendedVolatile, unsigned SpillCount, unsigned Reg1, unsigned Reg2, bool UsesWinAAPCS, bool NeedsWinCFI, bool NeedsFrameRecord, const TargetRegisterInfo *TRI)
Returns true if Reg1 and Reg2 cannot be paired using a ldp/stp instruction.
cl::opt< bool > EnableHomogeneousPrologEpilog("homogeneous-prolog-epilog", cl::Hidden, cl::desc("Emit homogeneous prologue and epilogue for the size " "optimization (default = off)"))
static bool isLikelyToHaveSVEStack(const AArch64FrameLowering &AFL, const MachineFunction &MF)
static bool invalidateWindowsRegisterPairing(bool SpillExtendedVolatile, unsigned SpillCount, unsigned Reg1, unsigned Reg2, bool NeedsWinCFI, const TargetRegisterInfo *TRI)
static SVEStackSizes determineSVEStackSizes(MachineFunction &MF, AssignObjectOffsets AssignOffsets)
Process all the SVE stack objects and the SVE stack size and offsets for each object.
static bool isTargetWindows(const MachineFunction &MF)
static unsigned estimateRSStackSizeLimit(MachineFunction &MF)
Look at each instruction that references stack frames and return the stack size limit beyond which so...
static bool getSVECalleeSaveSlotRange(const MachineFrameInfo &MFI, int &Min, int &Max)
returns true if there are any SVE callee saves.
static cl::opt< unsigned > StackHazardRemarkSize("aarch64-stack-hazard-remark-size", cl::init(0), cl::Hidden)
static MCRegister getRegisterOrZero(MCRegister Reg, bool HasSVE)
static unsigned getStackHazardSize(const MachineFunction &MF)
MCRegister findFreePredicateReg(BitVector &SavedRegs)
static bool isPPRAccess(const MachineInstr &MI)
static std::optional< int > getMMOFrameID(MachineMemOperand *MMO, const MachineFrameInfo &MFI)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declaration of the AArch64PrologueEmitter and AArch64EpilogueEmitter classes,...
static const int kSetTagLoopThreshold
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file contains the simple types necessary to represent the attributes associated with functions a...
#define CASE(ATTRNAME, AANAME,...)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
DXIL Forward Handle Accesses
const HexagonInstrInfo * TII
static std::string getTypeString(Type *T)
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
uint64_t IntrinsicInst * II
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
This file defines the SmallVector class.
void emitEpilogue()
Emit the epilogue.
StackOffset getSVEStackSize(const MachineFunction &MF) const
Returns the size of the entire SVE stackframe (PPRs + ZPRs).
StackOffset getZPRStackSize(const MachineFunction &MF) const
Returns the size of the entire ZPR stackframe (calleesaves + spills).
void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
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...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
bool enableFullCFIFixup(const MachineFunction &MF) const override
enableFullCFIFixup - Returns true if we may need to fix the unwind information such that it is accura...
StackOffset getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI) const override
getFrameIndexReferenceFromSP - This method returns the offset from the stack pointer to the slot of t...
bool enableCFIFixup(const MachineFunction &MF) const override
Returns true if we may need to fix the unwind information for the function.
StackOffset getNonLocalFrameIndexReference(const MachineFunction &MF, int FI) const override
getNonLocalFrameIndexReference - This method returns the offset used to reference a frame index locat...
TargetStackID::Value getStackIDForScalableVectors() const override
Returns the StackID that scalable vectors should be associated with.
friend class AArch64PrologueEmitter
bool hasFPImpl(const MachineFunction &MF) const override
hasFPImpl - Return true if the specified function should have a dedicated frame pointer register.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
friend class AArch64EpilogueEmitter
void resetCFIToInitialState(MachineBasicBlock &MBB) const override
Emit CFI instructions that recreate the state of the unwind information upon function entry.
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
bool hasSVECalleeSavesAboveFrameRecord(const MachineFunction &MF) const
StackOffset resolveFrameOffsetReference(const MachineFunction &MF, int64_t ObjectOffset, bool isFixed, TargetStackID::Value StackID, Register &FrameReg, bool PreferFP, bool ForSimm) const
bool canUseRedZone(const MachineFunction &MF) const
Can this function use the red zone for local allocations.
bool needsWinCFI(const MachineFunction &MF) const
bool isFPReserved(const MachineFunction &MF) const
Should the Frame Pointer be reserved for the current function?
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const
unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const
Funclets only need to account for space for the callee saved registers, as the locals are accounted f...
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack frame.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
StackOffset getPPRStackSize(const MachineFunction &MF) const
Returns the size of the entire PPR stackframe (calleesaves + spills + hazard padding).
int64_t getArgumentStackToRestore(MachineFunction &MF, MachineBasicBlock &MBB) const
Returns how much of the incoming argument stack area (in bytes) we should clean up in an epilogue.
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - Provide a base+offset reference to an FI slot for debug info.
StackOffset getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, Register &FrameReg, bool IgnoreSPUpdates) const override
For Win64 AArch64 EH, the offset to the Unwind object is from the SP before the update.
StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg, bool PreferFP, bool ForSimm) const
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...
bool requiresSaveVG(const MachineFunction &MF) const
void emitPacRetPlusLeafHardening(MachineFunction &MF) const
Harden the entire function with pac-ret.
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
unsigned getPPRCalleeSavedStackSize() const
void setHasStackFrame(bool s)
void setSwiftAsyncContextFrameIdx(int FI)
unsigned getTailCallReservedStack() const
unsigned getCalleeSavedStackSize(const MachineFrameInfo &MFI) const
void setCalleeSaveBaseToFrameRecordOffset(int Offset)
bool hasStackProbing() const
unsigned getArgumentStackToRestore() const
void setCalleeSaveStackHasFreeSpace(bool s)
int getCalleeSaveBaseToFrameRecordOffset() const
SignReturnAddress getSignReturnAddressCondition() const
bool hasStreamingModeChanges() const
void setPredicateRegForFillSpill(unsigned Reg)
int getStackHazardSlotIndex() const
void setCalleeSavedStackSize(unsigned Size)
void setSplitSVEObjects(bool s)
bool hasStackFrame() const
void setStackSizeSVE(uint64_t ZPR, uint64_t PPR)
std::optional< int > getTaggedBasePointerIndex() const
SMEAttrs getSMEFnAttrs() const
uint64_t getLocalStackSize() const
bool needsDwarfUnwindInfo(const MachineFunction &MF) const
unsigned getVarArgsGPRSize() const
uint64_t getStackSizePPR() const
bool hasSwiftAsyncContext() const
bool hasStackHazardSlotIndex() const
void setStackHazardSlotIndex(int Index)
unsigned getZPRCalleeSavedStackSize() const
void setStackHazardCSRSlotIndex(int Index)
unsigned getPredicateRegForFillSpill() const
void setSVECalleeSavedStackSize(unsigned ZPR, unsigned PPR)
bool hasCalculatedStackSizeSVE() const
uint64_t getStackSizeZPR() const
bool hasSVEStackSize() const
bool isStackHazardIncludedInCalleeSaveArea() const
unsigned getSVECalleeSavedStackSize() const
bool hasSplitSVEObjects() const
bool needsAsyncDwarfUnwindInfo(const MachineFunction &MF) const
bool hasCalleeSaveStackFreeSpace() const
static bool isTailCallReturnInst(const MachineInstr &MI)
Returns true if MI is one of the TCRETURN* instructions.
static bool isFpOrNEON(Register Reg)
Returns whether the physical register is FP or NEON.
void emitPrologue()
Emit the prologue.
bool isTargetWindows() const
const AArch64RegisterInfo * getRegisterInfo() const override
bool isNeonAvailable() const
Returns true if the target has NEON and the function at runtime is known to have NEON enabled (e....
const AArch64InstrInfo * getInstrInfo() const override
const AArch64TargetLowering * getTargetLowering() const override
bool isTargetMachO() const
bool isSVEorStreamingSVEAvailable() const
Returns true if the target has access to either the full range of SVE instructions,...
bool isStreaming() const
Returns true if the function has a streaming body.
bool hasInlineStackProbe(const MachineFunction &MF) const override
True if stack clash protection is enabled for this functions.
unsigned getRedZoneSize(const Function &F) const
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
bool test(unsigned Idx) const
Returns true if bit Idx is set.
BitVector & reset()
Reset all bits in the bitvector.
size_type count() const
Returns the number of bits which are set.
BitVector & set()
Set all bits in the bitvector.
iterator_range< const_set_bits_iterator > set_bits() const
size_type size() const
Returns the number of bits in this bitvector.
Helper class for creating CFI instructions and inserting them into MIR.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
AttributeList getAttributes() const
Return the attribute list for this Function.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
bool usesWindowsCFI() const
Wrapper class representing physical registers. Should be passed by value.
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
MachineInstr & instr_back()
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
reverse_iterator rbegin()
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
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 '...
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
LLVM_ABI 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 hasCalls() const
Return true if the current function has any function calls.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
bool isCalleeSavedObjectIndex(int ObjectIdx) const
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool hasScalableStackID(int ObjectIdx) const
int getStackProtectorIndex() const
Return the index for the stack protector object.
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
void setStackID(int ObjectIdx, uint8_t ID)
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool isMaxCallFrameSizeComputed() const
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment, TargetStackID::Value StackID=TargetStackID::Default)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
unsigned getNumObjects() const
Return the number of objects.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
bool hasStackObjects() const
Return true if there are any stack objects in this function.
uint8_t getStackID(int ObjectIdx) const
unsigned getNumFixedObjects() const
Return the number of fixed objects.
void setIsCalleeSavedObjectIndex(int ObjectIdx, bool IsCalleeSaved)
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
int getObjectIndexBegin() const
Return the minimum frame object index.
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, LLT MemTy, Align 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.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
bool hasEHFunclets() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & setMemRefs(ArrayRef< MachineMemOperand * > MMOs) const
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Representation of each machine instruction.
void setFlags(unsigned flags)
uint32_t getFlags() const
Return the MI flags bitvector.
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
A description of a memory reference used in the backend.
const PseudoSourceValue * getPseudoValue() const
@ MOVolatile
The memory access is volatile.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
const Value * getValue() const
Return the base address of the memory access.
MachineOperand class - Representation of each machine instruction operand.
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI void freezeReservedRegs()
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
LLVM_ABI bool isLiveIn(Register Reg) const
LLVM_ABI const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
LLVM_ABI bool isPhysRegUsed(MCRegister PhysReg, bool SkipRegMaskTest=false) const
Return true if the specified register is modified or read in this function.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
SMEAttrs is a utility class to parse the SME ACLE attributes on functions.
bool hasStreamingInterface() const
bool hasNonStreamingInterfaceAndBody() const
bool hasStreamingBody() const
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
int64_t getFixed() const
Returns the fixed component of the stack.
int64_t getScalable() const
Returns the scalable component of the stack.
static StackOffset get(int64_t Fixed, int64_t Scalable)
static StackOffset getScalable(int64_t Scalable)
static StackOffset getFixed(int64_t Fixed)
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
virtual bool enableCFIFixup(const MachineFunction &MF) const
Returns true if we may need to fix the unwind information for the function.
Primary interface to the complete machine description for the target machine.
const Triple & getTargetTriple() const
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
LLVM_ABI bool FramePointerIsReserved(const MachineFunction &MF) const
FramePointerIsReserved - This returns true if the frame pointer must always either point to a new fra...
LLVM_ABI bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Triple - Helper class for working with autoconf configuration names.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static unsigned getShiftValue(unsigned Imm)
getShiftValue - Extract the shift value.
static unsigned getArithExtendImm(AArch64_AM::ShiftExtendType ET, unsigned Imm)
getArithExtendImm - Encode the extend type and shift amount for an arithmetic instruction: imm: 3-bit...
const unsigned StackProbeMaxLoopUnroll
Maximum number of iterations to unroll for a constant size probing loop.
const unsigned StackProbeMaxUnprobedStack
Maximum allowed number of unprobed bytes above SP at an ABI boundary.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ AArch64_SVE_VectorCall
Used between AArch64 SVE functions.
@ PreserveMost
Used for runtime calls that preserves most registers.
@ CXX_FAST_TLS
Used for access functions.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
@ PreserveAll
Used for runtime calls that preserves (almost) all registers.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ PreserveNone
Used for runtime calls that preserves none general registers.
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
@ C
The default llvm calling convention, compatible with C.
@ ScalablePredicateVector
initializer< Ty > init(const Ty &Val)
NodeAddr< InstrNode * > Instr
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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.
RegState
Flags to represent properties of register accesses.
@ Define
Register definition.
@ LLVM_MARK_AS_BITMASK_ENUM
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ AArch64FrameOffsetCannotUpdate
Offset cannot apply.
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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, bool EmitCFAOffset=false, StackOffset InitialOffset={}, unsigned FrameReg=AArch64::SP)
emitFrameOffset - Emit instructions as needed to set DestReg to SrcReg plus Offset.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr RegState getDefRegState(bool B)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
void fullyRecomputeLiveIns(ArrayRef< MachineBasicBlock * > MBBs)
Convenience function for recomputing live-in's for a set of MBBs until the computation converges.
LLVM_ABI 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.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool operator<(const StackAccess &Rhs) const
void print(raw_ostream &OS) const
std::string getTypeString() const
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Pair of physical register and lane mask.
static LLVM_ABI MachinePointerInfo getUnknownStack(MachineFunction &MF)
Stack memory without other information.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
SmallVector< WinEHHandlerType, 1 > HandlerArray