[llvm] r184564 - MI-Sched: Adjust regpressure limits for reserved regs.
Andrew Trick
atrick at apple.com
Fri Jun 21 11:32:58 PDT 2013
Author: atrick
Date: Fri Jun 21 13:32:58 2013
New Revision: 184564
URL: http://llvm.org/viewvc/llvm-project?rev=184564&view=rev
Log:
MI-Sched: Adjust regpressure limits for reserved regs.
Modified:
llvm/trunk/include/llvm/CodeGen/RegisterClassInfo.h
llvm/trunk/lib/CodeGen/MachineScheduler.cpp
llvm/trunk/lib/CodeGen/RegisterClassInfo.cpp
llvm/trunk/lib/CodeGen/RegisterPressure.cpp
Modified: llvm/trunk/include/llvm/CodeGen/RegisterClassInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/RegisterClassInfo.h?rev=184564&r1=184563&r2=184564&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/RegisterClassInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/RegisterClassInfo.h Fri Jun 21 13:32:58 2013
@@ -62,6 +62,8 @@ class RegisterClassInfo {
// Reserved registers in the current MF.
BitVector Reserved;
+ OwningArrayPtr<unsigned> PSetLimits;
+
// Compute all information about RC.
void compute(const TargetRegisterClass *RC) const;
@@ -126,8 +128,19 @@ public:
unsigned getLastCostChange(const TargetRegisterClass *RC) {
return get(RC).LastCostChange;
}
+
+ /// Get the register unit limit for the given pressure set index.
+ ///
+ /// RegisterClassInfo adjusts this limit for reserved registers.
+ unsigned getRegPressureSetLimit(unsigned Idx) const {
+ if (!PSetLimits[Idx])
+ PSetLimits[Idx] = computePSetLimit(Idx);
+ return PSetLimits[Idx];
+ }
+
+protected:
+ unsigned computePSetLimit(unsigned Idx) const;
};
} // end namespace llvm
#endif
-
Modified: llvm/trunk/lib/CodeGen/MachineScheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineScheduler.cpp?rev=184564&r1=184563&r2=184564&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineScheduler.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineScheduler.cpp Fri Jun 21 13:32:58 2013
@@ -21,6 +21,7 @@
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/RegisterClassInfo.h"
#include "llvm/CodeGen/ScheduleDFS.h"
@@ -487,7 +488,7 @@ void ScheduleDAGMI::initRegPressure() {
const std::vector<unsigned> &RegionPressure =
RPTracker.getPressure().MaxSetPressure;
for (unsigned i = 0, e = RegionPressure.size(); i < e; ++i) {
- unsigned Limit = TRI->getRegPressureSetLimit(i);
+ unsigned Limit = RegClassInfo->getRegPressureSetLimit(i);
DEBUG(dbgs() << TRI->getRegPressureSetName(i)
<< "Limit " << Limit
<< " Actual " << RegionPressure[i] << "\n");
@@ -513,7 +514,7 @@ updateScheduledPressure(const std::vecto
}
DEBUG(
for (unsigned i = 0, e = NewMaxPressure.size(); i < e; ++i) {
- unsigned Limit = TRI->getRegPressureSetLimit(i);
+ unsigned Limit = RegClassInfo->getRegPressureSetLimit(i);
if (NewMaxPressure[i] > Limit ) {
dbgs() << " " << TRI->getRegPressureSetName(i) << ": "
<< NewMaxPressure[i] << " > " << Limit << "\n";
Modified: llvm/trunk/lib/CodeGen/RegisterClassInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegisterClassInfo.cpp?rev=184564&r1=184563&r2=184564&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegisterClassInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegisterClassInfo.cpp Fri Jun 21 13:32:58 2013
@@ -40,6 +40,9 @@ void RegisterClassInfo::runOnMachineFunc
if (MF->getTarget().getRegisterInfo() != TRI) {
TRI = MF->getTarget().getRegisterInfo();
RegClass.reset(new RCInfo[TRI->getNumRegClasses()]);
+ unsigned NumPSets = TRI->getNumRegPressureSets();
+ PSetLimits.reset(new unsigned[NumPSets]);
+ std::fill(&PSetLimits[0], &PSetLimits[NumPSets], 0);
Update = true;
}
@@ -144,3 +147,32 @@ void RegisterClassInfo::compute(const Ta
RCI.Tag = Tag;
}
+/// This is not accurate because two overlapping register sets may have some
+/// nonoverlapping reserved registers. However, computing the allocation order
+/// for all register classes would be too expensive.
+unsigned RegisterClassInfo::computePSetLimit(unsigned Idx) const {
+ const TargetRegisterClass *RC = 0;
+ unsigned NumRCUnits = 0;
+ for (TargetRegisterInfo::regclass_iterator
+ RI = TRI->regclass_begin(), RE = TRI->regclass_end(); RI != RE; ++RI) {
+ const int *PSetID = TRI->getRegClassPressureSets(*RI);
+ for (; *PSetID != -1; ++PSetID) {
+ if ((unsigned)*PSetID == Idx)
+ break;
+ }
+ if (*PSetID == -1)
+ continue;
+
+ // Found a register class that counts against this pressure set.
+ // For efficiency, only compute the set order for the largest set.
+ unsigned NUnits = TRI->getRegClassWeight(*RI).WeightLimit;
+ if (!RC || NUnits > NumRCUnits) {
+ RC = *RI;
+ NumRCUnits = NUnits;
+ }
+ }
+ compute(RC);
+ unsigned NReserved = RC->getNumRegs() - getNumAllocatableRegs(RC);
+ return TRI->getRegPressureSetLimit(Idx)
+ - TRI->getRegClassWeight(RC).RegWeight * NReserved;
+}
Modified: llvm/trunk/lib/CodeGen/RegisterPressure.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegisterPressure.cpp?rev=184564&r1=184563&r2=184564&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegisterPressure.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegisterPressure.cpp Fri Jun 21 13:32:58 2013
@@ -533,7 +533,7 @@ bool RegPressureTracker::advance() {
static void computeExcessPressureDelta(ArrayRef<unsigned> OldPressureVec,
ArrayRef<unsigned> NewPressureVec,
RegPressureDelta &Delta,
- const TargetRegisterInfo *TRI) {
+ const RegisterClassInfo *RCI) {
int ExcessUnits = 0;
unsigned PSetID = ~0U;
for (unsigned i = 0, e = OldPressureVec.size(); i < e; ++i) {
@@ -543,7 +543,7 @@ static void computeExcessPressureDelta(A
if (!PDiff) // No change in this set in the common case.
continue;
// Only consider change beyond the limit.
- unsigned Limit = TRI->getRegPressureSetLimit(i);
+ unsigned Limit = RCI->getRegPressureSetLimit(i);
if (Limit > POld) {
if (Limit > PNew)
PDiff = 0; // Under the limit
@@ -659,7 +659,7 @@ getMaxUpwardPressureDelta(const MachineI
bumpUpwardPressure(MI);
- computeExcessPressureDelta(SavedPressure, CurrSetPressure, Delta, TRI);
+ computeExcessPressureDelta(SavedPressure, CurrSetPressure, Delta, RCI);
computeMaxPressureDelta(SavedMaxPressure, P.MaxSetPressure, CriticalPSets,
MaxPressureLimit, Delta);
assert(Delta.CriticalMax.UnitIncrease >= 0 &&
@@ -749,7 +749,7 @@ getMaxDownwardPressureDelta(const Machin
bumpDownwardPressure(MI);
- computeExcessPressureDelta(SavedPressure, CurrSetPressure, Delta, TRI);
+ computeExcessPressureDelta(SavedPressure, CurrSetPressure, Delta, RCI);
computeMaxPressureDelta(SavedMaxPressure, P.MaxSetPressure, CriticalPSets,
MaxPressureLimit, Delta);
assert(Delta.CriticalMax.UnitIncrease >= 0 &&
More information about the llvm-commits
mailing list