31#define DEBUG_TYPE "machine-scheduler"
36 "amdgpu-disable-unclustered-high-rp-reschedule",
cl::Hidden,
37 cl::desc(
"Disable unclustered high register pressure "
38 "reduction scheduling stage."),
42 "amdgpu-disable-clustered-low-occupancy-reschedule",
cl::Hidden,
43 cl::desc(
"Disable clustered low occupancy "
44 "rescheduling for ILP scheduling stage."),
50 "Sets the bias which adds weight to occupancy vs latency. Set it to "
51 "100 to chase the occupancy only."),
56 cl::desc(
"Relax occupancy targets for kernels which are memory "
57 "bound (amdgpu-membound-threshold), or "
58 "Wave Limited (amdgpu-limit-wave-threshold)."),
65 HasHighPressure(
false) {}
98 "VGPRCriticalLimit calculation method.\n");
103 VGPRBudget = std::max(VGPRBudget, Granule);
142 if (!
Op.isReg() ||
Op.isImplicit())
144 if (
Op.getReg().isPhysical() ||
145 (
Op.isDef() &&
Op.getSubReg() != AMDGPU::NoSubRegister))
153 std::vector<unsigned> &Pressure,
154 std::vector<unsigned> &MaxPressure) {
168 unsigned SGPRPressure,
169 unsigned VGPRPressure,
bool IsBottomUp) {
195 Pressure[AMDGPU::RegisterPressureSets::SReg_32] = SGPRPressure;
196 Pressure[AMDGPU::RegisterPressureSets::VGPR_32] = VGPRPressure;
204 (IsBottomUp ? Diff.getUnitInc() : -Diff.getUnitInc());
207#ifdef EXPENSIVE_CHECKS
208 std::vector<unsigned> CheckPressure, CheckMaxPressure;
210 if (
Pressure[AMDGPU::RegisterPressureSets::SReg_32] !=
211 CheckPressure[AMDGPU::RegisterPressureSets::SReg_32] ||
212 Pressure[AMDGPU::RegisterPressureSets::VGPR_32] !=
213 CheckPressure[AMDGPU::RegisterPressureSets::VGPR_32]) {
214 errs() <<
"Register Pressure is inaccurate when calculated through "
216 <<
"SGPR got " <<
Pressure[AMDGPU::RegisterPressureSets::SReg_32]
218 << CheckPressure[AMDGPU::RegisterPressureSets::SReg_32] <<
"\n"
219 <<
"VGPR got " <<
Pressure[AMDGPU::RegisterPressureSets::VGPR_32]
221 << CheckPressure[AMDGPU::RegisterPressureSets::VGPR_32] <<
"\n";
227 unsigned NewSGPRPressure =
Pressure[AMDGPU::RegisterPressureSets::SReg_32];
228 unsigned NewVGPRPressure =
Pressure[AMDGPU::RegisterPressureSets::VGPR_32];
238 const unsigned MaxVGPRPressureInc = 16;
239 bool ShouldTrackVGPRs = VGPRPressure + MaxVGPRPressureInc >=
VGPRExcessLimit;
240 bool ShouldTrackSGPRs = !ShouldTrackVGPRs && SGPRPressure >=
SGPRExcessLimit;
271 if (SGPRDelta >= 0 || VGPRDelta >= 0) {
273 if (SGPRDelta > VGPRDelta) {
294 unsigned SGPRPressure = 0;
295 unsigned VGPRPressure = 0;
297 SGPRPressure =
Pressure[AMDGPU::RegisterPressureSets::SReg_32];
298 VGPRPressure =
Pressure[AMDGPU::RegisterPressureSets::VGPR_32];
301 for (
SUnit *SU : Q) {
305 VGPRPressure, IsBottomUp);
358 "Last pick result should correspond to re-picking right now");
380 "Last pick result should correspond to re-picking right now");
396 IsTopNode = Cand.AtTop;
506 bool SameBoundary = Zone !=
nullptr;
539 const SUnit *CandNextClusterSU =
541 const SUnit *TryCandNextClusterSU =
544 Cand.
SU == CandNextClusterSU, TryCand, Cand,
Cluster))
574 StartingOccupancy(MFI.getOccupancy()), MinOccupancy(StartingOccupancy) {
576 LLVM_DEBUG(
dbgs() <<
"Starting occupancy is " << StartingOccupancy <<
".\n");
579 if (MinOccupancy != StartingOccupancy)
580 LLVM_DEBUG(
dbgs() <<
"Allowing Occupancy drops to " << MinOccupancy
585std::unique_ptr<GCNSchedStage>
587 switch (SchedStageID) {
589 return std::make_unique<OccInitialScheduleStage>(SchedStageID, *
this);
591 return std::make_unique<UnclusteredHighRPStage>(SchedStageID, *
this);
593 return std::make_unique<ClusteredLowOccStage>(SchedStageID, *
this);
595 return std::make_unique<PreRARematStage>(SchedStageID, *
this);
597 return std::make_unique<ILPInitialScheduleStage>(SchedStageID, *
this);
610GCNScheduleDAGMILive::getRealRegPressure(
unsigned RegionIdx)
const {
616void GCNScheduleDAGMILive::computeBlockPressure(
unsigned RegionIdx,
631 if (!Candidate->empty() && Candidate->pred_size() == 1) {
634 OnlySucc = Candidate;
639 size_t CurRegion = RegionIdx;
640 for (
size_t E = Regions.size(); CurRegion != E; ++CurRegion)
641 if (Regions[CurRegion].first->getParent() !=
MBB)
646 auto LiveInIt = MBBLiveIns.find(
MBB);
647 auto &Rgn = Regions[CurRegion];
649 if (LiveInIt != MBBLiveIns.end()) {
650 auto LiveIn = std::move(LiveInIt->second);
652 MBBLiveIns.erase(LiveInIt);
655 auto LRS = BBLiveInMap.lookup(NonDbgMI);
656#ifdef EXPENSIVE_CHECKS
665 if (Regions[CurRegion].first ==
I || NonDbgMI ==
I) {
666 LiveIns[CurRegion] =
RPTracker.getLiveRegs();
670 if (Regions[CurRegion].second ==
I) {
671 Pressure[CurRegion] =
RPTracker.moveMaxPressure();
672 if (CurRegion-- == RegionIdx)
685 MBBLiveIns[OnlySucc] =
RPTracker.moveLiveRegs();
690GCNScheduleDAGMILive::getBBLiveInMap()
const {
692 std::vector<MachineInstr *> BBStarters;
693 BBStarters.reserve(Regions.size());
694 auto I = Regions.rbegin(), E = Regions.rend();
695 auto *
BB =
I->first->getParent();
698 BBStarters.push_back(
MI);
701 }
while (
I != E &&
I->first->getParent() ==
BB);
710 LiveIns.resize(Regions.size());
711 Pressure.resize(Regions.size());
712 RescheduleRegions.
resize(Regions.size());
713 RegionsWithHighRP.
resize(Regions.size());
714 RegionsWithExcessRP.
resize(Regions.size());
715 RegionsWithMinOcc.
resize(Regions.size());
716 RegionsWithIGLPInstrs.
resize(Regions.size());
717 RescheduleRegions.
set();
718 RegionsWithHighRP.
reset();
719 RegionsWithExcessRP.
reset();
720 RegionsWithMinOcc.
reset();
721 RegionsWithIGLPInstrs.
reset();
726void GCNScheduleDAGMILive::runSchedStages() {
727 LLVM_DEBUG(
dbgs() <<
"All regions recorded, starting actual scheduling.\n");
729 if (!Regions.empty())
730 BBLiveInMap = getBBLiveInMap();
735 if (!Stage->initGCNSchedStage())
738 for (
auto Region : Regions) {
742 if (!Stage->initGCNRegion()) {
743 Stage->advanceRegion();
749 Stage->finalizeGCNRegion();
752 Stage->finalizeGCNSchedStage();
760 OS <<
"Max Occupancy Initial Schedule";
763 OS <<
"Unclustered High Register Pressure Reschedule";
766 OS <<
"Clustered Low Occupancy Reschedule";
769 OS <<
"Pre-RA Rematerialize";
772 OS <<
"Max ILP Initial Schedule";
782 MFI(DAG.MFI), ST(DAG.ST), StageID(StageID) {}
799 if (
DAG.RegionsWithHighRP.
none() &&
DAG.RegionsWithExcessRP.
none())
806 InitialOccupancy =
DAG.MinOccupancy;
816 <<
"Retrying function scheduling without clustering. "
817 "Aggressivly try to reduce register pressure to achieve occupancy "
818 <<
DAG.MinOccupancy <<
".\n");
833 if (
DAG.StartingOccupancy <=
DAG.MinOccupancy)
837 dbgs() <<
"Retrying function scheduling with lowest recorded occupancy "
838 <<
DAG.MinOccupancy <<
".\n");
846 if (
DAG.RegionsWithMinOcc.
none() ||
DAG.Regions.size() == 1)
861 collectRematerializableInstructions();
862 if (RematerializableInsts.empty() || !sinkTriviallyRematInsts(
ST,
TII))
866 dbgs() <<
"Retrying function scheduling with improved occupancy of "
867 <<
DAG.MinOccupancy <<
" from rematerializing\n");
879 if (
DAG.MinOccupancy > InitialOccupancy) {
880 for (
unsigned IDX = 0; IDX <
DAG.Pressure.size(); ++IDX)
881 DAG.RegionsWithMinOcc[IDX] =
882 DAG.Pressure[IDX].getOccupancy(
DAG.ST) ==
DAG.MinOccupancy;
885 <<
" stage successfully increased occupancy to "
886 <<
DAG.MinOccupancy <<
'\n');
907 <<
"\n From: " << *
DAG.
begin() <<
" To: ";
909 else dbgs() <<
"End";
910 dbgs() <<
" RegionInstrs: " << NumRegionInstrs <<
'\n');
917 for (
auto &
I :
DAG) {
919 if (
I.getOpcode() == AMDGPU::SCHED_GROUP_BARRIER ||
920 I.getOpcode() == AMDGPU::IGLP_OPT)
931 dbgs() <<
"Pressure before scheduling:\nRegion live-ins:"
933 <<
"Region live-in pressure: "
958 DAG.MinOccupancy <= InitialOccupancy) &&
1032 unsigned TargetOccupancy =
1034 unsigned WavesAfter =
1036 unsigned WavesBefore =
1038 LLVM_DEBUG(
dbgs() <<
"Occupancy before scheduling: " << WavesBefore
1039 <<
", after " << WavesAfter <<
".\n");
1045 unsigned NewOccupancy = std::max(WavesAfter, WavesBefore);
1049 if (WavesAfter < WavesBefore && WavesAfter <
DAG.MinOccupancy &&
1051 LLVM_DEBUG(
dbgs() <<
"Function is memory bound, allow occupancy drop up to "
1053 NewOccupancy = WavesAfter;
1056 if (NewOccupancy <
DAG.MinOccupancy) {
1057 DAG.MinOccupancy = NewOccupancy;
1061 <<
DAG.MinOccupancy <<
".\n");
1095 unsigned ReadyCycle = CurrCycle;
1096 for (
auto &
D : SU.
Preds) {
1097 if (
D.isAssignedRegDep()) {
1101 ReadyCycle = std::max(ReadyCycle, DefReady +
Latency);
1104 ReadyCycles[SU.
NodeNum] = ReadyCycle;
1111 std::pair<MachineInstr *, unsigned>
B)
const {
1112 return A.second <
B.second;
1118 if (ReadyCycles.empty())
1120 unsigned BBNum = ReadyCycles.begin()->first->getParent()->getNumber();
1121 dbgs() <<
"\n################## Schedule time ReadyCycles for MBB : " << BBNum
1122 <<
" ##################\n# Cycle #\t\t\tInstruction "
1126 for (
auto &
I : ReadyCycles) {
1127 if (
I.second > IPrev + 1)
1128 dbgs() <<
"****************************** BUBBLE OF " <<
I.second - IPrev
1129 <<
" CYCLES DETECTED ******************************\n\n";
1130 dbgs() <<
"[ " <<
I.second <<
" ] : " << *
I.first <<
"\n";
1143 unsigned SumBubbles = 0;
1145 unsigned CurrCycle = 0;
1146 for (
auto &SU : InputSchedule) {
1147 unsigned ReadyCycle =
1149 SumBubbles += ReadyCycle - CurrCycle;
1151 ReadyCyclesSorted.insert(std::make_pair(SU.getInstr(), ReadyCycle));
1153 CurrCycle = ++ReadyCycle;
1176 unsigned SumBubbles = 0;
1178 unsigned CurrCycle = 0;
1179 for (
auto &
MI :
DAG) {
1183 unsigned ReadyCycle =
1185 SumBubbles += ReadyCycle - CurrCycle;
1187 ReadyCyclesSorted.insert(std::make_pair(SU->
getInstr(), ReadyCycle));
1189 CurrCycle = ++ReadyCycle;
1206 if (WavesAfter <
DAG.MinOccupancy)
1241 <<
"\n\t *** In shouldRevertScheduling ***\n"
1242 <<
" *********** BEFORE UnclusteredHighRPStage ***********\n");
1247 <<
"\n *********** AFTER UnclusteredHighRPStage ***********\n");
1249 unsigned OldMetric = MBefore.
getMetric();
1250 unsigned NewMetric = MAfter.
getMetric();
1251 unsigned WavesBefore =
1258 LLVM_DEBUG(
dbgs() <<
"\tMetric before " << MBefore <<
"\tMetric after "
1259 << MAfter <<
"Profit: " << Profit <<
"\n");
1296 LLVM_DEBUG(
dbgs() <<
"New pressure will result in more spilling.\n");
1311 int SkippedDebugInstr = 0;
1313 if (
MI->isDebugInstr()) {
1314 ++SkippedDebugInstr;
1321 if (!
MI->isDebugInstr())
1326 for (
auto &
Op :
MI->all_defs())
1327 Op.setIsUndef(
false);
1330 if (!
MI->isDebugInstr()) {
1348 while (SkippedDebugInstr-- > 0)
1357 if (
MI->isDebugInstr())
1371void PreRARematStage::collectRematerializableInstructions() {
1385 if (
Op->getSubReg() != 0 || !isTriviallyReMaterializable(*Def))
1389 if (Def->getParent() == UseI->
getParent())
1395 bool AddedToRematList =
false;
1396 for (
unsigned I = 0, E =
DAG.Regions.size();
I != E; ++
I) {
1397 auto It =
DAG.LiveIns[
I].find(Reg);
1398 if (It !=
DAG.LiveIns[
I].end() && !It->second.none()) {
1399 if (
DAG.RegionsWithMinOcc[
I]) {
1400 RematerializableInsts[
I][Def] = UseI;
1401 AddedToRematList =
true;
1406 RematDefToLiveInRegions[Def].push_back(
I);
1409 if (!AddedToRematList)
1410 RematDefToLiveInRegions.erase(Def);
1414bool PreRARematStage::sinkTriviallyRematInsts(
const GCNSubtarget &ST,
1419 std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>, 32>
1427 NewRescheduleRegions.
resize(
DAG.Regions.size());
1431 for (
const auto &It : RematDefToLiveInRegions)
1432 ImpactedRegions.
insert(It.second.begin(), It.second.end());
1436 for (
auto Idx : ImpactedRegions) {
1440 NewRegions =
DAG.Regions;
1441 NewRescheduleRegions.
reset();
1444 bool Improved =
false;
1445 for (
auto I : ImpactedRegions) {
1446 if (!
DAG.RegionsWithMinOcc[
I])
1451 int SGPRUsage = NewPressure[
I].getSGPRNum();
1460 if (NewPressure[
I].getOccupancy(
ST) >
DAG.MinOccupancy) {
1461 NewRescheduleRegions[
I] =
true;
1469 int TotalSinkableRegs = 0;
1470 for (
const auto &It : RematerializableInsts[
I]) {
1473 TotalSinkableRegs +=
1476 int VGPRsAfterSink = VGPRUsage - TotalSinkableRegs;
1480 if (OptimisticOccupancy <=
DAG.MinOccupancy)
1483 unsigned ImproveOccupancy = 0;
1485 for (
auto &It : RematerializableInsts[
I]) {
1494 TII->reMaterialize(*InsertPos->getParent(), InsertPos, Reg,
1495 Def->getOperand(0).getSubReg(), *Def, *
DAG.
TRI);
1500 InsertedMIToOldDef[NewMI] =
Def;
1504 DAG.updateRegionBoundaries(NewRegions, Def,
nullptr,
1508 DAG.updateRegionBoundaries(NewRegions, InsertPos, NewMI);
1514 for (
auto Idx : RematDefToLiveInRegions[Def]) {
1516 if (InsertPos->getParent() !=
DAG.Regions[
Idx].first->getParent()) {
1523 NewRegions[
Idx].first, NewRegions[
Idx].second);
1524 RPT.reset(*NonDbgMI, &NewLiveIns[
Idx]);
1525 RPT.advance(NewRegions[
Idx].second);
1526 NewPressure[
Idx] = RPT.moveMaxPressure();
1531 ImproveOccupancy = NewPressure[
I].getOccupancy(
ST);
1532 if (ImproveOccupancy >
DAG.MinOccupancy)
1537 for (
auto &Def : SinkedDefs)
1538 for (
auto TrackedIdx : RematDefToLiveInRegions[Def])
1539 RematerializableInsts[TrackedIdx].erase(Def);
1541 if (ImproveOccupancy <=
DAG.MinOccupancy)
1544 NewRescheduleRegions[
I] =
true;
1551 for (
auto &Entry : InsertedMIToOldDef) {
1556 MI->eraseFromParent();
1565 for (
auto &Entry : InsertedMIToOldDef) {
1570 DAG.BBLiveInMap.erase(OldMI);
1581 for (
auto Idx : ImpactedRegions) {
1584 DAG.MBBLiveIns.erase(
DAG.Regions[
Idx].first->getParent());
1586 DAG.Regions = NewRegions;
1587 DAG.RescheduleRegions = NewRescheduleRegions;
1596bool PreRARematStage::isTriviallyReMaterializable(
const MachineInstr &
MI) {
1601 if (MO.getReg().isVirtual())
1611void GCNScheduleDAGMILive::updateRegionBoundaries(
1615 unsigned I = 0, E = RegionBoundaries.size();
1617 while (
I != E &&
MI->getParent() != RegionBoundaries[
I].first->getParent())
1620 for (;
I != E; ++
I) {
1621 if (
MI->getParent() != RegionBoundaries[
I].first->getParent())
1624 if (Removing &&
MI == RegionBoundaries[
I].first &&
1625 MI == RegionBoundaries[
I].second) {
1628 RegionBoundaries[
I] =
1629 std::pair(
MI->getParent()->end(),
MI->getParent()->end());
1632 if (
MI == RegionBoundaries[
I].first) {
1634 RegionBoundaries[
I] =
1635 std::pair(std::next(
MI), RegionBoundaries[
I].second);
1639 RegionBoundaries[
I].second);
1642 if (Removing &&
MI == RegionBoundaries[
I].second) {
1643 RegionBoundaries[
I] = std::pair(RegionBoundaries[
I].first, std::prev(
MI));
1651 unsigned Opc =
MI->getOpcode();
1652 return Opc == AMDGPU::SCHED_GROUP_BARRIER || Opc == AMDGPU::IGLP_OPT;
1658 bool RemoveKillFlags)
1663 if (HasIGLPInstrs) {
1664 SavedMutations.clear();
MachineInstrBuilder MachineInstrBuilder & DefMI
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static cl::opt< bool > DisableClusteredLowOccupancy("amdgpu-disable-clustered-low-occupancy-reschedule", cl::Hidden, cl::desc("Disable clustered low occupancy " "rescheduling for ILP scheduling stage."), cl::init(false))
static cl::opt< bool > RelaxedOcc("amdgpu-schedule-relaxed-occupancy", cl::Hidden, cl::desc("Relax occupancy targets for kernels which are memory " "bound (amdgpu-membound-threshold), or " "Wave Limited (amdgpu-limit-wave-threshold)."), cl::init(false))
static cl::opt< bool > DisableUnclusterHighRP("amdgpu-disable-unclustered-high-rp-reschedule", cl::Hidden, cl::desc("Disable unclustered high register pressure " "reduction scheduling stage."), cl::init(false))
static void printScheduleModel(std::set< std::pair< MachineInstr *, unsigned >, EarlierIssuingCycle > &ReadyCycles)
static bool hasIGLPInstrs(ScheduleDAGInstrs *DAG)
static void getRegisterPressures(bool AtTop, const RegPressureTracker &RPTracker, SUnit *SU, std::vector< unsigned > &Pressure, std::vector< unsigned > &MaxPressure)
static bool canUsePressureDiffs(const SUnit &SU)
Checks whether SU can use the cached DAG pressure diffs to compute the current register pressure.
static cl::opt< unsigned > ScheduleMetricBias("amdgpu-schedule-metric-bias", cl::Hidden, cl::desc("Sets the bias which adds weight to occupancy vs latency. Set it to " "100 to chase the occupancy only."), cl::init(10))
const HexagonInstrInfo * TII
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
uint32_t getLDSSize() const
unsigned getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &) const
Inverse of getMaxLocalMemWithWaveCount.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
bool none() const
none - Returns true if none of the bits are set.
bool initGCNSchedStage() override
bool shouldRevertScheduling(unsigned WavesAfter) override
bool initGCNRegion() override
This class represents an Operation in the Expression.
bool erase(const KeyT &Val)
GCNMaxILPSchedStrategy(const MachineSchedContext *C)
bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand, SchedBoundary *Zone) const override
Apply a set of heuristics to a new candidate.
GCNMaxOccupancySchedStrategy(const MachineSchedContext *C)
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
GCNPostScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S, bool RemoveKillFlags)
virtual bool initGCNRegion()
GCNRegPressure PressureBefore
bool isRegionWithExcessRP() const
bool mayCauseSpilling(unsigned WavesAfter)
ScheduleMetrics getScheduleMetrics(const std::vector< SUnit > &InputSchedule)
GCNScheduleDAGMILive & DAG
const GCNSchedStageID StageID
std::vector< MachineInstr * > Unsched
GCNRegPressure PressureAfter
SIMachineFunctionInfo & MFI
unsigned computeSUnitReadyCycle(const SUnit &SU, unsigned CurrCycle, DenseMap< unsigned, unsigned > &ReadyCycles, const TargetSchedModel &SM)
virtual void finalizeGCNSchedStage()
virtual bool initGCNSchedStage()
virtual bool shouldRevertScheduling(unsigned WavesAfter)
std::vector< std::unique_ptr< ScheduleDAGMutation > > SavedMutations
GCNSchedStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
MachineBasicBlock * CurrentMBB
This is a minimal scheduler strategy.
const unsigned HighRPSGPRBias
GCNSchedStrategy(const MachineSchedContext *C)
SmallVector< GCNSchedStageID, 4 > SchedStages
SUnit * pickNodeBidirectional(bool &IsTopNode)
void pickNodeFromQueue(SchedBoundary &Zone, const CandPolicy &ZonePolicy, const RegPressureTracker &RPTracker, SchedCandidate &Cand, bool IsBottomUp)
unsigned SGPRCriticalLimit
std::vector< unsigned > MaxPressure
bool hasNextStage() const
GCNSchedStageID getCurrentStage()
SmallVectorImpl< GCNSchedStageID >::iterator CurrentStage
unsigned VGPRCriticalLimit
std::vector< unsigned > Pressure
void initialize(ScheduleDAGMI *DAG) override
Initialize the strategy after building the DAG for a new region.
const unsigned HighRPVGPRBias
void initCandidate(SchedCandidate &Cand, SUnit *SU, bool AtTop, const RegPressureTracker &RPTracker, const SIRegisterInfo *SRI, unsigned SGPRPressure, unsigned VGPRPressure, bool IsBottomUp)
unsigned getTargetOccupancy()
SUnit * pickNode(bool &IsTopNode) override
Pick the best node to balance the schedule. Implements MachineSchedStrategy.
GCNSchedStageID getNextStage() const
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
GCNScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
unsigned getAddressableNumArchVGPRs() const
bool hasGFX90AInsts() const
unsigned computeOccupancy(const Function &F, unsigned LDSSize=0, unsigned NumSGPRs=0, unsigned NumVGPRs=0) const
Return occupancy for the given function.
const SIInstrInfo * getInstrInfo() const override
unsigned getMaxNumVGPRs(unsigned WavesPerEU) const
unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const
Return the maximum number of waves per SIMD for kernels using VGPRs VGPRs.
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const
Return the maximum number of waves per SIMD for kernels using SGPRs SGPRs.
unsigned getMaxNumSGPRs(unsigned WavesPerEU, bool Addressable) const
void traceCandidate(const SchedCandidate &Cand)
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 outsi...
const TargetSchedModel * SchedModel
const MachineSchedContext * Context
const TargetRegisterInfo * TRI
GenericScheduler shrinks the unscheduled zone using heuristics to balance the schedule.
SchedCandidate BotCand
Candidate last picked from Bot boundary.
SchedCandidate TopCand
Candidate last picked from Top boundary.
MachineSchedPolicy RegionPolicy
virtual bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand, SchedBoundary *Zone) const
Apply a set of heuristics to a new candidate.
void initialize(ScheduleDAGMI *dag) override
Initialize the strategy after building the DAG for a new region.
bool shouldRevertScheduling(unsigned WavesAfter) override
bool hasInterval(Register Reg) const
SlotIndex InsertMachineInstrInMaps(MachineInstr &MI)
void handleMove(MachineInstr &MI, bool UpdateFlags=false)
Call this method to notify LiveIntervals that instruction MI has been moved within a basic block.
SlotIndexes * getSlotIndexes() const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
void removeInterval(Register Reg)
Interval removal.
LiveInterval & createAndComputeVirtRegInterval(Register Reg)
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
succ_iterator succ_begin()
MachineInstr * remove(MachineInstr *I)
Remove the unbundled instruction from the instruction list without deleting it.
unsigned succ_size() const
MachineInstrBundleIterator< MachineInstr > iterator
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
iterator_range< mop_iterator > operands()
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
void clearRegisterDeads(Register Reg)
Clear all dead flags on operands defining register Reg.
MachineOperand class - Representation of each machine instruction operand.
bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
MachineOperand * getOneDef(Register Reg) const
Returns the defining operand if there is exactly one operand defining the specified register,...
use_instr_nodbg_iterator use_instr_nodbg_begin(Register RegNo) const
bool hasOneDef(Register RegNo) const
Return true if there is exactly one operand defining the specified register.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
bool shouldRevertScheduling(unsigned WavesAfter) override
bool shouldRevertScheduling(unsigned WavesAfter) override
bool initGCNRegion() override
bool initGCNSchedStage() override
Capture a change in pressure for a single pressure set.
Helpers for implementing custom MachineSchedStrategy classes.
Track the current register pressure at some position in the instruction stream, and remember the high...
void advance()
Advance across the current instruction.
void getDownwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction top-down.
const std::vector< unsigned > & getRegSetPressureAtPos() const
Get the register set pressure at the current position, which may be less than the pressure across the...
void getUpwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction bottom-up.
unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const
getNumAllocatableRegs - Returns the number of actually allocatable registers in RC in the current fun...
List of registers defined and used by a machine instruction.
void collect(const MachineInstr &MI, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, bool TrackLaneMasks, bool IgnoreDead)
Analyze the given instruction MI and fill in the Uses, Defs and DeadDefs list based on the MachineOpe...
void adjustLaneLiveness(const LiveIntervals &LIS, const MachineRegisterInfo &MRI, SlotIndex Pos, MachineInstr *AddFlagsMI=nullptr)
Use liveness information to find out which uses/defs are partially undefined/dead and adjust the Regi...
void detectDeadDefs(const MachineInstr &MI, const LiveIntervals &LIS)
Use liveness information to find dead defs not marked with a dead flag and move them to the DeadDefs ...
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
const TargetSchedModel & getSchedModel() const
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
unsigned getOccupancy() const
void increaseOccupancy(const MachineFunction &MF, unsigned Limit)
unsigned getMaxWavesPerEU() const
unsigned getMinWavesPerEU() const
unsigned getMinAllowedOccupancy() const
void limitOccupancy(const MachineFunction &MF)
static unsigned getNumCoveredRegs(LaneBitmask LM)
static bool isVGPRClass(const TargetRegisterClass *RC)
Scheduling unit. This is a node in the scheduling DAG.
bool isInstr() const
Returns true if this SUnit refers to a machine instruction as opposed to an SDNode.
unsigned NodeNum
Entry # of node in the node vector.
bool isScheduled
True once scheduled.
bool isBottomReady() const
SmallVector< SDep, 4 > Preds
All sunit predecessors.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
Each Scheduling boundary is associated with ready queues.
unsigned getLatencyStallCycles(SUnit *SU)
Get the difference between the given SUnit's ready time and the current cycle.
SUnit * pickOnlyChoice()
Call this before applying any other heuristics to the Available queue.
void removeReady(SUnit *SU)
Remove SU from the ready set for this boundary.
A ScheduleDAG for scheduling lists of MachineInstr.
MachineBasicBlock::iterator end() const
Returns an iterator to the bottom of the current scheduling region.
MachineBasicBlock * BB
The block in which to insert instructions.
MachineBasicBlock::iterator RegionEnd
The end of the range to be scheduled.
virtual void finalizeSchedule()
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
MachineBasicBlock::iterator begin() const
Returns an iterator to the top of the current scheduling region.
SUnit * getSUnit(MachineInstr *MI) const
Returns an existing SUnit for this MI, or nullptr.
virtual void exitRegion()
Called when the scheduler has finished scheduling the current region.
MachineBasicBlock::iterator RegionBegin
The beginning of the range to be scheduled.
unsigned NumRegionInstrs
Instructions in this region (distance(RegionBegin, RegionEnd)).
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
PressureDiff & getPressureDiff(const SUnit *SU)
void enterRegion(MachineBasicBlock *bb, MachineBasicBlock::iterator begin, MachineBasicBlock::iterator end, unsigned regioninstrs) override
Implement the ScheduleDAGInstrs interface for handling the next scheduling region.
bool ShouldTrackLaneMasks
const RegPressureTracker & getBotRPTracker() const
bool isTrackingPressure() const
Return true if register pressure tracking is enabled.
const RegPressureTracker & getTopRPTracker() const
RegPressureTracker RPTracker
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
void startBlock(MachineBasicBlock *bb) override
Prepares to perform scheduling in the given block.
void addMutation(std::unique_ptr< ScheduleDAGMutation > Mutation)
Add a postprocessing step to the DAG builder.
MachineBasicBlock::iterator top() const
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
MachineBasicBlock::iterator bottom() const
void finishBlock() override
Cleans up after scheduling in the given block.
const SUnit * getNextClusterPred() const
void placeDebugValues()
Reinsert debug_values recorded in ScheduleDAGInstrs::DbgValues.
const SUnit * getNextClusterSucc() const
std::vector< std::unique_ptr< ScheduleDAGMutation > > Mutations
Ordered list of DAG postprocessing steps.
MachineRegisterInfo & MRI
Virtual/real register map.
const TargetInstrInfo * TII
Target instruction information.
std::vector< SUnit > SUnits
The scheduling units.
const TargetRegisterInfo * TRI
Target processor register info.
MachineFunction & MF
Machine function.
static const unsigned ScaleFactor
unsigned getMetric() const
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
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.
bool isTriviallyReMaterializable(const MachineInstr &MI) const
Return true if the instruction is trivially rematerializable, meaning it has no side effects and requ...
Provide an instruction scheduling machine model to CodeGen passes.
virtual const TargetInstrInfo * getInstrInfo() const
bool initGCNSchedStage() override
bool initGCNRegion() override
void finalizeGCNSchedStage() override
bool shouldRevertScheduling(unsigned WavesAfter) override
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getAddressableNumVGPRs(const MCSubtargetInfo *STI)
unsigned getVGPRAllocGranule(const MCSubtargetInfo *STI, std::optional< bool > EnableWavefrontSize32)
@ C
The default llvm calling convention, compatible with C.
Reg
All possible values of the reg field in the ModR/M byte.
initializer< Ty > init(const Ty &Val)
NodeAddr< DefNode * > Def
This is an optimization pass for GlobalISel generic memory operations.
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
unsigned getWeakLeft(const SUnit *SU, bool isTop)
GCNRegPressure getRegPressure(const MachineRegisterInfo &MRI, Range &&LiveRegs)
std::unique_ptr< ScheduleDAGMutation > createIGroupLPDAGMutation(AMDGPU::SchedulingPhase Phase)
Phase specifes whether or not this is a reentry into the IGroupLPDAGMutation.
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
cl::opt< bool > VerifyScheduling
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool tryPressure(const PressureChange &TryP, const PressureChange &CandP, GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, GenericSchedulerBase::CandReason Reason, const TargetRegisterInfo *TRI, const MachineFunction &MF)
@ UnclusteredHighRPReschedule
@ ClusteredLowOccupancyReschedule
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool tryLatency(GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, SchedBoundary &Zone)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool tryGreater(int TryVal, int CandVal, GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, GenericSchedulerBase::CandReason Reason)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
DenseMap< MachineInstr *, GCNRPTracker::LiveRegSet > getLiveRegMap(Range &&R, bool After, LiveIntervals &LIS)
creates a map MachineInstr -> LiveRegSet R - range of iterators on instructions After - upon entry or...
GCNRPTracker::LiveRegSet getLiveRegsBefore(const MachineInstr &MI, const LiveIntervals &LIS)
bool tryLess(int TryVal, int CandVal, GenericSchedulerBase::SchedCandidate &TryCand, GenericSchedulerBase::SchedCandidate &Cand, GenericSchedulerBase::CandReason Reason)
Return true if this heuristic determines order.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
int biasPhysReg(const SUnit *SU, bool isTop)
Minimize physical register live ranges.
Implement std::hash so that hash_code can be used in STL containers.
bool operator()(std::pair< MachineInstr *, unsigned > A, std::pair< MachineInstr *, unsigned > B) const
unsigned getOccupancy(const GCNSubtarget &ST) const
unsigned getVGPRNum(bool UnifiedVGPRFile) const
unsigned getAGPRNum() const
unsigned getSGPRNum() const
bool less(const MachineFunction &MF, const GCNRegPressure &O, unsigned MaxOccupancy=std::numeric_limits< unsigned >::max()) const
Compares this GCNRegpressure to O, returning true if this is less.
Policy for scheduling the next instruction in the candidate's zone.
Store the state used by GenericScheduler heuristics, required for the lifetime of one invocation of p...
void setBest(SchedCandidate &Best)
void reset(const CandPolicy &NewPolicy)
void initResourceDelta(const ScheduleDAGMI *DAG, const TargetSchedModel *SchedModel)
SchedResourceDelta ResDelta
Status of an instruction's critical resource consumption.
unsigned DemandedResources
static constexpr LaneBitmask getNone()
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
RegisterClassInfo * RegClassInfo
PressureChange CriticalMax
PressureChange CurrentMax