Skip to content

Commit 3495d04

Browse files
authored
[AMDGPU][MIR] Serialize SpillPhysVGPRs (#113129)
1 parent 70de0b8 commit 3495d04

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,13 @@ bool GCNTargetMachine::parseMachineFunctionInfo(
17401740
MFI->setFlag(Info->VReg, Info->Flags);
17411741
}
17421742

1743+
for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
1744+
Register ParsedReg;
1745+
if (parseRegister(YamlRegStr, ParsedReg))
1746+
return true;
1747+
MFI->SpillPhysVGPRs.push_back(ParsedReg);
1748+
}
1749+
17431750
auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
17441751
const TargetRegisterClass &RC,
17451752
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -run-pass=none -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=ERR
2+
3+
---
4+
name: invalid_reg_spill_phys_vgprs
5+
machineFunctionInfo:
6+
# ERR: [[@LINE+1]]:21: unknown register name 'notareg'
7+
spillPhysVGPRs: ['$notareg']
8+
body: |
9+
bb.0:
10+
S_ENDPGM 0
11+
12+
...
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -run-pass=none -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=ERR
2+
3+
---
4+
name: invalid_reg_spill_phys_vgprs
5+
machineFunctionInfo:
6+
# ERR: [[@LINE+1]]:20: expected a named register
7+
spillPhysVGPRs: [123]
8+
body: |
9+
bb.0:
10+
S_ENDPGM 0
11+
12+
...
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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_two
46+
# CHECK: machineFunctionInfo:
47+
# CHECK: spillPhysVGPRs
48+
# CHECK-NEXT: - '$vgpr0'
49+
# CHECK-NEXT: - '$vgpr1'
50+
---
51+
name: parse_two
52+
machineFunctionInfo:
53+
spillPhysVGPRs: ['$vgpr0', '$vgpr1']
54+
body: |
55+
bb.0:
56+
S_ENDPGM 0
57+
58+
...

0 commit comments

Comments
 (0)