41#define DEBUG_TYPE "x86-fl"
43STATISTIC(NumFrameLoopProbe,
"Number of loop stack probes used in prologue");
45 "Number of extra stack probes generated in prologue");
46STATISTIC(NumFunctionUsingPush2Pop2,
"Number of functions using push2/pop2");
71 return STI.hasBWI() ? &X86::VK64RegClass : &X86::VK16RegClass;
72 return TRI.getMinimalPhysRegClass(
Reg);
104 (
hasFP(MF) && !
TRI->hasStackRealignment(MF)) ||
105 TRI->hasBasePointer(MF);
137 return IsLP64 ? X86::SUB64ri32 : X86::SUB32ri;
141 return IsLP64 ? X86::ADD64ri32 : X86::ADD32ri;
145 return IsLP64 ? X86::SUB64rr : X86::SUB32rr;
149 return IsLP64 ? X86::ADD64rr : X86::ADD32rr;
153 return IsLP64 ? X86::AND64ri32 : X86::AND32ri;
157 return IsLP64 ? X86::LEA64r : X86::LEA32r;
178 return ST.is64Bit() ? (ST.hasPPX() ? X86::PUSHP64r : X86::PUSH64r)
182 return ST.is64Bit() ? (ST.hasPPX() ? X86::POPP64r : X86::POP64r)
186 return ST.hasPPX() ? X86::PUSH2P : X86::PUSH2;
189 return ST.hasPPX() ? X86::POP2P : X86::POP2;
196 if (
Reg == X86::RAX ||
Reg == X86::EAX ||
Reg == X86::AX ||
197 Reg == X86::AH ||
Reg == X86::AL)
211 bool BreakNext =
false;
216 if (
Reg != X86::EFLAGS)
237 if (Succ->isLiveIn(X86::EFLAGS))
250 bool InEpilogue)
const {
251 bool isSub = NumBytes < 0;
252 uint64_t
Offset = isSub ? -NumBytes : NumBytes;
267 const bool EmitInlineStackProbe = TLI.hasInlineStackProbe(MF);
271 if (EmitInlineStackProbe && !InEpilogue) {
299 MI->getOperand(3).setIsDead();
326 MI->getOperand(3).setIsDead();
345 unsigned Opc = isSub ? (
Is64Bit ? X86::PUSH64r : X86::PUSH32r)
346 : (
Is64Bit ? X86::POP64r : X86::POP32r);
356 BuildStackAdjustment(
MBB,
MBBI,
DL, isSub ? -ThisVal : ThisVal, InEpilogue)
366 assert(
Offset != 0 &&
"zero offset stack adjustment requested");
376 UseLEA =
STI.useLeaForSP() ||
MBB.isLiveIn(X86::EFLAGS);
384 if (UseLEA && !
STI.useLeaForSP())
389 "We shouldn't have allowed this insertion point");
392 MachineInstrBuilder
MI;
406 const unsigned Opc = IsSub ? X86::SUB64ri32_NF : X86::ADD64ri32_NF;
419 int64_t
Imm = AbsOffset;
430 if (AbsOffset == 128 &&
433 Opc = IsSub ? getADDriOpcode(Uses64BitFramePtr)
434 : getSUBriOpcode(Uses64BitFramePtr);
445template <
typename FoundT,
typename CalcT>
448 FoundT FoundStackAdjust,
450 bool doMergeWithPrevious)
const {
453 return CalcNewOffset(0);
469 if (doMergeWithPrevious && PI !=
MBB.
begin() && PI->isCFIInstruction())
474 unsigned Opc = PI->getOpcode();
476 if ((
Opc == X86::ADD64ri32 ||
Opc == X86::ADD32ri ||
477 Opc == X86::ADD64ri32_NF) &&
478 PI->getOperand(0).getReg() ==
StackPtr) {
480 Offset = PI->getOperand(2).getImm();
481 }
else if ((
Opc == X86::LEA32r ||
Opc == X86::LEA64_32r) &&
482 PI->getOperand(0).getReg() ==
StackPtr &&
483 PI->getOperand(1).getReg() ==
StackPtr &&
484 PI->getOperand(2).getImm() == 1 &&
485 PI->getOperand(3).getReg() == X86::NoRegister &&
486 PI->getOperand(5).getReg() == X86::NoRegister) {
488 Offset = PI->getOperand(4).getImm();
489 }
else if ((
Opc == X86::SUB64ri32 ||
Opc == X86::SUB32ri ||
490 Opc == X86::SUB64ri32_NF) &&
491 PI->getOperand(0).getReg() ==
StackPtr) {
493 Offset = -PI->getOperand(2).getImm();
495 return CalcNewOffset(0);
497 FoundStackAdjust(PI,
Offset);
501 if (doMergeWithPrevious ? (PI ==
MBB.
begin()) : (PI ==
MBB.
end()))
502 return CalcNewOffset(0);
504 PI = doMergeWithPrevious ? std::prev(PI) : std::next(PI);
508 if (PI !=
MBB.
end() && PI->isCFIInstruction()) {
510 MCCFIInstruction CI = CIs[PI->getOperand(0).getCFIIndex()];
515 if (!doMergeWithPrevious)
518 return CalcNewOffset(
Offset);
524 bool doMergeWithPrevious)
const {
525 return mergeSPUpdates(
527 doMergeWithPrevious);
594 CfaExpr.
push_back(dwarf::DW_CFA_expression);
600 STI.isTarget64BitILP32()
603 unsigned DwarfFramePtr = MRI->
getDwarfRegNum(MachineFramePtr,
true);
619 int FI =
MI->getOperand(1).getIndex();
624 STI.isTarget64BitILP32()
627 unsigned DwarfFramePtr = MRI->
getDwarfRegNum(MachineFramePtr,
true);
634 DefCfaExpr.
push_back(dwarf::DW_CFA_def_cfa_expression);
644void X86FrameLowering::emitZeroCallUsedRegs(
BitVector RegsToZero,
660 if (!X86::RFP80RegClass.
contains(Reg))
665 unsigned NumFPRegs = 8;
666 if (
MBBI->hasRegisterImplicitUseOperand(X86::ST0))
668 if (
MBBI->hasRegisterImplicitUseOperand(X86::ST1))
671 for (
unsigned i = 0; i != NumFPRegs; ++i)
674 for (
unsigned i = 0; i != NumFPRegs; ++i)
682 if (
TRI->isGeneralPurposeRegister(MF,
Reg)) {
688 for (MCRegister
Reg : GPRsToZero.set_bits())
693 auto getVectorClearReg = [&](MCRegister
Reg) -> MCRegister {
702 MCRegister Xmm =
TRI->getSubReg(
Reg, X86::sub_xmm);
705 if (X86::VR128RegClass.
contains(Xmm))
708 TRI->getMatchingSuperReg(Xmm, X86::sub_xmm, &X86::VR512RegClass);
709 assert(Zmm &&
"XMM16-31 must have an enclosing ZMM to clear through");
713 BitVector VecRegsToZero(
TRI->getNumRegs());
715 if (MCRegister Clear = getVectorClearReg(
Reg)) {
716 VecRegsToZero.set(Clear.id());
720 for (MCRegister
Reg : VecRegsToZero.set_bits())
731 std::optional<MachineFunction::DebugInstrOperandPair> InstrNum)
const {
733 if (
STI.isTargetWindowsCoreCLR()) {
738 emitStackProbeInline(MF,
MBB,
MBBI,
DL,
false);
741 emitStackProbeCall(MF,
MBB,
MBBI,
DL, InProlog, InstrNum);
746 return STI.isOSWindows() && !
STI.isTargetWin64();
752 return MI.getOpcode() == X86::STACKALLOC_W_PROBING;
754 if (Where != PrologMBB.
end()) {
756 emitStackProbeInline(MF, PrologMBB, Where,
DL,
true);
757 Where->eraseFromParent();
765 bool InProlog)
const {
768 emitStackProbeInlineWindowsCoreCLR64(MF,
MBB,
MBBI,
DL, InProlog);
770 emitStackProbeInlineGeneric(MF,
MBB,
MBBI,
DL, InProlog);
773void X86FrameLowering::emitStackProbeInlineGeneric(
782 "different expansion expected for CoreCLR 64 bit");
784 const uint64_t StackProbeSize = TLI.getStackProbeSize(MF);
785 uint64_t ProbeChunk = StackProbeSize * 8;
788 TRI->hasStackRealignment(MF) ? calculateMaxStackAlign(MF) : 0;
793 if (
Offset > ProbeChunk) {
795 MaxAlign % StackProbeSize);
798 MaxAlign % StackProbeSize);
802void X86FrameLowering::emitStackProbeInlineGenericBlock(
807 const bool NeedsDwarfCFI = needsDwarfCFI(MF);
810 const X86TargetLowering &TLI = *
STI.getTargetLowering();
811 const unsigned MovMIOpc =
Is64Bit ? X86::MOV64mi32 : X86::MOV32mi;
812 const uint64_t StackProbeSize = TLI.getStackProbeSize(MF);
816 assert(AlignOffset < StackProbeSize);
819 if (StackProbeSize <
Offset + AlignOffset) {
822 BuildStackAdjustment(
MBB,
MBBI,
DL, -StackAdjustment,
false)
824 if (!HasFP && NeedsDwarfCFI) {
835 NumFrameExtraProbe++;
836 CurrentOffset = StackProbeSize - AlignOffset;
842 while (CurrentOffset + StackProbeSize <
Offset) {
843 BuildStackAdjustment(
MBB,
MBBI,
DL, -StackProbeSize,
false)
846 if (!HasFP && NeedsDwarfCFI) {
856 NumFrameExtraProbe++;
857 CurrentOffset += StackProbeSize;
866 unsigned Opc =
Is64Bit ? X86::PUSH64r : X86::PUSH32r;
871 BuildStackAdjustment(
MBB,
MBBI,
DL, -ChunkSize,
false)
878void X86FrameLowering::emitStackProbeInlineGenericLoop(
886 "Inline stack probe loop will clobber live EFLAGS.");
888 const bool NeedsDwarfCFI = needsDwarfCFI(MF);
891 const X86TargetLowering &TLI = *
STI.getTargetLowering();
892 const unsigned MovMIOpc =
Is64Bit ? X86::MOV64mi32 : X86::MOV32mi;
893 const uint64_t StackProbeSize = TLI.getStackProbeSize(MF);
896 if (AlignOffset < StackProbeSize) {
898 BuildStackAdjustment(
MBB,
MBBI,
DL, -AlignOffset,
false)
906 NumFrameExtraProbe++;
919 MF.
insert(MBBIter, testMBB);
920 MF.
insert(MBBIter, tailMBB);
960 if (!HasFP && NeedsDwarfCFI) {
963 const Register DwarfFinalStackProbed =
964 STI.isTarget64BitILP32()
970 nullptr,
TRI->getDwarfRegNum(DwarfFinalStackProbed,
true)));
977 BuildStackAdjustment(*testMBB, testMBB->
end(),
DL, -StackProbeSize,
1011 BuildStackAdjustment(*tailMBB, TailMBBIter,
DL, -TailOffset,
1017 if (!HasFP && NeedsDwarfCFI) {
1021 STI.isTarget64BitILP32()
1027 nullptr,
TRI->getDwarfRegNum(DwarfStackPtr,
true)));
1034void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
1038 assert(
STI.is64Bit() &&
"different expansion needed for 32 bit");
1039 assert(
STI.isTargetWindowsCoreCLR() &&
"custom expansion expects CoreCLR");
1040 const TargetInstrInfo &
TII = *
STI.getInstrInfo();
1045 "Inline stack probe loop will clobber live EFLAGS.");
1080 MF.
insert(MBBIter, RoundMBB);
1081 MF.
insert(MBBIter, LoopMBB);
1082 MF.
insert(MBBIter, ContinueMBB);
1090 const int64_t ThreadEnvironmentStackLimit = 0x10;
1092 const int64_t PageMask = ~(
PageSize - 1);
1110 int64_t RCXShadowSlot = 0;
1111 int64_t RDXShadowSlot = 0;
1118 X86MachineFunctionInfo *X86FI = MF.
getInfo<X86MachineFunctionInfo>();
1127 int64_t InitSlot = 8 + CalleeSaveSize + (
HasFP ? 8 : 0);
1131 RCXShadowSlot = InitSlot;
1133 RDXShadowSlot = InitSlot;
1134 if (IsRDXLiveIn && IsRCXLiveIn)
1175 .
addImm(ThreadEnvironmentStackLimit)
1186 BuildMI(RoundMBB,
DL,
TII.get(X86::AND64ri32), RoundedReg)
1231 TII.get(X86::MOV64rm), X86::RCX),
1232 X86::RSP,
false, RCXShadowSlot);
1235 TII.get(X86::MOV64rm), X86::RDX),
1236 X86::RSP,
false, RDXShadowSlot);
1241 BuildMI(*ContinueMBB, ContinueMBBI,
DL,
TII.get(X86::SUB64rr), X86::RSP)
1253 LivePhysRegs LiveRegs;
1259 for (++BeforeMBBI; BeforeMBBI !=
MBB.
end(); ++BeforeMBBI) {
1262 for (MachineInstr &
MI : *RoundMBB) {
1265 for (MachineInstr &
MI : *LoopMBB) {
1268 for (MachineInstr &
MI :
1275void X86FrameLowering::emitStackProbeCall(
1278 std::optional<MachineFunction::DebugInstrOperandPair> InstrNum)
const {
1282 if (
Is64Bit && IsLargeCodeModel &&
STI.useIndirectThunkCalls())
1284 "code model and indirect thunks not yet implemented.");
1288 "Stack probe calls will clobber live EFLAGS.");
1292 CallOp = IsLargeCodeModel ? X86::CALL64r : X86::CALL64pcrel32;
1294 CallOp = X86::CALLpcrel32;
1296 StringRef
Symbol =
STI.getTargetLowering()->getStackProbeSymbolName(MF);
1298 MachineInstrBuilder CI;
1322 MachineInstr *ModInst = CI;
1323 if (
STI.isTargetWin64() || !
STI.isOSWindows()) {
1340 if (
STI.isTargetWin64() || !
STI.isOSWindows()) {
1355 for (++ExpansionMBBI; ExpansionMBBI !=
MBBI; ++ExpansionMBBI)
1363 const uint64_t Win64MaxSEHOffset = 128;
1364 uint64_t SEHFrameOffset = std::min(SPAdjust, Win64MaxSEHOffset);
1366 return SEHFrameOffset & -16;
1374X86FrameLowering::calculateMaxStackAlign(
const MachineFunction &MF)
const {
1381 MaxAlign = (StackAlign > MaxAlign) ? StackAlign : MaxAlign;
1388 MaxAlign = (MaxAlign > 16) ? MaxAlign :
Align(16);
1390 MaxAlign =
Align(16);
1392 return MaxAlign.
value();
1404 const X86TargetLowering &TLI = *
STI.getTargetLowering();
1405 const uint64_t StackProbeSize = TLI.getStackProbeSize(MF);
1406 const bool EmitInlineStackProbe = TLI.hasInlineStackProbe(MF);
1411 if (
Reg ==
StackPtr && EmitInlineStackProbe && MaxAlign >= StackProbeSize) {
1413 NumFrameLoopProbe++;
1414 MachineBasicBlock *entryMBB =
1416 MachineBasicBlock *headMBB =
1418 MachineBasicBlock *bodyMBB =
1420 MachineBasicBlock *footMBB =
1424 MF.
insert(MBBIter, entryMBB);
1425 MF.
insert(MBBIter, headMBB);
1426 MF.
insert(MBBIter, bodyMBB);
1427 MF.
insert(MBBIter, footMBB);
1428 const unsigned MovMIOpc =
Is64Bit ? X86::MOV64mi32 : X86::MOV32mi;
1437 BuildMI(entryMBB,
DL,
TII.get(TargetOpcode::COPY), FinalStackProbed)
1441 BuildMI(entryMBB,
DL,
TII.get(AndOp), FinalStackProbed)
1442 .
addReg(FinalStackProbed)
1451 .
addReg(FinalStackProbed)
1474 .
addReg(FinalStackProbed)
1504 .
addReg(FinalStackProbed)
1520 .
addReg(FinalStackProbed)
1547 "MF used frame lowering for wrong subtarget");
1556bool X86FrameLowering::isWin64Prologue(
const MachineFunction &MF)
const {
1560bool X86FrameLowering::needsDwarfCFI(
const MachineFunction &MF)
const {
1567 case X86::REPNE_PREFIX:
1568 case X86::REP_MOVSB_32:
1569 case X86::REP_MOVSB_64:
1570 case X86::REP_MOVSD_32:
1571 case X86::REP_MOVSD_64:
1572 case X86::REP_MOVSQ_32:
1573 case X86::REP_MOVSQ_64:
1574 case X86::REP_MOVSW_32:
1575 case X86::REP_MOVSW_64:
1576 case X86::REP_PREFIX:
1577 case X86::REP_STOSB_32:
1578 case X86::REP_STOSB_64:
1579 case X86::REP_STOSD_32:
1580 case X86::REP_STOSD_64:
1581 case X86::REP_STOSQ_32:
1582 case X86::REP_STOSQ_64:
1583 case X86::REP_STOSW_32:
1584 case X86::REP_STOSW_64:
1596 int64_t FixedEnd = 0;
1597 int64_t LocalsTop = std::numeric_limits<int64_t>::max();
1607 FixedEnd = std::max(FixedEnd, -ObjOffset);
1609 LocalsTop = std::min<int64_t>(LocalsTop, -ObjOffset - ObjSize);
1611 if (LocalsTop == std::numeric_limits<int64_t>::max())
1614 assert(LocalsTop >= FixedEnd &&
"Local object overlaps the fixed area");
1615 return LocalsTop - FixedEnd;
1706 "MF used frame lowering for wrong subtarget");
1711 uint64_t MaxAlign = calculateMaxStackAlign(MF);
1713 bool IsFunclet =
MBB.isEHFuncletEntry();
1717 bool FnHasClrFunclet =
1719 bool IsClrFunclet = IsFunclet && FnHasClrFunclet;
1720 bool HasFP =
hasFP(MF);
1721 bool IsWin64Prologue = isWin64Prologue(MF);
1724 bool NeedsWinFPO = !IsFunclet &&
STI.isTargetWin32() &&
1726 bool NeedsWinCFI = NeedsWin64CFI || NeedsWinFPO;
1727 bool NeedsDwarfCFI = needsDwarfCFI(MF);
1734 bool HasWinCFI =
false;
1743 auto EmitSEHBefore = [&](
auto EmitFn) {
1744 if (NeedsWinCFI && IsWin64UnwindV3) {
1749 auto EmitSEHAfter = [&](
auto EmitFn) {
1750 if (NeedsWinCFI && !IsWin64UnwindV3) {
1765 ArgBaseReg =
MI->getOperand(0).getReg();
1778 if (NeedsDwarfCFI) {
1780 unsigned DwarfStackPtr =
TRI->getDwarfRegNum(ArgBaseReg,
true);
1799 if (TailCallArgReserveSize && IsWin64Prologue)
1802 const bool EmitStackProbeCall =
1803 STI.getTargetLowering()->hasStackProbeSymbol(MF);
1804 unsigned StackProbeSize =
STI.getTargetLowering()->getStackProbeSize(MF);
1809 if (
STI.swiftAsyncContextIsDynamicallySet()) {
1819 .
addUse(X86::NoRegister);
1827 "win64 prologue does not set the bit 60 in the saved frame pointer");
1866 !EmitStackProbeCall &&
1874 StackSize = std::max(MinSize, StackSize > 128 ? StackSize - 128 : 0);
1881 if (TailCallArgReserveSize != 0) {
1882 BuildStackAdjustment(
MBB,
MBBI,
DL, -(
int)TailCallArgReserveSize,
1901 uint64_t NumBytes = 0;
1911 if (IsWin64Prologue && IsFunclet && !IsClrFunclet) {
1919 MBB.addLiveIn(Establisher);
1926 uint64_t FrameSize = StackSize -
SlotSize;
1933 if (
TRI->hasStackRealignment(MF) && !IsWin64Prologue) {
1935 assert(Padding <= NumBytes &&
"Padding exceeds the local area");
1936 NumBytes =
alignTo(NumBytes - Padding, MaxAlign);
1940 auto EmitSEHPushFramePtr = [&]() {
1945 EmitSEHBefore(EmitSEHPushFramePtr);
1950 EmitSEHAfter(EmitSEHPushFramePtr);
1952 if (NeedsDwarfCFI && !ArgBaseReg.
isValid()) {
1958 nullptr, -2 * stackGrowth + (
int)TailCallArgReserveSize),
1962 unsigned DwarfFramePtr =
TRI->getDwarfRegNum(MachineFramePtr,
true);
1966 (
int)TailCallArgReserveSize),
1972 assert(!IsWin64Prologue &&
1973 "win64 prologue does not store async context right below rbp");
1979 auto EmitSEHPushR14 = [&]() {
1984 EmitSEHBefore(EmitSEHPushR14);
1985 if (Attrs.hasAttrSomewhere(Attribute::SwiftAsync)) {
1988 MBB.addLiveIn(X86::R14);
2001 if (NeedsDwarfCFI && !ArgBaseReg.
isValid()) {
2008 EmitSEHAfter(EmitSEHPushR14);
2019 if (NeedsDwarfCFI && !ArgBaseReg.
isValid()) {
2020 unsigned DwarfFramePtr =
TRI->getDwarfRegNum(MachineFramePtr,
true);
2024 (
int)TailCallArgReserveSize),
2034 if (!IsWin64Prologue && !IsFunclet) {
2043 if (NeedsDwarfCFI) {
2046 CfaExpr.
push_back(dwarf::DW_CFA_expression);
2048 unsigned DwarfReg =
TRI->getDwarfRegNum(MachineFramePtr,
true);
2060 unsigned DwarfFramePtr =
TRI->getDwarfRegNum(MachineFramePtr,
true);
2072 assert(!IsWin64UnwindV3);
2082 assert(!IsFunclet &&
"funclets without FPs not yet implemented");
2090 if (HasFP &&
TRI->hasStackRealignment(MF))
2098 unsigned ParentFrameNumBytes = NumBytes;
2100 NumBytes = getWinEHFuncletFrameSize(MF);
2103 bool PushedRegs =
false;
2109 unsigned Opc =
MBBI->getOpcode();
2110 return Opc == X86::PUSH32r ||
Opc == X86::PUSH64r ||
Opc == X86::PUSHP64r ||
2111 Opc == X86::PUSH2 ||
Opc == X86::PUSH2P;
2114 while (IsCSPush(
MBBI)) {
2118 unsigned Opc = LastCSPush->getOpcode();
2119 bool IsPush2 =
Opc == X86::PUSH2 ||
Opc == X86::PUSH2P;
2122 EmitSEHBefore([&]() {
2126 .
addImm(LastCSPush->getOperand(1).getReg())
2136 if (!HasFP && NeedsDwarfCFI) {
2151 EmitSEHAfter([&]() {
2157 .
addImm(LastCSPush->getOperand(1).getReg())
2165 if (!IsWin64Prologue && !IsFunclet &&
TRI->hasStackRealignment(MF) &&
2167 assert(HasFP &&
"There should be a frame pointer if stack is realigned.");
2168 auto EmitSEHStackAlign = [&]() {
2173 EmitSEHBefore(EmitSEHStackAlign);
2175 EmitSEHAfter(EmitSEHStackAlign);
2181 NumBytes = mergeSPUpdates(
2195 uint64_t AlignedNumBytes = NumBytes;
2196 if (IsWin64Prologue && !IsFunclet &&
TRI->hasStackRealignment(MF))
2197 AlignedNumBytes =
alignTo(AlignedNumBytes, MaxAlign);
2199 auto EmitSEHStackAlloc = [&]() {
2205 EmitSEHBefore(EmitSEHStackAlloc);
2207 if (AlignedNumBytes >= StackProbeSize && EmitStackProbeCall) {
2209 "The Red Zone is not accounted for in stack probes");
2231 int64_t
Alloc = isEAXAlive ? NumBytes - 8 : NumBytes;
2240 .
addImm(isEAXAlive ? NumBytes - 4 : NumBytes)
2259 }
else if (NumBytes) {
2264 EmitSEHAfter(EmitSEHStackAlloc);
2266 int SEHFrameOffset = 0;
2274 unsigned PSPSlotOffset = getPSPSlotOffsetFromSP(MF);
2276 MBB.addLiveIn(Establisher);
2278 Establisher,
false, PSPSlotOffset)
2285 false, PSPSlotOffset)
2292 SPOrEstablisher = Establisher;
2297 if (IsWin64Prologue && HasFP) {
2304 if (NeedsWinCFI && !IsFunclet) {
2305 assert(!NeedsWinFPO &&
"this setframe incompatible with FPO data");
2308 if (
TRI->hasBasePointer(MF))
2316 auto EmitSEHSetFrame = [&]() {
2324 EmitSEHBefore(EmitSEHSetFrame);
2328 SPOrEstablisher,
false, SEHFrameOffset);
2331 .
addReg(SPOrEstablisher);
2334 EmitSEHAfter(EmitSEHSetFrame);
2335 }
else if (IsFunclet &&
STI.is32Bit()) {
2340 if (!
MBB.isCleanupFuncletEntry()) {
2357 if (
Register Reg =
TII.isStoreToStackSlot(FrameInstr, FI)) {
2358 if (X86::FR64RegClass.
contains(Reg)) {
2361 if (IsWin64Prologue && IsFunclet)
2368 assert(!NeedsWinFPO &&
"SEH_SaveXMM incompatible with FPO data");
2369 auto EmitSEHSaveXMM = [&]() {
2375 EmitSEHBefore(EmitSEHSaveXMM);
2377 EmitSEHAfter(EmitSEHSaveXMM);
2385 if (NeedsWinCFI && HasWinCFI) {
2390 if (FnHasClrFunclet && !IsFunclet) {
2394 unsigned PSPSlotOffset = getPSPSlotOffsetFromSP(MF);
2408 if (IsWin64Prologue &&
TRI->hasStackRealignment(MF)) {
2409 assert(HasFP &&
"There should be a frame pointer if stack is realigned.");
2410 BuildStackAlignAND(
MBB,
MBBI,
DL, SPOrEstablisher, MaxAlign);
2414 if (IsFunclet &&
STI.is32Bit())
2421 if (
TRI->hasBasePointer(MF)) {
2447 assert(UsedReg == BasePtr);
2456 int FI =
MI->getOperand(1).getIndex();
2457 unsigned MOVmr =
Is64Bit ? X86::MOV64mr : X86::MOV32mr;
2464 if (((!HasFP && NumBytes) || PushedRegs) && NeedsDwarfCFI) {
2466 if (!HasFP && NumBytes) {
2492 bool NeedsCLD =
false;
2506 if (
MI.isInlineAsm()) {
2538 switch (
MI.getOpcode()) {
2540 case X86::CLEANUPRET:
2562X86FrameLowering::getPSPSlotOffsetFromSP(
const MachineFunction &MF)
const {
2569 return static_cast<unsigned>(
Offset);
2573X86FrameLowering::getWinEHFuncletFrameSize(
const MachineFunction &MF)
const {
2574 const X86MachineFunctionInfo *X86FI = MF.
getInfo<X86MachineFunctionInfo>();
2580 WinEHXMMSlotInfo.
size() *
TRI->getSpillSize(X86::VR128RegClass);
2589 UsedSize = getPSPSlotOffsetFromSP(MF) +
SlotSize;
2600 return FrameSizeMinusRBP + XMMSize - CSSize;
2604 return Opc == X86::TCRETURNri ||
Opc == X86::TCRETURN_WIN64ri ||
2605 Opc == X86::TCRETURN_HIPE32ri ||
Opc == X86::TCRETURNdi ||
2606 Opc == X86::TCRETURNmi ||
Opc == X86::TCRETURNri64 ||
2607 Opc == X86::TCRETURNri64_ImpCall ||
Opc == X86::TCRETURNdi64 ||
2608 Opc == X86::TCRETURNmi64 ||
Opc == X86::TCRETURN_WINmi64;
2619 DL =
MBBI->getDebugLoc();
2621 const bool Is64BitILP32 =
STI.isTarget64BitILP32();
2627 bool NeedsWin64CFI =
2631 bool IsWin64UnwindV3 =
2637 uint64_t MaxAlign = calculateMaxStackAlign(MF);
2640 bool HasFP =
hasFP(MF);
2641 uint64_t NumBytes = 0;
2643 bool NeedsDwarfCFI = (!MF.
getTarget().getTargetTriple().isOSDarwin() &&
2650 unsigned Opc = X86::LEA32r;
2652 ArgBaseReg =
MI->getOperand(0).getReg();
2653 if (
STI.is64Bit()) {
2655 StackReg = X86::RSP;
2666 if (NeedsDwarfCFI) {
2667 unsigned DwarfStackPtr =
TRI->getDwarfRegNum(StackReg,
true);
2677 assert(HasFP &&
"EH funclets without FP not yet implemented");
2678 NumBytes = getWinEHFuncletFrameSize(MF);
2681 uint64_t FrameSize = StackSize -
SlotSize;
2682 NumBytes = FrameSize - CSSize - TailCallArgReserveSize;
2686 if (
TRI->hasStackRealignment(MF) && !IsWin64Prologue)
2687 NumBytes =
alignTo(FrameSize, MaxAlign);
2689 NumBytes = StackSize - CSSize - TailCallArgReserveSize;
2691 uint64_t SEHStackAllocAmt = NumBytes;
2693 unsigned SEHFrameOffset = 0;
2694 if (IsWin64Prologue && HasFP)
2706 if (IsWin64UnwindV3)
2724 if (NeedsDwarfCFI) {
2726 unsigned DwarfStackPtr =
2727 TRI->getDwarfRegNum(
Is64Bit ? X86::RSP : X86::ESP,
true);
2732 if (!
MBB.succ_empty() && !
MBB.isReturnBlock()) {
2733 unsigned DwarfFramePtr =
TRI->getDwarfRegNum(MachineFramePtr,
true);
2748 unsigned Opc = PI->getOpcode();
2750 if (
Opc != X86::DBG_VALUE && !PI->isTerminator()) {
2752 (
Opc != X86::POP32r &&
Opc != X86::POP64r &&
Opc != X86::BTR64ri8 &&
2753 Opc != X86::ADD64ri32 &&
Opc != X86::POPP64r &&
Opc != X86::POP2 &&
2754 Opc != X86::POP2P &&
Opc != X86::LEA64r &&
Opc != X86::SEH_PushReg &&
2755 Opc != X86::SEH_Push2Regs &&
Opc != X86::SEH_StackAlloc &&
2756 Opc != X86::ADD64ri32_NF))
2766 int FI =
MI->getOperand(1).getIndex();
2767 unsigned MOVrm =
Is64Bit ? X86::MOV64rm : X86::MOV32rm;
2774 if (IsFunclet && Terminator->getOpcode() == X86::CATCHRET)
2775 emitCatchRetReturnValue(
MBB, FirstCSPop, &*Terminator);
2778 DL =
MBBI->getDebugLoc();
2784 if (IsWin64UnwindV3 && NeedsWin64CFI && MF.
hasWinCFI()) {
2787 auto EpilogStart =
MBBI;
2790 while (ScanIt !=
MBB.begin()) {
2791 auto PI = std::prev(ScanIt);
2794 TII.isLoadFromStackSlot(*PI, FI)) {
2795 Register Reg = PI->getOperand(0).getReg();
2796 if (X86::FR64RegClass.
contains(Reg)) {
2809 EpilogStart = std::prev(PI);
2810 ScanIt = EpilogStart;
2829 if (
TRI->hasStackRealignment(MF))
2831 uint64_t LEAAmount =
2832 IsWin64Prologue ? SEHStackAllocAmt - SEHFrameOffset : -CSSize;
2844 if (IsWin64UnwindV3) {
2849 if (SEHStackAllocAmt)
2851 .
addImm(SEHStackAllocAmt)
2854 if (LEAAmount != 0) {
2864 }
else if (NumBytes) {
2866 if (IsWin64UnwindV3)
2871 if (!HasFP && NeedsDwarfCFI) {
2875 nullptr, CSSize + TailCallArgReserveSize +
SlotSize),
2882 if (!IsWin64UnwindV3 && NeedsWin64CFI && MF.
hasWinCFI())
2886 if (!HasFP && NeedsDwarfCFI) {
2893 unsigned Opc = PI->getOpcode();
2895 if (
Opc == X86::POP32r ||
Opc == X86::POP64r ||
Opc == X86::POPP64r ||
2896 Opc == X86::POP2 ||
Opc == X86::POP2P) {
2900 if (
Opc == X86::POP2 ||
Opc == X86::POP2P)
2912 if (NeedsDwarfCFI && !
MBB.succ_empty())
2918 assert(Delta <= 0 &&
"TCDelta should never be positive");
2944 if (
TRI->hasBasePointer(MF))
2945 FrameReg = IsFixed ?
TRI->getFramePtr() :
TRI->getBaseRegister();
2946 else if (
TRI->hasStackRealignment(MF))
2947 FrameReg = IsFixed ?
TRI->getFramePtr() :
TRI->getStackRegister();
2949 FrameReg =
TRI->getFrameRegister(MF);
2960 int64_t FPDelta = 0;
2971 if (IsWin64Prologue) {
2975 uint64_t FrameSize = StackSize -
SlotSize;
2980 uint64_t NumBytes = FrameSize - CSSize;
2990 FPDelta = FrameSize - SEHFrameOffset;
2992 "FPDelta isn't aligned per the Win64 ABI!");
2995 if (FrameReg ==
TRI->getFramePtr()) {
3004 if (TailCallReturnAddrDelta < 0)
3005 Offset -= TailCallReturnAddrDelta;
3013 if (
TRI->hasStackRealignment(MF) ||
TRI->hasBasePointer(MF))
3023 const auto it = WinEHXMMSlotInfo.find(FI);
3025 if (it == WinEHXMMSlotInfo.end())
3028 FrameReg =
TRI->getStackRegister();
3036 int Adjustment)
const {
3038 FrameReg =
TRI->getStackRegister();
3046 bool IgnoreSPUpdates)
const {
3085 !
STI.isTargetWin64())
3096 "we don't handle this case!");
3128 std::vector<CalleeSavedInfo> &CSI)
const {
3132 unsigned CalleeSavedFrameSize = 0;
3133 unsigned XMMCalleeSavedFrameSize = 0;
3139 if (TailCallReturnAddrDelta < 0) {
3150 TailCallReturnAddrDelta -
SlotSize,
true);
3154 if (this->TRI->hasBasePointer(MF)) {
3163 bool IsFPRemovedFromCSI =
false;
3181 for (
unsigned i = 0; i < CSI.size(); ++i) {
3182 if (
TRI->regsOverlap(CSI[i].getReg(),
FPReg)) {
3183 CSI.erase(CSI.begin() + i);
3184 IsFPRemovedFromCSI =
true;
3200 unsigned NumRegsForPush2 = 0;
3203 return X86::GR64RegClass.contains(
I.getReg());
3205 bool UsePush2Pop2 = !IsFPRemovedFromCSI ? NumCSGPR > 2 : NumCSGPR > 1;
3208 ?
alignDown(IsFPRemovedFromCSI ? NumCSGPR : NumCSGPR - 1, 2)
3222 (SpillSlotOffset % 16 == 0 ||
3244 "Expect even candidates for push2/pop2");
3246 ++NumFunctionUsingPush2Pop2;
3257 unsigned Size =
TRI->getSpillSize(*RC);
3258 Align Alignment =
TRI->getSpillAlign(*RC);
3260 assert(SpillSlotOffset < 0 &&
"SpillSlotOffset should always < 0 on X86");
3261 SpillSlotOffset = -
alignTo(-SpillSlotOffset, Alignment);
3264 SpillSlotOffset -=
Size;
3270 if (X86::VR128RegClass.
contains(Reg)) {
3271 WinEHXMMSlotInfo[
SlotIndex] = XMMCalleeSavedFrameSize;
3272 XMMCalleeSavedFrameSize +=
Size;
3286 if (
MBB.isEHFuncletEntry() &&
STI.is32Bit() &&
STI.isOSWindows())
3295 auto UpdateLiveInCheckCanKill = [&](
Register Reg) {
3311 auto UpdateLiveInGetKillRegState = [&](
Register Reg) {
3315 for (
auto RI = CSI.
rbegin(), RE = CSI.
rend(); RI != RE; ++RI) {
3323 .
addReg(Reg, UpdateLiveInGetKillRegState(Reg))
3324 .
addReg(Reg2, UpdateLiveInGetKillRegState(Reg2))
3328 .
addReg(Reg, UpdateLiveInGetKillRegState(Reg))
3334 unsigned Opc =
STI.is64Bit() ? X86::PUSH64r : X86::PUSH32r;
3335 Register BaseReg = this->TRI->getBaseRegister();
3364 MBB.getParent()->getFunction().getPersonalityFn())) &&
3365 "SEH should not use CATCHRET");
3370 if (
STI.is64Bit()) {
3402 if (
MI->getOpcode() == X86::CATCHRET) {
3415 bool NeedsWin64CFI =
3432 if (IsWin64UnwindV3)
3434 .
addImm(this->TRI->getBaseRegister())
3436 unsigned Opc =
STI.is64Bit() ? X86::POP64r : X86::POP32r;
3437 Register BaseReg = this->TRI->getBaseRegister();
3443 for (
auto I = CSI.
begin(), E = CSI.
end();
I != E; ++
I) {
3450 if (IsWin64UnwindV3) {
3460 if (IsWin64UnwindV3)
3478 if (
TRI->hasBasePointer(MF)) {
3480 if (
STI.isTarget64BitILP32())
3482 SavedRegs.
set(BasePtr);
3484 if (
STI.hasUserReservedRegisters()) {
3485 for (
int Reg = SavedRegs.
find_first(); Reg != -1;
3487 if (
STI.isRegisterReservedByUser(Reg)) {
3488 SavedRegs.
reset(Reg);
3498 if (
I->hasNestAttr() && !
I->use_empty())
3515 return Primary ? X86::R14 : X86::R13;
3517 return Primary ? X86::EBX : X86::EDI;
3522 return Primary ? X86::R11 : X86::R12;
3524 return Primary ? X86::R11D : X86::R12D;
3534 "nested function.");
3535 return Primary ? X86::EAX : X86::ECX;
3538 return Primary ? X86::EDX : X86::EAX;
3539 return Primary ? X86::ECX : X86::EAX;
3550 unsigned TlsReg, TlsOffset;
3555 assert(&(*MF.
begin()) == &PrologueMBB &&
"Shrink-wrapping not supported yet");
3559 "Scratch register is live-in");
3563 if (!
STI.isTargetLinux() && !
STI.isTargetDarwin() && !
STI.isTargetWin32() &&
3564 !
STI.isTargetWin64() && !
STI.isTargetFreeBSD() &&
3565 !
STI.isTargetDragonFly())
3579 bool IsNested =
false;
3588 for (
const auto &LI : PrologueMBB.
liveins()) {
3605 if (
STI.isTargetLinux()) {
3607 TlsOffset =
IsLP64 ? 0x70 : 0x40;
3608 }
else if (
STI.isTargetDarwin()) {
3610 TlsOffset = 0x60 + 90 * 8;
3611 }
else if (
STI.isTargetWin64()) {
3614 }
else if (
STI.isTargetFreeBSD()) {
3617 }
else if (
STI.isTargetDragonFly()) {
3624 if (CompareStackPointer)
3625 ScratchReg =
IsLP64 ? X86::RSP : X86::ESP;
3643 if (
STI.isTargetLinux()) {
3646 }
else if (
STI.isTargetDarwin()) {
3648 TlsOffset = 0x48 + 90 * 4;
3649 }
else if (
STI.isTargetWin32()) {
3652 }
else if (
STI.isTargetDragonFly()) {
3655 }
else if (
STI.isTargetFreeBSD()) {
3661 if (CompareStackPointer)
3662 ScratchReg = X86::ESP;
3664 BuildMI(checkMBB,
DL,
TII.get(X86::LEA32r), ScratchReg)
3671 if (
STI.isTargetLinux() ||
STI.isTargetWin32() ||
STI.isTargetWin64() ||
3672 STI.isTargetDragonFly()) {
3680 }
else if (
STI.isTargetDarwin()) {
3683 unsigned ScratchReg2;
3685 if (CompareStackPointer) {
3688 SaveScratch2 =
false;
3700 "Scratch register is live-in and not saved");
3706 BuildMI(checkMBB,
DL,
TII.get(X86::MOV32ri), ScratchReg2)
3717 BuildMI(checkMBB,
DL,
TII.get(X86::POP32r), ScratchReg2);
3733 const unsigned RegAX =
IsLP64 ? X86::RAX : X86::EAX;
3734 const unsigned Reg10 =
IsLP64 ? X86::R10 : X86::R10D;
3735 const unsigned Reg11 =
IsLP64 ? X86::R11 : X86::R11D;
3736 const unsigned MOVrr =
IsLP64 ? X86::MOV64rr : X86::MOV32rr;
3771 if (
STI.useIndirectThunkCalls())
3773 "code model and thunks not yet implemented.");
3790 BuildMI(allocMBB,
DL,
TII.get(X86::MORESTACK_RET_RESTORE_R10));
3799#ifdef EXPENSIVE_CHECKS
3810 for (
int i = 0, e = HiPELiteralsMD->
getNumOperands(); i != e; ++i) {
3812 if (
Node->getNumOperands() != 2)
3816 if (!NodeName || !NodeVal)
3819 if (ValConst && NodeName->
getString() == LiteralName) {
3825 " required but not provided");
3836 return MI.isMetaInstruction();
3862 assert(&(*MF.
begin()) == &PrologueMBB &&
"Shrink-wrapping not supported yet");
3867 if (!HiPELiteralsMD)
3869 "Can't generate HiPE prologue without runtime parameters");
3871 HiPELiteralsMD,
Is64Bit ?
"AMD64_LEAF_WORDS" :
"X86_LEAF_WORDS");
3872 const unsigned CCRegisteredArgs =
Is64Bit ? 6 : 5;
3873 const unsigned Guaranteed = HipeLeafWords *
SlotSize;
3880 "HiPE prologue is only supported on Linux operating systems.");
3890 unsigned MoreStackForCalls = 0;
3892 for (
auto &
MBB : MF) {
3893 for (
auto &
MI :
MBB) {
3913 if (
F->getName().contains(
"erlang.") ||
F->getName().contains(
"bif_") ||
3917 unsigned CalleeStkArity =
F->arg_size() > CCRegisteredArgs
3918 ?
F->arg_size() - CCRegisteredArgs
3920 if (HipeLeafWords - 1 > CalleeStkArity)
3922 std::max(MoreStackForCalls,
3923 (HipeLeafWords - 1 - CalleeStkArity) *
SlotSize);
3926 MaxStack += MoreStackForCalls;
3931 if (MaxStack > Guaranteed) {
3935 for (
const auto &LI : PrologueMBB.
liveins()) {
3943 unsigned ScratchReg,
SPReg, PReg, SPLimitOffset;
3944 unsigned LEAop, CMPop, CALLop;
3949 LEAop = X86::LEA64r;
3950 CMPop = X86::CMP64rm;
3951 CALLop = X86::CALL64pcrel32;
3955 LEAop = X86::LEA32r;
3956 CMPop = X86::CMP32rm;
3957 CALLop = X86::CALLpcrel32;
3962 "HiPE prologue scratch register is live-in");
3969 PReg,
false, SPLimitOffset);
3979 PReg,
false, SPLimitOffset);
3989#ifdef EXPENSIVE_CHECKS
4006 if (NumPops != 1 && NumPops != 2)
4014 if (!Prev->isCall() || !Prev->getOperand(1).isRegMask())
4018 unsigned FoundRegs = 0;
4024 Is64Bit ? X86::GR64_NOREX_NOSPRegClass : X86::GR32_NOREX_NOSPRegClass;
4026 for (
auto Candidate : RegClass) {
4039 if (MO.isReg() && MO.isDef() &&
4040 TRI->isSuperOrSubRegisterEq(MO.getReg(), Candidate)) {
4049 Regs[FoundRegs++] = Candidate;
4050 if (FoundRegs == (
unsigned)NumPops)
4058 while (FoundRegs < (
unsigned)NumPops)
4059 Regs[FoundRegs++] = Regs[0];
4061 for (
int i = 0; i < NumPops; ++i)
4072 unsigned Opcode =
I->getOpcode();
4073 bool isDestroy = Opcode ==
TII.getCallFrameDestroyOpcode();
4075 uint64_t Amount =
TII.getFrameSize(*
I);
4076 uint64_t InternalAmt = (isDestroy || Amount) ?
TII.getFrameAdjustment(*
I) : 0;
4086 if (!reserveCallFrame) {
4107 bool HasDwarfEHHandlers = !WindowsCFI && !MF.
getLandingPads().empty();
4109 if (HasDwarfEHHandlers && !isDestroy &&
4119 Amount -= InternalAmt;
4129 int64_t StackAdjustment = isDestroy ? Amount : -Amount;
4130 int64_t CfaAdjustment = StackAdjustment;
4132 if (StackAdjustment) {
4141 auto CalcNewOffset = [&StackAdjustment](int64_t
Offset) {
4142 return StackAdjustment +
Offset;
4145 mergeSPUpdates(
MBB, InsertPos, CalcCfaAdjust, CalcNewOffset,
true);
4147 mergeSPUpdates(
MBB, InsertPos, CalcCfaAdjust, CalcNewOffset,
false);
4149 if (StackAdjustment) {
4150 if (!(
F.hasMinSize() &&
4151 adjustStackWithPops(
MBB, InsertPos,
DL, StackAdjustment)))
4152 BuildStackAdjustment(
MBB, InsertPos,
DL, StackAdjustment,
4178 while (CI !=
B && !std::prev(CI)->isCall())
4180 BuildStackAdjustment(
MBB, CI,
DL, -InternalAmt,
false);
4187 assert(
MBB.getParent() &&
"Block is not attached to a function!");
4189 if (!
MBB.isLiveIn(X86::EFLAGS))
4196 if (TLI.hasInlineStackProbe(MF) || TLI.hasStackProbeSymbol(MF))
4204 assert(
MBB.getParent() &&
"Block is not attached to a function!");
4210 if (
STI.isTargetWin64() && !
MBB.succ_empty() && !
MBB.isReturnBlock())
4232 bool CompactUnwind =
4248 assert(
STI.isTargetWindowsMSVC() &&
"funclets only supported in MSVC env");
4249 assert(
STI.isTargetWin32() &&
"EBP/ESI restoration only required on win32");
4251 "restoring EBP/ESI on non-32-bit target");
4263 int EHRegSize = MFI.getObjectSize(FI);
4268 X86::EBP,
true, -EHRegSize)
4274 int EndOffset = -EHRegOffset - EHRegSize;
4287 "end of registration object above normal EBP position!");
4288 }
else if (UsedReg == BasePtr) {
4298 assert(UsedReg == BasePtr);
4309 return TRI->getSlotSize();
4324 FrameBase.
Kind = DwarfFrameBase::CFA;
4330 return DwarfFrameBase{DwarfFrameBase::Register, {FrameRegister}};
4335struct X86FrameSortingObject {
4336 bool IsValid =
false;
4337 unsigned ObjectIndex = 0;
4338 unsigned ObjectSize = 0;
4340 unsigned ObjectNumUses = 0;
4356struct X86FrameSortingComparator {
4357 inline bool operator()(
const X86FrameSortingObject &
A,
4358 const X86FrameSortingObject &
B)
const {
4359 uint64_t DensityAScaled, DensityBScaled;
4379 DensityAScaled =
static_cast<uint64_t>(
A.ObjectNumUses) *
4381 DensityBScaled =
static_cast<uint64_t>(
B.ObjectNumUses) *
4392 if (DensityAScaled == DensityBScaled)
4393 return A.ObjectAlignment <
B.ObjectAlignment;
4395 return DensityAScaled < DensityBScaled;
4409 if (ObjectsToAllocate.
empty())
4421 for (
auto &Obj : ObjectsToAllocate) {
4422 SortingObjects[Obj].IsValid =
true;
4423 SortingObjects[Obj].ObjectIndex = Obj;
4427 if (ObjectSize == 0)
4429 SortingObjects[Obj].ObjectSize = 4;
4431 SortingObjects[Obj].ObjectSize = ObjectSize;
4435 for (
auto &
MBB : MF) {
4436 for (
auto &
MI :
MBB) {
4437 if (
MI.isDebugInstr())
4443 int Index = MO.getIndex();
4447 SortingObjects[Index].IsValid)
4448 SortingObjects[Index].ObjectNumUses++;
4463 for (
auto &Obj : SortingObjects) {
4467 ObjectsToAllocate[i++] = Obj.ObjectIndex;
4471 if (!
TRI->hasStackRealignment(MF) &&
hasFP(MF))
4472 std::reverse(ObjectsToAllocate.
begin(), ObjectsToAllocate.
end());
4484 Offset += getWinEHFuncletFrameSize(MF);
4499 RS->addScavengingFrameIndex(FI);
4512 adjustFrameForMsvcCxxEh(MF);
4516void X86FrameLowering::adjustFrameForMsvcCxxEh(
MachineFunction &MF)
const {
4524 int64_t MinFixedObjOffset = -
SlotSize;
4530 int FrameIndex =
H.CatchObj.FrameIndex;
4531 if ((FrameIndex != INT_MAX) && MFI.
getObjectOffset(FrameIndex) == 0) {
4534 MinFixedObjOffset -= std::abs(MinFixedObjOffset) %
Align;
4542 MinFixedObjOffset -= std::abs(MinFixedObjOffset) % 8;
4543 int64_t UnwindHelpOffset = MinFixedObjOffset -
SlotSize;
4550 MachineBasicBlock &
MBB = MF.
front();
4570 MI->eraseFromParent();
4583 bool NeedsRestore =
MBB.isEHPad() && !
MBB.isEHFuncletEntry();
4594 unsigned NumSpilledRegs) {
4596 unsigned AllocSize =
TRI->getSpillSize(*RC) * NumSpilledRegs;
4598 unsigned AlignedSize =
alignTo(AllocSize, StackAlign);
4599 return AlignedSize - AllocSize;
4605 int SPAdjust)
const {
4608 MachineBasicBlock *
MBB = BeforeMI->getParent();
4630 if (
FP.isValid() && needsDwarfCFI(MF)) {
4639 SmallString<64> CfaExpr;
4643 Offset +=
TRI->getSpillSize(*
TRI->getMinimalPhysRegClass(BP));
4646 if (
TII.isFrameSetup(*BeforeMI)) {
4648 BeforeMI = std::next(BeforeMI);
4651 if (
STI.isTarget64BitILP32())
4653 unsigned DwarfStackPtr =
TRI->getDwarfRegNum(
StackPtr,
true);
4654 CfaExpr.
push_back((uint8_t)(dwarf::DW_OP_breg0 + DwarfStackPtr));
4659 CfaExpr.
push_back((uint8_t)dwarf::DW_OP_plus);
4661 SmallString<64> DefCfaExpr;
4662 DefCfaExpr.
push_back(dwarf::DW_CFA_def_cfa_expression);
4674 int SPAdjust)
const {
4678 MachineBasicBlock *
MBB = AfterMI->getParent();
4696 if (needsDwarfCFI(MF)) {
4706void X86FrameLowering::saveAndRestoreFPBPUsingSP(
4709 assert(SpillFP || SpillBP);
4713 unsigned NumRegs = 0;
4716 FP =
TRI->getFrameRegister(MF);
4717 if (
STI.isTarget64BitILP32())
4719 RC =
TRI->getMinimalPhysRegClass(
FP);
4723 BP =
TRI->getBaseRegister();
4724 if (
STI.isTarget64BitILP32())
4726 RC =
TRI->getMinimalPhysRegClass(BP);
4731 spillFPBPUsingSP(MF, BeforeMI,
FP, BP, SPAdjust);
4732 restoreFPBPUsingSP(MF, AfterMI,
FP, BP, SPAdjust);
4735bool X86FrameLowering::skipSpillFPBP(
4737 if (
MI->getOpcode() == X86::LCMPXCHG16B_SAVE_RBX) {
4745 while (!(
MI->getOpcode() == TargetOpcode::COPY &&
4746 MI->getOperand(1).getReg() == X86::RBX) &&
4747 !((
Reg =
TII.isStoreToStackSlot(*
MI, FI)) &&
Reg == X86::RBX))
4757 AccessFP = AccessBP =
false;
4759 if (
MI.findRegisterUseOperandIdx(
FP,
TRI,
false) != -1 ||
4760 MI.findRegisterDefOperandIdx(
FP,
TRI,
false,
true) != -1)
4764 if (
MI.findRegisterUseOperandIdx(BP,
TRI,
false) != -1 ||
4765 MI.findRegisterDefOperandIdx(BP,
TRI,
false,
true) != -1)
4768 return AccessFP || AccessBP;
4781 if (!
MBB->hasEHPadSuccessor())
4794void X86FrameLowering::checkInterferedAccess(
4797 bool SpillBP)
const {
4798 if (
DefMI == KillMI)
4800 if (
TRI->hasBasePointer(MF)) {
4811 [](
const MachineOperand &MO) { return MO.isFI(); }))
4813 "Interference usage of base pointer/frame "
4844 FP =
TRI->getFrameRegister(MF);
4845 if (
TRI->hasBasePointer(MF))
4846 BP =
TRI->getBaseRegister();
4861 bool InsideEHLabels =
false;
4862 auto MI =
MBB.rbegin(), ME =
MBB.rend();
4863 auto TermMI =
MBB.getFirstTerminator();
4864 if (TermMI ==
MBB.begin())
4866 MI = *(std::prev(TermMI));
4874 isInvoke(*
MI, InsideEHLabels) || skipSpillFPBP(MF,
MI)) {
4879 if (
MI->getOpcode() == TargetOpcode::EH_LABEL) {
4880 InsideEHLabels = !InsideEHLabels;
4885 bool AccessFP, AccessBP;
4894 bool FPLive =
false, BPLive =
false;
4895 bool SpillFP =
false, SpillBP =
false;
4898 SpillFP |= AccessFP;
4899 SpillBP |= AccessBP;
4902 if (FPLive &&
MI->findRegisterDefOperandIdx(
FP,
TRI,
false,
true) != -1)
4904 if (
FP &&
MI->findRegisterUseOperandIdx(
FP,
TRI,
false) != -1)
4906 if (BPLive &&
MI->findRegisterDefOperandIdx(BP,
TRI,
false,
true) != -1)
4908 if (BP &&
MI->findRegisterUseOperandIdx(BP,
TRI,
false) != -1)
4912 }
while ((
MI != ME) &&
4913 (FPLive || BPLive ||
4917 if (FPLive && !SpillBP)
4922 if (KillMI->isCall() &&
DefMI != ME) {
4923 auto FrameSetup = std::next(
DefMI);
4927 while (FrameSetup != ME && !
TII.isFrameSetup(*FrameSetup) &&
4928 !FrameSetup->isCall())
4932 if (FrameSetup != ME &&
TII.isFrameSetup(*FrameSetup) &&
4933 (
TII.getFrameSize(*FrameSetup) ||
4934 TII.getFrameAdjustment(*FrameSetup))) {
4935 while (!
TII.isFrameInstr(*KillMI))
4943 checkInterferedAccess(MF,
DefMI, KillMI, SpillFP, SpillBP);
4946 saveAndRestoreFPBPUsingSP(MF, &(*
DefMI), &(*KillMI), SpillFP, SpillBP);
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static const uint64_t kSplitStackAvailable
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
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")
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
static bool isTailCallOpcode(unsigned Opc)
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static constexpr MCPhysReg FPReg
static constexpr MCPhysReg SPReg
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool is64Bit(const char *name)
static unsigned calculateSetFPREG(uint64_t SPAdjust)
static unsigned GetScratchRegister(bool Is64Bit, bool IsLP64, const MachineFunction &MF, bool Primary)
GetScratchRegister - Get a temp register for performing work in the segmented stack and the Erlang/Hi...
static unsigned getADDriOpcode(bool IsLP64)
static unsigned getPUSH2Opcode(const X86Subtarget &ST)
static uint64_t getUnusedLocalAreaPadding(const MachineFrameInfo &MFI)
Returns the number of bytes between the end of the fixed and callee-save area and the first local obj...
static unsigned getLEArOpcode(bool IsLP64)
static unsigned getSUBriOpcode(bool IsLP64)
static bool flagsNeedToBePreservedBeforeTheTerminators(const MachineBasicBlock &MBB)
Check if the flags need to be preserved before the terminators.
static bool isFPBPAccess(const MachineInstr &MI, Register FP, Register BP, const TargetRegisterInfo *TRI, bool &AccessFP, bool &AccessBP)
static const TargetRegisterClass * getCalleeSavedSpillRC(MCRegister Reg, const X86Subtarget &STI, const TargetRegisterInfo &TRI)
static bool isOpcodeRep(unsigned Opcode)
Return true if an opcode is part of the REP group of instructions.
static unsigned getANDriOpcode(bool IsLP64, int64_t Imm)
static bool isEAXLiveIn(MachineBasicBlock &MBB)
static int computeFPBPAlignmentGap(MachineFunction &MF, const TargetRegisterClass *RC, unsigned NumSpilledRegs)
static unsigned getADDrrOpcode(bool IsLP64)
static bool HasNestArgument(const MachineFunction *MF)
static unsigned getPOPOpcode(const X86Subtarget &ST)
static bool isInvoke(const MachineInstr &MI, bool InsideEHLabels)
static unsigned getPOP2Opcode(const X86Subtarget &ST)
static unsigned getHiPELiteral(NamedMDNode *HiPELiteralsMD, const StringRef LiteralName)
Lookup an ERTS parameter in the !hipe.literals named metadata node.
static bool blockEndIsUnreachable(const MachineBasicBlock &MBB, MachineBasicBlock::const_iterator MBBI)
static unsigned getSUBrrOpcode(bool IsLP64)
static unsigned getPUSHOpcode(const X86Subtarget &ST)
constexpr uint64_t MaxSPChunk
static const unsigned FramePtr
Represent a constant reference to an array (0 or more elements consecutively in memory),...
reverse_iterator rend() const
bool empty() const
Check if the array is empty.
reverse_iterator rbegin() const
BitVector & reset()
Reset all bits in the bitvector.
int find_first() const
Returns the index of the first set bit, -1 if none of the bits are set.
BitVector & set()
Set all bits in the bitvector.
int find_next(unsigned Prev) const
Returns the index of the next set bit following the "Prev" bit.
iterator_range< const_set_bits_iterator > set_bits() const
static constexpr BranchProbability getOne()
static constexpr BranchProbability getZero()
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
This is the shared class of boolean and integer constants.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasPersonalityFn() const
Check whether this function has a personality function.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
AttributeList getAttributes() const
Return the attribute list for this Function.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
const Argument * const_arg_iterator
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...
bool usesWindowsCFI() const
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int64_t Size, SMLoc Loc={})
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
static MCCFIInstruction createRememberState(MCSymbol *L, SMLoc Loc={})
.cfi_remember_state Save all current rules for all registers.
OpType getOperation() const
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals, SMLoc Loc={}, StringRef Comment="")
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int64_t Adjustment, SMLoc Loc={})
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
static MCCFIInstruction createRestoreState(MCSymbol *L, SMLoc Loc={})
.cfi_restore_state Restore the previously saved state.
const MCObjectFileInfo * getObjectFileInfo() const
const MCRegisterInfo * getRegisterInfo() const
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
MCSection * getCompactUnwindSection() const
MCRegAliasIterator enumerates all registers aliasing Reg.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
virtual int64_t getDwarfRegNum(MCRegister Reg, bool isEH) const
Map a target register to an equivalent dwarf register number.
Wrapper class representing physical registers. Should be passed by value.
LLVM_ABI StringRef getString() const
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
MachineInstrBundleIterator< const MachineInstr > const_iterator
iterator_range< livein_iterator > liveins() const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, MCRegister Reg, const_iterator Before, unsigned Neighborhood=10) const
Return whether (physical) register Reg has been defined and not killed as of just before Before.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
LLVM_ABI iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
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.
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
@ LQR_Live
Register is known to be (at least partially) live.
void setMachineBlockAddressTaken()
Set this block to indicate that its address is used as something other than the target of a terminato...
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
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.
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 ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
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.
LLVM_ABI void ensureMaxAlignment(Align Alignment)
Make sure the function's frame is at least Align bytes aligned.
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...
Align getMaxAlign() const
Return alignment of this function's frame.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
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 hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
void setCVBytesOfCalleeSavedRegisters(unsigned S)
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
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 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.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasCopyImplyingStackAdjustment() const
Returns true if the function contains operations which will lower down to instructions which manipula...
bool hasStackObjects() const
Return true if there are any stack objects in this function.
LLVM_ABI int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
void setStackSize(uint64_t Size)
Set the size of the stack.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
int getObjectIndexBegin() const
Return the minimum frame object index.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
void setOffsetAdjustment(int64_t Adj)
Set the correction for frame offsets.
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
unsigned addFrameInst(const MCCFIInstruction &Inst)
void setHasWinCFI(bool v)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const std::vector< MCCFIInstruction > & getFrameInstructions() const
Returns a reference to a list of cfi instructions in the function's prologue.
bool hasInlineAsm() const
Returns true if the function contains any inline assembly.
void makeDebugValueSubstitution(DebugInstrOperandPair, DebugInstrOperandPair, unsigned SubReg=0)
Create a substitution between one <instr,operand> value to a different, new value.
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool callsUnwindInit() const
void push_front(MachineBasicBlock *MBB)
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
MCContext & getContext() const
bool callsEHReturn() const
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
BasicBlockListType::iterator iterator
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...
const MachineBasicBlock & front() const
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
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 & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
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 & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Representation of each machine instruction.
unsigned getNumOperands() const
Retuns the total number of operands.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI unsigned getDebugInstrNum()
Fetch the instruction number of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
@ MOVolatile
The memory access is volatile.
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
MachineBasicBlock * getMBB() const
void setIsDead(bool Val=true)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
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
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
WinX64EHUnwindMode getWinX64EHUnwindMode() const
Get how unwind information should be generated for x64 Windows.
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
SlotIndex - An opaque wrapper around machine indexes.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
StringRef str() const
Explicit conversion to StringRef.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
StackOffset holds a fixed and a scalable offset in bytes.
int64_t getFixed() const
Returns the fixed component of the stack.
static StackOffset getFixed(int64_t Fixed)
Represent a constant reference to a string, i.e.
static constexpr size_t npos
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...
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
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...
const Triple & getTargetTriple() const
const MCAsmInfo & getMCAsmInfo() const
Return target specific asm information.
CodeModel::Model getCodeModel() const
Returns the code model.
SwiftAsyncFramePointerMode SwiftAsyncFramePointer
Control when and how the Swift async frame pointer bit should be set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
bool isUEFI() const
Tests whether the OS is UEFI.
bool isOSWindows() const
Tests whether the OS is Windows.
bool has128ByteRedZone(const MachineFunction &MF) const
Return true if the function has a redzone (accessible bytes past the frame of the top of stack functi...
void spillFPBP(MachineFunction &MF) const override
If a function uses base pointer and the base pointer is clobbered by inline asm, RA doesn't detect th...
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
canSimplifyCallFramePseudos - If there is a reserved call frame, the call frame pseudos can be simpli...
bool needsFrameIndexResolution(const MachineFunction &MF) const override
X86FrameLowering(const X86Subtarget &STI, MaybeAlign StackAlignOverride)
const X86RegisterInfo * TRI
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
bool hasFPImpl(const MachineFunction &MF) const override
hasFPImpl - Return true if the specified function should have a dedicated frame pointer register.
MachineBasicBlock::iterator restoreWin32EHStackPointers(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool RestoreSP=false) const
Sets up EBP and optionally ESI based on the incoming EBP value.
int getInitialCFAOffset(const MachineFunction &MF) const override
Return initial CFA offset value i.e.
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
void emitStackProbe(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool InProlog, std::optional< MachineFunction::DebugInstrOperandPair > InstrNum=std::nullopt) const
Emit target stack probe code.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool IsPrologue) const
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
int64_t mergeSPAdd(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, int64_t AddOffset, bool doMergeWithPrevious) const
Equivalent to: mergeSPUpdates(MBB, MBBI, [AddOffset](int64_t Offset) { return AddOffset + Offset; }...
StackOffset getFrameIndexReferenceSP(const MachineFunction &MF, int FI, Register &SPReg, int Adjustment) const
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe inline-stub with the actual probe code inline.
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...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &DL, int64_t NumBytes, bool InEpilogue) const
Emit a series of instructions to increment / decrement the stack pointer by a constant value.
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
bool Is64Bit
Is64Bit implies that x86_64 instructions are available.
Register getInitialCFARegister(const MachineFunction &MF) const override
Return initial CFA register value i.e.
bool Uses64BitFramePtr
True if the 64-bit frame or stack pointer should be used.
unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override
void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Adjust the prologue to have the function use segmented stacks.
DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override
Return the frame base information to be encoded in the DWARF subprogram debug info.
void emitCalleeSavedFrameMovesFullCFA(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) const override
Emits Dwarf Info specifying offsets of callee saved registers and frame pointer.
int getWin64EHFrameIndexRef(const MachineFunction &MF, int FI, Register &SPReg) const
bool canUseLEAForSPInEpilogue(const MachineFunction &MF) const
Check that LEA can be used on SP in an epilogue sequence for MF.
bool stackProbeFunctionModifiesSP() const override
Does the stack probe function call return with a modified stack pointer?
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack.
void BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const MCCFIInstruction &CFIInst, MachineInstr::MIFlag Flag=MachineInstr::NoFlags) const
Wraps up getting a CFI index and building a MachineInstr for it.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
StackOffset getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, Register &FrameReg, bool IgnoreSPUpdates) const override
Same as getFrameIndexReference, except that the stack pointer (as opposed to the frame pointer) will ...
void restoreWinEHStackPointersInParent(MachineFunction &MF) const
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...
void adjustForHiPEPrologue(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Erlang programs may need a special prologue to handle the stack size they might need at runtime.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
bool getForceFramePointer() const
bool isCandidateForPush2Pop2(Register Reg) const
unsigned getArgumentStackSize() const
bool getFPClobberedByCall() const
int getRestoreBasePointerOffset() const
int getSEHFramePtrSaveIndex() const
bool hasCFIAdjustCfa() const
int getTCReturnAddrDelta() const
void setRestoreBasePointer(const MachineFunction *MF)
bool getHasSEHFramePtrSave() const
DenseMap< int, unsigned > & getWinEHXMMSlotInfo()
bool getBPClobberedByCall() const
void setUsesRedZone(bool V)
bool hasPreallocatedCall() const
bool hasSwiftAsyncContext() const
void setHasSEHFramePtrSave(bool V)
bool getRestoreBasePointer() const
MachineInstr * getStackPtrSaveMI() const
size_t getNumCandidatesForPush2Pop2() const
AMXProgModelEnum getAMXProgModel() const
void addCandidateForPush2Pop2(Register Reg)
unsigned getCalleeSavedFrameSize() const
bool getHasPushSequences() const
void setStackPtrSaveMI(MachineInstr *MI)
bool getUsesRedZone() const
void setCalleeSavedFrameSize(unsigned bytes)
void setSEHFramePtrSaveIndex(int Index)
const X86TargetLowering * getTargetLowering() const override
bool isTargetWindowsCoreCLR() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
uint16_t StackAdjustment(const RuntimeFunction &RF)
StackAdjustment - calculated stack adjustment in words.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ HiPE
Used by the High-Performance Erlang Compiler (HiPE).
@ X86_INTR
x86 hardware interrupt context.
@ Fast
Attempts to make calls as fast as possible (e.g.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ X86_FastCall
'fast' analog of X86_StdCall.
@ BasicBlock
Various leaf nodes.
@ MO_GOTPCREL
MO_GOTPCREL - On a symbol operand this indicates that the immediate is offset to the GOT entry for th...
unsigned getMOVriOpcode(bool Use64BitReg, int64_t Imm)
Return a MOVri opcode for materializing Imm into a 32- or 64-bit GPR.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
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.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Kill
The last use of a register.
@ Undef
Value of the register doesn't matter.
@ Define
Register definition.
constexpr RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0, bool mem=true)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
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.
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
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.
static bool isFuncletReturnInstr(const MachineInstr &MI)
auto reverse(ContainerTy &&C)
@ Always
Always set the bit.
@ Never
Never set the bit.
@ DeploymentBased
Determine whether to set the bit statically or dynamically based on the deployment target.
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)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
bool requireWinX64UnwindV3(const MachineFunction &MF)
Returns true when MF must use Windows x64 Unwind V3: the module is in V3 mode, or the function needs ...
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
IterT skipDebugInstructionsBackward(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
@ DwarfCFI
DWARF-like instruction based exceptions.
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
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.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
LLVM_ABI void computeAndAddLiveIns(LivePhysRegs &LiveRegs, MachineBasicBlock &MBB)
Convenience function combining computeLiveIns() and addLiveIns().
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
static const MachineInstrBuilder & addRegOffset(const MachineInstrBuilder &MIB, Register Reg, bool isKill, int Offset)
addRegOffset - This function is used to add a memory reference of the form [Reg + Offset],...
constexpr RegState getUndefRegState(bool B)
void fullyRecomputeLiveIns(ArrayRef< MachineBasicBlock * > MBBs)
Convenience function for recomputing live-in's for a set of MBBs until the computation converges.
MCRegisterClass TargetRegisterClass
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.
This class contains a discriminated union of information about pointers in memory operands,...
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
union llvm::TargetFrameLowering::DwarfFrameBase::@004076321055032247336074224075335064105264310375 Location
enum llvm::TargetFrameLowering::DwarfFrameBase::FrameBaseKind Kind
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
SmallVector< WinEHHandlerType, 1 > HandlerArray