================
@@ -320,12 +325,72 @@ class GCNRPTracker {
 
 protected:
   const LiveIntervals &LIS;
+
   LiveRegSet VirtLiveRegs;
+
+  // Physical register liveness: Units provides O(1) unit-level alias checks,
+  // Regs tracks which register names contributed to pressure for cheap
+  // reconstruction. Both must be kept in sync.
+  struct PhysicalRegLiveness {
+    LiveRegUnits Units;
+    SmallDenseSet<MCRegister, 16> Regs;
+
+    void init(const TargetRegisterInfo &TRI) {
+      Units.init(TRI);
+      Regs.clear();
+    }
+    void clear() {
+      Units.clear();
+      Regs.clear();
+    }
+    const BitVector &getBitVector() const { return Units.getBitVector(); }
+
+    void add(Register Reg) {
+      Units.addReg(Reg);
+      Regs.insert(Reg.asMCReg());
+    }
+    void remove(Register Reg) {
+      Units.removeReg(Reg);
+      Regs.erase(Reg.asMCReg());
+    }
+    void remove(const BitVector &KilledUnits, MCRegister Reg) {
+      Units.removeUnits(KilledUnits);
+      Regs.erase(Reg);
+    }
+  };
+  PhysicalRegLiveness PhysLiveRegs;
+
   GCNRegPressure CurPressure, MaxPressure;
+
+  // Flag to control whether physical register tracking is active.
+  // Set to true when GCNTrackers are enabled, false otherwise.
+  bool TrackPhysRegs = false;
+
   const MachineInstr *LastTrackedMI = nullptr;
   mutable const MachineRegisterInfo *MRI = nullptr;
+  const SIRegisterInfo *SRI = nullptr;
+
+  GCNRPTracker(const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
+      : LIS(LIS), MRI(&MRI),
+        SRI(static_cast<const SIRegisterInfo *>(MRI.getTargetRegisterInfo())) {
+    setPhysRegTracking();
+    if (TrackPhysRegs)
+      PhysLiveRegs.init(*SRI);
----------------
macurtis-amd wrote:

Add `PhysicalRegLiveness::PhysicalRegLiveness((const TargetRegisterInfo &TRI)`?
I don't think there is benefit in conditionally initializing `PhysLiveRegs`.

https://github.com/llvm/llvm-project/pull/184275
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to