14#ifndef LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H
15#define LLVM_LIB_TARGET_AMDGPU_SIMACHINESCHEDULER_H
61 std::vector<SUnit*> SUnits;
62 std::map<unsigned, unsigned> NodeNum2Index;
63 std::vector<SUnit*> TopReadySUs;
64 std::vector<SUnit*> ScheduledSUnits;
74 std::vector<unsigned> InternalAdditionalPressure;
76 std::vector<unsigned> LiveInPressure;
77 std::vector<unsigned> LiveOutPressure;
83 std::set<Register> LiveInRegs;
84 std::set<Register> LiveOutRegs;
86 bool Scheduled =
false;
87 bool HighLatencyBlock =
false;
89 std::vector<unsigned> HasLowLatencyNonWaitedParent;
94 std::vector<SIScheduleBlock*> Preds;
96 std::vector<std::pair<SIScheduleBlock*, SIScheduleBlockLinkKind>> Succs;
97 unsigned NumHighLatencySuccessors = 0;
102 DAG(DAG), BC(BC), TopRPTracker(TopPressure), ID(ID) {}
106 unsigned getID()
const {
return ID; }
118 const std::vector<SIScheduleBlock*>&
getPreds()
const {
return Preds; }
126 return NumHighLatencySuccessors;
166 unsigned LowLatencyOffset;
167 bool HasLowLatencyNonWaitedParent;
169 SISchedCandidate() =
default;
171 bool isValid()
const {
return SU; }
174 void setBest(SISchedCandidate &Best) {
175 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
178 SGPRUsage = Best.SGPRUsage;
179 VGPRUsage = Best.VGPRUsage;
180 IsLowLatency = Best.IsLowLatency;
181 LowLatencyOffset = Best.LowLatencyOffset;
182 HasLowLatencyNonWaitedParent = Best.HasLowLatencyNonWaitedParent;
188 void undoReleaseSucc(SUnit *SU, SDep *SuccEdge);
189 void releaseSucc(SUnit *SU, SDep *SuccEdge);
192 void releaseSuccessors(SUnit *SU,
bool InOrOutBlock);
194 void nodeScheduled(SUnit *SU);
195 void tryCandidateTopDown(SISchedCandidate &Cand, SISchedCandidate &TryCand);
197 void traceCandidate(
const SISchedCandidate &Cand);
217 std::vector<std::unique_ptr<SIScheduleBlock>> BlockPtrs;
220 std::vector<SIScheduleBlock*> CurrentBlocks;
221 std::vector<int> Node2CurrentBlock;
225 std::vector<int> TopDownIndex2Block;
226 std::vector<int> TopDownBlock2Index;
227 std::vector<int> BottomUpIndex2Block;
233 int NextNonReservedID;
234 std::vector<int> CurrentColoring;
235 std::vector<int> CurrentTopDownReservedDependencyColoring;
236 std::vector<int> CurrentBottomUpReservedDependencyColoring;
248 void colorHighLatenciesAlone();
251 void colorHighLatenciesGroups();
255 void colorComputeReservedDependencies();
258 void colorAccordingToReservedDependencies();
263 void colorEndsAccordingToDependencies();
266 void colorForceConsecutiveOrderInGroup();
270 void colorMergeConstantLoadsNextGroup();
274 void colorMergeIfPossibleNextGroupOnlyForReserved();
278 void regroupNoUserInstructions();
285 void topologicalSort();
287 void scheduleInsideBlocks();
301 std::vector<SIScheduleBlock*> Blocks;
303 std::vector<std::map<Register, unsigned>> LiveOutRegsNumUsages;
304 std::set<Register> LiveRegs;
306 std::map<Register, unsigned> LiveRegsConsumers;
308 std::vector<unsigned> LastPosHighLatencyParentScheduled;
309 int LastPosWaitedHighLatency;
311 std::vector<SIScheduleBlock*> BlocksScheduled;
312 unsigned NumBlockScheduled;
313 std::vector<SIScheduleBlock*> ReadyBlocks;
315 unsigned VregCurrentUsage;
316 unsigned SregCurrentUsage;
319 unsigned maxVregUsage;
320 unsigned maxSregUsage;
322 std::vector<unsigned> BlockNumPredsLeft;
323 std::vector<unsigned> BlockNumSuccsLeft;
331 std::vector<SIScheduleBlock*>
getBlocks() {
return BlocksScheduled; }
343 unsigned NumSuccessors;
344 unsigned NumHighLatencySuccessors;
345 unsigned LastPosHighLatParentScheduled;
348 SIBlockSchedCandidate() =
default;
353 void setBest(SIBlockSchedCandidate &Best) {
354 assert(Best.Reason !=
NoCand &&
"uninitialized Sched candidate");
357 IsHighLatency = Best.IsHighLatency;
358 VGPRUsageDiff = Best.VGPRUsageDiff;
359 NumSuccessors = Best.NumSuccessors;
360 NumHighLatencySuccessors = Best.NumHighLatencySuccessors;
361 LastPosHighLatParentScheduled = Best.LastPosHighLatParentScheduled;
362 Height = Best.Height;
366 bool tryCandidateLatency(SIBlockSchedCandidate &Cand,
367 SIBlockSchedCandidate &TryCand);
368 bool tryCandidateRegUsage(SIBlockSchedCandidate &Cand,
369 SIBlockSchedCandidate &TryCand);
370 SIScheduleBlock *pickBlock();
372 void addLiveRegs(std::set<VirtRegOrUnit> &Regs);
373 void decreaseLiveRegs(SIScheduleBlock *
Block, std::set<Register> &Regs);
374 void releaseBlockSuccs(SIScheduleBlock *Parent);
375 void blockScheduled(SIScheduleBlock *
Block);
379 std::vector<int> checkRegUsageImpact(std::set<Register> &InRegs,
380 std::set<Register> &OutRegs);
384 std::vector<unsigned>
SUs;
407 std::vector<SUnit> SUnitsLinksBackup;
410 std::vector<unsigned> ScheduledSUnits;
411 std::vector<unsigned> ScheduledSUnitsInv;
439 unsigned &SgprUsage);
442 std::set<VirtRegOrUnit> InRegs;
443 for (
const auto &RegMaskPair :
RPTracker.getPressure().LiveInRegs) {
444 InRegs.insert(RegMaskPair.VRegOrUnit);
450 std::set<VirtRegOrUnit> OutRegs;
451 for (
const auto &RegMaskPair :
RPTracker.getPressure().LiveOutRegs) {
452 OutRegs.insert(RegMaskPair.VRegOrUnit);
458 void topologicalSort();
460 void moveLowLatencies();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
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...
bool isSUInBlock(SUnit *SU, unsigned ID)
SIScheduleBlockCreator(SIScheduleDAGMI *DAG)
SIScheduleBlocks getBlocks(SISchedulerBlockCreatorVariant BlockVariant)
SIScheduleBlockScheduler(SIScheduleDAGMI *DAG, SISchedulerBlockSchedulerVariant Variant, SIScheduleBlocks BlocksStruct)
~SIScheduleBlockScheduler()=default
std::vector< SIScheduleBlock * > getBlocks()
unsigned getNumHighLatencySuccessors() const
SIScheduleBlock(SIScheduleDAGMI *DAG, SIScheduleBlockCreator *BC, unsigned ID)
ArrayRef< std::pair< SIScheduleBlock *, SIScheduleBlockLinkKind > > getSuccs() const
~SIScheduleBlock()=default
const std::vector< SIScheduleBlock * > & getPreds() const
void addPred(SIScheduleBlock *Pred)
std::set< Register > & getOutRegs()
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.
std::set< Register > & getInRegs()
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()
SIScheduleDAGMI(MachineSchedContext *C)
MachineBasicBlock::iterator getCurrentBottom()
std::vector< unsigned > IsLowLatencySU
MachineBasicBlock::iterator getCurrentTop()
MachineBasicBlock * getBB()
void initRPTracker(RegPressureTracker &RPTracker)
std::set< VirtRegOrUnit > getOutRegs()
~SIScheduleDAGMI() override
const TargetRegisterInfo * getTRI()
std::set< VirtRegOrUnit > getInRegs()
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(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
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.
MachineFunction & MF
Machine function.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
SISchedulerBlockSchedulerVariant
SISchedulerBlockCreatorVariant
@ LatenciesAlonePlusConsecutive
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
@ End
Run the machine verifier once, at the end of the pipeline.
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...
std::vector< unsigned > SUs
std::vector< int > TopDownIndex2Block
std::vector< SIScheduleBlock * > Blocks
std::vector< int > TopDownBlock2Index
SISchedulerCandidate()=default
SIScheduleCandReason Reason
void setRepeat(SIScheduleCandReason R)