[llvm] [AMDGPU][CodeGen] Incrementally update reserved regs for SIPreAllocateWWMRegs pass in RegisterClassInfo (PR #212201)
Carl Ritson via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 23 19:00:44 PDT 2026
================
@@ -120,6 +120,71 @@ void RegisterClassInfo::runOnMachineFunction(const MachineFunction &mf,
}
}
+void RegisterClassInfo::updateReservedRegs(const BitVector &ReservedInput) {
+ assert(MF && TRI && RegClass &&
+ "RegisterClassInfo must be initialized before updating reserved regs");
+ assert(ReservedInput.size() == Reserved.size() &&
+ "Reserved register bit vectors must have the same size");
+ if (ReservedInput == Reserved)
+ return;
+
+ // Cached orders cannot regain unreserved registers; recompute them lazily.
+ bool OnlyNewReservations = Reserved.subsetOf(ReservedInput);
+
+ // Subtract the old set to find newly reserved registers.
+ BitVector NewReservations = ReservedInput;
+ NewReservations.reset(Reserved);
+
+ Reserved = ReservedInput;
+
+ // Pressure limits depend on the number of allocatable registers.
+ std::fill_n(PSetLimits.get(), TRI->getNumRegPressureSets(), 0);
+
+ // NumRegs may hide entries beyond the stress limit, so those orders cannot
+ // safely be compacted using only their visible prefix.
+ if (!OnlyNewReservations || StressRA) {
+ ++Tag;
+ return;
+ }
+
+ for (const TargetRegisterClass &RC : TRI->regclasses()) {
+ RCInfo &Info = RegClass[RC.getID()];
+
+ // Skip stale class information.
+ if (Info.Tag != Tag)
+ continue;
+
+ unsigned NewNumRegs = 0;
+ uint8_t MinCost = uint8_t(~0u);
+ uint8_t LastCost = uint8_t(~0u);
+ unsigned LastCostChange = 0;
+
+ for (unsigned I = 0; I != Info.NumRegs; ++I) {
+ MCPhysReg PhysReg = Info.Order[I];
+ if (NewReservations.test(PhysReg))
----------------
perlfu wrote:
Shouldn't this just be testing `Reserved`?
By testing only `NewReservations` the cost of existing reservations will be included in the cost calculation?
Should costs values be covered by the unit tests?
https://github.com/llvm/llvm-project/pull/212201
More information about the llvm-commits
mailing list