Skip to content

Commit 66c3dfb

Browse files
committed
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. llvm-svn: 189991
1 parent a6e8777 commit 66c3dfb

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class MachineSchedStrategy {
107107
public:
108108
virtual ~MachineSchedStrategy() {}
109109

110+
/// Check if pressure tracking is needed before building the DAG and
111+
/// initializing this strategy.
112+
virtual bool shouldTrackPressure(unsigned NumRegionInstrs) { return true; }
113+
110114
/// Initialize the strategy after building the DAG for a new region.
111115
virtual void initialize(ScheduleDAGMI *DAG) = 0;
112116

@@ -271,8 +275,8 @@ class ScheduleDAGMI : public ScheduleDAGInstrs {
271275

272276
virtual ~ScheduleDAGMI();
273277

274-
/// Return true if register pressure tracking is enabled.
275-
bool shouldTrackPressure() const { return ShouldTrackPressure; }
278+
/// \brief Return true if register pressure tracking is enabled.
279+
bool isTrackingPressure() const { return ShouldTrackPressure; }
276280

277281
/// Add a postprocessing step to the DAG builder.
278282
/// Mutations are applied in the order that they are added after normal DAG

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ void ScheduleDAGMI::enterRegion(MachineBasicBlock *bb,
480480
{
481481
ScheduleDAGInstrs::enterRegion(bb, begin, end, regioninstrs);
482482

483-
ShouldTrackPressure = EnableRegPressure;
483+
ShouldTrackPressure =
484+
EnableRegPressure && SchedImpl->shouldTrackPressure(regioninstrs);
484485

485486
// For convenience remember the end of the liveness region.
486487
LiveRegionEnd =
@@ -1583,6 +1584,7 @@ class ConvergingScheduler : public MachineSchedStrategy {
15831584
};
15841585

15851586
private:
1587+
const MachineSchedContext *Context;
15861588
ScheduleDAGMI *DAG;
15871589
const TargetSchedModel *SchedModel;
15881590
const TargetRegisterInfo *TRI;
@@ -1600,8 +1602,11 @@ class ConvergingScheduler : public MachineSchedStrategy {
16001602
LogMaxQID = 2
16011603
};
16021604

1603-
ConvergingScheduler():
1604-
DAG(0), SchedModel(0), TRI(0), Top(TopQID, "TopQ"), Bot(BotQID, "BotQ") {}
1605+
ConvergingScheduler(const MachineSchedContext *C):
1606+
Context(C), DAG(0), SchedModel(0), TRI(0),
1607+
Top(TopQID, "TopQ"), Bot(BotQID, "BotQ") {}
1608+
1609+
virtual bool shouldTrackPressure(unsigned NumRegionInstrs);
16051610

16061611
virtual void initialize(ScheduleDAGMI *dag);
16071612

@@ -1669,6 +1674,16 @@ init(ScheduleDAGMI *dag, const TargetSchedModel *smodel, SchedRemainder *rem) {
16691674
ExecutedResCounts.resize(SchedModel->getNumProcResourceKinds());
16701675
}
16711676

1677+
/// Avoid setting up the register pressure tracker for small regions to save
1678+
/// compile time. As a rough heuristic, only track pressure when the number
1679+
/// of schedulable instructions exceeds half the integer register file.
1680+
bool ConvergingScheduler::shouldTrackPressure(unsigned NumRegionInstrs) {
1681+
unsigned NIntRegs = Context->RegClassInfo->getNumAllocatableRegs(
1682+
Context->MF->getTarget().getTargetLowering()->getRegClassFor(MVT::i32));
1683+
1684+
return NumRegionInstrs > (NIntRegs / 2);
1685+
}
1686+
16721687
void ConvergingScheduler::initialize(ScheduleDAGMI *dag) {
16731688
DAG = dag;
16741689
SchedModel = DAG->getSchedModel();
@@ -2371,7 +2386,7 @@ void ConvergingScheduler::tryCandidate(SchedCandidate &Cand,
23712386
const RegPressureTracker &RPTracker,
23722387
RegPressureTracker &TempTracker) {
23732388

2374-
if (DAG->shouldTrackPressure()) {
2389+
if (DAG->isTrackingPressure()) {
23752390
// Always initialize TryCand's RPDelta.
23762391
if (Zone.isTop()) {
23772392
TempTracker.getMaxDownwardPressureDelta(
@@ -2413,19 +2428,19 @@ void ConvergingScheduler::tryCandidate(SchedCandidate &Cand,
24132428

24142429
// Avoid exceeding the target's limit. If signed PSetID is negative, it is
24152430
// invalid; convert it to INT_MAX to give it lowest priority.
2416-
if (DAG->shouldTrackPressure() && tryPressure(TryCand.RPDelta.Excess,
2417-
Cand.RPDelta.Excess,
2418-
TryCand, Cand, RegExcess))
2431+
if (DAG->isTrackingPressure() && tryPressure(TryCand.RPDelta.Excess,
2432+
Cand.RPDelta.Excess,
2433+
TryCand, Cand, RegExcess))
24192434
return;
24202435

24212436
// For loops that are acyclic path limited, aggressively schedule for latency.
24222437
if (Rem.IsAcyclicLatencyLimited && tryLatency(TryCand, Cand, Zone))
24232438
return;
24242439

24252440
// Avoid increasing the max critical pressure in the scheduled region.
2426-
if (DAG->shouldTrackPressure() && tryPressure(TryCand.RPDelta.CriticalMax,
2427-
Cand.RPDelta.CriticalMax,
2428-
TryCand, Cand, RegCritical))
2441+
if (DAG->isTrackingPressure() && tryPressure(TryCand.RPDelta.CriticalMax,
2442+
Cand.RPDelta.CriticalMax,
2443+
TryCand, Cand, RegCritical))
24292444
return;
24302445

24312446
// Keep clustered nodes together to encourage downstream peephole
@@ -2447,9 +2462,9 @@ void ConvergingScheduler::tryCandidate(SchedCandidate &Cand,
24472462
return;
24482463
}
24492464
// Avoid increasing the max pressure of the entire region.
2450-
if (DAG->shouldTrackPressure() && tryPressure(TryCand.RPDelta.CurrentMax,
2451-
Cand.RPDelta.CurrentMax,
2452-
TryCand, Cand, RegMax))
2465+
if (DAG->isTrackingPressure() && tryPressure(TryCand.RPDelta.CurrentMax,
2466+
Cand.RPDelta.CurrentMax,
2467+
TryCand, Cand, RegMax))
24532468
return;
24542469

24552470
// Avoid critical resource consumption and balance the schedule.
@@ -2744,9 +2759,7 @@ void ConvergingScheduler::schedNode(SUnit *SU, bool IsTopNode) {
27442759
/// Create the standard converging machine scheduler. This will be used as the
27452760
/// default scheduler if the target does not set a default.
27462761
static ScheduleDAGInstrs *createConvergingSched(MachineSchedContext *C) {
2747-
assert((!ForceTopDown || !ForceBottomUp) &&
2748-
"-misched-topdown incompatible with -misched-bottomup");
2749-
ScheduleDAGMI *DAG = new ScheduleDAGMI(C, new ConvergingScheduler());
2762+
ScheduleDAGMI *DAG = new ScheduleDAGMI(C, new ConvergingScheduler(C));
27502763
// Register DAG post-processors.
27512764
//
27522765
// FIXME: extend the mutation API to allow earlier mutations to instantiate

0 commit comments

Comments
 (0)