28 for (
unsigned i = 0; PSets[i] != -1; ++i) {
29 if (PSets[i] == (
int)PSetID)
35 void SIRegisterInfo::classifyPressureSet(
unsigned PSetID,
unsigned Reg,
40 PressureSets.
set(PSetID);
47 "amdgpu-spill-sgpr-to-smem",
48 cl::desc(
"Use scalar stores to spill SGPRs if supported by subtarget"),
52 "amdgpu-spill-sgpr-to-vgpr",
53 cl::desc(
"Enable spilling VGPRs to SGPRs"),
59 SGPRPressureSets(getNumRegPressureSets()),
60 VGPRPressureSets(getNumRegPressureSets()),
61 SpillSGPRToVGPR(
false),
62 SpillSGPRToSMEM(
false) {
64 SpillSGPRToSMEM =
true;
66 SpillSGPRToVGPR =
true;
68 unsigned NumRegPressureSets = getNumRegPressureSets();
70 SGPRSetID = NumRegPressureSets;
71 VGPRSetID = NumRegPressureSets;
73 for (
unsigned i = 0; i < NumRegPressureSets; ++i) {
74 classifyPressureSet(i, AMDGPU::SGPR0, SGPRPressureSets);
75 classifyPressureSet(i, AMDGPU::VGPR0, VGPRPressureSets);
79 std::vector<unsigned> PressureSetRegUnits(NumRegPressureSets, 0);
80 for (
unsigned i = 0, e = getNumRegUnits(); i != e; ++i) {
82 for (
unsigned j = 0; PSets[j] != -1; ++j) {
83 ++PressureSetRegUnits[PSets[j]];
87 unsigned VGPRMax = 0, SGPRMax = 0;
88 for (
unsigned i = 0; i < NumRegPressureSets; ++i) {
91 VGPRMax = PressureSetRegUnits[i];
96 SGPRMax = PressureSetRegUnits[i];
100 assert(SGPRSetID < NumRegPressureSets &&
101 VGPRSetID < NumRegPressureSets);
104 void SIRegisterInfo::reserveRegisterTuples(
BitVector &Reserved,
unsigned Reg)
const {
107 for (; R.isValid(); ++R)
116 unsigned BaseReg(AMDGPU::SGPR_32RegClass.getRegister(BaseIdx));
117 return getMatchingSuperReg(BaseReg, AMDGPU::sub0, &AMDGPU::SReg_128RegClass);
141 return AMDGPU::SGPR_32RegClass.getRegister(Reg);
146 return AMDGPU::SGPR32;
151 Reserved.
set(AMDGPU::INDIRECT_BASE_ADDR);
155 reserveRegisterTuples(Reserved, AMDGPU::EXEC);
156 reserveRegisterTuples(Reserved, AMDGPU::FLAT_SCR);
159 reserveRegisterTuples(Reserved, AMDGPU::M0);
162 reserveRegisterTuples(Reserved, AMDGPU::SRC_SHARED_BASE);
163 reserveRegisterTuples(Reserved, AMDGPU::SRC_SHARED_LIMIT);
164 reserveRegisterTuples(Reserved, AMDGPU::SRC_PRIVATE_BASE);
165 reserveRegisterTuples(Reserved, AMDGPU::SRC_PRIVATE_LIMIT);
168 reserveRegisterTuples(Reserved, AMDGPU::TBA);
169 reserveRegisterTuples(Reserved, AMDGPU::TMA);
170 reserveRegisterTuples(Reserved, AMDGPU::TTMP0_TTMP1);
171 reserveRegisterTuples(Reserved, AMDGPU::TTMP2_TTMP3);
172 reserveRegisterTuples(Reserved, AMDGPU::TTMP4_TTMP5);
173 reserveRegisterTuples(Reserved, AMDGPU::TTMP6_TTMP7);
174 reserveRegisterTuples(Reserved, AMDGPU::TTMP8_TTMP9);
175 reserveRegisterTuples(Reserved, AMDGPU::TTMP10_TTMP11);
180 unsigned TotalNumSGPRs = AMDGPU::SGPR_32RegClass.getNumRegs();
181 for (
unsigned i = MaxNumSGPRs; i < TotalNumSGPRs; ++i) {
182 unsigned Reg = AMDGPU::SGPR_32RegClass.getRegister(i);
183 reserveRegisterTuples(Reserved, Reg);
187 unsigned TotalNumVGPRs = AMDGPU::VGPR_32RegClass.getNumRegs();
188 for (
unsigned i = MaxNumVGPRs; i < TotalNumVGPRs; ++i) {
189 unsigned Reg = AMDGPU::VGPR_32RegClass.getRegister(i);
190 reserveRegisterTuples(Reserved, Reg);
196 if (ScratchWaveOffsetReg != AMDGPU::NoRegister) {
198 reserveRegisterTuples(Reserved, ScratchWaveOffsetReg);
202 if (ScratchRSrcReg != AMDGPU::NoRegister) {
206 reserveRegisterTuples(Reserved, ScratchRSrcReg);
207 assert(!isSubRegister(ScratchRSrcReg, ScratchWaveOffsetReg));
215 if (StackPtrReg != AMDGPU::NoRegister) {
216 reserveRegisterTuples(Reserved, StackPtrReg);
217 assert(!isSubRegister(ScratchRSrcReg, StackPtrReg));
221 if (FrameReg != AMDGPU::NoRegister) {
222 reserveRegisterTuples(Reserved, FrameReg);
223 assert(!isSubRegister(ScratchRSrcReg, FrameReg));
269 AMDGPU::OpName::offset);
279 AMDGPU::OpName::vaddr) &&
280 "Should never see frame index on non-address operand");
291 return !isUInt<12>(FullOffset);
301 if (Ins != MBB->
end())
302 DL = Ins->getDebugLoc();
309 BuildMI(*MBB, Ins, DL, TII->
get(AMDGPU::V_MOV_B32_e32), BaseReg)
310 .addFrameIndex(FrameIdx);
319 BuildMI(*MBB, Ins, DL, TII->
get(AMDGPU::S_MOV_B32), OffsetReg)
321 BuildMI(*MBB, Ins, DL, TII->
get(AMDGPU::V_MOV_B32_e32), FIReg)
322 .addFrameIndex(FrameIdx);
324 TII->getAddNoCarry(*MBB, Ins, DL, BaseReg)
350 MachineOperand *FIOp = TII->getNamedOperand(MI, AMDGPU::OpName::vaddr);
351 assert(FIOp && FIOp->
isFI() &&
"frame index must be address operand");
353 assert(TII->getNamedOperand(MI, AMDGPU::OpName::soffset)->getReg() ==
355 "should only be seeing frame offset relative FrameIndex");
358 MachineOperand *OffsetOp = TII->getNamedOperand(MI, AMDGPU::OpName::offset);
360 assert(isUInt<12>(NewOffset) &&
"offset should be legal");
363 OffsetOp->setImm(NewOffset);
374 return isUInt<12>(NewOffset);
382 return &AMDGPU::VGPR_32RegClass;
388 case AMDGPU::SI_SPILL_S512_SAVE:
389 case AMDGPU::SI_SPILL_S512_RESTORE:
390 case AMDGPU::SI_SPILL_V512_SAVE:
391 case AMDGPU::SI_SPILL_V512_RESTORE:
393 case AMDGPU::SI_SPILL_S256_SAVE:
394 case AMDGPU::SI_SPILL_S256_RESTORE:
395 case AMDGPU::SI_SPILL_V256_SAVE:
396 case AMDGPU::SI_SPILL_V256_RESTORE:
398 case AMDGPU::SI_SPILL_S128_SAVE:
399 case AMDGPU::SI_SPILL_S128_RESTORE:
400 case AMDGPU::SI_SPILL_V128_SAVE:
401 case AMDGPU::SI_SPILL_V128_RESTORE:
403 case AMDGPU::SI_SPILL_V96_SAVE:
404 case AMDGPU::SI_SPILL_V96_RESTORE:
406 case AMDGPU::SI_SPILL_S64_SAVE:
407 case AMDGPU::SI_SPILL_S64_RESTORE:
408 case AMDGPU::SI_SPILL_V64_SAVE:
409 case AMDGPU::SI_SPILL_V64_RESTORE:
411 case AMDGPU::SI_SPILL_S32_SAVE:
412 case AMDGPU::SI_SPILL_S32_RESTORE:
413 case AMDGPU::SI_SPILL_V32_SAVE:
414 case AMDGPU::SI_SPILL_V32_RESTORE:
422 case AMDGPU::BUFFER_STORE_DWORD_OFFEN:
423 return AMDGPU::BUFFER_STORE_DWORD_OFFSET;
424 case AMDGPU::BUFFER_STORE_BYTE_OFFEN:
425 return AMDGPU::BUFFER_STORE_BYTE_OFFSET;
426 case AMDGPU::BUFFER_STORE_SHORT_OFFEN:
427 return AMDGPU::BUFFER_STORE_SHORT_OFFSET;
428 case AMDGPU::BUFFER_STORE_DWORDX2_OFFEN:
429 return AMDGPU::BUFFER_STORE_DWORDX2_OFFSET;
430 case AMDGPU::BUFFER_STORE_DWORDX4_OFFEN:
431 return AMDGPU::BUFFER_STORE_DWORDX4_OFFSET;
439 case AMDGPU::BUFFER_LOAD_DWORD_OFFEN:
440 return AMDGPU::BUFFER_LOAD_DWORD_OFFSET;
441 case AMDGPU::BUFFER_LOAD_UBYTE_OFFEN:
442 return AMDGPU::BUFFER_LOAD_UBYTE_OFFSET;
443 case AMDGPU::BUFFER_LOAD_SBYTE_OFFEN:
444 return AMDGPU::BUFFER_LOAD_SBYTE_OFFSET;
445 case AMDGPU::BUFFER_LOAD_USHORT_OFFEN:
446 return AMDGPU::BUFFER_LOAD_USHORT_OFFSET;
447 case AMDGPU::BUFFER_LOAD_SSHORT_OFFEN:
448 return AMDGPU::BUFFER_LOAD_SSHORT_OFFSET;
449 case AMDGPU::BUFFER_LOAD_DWORDX2_OFFEN:
450 return AMDGPU::BUFFER_LOAD_DWORDX2_OFFSET;
451 case AMDGPU::BUFFER_LOAD_DWORDX4_OFFEN:
452 return AMDGPU::BUFFER_LOAD_DWORDX4_OFFSET;
467 bool IsStore = MI->mayStore();
469 unsigned Opc = MI->getOpcode();
470 int LoadStoreOp = IsStore ?
472 if (LoadStoreOp == -1)
477 BuildMI(*MBB, MI, DL, TII->get(LoadStoreOp))
485 .setMemRefs(MI->memoperands_begin(), MI->memoperands_end());
490 unsigned LoadStoreOp,
494 unsigned ScratchRsrcReg,
495 unsigned ScratchOffsetReg,
509 bool RanOutOfSGPRs =
false;
510 bool Scavenged =
false;
511 unsigned SOffset = ScratchOffsetReg;
515 unsigned Size = NumSubRegs * 4;
517 const int64_t OriginalImmOffset =
Offset;
522 if (!isUInt<12>(Offset + Size)) {
523 SOffset = AMDGPU::NoRegister;
530 if (SOffset == AMDGPU::NoRegister) {
538 RanOutOfSGPRs =
true;
539 SOffset = ScratchOffsetReg;
544 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_ADD_U32), SOffset)
545 .addReg(ScratchOffsetReg)
551 const unsigned EltSize = 4;
553 for (
unsigned i = 0, e = NumSubRegs; i != e; ++i, Offset += EltSize) {
554 unsigned SubReg = NumSubRegs == 1 ?
557 unsigned SOffsetRegState = 0;
568 EltSize,
MinAlign(Align, EltSize * i));
570 auto MIB =
BuildMI(*MBB, MI, DL, Desc)
573 .
addReg(SOffset, SOffsetRegState)
586 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_SUB_U32), ScratchOffsetReg)
587 .addReg(ScratchOffsetReg)
588 .
addImm(OriginalImmOffset);
594 if (SuperRegSize % 16 == 0) {
595 return { 16, Store ? AMDGPU::S_BUFFER_STORE_DWORDX4_SGPR :
596 AMDGPU::S_BUFFER_LOAD_DWORDX4_SGPR };
599 if (SuperRegSize % 8 == 0) {
600 return { 8, Store ? AMDGPU::S_BUFFER_STORE_DWORDX2_SGPR :
601 AMDGPU::S_BUFFER_LOAD_DWORDX2_SGPR };
604 return { 4, Store ? AMDGPU::S_BUFFER_STORE_DWORD_SGPR :
605 AMDGPU::S_BUFFER_LOAD_DWORD_SGPR};
611 bool OnlyToVGPR)
const {
618 bool SpillToVGPR = !VGPRSpills.empty();
619 if (OnlyToVGPR && !SpillToVGPR)
626 unsigned SuperReg = MI->getOperand(0).getReg();
627 bool IsKill = MI->getOperand(0).isKill();
628 const DebugLoc &DL = MI->getDebugLoc();
633 if (SpillToSMEM && OnlyToVGPR)
636 assert(SuperReg != AMDGPU::M0 &&
"m0 should never spill");
638 unsigned OffsetReg = AMDGPU::M0;
639 unsigned M0CopyReg = AMDGPU::NoRegister;
644 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::COPY), M0CopyReg)
649 unsigned ScalarStoreOp;
650 unsigned EltSize = 4;
655 std::tie(EltSize, ScalarStoreOp) =
660 unsigned NumSubRegs = SplitParts.
empty() ? 1 : SplitParts.
size();
664 for (
unsigned i = 0, e = NumSubRegs; i < e; ++i) {
665 unsigned SubReg = NumSubRegs == 1 ?
666 SuperReg : getSubReg(SuperReg, SplitParts[i]);
683 EltSize,
MinAlign(Align, EltSize * i));
690 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_ADD_U32), OffsetReg)
694 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_MOV_B32), OffsetReg)
698 BuildMI(*MBB, MI, DL, TII->
get(ScalarStoreOp))
712 TII->getMCOpcodeFromPseudo(AMDGPU::V_WRITELANE_B32),
731 =
BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_MOV_B32_e32), TmpReg)
732 .addReg(SubReg, SubKillState);
737 if (NumSubRegs > 1) {
739 unsigned SuperKillState = 0;
750 EltSize,
MinAlign(Align, EltSize * i));
751 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::SI_SPILL_V32_SAVE))
761 if (M0CopyReg != AMDGPU::NoRegister) {
762 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::COPY), AMDGPU::M0)
766 MI->eraseFromParent();
774 bool OnlyToVGPR)
const {
782 bool SpillToVGPR = !VGPRSpills.empty();
783 if (OnlyToVGPR && !SpillToVGPR)
789 const DebugLoc &DL = MI->getDebugLoc();
791 unsigned SuperReg = MI->getOperand(0).getReg();
793 if (SpillToSMEM && OnlyToVGPR)
796 assert(SuperReg != AMDGPU::M0 &&
"m0 should never spill");
798 unsigned OffsetReg = AMDGPU::M0;
799 unsigned M0CopyReg = AMDGPU::NoRegister;
804 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::COPY), M0CopyReg)
809 unsigned EltSize = 4;
810 unsigned ScalarLoadOp;
816 std::tie(EltSize, ScalarLoadOp) =
821 unsigned NumSubRegs = SplitParts.
empty() ? 1 : SplitParts.
size();
826 for (
unsigned i = 0, e = NumSubRegs; i < e; ++i) {
827 unsigned SubReg = NumSubRegs == 1 ?
828 SuperReg : getSubReg(SuperReg, SplitParts[i]);
837 EltSize,
MinAlign(Align, EltSize * i));
842 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_ADD_U32), OffsetReg)
846 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_MOV_B32), OffsetReg)
866 BuildMI(*MBB, MI, DL, TII->getMCOpcodeFromPseudo(AMDGPU::V_READLANE_B32),
889 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::SI_SPILL_V32_RESTORE), TmpReg)
890 .addFrameIndex(Index)
905 if (M0CopyReg != AMDGPU::NoRegister) {
906 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::COPY), AMDGPU::M0)
910 MI->eraseFromParent();
921 switch (MI->getOpcode()) {
922 case AMDGPU::SI_SPILL_S512_SAVE:
923 case AMDGPU::SI_SPILL_S256_SAVE:
924 case AMDGPU::SI_SPILL_S128_SAVE:
925 case AMDGPU::SI_SPILL_S64_SAVE:
926 case AMDGPU::SI_SPILL_S32_SAVE:
928 case AMDGPU::SI_SPILL_S512_RESTORE:
929 case AMDGPU::SI_SPILL_S256_RESTORE:
930 case AMDGPU::SI_SPILL_S128_RESTORE:
931 case AMDGPU::SI_SPILL_S64_RESTORE:
932 case AMDGPU::SI_SPILL_S32_RESTORE:
940 int SPAdj,
unsigned FIOperandNum,
952 int Index = MI->getOperand(FIOperandNum).getIndex();
954 switch (MI->getOpcode()) {
956 case AMDGPU::SI_SPILL_S512_SAVE:
957 case AMDGPU::SI_SPILL_S256_SAVE:
958 case AMDGPU::SI_SPILL_S128_SAVE:
959 case AMDGPU::SI_SPILL_S64_SAVE:
960 case AMDGPU::SI_SPILL_S32_SAVE: {
966 case AMDGPU::SI_SPILL_S512_RESTORE:
967 case AMDGPU::SI_SPILL_S256_RESTORE:
968 case AMDGPU::SI_SPILL_S128_RESTORE:
969 case AMDGPU::SI_SPILL_S64_RESTORE:
970 case AMDGPU::SI_SPILL_S32_RESTORE: {
976 case AMDGPU::SI_SPILL_V512_SAVE:
977 case AMDGPU::SI_SPILL_V256_SAVE:
978 case AMDGPU::SI_SPILL_V128_SAVE:
979 case AMDGPU::SI_SPILL_V96_SAVE:
980 case AMDGPU::SI_SPILL_V64_SAVE:
981 case AMDGPU::SI_SPILL_V32_SAVE: {
983 AMDGPU::OpName::vdata);
984 buildSpillLoadStore(MI, AMDGPU::BUFFER_STORE_DWORD_OFFSET,
987 TII->getNamedOperand(*MI, AMDGPU::OpName::srsrc)->getReg(),
988 TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg(),
989 TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm(),
990 *MI->memoperands_begin(),
993 MI->eraseFromParent();
996 case AMDGPU::SI_SPILL_V32_RESTORE:
997 case AMDGPU::SI_SPILL_V64_RESTORE:
998 case AMDGPU::SI_SPILL_V96_RESTORE:
999 case AMDGPU::SI_SPILL_V128_RESTORE:
1000 case AMDGPU::SI_SPILL_V256_RESTORE:
1001 case AMDGPU::SI_SPILL_V512_RESTORE: {
1003 AMDGPU::OpName::vdata);
1005 buildSpillLoadStore(MI, AMDGPU::BUFFER_LOAD_DWORD_OFFSET,
1008 TII->getNamedOperand(*MI, AMDGPU::OpName::srsrc)->getReg(),
1009 TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg(),
1010 TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm(),
1011 *MI->memoperands_begin(),
1013 MI->eraseFromParent();
1018 const DebugLoc &DL = MI->getDebugLoc();
1019 bool IsMUBUF = TII->isMUBUF(*MI);
1032 bool IsCopy = MI->getOpcode() == AMDGPU::V_MOV_B32_e32;
1033 unsigned ResultReg = IsCopy ?
1034 MI->getOperand(0).getReg() :
1037 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_SUB_U32), DiffReg)
1041 int64_t Offset = FrameInfo.getObjectOffset(Index);
1044 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_LSHRREV_B32_e64), ResultReg)
1053 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_LSHRREV_B32_e64), ScaledReg)
1059 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_ADD_I32_e64), ResultReg)
1064 unsigned ConstOffsetReg
1067 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_MOV_B32), ConstOffsetReg)
1069 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_ADD_I32_e64), ResultReg)
1080 MI->eraseFromParent();
1088 assert(static_cast<int>(FIOperandNum) ==
1090 AMDGPU::OpName::vaddr));
1092 assert(TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg()
1095 int64_t Offset = FrameInfo.getObjectOffset(Index);
1097 = TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm();
1098 int64_t NewOffset = OldImm +
Offset;
1100 if (isUInt<12>(NewOffset) &&
1102 MI->eraseFromParent();
1110 int64_t Offset = FrameInfo.getObjectOffset(Index);
1112 if (!TII->isImmOperandLegal(*MI, FIOperandNum, FIOp)) {
1114 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_MOV_B32_e32), TmpReg)
1123 #define AMDGPU_REG_ASM_NAMES
1126 #define REG_RANGE(BeginReg, EndReg, RegTable) \
1127 if (Reg >= BeginReg && Reg <= EndReg) { \
1128 unsigned Index = Reg - BeginReg; \
1129 assert(Index < array_lengthof(RegTable)); \
1130 return RegTable[Index]; \
1133 REG_RANGE(AMDGPU::VGPR0, AMDGPU::VGPR255, VGPR32RegNames);
1134 REG_RANGE(AMDGPU::SGPR0, AMDGPU::SGPR103, SGPR32RegNames);
1135 REG_RANGE(AMDGPU::VGPR0_VGPR1, AMDGPU::VGPR254_VGPR255, VGPR64RegNames);
1136 REG_RANGE(AMDGPU::SGPR0_SGPR1, AMDGPU::SGPR102_SGPR103, SGPR64RegNames);
1137 REG_RANGE(AMDGPU::VGPR0_VGPR1_VGPR2, AMDGPU::VGPR253_VGPR254_VGPR255,
1140 REG_RANGE(AMDGPU::VGPR0_VGPR1_VGPR2_VGPR3,
1141 AMDGPU::VGPR252_VGPR253_VGPR254_VGPR255,
1143 REG_RANGE(AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3,
1144 AMDGPU::SGPR100_SGPR101_SGPR102_SGPR103,
1147 REG_RANGE(AMDGPU::VGPR0_VGPR1_VGPR2_VGPR3_VGPR4_VGPR5_VGPR6_VGPR7,
1148 AMDGPU::VGPR248_VGPR249_VGPR250_VGPR251_VGPR252_VGPR253_VGPR254_VGPR255,
1152 AMDGPU::VGPR0_VGPR1_VGPR2_VGPR3_VGPR4_VGPR5_VGPR6_VGPR7_VGPR8_VGPR9_VGPR10_VGPR11_VGPR12_VGPR13_VGPR14_VGPR15,
1153 AMDGPU::VGPR240_VGPR241_VGPR242_VGPR243_VGPR244_VGPR245_VGPR246_VGPR247_VGPR248_VGPR249_VGPR250_VGPR251_VGPR252_VGPR253_VGPR254_VGPR255,
1156 REG_RANGE(AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3_SGPR4_SGPR5_SGPR6_SGPR7,
1157 AMDGPU::SGPR96_SGPR97_SGPR98_SGPR99_SGPR100_SGPR101_SGPR102_SGPR103,
1161 AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3_SGPR4_SGPR5_SGPR6_SGPR7_SGPR8_SGPR9_SGPR10_SGPR11_SGPR12_SGPR13_SGPR14_SGPR15,
1162 AMDGPU::SGPR88_SGPR89_SGPR90_SGPR91_SGPR92_SGPR93_SGPR94_SGPR95_SGPR96_SGPR97_SGPR98_SGPR99_SGPR100_SGPR101_SGPR102_SGPR103,
1170 case AMDGPU::FLAT_SCR:
1171 return "flat_scratch";
1172 case AMDGPU::FLAT_SCR_LO:
1173 return "flat_scratch_lo";
1174 case AMDGPU::FLAT_SCR_HI:
1175 return "flat_scratch_hi";
1188 &AMDGPU::VGPR_32RegClass,
1189 &AMDGPU::SReg_32RegClass,
1190 &AMDGPU::VReg_64RegClass,
1191 &AMDGPU::SReg_64RegClass,
1192 &AMDGPU::VReg_96RegClass,
1193 &AMDGPU::VReg_128RegClass,
1194 &AMDGPU::SReg_128RegClass,
1195 &AMDGPU::VReg_256RegClass,
1196 &AMDGPU::SReg_256RegClass,
1197 &AMDGPU::VReg_512RegClass,
1198 &AMDGPU::SReg_512RegClass,
1199 &AMDGPU::SCC_CLASSRegClass,
1203 if (BaseClass->contains(Reg)) {
1213 unsigned Size = getRegSizeInBits(*RC);
1218 return getCommonSubClass(&AMDGPU::VGPR_32RegClass, RC) !=
nullptr;
1220 return getCommonSubClass(&AMDGPU::VReg_64RegClass, RC) !=
nullptr;
1222 return getCommonSubClass(&AMDGPU::VReg_96RegClass, RC) !=
nullptr;
1224 return getCommonSubClass(&AMDGPU::VReg_128RegClass, RC) !=
nullptr;
1226 return getCommonSubClass(&AMDGPU::VReg_256RegClass, RC) !=
nullptr;
1228 return getCommonSubClass(&AMDGPU::VReg_512RegClass, RC) !=
nullptr;
1236 switch (getRegSizeInBits(*SRC)) {
1238 return &AMDGPU::VGPR_32RegClass;
1240 return &AMDGPU::VReg_64RegClass;
1242 return &AMDGPU::VReg_96RegClass;
1244 return &AMDGPU::VReg_128RegClass;
1246 return &AMDGPU::VReg_256RegClass;
1248 return &AMDGPU::VReg_512RegClass;
1256 switch (getRegSizeInBits(*VRC)) {
1258 return &AMDGPU::SGPR_32RegClass;
1260 return &AMDGPU::SReg_64RegClass;
1262 return &AMDGPU::SReg_128RegClass;
1264 return &AMDGPU::SReg_256RegClass;
1266 return &AMDGPU::SReg_512RegClass;
1274 if (SubIdx == AMDGPU::NoSubRegister)
1283 return &AMDGPU::SGPR_32RegClass;
1285 return &AMDGPU::SReg_64RegClass;
1287 return &AMDGPU::SReg_128RegClass;
1289 return &AMDGPU::SReg_256RegClass;
1297 return &AMDGPU::VGPR_32RegClass;
1299 return &AMDGPU::VReg_64RegClass;
1301 return &AMDGPU::VReg_96RegClass;
1303 return &AMDGPU::VReg_128RegClass;
1305 return &AMDGPU::VReg_256RegClass;
1317 unsigned SrcSubReg)
const {
1334 return getCommonSubClass(DefRC, SrcRC) !=
nullptr;
1349 return MFI->WorkGroupIDXSystemSGPR;
1352 return MFI->WorkGroupIDYSystemSGPR;
1355 return MFI->WorkGroupIDZSystemSGPR;
1357 return MFI->PrivateSegmentWaveByteOffsetSystemSGPR;
1360 return MFI->PrivateSegmentBufferUserSGPR;
1363 return MFI->ImplicitBufferPtrUserSGPR;
1366 return MFI->KernargSegmentPtrUserSGPR;
1369 return MFI->DispatchIDUserSGPR;
1372 return MFI->FlatScratchInitUserSGPR;
1375 return MFI->DispatchPtrUserSGPR;
1378 return MFI->QueuePtrUserSGPR;
1381 return AMDGPU::VGPR0;
1384 return AMDGPU::VGPR1;
1387 return AMDGPU::VGPR2;
1400 for (
unsigned Reg : *RC)
1403 return AMDGPU::NoRegister;
1407 unsigned EltSize)
const {
1409 static const int16_t Sub0_15[] = {
1410 AMDGPU::sub0, AMDGPU::sub1, AMDGPU::sub2, AMDGPU::sub3,
1411 AMDGPU::sub4, AMDGPU::sub5, AMDGPU::sub6, AMDGPU::sub7,
1412 AMDGPU::sub8, AMDGPU::sub9, AMDGPU::sub10, AMDGPU::sub11,
1413 AMDGPU::sub12, AMDGPU::sub13, AMDGPU::sub14, AMDGPU::sub15,
1416 static const int16_t Sub0_7[] = {
1417 AMDGPU::sub0, AMDGPU::sub1, AMDGPU::sub2, AMDGPU::sub3,
1418 AMDGPU::sub4, AMDGPU::sub5, AMDGPU::sub6, AMDGPU::sub7,
1421 static const int16_t Sub0_3[] = {
1422 AMDGPU::sub0, AMDGPU::sub1, AMDGPU::sub2, AMDGPU::sub3,
1425 static const int16_t Sub0_2[] = {
1426 AMDGPU::sub0, AMDGPU::sub1, AMDGPU::sub2,
1429 static const int16_t Sub0_1[] = {
1430 AMDGPU::sub0, AMDGPU::sub1,
1452 static const int16_t Sub0_15_64[] = {
1453 AMDGPU::sub0_sub1, AMDGPU::sub2_sub3,
1454 AMDGPU::sub4_sub5, AMDGPU::sub6_sub7,
1455 AMDGPU::sub8_sub9, AMDGPU::sub10_sub11,
1456 AMDGPU::sub12_sub13, AMDGPU::sub14_sub15
1459 static const int16_t Sub0_7_64[] = {
1460 AMDGPU::sub0_sub1, AMDGPU::sub2_sub3,
1461 AMDGPU::sub4_sub5, AMDGPU::sub6_sub7
1465 static const int16_t Sub0_3_64[] = {
1466 AMDGPU::sub0_sub1, AMDGPU::sub2_sub3
1483 assert(EltSize == 16 &&
"unhandled register spill split size");
1485 static const int16_t Sub0_15_128[] = {
1486 AMDGPU::sub0_sub1_sub2_sub3,
1487 AMDGPU::sub4_sub5_sub6_sub7,
1488 AMDGPU::sub8_sub9_sub10_sub11,
1489 AMDGPU::sub12_sub13_sub14_sub15
1492 static const int16_t Sub0_7_128[] = {
1493 AMDGPU::sub0_sub1_sub2_sub3,
1494 AMDGPU::sub4_sub5_sub6_sub7
1511 unsigned Reg)
const {
1519 unsigned Reg)
const {
1529 unsigned SrcSize = getRegSizeInBits(*SrcRC);
1530 unsigned DstSize = getRegSizeInBits(*DstRC);
1531 unsigned NewSize = getRegSizeInBits(*NewRC);
1537 if (SrcSize <= 32 || DstSize <= 32)
1540 return NewSize <= DstSize || NewSize <= SrcSize;
1551 switch (RC->
getID()) {
1553 return AMDGPURegisterInfo::getRegPressureLimit(RC, MF);
1554 case AMDGPU::VGPR_32RegClassID:
1556 case AMDGPU::SGPR_32RegClassID:
1562 unsigned Idx)
const {
1565 const_cast<MachineFunction &>(MF));
1569 const_cast<MachineFunction &>(MF));
1571 return AMDGPURegisterInfo::getRegPressureSetLimit(MF, Idx);
1575 static const int Empty[] = { -1 };
1577 if (hasRegUnit(AMDGPU::M0, RegUnit))
1579 return AMDGPURegisterInfo::getRegUnitPressureSets(RegUnit);
void materializeFrameBaseRegister(MachineBasicBlock *MBB, unsigned BaseReg, int FrameIdx, int64_t Offset) const override
bool eliminateSGPRToVGPRSpillFrameIndex(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS) const
Special case of eliminateFrameIndex.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool requiresRegisterScavenging(const MachineFunction &Fn) const override
unsigned reservedStackPtrOffsetReg(const MachineFunction &MF) const
Interface definition for SIRegisterInfo.
bool spillSGPRToSMEM() const
SIRegisterInfo(const SISubtarget &ST)
ArrayRef< int16_t > getRegSplitParts(const TargetRegisterClass *RC, unsigned EltSize) const
bool hasFlatScratchInit() const
Flags getFlags() const
Return the raw flags of the source value,.
AMDGPU specific subclass of TargetSubtarget.
bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override
void addToSpilledSGPRs(unsigned num)
virtual StringRef getRegAsmName(unsigned Reg) const
Return the assembly name for Reg.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
void addToSpilledVGPRs(unsigned num)
bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value...
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg, int64_t Offset) const override
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static int getOffsetMUBUFLoad(unsigned Opc)
StringRef getRegAsmName(unsigned Reg) const override
bool isSGPRPressureSet(unsigned SetID) const
unsigned getMaxNumVGPRs(unsigned WavesPerEU) const
bool hasDispatchID() const
bool mayStore() const
Return true if this instruction could possibly modify memory.
Describe properties that are true of each instruction in the target description file.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
static std::pair< unsigned, unsigned > getSpillEltSize(unsigned SuperRegSize, bool Store)
const SIInstrInfo * getInstrInfo() const override
const TargetRegisterClass * getRegClassForReg(const MachineRegisterInfo &MRI, unsigned Reg) const
bool hasImplicitBufferPtr() const
unsigned getRegBitWidth(unsigned RCID)
Get the size in bits of a register from the register class RC.
bool hasWorkGroupIDZ() const
unsigned getScratchWaveOffsetReg() const
unsigned getID() const
Return the register class ID number.
bool requiresVirtualBaseRegisters(const MachineFunction &Fn) const override
static unsigned findPrivateSegmentWaveByteOffsetRegIndex(unsigned RegCount)
bool isSGPRClass(const TargetRegisterClass *RC) const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
const MachinePointerInfo & getPointerInfo() const
bool hasWorkItemIDZ() const
iterator_range< mop_iterator > operands()
int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const override
void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg, int64_t Offset) const override
static unsigned getNumSubRegsForSpillOp(unsigned Op)
unsigned getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses...
const TargetRegisterClass * getSubRegClass(const TargetRegisterClass *RC, unsigned SubIdx) const
bool hasWorkGroupIDY() const
bool requiresFrameIndexScavenging(const MachineFunction &MF) const override
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the largest uint64_t less than or equal to Value and is Skew mod Align.
unsigned reservedPrivateSegmentWaveByteOffsetReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch wave offset in case spilling is needed...
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
const HexagonInstrInfo * TII
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
MachinePointerInfo getWithOffset(int64_t O) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
static bool hasPressureSet(const int *PSets, unsigned PSetID)
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const override
static bool isMUBUF(const MachineInstr &MI)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
int64_t getMUBUFInstrOffset(const MachineInstr *MI) const
bool hasWorkGroupIDX() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
size_t size() const
size - Get the array size.
unsigned getKillRegState(bool B)
bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const override
unsigned getVGPRPressureSet() const
const int * getRegUnitPressureSets(unsigned RegUnit) const override
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
#define REG_RANGE(BeginReg, EndReg, RegTable)
const MachineBasicBlock * getParent() const
bool restoreSGPR(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, bool OnlyToVGPR=false) const
unsigned getDefRegState(bool B)
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Function Alias Analysis false
initializer< Ty > init(const Ty &Val)
This file declares the machine register scavenger class.
const TargetRegisterClass * getEquivalentVGPRClass(const TargetRegisterClass *SRC) const
unsigned const MachineRegisterInfo * MRI
bool hasVGPRs(const TargetRegisterClass *RC) const
unsigned getPreloadedValue(const MachineFunction &MF, enum PreloadedValue Value) const
Returns the physical register that Value is stored in.
bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg, const TargetRegisterClass *DstRC, unsigned DstSubReg, const TargetRegisterClass *NewRC) const override
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static cl::opt< bool > EnableSpillSGPRToSMEM("amdgpu-spill-sgpr-to-smem", cl::desc("Use scalar stores to spill SGPRs if supported by subtarget"), cl::init(false))
static bool buildMUBUFOffsetLoadStore(const SIInstrInfo *TII, MachineFrameInfo &MFI, MachineBasicBlock::iterator MI, int Index, int64_t Offset)
const MachineOperand & getOperand(unsigned i) const
const TargetRegisterClass * getEquivalentSGPRClass(const TargetRegisterClass *VRC) const
unsigned getSubRegFromChannel(unsigned Channel) const
bool hasDispatchPtr() const
MCRegAliasIterator enumerates all registers aliasing Reg.
bool hasKernargSegmentPtr() const
bool hasScalarStores() const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
bool hasWorkItemIDX() const
bool empty() const
empty - Check if the array is empty.
void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS) const override
unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const
Inverse of getMaxLocalMemWithWaveCount.
BitVector getReservedRegs(const MachineFunction &MF) const override
bool hasInv2PiInlineImm() const
This class contains a discriminated union of information about pointers in memory operands...
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
The memory access writes data.
bool hasCalls() const
Return true if the current function has any function calls.
unsigned countPopulation(T Value)
Count the number of set bits in a value.
unsigned getRegPressureSetLimit(const MachineFunction &MF, unsigned Idx) const override
MachineOperand class - Representation of each machine instruction operand.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
void setRegAllocationHint(unsigned VReg, unsigned Type, unsigned PrefReg)
setRegAllocationHint - Specify a register allocation hint for the specified virtual register...
bool isRegUsed(unsigned Reg, bool includeReserved=true) const
Return if a specific register is currently used.
ArrayRef< SpilledReg > getSGPRToVGPRSpills(int FrameIndex) const
bool isAllocatable(unsigned PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
static cl::opt< bool > EnableSpillSGPRToVGPR("amdgpu-spill-sgpr-to-vgpr", cl::desc("Enable spilling VGPRs to SGPRs"), cl::ReallyHidden, cl::init(true))
const MachineInstrBuilder & addFrameIndex(int Idx) const
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
const MCRegisterClass * MC
const TargetRegisterClass * getPhysRegClass(unsigned Reg) const
Return the 'base' register class for this register.
bool isEntryFunction() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
The memory access reads data.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Representation of each machine instruction.
unsigned findUnusedRegister(const MachineRegisterInfo &MRI, const TargetRegisterClass *RC, const MachineFunction &MF) const
Returns a register that is not used at any point in the function.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
unsigned FindUnusedReg(const TargetRegisterClass *RegClass) const
Find an unused register of the specified register class.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override
unsigned getWavefrontSize() const
static int getOffsetMUBUFStore(unsigned Opc)
unsigned getSGPRPressureSet() const
bool hasWorkItemIDY() const
unsigned getReg() const
getReg - Returns the register number.
bool isVGPRPressureSet(unsigned SetID) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool spillSGPR(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, bool OnlyToVGPR=false) const
If OnlyToVGPR is true, this will only succeed if this.
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
LLVM Value Representation.
unsigned reservedPrivateSegmentBufferReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch buffer in case spilling is needed...
unsigned getFrameOffsetReg() const
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const
unsigned getStackPtrOffsetReg() const
StringRef - Represent a constant reference to a string, i.e.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
bool hasPrivateSegmentBuffer() const