41#define DEBUG_TYPE "machine-scheduler"
62 cl::desc(
"High register pressure threhold."));
87 if (SUd->
Succs.size() == 0)
90 for (
const auto &S : SUd->
Succs) {
96 if (S.getSUnit() == SUu && S.getLatency() > 0)
118 case TargetOpcode::EXTRACT_SUBREG:
119 case TargetOpcode::INSERT_SUBREG:
120 case TargetOpcode::SUBREG_TO_REG:
121 case TargetOpcode::REG_SEQUENCE:
122 case TargetOpcode::IMPLICIT_DEF:
123 case TargetOpcode::COPY:
124 case TargetOpcode::INLINEASM:
125 case TargetOpcode::INLINEASM_BR:
145 bool startNewCycle =
false;
158 startNewCycle =
true;
165 case TargetOpcode::EXTRACT_SUBREG:
166 case TargetOpcode::INSERT_SUBREG:
167 case TargetOpcode::SUBREG_TO_REG:
168 case TargetOpcode::REG_SEQUENCE:
169 case TargetOpcode::IMPLICIT_DEF:
170 case TargetOpcode::KILL:
171 case TargetOpcode::CFI_INSTRUCTION:
172 case TargetOpcode::EH_LABEL:
173 case TargetOpcode::COPY:
174 case TargetOpcode::INLINEASM:
175 case TargetOpcode::INLINEASM_BR:
182 for (
unsigned i = 0, e =
Packet.size(); i != e; ++i) {
189 return startNewCycle;
203 <<
" in_func " <<
BB->getParent()->getName()
204 <<
" at loop depth " <<
MLI->getLoopDepth(
BB) <<
" \n");
208 Topo.InitDAGTopologicalSorting();
222 if (SU.getHeight() > maxH)
223 maxH = SU.getHeight();
224 dbgs() <<
"Max Height " << maxH <<
"\n";
229 if (SU.getDepth() > maxD)
230 maxD = SU.getDepth();
231 dbgs() <<
"Max Depth " << maxD <<
"\n";
239 bool IsTopNode =
false;
242 dbgs() <<
"** VLIWMachineScheduler::schedule picking next node\n");
262 dbgs() <<
"*** Final schedule for "
281 delete Top.HazardRec;
282 delete Bot.HazardRec;
283 Top.HazardRec =
TII->CreateTargetMIHazardRecognizer(Itin,
DAG);
284 Bot.HazardRec =
TII->CreateTargetMIHazardRecognizer(Itin,
DAG);
286 delete Top.ResourceModel;
287 delete Bot.ResourceModel;
291 const std::vector<unsigned> &MaxPressure =
292 DAG->getRegPressure().MaxSetPressure;
294 for (
unsigned i = 0, e = MaxPressure.size(); i < e; ++i) {
295 unsigned Limit =
DAG->getRegClassInfo()->getRegPressureSetLimit(i);
297 ((float)MaxPressure[i] > ((float)Limit *
RPThreshold));
311 Top.MaxMinLatency = std::max(MinLatency,
Top.MaxMinLatency);
326 unsigned SuccReadyCycle =
I->getSUnit()->BotReadyCycle;
327 unsigned MinLatency =
I->getLatency();
329 Bot.MaxMinLatency = std::max(MinLatency,
Bot.MaxMinLatency);
369 SUnit *SU,
unsigned ReadyCycle) {
388 "MinReadyCycle uninitialized");
411 bool startNewCycle =
false;
446 for (
unsigned i = 0, e =
Pending.size(); i != e; ++i) {
484 auto AdvanceCycle = [
this]() {
492 for (
unsigned i = 0; AdvanceCycle(); ++i) {
511 dbgs() <<
DAG->TRI->getRegPressureSetName(
P.getPSet()) <<
":"
512 <<
P.getUnitInc() <<
" ";
529 DAG->getRegionCriticalPSets(),
530 DAG->getRegPressure().MaxSetPressure);
531 std::stringstream dbgstr;
532 dbgstr <<
"SU(" << std::setw(3) << (*I)->NodeNum <<
")";
533 dbgs() << dbgstr.str();
536 (*I)->getInstr()->dump();
548 for (
auto &Pred : SU->
Preds) {
550 if (!Pred.getSUnit()->isScheduled && (Pred.getSUnit() != SU2))
563 for (
auto &Succ : SU->
Succs) {
565 if (!Succ.getSUnit()->isScheduled && (Succ.getSUnit() != SU2))
578 for (
const auto &
P : PD) {
585 return (isBotUp ?
P.getUnitInc() : -
P.getUnitInc());
611 unsigned IsAvailableAmt = 0;
614 if (
Top.isLatencyBound(SU)) {
620 std::stringstream dbgstr;
621 dbgstr <<
"h" << std::setw(3) << SU->
getHeight() <<
"|";
622 dbgs() << dbgstr.str();
627 if (
Top.ResourceModel->isResourceAvailable(SU,
true)) {
629 ResCount += IsAvailableAmt;
634 if (
Bot.isLatencyBound(SU)) {
640 std::stringstream dbgstr;
641 dbgstr <<
"d" << std::setw(3) << SU->
getDepth() <<
"|";
642 dbgs() << dbgstr.str();
647 if (
Bot.ResourceModel->isResourceAvailable(SU,
false)) {
649 ResCount += IsAvailableAmt;
655 unsigned NumNodesBlocking = 0;
661 if (
Top.isLatencyBound(SU))
667 if (
Bot.isLatencyBound(SU))
672 ResCount += (NumNodesBlocking *
ScaleTwo);
675 std::stringstream dbgstr;
676 dbgstr <<
"blk " << std::setw(2) << NumNodesBlocking <<
")|";
677 dbgs() << dbgstr.str();
695 ResCount -= IsAvailableAmt;
716 if (!
SI.getSUnit()->getInstr()->isPseudo() &&
SI.isAssignedRegDep() &&
717 SI.getLatency() == 0 &&
718 Bot.ResourceModel->isInPacket(
SI.getSUnit())) {
732 for (
const auto &PI : SU->
Preds) {
733 if (PI.getLatency() > 0 &&
734 Top.ResourceModel->isInPacket(PI.getSUnit())) {
740 for (
const auto &
SI : SU->
Succs) {
741 if (
SI.getLatency() > 0 &&
742 Bot.ResourceModel->isInPacket(
SI.getSUnit())) {
751 std::stringstream dbgstr;
752 dbgstr <<
"Total " << std::setw(4) << ResCount <<
")";
753 dbgs() << dbgstr.str();
780 TempTracker.getMaxPressureDelta((*I)->getInstr(), RPDelta,
781 DAG->getRegionCriticalPSets(),
782 DAG->getRegPressure().MaxSetPressure);
791 Candidate.
SCost = CurrentCost;
798 if (CurrentCost < 0 && Candidate.
SCost < 0) {
804 Candidate.
SCost = CurrentCost;
811 if (CurrentCost > Candidate.
SCost) {
815 Candidate.
SCost = CurrentCost;
823 if (CurrWeak != CandWeak) {
824 if (CurrWeak < CandWeak) {
828 Candidate.
SCost = CurrentCost;
829 FoundCandidate =
Weak;
835 unsigned CurrSize, CandSize;
837 CurrSize = (*I)->Succs.size();
838 CandSize = Candidate.
SU->
Succs.size();
840 CurrSize = (*I)->Preds.size();
841 CandSize = Candidate.
SU->
Preds.size();
843 if (CurrSize > CandSize) {
847 Candidate.
SCost = CurrentCost;
852 if (CurrSize != CandSize)
865 Candidate.
SCost = CurrentCost;
873 if (FoundCandidate ==
NoCand)
876 return FoundCandidate;
883 if (
SUnit *SU =
Bot.pickOnlyChoice()) {
888 if (
SUnit *SU =
Top.pickOnlyChoice()) {
897 assert(BotResult !=
NoCand &&
"failed to find the first candidate");
915 assert(TopResult !=
NoCand &&
"failed to find the first candidate");
947 if (
DAG->top() ==
DAG->bottom()) {
949 Bot.Available.empty() &&
Bot.Pending.empty() &&
"ReadyQ garbage");
954 SU =
Top.pickOnlyChoice();
959 assert(TopResult !=
NoCand &&
"failed to find the first candidate");
965 SU =
Bot.pickOnlyChoice();
970 assert(BotResult !=
NoCand &&
"failed to find the first candidate");
984 <<
" Scheduling instruction in cycle "
985 << (IsTopNode ?
Top.CurrCycle :
Bot.CurrCycle) <<
" ("
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static const Function * getParent(const Value *V)
const HexagonInstrInfo * TII
This file defines the SmallVector class.
static bool isSingleUnscheduledPred(SUnit *SU, SUnit *SU2)
isSingleUnscheduledPred - If SU2 is the only unscheduled predecessor of SU, return true (we may have ...
static cl::opt< bool > CheckEarlyAvail("check-early-avail", cl::Hidden, cl::init(true))
static cl::opt< bool > IgnoreBBRegPressure("ignore-bb-reg-pressure", cl::Hidden, cl::init(false))
static cl::opt< float > RPThreshold("vliw-misched-reg-pressure", cl::Hidden, cl::init(0.75f), cl::desc("High register pressure threhold."))
static cl::opt< bool > UseNewerCandidate("use-newer-candidate", cl::Hidden, cl::init(true))
static bool isSingleUnscheduledSucc(SUnit *SU, SUnit *SU2)
isSingleUnscheduledSucc - If SU2 is the only unscheduled successor of SU, return true (we may have du...
static cl::opt< unsigned > SchedDebugVerboseLevel("misched-verbose-level", cl::Hidden, cl::init(1))
VLIWMachineScheduler * DAG
void releaseBottomNode(SUnit *SU) override
When all successor dependencies have been resolved, free this node for bottom-up scheduling.
static constexpr unsigned PriorityOne
SUnit * pickNode(bool &IsTopNode) override
Pick the best node to balance the schedule. Implements MachineSchedStrategy.
virtual VLIWResourceModel * createVLIWResourceModel(const TargetSubtargetInfo &STI, const TargetSchedModel *SchedModel) const
int pressureChange(const SUnit *SU, bool isBotUp)
Check if the instruction changes the register pressure of a register in the high pressure set.
SmallVector< bool > HighPressureSets
List of pressure sets that have a high pressure level in the region.
static constexpr unsigned ScaleTwo
CandResult pickNodeFromQueue(VLIWSchedBoundary &Zone, const RegPressureTracker &RPTracker, SchedCandidate &Candidate)
Pick the best candidate from the top queue.
void schedNode(SUnit *SU, bool IsTopNode) override
Update the scheduler's state after scheduling a node.
void readyQueueVerboseDump(const RegPressureTracker &RPTracker, SchedCandidate &Candidate, ReadyQueue &Q)
void releaseTopNode(SUnit *SU) override
When all predecessor dependencies have been resolved, free this node for top-down scheduling.
SUnit * pickNodeBidrectional(bool &IsTopNode)
Pick the best candidate node from either the top or bottom queue.
static constexpr unsigned PriorityTwo
static constexpr unsigned PriorityThree
const TargetSchedModel * SchedModel
void initialize(ScheduleDAGMI *dag) override
Initialize the strategy after building the DAG for a new region.
virtual int SchedulingCost(ReadyQueue &Q, SUnit *SU, SchedCandidate &Candidate, RegPressureDelta &Delta, bool verbose)
Single point to compute overall scheduling cost.
void traceCandidate(const char *Label, const ReadyQueue &Q, SUnit *SU, int Cost, PressureChange P=PressureChange())
CandResult
Represent the type of SchedCandidate found within a single queue.
Itinerary data supplied by a subtarget to be used by a target.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isPseudo(QueryType Type=IgnoreBundle) const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction.
Capture a change in pressure for a single pressure set.
List of PressureChanges in order of increasing, unique PSetID.
Helpers for implementing custom MachineSchedStrategy classes.
LLVM_ABI void dump() const
std::vector< SUnit * >::iterator iterator
StringRef getName() const
Track the current register pressure at some position in the instruction stream, and remember the high...
void getMaxPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Find the pressure set with the most change beyond its pressure limit after traversing this instructio...
unsigned getLatency() const
Returns the latency value for this edge, which roughly means the minimum number of cycles that must e...
bool isAssignedRegDep() const
Tests if this is a Data dependence that is associated with a register.
Scheduling unit. This is a node in the scheduling DAG.
bool isCall
Is a function call.
unsigned TopReadyCycle
Cycle relative to start when node is ready.
unsigned NodeNum
Entry # of node in the node vector.
unsigned getHeight() const
Returns the height of this node, which is the length of the maximum path down to any node which has n...
bool isScheduleHigh
True if preferable to schedule high.
unsigned getDepth() const
Returns the depth of this node, which is the length of the maximum path up to any node which has no p...
bool isScheduled
True once scheduled.
unsigned BotReadyCycle
Cycle relative to end when node is ready.
SmallVector< SDep, 4 > Succs
All sunit successors.
bool isBottomReady() const
SmallVector< SDep, 4 > Preds
All sunit predecessors.
SmallVectorImpl< SDep >::iterator succ_iterator
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
MachineBasicBlock * BB
The block in which to insert instructions.
ScheduleDAGTopologicalSort Topo
Topo - A topological ordering for SUnits which permits fast IsReachable and similar queries.
MachineBasicBlock::iterator begin() const
Returns an iterator to the top of the current scheduling region.
const MachineLoopInfo * MLI
void scheduleMI(SUnit *SU, bool IsTopNode)
Move an instruction and update register pressure.
void initQueues(ArrayRef< SUnit * > TopRoots, ArrayRef< SUnit * > BotRoots)
Release ExitSU predecessors and setup scheduler queues.
void buildDAGWithRegPressure()
Call ScheduleDAGInstrs::buildSchedGraph with register pressure tracking enabled.
void dump() const override
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
void dumpSchedule() const
dump the scheduled Sequence.
std::unique_ptr< MachineSchedStrategy > SchedImpl
void postProcessDAG()
Apply each ScheduleDAGMutation step in order.
void findRootsAndBiasEdges(SmallVectorImpl< SUnit * > &TopRoots, SmallVectorImpl< SUnit * > &BotRoots)
MachineBasicBlock::iterator CurrentBottom
The bottom of the unscheduled zone.
void viewGraph() override
Out-of-line implementation with no arguments is handy for gdb.
void updateQueues(SUnit *SU, bool IsTopNode)
Update scheduler DAG and queues after scheduling an instruction.
void placeDebugValues()
Reinsert debug_values recorded in ScheduleDAGInstrs::DbgValues.
MachineBasicBlock::iterator CurrentTop
The top of the unscheduled zone.
std::vector< SUnit > SUnits
The scheduling units.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetInstrInfo - Interface to description of machine instruction set.
virtual DFAPacketizer * CreateTargetScheduleState(const TargetSubtargetInfo &) const
Create machine specific model for scheduling.
Provide an instruction scheduling machine model to CodeGen passes.
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetInstrInfo * getInstrInfo() const
Extend the standard ScheduleDAGMILive to provide more context and override the top-level schedule() d...
void schedule() override
Schedule - This is called back from ScheduleDAGInstrs::Run() when it's time to do some work.
unsigned TotalPackets
Total packets created.
virtual ~VLIWResourceModel()
virtual bool hasDependence(const SUnit *SUd, const SUnit *SUu)
Return true if there is a dependence between SUd and SUu.
virtual DFAPacketizer * createPacketizer(const TargetSubtargetInfo &STI) const
virtual bool reserveResources(SUnit *SU, bool IsTop)
Keep track of available resources.
DFAPacketizer * ResourcesModel
ResourcesModel - Represents VLIW state.
SmallVector< SUnit * > Packet
Local packet/bundle model.
const TargetSchedModel * SchedModel
VLIWResourceModel(const TargetSubtargetInfo &STI, const TargetSchedModel *SM)
virtual bool isResourceAvailable(SUnit *SU, bool IsTop)
Check if scheduling of this SU is possible in the current packet.
const TargetInstrInfo * TII
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
LLVM_ABI unsigned getWeakLeft(const SUnit *SU, bool isTop)
cl::opt< bool > ViewMISchedDAGs
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI cl::opt< MISched::Direction > PreRADirection
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Store the state used by ConvergingVLIWScheduler heuristics, required for the lifetime of one invocati...
Each Scheduling boundary is associated with ready queues.
const TargetSchedModel * SchedModel
bool isLatencyBound(SUnit *SU)
void releaseNode(SUnit *SU, unsigned ReadyCycle)
void removeReady(SUnit *SU)
Remove SU from the ready set for this boundary.
ScheduleHazardRecognizer * HazardRec
void bumpNode(SUnit *SU)
Move the boundary of scheduled code by one SUnit.
unsigned MinReadyCycle
MinReadyCycle - Cycle of the soonest available instruction.
VLIWResourceModel * ResourceModel
void releasePending()
Release pending ready nodes in to the available queue.
SUnit * pickOnlyChoice()
If this queue only has one ready candidate, return it.
void bumpCycle()
Move the boundary of scheduled code by one cycle.
bool checkHazard(SUnit *SU)
Does this SU have a hazard within the current instruction group.
Store the effects of a change in pressure on things that MI scheduler cares about.
PressureChange CriticalMax
PressureChange CurrentMax