[llvm] [AMDGPU] Register allocation anti-hints to reduce MFMA hazard NOPs (PR #156943)
Diana Picus via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 24 02:38:40 PDT 2025
================
@@ -44,8 +45,68 @@ AllocationOrder AllocationOrder::create(Register VirtReg, const VirtRegMap &VRM,
dbgs() << '\n';
}
});
- assert(all_of(Hints,
- [&](MCPhysReg Hint) { return is_contained(Order, Hint); }) &&
+
+ // Get anti-hints
+ SmallVector<MCPhysReg, 16> AntiHintedPhysRegs;
+ MRI.getPhysRegAntiHints(VirtReg, AntiHintedPhysRegs, &VRM);
+
+ LLVM_DEBUG({
+ if (!AntiHintedPhysRegs.empty()) {
+ dbgs() << "anti-hints:";
+ for (MCPhysReg AntiHint : AntiHintedPhysRegs)
+ dbgs() << ' ' << printReg(AntiHint, TRI);
+ dbgs() << '\n';
+ }
+ });
+
+ // Create allocation order object
+ AllocationOrder AO(std::move(Hints), Order, HardHints);
+
+ // Apply anti-hints filtering if needed
+ if (!AntiHintedPhysRegs.empty()) {
+ AO.applyAntiHints(AntiHintedPhysRegs, TRI);
+
+ LLVM_DEBUG({
+ if (!AO.Hints.empty()) {
+ dbgs() << "filtered hints:";
+ for (MCPhysReg Hint : AO.Hints)
+ dbgs() << ' ' << printReg(Hint, TRI);
+ dbgs() << '\n';
+ }
+ });
+ }
+
+ assert(all_of(AO.Hints,
+ [&](MCPhysReg Hint) { return is_contained(AO.Order, Hint); }) &&
"Target hint is outside allocation order.");
- return AllocationOrder(std::move(Hints), Order, HardHints);
+ return AO;
+}
+
+void AllocationOrder::applyAntiHints(ArrayRef<MCPhysReg> AntiHintedPhysRegs,
+ const TargetRegisterInfo *TRI) {
+ // Create filtered order
+ FilteredOrderStorage.clear();
+ FilteredOrderStorage.reserve(Order.size());
----------------
rovka wrote:
Can `FilteredOrderStorage` be local to this method? Also, would it work to use `std::stable_partition` or something instead of looping twice?
https://github.com/llvm/llvm-project/pull/156943
More information about the llvm-commits
mailing list