159#define DEBUG_TYPE "arm-frame-lowering"
165 unsigned NumAlignedDPRCS2Regs);
180 unsigned NumAlignedDPRCS2Regs,
279 if (
Reg >= ARM::D8 &&
Reg < ARM::D8 + NumAlignedDPRCS2Regs)
365 if (CFSize >= ((1 << 12) - 1) / 2)
388 bool IsTailCallReturn =
false;
390 unsigned RetOpcode =
MBBI->getOpcode();
391 IsTailCallReturn = RetOpcode == ARM::TCRETURNdi ||
392 RetOpcode == ARM::TCRETURNri ||
393 RetOpcode == ARM::TCRETURNrinotr12;
397 int ArgumentPopSize = 0;
398 if (IsTailCallReturn) {
404 ArgumentPopSize = StackAdjust.
getImm();
413 return ArgumentPopSize;
421 unsigned Opc =
MBBI->getOpcode();
447 case ARM::t2MOVi16: {
448 bool Wide =
MBBI->getOperand(1).getImm() >= 256;
452 NewInstr.
add(
MBBI->getOperand(0));
470 case ARM::t2MOVi32imm:
488 if (
MBBI->getOperand(0).getReg() == ARM::SP &&
489 MBBI->getOperand(2).getReg() == ARM::SP &&
490 MBBI->getOperand(3).getImm() == -4) {
491 unsigned Reg =
RegInfo->getSEHRegNum(
MBBI->getOperand(1).getReg());
501 case ARM::t2LDR_POST:
502 if (
MBBI->getOperand(1).getReg() == ARM::SP &&
503 MBBI->getOperand(2).getReg() == ARM::SP &&
504 MBBI->getOperand(3).getImm() == 4) {
505 unsigned Reg =
RegInfo->getSEHRegNum(
MBBI->getOperand(0).getReg());
515 case ARM::t2LDMIA_RET:
516 case ARM::t2LDMIA_UPD:
517 case ARM::t2STMDB_UPD: {
527 if (
Reg >= 8 &&
Reg <= 13)
529 else if (
Opc == ARM::t2LDMIA_UPD &&
Reg == 14)
536 case ARM::t2LDMIA_RET:
537 NewOpc = ARM::tPOP_RET;
539 case ARM::t2LDMIA_UPD:
542 case ARM::t2STMDB_UPD:
551 NewInstr.
add(
MBBI->getOperand(i));
557 (
Opc == ARM::t2LDMIA_RET) ? ARM::SEH_SaveRegs_Ret : ARM::SEH_SaveRegs;
564 case ARM::VSTMDDB_UPD:
565 case ARM::VLDMDIA_UPD: {
568 unsigned Reg =
RegInfo->getSEHRegNum(MO.getReg());
586 case ARM::t2SUBspImm:
587 case ARM::t2SUBspImm12:
588 case ARM::t2ADDspImm:
589 case ARM::t2ADDspImm12:
597 if (
MBBI->getOperand(1).getReg() == ARM::SP &&
599 unsigned Reg =
RegInfo->getSEHRegNum(
MBBI->getOperand(0).getReg());
603 }
else if (
MBBI->getOperand(0).getReg() == ARM::SP &&
605 unsigned Reg =
RegInfo->getSEHRegNum(
MBBI->getOperand(1).getReg());
615 case ARM::t2BXAUT_RET:
616 case ARM::CLEANUPRET:
618 case ARM::TCRETURNri:
619 case ARM::TCRETURNrinotr12:
625 case ARM::TCRETURNdi:
631 return MBB->insertAfter(
MBBI, MIB);
638 return std::prev(
MBBI);
646 Start = std::next(Start);
650 for (
auto MI = Start;
MI !=
End;) {
651 auto Next = std::next(
MI);
683 unsigned PredReg = 0) {
685 MIFlags,
Pred, PredReg);
690 switch (
MI.getOpcode()) {
691 case ARM::VSTMDDB_UPD:
695 case ARM::t2STMDB_UPD:
699 case ARM::STR_PRE_IMM:
708 for (
int i =
MI.getNumOperands() - 1; i >= 4; --i)
714 size_t StackSizeInBytes) {
720 F.getFnAttributeAsParsedInteger(
"stack-probe-size", StackProbeSize);
721 return (StackSizeInBytes >= StackProbeSize) &&
722 !
F.hasFnAttribute(
"no-stack-arg-probe");
727struct StackAdjustingInsts {
733#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
735 dbgs() <<
" " << (BeforeFPSet ?
"before-fp " :
" ")
736 <<
"sp-adjust=" << SPAdjust;
745 bool BeforeFPSet =
false) {
746 InstInfo
Info = {
I, SPAdjust, BeforeFPSet};
753 assert(Info != Insts.
end() &&
"invalid sp adjusting instruction");
754 Info->SPAdjust += ExtraBytes;
757 void emitDefCFAOffsets(MachineBasicBlock &
MBB,
bool HasFP) {
759 unsigned CFAOffset = 0;
760 for (
auto &Info : Insts) {
761 if (HasFP && !
Info.BeforeFPSet)
764 CFAOffset +=
Info.SPAdjust;
765 CFIBuilder.setInsertPoint(std::next(
Info.I));
766 CFIBuilder.buildDefCFAOffset(CFAOffset);
770#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
772 dbgs() <<
"StackAdjustingInsts:\n";
773 for (
auto &Info : Insts)
793 const Align Alignment,
794 const bool MustBeSingleInstruction) {
796 const bool CanUseBFC = AST.hasV6T2Ops() || AST.hasV7Ops();
797 const unsigned AlignMask = Alignment.value() - 1U;
798 const unsigned NrBitsToZero =
Log2(Alignment);
815 }
else if (AlignMask <= 255) {
822 assert(!MustBeSingleInstruction &&
823 "Shouldn't call emitAligningInstructions demanding a single "
824 "instruction to be emitted for large stack alignment for a target "
864 int MaxRegBytes = 8 * 4;
867 MaxRegBytes = 11 * 4;
870 MaxRegBytes = 11 * 4 + 8 * 8;
886 "This emitPrologue does not support Thumb1!");
888 Align Alignment =
STI.getFrameLowering()->getStackAlign();
892 int FPCXTSaveSize = 0;
895 STI.getPushPopSplitVariation(MF);
907 unsigned GPRCS1Size = 0, GPRCS2Size = 0, FPStatusSize = 0,
908 DPRCS1Size = 0, GPRCS3Size = 0, DPRCS2Size = 0;
909 int FramePtrSpillFI = 0;
917 StackAdjustingInsts DefCFAOffsetCandidates;
918 bool HasFP =
hasFP(MF);
925 DefCFAOffsetCandidates.addInst(std::prev(
MBBI), NumBytes,
true);
928 DefCFAOffsetCandidates.emitDefCFAOffsets(
MBB, HasFP);
929 if (NeedsWinCFI &&
MBBI !=
MBB.begin()) {
940 bool BeforeFPPush =
true;
943 int FI =
I.getFrameIdx();
949 FramePtrSpillFI = FI;
950 FramePtrSpillArea = Area;
981 DPRCS1Push, GPRCS3Push;
988 if (FPCXTSaveSize > 0) {
990 DefCFAOffsetCandidates.addInst(LastPush, FPCXTSaveSize, BeforeFPPush);
994 if (ArgRegsSaveSize) {
997 LastPush = std::prev(
MBBI);
998 DefCFAOffsetCandidates.addInst(LastPush, ArgRegsSaveSize, BeforeFPPush);
1002 if (GPRCS1Size > 0) {
1003 GPRCS1Push = LastPush =
MBBI++;
1004 DefCFAOffsetCandidates.addInst(LastPush, GPRCS1Size, BeforeFPPush);
1006 BeforeFPPush =
false;
1013 unsigned FPCXTOffset = NumBytes - ArgRegsSaveSize - FPCXTSaveSize;
1014 unsigned GPRCS1Offset = FPCXTOffset - GPRCS1Size;
1015 unsigned GPRCS2Offset = GPRCS1Offset - GPRCS2Size;
1016 unsigned FPStatusOffset = GPRCS2Offset - FPStatusSize;
1018 Align DPRAlign = DPRCS1Size ? std::min(
Align(8), Alignment) :
Align(4);
1019 unsigned DPRGapSize = (ArgRegsSaveSize + FPCXTSaveSize + GPRCS1Size +
1020 GPRCS2Size + FPStatusSize) %
1023 unsigned DPRCS1Offset = FPStatusOffset - DPRGapSize - DPRCS1Size;
1029 <<
", FPOffset: " << FPOffset <<
"\n");
1031 "Max FP estimation is wrong");
1040 if (GPRCS2Size > 0) {
1042 GPRCS2Push = LastPush =
MBBI++;
1043 DefCFAOffsetCandidates.addInst(LastPush, GPRCS2Size, BeforeFPPush);
1045 BeforeFPPush =
false;
1049 if (FPStatusSize > 0) {
1051 unsigned Opc =
MBBI->getOpcode();
1052 if (
Opc == ARM::VMRS ||
Opc == ARM::VMRS_FPEXC)
1058 DefCFAOffsetCandidates.addInst(LastPush, FPStatusSize);
1064 assert(DPRGapSize == 4 &&
"unexpected alignment requirements for DPRs");
1065 if (LastPush !=
MBB.end() &&
1067 DefCFAOffsetCandidates.addExtraBytes(LastPush, DPRGapSize);
1071 DefCFAOffsetCandidates.addInst(std::prev(
MBBI), DPRGapSize, BeforeFPPush);
1076 if (DPRCS1Size > 0) {
1079 while (
MBBI !=
MBB.end() &&
MBBI->getOpcode() == ARM::VSTMDDB_UPD) {
1082 DPRCS1Push = LastPush =
MBBI++;
1087 if (DPRCS2Size > 0) {
1095 NumBytes = DPRCS1Offset;
1098 if (GPRCS3Size > 0) {
1100 GPRCS3Push = LastPush =
MBBI++;
1101 DefCFAOffsetCandidates.addInst(LastPush, GPRCS3Size, BeforeFPPush);
1103 BeforeFPPush =
false;
1104 NumBytes -= GPRCS3Size;
1107 bool NeedsWinCFIStackAlloc = NeedsWinCFI;
1109 NeedsWinCFIStackAlloc =
false;
1114 if (NumWords < 65536) {
1124 .
addImm(NumWords & 0xffff)
1135 RTLIB::LibcallImpl ChkStkLibcall =
TLI->getLibcallImpl(RTLIB::STACK_PROBE);
1136 if (ChkStkLibcall == RTLIB::Unsupported)
1138 const char *ChkStk =
TLI->getLibcallImplName(ChkStkLibcall).data();
1140 switch (TM.getCodeModel()) {
1172 if (NeedsWinCFIStackAlloc) {
1173 SEH =
BuildMI(MF, dl,
TII.get(ARM::SEH_StackAlloc))
1177 MBB.insertAfter(Instr, SEH);
1186 DefCFAOffsetCandidates.addExtraBytes(LastPush, NumBytes);
1190 DefCFAOffsetCandidates.addInst(std::prev(
MBBI), NumBytes);
1216 int64_t FPOffsetAfterPush;
1217 switch (FramePtrSpillArea) {
1219 FPPushInst = GPRCS1Push;
1221 ArgRegsSaveSize + FPCXTSaveSize +
1224 << FPOffsetAfterPush <<
" after that push\n");
1227 FPPushInst = GPRCS2Push;
1229 ArgRegsSaveSize + FPCXTSaveSize + GPRCS1Size +
1232 << FPOffsetAfterPush <<
" after that push\n");
1235 FPPushInst = GPRCS3Push;
1237 ArgRegsSaveSize + FPCXTSaveSize + GPRCS1Size +
1238 FPStatusSize + GPRCS2Size + DPRCS1Size + DPRGapSize +
1241 << FPOffsetAfterPush <<
" after that push\n");
1247 AfterPush = std::next(FPPushInst);
1249 assert(FPOffsetAfterPush == 0);
1253 FramePtr, ARM::SP, FPOffsetAfterPush,
1260 if (FPOffsetAfterPush != 0)
1269 if (NeedsWinCFI &&
MBBI !=
MBB.begin()) {
1283 for (
const auto &Entry :
reverse(CSI)) {
1285 int FI = Entry.getFrameIdx();
1290 CFIPos = std::next(GPRCS1Push);
1293 CFIPos = std::next(GPRCS2Push);
1296 CFIPos = std::next(DPRCS1Push);
1299 CFIPos = std::next(GPRCS3Push);
1310 .
buildOffset(Reg == ARM::R12 ? ARM::RA_AUTH_CODE : Reg,
1322 DefCFAOffsetCandidates.emitDefCFAOffsets(
MBB, HasFP);
1325 if (
STI.isTargetELF() &&
hasFP(MF))
1373 if (RegInfo->hasBasePointer(MF) && !
MBB.isEHFuncletEntry()) {
1400 "This emitEpilogue does not support Thumb1!");
1403 STI.getPushPopSplitVariation(MF);
1434 if (NumBytes + IncomingArgStackToRestore != 0)
1436 NumBytes + IncomingArgStackToRestore,
1443 }
while (
MBBI !=
MBB.begin() &&
1480 "No scratch register to restore SP from FP!");
1502 }
else if (NumBytes &&
1518 while (
MBBI !=
MBB.end() &&
MBBI->getOpcode() == ARM::VLDMDIA_UPD)
1523 "unexpected DPR alignment gap");
1535 if (ReservedArgStack || IncomingArgStackToRestore) {
1536 assert((
int)ReservedArgStack + IncomingArgStackToRestore >= 0 &&
1537 "attempting to restore negative stack amount");
1539 ReservedArgStack + IncomingArgStackToRestore,
1549 STI.isThumb() &&
STI.hasV8_1MMainlineOps() &&
STI.hasPACBTI();
1550 auto TMBBI =
MBB.getFirstTerminator();
1552 TMBBI !=
MBB.end() && TMBBI->getOpcode() == ARM::tBX_RET;
1553 if (IsBXReturn && CanUseBXAut)
1554 TMBBI->setDesc(
STI.getInstrInfo()->get(ARM::t2BXAUT_RET));
1605 if (RegInfo->hasStackRealignment(MF)) {
1606 assert(
hasFP(MF) &&
"dynamic stack realignment without a FP!");
1608 FrameReg = RegInfo->getFrameRegister(MF);
1610 }
else if (hasMovingSP) {
1611 assert(RegInfo->hasBasePointer(MF) &&
1612 "VLAs and dynamic stack alignment, but missing base pointer!");
1613 FrameReg = RegInfo->getBaseRegister();
1623 if (isFixed || (hasMovingSP && !RegInfo->hasBasePointer(MF))) {
1624 FrameReg = RegInfo->getFrameRegister(MF);
1626 }
else if (hasMovingSP) {
1627 assert(RegInfo->hasBasePointer(MF) &&
"missing base pointer!");
1632 if (FPOffset >= -255 && FPOffset < 0) {
1633 FrameReg = RegInfo->getFrameRegister(MF);
1648 FrameReg = RegInfo->getFrameRegister(MF);
1651 }
else if (
Offset > (FPOffset < 0 ? -FPOffset : FPOffset)) {
1653 FrameReg = RegInfo->getFrameRegister(MF);
1660 if (RegInfo->hasBasePointer(MF)) {
1661 FrameReg = RegInfo->getBaseRegister();
1670 unsigned StmOpc,
unsigned StrOpc,
1679 using RegAndKill = std::pair<unsigned, bool>;
1682 unsigned i = CSI.
size();
1684 unsigned LastReg = 0;
1685 for (; i != 0; --i) {
1691 bool isLiveIn =
MRI.isLiveIn(Reg);
1692 if (!isLiveIn && !
MRI.isReserved(Reg))
1697 if (NoGap && LastReg && LastReg != Reg-1)
1705 Regs.
push_back(std::make_pair(Reg, !isLiveIn));
1712 return TRI.getEncodingValue(
LHS.first) <
TRI.getEncodingValue(
RHS.first);
1715 if (Regs.
size() > 1 || StrOpc== 0) {
1720 for (
const auto &[
Reg,
Kill] : Regs)
1722 }
else if (Regs.size() == 1) {
1743 unsigned LdmOpc,
unsigned LdrOpc,
1744 bool isVarArg,
bool NoGap,
1748 const TargetRegisterInfo &
TRI = *
STI.getRegisterInfo();
1749 ARMFunctionInfo *AFI = MF.
getInfo<ARMFunctionInfo>();
1752 bool isTailCall =
false;
1753 bool isInterrupt =
false;
1754 bool isTrap =
false;
1755 bool isCmseEntry =
false;
1757 STI.getPushPopSplitVariation(MF);
1759 DL =
MI->getDebugLoc();
1760 unsigned RetOpcode =
MI->getOpcode();
1762 (RetOpcode == ARM::TCRETURNdi || RetOpcode == ARM::TCRETURNri ||
1763 RetOpcode == ARM::TCRETURNrinotr12);
1765 RetOpcode == ARM::SUBS_PC_LR || RetOpcode == ARM::t2SUBS_PC_LR;
1766 isTrap = RetOpcode == ARM::TRAP || RetOpcode == ARM::tTRAP;
1767 isCmseEntry = (RetOpcode == ARM::tBXNS || RetOpcode == ARM::tBXNS_RET);
1770 SmallVector<unsigned, 4> Regs;
1771 unsigned i = CSI.
size();
1773 unsigned LastReg = 0;
1774 bool DeleteRet =
false;
1775 for (; i != 0; --i) {
1776 CalleeSavedInfo &
Info = CSI[i-1];
1777 MCRegister
Reg =
Info.getReg();
1781 if (
Reg == ARM::LR && !isTailCall && !isVarArg && !isInterrupt &&
1795 if (NoGap && LastReg && LastReg !=
Reg-1)
1806 return TRI.getEncodingValue(
LHS) <
TRI.getEncodingValue(
RHS);
1809 if (Regs.
size() > 1 || LdrOpc == 0) {
1814 for (
unsigned Reg : Regs)
1823 }
else if (Regs.size() == 1) {
1826 if (Regs[0] == ARM::PC)
1828 MachineInstrBuilder MIB =
1835 if (LdrOpc == ARM::LDR_POST_REG || LdrOpc == ARM::LDR_POST_IMM) {
1854 unsigned PushOpc)
const {
1859 auto RegPresent = [&CSI](MCRegister
Reg) {
1861 return C.getReg() ==
Reg;
1867 if (RegPresent(ARM::FPSCR)) {
1877 if (RegPresent(ARM::FPEXC)) {
1886 if (Regs.
size() == 0)
1890 MachineInstrBuilder MIB =
1901void ARMFrameLowering::emitFPStatusRestores(
1907 auto RegPresent = [&CSI](MCRegister
Reg) {
1909 return C.getReg() ==
Reg;
1914 if (!RegPresent(ARM::FPSCR) && !RegPresent(ARM::FPEXC))
1918 MachineInstrBuilder MIB =
1925 if (RegPresent(ARM::FPSCR)) {
1930 if (RegPresent(ARM::FPEXC)) {
1935 if (RegPresent(ARM::FPSCR)) {
1944 if (RegPresent(ARM::FPEXC)) {
1957 unsigned NumAlignedDPRCS2Regs,
1970 unsigned DNum =
I.getReg() - ARM::D8;
1971 if (DNum > NumAlignedDPRCS2Regs - 1)
1973 int FI =
I.getFrameIdx();
2001 unsigned Opc =
isThumb ? ARM::t2SUBri : ARM::SUBri;
2004 .
addImm(8 * NumAlignedDPRCS2Regs)
2029 unsigned NextReg = ARM::D8;
2033 if (NumAlignedDPRCS2Regs >= 6) {
2035 TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, &ARM::QQPRRegClass);
2036 MBB.addLiveIn(SupReg);
2044 NumAlignedDPRCS2Regs -= 4;
2049 unsigned R4BaseReg = NextReg;
2052 if (NumAlignedDPRCS2Regs >= 4) {
2054 TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, &ARM::QQPRRegClass);
2055 MBB.addLiveIn(SupReg);
2063 NumAlignedDPRCS2Regs -= 4;
2067 if (NumAlignedDPRCS2Regs >= 2) {
2069 TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, &ARM::QPRRegClass);
2070 MBB.addLiveIn(SupReg);
2077 NumAlignedDPRCS2Regs -= 2;
2081 if (NumAlignedDPRCS2Regs) {
2082 MBB.addLiveIn(NextReg);
2087 .
addImm((NextReg - R4BaseReg) * 2)
2092 std::prev(
MI)->addRegisterKilled(ARM::R4,
TRI);
2099 unsigned NumAlignedDPRCS2Regs) {
2104 assert(
MI->mayStore() &&
"Expecting spill instruction");
2107 switch(NumAlignedDPRCS2Regs) {
2110 assert(
MI->mayStore() &&
"Expecting spill instruction");
2114 assert(
MI->mayStore() &&
"Expecting spill instruction");
2119 assert(
MI->killsRegister(ARM::R4,
nullptr) &&
"Missed kill flag");
2130 unsigned NumAlignedDPRCS2Regs,
2141 if (
I.getReg() == ARM::D8) {
2142 D8SpillFI =
I.getFrameIdx();
2154 unsigned Opc =
isThumb ? ARM::t2ADDri : ARM::ADDri;
2162 unsigned NextReg = ARM::D8;
2165 if (NumAlignedDPRCS2Regs >= 6) {
2167 TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, &ARM::QQPRRegClass);
2175 NumAlignedDPRCS2Regs -= 4;
2180 unsigned R4BaseReg = NextReg;
2183 if (NumAlignedDPRCS2Regs >= 4) {
2185 TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, &ARM::QQPRRegClass);
2192 NumAlignedDPRCS2Regs -= 4;
2196 if (NumAlignedDPRCS2Regs >= 2) {
2198 TRI->getMatchingSuperReg(NextReg, ARM::dsub_0, &ARM::QPRRegClass);
2204 NumAlignedDPRCS2Regs -= 2;
2208 if (NumAlignedDPRCS2Regs)
2211 .
addImm(2 * (NextReg - R4BaseReg))
2227 STI.getPushPopSplitVariation(MF);
2230 unsigned PushOpc = AFI->
isThumbFunction() ? ARM::t2STMDB_UPD : ARM::STMDB_UPD;
2232 ARM::t2STR_PRE : ARM::STR_PRE_IMM;
2233 unsigned FltOpc = ARM::VSTMDDB_UPD;
2242 return C.getReg() == ARM::FPCXTNS;
2251 auto CheckRegArea = [PushPopSplit, NumAlignedDPRCS2Regs,
2252 RegInfo](
unsigned Reg,
SpillArea TestArea) {
2253 return getSpillArea(Reg, PushPopSplit, NumAlignedDPRCS2Regs, RegInfo) ==
2256 auto IsGPRCS1 = [&CheckRegArea](
unsigned Reg) {
2259 auto IsGPRCS2 = [&CheckRegArea](
unsigned Reg) {
2262 auto IsDPRCS1 = [&CheckRegArea](
unsigned Reg) {
2265 auto IsGPRCS3 = [&CheckRegArea](
unsigned Reg) {
2269 emitPushInst(
MBB,
MI, CSI, PushOpc, PushOneOpc,
false, IsGPRCS1);
2270 emitPushInst(
MBB,
MI, CSI, PushOpc, PushOneOpc,
false, IsGPRCS2);
2271 emitFPStatusSaves(
MBB,
MI, CSI, PushOpc);
2272 emitPushInst(
MBB,
MI, CSI, FltOpc, 0,
true, IsDPRCS1);
2273 emitPushInst(
MBB,
MI, CSI, PushOpc, PushOneOpc,
false, IsGPRCS3);
2278 if (NumAlignedDPRCS2Regs)
2297 STI.getPushPopSplitVariation(MF);
2301 if (NumAlignedDPRCS2Regs)
2304 unsigned PopOpc = AFI->
isThumbFunction() ? ARM::t2LDMIA_UPD : ARM::LDMIA_UPD;
2307 unsigned FltOpc = ARM::VLDMDIA_UPD;
2309 auto CheckRegArea = [PushPopSplit, NumAlignedDPRCS2Regs,
2310 RegInfo](
unsigned Reg,
SpillArea TestArea) {
2311 return getSpillArea(Reg, PushPopSplit, NumAlignedDPRCS2Regs, RegInfo) ==
2314 auto IsGPRCS1 = [&CheckRegArea](
unsigned Reg) {
2317 auto IsGPRCS2 = [&CheckRegArea](
unsigned Reg) {
2320 auto IsDPRCS1 = [&CheckRegArea](
unsigned Reg) {
2323 auto IsGPRCS3 = [&CheckRegArea](
unsigned Reg) {
2327 emitPopInst(
MBB,
MI, CSI, PopOpc, LdrOpc, isVarArg,
false, IsGPRCS3);
2328 emitPopInst(
MBB,
MI, CSI, FltOpc, 0, isVarArg,
true, IsDPRCS1);
2329 emitFPStatusRestores(
MBB,
MI, CSI, PopOpc);
2330 emitPopInst(
MBB,
MI, CSI, PopOpc, LdrOpc, isVarArg,
false, IsGPRCS2);
2331 emitPopInst(
MBB,
MI, CSI, PopOpc, LdrOpc, isVarArg,
false, IsGPRCS1);
2342 bool BigFrameOffsets) {
2343 unsigned FnSize = 0;
2356 unsigned SavedHighRegs = 0;
2357 for (
auto Reg : {ARM::R8, ARM::R9, ARM::R10, ARM::R11, ARM::R12})
2370 unsigned PrologueSize = 2 + 4 * SavedHighRegs + 6 + 12 + 2;
2371 if (
RegInfo->hasStackRealignment(MF))
2373 FnSize += PrologueSize;
2382 unsigned EpilogueSize = 6 + 2 + 4 * SavedHighRegs + 4 + 2 + 2;
2384 bool FirstBlock =
true;
2385 for (
auto &
MBB : MF) {
2389 unsigned Alignment =
MBB.getMaxBytesForAlignment();
2390 FnSize += Alignment;
2393 unsigned SizeBeforeThisBB = FnSize;
2395 bool seenBranch =
false, seenConstantLoad =
false;
2396 for (
auto &
MI :
MBB) {
2398 switch (
MI.getOpcode()) {
2399 case ARM::tADDframe:
2400 if (BigFrameOffsets)
2411 if (BigFrameOffsets)
2421 case TargetOpcode::COPY:
2432 case ARM::Int_eh_sjlj_dispatchsetup:
2437 case ARM::tLDRpci_pic:
2441 case ARM::ADJCALLSTACKDOWN:
2442 case ARM::ADJCALLSTACKUP:
2446 case ARM::tBLXNS_CALL:
2451 InstSize = 2 + 2 * 4 + 2;
2466 InstSize += 2 + 2 * 4 + 2;
2469 case ARM::tBXNS_RET:
2473 InstSize = 5 * 2 + 4 + 2;
2476 case TargetOpcode::LOAD_STACK_GUARD:
2477 if (STI.genExecuteOnly())
2483 InstSize = 7 * 2 + 2 * 4 + 8;
2488 InstSize = 2 * 2 + 4;
2492 InstSize =
TII.getInstSizeInBytes(
MI);
2503 MO->getPointerInfo().V);
2505 unsigned ConstSize = MO->getType().getSizeInBytes();
2506 FnSize += ConstSize;
2507 seenConstantLoad =
true;
2514 if (
MI.isReturn() ||
TII.isTailCall(
MI)) {
2515 FnSize += EpilogueSize;
2520 if (KCFI &&
MI.isCall() &&
MI.getCFIType()) {
2522 FnSize +=
MCID.getSize();
2525 if (
MI.isUnconditionalBranch())
2532 if (seenConstantLoad && !seenBranch) {
2543 unsigned BBSize = FnSize - SizeBeforeThisBB;
2544 FnSize += 4 * BBSize / 512;
2548 unsigned TableLen =
Table.MBBs.size();
2549 unsigned TableSizeBytes = TableLen * 4;
2550 FnSize += TableSizeBytes;
2554 << FnSize <<
" bytes\n");
2564 bool &HasNonSPFrameIndex) {
2568 unsigned Limit = (1 << 12) - 1;
2569 for (
auto &
MBB : MF) {
2570 for (
auto &
MI :
MBB) {
2571 if (
MI.isDebugInstr())
2573 if (
MI.getOpcode() == TargetOpcode::LOCAL_ESCAPE)
2575 for (
unsigned i = 0, e =
MI.getNumOperands(); i != e; ++i) {
2576 if (!
MI.getOperand(i).isFI())
2581 if (
MI.getOpcode() == ARM::ADDri) {
2582 Limit = std::min(Limit, (1U << 8) - 1);
2587 if (
MI.getOpcode() == ARM::t2ADDri ||
MI.getOpcode() == ARM::t2ADDri12)
2592 if (RegClass && !RegClass->
contains(ARM::SP))
2593 HasNonSPFrameIndex =
true;
2603 Limit = std::min(Limit, (1U << 8) - 1);
2606 Limit = std::min(Limit, ((1U << 8) - 1) * 2);
2611 Limit = std::min(Limit, ((1U << 8) - 1) * 4);
2617 Limit = std::min(Limit, (1U << 8) - 1);
2625 Limit = std::min(Limit, ((1U << 7) - 1) * 1);
2628 Limit = std::min(Limit, ((1U << 7) - 1) * 2);
2631 Limit = std::min(Limit, ((1U << 7) - 1) * 4);
2634 llvm_unreachable(
"Unhandled addressing mode in stack size limit calculation");
2675 unsigned NumSpills = 0;
2676 for (; NumSpills < 8; ++NumSpills)
2677 if (!SavedRegs.
test(ARM::D8 + NumSpills))
2688 SavedRegs.
set(ARM::R4);
2694 if (
STI.hasV8_1MMainlineOps() &&
2724 for (
const auto &
MBB : MF)
2725 for (
const auto &
MI :
MBB) {
2726 if (
MI.isDebugInstr())
2728 if (
MI.getOpcode() == ARM::tSTRspi ||
MI.getOpcode() == ARM::tSTRi ||
2729 STI.genExecuteOnly())
2730 for (
const auto &
Op :
MI.operands())
2751 bool CS1Spilled =
false;
2752 bool LRSpilled =
false;
2753 unsigned NumGPRSpills = 0;
2754 unsigned NumFPRSpills = 0;
2769 STI.getPushPopSplitVariation(MF);
2773 if (
F.hasFnAttribute(
"interrupt") &&
F.hasFnAttribute(
"save-fp")) {
2774 SavedRegs.
set(ARM::FPSCR);
2775 SavedRegs.
set(ARM::R4);
2778 if (
STI.isMClass()) {
2779 SavedRegs.
reset(ARM::FPEXC);
2781 SavedRegs.
set(ARM::FPEXC);
2782 SavedRegs.
set(ARM::R5);
2792 (MFI.hasVarSizedObjects() || RegInfo->hasStackRealignment(MF)))
2793 SavedRegs.
set(ARM::R4);
2800 if (
STI.isTargetWindows() &&
2802 SavedRegs.
set(ARM::R4);
2803 SavedRegs.
set(ARM::LR);
2809 SavedRegs.
set(ARM::LR);
2817 if (MFI.hasVarSizedObjects() || RegInfo->hasStackRealignment(MF) ||
2818 MFI.estimateStackSize(MF) > 508)
2819 SavedRegs.
set(ARM::R4);
2826 if (RegInfo->hasBasePointer(MF))
2827 SavedRegs.
set(RegInfo->getBaseRegister());
2831 CanEliminateFrame =
false;
2835 CanEliminateFrame =
false;
2839 const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF);
2840 for (
unsigned i = 0; CSRegs[i]; ++i) {
2841 unsigned Reg = CSRegs[i];
2842 bool Spilled =
false;
2843 if (SavedRegs.
test(Reg)) {
2845 CanEliminateFrame =
false;
2848 if (!ARM::GPRRegClass.
contains(Reg)) {
2850 if (ARM::SPRRegClass.
contains(Reg))
2852 else if (ARM::DPRRegClass.
contains(Reg))
2854 else if (ARM::QPRRegClass.
contains(Reg))
2875 case ARM::R0:
case ARM::R1:
2876 case ARM::R2:
case ARM::R3:
2877 case ARM::R4:
case ARM::R5:
2878 case ARM::R6:
case ARM::R7:
2891 case ARM::R0:
case ARM::R1:
2892 case ARM::R2:
case ARM::R3:
2893 case ARM::R4:
case ARM::R5:
2894 case ARM::R6:
case ARM::R7:
2905 bool ForceLRSpill =
false;
2921 unsigned EstimatedStackSize =
2922 MFI.estimateStackSize(MF) + 4 * (NumGPRSpills + NumFPRSpills);
2925 int MaxFixedOffset = 0;
2926 for (
int I = MFI.getObjectIndexBegin();
I < 0; ++
I) {
2927 int MaxObjectOffset = MFI.getObjectOffset(
I) + MFI.getObjectSize(
I);
2928 MaxFixedOffset = std::max(MaxFixedOffset, MaxObjectOffset);
2931 bool HasFP =
hasFP(MF);
2934 EstimatedStackSize += 4;
2938 EstimatedStackSize += MaxFixedOffset;
2940 EstimatedStackSize += 16;
2942 unsigned EstimatedRSStackSizeLimit, EstimatedRSFixedSizeLimit;
2943 bool HasNonSPFrameIndex =
false;
2963 if (RegInfo->hasBasePointer(MF))
2964 EstimatedRSStackSizeLimit = (1U << 5) * 4;
2966 EstimatedRSStackSizeLimit = (1U << 8) * 4;
2967 EstimatedRSFixedSizeLimit = (1U << 5) * 4;
2969 EstimatedRSStackSizeLimit =
2971 EstimatedRSFixedSizeLimit = EstimatedRSStackSizeLimit;
2975 bool HasLargeStack = EstimatedStackSize > EstimatedRSStackSizeLimit;
2981 bool HasMovingSP = MFI.hasVarSizedObjects() ||
2983 bool HasBPOrFixedSP = RegInfo->hasBasePointer(MF) || !HasMovingSP;
2992 bool HasLargeArgumentList =
2993 HasFP && (MaxFixedOffset - MaxFPOffset) > (
int)EstimatedRSFixedSizeLimit;
2995 bool BigFrameOffsets = HasLargeStack || !HasBPOrFixedSP ||
2996 HasLargeArgumentList || HasNonSPFrameIndex;
2997 LLVM_DEBUG(
dbgs() <<
"EstimatedLimit: " << EstimatedRSStackSizeLimit
2998 <<
"; EstimatedStack: " << EstimatedStackSize
2999 <<
"; EstimatedFPStack: " << MaxFixedOffset - MaxFPOffset
3000 <<
"; BigFrameOffsets: " << BigFrameOffsets <<
"\n");
3004 SavedRegs, BigFrameOffsets);
3006 if (FnSize >= (1 << 11)) {
3009 CanEliminateFrame =
false;
3010 ForceLRSpill =
true;
3014 if (BigFrameOffsets ||
3015 !CanEliminateFrame || RegInfo->cannotEliminateFrame(MF)) {
3028 SavedRegs.
set(ARM::LR);
3031 auto LRPos =
llvm::find(UnspilledCS1GPRs, ARM::LR);
3032 if (LRPos != UnspilledCS1GPRs.
end())
3033 UnspilledCS1GPRs.
erase(LRPos);
3036 if (FPPos != UnspilledCS1GPRs.
end())
3037 UnspilledCS1GPRs.
erase(FPPos);
3055 unsigned NumExtraCSSpill = 0;
3072 int EntryRegDeficit = 0;
3073 for (
unsigned Reg : {ARM::R0, ARM::R1, ARM::R2, ARM::R3}) {
3078 <<
" is unused argument register, EntryRegDeficit = "
3079 << EntryRegDeficit <<
"\n");
3086 <<
" return regs used, ExitRegDeficit = "
3087 << ExitRegDeficit <<
"\n");
3089 int RegDeficit = std::max(EntryRegDeficit, ExitRegDeficit);
3094 for (
unsigned Reg : {ARM::R4, ARM::R5, ARM::R6}) {
3095 if (SavedRegs.
test(Reg)) {
3098 <<
" is saved low register, RegDeficit = "
3099 << RegDeficit <<
"\n");
3105 <<
" is non-saved low register, adding to AvailableRegs\n");
3110 if (!HasFP ||
FramePtr != ARM::R7) {
3111 if (SavedRegs.
test(ARM::R7)) {
3114 << RegDeficit <<
"\n");
3119 <<
"%r7 is non-saved low register, adding to AvailableRegs\n");
3124 for (
unsigned Reg : {ARM::R8, ARM::R9, ARM::R10, ARM::R11}) {
3125 if (SavedRegs.
test(Reg)) {
3128 <<
" is saved high register, RegDeficit = "
3129 << RegDeficit <<
"\n");
3136 if ((EntryRegDeficit > ExitRegDeficit) &&
3139 if (SavedRegs.
test(ARM::LR)) {
3142 << RegDeficit <<
"\n");
3145 LLVM_DEBUG(
dbgs() <<
"%lr is not saved, adding to AvailableRegs\n");
3154 LLVM_DEBUG(
dbgs() <<
"Final RegDeficit = " << RegDeficit <<
"\n");
3155 for (; RegDeficit > 0 && !AvailableRegs.
empty(); --RegDeficit) {
3158 <<
" to make up reg deficit\n");
3162 assert(!
MRI.isReserved(Reg) &&
"Should not be reserved");
3163 if (Reg != ARM::LR && !
MRI.isPhysRegUsed(Reg))
3169 LLVM_DEBUG(
dbgs() <<
"After adding spills, RegDeficit = " << RegDeficit
3179 if (!LRSpilled && CS1Spilled && !ExpensiveLRRestore) {
3180 SavedRegs.
set(ARM::LR);
3183 LRPos =
llvm::find(UnspilledCS1GPRs, (
unsigned)ARM::LR);
3184 if (LRPos != UnspilledCS1GPRs.
end())
3185 UnspilledCS1GPRs.
erase(LRPos);
3187 ForceLRSpill =
false;
3188 if (!
MRI.isReserved(ARM::LR) && !
MRI.isPhysRegUsed(ARM::LR) &&
3198 if (TargetAlign >=
Align(8) && (NumGPRSpills & 1)) {
3199 if (CS1Spilled && !UnspilledCS1GPRs.
empty()) {
3200 for (
unsigned Reg : UnspilledCS1GPRs) {
3204 (
STI.isTargetWindows() && Reg == ARM::R11) ||
3206 (Reg == ARM::LR && !ExpensiveLRRestore)) {
3209 <<
" to make up alignment\n");
3210 if (!
MRI.isReserved(Reg) && !
MRI.isPhysRegUsed(Reg) &&
3217 unsigned Reg = UnspilledCS2GPRs.
front();
3220 <<
" to make up alignment\n");
3221 if (!
MRI.isReserved(Reg) && !
MRI.isPhysRegUsed(Reg))
3232 unsigned RegsNeeded = 0;
3241 if (RegsNeeded > NumExtraCSSpill) {
3244 unsigned NumExtras = TargetAlign.
value() / 4;
3246 while (NumExtras && !UnspilledCS1GPRs.
empty()) {
3248 if (!
MRI.isReserved(Reg) &&
3256 while (NumExtras && !UnspilledCS2GPRs.
empty()) {
3258 if (!
MRI.isReserved(Reg)) {
3264 if (NumExtras == 0) {
3265 for (
unsigned Reg : Extras) {
3267 if (!
MRI.isPhysRegUsed(Reg))
3271 while ((RegsNeeded > NumExtraCSSpill) && RS) {
3275 unsigned Size =
TRI->getSpillSize(RC);
3276 Align Alignment =
TRI->getSpillAlign(RC);
3277 RS->addScavengingFrameIndex(
3278 MFI.CreateSpillStackObject(
Size, Alignment));
3285 SavedRegs.
set(ARM::LR);
3298 if (Info.getReg() != ARM::LR)
3302 return !Term.isReturn() || Term.getOpcode() == ARM::LDMIA_RET ||
3303 Term.getOpcode() == ARM::t2LDMIA_RET ||
3304 Term.getOpcode() == ARM::tPOP_RET;
3307 Info.setRestored(
false);
3328 SavedRegs.
set(ARM::R0);
3333 std::vector<CalleeSavedInfo> &CSI)
const {
3336 if (
STI.hasV8_1MMainlineOps() &&
3338 CSI.emplace_back(ARM::FPCXTNS);
3339 CSI.back().setRestored(
false);
3351 switch (
STI.getPushPopSplitVariation(MF)) {
3355 [=](
const auto &CS) {
3357 return Reg == ARM::R10 || Reg == ARM::R11 ||
3358 Reg == ARM::R8 || Reg == ARM::R9 ||
3359 ARM::DPRRegClass.contains(Reg);
3370 "ABI-required frame pointers need a CSR split when signing return "
3373 [=](
const auto &CS) {
3375 return Reg != ARM::LR;
3389 static const SpillSlot FixedSpillOffsets[] = {{ARM::FPCXTNS, -4}};
3390 NumEntries = std::size(FixedSpillOffsets);
3391 return FixedSpillOffsets;
3402 unsigned Opc =
I->getOpcode();
3403 bool IsDestroy =
Opc ==
TII.getCallFrameDestroyOpcode();
3404 unsigned CalleePopAmount = IsDestroy ?
I->getOperand(1).getImm() : 0;
3407 "This eliminateCallFramePseudoInstr does not support Thumb1!");
3409 int PIdx =
I->findFirstPredOperandIdx();
3413 unsigned PredReg =
TII.getFramePred(*
I);
3417 if (IsDestroy && CalleePopAmount != -1U)
3418 return MBB.erase(
I);
3423 unsigned Amount =
TII.getFrameSize(*
I);
3430 if (
Opc == ARM::ADJCALLSTACKDOWN ||
Opc == ARM::tADJCALLSTACKDOWN) {
3434 assert(
Opc == ARM::ADJCALLSTACKUP ||
Opc == ARM::tADJCALLSTACKUP);
3439 }
else if (CalleePopAmount != -1U) {
3453 unsigned Shifted = 0;
3458 while (!(
Value & 0xC0000000)) {
3463 bool Carry = (
Value & 0x00FFFFFF);
3464 Value = ((
Value & 0xFF000000) >> 24) + Carry;
3466 if (
Value & 0x0000100)
3509 bool Thumb = ST->isThumb();
3510 bool Thumb2 = ST->isThumb2();
3516 if (!ST->isTargetAndroid() && !ST->isTargetLinux())
3532 unsigned ScratchReg0 = ARM::R4;
3533 unsigned ScratchReg1 = ARM::R5;
3534 unsigned MovOp = ST->useMovt() ? ARM::t2MOVi32imm : ARM::tMOVi32imm;
3535 uint64_t AlignedStackSize;
3551 if (BeforePrologueRegion.
insert(PredBB).second)
3554 }
while (!WalkList.
empty());
3565 for (
const auto &LI : PrologueMBB.
liveins()) {
3567 PredBB->addLiveIn(LI);
3573 BeforePrologueRegion.
erase(
B);
3579 MBB->sortUniqueLiveIns();
3582 if (
MBB->isSuccessor(&PrologueMBB))
3583 MBB->ReplaceUsesOfBlockWith(&PrologueMBB, AddedBlocks[0]);
3628 }
else if (CompareStackPointer) {
3636 if (!CompareStackPointer && Thumb) {
3637 if (AlignedStackSize < 256) {
3641 .
addImm(AlignedStackSize)
3644 if (Thumb2 || ST->genExecuteOnly()) {
3646 .
addImm(AlignedStackSize);
3649 auto RegInfo =
STI.getRegisterInfo();
3650 RegInfo->emitLoadConstPool(*McrMBB,
MBBI,
DL, ScratchReg0, 0,
3659 }
else if (!CompareStackPointer) {
3660 if (AlignedStackSize < 256) {
3663 .
addImm(AlignedStackSize)
3668 auto RegInfo =
STI.getRegisterInfo();
3669 RegInfo->emitLoadConstPool(*McrMBB,
MBBI,
DL, ScratchReg0, 0,
3679 if (Thumb && ST->isThumb1Only()) {
3680 if (ST->genExecuteOnly()) {
3691 BuildMI(GetMBB,
DL,
TII.get(ARM::tLDRpci), ScratchReg0)
3704 BuildMI(McrMBB,
DL,
TII.get(Thumb ? ARM::t2MRC : ARM::MRC),
3714 assert(ST->isTargetAndroid() || ST->isTargetLinux());
3715 unsigned TlsOffset = ST->isTargetAndroid() ? 63 : 1;
3719 BuildMI(GetMBB,
DL,
TII.get(Thumb ? ARM::t2LDRi12 : ARM::LDRi12),
3728 Opcode = Thumb ? ARM::tCMPr : ARM::CMPrr;
3735 Opcode = Thumb ? ARM::tBcc : ARM::Bcc;
3748 if (AlignedStackSize < 256) {
3749 BuildMI(AllocMBB,
DL,
TII.get(ARM::tMOVi8), ScratchReg0)
3751 .
addImm(AlignedStackSize)
3754 if (Thumb2 || ST->genExecuteOnly()) {
3756 .
addImm(AlignedStackSize);
3759 auto RegInfo =
STI.getRegisterInfo();
3760 RegInfo->emitLoadConstPool(*AllocMBB,
MBBI,
DL, ScratchReg0, 0,
3765 if (AlignedStackSize < 256) {
3767 .
addImm(AlignedStackSize)
3772 auto RegInfo =
STI.getRegisterInfo();
3773 RegInfo->emitLoadConstPool(*AllocMBB,
MBBI,
DL, ScratchReg0, 0,
3782 BuildMI(AllocMBB,
DL,
TII.get(ARM::tMOVi8), ScratchReg1)
3787 if (Thumb2 || ST->genExecuteOnly()) {
3792 auto RegInfo =
STI.getRegisterInfo();
3793 RegInfo->emitLoadConstPool(
3794 *AllocMBB,
MBBI,
DL, ScratchReg1, 0,
3806 auto RegInfo =
STI.getRegisterInfo();
3807 RegInfo->emitLoadConstPool(
3808 *AllocMBB,
MBBI,
DL, ScratchReg1, 0,
3846 if (ST->isThumb1Only()) {
3933#ifdef EXPENSIVE_CHECKS
static unsigned estimateRSStackSizeLimit(MachineFunction &MF)
Look at each instruction that references stack frames and return the stack size limit beyond which so...
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool isThumb(const MCSubtargetInfo &STI)
static MachineBasicBlock::iterator skipAlignedDPRCS2Spills(MachineBasicBlock::iterator MI, unsigned NumAlignedDPRCS2Regs)
Skip past the code inserted by emitAlignedDPRCS2Spills, and return an iterator to the following instr...
static void emitAligningInstructions(MachineFunction &MF, ARMFunctionInfo *AFI, const TargetInstrInfo &TII, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const unsigned Reg, const Align Alignment, const bool MustBeSingleInstruction)
Emit an instruction sequence that will align the address in register Reg by zero-ing out the lower bi...
static uint32_t alignToARMConstant(uint32_t Value)
Get the minimum constant for ARM that is greater than or equal to the argument.
static void checkNumAlignedDPRCS2Regs(MachineFunction &MF, BitVector &SavedRegs)
static void insertSEHRange(MachineBasicBlock &MBB, MachineBasicBlock::iterator Start, const MachineBasicBlock::iterator &End, const ARMBaseInstrInfo &TII, unsigned MIFlags)
static unsigned EstimateFunctionSizeInBytes(const MachineFunction &MF, const ARMBaseInstrInfo &TII, const ARMSubtarget &STI, const ARMBaseRegisterInfo *RegInfo, BitVector &SavedRegs, bool BigFrameOffsets)
static void emitAlignedDPRCS2Restores(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned NumAlignedDPRCS2Regs, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI)
Emit aligned reload instructions for NumAlignedDPRCS2Regs D-registers starting from d8.
static void emitAlignedDPRCS2Spills(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned NumAlignedDPRCS2Regs, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI)
Emit aligned spill instructions for NumAlignedDPRCS2Regs D-registers starting from d8.
static int getArgumentStackToRestore(MachineFunction &MF, MachineBasicBlock &MBB)
static void emitSPUpdate(bool isARM, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &dl, const ARMBaseInstrInfo &TII, int NumBytes, unsigned MIFlags=MachineInstr::NoFlags, ARMCC::CondCodes Pred=ARMCC::AL, unsigned PredReg=0)
static MachineBasicBlock::iterator insertSEH(MachineBasicBlock::iterator MBBI, const TargetInstrInfo &TII, unsigned Flags)
SpillArea getSpillArea(Register Reg, ARMSubtarget::PushPopSplitVariation Variation, unsigned NumAlignedDPRCS2Regs, const ARMBaseRegisterInfo *RegInfo)
Get the spill area that Reg should be saved into in the prologue.
static bool canSpillOnFrameIndexAccess(const MachineFunction &MF, const TargetFrameLowering &TFI)
static bool WindowsRequiresStackProbe(const MachineFunction &MF, size_t StackSizeInBytes)
static int getMaxFPOffset(const ARMSubtarget &STI, const ARMFunctionInfo &AFI, const MachineFunction &MF)
We need the offset of the frame pointer relative to other MachineFrameInfo offsets which are encoded ...
static MachineBasicBlock::iterator initMBBRange(MachineBasicBlock &MBB, const MachineBasicBlock::iterator &MBBI)
static int sizeOfSPAdjustment(const MachineInstr &MI)
static const uint64_t kSplitStackAvailable
static void emitRegPlusImmediate(bool isARM, MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &dl, const ARMBaseInstrInfo &TII, unsigned DestReg, unsigned SrcReg, int NumBytes, unsigned MIFlags=MachineInstr::NoFlags, ARMCC::CondCodes Pred=ARMCC::AL, unsigned PredReg=0)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the BitVector class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register const TargetRegisterInfo * TRI
Promote Memory to Register
MachineRegisterInfo & MRI
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static const unsigned FramePtr
bool canRealignStack(const MachineFunction &MF) const override
static ARMConstantPoolSymbol * Create(LLVMContext &C, StringRef s, unsigned ID, unsigned char PCAdj, ARMCP::ARMCPModifier Modifier=ARMCP::no_modifier, bool AddCurrentAddress=false)
ARMConstantPoolValue - ARM specific constantpool value.
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...
StackOffset getNonLocalFrameIndexReference(const MachineFunction &MF, int FI) const override
getNonLocalFrameIndexReference - This method returns the offset used to reference a frame index locat...
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - Provide a base+offset reference to an FI slot for debug info.
bool keepFramePointer(const MachineFunction &MF) const
static void updateLRRestored(MachineFunction &MF)
Update the IsRestored flag on LR if it is spilled, based on the return instructions.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
ARMFrameLowering(const ARMSubtarget &sti)
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
bool requiresAAPCSFrameRecord(const MachineFunction &MF) const
bool isFPReserved(const MachineFunction &MF) const
isFPReserved - Return true if the frame pointer register should be considered a reserved register on ...
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
canSimplifyCallFramePseudos - If there is a reserved call frame, the call frame pseudos can be simpli...
void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &MBB) const override
Adjust the prologue to have the function use segmented stacks.
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 hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
bool hasFPImpl(const MachineFunction &MF) const override
hasFPImpl - Return true if the specified function should have a dedicated frame pointer register.
int ResolveFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg, int SPAdj) const
void getCalleeSaves(const MachineFunction &MF, BitVector &SavedRegs) const override
Returns the callee-saved registers as computed by determineCalleeSaves in the BitVector SavedRegs.
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool enableCalleeSaveSkip(const MachineFunction &MF) const override
Returns true if the target can safely skip saving callee-saved registers for noreturn nounwind functi...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
bool hasStackFrame() const
bool isThumb2Function() const
unsigned getFPCXTSaveAreaSize() const
unsigned getGPRCalleeSavedArea1Size() const
unsigned getDPRCalleeSavedGapSize() const
unsigned getDPRCalleeSavedArea1Size() const
unsigned createPICLabelUId()
void setLRIsSpilled(bool s)
void setDPRCalleeSavedArea1Offset(unsigned o)
void setGPRCalleeSavedArea2Size(unsigned s)
bool isThumb1OnlyFunction() const
void setHasStackFrame(bool s)
bool isThumbFunction() const
void setFramePtrSpillOffset(unsigned o)
unsigned getGPRCalleeSavedArea2Size() const
unsigned getNumAlignedDPRCS2Regs() const
bool shouldSignReturnAddress() const
void setGPRCalleeSavedArea1Size(unsigned s)
unsigned getArgumentStackToRestore() const
void setFPCXTSaveAreaSize(unsigned s)
bool isCmseNSEntryFunction() const
unsigned getGPRCalleeSavedArea3Size() const
unsigned getFramePtrSpillOffset() const
bool shouldRestoreSPFromFP() const
unsigned getArgRegsSaveSize() const
void setGPRCalleeSavedArea2Offset(unsigned o)
void setGPRCalleeSavedArea1Offset(unsigned o)
void setDPRCalleeSavedArea1Size(unsigned s)
void setDPRCalleeSavedGapSize(unsigned s)
void setFPStatusSavesSize(unsigned s)
unsigned getArgumentStackSize() const
void setShouldRestoreSPFromFP(bool s)
unsigned getReturnRegsCount() const
void setGPRCalleeSavedArea3Size(unsigned s)
bool getPreservesR0() const
unsigned getFPStatusSavesSize() const
const ARMBaseRegisterInfo * getRegisterInfo() const override
const ARMOptions & getCLOpts() const
enum PushPopSplitVariation getPushPopSplitVariation(const MachineFunction &MF) const
PushPopSplitVariation
How the push and pop instructions of callee saved general-purpose registers should be split.
@ SplitR11WindowsSEH
When the stack frame size is not known (because of variable-sized objects or realignment),...
@ SplitR7
R7 and LR must be adjacent, because R7 is the frame pointer, and must point to a frame record consist...
@ SplitR11AAPCSSignRA
When generating AAPCS-compilant frame chains, R11 is the frame pointer, and must be pushed adjacent t...
@ NoSplit
All GPRs can be pushed in a single instruction.
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.
BitVector & set()
Set all bits in the bitvector.
Helper class for creating CFI instructions and inserting them into MIR.
void buildDefCFAOffset(int64_t Offset, MCSymbol *Label=nullptr) const
void buildDefCFARegister(MCRegister Reg) const
void buildSameValue(MCRegister Reg) const
void buildOffset(MCRegister Reg, int64_t Offset) const
void buildDefCFA(MCRegister Reg, int64_t Offset) const
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with 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.
Module * getParent()
Get the module that this global value is contained inside of...
Describe properties that are true of each instruction in the target description file.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
Wrapper class representing physical registers and target specific virtual registers.
iterator_range< livein_iterator > liveins() const
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.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
LLVM_ABI unsigned getConstantPoolIndex(const Constant *C, Align Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool needsSplitStackProlog() const
Return true if this function requires a split stack prolog, even if it uses no stack space.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool isReturnAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Align getMaxAlign() const
Return alignment of this function's frame.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
int getStackProtectorIndex() const
Return the index for the stack protector object.
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
LLVM_ABI BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
void setOffsetAdjustment(int64_t Adj)
Set the correction for frame offsets.
void setHasWinCFI(bool v)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool framePointerIsReserved() const
Returns true if the frame pointer must always either point to a new frame record or be un-modified in...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, raw_ostream *OS=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use.
bool needsWinCFI() const
True if this function uses SEH unwind opcodes and needs an unwind table entry.
Function & getFunction()
Return the LLVM function that this machine code represents.
bool usesWindowsUnwindInfo() const
True if this function describes its unwind information with Windows SEH unwind opcodes (....
bool disableFramePointerElim() const
Returns true if frame pointer elimination should be disabled for this function.
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
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 & 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 & add(const MachineOperand &MO) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
const MachineInstrBuilder & copyImplicitOps(const MachineInstr &OtherMI) const
Copy all the implicit operands from OtherMI onto this one.
bool isValid() const
Check for null.
Representation of each machine instruction.
LLVM_ABI bool addRegisterKilled(Register IncomingReg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI kills a register.
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const std::vector< MachineJumpTableEntry > & getJumpTables() const
A description of a memory reference used in the backend.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI bool isLiveIn(Register Reg) const
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Special value supplied for machine level alias analysis.
Wrapper class representing virtual and physical registers.
bool erase(PtrType Ptr)
Remove pointer from the set.
void insert_range(Range &&R)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
iterator erase(const_iterator CI)
typename SuperClass::iterator iterator
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.
Information about stack frame layout on the target.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
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...
virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
virtual void getCalleeSaves(const MachineFunction &MF, BitVector &SavedRegs) const
Returns the callee-saved registers as computed by determineCalleeSaves in the BitVector SavedRegs.
TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
int alignSPAdjust(int SPAdj) const
alignSPAdjust - This method aligns the stack adjustment to the correct alignment.
virtual StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
TargetInstrInfo - Interface to description of machine instruction set.
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getAM2Opc(AddrOpc Opc, unsigned Imm12, ShiftOpc SO, unsigned IdxMode=0)
unsigned getSORegOpc(ShiftOpc ShOp, unsigned Imm)
@ D16
Only 16 D registers.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Kill
The last use of a register.
@ Define
Register definition.
constexpr RegState getKillRegState(bool B)
static bool isARMLowRegister(MCRegister Reg)
isARMLowRegister - Returns true if the register is a low register (r0-r7).
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
static bool isSEHInstruction(const MachineInstr &MI)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget, MachineFunction &MF, MachineInstr *MI, unsigned NumBytes)
Tries to add registers to the reglist of a given base-updating push/pop instruction to adjust the sta...
auto reverse(ContainerTy &&C)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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...
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
DWARFExpression::Operation Op
static MachineOperand t1CondCodeOp(bool isDead=false)
Get the operand corresponding to the conditional code result for Thumb1.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
static MachineOperand condCodeOp(unsigned CCReg=0)
Get the operand corresponding to the conditional code result.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
unsigned Log2(Align A)
Returns the log2 of the alignment.
@ End
Run the machine verifier once, at the end of the pipeline.
void emitARMRegPlusImmediate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &dl, Register DestReg, Register BaseReg, int NumBytes, ARMCC::CondCodes Pred, Register PredReg, const ARMBaseInstrInfo &TII, unsigned MIFlags=0)
emitARMRegPlusImmediate / emitT2RegPlusImmediate - Emits a series of instructions to materializea des...
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 emitT2RegPlusImmediate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &dl, Register DestReg, Register BaseReg, int NumBytes, ARMCC::CondCodes Pred, Register PredReg, const ARMBaseInstrInfo &TII, unsigned MIFlags=0)
MCRegisterClass TargetRegisterClass
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
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.