diff --git a/lib/Target/AMDGPU/GCNRegPressure.cpp b/lib/Target/AMDGPU/GCNRegPressure.cpp index 4e569a27e97..53b552adb2d 100644 --- a/lib/Target/AMDGPU/GCNRegPressure.cpp +++ b/lib/Target/AMDGPU/GCNRegPressure.cpp @@ -284,18 +284,27 @@ GCNRPTracker::LiveRegSet llvm::getLiveRegs(SlotIndex SI, return LiveRegs; } -void GCNUpwardRPTracker::reset(const MachineInstr &MI, - const LiveRegSet *LiveRegsCopy) { - MRI = &MI.getParent()->getParent()->getRegInfo(); +void GCNRPTracker::reset(const MachineInstr &MI, + const LiveRegSet *LiveRegsCopy, + bool After) { + const MachineFunction &MF = *MI.getMF(); + MRI = &MF.getRegInfo(); if (LiveRegsCopy) { if (&LiveRegs != LiveRegsCopy) LiveRegs = *LiveRegsCopy; } else { - LiveRegs = getLiveRegsAfter(MI, LIS); + LiveRegs = After ? getLiveRegsAfter(MI, LIS) + : getLiveRegsBefore(MI, LIS); } + MaxPressure = CurPressure = getRegPressure(*MRI, LiveRegs); } +void GCNUpwardRPTracker::reset(const MachineInstr &MI, + const LiveRegSet *LiveRegsCopy) { + GCNRPTracker::reset(MI, LiveRegsCopy, true); +} + void GCNUpwardRPTracker::recede(const MachineInstr &MI) { assert(MRI && "call reset first"); @@ -349,13 +358,7 @@ bool GCNDownwardRPTracker::reset(const MachineInstr &MI, NextMI = skipDebugInstructionsForward(NextMI, MBBEnd); if (NextMI == MBBEnd) return false; - if (LiveRegsCopy) { - if (&LiveRegs != LiveRegsCopy) - LiveRegs = *LiveRegsCopy; - } else { - LiveRegs = getLiveRegsBefore(*NextMI, LIS); - } - MaxPressure = CurPressure = getRegPressure(*MRI, LiveRegs); + GCNRPTracker::reset(*NextMI, LiveRegsCopy, false); return true; } diff --git a/lib/Target/AMDGPU/GCNRegPressure.h b/lib/Target/AMDGPU/GCNRegPressure.h index e418aa0fe91..b15384eb156 100644 --- a/lib/Target/AMDGPU/GCNRegPressure.h +++ b/lib/Target/AMDGPU/GCNRegPressure.h @@ -106,6 +106,9 @@ protected: GCNRPTracker(const LiveIntervals &LIS_) : LIS(LIS_) {} + void reset(const MachineInstr &MI, const LiveRegSet *LiveRegsCopy, + bool After); + public: // live regs for the current state const decltype(LiveRegs) &getLiveRegs() const { return LiveRegs; }