14#ifndef LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H
15#define LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H
29class SIScheduleBlockCreator;
62 std::vector<SUnit*> SUnits;
63 std::map<unsigned, unsigned> NodeNum2Index;
64 std::vector<SUnit*> TopReadySUs;
65 std::vector<SUnit*> ScheduledSUnits;
75 std::vector<unsigned> InternalAdditionalPressure;
77 std::vector<unsigned> LiveInPressure;
78 std::vector<unsigned> LiveOutPressure;
84 std::set<unsigned> LiveInRegs;
85 std::set<unsigned> LiveOutRegs;
87 bool Scheduled =
false;
88 bool HighLatencyBlock =
false;
90 std::vector<unsigned> HasLowLatencyNonWaitedParent;
95 std::vector<SIScheduleBlock*> Preds;
97 std::vector<std::pair<SIScheduleBlock*, SIScheduleBlockLinkKind>> Succs;
98 unsigned NumHighLatencySuccessors = 0;
103 DAG(DAG), BC(BC), TopRPTracker(TopPressure),
ID(
ID) {}
119 const std::vector<SIScheduleBlock*>&
getPreds()
const {
return Preds; }
127 return NumHighLatencySuccessors;
157 return InternalAdditionalPressure;
173 unsigned LowLatencyOffset;
174 bool HasLowLatencyNonWaitedParent;
176 SISchedCandidate() =
default;
178 bool isValid()
const {
return SU; }
181 void setBest(SISchedCandidate &Best) {
182 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
185 SGPRUsage = Best.SGPRUsage;
186 VGPRUsage = Best.VGPRUsage;
187 IsLowLatency = Best.IsLowLatency;
188 LowLatencyOffset = Best.LowLatencyOffset;
189 HasLowLatencyNonWaitedParent = Best.HasLowLatencyNonWaitedParent;
195 void undoReleaseSucc(SUnit *SU, SDep *SuccEdge);
196 void releaseSucc(SUnit *SU, SDep *SuccEdge);
199 void releaseSuccessors(SUnit *SU,
bool InOrOutBlock);
201 void nodeScheduled(SUnit *SU);
202 void tryCandidateTopDown(SISchedCandidate &Cand, SISchedCandidate &TryCand);
203 void tryCandidateBottomUp(SISchedCandidate &Cand, SISchedCandidate &TryCand);
205 void traceCandidate(
const SISchedCandidate &Cand);
225 std::vector<std::unique_ptr<SIScheduleBlock>> BlockPtrs;
228 std::vector<SIScheduleBlock*> CurrentBlocks;
229 std::vector<int> Node2CurrentBlock;
233 std::vector<int> TopDownIndex2Block;
234 std::vector<int> TopDownBlock2Index;
235 std::vector<int> BottomUpIndex2Block;
241 int NextNonReservedID;
242 std::vector<int> CurrentColoring;
243 std::vector<int> CurrentTopDownReservedDependencyColoring;
244 std::vector<int> CurrentBottomUpReservedDependencyColoring;
256 void colorHighLatenciesAlone();
259 void colorHighLatenciesGroups();
263 void colorComputeReservedDependencies();
266 void colorAccordingToReservedDependencies();
271 void colorEndsAccordingToDependencies();
274 void colorForceConsecutiveOrderInGroup();
278 void colorMergeConstantLoadsNextGroup();
281 void colorMergeIfPossibleNextGroup();
285 void colorMergeIfPossibleNextGroupOnlyForReserved();
289 void colorMergeIfPossibleSmallGroupsToNextGroup();
294 void cutHugeBlocks();
298 void regroupNoUserInstructions();
305 void topologicalSort();
307 void scheduleInsideBlocks();
321 std::vector<SIScheduleBlock*> Blocks;
323 std::vector<std::map<unsigned, unsigned>> LiveOutRegsNumUsages;
324 std::set<unsigned> LiveRegs;
326 std::map<unsigned, unsigned> LiveRegsConsumers;
328 std::vector<unsigned> LastPosHighLatencyParentScheduled;
329 int LastPosWaitedHighLatency;
331 std::vector<SIScheduleBlock*> BlocksScheduled;
332 unsigned NumBlockScheduled;
333 std::vector<SIScheduleBlock*> ReadyBlocks;
335 unsigned VregCurrentUsage;
336 unsigned SregCurrentUsage;
339 unsigned maxVregUsage;
340 unsigned maxSregUsage;
342 std::vector<unsigned> BlockNumPredsLeft;
343 std::vector<unsigned> BlockNumSuccsLeft;
351 std::vector<SIScheduleBlock*>
getBlocks() {
return BlocksScheduled; }
363 unsigned NumSuccessors;
364 unsigned NumHighLatencySuccessors;
365 unsigned LastPosHighLatParentScheduled;
368 SIBlockSchedCandidate() =
default;
370 bool isValid()
const {
return Block; }
373 void setBest(SIBlockSchedCandidate &Best) {
374 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
377 IsHighLatency = Best.IsHighLatency;
378 VGPRUsageDiff = Best.VGPRUsageDiff;
379 NumSuccessors = Best.NumSuccessors;
380 NumHighLatencySuccessors = Best.NumHighLatencySuccessors;
381 LastPosHighLatParentScheduled = Best.LastPosHighLatParentScheduled;
382 Height = Best.Height;
386 bool tryCandidateLatency(SIBlockSchedCandidate &Cand,
387 SIBlockSchedCandidate &TryCand);
388 bool tryCandidateRegUsage(SIBlockSchedCandidate &Cand,
389 SIBlockSchedCandidate &TryCand);
390 SIScheduleBlock *pickBlock();
392 void addLiveRegs(std::set<unsigned> &Regs);
393 void decreaseLiveRegs(SIScheduleBlock *
Block, std::set<unsigned> &Regs);
394 void releaseBlockSuccs(SIScheduleBlock *Parent);
395 void blockScheduled(SIScheduleBlock *
Block);
399 std::vector<int> checkRegUsageImpact(std::set<unsigned> &InRegs,
400 std::set<unsigned> &OutRegs);
406 std::vector<unsigned>
SUs;
429 std::vector<SUnit> SUnitsLinksBackup;
432 std::vector<unsigned> ScheduledSUnits;
433 std::vector<unsigned> ScheduledSUnitsInv;
463 unsigned &SgprUsage);
466 std::set<unsigned> InRegs;
468 InRegs.insert(RegMaskPair.RegUnit);
474 std::set<unsigned> OutRegs;
476 OutRegs.insert(RegMaskPair.RegUnit);
482 void topologicalSort();
484 void moveLowLatencies();
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
MachineInstrBundleIterator< MachineInstr > iterator
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Track the current register pressure at some position in the instruction stream, and remember the high...
RegisterPressure & getPressure()
Get the resulting register pressure over the traversed region.
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.
bool isSUInBlock(SUnit *SU, unsigned ID)
SIScheduleBlocks getBlocks(SISchedulerBlockCreatorVariant BlockVariant)
~SIScheduleBlockScheduler()=default
std::vector< SIScheduleBlock * > getBlocks()
unsigned getNumHighLatencySuccessors() const
SIScheduleBlock(SIScheduleDAGMI *DAG, SIScheduleBlockCreator *BC, unsigned ID)
ArrayRef< std::pair< SIScheduleBlock *, SIScheduleBlockLinkKind > > getSuccs() const
std::set< unsigned > & getOutRegs()
std::set< unsigned > & getInRegs()
~SIScheduleBlock()=default
std::vector< unsigned > & getInternalAdditionalRegUsage()
const std::vector< SIScheduleBlock * > & getPreds() const
void addPred(SIScheduleBlock *Pred)
void printDebug(bool Full)
std::vector< SUnit * > getScheduledUnits()
void addSucc(SIScheduleBlock *Succ, SIScheduleBlockLinkKind Kind)
void schedule(MachineBasicBlock::iterator BeginBlock, MachineBasicBlock::iterator EndBlock)
void addUnit(SUnit *SU)
Functions for Block construction.
bool isHighLatencyBlock()
void restoreSULinksLeft()
std::vector< int > BottomUpIndex2SU
std::vector< unsigned > IsHighLatencySU
std::vector< unsigned > LowLatencyOffset
std::vector< int > TopDownIndex2SU
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
ScheduleDAGTopologicalSort * GetTopo()
void fillVgprSgprCost(_Iterator First, _Iterator End, unsigned &VgprUsage, unsigned &SgprUsage)
MachineRegisterInfo * getMRI()
MachineBasicBlock::iterator getCurrentBottom()
std::vector< unsigned > IsLowLatencySU
MachineBasicBlock::iterator getCurrentTop()
std::set< unsigned > getInRegs()
MachineBasicBlock * getBB()
void initRPTracker(RegPressureTracker &RPTracker)
std::set< unsigned > getOutRegs()
~SIScheduleDAGMI() override
const TargetRegisterInfo * getTRI()
struct SIScheduleBlockResult scheduleVariant(SISchedulerBlockCreatorVariant BlockVariant, SISchedulerBlockSchedulerVariant ScheduleVariant)
SIScheduler(SIScheduleDAGMI *DAG)
Scheduling unit. This is a node in the scheduling DAG.
MachineBasicBlock * BB
The block in which to insert instructions.
ScheduleDAGTopologicalSort Topo
Topo - A topological ordering for SUnits which permits fast IsReachable and similar queries.
MachineBasicBlock::iterator RegionBegin
The beginning of the range to be scheduled.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
RegisterClassInfo * RegClassInfo
RegPressureTracker RPTracker
MachineBasicBlock::iterator CurrentBottom
The bottom of the unscheduled zone.
MachineBasicBlock::iterator CurrentTop
The top of the unscheduled zone.
This class can compute a topological ordering for SUnits and provides methods for dynamically updatin...
MachineRegisterInfo & MRI
Virtual/real register map.
const TargetRegisterInfo * TRI
Target processor register info.
SUnit EntrySU
Special node for the region entry.
MachineFunction & MF
Machine function.
SUnit ExitSU
Special node for the region exit.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
SISchedulerBlockSchedulerVariant
SISchedulerBlockCreatorVariant
@ LatenciesAlonePlusConsecutive
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx.
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
SmallVector< RegisterMaskPair, 8 > LiveInRegs
List of live in virtual registers or physical register units.
SmallVector< RegisterMaskPair, 8 > LiveOutRegs
std::vector< unsigned > SUs
std::vector< int > TopDownIndex2Block
std::vector< SIScheduleBlock * > Blocks
std::vector< int > TopDownBlock2Index
SISchedulerCandidate()=default
SIScheduleCandReason Reason
bool isRepeat(SIScheduleCandReason R)
void setRepeat(SIScheduleCandReason R)