From ba17293a8827a7e0e390b0a1d6075148a58d9edd Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Sat, 9 Jun 2012 02:16:58 +0000 Subject: Register pressure: added getPressureAfterInstr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158256 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/RegisterPressure.cpp | 113 +++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 33 deletions(-) (limited to 'lib/CodeGen/RegisterPressure.cpp') diff --git a/lib/CodeGen/RegisterPressure.cpp b/lib/CodeGen/RegisterPressure.cpp index 63d319e209..015d673538 100644 --- a/lib/CodeGen/RegisterPressure.cpp +++ b/lib/CodeGen/RegisterPressure.cpp @@ -654,32 +654,18 @@ static void computeMaxPressureDelta(ArrayRef OldMaxPressureVec, } } -/// Consider the pressure increase caused by traversing this instruction -/// bottom-up. Find the pressure set with the most change beyond its pressure -/// limit based on the tracker's current pressure, and return the change in -/// number of register units of that pressure set introduced by this -/// instruction. +/// Record the upward impact of a single instruction on current register +/// pressure. Unlike the advance/recede pressure tracking interface, this does +/// not discover live in/outs. /// -/// This assumes that the current LiveOut set is sufficient. -/// -/// FIXME: This is expensive for an on-the-fly query. We need to cache the -/// result per-SUnit with enough information to adjust for the current -/// scheduling position. But this works as a proof of concept. -void RegPressureTracker:: -getMaxUpwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, - ArrayRef CriticalPSets, - ArrayRef MaxPressureLimit) { +/// This is intended for speculative queries. It leaves pressure inconsistent +/// with the current position, so must be restored by the caller. +void RegPressureTracker::bumpUpwardPressure(const MachineInstr *MI) { // Account for register pressure similar to RegPressureTracker::recede(). PhysRegOperands PhysRegOpers; VirtRegOperands VirtRegOpers; collectOperands(MI, PhysRegOpers, VirtRegOpers, TRI, RCI); - // Snapshot Pressure. - // FIXME: The snapshot heap space should persist. But I'm planning to - // summarize the pressure effect so we don't need to snapshot at all. - std::vector SavedPressure = CurrSetPressure; - std::vector SavedMaxPressure = P.MaxSetPressure; - // Boost max pressure for all dead defs together. // Since CurrSetPressure and MaxSetPressure increasePhysRegPressure(PhysRegOpers.DeadDefs); @@ -708,6 +694,31 @@ getMaxUpwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, increaseVirtRegPressure(Reg); } } +} + +/// Consider the pressure increase caused by traversing this instruction +/// bottom-up. Find the pressure set with the most change beyond its pressure +/// limit based on the tracker's current pressure, and return the change in +/// number of register units of that pressure set introduced by this +/// instruction. +/// +/// This assumes that the current LiveOut set is sufficient. +/// +/// FIXME: This is expensive for an on-the-fly query. We need to cache the +/// result per-SUnit with enough information to adjust for the current +/// scheduling position. But this works as a proof of concept. +void RegPressureTracker:: +getMaxUpwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, + ArrayRef CriticalPSets, + ArrayRef MaxPressureLimit) { + // Snapshot Pressure. + // FIXME: The snapshot heap space should persist. But I'm planning to + // summarize the pressure effect so we don't need to snapshot at all. + std::vector SavedPressure = CurrSetPressure; + std::vector SavedMaxPressure = P.MaxSetPressure; + + bumpUpwardPressure(MI); + computeExcessPressureDelta(SavedPressure, CurrSetPressure, Delta, TRI); computeMaxPressureDelta(SavedMaxPressure, P.MaxSetPressure, CriticalPSets, MaxPressureLimit, Delta); @@ -735,25 +746,18 @@ static bool findUseBetween(unsigned Reg, return false; } -/// Consider the pressure increase caused by traversing this instruction -/// top-down. Find the register class with the most change in its pressure limit -/// based on the tracker's current pressure, and return the number of excess -/// register units of that pressure set introduced by this instruction. +/// Record the downward impact of a single instruction on current register +/// pressure. Unlike the advance/recede pressure tracking interface, this does +/// not discover live in/outs. /// -/// This assumes that the current LiveIn set is sufficient. -void RegPressureTracker:: -getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, - ArrayRef CriticalPSets, - ArrayRef MaxPressureLimit) { +/// This is intended for speculative queries. It leaves pressure inconsistent +/// with the current position, so must be restored by the caller. +void RegPressureTracker::bumpDownwardPressure(const MachineInstr *MI) { // Account for register pressure similar to RegPressureTracker::recede(). PhysRegOperands PhysRegOpers; VirtRegOperands VirtRegOpers; collectOperands(MI, PhysRegOpers, VirtRegOpers, TRI, RCI); - // Snapshot Pressure. - std::vector SavedPressure = CurrSetPressure; - std::vector SavedMaxPressure = P.MaxSetPressure; - // Kill liveness at last uses. Assume allocatable physregs are single-use // rather than checking LiveIntervals. decreasePhysRegPressure(PhysRegOpers.Uses); @@ -781,6 +785,23 @@ getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, increaseVirtRegPressure(VirtRegOpers.DeadDefs); decreasePhysRegPressure(PhysRegOpers.DeadDefs); decreaseVirtRegPressure(VirtRegOpers.DeadDefs); +} + +/// Consider the pressure increase caused by traversing this instruction +/// top-down. Find the register class with the most change in its pressure limit +/// based on the tracker's current pressure, and return the number of excess +/// register units of that pressure set introduced by this instruction. +/// +/// This assumes that the current LiveIn set is sufficient. +void RegPressureTracker:: +getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, + ArrayRef CriticalPSets, + ArrayRef MaxPressureLimit) { + // Snapshot Pressure. + std::vector SavedPressure = CurrSetPressure; + std::vector SavedMaxPressure = P.MaxSetPressure; + + bumpDownwardPressure(MI); computeExcessPressureDelta(SavedPressure, CurrSetPressure, Delta, TRI); computeMaxPressureDelta(SavedMaxPressure, P.MaxSetPressure, CriticalPSets, @@ -792,3 +813,29 @@ getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, P.MaxSetPressure.swap(SavedMaxPressure); CurrSetPressure.swap(SavedPressure); } + +/// Get the pressure of each PSet after traversing this instruction bottom-up. +void RegPressureTracker:: +getUpwardPressure(const MachineInstr *MI, + std::vector &PressureResult) { + // Snapshot pressure. + PressureResult = CurrSetPressure; + + bumpUpwardPressure(MI); + + // Current pressure becomes the result. Restore current pressure. + CurrSetPressure.swap(PressureResult); +} + +/// Get the pressure of each PSet after traversing this instruction top-down. +void RegPressureTracker:: +getDownwardPressure(const MachineInstr *MI, + std::vector &PressureResult) { + // Snapshot pressure. + PressureResult = CurrSetPressure; + + bumpDownwardPressure(MI); + + // Current pressure becomes the result. Restore current pressure. + CurrSetPressure.swap(PressureResult); +} -- cgit v1.2.3