41 STI(STI),
TII(*STI.getInstrInfo()),
TRI(STI.getRegisterInfo()) {
63 (
hasFP(MF) && !
TRI->needsStackRealignment(MF)) ||
86 TRI->needsStackRealignment(MF) ||
99 return X86::SUB64ri32;
102 return X86::SUB32ri8;
110 return X86::ADD64ri8;
111 return X86::ADD64ri32;
114 return X86::ADD32ri8;
120 return IsLP64 ? X86::SUB64rr : X86::SUB32rr;
124 return IsLP64 ? X86::ADD64rr : X86::ADD32rr;
130 return X86::AND64ri8;
131 return X86::AND64ri32;
134 return X86::AND32ri8;
139 return IsLP64 ? X86::LEA64r : X86::LEA32r;
155 if (MBBI == MBB.
end())
158 switch (MBBI->getOpcode()) {
160 case TargetOpcode::PATCHABLE_RET:
166 case X86::TCRETURNdi:
167 case X86::TCRETURNri:
168 case X86::TCRETURNmi:
169 case X86::TCRETURNdi64:
170 case X86::TCRETURNri64:
171 case X86::TCRETURNmi64:
173 case X86::EH_RETURN64: {
175 for (
unsigned i = 0,
e = MBBI->getNumOperands(); i !=
e; ++i) {
186 for (
auto CS : AvailableRegs)
187 if (!Uses.
count(CS) && CS != X86::RIP && CS != X86::RSP &&
198 unsigned Reg = RegMask.PhysReg;
200 if (Reg == X86::RAX || Reg ==
X86::EAX || Reg == X86::AX ||
201 Reg == X86::AH || Reg ==
X86::AL)
215 bool BreakNext =
false;
220 if (Reg != X86::EFLAGS)
241 if (Succ->isLiveIn(X86::EFLAGS))
252 int64_t NumBytes,
bool InEpilogue)
const {
253 bool isSub = NumBytes < 0;
254 uint64_t
Offset = isSub ? -NumBytes : NumBytes;
258 uint64_t Chunk = (1LL << 31) - 1;
260 if (Offset > Chunk) {
271 unsigned MovRIOpc =
Is64Bit ? X86::MOV64ri : X86::MOV32ri;
272 unsigned AddSubRROpc =
283 }
else if (Offset > 8 * Chunk) {
301 BuildMI(MBB, MBBI, DL,
TII.get(MovRIOpc), Rax)
310 BuildMI(MBB, MBBI, DL,
TII.get(X86::XCHG64rm), Rax).addReg(Rax),
320 uint64_t ThisVal = std::min(Offset, Chunk);
329 ? (
Is64Bit ? X86::PUSH64r : X86::PUSH32r)
330 : (
Is64Bit ? X86::POP64r : X86::POP32r);
339 BuildStackAdjustment(MBB, MBBI, DL, isSub ? -ThisVal : ThisVal, InEpilogue)
349 assert(
Offset != 0 &&
"zero offset stack adjustment requested");
372 "We shouldn't have allowed this insertion point");
396 bool doMergeWithPrevious)
const {
397 if ((doMergeWithPrevious && MBBI == MBB.
begin()) ||
398 (!doMergeWithPrevious && MBBI == MBB.
end()))
415 if (doMergeWithPrevious && PI != MBB.
begin() && PI->isCFIInstruction())
418 unsigned Opc = PI->getOpcode();
421 if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 ||
422 Opc == X86::ADD32ri || Opc == X86::ADD32ri8) &&
423 PI->getOperand(0).getReg() ==
StackPtr){
425 Offset = PI->getOperand(2).getImm();
426 }
else if ((Opc == X86::LEA32r || Opc == X86::LEA64_32r) &&
427 PI->getOperand(0).getReg() ==
StackPtr &&
428 PI->getOperand(1).getReg() ==
StackPtr &&
429 PI->getOperand(2).getImm() == 1 &&
430 PI->getOperand(3).getReg() == X86::NoRegister &&
431 PI->getOperand(5).getReg() == X86::NoRegister) {
433 Offset = PI->getOperand(4).getImm();
434 }
else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 ||
435 Opc == X86::SUB32ri || Opc == X86::SUB32ri8) &&
436 PI->getOperand(0).getReg() ==
StackPtr) {
438 Offset = -PI->getOperand(2).getImm();
443 if (PI != MBB.
end() && PI->isCFIInstruction()) PI = MBB.
erase(PI);
444 if (!doMergeWithPrevious)
456 BuildMI(MBB, MBBI, DL,
TII.get(TargetOpcode::CFI_INSTRUCTION))
457 .addCFIIndex(CFIIndex);
470 if (CSI.empty())
return;
473 for (std::vector<CalleeSavedInfo>::const_iterator
474 I = CSI.begin(),
E = CSI.end();
I !=
E; ++
I) {
476 unsigned Reg =
I->getReg();
487 const DebugLoc &DL,
bool InProlog)
const {
491 emitStackProbeInlineStub(MF, MBB, MBBI, DL,
true);
493 emitStackProbeInline(MF, MBB, MBBI, DL,
false);
496 emitStackProbeCall(MF, MBB, MBBI, DL, InProlog);
502 const StringRef ChkStkStubSymbol =
"__chkstk_stub";
506 if (
MI.isCall() &&
MI.getOperand(0).isSymbol() &&
507 ChkStkStubSymbol ==
MI.getOperand(0).getSymbolName()) {
513 if (ChkStkStub !=
nullptr) {
515 "Not expecting bundled instructions here");
517 assert(std::prev(MBBI) == ChkStkStub &&
518 "MBBI expected after __chkstk_stub.");
519 DebugLoc DL = PrologMBB.findDebugLoc(MBBI);
520 emitStackProbeInline(MF, PrologMBB, MBBI, DL,
true);
529 bool InProlog)
const {
531 assert(STI.
is64Bit() &&
"different expansion needed for 32 bit");
569 MF.
insert(MBBIter, RoundMBB);
570 MF.
insert(MBBIter, LoopMBB);
571 MF.
insert(MBBIter, ContinueMBB);
579 const int64_t ThreadEnvironmentStackLimit = 0x10;
581 const int64_t PageMask = ~(PageSize - 1);
587 const Register SizeReg = InProlog ? X86::RAX
589 ZeroReg = InProlog ? X86::RCX
591 CopyReg = InProlog ? X86::RDX
593 TestReg = InProlog ? X86::RDX
595 FinalReg = InProlog ? X86::RDX
597 RoundedReg = InProlog ? X86::RDX
599 LimitReg = InProlog ? X86::RCX
601 JoinReg = InProlog ? X86::RCX
603 ProbeReg = InProlog ? X86::RCX
607 int64_t RCXShadowSlot = 0;
608 int64_t RDXShadowSlot = 0;
617 const bool HasFP =
hasFP(MF);
622 const bool IsRCXLiveIn = MBB.
isLiveIn(X86::RCX);
623 const bool IsRDXLiveIn = MBB.
isLiveIn(X86::RDX);
624 int64_t InitSlot = 8 + CalleeSaveSize + (HasFP ? 8 : 0);
628 RCXShadowSlot = InitSlot;
630 RDXShadowSlot = InitSlot;
631 if (IsRDXLiveIn && IsRCXLiveIn)
644 BuildMI(&MBB, DL, TII.
get(X86::MOV64rr), SizeReg).addReg(X86::RAX);
649 BuildMI(&MBB, DL, TII.
get(X86::XOR64rr), ZeroReg)
652 BuildMI(&MBB, DL, TII.
get(X86::MOV64rr), CopyReg).addReg(X86::RSP);
653 BuildMI(&MBB, DL, TII.
get(X86::SUB64rr), TestReg)
656 BuildMI(&MBB, DL, TII.
get(X86::CMOV64rr), FinalReg)
668 BuildMI(&MBB, DL, TII.
get(X86::MOV64rm), LimitReg)
672 .
addImm(ThreadEnvironmentStackLimit)
680 BuildMI(RoundMBB, DL, TII.
get(X86::AND64ri32), RoundedReg)
683 BuildMI(RoundMBB, DL, TII.
get(X86::JMP_1)).addMBB(LoopMBB);
689 BuildMI(LoopMBB, DL, TII.
get(X86::PHI), JoinReg)
721 TII.
get(X86::MOV64rm), X86::RCX),
722 X86::RSP,
false, RCXShadowSlot);
725 TII.
get(X86::MOV64rm), X86::RDX),
726 X86::RSP,
false, RDXShadowSlot);
732 BuildMI(*ContinueMBB, ContinueMBBI, DL, TII.
get(X86::SUB64rr), X86::RSP)
745 for (++BeforeMBBI; BeforeMBBI != MBB.
end(); ++BeforeMBBI) {
755 CMBBI != ContinueMBBI; ++CMBBI) {
765 bool InProlog)
const {
771 "code model and retpoline not yet implemented.");
775 CallOp = IsLargeCodeModel ? X86::CALL64r : X86::CALL64pcrel32;
777 CallOp = X86::CALLpcrel32;
789 BuildMI(MBB, MBBI, DL,
TII.get(X86::MOV64ri), X86::R11)
791 CI =
BuildMI(MBB, MBBI, DL,
TII.get(CallOp)).addReg(X86::R11);
819 for (++ExpansionMBBI; ExpansionMBBI != MBBI; ++ExpansionMBBI)
824 void X86FrameLowering::emitStackProbeInlineStub(
828 assert(InProlog &&
"ChkStkStub called outside prolog!");
830 BuildMI(MBB, MBBI, DL,
TII.get(X86::CALLpcrel32))
831 .addExternalSymbol(
"__chkstk_stub");
837 const uint64_t Win64MaxSEHOffset = 128;
838 uint64_t SEHFrameOffset = std::min(SPAdjust, Win64MaxSEHOffset);
840 return SEHFrameOffset & -16;
847 uint64_t X86FrameLowering::calculateMaxStackAlign(
const MachineFunction &MF)
const {
853 MaxAlign = (StackAlign > MaxAlign) ? StackAlign : MaxAlign;
863 uint64_t MaxAlign)
const {
864 uint64_t Val = -MaxAlign;
879 "MF used frame lowering for wrong subtarget");
974 "MF used frame lowering for wrong subtarget");
980 uint64_t MaxAlign = calculateMaxStackAlign(MF);
986 bool FnHasClrFunclet =
988 bool IsClrFunclet = IsFunclet && FnHasClrFunclet;
989 bool HasFP =
hasFP(MF);
995 bool NeedsWinCFI = NeedsWin64CFI || NeedsWinFPO;
1002 bool HasWinCFI =
false;
1010 if (TailCallReturnAddrDelta && IsWin64Prologue)
1013 if (TailCallReturnAddrDelta < 0)
1036 !
TRI->needsStackRealignment(MF) &&
1045 StackSize =
std::max(MinSize, StackSize > 128 ? StackSize - 128 : 0);
1052 if (TailCallReturnAddrDelta < 0) {
1053 BuildStackAdjustment(MBB, MBBI, DL, TailCallReturnAddrDelta,
1072 uint64_t NumBytes = 0;
1076 Register Establisher = X86::NoRegister;
1082 if (IsWin64Prologue && IsFunclet && !IsClrFunclet) {
1097 uint64_t FrameSize = StackSize -
SlotSize;
1100 FrameSize += SlotSize;
1105 if (
TRI->needsStackRealignment(MF) && !IsWin64Prologue)
1106 NumBytes =
alignTo(NumBytes, MaxAlign);
1113 if (NeedsDwarfCFI) {
1121 unsigned DwarfFramePtr =
TRI->getDwarfRegNum(MachineFramePtr,
true);
1123 nullptr, DwarfFramePtr, 2 * stackGrowth));
1128 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_PushReg))
1133 if (!IsWin64Prologue && !IsFunclet) {
1141 if (NeedsDwarfCFI) {
1144 unsigned DwarfFramePtr =
TRI->getDwarfRegNum(MachineFramePtr,
true);
1146 nullptr, DwarfFramePtr));
1152 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_SetFrame))
1159 assert(!IsFunclet &&
"funclets without FPs not yet implemented");
1166 if (HasFP &&
TRI->needsStackRealignment(MF))
1174 unsigned ParentFrameNumBytes = NumBytes;
1176 NumBytes = getWinEHFuncletFrameSize(MF);
1179 bool PushedRegs =
false;
1182 while (MBBI != MBB.
end() &&
1184 (MBBI->getOpcode() == X86::PUSH32r ||
1185 MBBI->getOpcode() == X86::PUSH64r)) {
1187 Register Reg = MBBI->getOperand(0).getReg();
1190 if (!HasFP && NeedsDwarfCFI) {
1196 StackOffset += stackGrowth;
1201 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_PushReg))
1210 if (!IsWin64Prologue && !IsFunclet &&
TRI->needsStackRealignment(MF)) {
1211 assert(HasFP &&
"There should be a frame pointer if stack is realigned.");
1212 BuildStackAlignAND(MBB, MBBI, DL,
StackPtr, MaxAlign);
1216 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_StackAlign))
1237 uint64_t AlignedNumBytes = NumBytes;
1238 if (IsWin64Prologue && !IsFunclet &&
TRI->needsStackRealignment(MF))
1239 AlignedNumBytes =
alignTo(AlignedNumBytes, MaxAlign);
1240 if (AlignedNumBytes >= StackProbeSize && UseStackProbe) {
1242 "The Red Zone is not accounted for in stack probes");
1250 BuildMI(MBB, MBBI, DL,
TII.get(X86::PUSH64r))
1255 BuildMI(MBB, MBBI, DL,
TII.get(X86::PUSH32r))
1264 int64_t Alloc = isEAXAlive ? NumBytes - 8 : NumBytes;
1270 BuildMI(MBB, MBBI, DL,
TII.get(X86::MOV64ri32), X86::RAX)
1274 BuildMI(MBB, MBBI, DL,
TII.get(X86::MOV64ri), X86::RAX)
1282 .addImm(isEAXAlive ? NumBytes - 4 : NumBytes)
1301 }
else if (NumBytes) {
1302 emitSPUpdate(MBB, MBBI, DL, -(int64_t)NumBytes,
false);
1305 if (NeedsWinCFI && NumBytes) {
1307 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_StackAlloc))
1312 int SEHFrameOffset = 0;
1313 unsigned SPOrEstablisher;
1320 unsigned PSPSlotOffset = getPSPSlotOffsetFromSP(MF);
1324 Establisher,
false, PSPSlotOffset)
1331 false, PSPSlotOffset)
1338 SPOrEstablisher = Establisher;
1343 if (IsWin64Prologue && HasFP) {
1350 SPOrEstablisher,
false, SEHFrameOffset);
1352 BuildMI(MBB, MBBI, DL,
TII.get(X86::MOV64rr), FramePtr)
1353 .addReg(SPOrEstablisher);
1356 if (NeedsWinCFI && !IsFunclet) {
1357 assert(!NeedsWinFPO &&
"this setframe incompatible with FPO data");
1359 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_SetFrame))
1390 if (X86::FR64RegClass.
contains(Reg)) {
1392 unsigned IgnoredFrameReg;
1393 if (IsWin64Prologue && IsFunclet)
1400 assert(!NeedsWinFPO &&
"SEH_SaveXMM incompatible with FPO data");
1401 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_SaveXMM))
1410 if (NeedsWinCFI && HasWinCFI)
1411 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_EndPrologue))
1414 if (FnHasClrFunclet && !IsFunclet) {
1418 unsigned PSPSlotOffset = getPSPSlotOffsetFromSP(MF);
1432 if (IsWin64Prologue &&
TRI->needsStackRealignment(MF)) {
1433 assert(HasFP &&
"There should be a frame pointer if stack is realigned.");
1434 BuildStackAlignAND(MBB, MBBI, DL, SPOrEstablisher, MaxAlign);
1448 BuildMI(MBB, MBBI, DL,
TII.get(Opc), BasePtr)
1449 .addReg(SPOrEstablisher)
1457 .addReg(SPOrEstablisher)
1470 assert(UsedReg == BasePtr);
1477 if (((!HasFP && NumBytes) || PushedRegs) && NeedsDwarfCFI) {
1479 if (!HasFP && NumBytes) {
1483 nullptr, -StackSize + stackGrowth));
1542 X86FrameLowering::getPSPSlotOffsetFromSP(
const MachineFunction &MF)
const {
1548 return static_cast<unsigned>(
Offset);
1552 X86FrameLowering::getWinEHFuncletFrameSize(
const MachineFunction &MF)
const {
1558 unsigned XMMSize = WinEHXMMSlotInfo.
size() *
1559 TRI->getSpillSize(X86::VR128RegClass);
1568 UsedSize = getPSPSlotOffsetFromSP(MF) +
SlotSize;
1579 return FrameSizeMinusRBP + XMMSize - CSSize;
1583 return Opc == X86::TCRETURNri || Opc == X86::TCRETURNdi ||
1584 Opc == X86::TCRETURNmi ||
1585 Opc == X86::TCRETURNri64 || Opc == X86::TCRETURNdi64 ||
1586 Opc == X86::TCRETURNmi64;
1596 if (MBBI != MBB.
end())
1597 DL = MBBI->getDebugLoc();
1601 unsigned MachineFramePtr =
1605 bool NeedsWin64CFI =
1611 uint64_t MaxAlign = calculateMaxStackAlign(MF);
1613 bool HasFP =
hasFP(MF);
1614 uint64_t NumBytes = 0;
1621 assert(HasFP &&
"EH funclets without FP not yet implemented");
1622 NumBytes = getWinEHFuncletFrameSize(MF);
1625 uint64_t FrameSize = StackSize -
SlotSize;
1626 NumBytes = FrameSize - CSSize;
1630 if (
TRI->needsStackRealignment(MF) && !IsWin64Prologue)
1631 NumBytes =
alignTo(FrameSize, MaxAlign);
1633 NumBytes = StackSize - CSSize;
1635 uint64_t SEHStackAllocAmt = NumBytes;
1642 if (NeedsDwarfCFI) {
1643 unsigned DwarfStackPtr =
1646 nullptr, DwarfStackPtr, -
SlotSize));
1653 while (MBBI != MBB.
begin()) {
1655 unsigned Opc = PI->getOpcode();
1657 if (Opc != X86::DBG_VALUE && !PI->isTerminator()) {
1669 emitCatchRetReturnValue(MBB, FirstCSPop, &*Terminator);
1671 if (MBBI != MBB.
end())
1672 DL = MBBI->getDebugLoc();
1685 if (
TRI->needsStackRealignment(MF))
1688 uint64_t LEAAmount =
1689 IsWin64Prologue ? SEHStackAllocAmt - SEHFrameOffset : -CSSize;
1698 if (LEAAmount != 0) {
1701 FramePtr,
false, LEAAmount);
1709 }
else if (NumBytes) {
1712 if (!
hasFP(MF) && NeedsDwarfCFI) {
1727 BuildMI(MBB, MBBI, DL,
TII.get(X86::SEH_Epilogue));
1729 if (!
hasFP(MF) && NeedsDwarfCFI) {
1734 while (MBBI != MBB.
end()) {
1736 unsigned Opc = PI->getOpcode();
1738 if (Opc == X86::POP32r || Opc == X86::POP64r) {
1749 assert(Offset >= 0 &&
"TCDelta should never be positive");
1759 unsigned &FrameReg)
const {
1768 else if (
TRI->needsStackRealignment(MF))
1781 bool HasFP =
hasFP(MF);
1783 int64_t FPDelta = 0;
1794 if (IsWin64Prologue) {
1798 uint64_t FrameSize = StackSize -
SlotSize;
1801 FrameSize += SlotSize;
1802 uint64_t NumBytes = FrameSize - CSSize;
1806 return -SEHFrameOffset;
1812 FPDelta = FrameSize - SEHFrameOffset;
1814 "FPDelta isn't aligned per the Win64 ABI!");
1819 assert(HasFP &&
"VLAs and dynamic stack realign, but no FP?!");
1822 return Offset +
SlotSize + FPDelta;
1825 return Offset + StackSize;
1827 }
else if (
TRI->needsStackRealignment(MF)) {
1830 return Offset +
SlotSize + FPDelta;
1833 return Offset + StackSize;
1838 return Offset + StackSize;
1845 if (TailCallReturnAddrDelta < 0)
1846 Offset -= TailCallReturnAddrDelta;
1849 return Offset + FPDelta;
1853 int FI,
unsigned &FrameReg)
const {
1857 const auto it = WinEHXMMSlotInfo.find(FI);
1859 if (it == WinEHXMMSlotInfo.end())
1867 int FI,
unsigned &FrameReg,
1868 int Adjustment)
const {
1876 int FI,
unsigned &FrameReg,
1877 bool IgnoreSPUpdates)
const {
1927 "we don't handle this case!");
1959 std::vector<CalleeSavedInfo> &CSI)
const {
1963 unsigned CalleeSavedFrameSize = 0;
1964 unsigned XMMCalleeSavedFrameSize = 0;
1970 if (TailCallReturnAddrDelta < 0) {
1981 TailCallReturnAddrDelta -
SlotSize,
true);
1985 if (this->TRI->hasBasePointer(MF)) {
2003 for (
unsigned i = 0; i < CSI.size(); ++i) {
2005 CSI.erase(CSI.begin() + i);
2012 for (
unsigned i = CSI.size(); i != 0; --i) {
2013 unsigned Reg = CSI[i - 1].getReg();
2022 CSI[i - 1].setFrameIdx(SlotIndex);
2029 for (
unsigned i = CSI.size(); i != 0; --i) {
2030 unsigned Reg = CSI[i - 1].getReg();
2036 if (X86::VK16RegClass.
contains(Reg))
2043 assert(SpillSlotOffset < 0 &&
"SpillSlotOffset should always < 0 on X86");
2044 SpillSlotOffset = -
alignTo(-SpillSlotOffset, Align);
2047 SpillSlotOffset -=
Size;
2049 CSI[i - 1].setFrameIdx(SlotIndex);
2053 if (X86::VR128RegClass.
contains(Reg)) {
2054 WinEHXMMSlotInfo[SlotIndex] = XMMCalleeSavedFrameSize;
2055 XMMCalleeSavedFrameSize +=
Size;
2064 const std::vector<CalleeSavedInfo> &CSI,
2075 unsigned Opc =
STI.
is64Bit() ? X86::PUSH64r : X86::PUSH32r;
2076 for (
unsigned i = CSI.size(); i != 0; --i) {
2077 unsigned Reg = CSI[i - 1].getReg();
2088 bool CanKill = !isLiveIn;
2110 for (
unsigned i = CSI.size(); i != 0; --i) {
2111 unsigned Reg = CSI[i-1].getReg();
2117 if (X86::VK16RegClass.
contains(Reg))
2140 "SEH should not use CATCHRET");
2147 BuildMI(MBB, MBBI, DL,
TII.get(X86::LEA64r), X86::RAX)
2156 .addMBB(CatchRetTarget);
2166 std::vector<CalleeSavedInfo> &CSI,
2190 for (
unsigned i = 0,
e = CSI.size(); i !=
e; ++i) {
2191 unsigned Reg = CSI[i].getReg();
2192 if (X86::GR64RegClass.
contains(Reg) ||
2198 if (X86::VK16RegClass.
contains(Reg))
2206 unsigned Opc =
STI.
is64Bit() ? X86::POP64r : X86::POP32r;
2207 for (
unsigned i = 0,
e = CSI.size(); i !=
e; ++i) {
2208 unsigned Reg = CSI[i].getReg();
2209 if (!X86::GR64RegClass.
contains(Reg) &&
2229 SavedRegs.
set(BasePtr);
2238 if (
I->hasNestAttr() && !
I->use_empty())
2255 return Primary ? X86::R14 : X86::R13;
2262 return Primary ? X86::R11 : X86::R12;
2264 return Primary ? X86::R11D : X86::R12D;
2274 "nested function.");
2290 unsigned TlsReg, TlsOffset;
2295 assert(&(*MF.
begin()) == &PrologueMBB &&
"Shrink-wrapping not supported yet");
2299 "Scratch register is live-in");
2328 bool IsNested =
false;
2337 for (
const auto &LI : PrologueMBB.
liveins()) {
2356 TlsOffset =
IsLP64 ? 0x70 : 0x40;
2359 TlsOffset = 0x60 + 90*8;
2373 if (CompareStackPointer)
2376 BuildMI(checkMBB, DL,
TII.get(
IsLP64 ? X86::LEA64r : X86::LEA64_32r), ScratchReg).addReg(X86::RSP)
2379 BuildMI(checkMBB, DL,
TII.get(
IsLP64 ? X86::CMP64rm : X86::CMP32rm)).addReg(ScratchReg)
2387 TlsOffset = 0x48 + 90*4;
2400 if (CompareStackPointer)
2408 BuildMI(checkMBB, DL,
TII.get(X86::CMP32rm)).addReg(ScratchReg)
2413 unsigned ScratchReg2;
2415 if (CompareStackPointer) {
2418 SaveScratch2 =
false;
2430 "Scratch register is live-in and not saved");
2436 BuildMI(checkMBB, DL,
TII.get(X86::MOV32ri), ScratchReg2)
2445 BuildMI(checkMBB, DL,
TII.get(X86::POP32r), ScratchReg2);
2460 const unsigned Reg10 =
IsLP64 ? X86::R10 : X86::R10D;
2461 const unsigned Reg11 =
IsLP64 ? X86::R11 : X86::R11D;
2462 const unsigned MOVrr =
IsLP64 ? X86::MOV64rr : X86::MOV32rr;
2463 const unsigned MOVri =
IsLP64 ? X86::MOV64ri : X86::MOV32ri;
2466 BuildMI(allocMBB, DL,
TII.get(MOVrr), RegAX).addReg(Reg10);
2498 "code model and retpoline not yet implemented.");
2508 BuildMI(allocMBB, DL,
TII.get(X86::CALL64pcrel32))
2509 .addExternalSymbol(
"__morestack");
2511 BuildMI(allocMBB, DL,
TII.get(X86::CALLpcrel32))
2512 .addExternalSymbol(
"__morestack");
2516 BuildMI(allocMBB, DL,
TII.get(X86::MORESTACK_RET_RESTORE_R10));
2518 BuildMI(allocMBB, DL,
TII.get(X86::MORESTACK_RET));
2525 #ifdef EXPENSIVE_CHECKS 2541 if (!NodeName || !NodeVal)
continue;
2542 ConstantInt *ValConst = dyn_cast_or_null<ConstantInt>(NodeVal->getValue());
2543 if (ValConst && NodeName->
getString() == LiteralName) {
2549 +
" required but not provided");
2560 return MI.isMetaInstruction();
2586 assert(&(*MF.
begin()) == &PrologueMBB &&
"Shrink-wrapping not supported yet");
2591 if (!HiPELiteralsMD)
2593 "Can't generate HiPE prologue without runtime parameters");
2594 const unsigned HipeLeafWords
2596 Is64Bit ?
"AMD64_LEAF_WORDS" :
"X86_LEAF_WORDS");
2597 const unsigned CCRegisteredArgs =
Is64Bit ? 6 : 5;
2598 const unsigned Guaranteed = HipeLeafWords *
SlotSize;
2604 "HiPE prologue is only supported on Linux operating systems.");
2614 unsigned MoreStackForCalls = 0;
2616 for (
auto &MBB : MF) {
2617 for (
auto &
MI : MBB) {
2642 unsigned CalleeStkArity =
2644 if (HipeLeafWords - 1 > CalleeStkArity)
2645 MoreStackForCalls =
std::max(MoreStackForCalls,
2646 (HipeLeafWords - 1 - CalleeStkArity) * SlotSize);
2649 MaxStack += MoreStackForCalls;
2654 if (MaxStack > Guaranteed) {
2658 for (
const auto &LI : PrologueMBB.
liveins()) {
2666 unsigned ScratchReg, SPReg, PReg, SPLimitOffset;
2667 unsigned LEAop, CMPop, CALLop;
2672 LEAop = X86::LEA64r;
2673 CMPop = X86::CMP64rm;
2674 CALLop = X86::CALL64pcrel32;
2678 LEAop = X86::LEA32r;
2679 CMPop = X86::CMP32rm;
2680 CALLop = X86::CALLpcrel32;
2685 "HiPE prologue scratch register is live-in");
2689 SPReg,
false, -MaxStack);
2692 .addReg(ScratchReg), PReg,
false, SPLimitOffset);
2697 addExternalSymbol(
"inc_stack_0");
2699 SPReg,
false, -MaxStack);
2701 .addReg(ScratchReg), PReg,
false, SPLimitOffset);
2709 #ifdef EXPENSIVE_CHECKS 2727 if (NumPops != 1 && NumPops != 2)
2732 if (MBBI == MBB.
begin())
2735 if (!Prev->isCall() || !Prev->getOperand(1).isRegMask())
2739 unsigned FoundRegs = 0;
2742 auto RegMask = Prev->getOperand(1);
2745 Is64Bit ? X86::GR64_NOREX_NOSPRegClass : X86::GR32_NOREX_NOSPRegClass;
2747 for (
auto Candidate : RegClass) {
2752 if (!RegMask.clobbersPhysReg(Candidate))
2756 if (
MRI.isReserved(Candidate))
2761 if (MO.isReg() && MO.isDef() &&
2762 TRI->isSuperOrSubRegisterEq(MO.getReg(), Candidate)) {
2771 Regs[FoundRegs++] = Candidate;
2772 if (FoundRegs == (
unsigned)NumPops)
2780 while (FoundRegs < (
unsigned)NumPops)
2781 Regs[FoundRegs++] = Regs[0];
2783 for (
int i = 0; i < NumPops; ++i)
2785 TII.get(
STI.
is64Bit() ? X86::POP64r : X86::POP32r), Regs[i]);
2794 unsigned Opcode = I->getOpcode();
2795 bool isDestroy = Opcode ==
TII.getCallFrameDestroyOpcode();
2797 uint64_t Amount =
TII.getFrameSize(*I);
2802 if (!reserveCallFrame) {
2811 Amount =
alignTo(Amount, StackAlign);
2824 bool HasDwarfEHHandlers = !WindowsCFI && !MF.
getLandingPads().empty();
2826 if (HasDwarfEHHandlers && !isDestroy &&
2836 Amount -= InternalAmt;
2841 if (isDestroy && InternalAmt && DwarfCFI && !
hasFP(MF))
2848 if (StackAdjustment) {
2855 if (StackAdjustment) {
2857 adjustStackWithPops(MBB, InsertPos, DL, StackAdjustment)))
2858 BuildStackAdjustment(MBB, InsertPos, DL, StackAdjustment,
2863 if (DwarfCFI && !
hasFP(MF)) {
2874 if (CfaAdjustment) {
2893 while (CI != B && !std::prev(CI)->isCall())
2895 BuildStackAdjustment(MBB, CI, DL, -InternalAmt,
false);
2904 return !
TRI->needsStackRealignment(MF) || !MBB.
isLiveIn(X86::EFLAGS);
2942 const DebugLoc &DL,
bool RestoreSP)
const {
2946 "restoring EBP/ESI on non-32-bit target");
2958 int EHRegSize = MFI.getObjectSize(FI);
2963 X86::EBP,
true, -EHRegSize)
2969 int EndOffset = -EHRegOffset - EHRegSize;
2972 if (UsedReg == FramePtr) {
2975 BuildMI(MBB, MBBI, DL,
TII.get(ADDri), FramePtr)
2982 "end of registration object above normal EBP position!");
2983 }
else if (UsedReg == BasePtr) {
2986 FramePtr,
false, EndOffset)
2992 assert(UsedReg == BasePtr);
2994 UsedReg,
true, Offset)
3013 struct X86FrameSortingObject {
3014 bool IsValid =
false;
3015 unsigned ObjectIndex = 0;
3016 unsigned ObjectSize = 0;
3017 unsigned ObjectAlignment = 1;
3018 unsigned ObjectNumUses = 0;
3034 struct X86FrameSortingComparator {
3035 inline bool operator()(
const X86FrameSortingObject &A,
3036 const X86FrameSortingObject &
B) {
3037 uint64_t DensityAScaled, DensityBScaled;
3057 DensityAScaled =
static_cast<uint64_t
>(A.ObjectNumUses) *
3058 static_cast<uint64_t>(B.ObjectSize);
3059 DensityBScaled =
static_cast<uint64_t
>(B.ObjectNumUses) *
3060 static_cast<uint64_t>(A.ObjectSize);
3070 if (DensityAScaled == DensityBScaled)
3071 return A.ObjectAlignment < B.ObjectAlignment;
3073 return DensityAScaled < DensityBScaled;
3087 if (ObjectsToAllocate.
empty())
3099 for (
auto &Obj : ObjectsToAllocate) {
3100 SortingObjects[Obj].IsValid =
true;
3101 SortingObjects[Obj].ObjectIndex = Obj;
3105 if (ObjectSize == 0)
3107 SortingObjects[Obj].ObjectSize = 4;
3109 SortingObjects[Obj].ObjectSize = ObjectSize;
3113 for (
auto &MBB : MF) {
3114 for (
auto &
MI : MBB) {
3115 if (
MI.isDebugInstr())
3121 int Index = MO.getIndex();
3125 SortingObjects[
Index].IsValid)
3126 SortingObjects[Index].ObjectNumUses++;
3141 for (
auto &Obj : SortingObjects) {
3145 ObjectsToAllocate[i++] = Obj.ObjectIndex;
3149 if (!
TRI->needsStackRealignment(MF) &&
hasFP(MF))
3150 std::reverse(ObjectsToAllocate.begin(), ObjectsToAllocate.end());
3162 Offset += getWinEHFuncletFrameSize(MF);
3186 int64_t MinFixedObjOffset = -
SlotSize;
3193 if (FrameIndex != INT_MAX) {
3204 MinFixedObjOffset -=
std::abs(MinFixedObjOffset) % 8;
3205 int64_t UnwindHelpOffset = MinFixedObjOffset -
SlotSize;
3213 auto MBBI = MBB.
begin();
void push_front(MachineBasicBlock *MBB)
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
constexpr bool isUInt< 32 >(uint64_t x)
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (macOS, iOS, tvOS or watchOS).
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
static bool flagsNeedToBePreservedBeforeTheTerminators(const MachineBasicBlock &MBB)
Check if the flags need to be preserved before the terminators.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool usesWindowsCFI() const
bool hasBasePointer(const MachineFunction &MF) const
bool getRestoreBasePointer() const
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
SmallVector< WinEHHandlerType, 1 > HandlerArray
DILocation * get() const
Get the underlying DILocation.
This class represents an incoming formal argument to a Function.
StackOffset is a wrapper around scalable and non-scalable offsets and is used in several functions su...
bool isReserved(Register PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
MachineBasicBlock * getMBB() const
MDNode * getOperand(unsigned i) const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
void setHasWinCFI(bool v)
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
const X86InstrInfo * getInstrInfo() const override
bool hasStackObjects() const
Return true if there are any stack objects in this function.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool isCleanupFuncletEntry() const
Returns true if this is the entry block of a cleanup funclet.
const TargetRegisterClass * getGPRsForTailCall(const MachineFunction &MF) const
getGPRsForTailCall - Returns a register class with registers that can be used in forming tail calls...
static unsigned getLEArOpcode(bool IsLP64)
int getRestoreBasePointerOffset() const
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
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.
unsigned getCalleeSavedFrameSize() const
void ensureMaxAlignment(Align Alignment)
Make sure the function is at least Align bytes aligned.
constexpr bool isInt< 8 >(int64_t x)
void setCalleeSavedFrameSize(unsigned bytes)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
unsigned const TargetRegisterInfo * TRI
void setIsDead(bool Val=true)
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
MachineModuleInfo & getMMI() const
const MDOperand & getOperand(unsigned I) const
void setSEHFramePtrSaveIndex(int Index)
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
static BranchProbability getOne()
bool isTargetNaCl64() const
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
MCRegister getX86SubSuperRegister(MCRegister, unsigned, bool High=false)
Returns the sub or super register of a specific X86 register.
unsigned getSlotSize() const
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int Adjustment)
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
Register getFramePtr() const
Returns physical register used as frame pointer.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
bool isTargetWindowsMSVC() const
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
return AArch64::GPR64RegClass contains(Reg)
iterator_range< succ_iterator > successors()
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
bool Uses64BitFramePtr
True if the 64-bit frame or stack pointer should be used.
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class...
uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the largest uint64_t less than or equal to Value and is Skew mod Align.
CLEANUPRET - Represents a return from a cleanup block funclet.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction. ...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const HexagonInstrInfo * TII
bool getHasSEHFramePtrSave() const
bool isTarget64BitLP64() const
Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
iterator_range< iterator > terminators()
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
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...
unsigned getNumOperands() const
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static const uint64_t kSplitStackAvailable
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
int getWin64EHFrameIndexRef(const MachineFunction &MF, int FI, unsigned &SPReg) const
bool regsOverlap(Register regA, Register regB) const
Returns true if the two registers are equal or alias each other.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override
int getTCReturnAddrDelta() const
uint16_t StackAdjustment(const RuntimeFunction &RF)
StackAdjustment - calculated stack adjustment in words.
int getDwarfRegNum(MCRegister RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
bool canUseLEAForSPInEpilogue(const MachineFunction &MF) const
Check that LEA can be used on SP in an epilogue sequence for MF.
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
static bool blockEndIsUnreachable(const MachineBasicBlock &MBB, MachineBasicBlock::const_iterator MBBI)
bool needsFrameIndexResolution(const MachineFunction &MF) const override
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 inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe inline-stub with the actual probe code inline.
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
static unsigned getANDriOpcode(bool IsLP64, int64_t Imm)
const MCContext & getContext() const
void setHasSEHFramePtrSave(bool V)
int getObjectIndexBegin() const
Return the minimum frame object index.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
static unsigned getHiPELiteral(NamedMDNode *HiPELiteralsMD, const StringRef LiteralName)
Lookup an ERTS parameter in the !hipe.literals named metadata node.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasPersonalityFn() const
Check whether this function has a personality function.
bool hasCopyImplyingStackAdjustment() const
Returns true if the function contains operations which will lower down to instructions which manipula...
StringRef getStackProbeSymbolName(MachineFunction &MF) const override
Returns the name of the symbol used to emit stack probes or the empty string if not applicable...
static unsigned calculateSetFPREG(uint64_t SPAdjust)
int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
void setHasNosplitStack(bool b)
bool Is64Bit
Is64Bit implies that x86_64 instructions are available.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
unsigned getUndefRegState(bool B)
void BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const MCCFIInstruction &CFIInst) const
Wraps up getting a CFI index and building a MachineInstr for it.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
Analysis containing CSE Info
unsigned getKillRegState(bool B)
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
TargetInstrInfo - Interface to description of machine instruction set.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
unsigned getInitialCFARegister(const MachineFunction &MF) const override
Return initial CFA register value i.e.
static unsigned getSUBrrOpcode(bool IsLP64)
StringRef getString() const
X86_INTR - x86 hardware interrupt context.
bool isOSWindows() const
Tests whether the OS is Windows.
unsigned getDefRegState(bool B)
The memory access is volatile.
const X86TargetLowering * getTargetLowering() const override
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getArgumentStackSize() const
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
LLVM Basic Block Representation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
unsigned getStackProbeSize(MachineFunction &MF) const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool isBundled() const
Return true if this instruction part of a bundle.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool hasEHFunclets() const
void setStackSize(uint64_t Size)
Set the size of the stack.
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
const GlobalValue * getGlobal() const
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size)
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
void setFlag(MIFlag Flag)
Set a MI flag.
MCRegAliasIterator enumerates all registers aliasing Reg.
static const MachineInstrBuilder & addRegOffset(const MachineInstrBuilder &MIB, unsigned Reg, bool isKill, int Offset)
addRegOffset - This function is used to add a memory reference of the form [Reg + Offset]...
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
bool isTargetFreeBSD() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const Triple & getTargetTriple() const
self_iterator getIterator()
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
succ_iterator succ_begin()
bool isTargetDarwin() const
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
bool useRetpolineIndirectCalls() const
bool isTargetWin64() const
This class contains a discriminated union of information about pointers in memory operands...
const char * createExternalSymbolName(StringRef Name)
Allocate a string and populate it with the given external symbol name.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static bool isFuncletReturnInstr(MachineInstr &MI)
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...
void emitStackProbe(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool InProlog) const
Emit target stack probe code.
The memory access writes data.
Register getFrameRegister(const MachineFunction &MF) const override
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
Iterator for intrusive lists based on ilist_node.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
This is the shared class of boolean and integer constants.
constexpr bool isInt< 32 >(int64_t x)
DenseMap< int, unsigned > & getWinEHXMMSlotInfo()
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required, we reserve argument space for call sites in the function immediately on entry to the current function.
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
static unsigned getADDriOpcode(bool IsLP64, int64_t Imm)
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...
MachineOperand class - Representation of each machine instruction operand.
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
Information about stack frame layout on the target.
void setUsesMorestackAddr(bool b)
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Promote Memory to Register
X86FrameLowering(const X86Subtarget &STI, MaybeAlign StackAlignOverride)
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
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 isTargetWin32() const
int getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, unsigned &FrameReg, bool IgnoreSPUpdates) const override
Same as getFrameIndexReference, except that the stack pointer (as opposed to the frame pointer) will ...
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling...
int64_t getFrameAdjustment(const MachineInstr &I) const
Returns the stack pointer adjustment that happens inside the frame setup..destroy sequence (e...
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
bool callsUnwindInit() const
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
canSimplifyCallFramePseudos - If there is a reserved call frame, the call frame pseudos can be simpli...
IterT skipDebugInstructionsBackward(IterT It, IterT Begin)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
bool isTarget64BitILP32() const
Is this x86_64 with the ILP32 programming model (x32 ABI)?
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
bool callsEHReturn() const
static bool isTailCallOpcode(unsigned Opc)
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
bool getUsesRedZone() const
CodeModel::Model getCodeModel() const
Returns the code model.
static unsigned getADDrrOpcode(bool IsLP64)
X86_FastCall - 'fast' analog of X86_StdCall.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
union llvm::WinEHHandlerType::@202 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
void setHasAddressTaken()
Set this block to reflect that it potentially is the target of an indirect branch.
IterT skipDebugInstructionsForward(IterT It, IterT End)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
CATCHRET - Represents a return from a catch block funclet.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
int getFrameIndexReferenceSP(const MachineFunction &MF, int FI, unsigned &SPReg, int Adjustment) const
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
bool isLiveIn(unsigned Reg) const
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Adjust the prologue to have the function use segmented stacks.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
int getSEHFramePtrSaveIndex() const
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool isTargetDragonFly() const
LLVM_NODISCARD bool empty() const
bool verify(Pass *p=nullptr, const char *Banner=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
static unsigned getSUBriOpcode(bool IsLP64, int64_t Imm)
StringRef getName() const
Return a constant reference to the value's name.
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Pair of physical register and lane mask.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
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...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void setCVBytesOfCalleeSavedRegisters(unsigned S)
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Tail - This calling convention attemps to make calls as fast as possible while guaranteeing that tail...
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const X86RegisterInfo * TRI
const Module * getModule() const
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
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)
iterator_range< livein_iterator > liveins() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isEAXLiveIn(MachineBasicBlock &MBB)
void insert(iterator MBBI, MachineBasicBlock *MBB)
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
void stable_sort(R &&Range)
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...
const MCRegisterInfo * getRegisterInfo() const
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
bool isTargetLinux() const
static unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const X86RegisterInfo *TRI, bool Is64Bit)
findDeadCallerSavedReg - Return a caller-saved register that isn't live when it reaches the "return" ...
bool isCallingConvWin64(CallingConv::ID CC) const
int getInitialCFAOffset(const MachineFunction &MF) const override
Return initial CFA offset value i.e.
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
void setUsesRedZone(bool V)
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
StringRef - Represent a constant reference to a string, i.e.
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL) const
static BranchProbability getZero()
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
DWARF-like instruction based exceptions.
Register getReg() const
getReg - Returns the register number.
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack.
int mergeSPUpdates(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, bool doMergeWithPrevious) const
Check the instruction before/after the passed instruction.
unsigned getNumOperands() const
Return number of MDNode operands.
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
const MachineOperand & getOperand(unsigned i) const
static bool HasNestArgument(const MachineFunction *MF)
SlotIndex - An opaque wrapper around machine indexes.
bool hasTailCall() const
Returns true if the function contains a tail call.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
Function Alias Analysis false
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
static bool is64Bit(const char *name)
Register getStackRegister() const
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
Wrapper class representing virtual and physical registers.
bool getHasPushSequences() const
This class contains meta information specific to a module.
Register getBaseRegister() const
bool hasCalls() const
Return true if the current function has any function calls.
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
bool isTargetWindowsCoreCLR() const