14 #ifndef LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H 15 #define LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H 65 std::vector<SUnit*> SUnits;
66 std::map<unsigned, unsigned> NodeNum2Index;
67 std::vector<SUnit*> TopReadySUs;
68 std::vector<SUnit*> ScheduledSUnits;
78 std::vector<unsigned> InternalAdditionnalPressure;
80 std::vector<unsigned> LiveInPressure;
81 std::vector<unsigned> LiveOutPressure;
87 std::set<unsigned> LiveInRegs;
88 std::set<unsigned> LiveOutRegs;
90 bool Scheduled =
false;
91 bool HighLatencyBlock =
false;
93 std::vector<unsigned> HasLowLatencyNonWaitedParent;
98 std::vector<SIScheduleBlock*> Preds;
100 std::vector<std::pair<SIScheduleBlock*, SIScheduleBlockLinkKind>> Succs;
101 unsigned NumHighLatencySuccessors = 0;
106 DAG(DAG), BC(BC), TopRPTracker(TopPressure), ID(ID) {}
113 void addUnit(
SUnit *SU);
116 void finalizeUnits();
122 const std::vector<SIScheduleBlock*>&
getPreds()
const {
return Preds; }
130 return NumHighLatencySuccessors;
160 return InternalAdditionnalPressure;
166 void printDebug(
bool Full);
176 unsigned LowLatencyOffset;
177 bool HasLowLatencyNonWaitedParent;
179 SISchedCandidate() =
default;
181 bool isValid()
const {
return SU; }
184 void setBest(SISchedCandidate &Best) {
185 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
188 SGPRUsage = Best.SGPRUsage;
189 VGPRUsage = Best.VGPRUsage;
190 IsLowLatency = Best.IsLowLatency;
191 LowLatencyOffset = Best.LowLatencyOffset;
192 HasLowLatencyNonWaitedParent = Best.HasLowLatencyNonWaitedParent;
198 void undoReleaseSucc(
SUnit *SU,
SDep *SuccEdge);
199 void releaseSucc(
SUnit *SU,
SDep *SuccEdge);
202 void releaseSuccessors(
SUnit *SU,
bool InOrOutBlock);
204 void nodeScheduled(
SUnit *SU);
205 void tryCandidateTopDown(SISchedCandidate &Cand, SISchedCandidate &TryCand);
206 void tryCandidateBottomUp(SISchedCandidate &Cand, SISchedCandidate &TryCand);
208 void traceCandidate(
const SISchedCandidate &Cand);
228 std::vector<std::unique_ptr<SIScheduleBlock>> BlockPtrs;
231 std::vector<SIScheduleBlock*> CurrentBlocks;
232 std::vector<int> Node2CurrentBlock;
236 std::vector<int> TopDownIndex2Block;
237 std::vector<int> TopDownBlock2Index;
238 std::vector<int> BottomUpIndex2Block;
244 int NextNonReservedID;
245 std::vector<int> CurrentColoring;
246 std::vector<int> CurrentTopDownReservedDependencyColoring;
247 std::vector<int> CurrentBottomUpReservedDependencyColoring;
253 getBlocks(SISchedulerBlockCreatorVariant BlockVariant);
255 bool isSUInBlock(
SUnit *SU,
unsigned ID);
259 void colorHighLatenciesAlone();
262 void colorHighLatenciesGroups();
266 void colorComputeReservedDependencies();
269 void colorAccordingToReservedDependencies();
274 void colorEndsAccordingToDependencies();
277 void colorForceConsecutiveOrderInGroup();
281 void colorMergeConstantLoadsNextGroup();
284 void colorMergeIfPossibleNextGroup();
288 void colorMergeIfPossibleNextGroupOnlyForReserved();
292 void colorMergeIfPossibleSmallGroupsToNextGroup();
297 void cutHugeBlocks();
301 void regroupNoUserInstructions();
306 void createBlocksForVariant(SISchedulerBlockCreatorVariant BlockVariant);
308 void topologicalSort();
310 void scheduleInsideBlocks();
324 std::vector<SIScheduleBlock*> Blocks;
326 std::vector<std::map<unsigned, unsigned>> LiveOutRegsNumUsages;
327 std::set<unsigned> LiveRegs;
329 std::map<unsigned, unsigned> LiveRegsConsumers;
331 std::vector<unsigned> LastPosHighLatencyParentScheduled;
332 int LastPosWaitedHighLatency;
334 std::vector<SIScheduleBlock*> BlocksScheduled;
335 unsigned NumBlockScheduled;
336 std::vector<SIScheduleBlock*> ReadyBlocks;
338 unsigned VregCurrentUsage;
339 unsigned SregCurrentUsage;
342 unsigned maxVregUsage;
343 unsigned maxSregUsage;
345 std::vector<unsigned> BlockNumPredsLeft;
346 std::vector<unsigned> BlockNumSuccsLeft;
354 std::vector<SIScheduleBlock*>
getBlocks() {
return BlocksScheduled; }
366 unsigned NumSuccessors;
367 unsigned NumHighLatencySuccessors;
368 unsigned LastPosHighLatParentScheduled;
371 SIBlockSchedCandidate() =
default;
373 bool isValid()
const {
return Block; }
376 void setBest(SIBlockSchedCandidate &Best) {
377 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
380 IsHighLatency = Best.IsHighLatency;
381 VGPRUsageDiff = Best.VGPRUsageDiff;
382 NumSuccessors = Best.NumSuccessors;
383 NumHighLatencySuccessors = Best.NumHighLatencySuccessors;
384 LastPosHighLatParentScheduled = Best.LastPosHighLatParentScheduled;
385 Height = Best.Height;
389 bool tryCandidateLatency(SIBlockSchedCandidate &Cand,
390 SIBlockSchedCandidate &TryCand);
391 bool tryCandidateRegUsage(SIBlockSchedCandidate &Cand,
392 SIBlockSchedCandidate &TryCand);
395 void addLiveRegs(std::set<unsigned> &Regs);
396 void decreaseLiveRegs(
SIScheduleBlock *Block, std::set<unsigned> &Regs);
402 std::vector<int> checkRegUsageImpact(std::set<unsigned> &InRegs,
403 std::set<unsigned> &OutRegs);
409 std::vector<unsigned>
SUs;
424 scheduleVariant(SISchedulerBlockCreatorVariant BlockVariant,
425 SISchedulerBlockSchedulerVariant ScheduleVariant);
432 std::vector<SUnit> SUnitsLinksBackup;
435 std::vector<unsigned> ScheduledSUnits;
436 std::vector<unsigned> ScheduledSUnitsInv;
447 void schedule()
override;
451 RPTracker.
init(&MF, RegClassInfo, LIS, BB, RegionBegin,
false,
false);
464 void restoreSULinksLeft();
466 template<
typename _Iterator>
void fillVgprSgprCost(_Iterator First,
469 unsigned &SgprUsage);
472 std::set<unsigned> InRegs;
473 for (
const auto &RegMaskPair : RPTracker.getPressure().LiveInRegs) {
474 InRegs.insert(RegMaskPair.RegUnit);
480 std::set<unsigned> OutRegs;
481 for (
const auto &RegMaskPair : RPTracker.getPressure().LiveOutRegs) {
482 OutRegs.insert(RegMaskPair.RegUnit);
491 void topologicalSort();
493 void moveLowLatencies();
508 #endif // LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H
std::vector< SIScheduleBlock * > Blocks
This class represents lattice values for constants.
SIScheduleCandReason Reason
std::vector< unsigned > & getInternalAdditionnalRegUsage()
std::vector< unsigned > IsLowLatencySU
std::vector< SIScheduleBlock * > getBlocks()
unsigned getSGPRSetID() const
unsigned const TargetRegisterInfo * TRI
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
std::vector< unsigned > LowLatencyOffset
ArrayRef< std::pair< SIScheduleBlock *, SIScheduleBlockLinkKind > > getSuccs() const
std::set< unsigned > getOutRegs()
std::set< unsigned > getInRegs()
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isRepeat(SIScheduleCandReason R)
std::vector< int > TopDownIndex2Block
unsigned const MachineRegisterInfo * MRI
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx...
std::vector< int > TopDownIndex2SU
std::vector< SUnit * > getScheduledUnits()
MachineRegisterInfo * getMRI()
MachineBasicBlock * getBB()
Track the current register pressure at some position in the instruction stream, and remember the high...
const TargetRegisterInfo * getTRI()
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MachineBasicBlock::iterator getCurrentBottom()
std::set< unsigned > & getOutRegs()
SISchedulerCandidate()=default
SIScheduleBlock(SIScheduleDAGMI *DAG, SIScheduleBlockCreator *BC, unsigned ID)
std::vector< unsigned > IsHighLatencySU
std::vector< unsigned > SUs
SISchedulerBlockCreatorVariant
MachineBasicBlock::iterator getCurrentTop()
bool isHighLatencyBlock()
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
ScheduleDAGTopologicalSort * GetTopo()
Interface definition for SIInstrInfo.
std::vector< int > BottomUpIndex2SU
SIScheduler(SIScheduleDAGMI *DAG)
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
void init(const MachineFunction *mf, const RegisterClassInfo *rci, const LiveIntervals *lis, const MachineBasicBlock *mbb, MachineBasicBlock::const_iterator pos, bool TrackLaneMasks, bool TrackUntiedDefs)
Setup the RegPressureTracker.
void initRPTracker(RegPressureTracker &RPTracker)
std::set< unsigned > & getInRegs()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumHighLatencySuccessors() const
std::vector< int > TopDownBlock2Index
const std::vector< SIScheduleBlock * > & getPreds() const
void setRepeat(SIScheduleCandReason R)
This class can compute a topological ordering for SUnits and provides methods for dynamically updatin...
unsigned getVGPRSetID() const
SISchedulerBlockSchedulerVariant
Scheduling unit. This is a node in the scheduling DAG.