15 #ifndef LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H 16 #define LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H 66 std::vector<SUnit*> SUnits;
67 std::map<unsigned, unsigned> NodeNum2Index;
68 std::vector<SUnit*> TopReadySUs;
69 std::vector<SUnit*> ScheduledSUnits;
79 std::vector<unsigned> InternalAdditionnalPressure;
81 std::vector<unsigned> LiveInPressure;
82 std::vector<unsigned> LiveOutPressure;
88 std::set<unsigned> LiveInRegs;
89 std::set<unsigned> LiveOutRegs;
91 bool Scheduled =
false;
92 bool HighLatencyBlock =
false;
94 std::vector<unsigned> HasLowLatencyNonWaitedParent;
99 std::vector<SIScheduleBlock*> Preds;
101 std::vector<std::pair<SIScheduleBlock*, SIScheduleBlockLinkKind>> Succs;
102 unsigned NumHighLatencySuccessors = 0;
107 DAG(DAG), BC(BC), TopRPTracker(TopPressure), ID(ID) {}
114 void addUnit(
SUnit *SU);
117 void finalizeUnits();
123 const std::vector<SIScheduleBlock*>&
getPreds()
const {
return Preds; }
131 return NumHighLatencySuccessors;
161 return InternalAdditionnalPressure;
167 void printDebug(
bool Full);
177 unsigned LowLatencyOffset;
178 bool HasLowLatencyNonWaitedParent;
180 SISchedCandidate() =
default;
182 bool isValid()
const {
return SU; }
185 void setBest(SISchedCandidate &Best) {
186 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
189 SGPRUsage = Best.SGPRUsage;
190 VGPRUsage = Best.VGPRUsage;
191 IsLowLatency = Best.IsLowLatency;
192 LowLatencyOffset = Best.LowLatencyOffset;
193 HasLowLatencyNonWaitedParent = Best.HasLowLatencyNonWaitedParent;
199 void undoReleaseSucc(
SUnit *SU,
SDep *SuccEdge);
200 void releaseSucc(
SUnit *SU,
SDep *SuccEdge);
203 void releaseSuccessors(
SUnit *SU,
bool InOrOutBlock);
205 void nodeScheduled(
SUnit *SU);
206 void tryCandidateTopDown(SISchedCandidate &Cand, SISchedCandidate &TryCand);
207 void tryCandidateBottomUp(SISchedCandidate &Cand, SISchedCandidate &TryCand);
209 void traceCandidate(
const SISchedCandidate &Cand);
229 std::vector<std::unique_ptr<SIScheduleBlock>> BlockPtrs;
232 std::vector<SIScheduleBlock*> CurrentBlocks;
233 std::vector<int> Node2CurrentBlock;
237 std::vector<int> TopDownIndex2Block;
238 std::vector<int> TopDownBlock2Index;
239 std::vector<int> BottomUpIndex2Block;
245 int NextNonReservedID;
246 std::vector<int> CurrentColoring;
247 std::vector<int> CurrentTopDownReservedDependencyColoring;
248 std::vector<int> CurrentBottomUpReservedDependencyColoring;
255 getBlocks(SISchedulerBlockCreatorVariant BlockVariant);
257 bool isSUInBlock(
SUnit *SU,
unsigned ID);
261 void colorHighLatenciesAlone();
264 void colorHighLatenciesGroups();
268 void colorComputeReservedDependencies();
271 void colorAccordingToReservedDependencies();
276 void colorEndsAccordingToDependencies();
279 void colorForceConsecutiveOrderInGroup();
283 void colorMergeConstantLoadsNextGroup();
286 void colorMergeIfPossibleNextGroup();
290 void colorMergeIfPossibleNextGroupOnlyForReserved();
294 void colorMergeIfPossibleSmallGroupsToNextGroup();
299 void cutHugeBlocks();
303 void regroupNoUserInstructions();
308 void createBlocksForVariant(SISchedulerBlockCreatorVariant BlockVariant);
310 void topologicalSort();
312 void scheduleInsideBlocks();
326 std::vector<SIScheduleBlock*> Blocks;
328 std::vector<std::map<unsigned, unsigned>> LiveOutRegsNumUsages;
329 std::set<unsigned> LiveRegs;
331 std::map<unsigned, unsigned> LiveRegsConsumers;
333 std::vector<unsigned> LastPosHighLatencyParentScheduled;
334 int LastPosWaitedHighLatency;
336 std::vector<SIScheduleBlock*> BlocksScheduled;
337 unsigned NumBlockScheduled;
338 std::vector<SIScheduleBlock*> ReadyBlocks;
340 unsigned VregCurrentUsage;
341 unsigned SregCurrentUsage;
344 unsigned maxVregUsage;
345 unsigned maxSregUsage;
347 std::vector<unsigned> BlockNumPredsLeft;
348 std::vector<unsigned> BlockNumSuccsLeft;
356 std::vector<SIScheduleBlock*>
getBlocks() {
return BlocksScheduled; }
368 unsigned NumSuccessors;
369 unsigned NumHighLatencySuccessors;
370 unsigned LastPosHighLatParentScheduled;
373 SIBlockSchedCandidate() =
default;
375 bool isValid()
const {
return Block; }
378 void setBest(SIBlockSchedCandidate &Best) {
379 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
382 IsHighLatency = Best.IsHighLatency;
383 VGPRUsageDiff = Best.VGPRUsageDiff;
384 NumSuccessors = Best.NumSuccessors;
385 NumHighLatencySuccessors = Best.NumHighLatencySuccessors;
386 LastPosHighLatParentScheduled = Best.LastPosHighLatParentScheduled;
387 Height = Best.Height;
391 bool tryCandidateLatency(SIBlockSchedCandidate &Cand,
392 SIBlockSchedCandidate &TryCand);
393 bool tryCandidateRegUsage(SIBlockSchedCandidate &Cand,
394 SIBlockSchedCandidate &TryCand);
397 void addLiveRegs(std::set<unsigned> &Regs);
398 void decreaseLiveRegs(
SIScheduleBlock *Block, std::set<unsigned> &Regs);
404 std::vector<int> checkRegUsageImpact(std::set<unsigned> &InRegs,
405 std::set<unsigned> &OutRegs);
411 std::vector<unsigned>
SUs;
426 scheduleVariant(SISchedulerBlockCreatorVariant BlockVariant,
427 SISchedulerBlockSchedulerVariant ScheduleVariant);
434 std::vector<SUnit> SUnitsLinksBackup;
437 std::vector<unsigned> ScheduledSUnits;
438 std::vector<unsigned> ScheduledSUnitsInv;
449 void schedule()
override;
453 RPTracker.
init(&MF, RegClassInfo, LIS, BB, RegionBegin,
false,
false);
466 void restoreSULinksLeft();
468 template<
typename _Iterator>
void fillVgprSgprCost(_Iterator First,
471 unsigned &SgprUsage);
474 std::set<unsigned> InRegs;
475 for (
const auto &RegMaskPair : RPTracker.getPressure().LiveInRegs) {
476 InRegs.insert(RegMaskPair.RegUnit);
482 std::set<unsigned> OutRegs;
483 for (
const auto &RegMaskPair : RPTracker.getPressure().LiveOutRegs) {
484 OutRegs.insert(RegMaskPair.RegUnit);
493 void topologicalSort();
495 void moveLowLatencies();
510 #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.