15 #ifndef LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H
16 #define LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H
54 class SIScheduleDAGMI;
55 class SIScheduleBlockCreator;
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) {}
111 unsigned getID()
const {
return ID; }
123 const std::vector<SIScheduleBlock*>&
getPreds()
const {
return Preds; }
131 return NumHighLatencySuccessors;
161 return InternalAdditionnalPressure;
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");
188 Reason = Best.Reason;
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;
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();
307 void topologicalSort();
309 void scheduleInsideBlocks();
323 std::vector<SIScheduleBlock*> Blocks;
325 std::vector<std::map<unsigned, unsigned>> LiveOutRegsNumUsages;
326 std::set<unsigned> LiveRegs;
328 std::map<unsigned, unsigned> LiveRegsConsumers;
330 std::vector<unsigned> LastPosHighLatencyParentScheduled;
331 int LastPosWaitedHighLatency;
333 std::vector<SIScheduleBlock*> BlocksScheduled;
334 unsigned NumBlockScheduled;
335 std::vector<SIScheduleBlock*> ReadyBlocks;
337 unsigned VregCurrentUsage;
338 unsigned SregCurrentUsage;
341 unsigned maxVregUsage;
342 unsigned maxSregUsage;
344 std::vector<unsigned> BlockNumPredsLeft;
345 std::vector<unsigned> BlockNumSuccsLeft;
353 std::vector<SIScheduleBlock*>
getBlocks() {
return BlocksScheduled; }
365 unsigned NumSuccessors;
366 unsigned NumHighLatencySuccessors;
367 unsigned LastPosHighLatParentScheduled;
370 SIBlockSchedCandidate() =
default;
372 bool isValid()
const {
return Block; }
375 void setBest(SIBlockSchedCandidate &Best) {
376 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
378 Reason = Best.Reason;
379 IsHighLatency = Best.IsHighLatency;
380 VGPRUsageDiff = Best.VGPRUsageDiff;
381 NumSuccessors = Best.NumSuccessors;
382 NumHighLatencySuccessors = Best.NumHighLatencySuccessors;
383 LastPosHighLatParentScheduled = Best.LastPosHighLatParentScheduled;
384 Height = Best.Height;
388 bool tryCandidateLatency(SIBlockSchedCandidate &Cand,
389 SIBlockSchedCandidate &TryCand);
390 bool tryCandidateRegUsage(SIBlockSchedCandidate &Cand,
391 SIBlockSchedCandidate &TryCand);
392 SIScheduleBlock *pickBlock();
394 void addLiveRegs(std::set<unsigned> &
Regs);
395 void decreaseLiveRegs(SIScheduleBlock *Block, std::set<unsigned> &
Regs);
396 void releaseBlockSuccs(SIScheduleBlock *Parent);
397 void blockScheduled(SIScheduleBlock *Block);
401 std::vector<int> checkRegUsageImpact(std::set<unsigned> &InRegs,
402 std::set<unsigned> &OutRegs);
408 std::vector<unsigned>
SUs;
431 std::vector<SUnit> SUnitsLinksBackup;
434 std::vector<unsigned> ScheduledSUnits;
435 std::vector<unsigned> ScheduledSUnitsInv;
468 unsigned &SgprUsage);
471 std::set<unsigned> InRegs;
473 InRegs.insert(RegMaskPair.RegUnit);
479 std::set<unsigned> OutRegs;
481 OutRegs.insert(RegMaskPair.RegUnit);
490 void topologicalSort();
492 void moveLowLatencies();
507 #endif // LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H
std::vector< SIScheduleBlock * > Blocks
SIScheduleDAGMI(MachineSchedContext *C)
unsigned getNumHighLatencySuccessors() const
ScheduleDAGTopologicalSort Topo
Topo - A topological ordering for SUnits which permits fast IsReachable and similar queries...
MachineBasicBlock::iterator CurrentTop
The top of the unscheduled zone.
SIScheduleCandReason Reason
std::vector< unsigned > & getInternalAdditionnalRegUsage()
std::vector< unsigned > IsLowLatencySU
void addUnit(SUnit *SU)
Functions for Block construction.
std::vector< SIScheduleBlock * > getBlocks()
~SIScheduleBlockScheduler()=default
RegisterClassInfo * RegClassInfo
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
MachineFunction & MF
Machine function.
std::vector< unsigned > LowLatencyOffset
~SIScheduleBlock()=default
ArrayRef< std::pair< SIScheduleBlock *, SIScheduleBlockLinkKind > > getSuccs() const
std::set< unsigned > getOutRegs()
std::set< unsigned > getInRegs()
MachineBasicBlock::iterator RegionBegin
The beginning of the range to be scheduled.
SmallVector< RegisterMaskPair, 8 > LiveInRegs
List of live in virtual registers or physical register units.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
bool isRepeat(SIScheduleCandReason R)
unsigned getSGPRSetID() const
std::vector< int > TopDownIndex2Block
struct SIScheduleBlockResult scheduleVariant(SISchedulerBlockCreatorVariant BlockVariant, SISchedulerBlockSchedulerVariant ScheduleVariant)
void printDebug(bool Full)
SmallVector< RegisterMaskPair, 8 > LiveOutRegs
MachineInstrBundleIterator< MachineInstr > iterator
~SIScheduleDAGMI() override
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx...
bool isSUInBlock(SUnit *SU, unsigned ID)
std::vector< int > TopDownIndex2SU
std::vector< SUnit * > getScheduledUnits()
SIScheduleBlockScheduler(SIScheduleDAGMI *DAG, SISchedulerBlockSchedulerVariant Variant, SIScheduleBlocks BlocksStruct)
void addSucc(SIScheduleBlock *Succ, SIScheduleBlockLinkKind Kind)
MachineRegisterInfo * getMRI()
MachineBasicBlock * getBB()
static const unsigned End
Track the current register pressure at some position in the instruction stream, and remember the high...
const TargetRegisterInfo * getTRI()
SIScheduleBlocks getBlocks(SISchedulerBlockCreatorVariant BlockVariant)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MachineBasicBlock::iterator getCurrentBottom()
void schedule(MachineBasicBlock::iterator BeginBlock, MachineBasicBlock::iterator EndBlock)
std::set< unsigned > & getOutRegs()
SISchedulerCandidate()=default
SIScheduleBlock(SIScheduleDAGMI *DAG, SIScheduleBlockCreator *BC, unsigned ID)
std::vector< unsigned > IsHighLatencySU
std::vector< unsigned > SUs
SISchedulerBlockCreatorVariant
SIScheduleBlockCreator(SIScheduleDAGMI *DAG)
MachineBasicBlock::iterator getCurrentTop()
void fillVgprSgprCost(_Iterator First, _Iterator End, unsigned &VgprUsage, unsigned &SgprUsage)
bool isHighLatencyBlock()
unsigned getVGPRSetID() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
SUnit EntrySU
Special node for the region entry.
ScheduleDAGTopologicalSort * GetTopo()
SUnit ExitSU
Special node for the region exit.
Interface definition for SIInstrInfo.
void addPred(SIScheduleBlock *Pred)
const TargetRegisterInfo * TRI
Target processor register info.
std::vector< int > BottomUpIndex2SU
SIScheduler(SIScheduleDAGMI *DAG)
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
INITIALIZE_PASS(HexagonGenMux,"hexagon-gen-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
void restoreSULinksLeft()
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)
MachineBasicBlock::iterator CurrentBottom
The bottom of the unscheduled zone.
std::set< unsigned > & getInRegs()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::vector< int > TopDownBlock2Index
void setRepeat(SIScheduleCandReason R)
const std::vector< SIScheduleBlock * > & getPreds() const
~SIScheduleBlockCreator()
MachineBasicBlock * BB
The block in which to insert instructions.
RegisterPressure & getPressure()
Get the resulting register pressure over the traversed region.
MachineRegisterInfo & MRI
Virtual/real register map.
This class can compute a topological ordering for SUnits and provides methods for dynamically updatin...
RegPressureTracker RPTracker
SISchedulerBlockSchedulerVariant
Scheduling unit. This is a node in the scheduling DAG.