Skip to content

[AMDGPU][MIR] Serialize SpillPhysVGPRs #113129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,13 @@ bool GCNTargetMachine::parseMachineFunctionInfo(
MFI->setFlag(Info->VReg, Info->Flags);
}

for (const auto &YamlRegStr : YamlMFI.SpillPhysVGPRS) {
Register ParsedReg;
if (parseRegister(YamlRegStr, ParsedReg))
return true;
MFI->SpillPhysVGPRs.push_back(ParsedReg);
}

auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
const TargetRegisterClass &RC,
ArgDescriptor &Arg, unsigned UserSGPRs,
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ yaml::SIMachineFunctionInfo::SIMachineFunctionInfo(
PSInputAddr(MFI.getPSInputAddr()),
PSInputEnable(MFI.getPSInputEnable()),
Mode(MFI.getMode()) {
for (Register Reg : MFI.getSGPRSpillPhysVGPRs())
SpillPhysVGPRS.push_back(regToString(Reg, TRI));

for (Register Reg : MFI.getWWMReservedRegs())
WWMReservedRegs.push_back(regToString(Reg, TRI));

Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo {
// TODO: 10 may be a better default since it's the maximum.
unsigned Occupancy = 0;

SmallVector<StringValue, 2> SpillPhysVGPRS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the name was copied from the existing MFI field, but this is not a good name. We ought to rename this to reflect the special usage; this isn't just any spilled physical vgprs

Copy link
Contributor Author

@optimisan optimisan Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iinw these are VGPRs used for CSR or FP/BP SGPR spills. This is also related to SGPRSpillToPhysicalVGPRLanes map.

Would PhysVGPRsForSGPRSpills or SGPRSpillPhysVGPRS still be a bit general?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WWMPhysVGPRs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

SmallVector<StringValue> WWMReservedRegs;

StringValue ScratchRSrcReg = "$private_rsrc_reg";
Expand Down Expand Up @@ -336,6 +337,7 @@ template <> struct MappingTraits<SIMachineFunctionInfo> {
YamlIO.mapOptional("highBitsOf32BitAddress",
MFI.HighBitsOf32BitAddress, 0u);
YamlIO.mapOptional("occupancy", MFI.Occupancy, 0);
YamlIO.mapOptional("spillPhysVGPRs", MFI.SpillPhysVGPRS);
YamlIO.mapOptional("wwmReservedRegs", MFI.WWMReservedRegs);
YamlIO.mapOptional("scavengeFI", MFI.ScavengeFI);
YamlIO.mapOptional("vgprForAGPRCopy", MFI.VGPRForAGPRCopy,
Expand Down Expand Up @@ -610,6 +612,7 @@ class SIMachineFunctionInfo final : public AMDGPUMachineFunction,
}

ArrayRef<Register> getSGPRSpillVGPRs() const { return SpillVGPRs; }
ArrayRef<Register> getSGPRSpillPhysVGPRs() const { return SpillPhysVGPRs; }

const WWMSpillsMap &getWWMSpills() const { return WWMSpills; }
const ReservedRegSet &getWWMReservedRegs() const { return WWMReservedRegs; }
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/CodeGen/MIR/AMDGPU/spill-phys-vgprs-invalid.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -run-pass=none -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=ERR

---
name: invalid_reg_spill_phys_vgprs
machineFunctionInfo:
# ERR: [[@LINE+1]]:21: unknown register name 'notareg'
spillPhysVGPRs: ['$notareg']
body: |
bb.0:
S_ENDPGM 0

...
12 changes: 12 additions & 0 deletions llvm/test/CodeGen/MIR/AMDGPU/spill-phys-vgprs-not-a-reg.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# RUN: not llc -mtriple=amdgcn-amd-amdhsa -run-pass=none -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=ERR

---
name: invalid_reg_spill_phys_vgprs
machineFunctionInfo:
# ERR: [[@LINE+1]]:20: expected a named register
spillPhysVGPRs: [123]
body: |
bb.0:
S_ENDPGM 0

...
58 changes: 58 additions & 0 deletions llvm/test/CodeGen/MIR/AMDGPU/spill-phys-vgprs.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# RUN: llc -mtriple=amdgcn-amd-amdhsa --start-before=si-lower-sgpr-spills --stop-after=prologepilog -o - %s | FileCheck %s

# CHECK: csr_sgpr_spill
# CHECK: spillPhysVGPRs
# CHECK-NEXT: - '$vgpr0'
---
name: csr_sgpr_spill
tracksRegLiveness: true
body: |
bb.0:
S_NOP 0
bb.1:
$sgpr40 = S_MOV_B32 0
$sgpr41 = S_MOV_B32 1

...

# CHECK-LABEL: name: parse_none
# CHECK: machineFunctionInfo:
# CHECK-NOT: spillPhysVGPRs
---
name: parse_none
machineFunctionInfo:
spillPhysVGPRs: []
body: |
bb.0:
S_ENDPGM 0

...

# CHECK-LABEL: name: parse_one
# CHECK: machineFunctionInfo:
# CHECK: spillPhysVGPRs
# CHECK-NEXT: - '$vgpr0'
---
name: parse_one
machineFunctionInfo:
spillPhysVGPRs: ['$vgpr0']
body: |
bb.0:
S_ENDPGM 0

...

# CHECK-LABEL: name: parse_two
# CHECK: machineFunctionInfo:
# CHECK: spillPhysVGPRs
# CHECK-NEXT: - '$vgpr0'
# CHECK-NEXT: - '$vgpr1'
---
name: parse_two
machineFunctionInfo:
spillPhysVGPRs: ['$vgpr0', '$vgpr1']
body: |
bb.0:
S_ENDPGM 0

...
Loading