38 #define DEBUG_TYPE "pre-RA-sched"
40 STATISTIC(NumBacktracks,
"Number of times scheduler backtracked");
41 STATISTIC(NumUnfolds,
"Number of nodes unfolded");
42 STATISTIC(NumDups,
"Number of duplicated nodes");
43 STATISTIC(NumPRCopies,
"Number of physical register copies");
47 "Bottom-up register reduction list scheduling",
51 "Similar to list-burr but schedules in source "
52 "order when possible",
57 "Bottom-up register pressure aware list scheduling "
58 "which tries to balance latency and register pressure",
63 "Bottom-up register pressure aware list scheduling "
64 "which tries to balance ILP and register pressure",
69 cl::desc(
"Disable cycle-level precision during preRA scheduling"));
75 cl::desc(
"Disable regpressure priority in sched=list-ilp"));
78 cl::desc(
"Disable live use priority in sched=list-ilp"));
81 cl::desc(
"Disable virtual register cycle interference checks"));
84 cl::desc(
"Disable physreg def-use affinity"));
87 cl::desc(
"Disable no-stall priority in sched=list-ilp"));
90 cl::desc(
"Disable critical path priority in sched=list-ilp"));
93 cl::desc(
"Disable scheduled-height priority in sched=list-ilp"));
96 cl::desc(
"Disable scheduler's two-address hack"));
100 cl::desc(
"Number of instructions to allow ahead of the critical path "
101 "in sched=list-ilp"));
105 cl::desc(
"Average inst/cycle whan no target itinerary exists."));
125 std::vector<SUnit*> PendingQueue;
134 unsigned MinAvailableCycle;
143 unsigned NumLiveRegs;
144 std::unique_ptr<SUnit*[]> LiveRegDefs;
145 std::unique_ptr<SUnit*[]> LiveRegGens;
166 NeedLatency(needlatency), AvailableQueue(availqueue), CurCycle(0),
167 Topo(SUnits, nullptr) {
176 ~ScheduleDAGRRList()
override {
178 delete AvailableQueue;
181 void Schedule()
override;
186 bool IsReachable(
const SUnit *SU,
const SUnit *TargetSU) {
187 return Topo.IsReachable(SU, TargetSU);
192 bool WillCreateCycle(
SUnit *SU,
SUnit *TargetSU) {
193 return Topo.WillCreateCycle(SU, TargetSU);
207 void RemovePred(
SUnit *SU,
const SDep &D) {
213 bool isReady(
SUnit *SU) {
215 AvailableQueue->isReady(SU);
218 void ReleasePred(
SUnit *SU,
const SDep *PredEdge);
219 void ReleasePredecessors(
SUnit *SU);
220 void ReleasePending();
221 void AdvanceToCycle(
unsigned NextCycle);
222 void AdvancePastStalls(
SUnit *SU);
223 void EmitNode(
SUnit *SU);
224 void ScheduleNodeBottomUp(
SUnit*);
225 void CapturePred(
SDep *PredEdge);
226 void UnscheduleNodeBottomUp(
SUnit*);
227 void RestoreHazardCheckerBottomUp();
231 void InsertCopiesAndMoveSuccs(
SUnit*,
unsigned,
237 void releaseInterferences(
unsigned Reg = 0);
239 SUnit *PickNodeToScheduleBottomUp();
240 void ListScheduleBottomUp();
245 unsigned NumSUnits = SUnits.size();
246 SUnit *NewNode = newSUnit(N);
248 if (NewNode->
NodeNum >= NumSUnits)
249 Topo.InitDAGTopologicalSorting();
256 unsigned NumSUnits = SUnits.size();
257 SUnit *NewNode = Clone(N);
259 if (NewNode->
NodeNum >= NumSUnits)
260 Topo.InitDAGTopologicalSorting();
266 bool forceUnitLatencies()
const override {
280 unsigned &RegClass,
unsigned &Cost,
293 RegClass = RC->
getID();
299 if (Opcode == TargetOpcode::REG_SEQUENCE) {
300 unsigned DstRCIdx = cast<ConstantSDNode>(Node->
getOperand(0))->getZExtValue();
302 RegClass = RC->
getID();
307 unsigned Idx = RegDefPos.
GetIdx();
310 RegClass = RC->
getID();
321 void ScheduleDAGRRList::Schedule() {
323 <<
"********** List Scheduling BB#" << BB->getNumber()
324 <<
" '" << BB->getName() <<
"' **********\n");
332 LiveRegDefs.reset(
new SUnit*[TRI->getNumRegs() + 1]());
333 LiveRegGens.reset(
new SUnit*[TRI->getNumRegs() + 1]());
334 CallSeqEndForStart.clear();
335 assert(Interferences.empty() && LRegsMap.empty() &&
"stale Interferences");
338 BuildSchedGraph(
nullptr);
342 Topo.InitDAGTopologicalSorting();
344 AvailableQueue->initNodes(SUnits);
349 ListScheduleBottomUp();
351 AvailableQueue->releaseState();
354 dbgs() <<
"*** Final schedule ***\n";
366 void ScheduleDAGRRList::ReleasePred(
SUnit *SU,
const SDep *PredEdge) {
371 dbgs() <<
"*** Scheduling failed! ***\n";
373 dbgs() <<
" has been released too many times!\n";
379 if (!forceUnitLatencies()) {
391 if (Height < MinAvailableCycle)
392 MinAvailableCycle = Height;
394 if (isReady(PredSU)) {
395 AvailableQueue->push(PredSU);
401 PendingQueue.push_back(PredSU);
438 goto found_chain_operand;
441 found_chain_operand:;
465 unsigned BestMaxNest = MaxNest;
467 unsigned MyNestLevel = NestLevel;
468 unsigned MyMaxNest = MaxNest;
470 MyNestLevel, MyMaxNest,
TII))
471 if (!Best || (MyMaxNest > BestMaxNest)) {
473 BestMaxNest = MyMaxNest;
477 MaxNest = BestMaxNest;
484 MaxNest =
std::max(MaxNest, NestLevel);
496 goto found_chain_operand;
499 found_chain_operand:;
522 void ScheduleDAGRRList::ReleasePredecessors(
SUnit *SU) {
525 ReleasePred(SU, &Pred);
531 SUnit *RegDef = LiveRegDefs[Pred.
getReg()]; (void)RegDef;
533 "interference on register dependence");
535 if (!LiveRegGens[Pred.
getReg()]) {
537 LiveRegGens[Pred.
getReg()] = SU;
545 unsigned CallResource = TRI->getNumRegs();
546 if (!LiveRegDefs[CallResource])
548 if (Node->isMachineOpcode() &&
549 Node->getMachineOpcode() ==
TII->getCallFrameDestroyOpcode()) {
550 unsigned NestLevel = 0;
551 unsigned MaxNest = 0;
555 CallSeqEndForStart[
Def] = SU;
558 LiveRegDefs[CallResource] =
Def;
559 LiveRegGens[CallResource] = SU;
566 void ScheduleDAGRRList::ReleasePending() {
568 assert(PendingQueue.empty() &&
"pending instrs not allowed in this mode");
573 if (AvailableQueue->empty())
574 MinAvailableCycle = UINT_MAX;
578 for (
unsigned i = 0, e = PendingQueue.size(); i != e; ++i) {
579 unsigned ReadyCycle = PendingQueue[i]->getHeight();
580 if (ReadyCycle < MinAvailableCycle)
581 MinAvailableCycle = ReadyCycle;
584 if (!isReady(PendingQueue[i]))
586 AvailableQueue->push(PendingQueue[i]);
588 PendingQueue[i]->isPending =
false;
589 PendingQueue[i] = PendingQueue.back();
590 PendingQueue.pop_back();
596 void ScheduleDAGRRList::AdvanceToCycle(
unsigned NextCycle) {
597 if (NextCycle <= CurCycle)
601 AvailableQueue->setCurCycle(NextCycle);
602 if (!HazardRec->isEnabled()) {
604 CurCycle = NextCycle;
607 for (; CurCycle != NextCycle; ++CurCycle) {
608 HazardRec->RecedeCycle();
618 void ScheduleDAGRRList::AdvancePastStalls(
SUnit *SU) {
635 AdvanceToCycle(ReadyCycle);
648 HazardRec->getHazardType(SU, -Stalls);
655 AdvanceToCycle(CurCycle + Stalls);
660 void ScheduleDAGRRList::EmitNode(
SUnit *SU) {
661 if (!HazardRec->isEnabled())
671 "This target-independent node should not be scheduled.");
694 HazardRec->EmitInstruction(SU);
702 void ScheduleDAGRRList::ScheduleNodeBottomUp(
SUnit *SU) {
703 DEBUG(
dbgs() <<
"\n*** Scheduling [" << CurCycle <<
"]: ");
707 if (CurCycle < SU->getHeight())
709 <<
"] pipeline stall!\n");
723 AvailableQueue->scheduledNode(SU);
728 if (!HazardRec->isEnabled() &&
AvgIPC < 2)
729 AdvanceToCycle(CurCycle + 1);
733 ReleasePredecessors(SU);
739 assert(NumLiveRegs > 0 &&
"NumLiveRegs is already zero!");
741 LiveRegDefs[Succ.
getReg()] =
nullptr;
742 LiveRegGens[Succ.
getReg()] =
nullptr;
743 releaseInterferences(Succ.
getReg());
748 unsigned CallResource = TRI->getNumRegs();
749 if (LiveRegDefs[CallResource] == SU)
752 if (SUNode->isMachineOpcode() &&
753 SUNode->getMachineOpcode() ==
TII->getCallFrameSetupOpcode()) {
754 assert(NumLiveRegs > 0 &&
"NumLiveRegs is already zero!");
756 LiveRegDefs[CallResource] =
nullptr;
757 LiveRegGens[CallResource] =
nullptr;
758 releaseInterferences(CallResource);
774 if (HazardRec->isEnabled() ||
AvgIPC > 1) {
777 if ((HazardRec->isEnabled() && HazardRec->atIssueLimit())
778 || (!HazardRec->isEnabled() && IssueCount ==
AvgIPC))
779 AdvanceToCycle(CurCycle + 1);
786 void ScheduleDAGRRList::CapturePred(
SDep *PredEdge) {
791 AvailableQueue->remove(PredSU);
800 void ScheduleDAGRRList::UnscheduleNodeBottomUp(
SUnit *SU) {
807 assert(NumLiveRegs > 0 &&
"NumLiveRegs is already zero!");
809 "Physical register dependency violated?");
811 LiveRegDefs[Pred.
getReg()] =
nullptr;
812 LiveRegGens[Pred.
getReg()] =
nullptr;
813 releaseInterferences(Pred.
getReg());
819 unsigned CallResource = TRI->getNumRegs();
822 if (SUNode->isMachineOpcode() &&
823 SUNode->getMachineOpcode() ==
TII->getCallFrameSetupOpcode()) {
825 LiveRegDefs[CallResource] = SU;
826 LiveRegGens[CallResource] = CallSeqEndForStart[SU];
832 if (LiveRegGens[CallResource] == SU)
835 if (SUNode->isMachineOpcode() &&
836 SUNode->getMachineOpcode() ==
TII->getCallFrameDestroyOpcode()) {
837 assert(NumLiveRegs > 0 &&
"NumLiveRegs is already zero!");
839 LiveRegDefs[CallResource] =
nullptr;
840 LiveRegGens[CallResource] =
nullptr;
841 releaseInterferences(CallResource);
845 for (
auto &Succ : SU->
Succs) {
848 if (!LiveRegDefs[
Reg])
852 LiveRegDefs[
Reg] = SU;
856 if (!LiveRegGens[Reg]) {
859 for (
auto &Succ2 : SU->
Succs) {
860 if (Succ2.isAssignedRegDep() && Succ2.getReg() == Reg &&
861 Succ2.getSUnit()->getHeight() < LiveRegGens[
Reg]->getHeight())
862 LiveRegGens[Reg] = Succ2.getSUnit();
876 PendingQueue.push_back(SU);
879 AvailableQueue->push(SU);
881 AvailableQueue->unscheduledNode(SU);
886 void ScheduleDAGRRList::RestoreHazardCheckerBottomUp() {
890 HazardRec->getMaxLookAhead());
894 std::vector<SUnit*>::const_iterator
I = (
Sequence.end() - LookAhead);
895 unsigned HazardCycle = (*I)->getHeight();
898 for (; SU->
getHeight() > HazardCycle; ++HazardCycle) {
899 HazardRec->RecedeCycle();
907 void ScheduleDAGRRList::BacktrackBottomUp(
SUnit *SU,
SUnit *BtSU) {
913 UnscheduleNodeBottomUp(OldSU);
914 AvailableQueue->setCurCycle(CurCycle);
922 RestoreHazardCheckerBottomUp();
932 if (SUNode->isOperandOf(N))
939 SUnit *ScheduleDAGRRList::TryUnfoldSU(
SUnit *SU) {
943 if (!
TII->unfoldMemoryOperand(*DAG, N, NewNodes))
948 if (NewNodes.
size() == 3)
951 assert(NewNodes.
size() == 2 &&
"Expected a load folding node!");
954 SDNode *LoadNode = NewNodes[0];
955 unsigned NumVals = N->getNumValues();
961 bool isNewLoad =
true;
971 LoadSU = CreateNewSUnit(LoadNode);
974 InitNumRegDefsLeft(LoadSU);
975 computeLatency(LoadSU);
981 for (
unsigned i = 0; i != NumVals; ++i)
983 DAG->ReplaceAllUsesOfValueWith(
SDValue(SU->
getNode(), OldNumVals - 1),
986 SUnit *NewSU = CreateNewSUnit(N);
987 assert(N->getNodeId() == -1 &&
"Node already inserted!");
1000 InitNumRegDefsLeft(NewSU);
1001 computeLatency(NewSU);
1025 for (
const SDep &Pred : ChainPreds) {
1026 RemovePred(SU, Pred);
1028 AddPred(LoadSU, Pred);
1030 for (
const SDep &Pred : LoadPreds) {
1031 RemovePred(SU, Pred);
1033 AddPred(LoadSU, Pred);
1035 for (
const SDep &Pred : NodePreds) {
1036 RemovePred(SU, Pred);
1037 AddPred(NewSU, Pred);
1039 for (
SDep D : NodeSuccs) {
1042 RemovePred(SuccDep, D);
1044 AddPred(SuccDep, D);
1046 if (AvailableQueue->tracksRegPressure() && SuccDep->
isScheduled &&
1050 for (
SDep D : ChainSuccs) {
1053 RemovePred(SuccDep, D);
1056 AddPred(SuccDep, D);
1067 AvailableQueue->addNode(LoadSU);
1068 AvailableQueue->addNode(NewSU);
1080 SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(
SUnit *SU) {
1089 bool TryUnfold =
false;
1090 for (
unsigned i = 0, e = N->
getNumValues(); i != e; ++i) {
1098 MVT VT =
Op.getNode()->getSimpleValueType(
Op.getResNo());
1105 SUnit *UnfoldSU = TryUnfoldSU(SU);
1116 NewSU = CreateClone(SU);
1121 AddPred(NewSU, Pred);
1135 DelDeps.
push_back(std::make_pair(SuccSU, D));
1138 for (
auto &DelDep : DelDeps)
1139 RemovePred(DelDep.first, DelDep.second);
1141 AvailableQueue->updateNode(SU);
1142 AvailableQueue->addNode(NewSU);
1150 void ScheduleDAGRRList::InsertCopiesAndMoveSuccs(
SUnit *SU,
unsigned Reg,
1154 SUnit *CopyFromSU = CreateNewSUnit(
nullptr);
1158 SUnit *CopyToSU = CreateNewSUnit(
nullptr);
1173 DelDeps.
push_back(std::make_pair(SuccSU, Succ));
1182 for (
auto &DelDep : DelDeps)
1183 RemovePred(DelDep.first, DelDep.second);
1186 FromDep.setLatency(SU->
Latency);
1187 AddPred(CopyFromSU, FromDep);
1189 ToDep.setLatency(CopyFromSU->
Latency);
1190 AddPred(CopyToSU, ToDep);
1192 AvailableQueue->updateNode(SU);
1193 AvailableQueue->addNode(CopyFromSU);
1194 AvailableQueue->addNode(CopyToSU);
1226 SUnit **LiveRegDefs,
1233 if (!LiveRegDefs[*AliasI])
continue;
1236 if (LiveRegDefs[*AliasI] == SU)
continue;
1239 if (RegAdded.
insert(*AliasI).second) {
1252 for (
unsigned i = 1, e = LiveRegDefs.
size()-1; i != e; ++i) {
1253 if (!LiveRegDefs[i])
continue;
1254 if (LiveRegDefs[i] == SU)
continue;
1256 if (RegAdded.
insert(i).second)
1264 if (
const auto *RegOp = dyn_cast<RegisterMaskSDNode>(
Op.getNode()))
1265 return RegOp->getRegMask();
1273 bool ScheduleDAGRRList::
1275 if (NumLiveRegs == 0)
1286 RegAdded, LRegs, TRI);
1292 unsigned NumOps = Node->getNumOperands();
1293 if (Node->getOperand(NumOps-1).getValueType() ==
MVT::Glue)
1298 cast<ConstantSDNode>(Node->getOperand(i))->getZExtValue();
1306 for (; NumVals; --NumVals, ++i) {
1307 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->
getReg();
1317 if (!Node->isMachineOpcode())
1322 if ((Node->getMachineOpcode() ==
TII->getCallFrameDestroyOpcode()) ||
1323 (Node->getMachineOpcode() ==
TII->getCallFrameSetupOpcode())) {
1325 unsigned CallResource = TRI->getNumRegs();
1326 if (LiveRegDefs[CallResource]) {
1327 SDNode *Gen = LiveRegGens[CallResource]->getNode();
1331 RegAdded.
insert(CallResource).second)
1346 for (
unsigned i = 0; i < MCID.
getNumDefs(); ++i)
1359 return !LRegs.
empty();
1362 void ScheduleDAGRRList::releaseInterferences(
unsigned Reg) {
1364 for (
unsigned i = Interferences.size(); i > 0; --i) {
1365 SUnit *SU = Interferences[i-1];
1366 LRegsMapT::iterator LRegsPos = LRegsMap.find(SU);
1378 AvailableQueue->push(SU);
1380 if (i < Interferences.size())
1381 Interferences[i-1] = Interferences.back();
1382 Interferences.pop_back();
1383 LRegsMap.erase(LRegsPos);
1391 SUnit *ScheduleDAGRRList::PickNodeToScheduleBottomUp() {
1392 SUnit *CurSU = AvailableQueue->empty() ?
nullptr : AvailableQueue->pop();
1395 if (!DelayForLiveRegsBottomUp(CurSU, LRegs))
1398 (LRegs[0] == TRI->getNumRegs() ?
"CallResource"
1399 : TRI->getName(LRegs[0]))
1400 <<
" SU #" << CurSU->
NodeNum <<
'\n');
1401 std::pair<LRegsMapT::iterator, bool> LRegsPair =
1402 LRegsMap.insert(std::make_pair(CurSU, LRegs));
1403 if (LRegsPair.second) {
1405 Interferences.push_back(CurSU);
1410 LRegsPair.first->second = LRegs;
1412 CurSU = AvailableQueue->pop();
1420 for (
SUnit *TrySU : Interferences) {
1425 SUnit *BtSU =
nullptr;
1426 unsigned LiveCycle = UINT_MAX;
1427 for (
unsigned Reg : LRegs) {
1428 if (LiveRegGens[Reg]->getHeight() < LiveCycle) {
1429 BtSU = LiveRegGens[
Reg];
1433 if (!WillCreateCycle(TrySU, BtSU)) {
1435 BacktrackBottomUp(TrySU, BtSU);
1442 AvailableQueue->remove(BtSU);
1445 << TrySU->NodeNum <<
")\n");
1450 if (!TrySU->isAvailable || !TrySU->NodeQueueId)
1451 CurSU = AvailableQueue->pop();
1454 AvailableQueue->remove(TrySU);
1468 SUnit *TrySU = Interferences[0];
1470 assert(LRegs.
size() == 1 &&
"Can't handle this yet!");
1471 unsigned Reg = LRegs[0];
1475 TRI->getMinimalPhysRegClass(Reg, VT);
1485 SUnit *NewDef =
nullptr;
1487 NewDef = CopyAndMoveSuccessors(LRDef);
1488 if (!DestRC && !NewDef)
1494 InsertCopiesAndMoveSuccs(LRDef, Reg, DestRC, RC, Copies);
1498 NewDef = Copies.
back();
1502 <<
" to SU #" << TrySU->
NodeNum <<
"\n");
1503 LiveRegDefs[
Reg] = NewDef;
1508 assert(CurSU &&
"Unable to resolve live physical register dependencies!");
1514 void ScheduleDAGRRList::ListScheduleBottomUp() {
1516 ReleasePredecessors(&ExitSU);
1519 if (!SUnits.empty()) {
1520 SUnit *RootSU = &SUnits[DAG->getRoot().getNode()->getNodeId()];
1521 assert(RootSU->
Succs.empty() &&
"Graph root shouldn't have successors!");
1523 AvailableQueue->push(RootSU);
1529 while (!AvailableQueue->empty() || !Interferences.empty()) {
1530 DEBUG(
dbgs() <<
"\nExamining Available:\n";
1531 AvailableQueue->dump(
this));
1535 SUnit *SU = PickNodeToScheduleBottomUp();
1537 AdvancePastStalls(SU);
1539 ScheduleNodeBottomUp(SU);
1541 while (AvailableQueue->empty() && !PendingQueue.empty()) {
1543 assert(MinAvailableCycle < UINT_MAX &&
"MinAvailableCycle uninitialized");
1544 AdvanceToCycle(
std::max(CurCycle + 1, MinAvailableCycle));
1552 VerifyScheduledSequence(
true);
1564 class RegReductionPQBase;
1566 struct queue_sort :
public std::binary_function<SUnit*, SUnit*, bool> {
1567 bool isReady(
SUnit* SU,
unsigned CurCycle)
const {
return true; }
1572 struct reverse_sort :
public queue_sort {
1574 reverse_sort(SF &sf) : SortFunc(sf) {}
1576 bool operator()(
SUnit* left,
SUnit* right)
const {
1579 return SortFunc(right, left);
1586 struct bu_ls_rr_sort :
public queue_sort {
1589 HasReadyFilter =
false
1592 RegReductionPQBase *SPQ;
1593 bu_ls_rr_sort(RegReductionPQBase *spq) : SPQ(spq) {}
1595 bool operator()(
SUnit* left,
SUnit* right)
const;
1599 struct src_ls_rr_sort :
public queue_sort {
1602 HasReadyFilter =
false
1605 RegReductionPQBase *SPQ;
1606 src_ls_rr_sort(RegReductionPQBase *spq)
1609 bool operator()(
SUnit* left,
SUnit* right)
const;
1613 struct hybrid_ls_rr_sort :
public queue_sort {
1616 HasReadyFilter =
false
1619 RegReductionPQBase *SPQ;
1620 hybrid_ls_rr_sort(RegReductionPQBase *spq)
1623 bool isReady(
SUnit *SU,
unsigned CurCycle)
const;
1625 bool operator()(
SUnit* left,
SUnit* right)
const;
1630 struct ilp_ls_rr_sort :
public queue_sort {
1633 HasReadyFilter =
false
1636 RegReductionPQBase *SPQ;
1637 ilp_ls_rr_sort(RegReductionPQBase *spq)
1640 bool isReady(
SUnit *SU,
unsigned CurCycle)
const;
1642 bool operator()(
SUnit* left,
SUnit* right)
const;
1647 std::vector<SUnit*>
Queue;
1648 unsigned CurQueueId;
1649 bool TracksRegPressure;
1653 std::vector<SUnit> *SUnits;
1659 ScheduleDAGRRList *scheduleDAG;
1662 std::vector<unsigned> SethiUllmanNumbers;
1670 std::vector<unsigned> RegLimit;
1674 bool hasReadyFilter,
1681 CurQueueId(0), TracksRegPressure(tracksrp), SrcOrder(srcorder),
1682 MF(mf),
TII(tii), TRI(tri), TLI(tli), scheduleDAG(nullptr) {
1683 if (TracksRegPressure) {
1684 unsigned NumRC = TRI->getNumRegClasses();
1685 RegLimit.resize(NumRC);
1687 std::fill(RegLimit.begin(), RegLimit.end(), 0);
1694 void setScheduleDAG(ScheduleDAGRRList *scheduleDag) {
1695 scheduleDAG = scheduleDag;
1699 return scheduleDAG->getHazardRec();
1702 void initNodes(std::vector<SUnit> &sunits)
override;
1704 void addNode(
const SUnit *SU)
override;
1706 void updateNode(
const SUnit *SU)
override;
1708 void releaseState()
override {
1710 SethiUllmanNumbers.clear();
1714 unsigned getNodePriority(
const SUnit *SU)
const;
1716 unsigned getNodeOrdering(
const SUnit *SU)
const {
1722 bool empty()
const override {
return Queue.empty(); }
1724 void push(
SUnit *U)
override {
1730 void remove(
SUnit *SU)
override {
1733 std::vector<SUnit *>::iterator I =
find(Queue, SU);
1734 if (I != std::prev(
Queue.end()))
1740 bool tracksRegPressure()
const override {
return TracksRegPressure; }
1742 void dumpRegPressure()
const;
1744 bool HighRegPressure(
const SUnit *SU)
const;
1746 bool MayReduceRegPressure(
SUnit *SU)
const;
1748 int RegPressureDiff(
SUnit *SU,
unsigned &LiveUses)
const;
1750 void scheduledNode(
SUnit *SU)
override;
1752 void unscheduledNode(
SUnit *SU)
override;
1756 void AddPseudoTwoAddrDeps();
1757 void PrescheduleNodesWithMultipleUses();
1758 void CalculateSethiUllmanNumbers();
1762 static SUnit *popFromQueueImpl(std::vector<SUnit*> &Q, SF &Picker) {
1763 std::vector<SUnit *>::iterator Best = Q.begin();
1764 for (
auto I = std::next(Q.begin()),
E = Q.end(); I !=
E; ++
I)
1765 if (Picker(*Best, *I))
1768 if (Best != std::prev(Q.end()))
1775 SUnit *popFromQueue(std::vector<SUnit*> &Q, SF &Picker,
ScheduleDAG *DAG) {
1778 reverse_sort<SF> RPicker(Picker);
1779 return popFromQueueImpl(Q, RPicker);
1783 return popFromQueueImpl(Q, Picker);
1787 class RegReductionPriorityQueue :
public RegReductionPQBase {
1797 : RegReductionPQBase(mf, SF::HasReadyFilter, tracksrp, srcorder,
1801 bool isBottomUp()
const override {
return SF::IsBottomUp; }
1803 bool isReady(
SUnit *U)
const override {
1804 return Picker.HasReadyFilter && Picker.isReady(U, getCurCycle());
1807 SUnit *pop()
override {
1808 if (
Queue.empty())
return nullptr;
1810 SUnit *V = popFromQueue(Queue, Picker, scheduleDAG);
1815 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1818 std::vector<SUnit*> DumpQueue =
Queue;
1819 SF DumpPicker = Picker;
1820 while (!DumpQueue.empty()) {
1821 SUnit *SU = popFromQueue(DumpQueue, DumpPicker, scheduleDAG);
1829 typedef RegReductionPriorityQueue<bu_ls_rr_sort>
1830 BURegReductionPriorityQueue;
1832 typedef RegReductionPriorityQueue<src_ls_rr_sort>
1833 SrcRegReductionPriorityQueue;
1835 typedef RegReductionPriorityQueue<hybrid_ls_rr_sort>
1836 HybridBURRPriorityQueue;
1838 typedef RegReductionPriorityQueue<ilp_ls_rr_sort>
1839 ILPBURRPriorityQueue;
1855 if (LSchedLow != RSchedLow)
1856 return LSchedLow < RSchedLow ? 1 : -1;
1864 if (SUNumbers[SU->
NodeNum] != 0)
1865 return SUNumbers[SU->
NodeNum];
1869 WorkState(
const SUnit *SU) : SU(SU) {}
1871 unsigned PredsProcessed = 0;
1876 while (!WorkList.
empty()) {
1877 auto &Temp = WorkList.
back();
1878 auto *TempSU = Temp.SU;
1879 bool AllPredsKnown =
true;
1881 for (
unsigned P = Temp.PredsProcessed; P < TempSU->Preds.size(); ++
P) {
1882 auto &Pred = TempSU->Preds[
P];
1883 if (Pred.
isCtrl())
continue;
1885 if (SUNumbers[PredSU->
NodeNum] == 0) {
1888 for (
auto It : WorkList)
1889 assert(It.SU != PredSU &&
"Trying to push an element twice?");
1892 Temp.PredsProcessed =
P + 1;
1893 WorkList.push_back(PredSU);
1894 AllPredsKnown =
false;
1903 unsigned SethiUllmanNumber = 0;
1905 for (
const SDep &Pred : TempSU->Preds) {
1906 if (Pred.
isCtrl())
continue;
1908 unsigned PredSethiUllman = SUNumbers[PredSU->
NodeNum];
1909 assert(PredSethiUllman > 0 &&
"We should have evaluated this pred!");
1910 if (PredSethiUllman > SethiUllmanNumber) {
1911 SethiUllmanNumber = PredSethiUllman;
1913 }
else if (PredSethiUllman == SethiUllmanNumber)
1917 SethiUllmanNumber += Extra;
1918 if (SethiUllmanNumber == 0)
1919 SethiUllmanNumber = 1;
1920 SUNumbers[TempSU->NodeNum] = SethiUllmanNumber;
1924 assert(SUNumbers[SU->
NodeNum] > 0 &&
"SethiUllman should never be zero!");
1925 return SUNumbers[SU->
NodeNum];
1930 void RegReductionPQBase::CalculateSethiUllmanNumbers() {
1931 SethiUllmanNumbers.assign(SUnits->size(), 0);
1933 for (
const SUnit &SU : *SUnits)
1937 void RegReductionPQBase::addNode(
const SUnit *SU) {
1938 unsigned SUSize = SethiUllmanNumbers.size();
1939 if (SUnits->size() > SUSize)
1940 SethiUllmanNumbers.resize(SUSize*2, 0);
1944 void RegReductionPQBase::updateNode(
const SUnit *SU) {
1945 SethiUllmanNumbers[SU->
NodeNum] = 0;
1951 unsigned RegReductionPQBase::getNodePriority(
const SUnit *SU)
const {
1958 if (Opc == TargetOpcode::EXTRACT_SUBREG ||
1959 Opc == TargetOpcode::SUBREG_TO_REG ||
1960 Opc == TargetOpcode::INSERT_SUBREG)
1976 return SethiUllmanNumbers[SU->
NodeNum];
1978 unsigned Priority = SethiUllmanNumbers[SU->
NodeNum];
1982 return (NP > 0) ? NP : 0;
1992 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1995 unsigned Id = RC->getID();
1998 DEBUG(
dbgs() << TRI->getRegClassName(RC) <<
": " << RP <<
" / "
1999 << RegLimit[
Id] <<
'\n');
2004 bool RegReductionPQBase::HighRegPressure(
const SUnit *SU)
const {
2018 RegDefPos.
IsValid(); RegDefPos.Advance()) {
2019 unsigned RCId, Cost;
2029 bool RegReductionPQBase::MayReduceRegPressure(
SUnit *SU)
const {
2036 for (
unsigned i = 0; i != NumDefs; ++i) {
2040 unsigned RCId = TLI->getRepRegClassFor(VT)->getID();
2054 int RegReductionPQBase::RegPressureDiff(
SUnit *SU,
unsigned &LiveUses)
const {
2069 RegDefPos.
IsValid(); RegDefPos.Advance()) {
2070 MVT VT = RegDefPos.GetValue();
2071 unsigned RCId = TLI->getRepRegClassFor(VT)->getID();
2082 for (
unsigned i = 0; i != NumDefs; ++i) {
2086 unsigned RCId = TLI->getRepRegClassFor(VT)->getID();
2093 void RegReductionPQBase::scheduledNode(
SUnit *SU) {
2094 if (!TracksRegPressure)
2127 RegDefPos.
IsValid(); RegDefPos.Advance(), --SkipRegDefs) {
2131 unsigned RCId, Cost;
2143 RegDefPos.
IsValid(); RegDefPos.Advance(), --SkipRegDefs) {
2144 if (SkipRegDefs > 0)
2146 unsigned RCId, Cost;
2158 DEBUG(dumpRegPressure());
2161 void RegReductionPQBase::unscheduledNode(
SUnit *SU) {
2162 if (!TracksRegPressure)
2173 if (Opc == TargetOpcode::EXTRACT_SUBREG ||
2174 Opc == TargetOpcode::INSERT_SUBREG ||
2175 Opc == TargetOpcode::SUBREG_TO_REG ||
2176 Opc == TargetOpcode::REG_SEQUENCE ||
2177 Opc == TargetOpcode::IMPLICIT_DEF)
2193 unsigned RCId = TLI->getRepRegClassFor(VT)->getID();
2194 RegPressure[RCId] += TLI->getRepRegClassCostFor(VT);
2199 if (POpc == TargetOpcode::IMPLICIT_DEF)
2201 if (POpc == TargetOpcode::EXTRACT_SUBREG ||
2202 POpc == TargetOpcode::INSERT_SUBREG ||
2203 POpc == TargetOpcode::SUBREG_TO_REG) {
2205 unsigned RCId = TLI->getRepRegClassFor(VT)->getID();
2206 RegPressure[RCId] += TLI->getRepRegClassCostFor(VT);
2210 for (
unsigned i = 0; i != NumDefs; ++i) {
2214 unsigned RCId = TLI->getRepRegClassFor(VT)->getID();
2215 if (
RegPressure[RCId] < TLI->getRepRegClassCostFor(VT))
2219 RegPressure[RCId] -= TLI->getRepRegClassCostFor(VT);
2227 for (
unsigned i = NumDefs, e = N->
getNumValues(); i != e; ++i) {
2233 unsigned RCId = TLI->getRepRegClassFor(VT)->getID();
2234 RegPressure[RCId] += TLI->getRepRegClassCostFor(VT);
2238 DEBUG(dumpRegPressure());
2248 unsigned MaxHeight = 0;
2250 if (Succ.
isCtrl())
continue;
2257 if (Height > MaxHeight)
2266 unsigned Scratches = 0;
2268 if (Pred.
isCtrl())
continue;
2277 bool RetVal =
false;
2279 if (Pred.
isCtrl())
continue;
2299 bool RetVal =
false;
2301 if (Succ.
isCtrl())
continue;
2338 if (Pred.
isCtrl())
continue;
2350 if (Pred.
isCtrl())
continue;
2354 "VRegCycle def must be CopyFromReg");
2368 if (Pred.
isCtrl())
continue;
2382 if ((
int)SPQ->getCurCycle() < Height)
return true;
2383 if (SPQ->getHazardRec()->getHazardType(SU, 0)
2392 RegReductionPQBase *SPQ) {
2397 int LHeight = (int)left->
getHeight() + LPenalty;
2398 int RHeight = (int)right->
getHeight() + RPenalty;
2411 if (LHeight != RHeight)
2412 return LHeight > RHeight ? 1 : -1;
2424 if (!SPQ->getHazardRec()->isEnabled()) {
2425 if (LHeight != RHeight)
2426 return LHeight > RHeight ? 1 : -1;
2428 int LDepth = left->
getDepth() - LPenalty;
2429 int RDepth = right->
getDepth() - RPenalty;
2430 if (LDepth != RDepth) {
2432 <<
") depth " << LDepth <<
" vs SU (" << right->
NodeNum
2433 <<
") depth " << RDepth <<
"\n");
2434 return LDepth < RDepth ? 1 : -1;
2450 if (LHasPhysReg != RHasPhysReg) {
2452 static const char *
const PhysRegMsg[] = {
" has no physreg",
2453 " defines a physreg" };
2456 << PhysRegMsg[LHasPhysReg] <<
" SU(" << right->
NodeNum <<
") "
2457 << PhysRegMsg[RHasPhysReg] <<
"\n");
2458 return LHasPhysReg < RHasPhysReg;
2463 unsigned LPriority = SPQ->getNodePriority(left);
2464 unsigned RPriority = SPQ->getNodePriority(right);
2470 RPriority = (RPriority > RNumVals) ? (RPriority - RNumVals) : 0;
2474 LPriority = (LPriority > LNumVals) ? (LPriority - LNumVals) : 0;
2477 if (LPriority != RPriority)
2478 return LPriority > RPriority;
2483 unsigned LOrder = SPQ->getNodeOrdering(left);
2484 unsigned ROrder = SPQ->getNodeOrdering(right);
2488 if ((LOrder || ROrder) && LOrder != ROrder)
2489 return LOrder != 0 && (LOrder < ROrder || ROrder == 0);
2512 return LDist < RDist;
2517 if (LScratch != RScratch)
2518 return LScratch > RScratch;
2522 if ((left->
isCall && RPriority > 0) || (right->
isCall && LPriority > 0))
2541 "NodeQueueId cannot be zero");
2546 bool bu_ls_rr_sort::operator()(
SUnit *left,
SUnit *right)
const {
2554 bool src_ls_rr_sort::operator()(
SUnit *left,
SUnit *right)
const {
2558 unsigned LOrder = SPQ->getNodeOrdering(left);
2559 unsigned ROrder = SPQ->getNodeOrdering(right);
2563 if ((LOrder || ROrder) && LOrder != ROrder)
2564 return LOrder != 0 && (LOrder < ROrder || ROrder == 0);
2573 bool hybrid_ls_rr_sort::isReady(
SUnit *SU,
unsigned CurCycle)
const {
2574 static const unsigned ReadyDelay = 3;
2576 if (SPQ->MayReduceRegPressure(SU))
return true;
2578 if (SU->
getHeight() > (CurCycle + ReadyDelay))
return false;
2580 if (SPQ->getHazardRec()->getHazardType(SU, -ReadyDelay)
2588 bool hybrid_ls_rr_sort::operator()(
SUnit *left,
SUnit *right)
const {
2596 bool LHigh = SPQ->HighRegPressure(left);
2597 bool RHigh = SPQ->HighRegPressure(right);
2600 if (LHigh && !RHigh) {
2605 else if (!LHigh && RHigh) {
2610 if (!LHigh && !RHigh) {
2620 bool ilp_ls_rr_sort::isReady(
SUnit *SU,
unsigned CurCycle)
const {
2621 if (SU->
getHeight() > CurCycle)
return false;
2623 if (SPQ->getHazardRec()->getHazardType(SU, 0)
2637 if (Opc == TargetOpcode::EXTRACT_SUBREG ||
2638 Opc == TargetOpcode::SUBREG_TO_REG ||
2639 Opc == TargetOpcode::INSERT_SUBREG)
2654 bool ilp_ls_rr_sort::operator()(
SUnit *left,
SUnit *right)
const {
2662 unsigned LLiveUses = 0, RLiveUses = 0;
2663 int LPDiff = 0, RPDiff = 0;
2665 LPDiff = SPQ->RegPressureDiff(left, LLiveUses);
2666 RPDiff = SPQ->RegPressureDiff(right, RLiveUses);
2670 <<
" != SU(" << right->
NodeNum <<
"): " << RPDiff <<
"\n");
2671 return LPDiff > RPDiff;
2677 if (LReduce && !RReduce)
return false;
2678 if (RReduce && !LReduce)
return true;
2683 <<
" != SU(" << right->
NodeNum <<
"): " << RLiveUses <<
"\n");
2684 return LLiveUses < RLiveUses;
2690 if (LStall != RStall)
2713 void RegReductionPQBase::initNodes(std::vector<SUnit> &sunits) {
2717 AddPseudoTwoAddrDeps();
2719 if (!TracksRegPressure && !SrcOrder)
2720 PrescheduleNodesWithMultipleUses();
2722 CalculateSethiUllmanNumbers();
2725 if (scheduleDAG->BB->isSuccessor(scheduleDAG->BB))
2726 for (
SUnit &SU : sunits)
2734 bool RegReductionPQBase::canClobber(
const SUnit *SU,
const SUnit *
Op) {
2740 for (
unsigned i = 0; i != NumOps; ++i) {
2756 ScheduleDAGRRList *scheduleDAG,
2762 if(!ImpDefs && !RegMask)
2767 for (
const SDep &SuccPred : SuccSU->
Preds) {
2773 scheduleDAG->IsReachable(DepSU, SuccPred.
getSUnit()))
2777 for (
const MCPhysReg *ImpDef = ImpDefs; *ImpDef; ++ImpDef)
2782 scheduleDAG->IsReachable(DepSU, SuccPred.
getSUnit()))
2797 assert(ImpDefs &&
"Caller should check hasPhysRegDefs");
2800 if (!SUNode->isMachineOpcode())
2803 TII->
get(SUNode->getMachineOpcode()).getImplicitDefs();
2805 if (!SUImpDefs && !SURegMask)
2807 for (
unsigned i = NumDefs, e = N->
getNumValues(); i != e; ++i) {
2813 unsigned Reg = ImpDefs[i - NumDefs];
2818 for (;*SUImpDefs; ++SUImpDefs) {
2819 unsigned SUReg = *SUImpDefs;
2859 void RegReductionPQBase::PrescheduleNodesWithMultipleUses() {
2861 for (
SUnit &SU : *SUnits) {
2879 SUnit *PredSU =
nullptr;
2903 for (
const SDep &PredSucc : PredSU->
Succs) {
2905 if (PredSuccSU == &SU)
continue;
2909 goto outer_loop_continue;
2913 goto outer_loop_continue;
2915 if (scheduleDAG->IsReachable(&SU, PredSuccSU))
2916 goto outer_loop_continue;
2922 <<
" next to PredSU #" << PredSU->
NodeNum
2923 <<
" to guide scheduling in the presence of multiple uses\n");
2924 for (
unsigned i = 0; i != PredSU->
Succs.size(); ++i) {
2928 if (SuccSU != &SU) {
2930 scheduleDAG->RemovePred(SuccSU, Edge);
2931 scheduleDAG->AddPred(&SU, Edge);
2933 scheduleDAG->AddPred(SuccSU, Edge);
2937 outer_loop_continue:;
2948 void RegReductionPQBase::AddPseudoTwoAddrDeps() {
2949 for (
SUnit &SU : *SUnits) {
2962 for (
unsigned j = 0; j != NumOps; ++j) {
2986 while (SuccSU->
Succs.size() == 1 &&
2989 TargetOpcode::COPY_TO_REGCLASS)
2990 SuccSU = SuccSU->
Succs.front().getSUnit();
3003 if (SuccOpc == TargetOpcode::EXTRACT_SUBREG ||
3004 SuccOpc == TargetOpcode::INSERT_SUBREG ||
3005 SuccOpc == TargetOpcode::SUBREG_TO_REG)
3008 (!canClobber(SuccSU, DUSU) ||
3011 !scheduleDAG->IsReachable(SuccSU, &SU)) {
3012 DEBUG(
dbgs() <<
" Adding a pseudo-two-addr edge from SU #"
3032 BURegReductionPriorityQueue *PQ =
3033 new BURegReductionPriorityQueue(*IS->
MF,
false,
false, TII, TRI,
nullptr);
3034 ScheduleDAGRRList *SD =
new ScheduleDAGRRList(*IS->
MF,
false, PQ, OptLevel);
3035 PQ->setScheduleDAG(SD);
3046 SrcRegReductionPriorityQueue *PQ =
3047 new SrcRegReductionPriorityQueue(*IS->
MF,
false,
true, TII, TRI,
nullptr);
3048 ScheduleDAGRRList *SD =
new ScheduleDAGRRList(*IS->
MF,
false, PQ, OptLevel);
3049 PQ->setScheduleDAG(SD);
3061 HybridBURRPriorityQueue *PQ =
3062 new HybridBURRPriorityQueue(*IS->
MF,
true,
false, TII, TRI, TLI);
3064 ScheduleDAGRRList *SD =
new ScheduleDAGRRList(*IS->
MF,
true, PQ, OptLevel);
3065 PQ->setScheduleDAG(SD);
3077 ILPBURRPriorityQueue *PQ =
3078 new ILPBURRPriorityQueue(*IS->
MF,
true,
false, TII, TRI, TLI);
3079 ScheduleDAGRRList *SD =
new ScheduleDAGRRList(*IS->
MF,
true, PQ, OptLevel);
3080 PQ->setScheduleDAG(SD);
void push_back(const T &Elt)
bool isCtrl() const
Shorthand for getKind() != SDep::Data.
const SDNode * GetNode() const
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
unsigned NumPreds
of SDep::Data preds.
STATISTIC(NumFunctions,"Total number of functions")
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
static int BUCompareLatency(SUnit *left, SUnit *right, bool checkPref, RegReductionPQBase *SPQ)
bool isCommutable() const
Return true if this may be a 2- or 3-address instruction (of the form "X = op Y, Z, ..."), which produces the same result if Y and Z are exchanged.
static bool canEnableCoalescing(SUnit *SU)
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static cl::opt< bool > DisableSchedRegPressure("disable-sched-reg-pressure", cl::Hidden, cl::init(false), cl::desc("Disable regpressure priority in sched=list-ilp"))
static cl::opt< unsigned > AvgIPC("sched-avg-ipc", cl::Hidden, cl::init(1), cl::desc("Average inst/cycle whan no target itinerary exists."))
bool hasOptionalDef() const
Set if this instruction has an optional definition, e.g.
bool isTwoAddress
Is a two-address instruction.
SDNode * getGluedNode() const
If this node has a glue operand, return the node to which the glue operand points.
Describe properties that are true of each instruction in the target description file.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
static void GetCostForDef(const ScheduleDAGSDNodes::RegDefIter &RegDefPos, const TargetLowering *TLI, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI, unsigned &RegClass, unsigned &Cost, const MachineFunction &MF)
GetCostForDef - Looks up the register class and cost for a given definition.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void dumpAll(const ScheduleDAG *G) const
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
unsigned getID() const
Return the register class ID number.
static bool isClobberKind(unsigned Flag)
static bool canClobberReachingPhysRegUse(const SUnit *DepSU, const SUnit *SU, ScheduleDAGRRList *scheduleDAG, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI)
canClobberReachingPhysRegUse - True if SU would clobber one of it's successor's explicit physregs who...
const SDValue & getOperand(unsigned Num) const
void removePred(const SDep &D)
Removes the specified edge as a pred of the current node if it exists.
static cl::opt< bool > DisableSchedVRegCycle("disable-sched-vrcycle", cl::Hidden, cl::init(false), cl::desc("Disable virtual register cycle interference checks"))
void setNodeId(int Id)
Set unique node id.
static unsigned CalcNodeSethiUllmanNumber(const SUnit *SU, std::vector< unsigned > &SUNumbers)
CalcNodeSethiUllmanNumber - Compute Sethi Ullman number.
bool isAssignedRegDep() const
Tests if this is a Data dependence that is associated with a register.
static bool hasVRegCycleUse(const SUnit *SU)
const TargetRegisterClass * CopyDstRC
Is a special copy node if != nullptr.
EntryToken - This is the marker used to indicate the start of a region.
bool isArtificial() const
Tests if this is an Order dependence that is marked as "artificial", meaning it isn't necessary for...
virtual const TargetRegisterClass * getRepRegClassFor(MVT VT) const
Return the 'representative' register class for the specified value type.
SmallVector< SDep, 4 > Preds
All sunit predecessors.
static SDNode * FindCallSeqStart(SDNode *N, unsigned &NestLevel, unsigned &MaxNest, const TargetInstrInfo *TII)
FindCallSeqStart - Starting from the (lowered) CALLSEQ_END node, locate the corresponding (lowered) C...
bool isScheduled
True once scheduled.
This interface is used to plug different priorities computation algorithms into the list scheduler...
unsigned getHeight() const
Returns the height of this node, which is the length of the maximum path down to any node which has n...
unsigned getCallFrameDestroyOpcode() const
static int checkSpecialNodes(const SUnit *left, const SUnit *right)
unsigned NumSuccs
of SDep::Data sucss.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned NumSuccsLeft
of succs not scheduled.
const HexagonInstrInfo * TII
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
const TargetLowering * TLI
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Regular data dependence (aka true-dependence).
CopyToReg - This node has three operands: a chain, a register number to set to this value...
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
bool hasPhysRegDefs
Has physreg defs that are being used.
static bool isRegDefEarlyClobberKind(unsigned Flag)
static void CheckForLiveRegDef(SUnit *SU, unsigned Reg, SUnit **LiveRegDefs, SmallSet< unsigned, 4 > &RegAdded, SmallVectorImpl< unsigned > &LRegs, const TargetRegisterInfo *TRI)
CheckForLiveRegDef - Return true and update live register vector if the specified register def of the...
static const uint32_t * getNodeRegMask(const SDNode *N)
getNodeRegMask - Returns the register mask attached to an SDNode, if any.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
INLINEASM - Represents an inline asm block.
LLVM_NODISCARD bool empty() const
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
SUnit * OrigNode
If not this, the node from which this node was cloned.
unsigned getIROrder() const
Return the node ordering.
unsigned getNumValues() const
Return the number of values defined/returned by this operator.
ScheduleDAGSDNodes * createHybridListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level)
createHybridListDAGScheduler - This creates a bottom up register pressure aware list scheduler that m...
unsigned getCallFrameSetupOpcode() const
These methods return the opcode of the frame setup/destroy instructions if they exist (-1 otherwise)...
const MCPhysReg * getImplicitDefs() const
Return a list of registers that are potentially written by any instance of this machine instruction...
void dump(const ScheduleDAG *G) const
bool isPending
True once pending.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static bool isRegDefKind(unsigned Flag)
ScheduleDAGSDNodes * createSourceListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createBURRListDAGScheduler - This creates a bottom up list scheduler that schedules nodes in source c...
size_t size() const
size - Get the array size.
static RegisterScheduler burrListDAGScheduler("list-burr","Bottom-up register reduction list scheduling", createBURRListDAGScheduler)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
TargetInstrInfo - Interface to description of machine instruction set.
This corresponds to the llvm.lifetime.
static void CheckForLiveRegDefMasked(SUnit *SU, const uint32_t *RegMask, ArrayRef< SUnit * > LiveRegDefs, SmallSet< unsigned, 4 > &RegAdded, SmallVectorImpl< unsigned > &LRegs)
CheckForLiveRegDefMasked - Check for any live physregs that are clobbered by RegMask, and add them to LRegs.
SDNode * getNode() const
get the SDNode which holds the desired result
void setHeightToAtLeast(unsigned NewHeight)
If NewDepth is greater than this node's depth value, set it to be the new height value.
initializer< Ty > init(const Ty &Val)
bool isCall
Is a function call.
static RegisterScheduler hybridListDAGScheduler("list-hybrid","Bottom-up register pressure aware list scheduling ""which tries to balance latency and register pressure", createHybridListDAGScheduler)
ScheduleDAGSDNodes - A ScheduleDAG for scheduling SDNode-based DAGs.
bool regsOverlap(unsigned regA, unsigned regB) const
Returns true if the two registers are equal or alias each other.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
static cl::opt< bool > DisableSchedStalls("disable-sched-stalls", cl::Hidden, cl::init(true), cl::desc("Disable no-stall priority in sched=list-ilp"))
HazardRecognizer - This determines whether or not an instruction can be issued this cycle...
SDNode * getNode() const
Returns the representative SDNode for this SUnit.
unsigned short Latency
Node latency.
ScheduleDAGSDNodes * createBURRListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level OptLevel)
createBURRListDAGScheduler - This creates a bottom up register usage reduction list scheduler...
bool isOptionalDef() const
Set if this operand is a optional def.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
static bool isOperandOf(const SUnit *SU, SDNode *N)
static RegisterScheduler ILPListDAGScheduler("list-ilp","Bottom-up register pressure aware list scheduling ""which tries to balance ILP and register pressure", createILPListDAGScheduler)
static unsigned calcMaxScratches(const SUnit *SU)
calcMaxScratches - Returns an cost estimate of the worse case requirement for scratch registers...
static bool IsChainDependent(SDNode *Outer, SDNode *Inner, unsigned NestLevel, const TargetInstrInfo *TII)
IsChainDependent - Test if Outer is reachable from Inner through chain dependencies.
static bool BUHasStall(SUnit *SU, int Height, RegReductionPQBase *SPQ)
const MCPhysReg * ImplicitDefs
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag...
static cl::opt< bool > DisableSchedCriticalPath("disable-sched-critical-path", cl::Hidden, cl::init(false), cl::desc("Disable critical path priority in sched=list-ilp"))
bool isVRegCycle
May use and def the same vreg.
MCRegAliasIterator enumerates all registers aliasing Reg.
unsigned getLatency() const
Returns the latency value for this edge, which roughly means the minimum number of cycles that must e...
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
static bool canClobberPhysRegDefs(const SUnit *SuccSU, const SUnit *SU, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI)
canClobberPhysRegDefs - True if SU would clobber one of SuccSU's physical register defs...
static void resetVRegCycle(SUnit *SU)
static cl::opt< bool > DisableSchedLiveUses("disable-sched-live-uses", cl::Hidden, cl::init(true), cl::desc("Disable live use priority in sched=list-ilp"))
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
static bool hasOnlyLiveInOpers(const SUnit *SU)
hasOnlyLiveInOpers - Return true if SU has only value predecessors that are CopyFromReg from a virtua...
static unsigned closestSucc(const SUnit *SU)
closestSucc - Returns the scheduled cycle of the successor which is closest to the current cycle...
Sched::Preference SchedulingPref
Scheduling preference.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
RegDefIter - In place iteration over the values defined by an SUnit.
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
EH_LABEL - Represents a label in mid basic block used to track locations needed for debug and excepti...
static bool BURRSort(SUnit *left, SUnit *right, RegReductionPQBase *SPQ)
TokenFactor - This node takes multiple tokens as input and produces a single token result...
bool isCommutable
Is a commutable instruction.
ScheduleDAGSDNodes * createILPListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level)
createILPListDAGScheduler - This creates a bottom up register pressure aware list scheduler that trie...
static cl::opt< bool > DisableSchedHeight("disable-sched-height", cl::Hidden, cl::init(false), cl::desc("Disable scheduled-height priority in sched=list-ilp"))
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
static void initVRegCycle(SUnit *SU)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
const TargetRegisterClass * CopySrcRC
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static bool clobbersPhysReg(const uint32_t *RegMask, unsigned PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
bool isCallOp
Is a function call operand.
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...
iterator_range< value_op_iterator > op_values() const
llvm_unreachable("Unknown RegBank!")
void setLatency(unsigned Lat)
Sets the latency for this edge.
TargetSubtargetInfo - Generic base class for all target subtargets.
bool isAvailable
True once available.
unsigned NodeQueueId
Queue id of node.
static std::vector< std::string > Flags
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static bool hasOnlyLiveOutUses(const SUnit *SU)
hasOnlyLiveOutUses - Return true if SU has only value successors that are CopyToReg to a virtual regi...
static cl::opt< bool > DisableSchedPhysRegJoin("disable-sched-physreg-join", cl::Hidden, cl::init(false), cl::desc("Disable physreg def-use affinity"))
static cl::opt< int > MaxReorderWindow("max-sched-reorder", cl::Hidden, cl::init(6), cl::desc("Number of instructions to allow ahead of the critical path ""in sched=list-ilp"))
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
unsigned short NumRegDefsLeft
of reg defs with no scheduled use.
static cl::opt< bool > Disable2AddrHack("disable-2addr-hack", cl::Hidden, cl::init(true), cl::desc("Disable scheduler's two-address hack"))
static MVT getPhysicalRegisterVT(SDNode *N, unsigned Reg, const TargetInstrInfo *TII)
getPhysicalRegisterVT - Returns the ValueType of the physical register definition of the specified no...
static cl::opt< bool > DisableSchedCycles("disable-sched-cycles", cl::Hidden, cl::init(false), cl::desc("Disable cycle-level precision during preRA scheduling"))
int getNodeId() const
Return the unique node id.
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
bool isSucc(const SUnit *N) const
Tests if node N is a successor of this node.
static RegisterScheduler sourceListDAGScheduler("source","Similar to list-burr but schedules in source ""order when possible", createSourceListDAGScheduler)
virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const
Return the register pressure "high water mark" for the specific register class.
unsigned NodeNum
Entry # of node in the node vector.
virtual ScheduleHazardRecognizer * CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI, const ScheduleDAG *DAG) const
Allocate and return a hazard recognizer to use for this target when scheduling the machine instructio...
void setHeightDirty()
Sets a flag in this node to indicate that its stored Height value will require recomputation the next...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool addPred(const SDep &D, bool Required=true)
Adds the specified edge as a pred of the current node if not already.
virtual const TargetInstrInfo * getInstrInfo() const
SmallVector< SDep, 4 > Succs
All sunit successors.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const MCOperandInfo * OpInfo
Arbitrary strong DAG edge (no real dependence).
virtual uint8_t getRepRegClassCostFor(MVT VT) const
Return the cost of the 'representative' register class for the specified value type.
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
const TargetRegisterClass * getRegClass(const MCInstrDesc &TID, unsigned OpNum, const TargetRegisterInfo *TRI, const MachineFunction &MF) const
Given a machine instruction descriptor, returns the register class constraint for OpNum...
bool isScheduleLow
True if preferable to schedule low.
MERGE_VALUES - This node takes multiple discrete operands and returns them all as its individual resu...
unsigned getReg() const
Returns the register associated with this edge.
This class can compute a topological ordering for SUnits and provides methods for dynamically updatin...
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
bool hasPhysRegClobbers
Has any physreg defs, used or not.
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
Scheduling unit. This is a node in the scheduling DAG.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
This file describes how to lower LLVM code to machine code.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.