Skip to content

Commit a221286

Browse files
committed
[AMDGPU][MIR] Serialize SpillPhysVGPRs
1 parent 615a5eb commit a221286

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,13 @@ bool GCNTargetMachine::parseMachineFunctionInfo(
17181718
MFI->reserveWWMRegister(ParsedReg);
17191719
}
17201720

1721+
for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
1722+
Register ParsedReg;
1723+
if (parseRegister(YamlRegStr, ParsedReg))
1724+
return true;
1725+
MFI->SpillPhysVGPRs.push_back(ParsedReg);
1726+
}
1727+
17211728
auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
17221729
const TargetRegisterClass &RC,
17231730
ArgDescriptor &Arg, unsigned UserSGPRs,

llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ yaml::SIMachineFunctionInfo::SIMachineFunctionInfo(
711711
PSInputAddr(MFI.getPSInputAddr()),
712712
PSInputEnable(MFI.getPSInputEnable()),
713713
Mode(MFI.getMode()) {
714+
for (Register Reg : MFI.getSGPRSpillPhysVGPRs())
715+
SpillPhysVGPRS.push_back(regToString(Reg, TRI));
716+
714717
for (Register Reg : MFI.getWWMReservedRegs())
715718
WWMReservedRegs.push_back(regToString(Reg, TRI));
716719

llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo {
275275
// TODO: 10 may be a better default since it's the maximum.
276276
unsigned Occupancy = 0;
277277

278+
SmallVector<StringValue, 2> SpillPhysVGPRS;
278279
SmallVector<StringValue> WWMReservedRegs;
279280

280281
StringValue ScratchRSrcReg = "$private_rsrc_reg";
@@ -336,6 +337,7 @@ template <> struct MappingTraits<SIMachineFunctionInfo> {
336337
YamlIO.mapOptional("highBitsOf32BitAddress",
337338
MFI.HighBitsOf32BitAddress, 0u);
338339
YamlIO.mapOptional("occupancy", MFI.Occupancy, 0);
340+
YamlIO.mapOptional("spillPhysVGPRs", MFI.SpillPhysVGPRS);
339341
YamlIO.mapOptional("wwmReservedRegs", MFI.WWMReservedRegs);
340342
YamlIO.mapOptional("scavengeFI", MFI.ScavengeFI);
341343
YamlIO.mapOptional("vgprForAGPRCopy", MFI.VGPRForAGPRCopy,
@@ -610,6 +612,7 @@ class SIMachineFunctionInfo final : public AMDGPUMachineFunction,
610612
}
611613

612614
ArrayRef<Register> getSGPRSpillVGPRs() const { return SpillVGPRs; }
615+
ArrayRef<Register> getSGPRSpillPhysVGPRs() const { return SpillPhysVGPRs; }
613616

614617
const WWMSpillsMap &getWWMSpills() const { return WWMSpills; }
615618
const ReservedRegSet &getWWMReservedRegs() const { return WWMReservedRegs; }
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# RUN: llc -mtriple=amdgcn-amd-amdhsa --start-before=si-lower-sgpr-spills --stop-after=prologepilog -o - %s | FileCheck %s
2+
3+
# CHECK: csr_sgpr_spill
4+
# CHECK: spillPhysVGPRs:
5+
# CHECK-NEXT: - '$vgpr0'
6+
---
7+
name: csr_sgpr_spill
8+
tracksRegLiveness: true
9+
body: |
10+
bb.0:
11+
S_NOP 0
12+
bb.1:
13+
$sgpr40 = S_MOV_B32 0
14+
$sgpr41 = S_MOV_B32 1
15+
16+
...
17+
18+
# CHECK-LABEL: name: parse_none
19+
# CHECK: machineFunctionInfo:
20+
# CHECK-NOT: spillPhysVGPRs:
21+
---
22+
name: parse_none
23+
machineFunctionInfo:
24+
spillPhysVGPRs: []
25+
body: |
26+
bb.0:
27+
S_ENDPGM 0
28+
29+
...
30+
31+
# CHECK-LABEL: name: parse_one
32+
# CHECK: machineFunctionInfo:
33+
# CHECK: spillPhysVGPRs:
34+
# CHECK-NEXT: - '$vgpr0'
35+
---
36+
name: parse_one
37+
machineFunctionInfo:
38+
spillPhysVGPRs: ['$vgpr0']
39+
body: |
40+
bb.0:
41+
S_ENDPGM 0
42+
43+
...
44+
45+
# CHECK-LABEL: name: parse_one
46+
# CHECK: machineFunctionInfo:
47+
# CHECK: spillPhysVGPRs:
48+
# CHECK-NEXT: - '$vgpr0'
49+
---
50+
name: parse_one
51+
machineFunctionInfo:
52+
spillPhysVGPRs: ['$vgpr0']
53+
body: |
54+
bb.0:
55+
S_ENDPGM 0
56+
57+
...

0 commit comments

Comments
 (0)