34#define DEBUG_TYPE "riscv-frame"
68 RISCV::X18, RISCV::X19, RISCV::X20,
69 RISCV::X21, RISCV::X22, RISCV::X23,
70 RISCV::X24, RISCV::X25, RISCV::X26,
135 "Unexpected Shadow Stack Kind");
139 bool IsRV64 = STI.is64Bit();
140 int64_t SlotSize = STI.getXLen() / 8;
159 char DwarfSCSReg =
TRI->getDwarfRegNum(SCSPReg,
true);
160 assert(DwarfSCSReg < 32 &&
"SCS Register should be < 32 (X3).");
162 char Offset =
static_cast<char>(-SlotSize) & 0x7f;
163 const char CFIInst[] = {
164 dwarf::DW_CFA_val_expression,
167 static_cast<char>(
unsigned(dwarf::DW_OP_breg0 + DwarfSCSReg)),
192 if (
MI !=
MBB.end() &&
193 (
MI->getOpcode() == RISCV::CM_POP ||
MI->getOpcode() == RISCV::QC_CM_POP))
207 "Unexpected Shadow Stack Kind");
211 bool IsRV64 = STI.is64Bit();
212 int64_t SlotSize = STI.getXLen() / 8;
237 if (!RVFI->isSiFiveStackSwapInterrupt(MF))
243 assert(STI.hasVendorXSfmclic() &&
"Stack Swapping Requires XSfmclic");
246 .
addImm(RISCVSysReg::sf_mscratchcsw)
265 for (
int I = 0;
I < 2; ++
I) {
278 assert(ScratchCS != CSI.end() &&
"Missing SiFive CLIC scratch spill slot");
279 return ScratchCS->getFrameIdx();
288 if (!RVFI->isSiFivePreemptibleInterrupt(MF))
299 TII->storeRegToStackSlot(
MBB,
MBBI, RISCV::X5,
true, ScratchFI,
307 .
addImm(RISCVSysReg::mcause)
310 TII->storeRegToStackSlot(
MBB,
MBBI, RISCV::X5,
true,
311 RVFI->getInterruptCSRFrameIndex(0),
316 .
addImm(RISCVSysReg::mepc)
322 .
addImm(RISCVSysReg::mstatus)
325 TII->storeRegToStackSlot(
MBB,
MBBI, RISCV::X5,
true,
326 RVFI->getInterruptCSRFrameIndex(1),
338 if (!RVFI->isSiFivePreemptibleInterrupt(MF))
348 TII->loadRegFromStackSlot(
MBB,
MBBI, RISCV::X5,
349 RVFI->getInterruptCSRFrameIndex(1),
355 .
addImm(RISCVSysReg::mstatus)
362 .
addImm(RISCVSysReg::mepc)
366 TII->loadRegFromStackSlot(
MBB,
MBBI, RISCV::X5,
367 RVFI->getInterruptCSRFrameIndex(0),
371 .
addImm(RISCVSysReg::mcause)
377 TII->loadRegFromStackSlot(
MBB,
MBBI, RISCV::X5,
390 const std::vector<CalleeSavedInfo> &CSI) {
393 if (CSI.empty() || !RVFI->useSaveRestoreLibCalls(MF))
400 if (CS.getFrameIdx() < 0)
401 MaxReg = std::max(MaxReg.
id(), CS.getReg().id());
406 switch (MaxReg.
id()) {
410 case RISCV::X27:
return 12;
411 case RISCV::X26:
return 11;
412 case RISCV::X25:
return 10;
413 case RISCV::X24:
return 9;
414 case RISCV::X23:
return 8;
415 case RISCV::X22:
return 7;
416 case RISCV::X21:
return 6;
417 case RISCV::X20:
return 5;
418 case RISCV::X19:
return 4;
419 case RISCV::X18:
return 3;
420 case RISCV::X9:
return 2;
421 case FPReg:
return 1;
422 case RAReg:
return 0;
431 const std::vector<CalleeSavedInfo> &CSI) {
432 static const char *
const SpillLibCalls[] = {
451 return SpillLibCalls[LibCallID];
458 const std::vector<CalleeSavedInfo> &CSI) {
459 static const char *
const RestoreLibCalls[] = {
470 "__riscv_restore_10",
471 "__riscv_restore_11",
478 return RestoreLibCalls[LibCallID];
483 unsigned NumPushPopRegs = 0;
484 for (
auto &CS : CSI) {
488 unsigned RegNum = std::distance(std::begin(
FixedCSRFIMap), FII);
489 NumPushPopRegs = std::max(NumPushPopRegs, RegNum + 1);
492 assert(NumPushPopRegs != 12 &&
"x26 requires x27 to also be pushed");
493 return NumPushPopRegs;
536 TRI->hasStackRealignment(MF);
540void RISCVFrameLowering::determineFrameLayout(
MachineFunction &MF)
const {
548 if (RVFI->useQCIInterrupt(MF))
555 FrameSize =
alignTo(FrameSize, StackAlign);
565 if (RVFI->getRVVStackSize() && (!
hasFP(MF) ||
TRI->hasStackRealignment(MF))) {
566 int ScalarLocalVarSize = FrameSize - RVFI->getCalleeSavedStackSize() -
567 RVFI->getVarArgsSaveSize();
568 if (
auto RVVPadding =
570 RVFI->setRVVPadding(RVVPadding);
585 const std::vector<CalleeSavedInfo> &CSI,
586 bool ReverseOrder =
false) {
590 for (
auto &CS : CSI) {
591 int FI = CS.getFrameIdx();
599 std::reverse(NonLibcallCSI.
begin(), NonLibcallCSI.
end());
601 return NonLibcallCSI;
608 const std::vector<CalleeSavedInfo> &CSI,
609 bool ReverseOrder =
false) {
613 return CS.
getReg() == RISCV::X5;
620 const std::vector<CalleeSavedInfo> &CSI) {
624 for (
auto &CS : CSI) {
625 int FI = CS.getFrameIdx();
635 const std::vector<CalleeSavedInfo> &CSI) {
639 if (!RVFI->useSaveRestoreLibCalls(MF) && !RVFI->isPushable(MF))
640 return PushOrLibCallsCSI;
642 for (
const auto &CS : CSI) {
643 if (RVFI->useQCIInterrupt(MF)) {
654 PushOrLibCallsCSI.push_back(CS);
657 return PushOrLibCallsCSI;
662 const std::vector<CalleeSavedInfo> &CSI) {
666 if (!RVFI->useQCIInterrupt(MF))
667 return QCIInterruptCSI;
669 for (
const auto &CS : CSI) {
672 QCIInterruptCSI.push_back(CS);
675 return QCIInterruptCSI;
683 for (
unsigned i = 0; CSRegs[i]; ++i)
703 if (
LiveRegs.available(MRI, PreferredReg))
706 static const MCPhysReg CandidateRegs[] = {
707 RISCV::X5, RISCV::X6, RISCV::X7, RISCV::X28,
708 RISCV::X29, RISCV::X30, RISCV::X31,
711 for (
unsigned Reg : CandidateRegs) {
712 if (Reg != DontUseReg &&
LiveRegs.available(MRI, Reg))
719void RISCVFrameLowering::allocateAndProbeStackForRVV(
723 assert(Amount != 0 &&
"Did not need to adjust stack pointer for RVV.");
730 "No available scratch register for stack probing");
735 TII->mulImm(MF,
MBB,
MBBI,
DL, TargetReg, NumOfVReg, Flag);
740 CFIBuilder.buildDefCFA(TargetReg, -Amount);
749 CFIBuilder.buildDefCFARegister(
SPReg);
772 int64_t FixedOffset =
Offset.getFixed();
773 int64_t ScalableOffset =
Offset.getScalable();
774 unsigned DwarfVLenB =
TRI.getDwarfRegNum(RISCV::VLENB,
true);
779 Comment << (FixedOffset < 0 ?
" - " :
" + ") << std::abs(FixedOffset);
792 Comment << (ScalableOffset < 0 ?
" - " :
" + ") << std::abs(ScalableOffset)
799 assert(
Offset.getScalable() != 0 &&
"Did not need to adjust CFA for RVV");
801 std::string CommentBuffer;
804 unsigned DwarfReg =
TRI.getDwarfRegNum(
Reg,
true);
815 DefCfaExpr.
push_back(dwarf::DW_CFA_def_cfa_expression);
825 assert(
Offset.getScalable() != 0 &&
"Did not need to adjust CFA for RVV");
827 std::string CommentBuffer;
835 unsigned DwarfReg =
TRI.getDwarfRegNum(
Reg,
true);
836 DefCfaExpr.
push_back(dwarf::DW_CFA_expression);
849 uint64_t RealStackSize,
bool EmitCFI,
850 bool NeedProbe, uint64_t ProbeSize,
856 bool IsRV64 =
STI.is64Bit();
860 if (!NeedProbe ||
Offset <= ProbeSize) {
867 if (NeedProbe && DynAllocation) {
880 uint64_t CFAAdjust = RealStackSize -
Offset;
883 if (
Offset < ProbeSize * 5) {
884 uint64_t CurrentOffset = 0;
885 while (CurrentOffset + ProbeSize <=
Offset) {
895 CurrentOffset += ProbeSize;
900 uint64_t Residual =
Offset - CurrentOffset;
922 uint64_t Residual =
Offset - RoundedSize;
926 "No available scratch register for stack probing");
933 CFIBuilder.
buildDefCFA(TargetReg, RoundedSize + CFAAdjust);
964 case RISCV::QC_CM_PUSH:
965 case RISCV::QC_CM_PUSHFP:
977 case RISCV::QC_CM_POP:
988 return RISCV::CM_PUSH;
990 return UpdateFP ? RISCV::QC_CM_PUSHFP : RISCV::QC_CM_PUSH;
1001 return RISCV::CM_POP;
1003 return RISCV::QC_CM_POP;
1015 bool PreferAscendingLS =
STI.preferAscendingLoadStore();
1037 auto PossiblePush =
MBBI;
1044 determineFrameLayout(MF);
1079 unsigned LibCallFrameSize =
1081 RVFI->setLibCallStackSize(LibCallFrameSize);
1083 if (NeedsDwarfCFI) {
1094 uint64_t StackSize = RealStackSize - RVFI->getReservedSpillsSize();
1095 uint64_t RVVStackSize = RVFI->getRVVStackSize();
1098 if (RealStackSize == 0 && !MFI.
adjustsStack() && RVVStackSize == 0)
1103 if (
STI.isRegisterReservedByUser(
SPReg))
1105 MF.
getFunction(),
"Stack pointer required, but has been reserved."});
1109 if (FirstSPAdjustAmount) {
1110 StackSize = FirstSPAdjustAmount;
1111 RealStackSize = FirstSPAdjustAmount;
1114 if (RVFI->useQCIInterrupt(MF)) {
1119 if (NeedsDwarfCFI) {
1132 if (RVFI->isPushable(MF) && PossiblePush !=
MBB.end() &&
1133 isPush(PossiblePush->getOpcode())) {
1139 std::min(
alignDown(StackSize, 16),
static_cast<uint64_t
>(48));
1140 PossiblePush->getOperand(1).setImm(StackAdj);
1141 StackSize -= StackAdj;
1143 if (NeedsDwarfCFI) {
1155 uint64_t ProbeSize = TLI->getStackProbeSize(MF,
getStackAlign());
1156 bool DynAllocation =
1160 NeedProbe, ProbeSize, DynAllocation,
1178 if (NeedsDwarfCFI) {
1185 if (RISCV::GPRPairRegClass.
contains(Reg)) {
1186 MCRegister EvenReg = RI->getSubReg(Reg, RISCV::sub_gpr_even);
1187 MCRegister OddReg = RI->getSubReg(Reg, RISCV::sub_gpr_odd);
1198 if (
STI.isRegisterReservedByUser(
FPReg))
1200 MF.
getFunction(),
"Frame pointer required, but has been reserved."});
1206 if (!RVFI->hasImplicitFPUpdates(MF)) {
1217 uint64_t SecondSPAdjustAmount = 0;
1219 if (FirstSPAdjustAmount) {
1221 assert(SecondSPAdjustAmount > 0 &&
1222 "SecondSPAdjustAmount should be greater than zero");
1226 NeedProbe, ProbeSize, DynAllocation,
1232 allocateAndProbeStackForRVV(MF,
MBB,
MBBI,
DL, RVVStackSize,
1234 NeedsDwarfCFI && !
hasFP(MF), DynAllocation);
1243 if (NeedsDwarfCFI && !
hasFP(MF)) {
1258 if (RI->hasStackRealignment(MF)) {
1262 if (
isInt<12>(-(int64_t)MaxAlignment.value())) {
1265 .
addImm(-(int64_t)MaxAlignment.value())
1268 unsigned ShiftAmount =
Log2(MaxAlignment);
1280 if (NeedProbe && RVVStackSize == 0) {
1283 if (SecondSPAdjustAmount < ProbeSize &&
1284 SecondSPAdjustAmount + MaxAlignment.value() >= ProbeSize) {
1285 bool IsRV64 =
STI.is64Bit();
1311 uint64_t &StackSize,
1312 int64_t CFAOffset)
const {
1329 bool PreferAscendingLS =
STI.preferAscendingLoadStore();
1341 MBBI =
MBB.getLastNonDebugInstr();
1343 DL =
MBBI->getDebugLoc();
1345 MBBI =
MBB.getFirstTerminator();
1358 auto FirstScalarCSRRestoreInsn =
1365 uint64_t RealStackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
1367 uint64_t StackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
1369 RVFI->getReservedSpillsSize();
1370 uint64_t FPOffset = RealStackSize - RVFI->getVarArgsSaveSize();
1371 uint64_t RVVStackSize = RVFI->getRVVStackSize();
1373 bool RestoreSPFromFP = RI->hasStackRealignment(MF) ||
1378 if (!RestoreSPFromFP)
1383 if (NeedsDwarfCFI) {
1386 emitCalleeSavedRVVEpilogCFI(
MBB, FirstScalarCSRRestoreInsn);
1390 if (FirstSPAdjustAmount) {
1391 uint64_t SecondSPAdjustAmount =
1393 assert(SecondSPAdjustAmount > 0 &&
1394 "SecondSPAdjustAmount should be greater than zero");
1398 if (!RestoreSPFromFP)
1403 if (NeedsDwarfCFI && !
hasFP(MF))
1417 if (RestoreSPFromFP) {
1418 assert(
hasFP(MF) &&
"frame pointer should not have been eliminated");
1424 if (NeedsDwarfCFI &&
hasFP(MF))
1430 MBBI = std::next(FirstScalarCSRRestoreInsn,
1435 auto emitRestoreCFI = [&](
auto CSInfo) {
1436 for (
auto &CS : CSInfo) {
1439 if (RISCV::GPRPairRegClass.
contains(Reg)) {
1440 MCRegister EvenReg = RI->getSubReg(Reg, RISCV::sub_gpr_even);
1441 MCRegister OddReg = RI->getSubReg(Reg, RISCV::sub_gpr_odd);
1450 if (RVFI->useSaveRestoreLibCalls(MF)) {
1451 if (RVFI->hasShadowStack(MF)) {
1456 StackSize += RVFI->getLibCallStackSize();
1464 emitRestoreCFI(LibcallCSI);
1470 deallocateStack(MF,
MBB,
MBBI,
DL, StackSize,
1471 RVFI->getLibCallStackSize());
1483 if (RVFI->isPushable(MF) &&
MBBI !=
MBB.end() &&
isPop(
MBBI->getOpcode())) {
1489 std::min(
alignDown(StackSize, 16),
static_cast<uint64_t
>(48));
1490 MBBI->getOperand(1).setImm(StackAdj);
1491 StackSize -= StackAdj;
1494 deallocateStack(MF,
MBB,
MBBI,
DL, StackSize,
1495 RealStackSize - StackSize);
1498 if (NextI ==
MBB.end() || NextI->getOpcode() != RISCV::PseudoRET) {
1500 if (NeedsDwarfCFI) {
1518 deallocateStack(MF,
MBB,
MBBI,
DL, StackSize,
1519 RVFI->getQCIInterruptStackSize());
1533 std::array<TargetRegisterClass const *, 2> RegisterClasses = {
1534 &RISCV::GPRF16RegClass, &RISCV::GPRF32RegClass};
1535 std::array<unsigned, 2> SubIdx = {RISCV::sub_16, RISCV::sub_32};
1537 for (
auto [RegClass, SubReg] :
zip(RegisterClasses, SubIdx)) {
1538 if (RegClass->contains(
Reg)) {
1540 TRI.getMatchingSuperReg(
Reg, SubReg, &RISCV::GPRRegClass))
1546 "getPhysicalGPR called with unsupported register");
1552 if (!STI.hasStdExtF())
1556 assert(LargestFPRegClass);
1561 std::array<TargetRegisterClass const *, 3> RegisterClasses = {
1562 &RISCV::FPR16RegClass, &RISCV::FPR32RegClass, &RISCV::FPR64RegClass};
1563 std::array<unsigned, 3> SubIdx = {RISCV::sub_16, RISCV::sub_32,
1566 for (
auto [RegClass, SubReg] :
zip(RegisterClasses, SubIdx)) {
1567 if (RegClass->contains(
Reg)) {
1569 TRI.getMatchingSuperReg(
Reg, SubReg, LargestFPRegClass))
1579void RISCVFrameLowering::emitZeroCallUsedRegs(
BitVector RegsToZero,
1588 DL =
MBBI->getDebugLoc();
1591 const RISCVRegisterInfo &
TRI = *
STI.getRegisterInfo();
1592 const RISCVInstrInfo &
TII = *
STI.getInstrInfo();
1594 BitVector FinalRegsToZero(
TRI.getNumRegs());
1596 bool HasVRegister =
false;
1599 if (
TRI.isGeneralPurposeRegister(MF,
Reg)) {
1601 }
else if (RISCV::GPRPairRegClass.
contains(
Reg)) {
1602 FinalRegsToZero.set(
1604 FinalRegsToZero.set(
1606 }
else if (
TRI.isFPRegister(
Reg)) {
1608 FinalRegsToZero.set(MaybeReg.id());
1610 TRI.getMinimalPhysRegClass(
Reg))) {
1611 if (!
STI.hasVInstructions())
1613 HasVRegister =
true;
1615 for (MCRegister SubReg :
TRI.subregs_inclusive(
Reg)) {
1616 if (
TRI.subregs(SubReg).empty())
1617 FinalRegsToZero.set(SubReg.id());
1625 VLMUL, 32,
true,
true);
1627 MCRegister TemporaryReg = RISCV::NoRegister;
1628 for (MCRegister
Reg : FinalRegsToZero.set_bits()) {
1629 if (
TRI.isGeneralPurposeRegister(MF,
Reg)) {
1635 if (TemporaryReg == RISCV::NoRegister) {
1636 RS->enterBasicBlockEnd(
MBB);
1637 TemporaryReg =
RS->scavengeRegisterBackwards(RISCV::GPRRegClass,
MBBI,
1646 FinalRegsToZero.set(TemporaryReg.
id());
1655 for (MCRegister
Reg : FinalRegsToZero.set_bits())
1670 STI.preferAscendingLoadStore());
1678 "Unexpected stack ID for the frame object.");
1690 MinCSFI = std::min(CSI.front().getFrameIdx(), CSI.back().getFrameIdx());
1691 MaxCSFI = std::max(CSI.front().getFrameIdx(), CSI.back().getFrameIdx());
1694 bool IsInterruptCSR = RVFI->isSiFivePreemptibleInterrupt(MF) &&
1695 (FI == RVFI->getInterruptCSRFrameIndex(0) ||
1696 FI == RVFI->getInterruptCSRFrameIndex(1));
1697 if ((FI >= MinCSFI && FI <= MaxCSFI) || IsInterruptCSR) {
1700 if (FirstSPAdjustAmount)
1764 int64_t CLWSPMaxOffset = 252;
1765 int64_t CLDSPMaxOffset = 504;
1766 int64_t SPThreshold =
STI.is64Bit() ? CLDSPMaxOffset : CLWSPMaxOffset;
1767 if (SPOff >= 0 && SPOff <= SPThreshold)
1773 "Expected fixed object with stack realignment");
1774 assert(
hasFP(MF) &&
"Re-aligned stack must have frame pointer");
1778 if (FrameReg ==
FPReg) {
1797 "Can't index across variable sized realign");
1802 "Inconsistent stack layout");
1845 "Can't index across variable sized realign");
1847 RVFI->getRVVStackSize());
1854 int64_t ScalarLocalVarSize =
1856 RVFI->getVarArgsSaveSize() + RVFI->getRVVPadding();
1867 if (!BaseReg.isValid())
1887 for (
unsigned i = 0; CSRegs[i]; ++i) {
1888 unsigned CSReg = CSRegs[i];
1893 SavedRegs.
reset(CSReg);
1895 auto SubRegs =
TRI.subregs(CSReg);
1898 SavedRegs.
set(CSReg);
1899 for (
unsigned Reg : SubRegs)
1917 if (RVFI->isSiFivePreemptibleInterrupt(MF))
1918 SavedRegs.
set(RISCV::X5);
1921 if (RVFI->isPushable(MF) && SavedRegs.
test(RISCV::X26))
1922 SavedRegs.
set(RISCV::X27);
1929 bool UseZilsd = !
STI.is64Bit() &&
STI.hasStdExtZilsd() &&
1931 !RVFI->isPushable(MF) && !RVFI->useSaveRestoreLibCalls(MF);
1935 for (
unsigned i = 0; CSRegs[i]; ++i) {
1937 CSRSet.
insert(CSRegs[i]);
1942 for (
MCPhysReg Pair : RISCV::GPRPairRegClass) {
1946 MCRegister EvenReg =
TRI.getSubReg(Pair, RISCV::sub_gpr_even);
1947 MCRegister OddReg =
TRI.getSubReg(Pair, RISCV::sub_gpr_odd);
1961 for (
unsigned i = 0; CSRegs[i]; ++i) {
1963 bool CombineToSuperReg;
1964 if (RISCV::GPRPairRegClass.
contains(CSReg)) {
1965 MCRegister EvenReg =
TRI.getSubReg(CSReg, RISCV::sub_gpr_even);
1966 MCRegister OddReg =
TRI.getSubReg(CSReg, RISCV::sub_gpr_odd);
1968 SavedRegs.
test(EvenReg.
id()) && SavedRegs.
test(OddReg.
id());
1971 if (
hasFP(MF) && CSReg == RISCV::X8_X9)
1972 CombineToSuperReg =
false;
1974 auto SubRegs =
TRI.subregs(CSReg);
1976 !SubRegs.empty() &&
llvm::all_of(SubRegs, [&](
unsigned Reg) {
1977 return SavedRegs.
test(Reg);
1981 if (CombineToSuperReg)
1982 SavedRegs.
set(CSReg);
1989std::pair<int64_t, Align>
1990RISCVFrameLowering::assignRVVStackObjectOffsets(
MachineFunction &MF)
const {
1994 auto pushRVVObjects = [&](
int FIBegin,
int FIEnd) {
1995 for (
int I = FIBegin, E = FIEnd;
I != E; ++
I) {
2008 if (!RVVCSI.empty())
2009 pushRVVObjects(RVVCSI[0].getFrameIdx(),
2010 RVVCSI[RVVCSI.size() - 1].getFrameIdx() + 1);
2014 Align RVVStackAlign(16);
2017 if (!
ST.hasVInstructions()) {
2019 "Can't allocate scalable-vector objects without V instructions");
2020 return std::make_pair(0, RVVStackAlign);
2025 for (
int FI : ObjectsToAllocate) {
2037 RVVStackAlign = std::max(RVVStackAlign, ObjectAlign);
2050 if (
auto RVVStackAlignVScale = RVVStackAlign.value() / VScale) {
2051 if (
auto AlignmentPadding =
2053 StackSize += AlignmentPadding;
2054 for (
int FI : ObjectsToAllocate)
2059 return std::make_pair(StackSize, RVVStackAlign);
2065 static constexpr unsigned ScavSlotsNumRVVSpillScalableObject = 2;
2069 static constexpr unsigned ScavSlotsNumRVVSpillNonScalableObject = 1;
2073 static constexpr unsigned ScavSlotsADDIScalableObject = 1;
2075 static constexpr unsigned MaxScavSlotsNumKnown =
2076 std::max({ScavSlotsADDIScalableObject, ScavSlotsNumRVVSpillScalableObject,
2077 ScavSlotsNumRVVSpillNonScalableObject});
2079 unsigned MaxScavSlotsNum = 0;
2085 for (
auto &MO :
MI.operands()) {
2091 MaxScavSlotsNum = std::max(
2092 MaxScavSlotsNum, IsScalableVectorID
2093 ? ScavSlotsNumRVVSpillScalableObject
2094 : ScavSlotsNumRVVSpillNonScalableObject);
2095 }
else if (
MI.getOpcode() == RISCV::ADDI && IsScalableVectorID) {
2097 std::max(MaxScavSlotsNum, ScavSlotsADDIScalableObject);
2100 if (MaxScavSlotsNum == MaxScavSlotsNumKnown)
2101 return MaxScavSlotsNumKnown;
2103 return MaxScavSlotsNum;
2127 unsigned FnSize = 0;
2128 for (
auto &
MBB : MF) {
2129 for (
auto &
MI :
MBB) {
2147 if (
MI.isConditionalBranch())
2148 FnSize +=
TII.getInstSizeInBytes(
MI);
2149 if (
MI.isConditionalBranch() ||
MI.isUnconditionalBranch()) {
2151 FnSize += 2 + 8 + 2 + 2;
2153 FnSize += 4 + 8 + 4 + 4;
2157 FnSize +=
TII.getInstSizeInBytes(
MI);
2172 int64_t RVVStackSize;
2173 Align RVVStackAlign;
2174 std::tie(RVVStackSize, RVVStackAlign) = assignRVVStackObjectOffsets(MF);
2176 RVFI->setRVVStackSize(RVVStackSize);
2177 RVFI->setRVVStackAlign(RVVStackAlign);
2186 unsigned ScavSlotsNum = 0;
2196 if (IsLargeFunction)
2197 ScavSlotsNum = std::max(ScavSlotsNum, 1u);
2204 for (
unsigned I = 0;
I < ScavSlotsNum;
I++) {
2206 RegInfo->getSpillAlign(*RC));
2207 RS->addScavengingFrameIndex(FI);
2209 if (IsLargeFunction && RVFI->getBranchRelaxationScratchFrameIndex() == -1)
2210 RVFI->setBranchRelaxationScratchFrameIndex(FI);
2213 unsigned Size = RVFI->getReservedSpillsSize();
2215 int FrameIdx = Info.getFrameIdx();
2221 RVFI->setCalleeSavedStackSize(
Size);
2245 int64_t Amount =
MI->getOperand(0).getImm();
2251 if (
MI->getOpcode() == RISCV::ADJCALLSTACKDOWN)
2261 bool DynAllocation =
2265 true, ProbeSize, DynAllocation,
2267 inlineStackProbe(MF,
MBB);
2276 return MBB.erase(
MI);
2294 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
2300 if (RVFI->getReservedSpillsSize())
2305 if (!
isInt<12>(StackSize) && (CSI.size() > 0)) {
2318 if (
STI.hasStdExtZca()) {
2328 const uint64_t RVCompressLen =
STI.getXLen() * 8;
2335 auto CanCompress = [&](uint64_t CompressLen) ->
bool {
2336 if (StackSize <= 2047 + CompressLen ||
2337 (StackSize > 2048 * 2 - StackAlign &&
2338 StackSize <= 2047 * 2 + CompressLen) ||
2339 StackSize > 2048 * 3 - StackAlign)
2347 const uint64_t ADDI16SPCompressLen = 496;
2348 if (
STI.is64Bit() && CanCompress(ADDI16SPCompressLen))
2349 return ADDI16SPCompressLen;
2350 if (CanCompress(RVCompressLen))
2351 return RVCompressLen;
2353 return 2048 - StackAlign;
2360 std::vector<CalleeSavedInfo> &CSI)
const {
2367 if (RVFI->isSiFivePreemptibleInterrupt(MF)) {
2368 for (
int I = 0;
I < 2; ++
I) {
2369 int FI = RVFI->getInterruptCSRFrameIndex(
I);
2370 MFI.setIsCalleeSavedObjectIndex(FI,
true);
2378 if (RVFI->useQCIInterrupt(MF)) {
2382 if (RVFI->isPushable(MF)) {
2389 unsigned OnlyPushIfMoreThan = RVFI->useQCIInterrupt(MF) ? 2 : 0;
2390 if (PushedRegNum > OnlyPushIfMoreThan) {
2391 RVFI->setRVPushRegs(PushedRegNum);
2392 RVFI->setRVPushStackSize(
alignTo((
STI.getXLen() / 8) * PushedRegNum, 16));
2396 for (
auto &CS : CSI) {
2399 unsigned Size = RegInfo->getSpillSize(*RC);
2401 if (RVFI->useQCIInterrupt(MF)) {
2403 return P.first == CS.getReg();
2406 int64_t
Offset = FFI->second * (int64_t)
Size;
2408 int FrameIdx = MFI.CreateFixedSpillStackObject(
Size,
Offset);
2410 CS.setFrameIdx(FrameIdx);
2415 if (RVFI->useSaveRestoreLibCalls(MF) || RVFI->isPushable(MF)) {
2418 unsigned RegNum = std::distance(std::begin(
FixedCSRFIMap), FII);
2422 if (RVFI->getPushPopKind(MF) ==
2424 Offset = -int64_t(RVFI->getRVPushRegs() - RegNum) *
Size;
2428 if (RVFI->useQCIInterrupt(MF))
2431 int FrameIdx = MFI.CreateFixedSpillStackObject(
Size,
Offset);
2433 CS.setFrameIdx(FrameIdx);
2439 if (!
STI.is64Bit() &&
STI.hasStdExtZilsd() &&
2440 RISCV::GPRPairRegClass.contains(Reg)) {
2441 Align PairAlign =
STI.getZilsdAlign();
2442 int FrameIdx = MFI.CreateStackObject(8, PairAlign,
true);
2443 MFI.setIsCalleeSavedObjectIndex(FrameIdx,
true);
2444 CS.setFrameIdx(FrameIdx);
2449 Align Alignment = RegInfo->getSpillAlign(*RC);
2454 int FrameIdx = MFI.CreateStackObject(
Size, Alignment,
true);
2455 MFI.setIsCalleeSavedObjectIndex(FrameIdx,
true);
2456 CS.setFrameIdx(FrameIdx);
2461 if (RVFI->useQCIInterrupt(MF)) {
2464 MFI.CreateFixedSpillStackObject(
2468 if (RVFI->isPushable(MF)) {
2471 if (int64_t PushSize = RVFI->getRVPushStackSize())
2472 MFI.CreateFixedSpillStackObject(PushSize, -PushSize - QCIOffset);
2473 }
else if (
int LibCallRegs =
getLibCallID(MF, CSI) + 1) {
2474 int64_t LibCallFrameSize =
2476 MFI.CreateFixedSpillStackObject(LibCallFrameSize, -LibCallFrameSize);
2491 if (
MI !=
MBB.end() && !
MI->isDebugInstr())
2492 DL =
MI->getDebugLoc();
2501 ? RISCV::QC_C_MIENTER_NEST
2502 : RISCV::QC_C_MIENTER))
2512 if (PushedRegNum > 0) {
2520 PushBuilder.
addImm(RegEnc);
2523 for (
unsigned i = 0; i < PushedRegNum; i++)
2536 for (
auto &CS : CSI)
2541 const auto &UnmanagedCSI =
2546 for (
auto &CS : CSInfo) {
2550 TII.storeRegToStackSlot(
MBB,
MI, Reg, !
MBB.isLiveIn(Reg),
2555 storeRegsToStackSlots(UnmanagedCSI);
2556 storeRegsToStackSlots(RVVCSI);
2562 return RISCV::VRRegClass.contains(BaseReg) ? 1
2563 : RISCV::VRM2RegClass.contains(BaseReg) ? 2
2564 : RISCV::VRM4RegClass.contains(BaseReg) ? 4
2568void RISCVFrameLowering::emitCalleeSavedRVVPrologCFI(
2572 RISCVMachineFunctionInfo *RVFI = MF->
getInfo<RISCVMachineFunctionInfo>();
2573 const RISCVRegisterInfo &
TRI = *
STI.getRegisterInfo();
2584 FixedSize -= ScalarLocalVarSize;
2588 for (
auto &CS : RVVCSI) {
2590 int FI = CS.getFrameIdx();
2593 for (
unsigned i = 0; i < NumRegs; ++i) {
2601void RISCVFrameLowering::emitCalleeSavedRVVEpilogCFI(
2605 const RISCVRegisterInfo &
TRI = *
STI.getRegisterInfo();
2609 for (
auto &CS : RVVCSI) {
2612 for (
unsigned i = 0; i < NumRegs; ++i)
2613 CFIHelper.buildRestore(BaseReg + i);
2626 if (
MI !=
MBB.end() && !
MI->isDebugInstr())
2627 DL =
MI->getDebugLoc();
2635 const auto &UnmanagedCSI =
2640 for (
auto &CS : CSInfo) {
2644 RISCV::NoSubRegister,
2647 "loadRegFromStackSlot didn't insert any code!");
2650 loadRegFromStackSlot(RVVCSI);
2651 loadRegFromStackSlot(UnmanagedCSI);
2657 assert(
MI->getOpcode() == RISCV::QC_C_MILEAVERET &&
2658 "Unexpected QCI Interrupt Return Instruction");
2663 if (PushedRegNum > 0) {
2670 PopBuilder.
addImm(RegEnc);
2680 loadRegFromStackSlot(CSI);
2692 for (
auto &CS : CSI)
2697 if (
MI !=
MBB.end() &&
MI->getOpcode() == RISCV::PseudoRET) {
2699 MI->eraseFromParent();
2731 if (
STI.preferVsetvliOverReadVLENB() &&
2732 (
MBB.isLiveIn(RISCV::VTYPE) ||
MBB.isLiveIn(RISCV::VL)))
2743 RS.enterBasicBlock(*TmpMBB);
2744 return !RS.isRegUsed(RISCV::X5);
2763 if (
MBB.succ_size() > 1)
2780 return !MI.isDebugInstr();
2796 assert(TargetReg != RISCV::X2 &&
"New top of stack cannot already be in SP");
2797 assert(ScratchReg != RISCV::X2 &&
"Scratch register cannot be SP");
2798 assert(TargetReg != ScratchReg &&
"Target and scratch must be different");
2805 bool IsRV64 = Subtarget.is64Bit();
2806 Align StackAlign = Subtarget.getFrameLowering()->getStackAlign();
2813 MF.
insert(MBBInsertPoint, LoopTestMBB);
2815 MF.
insert(MBBInsertPoint, ExitMBB);
2819 TII->movImm(
MBB,
MBBI,
DL, ScratchReg, ProbeSize, Flags);
2830 TII->get(IsRV64 ? RISCV::SD : RISCV::SW))
2865 MBB.addSuccessor(LoopTestMBB);
2875 SmallVector<MachineInstr *, 4> ToReplace;
2876 for (MachineInstr &
MI :
MBB) {
2877 unsigned Opc =
MI.getOpcode();
2878 if (
Opc == RISCV::PROBED_STACKALLOC ||
2879 Opc == RISCV::PROBED_STACKALLOC_RVV) {
2884 for (MachineInstr *
MI : ToReplace) {
2885 if (
MI->getOpcode() == RISCV::PROBED_STACKALLOC ||
2886 MI->getOpcode() == RISCV::PROBED_STACKALLOC_RVV) {
2889 Register TargetReg =
MI->getOperand(0).getReg();
2895 "No available scratch register for stack probe loop");
2898 (
MI->getOpcode() == RISCV::PROBED_STACKALLOC_RVV));
static void getLiveRegsForEntryMBB(LivePhysRegs &LiveRegs, const MachineBasicBlock &MBB)
static MCCFIInstruction createDefCFAExpression(const TargetRegisterInfo &TRI, unsigned Reg, const StackOffset &Offset)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file contains constants used for implementing Dwarf debug support.
const HexagonInstrInfo * TII
static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL)
static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL)
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
static uint64_t estimateFunctionSizeInBytes(const LoongArchInstrInfo *TII, const MachineFunction &MF)
static void emitStackProbeInline(MachineBasicBlock::iterator MBBI, DebugLoc DL, Register TargetReg)
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static constexpr uint64_t QCIInterruptPushAmount
static void emitSiFiveCLICStackSwap(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MachineInstr::MIFlag FrameFlag)
static unsigned getPushOpcode(RISCVMachineFunctionInfo::PushPopKind Kind, bool UpdateFP)
static void emitSiFiveCLICPreemptibleSaves(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL)
static MCRegister getRVVBaseRegister(const RISCVRegisterInfo &TRI, const Register &Reg)
static void createSiFivePreemptibleInterruptFrameEntries(MachineFunction &MF, RISCVMachineFunctionInfo &RVFI)
static constexpr MCPhysReg FPReg
static const char * getRestoreLibCallName(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI)
static bool needsDwarfCFI(const MachineFunction &MF)
Returns true if DWARF CFI instructions ("frame moves") should be emitted.
static constexpr MCPhysReg SPReg
static const char * getSpillLibCallName(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI)
static bool hasRVVFrameObject(const MachineFunction &MF)
static SmallVector< CalleeSavedInfo, 8 > getUnmanagedInterruptCSI(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI, bool ReverseOrder=false)
static void appendScalableVectorExpression(const TargetRegisterInfo &TRI, SmallVectorImpl< char > &Expr, StackOffset Offset, llvm::raw_string_ostream &Comment)
static SmallVector< CalleeSavedInfo, 8 > getQCISavedInfo(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI)
static SmallVector< CalleeSavedInfo, 8 > getRVVCalleeSavedInfo(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI)
static SmallVector< CalleeSavedInfo, 8 > getUnmanagedCSI(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI, bool ReverseOrder=false)
static void emitSiFiveCLICPreemptibleRestores(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, CFIInstBuilder &CFIBuilder, const DebugLoc &DL)
static bool isPop(unsigned Opcode)
static unsigned getCalleeSavedRVVNumRegs(const Register &BaseReg)
static MCCFIInstruction createDefCFAOffset(const TargetRegisterInfo &TRI, Register Reg, StackOffset Offset)
static Align getABIStackAlignment(RISCVABI::ABI ABI)
static unsigned getPopOpcode(RISCVMachineFunctionInfo::PushPopKind Kind)
static SmallVector< CalleeSavedInfo, 8 > getPushOrLibCallsSavedInfo(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI)
static int getLibCallID(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI)
static const std::pair< MCPhysReg, int8_t > FixedCSRFIQCIInterruptMap[]
static bool isPush(unsigned Opcode)
static constexpr MCPhysReg RAReg
static MCRegister getLargestFPRegisterOrZero(const RISCVSubtarget &STI, const TargetRegisterInfo &TRI, MCRegister Reg)
static const MCPhysReg FixedCSRFIMap[]
static int getSiFiveCLICScratchFrameIndex(const MachineFunction &MF)
static unsigned getNumPushPopRegs(const std::vector< CalleeSavedInfo > &CSI)
static MCRegister getPhysicalGPR(const TargetRegisterInfo &TRI, MCRegister Reg)
static unsigned getScavSlotsNumForRVV(MachineFunction &MF)
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
Check if the array is empty.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool test(unsigned Idx) const
Returns true if bit Idx is set.
BitVector & reset()
Reset all bits in the bitvector.
BitVector & set()
Set all bits in the bitvector.
iterator_range< const_set_bits_iterator > set_bits() const
Helper class for creating CFI instructions and inserting them into MIR.
void buildEscape(StringRef Bytes, StringRef Comment="") const
void buildDefCFAOffset(int64_t Offset, MCSymbol *Label=nullptr) const
void buildRestore(MCRegister Reg) const
void buildDefCFARegister(MCRegister Reg) const
void buildOffset(MCRegister Reg, int64_t Offset) const
void insertCFIInst(const MCCFIInstruction &CFIInst) const
void buildDefCFA(MCRegister Reg, int64_t Offset) const
void setInsertPoint(MachineBasicBlock::iterator IP)
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
MCRegister getReg() const
Diagnostic information for unsupported feature in backend.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasOptNone() const
Do not optimize this function (-O0).
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
A set of physical registers with utility functions to track liveness when walking backward/forward th...
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals, SMLoc Loc={}, StringRef Comment="")
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
Wrapper class representing physical registers. Should be passed by value.
constexpr unsigned id() const
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI MachineBasicBlock * getFallThrough(bool JumpToFallThrough=true)
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
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 void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
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.
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.
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
LLVM_ABI void ensureMaxAlignment(Align Alignment)
Make sure the function's frame is at least Align bytes aligned.
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.
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool isMaxCallFrameSizeComputed() const
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.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
uint8_t getStackID(int ObjectIdx) 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.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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.
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...
const MachineBasicBlock & front() const
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned TargetFlags=0) const
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
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.
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
LLVM_ABI void copyImplicitOps(MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const BitVector & getUsedPhysRegsMask() const
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
LLVM_ABI const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
LLVM_ABI void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
uint64_t getStackThreshold() const override
getStackThreshold - Return the maximum stack size
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...
bool hasBP(const MachineFunction &MF) const
void allocateStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, MachineFunction &MF, uint64_t Offset, uint64_t RealStackSize, bool EmitCFI, bool NeedProbe, uint64_t ProbeSize, bool DynAllocation, MachineInstr::MIFlag Flag) const
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
bool hasFPImpl(const MachineFunction &MF) const override
Register findScratchNonCalleeSaveRegister(MachineBasicBlock *MBB, Register PreferredReg, Register DontUseReg=Register()) const
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...
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Register getInitialCFARegister(const MachineFunction &MF) const override
Return initial CFA register value i.e.
const RISCVSubtarget & STI
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool isSupportedStackID(TargetStackID::Value ID) const override
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
TargetStackID::Value getStackIDForScalableVectors() const override
Returns the StackID that scalable vectors should be associated with.
int getInitialCFAOffset(const MachineFunction &MF) const override
Return initial CFA offset value i.e.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
RISCVFrameLowering(const RISCVSubtarget &STI)
uint64_t getStackSizeWithRVVPadding(const MachineFunction &MF) const
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
bool isPushable(const MachineFunction &MF) const
InterruptStackKind getInterruptStackKind(const MachineFunction &MF) const
bool useSiFiveInterrupt(const MachineFunction &MF) const
bool isSiFivePreemptibleInterrupt(const MachineFunction &MF) const
void pushInterruptCSRFrameIndex(int FI)
PushPopKind getPushPopKind(const MachineFunction &MF) const
bool hasShadowStack(const MachineFunction &MF) const
uint64_t getRVVPadding() const
unsigned getRVPushRegs() const
bool useSaveRestoreLibCalls(const MachineFunction &MF) const
unsigned getVarArgsSaveSize() const
bool useQCIInterrupt(const MachineFunction &MF) const
unsigned getCalleeSavedStackSize() const
TargetRegisterClass const * getLargestFPRegClass() const
bool hasVInstructions() const
const RISCVRegisterInfo * getRegisterInfo() const override
const RISCVInstrInfo * getInstrInfo() const override
bool hasInlineStackProbe(const MachineFunction &MF) const override
True if stack clash protection is enabled for this functions.
unsigned getStackProbeSize(const MachineFunction &MF, Align StackAlign) const
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
Represents a location in source code.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool contains(const T &V) const
Check if the SmallSet contains the given element.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
StringRef str() const
Explicit conversion to StringRef.
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.
StackOffset holds a fixed and a scalable offset in bytes.
int64_t getFixed() const
Returns the fixed component of the stack.
int64_t getScalable() const
Returns the scalable component of the stack.
static StackOffset get(int64_t Fixed, int64_t Scalable)
static StackOffset getScalable(int64_t Scalable)
static StackOffset getFixed(int64_t Fixed)
Represent a constant reference to a string, i.e.
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...
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
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...
int alignSPAdjust(int SPAdj) const
alignSPAdjust - This method aligns the stack adjustment to the correct alignment.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
self_iterator getIterator()
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
static VLMUL encodeLMUL(unsigned LMUL, bool Fractional)
LLVM_ABI unsigned encodeVTYPE(VLMUL VLMUL, unsigned SEW, bool TailAgnostic, bool MaskAgnostic, bool AltFmt=false)
static unsigned encodeRegListNumRegs(unsigned NumRegs)
static constexpr unsigned RVVBitsPerBlock
bool isRVVSpill(const MachineInstr &MI)
static constexpr unsigned RVVBytesPerBlock
BaseReg
Stack frame base register. Bit 0 of FREInfo.Info.
This is an optimization pass for GlobalISel generic memory operations.
IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It, then continue incrementing it while it points to a debug instruction.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
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 T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
auto make_first_range(ContainerTy &&c)
Given a container of pairs, return a range over the first elements.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
void appendLEB128(SmallVectorImpl< U > &Buffer, T Value)
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.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
MCRegisterClass TargetRegisterClass
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
static bool isRVVRegClass(const TargetRegisterClass *RC)
void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator II, const DebugLoc &DL, Register DestReg, Register SrcReg, StackOffset Offset, MachineInstr::MIFlag Flag, MaybeAlign RequiredAlign) const