[llvm] r189991 - mi-sched: Suppress register pressure tracking when the scheduling window is too small.
Andrew Trick
atrick at apple.com
Wed Sep 4 14:00:11 PDT 2013
Author: atrick
Date: Wed Sep 4 16:00:11 2013
New Revision: 189991
URL: http://llvm.org/viewvc/llvm-project?rev=189991&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/CodeGen/MachineScheduler.h
llvm/trunk/lib/CodeGen/MachineScheduler.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineScheduler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineScheduler.h?rev=189991&r1=189990&r2=189991&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineScheduler.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineScheduler.h Wed Sep 4 16:00:11 2013
@@ -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
Modified: llvm/trunk/lib/CodeGen/MachineScheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineScheduler.cpp?rev=189991&r1=189990&r2=189991&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineScheduler.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineScheduler.cpp Wed Sep 4 16:00:11 2013
@@ -480,7 +480,8 @@ void ScheduleDAGMI::enterRegion(MachineB
{
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 TargetSch
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(S
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(S
// 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(S
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(S
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(SUni
/// 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
More information about the llvm-commits
mailing list