31#define DEBUG_TYPE "riscv-frame"
65 RISCV::X18, RISCV::X19, RISCV::X20,
66 RISCV::X21, RISCV::X22, RISCV::X23,
67 RISCV::X24, RISCV::X25, RISCV::X26,
116 STI.hasStdExtZimop();
117 bool HasSWShadowStack =
119 if (!HasHWShadowStack && !HasSWShadowStack)
132 if (HasHWShadowStack) {
133 if (STI.hasStdExtZcmop()) {
134 static_assert(
RAReg == RISCV::X1,
"C.SSPUSH only accepts X1");
148 bool IsRV64 = STI.is64Bit();
149 int64_t SlotSize = STI.getXLen() / 8;
169 char DwarfSCSReg =
TRI->getDwarfRegNum(SCSPReg,
true);
170 assert(DwarfSCSReg < 32 &&
"SCS Register should be < 32 (X3).");
172 char Offset =
static_cast<char>(-SlotSize) & 0x7f;
173 const char CFIInst[] = {
174 dwarf::DW_CFA_val_expression,
177 static_cast<char>(
unsigned(dwarf::DW_OP_breg0 + DwarfSCSReg)),
190 STI.hasStdExtZimop();
191 bool HasSWShadowStack =
193 if (!HasHWShadowStack && !HasSWShadowStack)
203 if (HasHWShadowStack) {
212 bool IsRV64 = STI.is64Bit();
213 int64_t SlotSize = STI.getXLen() / 8;
239 if (!RVFI->isSiFiveStackSwapInterrupt(MF))
245 assert(STI.hasVendorXSfmclic() &&
"Stack Swapping Requires XSfmclic");
249 .
addImm(RISCVSysReg::sf_mscratchcsw)
270 for (
int I = 0;
I < 2; ++
I) {
283 if (!RVFI->isSiFivePreemptibleInterrupt(MF))
298 TII->storeRegToStackSlot(
MBB,
MBBI, RISCV::X8,
true,
299 RVFI->getInterruptCSRFrameIndex(0),
302 TII->storeRegToStackSlot(
MBB,
MBBI, RISCV::X9,
true,
303 RVFI->getInterruptCSRFrameIndex(1),
312 .
addImm(RISCVSysReg::mcause)
317 .
addImm(RISCVSysReg::mepc)
324 .
addImm(RISCVSysReg::mstatus)
335 if (!RVFI->isSiFivePreemptibleInterrupt(MF))
346 .
addImm(RISCVSysReg::mstatus)
355 .
addImm(RISCVSysReg::mepc)
360 .
addImm(RISCVSysReg::mcause)
366 TII->loadRegFromStackSlot(
MBB,
MBBI, RISCV::X9,
367 RVFI->getInterruptCSRFrameIndex(1),
370 TII->loadRegFromStackSlot(
MBB,
MBBI, RISCV::X8,
371 RVFI->getInterruptCSRFrameIndex(0),
381 const std::vector<CalleeSavedInfo> &CSI) {
384 if (CSI.empty() || !RVFI->useSaveRestoreLibCalls(MF))
391 if (CS.getFrameIdx() < 0)
392 MaxReg = std::max(MaxReg.
id(), CS.getReg().id());
397 switch (MaxReg.
id()) {
401 case RISCV::X27:
return 12;
402 case RISCV::X26:
return 11;
403 case RISCV::X25:
return 10;
404 case RISCV::X24:
return 9;
405 case RISCV::X23:
return 8;
406 case RISCV::X22:
return 7;
407 case RISCV::X21:
return 6;
408 case RISCV::X20:
return 5;
409 case RISCV::X19:
return 4;
410 case RISCV::X18:
return 3;
411 case RISCV::X9:
return 2;
412 case FPReg:
return 1;
413 case RAReg:
return 0;
422 const std::vector<CalleeSavedInfo> &CSI) {
423 static const char *
const SpillLibCalls[] = {
442 return SpillLibCalls[LibCallID];
449 const std::vector<CalleeSavedInfo> &CSI) {
450 static const char *
const RestoreLibCalls[] = {
461 "__riscv_restore_10",
462 "__riscv_restore_11",
469 return RestoreLibCalls[LibCallID];
474 unsigned NumPushPopRegs = 0;
475 for (
auto &CS : CSI) {
479 unsigned RegNum = std::distance(std::begin(
FixedCSRFIMap), FII);
480 NumPushPopRegs = std::max(NumPushPopRegs, RegNum + 1);
483 assert(NumPushPopRegs != 12 &&
"x26 requires x27 to also be pushed");
484 return NumPushPopRegs;
528 TRI->hasStackRealignment(MF);
532void RISCVFrameLowering::determineFrameLayout(
MachineFunction &MF)
const {
540 if (RVFI->useQCIInterrupt(MF))
547 FrameSize =
alignTo(FrameSize, StackAlign);
557 if (RVFI->getRVVStackSize() && (!
hasFP(MF) ||
TRI->hasStackRealignment(MF))) {
558 int ScalarLocalVarSize = FrameSize - RVFI->getCalleeSavedStackSize() -
559 RVFI->getVarArgsSaveSize();
560 if (
auto RVVPadding =
562 RVFI->setRVVPadding(RVVPadding);
577 const std::vector<CalleeSavedInfo> &CSI,
578 bool ReverseOrder =
false) {
582 for (
auto &CS : CSI) {
583 int FI = CS.getFrameIdx();
591 std::reverse(NonLibcallCSI.
begin(), NonLibcallCSI.
end());
593 return NonLibcallCSI;
598 const std::vector<CalleeSavedInfo> &CSI) {
602 for (
auto &CS : CSI) {
603 int FI = CS.getFrameIdx();
613 const std::vector<CalleeSavedInfo> &CSI) {
617 if (!RVFI->useSaveRestoreLibCalls(MF) && !RVFI->isPushable(MF))
618 return PushOrLibCallsCSI;
620 for (
const auto &CS : CSI) {
621 if (RVFI->useQCIInterrupt(MF)) {
632 PushOrLibCallsCSI.push_back(CS);
635 return PushOrLibCallsCSI;
640 const std::vector<CalleeSavedInfo> &CSI) {
644 if (!RVFI->useQCIInterrupt(MF))
645 return QCIInterruptCSI;
647 for (
const auto &CS : CSI) {
650 QCIInterruptCSI.push_back(CS);
653 return QCIInterruptCSI;
656void RISCVFrameLowering::allocateAndProbeStackForRVV(
660 assert(Amount != 0 &&
"Did not need to adjust stack pointer for RVV.");
665 const RISCVInstrInfo *
TII =
STI.getInstrInfo();
670 TII->mulImm(MF,
MBB,
MBBI,
DL, TargetReg, NumOfVReg, Flag);
675 CFIBuilder.buildDefCFA(TargetReg, -Amount);
684 CFIBuilder.buildDefCFARegister(
SPReg);
707 int64_t FixedOffset =
Offset.getFixed();
708 int64_t ScalableOffset =
Offset.getScalable();
709 unsigned DwarfVLenB =
TRI.getDwarfRegNum(RISCV::VLENB,
true);
714 Comment << (FixedOffset < 0 ?
" - " :
" + ") << std::abs(FixedOffset);
727 Comment << (ScalableOffset < 0 ?
" - " :
" + ") << std::abs(ScalableOffset)
734 assert(
Offset.getScalable() != 0 &&
"Did not need to adjust CFA for RVV");
736 std::string CommentBuffer;
739 unsigned DwarfReg =
TRI.getDwarfRegNum(
Reg,
true);
750 DefCfaExpr.
push_back(dwarf::DW_CFA_def_cfa_expression);
760 assert(
Offset.getScalable() != 0 &&
"Did not need to adjust CFA for RVV");
762 std::string CommentBuffer;
770 unsigned DwarfReg =
TRI.getDwarfRegNum(
Reg,
true);
771 DefCfaExpr.
push_back(dwarf::DW_CFA_expression);
784 uint64_t RealStackSize,
bool EmitCFI,
791 bool IsRV64 =
STI.is64Bit();
795 if (!NeedProbe ||
Offset <= ProbeSize) {
802 if (NeedProbe && DynAllocation) {
815 if (
Offset < ProbeSize * 5) {
819 while (CurrentOffset + ProbeSize <=
Offset) {
829 CurrentOffset += ProbeSize;
896 case RISCV::QC_CM_PUSH:
897 case RISCV::QC_CM_PUSHFP:
909 case RISCV::QC_CM_POP:
920 return RISCV::CM_PUSH;
922 return UpdateFP ? RISCV::QC_CM_PUSHFP : RISCV::QC_CM_PUSH;
933 return RISCV::CM_POP;
935 return RISCV::QC_CM_POP;
947 bool PreferAscendingLS =
STI.preferAscendingLoadStore();
969 auto PossiblePush =
MBBI;
976 determineFrameLayout(MF);
1011 unsigned LibCallFrameSize =
1013 RVFI->setLibCallStackSize(LibCallFrameSize);
1015 if (NeedsDwarfCFI) {
1026 uint64_t StackSize = RealStackSize - RVFI->getReservedSpillsSize();
1027 uint64_t RVVStackSize = RVFI->getRVVStackSize();
1030 if (RealStackSize == 0 && !MFI.
adjustsStack() && RVVStackSize == 0)
1035 if (
STI.isRegisterReservedByUser(
SPReg))
1037 MF.
getFunction(),
"Stack pointer required, but has been reserved."});
1041 if (FirstSPAdjustAmount) {
1042 StackSize = FirstSPAdjustAmount;
1043 RealStackSize = FirstSPAdjustAmount;
1046 if (RVFI->useQCIInterrupt(MF)) {
1051 if (NeedsDwarfCFI) {
1064 if (RVFI->isPushable(MF) && PossiblePush !=
MBB.end() &&
1065 isPush(PossiblePush->getOpcode())) {
1072 PossiblePush->getOperand(1).setImm(StackAdj);
1073 StackSize -= StackAdj;
1075 if (NeedsDwarfCFI) {
1088 bool DynAllocation =
1092 NeedProbe, ProbeSize, DynAllocation,
1109 if (NeedsDwarfCFI) {
1116 if (RISCV::GPRPairRegClass.
contains(Reg)) {
1117 MCRegister EvenReg = RI->getSubReg(Reg, RISCV::sub_gpr_even);
1118 MCRegister OddReg = RI->getSubReg(Reg, RISCV::sub_gpr_odd);
1129 if (
STI.isRegisterReservedByUser(
FPReg))
1131 MF.
getFunction(),
"Frame pointer required, but has been reserved."});
1137 if (!RVFI->hasImplicitFPUpdates(MF)) {
1150 if (FirstSPAdjustAmount) {
1152 assert(SecondSPAdjustAmount > 0 &&
1153 "SecondSPAdjustAmount should be greater than zero");
1157 NeedProbe, ProbeSize, DynAllocation,
1163 allocateAndProbeStackForRVV(MF,
MBB,
MBBI,
DL, RVVStackSize,
1165 NeedsDwarfCFI && !
hasFP(MF), DynAllocation);
1174 if (NeedsDwarfCFI && !
hasFP(MF)) {
1189 if (RI->hasStackRealignment(MF)) {
1193 if (
isInt<12>(-(
int)MaxAlignment.value())) {
1196 .
addImm(-(
int)MaxAlignment.value())
1199 unsigned ShiftAmount =
Log2(MaxAlignment);
1211 if (NeedProbe && RVVStackSize == 0) {
1214 if (SecondSPAdjustAmount < ProbeSize &&
1215 SecondSPAdjustAmount + MaxAlignment.value() >= ProbeSize) {
1216 bool IsRV64 =
STI.is64Bit();
1243 int64_t CFAOffset)
const {
1260 bool PreferAscendingLS =
STI.preferAscendingLoadStore();
1272 MBBI =
MBB.getLastNonDebugInstr();
1274 DL =
MBBI->getDebugLoc();
1276 MBBI =
MBB.getFirstTerminator();
1289 auto FirstScalarCSRRestoreInsn =
1296 uint64_t RealStackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
1298 uint64_t StackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
1300 RVFI->getReservedSpillsSize();
1301 uint64_t FPOffset = RealStackSize - RVFI->getVarArgsSaveSize();
1302 uint64_t RVVStackSize = RVFI->getRVVStackSize();
1304 bool RestoreSPFromFP = RI->hasStackRealignment(MF) ||
1309 if (!RestoreSPFromFP)
1314 if (NeedsDwarfCFI) {
1317 emitCalleeSavedRVVEpilogCFI(
MBB, FirstScalarCSRRestoreInsn);
1321 if (FirstSPAdjustAmount) {
1324 assert(SecondSPAdjustAmount > 0 &&
1325 "SecondSPAdjustAmount should be greater than zero");
1329 if (!RestoreSPFromFP)
1334 if (NeedsDwarfCFI && !
hasFP(MF))
1348 if (RestoreSPFromFP) {
1349 assert(
hasFP(MF) &&
"frame pointer should not have been eliminated");
1355 if (NeedsDwarfCFI &&
hasFP(MF))
1361 MBBI = std::next(FirstScalarCSRRestoreInsn,
1370 deallocateStack(MF,
MBB,
MBBI,
DL, StackSize,
1371 RVFI->getLibCallStackSize());
1379 if (NeedsDwarfCFI) {
1384 if (RISCV::GPRPairRegClass.
contains(Reg)) {
1385 MCRegister EvenReg = RI->getSubReg(Reg, RISCV::sub_gpr_even);
1386 MCRegister OddReg = RI->getSubReg(Reg, RISCV::sub_gpr_odd);
1395 if (RVFI->isPushable(MF) &&
MBBI !=
MBB.end() &&
isPop(
MBBI->getOpcode())) {
1402 MBBI->getOperand(1).setImm(StackAdj);
1403 StackSize -= StackAdj;
1406 deallocateStack(MF,
MBB,
MBBI,
DL, StackSize,
1407 RealStackSize - StackSize);
1410 if (NextI ==
MBB.end() || NextI->getOpcode() != RISCV::PseudoRET) {
1412 if (NeedsDwarfCFI) {
1432 deallocateStack(MF,
MBB,
MBBI,
DL, StackSize,
1433 RVFI->getQCIInterruptStackSize());
1442void RISCVFrameLowering::emitZeroCallUsedRegs(
BitVector RegsToZero,
1450 DL =
MBBI->getDebugLoc();
1458 if (
TRI.isGeneralPurposeRegister(MF, Reg))
1474 STI.preferAscendingLoadStore());
1482 "Unexpected stack ID for the frame object.");
1494 MinCSFI = std::min(CSI.front().getFrameIdx(), CSI.back().getFrameIdx());
1495 MaxCSFI = std::max(CSI.front().getFrameIdx(), CSI.back().getFrameIdx());
1498 if (FI >= MinCSFI && FI <= MaxCSFI) {
1501 if (FirstSPAdjustAmount)
1565 int64_t CLWSPMaxOffset = 252;
1566 int64_t CLDSPMaxOffset = 504;
1567 int64_t SPThreshold =
STI.is64Bit() ? CLDSPMaxOffset : CLWSPMaxOffset;
1568 if (SPOff >= 0 && SPOff <= SPThreshold)
1574 "Expected fixed object with stack realignment");
1575 assert(
hasFP(MF) &&
"Re-aligned stack must have frame pointer");
1579 if (FrameReg ==
FPReg) {
1598 "Can't index across variable sized realign");
1603 "Inconsistent stack layout");
1646 "Can't index across variable sized realign");
1648 RVFI->getRVVStackSize());
1655 int64_t ScalarLocalVarSize =
1657 RVFI->getVarArgsSaveSize() + RVFI->getRVVPadding();
1668 if (!BaseReg.isValid())
1688 for (
unsigned i = 0; CSRegs[i]; ++i) {
1689 unsigned CSReg = CSRegs[i];
1694 SavedRegs.
reset(CSReg);
1696 auto SubRegs =
TRI.subregs(CSReg);
1699 SavedRegs.
set(CSReg);
1700 for (
unsigned Reg : SubRegs)
1718 if (RVFI->isPushable(MF) && SavedRegs.
test(RISCV::X26))
1719 SavedRegs.
set(RISCV::X27);
1726 bool UseZilsd = !
STI.is64Bit() &&
STI.hasStdExtZilsd() &&
1728 !RVFI->isPushable(MF) && !RVFI->useSaveRestoreLibCalls(MF);
1732 for (
unsigned i = 0; CSRegs[i]; ++i) {
1734 CSRSet.
insert(CSRegs[i]);
1739 for (
MCPhysReg Pair : RISCV::GPRPairRegClass) {
1743 MCPhysReg EvenReg =
TRI.getSubReg(Pair, RISCV::sub_gpr_even);
1744 MCPhysReg OddReg =
TRI.getSubReg(Pair, RISCV::sub_gpr_odd);
1758 for (
unsigned i = 0; CSRegs[i]; ++i) {
1759 unsigned CSReg = CSRegs[i];
1760 bool CombineToSuperReg;
1761 if (RISCV::GPRPairRegClass.
contains(CSReg)) {
1762 MCPhysReg EvenReg =
TRI.getSubReg(CSReg, RISCV::sub_gpr_even);
1763 MCPhysReg OddReg =
TRI.getSubReg(CSReg, RISCV::sub_gpr_odd);
1764 CombineToSuperReg = SavedRegs.
test(EvenReg) && SavedRegs.
test(OddReg);
1767 if (
hasFP(MF) && CSReg == RISCV::X8_X9)
1768 CombineToSuperReg =
false;
1770 auto SubRegs =
TRI.subregs(CSReg);
1772 !SubRegs.empty() &&
llvm::all_of(SubRegs, [&](
unsigned Reg) {
1773 return SavedRegs.
test(Reg);
1777 if (CombineToSuperReg)
1778 SavedRegs.
set(CSReg);
1785std::pair<int64_t, Align>
1786RISCVFrameLowering::assignRVVStackObjectOffsets(
MachineFunction &MF)
const {
1790 auto pushRVVObjects = [&](
int FIBegin,
int FIEnd) {
1791 for (
int I = FIBegin, E = FIEnd;
I != E; ++
I) {
1804 if (!RVVCSI.empty())
1805 pushRVVObjects(RVVCSI[0].getFrameIdx(),
1806 RVVCSI[RVVCSI.size() - 1].getFrameIdx() + 1);
1810 Align RVVStackAlign(16);
1813 if (!
ST.hasVInstructions()) {
1815 "Can't allocate scalable-vector objects without V instructions");
1816 return std::make_pair(0, RVVStackAlign);
1821 for (
int FI : ObjectsToAllocate) {
1833 RVVStackAlign = std::max(RVVStackAlign, ObjectAlign);
1836 uint64_t StackSize =
Offset;
1846 if (
auto RVVStackAlignVScale = RVVStackAlign.value() / VScale) {
1847 if (
auto AlignmentPadding =
1849 StackSize += AlignmentPadding;
1850 for (
int FI : ObjectsToAllocate)
1855 return std::make_pair(StackSize, RVVStackAlign);
1861 static constexpr unsigned ScavSlotsNumRVVSpillScalableObject = 2;
1865 static constexpr unsigned ScavSlotsNumRVVSpillNonScalableObject = 1;
1869 static constexpr unsigned ScavSlotsADDIScalableObject = 1;
1871 static constexpr unsigned MaxScavSlotsNumKnown =
1872 std::max({ScavSlotsADDIScalableObject, ScavSlotsNumRVVSpillScalableObject,
1873 ScavSlotsNumRVVSpillNonScalableObject});
1875 unsigned MaxScavSlotsNum = 0;
1881 for (
auto &MO :
MI.operands()) {
1887 MaxScavSlotsNum = std::max(
1888 MaxScavSlotsNum, IsScalableVectorID
1889 ? ScavSlotsNumRVVSpillScalableObject
1890 : ScavSlotsNumRVVSpillNonScalableObject);
1891 }
else if (
MI.getOpcode() == RISCV::ADDI && IsScalableVectorID) {
1893 std::max(MaxScavSlotsNum, ScavSlotsADDIScalableObject);
1896 if (MaxScavSlotsNum == MaxScavSlotsNumKnown)
1897 return MaxScavSlotsNumKnown;
1899 return MaxScavSlotsNum;
1923 unsigned FnSize = 0;
1924 for (
auto &
MBB : MF) {
1925 for (
auto &
MI :
MBB) {
1943 if (
MI.isConditionalBranch())
1944 FnSize +=
TII.getInstSizeInBytes(
MI);
1945 if (
MI.isConditionalBranch() ||
MI.isUnconditionalBranch()) {
1947 FnSize += 2 + 8 + 2 + 2;
1949 FnSize += 4 + 8 + 4 + 4;
1953 FnSize +=
TII.getInstSizeInBytes(
MI);
1968 int64_t RVVStackSize;
1969 Align RVVStackAlign;
1970 std::tie(RVVStackSize, RVVStackAlign) = assignRVVStackObjectOffsets(MF);
1972 RVFI->setRVVStackSize(RVVStackSize);
1973 RVFI->setRVVStackAlign(RVVStackAlign);
1982 unsigned ScavSlotsNum = 0;
1992 if (IsLargeFunction)
1993 ScavSlotsNum = std::max(ScavSlotsNum, 1u);
2000 for (
unsigned I = 0;
I < ScavSlotsNum;
I++) {
2002 RegInfo->getSpillAlign(*RC));
2003 RS->addScavengingFrameIndex(FI);
2005 if (IsLargeFunction && RVFI->getBranchRelaxationScratchFrameIndex() == -1)
2006 RVFI->setBranchRelaxationScratchFrameIndex(FI);
2009 unsigned Size = RVFI->getReservedSpillsSize();
2011 int FrameIdx = Info.getFrameIdx();
2017 RVFI->setCalleeSavedStackSize(
Size);
2041 int64_t Amount =
MI->getOperand(0).getImm();
2047 if (
MI->getOpcode() == RISCV::ADJCALLSTACKDOWN)
2057 bool DynAllocation =
2061 true, ProbeSize, DynAllocation,
2063 inlineStackProbe(MF,
MBB);
2072 return MBB.erase(
MI);
2090 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
2096 if (RVFI->getReservedSpillsSize())
2101 if (!
isInt<12>(StackSize) && (CSI.size() > 0)) {
2114 if (
STI.hasStdExtZca()) {
2131 auto CanCompress = [&](
uint64_t CompressLen) ->
bool {
2132 if (StackSize <= 2047 + CompressLen ||
2133 (StackSize > 2048 * 2 - StackAlign &&
2134 StackSize <= 2047 * 2 + CompressLen) ||
2135 StackSize > 2048 * 3 - StackAlign)
2143 const uint64_t ADDI16SPCompressLen = 496;
2144 if (
STI.is64Bit() && CanCompress(ADDI16SPCompressLen))
2145 return ADDI16SPCompressLen;
2146 if (CanCompress(RVCompressLen))
2147 return RVCompressLen;
2149 return 2048 - StackAlign;
2156 std::vector<CalleeSavedInfo> &CSI)
const {
2163 if (RVFI->isSiFivePreemptibleInterrupt(MF)) {
2164 for (
int I = 0;
I < 2; ++
I) {
2165 int FI = RVFI->getInterruptCSRFrameIndex(
I);
2166 MFI.setIsCalleeSavedObjectIndex(FI,
true);
2174 if (RVFI->useQCIInterrupt(MF)) {
2178 if (RVFI->isPushable(MF)) {
2185 unsigned OnlyPushIfMoreThan = RVFI->useQCIInterrupt(MF) ? 2 : 0;
2186 if (PushedRegNum > OnlyPushIfMoreThan) {
2187 RVFI->setRVPushRegs(PushedRegNum);
2188 RVFI->setRVPushStackSize(
alignTo((
STI.getXLen() / 8) * PushedRegNum, 16));
2192 for (
auto &CS : CSI) {
2195 unsigned Size = RegInfo->getSpillSize(*RC);
2197 if (RVFI->useQCIInterrupt(MF)) {
2199 return P.first == CS.getReg();
2202 int64_t
Offset = FFI->second * (int64_t)
Size;
2204 int FrameIdx = MFI.CreateFixedSpillStackObject(
Size,
Offset);
2206 CS.setFrameIdx(FrameIdx);
2211 if (RVFI->useSaveRestoreLibCalls(MF) || RVFI->isPushable(MF)) {
2214 unsigned RegNum = std::distance(std::begin(
FixedCSRFIMap), FII);
2218 if (RVFI->getPushPopKind(MF) ==
2220 Offset = -int64_t(RVFI->getRVPushRegs() - RegNum) *
Size;
2224 if (RVFI->useQCIInterrupt(MF))
2227 int FrameIdx = MFI.CreateFixedSpillStackObject(
Size,
Offset);
2229 CS.setFrameIdx(FrameIdx);
2235 if (!
STI.is64Bit() &&
STI.hasStdExtZilsd() &&
2236 RISCV::GPRPairRegClass.contains(Reg)) {
2237 Align PairAlign =
STI.getZilsdAlign();
2238 int FrameIdx = MFI.CreateStackObject(8, PairAlign,
true);
2239 MFI.setIsCalleeSavedObjectIndex(FrameIdx,
true);
2240 CS.setFrameIdx(FrameIdx);
2245 Align Alignment = RegInfo->getSpillAlign(*RC);
2250 int FrameIdx = MFI.CreateStackObject(
Size, Alignment,
true);
2251 MFI.setIsCalleeSavedObjectIndex(FrameIdx,
true);
2252 CS.setFrameIdx(FrameIdx);
2257 if (RVFI->useQCIInterrupt(MF)) {
2260 MFI.CreateFixedSpillStackObject(
2264 if (RVFI->isPushable(MF)) {
2267 if (int64_t PushSize = RVFI->getRVPushStackSize())
2268 MFI.CreateFixedSpillStackObject(PushSize, -PushSize - QCIOffset);
2269 }
else if (
int LibCallRegs =
getLibCallID(MF, CSI) + 1) {
2270 int64_t LibCallFrameSize =
2272 MFI.CreateFixedSpillStackObject(LibCallFrameSize, -LibCallFrameSize);
2287 if (
MI !=
MBB.end() && !
MI->isDebugInstr())
2288 DL =
MI->getDebugLoc();
2297 ? RISCV::QC_C_MIENTER_NEST
2298 : RISCV::QC_C_MIENTER))
2308 if (PushedRegNum > 0) {
2316 PushBuilder.
addImm(RegEnc);
2319 for (
unsigned i = 0; i < PushedRegNum; i++)
2332 for (
auto &CS : CSI)
2337 const auto &UnmanagedCSI =
2341 auto storeRegsToStackSlots = [&](
decltype(UnmanagedCSI) CSInfo) {
2342 for (
auto &CS : CSInfo) {
2346 TII.storeRegToStackSlot(
MBB,
MI, Reg, !
MBB.isLiveIn(Reg),
2351 storeRegsToStackSlots(UnmanagedCSI);
2352 storeRegsToStackSlots(RVVCSI);
2358 return RISCV::VRRegClass.contains(BaseReg) ? 1
2359 : RISCV::VRM2RegClass.contains(BaseReg) ? 2
2360 : RISCV::VRM4RegClass.contains(BaseReg) ? 4
2364void RISCVFrameLowering::emitCalleeSavedRVVPrologCFI(
2368 RISCVMachineFunctionInfo *RVFI = MF->
getInfo<RISCVMachineFunctionInfo>();
2369 const RISCVRegisterInfo &
TRI = *
STI.getRegisterInfo();
2377 uint64_t ScalarLocalVarSize =
2380 FixedSize -= ScalarLocalVarSize;
2384 for (
auto &CS : RVVCSI) {
2386 int FI = CS.getFrameIdx();
2389 for (
unsigned i = 0; i < NumRegs; ++i) {
2397void RISCVFrameLowering::emitCalleeSavedRVVEpilogCFI(
2401 const RISCVRegisterInfo &
TRI = *
STI.getRegisterInfo();
2405 for (
auto &CS : RVVCSI) {
2408 for (
unsigned i = 0; i < NumRegs; ++i)
2409 CFIHelper.buildRestore(BaseReg + i);
2422 if (
MI !=
MBB.end() && !
MI->isDebugInstr())
2423 DL =
MI->getDebugLoc();
2431 const auto &UnmanagedCSI =
2435 auto loadRegFromStackSlot = [&](
decltype(UnmanagedCSI) CSInfo) {
2436 for (
auto &CS : CSInfo) {
2440 RISCV::NoSubRegister,
2443 "loadRegFromStackSlot didn't insert any code!");
2446 loadRegFromStackSlot(RVVCSI);
2447 loadRegFromStackSlot(UnmanagedCSI);
2453 assert(
MI->getOpcode() == RISCV::QC_C_MILEAVERET &&
2454 "Unexpected QCI Interrupt Return Instruction");
2459 if (PushedRegNum > 0) {
2466 PopBuilder.
addImm(RegEnc);
2481 for (
auto &CS : CSI)
2486 if (
MI !=
MBB.end() &&
MI->getOpcode() == RISCV::PseudoRET) {
2488 MI->eraseFromParent();
2514 if (
STI.preferVsetvliOverReadVLENB() &&
2515 (
MBB.isLiveIn(RISCV::VTYPE) ||
MBB.isLiveIn(RISCV::VL)))
2526 RS.enterBasicBlock(*TmpMBB);
2527 return !RS.isRegUsed(RISCV::X5);
2538 return MBB.succ_empty();
2547 if (
MBB.succ_size() > 1)
2585 assert(TargetReg != RISCV::X2 &&
"New top of stack cannot already be in SP");
2592 bool IsRV64 = Subtarget.is64Bit();
2593 Align StackAlign = Subtarget.getFrameLowering()->getStackAlign();
2600 MF.
insert(MBBInsertPoint, LoopTestMBB);
2602 MF.
insert(MBBInsertPoint, ExitMBB);
2607 TII->movImm(
MBB,
MBBI,
DL, ScratchReg, ProbeSize, Flags);
2618 TII->get(IsRV64 ? RISCV::SD : RISCV::SW))
2653 MBB.addSuccessor(LoopTestMBB);
2663 SmallVector<MachineInstr *, 4> ToReplace;
2664 for (MachineInstr &
MI :
MBB) {
2665 unsigned Opc =
MI.getOpcode();
2666 if (
Opc == RISCV::PROBED_STACKALLOC ||
2667 Opc == RISCV::PROBED_STACKALLOC_RVV) {
2672 for (MachineInstr *
MI : ToReplace) {
2673 if (
MI->getOpcode() == RISCV::PROBED_STACKALLOC ||
2674 MI->getOpcode() == RISCV::PROBED_STACKALLOC_RVV) {
2677 Register TargetReg =
MI->getOperand(0).getReg();
2679 (
MI->getOpcode() == RISCV::PROBED_STACKALLOC_RVV));
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
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 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 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 void emitSiFiveCLICPreemptibleRestores(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL)
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 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 void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL)
static const MCPhysReg FixedCSRFIMap[]
static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const DebugLoc &DL)
static void emitSiFiveCLICStackSwap(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL)
static unsigned getNumPushPopRegs(const std::vector< CalleeSavedInfo > &CSI)
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.
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.
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.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals, SMLoc Loc={}, StringRef Comment="")
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
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...
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 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 the alignment in bytes that this function must be aligned to, which is greater than the defaul...
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
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & 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.
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
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 isSiFivePreemptibleInterrupt(const MachineFunction &MF) const
void pushInterruptCSRFrameIndex(int FI)
PushPopKind getPushPopKind(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
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.
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.
LLVM_ABI bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
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.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
static unsigned encodeRegListNumRegs(unsigned NumRegs)
static constexpr unsigned RVVBitsPerBlock
bool isRVVSpill(const MachineInstr &MI)
static constexpr unsigned RVVBytesPerBlock
@ ScalablePredicateVector
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.
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.
@ Define
Register definition.
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.
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 find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
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.
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