[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
================
@@ -499,6 +499,45 @@ bool TargetRegisterInfo::getRegAllocationHints(
return false;
}
+void TargetRegisterInfo::applyRegAllocationAntiHints(
+ Register VirtReg, ArrayRef<MCPhysReg> &Order,
+ SmallVectorImpl<MCPhysReg> &OrderStorage,
+ SmallVector<MCPhysReg, 16> &AntiHints, const MachineFunction &MF,
+ const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const {
+
+ if (AntiHints.empty() || !VRM)
+ return;
+
+ auto isAntiHinted = [&](MCPhysReg Reg) {
+ return std::any_of(
+ AntiHints.begin(), AntiHints.end(),
+ [&](MCPhysReg AntiHint) { return regsOverlap(Reg, AntiHint); });
+ };
+
+ // Copy order into storage
+ OrderStorage.clear();
+ OrderStorage.assign(Order.begin(), Order.end());
+
+ // Partition non-anti-hinted register go first
+ auto PartionPoint =
+ std::stable_partition(OrderStorage.begin(), OrderStorage.end(),
+ [&](MCPhysReg Reg) { return !isAntiHinted(Reg); });
+
+ Order = OrderStorage;
+
+ // print the details
+ LLVM_DEBUG({
+ size_t NonAntiHintedCount =
+ std::distance(OrderStorage.begin(), PartionPoint);
+ size_t AntiHintedCount = std::distance(PartionPoint, OrderStorage.end());
+ dbgs() << "Addded " << NonAntiHintedCount
+ << "non-anti-hinted registers first\n"
+ << "Added " << AntiHintedCount << "anit-hinted at the end!\n";
----------------
JanekvO wrote:
```suggestion
<< "Added " << AntiHintedCount << "anti-hinted at the end!\n";
```
https://github.com/llvm/llvm-project/pull/156943
More information about the llvm-commits
mailing list