-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[AMDGPU] Serialize WWM_REG vreg flag #110229
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
[AMDGPU] Serialize WWM_REG vreg flag #110229
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @optimisan and the rest of your teammates on |
@llvm/pr-subscribers-backend-amdgpu Author: Akshat Oke (Akshat-Oke) ChangesFull diff: https://github.com/llvm/llvm-project/pull/110229.diff 5 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index abd50748f2cc05..c42b443230acc9 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1628,6 +1628,21 @@ bool GCNTargetMachine::parseMachineFunctionInfo(
MFI->reserveWWMRegister(ParsedReg);
}
+ auto setRegisterFlags = [&](const VRegInfo &Info) {
+ for (const auto &Flag : Info.Flags) {
+ MFI->setFlag(Info.VReg, Flag);
+ }
+ };
+
+ for (const auto &P : PFS.VRegInfosNamed) {
+ const VRegInfo &Info = *P.second;
+ setRegisterFlags(Info);
+ }
+ for (const auto &P : PFS.VRegInfos) {
+ const VRegInfo &Info = *P.second;
+ setRegisterFlags(Info);
+ }
+
auto parseAndCheckArgument = [&](const std::optional<yaml::SIArgument> &A,
const TargetRegisterClass &RC,
ArgDescriptor &Arg, unsigned UserSGPRs,
diff --git a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
index aff0b34947d688..7fffc706c4b027 100644
--- a/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
@@ -684,8 +684,8 @@ class SIMachineFunctionInfo final : public AMDGPUMachineFunction,
void setFlag(Register Reg, uint8_t Flag) {
assert(Reg.isVirtual());
- if (VRegFlags.inBounds(Reg))
- VRegFlags[Reg] |= Flag;
+ VRegFlags.grow(Reg);
+ VRegFlags[Reg] |= Flag;
}
bool checkFlag(Register Reg, uint8_t Flag) const {
diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
index 2d1cd1bda3afe1..ad3e592127de80 100644
--- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
@@ -3614,3 +3614,14 @@ SIRegisterInfo::getSubRegAlignmentNumBits(const TargetRegisterClass *RC,
}
return 0;
}
+
+SmallVector<std::string>
+SIRegisterInfo::getVRegFlagsOfReg(Register Reg,
+ const MachineFunction &MF) const {
+ SmallVector<std::string> RegFlags;
+ const SIMachineFunctionInfo *FuncInfo = MF.getInfo<SIMachineFunctionInfo>();
+ if (FuncInfo->checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG)) {
+ RegFlags.push_back("WWM_REG");
+ }
+ return RegFlags;
+}
diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.h b/llvm/lib/Target/AMDGPU/SIRegisterInfo.h
index 88d5686720985e..bce5a2aa792bd3 100644
--- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.h
+++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.h
@@ -449,6 +449,16 @@ class SIRegisterInfo final : public AMDGPUGenRegisterInfo {
// No check if the subreg is supported by the current RC is made.
unsigned getSubRegAlignmentNumBits(const TargetRegisterClass *RC,
unsigned SubReg) const;
+
+ std::pair<bool, uint8_t> getVRegFlagValue(StringRef Name) const override {
+ if (Name == "WWM_REG") {
+ return {true, AMDGPU::VirtRegFlag::WWM_REG};
+ }
+ return {false, 0};
+ }
+
+ SmallVector<std::string>
+ getVRegFlagsOfReg(Register Reg, const MachineFunction &MF) const override;
};
namespace AMDGPU {
diff --git a/llvm/test/CodeGen/AMDGPU/virtual-registers.mir b/llvm/test/CodeGen/AMDGPU/virtual-registers.mir
new file mode 100644
index 00000000000000..3ea8f6eafcf10c
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/virtual-registers.mir
@@ -0,0 +1,16 @@
+# RUN: llc -mtriple=amdgcn -run-pass=none -o - %s | FileCheck %s
+# This test ensures that the MIR parser parses virtual register flags correctly
+
+---
+name: vregs
+# CHECK: registers:
+# CHECK-NEXT: - { id: 0, class: vgpr_32, preferred-register: '$vgpr1', flags: [ WWM_REG ] }
+# CHECK-NEXT: - { id: 1, class: sgpr_64, preferred-register: '$sgpr0_sgpr1', flags: [ ] }
+# CHECK-NEXT: - { id: 2, class: sgpr_64, preferred-register: '', flags: [ ] }
+registers:
+ - { id: 0, class: vgpr_32, preferred-register: $vgpr1, flags: [ WWM_REG ]}
+ - { id: 1, class: sgpr_64, preferred-register: $sgpr0_sgpr1 }
+body: |
+ bb.0:
+ %2:sgpr_64 = COPY %1
+ %1:sgpr_64 = COPY %0
|
@@ -684,8 +684,8 @@ class SIMachineFunctionInfo final : public AMDGPUMachineFunction, | |||
|
|||
void setFlag(Register Reg, uint8_t Flag) { | |||
assert(Reg.isVirtual()); | |||
if (VRegFlags.inBounds(Reg)) | |||
VRegFlags[Reg] |= Flag; | |||
VRegFlags.grow(Reg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, this change is unnecessary. Keep the inbounds check back.
The following change in the other patch would make sure to grow VRegFlags for each virtual register it encountered.
https://github.com/llvm/llvm-project/pull/110228/files#diff-c72079b2a595aca3300d5e3c15d227f81937f2745f7c5494fcf1fe9ba37d8828R1789
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MIR function is parsed after parsing the options, so the noteNewVirtualRegister
callback doesn't take effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You changed this though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't take effect here.
Might be better to move it to a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change doesn't make sense to me. What will happen to the regular flow when it reaches from MRI createVirtualRegister? Isn't duplicating the size?
https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/MachineRegisterInfo.cpp#L166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Register info is an avenue for noting new virtual registers so I've put it here #111634
@@ -0,0 +1,16 @@ | |||
# RUN: llc -mtriple=amdgcn -run-pass=none -o - %s | FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly, the tests related to serialize options go in llvm/test/CodeGen/MIR/AMDGPU/machine-function-info-no-ir.mir.
Additionally, a negative test is required for this serialized option and that should be a separate test like llvm/test/CodeGen/MIR/AMDGPU/sgpr-for-exec-copy-invalid-reg.mir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Negative test is now in MIR/Generic.
@@ -1628,6 +1628,21 @@ bool GCNTargetMachine::parseMachineFunctionInfo( | |||
MFI->reserveWWMRegister(ParsedReg); | |||
} | |||
|
|||
auto setRegisterFlags = [&](const VRegInfo &Info) { | |||
for (const auto &Flag : Info.Flags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No auto, no reference. This is just uint8_t
for (const auto &P : PFS.VRegInfosNamed) { | ||
const VRegInfo &Info = *P.second; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c++17 destructuring
for (const auto &P : PFS.VRegInfos) { | ||
const VRegInfo &Info = *P.second; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c++17 destructuring
@@ -3614,3 +3614,14 @@ SIRegisterInfo::getSubRegAlignmentNumBits(const TargetRegisterClass *RC, | |||
} | |||
return 0; | |||
} | |||
|
|||
SmallVector<std::string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably should just be const char*, this will probably only ever be used with literals
f494d56
to
336b9bc
Compare
35536a8
to
c428da0
Compare
c428da0
to
6651bfa
Compare
if (FuncInfo->checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG)) { | ||
RegFlags.push_back(SmallString<8>("WWM_REG")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (FuncInfo->checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG)) { | |
RegFlags.push_back(SmallString<8>("WWM_REG")); | |
} | |
if (FuncInfo->checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG)) | |
RegFlags.push_back("WWM_REG"); |
I would hope construct from literal works fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change this to a const char* instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect only literals, so could use StringRef or StringLiteral
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, will keep this.
I have to keep the explicit construct since "WWM_REG" is being refused to be casted to a SmallString (without creating a StringRef explicitly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the interface could change from SmallString to StringLiteral
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it
if (Name == "WWM_REG") { | ||
return AMDGPU::VirtRegFlag::WWM_REG; | ||
} | ||
return {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Name == "WWM_REG") { | |
return AMDGPU::VirtRegFlag::WWM_REG; | |
} | |
return {}; | |
return Name == "WWM_REG" ? AMDGPU::VirtRegFlag::WWM_REG : {}; |
@@ -684,8 +684,8 @@ class SIMachineFunctionInfo final : public AMDGPUMachineFunction, | |||
|
|||
void setFlag(Register Reg, uint8_t Flag) { | |||
assert(Reg.isVirtual()); | |||
if (VRegFlags.inBounds(Reg)) | |||
VRegFlags[Reg] |= Flag; | |||
VRegFlags.grow(Reg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You changed this though?
return (Name == "WWM_REG") ? AMDGPU::VirtRegFlag::WWM_REG | ||
: std::optional<uint8_t>{}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (Name == "WWM_REG") ? AMDGPU::VirtRegFlag::WWM_REG | |
: std::optional<uint8_t>{}; | |
return Name == "WWM_REG" ? AMDGPU::VirtRegFlag::WWM_REG | |
: std::optional<uint8_t>{}; |
9f8b6eb
to
7af9e5e
Compare
81baf9e
to
79de29b
Compare
2b87714
to
8e7f366
Compare
79de29b
to
81059dc
Compare
for (uint8_t Flag : Info.Flags) { | ||
MFI->setFlag(Info.VReg, Flag); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well just inline this and duplicate the code, the loop is trivial enough
if (FuncInfo->checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG)) { | ||
RegFlags.push_back("WWM_REG"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (FuncInfo->checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG)) { | |
RegFlags.push_back("WWM_REG"); | |
} | |
if (FuncInfo->checkFlag(Reg, AMDGPU::VirtRegFlag::WWM_REG)) | |
RegFlags.push_back("WWM_REG"); |
bf5cc39
to
9dd1158
Compare
81059dc
to
db80f0b
Compare
9dd1158
to
9390926
Compare
db80f0b
to
3240cf9
Compare
9390926
to
38a9c7b
Compare
3240cf9
to
4870a8a
Compare
32b44f5
to
0712903
Compare
It looks like this change caused LSan reports. See e.g. https://lab.llvm.org/buildbot/#/builders/52/builds/2928 Can you please take a look? |
Taking a look |
This reverts commit bec839d. Caused buildbot failures, e.g. https://lab.llvm.org/buildbot/#/builders/52/builds/2928
I reverted the change for now, please reland when you have a fix. |
Yep |
This reverts commit bec839d. Caused buildbot failures, e.g. https://lab.llvm.org/buildbot/#/builders/52/builds/2928
No description provided.