[llvm-branch-commits] [llvm] [AMDGPU] Physical register tracking in GCN trackers. (PR #184275)

Dhruva Chakrabarti via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Mar 24 23:06:38 PDT 2026


================
@@ -601,6 +706,46 @@ void GCNUpwardRPTracker::recede(const MachineInstr &MI) {
                         ? max(CurVirtPressure + ECDefPressure, MaxVirtPressure)
                         : max(CurVirtPressure, MaxVirtPressure);
 
+  // Track physical register defs and uses (only if enabled).
+  if (TrackPhysRegs) {
+    // Kill physical register defs (moving backward in upward tracking).
+    for (const MachineOperand &MO : MI.all_defs()) {
+      if (!MO.getReg().isPhysical())
+        continue;
+      Register Reg = MO.getReg();
+      if (!MRI->isAllocatable(Reg))
+        continue;
+
+      // Check if any unit of this register was live before and if so,
+      // erase all of the regunits from PhysLiveRegs.
+      bool WasLive = eraseAllLiveUnits(Reg.asMCReg());
+
+      // Update pressure once per register if any unit of this register was live
+      // before.
+      if (WasLive)
+        CurPhysPressure.inc(Reg.asMCReg(), /*IsAdd=*/false, *MRI);
+    }
+
+    // Make physical register uses alive (moving backward in upward tracking).
+    for (const MachineOperand &MO : MI.all_uses()) {
+      if (!MO.isReg() || !MO.getReg().isPhysical() || !MO.readsReg())
+        continue;
+      Register Reg = MO.getReg();
+      if (!MRI->isAllocatable(Reg))
+        continue;
+      // Check if any unit of this register was not live before and if so,
+      // insert all of the regunits into PhysLiveRegs.
+      bool WasNotLive = insertAllNotLiveUnits(Reg.asMCReg());
----------------
dhruvachak wrote:

Done.

https://github.com/llvm/llvm-project/pull/184275


More information about the llvm-branch-commits mailing list