[llvm] [AMDGPU] Register allocation anti-hints to reduce MFMA hazard NOPs (PR #156943)
Janek van Oirschot via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 6 06:18:58 PST 2026
================
@@ -859,6 +866,56 @@ class MachineRegisterInfo {
return RegAllocHints.inBounds(VReg) ? &RegAllocHints[VReg] : nullptr;
}
+ /// addRegAllocAntiHint - Add a register allocation anti-hint for the
+ /// specified virtual register. This tells the allocator to avoid allocating
+ /// VReg to the same physical register as AntiHintVReg (or overlapping ones).
+ void addRegAllocAntiHint(Register VReg, Register AntiHintVReg) {
+ assert(VReg.isVirtual() && "Anti-hints are only for virtual registers");
+ assert(AntiHintVReg.isVirtual() && "Anti-hint target must be virtual");
+ AntiHintRegs.grow(VReg);
+ SmallVector<Register, 4> &AntiHints = AntiHintRegs[VReg];
+ // Avoid duplicates
+ if (llvm::find(AntiHints, AntiHintVReg) == AntiHints.end())
+ AntiHints.push_back(AntiHintVReg);
+ }
+
+ /// addRegAllocationAntiHint - Add multiple anti-hints at once.
+ void addRegAllocationAntiHints(Register VReg,
+ ArrayRef<Register> AntiHintVRegs) {
+ for (Register AntiHint : AntiHintVRegs)
+ addRegAllocAntiHint(VReg, AntiHint);
+ }
+
+ /// clearRegAllocationAntiHints - Clear all anti-hints for a register.
+ void clearRegAllocationAntiHints(Register VReg) {
+ assert(VReg.isVirtual());
+ if (AntiHintRegs.inBounds(VReg))
+ AntiHintRegs[VReg].clear();
+ }
+
+ /// getRegAllocationAntiHints - Return the vector of anti-hints for VReg.
+ ArrayRef<Register> getRegAllocationAntiHints(Register VReg) const {
+ assert(VReg.isVirtual());
+ if (!AntiHintRegs.inBounds(VReg))
+ return ArrayRef<Register>();
+ return AntiHintRegs[VReg];
+ }
+
+ /// hasRegAllocationAntiHint - Check if VReg has AntiHintVReg as an anti-hint.
+ bool hasRegAllocationAntiHint(Register VReg, Register AntiHintVReg) const {
+ assert(VReg.isVirtual() && AntiHintVReg.isVirtual());
+ if (!AntiHintRegs.inBounds(VReg))
+ return false;
+ const SmallVector<Register, 4> &AntiHints = AntiHintRegs[VReg];
+ return llvm::find(AntiHints, AntiHintVReg) != AntiHints.end();
+ }
----------------
JanekvO wrote:
Nit: make asserts consistent with one another (comments with each assert, combined assert for both `Register`s)
https://github.com/llvm/llvm-project/pull/156943
More information about the llvm-commits
mailing list