LLVM 20.0.0git
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::GenericScheduler Class Reference

GenericScheduler shrinks the unscheduled zone using heuristics to balance the schedule. More...

#include "llvm/CodeGen/MachineScheduler.h"

Inheritance diagram for llvm::GenericScheduler:
Inheritance graph
[legend]

Public Member Functions

 GenericScheduler (const MachineSchedContext *C)
 
void initPolicy (MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned NumRegionInstrs) override
 Initialize the per-region scheduling policy.
 
void dumpPolicy () const override
 
bool shouldTrackPressure () const override
 Check if pressure tracking is needed before building the DAG and initializing this strategy.
 
bool shouldTrackLaneMasks () const override
 Returns true if lanemasks should be tracked.
 
void initialize (ScheduleDAGMI *dag) override
 Initialize the strategy after building the DAG for a new region.
 
SUnitpickNode (bool &IsTopNode) override
 Pick the best node to balance the schedule. Implements MachineSchedStrategy.
 
void schedNode (SUnit *SU, bool IsTopNode) override
 Update the scheduler's state after scheduling a node.
 
void releaseTopNode (SUnit *SU) override
 When all predecessor dependencies have been resolved, free this node for top-down scheduling.
 
void releaseBottomNode (SUnit *SU) override
 When all successor dependencies have been resolved, free this node for bottom-up scheduling.
 
void registerRoots () override
 Notify this strategy that all roots have been released (including those that depend on EntrySU or ExitSU).
 
- Public Member Functions inherited from llvm::MachineSchedStrategy
virtual ~MachineSchedStrategy ()=default
 
virtual void initPolicy (MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned NumRegionInstrs)
 Optionally override the per-region scheduling policy.
 
virtual void dumpPolicy () const
 
virtual bool shouldTrackPressure () const
 Check if pressure tracking is needed before building the DAG and initializing this strategy.
 
virtual bool shouldTrackLaneMasks () const
 Returns true if lanemasks should be tracked.
 
virtual bool doMBBSchedRegionsTopDown () const
 
virtual void initialize (ScheduleDAGMI *DAG)=0
 Initialize the strategy after building the DAG for a new region.
 
virtual void enterMBB (MachineBasicBlock *MBB)
 Tell the strategy that MBB is about to be processed.
 
virtual void leaveMBB ()
 Tell the strategy that current MBB is done.
 
virtual void registerRoots ()
 Notify this strategy that all roots have been released (including those that depend on EntrySU or ExitSU).
 
virtual SUnitpickNode (bool &IsTopNode)=0
 Pick the next node to schedule, or return NULL.
 
virtual void scheduleTree (unsigned SubtreeID)
 Scheduler callback to notify that a new subtree is scheduled.
 
virtual void schedNode (SUnit *SU, bool IsTopNode)=0
 Notify MachineSchedStrategy that ScheduleDAGMI has scheduled an instruction and updated scheduled/remaining flags in the DAG nodes.
 
virtual void releaseTopNode (SUnit *SU)=0
 When all predecessor dependencies have been resolved, free this node for top-down scheduling.
 
virtual void releaseBottomNode (SUnit *SU)=0
 When all successor dependencies have been resolved, free this node for bottom-up scheduling.
 

Protected Member Functions

void checkAcyclicLatency ()
 Set IsAcyclicLatencyLimited if the acyclic path is longer than the cyclic critical path by more cycles than it takes to drain the instruction buffer.
 
void initCandidate (SchedCandidate &Cand, SUnit *SU, bool AtTop, const RegPressureTracker &RPTracker, RegPressureTracker &TempTracker)
 
virtual bool tryCandidate (SchedCandidate &Cand, SchedCandidate &TryCand, SchedBoundary *Zone) const
 Apply a set of heuristics to a new candidate.
 
SUnitpickNodeBidirectional (bool &IsTopNode)
 Pick the best candidate node from either the top or bottom queue.
 
void pickNodeFromQueue (SchedBoundary &Zone, const CandPolicy &ZonePolicy, const RegPressureTracker &RPTracker, SchedCandidate &Candidate)
 Pick the best candidate from the queue.
 
void reschedulePhysReg (SUnit *SU, bool isTop)
 
- Protected Member Functions inherited from llvm::GenericSchedulerBase
 GenericSchedulerBase (const MachineSchedContext *C)
 
void setPolicy (CandPolicy &Policy, bool IsPostRA, SchedBoundary &CurrZone, SchedBoundary *OtherZone)
 Set the CandPolicy given a scheduling zone given the current resources and latencies inside and outside the zone.
 
void traceCandidate (const SchedCandidate &Cand)
 

Protected Attributes

ScheduleDAGMILiveDAG = nullptr
 
MachineSchedPolicy RegionPolicy
 
SchedBoundary Top
 
SchedBoundary Bot
 
SchedCandidate TopCand
 Candidate last picked from Top boundary.
 
SchedCandidate BotCand
 Candidate last picked from Bot boundary.
 
- Protected Attributes inherited from llvm::GenericSchedulerBase
const MachineSchedContextContext
 
const TargetSchedModelSchedModel = nullptr
 
const TargetRegisterInfoTRI = nullptr
 
SchedRemainder Rem
 

Additional Inherited Members

- Public Types inherited from llvm::GenericSchedulerBase
enum  CandReason : uint8_t {
  NoCand , Only1 , PhysReg , RegExcess ,
  RegCritical , Stall , Cluster , Weak ,
  RegMax , ResourceReduce , ResourceDemand , BotHeightReduce ,
  BotPathReduce , TopDepthReduce , TopPathReduce , NextDefUse ,
  NodeOrder
}
 Represent the type of SchedCandidate found within a single queue. More...
 
- Static Public Member Functions inherited from llvm::GenericSchedulerBase
static const chargetReasonStr (GenericSchedulerBase::CandReason Reason)
 

Detailed Description

GenericScheduler shrinks the unscheduled zone using heuristics to balance the schedule.

Definition at line 1210 of file MachineScheduler.h.

Constructor & Destructor Documentation

◆ GenericScheduler()

llvm::GenericScheduler::GenericScheduler ( const MachineSchedContext C)
inline

Definition at line 1212 of file MachineScheduler.h.

Member Function Documentation

◆ checkAcyclicLatency()

void GenericScheduler::checkAcyclicLatency ( )
protected

Set IsAcyclicLatencyLimited if the acyclic path is longer than the cyclic critical path by more cycles than it takes to drain the instruction buffer.

We estimate an upper bounds on in-flight instructions as:

CyclesPerIteration = max( CyclicPath, Loop-Resource-Height ) InFlightIterations = AcyclicPath / CyclesPerIteration InFlightResources = InFlightIterations * LoopResources

TODO: Check execution resources in addition to IssueCount.

Definition at line 3348 of file MachineScheduler.cpp.

References llvm::SchedRemainder::CriticalPath, llvm::SchedRemainder::CyclicCritPath, llvm::dbgs(), llvm::TargetSchedModel::getLatencyFactor(), llvm::TargetSchedModel::getMicroOpBufferSize(), llvm::TargetSchedModel::getMicroOpFactor(), if(), llvm::SchedRemainder::IsAcyclicLatencyLimited, LLVM_DEBUG, llvm::GenericSchedulerBase::Rem, llvm::SchedRemainder::RemIssueCount, and llvm::GenericSchedulerBase::SchedModel.

◆ dumpPolicy()

void GenericScheduler::dumpPolicy ( ) const
overridevirtual

Reimplemented from llvm::MachineSchedStrategy.

Definition at line 3328 of file MachineScheduler.cpp.

References llvm::dbgs().

◆ initCandidate()

void GenericScheduler::initCandidate ( SchedCandidate Cand,
SUnit SU,
bool  AtTop,
const RegPressureTracker RPTracker,
RegPressureTracker TempTracker 
)
protected

◆ initialize()

void GenericScheduler::initialize ( ScheduleDAGMI DAG)
overridevirtual

◆ initPolicy()

void GenericScheduler::initPolicy ( MachineBasicBlock::iterator  Begin,
MachineBasicBlock::iterator  End,
unsigned  NumRegionInstrs 
)
overridevirtual

◆ pickNode()

SUnit * GenericScheduler::pickNode ( bool IsTopNode)
overridevirtual

◆ pickNodeBidirectional()

SUnit * GenericScheduler::pickNodeBidirectional ( bool IsTopNode)
protected

◆ pickNodeFromQueue()

void GenericScheduler::pickNodeFromQueue ( SchedBoundary Zone,
const CandPolicy ZonePolicy,
const RegPressureTracker RPTracker,
SchedCandidate Cand 
)
protected

Pick the best candidate from the queue.

TODO: getMaxPressureDelta results can be mostly cached for each SUnit during DAG building. To adjust for the current scheduling location we need to maintain the number of vreg uses remaining to be top-scheduled.

Definition at line 3642 of file MachineScheduler.cpp.

References llvm::GenericSchedulerBase::SchedCandidate::AtTop, llvm::SchedBoundary::Available, llvm::GenericSchedulerBase::SchedCandidate::initResourceDelta(), llvm::SchedBoundary::isTop(), LLVM_DEBUG, llvm::GenericSchedulerBase::SchedCandidate::ResDelta, llvm::GenericSchedulerBase::SchedModel, llvm::GenericSchedulerBase::SchedCandidate::setBest(), and llvm::GenericSchedulerBase::traceCandidate().

◆ registerRoots()

void GenericScheduler::registerRoots ( )
overridevirtual

◆ releaseBottomNode()

void llvm::GenericScheduler::releaseBottomNode ( SUnit SU)
inlineoverridevirtual

When all successor dependencies have been resolved, free this node for bottom-up scheduling.

Implements llvm::MachineSchedStrategy.

Definition at line 1244 of file MachineScheduler.h.

References Bot, BotCand, llvm::SUnit::BotReadyCycle, llvm::SUnit::isScheduled, llvm::SchedBoundary::releaseNode(), and llvm::GenericSchedulerBase::SchedCandidate::SU.

◆ releaseTopNode()

void llvm::GenericScheduler::releaseTopNode ( SUnit SU)
inlineoverridevirtual

When all predecessor dependencies have been resolved, free this node for top-down scheduling.

Implements llvm::MachineSchedStrategy.

Definition at line 1236 of file MachineScheduler.h.

References llvm::SUnit::isScheduled, llvm::SchedBoundary::releaseNode(), llvm::GenericSchedulerBase::SchedCandidate::SU, Top, TopCand, and llvm::SUnit::TopReadyCycle.

◆ reschedulePhysReg()

void GenericScheduler::reschedulePhysReg ( SUnit SU,
bool  isTop 
)
protected

◆ schedNode()

void GenericScheduler::schedNode ( SUnit SU,
bool  IsTopNode 
)
overridevirtual

Update the scheduler's state after scheduling a node.

This is the same node that was just returned by pickNode(). However, ScheduleDAGMILive needs to update it's state based on the current cycle before MachineSchedStrategy does.

FIXME: Eventually, we may bundle physreg copies rather than rescheduling them here. See comments in biasPhysReg.

Implements llvm::MachineSchedStrategy.

Definition at line 3836 of file MachineScheduler.cpp.

References llvm::SUnit::BotReadyCycle, llvm::SUnit::hasPhysRegDefs, llvm::SUnit::hasPhysRegUses, and llvm::SUnit::TopReadyCycle.

◆ shouldTrackLaneMasks()

bool llvm::GenericScheduler::shouldTrackLaneMasks ( ) const
inlineoverridevirtual

Returns true if lanemasks should be tracked.

LaneMask tracking is necessary to reorder independent subregister defs for the same vreg. This has to be enabled in combination with shouldTrackPressure().

Reimplemented from llvm::MachineSchedStrategy.

Definition at line 1226 of file MachineScheduler.h.

References RegionPolicy, and llvm::MachineSchedPolicy::ShouldTrackLaneMasks.

◆ shouldTrackPressure()

bool llvm::GenericScheduler::shouldTrackPressure ( ) const
inlineoverridevirtual

Check if pressure tracking is needed before building the DAG and initializing this strategy.

Called after initPolicy.

Reimplemented from llvm::MachineSchedStrategy.

Definition at line 1222 of file MachineScheduler.h.

References RegionPolicy, and llvm::MachineSchedPolicy::ShouldTrackPressure.

◆ tryCandidate()

bool GenericScheduler::tryCandidate ( SchedCandidate Cand,
SchedCandidate TryCand,
SchedBoundary Zone 
) const
protectedvirtual

Apply a set of heuristics to a new candidate.

Heuristics are currently hierarchical. This may be more efficient than a graduated cost model because we don't need to evaluate all aspects of the model for each node in the queue. But it's really done to make the heuristics easier to debug and statistically analyze.

Parameters
Candprovides the policy and current best candidate.
TryCandrefers to the next SUnit candidate, otherwise uninitialized.
Zonedescribes the scheduled zone that we are extending, or nullptr if Cand is from a different zone than TryCand.
Returns
true if TryCand is better than Cand (Reason is NOT NoCand)

Reimplemented in llvm::GCNMaxILPSchedStrategy, and llvm::PPCPreRASchedStrategy.

Definition at line 3531 of file MachineScheduler.cpp.

References llvm::GenericSchedulerBase::SchedCandidate::AtTop, llvm::biasPhysReg(), llvm::GenericSchedulerBase::Cluster, llvm::RegPressureDelta::CriticalMax, llvm::GenericSchedulerBase::SchedResourceDelta::CritResources, llvm::RegPressureDelta::CurrentMax, llvm::GenericSchedulerBase::SchedResourceDelta::DemandedResources, llvm::RegPressureDelta::Excess, llvm::SchedBoundary::getCurrMOps(), llvm::SchedBoundary::getLatencyStallCycles(), llvm::ScheduleDAGMI::getNextClusterPred(), llvm::ScheduleDAGMI::getNextClusterSucc(), llvm::getWeakLeft(), llvm::GenericSchedulerBase::SchedCandidate::initResourceDelta(), llvm::SchedRemainder::IsAcyclicLatencyLimited, llvm::SchedBoundary::isTop(), llvm::GenericSchedulerBase::SchedCandidate::isValid(), llvm::ScheduleDAG::MF, llvm::GenericSchedulerBase::NoCand, llvm::SUnit::NodeNum, llvm::GenericSchedulerBase::NodeOrder, llvm::GenericSchedulerBase::PhysReg, llvm::GenericSchedulerBase::SchedCandidate::Policy, llvm::GenericSchedulerBase::SchedCandidate::Reason, llvm::GenericSchedulerBase::CandPolicy::ReduceLatency, llvm::GenericSchedulerBase::RegCritical, llvm::GenericSchedulerBase::RegExcess, llvm::GenericSchedulerBase::RegMax, llvm::GenericSchedulerBase::Rem, llvm::GenericSchedulerBase::SchedCandidate::ResDelta, llvm::GenericSchedulerBase::ResourceDemand, llvm::GenericSchedulerBase::ResourceReduce, llvm::GenericSchedulerBase::SchedCandidate::RPDelta, llvm::GenericSchedulerBase::SchedModel, llvm::GenericSchedulerBase::Stall, llvm::GenericSchedulerBase::SchedCandidate::SU, llvm::GenericSchedulerBase::TRI, llvm::tryGreater(), llvm::tryLatency(), llvm::tryLess(), llvm::tryPressure(), and llvm::GenericSchedulerBase::Weak.

Referenced by llvm::GCNSchedStrategy::pickNodeBidirectional(), and llvm::GCNSchedStrategy::pickNodeFromQueue().

Member Data Documentation

◆ Bot

SchedBoundary llvm::GenericScheduler::Bot
protected

◆ BotCand

SchedCandidate llvm::GenericScheduler::BotCand
protected

Candidate last picked from Bot boundary.

Definition at line 1266 of file MachineScheduler.h.

Referenced by llvm::GCNSchedStrategy::pickNode(), llvm::GCNSchedStrategy::pickNodeBidirectional(), and releaseBottomNode().

◆ DAG

ScheduleDAGMILive* llvm::GenericScheduler::DAG = nullptr
protected

◆ RegionPolicy

MachineSchedPolicy llvm::GenericScheduler::RegionPolicy
protected

◆ Top

SchedBoundary llvm::GenericScheduler::Top
protected

◆ TopCand

SchedCandidate llvm::GenericScheduler::TopCand
protected

Candidate last picked from Top boundary.

Definition at line 1264 of file MachineScheduler.h.

Referenced by llvm::GCNSchedStrategy::pickNode(), llvm::GCNSchedStrategy::pickNodeBidirectional(), and releaseTopNode().


The documentation for this class was generated from the following files: