35 PPC::V8 , PPC::V9 , PPC::V10, PPC::V11, PPC::V12, PPC::V13, PPC::V14, PPC::V15,
36 PPC::V16, PPC::V17, PPC::V18, PPC::V19, PPC::V20, PPC::V21, PPC::V22, PPC::V23,
37 PPC::V24, PPC::V25, PPC::V26, PPC::V27, PPC::V28, PPC::V29, PPC::V30, PPC::V31
58 return STI.
isPPC64() ? -8U : -4U;
61 return STI.
isPPC64() ? -8U : -4U;
74 return STI.
isPPC64() ? -16U : -8U;
84 STI.getPlatformStackAlignment(), 0),
93 unsigned &NumEntries)
const {
97 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
98 return &darwin64Offsets;
100 static const SpillSlot darwinOffsets = {PPC::R31, -4};
101 return &darwinOffsets;
263 assert(MBBI != Entry->
end() && MBBI->getOpcode() == PPC::MTVRSAVE);
264 MBBI->eraseFromParent();
266 bool RemovedAllMTVRSAVEs =
true;
271 if (
I->isReturnBlock()) {
272 bool FoundIt =
false;
273 for (MBBI =
I->end(); MBBI !=
I->begin(); ) {
275 if (MBBI->getOpcode() == PPC::MTVRSAVE) {
276 MBBI->eraseFromParent();
281 RemovedAllMTVRSAVEs &= FoundIt;
287 if (RemovedAllMTVRSAVEs) {
289 assert(MBBI != Entry->
begin() &&
"UPDATE_VRSAVE is first instr in block?");
291 assert(MBBI->getOpcode() == PPC::MFVRSAVE &&
"VRSAVE instrs wandered?");
292 MBBI->eraseFromParent();
308 unsigned UsedRegMask = 0;
309 for (
unsigned i = 0; i != 32; ++i)
311 UsedRegMask |= 1 << (31-i);
320 UsedRegMask &= ~(1 << (31-RegNo));
325 UsedRegMask != 0 && BI != BE; ++BI) {
332 if (!MO.
isReg() || !PPC::VRRCRegClass.contains(MO.
getReg()))
335 UsedRegMask &= ~(1 << (31-RegNo));
340 if (UsedRegMask == 0) {
349 if ((UsedRegMask & 0xFFFF) == UsedRegMask) {
350 if (DstReg != SrcReg)
358 }
else if ((UsedRegMask & 0xFFFF0000) == UsedRegMask) {
359 if (DstReg != SrcReg)
362 .
addImm(UsedRegMask >> 16);
366 .
addImm(UsedRegMask >> 16);
368 if (DstReg != SrcReg)
371 .
addImm(UsedRegMask >> 16);
375 .
addImm(UsedRegMask >> 16);
379 .
addImm(UsedRegMask & 0xFFFF);
424 bool UseEstimate)
const {
434 unsigned AlignMask =
std::max(MaxAlign, TargetAlign) - 1;
438 unsigned LR = RegInfo->getRARegister();
450 if (!DisableRedZone && CanUseRedZone && FitsInRedZone) {
462 maxCallFrameSize =
std::max(maxCallFrameSize, minCallFrameSize);
467 maxCallFrameSize = (maxCallFrameSize + AlignMask) & ~AlignMask;
474 FrameSize += maxCallFrameSize;
477 FrameSize = (FrameSize + AlignMask) & ~AlignMask;
515 unsigned FPReg = is31 ? PPC::R31 : PPC::R1;
516 unsigned FP8Reg = is31 ? PPC::X31 : PPC::X1;
521 unsigned BP8Reg = HasBP ? (
unsigned) PPC::X30 : FP8Reg;
527 for (
unsigned I = 0,
E = MBBI->getNumOperands();
I !=
E; ++
I) {
570 bool TwoUniqueRegsRequired,
572 unsigned *SR2)
const {
574 unsigned R0 = Subtarget.
isPPC64() ? PPC::X0 : PPC::R0;
575 unsigned R12 = Subtarget.
isPPC64() ? PPC::X12 : PPC::R12;
582 assert (SR1 &&
"Asking for the second scratch register but not the first?");
593 if (UseAtEnd && !MBB->
empty()) {
599 if (MBBI == MBB->
end())
600 MBBI = std::prev(MBBI);
602 if (MBBI != MBB->
begin())
625 for (
int i = 0; CSRegs[i]; ++i)
631 *SR1 = FirstScratchReg == -1 ? (
unsigned)PPC::NoRegister : FirstScratchReg;
638 int SecondScratchReg = BV.
find_next(*SR1);
639 if (SecondScratchReg != -1)
640 *SR2 = SecondScratchReg;
642 *SR2 = TwoUniqueRegsRequired ? (
unsigned)PPC::NoRegister : *SR1;
647 if (BV.
count() < (TwoUniqueRegsRequired ? 2U : 1U))
664 int NegFrameSize = -FrameSize;
665 bool IsLargeFrame = !
isInt<16>(NegFrameSize);
670 return (IsLargeFrame || !HasRedZone) && HasBP && MaxAlign > 1;
676 return findScratchRegister(TmpMBB,
false,
677 twoUniqueScratchRegsRequired(TmpMBB));
683 return findScratchRegister(TmpMBB,
true);
700 bool isPPC64 = Subtarget.
isPPC64();
705 "Currently only Darwin and SVR4 ABIs are supported for PowerPC.");
710 for (
unsigned i = 0; MBBI != MBB.
end(); ++i, ++MBBI) {
711 if (MBBI->getOpcode() == PPC::UPDATE_VRSAVE) {
722 int NegFrameSize = -FrameSize;
733 bool MustSaveCR = !MustSaveCRs.
empty();
735 bool HasFP =
hasFP(MF);
737 bool HasRedZone = isPPC64 || !isSVR4ABI;
739 unsigned SPReg = isPPC64 ? PPC::X1 : PPC::R1;
741 unsigned FPReg = isPPC64 ? PPC::X31 : PPC::R31;
742 unsigned LRReg = isPPC64 ? PPC::LR8 : PPC::LR;
743 unsigned ScratchReg = 0;
744 unsigned TempReg = isPPC64 ? PPC::X12 : PPC::R12;
746 const MCInstrDesc& MFLRInst = TII.get(isPPC64 ? PPC::MFLR8
750 const MCInstrDesc& StoreUpdtInst = TII.get(isPPC64 ? PPC::STDU
752 const MCInstrDesc& StoreUpdtIdxInst = TII.get(isPPC64 ? PPC::STDUX
754 const MCInstrDesc& LoadImmShiftedInst = TII.get(isPPC64 ? PPC::LIS8
756 const MCInstrDesc& OrImmInst = TII.get(isPPC64 ? PPC::ORI8
758 const MCInstrDesc& OrInst = TII.get(isPPC64 ? PPC::OR8
760 const MCInstrDesc& SubtractCarryingInst = TII.get(isPPC64 ? PPC::SUBFC8
762 const MCInstrDesc& SubtractImmCarryingInst = TII.get(isPPC64 ? PPC::SUBFIC8
769 assert((isPPC64 || !isSVR4ABI || !(!FrameSize && (MustSaveLR || HasFP))) &&
770 "FrameSize must be >0 to save/restore the FP or LR for 32-bit SVR4.");
773 bool SingleScratchReg =
774 findScratchRegister(&MBB,
false, twoUniqueScratchRegsRequired(&MBB),
775 &ScratchReg, &TempReg);
776 assert(SingleScratchReg &&
777 "Required number of registers not available in this block");
779 SingleScratchReg = ScratchReg == TempReg;
788 assert(FPIndex &&
"No Frame Pointer Save Slot!");
800 assert(BPIndex &&
"No Base Pointer Save Slot!");
811 assert(PBPIndex &&
"No PIC Base Pointer Save Slot!");
817 if (HasBP && MaxAlign > 1)
819 "Invalid alignment!");
823 bool isLargeFrame = !
isInt<16>(NegFrameSize);
825 assert((isPPC64 || !MustSaveCR) &&
826 "Prologue CR saving supported only in 64-bit mode");
830 if (MustSaveCR && SingleScratchReg && MustSaveLR) {
835 unsigned MfcrOpcode = PPC::MFCR8;
837 if (isELFv2ABI && MustSaveCRs.
size() == 1) {
838 MfcrOpcode = PPC::MFOCRF8;
842 BuildMI(MBB, MBBI, dl, TII.get(MfcrOpcode), TempReg);
843 for (
unsigned i = 0, e = MustSaveCRs.
size(); i != e; ++i)
844 MIB.
addReg(MustSaveCRs[i], CrState);
845 BuildMI(MBB, MBBI, dl, TII.get(PPC::STW8))
852 BuildMI(MBB, MBBI, dl, MFLRInst, ScratchReg);
855 !(SingleScratchReg && MustSaveLR)) {
860 unsigned MfcrOpcode = PPC::MFCR8;
862 if (isELFv2ABI && MustSaveCRs.
size() == 1) {
863 MfcrOpcode = PPC::MFOCRF8;
867 BuildMI(MBB, MBBI, dl, TII.get(MfcrOpcode), TempReg);
868 for (
unsigned i = 0, e = MustSaveCRs.
size(); i != e; ++i)
869 MIB.
addReg(MustSaveCRs[i], CrState);
874 BuildMI(MBB, MBBI, dl, StoreInst)
879 BuildMI(MBB, MBBI, dl, StoreInst)
884 BuildMI(MBB, MBBI, dl, StoreInst)
891 BuildMI(MBB, MBBI, dl, StoreInst)
897 !(SingleScratchReg && MustSaveLR)) {
898 assert(HasRedZone &&
"A red zone is always available on PPC64");
899 BuildMI(MBB, MBBI, dl, TII.get(PPC::STW8))
912 if (HasBP && HasRedZone) {
914 BuildMI(MBB, MBBI, dl, OrInst, BPReg)
921 bool HasSTUX =
false;
924 if (HasBP && MaxAlign > 1) {
926 BuildMI(MBB, MBBI, dl, TII.get(PPC::RLDICL), ScratchReg)
931 BuildMI(MBB, MBBI, dl, TII.get(PPC::RLWINM), ScratchReg)
937 BuildMI(MBB, MBBI, dl, SubtractImmCarryingInst, ScratchReg)
941 assert(!SingleScratchReg &&
"Only a single scratch reg available");
942 BuildMI(MBB, MBBI, dl, LoadImmShiftedInst, TempReg)
943 .
addImm(NegFrameSize >> 16);
944 BuildMI(MBB, MBBI, dl, OrImmInst, TempReg)
946 .
addImm(NegFrameSize & 0xFFFF);
947 BuildMI(MBB, MBBI, dl, SubtractCarryingInst, ScratchReg)
952 BuildMI(MBB, MBBI, dl, StoreUpdtIdxInst, SPReg)
958 }
else if (!isLargeFrame) {
959 BuildMI(MBB, MBBI, dl, StoreUpdtInst, SPReg)
965 BuildMI(MBB, MBBI, dl, LoadImmShiftedInst, ScratchReg)
966 .
addImm(NegFrameSize >> 16);
967 BuildMI(MBB, MBBI, dl, OrImmInst, ScratchReg)
969 .
addImm(NegFrameSize & 0xFFFF);
970 BuildMI(MBB, MBBI, dl, StoreUpdtIdxInst, SPReg)
978 assert(!isPPC64 &&
"A red zone is always available on PPC64");
990 BuildMI(MBB, MBBI, dl, TII.get(PPC::SUBF), ScratchReg)
994 if (ScratchReg == PPC::R0) {
1001 BuildMI(MBB, MBBI, dl, TII.get(PPC::ADDIC), ScratchReg)
1003 .
addImm(FPOffset-LastOffset);
1004 LastOffset = FPOffset;
1006 BuildMI(MBB, MBBI, dl, TII.get(PPC::STWX))
1013 BuildMI(MBB, MBBI, dl, TII.get(PPC::ADDIC), ScratchReg)
1015 .
addImm(PBPOffset-LastOffset);
1016 LastOffset = PBPOffset;
1017 BuildMI(MBB, MBBI, dl, TII.get(PPC::STWX))
1024 BuildMI(MBB, MBBI, dl, TII.get(PPC::ADDIC), ScratchReg)
1026 .
addImm(BPOffset-LastOffset);
1027 LastOffset = BPOffset;
1028 BuildMI(MBB, MBBI, dl, TII.get(PPC::STWX))
1033 BuildMI(MBB, MBBI, dl, TII.get(PPC::ADDIC), BPReg)
1044 BuildMI(MBB, MBBI, dl, StoreInst)
1049 BuildMI(MBB, MBBI, dl, StoreInst)
1054 BuildMI(MBB, MBBI, dl, StoreInst)
1058 BuildMI(MBB, MBBI, dl, OrInst, BPReg)
1069 BuildMI(MBB, MBBI, dl, StoreInst)
1071 .
addImm(FrameSize + FPOffset)
1074 BuildMI(MBB, MBBI, dl, StoreInst)
1076 .
addImm(FrameSize + PBPOffset)
1079 BuildMI(MBB, MBBI, dl, StoreInst)
1081 .
addImm(FrameSize + BPOffset)
1083 BuildMI(MBB, MBBI, dl, TII.get(PPC::ADDI), BPReg)
1107 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
1108 .addCFIIndex(CFIIndex);
1115 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
1116 .addCFIIndex(CFIIndex);
1124 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
1125 .addCFIIndex(CFIIndex);
1133 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
1134 .addCFIIndex(CFIIndex);
1142 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
1143 .addCFIIndex(CFIIndex);
1149 BuildMI(MBB, MBBI, dl, OrInst, FPReg)
1153 if (!HasBP && needsCFI) {
1160 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
1161 .addCFIIndex(CFIIndex);
1169 for (
unsigned I = 0,
E = CSI.size();
I !=
E; ++
I) {
1170 unsigned Reg = CSI[
I].getReg();
1171 if (Reg == PPC::LR || Reg == PPC::LR8 || Reg ==
PPC::RM)
continue;
1175 if (PPC::CRBITRCRegClass.
contains(Reg))
1180 if (isSVR4ABI && (PPC::CR2 <= Reg && Reg <= PPC::CR4)
1186 if (isSVR4ABI && isPPC64 && (PPC::CR2 <= Reg && Reg <= PPC::CR4)) {
1190 unsigned CRReg = isELFv2ABI? Reg : (
unsigned) PPC::CR2;
1193 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
1194 .addCFIIndex(CFIIndex);
1201 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
1202 .addCFIIndex(CFIIndex);
1212 if (MBBI != MBB.
end())
1213 dl = MBBI->getDebugLoc();
1225 bool isPPC64 = Subtarget.
isPPC64();
1233 bool MustSaveCR = !MustSaveCRs.
empty();
1235 bool HasFP =
hasFP(MF);
1239 unsigned SPReg = isPPC64 ? PPC::X1 : PPC::R1;
1241 unsigned FPReg = isPPC64 ? PPC::X31 : PPC::R31;
1242 unsigned ScratchReg = 0;
1243 unsigned TempReg = isPPC64 ? PPC::X12 : PPC::R12;
1244 const MCInstrDesc& MTLRInst = TII.get( isPPC64 ? PPC::MTLR8
1248 const MCInstrDesc& LoadImmShiftedInst = TII.get( isPPC64 ? PPC::LIS8
1250 const MCInstrDesc& OrInst = TII.get(isPPC64 ? PPC::OR8
1252 const MCInstrDesc& OrImmInst = TII.get( isPPC64 ? PPC::ORI8
1254 const MCInstrDesc& AddImmInst = TII.get( isPPC64 ? PPC::ADDI8
1256 const MCInstrDesc& AddInst = TII.get( isPPC64 ? PPC::ADD8
1264 bool SingleScratchReg = findScratchRegister(&MBB,
true,
false, &ScratchReg,
1266 assert(SingleScratchReg &&
1267 "Could not find an available scratch register");
1269 SingleScratchReg = ScratchReg == TempReg;
1274 assert(FPIndex &&
"No Frame Pointer Save Slot!");
1285 assert(BPIndex &&
"No Base Pointer Save Slot!");
1295 assert(PBPIndex &&
"No PIC Base Pointer Save Slot!");
1299 bool IsReturnBlock = (MBBI != MBB.
end() && MBBI->isReturn());
1301 if (IsReturnBlock) {
1302 unsigned RetOpcode = MBBI->getOpcode();
1303 bool UsesTCRet = RetOpcode == PPC::TCRETURNri ||
1304 RetOpcode == PPC::TCRETURNdi ||
1305 RetOpcode == PPC::TCRETURNai ||
1306 RetOpcode == PPC::TCRETURNri8 ||
1307 RetOpcode == PPC::TCRETURNdi8 ||
1308 RetOpcode == PPC::TCRETURNai8;
1313 assert(StackAdjust.
isImm() &&
"Expecting immediate value.");
1315 int StackAdj = StackAdjust.
getImm();
1316 int Delta = StackAdj - MaxTCRetDelta;
1317 assert((Delta >= 0) &&
"Delta must be positive");
1318 if (MaxTCRetDelta>0)
1319 FrameSize += (StackAdj +Delta);
1321 FrameSize += StackAdj;
1327 bool isLargeFrame = !
isInt<16>(FrameSize);
1341 unsigned RBReg = SPReg;
1354 assert(HasFP &&
"Expecting a valid frame pointer.");
1357 if (!isLargeFrame) {
1358 BuildMI(MBB, MBBI, dl, AddImmInst, RBReg)
1361 BuildMI(MBB, MBBI, dl, LoadImmShiftedInst, ScratchReg)
1362 .
addImm(FrameSize >> 16);
1363 BuildMI(MBB, MBBI, dl, OrImmInst, ScratchReg)
1365 .
addImm(FrameSize & 0xFFFF);
1366 BuildMI(MBB, MBBI, dl, AddInst)
1373 BuildMI(MBB, MBBI, dl, AddImmInst, SPReg)
1379 assert(FPOffset <= 0 && BPOffset <= 0 && PBPOffset <= 0 &&
1380 "Local offsets should be negative");
1382 FPOffset += FrameSize;
1383 BPOffset += FrameSize;
1384 PBPOffset += FrameSize;
1392 BuildMI(MBB, MBBI, dl, OrInst, ScratchReg)
1397 BuildMI(MBB, MBBI, dl, LoadInst, RBReg)
1402 assert(RBReg != ScratchReg &&
"Should have avoided ScratchReg");
1407 assert((isPPC64 || !MustSaveCR) &&
1408 "Epilogue CR restoring supported only in 64-bit mode");
1412 if (MustSaveCR && SingleScratchReg && MustSaveLR) {
1415 assert(HasRedZone &&
"Expecting red zone");
1416 BuildMI(MBB, MBBI, dl, TII.get(PPC::LWZ8), TempReg)
1419 for (
unsigned i = 0, e = MustSaveCRs.
size(); i != e; ++i)
1420 BuildMI(MBB, MBBI, dl, TII.get(PPC::MTOCRF8), MustSaveCRs[i])
1428 bool LoadedLR =
false;
1429 if (MustSaveLR && RBReg == SPReg &&
isInt<16>(LROffset+SPAdd)) {
1430 BuildMI(MBB, MBBI, dl, LoadInst, ScratchReg)
1436 if (MustSaveCR && !(SingleScratchReg && MustSaveLR)) {
1438 assert(isPPC64 &&
"Expecting 64-bit mode");
1439 assert(RBReg == SPReg &&
"Should be using SP as a base register");
1440 BuildMI(MBB, MBBI, dl, TII.get(PPC::LWZ8), TempReg)
1448 if (HasRedZone || RBReg == SPReg)
1449 BuildMI(MBB, MBBI, dl, LoadInst, FPReg)
1453 BuildMI(MBB, MBBI, dl, LoadInst, ScratchReg)
1459 BuildMI(MBB, MBBI, dl, LoadInst, PPC::R30)
1464 BuildMI(MBB, MBBI, dl, LoadInst, BPReg)
1470 if (RBReg != SPReg || SPAdd != 0) {
1471 assert(!HasRedZone &&
"This should not happen with red zone");
1474 BuildMI(MBB, MBBI, dl, OrInst, SPReg)
1478 BuildMI(MBB, MBBI, dl, AddImmInst, SPReg)
1482 assert(RBReg != ScratchReg &&
"Should be using FP or SP as base register");
1484 BuildMI(MBB, MBBI, dl, OrInst, FPReg)
1489 if (MustSaveLR && !LoadedLR)
1490 BuildMI(MBB, MBBI, dl, LoadInst, ScratchReg)
1496 !(SingleScratchReg && MustSaveLR))
1497 for (
unsigned i = 0, e = MustSaveCRs.
size(); i != e; ++i)
1498 BuildMI(MBB, MBBI, dl, TII.get(PPC::MTOCRF8), MustSaveCRs[i])
1506 if (IsReturnBlock) {
1507 unsigned RetOpcode = MBBI->getOpcode();
1509 (RetOpcode == PPC::BLR || RetOpcode == PPC::BLR8) &&
1514 if (CallerAllocatedAmt &&
isInt<16>(CallerAllocatedAmt)) {
1515 BuildMI(MBB, MBBI, dl, AddImmInst, SPReg)
1518 BuildMI(MBB, MBBI, dl, LoadImmShiftedInst, ScratchReg)
1519 .
addImm(CallerAllocatedAmt >> 16);
1520 BuildMI(MBB, MBBI, dl, OrImmInst, ScratchReg)
1522 .
addImm(CallerAllocatedAmt & 0xFFFF);
1523 BuildMI(MBB, MBBI, dl, AddInst)
1529 createTailCallBranchInstr(MBB);
1534 void PPCFrameLowering::createTailCallBranchInstr(
MachineBasicBlock &MBB)
const {
1538 if (MBBI != MBB.
end())
1539 dl = MBBI->getDebugLoc();
1544 unsigned RetOpcode = MBBI->getOpcode();
1545 if (RetOpcode == PPC::TCRETURNdi) {
1548 BuildMI(MBB, MBBI, dl, TII.get(PPC::TAILB)).
1550 }
else if (RetOpcode == PPC::TCRETURNri) {
1552 assert(MBBI->getOperand(0).isReg() &&
"Expecting register operand.");
1553 BuildMI(MBB, MBBI, dl, TII.get(PPC::TAILBCTR));
1554 }
else if (RetOpcode == PPC::TCRETURNai) {
1557 BuildMI(MBB, MBBI, dl, TII.get(PPC::TAILBA)).addImm(JumpTarget.
getImm());
1558 }
else if (RetOpcode == PPC::TCRETURNdi8) {
1561 BuildMI(MBB, MBBI, dl, TII.get(PPC::TAILB8)).
1563 }
else if (RetOpcode == PPC::TCRETURNri8) {
1565 assert(MBBI->getOperand(0).isReg() &&
"Expecting register operand.");
1566 BuildMI(MBB, MBBI, dl, TII.get(PPC::TAILBCTR8));
1567 }
else if (RetOpcode == PPC::TCRETURNai8) {
1570 BuildMI(MBB, MBBI, dl, TII.get(PPC::TAILBA8)).addImm(JumpTarget.
getImm());
1583 unsigned LR = RegInfo->getRARegister();
1585 SavedRegs.
reset(LR);
1589 bool isPPC64 = Subtarget.
isPPC64();
1624 SavedRegs.
reset(isPPC64 ? PPC::X31 : PPC::R31);
1628 SavedRegs.
reset(PPC::R30);
1639 if (!isPPC64 && !isDarwinABI &&
1640 (SavedRegs.
test(PPC::CR2) ||
1641 SavedRegs.
test(PPC::CR3) ||
1642 SavedRegs.
test(PPC::CR4))) {
1668 createTailCallBranchInstr(MBB);
1673 if (CSI.empty() && !
needsFP(MF)) {
1678 unsigned MinGPR = PPC::R31;
1679 unsigned MinG8R = PPC::X31;
1680 unsigned MinFPR = PPC::F31;
1681 unsigned MinVR = PPC::V31;
1683 bool HasGPSaveArea =
false;
1684 bool HasG8SaveArea =
false;
1685 bool HasFPSaveArea =
false;
1686 bool HasVRSAVESaveArea =
false;
1687 bool HasVRSaveArea =
false;
1694 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
1695 unsigned Reg = CSI[i].getReg();
1696 if (PPC::GPRCRegClass.
contains(Reg)) {
1697 HasGPSaveArea =
true;
1704 }
else if (PPC::G8RCRegClass.
contains(Reg)) {
1705 HasG8SaveArea =
true;
1712 }
else if (PPC::F8RCRegClass.
contains(Reg)) {
1713 HasFPSaveArea =
true;
1720 }
else if (PPC::CRBITRCRegClass.
contains(Reg) ||
1723 }
else if (PPC::VRSAVERCRegClass.
contains(Reg)) {
1724 HasVRSAVESaveArea =
true;
1725 }
else if (PPC::VRRCRegClass.
contains(Reg)) {
1726 HasVRSaveArea =
true;
1741 int64_t LowerBound = 0;
1747 LowerBound = TCSPDelta;
1752 if (HasFPSaveArea) {
1753 for (
unsigned i = 0, e = FPRegs.
size(); i != e; ++i) {
1754 int FI = FPRegs[i].getFrameIdx();
1759 LowerBound -= (31 - TRI->getEncodingValue(MinFPR) + 1) * 8;
1766 assert(FI &&
"No Frame Pointer Save Slot!");
1769 HasGPSaveArea =
true;
1774 assert(FI &&
"No PIC Base Pointer Save Slot!");
1777 MinGPR = std::min<unsigned>(MinGPR, PPC::R30);
1778 HasGPSaveArea =
true;
1784 assert(FI &&
"No Base Pointer Save Slot!");
1788 if (PPC::G8RCRegClass.
contains(BP)) {
1789 MinG8R = std::min<unsigned>(MinG8R, BP);
1790 HasG8SaveArea =
true;
1791 }
else if (PPC::GPRCRegClass.
contains(BP)) {
1792 MinGPR = std::min<unsigned>(MinGPR, BP);
1793 HasGPSaveArea =
true;
1799 if (HasGPSaveArea || HasG8SaveArea) {
1802 for (
unsigned i = 0, e = GPRegs.
size(); i != e; ++i) {
1803 int FI = GPRegs[i].getFrameIdx();
1810 for (
unsigned i = 0, e = G8Regs.
size(); i != e; ++i) {
1811 int FI = G8Regs[i].getFrameIdx();
1817 std::min<unsigned>(TRI->getEncodingValue(MinGPR),
1818 TRI->getEncodingValue(MinG8R));
1821 LowerBound -= (31 - MinReg + 1) * 8;
1823 LowerBound -= (31 - MinReg + 1) * 4;
1834 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
1835 unsigned Reg = CSI[i].getReg();
1837 if ((Subtarget.
isSVR4ABI() && Reg == PPC::CR2)
1840 (PPC::CRBITRCRegClass.contains(Reg) ||
1841 PPC::CRRCRegClass.contains(Reg)))) {
1842 int FI = CSI[i].getFrameIdx();
1851 if (HasVRSAVESaveArea) {
1855 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
1856 unsigned Reg = CSI[i].getReg();
1858 if (PPC::VRSAVERCRegClass.
contains(Reg)) {
1859 int FI = CSI[i].getFrameIdx();
1868 if (HasVRSaveArea) {
1874 assert(LowerBound <= 0 &&
"Expect LowerBound have a non-positive value!");
1875 LowerBound &= ~(15);
1877 for (
unsigned i = 0, e = VRegs.
size(); i != e; ++i) {
1878 int FI = VRegs[i].getFrameIdx();
1929 const std::vector<CalleeSavedInfo> &CSI,
1940 bool CRSpilled =
false;
1943 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
1944 unsigned Reg = CSI[i].getReg();
1948 if (Reg == PPC::VRSAVE && !Subtarget.
isDarwinABI())
1952 bool IsCRField = PPC::CR2 <= Reg && Reg <= PPC::CR4;
1957 if (CRSpilled && IsCRField) {
1974 CRMIB =
BuildMI(*MF, DL, TII.get(PPC::MFCR), PPC::R12)
1981 CSI[i].getFrameIdx()));
1986 CSI[i].getFrameIdx(), RC, TRI);
1994 bool CR2Spilled,
bool CR3Spilled,
bool CR4Spilled,
1996 const std::vector<CalleeSavedInfo> &CSI,
unsigned CSIIndex) {
2001 unsigned RestoreOp, MoveReg;
2010 CSI[CSIIndex].getFrameIdx()));
2011 RestoreOp = PPC::MTOCRF;
2016 MBB.
insert(MI,
BuildMI(*MF, DL, TII.get(RestoreOp), PPC::CR2)
2020 MBB.
insert(MI,
BuildMI(*MF, DL, TII.get(RestoreOp), PPC::CR3)
2024 MBB.
insert(MI,
BuildMI(*MF, DL, TII.get(RestoreOp), PPC::CR4)
2033 I->getOpcode() == PPC::ADJCALLSTACKUP) {
2035 if (
int CalleeAmt = I->getOperand(1).getImm()) {
2038 unsigned StackReg = is64Bit ? PPC::X1 : PPC::R1;
2039 unsigned TmpReg = is64Bit ? PPC::X0 : PPC::R0;
2040 unsigned ADDIInstr = is64Bit ? PPC::ADDI8 : PPC::ADDI;
2041 unsigned ADDInstr = is64Bit ? PPC::ADD8 : PPC::ADD4;
2042 unsigned LISInstr = is64Bit ? PPC::LIS8 : PPC::LIS;
2043 unsigned ORIInstr = is64Bit ? PPC::ORI8 : PPC::ORI;
2044 const DebugLoc &dl = I->getDebugLoc();
2047 BuildMI(MBB, I, dl, TII.
get(ADDIInstr), StackReg)
2052 BuildMI(MBB, MBBI, dl, TII.
get(LISInstr), TmpReg)
2053 .addImm(CalleeAmt >> 16);
2054 BuildMI(MBB, MBBI, dl, TII.
get(ORIInstr), TmpReg)
2056 .
addImm(CalleeAmt & 0xFFFF);
2057 BuildMI(MBB, MBBI, dl, TII.
get(ADDInstr), StackReg)
2064 return MBB.
erase(I);
2070 const std::vector<CalleeSavedInfo> &CSI,
2080 bool CR2Spilled =
false;
2081 bool CR3Spilled =
false;
2082 bool CR4Spilled =
false;
2083 unsigned CSIIndex = 0;
2088 bool AtStart = I == MBB.
begin();
2093 for (
unsigned i = 0, e = CSI.size(); i != e; ++i) {
2094 unsigned Reg = CSI[i].getReg();
2099 if (Reg == PPC::VRSAVE && !Subtarget.
isDarwinABI())
2102 if (Reg == PPC::CR2) {
2108 }
else if (Reg == PPC::CR3) {
2111 }
else if (Reg == PPC::CR4) {
2117 if ((CR2Spilled || CR3Spilled || CR4Spilled)
2118 && !(PPC::CR2 <= Reg && Reg <= PPC::CR4)) {
2121 CR2Spilled, CR3Spilled, CR4Spilled,
2122 MBB,
I, CSI, CSIIndex);
2123 CR2Spilled = CR3Spilled = CR4Spilled =
false;
2131 "loadRegFromStackSlot didn't insert any code!");
2144 if (CR2Spilled || CR3Spilled || CR4Spilled) {
2147 MBB,
I, CSI, CSIIndex);
void replaceFPWithRealFP(MachineFunction &MF) const
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
void push_back(const T &Elt)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
int getDwarfRegNum(unsigned RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
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 GlobalValue * getGlobal() const
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
int getTailCallSPDelta() const
static const unsigned GPRegs[]
livein_iterator livein_end() const
const PPCTargetMachine & getTargetMachine() const
void addMustSaveCR(unsigned Reg)
MachineBasicBlock * getRestorePoint() const
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment for a spill slot for a register of this class.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Describe properties that are true of each instruction in the target description file.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
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...
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
void setFramePointerSaveIndex(int Idx)
static unsigned computeTOCSaveOffset(const PPCSubtarget &STI)
static const MCPhysReg VRegs[32]
bool isLRStoreRequired() const
constexpr bool isInt< 16 >(int64_t x)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
An instruction for reading from memory.
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
return AArch64::GPR64RegClass contains(Reg)
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
static void restoreCRs(bool isPPC64, bool is31, bool CR2Spilled, bool CR3Spilled, bool CR4Spilled, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, unsigned CSIIndex)
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...
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
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.
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
const HexagonInstrInfo * TII
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
unsigned getMinReservedArea() const
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.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
Reg
All possible values of the reg field in the ModR/M byte.
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...
bool isVRSAVESpilled() const
bool hasDebugInfo() const
Returns true if valid debug info is present.
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
LLVM_NODISCARD bool empty() const
unsigned getNumOperands() const
Access to explicit operands of the instruction.
unsigned getReturnSaveOffset() const
getReturnSaveOffset - Return the previous frame offset to save the return address.
int getBasePointerSaveIndex() const
static bool hasNonRISpills(const MachineFunction &MF)
void forward()
Move the internal MBB iterator and update register states.
const MachineBasicBlock & front() const
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
unsigned getBasePointerSaveOffset() const
getBasePointerSaveOffset - Return the previous frame offset to save the base pointer.
BitVector getRegsAvailable(const TargetRegisterClass *RC)
Return all available registers in the register class in Mask.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
int getPICBasePointerSaveIndex() const
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
An instruction for storing to memory.
int getFramePointerSaveIndex() const
const SmallVectorImpl< unsigned > & getMustSaveCRs() const
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
unsigned getKillRegState(bool B)
unsigned estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
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.
size_type count() const
count - Returns the number of bits which are set.
This file declares the machine register scavenger class.
static const unsigned G8Regs[]
unsigned const MachineRegisterInfo * MRI
unsigned getFramePointerSaveOffset() const
getFramePointerSaveOffset - Return the previous frame offset to save the frame pointer.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const
unsigned getBaseRegister(const MachineFunction &MF) const
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 canUseAsPrologue(const MachineBasicBlock &MBB) const override
Methods used by shrink wrapping to determine if MBB can be used for the function prologue/epilogue.
void setStackSize(uint64_t Size)
Set the size of the stack.
static bool is64Bit(const char *name)
const MachineOperand & getOperand(unsigned i) const
static ManagedStatic< OptionRegistry > OR
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
std::vector< std::pair< unsigned, unsigned >>::const_iterator livein_iterator
bool isPositionIndependent() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
static unsigned computeReturnSaveOffset(const PPCSubtarget &STI)
void setBasePointerSaveIndex(int Idx)
unsigned GuaranteedTailCallOpt
GuaranteedTailCallOpt - This flag is enabled when -tailcallopt is specified on the commandline...
int64_t getOffset() const
Return the offset from the symbol in this operand.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
static unsigned computeBasePointerSaveOffset(const PPCSubtarget &STI)
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction. ...
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 const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0, bool mem=true)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
void setCRSpillFrameIndex(int idx)
const PPCRegisterInfo * getRegisterInfo() const override
Iterator for intrusive lists based on ilist_node.
bool hasTailCall() const
Returns true if the function contains a tail call.
constexpr bool isInt< 32 >(int64_t x)
const MCContext & getContext() const
const PPCInstrInfo * getInstrInfo() const override
void addScavengingFrameIndex(int FI)
Add a scavenging frame index.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool test(unsigned Idx) const
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
bool isRegUsed(unsigned Reg, bool includeReserved=true) const
Return if a specific register is currently used.
Information about stack frame layout on the target.
unsigned getRedZoneSize() const
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
static bool spillsVRSAVE(const MachineFunction &MF)
livein_iterator livein_begin() const
static bool hasSpills(const MachineFunction &MF)
unsigned determineFrameLayout(MachineFunction &MF, bool UpdateMF=true, bool UseEstimate=false) const
determineFrameLayout - Determine the size of the frame and maximum call frame size.
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...
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
static bool spillsCR(const MachineFunction &MF)
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...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
static bool MustSaveLR(const MachineFunction &MF, unsigned LR)
MustSaveLR - Return true if this function requires that we save the LR register onto the stack in the...
def_iterator def_begin(unsigned RegNo) const
bool needsFP(const MachineFunction &MF) const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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
MachineBasicBlock * getSavePoint() const
void setPICBasePointerSaveIndex(int Idx)
Representation of each machine instruction.
bool hasPatchPoint() const
This method may be called any time after instruction selection is complete to determine if there is a...
void enterBasicBlock(MachineBasicBlock &MBB)
Start tracking liveness from the begin of basic block MBB.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static void HandleVRSaveUpdate(MachineInstr &MI, const TargetInstrInfo &TII)
PPCFrameLowering(const PPCSubtarget &STI)
void setReg(unsigned Reg)
Change the register this operand corresponds to.
void setMaxCallFrameSize(unsigned S)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
bool hasNonRISpills() const
bool isPhysRegModified(unsigned PhysReg, bool SkipNoReturnDef=false) const
Return true if the specified register is modified in this function.
static unsigned computeFramePointerSaveOffset(const PPCSubtarget &STI)
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
static void RemoveVRSaveCode(MachineInstr &MI)
RemoveVRSaveCode - We have found that this function does not need any code to manipulate the VRSAVE r...
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static def_iterator def_end()
uint16_t getEncodingValue(unsigned RegNo) const
Returns the encoding for RegNo.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
MachineModuleInfo & getMMI() const
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
unsigned getLinkageSize() const
getLinkageSize - Return the size of the PowerPC ABI linkage area.
static const MCPhysReg VRRegNo[]
VRRegNo - Map from a numbered VR register to its enum value.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
bool hasBasePointer(const MachineFunction &MF) const
static unsigned computeLinkageSize(const PPCSubtarget &STI)
void setMustSaveLR(bool U)
MustSaveLR - This is set when the prolog/epilog inserter does its initial scan of the function...
This class contains meta information specific to a module.