39 unsigned StackAlignOverride)
42 STI(STI),
TII(*STI.getInstrInfo()), TRI(STI.getRegisterInfo()) {
64 (
hasFP(MF) && !
TRI->needsStackRealignment(MF)) ||
87 TRI->needsStackRealignment(MF) ||
100 return X86::SUB64ri32;
103 return X86::SUB32ri8;
111 return X86::ADD64ri8;
112 return X86::ADD64ri32;
115 return X86::ADD32ri8;
121 return isLP64 ? X86::SUB64rr : X86::SUB32rr;
125 return isLP64 ? X86::ADD64rr : X86::ADD32rr;
131 return X86::AND64ri8;
132 return X86::AND64ri32;
135 return X86::AND32ri8;
140 return IsLP64 ? X86::LEA64r : X86::LEA32r;
157 if (MBBI == MBB.
end())
160 switch (MBBI->getOpcode()) {
162 case TargetOpcode::PATCHABLE_RET:
168 case X86::TCRETURNdi:
169 case X86::TCRETURNri:
170 case X86::TCRETURNmi:
171 case X86::TCRETURNdi64:
172 case X86::TCRETURNri64:
173 case X86::TCRETURNmi64:
175 case X86::EH_RETURN64: {
177 for (
unsigned i = 0, e = MBBI->getNumOperands(); i != e; ++i) {
188 for (
auto CS : AvailableRegs)
189 if (!Uses.
count(CS) && CS != X86::RIP)
199 unsigned Reg = RegMask.PhysReg;
201 if (Reg == X86::RAX || Reg == X86::EAX || Reg == X86::AX ||
202 Reg == X86::AH || Reg == X86::AL)
216 bool BreakNext =
false;
220 unsigned Reg = MO.getReg();
221 if (Reg != X86::EFLAGS)
242 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;
261 if (Offset > Chunk) {
272 unsigned MovRIOpc =
Is64Bit ? X86::MOV64ri : X86::MOV32ri;
273 unsigned AddSubRROpc =
284 }
else if (Offset > 8 * Chunk) {
302 BuildMI(MBB, MBBI, DL,
TII.get(MovRIOpc), Rax)
311 BuildMI(MBB, MBBI, DL,
TII.get(X86::XCHG64rm), Rax).addReg(Rax),
321 uint64_t ThisVal =
std::min(Offset, Chunk);
330 ? (
Is64Bit ? X86::PUSH64r : X86::PUSH32r)
331 : (
Is64Bit ? X86::POP64r : X86::POP32r);
340 BuildStackAdjustment(MBB, MBBI, DL, isSub ? -ThisVal : ThisVal, InEpilogue)
350 assert(Offset != 0 &&
"zero offset stack adjustment requested");
373 "We shouldn't have allowed this insertion point");
383 bool IsSub = Offset < 0;
384 uint64_t AbsOffset = IsSub ? -Offset :
Offset;
397 bool doMergeWithPrevious)
const {
398 if ((doMergeWithPrevious && MBBI == MBB.
begin()) ||
399 (!doMergeWithPrevious && MBBI == MBB.
end()))
409 unsigned Opc = PI->getOpcode();
412 if (!doMergeWithPrevious && NI != MBB.
end() &&
413 NI->getOpcode() == TargetOpcode::CFI_INSTRUCTION) {
418 if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 ||
419 Opc == X86::ADD32ri || Opc == X86::ADD32ri8) &&
420 PI->getOperand(0).getReg() ==
StackPtr){
422 Offset += PI->getOperand(2).getImm();
424 if (!doMergeWithPrevious) MBBI = NI;
425 }
else if ((Opc == X86::LEA32r || Opc == X86::LEA64_32r) &&
426 PI->getOperand(0).getReg() ==
StackPtr &&
427 PI->getOperand(1).getReg() ==
StackPtr &&
428 PI->getOperand(2).getImm() == 1 &&
429 PI->getOperand(3).getReg() == X86::NoRegister &&
430 PI->getOperand(5).getReg() == X86::NoRegister) {
432 Offset += PI->getOperand(4).getImm();
434 if (!doMergeWithPrevious) MBBI = NI;
435 }
else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 ||
436 Opc == X86::SUB32ri || Opc == X86::SUB32ri8) &&
437 PI->getOperand(0).getReg() ==
StackPtr) {
439 Offset -= PI->getOperand(2).getImm();
441 if (!doMergeWithPrevious) MBBI = NI;
453 BuildMI(MBB, MBBI, DL,
TII.get(TargetOpcode::CFI_INSTRUCTION))
454 .addCFIIndex(CFIIndex);
467 if (CSI.empty())
return;
470 for (std::vector<CalleeSavedInfo>::const_iterator
471 I = CSI.begin(),
E = CSI.end();
I !=
E; ++
I) {
473 unsigned Reg =
I->getReg();
484 const DebugLoc &DL,
bool InProlog)
const {
488 emitStackProbeInlineStub(MF, MBB, MBBI, DL,
true);
490 emitStackProbeInline(MF, MBB, MBBI, DL,
false);
493 emitStackProbeCall(MF, MBB, MBBI, DL, InProlog);
499 const StringRef ChkStkStubSymbol =
"__chkstk_stub";
503 if (MI.isCall() && MI.getOperand(0).isSymbol() &&
504 ChkStkStubSymbol == MI.getOperand(0).getSymbolName()) {
510 if (ChkStkStub !=
nullptr) {
512 "Not expecting bundled instructions here");
514 assert(std::prev(MBBI) == ChkStkStub &&
515 "MBBI expected after __chkstk_stub.");
516 DebugLoc DL = PrologMBB.findDebugLoc(MBBI);
517 emitStackProbeInline(MF, PrologMBB, MBBI, DL,
true);
526 bool InProlog)
const {
528 assert(STI.
is64Bit() &&
"different expansion needed for 32 bit");
566 MF.
insert(MBBIter, RoundMBB);
567 MF.
insert(MBBIter, LoopMBB);
568 MF.
insert(MBBIter, ContinueMBB);
576 const int64_t ThreadEnvironmentStackLimit = 0x10;
578 const int64_t PageMask = ~(PageSize - 1);
584 const unsigned SizeReg = InProlog ? (
unsigned)X86::RAX
586 ZeroReg = InProlog ? (
unsigned)X86::RCX
588 CopyReg = InProlog ? (
unsigned)X86::RDX
590 TestReg = InProlog ? (
unsigned)X86::RDX
592 FinalReg = InProlog ? (
unsigned)X86::RDX
594 RoundedReg = InProlog ? (
unsigned)X86::RDX
596 LimitReg = InProlog ? (
unsigned)X86::RCX
598 JoinReg = InProlog ? (
unsigned)X86::RCX
600 ProbeReg = InProlog ? (
unsigned)X86::RCX
604 int64_t RCXShadowSlot = 0;
605 int64_t RDXShadowSlot = 0;
615 const bool HasFP =
hasFP(MF);
616 RCXShadowSlot = 8 + CalleeSaveSize + (HasFP ? 8 : 0);
617 RDXShadowSlot = RCXShadowSlot + 8;
627 BuildMI(&MBB, DL, TII.
get(X86::MOV64rr), SizeReg).addReg(X86::RAX);
632 BuildMI(&MBB, DL, TII.
get(X86::XOR64rr), ZeroReg)
635 BuildMI(&MBB, DL, TII.
get(X86::MOV64rr), CopyReg).addReg(X86::RSP);
636 BuildMI(&MBB, DL, TII.
get(X86::SUB64rr), TestReg)
639 BuildMI(&MBB, DL, TII.
get(X86::CMOVB64rr), FinalReg)
650 BuildMI(&MBB, DL, TII.
get(X86::MOV64rm), LimitReg)
654 .
addImm(ThreadEnvironmentStackLimit)
658 BuildMI(&MBB, DL, TII.
get(X86::JAE_1)).addMBB(ContinueMBB);
661 BuildMI(RoundMBB, DL, TII.
get(X86::AND64ri32), RoundedReg)
664 BuildMI(RoundMBB, DL, TII.
get(X86::JMP_1)).addMBB(LoopMBB);
670 BuildMI(LoopMBB, DL, TII.
get(X86::PHI), JoinReg)
691 BuildMI(LoopMBB, DL, TII.
get(X86::JNE_1)).addMBB(LoopMBB);
699 X86::RSP,
false, RCXShadowSlot);
702 X86::RSP,
false, RDXShadowSlot);
707 BuildMI(*ContinueMBB, ContinueMBBI, DL, TII.
get(X86::SUB64rr), X86::RSP)
720 for (++BeforeMBBI; BeforeMBBI != MBB.
end(); ++BeforeMBBI) {
730 CMBBI != ContinueMBBI; ++CMBBI) {
742 bool InProlog)
const {
747 CallOp = IsLargeCodeModel ? X86::CALL64r : X86::CALL64pcrel32;
749 CallOp = X86::CALLpcrel32;
761 BuildMI(MBB, MBBI, DL, TII.
get(X86::MOV64ri), X86::R11)
763 CI =
BuildMI(MBB, MBBI, DL, TII.
get(CallOp)).addReg(X86::R11);
769 unsigned AX =
Is64Bit ? X86::RAX : X86::EAX;
770 unsigned SP =
Is64Bit ? X86::RSP : X86::ESP;
791 for (++ExpansionMBBI; ExpansionMBBI != MBBI; ++ExpansionMBBI)
796 void X86FrameLowering::emitStackProbeInlineStub(
800 assert(InProlog &&
"ChkStkStub called outside prolog!");
802 BuildMI(MBB, MBBI, DL, TII.
get(X86::CALLpcrel32))
803 .addExternalSymbol(
"__chkstk_stub");
809 const uint64_t Win64MaxSEHOffset = 128;
810 uint64_t SEHFrameOffset =
std::min(SPAdjust, Win64MaxSEHOffset);
812 return SEHFrameOffset & -16;
819 uint64_t X86FrameLowering::calculateMaxStackAlign(
const MachineFunction &MF)
const {
825 MaxAlign = (StackAlign > MaxAlign) ? StackAlign : MaxAlign;
835 uint64_t MaxAlign)
const {
836 uint64_t Val = -MaxAlign;
934 "MF used frame lowering for wrong subtarget");
940 uint64_t MaxAlign = calculateMaxStackAlign(MF);
946 bool FnHasClrFunclet =
948 bool IsClrFunclet = IsFunclet && FnHasClrFunclet;
949 bool HasFP =
hasFP(MF);
956 const unsigned MachineFramePtr =
960 bool HasWinCFI =
false;
968 if (TailCallReturnAddrDelta && IsWin64Prologue)
971 if (TailCallReturnAddrDelta < 0)
979 unsigned StackProbeSize = 4096;
1001 !
TRI->needsStackRealignment(MF) &&
1011 StackSize =
std::max(MinSize, StackSize > 128 ? StackSize - 128 : 0);
1018 if (TailCallReturnAddrDelta < 0) {
1019 BuildStackAdjustment(MBB, MBBI, DL, TailCallReturnAddrDelta,
1038 uint64_t NumBytes = 0;
1042 unsigned Establisher = X86::NoRegister;
1048 if (IsWin64Prologue && IsFunclet && !IsClrFunclet) {
1063 uint64_t FrameSize = StackSize -
SlotSize;
1066 FrameSize += SlotSize;
1071 if (
TRI->needsStackRealignment(MF) && !IsWin64Prologue)
1072 NumBytes =
alignTo(NumBytes, MaxAlign);
1081 "should calculate same local variable offset for funclets");
1088 if (NeedsDwarfCFI) {
1096 unsigned DwarfFramePtr =
TRI->getDwarfRegNum(MachineFramePtr,
true);
1098 nullptr, DwarfFramePtr, 2 * stackGrowth));
1103 BuildMI(MBB, MBBI, DL, TII.
get(X86::SEH_PushReg))
1108 if (!IsWin64Prologue && !IsFunclet) {
1116 if (NeedsDwarfCFI) {
1119 unsigned DwarfFramePtr =
TRI->getDwarfRegNum(MachineFramePtr,
true);
1121 nullptr, DwarfFramePtr));
1125 assert(!IsFunclet &&
"funclets without FPs not yet implemented");
1131 unsigned ParentFrameNumBytes = NumBytes;
1133 NumBytes = getWinEHFuncletFrameSize(MF);
1136 bool PushedRegs =
false;
1137 int StackOffset = 2 * stackGrowth;
1139 while (MBBI != MBB.
end() &&
1141 (MBBI->getOpcode() == X86::PUSH32r ||
1142 MBBI->getOpcode() == X86::PUSH64r)) {
1144 unsigned Reg = MBBI->getOperand(0).getReg();
1147 if (!HasFP && NeedsDwarfCFI) {
1153 StackOffset += stackGrowth;
1166 if (!IsWin64Prologue && !IsFunclet &&
TRI->needsStackRealignment(MF)) {
1167 assert(HasFP &&
"There should be a frame pointer if stack is realigned.");
1168 BuildStackAlignAND(MBB, MBBI, DL,
StackPtr, MaxAlign);
1186 uint64_t AlignedNumBytes = NumBytes;
1187 if (IsWin64Prologue && !IsFunclet &&
TRI->needsStackRealignment(MF))
1188 AlignedNumBytes =
alignTo(AlignedNumBytes, MaxAlign);
1189 if (AlignedNumBytes >= StackProbeSize && UseStackProbe) {
1191 "The Red Zone is not accounted for in stack probes");
1202 BuildMI(MBB, MBBI, DL, TII.
get(X86::PUSH32r))
1211 BuildMI(MBB, MBBI, DL, TII.
get(X86::MOV32ri), X86::EAX)
1215 BuildMI(MBB, MBBI, DL, TII.
get(X86::MOV64ri32), X86::RAX)
1219 BuildMI(MBB, MBBI, DL, TII.
get(X86::MOV64ri), X86::RAX)
1226 BuildMI(MBB, MBBI, DL, TII.
get(X86::MOV32ri), X86::EAX)
1227 .addImm(isEAXAlive ? NumBytes - 4 : NumBytes)
1242 }
else if (NumBytes) {
1246 if (NeedsWinCFI && NumBytes) {
1248 BuildMI(MBB, MBBI, DL, TII.
get(X86::SEH_StackAlloc))
1253 int SEHFrameOffset = 0;
1254 unsigned SPOrEstablisher;
1261 unsigned PSPSlotOffset = getPSPSlotOffsetFromSP(MF);
1265 Establisher,
false, PSPSlotOffset)
1272 false, PSPSlotOffset)
1279 SPOrEstablisher = Establisher;
1284 if (IsWin64Prologue && HasFP) {
1291 SPOrEstablisher,
false, SEHFrameOffset);
1294 .addReg(SPOrEstablisher);
1297 if (NeedsWinCFI && !IsFunclet) {
1299 BuildMI(MBB, MBBI, DL, TII.
get(X86::SEH_SetFrame))
1306 }
else if (IsFunclet && STI.
is32Bit()) {
1329 if (
unsigned Reg = TII.isStoreToStackSlot(FrameInstr, FI)) {
1330 if (X86::FR64RegClass.
contains(Reg)) {
1331 unsigned IgnoredFrameReg;
1333 Offset += SEHFrameOffset;
1336 BuildMI(MBB, MBBI, DL, TII.
get(X86::SEH_SaveXMM))
1345 if (NeedsWinCFI && HasWinCFI)
1346 BuildMI(MBB, MBBI, DL, TII.
get(X86::SEH_EndPrologue))
1349 if (FnHasClrFunclet && !IsFunclet) {
1353 unsigned PSPSlotOffset = getPSPSlotOffsetFromSP(MF);
1367 if (IsWin64Prologue &&
TRI->needsStackRealignment(MF)) {
1368 assert(HasFP &&
"There should be a frame pointer if stack is realigned.");
1369 BuildStackAlignAND(MBB, MBBI, DL, SPOrEstablisher, MaxAlign);
1373 if (IsFunclet && STI.
is32Bit())
1383 BuildMI(MBB, MBBI, DL, TII.
get(Opc), BasePtr)
1384 .addReg(SPOrEstablisher)
1392 .addReg(SPOrEstablisher)
1405 assert(UsedReg == BasePtr);
1412 if (((!HasFP && NumBytes) || PushedRegs) && NeedsDwarfCFI) {
1414 if (!HasFP && NumBytes) {
1418 nullptr, -StackSize + stackGrowth));
1478 X86FrameLowering::getPSPSlotOffsetFromSP(
const MachineFunction &MF)
const {
1484 return static_cast<unsigned>(
Offset);
1488 X86FrameLowering::getWinEHFuncletFrameSize(
const MachineFunction &MF)
const {
1500 UsedSize = getPSPSlotOffsetFromSP(MF) +
SlotSize;
1511 return FrameSizeMinusRBP - CSSize;
1515 return Opc == X86::TCRETURNri || Opc == X86::TCRETURNdi ||
1516 Opc == X86::TCRETURNmi ||
1517 Opc == X86::TCRETURNri64 || Opc == X86::TCRETURNdi64 ||
1518 Opc == X86::TCRETURNmi64;
1527 if (MBBI != MBB.
end())
1528 RetOpcode = MBBI->getOpcode();
1530 if (MBBI != MBB.
end())
1531 DL = MBBI->getDebugLoc();
1535 unsigned MachineFramePtr =
1546 uint64_t MaxAlign = calculateMaxStackAlign(MF);
1548 uint64_t NumBytes = 0;
1554 "SEH should not use CATCHRET");
1556 NumBytes = getWinEHFuncletFrameSize(MF);
1557 assert(
hasFP(MF) &&
"EH funclets without FP not yet implemented");
1558 TargetMBB = MBBI->getOperand(0).getMBB();
1565 NumBytes = getWinEHFuncletFrameSize(MF);
1566 assert(
hasFP(MF) &&
"EH funclets without FP not yet implemented");
1570 }
else if (
hasFP(MF)) {
1572 uint64_t FrameSize = StackSize -
SlotSize;
1573 NumBytes = FrameSize - CSSize;
1577 if (
TRI->needsStackRealignment(MF) && !IsWin64Prologue)
1578 NumBytes =
alignTo(FrameSize, MaxAlign);
1582 TII.
get(
Is64Bit ? X86::POP64r : X86::POP32r), MachineFramePtr)
1585 NumBytes = StackSize - CSSize;
1587 uint64_t SEHStackAllocAmt = NumBytes;
1591 while (MBBI != MBB.
begin()) {
1593 unsigned Opc = PI->getOpcode();
1595 if (Opc != X86::DBG_VALUE && !PI->isTerminator()) {
1608 unsigned ReturnReg = STI.
is64Bit() ? X86::RAX : X86::EAX;
1611 BuildMI(MBB, FirstCSPop, DL, TII.
get(X86::LEA64r), ReturnReg)
1619 BuildMI(MBB, FirstCSPop, DL, TII.
get(X86::MOV32ri), ReturnReg)
1627 if (MBBI != MBB.
end())
1628 DL = MBBI->getDebugLoc();
1641 if (
TRI->needsStackRealignment(MF))
1644 uint64_t LEAAmount =
1645 IsWin64Prologue ? SEHStackAllocAmt - SEHFrameOffset : -CSSize;
1654 if (LEAAmount != 0) {
1657 FramePtr,
false, LEAAmount);
1665 }
else if (NumBytes) {
1678 BuildMI(MBB, MBBI, DL, TII.
get(X86::SEH_Epilogue));
1683 assert(Offset >= 0 &&
"TCDelta should never be positive");
1695 unsigned &FrameReg)
const {
1704 else if (
TRI->needsStackRealignment(MF))
1717 bool HasFP =
hasFP(MF);
1719 int64_t FPDelta = 0;
1721 if (IsWin64Prologue) {
1725 uint64_t FrameSize = StackSize -
SlotSize;
1728 FrameSize += SlotSize;
1729 uint64_t NumBytes = FrameSize - CSSize;
1733 return -SEHFrameOffset;
1739 FPDelta = FrameSize - SEHFrameOffset;
1741 "FPDelta isn't aligned per the Win64 ABI!");
1746 assert(HasFP &&
"VLAs and dynamic stack realign, but no FP?!");
1749 return Offset +
SlotSize + FPDelta;
1752 return Offset + StackSize;
1754 }
else if (
TRI->needsStackRealignment(MF)) {
1757 return Offset +
SlotSize + FPDelta;
1760 return Offset + StackSize;
1765 return Offset + StackSize;
1772 if (TailCallReturnAddrDelta < 0)
1773 Offset -= TailCallReturnAddrDelta;
1776 return Offset + FPDelta;
1780 int FI,
unsigned &FrameReg,
1781 int Adjustment)
const {
1789 int FI,
unsigned &FrameReg,
1790 bool IgnoreSPUpdates)
const {
1841 "we don't handle this case!");
1873 std::vector<CalleeSavedInfo> &CSI)
const {
1877 unsigned CalleeSavedFrameSize = 0;
1889 for (
unsigned i = 0; i < CSI.size(); ++i) {
1891 CSI.erase(CSI.begin() + i);
1898 for (
unsigned i = CSI.size(); i != 0; --i) {
1899 unsigned Reg = CSI[i - 1].getReg();
1908 CSI[i - 1].setFrameIdx(SlotIndex);
1914 for (
unsigned i = CSI.size(); i != 0; --i) {
1915 unsigned Reg = CSI[i - 1].getReg();
1925 SpillSlotOffset -=
Size;
1927 CSI[i - 1].setFrameIdx(SlotIndex);
1936 const std::vector<CalleeSavedInfo> &CSI,
1947 unsigned Opc = STI.
is64Bit() ? X86::PUSH64r : X86::PUSH32r;
1948 for (
unsigned i = CSI.size(); i != 0; --i) {
1949 unsigned Reg = CSI[i - 1].getReg();
1960 bool CanKill = !isLiveIn;
1982 for (
unsigned i = CSI.size(); i != 0; --i) {
1983 unsigned Reg = CSI[i-1].getReg();
1990 TII.storeRegToStackSlot(MBB, MI, Reg,
true, CSI[i - 1].getFrameIdx(), RC,
2002 const std::vector<CalleeSavedInfo> &CSI,
2026 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
2027 unsigned Reg = CSI[i].getReg();
2028 if (X86::GR64RegClass.
contains(Reg) ||
2033 TII.loadRegFromStackSlot(MBB, MI, Reg, CSI[i].getFrameIdx(), RC, TRI);
2037 unsigned Opc = STI.
is64Bit() ? X86::POP64r : X86::POP32r;
2038 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
2039 unsigned Reg = CSI[i].getReg();
2040 if (!X86::GR64RegClass.
contains(Reg) &&
2060 if (TailCallReturnAddrDelta < 0) {
2071 TailCallReturnAddrDelta -
SlotSize,
true);
2092 if (
I->hasNestAttr())
2109 return Primary ? X86::R14 : X86::R13;
2111 return Primary ? X86::EBX : X86::EDI;
2116 return Primary ? X86::R11 : X86::R12;
2118 return Primary ? X86::R11D : X86::R12D;
2127 "nested function.");
2128 return Primary ? X86::EAX : X86::ECX;
2131 return Primary ? X86::EDX : X86::EAX;
2132 return Primary ? X86::ECX : X86::EAX;
2143 unsigned TlsReg, TlsOffset;
2148 assert(&(*MF.
begin()) == &PrologueMBB &&
"Shrink-wrapping not supported yet");
2152 "Scratch register is live-in");
2173 bool IsNested =
false;
2182 for (
const auto &LI : PrologueMBB.
liveins()) {
2201 TlsOffset =
IsLP64 ? 0x70 : 0x40;
2204 TlsOffset = 0x60 + 90*8;
2218 if (CompareStackPointer)
2219 ScratchReg =
IsLP64 ? X86::RSP : X86::ESP;
2221 BuildMI(checkMBB, DL, TII.
get(
IsLP64 ? X86::LEA64r : X86::LEA64_32r), ScratchReg).addReg(X86::RSP)
2224 BuildMI(checkMBB, DL, TII.
get(
IsLP64 ? X86::CMP64rm : X86::CMP32rm)).addReg(ScratchReg)
2232 TlsOffset = 0x48 + 90*4;
2245 if (CompareStackPointer)
2246 ScratchReg = X86::ESP;
2248 BuildMI(checkMBB, DL, TII.
get(X86::LEA32r), ScratchReg).addReg(X86::ESP)
2253 BuildMI(checkMBB, DL, TII.
get(X86::CMP32rm)).addReg(ScratchReg)
2258 unsigned ScratchReg2;
2260 if (CompareStackPointer) {
2263 SaveScratch2 =
false;
2275 "Scratch register is live-in and not saved");
2281 BuildMI(checkMBB, DL, TII.
get(X86::MOV32ri), ScratchReg2)
2290 BuildMI(checkMBB, DL, TII.
get(X86::POP32r), ScratchReg2);
2296 BuildMI(checkMBB, DL, TII.
get(X86::JA_1)).addMBB(&PrologueMBB);
2304 const unsigned RegAX =
IsLP64 ? X86::RAX : X86::EAX;
2305 const unsigned Reg10 =
IsLP64 ? X86::R10 : X86::R10D;
2306 const unsigned Reg11 =
IsLP64 ? X86::R11 : X86::R11D;
2307 const unsigned MOVrr =
IsLP64 ? X86::MOV64rr : X86::MOV32rr;
2308 const unsigned MOVri =
IsLP64 ? X86::MOV64ri : X86::MOV32ri;
2311 BuildMI(allocMBB, DL, TII.
get(MOVrr), RegAX).addReg(Reg10);
2349 BuildMI(allocMBB, DL, TII.
get(X86::CALL64pcrel32))
2350 .addExternalSymbol(
"__morestack");
2352 BuildMI(allocMBB, DL, TII.
get(X86::CALLpcrel32))
2353 .addExternalSymbol(
"__morestack");
2357 BuildMI(allocMBB, DL, TII.
get(X86::MORESTACK_RET_RESTORE_R10));
2359 BuildMI(allocMBB, DL, TII.
get(X86::MORESTACK_RET));
2366 #ifdef EXPENSIVE_CHECKS
2377 for (
int i = 0, e = HiPELiteralsMD->
getNumOperands(); i != e; ++i) {
2382 if (!NodeName || !NodeVal)
continue;
2383 ConstantInt *ValConst = dyn_cast_or_null<ConstantInt>(NodeVal->getValue());
2384 if (ValConst && NodeName->
getString() == LiteralName) {
2390 +
" required but not provided");
2415 assert(&(*MF.
begin()) == &PrologueMBB &&
"Shrink-wrapping not supported yet");
2420 if (!HiPELiteralsMD)
2422 "Can't generate HiPE prologue without runtime parameters");
2423 const unsigned HipeLeafWords
2425 Is64Bit ?
"AMD64_LEAF_WORDS" :
"X86_LEAF_WORDS");
2426 const unsigned CCRegisteredArgs =
Is64Bit ? 6 : 5;
2427 const unsigned Guaranteed = HipeLeafWords *
SlotSize;
2433 "HiPE prologue is only supported on Linux operating systems.");
2443 unsigned MoreStackForCalls = 0;
2445 for (
auto &MBB : MF) {
2446 for (
auto &MI : MBB) {
2471 unsigned CalleeStkArity =
2473 if (HipeLeafWords - 1 > CalleeStkArity)
2474 MoreStackForCalls =
std::max(MoreStackForCalls,
2475 (HipeLeafWords - 1 - CalleeStkArity) * SlotSize);
2478 MaxStack += MoreStackForCalls;
2483 if (MaxStack > Guaranteed) {
2487 for (
const auto &LI : PrologueMBB.
liveins()) {
2495 unsigned ScratchReg, SPReg, PReg, SPLimitOffset;
2496 unsigned LEAop, CMPop, CALLop;
2501 LEAop = X86::LEA64r;
2502 CMPop = X86::CMP64rm;
2503 CALLop = X86::CALL64pcrel32;
2507 LEAop = X86::LEA32r;
2508 CMPop = X86::CMP32rm;
2509 CALLop = X86::CALLpcrel32;
2514 "HiPE prologue scratch register is live-in");
2518 SPReg,
false, -MaxStack);
2521 .addReg(ScratchReg), PReg,
false, SPLimitOffset);
2522 BuildMI(stackCheckMBB, DL, TII.
get(X86::JAE_1)).addMBB(&PrologueMBB);
2526 addExternalSymbol(
"inc_stack_0");
2528 SPReg,
false, -MaxStack);
2530 .addReg(ScratchReg), PReg,
false, SPLimitOffset);
2531 BuildMI(incStackMBB, DL, TII.
get(X86::JLE_1)).addMBB(incStackMBB);
2538 #ifdef EXPENSIVE_CHECKS
2556 if (NumPops != 1 && NumPops != 2)
2561 if (MBBI == MBB.
begin())
2564 if (!Prev->isCall() || !Prev->getOperand(1).isRegMask())
2568 unsigned FoundRegs = 0;
2570 auto RegMask = Prev->getOperand(1);
2573 Is64Bit ? X86::GR64_NOREX_NOSPRegClass : X86::GR32_NOREX_NOSPRegClass;
2575 for (
auto Candidate : RegClass) {
2580 if (!RegMask.clobbersPhysReg(Candidate))
2585 if (MO.isReg() && MO.isDef() &&
2586 TRI->isSuperOrSubRegisterEq(MO.getReg(), Candidate)) {
2595 Regs[FoundRegs++] = Candidate;
2596 if (FoundRegs == (
unsigned)NumPops)
2604 while (FoundRegs < (
unsigned)NumPops)
2605 Regs[FoundRegs++] = Regs[0];
2607 for (
int i = 0; i < NumPops; ++i)
2609 TII.
get(STI.
is64Bit() ? X86::POP64r : X86::POP32r), Regs[i]);
2618 unsigned Opcode = I->getOpcode();
2619 bool isDestroy = Opcode == TII.getCallFrameDestroyOpcode();
2621 uint64_t Amount = !reserveCallFrame ? TII.getFrameSize(*I) : 0;
2622 uint64_t InternalAmt = (isDestroy || Amount) ? TII.getFrameAdjustment(*I) : 0;
2626 if (!reserveCallFrame) {
2635 Amount =
alignTo(Amount, StackAlign);
2650 bool HasDwarfEHHandlers = !WindowsCFI && !MF.
getLandingPads().empty();
2652 if (HasDwarfEHHandlers && !isDestroy &&
2662 Amount -= InternalAmt;
2667 if (isDestroy && InternalAmt && DwarfCFI && !
hasFP(MF))
2675 if (StackAdjustment) {
2682 if (StackAdjustment) {
2684 adjustStackWithPops(MBB, InsertPos, DL, StackAdjustment)))
2685 BuildStackAdjustment(MBB, InsertPos, DL, StackAdjustment,
2690 if (DwarfCFI && !
hasFP(MF)) {
2700 if (CfaAdjustment) {
2710 if (isDestroy && InternalAmt) {
2719 while (CI != B && !std::prev(CI)->isCall())
2721 BuildStackAdjustment(MBB, CI, DL, -InternalAmt,
false);
2730 return !
TRI->needsStackRealignment(MF) || !MBB.
isLiveIn(X86::EFLAGS);
2768 const DebugLoc &DL,
bool RestoreSP)
const {
2772 "restoring EBP/ESI on non-32-bit target");
2784 int EHRegSize = MFI.getObjectSize(FI);
2789 X86::EBP,
true, -EHRegSize)
2795 int EndOffset = -EHRegOffset - EHRegSize;
2798 if (UsedReg == FramePtr) {
2808 "end of registration object above normal EBP position!");
2809 }
else if (UsedReg == BasePtr) {
2812 FramePtr,
false, EndOffset)
2818 assert(UsedReg == BasePtr);
2820 UsedReg,
true, Offset)
2830 struct X86FrameSortingObject {
2831 bool IsValid =
false;
2832 unsigned ObjectIndex = 0;
2833 unsigned ObjectSize = 0;
2834 unsigned ObjectAlignment = 1;
2835 unsigned ObjectNumUses = 0;
2851 struct X86FrameSortingComparator {
2852 inline bool operator()(
const X86FrameSortingObject &
A,
2853 const X86FrameSortingObject &
B) {
2854 uint64_t DensityAScaled, DensityBScaled;
2874 DensityAScaled =
static_cast<uint64_t
>(A.ObjectNumUses) *
2875 static_cast<uint64_t>(B.ObjectSize);
2876 DensityBScaled =
static_cast<uint64_t
>(B.ObjectNumUses) *
2877 static_cast<uint64_t>(A.ObjectSize);
2887 if (DensityAScaled == DensityBScaled)
2888 return A.ObjectAlignment < B.ObjectAlignment;
2890 return DensityAScaled < DensityBScaled;
2904 if (ObjectsToAllocate.
empty())
2916 for (
auto &Obj : ObjectsToAllocate) {
2917 SortingObjects[Obj].IsValid =
true;
2918 SortingObjects[Obj].ObjectIndex = Obj;
2922 if (ObjectSize == 0)
2924 SortingObjects[Obj].ObjectSize = 4;
2926 SortingObjects[Obj].ObjectSize = ObjectSize;
2930 for (
auto &MBB : MF) {
2931 for (
auto &MI : MBB) {
2938 int Index = MO.getIndex();
2942 SortingObjects[Index].IsValid)
2943 SortingObjects[Index].ObjectNumUses++;
2950 std::stable_sort(SortingObjects.begin(), SortingObjects.end(),
2951 X86FrameSortingComparator());
2959 for (
auto &Obj : SortingObjects) {
2963 ObjectsToAllocate[i++] = Obj.ObjectIndex;
2967 if (!
TRI->needsStackRealignment(MF) &&
hasFP(MF))
2968 std::reverse(ObjectsToAllocate.begin(), ObjectsToAllocate.end());
2974 unsigned Offset = 16;
2980 Offset += getWinEHFuncletFrameSize(MF);
3004 int64_t MinFixedObjOffset = -
SlotSize;
3011 if (FrameIndex != INT_MAX) {
3022 MinFixedObjOffset -=
std::abs(MinFixedObjOffset) % 8;
3023 int64_t UnwindHelpOffset = MinFixedObjOffset -
SlotSize;
3031 auto MBBI = MBB.
begin();
void push_front(MachineBasicBlock *MBB)
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 getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr bool isUInt< 32 >(uint64_t x)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
static bool flagsNeedToBePreservedBeforeTheTerminators(const MachineBasicBlock &MBB)
Check if the flags need to be preserved before the terminators.
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
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...
SmallVector< WinEHHandlerType, 1 > HandlerArray
const GlobalValue * getGlobal() const
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
iterator_range< livein_iterator > liveins() const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void setHasWinCFI(bool v)
bool hasCopyImplyingStackAdjustment() const
Returns true if the function contains operations which will lower down to instructions which manipula...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
const X86InstrInfo * getInstrInfo() const override
bool hasBasePointer(const MachineFunction &MF) const
unsigned getNumOperands() const
Return number of MDNode operands.
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment for a spill slot for a register of this class.
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
static unsigned getLEArOpcode(unsigned IsLP64)
bool callsEHReturn() 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...
bool isCleanupFuncletEntry() const
Returns true if this is the entry block of a cleanup funclet.
unsigned getArgumentStackSize() const
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
constexpr bool isInt< 8 >(int64_t x)
unsigned getCalleeSavedFrameSize() const
void setCalleeSavedFrameSize(unsigned bytes)
bool isTargetWindowsCoreCLR() const
void setIsDead(bool Val=true)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
void setSEHFramePtrSaveIndex(int Index)
iterator_range< mop_iterator > operands()
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
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...
X86FrameLowering(const X86Subtarget &STI, unsigned StackAlignOverride)
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
return AArch64::GPR64RegClass contains(Reg)
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
iterator_range< succ_iterator > successors()
StringRef getName() const
Return a constant reference to the value's name.
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
bool Uses64BitFramePtr
True if the 64-bit frame or stack pointer should be used.
X86_INTR - x86 hardware interrupt context.
bool isTargetNaCl64() const
CLEANUPRET - Represents a return from a cleanup block funclet.
int getTCReturnAddrDelta() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
DILocation * get() const
Get the underlying DILocation.
const HexagonInstrInfo * TII
bool isTargetDarwin() const
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
const MCAsmInfo * getMCAsmInfo() const
Return target specific asm information.
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const Module * getModule() const
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Reg
All possible values of the reg field in the ModR/M byte.
iterator_range< iterator > terminators()
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.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
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...
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
static const uint64_t kSplitStackAvailable
bool hasDebugInfo() const
Returns true if valid debug info is present.
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
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.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool Immutable=false)
Create a spill slot at a fixed location on the stack.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
LLVM_NODISCARD bool empty() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
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
uint16_t StackAdjustment(const RuntimeFunction &RF)
StackAdjustment - calculated stack adjustment in words.
const MachineBasicBlock & front() const
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
int getObjectIndexBegin() const
Return the minimum frame object index.
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...
bool hasStackObjects() const
Return true if there are any stack objects in this function.
bool isLiveIn(unsigned Reg) const
int getOffsetAdjustment() const
Return the correction for frame offsets.
unsigned getFramePtr() const
Returns physical register used as frame pointer.
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe inline-stub with the actual probe code inline.
static unsigned getANDriOpcode(bool IsLP64, int64_t Imm)
bool isBundled() const
Return true if this instruction part of a bundle.
bool is64Bit() const
Is this x86_64? (disregarding specific ABI / programming model)
void setHasSEHFramePtrSave(bool V)
static unsigned getHiPELiteral(NamedMDNode *HiPELiteralsMD, const StringRef LiteralName)
Lookup an ERTS parameter in the !hipe.literals named metadata node.
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096))
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)
bool getHasSEHFramePtrSave() const
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.
int getFrameIndexReferenceSP(const MachineFunction &MF, int FI, unsigned &SPReg, int Adjustment) const
unsigned getUndefRegState(bool B)
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
unsigned getKillRegState(bool B)
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
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.
bool isDebugValue() const
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.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
bool regsOverlap(unsigned regA, unsigned regB) const
Returns true if the two registers are equal or alias each other.
unsigned const MachineRegisterInfo * MRI
bool isCallingConvWin64(CallingConv::ID CC) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
CodeModel::Model getCodeModel() const
Returns the code model.
LLVM Basic Block Representation.
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.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
void setStackSize(uint64_t Size)
Set the size of the stack.
static bool is64Bit(const char *name)
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE instructions.
void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL) const
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const MachineOperand & getOperand(unsigned i) const
bool isTargetWin32() const
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size)
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
bool hasPersonalityFn() const
Check whether this function has a personality function.
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
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]...
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
MDNode * getOperand(unsigned i) const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const TargetRegisterClass * getGPRsForTailCall(const MachineFunction &MF) const
getGPRsForTailCall - Returns a register class with registers that can be used in forming tail calls...
self_iterator getIterator()
int mergeSPUpdates(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, bool doMergeWithPrevious) const
Check the instruction before/after the passed instruction.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
X86_FastCall - 'fast' analog of X86_StdCall.
bool getUsesRedZone() const
int CreateSpillStackObject(uint64_t Size, unsigned Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
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...
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 getBaseRegister() const
unsigned getStackRegister() const
static unsigned getSUBriOpcode(unsigned IsLP64, int64_t Imm)
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction. ...
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
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.
static bool isFuncletReturnInstr(MachineInstr &MI)
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
static unsigned getADDriOpcode(unsigned IsLP64, int64_t Imm)
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...
The memory access writes data.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
bool hasCalls() const
Return true if the current function has any function calls.
virtual const TargetFrameLowering * getFrameLowering() const
StringRef getString() const
const MDOperand & getOperand(unsigned I) const
int getRestoreBasePointerOffset() const
bool isTargetWindowsMSVC() const
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)
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.
const MCContext & getContext() const
bool isTarget64BitILP32() const
Is this x86_64 with the ILP32 programming model (x32 ABI)?
MachineOperand class - Representation of each machine instruction operand.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
void emitStackProbe(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool InProlog) const
Emit target stack probe code.
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
Information about stack frame layout on the target.
void setUsesMorestackAddr(bool b)
bool isTargetLinux() const
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
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 ...
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
canSimplifyCallFramePseudos - If there is a reserved call frame, the call frame pseudos can be simpli...
bool getHasPushSequences() const
IterT skipDebugInstructionsBackward(IterT It, IterT Begin)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
unsigned getX86SubSuperRegister(unsigned, unsigned, bool High=false)
Returns the sub or super register of a specific X86 register.
static bool isTailCallOpcode(unsigned Opc)
SmallVector< WinEHTryBlockMapEntry, 4 > TryBlockMap
bool hasEHFunclets() 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...
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
void setHasAddressTaken()
Set this block to reflect that it potentially is the target of an indirect branch.
union llvm::WinEHHandlerType::@158 CatchObj
The CatchObj starts out life as an LLVM alloca and is eventually turned frame index.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
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.
bool canUseLEAForSPInEpilogue(const MachineFunction &MF) const
Check that LEA can be used on SP in an epilogue sequence for MF.
bool isTargetDragonFly() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
CATCHRET - Represents a return from a catch block funclet.
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
const MCRegisterInfo * getRegisterInfo() const
The memory access reads data.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
Representation of each machine instruction.
int getSEHFramePtrSaveIndex() const
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Adjust the prologue to have the function use segmented stacks.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
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.
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
bool isTarget64BitLP64() const
Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
bool isCall(QueryType Type=AnyInBundle) const
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Pair of physical register and lane mask.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool callsUnwindInit() const
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Fast - This calling convention attempts to make calls as fast as possible (e.g.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getSlotSize() const
static unsigned getSUBrrOpcode(unsigned isLP64)
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling...
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
const X86RegisterInfo * TRI
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin...
unsigned getReg() const
getReg - Returns the register number.
StringRef getValueAsString() const
Return the attribute's value as a string.
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isEAXLiveIn(MachineBasicBlock &MBB)
static unsigned getADDrrOpcode(unsigned isLP64)
void insert(iterator MBBI, MachineBasicBlock *MBB)
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
bool isTargetWin64() const
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...
void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, int64_t NumBytes, bool InEpilogue) const
Emit a series of instructions to increment / decrement the stack pointer by a constant value...
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) 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 isTargetFreeBSD() const
static const unsigned FramePtr
unsigned getNumOperands() const
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)
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
StringRef - Represent a constant reference to a string, i.e.
MachineModuleInfo & getMMI() const
unsigned getFrameRegister(const MachineFunction &MF) const override
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...
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
int getObjectIndexEnd() const
Return one past the maximum frame object index.
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack.
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 ...
static bool HasNestArgument(const MachineFunction *MF)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
SlotIndex - An opaque wrapper around machine indexes.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool getRestoreBasePointer() const
This class contains meta information specific to a module.
bool usesWindowsCFI() const