27#define GET_REGINFO_TARGET_DESC
28#include "RISCVGenRegisterInfo.inc"
32static_assert(RISCV::X1 == RISCV::X0 + 1,
"Register list not consecutive");
33static_assert(RISCV::X31 == RISCV::X0 + 31,
"Register list not consecutive");
34static_assert(RISCV::F1_H == RISCV::F0_H + 1,
"Register list not consecutive");
35static_assert(RISCV::F31_H == RISCV::F0_H + 31,
36 "Register list not consecutive");
37static_assert(RISCV::F1_F == RISCV::F0_F + 1,
"Register list not consecutive");
38static_assert(RISCV::F31_F == RISCV::F0_F + 31,
39 "Register list not consecutive");
40static_assert(RISCV::F1_D == RISCV::F0_D + 1,
"Register list not consecutive");
41static_assert(RISCV::F31_D == RISCV::F0_D + 31,
42 "Register list not consecutive");
43static_assert(RISCV::F1_Q == RISCV::F0_Q + 1,
"Register list not consecutive");
44static_assert(RISCV::F31_Q == RISCV::F0_Q + 31,
45 "Register list not consecutive");
46static_assert(RISCV::V1 == RISCV::V0 + 1,
"Register list not consecutive");
47static_assert(RISCV::V31 == RISCV::V0 + 31,
"Register list not consecutive");
50 const std::bitset<32> &UserReservedXRegs)
53 UserReservedRegs(getNumRegs()) {
55 for (
unsigned I = 1;
I != 32; ++
I) {
56 if (!UserReservedXRegs[
I])
60 UserReservedRegs.set((*AI).id());
66 return CSR_IPRA_SaveList;
73 return CSR_NoRegs_SaveList;
75 return Subtarget.hasStdExtE() ? CSR_RT_MostRegs_RVE_SaveList
76 : CSR_RT_MostRegs_SaveList;
80 return Subtarget.hasStdExtE() ? CSR_XLEN_F64_V_Interrupt_RVE_SaveList
81 : CSR_XLEN_F64_V_Interrupt_SaveList;
83 return Subtarget.hasStdExtE() ? CSR_XLEN_F32_V_Interrupt_RVE_SaveList
84 : CSR_XLEN_F32_V_Interrupt_SaveList;
85 return Subtarget.hasStdExtE() ? CSR_XLEN_V_Interrupt_RVE_SaveList
86 : CSR_XLEN_V_Interrupt_SaveList;
89 return Subtarget.hasStdExtE() ? CSR_XLEN_F64_Interrupt_RVE_SaveList
90 : CSR_XLEN_F64_Interrupt_SaveList;
92 return Subtarget.hasStdExtE() ? CSR_XLEN_F32_Interrupt_RVE_SaveList
93 : CSR_XLEN_F32_Interrupt_SaveList;
94 return Subtarget.hasStdExtE() ? CSR_Interrupt_RVE_SaveList
95 : CSR_Interrupt_SaveList;
106 return CSR_ILP32E_LP64E_SaveList;
108 return HasVectorCSR ? CSR_ILP32_LP64_V_SaveList : CSR_ILP32_LP64_SaveList;
110 return HasVectorCSR ? CSR_ILP32F_LP64F_V_SaveList
111 : CSR_ILP32F_LP64F_SaveList;
113 return HasVectorCSR ? CSR_ILP32D_LP64D_V_SaveList : CSR_ILP32D_LP64D_SaveList;
125 return getAllocatableClass(RC);
133 bool Is64Bit)
const {
134 if (RB.
getID() == RISCV::GPRBRegBankID) {
135 if (Ty.getSizeInBits() <= 32 || (Is64Bit && Ty.getSizeInBits() == 64))
136 return &RISCV::GPRRegClass;
139 if (RB.
getID() == RISCV::FPRBRegBankID) {
140 if (Ty.getSizeInBits() == 16)
141 return &RISCV::FPR16RegClass;
142 if (Ty.getSizeInBits() == 32)
143 return &RISCV::FPR32RegClass;
144 if (Ty.getSizeInBits() == 64)
145 return &RISCV::FPR64RegClass;
148 if (RB.
getID() == RISCV::VRBRegBankID) {
149 if (Ty.getSizeInBits().getKnownMinValue() <= 64)
150 return &RISCV::VRRegClass;
152 if (Ty.getSizeInBits().getKnownMinValue() == 128)
153 return &RISCV::VRM2RegClass;
155 if (Ty.getSizeInBits().getKnownMinValue() == 256)
156 return &RISCV::VRM4RegClass;
158 if (Ty.getSizeInBits().getKnownMinValue() == 512)
159 return &RISCV::VRM8RegClass;
171 const std::bitset<32> &UserReservedXRegs =
Subtarget.getUserReservedXRegs();
172 for (
unsigned I = 1;
I != 32; ++
I) {
173 if (!UserReservedXRegs[
I])
179 markSuperRegs(
Reserved, RISCV::X0_H);
180 markSuperRegs(
Reserved, RISCV::X2_H);
181 markSuperRegs(
Reserved, RISCV::X3_H);
182 markSuperRegs(
Reserved, RISCV::X4_H);
184 markSuperRegs(
Reserved, RISCV::X8_H);
192 for (
MCPhysReg Reg = RISCV::X16_H; Reg <= RISCV::X31_H; Reg++)
197 markSuperRegs(
Reserved, RISCV::VTYPE);
198 markSuperRegs(
Reserved, RISCV::VXSAT);
199 markSuperRegs(
Reserved, RISCV::VXRM);
200 markSuperRegs(
Reserved, RISCV::VLENB);
203 markSuperRegs(
Reserved, RISCV::FRM);
204 markSuperRegs(
Reserved, RISCV::FFLAGS);
207 markSuperRegs(
Reserved, RISCV::SF_VCIX_STATE);
212 markSuperRegs(
Reserved, RISCV::X23_H);
213 markSuperRegs(
Reserved, RISCV::X27_H);
217 markSuperRegs(
Reserved, RISCV::SSP);
220 for (
MCPhysReg Reg = RISCV::T0; Reg <= RISCV::T15; Reg++)
233 return CSR_NoRegs_RegMask;
243 if (DestReg == SrcReg && !
Offset.getFixed() && !
Offset.getScalable())
252 if (
Offset.getScalable()) {
253 if (
auto VLEN = ST.getRealVLen()) {
255 const int64_t VLENB = *VLEN / 8;
257 "Reserve the stack by the multiple of one vector size.");
258 const int64_t NumOfVReg =
Offset.getScalable() / 8;
259 const int64_t FixedOffset = NumOfVReg * VLENB;
266 "32-bit range not supported");
272 bool KillSrcReg =
false;
274 if (
Offset.getScalable()) {
275 unsigned ScalableAdjOpc = RISCV::ADD;
276 int64_t ScalableValue =
Offset.getScalable();
277 if (ScalableValue < 0) {
278 ScalableValue = -ScalableValue;
279 ScalableAdjOpc = RISCV::SUB;
283 if (DestReg == SrcReg)
284 ScratchReg =
MRI.createVirtualRegister(&RISCV::GPRRegClass);
286 assert(ScalableValue > 0 &&
"There is no need to get VLEN scaled value.");
288 "Reserve the stack by the multiple of one vector size.");
290 "Expect the number of vector registers within 32-bits.");
294 bool IsPrologueOrEpilogue =
296 bool UseVsetvliRatherThanVlenb =
297 IsPrologueOrEpilogue && ST.preferVsetvliOverReadVLENB();
298 if (UseVsetvliRatherThanVlenb && (NumOfVReg == 1 || NumOfVReg == 2 ||
299 NumOfVReg == 4 || NumOfVReg == 8)) {
309 if (UseVsetvliRatherThanVlenb)
318 if (ScalableAdjOpc == RISCV::ADD && ST.hasStdExtZba() &&
319 (NumOfVReg == 2 || NumOfVReg == 4 || NumOfVReg == 8)) {
320 unsigned Opc = NumOfVReg == 2
322 : (NumOfVReg == 4 ? RISCV::SH2ADD : RISCV::SH3ADD);
328 TII->mulImm(MF,
MBB,
II,
DL, ScratchReg, NumOfVReg, Flag);
339 int64_t Val =
Offset.getFixed();
340 if (DestReg == SrcReg && Val == 0)
355 if (ST.hasVendorXqcilia() &&
isInt<26>(Val)) {
359 int Hi20 = (Val & 0xFFFFF000) >> 12;
361 ((Val & 0xFFF) == 0) && (Hi20 != 0) &&
362 (
isUInt<5>(Hi20) || (Hi20 >= 0xfffe0 && Hi20 <= 0xfffff));
363 bool IsCompressAddSub =
364 (SrcReg == DestReg) &&
365 ((Val > 0 && RISCV::GPRNoX0RegClass.
contains(SrcReg)) ||
366 (Val < 0 && RISCV::GPRCRegClass.
contains(SrcReg)));
368 if (!(IsCompressLUI && IsCompressAddSub)) {
383 assert(
Align < 2048 &&
"Required alignment too large");
384 int64_t MaxPosAdjStep = 2048 -
Align;
385 if (Val > -4096 && Val <= (2 * MaxPosAdjStep)) {
386 int64_t FirstAdj = Val < 0 ? -2048 : MaxPosAdjStep;
404 if (ST.hasStdExtZba() && (Val & 0xFFF) != 0) {
414 Register ScratchReg =
MRI.createVirtualRegister(&RISCV::GPRRegClass);
415 TII->movImm(
MBB,
II,
DL, ScratchReg, Val, Flag);
436 unsigned Opc = RISCV::ADD;
442 Register ScratchReg =
MRI.createVirtualRegister(&RISCV::GPRRegClass);
443 TII->movImm(
MBB,
II,
DL, ScratchReg, Val, Flag);
450static std::tuple<RISCVVType::VLMUL, const TargetRegisterClass &, unsigned>
452 if (NumRemaining >= 8 && RegEncoding % 8 == 0)
454 IsSpill ? RISCV::VS8R_V : RISCV::VL8RE8_V};
455 if (NumRemaining >= 4 && RegEncoding % 4 == 0)
457 IsSpill ? RISCV::VS4R_V : RISCV::VL4RE8_V};
458 if (NumRemaining >= 2 && RegEncoding % 2 == 0)
460 IsSpill ? RISCV::VS2R_V : RISCV::VL2RE8_V};
462 IsSpill ? RISCV::VS1R_V : RISCV::VL1RE8_V};
468 bool IsSpill)
const {
478 unsigned NF = ZvlssegInfo->first;
479 unsigned LMUL = ZvlssegInfo->second;
480 unsigned NumRegs = NF * LMUL;
481 assert(NumRegs <= 8 &&
"Invalid NF/LMUL combinations.");
484 uint16_t RegEncoding =
TRI->getEncodingValue(Reg);
486 bool IsBaseKill =
II->getOperand(1).isKill();
487 Register NewBase =
MRI.createVirtualRegister(&RISCV::GPRRegClass);
489 auto *OldMMO = *(
II->memoperands_begin());
495 unsigned VLENBShift = 0;
496 unsigned PrevHandledNum = 0;
498 while (
I != NumRegs) {
499 auto [LMulHandled, RegClass, Opcode] =
502 bool IsLast =
I + RegNumHandled == NumRegs;
503 if (PrevHandledNum) {
507 int64_t
Offset = *VLEN / 8 * PrevHandledNum;
508 Step =
MRI.createVirtualRegister(&RISCV::GPRRegClass);
512 VLENB =
MRI.createVirtualRegister(&RISCV::GPRRegClass);
519 if (VLENBShift > ShiftAmount) {
522 .
addImm(VLENBShift - ShiftAmount);
523 }
else if (VLENBShift < ShiftAmount) {
526 .
addImm(ShiftAmount - VLENBShift);
528 VLENBShift = ShiftAmount;
544 VRegSize * RegNumHandled));
553 PrevHandledNum = RegNumHandled;
554 RegEncoding += RegNumHandled;
557 II->eraseFromParent();
563 return RISCV::QC_E_LW;
565 return RISCV::QC_E_SW;
567 return RISCV::QC_E_LB;
569 return RISCV::QC_E_LBU;
571 return RISCV::QC_E_LH;
573 return RISCV::QC_E_LHU;
575 return RISCV::QC_E_SB;
577 return RISCV::QC_E_SH;
585 if (Lo12 < 0 || !RISCV::GPRCRegClass.
contains(
MI.getOperand(0).getReg()))
588 switch (
MI.getOpcode()) {
593 case RISCV::PseudoCCQC_E_LW:
595 case RISCV::QC_E_LBU:
597 case RISCV::PseudoCCQC_E_LBU:
598 return ST.hasStdExtZcb() &&
isUInt<2>(Lo12);
600 case RISCV::QC_E_LHU:
602 case RISCV::PseudoCCQC_E_LH:
603 case RISCV::PseudoCCQC_E_LHU:
621 int64_t Adj = Val - Imm26;
630 bool IsAddiCompressible = ST.hasStdExtZca() && FrameReg == RISCV::X2 &&
633 if (IsAddiCompressible)
644 int SPAdj,
unsigned FIOperandNum,
646 assert(SPAdj == 0 &&
"Unexpected non-zero SPAdj value");
653 bool Is64Bit = ST.is64Bit();
656 int FrameIndex =
MI.getOperand(FIOperandNum).getIndex();
659 getFrameLowering(MF)->getFrameIndexReference(MF, FrameIndex, FrameReg);
666 "not supported on RV32");
670 int64_t Val =
Offset.getFixed();
673 unsigned Opc =
MI.getOpcode();
681 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(0);
682 }
else if ((
Opc == RISCV::PREFETCH_I ||
Opc == RISCV::PREFETCH_R ||
683 Opc == RISCV::PREFETCH_W) &&
684 (Lo12 & 0b11111) != 0) {
686 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(0);
687 }
else if (
Opc == RISCV::MIPS_PREF && !
isUInt<9>(Val)) {
689 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(0);
690 }
else if ((
Opc == RISCV::PseudoRV32ZdinxLD ||
691 Opc == RISCV::PseudoRV32ZdinxSD ||
692 Opc == RISCV::PseudoLD_RV32_OPT ||
693 Opc == RISCV::PseudoSD_RV32_OPT) &&
698 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(0);
700 !
isInt<12>(Val) && ST.hasVendorXqcilo() && WideOpc) {
706 MI.setDesc(
TII->get(WideOpc));
707 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Lo26);
710 }
else if (RISCVInstrInfo::isXqciloLoad(
MI) ||
711 RISCVInstrInfo::isXqciloStore(
MI) ||
712 RISCVInstrInfo::isPredicatedXqciloLoad(
MI)) {
717 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(
Imm);
720 }
else if (
Opc == RISCV::QC_E_ADDI) {
721 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Lo26);
728 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Lo12);
736 if (
MI.getOpcode() == RISCV::ADDI)
737 DestReg =
MI.getOperand(0).getReg();
739 DestReg =
MRI.createVirtualRegister(&RISCV::GPRRegClass);
742 MI.getOperand(FIOperandNum).ChangeToRegister(DestReg,
false,
746 MI.getOperand(FIOperandNum).ChangeToRegister(FrameReg,
false,
752 if (
MI.getOpcode() == RISCV::ADDI &&
753 MI.getOperand(0).getReg() ==
MI.getOperand(1).getReg() &&
754 MI.getOperand(2).getImm() == 0) {
755 MI.eraseFromParent();
761 switch (
MI.getOpcode()) {
762 case RISCV::PseudoVSPILL2_M1:
763 case RISCV::PseudoVSPILL2_M2:
764 case RISCV::PseudoVSPILL2_M4:
765 case RISCV::PseudoVSPILL3_M1:
766 case RISCV::PseudoVSPILL3_M2:
767 case RISCV::PseudoVSPILL4_M1:
768 case RISCV::PseudoVSPILL4_M2:
769 case RISCV::PseudoVSPILL5_M1:
770 case RISCV::PseudoVSPILL6_M1:
771 case RISCV::PseudoVSPILL7_M1:
772 case RISCV::PseudoVSPILL8_M1:
775 case RISCV::PseudoVRELOAD2_M1:
776 case RISCV::PseudoVRELOAD2_M2:
777 case RISCV::PseudoVRELOAD2_M4:
778 case RISCV::PseudoVRELOAD3_M1:
779 case RISCV::PseudoVRELOAD3_M2:
780 case RISCV::PseudoVRELOAD4_M1:
781 case RISCV::PseudoVRELOAD4_M2:
782 case RISCV::PseudoVRELOAD5_M1:
783 case RISCV::PseudoVRELOAD6_M1:
784 case RISCV::PseudoVRELOAD7_M1:
785 case RISCV::PseudoVRELOAD8_M1:
804 unsigned FIOperandNum = 0;
805 for (; !
MI->getOperand(FIOperandNum).isFI(); FIOperandNum++)
806 assert(FIOperandNum < MI->getNumOperands() &&
807 "Instr doesn't have FrameIndex operand");
816 if (!
MI->mayLoad() && !
MI->mayStore())
824 if (TFI->
hasFP(MF) && !shouldRealignStack(MF)) {
828 unsigned CalleeSavedSize = 0;
831 if (
Subtarget.isRegisterReservedByUser(Reg))
834 if (RISCV::GPRRegClass.
contains(Reg))
835 CalleeSavedSize += getSpillSize(RISCV::GPRRegClass);
836 else if (RISCV::FPR64RegClass.
contains(Reg))
837 CalleeSavedSize += getSpillSize(RISCV::FPR64RegClass);
838 else if (RISCV::FPR32RegClass.
contains(Reg))
839 CalleeSavedSize += getSpillSize(RISCV::FPR32RegClass);
843 int64_t MaxFPOffset =
Offset - CalleeSavedSize;
857 int64_t MaxSPOffset =
Offset + 128;
867 unsigned FIOperandNum = 0;
868 while (!
MI->getOperand(FIOperandNum).isFI()) {
870 assert(FIOperandNum < MI->getNumOperands() &&
871 "Instr does not have a FrameIndex operand!");
903 unsigned FIOperandNum = 0;
904 while (!
MI.getOperand(FIOperandNum).isFI()) {
906 assert(FIOperandNum <
MI.getNumOperands() &&
907 "Instr does not have a FrameIndex operand!");
913 MI.getOperand(FIOperandNum).ChangeToRegister(BaseReg,
false);
914 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(
Offset);
923 "The MI must be I or S format.");
924 assert(
MI->getOperand(Idx).isFI() &&
"The Idx'th operand of MI is not a "
925 "FrameIndex operand");
926 return MI->getOperand(Idx + 1).getImm();
931 return TFI->
hasFP(MF) ? RISCV::X8 : RISCV::X2;
939 if (
TRI->isGeneralPurposeRegister(MF, Reg))
942 if (
TRI->isFPRegister(Reg))
945 if (RISCV::VRRegClass.
contains(Reg))
952 if (Reg == RISCV::SF_VCIX_STATE)
953 return "sf.vcix_state";
963 return CSR_NoRegs_RegMask;
969 return CSR_RT_MostRegs_RVE_RegMask;
970 return CSR_RT_MostRegs_RegMask;
973 return CSR_ILP32E_LP64E_RegMask;
976 return IsVectorCall ? CSR_ILP32_LP64_V_RegMask : CSR_ILP32_LP64_RegMask;
978 return IsVectorCall ? CSR_ILP32F_LP64F_V_RegMask : CSR_ILP32F_LP64F_RegMask;
980 return IsVectorCall ? CSR_ILP32D_LP64D_V_RegMask : CSR_ILP32D_LP64D_RegMask;
986 if (RC == &RISCV::VMV0RegClass)
987 return &RISCV::VRRegClass;
988 if (RC == &RISCV::VRNoV0RegClass)
989 return &RISCV::VRRegClass;
990 if (RC == &RISCV::VRM2NoV0RegClass)
991 return &RISCV::VRM2RegClass;
992 if (RC == &RISCV::VRM4NoV0RegClass)
993 return &RISCV::VRM4RegClass;
994 if (RC == &RISCV::VRM8NoV0RegClass)
995 return &RISCV::VRM8RegClass;
1004 assert(
Offset.getScalable() % 8 == 0 &&
"Invalid frame offset");
1010 int64_t VLENBSized =
Offset.getScalable() / 8;
1011 if (VLENBSized > 0) {
1012 Ops.push_back(dwarf::DW_OP_constu);
1013 Ops.push_back(VLENBSized);
1014 Ops.append({dwarf::DW_OP_bregx, VLENB, 0ULL});
1015 Ops.push_back(dwarf::DW_OP_mul);
1016 Ops.push_back(dwarf::DW_OP_plus);
1017 }
else if (VLENBSized < 0) {
1018 Ops.push_back(dwarf::DW_OP_constu);
1019 Ops.push_back(-VLENBSized);
1020 Ops.append({dwarf::DW_OP_bregx, VLENB, 0ULL});
1021 Ops.push_back(dwarf::DW_OP_mul);
1022 Ops.push_back(dwarf::DW_OP_minus);
1026std::pair<Register, Register>
1028 if (Pair == RISCV::X0_Pair)
1029 return {RISCV::X0, RISCV::X0};
1030 return {getSubReg(Pair, RISCV::sub_gpr_even),
1031 getSubReg(Pair, RISCV::sub_gpr_odd)};
1039 ST.getCLOpts().cost_per_use
1046 return getRegClassWeight(RC).RegWeight;
1059 std::pair<unsigned, Register> Hint =
MRI->getRegAllocationHint(VirtReg);
1060 unsigned HintType = Hint.first;
1072 TargetReg = PartnerPhys.
id() + (WantOdd ? 1 : -1);
1075 if (RISCV::GPRRegClass.
contains(TargetReg) &&
1084 if (TargetReg == PhysReg)
1087 unsigned RegNum = getEncodingValue(PhysReg);
1089 bool IsOdd = (RegNum % 2 != 0);
1092 MCRegister Paired = PhysReg + (IsOdd ? -1 : 1);
1093 if (WantOdd == IsOdd && !
MRI->isReserved(Paired))
1099 VirtReg, Order, Hints, MF, VRM,
Matrix);
1102 return BaseImplRetVal;
1108 bool NeedGPRC) ->
void {
1114 if (PhysReg && (!NeedGPRC || RISCV::GPRCRegClass.
contains(PhysReg)) &&
1115 !MO.getSubReg() && !VRRegMO.
getSubReg()) {
1116 if (!
MRI->isReserved(PhysReg) && !Hints.
contains(PhysReg))
1117 TwoAddrHints.
insert(PhysReg);
1125 switch (
MI.getOpcode()) {
1138 if (!
MI.getOperand(2).isImm())
1140 int64_t
Imm =
MI.getOperand(2).getImm();
1155 return MI.getOperand(2).isImm() &&
isInt<6>(
MI.getOperand(2).getImm());
1162 case RISCV::ZEXT_H_RV32:
1163 case RISCV::ZEXT_H_RV64:
1170 return Subtarget.hasStdExtZcb() &&
MI.getOperand(2).isReg() &&
1171 MI.getOperand(2).getReg() == RISCV::X0;
1175 return Subtarget.hasStdExtZcb() &&
MI.getOperand(2).isImm() &&
1176 MI.getOperand(2).getImm() == -1;
1177 case RISCV::QC_EXTU:
1178 return MI.getOperand(2).getImm() >= 6 &&
MI.getOperand(3).getImm() == 0;
1183 return Subtarget.hasVendorXqcibm() &&
MI.getOperand(2).getImm() != 0;
1196 return PhysReg && RISCV::GPRCRegClass.contains(PhysReg);
1199 for (
auto &MO :
MRI->reg_nodbg_operands(VirtReg)) {
1201 unsigned OpIdx = MO.getOperandNo();
1203 if (isCompressible(
MI, NeedGPRC)) {
1204 if (OpIdx == 0 &&
MI.getOperand(1).isReg()) {
1205 if (!NeedGPRC ||
MI.getNumExplicitOperands() < 3 ||
1206 MI.getOpcode() == RISCV::ADD_UW ||
1207 isCompressibleOpnd(
MI.getOperand(2)))
1208 tryAddHint(MO,
MI.getOperand(1), NeedGPRC);
1209 if (
MI.isCommutable() &&
MI.getOperand(2).isReg() &&
1210 (!NeedGPRC || isCompressibleOpnd(
MI.getOperand(1))))
1211 tryAddHint(MO,
MI.getOperand(2), NeedGPRC);
1212 }
else if (OpIdx == 1 && (!NeedGPRC ||
MI.getNumExplicitOperands() < 3 ||
1213 isCompressibleOpnd(
MI.getOperand(2)))) {
1214 tryAddHint(MO,
MI.getOperand(0), NeedGPRC);
1215 }
else if (
MI.isCommutable() && OpIdx == 2 &&
1216 (!NeedGPRC || isCompressibleOpnd(
MI.getOperand(1)))) {
1217 tryAddHint(MO,
MI.getOperand(0), NeedGPRC);
1224 if ((
MI.getOpcode() == RISCV::ADDIW ||
MI.getOpcode() == RISCV::ADDI) &&
1225 MI.getOperand(1).isReg()) {
1229 if (
I !=
MBB.begin()) {
1231 if ((
I->getOpcode() == RISCV::LUI ||
I->getOpcode() == RISCV::AUIPC) &&
1232 I->getOperand(0).getReg() ==
MI.getOperand(1).getReg()) {
1234 tryAddHint(MO,
MI.getOperand(1),
false);
1236 tryAddHint(MO,
MI.getOperand(0),
false);
1243 if (TwoAddrHints.
count(OrderReg))
1246 return BaseImplRetVal;
1252 std::pair<unsigned, Register> Hint =
MRI->getRegAllocationHint(Reg);
1257 Hint.second.isVirtual()) {
1262 std::pair<unsigned, Register> PartnerHint =
1263 MRI->getRegAllocationHint(Partner);
1266 if (PartnerHint.second == Reg) {
1268 MRI->setRegAllocationHint(Partner, PartnerHint.first, NewReg);
1273 MRI->setRegAllocationHint(NewReg, Hint.first, Partner);
1280 uint16_t Encoding)
const {
1284 return getMatchingSuperReg(Reg, RISCV::sub_vrm1_0, &RegClass);
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file contains constants used for implementing Dwarf debug support.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
Register const TargetRegisterInfo * TRI
Promote Memory to Register
uint64_t IntrinsicInst * II
MachineRegisterInfo & MRI
static std::optional< int64_t > getXqciloWideOffset(const RISCVSubtarget &ST, const MachineInstr &MI, Register FrameReg, int64_t Val)
static unsigned getXqciloWideOpcode(unsigned Opc)
static bool isMemoryAccessCompressible(const RISCVSubtarget &ST, const MachineInstr &MI, int64_t Lo12)
static std::tuple< RISCVVType::VLMUL, const TargetRegisterClass &, unsigned > getSpillReloadInfo(unsigned NumRemaining, uint16_t RegEncoding, bool IsSpill)
This file declares the machine register scavenger class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the SmallSet class.
static unsigned getDwarfRegNum(MCRegister Reg, const TargetRegisterInfo *TRI)
Go up the super-register chain until we hit a valid dwarf register number.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
TypeSize getValue() const
MCRegAliasIterator enumerates all registers aliasing Reg.
const uint8_t TSFlags
Configurable target specific flags.
Wrapper class representing physical registers and target specific virtual registers.
constexpr unsigned id() const
MachineInstrBundleIterator< const MachineInstr > const_iterator
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
int64_t getLocalFrameSize() const
Get the size of the local object blob.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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.
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags F, LLT MemTy, Align BaseAlignment, const MMOMetadata &Metadata=MMOMetadata(), SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
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 & addFrameIndex(int Idx) const
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
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 hasBP(const MachineFunction &MF) const
void movImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, Register DstReg, uint64_t Val, MachineInstr::MIFlag Flag=MachineInstr::NoFlags, bool DstRenamable=false, bool DstIsDead=false) const
const RISCVOptions & getCLOpts() const
std::optional< unsigned > getRealVLen() const
const RISCVRegisterInfo * getRegisterInfo() const override
const RISCVInstrInfo * getInstrInfo() const override
This class implements the register bank concept.
unsigned getID() const
Get the identifier of this register bank.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
bool contains(const_arg_type key) const
Check if the SetVector contains the given key.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StackOffset holds a fixed and a scalable offset in bytes.
int64_t getFixed() const
Returns the fixed component of the stack.
static StackOffset get(int64_t Fixed, int64_t Scalable)
Represent a constant reference to a string, i.e.
Information about stack frame layout on the target.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallSetVector< MCPhysReg, 16 > &Hints, const MachineFunction &MF, const VirtRegMap *VRM=nullptr, const LiveRegMatrix *Matrix=nullptr) const
Get a list of 'hint' registers that the register allocator should try first when allocating a physica...
virtual StringRef getRegAsmName(MCRegister Reg) const
Return the assembly name for Reg.
virtual bool isRegisterReservedByUser(Register R) const
virtual const TargetInstrInfo * getInstrInfo() const
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
bool hasPhys(Register virtReg) const
returns true if the specified virtual register is mapped to a physical register
constexpr bool isKnownMultipleOf(ScalarTy RHS) const
This function tells the caller whether the element count is known at compile time to be a multiple of...
constexpr LeafTy divideCoefficientBy(ScalarTy RHS) const
We do not provide the '/' operator here because division for polynomial types does not work in the sa...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ RISCV_VectorCall
Calling convention used for RISC-V V-extension.
@ PreserveMost
Used for runtime calls that preserves most registers.
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
@ GRAAL
Used by GraalVM. Two additional registers are reserved.
bool isRVE(ABI TargetABI)
bool isSingleFP(ABI TargetABI)
bool isDoubleFP(ABI TargetABI)
bool isPurecap(ABI TargetABI)
bool isSoftFP(ABI TargetABI)
static unsigned getFormat(uint64_t TSFlags)
static RISCVVType::VLMUL getLMul(uint8_t TSFlags)
LLVM_ABI std::pair< unsigned, bool > decodeVLMUL(VLMUL VLMul)
ArrayRef< MCPhysReg > getArgFPRs(const RISCVSubtarget &STI)
ArrayRef< MCPhysReg > getArgGPRs(const RISCVSubtarget &STI)
ArrayRef< MCPhysReg > getArgVRs(const RISCVSubtarget &STI)
std::optional< std::pair< unsigned, unsigned > > isRVVSpillForZvlsseg(unsigned Opcode)
bool isRVVSpill(const MachineInstr &MI)
static constexpr unsigned RVVBytesPerBlock
This is an optimization pass for GlobalISel generic memory operations.
PointerUnion< const TargetRegisterClass *, const RegisterBank * > RegClassOrRegBank
Convenient type to represent either a register class or a register bank.
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 RegState getKillRegState(bool B)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
constexpr int64_t minIntN(int64_t N)
Gets the minimum value for a N-bit signed integer.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr RegState getDefRegState(bool B)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
IterT skipDebugInstructionsBackward(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
constexpr bool isShiftedInt(int64_t x)
Checks if a signed integer is an N bit number shifted left by S.
constexpr int64_t maxIntN(int64_t N)
Gets the maximum value for a N-bit signed integer.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
constexpr bool isShiftedUInt(uint64_t x)
Checks if a unsigned integer is an N bit number shifted left by S.
MCRegisterClass TargetRegisterClass
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
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.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override
bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override
const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &) const override
std::pair< Register, Register > getGPRPairSubRegs(MCRegister Pair) const
bool isArgumentRegister(const MachineFunction &MF, MCRegister Reg) const override
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallSetVector< MCPhysReg, 16 > &Hints, const MachineFunction &MF, const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const override
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
MCRegister findVRegWithEncoding(const TargetRegisterClass &RegClass, uint16_t Encoding) const
Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx, int64_t Offset) const override
void getOffsetOpcodes(const StackOffset &Offset, SmallVectorImpl< uint64_t > &Ops) const override
RISCVRegisterInfo(unsigned HwMode, const std::bitset< 32 > &UserReservedXRegs)
UserReservedXRegs is the set of X registers reserved by the reserve-xN features, indexed by N.
bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg, int64_t Offset) const override
Register getFrameRegister(const MachineFunction &MF) const override
const MCPhysReg * getIPRACSRegs(const MachineFunction *MF) const override
void lowerSegmentSpillReload(MachineBasicBlock::iterator II, bool IsSpill) const
const TargetRegisterClass * getRegClassForTypeOnBank(LLT Ty, const RegisterBank &RB, bool Is64Bit) const
void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator II, const DebugLoc &DL, Register DestReg, Register SrcReg, StackOffset Offset, MachineInstr::MIFlag Flag, MaybeAlign RequiredAlign) const
void updateRegAllocHint(Register Reg, Register NewReg, MachineFunction &MF) const override
bool isAsmClobberable(const MachineFunction &MF, MCRegister PhysReg) const override
const uint32_t * getNoPreservedMask() const override
float getSpillWeightScaleFactor(const TargetRegisterClass *RC) const override
const TargetRegisterClass * getConstrainedRegClassForReg(Register Reg, const MachineRegisterInfo &MRI) const override
void resolveFrameIndex(MachineInstr &MI, Register BaseReg, int64_t Offset) const override
int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const override
unsigned getRegisterCostTableIndex(const MachineFunction &MF) const override
StringRef getRegAsmName(MCRegister Reg) const override
bool eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override