33#define DEBUG_TYPE "framelowering"
34STATISTIC(NumPESpillVSR,
"Number of spills to vector in prologue");
35STATISTIC(NumPEReloadVSR,
"Number of reloads from vector in epilogue");
36STATISTIC(NumPrologProbed,
"Number of prologues probed");
40 return STI.isPPC64() ? 16 : 8;
42 return STI.isPPC64() ? 16 : 4;
47 return STI.isPPC64() ? 40 : 20;
53 return STI.isPPC64() ? -8U : -4U;
58 return (STI.
isELFv2ABI() ? 4 : 6) * (STI.isPPC64() ? 8 : 4);
70 return STI.isPPC64() ? -16U : -8U;
74 return (STI.
isAIXABI() && !STI.isPPC64()) ? 4 : 8;
79 STI.getPlatformStackAlignment(), 0),
89 unsigned &NumEntries)
const {
92#define CALLEE_SAVED_FPRS \
114#define CALLEE_SAVED_GPRS32 \
135#define CALLEE_SAVED_GPRS64 \
156#define CALLEE_SAVED_VRS \
173 static const SpillSlot ELFOffsets32[] = {
208 static const SpillSlot ELFOffsets64[] = {
223 static const SpillSlot AIXOffsets64[] = {
226 if (Subtarget.is64BitELFABI()) {
227 NumEntries = std::size(ELFOffsets64);
231 if (Subtarget.is32BitELFABI()) {
232 NumEntries = std::size(ELFOffsets32);
236 assert(Subtarget.isAIXABI() &&
"Unexpected ABI.");
238 if (Subtarget.isPPC64()) {
239 NumEntries = std::size(AIXOffsets64);
243 NumEntries = std::size(AIXOffsets32);
280 bool UseEstimate)
const {
281 unsigned NewMaxCallFrameSize = 0;
283 &NewMaxCallFrameSize);
294 unsigned *NewMaxCallFrameSize)
const {
305 Align Alignment = std::max(TargetAlign, MaxAlign);
315 !RegInfo->hasBasePointer(MF) &&
320 bool FitsInRedZone = FrameSize <= Subtarget.getRedZoneSize();
323 if (!DisableRedZone && CanUseRedZone && FitsInRedZone) {
333 maxCallFrameSize = std::max(maxCallFrameSize, minCallFrameSize);
338 maxCallFrameSize =
alignTo(maxCallFrameSize, Alignment);
341 if (NewMaxCallFrameSize)
342 *NewMaxCallFrameSize = maxCallFrameSize;
345 FrameSize += maxCallFrameSize;
348 FrameSize =
alignTo(FrameSize, Alignment);
385 unsigned FPReg = is31 ? PPC::R31 : PPC::R1;
386 unsigned FP8Reg = is31 ? PPC::X31 : PPC::X1;
390 unsigned BPReg = HasBP ? (
unsigned) RegInfo->getBaseRegister(MF) :
FPReg;
391 unsigned BP8Reg = HasBP ? (
unsigned) PPC::X30 : FP8Reg;
400 switch (MO.getReg()) {
438 bool TwoUniqueRegsRequired,
450 assert (SR1 &&
"Asking for the second scratch register but not the first?");
455 if ((UseAtEnd &&
MBB->isReturnBlock()) ||
456 (!UseAtEnd && (&
MBB->getParent()->front() ==
MBB)))
464 RS.enterBasicBlock(*
MBB);
466 RS.enterBasicBlockEnd(*
MBB);
471 RS.enterBasicBlock(*
MBB);
478 if (!
RS.isRegUsed(R0) && !
RS.isRegUsed(R12))
482 const PPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
486 BitVector BV =
RS.getRegsAvailable(Subtarget.isPPC64() ? &PPC::G8RCRegClass :
493 for (
int i = 0; CSRegs[i]; ++i)
499 *SR1 = FirstScratchReg == -1 ? (unsigned)PPC::NoRegister : FirstScratchReg;
506 int SecondScratchReg = BV.
find_next(*SR1);
507 if (SecondScratchReg != -1)
508 *SR2 = SecondScratchReg;
510 *SR2 = TwoUniqueRegsRequired ?
Register() : *SR1;
515 if (BV.
count() < (TwoUniqueRegsRequired ? 2U : 1U))
530 const PPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
534 int NegFrameSize = -FrameSize;
535 bool IsLargeFrame = !
isInt<16>(NegFrameSize);
538 bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
539 const PPCTargetLowering &
TLI = *Subtarget.getTargetLowering();
541 return ((IsLargeFrame || !HasRedZone) && HasBP && MaxAlign > 1) ||
548 return findScratchRegister(TmpMBB,
false,
549 twoUniqueScratchRegsRequired(TmpMBB));
555 return findScratchRegister(TmpMBB,
true);
558bool PPCFrameLowering::stackUpdateCanBeMoved(
MachineFunction &MF)
const {
579 if (!FrameSize || FrameSize >
Subtarget.getRedZoneSize())
599 return !RegInfo->requiresFrameIndexScavenging(MF);
615 const bool HasFastMFLR = Subtarget.hasFastMFLR();
618 bool isPPC64 = Subtarget.isPPC64();
620 bool isSVR4ABI = Subtarget.isSVR4ABI();
621 bool isELFv2ABI = Subtarget.isELFv2ABI();
622 assert((isSVR4ABI || Subtarget.isAIXABI()) &&
"Unsupported PPC ABI.");
626 int64_t NegFrameSize = -FrameSize;
638 bool MustSaveCR = !MustSaveCRs.
empty();
640 bool HasFP =
hasFP(MF);
641 bool HasBP = RegInfo->hasBasePointer(MF);
642 bool HasRedZone = isPPC64 || !isSVR4ABI;
643 const bool HasROPProtect = Subtarget.hasROPProtect();
644 bool HasPrivileged = Subtarget.hasPrivileged();
647 Register BPReg = RegInfo->getBaseRegister(MF);
649 Register LRReg = isPPC64 ? PPC::LR8 : PPC::LR;
650 Register TOCReg = isPPC64 ? PPC::X2 : PPC::R2;
652 Register TempReg = isPPC64 ? PPC::X12 : PPC::R12;
660 const MCInstrDesc& StoreUpdtIdxInst =
TII.get(isPPC64 ? PPC::STDUX
664 const MCInstrDesc& SubtractCarryingInst =
TII.get(isPPC64 ? PPC::SUBFC8
666 const MCInstrDesc& SubtractImmCarryingInst =
TII.get(isPPC64 ? PPC::SUBFIC8
668 const MCInstrDesc &MoveFromCondRegInst =
TII.get(isPPC64 ? PPC::MFCR8
670 const MCInstrDesc &StoreWordInst =
TII.get(isPPC64 ? PPC::STW8 : PPC::STW);
672 TII.get(isPPC64 ? (HasPrivileged ? PPC::HASHSTP8 : PPC::HASHST8)
673 : (HasPrivileged ? PPC::HASHSTP : PPC::HASHST));
680 "FrameSize must be >0 to save/restore the FP or LR for 32-bit SVR4.");
683 bool SingleScratchReg = findScratchRegister(
684 &
MBB,
false, twoUniqueScratchRegsRequired(&
MBB), &ScratchReg, &TempReg);
685 assert(SingleScratchReg &&
686 "Required number of registers not available in this block");
688 SingleScratchReg = ScratchReg == TempReg;
692 int64_t FPOffset = 0;
696 assert(FPIndex &&
"No Frame Pointer Save Slot!");
700 int64_t BPOffset = 0;
704 assert(BPIndex &&
"No Base Pointer Save Slot!");
708 int64_t PBPOffset = 0;
712 assert(PBPIndex &&
"No PIC Base Pointer Save Slot!");
718 if (HasBP && MaxAlign > 1)
719 assert(
Log2(MaxAlign) < 16 &&
"Invalid alignment!");
723 bool isLargeFrame = !
isInt<16>(NegFrameSize);
729 bool MovingStackUpdateDown =
false;
732 if (stackUpdateCanBeMoved(MF)) {
745 if (CSI.isSpilledToReg()) {
746 StackUpdateLoc =
MBBI;
747 MovingStackUpdateDown =
false;
751 int FrIdx = CSI.getFrameIdx();
760 MovingStackUpdateDown =
true;
764 StackUpdateLoc =
MBBI;
765 MovingStackUpdateDown =
false;
771 if (MovingStackUpdateDown) {
773 int FrIdx = CSI.getFrameIdx();
783 auto BuildMoveFromCR = [&]() {
784 if (isELFv2ABI && MustSaveCRs.
size() == 1) {
789 assert(isPPC64 &&
"V2 ABI is 64-bit only.");
796 for (
unsigned CRfield : MustSaveCRs)
803 if (MustSaveCR && SingleScratchReg &&
MustSaveLR) {
814 if (MustSaveCR && !(SingleScratchReg &&
MustSaveLR))
838 auto SaveLR = [&](int64_t
Offset) {
854 assert((ImmOffset <= -8 && ImmOffset >= -512) &&
855 "ROP hash save offset out of range.");
856 assert(((ImmOffset & 0x7) == 0) &&
857 "ROP hash save offset must be 8 byte aligned.");
870 assert(HasRedZone &&
"A red zone is always available on PPC64");
887 if (HasBP && HasRedZone) {
897 (
TLI.hasInlineStackProbe(MF) && FrameSize >
TLI.getStackProbeSize(MF)) ||
898 (HasBP && MaxAlign > 1) || isLargeFrame;
908 (HasSTUX || !
isInt<16>(FrameSize + LROffset) || HasROPProtect))
914 if (
TLI.hasInlineStackProbe(MF) && FrameSize >
TLI.getStackProbeSize(MF)) {
918 TII.get(isPPC64 ? PPC::PROBED_STACKALLOC_64
919 : PPC::PROBED_STACKALLOC_32))
933 if (HasBP && MaxAlign > 1) {
950 assert(!SingleScratchReg &&
"Only a single scratch reg available");
951 TII.materializeImmPostRA(
MBB,
MBBI, dl, TempReg, NegFrameSize);
961 }
else if (!isLargeFrame) {
967 TII.materializeImmPostRA(
MBB,
MBBI, dl, ScratchReg, NegFrameSize);
978 assert(isELFv2ABI &&
"TOC saves in the prologue only supported on ELFv2");
986 assert(!isPPC64 &&
"A red zone is always available on PPC64");
1002 if (ScratchReg == PPC::R0) {
1011 .
addImm(FPOffset-LastOffset);
1012 LastOffset = FPOffset;
1023 .
addImm(PBPOffset-LastOffset);
1024 LastOffset = PBPOffset;
1034 .
addImm(BPOffset-LastOffset);
1035 LastOffset = BPOffset;
1079 .
addImm(FrameSize + FPOffset)
1084 .
addImm(FrameSize + PBPOffset)
1089 .
addImm(FrameSize + BPOffset)
1099 if (!HasSTUX &&
MustSaveLR && !HasFastMFLR &&
1100 isInt<16>(FrameSize + LROffset) && !HasROPProtect)
1101 SaveLR(LROffset + FrameSize);
1111 unsigned Reg =
MRI->getDwarfRegNum(BPReg,
true);
1125 unsigned Reg =
MRI->getDwarfRegNum(
FPReg,
true);
1134 unsigned Reg =
MRI->getDwarfRegNum(PPC::R30,
true);
1143 unsigned Reg =
MRI->getDwarfRegNum(BPReg,
true);
1152 unsigned Reg =
MRI->getDwarfRegNum(LRReg,
true);
1166 if (!HasBP && needsCFI) {
1169 unsigned Reg =
MRI->getDwarfRegNum(
FPReg,
true);
1184 if (Reg == PPC::LR || Reg == PPC::LR8 || Reg == PPC::RM)
continue;
1188 if (PPC::CRBITRCRegClass.
contains(Reg))
1191 if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
1196 if (isSVR4ABI && isPPC64 && (PPC::CR2 <= Reg && Reg <= PPC::CR4)) {
1200 Register CRReg = isELFv2ABI? Reg : PPC::CR2;
1202 nullptr,
MRI->getDwarfRegNum(CRReg,
true), CRSaveOffset));
1208 if (
I.isSpilledToReg()) {
1209 unsigned SpilledReg =
I.getDstReg();
1211 nullptr,
MRI->getDwarfRegNum(Reg,
true),
1212 MRI->getDwarfRegNum(SpilledReg,
true)));
1220 if (MovingStackUpdateDown)
1224 nullptr,
MRI->getDwarfRegNum(Reg,
true),
Offset));
1234 bool isPPC64 = Subtarget.isPPC64();
1242 int Opc =
MI.getOpcode();
1243 return Opc == PPC::PROBED_STACKALLOC_64 ||
Opc == PPC::PROBED_STACKALLOC_32;
1245 if (StackAllocMIPos == PrologMBB.
end())
1251 int64_t NegFrameSize =
MI.getOperand(2).getImm();
1252 unsigned ProbeSize =
TLI.getStackProbeSize(MF);
1253 int64_t NegProbeSize = -(int64_t)ProbeSize;
1255 int64_t NumBlocks = NegFrameSize / NegProbeSize;
1256 int64_t NegResidualSize = NegFrameSize % NegProbeSize;
1258 Register ScratchReg =
MI.getOperand(0).getReg();
1261 bool HasBP = RegInfo->hasBasePointer(MF);
1262 Register BPReg = RegInfo->getBaseRegister(MF);
1264 bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
1265 const MCInstrDesc &CopyInst =
TII.get(isPPC64 ? PPC::OR8 : PPC::OR);
1269 unsigned RegNum =
MRI->getDwarfRegNum(Reg,
true);
1278 unsigned RegNum =
MRI->getDwarfRegNum(Reg,
true);
1279 unsigned CFIIndex =
MBB.getParent()->addFrameInst(
1305 Register NegSizeReg,
bool UseDForm,
1347 assert(HasBP &&
"The function is supposed to have base pointer when its "
1348 "stack is realigned.");
1355 assert(ProbeSize >= Subtarget.getRedZoneSize() &&
1356 "Probe size should be larger or equal to the size of red-zone so "
1357 "that red-zone is not clobbered by probing.");
1363 NegProbeSize = std::max(NegProbeSize, -((int64_t)1 << 15));
1365 "NegProbeSize should be materializable by DForm");
1382 MF.
insert(MBBInsertPoint, ProbeLoopBodyMBB);
1384 MF.
insert(MBBInsertPoint, ProbeExitMBB);
1387 Register BackChainPointer = HasRedZone ? BPReg : TempReg;
1388 allocateAndProbe(*ProbeExitMBB, ProbeExitMBB->
end(), 0, ScratchReg,
false,
1393 BuildMI(*ProbeExitMBB, ProbeExitMBB->
end(),
DL, CopyInst, TempReg)
1401 BuildMI(&
MBB,
DL,
TII.get(isPPC64 ? PPC::SUBF8 : PPC::SUBF), ScratchReg)
1413 MBB.addSuccessor(ProbeLoopBodyMBB);
1414 MBB.addSuccessor(ProbeExitMBB);
1418 Register BackChainPointer = HasRedZone ? BPReg : TempReg;
1419 allocateAndProbe(*ProbeLoopBodyMBB, ProbeLoopBodyMBB->
end(), NegProbeSize,
1420 0,
true , BackChainPointer);
1421 BuildMI(ProbeLoopBodyMBB,
DL,
TII.get(isPPC64 ? PPC::ADDI8 : PPC::ADDI),
1425 BuildMI(ProbeLoopBodyMBB,
DL,
TII.get(isPPC64 ? PPC::CMPDI : PPC::CMPWI),
1432 .
addMBB(ProbeLoopBodyMBB);
1438 return ProbeExitMBB;
1443 if (HasBP && MaxAlign > 1) {
1456 BuildMI(*CurrentMBB, {
MI},
DL,
TII.get(isPPC64 ? PPC::SUBF8 : PPC::SUBF),
1460 MaterializeImm(*CurrentMBB, {
MI}, NegFrameSize, ScratchReg);
1461 BuildMI(*CurrentMBB, {
MI},
DL,
TII.get(isPPC64 ? PPC::ADD8 : PPC::ADD4),
1465 CurrentMBB = probeRealignedStack(*CurrentMBB, {
MI}, ScratchReg,
FPReg);
1473 buildDefCFA(*CurrentMBB, {
MI},
FPReg, 0);
1475 if (NegResidualSize) {
1476 bool ResidualUseDForm = CanUseDForm(NegResidualSize);
1477 if (!ResidualUseDForm)
1478 MaterializeImm(*CurrentMBB, {
MI}, NegResidualSize, ScratchReg);
1479 allocateAndProbe(*CurrentMBB, {
MI}, NegResidualSize, ScratchReg,
1480 ResidualUseDForm,
FPReg);
1482 bool UseDForm = CanUseDForm(NegProbeSize);
1484 if (NumBlocks < 3) {
1486 MaterializeImm(*CurrentMBB, {
MI}, NegProbeSize, ScratchReg);
1487 for (
int i = 0; i < NumBlocks; ++i)
1488 allocateAndProbe(*CurrentMBB, {
MI}, NegProbeSize, ScratchReg, UseDForm,
1499 MaterializeImm(*CurrentMBB, {
MI}, NumBlocks, ScratchReg);
1500 BuildMI(*CurrentMBB, {
MI},
DL,
TII.get(isPPC64 ? PPC::MTCTR8 : PPC::MTCTR))
1503 MaterializeImm(*CurrentMBB, {
MI}, NegProbeSize, ScratchReg);
1508 MF.
insert(MBBInsertPoint, LoopMBB);
1510 MF.
insert(MBBInsertPoint, ExitMBB);
1512 allocateAndProbe(*LoopMBB, LoopMBB->
end(), NegProbeSize, ScratchReg,
1514 BuildMI(LoopMBB,
DL,
TII.get(isPPC64 ? PPC::BDNZ8 : PPC::BDNZ))
1519 ExitMBB->
splice(ExitMBB->
end(), CurrentMBB,
1533 MI.eraseFromParent();
1542 dl =
MBBI->getDebugLoc();
1554 bool isPPC64 = Subtarget.isPPC64();
1560 bool MustSaveCR = !MustSaveCRs.
empty();
1562 bool HasFP =
hasFP(MF);
1563 bool HasBP = RegInfo->hasBasePointer(MF);
1564 bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
1565 bool HasROPProtect = Subtarget.hasROPProtect();
1566 bool HasPrivileged = Subtarget.hasPrivileged();
1569 Register BPReg = RegInfo->getBaseRegister(MF);
1572 Register TempReg = isPPC64 ? PPC::X12 : PPC::R12;
1577 const MCInstrDesc& LoadImmShiftedInst =
TII.get( isPPC64 ? PPC::LIS8
1589 const MCInstrDesc& MoveToCRInst =
TII.get( isPPC64 ? PPC::MTOCRF8
1592 TII.get(isPPC64 ? (HasPrivileged ? PPC::HASHCHKP8 : PPC::HASHCHK8)
1593 : (HasPrivileged ? PPC::HASHCHKP : PPC::HASHCHK));
1596 int64_t FPOffset = 0;
1599 bool SingleScratchReg = findScratchRegister(&
MBB,
true,
false, &ScratchReg,
1601 assert(SingleScratchReg &&
1602 "Could not find an available scratch register");
1604 SingleScratchReg = ScratchReg == TempReg;
1608 assert(FPIndex &&
"No Frame Pointer Save Slot!");
1612 int64_t BPOffset = 0;
1615 assert(BPIndex &&
"No Base Pointer Save Slot!");
1619 int64_t PBPOffset = 0;
1622 assert(PBPIndex &&
"No PIC Base Pointer Save Slot!");
1626 bool IsReturnBlock = (
MBBI !=
MBB.end() &&
MBBI->isReturn());
1628 if (IsReturnBlock) {
1629 unsigned RetOpcode =
MBBI->getOpcode();
1630 bool UsesTCRet = RetOpcode == PPC::TCRETURNri ||
1631 RetOpcode == PPC::TCRETURNdi ||
1632 RetOpcode == PPC::TCRETURNai ||
1633 RetOpcode == PPC::TCRETURNri8 ||
1634 RetOpcode == PPC::TCRETURNdi8 ||
1635 RetOpcode == PPC::TCRETURNai8;
1640 assert(StackAdjust.
isImm() &&
"Expecting immediate value.");
1642 int StackAdj = StackAdjust.
getImm();
1643 int Delta = StackAdj - MaxTCRetDelta;
1644 assert((Delta >= 0) &&
"Delta must be positive");
1645 if (MaxTCRetDelta>0)
1646 FrameSize += (StackAdj +Delta);
1648 FrameSize += StackAdj;
1654 bool isLargeFrame = !
isInt<16>(FrameSize);
1668 unsigned RBReg =
SPReg;
1676 if (stackUpdateCanBeMoved(MF)) {
1681 if (CSI.isSpilledToReg()) {
1682 StackUpdateLoc =
MBBI;
1685 int FrIdx = CSI.getFrameIdx();
1697 StackUpdateLoc =
MBBI;
1710 if (HasRedZone && HasBP) {
1720 assert(HasFP &&
"Expecting a valid frame pointer.");
1723 if (!isLargeFrame) {
1727 TII.materializeImmPostRA(
MBB,
MBBI, dl, ScratchReg, FrameSize);
1741 assert(FPOffset <= 0 && BPOffset <= 0 && PBPOffset <= 0 &&
1742 "Local offsets should be negative");
1744 FPOffset += FrameSize;
1745 BPOffset += FrameSize;
1746 PBPOffset += FrameSize;
1764 assert(RBReg != ScratchReg &&
"Should have avoided ScratchReg");
1769 if (MustSaveCRs.
size() == 1)
1771 BuildMI(
MBB, InsertPt, dl, MoveToCRInst, MustSaveCRs[0])
1775 unsigned CRMask = 0;
1776 for (
unsigned CRField : MustSaveCRs) {
1777 CRMask |= 0x80 >> (CRField - PPC::CR0);
1781 TII.get(isPPC64 ? PPC::MTCRF8 : PPC::MTCRF))
1787 for (
unsigned CRField : MustSaveCRs)
1798 if (MustSaveCR && SingleScratchReg &&
MustSaveLR) {
1801 assert(HasRedZone &&
"Expecting red zone");
1805 BuildMoveToCR(
MBBI, TempReg);
1812 bool LoadedLR =
false;
1820 if (MustSaveCR && !(SingleScratchReg &&
MustSaveLR)) {
1821 assert(RBReg ==
SPReg &&
"Should be using SP as a base register");
1830 if (HasRedZone || RBReg ==
SPReg)
1852 if (RBReg !=
SPReg || SPAdd != 0) {
1853 assert(!HasRedZone &&
"This should not happen with red zone");
1864 assert(RBReg != ScratchReg &&
"Should be using FP or SP as base register");
1879 BuildMoveToCR(
MBBI, TempReg);
1884 if (HasROPProtect) {
1887 assert((ImmOffset <= -8 && ImmOffset >= -512) &&
1888 "ROP hash check location offset out of range.");
1889 assert(((ImmOffset & 0x7) == 0) &&
1890 "ROP hash check location offset must be 8 byte aligned.");
1901 if (IsReturnBlock) {
1902 unsigned RetOpcode =
MBBI->getOpcode();
1904 (RetOpcode == PPC::BLR || RetOpcode == PPC::BLR8) &&
1909 if (CallerAllocatedAmt &&
isInt<16>(CallerAllocatedAmt)) {
1914 .
addImm(CallerAllocatedAmt >> 16);
1917 .
addImm(CallerAllocatedAmt & 0xFFFF);
1924 createTailCallBranchInstr(
MBB);
1933 assert(
MBBI !=
MBB.end() &&
"Failed to find the first terminator.");
1945 unsigned RetOpcode =
MBBI->getOpcode();
1946 if (RetOpcode == PPC::TCRETURNdi) {
1947 MBBI =
MBB.getLastNonDebugInstr();
1957 }
else if (RetOpcode == PPC::TCRETURNri) {
1958 MBBI =
MBB.getLastNonDebugInstr();
1959 assert(
MBBI->getOperand(0).isReg() &&
"Expecting register operand.");
1961 }
else if (RetOpcode == PPC::TCRETURNai) {
1963 MachineOperand &JumpTarget =
MBBI->getOperand(0);
1965 }
else if (RetOpcode == PPC::TCRETURNdi8) {
1967 MachineOperand &JumpTarget =
MBBI->getOperand(0);
1976 }
else if (RetOpcode == PPC::TCRETURNri8) {
1978 assert(
MBBI->getOperand(0).isReg() &&
"Expecting register operand.");
1980 }
else if (RetOpcode == PPC::TCRETURNai8) {
1982 MachineOperand &JumpTarget =
MBBI->getOperand(0);
1991 if (Subtarget.isAIXABI())
1998 SavedRegs.
reset(PPC::VSRp26);
1999 SavedRegs.
reset(PPC::VSRp27);
2000 SavedRegs.
reset(PPC::VSRp28);
2001 SavedRegs.
reset(PPC::VSRp29);
2002 SavedRegs.
reset(PPC::VSRp30);
2003 SavedRegs.
reset(PPC::VSRp31);
2009 SavedRegs.
reset(LR);
2013 const bool isPPC64 = Subtarget.isPPC64();
2027 if (!BPSI && RegInfo->hasBasePointer(MF)) {
2047 SavedRegs.
reset(isPPC64 ? PPC::X31 : PPC::R31);
2048 if (RegInfo->hasBasePointer(MF)) {
2049 SavedRegs.
reset(RegInfo->getBaseRegister(MF));
2052 if (!
needsFP(MF) && !SavedRegs.
test(isPPC64 ? PPC::X31 : PPC::R31) &&
2053 Subtarget.isAIXABI()) {
2055 (RegInfo->getBaseRegister(MF) == (isPPC64 ? PPC::X30 : PPC::R30)) &&
2056 "Invalid base register on AIX!");
2057 SavedRegs.
set(isPPC64 ? PPC::X31 : PPC::R31);
2061 SavedRegs.
reset(PPC::R30);
2076 if ((SavedRegs.
test(PPC::CR2) || SavedRegs.
test(PPC::CR3) ||
2077 SavedRegs.
test(PPC::CR4))) {
2078 const uint64_t SpillSize = 4;
2079 const int64_t SpillOffset =
2080 Subtarget.isPPC64() ? 8 : Subtarget.isAIXABI() ? 4 : -4;
2100 "MFI can't contain multiple restore points!");
2103 createTailCallBranchInstr(
MBB);
2108 if (CSI.empty() && !
needsFP(MF)) {
2113 unsigned MinGPR = PPC::R31;
2114 unsigned MinG8R = PPC::X31;
2115 unsigned MinFPR = PPC::F31;
2116 unsigned MinVR = Subtarget.hasSPE() ? PPC::S31 : PPC::V31;
2118 bool HasGPSaveArea =
false;
2119 bool HasG8SaveArea =
false;
2120 bool HasFPSaveArea =
false;
2121 bool HasVRSaveArea =
false;
2131 (Reg != PPC::X2 && Reg != PPC::R2)) &&
2132 "Not expecting to try to spill R2 in a function that must save TOC");
2133 if (PPC::GPRCRegClass.
contains(Reg)) {
2134 HasGPSaveArea =
true;
2141 }
else if (PPC::G8RCRegClass.
contains(Reg)) {
2142 HasG8SaveArea =
true;
2149 }
else if (PPC::F8RCRegClass.
contains(Reg)) {
2150 HasFPSaveArea =
true;
2157 }
else if (PPC::CRBITRCRegClass.
contains(Reg) ||
2160 }
else if (PPC::VRRCRegClass.
contains(Reg) ||
2161 PPC::SPERCRegClass.
contains(Reg)) {
2164 HasVRSaveArea =
true;
2179 int64_t LowerBound = 0;
2185 LowerBound = TCSPDelta;
2190 if (HasFPSaveArea) {
2192 int FI =
FPReg.getFrameIdx();
2197 LowerBound -= (31 -
TRI->getEncodingValue(MinFPR) + 1) * 8;
2204 assert(FI &&
"No Frame Pointer Save Slot!");
2207 HasGPSaveArea =
true;
2212 assert(FI &&
"No PIC Base Pointer Save Slot!");
2215 MinGPR = std::min<unsigned>(MinGPR, PPC::R30);
2216 HasGPSaveArea =
true;
2220 if (RegInfo->hasBasePointer(MF)) {
2222 assert(FI &&
"No Base Pointer Save Slot!");
2225 Register BP = RegInfo->getBaseRegister(MF);
2226 if (PPC::G8RCRegClass.
contains(BP)) {
2227 MinG8R = std::min<unsigned>(MinG8R, BP);
2228 HasG8SaveArea =
true;
2229 }
else if (PPC::GPRCRegClass.
contains(BP)) {
2230 MinGPR = std::min<unsigned>(MinGPR, BP);
2231 HasGPSaveArea =
true;
2237 if (HasGPSaveArea || HasG8SaveArea) {
2241 if (!GPReg.isSpilledToReg()) {
2242 int FI = GPReg.getFrameIdx();
2250 if (!G8Reg.isSpilledToReg()) {
2251 int FI = G8Reg.getFrameIdx();
2257 std::min<unsigned>(
TRI->getEncodingValue(MinGPR),
2258 TRI->getEncodingValue(MinG8R));
2260 const unsigned GPRegSize = Subtarget.isPPC64() ? 8 : 4;
2261 LowerBound -= (31 - MinReg + 1) * GPRegSize;
2269 if (
spillsCR(MF) && Subtarget.is32BitELFABI()) {
2271 for (
const auto &CSInfo : CSI) {
2272 if (CSInfo.getReg() == PPC::CR2) {
2273 int FI = CSInfo.getFrameIdx();
2284 if (HasVRSaveArea) {
2290 assert(LowerBound <= 0 &&
"Expect LowerBound have a non-positive value!");
2291 LowerBound &= ~(15);
2294 int FI = VReg.getFrameIdx();
2321 bool NeedSpills = Subtarget.hasSPE() ? !
isInt<8>(StackSize) : !
isInt<16>(StackSize);
2329 unsigned Size =
TRI.getSpillSize(RC);
2330 Align Alignment =
TRI.getSpillAlign(RC);
2350 std::vector<CalleeSavedInfo> &CSI)
const {
2356 const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF);
2359 if (Subtarget.hasSPE()) {
2363 for (
auto &CalleeSaveReg : CSI) {
2366 MCRegister Higher = RegInfo->getSubReg(Reg, PPC::sub_32_hi_phony);
2371 !
MRI.isPhysRegModified(Higher))
2378 if (!Subtarget.getCLOpts().enable_pe_vector_spills || MFI.
hasCalls() ||
2379 !Subtarget.hasP9Vector())
2385 for (
unsigned i = 0; CSRegs[i]; ++i)
2386 BVCalleeSaved.
set(CSRegs[i]);
2388 for (
unsigned Reg : BVAllocatable.
set_bits()) {
2391 if (BVCalleeSaved[Reg] || !PPC::VSRCRegClass.
contains(Reg) ||
2392 MRI.isPhysRegUsed(Reg))
2393 BVAllocatable.
reset(Reg);
2396 bool AllSpilledToReg =
true;
2397 unsigned LastVSRUsedForSpill = 0;
2398 for (
auto &CS : CSI) {
2399 if (BVAllocatable.
none())
2404 if (!PPC::G8RCRegClass.
contains(Reg)) {
2405 AllSpilledToReg =
false;
2411 if (LastVSRUsedForSpill != 0) {
2412 CS.setDstReg(LastVSRUsedForSpill);
2413 BVAllocatable.
reset(LastVSRUsedForSpill);
2414 LastVSRUsedForSpill = 0;
2418 unsigned VolatileVFReg = BVAllocatable.
find_first();
2419 if (VolatileVFReg < BVAllocatable.
size()) {
2420 CS.setDstReg(VolatileVFReg);
2421 LastVSRUsedForSpill = VolatileVFReg;
2423 AllSpilledToReg =
false;
2426 return AllSpilledToReg;
2438 bool CRSpilled =
false;
2442 VSRContainingGPRs.clear();
2447 if (Info.isSpilledToReg()) {
2448 auto &SpilledVSR = VSRContainingGPRs[Info.getDstReg()];
2449 assert(SpilledVSR.second == 0 &&
2450 "Can't spill more than two GPRs into VSR!");
2451 if (SpilledVSR.first == 0)
2452 SpilledVSR.first = Info.getReg();
2454 SpilledVSR.second = Info.getReg();
2462 bool IsCRField = PPC::CR2 <= Reg && Reg <= PPC::CR4;
2470 bool IsLiveIn =
MRI.isLiveIn(Reg);
2474 if (CRSpilled && IsCRField) {
2480 if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
2486 if (!Subtarget.is32BitELFABI()) {
2498 MBB.insert(
MI, CRMIB);
2505 if (
I.isSpilledToReg()) {
2506 unsigned Dst =
I.getDstReg();
2511 const auto &VSR = VSRContainingGPRs[Dst];
2512 if (VSR.second != 0) {
2513 assert(Subtarget.hasP9Vector() &&
2514 "mtvsrdd is unavailable on pre-P9 targets.");
2520 }
else if (VSR.second == 0) {
2521 assert(Subtarget.hasP8Vector() &&
2522 "Can't move GPR to VSR on pre-P8 targets.");
2526 TRI->getSubReg(Dst, PPC::sub_64))
2539 if (Subtarget.needsSwapsForVSXMemOps() &&
2541 TII.storeRegToStackSlotNoUpd(
MBB,
MI, Reg, !IsLiveIn,
I.getFrameIdx(),
2544 TII.storeRegToStackSlot(
MBB,
MI, Reg, !IsLiveIn,
I.getFrameIdx(), RC,
2552static void restoreCRs(
bool is31,
bool CR2Spilled,
bool CR3Spilled,
2560 unsigned MoveReg = PPC::R12;
2565 CSI[CSIIndex].getFrameIdx()));
2568 (CR2Spilled ? 1 : 0) + (CR3Spilled ? 1 : 0) + (CR4Spilled ? 1 : 0);
2571 "Requires at least one non-volatile CR field to be restored.");
2575 unsigned CRReg = CR2Spilled ? PPC::CR2 : (CR3Spilled ? PPC::CR3 : PPC::CR4);
2580 unsigned CRMask = 0;
2597 MBB.insert(
MI, MIB);
2606 I->getOpcode() == PPC::ADJCALLSTACKUP) {
2608 if (
int CalleeAmt =
I->getOperand(1).getImm()) {
2609 bool is64Bit = Subtarget.isPPC64();
2611 unsigned StackReg =
is64Bit ? PPC::X1 : PPC::R1;
2612 unsigned TmpReg =
is64Bit ? PPC::X0 : PPC::R0;
2613 unsigned ADDIInstr =
is64Bit ? PPC::ADDI8 : PPC::ADDI;
2614 unsigned ADDInstr =
is64Bit ? PPC::ADD8 : PPC::ADD4;
2615 unsigned LISInstr =
is64Bit ? PPC::LIS8 : PPC::LIS;
2616 unsigned ORIInstr =
is64Bit ? PPC::ORI8 : PPC::ORI;
2626 .
addImm(CalleeAmt >> 16);
2629 .
addImm(CalleeAmt & 0xFFFF);
2637 return MBB.erase(
I);
2641 return PPC::CR2 ==
Reg ||
Reg == PPC::CR3 ||
Reg == PPC::CR4;
2651 bool CR2Spilled =
false;
2652 bool CR3Spilled =
false;
2653 bool CR4Spilled =
false;
2654 unsigned CSIIndex = 0;
2660 bool AtStart =
I ==
MBB.begin();
2665 for (
unsigned i = 0, e = CSI.
size(); i != e; ++i) {
2668 if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
2676 if (Reg == PPC::CR2) {
2682 }
else if (Reg == PPC::CR3) {
2685 }
else if (Reg == PPC::CR4) {
2691 if (CR2Spilled || CR3Spilled || CR4Spilled) {
2693 restoreCRs(is31, CR2Spilled, CR3Spilled, CR4Spilled,
MBB,
I, CSI,
2695 CR2Spilled = CR3Spilled = CR4Spilled =
false;
2698 if (CSI[i].isSpilledToReg()) {
2700 unsigned Dst = CSI[i].getDstReg();
2705 const auto &VSR = VSRContainingGPRs[Dst];
2706 if (VSR.second != 0) {
2707 assert(Subtarget.hasP9Vector());
2708 NumPEReloadVSR += 2;
2712 }
else if (VSR.second == 0) {
2713 assert(Subtarget.hasP8Vector());
2729 if (Subtarget.needsSwapsForVSXMemOps() &&
2731 TII.loadRegFromStackSlotNoUpd(
MBB,
I, Reg, CSI[i].getFrameIdx(), RC);
2733 TII.loadRegFromStackSlot(
MBB,
I, Reg, CSI[i].getFrameIdx(), RC,
2737 "loadRegFromStackSlot didn't insert any code!");
2751 if (CR2Spilled || CR3Spilled || CR4Spilled) {
2752 assert(Subtarget.is32BitELFABI() &&
2753 "Only set CR[2|3|4]Spilled on 32-bit SVR4.");
2755 restoreCRs(is31, CR2Spilled, CR3Spilled, CR4Spilled,
MBB,
I, CSI, CSIIndex);
2762 return TOCSaveOffset;
2766 return FramePointerSaveOffset;
2770 return BasePointerSaveOffset;
2788 assert(Subtarget.isAIXABI() &&
2789 "Function updateCalleeSaves should only be called for AIX.");
2792 if (SavedRegs.
none())
2796 Subtarget.getRegisterInfo()->getCalleeSavedRegs(&MF);
2806 for (
int i = 0; CSRegs[i]; i++) {
2810 if (!SavedRegs.
test(Cand))
2815 if (Cand == PPC::X2 || Cand == PPC::R2) {
2816 SavedRegs.
set(Cand);
2820 if (PPC::GPRCRegClass.
contains(Cand) && Cand < LowestGPR)
2822 else if (PPC::G8RCRegClass.
contains(Cand) && Cand < LowestG8R)
2824 else if ((PPC::F4RCRegClass.
contains(Cand) ||
2825 PPC::F8RCRegClass.
contains(Cand)) &&
2828 else if (PPC::VRRCRegClass.
contains(Cand) && Cand < LowestVR)
2832 for (
int i = 0; CSRegs[i]; i++) {
2834 if ((PPC::GPRCRegClass.
contains(Cand) && Cand > LowestGPR) ||
2835 (PPC::G8RCRegClass.
contains(Cand) && Cand > LowestG8R) ||
2836 ((PPC::F4RCRegClass.
contains(Cand) ||
2837 PPC::F8RCRegClass.
contains(Cand)) &&
2838 Cand > LowestFPR) ||
2839 (PPC::VRRCRegClass.
contains(Cand) && Cand > LowestVR))
2840 SavedRegs.
set(Cand);
2852 if (Subtarget.isPPC64())
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
const HexagonInstrInfo * TII
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static bool MustSaveLR(const MachineFunction &MF, MCRegister LR)
MustSaveLR - Return true if this function requires that we save the LR register onto the stack in the...
static bool hasSpills(const MachineFunction &MF)
static unsigned computeCRSaveOffset(const PPCSubtarget &STI)
static void restoreCRs(bool is31, bool CR2Spilled, bool CR3Spilled, bool CR4Spilled, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, unsigned CSIIndex)
static unsigned computeReturnSaveOffset(const PPCSubtarget &STI)
#define CALLEE_SAVED_FPRS
#define CALLEE_SAVED_GPRS32
#define CALLEE_SAVED_GPRS64
static unsigned computeLinkageSize(const PPCSubtarget &STI)
static unsigned computeFramePointerSaveOffset(const PPCSubtarget &STI)
static bool isCalleeSavedCR(unsigned Reg)
static unsigned computeTOCSaveOffset(const PPCSubtarget &STI)
static bool hasNonRISpills(const MachineFunction &MF)
static bool spillsCR(const MachineFunction &MF)
static unsigned computeBasePointerSaveOffset(const PPCSubtarget &STI)
static constexpr MCPhysReg FPReg
static constexpr MCPhysReg SPReg
MachineRegisterInfo & MRI
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static void buildDefCFAReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned Reg, const SystemZInstrInfo *ZII)
static bool is64Bit(const char *name)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
LLVM Basic Block Representation.
bool test(unsigned Idx) const
Returns true if bit Idx is set.
BitVector & reset()
Reset all bits in the bitvector.
int find_first() const
Returns the index of the first set bit, -1 if none of the bits are set.
size_type count() const
Returns the number of bits which are set.
BitVector & set()
Set all bits in the bitvector.
int find_next(unsigned Prev) const
Returns the index of the next set bit following the "Prev" bit.
bool none() const
Returns true if none of the bits are set.
iterator_range< const_set_bits_iterator > set_bits() const
size_type size() const
Returns the number of bits in this bitvector.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
An instruction for reading from memory.
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2, SMLoc Loc={})
.cfi_register Previous value of Register1 is saved in register Register2.
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
const MCRegisterInfo * getRegisterInfo() const
Describe properties that are true of each instruction in the target description file.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
LLVM_ABI iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
void setMaxCallFrameSize(uint64_t S)
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
bool hasCalls() const
Return true if the current function has any function calls.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Align getMaxAlign() const
Return alignment of this function's frame.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
bool hasTailCall() const
Returns true if the function contains a tail call.
bool hasStackMap() const
This method may be called any time after instruction selection is complete to determine if there is a...
LLVM_ABI int CreateSpillStackObject(uint64_t Size, Align Alignment, TargetStackID::Value StackID=TargetStackID::Default)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
const SaveRestorePoints & getRestorePoints() const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
void setStackSize(uint64_t Size)
Set the size of the stack.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
const SaveRestorePoints & getSavePoints() const
unsigned addFrameInst(const MCCFIInstruction &Inst)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
bool needsFrameMoves() const
True if this function needs frame moves for debug or exceptions.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
bool disableFramePointerElim() const
Returns true if frame pointer elimination should be disabled for this function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
const char * getSymbolName() const
int64_t getOffset() const
Return the offset from the symbol in this operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
def_iterator def_begin(Register RegNo) const
defusechain_iterator< false, true, false, true, false > def_iterator
def_iterator/def_begin/def_end - Walk all defs of the specified register.
static def_iterator def_end()
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
uint64_t getReturnSaveOffset() const
getReturnSaveOffset - Return the previous frame offset to save the return address.
bool needsFP(const MachineFunction &MF) const
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
uint64_t getStackThreshold() const override
getStackThreshold - Return the maximum stack size
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
bool hasFPImpl(const MachineFunction &MF) const override
uint64_t getFramePointerSaveOffset() const
getFramePointerSaveOffset - Return the previous frame offset to save the frame pointer.
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
unsigned getLinkageSize() const
getLinkageSize - Return the size of the PowerPC ABI linkage area.
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Methods used by shrink wrapping to determine if MBB can be used for the function prologue/epilogue.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
void replaceFPWithRealFP(MachineFunction &MF) const
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
uint64_t determineFrameLayout(const MachineFunction &MF, bool UseEstimate=false, unsigned *NewMaxCallFrameSize=nullptr) const
Determine the frame layout but do not update the machine function.
void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const
PPCFrameLowering(const PPCSubtarget &STI)
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
This function will assign callee saved gprs to volatile vector registers for prologue spills when app...
uint64_t determineFrameLayoutAndUpdate(MachineFunction &MF, bool UseEstimate=false) const
Determine the frame layout and update the machine function.
void updateCalleeSaves(const MachineFunction &MF, BitVector &SavedRegs) const
void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe stub (if any) with the actual probe code inline.
uint64_t getTOCSaveOffset() const
getTOCSaveOffset - Return the previous frame offset to save the TOC register – 64-bit SVR4 ABI only.
uint64_t getBasePointerSaveOffset() const
getBasePointerSaveOffset - Return the previous frame offset to save the base pointer.
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
int getTailCallSPDelta() const
const SmallVectorImpl< Register > & getMustSaveCRs() const
int getPICBasePointerSaveIndex() const
bool shrinkWrapDisabled() const
int getFramePointerSaveIndex() const
void addMustSaveCR(Register Reg)
void setBasePointerSaveIndex(int Idx)
bool hasNonRISpills() const
bool isLRStoreRequired() const
void setPICBasePointerSaveIndex(int Idx)
int getROPProtectionHashSaveIndex() const
unsigned getMinReservedArea() const
void setMustSaveLR(bool U)
MustSaveLR - This is set when the prolog/epilog inserter does its initial scan of the function.
void setCRSpillFrameIndex(int idx)
int getBasePointerSaveIndex() const
void setFramePointerSaveIndex(int Idx)
bool hasBasePointer(const MachineFunction &MF) const
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
bool is32BitELFABI() const
const PPCTargetMachine & getTargetMachine() const
Wrapper class representing virtual and physical registers.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
virtual uint64_t getStackThreshold() const
getStackThreshold - Return the maximum stack size
TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
virtual bool hasInlineStackProbe(const MachineFunction &MF) const
bool isPositionIndependent() const
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ Fast
Attempts to make calls as fast as possible (e.g.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Kill
The last use of a register.
constexpr RegState getKillRegState(bool B)
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0, bool mem=true)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
unsigned Log2(Align A)
Returns the log2 of the alignment.
void fullyRecomputeLiveIns(ArrayRef< MachineBasicBlock * > MBBs)
Convenience function for recomputing live-in's for a set of MBBs until the computation converges.
MCRegisterClass TargetRegisterClass
This struct is a compact representation of a valid (non-zero power of two) alignment.