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 cl::desc(
"Enable spills in prologue to vector registers."),
45 return STI.isPPC64() ? 16 : 8;
47 return STI.isPPC64() ? 16 : 4;
52 return STI.isPPC64() ? 40 : 20;
58 return STI.isPPC64() ? -8U : -4U;
63 return (STI.
isELFv2ABI() ? 4 : 6) * (STI.isPPC64() ? 8 : 4);
75 return STI.isPPC64() ? -16U : -8U;
79 return (STI.
isAIXABI() && !STI.isPPC64()) ? 4 : 8;
84 STI.getPlatformStackAlignment(), 0),
94 unsigned &NumEntries)
const {
97#define CALLEE_SAVED_FPRS \
119#define CALLEE_SAVED_GPRS32 \
140#define CALLEE_SAVED_GPRS64 \
161#define CALLEE_SAVED_VRS \
178 static const SpillSlot ELFOffsets32[] = {
213 static const SpillSlot ELFOffsets64[] = {
228 static const SpillSlot AIXOffsets64[] = {
231 if (Subtarget.is64BitELFABI()) {
232 NumEntries = std::size(ELFOffsets64);
236 if (Subtarget.is32BitELFABI()) {
237 NumEntries = std::size(ELFOffsets32);
241 assert(Subtarget.isAIXABI() &&
"Unexpected ABI.");
243 if (Subtarget.isPPC64()) {
244 NumEntries = std::size(AIXOffsets64);
248 NumEntries = std::size(AIXOffsets32);
285 bool UseEstimate)
const {
286 unsigned NewMaxCallFrameSize = 0;
288 &NewMaxCallFrameSize);
299 unsigned *NewMaxCallFrameSize)
const {
310 Align Alignment = std::max(TargetAlign, MaxAlign);
320 !RegInfo->hasBasePointer(MF) &&
325 bool FitsInRedZone = FrameSize <= Subtarget.getRedZoneSize();
328 if (!DisableRedZone && CanUseRedZone && FitsInRedZone) {
338 maxCallFrameSize = std::max(maxCallFrameSize, minCallFrameSize);
343 maxCallFrameSize =
alignTo(maxCallFrameSize, Alignment);
346 if (NewMaxCallFrameSize)
347 *NewMaxCallFrameSize = maxCallFrameSize;
350 FrameSize += maxCallFrameSize;
353 FrameSize =
alignTo(FrameSize, Alignment);
390 unsigned FPReg = is31 ? PPC::R31 : PPC::R1;
391 unsigned FP8Reg = is31 ? PPC::X31 : PPC::X1;
395 unsigned BPReg = HasBP ? (
unsigned) RegInfo->getBaseRegister(MF) :
FPReg;
396 unsigned BP8Reg = HasBP ? (
unsigned) PPC::X30 : FP8Reg;
405 switch (MO.getReg()) {
443 bool TwoUniqueRegsRequired,
455 assert (SR1 &&
"Asking for the second scratch register but not the first?");
460 if ((UseAtEnd &&
MBB->isReturnBlock()) ||
461 (!UseAtEnd && (&
MBB->getParent()->front() ==
MBB)))
469 RS.enterBasicBlock(*
MBB);
471 RS.enterBasicBlockEnd(*
MBB);
476 RS.enterBasicBlock(*
MBB);
483 if (!
RS.isRegUsed(R0) && !
RS.isRegUsed(R12))
487 const PPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
491 BitVector BV =
RS.getRegsAvailable(Subtarget.isPPC64() ? &PPC::G8RCRegClass :
498 for (
int i = 0; CSRegs[i]; ++i)
504 *SR1 = FirstScratchReg == -1 ? (unsigned)PPC::NoRegister : FirstScratchReg;
511 int SecondScratchReg = BV.
find_next(*SR1);
512 if (SecondScratchReg != -1)
513 *SR2 = SecondScratchReg;
515 *SR2 = TwoUniqueRegsRequired ?
Register() : *SR1;
520 if (BV.
count() < (TwoUniqueRegsRequired ? 2U : 1U))
535 const PPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();
539 int NegFrameSize = -FrameSize;
540 bool IsLargeFrame = !
isInt<16>(NegFrameSize);
543 bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
544 const PPCTargetLowering &
TLI = *Subtarget.getTargetLowering();
546 return ((IsLargeFrame || !HasRedZone) && HasBP && MaxAlign > 1) ||
553 return findScratchRegister(TmpMBB,
false,
554 twoUniqueScratchRegsRequired(TmpMBB));
560 return findScratchRegister(TmpMBB,
true);
563bool PPCFrameLowering::stackUpdateCanBeMoved(
MachineFunction &MF)
const {
584 if (!FrameSize || FrameSize >
Subtarget.getRedZoneSize())
604 return !RegInfo->requiresFrameIndexScavenging(MF);
620 const bool HasFastMFLR = Subtarget.hasFastMFLR();
623 bool isPPC64 = Subtarget.isPPC64();
625 bool isSVR4ABI = Subtarget.isSVR4ABI();
626 bool isELFv2ABI = Subtarget.isELFv2ABI();
627 assert((isSVR4ABI || Subtarget.isAIXABI()) &&
"Unsupported PPC ABI.");
631 int64_t NegFrameSize = -FrameSize;
643 bool MustSaveCR = !MustSaveCRs.
empty();
645 bool HasFP =
hasFP(MF);
646 bool HasBP = RegInfo->hasBasePointer(MF);
647 bool HasRedZone = isPPC64 || !isSVR4ABI;
648 const bool HasROPProtect = Subtarget.hasROPProtect();
649 bool HasPrivileged = Subtarget.hasPrivileged();
652 Register BPReg = RegInfo->getBaseRegister(MF);
654 Register LRReg = isPPC64 ? PPC::LR8 : PPC::LR;
655 Register TOCReg = isPPC64 ? PPC::X2 : PPC::R2;
657 Register TempReg = isPPC64 ? PPC::X12 : PPC::R12;
665 const MCInstrDesc& StoreUpdtIdxInst =
TII.get(isPPC64 ? PPC::STDUX
669 const MCInstrDesc& SubtractCarryingInst =
TII.get(isPPC64 ? PPC::SUBFC8
671 const MCInstrDesc& SubtractImmCarryingInst =
TII.get(isPPC64 ? PPC::SUBFIC8
673 const MCInstrDesc &MoveFromCondRegInst =
TII.get(isPPC64 ? PPC::MFCR8
675 const MCInstrDesc &StoreWordInst =
TII.get(isPPC64 ? PPC::STW8 : PPC::STW);
677 TII.get(isPPC64 ? (HasPrivileged ? PPC::HASHSTP8 : PPC::HASHST8)
678 : (HasPrivileged ? PPC::HASHSTP : PPC::HASHST));
685 "FrameSize must be >0 to save/restore the FP or LR for 32-bit SVR4.");
688 bool SingleScratchReg = findScratchRegister(
689 &
MBB,
false, twoUniqueScratchRegsRequired(&
MBB), &ScratchReg, &TempReg);
690 assert(SingleScratchReg &&
691 "Required number of registers not available in this block");
693 SingleScratchReg = ScratchReg == TempReg;
697 int64_t FPOffset = 0;
701 assert(FPIndex &&
"No Frame Pointer Save Slot!");
705 int64_t BPOffset = 0;
709 assert(BPIndex &&
"No Base Pointer Save Slot!");
713 int64_t PBPOffset = 0;
717 assert(PBPIndex &&
"No PIC Base Pointer Save Slot!");
723 if (HasBP && MaxAlign > 1)
724 assert(
Log2(MaxAlign) < 16 &&
"Invalid alignment!");
728 bool isLargeFrame = !
isInt<16>(NegFrameSize);
734 bool MovingStackUpdateDown =
false;
737 if (stackUpdateCanBeMoved(MF)) {
750 if (CSI.isSpilledToReg()) {
751 StackUpdateLoc =
MBBI;
752 MovingStackUpdateDown =
false;
756 int FrIdx = CSI.getFrameIdx();
765 MovingStackUpdateDown =
true;
769 StackUpdateLoc =
MBBI;
770 MovingStackUpdateDown =
false;
776 if (MovingStackUpdateDown) {
778 int FrIdx = CSI.getFrameIdx();
788 auto BuildMoveFromCR = [&]() {
789 if (isELFv2ABI && MustSaveCRs.
size() == 1) {
794 assert(isPPC64 &&
"V2 ABI is 64-bit only.");
801 for (
unsigned CRfield : MustSaveCRs)
808 if (MustSaveCR && SingleScratchReg &&
MustSaveLR) {
819 if (MustSaveCR && !(SingleScratchReg &&
MustSaveLR))
843 auto SaveLR = [&](int64_t
Offset) {
859 assert((ImmOffset <= -8 && ImmOffset >= -512) &&
860 "ROP hash save offset out of range.");
861 assert(((ImmOffset & 0x7) == 0) &&
862 "ROP hash save offset must be 8 byte aligned.");
875 assert(HasRedZone &&
"A red zone is always available on PPC64");
892 if (HasBP && HasRedZone) {
902 (
TLI.hasInlineStackProbe(MF) && FrameSize >
TLI.getStackProbeSize(MF)) ||
903 (HasBP && MaxAlign > 1) || isLargeFrame;
913 (HasSTUX || !
isInt<16>(FrameSize + LROffset) || HasROPProtect))
919 if (
TLI.hasInlineStackProbe(MF) && FrameSize >
TLI.getStackProbeSize(MF)) {
923 TII.get(isPPC64 ? PPC::PROBED_STACKALLOC_64
924 : PPC::PROBED_STACKALLOC_32))
938 if (HasBP && MaxAlign > 1) {
955 assert(!SingleScratchReg &&
"Only a single scratch reg available");
956 TII.materializeImmPostRA(
MBB,
MBBI, dl, TempReg, NegFrameSize);
966 }
else if (!isLargeFrame) {
972 TII.materializeImmPostRA(
MBB,
MBBI, dl, ScratchReg, NegFrameSize);
983 assert(isELFv2ABI &&
"TOC saves in the prologue only supported on ELFv2");
991 assert(!isPPC64 &&
"A red zone is always available on PPC64");
1007 if (ScratchReg == PPC::R0) {
1016 .
addImm(FPOffset-LastOffset);
1017 LastOffset = FPOffset;
1028 .
addImm(PBPOffset-LastOffset);
1029 LastOffset = PBPOffset;
1039 .
addImm(BPOffset-LastOffset);
1040 LastOffset = BPOffset;
1084 .
addImm(FrameSize + FPOffset)
1089 .
addImm(FrameSize + PBPOffset)
1094 .
addImm(FrameSize + BPOffset)
1104 if (!HasSTUX &&
MustSaveLR && !HasFastMFLR &&
1105 isInt<16>(FrameSize + LROffset) && !HasROPProtect)
1106 SaveLR(LROffset + FrameSize);
1116 unsigned Reg =
MRI->getDwarfRegNum(BPReg,
true);
1130 unsigned Reg =
MRI->getDwarfRegNum(
FPReg,
true);
1139 unsigned Reg =
MRI->getDwarfRegNum(PPC::R30,
true);
1148 unsigned Reg =
MRI->getDwarfRegNum(BPReg,
true);
1157 unsigned Reg =
MRI->getDwarfRegNum(LRReg,
true);
1171 if (!HasBP && needsCFI) {
1174 unsigned Reg =
MRI->getDwarfRegNum(
FPReg,
true);
1189 if (Reg == PPC::LR || Reg == PPC::LR8 || Reg == PPC::RM)
continue;
1193 if (PPC::CRBITRCRegClass.
contains(Reg))
1196 if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
1201 if (isSVR4ABI && isPPC64 && (PPC::CR2 <= Reg && Reg <= PPC::CR4)) {
1205 Register CRReg = isELFv2ABI? Reg : PPC::CR2;
1207 nullptr,
MRI->getDwarfRegNum(CRReg,
true), CRSaveOffset));
1213 if (
I.isSpilledToReg()) {
1214 unsigned SpilledReg =
I.getDstReg();
1216 nullptr,
MRI->getDwarfRegNum(Reg,
true),
1217 MRI->getDwarfRegNum(SpilledReg,
true)));
1225 if (MovingStackUpdateDown)
1229 nullptr,
MRI->getDwarfRegNum(Reg,
true),
Offset));
1239 bool isPPC64 = Subtarget.isPPC64();
1247 int Opc =
MI.getOpcode();
1248 return Opc == PPC::PROBED_STACKALLOC_64 ||
Opc == PPC::PROBED_STACKALLOC_32;
1250 if (StackAllocMIPos == PrologMBB.
end())
1256 int64_t NegFrameSize =
MI.getOperand(2).getImm();
1257 unsigned ProbeSize =
TLI.getStackProbeSize(MF);
1258 int64_t NegProbeSize = -(int64_t)ProbeSize;
1260 int64_t NumBlocks = NegFrameSize / NegProbeSize;
1261 int64_t NegResidualSize = NegFrameSize % NegProbeSize;
1263 Register ScratchReg =
MI.getOperand(0).getReg();
1266 bool HasBP = RegInfo->hasBasePointer(MF);
1267 Register BPReg = RegInfo->getBaseRegister(MF);
1269 bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
1270 const MCInstrDesc &CopyInst =
TII.get(isPPC64 ? PPC::OR8 : PPC::OR);
1274 unsigned RegNum =
MRI->getDwarfRegNum(Reg,
true);
1283 unsigned RegNum =
MRI->getDwarfRegNum(Reg,
true);
1284 unsigned CFIIndex =
MBB.getParent()->addFrameInst(
1310 Register NegSizeReg,
bool UseDForm,
1352 assert(HasBP &&
"The function is supposed to have base pointer when its "
1353 "stack is realigned.");
1360 assert(ProbeSize >= Subtarget.getRedZoneSize() &&
1361 "Probe size should be larger or equal to the size of red-zone so "
1362 "that red-zone is not clobbered by probing.");
1368 NegProbeSize = std::max(NegProbeSize, -((int64_t)1 << 15));
1370 "NegProbeSize should be materializable by DForm");
1387 MF.
insert(MBBInsertPoint, ProbeLoopBodyMBB);
1389 MF.
insert(MBBInsertPoint, ProbeExitMBB);
1392 Register BackChainPointer = HasRedZone ? BPReg : TempReg;
1393 allocateAndProbe(*ProbeExitMBB, ProbeExitMBB->
end(), 0, ScratchReg,
false,
1398 BuildMI(*ProbeExitMBB, ProbeExitMBB->
end(),
DL, CopyInst, TempReg)
1406 BuildMI(&
MBB,
DL,
TII.get(isPPC64 ? PPC::SUBF8 : PPC::SUBF), ScratchReg)
1418 MBB.addSuccessor(ProbeLoopBodyMBB);
1419 MBB.addSuccessor(ProbeExitMBB);
1423 Register BackChainPointer = HasRedZone ? BPReg : TempReg;
1424 allocateAndProbe(*ProbeLoopBodyMBB, ProbeLoopBodyMBB->
end(), NegProbeSize,
1425 0,
true , BackChainPointer);
1426 BuildMI(ProbeLoopBodyMBB,
DL,
TII.get(isPPC64 ? PPC::ADDI8 : PPC::ADDI),
1430 BuildMI(ProbeLoopBodyMBB,
DL,
TII.get(isPPC64 ? PPC::CMPDI : PPC::CMPWI),
1437 .
addMBB(ProbeLoopBodyMBB);
1443 return ProbeExitMBB;
1448 if (HasBP && MaxAlign > 1) {
1461 BuildMI(*CurrentMBB, {
MI},
DL,
TII.get(isPPC64 ? PPC::SUBF8 : PPC::SUBF),
1465 MaterializeImm(*CurrentMBB, {
MI}, NegFrameSize, ScratchReg);
1466 BuildMI(*CurrentMBB, {
MI},
DL,
TII.get(isPPC64 ? PPC::ADD8 : PPC::ADD4),
1470 CurrentMBB = probeRealignedStack(*CurrentMBB, {
MI}, ScratchReg,
FPReg);
1478 buildDefCFA(*CurrentMBB, {
MI},
FPReg, 0);
1480 if (NegResidualSize) {
1481 bool ResidualUseDForm = CanUseDForm(NegResidualSize);
1482 if (!ResidualUseDForm)
1483 MaterializeImm(*CurrentMBB, {
MI}, NegResidualSize, ScratchReg);
1484 allocateAndProbe(*CurrentMBB, {
MI}, NegResidualSize, ScratchReg,
1485 ResidualUseDForm,
FPReg);
1487 bool UseDForm = CanUseDForm(NegProbeSize);
1489 if (NumBlocks < 3) {
1491 MaterializeImm(*CurrentMBB, {
MI}, NegProbeSize, ScratchReg);
1492 for (
int i = 0; i < NumBlocks; ++i)
1493 allocateAndProbe(*CurrentMBB, {
MI}, NegProbeSize, ScratchReg, UseDForm,
1504 MaterializeImm(*CurrentMBB, {
MI}, NumBlocks, ScratchReg);
1505 BuildMI(*CurrentMBB, {
MI},
DL,
TII.get(isPPC64 ? PPC::MTCTR8 : PPC::MTCTR))
1508 MaterializeImm(*CurrentMBB, {
MI}, NegProbeSize, ScratchReg);
1513 MF.
insert(MBBInsertPoint, LoopMBB);
1515 MF.
insert(MBBInsertPoint, ExitMBB);
1517 allocateAndProbe(*LoopMBB, LoopMBB->
end(), NegProbeSize, ScratchReg,
1519 BuildMI(LoopMBB,
DL,
TII.get(isPPC64 ? PPC::BDNZ8 : PPC::BDNZ))
1524 ExitMBB->
splice(ExitMBB->
end(), CurrentMBB,
1538 MI.eraseFromParent();
1547 dl =
MBBI->getDebugLoc();
1559 bool isPPC64 = Subtarget.isPPC64();
1565 bool MustSaveCR = !MustSaveCRs.
empty();
1567 bool HasFP =
hasFP(MF);
1568 bool HasBP = RegInfo->hasBasePointer(MF);
1569 bool HasRedZone = Subtarget.isPPC64() || !Subtarget.isSVR4ABI();
1570 bool HasROPProtect = Subtarget.hasROPProtect();
1571 bool HasPrivileged = Subtarget.hasPrivileged();
1574 Register BPReg = RegInfo->getBaseRegister(MF);
1577 Register TempReg = isPPC64 ? PPC::X12 : PPC::R12;
1582 const MCInstrDesc& LoadImmShiftedInst =
TII.get( isPPC64 ? PPC::LIS8
1594 const MCInstrDesc& MoveToCRInst =
TII.get( isPPC64 ? PPC::MTOCRF8
1597 TII.get(isPPC64 ? (HasPrivileged ? PPC::HASHCHKP8 : PPC::HASHCHK8)
1598 : (HasPrivileged ? PPC::HASHCHKP : PPC::HASHCHK));
1601 int64_t FPOffset = 0;
1604 bool SingleScratchReg = findScratchRegister(&
MBB,
true,
false, &ScratchReg,
1606 assert(SingleScratchReg &&
1607 "Could not find an available scratch register");
1609 SingleScratchReg = ScratchReg == TempReg;
1613 assert(FPIndex &&
"No Frame Pointer Save Slot!");
1617 int64_t BPOffset = 0;
1620 assert(BPIndex &&
"No Base Pointer Save Slot!");
1624 int64_t PBPOffset = 0;
1627 assert(PBPIndex &&
"No PIC Base Pointer Save Slot!");
1631 bool IsReturnBlock = (
MBBI !=
MBB.end() &&
MBBI->isReturn());
1633 if (IsReturnBlock) {
1634 unsigned RetOpcode =
MBBI->getOpcode();
1635 bool UsesTCRet = RetOpcode == PPC::TCRETURNri ||
1636 RetOpcode == PPC::TCRETURNdi ||
1637 RetOpcode == PPC::TCRETURNai ||
1638 RetOpcode == PPC::TCRETURNri8 ||
1639 RetOpcode == PPC::TCRETURNdi8 ||
1640 RetOpcode == PPC::TCRETURNai8;
1645 assert(StackAdjust.
isImm() &&
"Expecting immediate value.");
1647 int StackAdj = StackAdjust.
getImm();
1648 int Delta = StackAdj - MaxTCRetDelta;
1649 assert((Delta >= 0) &&
"Delta must be positive");
1650 if (MaxTCRetDelta>0)
1651 FrameSize += (StackAdj +Delta);
1653 FrameSize += StackAdj;
1659 bool isLargeFrame = !
isInt<16>(FrameSize);
1673 unsigned RBReg =
SPReg;
1681 if (stackUpdateCanBeMoved(MF)) {
1686 if (CSI.isSpilledToReg()) {
1687 StackUpdateLoc =
MBBI;
1690 int FrIdx = CSI.getFrameIdx();
1702 StackUpdateLoc =
MBBI;
1715 if (HasRedZone && HasBP) {
1725 assert(HasFP &&
"Expecting a valid frame pointer.");
1728 if (!isLargeFrame) {
1732 TII.materializeImmPostRA(
MBB,
MBBI, dl, ScratchReg, FrameSize);
1746 assert(FPOffset <= 0 && BPOffset <= 0 && PBPOffset <= 0 &&
1747 "Local offsets should be negative");
1749 FPOffset += FrameSize;
1750 BPOffset += FrameSize;
1751 PBPOffset += FrameSize;
1769 assert(RBReg != ScratchReg &&
"Should have avoided ScratchReg");
1774 if (MustSaveCRs.
size() == 1)
1776 BuildMI(
MBB, InsertPt, dl, MoveToCRInst, MustSaveCRs[0])
1780 unsigned CRMask = 0;
1781 for (
unsigned CRField : MustSaveCRs) {
1782 CRMask |= 0x80 >> (CRField - PPC::CR0);
1786 TII.get(isPPC64 ? PPC::MTCRF8 : PPC::MTCRF))
1792 for (
unsigned CRField : MustSaveCRs)
1803 if (MustSaveCR && SingleScratchReg &&
MustSaveLR) {
1806 assert(HasRedZone &&
"Expecting red zone");
1810 BuildMoveToCR(
MBBI, TempReg);
1817 bool LoadedLR =
false;
1825 if (MustSaveCR && !(SingleScratchReg &&
MustSaveLR)) {
1826 assert(RBReg ==
SPReg &&
"Should be using SP as a base register");
1835 if (HasRedZone || RBReg ==
SPReg)
1857 if (RBReg !=
SPReg || SPAdd != 0) {
1858 assert(!HasRedZone &&
"This should not happen with red zone");
1869 assert(RBReg != ScratchReg &&
"Should be using FP or SP as base register");
1884 BuildMoveToCR(
MBBI, TempReg);
1889 if (HasROPProtect) {
1892 assert((ImmOffset <= -8 && ImmOffset >= -512) &&
1893 "ROP hash check location offset out of range.");
1894 assert(((ImmOffset & 0x7) == 0) &&
1895 "ROP hash check location offset must be 8 byte aligned.");
1906 if (IsReturnBlock) {
1907 unsigned RetOpcode =
MBBI->getOpcode();
1909 (RetOpcode == PPC::BLR || RetOpcode == PPC::BLR8) &&
1914 if (CallerAllocatedAmt &&
isInt<16>(CallerAllocatedAmt)) {
1919 .
addImm(CallerAllocatedAmt >> 16);
1922 .
addImm(CallerAllocatedAmt & 0xFFFF);
1929 createTailCallBranchInstr(
MBB);
1938 assert(
MBBI !=
MBB.end() &&
"Failed to find the first terminator.");
1950 unsigned RetOpcode =
MBBI->getOpcode();
1951 if (RetOpcode == PPC::TCRETURNdi) {
1952 MBBI =
MBB.getLastNonDebugInstr();
1962 }
else if (RetOpcode == PPC::TCRETURNri) {
1963 MBBI =
MBB.getLastNonDebugInstr();
1964 assert(
MBBI->getOperand(0).isReg() &&
"Expecting register operand.");
1966 }
else if (RetOpcode == PPC::TCRETURNai) {
1968 MachineOperand &JumpTarget =
MBBI->getOperand(0);
1970 }
else if (RetOpcode == PPC::TCRETURNdi8) {
1972 MachineOperand &JumpTarget =
MBBI->getOperand(0);
1981 }
else if (RetOpcode == PPC::TCRETURNri8) {
1983 assert(
MBBI->getOperand(0).isReg() &&
"Expecting register operand.");
1985 }
else if (RetOpcode == PPC::TCRETURNai8) {
1987 MachineOperand &JumpTarget =
MBBI->getOperand(0);
1996 if (Subtarget.isAIXABI())
2003 SavedRegs.
reset(PPC::VSRp26);
2004 SavedRegs.
reset(PPC::VSRp27);
2005 SavedRegs.
reset(PPC::VSRp28);
2006 SavedRegs.
reset(PPC::VSRp29);
2007 SavedRegs.
reset(PPC::VSRp30);
2008 SavedRegs.
reset(PPC::VSRp31);
2014 SavedRegs.
reset(LR);
2018 const bool isPPC64 = Subtarget.isPPC64();
2032 if (!BPSI && RegInfo->hasBasePointer(MF)) {
2052 SavedRegs.
reset(isPPC64 ? PPC::X31 : PPC::R31);
2053 if (RegInfo->hasBasePointer(MF)) {
2054 SavedRegs.
reset(RegInfo->getBaseRegister(MF));
2057 if (!
needsFP(MF) && !SavedRegs.
test(isPPC64 ? PPC::X31 : PPC::R31) &&
2058 Subtarget.isAIXABI()) {
2060 (RegInfo->getBaseRegister(MF) == (isPPC64 ? PPC::X30 : PPC::R30)) &&
2061 "Invalid base register on AIX!");
2062 SavedRegs.
set(isPPC64 ? PPC::X31 : PPC::R31);
2066 SavedRegs.
reset(PPC::R30);
2081 if ((SavedRegs.
test(PPC::CR2) || SavedRegs.
test(PPC::CR3) ||
2082 SavedRegs.
test(PPC::CR4))) {
2083 const uint64_t SpillSize = 4;
2084 const int64_t SpillOffset =
2085 Subtarget.isPPC64() ? 8 : Subtarget.isAIXABI() ? 4 : -4;
2105 "MFI can't contain multiple restore points!");
2108 createTailCallBranchInstr(
MBB);
2113 if (CSI.empty() && !
needsFP(MF)) {
2118 unsigned MinGPR = PPC::R31;
2119 unsigned MinG8R = PPC::X31;
2120 unsigned MinFPR = PPC::F31;
2121 unsigned MinVR = Subtarget.hasSPE() ? PPC::S31 : PPC::V31;
2123 bool HasGPSaveArea =
false;
2124 bool HasG8SaveArea =
false;
2125 bool HasFPSaveArea =
false;
2126 bool HasVRSaveArea =
false;
2136 (Reg != PPC::X2 && Reg != PPC::R2)) &&
2137 "Not expecting to try to spill R2 in a function that must save TOC");
2138 if (PPC::GPRCRegClass.
contains(Reg)) {
2139 HasGPSaveArea =
true;
2146 }
else if (PPC::G8RCRegClass.
contains(Reg)) {
2147 HasG8SaveArea =
true;
2154 }
else if (PPC::F8RCRegClass.
contains(Reg)) {
2155 HasFPSaveArea =
true;
2162 }
else if (PPC::CRBITRCRegClass.
contains(Reg) ||
2165 }
else if (PPC::VRRCRegClass.
contains(Reg) ||
2166 PPC::SPERCRegClass.
contains(Reg)) {
2169 HasVRSaveArea =
true;
2184 int64_t LowerBound = 0;
2190 LowerBound = TCSPDelta;
2195 if (HasFPSaveArea) {
2197 int FI =
FPReg.getFrameIdx();
2202 LowerBound -= (31 -
TRI->getEncodingValue(MinFPR) + 1) * 8;
2209 assert(FI &&
"No Frame Pointer Save Slot!");
2212 HasGPSaveArea =
true;
2217 assert(FI &&
"No PIC Base Pointer Save Slot!");
2220 MinGPR = std::min<unsigned>(MinGPR, PPC::R30);
2221 HasGPSaveArea =
true;
2225 if (RegInfo->hasBasePointer(MF)) {
2227 assert(FI &&
"No Base Pointer Save Slot!");
2230 Register BP = RegInfo->getBaseRegister(MF);
2231 if (PPC::G8RCRegClass.
contains(BP)) {
2232 MinG8R = std::min<unsigned>(MinG8R, BP);
2233 HasG8SaveArea =
true;
2234 }
else if (PPC::GPRCRegClass.
contains(BP)) {
2235 MinGPR = std::min<unsigned>(MinGPR, BP);
2236 HasGPSaveArea =
true;
2242 if (HasGPSaveArea || HasG8SaveArea) {
2246 if (!GPReg.isSpilledToReg()) {
2247 int FI = GPReg.getFrameIdx();
2255 if (!G8Reg.isSpilledToReg()) {
2256 int FI = G8Reg.getFrameIdx();
2262 std::min<unsigned>(
TRI->getEncodingValue(MinGPR),
2263 TRI->getEncodingValue(MinG8R));
2265 const unsigned GPRegSize = Subtarget.isPPC64() ? 8 : 4;
2266 LowerBound -= (31 - MinReg + 1) * GPRegSize;
2274 if (
spillsCR(MF) && Subtarget.is32BitELFABI()) {
2276 for (
const auto &CSInfo : CSI) {
2277 if (CSInfo.getReg() == PPC::CR2) {
2278 int FI = CSInfo.getFrameIdx();
2289 if (HasVRSaveArea) {
2295 assert(LowerBound <= 0 &&
"Expect LowerBound have a non-positive value!");
2296 LowerBound &= ~(15);
2299 int FI = VReg.getFrameIdx();
2326 bool NeedSpills = Subtarget.hasSPE() ? !
isInt<8>(StackSize) : !
isInt<16>(StackSize);
2334 unsigned Size =
TRI.getSpillSize(RC);
2335 Align Alignment =
TRI.getSpillAlign(RC);
2355 std::vector<CalleeSavedInfo> &CSI)
const {
2361 const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF);
2364 if (Subtarget.hasSPE()) {
2368 for (
auto &CalleeSaveReg : CSI) {
2371 MCRegister Higher = RegInfo->getSubReg(Reg, PPC::sub_32_hi_phony);
2376 !
MRI.isPhysRegModified(Higher))
2389 for (
unsigned i = 0; CSRegs[i]; ++i)
2390 BVCalleeSaved.
set(CSRegs[i]);
2392 for (
unsigned Reg : BVAllocatable.
set_bits()) {
2395 if (BVCalleeSaved[Reg] || !PPC::VSRCRegClass.
contains(Reg) ||
2396 MRI.isPhysRegUsed(Reg))
2397 BVAllocatable.
reset(Reg);
2400 bool AllSpilledToReg =
true;
2401 unsigned LastVSRUsedForSpill = 0;
2402 for (
auto &CS : CSI) {
2403 if (BVAllocatable.
none())
2408 if (!PPC::G8RCRegClass.
contains(Reg)) {
2409 AllSpilledToReg =
false;
2415 if (LastVSRUsedForSpill != 0) {
2416 CS.setDstReg(LastVSRUsedForSpill);
2417 BVAllocatable.
reset(LastVSRUsedForSpill);
2418 LastVSRUsedForSpill = 0;
2422 unsigned VolatileVFReg = BVAllocatable.
find_first();
2423 if (VolatileVFReg < BVAllocatable.
size()) {
2424 CS.setDstReg(VolatileVFReg);
2425 LastVSRUsedForSpill = VolatileVFReg;
2427 AllSpilledToReg =
false;
2430 return AllSpilledToReg;
2442 bool CRSpilled =
false;
2446 VSRContainingGPRs.clear();
2451 if (Info.isSpilledToReg()) {
2452 auto &SpilledVSR = VSRContainingGPRs[Info.getDstReg()];
2453 assert(SpilledVSR.second == 0 &&
2454 "Can't spill more than two GPRs into VSR!");
2455 if (SpilledVSR.first == 0)
2456 SpilledVSR.first = Info.getReg();
2458 SpilledVSR.second = Info.getReg();
2466 bool IsCRField = PPC::CR2 <= Reg && Reg <= PPC::CR4;
2474 bool IsLiveIn =
MRI.isLiveIn(Reg);
2478 if (CRSpilled && IsCRField) {
2484 if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
2490 if (!Subtarget.is32BitELFABI()) {
2502 MBB.insert(
MI, CRMIB);
2509 if (
I.isSpilledToReg()) {
2510 unsigned Dst =
I.getDstReg();
2515 const auto &VSR = VSRContainingGPRs[Dst];
2516 if (VSR.second != 0) {
2517 assert(Subtarget.hasP9Vector() &&
2518 "mtvsrdd is unavailable on pre-P9 targets.");
2524 }
else if (VSR.second == 0) {
2525 assert(Subtarget.hasP8Vector() &&
2526 "Can't move GPR to VSR on pre-P8 targets.");
2530 TRI->getSubReg(Dst, PPC::sub_64))
2543 if (Subtarget.needsSwapsForVSXMemOps() &&
2545 TII.storeRegToStackSlotNoUpd(
MBB,
MI, Reg, !IsLiveIn,
I.getFrameIdx(),
2548 TII.storeRegToStackSlot(
MBB,
MI, Reg, !IsLiveIn,
I.getFrameIdx(), RC,
2556static void restoreCRs(
bool is31,
bool CR2Spilled,
bool CR3Spilled,
2564 unsigned MoveReg = PPC::R12;
2569 CSI[CSIIndex].getFrameIdx()));
2572 (CR2Spilled ? 1 : 0) + (CR3Spilled ? 1 : 0) + (CR4Spilled ? 1 : 0);
2575 "Requires at least one non-volatile CR field to be restored.");
2579 unsigned CRReg = CR2Spilled ? PPC::CR2 : (CR3Spilled ? PPC::CR3 : PPC::CR4);
2584 unsigned CRMask = 0;
2601 MBB.insert(
MI, MIB);
2610 I->getOpcode() == PPC::ADJCALLSTACKUP) {
2612 if (
int CalleeAmt =
I->getOperand(1).getImm()) {
2613 bool is64Bit = Subtarget.isPPC64();
2615 unsigned StackReg =
is64Bit ? PPC::X1 : PPC::R1;
2616 unsigned TmpReg =
is64Bit ? PPC::X0 : PPC::R0;
2617 unsigned ADDIInstr =
is64Bit ? PPC::ADDI8 : PPC::ADDI;
2618 unsigned ADDInstr =
is64Bit ? PPC::ADD8 : PPC::ADD4;
2619 unsigned LISInstr =
is64Bit ? PPC::LIS8 : PPC::LIS;
2620 unsigned ORIInstr =
is64Bit ? PPC::ORI8 : PPC::ORI;
2630 .
addImm(CalleeAmt >> 16);
2633 .
addImm(CalleeAmt & 0xFFFF);
2641 return MBB.erase(
I);
2645 return PPC::CR2 ==
Reg ||
Reg == PPC::CR3 ||
Reg == PPC::CR4;
2655 bool CR2Spilled =
false;
2656 bool CR3Spilled =
false;
2657 bool CR4Spilled =
false;
2658 unsigned CSIIndex = 0;
2664 bool AtStart =
I ==
MBB.begin();
2669 for (
unsigned i = 0, e = CSI.
size(); i != e; ++i) {
2672 if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
2680 if (Reg == PPC::CR2) {
2686 }
else if (Reg == PPC::CR3) {
2689 }
else if (Reg == PPC::CR4) {
2695 if (CR2Spilled || CR3Spilled || CR4Spilled) {
2697 restoreCRs(is31, CR2Spilled, CR3Spilled, CR4Spilled,
MBB,
I, CSI,
2699 CR2Spilled = CR3Spilled = CR4Spilled =
false;
2702 if (CSI[i].isSpilledToReg()) {
2704 unsigned Dst = CSI[i].getDstReg();
2709 const auto &VSR = VSRContainingGPRs[Dst];
2710 if (VSR.second != 0) {
2711 assert(Subtarget.hasP9Vector());
2712 NumPEReloadVSR += 2;
2716 }
else if (VSR.second == 0) {
2717 assert(Subtarget.hasP8Vector());
2733 if (Subtarget.needsSwapsForVSXMemOps() &&
2735 TII.loadRegFromStackSlotNoUpd(
MBB,
I, Reg, CSI[i].getFrameIdx(), RC);
2737 TII.loadRegFromStackSlot(
MBB,
I, Reg, CSI[i].getFrameIdx(), RC,
2741 "loadRegFromStackSlot didn't insert any code!");
2755 if (CR2Spilled || CR3Spilled || CR4Spilled) {
2756 assert(Subtarget.is32BitELFABI() &&
2757 "Only set CR[2|3|4]Spilled on 32-bit SVR4.");
2759 restoreCRs(is31, CR2Spilled, CR3Spilled, CR4Spilled,
MBB,
I, CSI, CSIIndex);
2766 return TOCSaveOffset;
2770 return FramePointerSaveOffset;
2774 return BasePointerSaveOffset;
2792 assert(Subtarget.isAIXABI() &&
2793 "Function updateCalleeSaves should only be called for AIX.");
2796 if (SavedRegs.
none())
2800 Subtarget.getRegisterInfo()->getCalleeSavedRegs(&MF);
2810 for (
int i = 0; CSRegs[i]; i++) {
2814 if (!SavedRegs.
test(Cand))
2819 if (Cand == PPC::X2 || Cand == PPC::R2) {
2820 SavedRegs.
set(Cand);
2824 if (PPC::GPRCRegClass.
contains(Cand) && Cand < LowestGPR)
2826 else if (PPC::G8RCRegClass.
contains(Cand) && Cand < LowestG8R)
2828 else if ((PPC::F4RCRegClass.
contains(Cand) ||
2829 PPC::F8RCRegClass.
contains(Cand)) &&
2832 else if (PPC::VRRCRegClass.
contains(Cand) && Cand < LowestVR)
2836 for (
int i = 0; CSRegs[i]; i++) {
2838 if ((PPC::GPRCRegClass.
contains(Cand) && Cand > LowestGPR) ||
2839 (PPC::G8RCRegClass.
contains(Cand) && Cand > LowestG8R) ||
2840 ((PPC::F4RCRegClass.
contains(Cand) ||
2841 PPC::F8RCRegClass.
contains(Cand)) &&
2842 Cand > LowestFPR) ||
2843 (PPC::VRRCRegClass.
contains(Cand) && Cand > LowestVR))
2844 SavedRegs.
set(Cand);
2856 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
static cl::opt< bool > EnablePEVectorSpills("ppc-enable-pe-vector-spills", cl::desc("Enable spills in prologue to vector registers."), cl::init(false), cl::Hidden)
#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.
initializer< Ty > init(const Ty &Val)
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.