33 #define DEBUG_TYPE "scheduler" 37 cl::desc(
"Disable use of DFA during scheduling"));
41 cl::desc(
"Track reg pressure and switch priority to in-depth"));
44 : Picker(this), InstrItins(IS->MF->getSubtarget().getInstrItineraryData()) {
52 assert(ResourcesModel &&
"Unimplemented CreateTargetScheduleState.");
55 RegLimit.resize(NumRC);
56 RegPressure.resize(NumRC);
57 std::fill(RegLimit.begin(), RegLimit.end(), 0);
58 std::fill(RegPressure.begin(), RegPressure.end(), 0);
62 ParallelLiveRanges = 0;
63 HorizontalVerticalBalance = 0;
67 ResourcePriorityQueue::numberRCValPredInSU(
SUnit *SU,
unsigned RCId) {
68 unsigned NumberDeps = 0;
104 unsigned ResourcePriorityQueue::numberRCValSuccInSU(
SUnit *SU,
106 unsigned NumberDeps = 0;
143 unsigned NumberDeps = 0;
152 unsigned NumberDeps = 0;
165 NumNodesSolelyBlocking.resize(SUnits->size(), 0);
167 for (
unsigned i = 0,
e = SUnits->size(); i !=
e; ++i) {
168 SUnit *SU = &(*SUnits)[i];
186 unsigned LHSNum = LHS->
NodeNum;
187 unsigned RHSNum = RHS->
NodeNum;
190 unsigned LHSLatency = PQ->getLatency(LHSNum);
191 unsigned RHSLatency = PQ->getLatency(RHSNum);
192 if (LHSLatency < RHSLatency)
return true;
193 if (LHSLatency > RHSLatency)
return false;
197 unsigned LHSBlocked = PQ->getNumSolelyBlockNodes(LHSNum);
198 unsigned RHSBlocked = PQ->getNumSolelyBlockNodes(RHSNum);
199 if (LHSBlocked < RHSBlocked)
return true;
200 if (LHSBlocked > RHSBlocked)
return false;
204 return LHSNum < RHSNum;
210 SUnit *ResourcePriorityQueue::getSingleUnscheduledPred(
SUnit *SU) {
211 SUnit *OnlyAvailablePred =
nullptr;
217 if (OnlyAvailablePred && OnlyAvailablePred != &PredSU)
219 OnlyAvailablePred = &PredSU;
222 return OnlyAvailablePred;
228 unsigned NumNodesBlocking = 0;
230 if (getSingleUnscheduledPred(Succ.
getSUnit()) == SU)
233 NumNodesSolelyBlocking[SU->
NodeNum] = NumNodesBlocking;
253 if (!ResourcesModel->canReserveResources(&TII->
get(
257 case TargetOpcode::EXTRACT_SUBREG:
258 case TargetOpcode::INSERT_SUBREG:
259 case TargetOpcode::SUBREG_TO_REG:
260 case TargetOpcode::REG_SEQUENCE:
261 case TargetOpcode::IMPLICIT_DEF:
267 for (
unsigned i = 0,
e = Packet.size(); i !=
e; ++i)
268 for (
const SDep &Succ : Packet[i]->Succs) {
274 if (Succ.getSUnit() == SU)
286 ResourcesModel->clearResources();
293 ResourcesModel->reserveResources(&TII->
get(
296 case TargetOpcode::EXTRACT_SUBREG:
297 case TargetOpcode::INSERT_SUBREG:
298 case TargetOpcode::SUBREG_TO_REG:
299 case TargetOpcode::REG_SEQUENCE:
300 case TargetOpcode::IMPLICIT_DEF:
303 Packet.push_back(SU);
307 ResourcesModel->clearResources();
314 ResourcesModel->clearResources();
331 RegBalance += numberRCValSuccInSU(SU, RCId);
337 if (isa<ConstantSDNode>(Op.
getNode()))
342 RegBalance -= numberRCValPredInSU(SU, RCId);
365 if ((RegPressure[RC->getID()] +
367 (RegPressure[RC->getID()] +
410 ResCount <<= FactorOne;
426 ResCount <<= FactorOne;
435 if (
N->isMachineOpcode()) {
438 ResCount += (PriorityTwo + (ScaleThree*
N->getNumValues()));
441 switch (
N->getOpcode()) {
464 ResourcesModel->clearResources();
480 RegPressure[RC->
getID()] += numberRCValSuccInSU(SU, RC->
getID());
491 if (RegPressure[RC->
getID()] >
492 (numberRCValPredInSU(SU, RC->
getID())))
493 RegPressure[RC->
getID()] -= numberRCValPredInSU(SU, RC->
getID());
494 else RegPressure[RC->
getID()] = 0;
511 unsigned NumberNonControlDeps = 0;
514 adjustPriorityOfUnscheduledPreds(Succ.
getSUnit());
516 NumberNonControlDeps++;
519 if (!NumberNonControlDeps) {
520 if (ParallelLiveRanges >= SU->
NumPreds)
523 ParallelLiveRanges = 0;
535 unsigned NodeNumDefs = 0;
537 if (
N->isMachineOpcode()) {
540 if (
N->getMachineOpcode() == TargetOpcode::IMPLICIT_DEF) {
544 NodeNumDefs = std::min(
N->getNumValues(), TID.
getNumDefs());
547 switch(
N->getOpcode()) {
567 void ResourcePriorityQueue::adjustPriorityOfUnscheduledPreds(
SUnit *SU) {
570 SUnit *OnlyAvailablePred = getSingleUnscheduledPred(SU);
571 if (!OnlyAvailablePred || !OnlyAvailablePred->
isAvailable)
576 remove(OnlyAvailablePred);
580 push(OnlyAvailablePred);
590 std::vector<SUnit *>::iterator Best = Queue.begin();
593 for (
auto I = std::next(Queue.begin()),
E = Queue.end();
I !=
E; ++
I) {
603 for (
auto I = std::next(Queue.begin()),
E = Queue.end();
I !=
E; ++
I)
604 if (Picker(*Best, *
I))
609 if (Best != std::prev(Queue.end()))
619 assert(!Queue.empty() &&
"Queue is empty!");
620 std::vector<SUnit *>::iterator
I =
find(Queue, SU);
621 if (I != std::prev(Queue.end()))
static const unsigned PriorityTwo
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
static const unsigned PriorityFour
unsigned NumPreds
of SDep::Data preds.
This class represents lattice values for constants.
SDNode * getNode() const
Returns the representative SDNode for this SUnit.
static const unsigned ScaleTwo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Describe properties that are true of each instruction in the target description file.
bool empty() const override
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
static cl::opt< int > RegPressureThreshold("dfa-sched-reg-pressure-threshold", cl::Hidden, cl::ZeroOrMore, cl::init(5), cl::desc("Track reg pressure and switch priority to in-depth"))
SDNode * getNode() const
get the SDNode which holds the desired result
virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const
Return the register pressure "high water mark" for the specific register class.
void reserveResources(SUnit *SU)
Keep track of available resources.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
static unsigned numberCtrlDepsInSU(SUnit *SU)
bool isScheduled
True once scheduled.
virtual DFAPacketizer * CreateTargetScheduleState(const TargetSubtargetInfo &) const
Create machine specific model for scheduling.
const TargetLowering * TLI
CopyToReg - This node has three operands: a chain, a register number to set to this value...
iterator_range< regclass_iterator > regclasses() const
void initNumRegDefsLeft(SUnit *SU)
InitNumRegDefsLeft - Determine the # of regs defined by this node.
unsigned getID() const
Return the register class ID number.
INLINEASM - Represents an inline asm block.
ResourcePriorityQueue(SelectionDAGISel *IS)
unsigned getNumRegClasses() const
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
bool isCtrl() const
Shorthand for getKind() != SDep::Data.
virtual const TargetInstrInfo * getInstrInfo() const
static const unsigned ScaleThree
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
initializer< Ty > init(const Ty &Val)
int rawRegPressureDelta(SUnit *SU, unsigned RCId)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const SDValue & getOperand(unsigned Num) const
bool operator()(const SUnit *LHS, const SUnit *RHS) const
This heuristic is used if DFA scheduling is not desired for some VLIW platform.
int SUSchedulingCost(SUnit *SU)
Single cost function reflecting benefit of scheduling SU in the current cycle.
SDNode * getGluedNode() const
If this node has a glue operand, return the node to which the glue operand points.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
unsigned getNumOperands() const
Return the number of values used by this operation.
void remove(SUnit *SU) override
TokenFactor - This node takes multiple tokens as input and produces a single token result...
bool isScheduleHigh
True if preferable to schedule high.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
TargetSubtargetInfo - Generic base class for all target subtargets.
bool isAvailable
True once available.
unsigned NodeQueueId
Queue id of node.
unsigned getHeight() const
Returns the height of this node, which is the length of the maximum path down to any node which has n...
static const unsigned FactorOne
void scheduledNode(SUnit *SU) override
scheduledNode - Main resource tracking point.
MCSchedModel SchedModel
Basic machine properties.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
unsigned short NumRegDefsLeft
of reg defs with no scheduled use.
bool isCall() const
Return true if the instruction is a call.
static const unsigned PriorityThree
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
bool isResourceAvailable(SUnit *SU)
Check if scheduling of this SU is possible in the current packet.
static const unsigned PriorityOne
unsigned NodeNum
Entry # of node in the node vector.
static const unsigned ScaleOne
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void push(SUnit *U) override
INLINEASM_BR - Terminator version of inline asm. Used by asm-goto.
unsigned getResNo() const
get the index which selects a specific result in the SDNode
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
SmallVector< SDep, 4 > Succs
All sunit successors.
SUnit * pop() override
Main access point - returns next instructions to be placed in scheduling sequence.
static unsigned numberCtrlPredInSU(SUnit *SU)
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
int regPressureDelta(SUnit *SU, bool RawPressure=false)
Estimates change in reg pressure from this SU.
void initNodes(std::vector< SUnit > &sunits) override
Initialize nodes.
static cl::opt< bool > DisableDFASched("disable-dfa-sched", cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::desc("Disable use of DFA during scheduling"))
Scheduling unit. This is a node in the scheduling DAG.
This file describes how to lower LLVM code to machine code.