[llvm] 4113577 - [TableGen] Recompute only the affected UberSet when inheriting reg units (#200962)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 18:55:09 PDT 2026
Author: Justin Lebar
Date: 2026-06-05T18:55:05-07:00
New Revision: 4113577578485d6b6e8cb398aa69637263fdb64f
URL: https://github.com/llvm/llvm-project/commit/4113577578485d6b6e8cb398aa69637263fdb64f
DIFF: https://github.com/llvm/llvm-project/commit/4113577578485d6b6e8cb398aa69637263fdb64f.diff
LOG: [TableGen] Recompute only the affected UberSet when inheriting reg units (#200962)
CodeGenRegBank::computeRegUnitWeights() runs a fixpoint over all registers;
normalizeWeight() calls the global computeUberWeights() -- which rescans
every UberRegSet, every register, and all of their register units -- each time
a register inherits register units from its subregisters.
Most of the time, we do better by just recomputing one register's
UberSet.
On AMDGPU (21266 registers) with this change, the "Compute reg unit
weights" phase drops from 3.19s to 0.70s (4.5x speedup) and
-gen-register-info improves overall from ~16.4s to ~14.0s.
Added:
Modified:
llvm/utils/TableGen/Common/CodeGenRegisters.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 741e94552639c..6f089bab7a89d 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -1816,44 +1816,47 @@ static void computeUberSets(std::vector<UberRegSet> &UberSets,
}
}
-// Recompute each UberSet weight after changing unit weights.
-static void computeUberWeights(MutableArrayRef<UberRegSet> UberSets,
- CodeGenRegBank &RegBank) {
- // Skip the first unallocatable set.
- for (UberRegSet &S : UberSets.drop_front()) {
- // Initialize all unit weights in this set, and remember the max units/reg.
- unsigned MaxWeight = 0;
- for (const CodeGenRegister *R : S.Regs) {
- unsigned Weight = 0;
- for (unsigned U : R->getRegUnits()) {
- if (!RegBank.getRegUnit(U).Artificial) {
- unsigned UWeight = RegBank.getRegUnit(U).Weight;
- if (!UWeight) {
- UWeight = 1;
- RegBank.increaseRegUnitWeight(U, UWeight);
- }
- Weight += UWeight;
+// Recompute a single UberSet's weight after a change to register-unit weights.
+static void computeUberWeight(UberRegSet &S, CodeGenRegBank &RegBank) {
+ // Initialize all unit weights in this set, and remember the max units/reg.
+ unsigned MaxWeight = 0;
+ for (const CodeGenRegister *R : S.Regs) {
+ unsigned Weight = 0;
+ for (unsigned U : R->getRegUnits()) {
+ if (!RegBank.getRegUnit(U).Artificial) {
+ unsigned UWeight = RegBank.getRegUnit(U).Weight;
+ if (!UWeight) {
+ UWeight = 1;
+ RegBank.increaseRegUnitWeight(U, UWeight);
}
+ Weight += UWeight;
}
- MaxWeight = std::max(MaxWeight, Weight);
}
- if (S.Weight != MaxWeight) {
- LLVM_DEBUG({
- dbgs() << "UberSet " << &S - UberSets.begin() << " Weight "
- << MaxWeight;
- for (const CodeGenRegister *R : S.Regs)
- dbgs() << " " << R->getName();
- dbgs() << '\n';
- });
- // Update the set weight.
- S.Weight = MaxWeight;
- }
-
- // Find singular determinants.
- for (const CodeGenRegister *R : S.Regs)
- if (R->getRegUnits().count() == 1 && R->getWeight(RegBank) == S.Weight)
- S.SingularDeterminants |= R->getRegUnits();
+ MaxWeight = std::max(MaxWeight, Weight);
}
+ if (S.Weight != MaxWeight) {
+ LLVM_DEBUG({
+ dbgs() << "UberSet Weight " << MaxWeight;
+ for (const CodeGenRegister *R : S.Regs)
+ dbgs() << " " << R->getName();
+ dbgs() << '\n';
+ });
+ // Update the set weight.
+ S.Weight = MaxWeight;
+ }
+
+ // Find singular determinants.
+ for (const CodeGenRegister *R : S.Regs)
+ if (R->getRegUnits().count() == 1 && R->getWeight(RegBank) == S.Weight)
+ S.SingularDeterminants |= R->getRegUnits();
+}
+
+// Recompute each UberSet weight after changing unit weights.
+static void computeUberWeights(MutableArrayRef<UberRegSet> UberSets,
+ CodeGenRegBank &RegBank) {
+ // Skip the first unallocatable set.
+ for (UberRegSet &S : UberSets.drop_front())
+ computeUberWeight(S, RegBank);
}
// normalizeWeight is a computeRegUnitWeights helper that adjusts the weight of
@@ -1888,9 +1891,11 @@ static bool normalizeWeight(CodeGenRegister *Reg,
}
// Postorder register normalization.
- // Inherit register units newly adopted by subregisters.
+ // Inherit register units newly adopted by subregisters. Inheriting units
+ // only changes this register's weight, so just its own UberSet can change;
+ // recompute only that set rather than rescanning every UberSet.
if (Reg->inheritRegUnits(RegBank))
- computeUberWeights(UberSets, RegBank);
+ computeUberWeight(*RegSets[RegBank.getRegIndex(Reg)], RegBank);
// Check if this register is too skinny for its UberRegSet.
UberRegSet *UberSet = RegSets[RegBank.getRegIndex(Reg)];
More information about the llvm-commits
mailing list