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");
 
  144  bool IsRV64 = STI.is64Bit();
 
  145  int64_t SlotSize = STI.getXLen() / 8;
 
  165  char DwarfSCSReg = 
TRI->getDwarfRegNum(SCSPReg,  
true);
 
  166  assert(DwarfSCSReg < 32 && 
"SCS Register should be < 32 (X3).");
 
  168  char Offset = 
static_cast<char>(-SlotSize) & 0x7f;
 
  169  const char CFIInst[] = {
 
  170      dwarf::DW_CFA_val_expression,
 
  173      static_cast<char>(
unsigned(dwarf::DW_OP_breg0 + DwarfSCSReg)),
 
 
  186                          STI.hasStdExtZimop();
 
  187  bool HasSWShadowStack =
 
  189  if (!HasHWShadowStack && !HasSWShadowStack)
 
  199  if (HasHWShadowStack) {
 
  206  bool IsRV64 = STI.is64Bit();
 
  207  int64_t SlotSize = STI.getXLen() / 8;
 
 
  233  if (!RVFI->isSiFiveStackSwapInterrupt(MF))
 
  239  assert(STI.hasVendorXSfmclic() && 
"Stack Swapping Requires XSfmclic");
 
  243      .
addImm(RISCVSysReg::sf_mscratchcsw)
 
 
  264  for (
int I = 0; 
I < 2; ++
I) {
 
 
  277  if (!RVFI->isSiFivePreemptibleInterrupt(MF))
 
  292  TII->storeRegToStackSlot(
MBB, 
MBBI, RISCV::X8, 
true,
 
  293                           RVFI->getInterruptCSRFrameIndex(0),
 
  294                           &RISCV::GPRRegClass, STI.getRegisterInfo(),
 
  296  TII->storeRegToStackSlot(
MBB, 
MBBI, RISCV::X9, 
true,
 
  297                           RVFI->getInterruptCSRFrameIndex(1),
 
  298                           &RISCV::GPRRegClass, STI.getRegisterInfo(),
 
  306      .
addImm(RISCVSysReg::mcause)
 
  311      .
addImm(RISCVSysReg::mepc)
 
  318      .
addImm(RISCVSysReg::mstatus)
 
 
  329  if (!RVFI->isSiFivePreemptibleInterrupt(MF))
 
  340      .
addImm(RISCVSysReg::mstatus)
 
  349      .
addImm(RISCVSysReg::mepc)
 
  354      .
addImm(RISCVSysReg::mcause)
 
  360  TII->loadRegFromStackSlot(
MBB, 
MBBI, RISCV::X9,
 
  361                            RVFI->getInterruptCSRFrameIndex(1),
 
  362                            &RISCV::GPRRegClass, STI.getRegisterInfo(),
 
  364  TII->loadRegFromStackSlot(
MBB, 
MBBI, RISCV::X8,
 
  365                            RVFI->getInterruptCSRFrameIndex(0),
 
  366                            &RISCV::GPRRegClass, STI.getRegisterInfo(),
 
 
  375                        const std::vector<CalleeSavedInfo> &CSI) {
 
  378  if (CSI.empty() || !RVFI->useSaveRestoreLibCalls(MF))
 
  385    if (CS.getFrameIdx() < 0)
 
  386      MaxReg = std::max(MaxReg.
id(), CS.getReg().id());
 
  391  switch (MaxReg.
id()) {
 
  395  case  RISCV::X27: 
return 12;
 
  396  case  RISCV::X26: 
return 11;
 
  397  case   RISCV::X25: 
return 10;
 
  398  case   RISCV::X24: 
return 9;
 
  399  case   RISCV::X23: 
return 8;
 
  400  case   RISCV::X22: 
return 7;
 
  401  case   RISCV::X21: 
return 6;
 
  402  case   RISCV::X20: 
return 5;
 
  403  case   RISCV::X19: 
return 4;
 
  404  case   RISCV::X18: 
return 3;
 
  405  case   RISCV::X9:  
return 2;
 
  406  case   FPReg:  
return 1;
 
  407  case   RAReg:  
return 0;
 
 
  416                    const std::vector<CalleeSavedInfo> &CSI) {
 
  417  static const char *
const SpillLibCalls[] = {
 
  436  return SpillLibCalls[LibCallID];
 
 
  443                      const std::vector<CalleeSavedInfo> &CSI) {
 
  444  static const char *
const RestoreLibCalls[] = {
 
  455    "__riscv_restore_10",
 
  456    "__riscv_restore_11",
 
  463  return RestoreLibCalls[LibCallID];
 
 
  468  unsigned NumPushPopRegs = 0;
 
  469  for (
auto &CS : CSI) {
 
  473      unsigned RegNum = std::distance(std::begin(
FixedCSRFIMap), FII);
 
  474      NumPushPopRegs = std::max(NumPushPopRegs, RegNum + 1);
 
  477  assert(NumPushPopRegs != 12 && 
"x26 requires x27 to also be pushed");
 
  478  return NumPushPopRegs;
 
 
  505         TRI->hasStackRealignment(MF);
 
 
  509void RISCVFrameLowering::determineFrameLayout(
MachineFunction &MF)
 const {
 
  517  if (RVFI->useQCIInterrupt(MF))
 
  524  FrameSize = 
alignTo(FrameSize, StackAlign);
 
  534  if (RVFI->getRVVStackSize() && (!
hasFP(MF) || 
TRI->hasStackRealignment(MF))) {
 
  535    int ScalarLocalVarSize = FrameSize - RVFI->getCalleeSavedStackSize() -
 
  536                             RVFI->getVarArgsSaveSize();
 
  537    if (
auto RVVPadding =
 
  539      RVFI->setRVVPadding(RVVPadding);
 
  554                const std::vector<CalleeSavedInfo> &CSI) {
 
  558  for (
auto &CS : CSI) {
 
  559    int FI = CS.getFrameIdx();
 
  564  return NonLibcallCSI;
 
 
  569                      const std::vector<CalleeSavedInfo> &CSI) {
 
  573  for (
auto &CS : CSI) {
 
  574    int FI = CS.getFrameIdx();
 
 
  584                           const std::vector<CalleeSavedInfo> &CSI) {
 
  588  if (!RVFI->useSaveRestoreLibCalls(MF) && !RVFI->isPushable(MF))
 
  589    return PushOrLibCallsCSI;
 
  591  for (
const auto &CS : CSI) {
 
  592    if (RVFI->useQCIInterrupt(MF)) {
 
  603      PushOrLibCallsCSI.push_back(CS);
 
  606  return PushOrLibCallsCSI;
 
 
  611                const std::vector<CalleeSavedInfo> &CSI) {
 
  615  if (!RVFI->useQCIInterrupt(MF))
 
  616    return QCIInterruptCSI;
 
  618  for (
const auto &CS : CSI) {
 
  621      QCIInterruptCSI.push_back(CS);
 
  624  return QCIInterruptCSI;
 
 
  627void RISCVFrameLowering::allocateAndProbeStackForRVV(
 
  631  assert(Amount != 0 && 
"Did not need to adjust stack pointer for RVV.");
 
  636  const RISCVInstrInfo *
TII = 
STI.getInstrInfo();
 
  641  TII->mulImm(MF, 
MBB, 
MBBI, 
DL, TargetReg, NumOfVReg, Flag);
 
  646    CFIBuilder.buildDefCFA(TargetReg, -Amount);
 
  655    CFIBuilder.buildDefCFARegister(
SPReg);
 
  676                                           int FixedOffset, 
int ScalableOffset,
 
  678  unsigned DwarfVLenB = 
TRI.getDwarfRegNum(RISCV::VLENB, 
true);
 
  684    Comment << (FixedOffset < 0 ? 
" - " : 
" + ") << std::abs(FixedOffset);
 
  697  Comment << (ScalableOffset < 0 ? 
" - " : 
" + ") << std::abs(ScalableOffset)
 
 
  705  assert(ScalableOffset != 0 && 
"Did not need to adjust CFA for RVV");
 
  707  std::string CommentBuffer;
 
  710  unsigned DwarfReg = 
TRI.getDwarfRegNum(
Reg, 
true);
 
  723  DefCfaExpr.
push_back(dwarf::DW_CFA_def_cfa_expression);
 
 
  734  assert(ScalableOffset != 0 && 
"Did not need to adjust CFA for RVV");
 
  736  std::string CommentBuffer;
 
  746  unsigned DwarfReg = 
TRI.getDwarfRegNum(
Reg, 
true);
 
  747  DefCfaExpr.
push_back(dwarf::DW_CFA_expression);
 
 
  760                                       uint64_t RealStackSize, 
bool EmitCFI,
 
  767  bool IsRV64 = 
STI.is64Bit();
 
  771  if (!NeedProbe || 
Offset <= ProbeSize) {
 
  778    if (NeedProbe && DynAllocation) {
 
  791  if (
Offset < ProbeSize * 5) {
 
  793    while (CurrentOffset + ProbeSize <= 
Offset) {
 
  803      CurrentOffset += ProbeSize;
 
 
  870  case RISCV::QC_CM_PUSH:
 
  871  case RISCV::QC_CM_PUSHFP:
 
 
  883  case RISCV::QC_CM_POP:
 
 
  894    return RISCV::CM_PUSH;
 
  896    return UpdateFP ? RISCV::QC_CM_PUSHFP : RISCV::QC_CM_PUSH;
 
 
  907    return RISCV::CM_POP;
 
  909    return RISCV::QC_CM_POP;
 
 
  942  auto PossiblePush = 
MBBI;
 
  949  determineFrameLayout(MF);
 
  983    unsigned LibCallFrameSize =
 
  985    RVFI->setLibCallStackSize(LibCallFrameSize);
 
  998  uint64_t StackSize = RealStackSize - RVFI->getReservedSpillsSize();
 
  999  uint64_t RVVStackSize = RVFI->getRVVStackSize();
 
 1002  if (RealStackSize == 0 && !MFI.
adjustsStack() && RVVStackSize == 0)
 
 1007  if (
STI.isRegisterReservedByUser(
SPReg))
 
 1009        MF.
getFunction(), 
"Stack pointer required, but has been reserved."});
 
 1013  if (FirstSPAdjustAmount) {
 
 1014    StackSize = FirstSPAdjustAmount;
 
 1015    RealStackSize = FirstSPAdjustAmount;
 
 1018  if (RVFI->useQCIInterrupt(MF)) {
 
 1023    if (NeedsDwarfCFI) {
 
 1036  if (RVFI->isPushable(MF) && PossiblePush != 
MBB.end() &&
 
 1037      isPush(PossiblePush->getOpcode())) {
 
 1044    PossiblePush->getOperand(1).setImm(StackAdj);
 
 1045    StackSize -= StackAdj;
 
 1047    if (NeedsDwarfCFI) {
 
 1060  bool DynAllocation =
 
 1064                  NeedProbe, ProbeSize, DynAllocation,
 
 1088    if (
STI.isRegisterReservedByUser(
FPReg))
 
 1090          MF.
getFunction(), 
"Frame pointer required, but has been reserved."});
 
 1096    if (!RVFI->hasImplicitFPUpdates(MF)) {
 
 1109  if (FirstSPAdjustAmount) {
 
 1111    assert(SecondSPAdjustAmount > 0 &&
 
 1112           "SecondSPAdjustAmount should be greater than zero");
 
 1116                  NeedProbe, ProbeSize, DynAllocation,
 
 1122      allocateAndProbeStackForRVV(MF, 
MBB, 
MBBI, 
DL, RVVStackSize,
 
 1124                                  NeedsDwarfCFI && !
hasFP(MF), DynAllocation);
 
 1133    if (NeedsDwarfCFI && !
hasFP(MF)) {
 
 1147    if (RI->hasStackRealignment(MF)) {
 
 1151      if (
isInt<12>(-(
int)MaxAlignment.value())) {
 
 1154            .
addImm(-(
int)MaxAlignment.value())
 
 1157        unsigned ShiftAmount = 
Log2(MaxAlignment);
 
 1169      if (NeedProbe && RVVStackSize == 0) {
 
 1172        if (SecondSPAdjustAmount < ProbeSize &&
 
 1173            SecondSPAdjustAmount + MaxAlignment.value() >= ProbeSize) {
 
 1174          bool IsRV64 = 
STI.is64Bit();
 
 
 1201                                         int64_t CFAOffset)
 const {
 
 1229    MBBI = 
MBB.getLastNonDebugInstr();
 
 1231      DL = 
MBBI->getDebugLoc();
 
 1233    MBBI = 
MBB.getFirstTerminator();
 
 1246  auto FirstScalarCSRRestoreInsn =
 
 1253  uint64_t RealStackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
 
 1255  uint64_t StackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
 
 1257                                                 RVFI->getReservedSpillsSize();
 
 1258  uint64_t FPOffset = RealStackSize - RVFI->getVarArgsSaveSize();
 
 1259  uint64_t RVVStackSize = RVFI->getRVVStackSize();
 
 1261  bool RestoreSPFromFP = RI->hasStackRealignment(MF) ||
 
 1266    if (!RestoreSPFromFP)
 
 1271    if (NeedsDwarfCFI) {
 
 1274      emitCalleeSavedRVVEpilogCFI(
MBB, FirstScalarCSRRestoreInsn);
 
 1278  if (FirstSPAdjustAmount) {
 
 1281    assert(SecondSPAdjustAmount > 0 &&
 
 1282           "SecondSPAdjustAmount should be greater than zero");
 
 1286    if (!RestoreSPFromFP)
 
 1291    if (NeedsDwarfCFI && !
hasFP(MF))
 
 1305  if (RestoreSPFromFP) {
 
 1306    assert(
hasFP(MF) && 
"frame pointer should not have been eliminated");
 
 1312  if (NeedsDwarfCFI && 
hasFP(MF))
 
 1326      deallocateStack(MF, 
MBB, 
MBBI, 
DL, StackSize,
 
 1327                      RVFI->getLibCallStackSize());
 
 1339  if (RVFI->isPushable(MF) && 
MBBI != 
MBB.end() && 
isPop(
MBBI->getOpcode())) {
 
 1346    MBBI->getOperand(1).setImm(StackAdj);
 
 1347    StackSize -= StackAdj;
 
 1350      deallocateStack(MF, 
MBB, 
MBBI, 
DL, StackSize,
 
 1351                       RealStackSize - StackSize);
 
 1354    if (NextI == 
MBB.end() || NextI->getOpcode() != RISCV::PseudoRET) {
 
 1356      if (NeedsDwarfCFI) {
 
 1376    deallocateStack(MF, 
MBB, 
MBBI, 
DL, StackSize,
 
 1377                    RVFI->getQCIInterruptStackSize());
 
 
 1404         "Unexpected stack ID for the frame object.");
 
 1416    MinCSFI = CSI[0].getFrameIdx();
 
 1417    MaxCSFI = CSI[CSI.size() - 1].getFrameIdx();
 
 1420  if (FI >= MinCSFI && FI <= MaxCSFI) {
 
 1423    if (FirstSPAdjustAmount)
 
 1474  if (FrameReg == 
FPReg) {
 
 1493             "Can't index across variable sized realign");
 
 1498             "Inconsistent stack layout");
 
 1541             "Can't index across variable sized realign");
 
 1543                                 RVFI->getRVVStackSize());
 
 1551                             RVFI->getCalleeSavedStackSize() -
 
 1552                             RVFI->getVarArgsSaveSize() + RVFI->getRVVPadding();
 
 
 1563  if (!BaseReg.isValid())
 
 
 1583  for (
unsigned i = 0; CSRegs[i]; ++i) {
 
 1584    unsigned CSReg = CSRegs[i];
 
 1589    SavedRegs.
reset(CSReg);
 
 1591    auto SubRegs = 
TRI.subregs(CSReg);
 
 1593    if (!
MRI.def_empty(CSReg) || 
MRI.getUsedPhysRegsMask().test(CSReg)) {
 
 1594      SavedRegs.
set(CSReg);
 
 1595      for (
unsigned Reg : SubRegs)
 
 1600    if (!SubRegs.empty() && 
llvm::all_of(SubRegs, [&](
unsigned Reg) {
 
 1601          return SavedRegs.test(Reg);
 
 1603      SavedRegs.
set(CSReg);
 
 1618  if (RVFI->isPushable(MF) && SavedRegs.
test(RISCV::X26))
 
 1619    SavedRegs.
set(RISCV::X27);
 
 
 1625std::pair<int64_t, Align>
 
 1626RISCVFrameLowering::assignRVVStackObjectOffsets(
MachineFunction &MF)
 const {
 
 1630  auto pushRVVObjects = [&](
int FIBegin, 
int FIEnd) {
 
 1631    for (
int I = FIBegin, E = FIEnd; 
I != E; ++
I) {
 
 1644  if (!RVVCSI.empty())
 
 1645    pushRVVObjects(RVVCSI[0].getFrameIdx(),
 
 1646                   RVVCSI[RVVCSI.size() - 1].getFrameIdx() + 1);
 
 1650  Align RVVStackAlign(16);
 
 1653  if (!
ST.hasVInstructions()) {
 
 1655           "Can't allocate scalable-vector objects without V instructions");
 
 1656    return std::make_pair(0, RVVStackAlign);
 
 1661  for (
int FI : ObjectsToAllocate) {
 
 1673    RVVStackAlign = std::max(RVVStackAlign, ObjectAlign);
 
 1676  uint64_t StackSize = 
Offset;
 
 1686  if (
auto RVVStackAlignVScale = RVVStackAlign.value() / VScale) {
 
 1687    if (
auto AlignmentPadding =
 
 1689      StackSize += AlignmentPadding;
 
 1690      for (
int FI : ObjectsToAllocate)
 
 1695  return std::make_pair(StackSize, RVVStackAlign);
 
 1701  static constexpr unsigned ScavSlotsNumRVVSpillScalableObject = 2;
 
 1705  static constexpr unsigned ScavSlotsNumRVVSpillNonScalableObject = 1;
 
 1709  static constexpr unsigned ScavSlotsADDIScalableObject = 1;
 
 1711  static constexpr unsigned MaxScavSlotsNumKnown =
 
 1712      std::max({ScavSlotsADDIScalableObject, ScavSlotsNumRVVSpillScalableObject,
 
 1713                ScavSlotsNumRVVSpillNonScalableObject});
 
 1715  unsigned MaxScavSlotsNum = 0;
 
 1721      for (
auto &MO : 
MI.operands()) {
 
 1727          MaxScavSlotsNum = std::max(
 
 1728              MaxScavSlotsNum, IsScalableVectorID
 
 1729                                   ? ScavSlotsNumRVVSpillScalableObject
 
 1730                                   : ScavSlotsNumRVVSpillNonScalableObject);
 
 1731        } 
else if (
MI.getOpcode() == RISCV::ADDI && IsScalableVectorID) {
 
 1733              std::max(MaxScavSlotsNum, ScavSlotsADDIScalableObject);
 
 1736      if (MaxScavSlotsNum == MaxScavSlotsNumKnown)
 
 1737        return MaxScavSlotsNumKnown;
 
 1739  return MaxScavSlotsNum;
 
 
 1763  unsigned FnSize = 0;
 
 1764  for (
auto &
MBB : MF) {
 
 1765    for (
auto &
MI : 
MBB) {
 
 1783      if (
MI.isConditionalBranch())
 
 1784        FnSize += 
TII.getInstSizeInBytes(
MI);
 
 1785      if (
MI.isConditionalBranch() || 
MI.isUnconditionalBranch()) {
 
 1787          FnSize += 2 + 8 + 2 + 2;
 
 1789          FnSize += 4 + 8 + 4 + 4;
 
 1793      FnSize += 
TII.getInstSizeInBytes(
MI);
 
 
 1808  int64_t RVVStackSize;
 
 1809  Align RVVStackAlign;
 
 1810  std::tie(RVVStackSize, RVVStackAlign) = assignRVVStackObjectOffsets(MF);
 
 1812  RVFI->setRVVStackSize(RVVStackSize);
 
 1813  RVFI->setRVVStackAlign(RVVStackAlign);
 
 1822  unsigned ScavSlotsNum = 0;
 
 1832  if (IsLargeFunction)
 
 1833    ScavSlotsNum = std::max(ScavSlotsNum, 1u);
 
 1840  for (
unsigned I = 0; 
I < ScavSlotsNum; 
I++) {
 
 1842                                        RegInfo->getSpillAlign(*RC));
 
 1843    RS->addScavengingFrameIndex(FI);
 
 1845    if (IsLargeFunction && RVFI->getBranchRelaxationScratchFrameIndex() == -1)
 
 1846      RVFI->setBranchRelaxationScratchFrameIndex(FI);
 
 1849  unsigned Size = RVFI->getReservedSpillsSize();
 
 1851    int FrameIdx = Info.getFrameIdx();
 
 1857  RVFI->setCalleeSavedStackSize(
Size);
 
 
 1881    int64_t Amount = 
MI->getOperand(0).getImm();
 
 1887      if (
MI->getOpcode() == RISCV::ADJCALLSTACKDOWN)
 
 1897        bool DynAllocation =
 
 1901                      true, ProbeSize, DynAllocation,
 
 1911  return MBB.erase(
MI);
 
 
 1929  const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
 
 1935  if (RVFI->getReservedSpillsSize())
 
 1940  if (!
isInt<12>(StackSize) && (CSI.size() > 0)) {
 
 1953    if (
STI.hasStdExtZca()) {
 
 1970      auto CanCompress = [&](
uint64_t CompressLen) -> 
bool {
 
 1971        if (StackSize <= 2047 + CompressLen ||
 
 1972            (StackSize > 2048 * 2 - StackAlign &&
 
 1973             StackSize <= 2047 * 2 + CompressLen) ||
 
 1974            StackSize > 2048 * 3 - StackAlign)
 
 1982      const uint64_t ADDI16SPCompressLen = 496;
 
 1983      if (
STI.is64Bit() && CanCompress(ADDI16SPCompressLen))
 
 1984        return ADDI16SPCompressLen;
 
 1985      if (CanCompress(RVCompressLen))
 
 1986        return RVCompressLen;
 
 1988    return 2048 - StackAlign;
 
 
 1995    std::vector<CalleeSavedInfo> &CSI, 
unsigned &MinCSFrameIndex,
 
 1996    unsigned &MaxCSFrameIndex)
 const {
 
 2001  if (RVFI->isSiFivePreemptibleInterrupt(MF)) {
 
 2002    for (
int I = 0; 
I < 2; ++
I) {
 
 2003      int FI = RVFI->getInterruptCSRFrameIndex(
I);
 
 2004      MinCSFrameIndex = std::min<unsigned>(MinCSFrameIndex, FI);
 
 2005      MaxCSFrameIndex = std::max<unsigned>(MaxCSFrameIndex, FI);
 
 2013  if (RVFI->useQCIInterrupt(MF)) {
 
 2017  if (RVFI->isPushable(MF)) {
 
 2024    unsigned OnlyPushIfMoreThan = RVFI->useQCIInterrupt(MF) ? 2 : 0;
 
 2025    if (PushedRegNum > OnlyPushIfMoreThan) {
 
 2026      RVFI->setRVPushRegs(PushedRegNum);
 
 2027      RVFI->setRVPushStackSize(
alignTo((
STI.getXLen() / 8) * PushedRegNum, 16));
 
 2034  for (
auto &CS : CSI) {
 
 2037    unsigned Size = RegInfo->getSpillSize(*RC);
 
 2039    if (RVFI->useQCIInterrupt(MF)) {
 
 2041        return P.first == CS.getReg();
 
 2044        int64_t 
Offset = FFI->second * (int64_t)
Size;
 
 2048        CS.setFrameIdx(FrameIdx);
 
 2053    if (RVFI->useSaveRestoreLibCalls(MF) || RVFI->isPushable(MF)) {
 
 2056      unsigned RegNum = std::distance(std::begin(
FixedCSRFIMap), FII);
 
 2060        if (RVFI->getPushPopKind(MF) ==
 
 2062          Offset = -int64_t(RVFI->getRVPushRegs() - RegNum) * 
Size;
 
 2066        if (RVFI->useQCIInterrupt(MF))
 
 2071        CS.setFrameIdx(FrameIdx);
 
 2077    Align Alignment = RegInfo->getSpillAlign(*RC);
 
 2083    if ((
unsigned)FrameIdx < MinCSFrameIndex)
 
 2084      MinCSFrameIndex = FrameIdx;
 
 2085    if ((
unsigned)FrameIdx > MaxCSFrameIndex)
 
 2086      MaxCSFrameIndex = FrameIdx;
 
 2087    CS.setFrameIdx(FrameIdx);
 
 2092  if (RVFI->useQCIInterrupt(MF)) {
 
 2099  if (RVFI->isPushable(MF)) {
 
 2102    if (int64_t PushSize = RVFI->getRVPushStackSize())
 
 2104  } 
else if (
int LibCallRegs = 
getLibCallID(MF, CSI) + 1) {
 
 2105    int64_t LibCallFrameSize =
 
 
 2122  if (
MI != 
MBB.end() && !
MI->isDebugInstr())
 
 2123    DL = 
MI->getDebugLoc();
 
 2132                    ? RISCV::QC_C_MIENTER_NEST
 
 2133                    : RISCV::QC_C_MIENTER))
 
 2143    if (PushedRegNum > 0) {
 
 2151      PushBuilder.
addImm(RegEnc);
 
 2154      for (
unsigned i = 0; i < PushedRegNum; i++)
 
 2164    for (
auto &CS : CSI)
 
 2165      MBB.addLiveIn(CS.getReg());
 
 2172  auto storeRegsToStackSlots = [&](
decltype(UnmanagedCSI) CSInfo) {
 
 2173    for (
auto &CS : CSInfo) {
 
 2177      TII.storeRegToStackSlot(
MBB, 
MI, Reg, !
MBB.isLiveIn(Reg),
 
 2182  storeRegsToStackSlots(UnmanagedCSI);
 
 2183  storeRegsToStackSlots(RVVCSI);
 
 
 2189  return RISCV::VRRegClass.contains(BaseReg)     ? 1
 
 2190         : RISCV::VRM2RegClass.contains(BaseReg) ? 2
 
 2191         : RISCV::VRM4RegClass.contains(BaseReg) ? 4
 
 
 2195void RISCVFrameLowering::emitCalleeSavedRVVPrologCFI(
 
 2199  RISCVMachineFunctionInfo *RVFI = MF->
getInfo<RISCVMachineFunctionInfo>();
 
 2200  const RISCVRegisterInfo &
TRI = *
STI.getRegisterInfo();
 
 2208    uint64_t ScalarLocalVarSize =
 
 2211    FixedSize -= ScalarLocalVarSize;
 
 2215  for (
auto &CS : RVVCSI) {
 
 2217    int FI = CS.getFrameIdx();
 
 2220    for (
unsigned i = 0; i < NumRegs; ++i) {
 
 2227void RISCVFrameLowering::emitCalleeSavedRVVEpilogCFI(
 
 2231  const RISCVRegisterInfo &
TRI = *
STI.getRegisterInfo();
 
 2235  for (
auto &CS : RVVCSI) {
 
 2238    for (
unsigned i = 0; i < NumRegs; ++i)
 
 2239      CFIHelper.buildRestore(BaseReg + i);
 
 2252  if (
MI != 
MBB.end() && !
MI->isDebugInstr())
 
 2253    DL = 
MI->getDebugLoc();
 
 2264  auto loadRegFromStackSlot = [&](
decltype(UnmanagedCSI) CSInfo) {
 
 2265    for (
auto &CS : CSInfo) {
 
 2268      TII.loadRegFromStackSlot(
MBB, 
MI, Reg, CS.getFrameIdx(), RC, 
TRI,
 
 2271             "loadRegFromStackSlot didn't insert any code!");
 
 2274  loadRegFromStackSlot(RVVCSI);
 
 2275  loadRegFromStackSlot(UnmanagedCSI);
 
 2281    assert(
MI->getOpcode() == RISCV::QC_C_MILEAVERET &&
 
 2282           "Unexpected QCI Interrupt Return Instruction");
 
 2287    if (PushedRegNum > 0) {
 
 2294      PopBuilder.
addImm(RegEnc);
 
 2302    if (RestoreLibCall) {
 
 2311      if (
MI != 
MBB.end() && 
MI->getOpcode() == RISCV::PseudoRET) {
 
 2312        NewMI->copyImplicitOps(*MF, *
MI);
 
 2313        MI->eraseFromParent();
 
 
 2340  if (
STI.preferVsetvliOverReadVLENB() &&
 
 2341      (
MBB.isLiveIn(RISCV::VTYPE) || 
MBB.isLiveIn(RISCV::VL)))
 
 2352  RS.enterBasicBlock(*TmpMBB);
 
 2353  return !RS.isRegUsed(RISCV::X5);
 
 
 2364    return MBB.succ_empty();
 
 2373  if (
MBB.succ_size() > 1)
 
 
 2411  assert(TargetReg != RISCV::X2 && 
"New top of stack cannot already be in SP");
 
 2418  bool IsRV64 = Subtarget.is64Bit();
 
 2419  Align StackAlign = Subtarget.getFrameLowering()->getStackAlign();
 
 2426  MF.
insert(MBBInsertPoint, LoopTestMBB);
 
 2428  MF.
insert(MBBInsertPoint, ExitMBB);
 
 2433  TII->movImm(
MBB, 
MBBI, 
DL, ScratchReg, ProbeSize, Flags);
 
 2444          TII->get(IsRV64 ? RISCV::SD : RISCV::SW))
 
 2479  MBB.addSuccessor(LoopTestMBB);
 
 
 2489  SmallVector<MachineInstr *, 4> ToReplace;
 
 2490  for (MachineInstr &
MI : 
MBB) {
 
 2491    unsigned Opc = 
MI.getOpcode();
 
 2492    if (
Opc == RISCV::PROBED_STACKALLOC ||
 
 2493        Opc == RISCV::PROBED_STACKALLOC_RVV) {
 
 2498  for (MachineInstr *
MI : ToReplace) {
 
 2499    if (
MI->getOpcode() == RISCV::PROBED_STACKALLOC ||
 
 2500        MI->getOpcode() == RISCV::PROBED_STACKALLOC_RVV) {
 
 2503      Register TargetReg = 
MI->getOperand(0).getReg();
 
 2505                           (
MI->getOpcode() == RISCV::PROBED_STACKALLOC_RVV));
 
unsigned const MachineRegisterInfo * MRI
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)
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 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 void appendScalableVectorExpression(const TargetRegisterInfo &TRI, SmallVectorImpl< char > &Expr, int FixedOffset, int ScalableOffset, llvm::raw_string_ostream &Comment)
static bool isPop(unsigned Opcode)
static unsigned getCalleeSavedRVVNumRegs(const Register &BaseReg)
static void emitStackProbeInline(MachineBasicBlock::iterator MBBI, DebugLoc DL, Register TargetReg, bool IsRVV)
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 SmallVector< CalleeSavedInfo, 8 > getUnmanagedCSI(const MachineFunction &MF, const std::vector< CalleeSavedInfo > &CSI)
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)
static MCCFIInstruction createDefCFAOffset(const TargetRegisterInfo &TRI, Register Reg, uint64_t FixedOffset, uint64_t ScalableOffset)
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
bool test(unsigned Idx) 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 int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
LLVM_ABI uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
void setStackID(int ObjectIdx, uint8_t ID)
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
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.
LLVM_ABI int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
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 & setMIFlag(MachineInstr::MIFlag Flag) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
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...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
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 assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
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,...
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.
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
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.
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 append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
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)
StringRef - 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 Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
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
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Define
Register definition.
@ Kill
The last use of a register.
@ 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.
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.
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...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
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.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
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