mi-sched: Suppress register pressure tracking when the scheduling window is too small.

If the instruction window is < NumRegs/2, pressure tracking is not
likely to be effective. The scheduler has to process a very large
number of tiny blocks. We want this to be fast.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189991 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrew Trick 2013-09-04 21:00:11 +00:00
parent d1d0d37a19
commit 16bb45c5c8
2 changed files with 35 additions and 18 deletions

View File

@ -107,6 +107,10 @@ class MachineSchedStrategy {
public:
virtual ~MachineSchedStrategy() {}
/// Check if pressure tracking is needed before building the DAG and
/// initializing this strategy.
virtual bool shouldTrackPressure(unsigned NumRegionInstrs) { return true; }
/// Initialize the strategy after building the DAG for a new region.
virtual void initialize(ScheduleDAGMI *DAG) = 0;
@ -271,8 +275,8 @@ public:
virtual ~ScheduleDAGMI();
/// Return true if register pressure tracking is enabled.
bool shouldTrackPressure() const { return ShouldTrackPressure; }
/// \brief Return true if register pressure tracking is enabled.
bool isTrackingPressure() const { return ShouldTrackPressure; }
/// Add a postprocessing step to the DAG builder.
/// Mutations are applied in the order that they are added after normal DAG

View File

@ -480,7 +480,8 @@ void ScheduleDAGMI::enterRegion(MachineBasicBlock *bb,
{
ScheduleDAGInstrs::enterRegion(bb, begin, end, regioninstrs);
ShouldTrackPressure = EnableRegPressure;
ShouldTrackPressure =
EnableRegPressure && SchedImpl->shouldTrackPressure(regioninstrs);
// For convenience remember the end of the liveness region.
LiveRegionEnd =
@ -1583,6 +1584,7 @@ public:
};
private:
const MachineSchedContext *Context;
ScheduleDAGMI *DAG;
const TargetSchedModel *SchedModel;
const TargetRegisterInfo *TRI;
@ -1600,8 +1602,11 @@ public:
LogMaxQID = 2
};
ConvergingScheduler():
DAG(0), SchedModel(0), TRI(0), Top(TopQID, "TopQ"), Bot(BotQID, "BotQ") {}
ConvergingScheduler(const MachineSchedContext *C):
Context(C), DAG(0), SchedModel(0), TRI(0),
Top(TopQID, "TopQ"), Bot(BotQID, "BotQ") {}
virtual bool shouldTrackPressure(unsigned NumRegionInstrs);
virtual void initialize(ScheduleDAGMI *dag);
@ -1669,6 +1674,16 @@ init(ScheduleDAGMI *dag, const TargetSchedModel *smodel, SchedRemainder *rem) {
ExecutedResCounts.resize(SchedModel->getNumProcResourceKinds());
}
/// Avoid setting up the register pressure tracker for small regions to save
/// compile time. As a rough heuristic, only track pressure when the number
/// of schedulable instructions exceeds half the integer register file.
bool ConvergingScheduler::shouldTrackPressure(unsigned NumRegionInstrs) {
unsigned NIntRegs = Context->RegClassInfo->getNumAllocatableRegs(
Context->MF->getTarget().getTargetLowering()->getRegClassFor(MVT::i32));
return NumRegionInstrs > (NIntRegs / 2);
}
void ConvergingScheduler::initialize(ScheduleDAGMI *dag) {
DAG = dag;
SchedModel = DAG->getSchedModel();
@ -2371,7 +2386,7 @@ void ConvergingScheduler::tryCandidate(SchedCandidate &Cand,
const RegPressureTracker &RPTracker,
RegPressureTracker &TempTracker) {
if (DAG->shouldTrackPressure()) {
if (DAG->isTrackingPressure()) {
// Always initialize TryCand's RPDelta.
if (Zone.isTop()) {
TempTracker.getMaxDownwardPressureDelta(
@ -2413,9 +2428,9 @@ void ConvergingScheduler::tryCandidate(SchedCandidate &Cand,
// Avoid exceeding the target's limit. If signed PSetID is negative, it is
// invalid; convert it to INT_MAX to give it lowest priority.
if (DAG->shouldTrackPressure() && tryPressure(TryCand.RPDelta.Excess,
Cand.RPDelta.Excess,
TryCand, Cand, RegExcess))
if (DAG->isTrackingPressure() && tryPressure(TryCand.RPDelta.Excess,
Cand.RPDelta.Excess,
TryCand, Cand, RegExcess))
return;
// For loops that are acyclic path limited, aggressively schedule for latency.
@ -2423,9 +2438,9 @@ void ConvergingScheduler::tryCandidate(SchedCandidate &Cand,
return;
// Avoid increasing the max critical pressure in the scheduled region.
if (DAG->shouldTrackPressure() && tryPressure(TryCand.RPDelta.CriticalMax,
Cand.RPDelta.CriticalMax,
TryCand, Cand, RegCritical))
if (DAG->isTrackingPressure() && tryPressure(TryCand.RPDelta.CriticalMax,
Cand.RPDelta.CriticalMax,
TryCand, Cand, RegCritical))
return;
// Keep clustered nodes together to encourage downstream peephole
@ -2447,9 +2462,9 @@ void ConvergingScheduler::tryCandidate(SchedCandidate &Cand,
return;
}
// Avoid increasing the max pressure of the entire region.
if (DAG->shouldTrackPressure() && tryPressure(TryCand.RPDelta.CurrentMax,
Cand.RPDelta.CurrentMax,
TryCand, Cand, RegMax))
if (DAG->isTrackingPressure() && tryPressure(TryCand.RPDelta.CurrentMax,
Cand.RPDelta.CurrentMax,
TryCand, Cand, RegMax))
return;
// Avoid critical resource consumption and balance the schedule.
@ -2744,9 +2759,7 @@ void ConvergingScheduler::schedNode(SUnit *SU, bool IsTopNode) {
/// Create the standard converging machine scheduler. This will be used as the
/// default scheduler if the target does not set a default.
static ScheduleDAGInstrs *createConvergingSched(MachineSchedContext *C) {
assert((!ForceTopDown || !ForceBottomUp) &&
"-misched-topdown incompatible with -misched-bottomup");
ScheduleDAGMI *DAG = new ScheduleDAGMI(C, new ConvergingScheduler());
ScheduleDAGMI *DAG = new ScheduleDAGMI(C, new ConvergingScheduler(C));
// Register DAG post-processors.
//
// FIXME: extend the mutation API to allow earlier mutations to instantiate