30 for (
unsigned i = 0; PSets[i] != -1; ++i) {
31 if (PSets[i] == (
int)PSetID)
37 void SIRegisterInfo::classifyPressureSet(
unsigned PSetID,
unsigned Reg,
42 PressureSets.
set(PSetID);
49 "amdgpu-spill-sgpr-to-smem",
50 cl::desc(
"Use scalar stores to spill SGPRs if supported by subtarget"),
54 "amdgpu-spill-sgpr-to-vgpr",
55 cl::desc(
"Enable spilling VGPRs to SGPRs"),
61 SGPRPressureSets(getNumRegPressureSets()),
62 VGPRPressureSets(getNumRegPressureSets()),
63 SpillSGPRToVGPR(
false),
64 SpillSGPRToSMEM(
false) {
66 SpillSGPRToSMEM =
true;
67 else if (EnableSpillSGPRToVGPR)
68 SpillSGPRToVGPR =
true;
70 unsigned NumRegPressureSets = getNumRegPressureSets();
72 SGPRSetID = NumRegPressureSets;
73 VGPRSetID = NumRegPressureSets;
75 for (
unsigned i = 0; i < NumRegPressureSets; ++i) {
76 classifyPressureSet(i, AMDGPU::SGPR0, SGPRPressureSets);
77 classifyPressureSet(i, AMDGPU::VGPR0, VGPRPressureSets);
81 std::vector<unsigned> PressureSetRegUnits(NumRegPressureSets, 0);
82 for (
unsigned i = 0, e = getNumRegUnits(); i != e; ++i) {
84 for (
unsigned j = 0; PSets[j] != -1; ++j) {
85 ++PressureSetRegUnits[PSets[j]];
89 unsigned VGPRMax = 0, SGPRMax = 0;
90 for (
unsigned i = 0; i < NumRegPressureSets; ++i) {
93 VGPRMax = PressureSetRegUnits[i];
98 SGPRMax = PressureSetRegUnits[i];
102 assert(SGPRSetID < NumRegPressureSets &&
103 VGPRSetID < NumRegPressureSets);
111 unsigned BaseReg(AMDGPU::SGPR_32RegClass.getRegister(BaseIdx));
112 return getMatchingSuperReg(BaseReg, AMDGPU::sub0, &AMDGPU::SReg_128RegClass);
136 return AMDGPU::SGPR_32RegClass.getRegister(Reg);
141 return AMDGPU::SGPR32;
179 unsigned TotalNumSGPRs = AMDGPU::SGPR_32RegClass.getNumRegs();
180 for (
unsigned i = MaxNumSGPRs; i < TotalNumSGPRs; ++i) {
181 unsigned Reg = AMDGPU::SGPR_32RegClass.getRegister(i);
186 unsigned TotalNumVGPRs = AMDGPU::VGPR_32RegClass.getNumRegs();
187 for (
unsigned i = MaxNumVGPRs; i < TotalNumVGPRs; ++i) {
188 unsigned Reg = AMDGPU::VGPR_32RegClass.getRegister(i);
195 if (ScratchWaveOffsetReg != AMDGPU::NoRegister) {
201 if (ScratchRSrcReg != AMDGPU::NoRegister) {
206 assert(!isSubRegister(ScratchRSrcReg, ScratchWaveOffsetReg));
214 if (StackPtrReg != AMDGPU::NoRegister) {
216 assert(!isSubRegister(ScratchRSrcReg, StackPtrReg));
220 if (FrameReg != AMDGPU::NoRegister) {
222 assert(!isSubRegister(ScratchRSrcReg, FrameReg));
275 AMDGPU::OpName::offset);
285 AMDGPU::OpName::vaddr) &&
286 "Should never see frame index on non-address operand");
297 return !isUInt<12>(FullOffset);
307 if (Ins != MBB->
end())
308 DL = Ins->getDebugLoc();
315 BuildMI(*MBB, Ins, DL, TII->
get(AMDGPU::V_MOV_B32_e32), BaseReg)
316 .addFrameIndex(FrameIdx);
325 BuildMI(*MBB, Ins, DL, TII->
get(AMDGPU::S_MOV_B32), OffsetReg)
327 BuildMI(*MBB, Ins, DL, TII->
get(AMDGPU::V_MOV_B32_e32), FIReg)
328 .addFrameIndex(FrameIdx);
330 TII->getAddNoCarry(*MBB, Ins, DL, BaseReg)
356 MachineOperand *FIOp = TII->getNamedOperand(MI, AMDGPU::OpName::vaddr);
357 assert(FIOp && FIOp->
isFI() &&
"frame index must be address operand");
359 assert(TII->getNamedOperand(MI, AMDGPU::OpName::soffset)->getReg() ==
361 "should only be seeing frame offset relative FrameIndex");
364 MachineOperand *OffsetOp = TII->getNamedOperand(MI, AMDGPU::OpName::offset);
366 assert(isUInt<12>(NewOffset) &&
"offset should be legal");
369 OffsetOp->setImm(NewOffset);
380 return isUInt<12>(NewOffset);
388 return &AMDGPU::VGPR_32RegClass;
394 case AMDGPU::SI_SPILL_S512_SAVE:
395 case AMDGPU::SI_SPILL_S512_RESTORE:
396 case AMDGPU::SI_SPILL_V512_SAVE:
397 case AMDGPU::SI_SPILL_V512_RESTORE:
399 case AMDGPU::SI_SPILL_S256_SAVE:
400 case AMDGPU::SI_SPILL_S256_RESTORE:
401 case AMDGPU::SI_SPILL_V256_SAVE:
402 case AMDGPU::SI_SPILL_V256_RESTORE:
404 case AMDGPU::SI_SPILL_S128_SAVE:
405 case AMDGPU::SI_SPILL_S128_RESTORE:
406 case AMDGPU::SI_SPILL_V128_SAVE:
407 case AMDGPU::SI_SPILL_V128_RESTORE:
409 case AMDGPU::SI_SPILL_V96_SAVE:
410 case AMDGPU::SI_SPILL_V96_RESTORE:
412 case AMDGPU::SI_SPILL_S64_SAVE:
413 case AMDGPU::SI_SPILL_S64_RESTORE:
414 case AMDGPU::SI_SPILL_V64_SAVE:
415 case AMDGPU::SI_SPILL_V64_RESTORE:
417 case AMDGPU::SI_SPILL_S32_SAVE:
418 case AMDGPU::SI_SPILL_S32_RESTORE:
419 case AMDGPU::SI_SPILL_V32_SAVE:
420 case AMDGPU::SI_SPILL_V32_RESTORE:
428 case AMDGPU::BUFFER_STORE_DWORD_OFFEN:
429 return AMDGPU::BUFFER_STORE_DWORD_OFFSET;
430 case AMDGPU::BUFFER_STORE_BYTE_OFFEN:
431 return AMDGPU::BUFFER_STORE_BYTE_OFFSET;
432 case AMDGPU::BUFFER_STORE_SHORT_OFFEN:
433 return AMDGPU::BUFFER_STORE_SHORT_OFFSET;
434 case AMDGPU::BUFFER_STORE_DWORDX2_OFFEN:
435 return AMDGPU::BUFFER_STORE_DWORDX2_OFFSET;
436 case AMDGPU::BUFFER_STORE_DWORDX4_OFFEN:
437 return AMDGPU::BUFFER_STORE_DWORDX4_OFFSET;
438 case AMDGPU::BUFFER_STORE_SHORT_D16_HI_OFFEN:
439 return AMDGPU::BUFFER_STORE_SHORT_D16_HI_OFFSET;
440 case AMDGPU::BUFFER_STORE_BYTE_D16_HI_OFFEN:
441 return AMDGPU::BUFFER_STORE_BYTE_D16_HI_OFFSET;
449 case AMDGPU::BUFFER_LOAD_DWORD_OFFEN:
450 return AMDGPU::BUFFER_LOAD_DWORD_OFFSET;
451 case AMDGPU::BUFFER_LOAD_UBYTE_OFFEN:
452 return AMDGPU::BUFFER_LOAD_UBYTE_OFFSET;
453 case AMDGPU::BUFFER_LOAD_SBYTE_OFFEN:
454 return AMDGPU::BUFFER_LOAD_SBYTE_OFFSET;
455 case AMDGPU::BUFFER_LOAD_USHORT_OFFEN:
456 return AMDGPU::BUFFER_LOAD_USHORT_OFFSET;
457 case AMDGPU::BUFFER_LOAD_SSHORT_OFFEN:
458 return AMDGPU::BUFFER_LOAD_SSHORT_OFFSET;
459 case AMDGPU::BUFFER_LOAD_DWORDX2_OFFEN:
460 return AMDGPU::BUFFER_LOAD_DWORDX2_OFFSET;
461 case AMDGPU::BUFFER_LOAD_DWORDX4_OFFEN:
462 return AMDGPU::BUFFER_LOAD_DWORDX4_OFFSET;
463 case AMDGPU::BUFFER_LOAD_UBYTE_D16_OFFEN:
464 return AMDGPU::BUFFER_LOAD_UBYTE_D16_OFFSET;
465 case AMDGPU::BUFFER_LOAD_UBYTE_D16_HI_OFFEN:
466 return AMDGPU::BUFFER_LOAD_UBYTE_D16_HI_OFFSET;
467 case AMDGPU::BUFFER_LOAD_SBYTE_D16_OFFEN:
468 return AMDGPU::BUFFER_LOAD_SBYTE_D16_OFFSET;
469 case AMDGPU::BUFFER_LOAD_SBYTE_D16_HI_OFFEN:
470 return AMDGPU::BUFFER_LOAD_SBYTE_D16_HI_OFFSET;
471 case AMDGPU::BUFFER_LOAD_SHORT_D16_OFFEN:
472 return AMDGPU::BUFFER_LOAD_SHORT_D16_OFFSET;
473 case AMDGPU::BUFFER_LOAD_SHORT_D16_HI_OFFEN:
474 return AMDGPU::BUFFER_LOAD_SHORT_D16_HI_OFFSET;
488 const DebugLoc &DL = MI->getDebugLoc();
489 bool IsStore = MI->mayStore();
491 unsigned Opc = MI->getOpcode();
492 int LoadStoreOp = IsStore ?
494 if (LoadStoreOp == -1)
506 .setMemRefs(MI->memoperands_begin(), MI->memoperands_end());
509 AMDGPU::OpName::vdata_in);
516 unsigned LoadStoreOp,
520 unsigned ScratchRsrcReg,
521 unsigned ScratchOffsetReg,
532 const DebugLoc &DL = MI->getDebugLoc();
535 bool Scavenged =
false;
536 unsigned SOffset = ScratchOffsetReg;
538 const unsigned EltSize = 4;
541 unsigned Size = NumSubRegs * EltSize;
543 int64_t ScratchOffsetRegDelta = 0;
548 assert((Offset % EltSize) == 0 &&
"unexpected VGPR spill offset");
550 if (!isUInt<12>(Offset + Size - EltSize)) {
551 SOffset = AMDGPU::NoRegister;
563 if (SOffset == AMDGPU::NoRegister) {
571 SOffset = ScratchOffsetReg;
572 ScratchOffsetRegDelta =
Offset;
577 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_ADD_U32), SOffset)
578 .addReg(ScratchOffsetReg)
584 for (
unsigned i = 0, e = NumSubRegs; i != e; ++i, Offset += EltSize) {
585 unsigned SubReg = NumSubRegs == 1 ?
588 unsigned SOffsetRegState = 0;
599 EltSize,
MinAlign(Align, EltSize * i));
601 auto MIB =
BuildMI(*MBB, MI, DL, Desc)
604 .
addReg(SOffset, SOffsetRegState)
615 if (ScratchOffsetRegDelta != 0) {
617 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_SUB_U32), ScratchOffsetReg)
618 .addReg(ScratchOffsetReg)
619 .
addImm(ScratchOffsetRegDelta);
625 if (SuperRegSize % 16 == 0) {
626 return { 16, Store ? AMDGPU::S_BUFFER_STORE_DWORDX4_SGPR :
627 AMDGPU::S_BUFFER_LOAD_DWORDX4_SGPR };
630 if (SuperRegSize % 8 == 0) {
631 return { 8, Store ? AMDGPU::S_BUFFER_STORE_DWORDX2_SGPR :
632 AMDGPU::S_BUFFER_LOAD_DWORDX2_SGPR };
635 return { 4, Store ? AMDGPU::S_BUFFER_STORE_DWORD_SGPR :
636 AMDGPU::S_BUFFER_LOAD_DWORD_SGPR};
642 bool OnlyToVGPR)
const {
650 bool SpillToVGPR = !VGPRSpills.
empty();
651 if (OnlyToVGPR && !SpillToVGPR)
658 unsigned SuperReg = MI->getOperand(0).getReg();
659 bool IsKill = MI->getOperand(0).isKill();
660 const DebugLoc &DL = MI->getDebugLoc();
665 if (SpillToSMEM && OnlyToVGPR)
672 assert(SuperReg != AMDGPU::M0 &&
"m0 should never spill");
674 unsigned OffsetReg = AMDGPU::M0;
675 unsigned M0CopyReg = AMDGPU::NoRegister;
680 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::COPY), M0CopyReg)
685 unsigned ScalarStoreOp;
686 unsigned EltSize = 4;
691 std::tie(EltSize, ScalarStoreOp) =
696 unsigned NumSubRegs = SplitParts.
empty() ? 1 : SplitParts.
size();
700 for (
unsigned i = 0, e = NumSubRegs; i < e; ++i) {
701 unsigned SubReg = NumSubRegs == 1 ?
702 SuperReg : getSubReg(SuperReg, SplitParts[i]);
719 EltSize,
MinAlign(Align, EltSize * i));
726 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_ADD_U32), OffsetReg)
730 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_MOV_B32), OffsetReg)
734 BuildMI(*MBB, MI, DL, TII->
get(ScalarStoreOp))
750 bool VGPRDefined =
true;
751 if (MBB == &MF->
front())
752 VGPRDefined = !SGPRSpillVGPRDefinedSet.insert(Spill.
VGPR).second;
757 TII->getMCOpcodeFromPseudo(AMDGPU::V_WRITELANE_B32),
777 =
BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_MOV_B32_e32), TmpReg)
778 .addReg(SubReg, SubKillState);
783 if (NumSubRegs > 1) {
785 unsigned SuperKillState = 0;
796 EltSize,
MinAlign(Align, EltSize * i));
797 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::SI_SPILL_V32_SAVE))
807 if (M0CopyReg != AMDGPU::NoRegister) {
808 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::COPY), AMDGPU::M0)
812 MI->eraseFromParent();
820 bool OnlyToVGPR)
const {
828 bool SpillToVGPR = !VGPRSpills.empty();
829 if (OnlyToVGPR && !SpillToVGPR)
835 const DebugLoc &DL = MI->getDebugLoc();
837 unsigned SuperReg = MI->getOperand(0).getReg();
839 if (SpillToSMEM && OnlyToVGPR)
842 assert(SuperReg != AMDGPU::M0 &&
"m0 should never spill");
844 unsigned OffsetReg = AMDGPU::M0;
845 unsigned M0CopyReg = AMDGPU::NoRegister;
850 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::COPY), M0CopyReg)
855 unsigned EltSize = 4;
856 unsigned ScalarLoadOp;
862 std::tie(EltSize, ScalarLoadOp) =
867 unsigned NumSubRegs = SplitParts.
empty() ? 1 : SplitParts.
size();
872 for (
unsigned i = 0, e = NumSubRegs; i < e; ++i) {
873 unsigned SubReg = NumSubRegs == 1 ?
874 SuperReg : getSubReg(SuperReg, SplitParts[i]);
883 EltSize,
MinAlign(Align, EltSize * i));
888 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_ADD_U32), OffsetReg)
892 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_MOV_B32), OffsetReg)
912 BuildMI(*MBB, MI, DL, TII->getMCOpcodeFromPseudo(AMDGPU::V_READLANE_B32),
935 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::SI_SPILL_V32_RESTORE), TmpReg)
936 .addFrameIndex(Index)
951 if (M0CopyReg != AMDGPU::NoRegister) {
952 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::COPY), AMDGPU::M0)
956 MI->eraseFromParent();
967 switch (MI->getOpcode()) {
968 case AMDGPU::SI_SPILL_S512_SAVE:
969 case AMDGPU::SI_SPILL_S256_SAVE:
970 case AMDGPU::SI_SPILL_S128_SAVE:
971 case AMDGPU::SI_SPILL_S64_SAVE:
972 case AMDGPU::SI_SPILL_S32_SAVE:
974 case AMDGPU::SI_SPILL_S512_RESTORE:
975 case AMDGPU::SI_SPILL_S256_RESTORE:
976 case AMDGPU::SI_SPILL_S128_RESTORE:
977 case AMDGPU::SI_SPILL_S64_RESTORE:
978 case AMDGPU::SI_SPILL_S32_RESTORE:
986 int SPAdj,
unsigned FIOperandNum,
998 int Index = MI->getOperand(FIOperandNum).getIndex();
1000 switch (MI->getOpcode()) {
1002 case AMDGPU::SI_SPILL_S512_SAVE:
1003 case AMDGPU::SI_SPILL_S256_SAVE:
1004 case AMDGPU::SI_SPILL_S128_SAVE:
1005 case AMDGPU::SI_SPILL_S64_SAVE:
1006 case AMDGPU::SI_SPILL_S32_SAVE: {
1012 case AMDGPU::SI_SPILL_S512_RESTORE:
1013 case AMDGPU::SI_SPILL_S256_RESTORE:
1014 case AMDGPU::SI_SPILL_S128_RESTORE:
1015 case AMDGPU::SI_SPILL_S64_RESTORE:
1016 case AMDGPU::SI_SPILL_S32_RESTORE: {
1022 case AMDGPU::SI_SPILL_V512_SAVE:
1023 case AMDGPU::SI_SPILL_V256_SAVE:
1024 case AMDGPU::SI_SPILL_V128_SAVE:
1025 case AMDGPU::SI_SPILL_V96_SAVE:
1026 case AMDGPU::SI_SPILL_V64_SAVE:
1027 case AMDGPU::SI_SPILL_V32_SAVE: {
1029 AMDGPU::OpName::vdata);
1030 buildSpillLoadStore(MI, AMDGPU::BUFFER_STORE_DWORD_OFFSET,
1033 TII->getNamedOperand(*MI, AMDGPU::OpName::srsrc)->getReg(),
1034 TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg(),
1035 TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm(),
1036 *MI->memoperands_begin(),
1039 MI->eraseFromParent();
1042 case AMDGPU::SI_SPILL_V32_RESTORE:
1043 case AMDGPU::SI_SPILL_V64_RESTORE:
1044 case AMDGPU::SI_SPILL_V96_RESTORE:
1045 case AMDGPU::SI_SPILL_V128_RESTORE:
1046 case AMDGPU::SI_SPILL_V256_RESTORE:
1047 case AMDGPU::SI_SPILL_V512_RESTORE: {
1049 AMDGPU::OpName::vdata);
1051 buildSpillLoadStore(MI, AMDGPU::BUFFER_LOAD_DWORD_OFFSET,
1054 TII->getNamedOperand(*MI, AMDGPU::OpName::srsrc)->getReg(),
1055 TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg(),
1056 TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm(),
1057 *MI->memoperands_begin(),
1059 MI->eraseFromParent();
1064 const DebugLoc &DL = MI->getDebugLoc();
1065 bool IsMUBUF = TII->isMUBUF(*MI);
1078 bool IsCopy = MI->getOpcode() == AMDGPU::V_MOV_B32_e32;
1079 unsigned ResultReg = IsCopy ?
1080 MI->getOperand(0).getReg() :
1083 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_SUB_U32), DiffReg)
1087 int64_t
Offset = FrameInfo.getObjectOffset(Index);
1090 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_LSHRREV_B32_e64), ResultReg)
1097 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_LSHRREV_B32_e64), ScaledReg)
1103 TII->getAddNoCarry(*MBB, MI, DL, ResultReg)
1107 unsigned ConstOffsetReg
1110 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::S_MOV_B32), ConstOffsetReg)
1112 TII->getAddNoCarry(*MBB, MI, DL, ResultReg)
1120 MI->eraseFromParent();
1128 assert(static_cast<int>(FIOperandNum) ==
1130 AMDGPU::OpName::vaddr));
1132 assert(TII->getNamedOperand(*MI, AMDGPU::OpName::soffset)->getReg()
1135 int64_t
Offset = FrameInfo.getObjectOffset(Index);
1137 = TII->getNamedOperand(*MI, AMDGPU::OpName::offset)->getImm();
1138 int64_t NewOffset = OldImm +
Offset;
1140 if (isUInt<12>(NewOffset) &&
1142 MI->eraseFromParent();
1150 int64_t
Offset = FrameInfo.getObjectOffset(Index);
1152 if (!TII->isImmOperandLegal(*MI, FIOperandNum, FIOp)) {
1154 BuildMI(*MBB, MI, DL, TII->
get(AMDGPU::V_MOV_B32_e32), TmpReg)
1163 #define AMDGPU_REG_ASM_NAMES 1166 #define REG_RANGE(BeginReg, EndReg, RegTable) \ 1167 if (Reg >= BeginReg && Reg <= EndReg) { \ 1168 unsigned Index = Reg - BeginReg; \ 1169 assert(Index < array_lengthof(RegTable)); \ 1170 return RegTable[Index]; \ 1173 REG_RANGE(AMDGPU::VGPR0, AMDGPU::VGPR255, VGPR32RegNames);
1174 REG_RANGE(AMDGPU::SGPR0, AMDGPU::SGPR103, SGPR32RegNames);
1175 REG_RANGE(AMDGPU::VGPR0_VGPR1, AMDGPU::VGPR254_VGPR255, VGPR64RegNames);
1176 REG_RANGE(AMDGPU::SGPR0_SGPR1, AMDGPU::SGPR102_SGPR103, SGPR64RegNames);
1177 REG_RANGE(AMDGPU::VGPR0_VGPR1_VGPR2, AMDGPU::VGPR253_VGPR254_VGPR255,
1180 REG_RANGE(AMDGPU::VGPR0_VGPR1_VGPR2_VGPR3,
1181 AMDGPU::VGPR252_VGPR253_VGPR254_VGPR255,
1183 REG_RANGE(AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3,
1184 AMDGPU::SGPR100_SGPR101_SGPR102_SGPR103,
1187 REG_RANGE(AMDGPU::VGPR0_VGPR1_VGPR2_VGPR3_VGPR4_VGPR5_VGPR6_VGPR7,
1188 AMDGPU::VGPR248_VGPR249_VGPR250_VGPR251_VGPR252_VGPR253_VGPR254_VGPR255,
1192 AMDGPU::VGPR0_VGPR1_VGPR2_VGPR3_VGPR4_VGPR5_VGPR6_VGPR7_VGPR8_VGPR9_VGPR10_VGPR11_VGPR12_VGPR13_VGPR14_VGPR15,
1193 AMDGPU::VGPR240_VGPR241_VGPR242_VGPR243_VGPR244_VGPR245_VGPR246_VGPR247_VGPR248_VGPR249_VGPR250_VGPR251_VGPR252_VGPR253_VGPR254_VGPR255,
1196 REG_RANGE(AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3_SGPR4_SGPR5_SGPR6_SGPR7,
1197 AMDGPU::SGPR96_SGPR97_SGPR98_SGPR99_SGPR100_SGPR101_SGPR102_SGPR103,
1201 AMDGPU::SGPR0_SGPR1_SGPR2_SGPR3_SGPR4_SGPR5_SGPR6_SGPR7_SGPR8_SGPR9_SGPR10_SGPR11_SGPR12_SGPR13_SGPR14_SGPR15,
1202 AMDGPU::SGPR88_SGPR89_SGPR90_SGPR91_SGPR92_SGPR93_SGPR94_SGPR95_SGPR96_SGPR97_SGPR98_SGPR99_SGPR100_SGPR101_SGPR102_SGPR103,
1210 case AMDGPU::FLAT_SCR:
1211 return "flat_scratch";
1212 case AMDGPU::FLAT_SCR_LO:
1213 return "flat_scratch_lo";
1214 case AMDGPU::FLAT_SCR_HI:
1215 return "flat_scratch_hi";
1228 &AMDGPU::VGPR_32RegClass,
1229 &AMDGPU::SReg_32RegClass,
1230 &AMDGPU::VReg_64RegClass,
1231 &AMDGPU::SReg_64RegClass,
1232 &AMDGPU::VReg_96RegClass,
1233 &AMDGPU::VReg_128RegClass,
1234 &AMDGPU::SReg_128RegClass,
1235 &AMDGPU::VReg_256RegClass,
1236 &AMDGPU::SReg_256RegClass,
1237 &AMDGPU::VReg_512RegClass,
1238 &AMDGPU::SReg_512RegClass,
1239 &AMDGPU::SCC_CLASSRegClass,
1240 &AMDGPU::Pseudo_SReg_32RegClass,
1241 &AMDGPU::Pseudo_SReg_128RegClass,
1245 if (BaseClass->contains(Reg)) {
1255 unsigned Size = getRegSizeInBits(*RC);
1260 return getCommonSubClass(&AMDGPU::VGPR_32RegClass, RC) !=
nullptr;
1262 return getCommonSubClass(&AMDGPU::VReg_64RegClass, RC) !=
nullptr;
1264 return getCommonSubClass(&AMDGPU::VReg_96RegClass, RC) !=
nullptr;
1266 return getCommonSubClass(&AMDGPU::VReg_128RegClass, RC) !=
nullptr;
1268 return getCommonSubClass(&AMDGPU::VReg_256RegClass, RC) !=
nullptr;
1270 return getCommonSubClass(&AMDGPU::VReg_512RegClass, RC) !=
nullptr;
1278 switch (getRegSizeInBits(*SRC)) {
1280 return &AMDGPU::VGPR_32RegClass;
1282 return &AMDGPU::VReg_64RegClass;
1284 return &AMDGPU::VReg_96RegClass;
1286 return &AMDGPU::VReg_128RegClass;
1288 return &AMDGPU::VReg_256RegClass;
1290 return &AMDGPU::VReg_512RegClass;
1298 switch (getRegSizeInBits(*VRC)) {
1300 return &AMDGPU::SGPR_32RegClass;
1302 return &AMDGPU::SReg_64RegClass;
1304 return &AMDGPU::SReg_128RegClass;
1306 return &AMDGPU::SReg_256RegClass;
1308 return &AMDGPU::SReg_512RegClass;
1316 if (SubIdx == AMDGPU::NoSubRegister)
1320 unsigned Count = getSubRegIndexLaneMask(SubIdx).getNumLanes();
1324 return &AMDGPU::SGPR_32RegClass;
1326 return &AMDGPU::SReg_64RegClass;
1328 return &AMDGPU::SReg_128RegClass;
1330 return &AMDGPU::SReg_256RegClass;
1338 return &AMDGPU::VGPR_32RegClass;
1340 return &AMDGPU::VReg_64RegClass;
1342 return &AMDGPU::VReg_96RegClass;
1344 return &AMDGPU::VReg_128RegClass;
1346 return &AMDGPU::VReg_256RegClass;
1358 unsigned SrcSubReg)
const {
1375 return getCommonSubClass(DefRC, SrcRC) !=
nullptr;
1386 for (
unsigned Reg : *RC)
1389 return AMDGPU::NoRegister;
1393 unsigned EltSize)
const {
1395 static const int16_t Sub0_15[] = {
1396 AMDGPU::sub0, AMDGPU::sub1, AMDGPU::sub2, AMDGPU::sub3,
1397 AMDGPU::sub4, AMDGPU::sub5, AMDGPU::sub6, AMDGPU::sub7,
1398 AMDGPU::sub8, AMDGPU::sub9, AMDGPU::sub10, AMDGPU::sub11,
1399 AMDGPU::sub12, AMDGPU::sub13, AMDGPU::sub14, AMDGPU::sub15,
1402 static const int16_t Sub0_7[] = {
1403 AMDGPU::sub0, AMDGPU::sub1, AMDGPU::sub2, AMDGPU::sub3,
1404 AMDGPU::sub4, AMDGPU::sub5, AMDGPU::sub6, AMDGPU::sub7,
1407 static const int16_t Sub0_3[] = {
1408 AMDGPU::sub0, AMDGPU::sub1, AMDGPU::sub2, AMDGPU::sub3,
1411 static const int16_t Sub0_2[] = {
1412 AMDGPU::sub0, AMDGPU::sub1, AMDGPU::sub2,
1415 static const int16_t Sub0_1[] = {
1416 AMDGPU::sub0, AMDGPU::sub1,
1438 static const int16_t Sub0_15_64[] = {
1439 AMDGPU::sub0_sub1, AMDGPU::sub2_sub3,
1440 AMDGPU::sub4_sub5, AMDGPU::sub6_sub7,
1441 AMDGPU::sub8_sub9, AMDGPU::sub10_sub11,
1442 AMDGPU::sub12_sub13, AMDGPU::sub14_sub15
1445 static const int16_t Sub0_7_64[] = {
1446 AMDGPU::sub0_sub1, AMDGPU::sub2_sub3,
1447 AMDGPU::sub4_sub5, AMDGPU::sub6_sub7
1451 static const int16_t Sub0_3_64[] = {
1452 AMDGPU::sub0_sub1, AMDGPU::sub2_sub3
1469 assert(EltSize == 16 &&
"unhandled register spill split size");
1471 static const int16_t Sub0_15_128[] = {
1472 AMDGPU::sub0_sub1_sub2_sub3,
1473 AMDGPU::sub4_sub5_sub6_sub7,
1474 AMDGPU::sub8_sub9_sub10_sub11,
1475 AMDGPU::sub12_sub13_sub14_sub15
1478 static const int16_t Sub0_7_128[] = {
1479 AMDGPU::sub0_sub1_sub2_sub3,
1480 AMDGPU::sub4_sub5_sub6_sub7
1497 unsigned Reg)
const {
1505 unsigned Reg)
const {
1507 assert(RC &&
"Register class for the reg not found");
1518 unsigned SrcSize = getRegSizeInBits(*SrcRC);
1519 unsigned DstSize = getRegSizeInBits(*DstRC);
1520 unsigned NewSize = getRegSizeInBits(*NewRC);
1526 if (SrcSize <= 32 || DstSize <= 32)
1529 return NewSize <= DstSize || NewSize <= SrcSize;
1540 switch (RC->
getID()) {
1542 return AMDGPURegisterInfo::getRegPressureLimit(RC, MF);
1543 case AMDGPU::VGPR_32RegClassID:
1545 case AMDGPU::SGPR_32RegClassID:
1551 unsigned Idx)
const {
1554 const_cast<MachineFunction &>(MF));
1558 const_cast<MachineFunction &>(MF));
1560 return AMDGPURegisterInfo::getRegPressureSetLimit(MF, Idx);
1564 static const int Empty[] = { -1 };
1566 if (hasRegUnit(AMDGPU::M0, RegUnit))
1568 return AMDGPURegisterInfo::getRegUnitPressureSets(RegUnit);
1573 return AMDGPU::SGPR30_SGPR31;
1586 return RB->
getID() == AMDGPU::VGPRRegBankID ? &AMDGPU::VGPR_32RegClass :
1587 &AMDGPU::SReg_32_XM0RegClass;
1589 return RB->getID() == AMDGPU::VGPRRegBankID ? &AMDGPU::VReg_64RegClass :
1590 &AMDGPU::SReg_64_XEXECRegClass;
1592 return RB->getID() == AMDGPU::VGPRRegBankID ? &AMDGPU::VReg_96RegClass :
1595 return RB->getID() == AMDGPU::VGPRRegBankID ? &AMDGPU::VReg_128RegClass :
1596 &AMDGPU::SReg_128RegClass;
unsigned getFrameOffsetReg() const
unsigned getScratchWaveOffsetReg() const
void materializeFrameBaseRegister(MachineBasicBlock *MBB, unsigned BaseReg, int FrameIdx, int64_t Offset) const override
const MachineInstrBuilder & add(const MachineOperand &MO) const
bool requiresRegisterScavenging(const MachineFunction &Fn) const override
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Interface definition for SIRegisterInfo.
static unsigned getSubRegFromChannel(unsigned Channel)
unsigned reservedPrivateSegmentBufferReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch buffer in case spilling is needed...
This file declares the targeting of the RegisterBankInfo class for AMDGPU.
AMDGPU specific subclass of TargetSubtarget.
bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override
bool hasScalarStores() const
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
void addToSpilledSGPRs(unsigned num)
bool isRegUsed(unsigned Reg, bool includeReserved=true) const
Return if a specific register is currently used.
bool isAllocatable(unsigned PhysReg) const
isAllocatable - Returns true when PhysReg belongs to an allocatable register class and it hasn't been...
Compute iterated dominance frontiers using a linear time algorithm.
void addToSpilledVGPRs(unsigned num)
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...
SIRegisterInfo(const GCNSubtarget &ST)
unsigned getStackPtrOffsetReg() const
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const
Inverse of getMaxLocalMemWithWaveCount.
bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg, int64_t Offset) const override
static int getOffsetMUBUFLoad(unsigned Opc)
StringRef getRegAsmName(unsigned Reg) const override
bool hasStackObjects() const
Return true if there are any stack objects in this function.
const TargetRegisterClass * getEquivalentVGPRClass(const TargetRegisterClass *SRC) const
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
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)
bool hasInv2PiInlineImm() const
unsigned getRegBitWidth(unsigned RCID)
Get the size in bits of a register from the register class RC.
bool shouldCoalesce(MachineInstr *MI, const TargetRegisterClass *SrcRC, unsigned SubReg, const TargetRegisterClass *DstRC, unsigned DstSubReg, const TargetRegisterClass *NewRC, LiveIntervals &LIS) const override
bool requiresVirtualBaseRegisters(const MachineFunction &Fn) const override
bool mayLoadOrStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read or modify memory.
const SIInstrInfo * getInstrInfo() const override
const TargetRegisterClass * getConstrainedRegClassForOperand(const MachineOperand &MO, const MachineRegisterInfo &MRI) const override
static unsigned findPrivateSegmentWaveByteOffsetRegIndex(unsigned RegCount)
const TargetRegisterClass * getEquivalentSGPRClass(const TargetRegisterClass *VRC) 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)
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.
A description of a memory reference used in the backend.
const HexagonInstrInfo * TII
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool isEntryFunction() const
bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
ArrayRef< SpilledReg > getSGPRToVGPRSpills(int FrameIndex) const
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
unsigned reservedStackPtrOffsetReg(const MachineFunction &MF) const
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.
unsigned getID() const
Return the register class ID number.
static bool hasPressureSet(const int *PSets, unsigned PSetID)
bool isSGPRClass(const TargetRegisterClass *RC) const
bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const
bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const override
static bool isMUBUF(const MachineInstr &MI)
unsigned FindUnusedReg(const TargetRegisterClass *RC) const
Find an unused register of the specified register class.
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
bool isSGPRPressureSet(unsigned SetID) const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
ArrayRef< int16_t > getRegSplitParts(const TargetRegisterClass *RC, unsigned EltSize) const
bool spillSGPR(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, bool OnlyToVGPR=false) const
If OnlyToVGPR is true, this will only succeed if this.
virtual StringRef getRegAsmName(unsigned Reg) const
Return the assembly name for Reg.
unsigned getKillRegState(bool B)
bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const override
const int * getRegUnitPressureSets(unsigned RegUnit) const override
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
#define REG_RANGE(BeginReg, EndReg, RegTable)
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.
unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
initializer< Ty > init(const Ty &Val)
This file declares the machine register scavenger class.
unsigned const MachineRegisterInfo * MRI
unsigned reservedPrivateSegmentWaveByteOffsetReg(const MachineFunction &MF) const
Return the end register initially reserved for the scratch wave offset in case spilling is needed...
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.
size_t size() const
size - Get the array size.
unsigned getReturnAddressReg(const MachineFunction &MF) const
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)
bool hasVGPRs(const TargetRegisterClass *RC) const
int64_t getMUBUFInstrOffset(const MachineInstr *MI) const
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
unsigned getSGPRPressureSet() const
const RegisterBank * getRegBankOrNull(unsigned Reg) const
Return the register bank of Reg, or null if Reg has not been assigned a register bank or has been ass...
const TargetRegisterClass * getSubRegClass(const TargetRegisterClass *RC, unsigned SubIdx) const
const MachineInstrBuilder & addFrameIndex(int Idx) const
void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
const MachineBasicBlock & front() const
bool restoreSGPR(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS, bool OnlyToVGPR=false) const
This class contains a discriminated union of information about pointers in memory operands...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getVGPRPressureSet() const
The memory access writes data.
unsigned getWavefrontSize() const
unsigned getRegPressureSetLimit(const MachineFunction &MF, unsigned Idx) const override
MachineOperand class - Representation of each machine instruction operand.
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.
unsigned getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses...
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
static cl::opt< bool > EnableSpillSGPRToVGPR("amdgpu-spill-sgpr-to-vgpr", cl::desc("Enable spilling VGPRs to SGPRs"), cl::ReallyHidden, cl::init(true))
This class implements the register bank concept.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
const TargetRegisterClass * getRegClassForReg(const MachineRegisterInfo &MRI, unsigned Reg) const
MachinePointerInfo getWithOffset(int64_t O) const
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
bool isPhysRegUsed(unsigned PhysReg) const
Return true if the specified register is modified or read in this function.
const MCRegisterClass * MC
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
bool eliminateSGPRToVGPRSpillFrameIndex(MachineBasicBlock::iterator MI, int FI, RegScavenger *RS) const
Special case of eliminateFrameIndex.
bool mayStore() const
Return true if this instruction could possibly modify memory.
const MachineBasicBlock * getParent() const
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.
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
const MachinePointerInfo & getPointerInfo() const
void reserveRegisterTuples(BitVector &, unsigned Reg) const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Flags getFlags() const
Return the raw flags of the source value,.
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
static int getOffsetMUBUFStore(unsigned Opc)
bool spillSGPRToSMEM() const
unsigned getMaxNumVGPRs(unsigned WavesPerEU) const
bool isVGPRPressureSet(unsigned SetID) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
const TargetRegisterClass * getPhysRegClass(unsigned Reg) const
Return the 'base' register class for this register.
StringRef - Represent a constant reference to a string, i.e.
const MachineOperand & getOperand(unsigned i) const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool empty() const
empty - Check if the array is empty.
unsigned getID() const
Get the identifier of this register bank.
bool hasCalls() const
Return true if the current function has any function calls.