Lines Matching defs:MF

58 static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB,
61 if (!MF.getFunction().hasFnAttribute(Attribute::ShadowCallStack))
64 const auto &STI = MF.getSubtarget<RISCVSubtarget>();
70 std::vector<CalleeSavedInfo> &CSI = MF.getFrameInfo().getCalleeSavedInfo();
113 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createEscape(
120 static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB,
123 if (!MF.getFunction().hasFnAttribute(Attribute::ShadowCallStack))
126 const auto &STI = MF.getSubtarget<RISCVSubtarget>();
130 std::vector<CalleeSavedInfo> &CSI = MF.getFrameInfo().getCalleeSavedInfo();
159 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createRestore(
170 static int getLibCallID(const MachineFunction &MF,
172 const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
174 if (CSI.empty() || !RVFI->useSaveRestoreLibCalls(MF))
209 getSpillLibCallName(const MachineFunction &MF,
227 int LibCallID = getLibCallID(MF, CSI);
236 getRestoreLibCallName(const MachineFunction &MF,
254 int LibCallID = getLibCallID(MF, CSI);
295 static Register getMaxPushPopReg(const MachineFunction &MF,
312 bool RISCVFrameLowering::hasFP(const MachineFunction &MF) const {
313 const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
315 const MachineFrameInfo &MFI = MF.getFrameInfo();
316 return MF.getTarget().Options.DisableFramePointerElim(MF) ||
317 RegInfo->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||
321 bool RISCVFrameLowering::hasBP(const MachineFunction &MF) const {
322 const MachineFrameInfo &MFI = MF.getFrameInfo();
330 (!hasReservedCallFrame(MF) && (!MFI.isMaxCallFrameSizeComputed() ||
332 TRI->hasStackRealignment(MF);
336 void RISCVFrameLowering::determineFrameLayout(MachineFunction &MF) const {
337 MachineFrameInfo &MFI = MF.getFrameInfo();
338 auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
357 if (RVFI->getRVVStackSize() && (!hasFP(MF) || TRI->hasStackRealignment(MF))) {
369 const MachineFunction &MF) const {
370 const MachineFrameInfo &MFI = MF.getFrameInfo();
371 auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
382 getUnmanagedCSI(const MachineFunction &MF,
384 const MachineFrameInfo &MFI = MF.getFrameInfo();
397 getRVVCalleeSavedInfo(const MachineFunction &MF,
399 const MachineFrameInfo &MFI = MF.getFrameInfo();
411 void RISCVFrameLowering::adjustStackForRVV(MachineFunction &MF,
525 void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
527 MachineFrameInfo &MFI = MF.getFrameInfo();
528 auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
543 if (MF.getFunction().getCallingConv() == CallingConv::GHC)
547 emitSCSPrologue(MF, MBB, MBBI, DL);
557 determineFrameLayout(MF);
577 if (int LibCallRegs = getLibCallID(MF, MFI.getCalleeSavedInfo()) + 1) {
588 uint64_t RealStackSize = getStackSizeWithRVVPadding(MF);
599 MF.getFunction().getContext().diagnose(DiagnosticInfoUnsupported{
600 MF.getFunction(), "Stack pointer required, but has been reserved."});
602 uint64_t FirstSPAdjustAmount = getFirstSPAdjustAmount(MF);
609 if (RVFI->isPushable(MF) && FirstFrameSetup != MBB.end() &&
628 unsigned CFIIndex = MF.addFrameInst(
642 std::advance(MBBI, getUnmanagedCSI(MF, CSI).size());
654 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::createOffset(
662 if (hasFP(MF)) {
664 MF.getFunction().getContext().diagnose(DiagnosticInfoUnsupported{
665 MF.getFunction(), "Frame pointer required, but has been reserved."});
667 assert(MF.getRegInfo().isReserved(FPReg) && "FP not reserved");
674 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(
684 getStackSizeWithRVVPadding(MF) - FirstSPAdjustAmount;
693 if (!hasFP(MF)) {
695 unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(
696 nullptr, getStackSizeWithRVVPadding(MF)));
704 adjustStackForRVV(MF, MBB, MBBI, DL, -RVVStackSize,
706 if (!hasFP(MF)) {
708 unsigned CFIIndex = MF.addFrameInst(createDefCFAExpression(
709 *RI, SPReg, getStackSizeWithRVVPadding(MF), RVVStackSize / 8));
715 std::advance(MBBI, getRVVCalleeSavedInfo(MF, CSI).size());
716 emitCalleeSavedRVVPrologCFI(MBB, MBBI, hasFP(MF));
719 if (hasFP(MF)) {
722 if (RI->hasStackRealignment(MF)) {
734 MF.getRegInfo().createVirtualRegister(&RISCV::GPRRegClass);
747 if (hasBP(MF)) {
758 void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
761 MachineFrameInfo &MFI = MF.getFrameInfo();
762 auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
768 if (MF.getFunction().getCallingConv() == CallingConv::GHC)
789 const auto &CSI = getUnmanagedCSI(MF, MFI.getCalleeSavedInfo());
798 uint64_t RealStackSize = getStackSizeWithRVVPadding(MF);
813 if (RI->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||
814 !hasReservedCallFrame(MF)) {
815 assert(hasFP(MF) && "frame pointer should not have been eliminated");
821 adjustStackForRVV(MF, MBB, LastFrameDestroy, DL, RVVStackSize,
825 uint64_t FirstSPAdjustAmount = getFirstSPAdjustAmount(MF);
828 getStackSizeWithRVVPadding(MF) - FirstSPAdjustAmount;
840 if (RVFI->isPushable(MF) && MBBI != MBB.end() &&
858 emitSCSEpilogue(MF, MBB, MBBI, DL);
862 RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
864 const MachineFrameInfo &MFI = MF.getFrameInfo();
865 const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
866 const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
871 const auto &CSI = getUnmanagedCSI(MF, MFI.getCalleeSavedInfo());
888 uint64_t FirstSPAdjustAmount = getFirstSPAdjustAmount(MF);
901 Offset += StackOffset::getFixed(getStackSizeWithRVVPadding(MF));
905 if (RI->hasStackRealignment(MF) && !MFI.isFixedObjectIndex(FI)) {
938 if (hasBP(MF)) {
946 FrameReg = RI->getFrameRegister(MF);
967 assert(!RI->hasStackRealignment(MF) &&
972 assert(MFI.getStackSize() == getStackSizeWithRVVPadding(MF) &&
1015 assert(!RI->hasStackRealignment(MF) &&
1017 Offset += StackOffset::get(getStackSizeWithRVVPadding(MF),
1034 void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
1037 TargetFrameLowering::determineCalleeSaves(MF, SavedRegs, RS);
1040 if (hasFP(MF)) {
1045 if (hasBP(MF))
1049 auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
1050 if (RVFI->isPushable(MF) && SavedRegs.test(RISCV::X26))
1055 RISCVFrameLowering::assignRVVStackObjectOffsets(MachineFunction &MF) const {
1056 MachineFrameInfo &MFI = MF.getFrameInfo();
1071 std::vector<CalleeSavedInfo> &CSI = MF.getFrameInfo().getCalleeSavedInfo();
1072 const auto &RVVCSI = getRVVCalleeSavedInfo(MF, CSI);
1080 const auto &ST = MF.getSubtarget<RISCVSubtarget>();
1117 static unsigned getScavSlotsNumForRVV(MachineFunction &MF) {
1135 if (!MF.getSubtarget<RISCVSubtarget>().hasVInstructions())
1137 for (const MachineBasicBlock &MBB : MF)
1143 bool IsScalableVectorID = MF.getFrameInfo().getStackID(MO.getIndex()) ==
1161 static bool hasRVVFrameObject(const MachineFunction &MF) {
1177 return MF.getSubtarget<RISCVSubtarget>().hasVInstructions();
1180 static unsigned estimateFunctionSizeInBytes(const MachineFunction &MF,
1183 for (auto &MBB : MF) {
1205 if (MF.getSubtarget<RISCVSubtarget>().hasStdExtCOrZca())
1219 MachineFunction &MF, RegScavenger *RS) const {
1221 MF.getSubtarget<RISCVSubtarget>().getRegisterInfo();
1222 const RISCVInstrInfo *TII = MF.getSubtarget<RISCVSubtarget>().getInstrInfo();
1223 MachineFrameInfo &MFI = MF.getFrameInfo();
1225 auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
1229 std::tie(RVVStackSize, RVVStackAlign) = assignRVVStackObjectOffsets(MF);
1234 if (hasRVVFrameObject(MF)) {
1246 if (!isInt<11>(MFI.estimateStackSize(MF)))
1250 bool IsLargeFunction = !isInt<20>(estimateFunctionSizeInBytes(MF, *TII));
1257 ScavSlotsNum = std::max(ScavSlotsNum, getScavSlotsNumForRVV(MF));
1283 bool RISCVFrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
1284 return !MF.getFrameInfo().hasVarSizedObjects() &&
1285 !(hasFP(MF) && hasRVVFrameObject(MF));
1290 MachineFunction &MF, MachineBasicBlock &MBB,
1295 if (!hasReservedCallFrame(MF)) {
1331 RISCVFrameLowering::getFirstSPAdjustAmount(const MachineFunction &MF) const {
1332 const auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
1333 const MachineFrameInfo &MFI = MF.getFrameInfo();
1335 uint64_t StackSize = getStackSizeWithRVVPadding(MF);
1399 MachineFunction &MF, const TargetRegisterInfo *TRI,
1406 auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
1408 if (RVFI->isPushable(MF)) {
1410 Register MaxReg = getMaxPushPopReg(MF, CSI);
1421 MachineFrameInfo &MFI = MF.getFrameInfo();
1422 const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
1430 if (RVFI->useSaveRestoreLibCalls(MF) || RVFI->isPushable(MF)) {
1435 if (RVFI->isPushable(MF))
1462 if (RVFI->isPushable(MF)) {
1465 } else if (int LibCallRegs = getLibCallID(MF, CSI) + 1) {
1480 MachineFunction *MF = MBB.getParent();
1481 const TargetInstrInfo &TII = *MF->getSubtarget().getInstrInfo();
1487 RISCVMachineFunctionInfo *RVFI = MF->getInfo<RISCVMachineFunctionInfo>();
1488 if (RVFI->isPushable(*MF)) {
1502 } else if (const char *SpillLibCall = getSpillLibCallName(*MF, CSI)) {
1514 const auto &UnmanagedCSI = getUnmanagedCSI(*MF, CSI);
1515 const auto &RVVCSI = getRVVCalleeSavedInfo(*MF, CSI);
1534 MachineFunction *MF = MBB.getParent();
1535 const MachineFrameInfo &MFI = MF->getFrameInfo();
1536 RISCVMachineFunctionInfo *RVFI = MF->getInfo<RISCVMachineFunctionInfo>();
1540 const auto &RVVCSI = getRVVCalleeSavedInfo(*MF, MFI.getCalleeSavedInfo());
1544 uint64_t FixedSize = getStackSizeWithRVVPadding(*MF);
1557 unsigned CFIIndex = MF->addFrameInst(
1573 MachineFunction *MF = MBB.getParent();
1574 const TargetInstrInfo &TII = *MF->getSubtarget().getInstrInfo();
1585 const auto &UnmanagedCSI = getUnmanagedCSI(*MF, CSI);
1586 const auto &RVVCSI = getRVVCalleeSavedInfo(*MF, CSI);
1601 RISCVMachineFunctionInfo *RVFI = MF->getInfo<RISCVMachineFunctionInfo>();
1602 if (RVFI->isPushable(*MF)) {
1616 const char *RestoreLibCall = getRestoreLibCallName(*MF, CSI);
1627 NewMI->copyImplicitOps(*MF, *MI);
1635 bool RISCVFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const {
1637 if (MF.getFunction().hasOptNone())
1645 const MachineFunction *MF = MBB.getParent();
1646 const auto *RVFI = MF->getInfo<RISCVMachineFunctionInfo>();
1648 if (!RVFI->useSaveRestoreLibCalls(*MF))
1661 const MachineFunction *MF = MBB.getParent();
1663 const auto *RVFI = MF->getInfo<RISCVMachineFunctionInfo>();
1665 if (!RVFI->useSaveRestoreLibCalls(*MF))