LLVM 24.0.0git
GCNSchedStrategy.h
Go to the documentation of this file.
1//===-- GCNSchedStrategy.h - GCN Scheduler Strategy -*- C++ -*-------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
14#define LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
15
16#include "GCNRegPressure.h"
17#include "GCNRematStrategy.h"
18#include "llvm/ADT/DenseMap.h"
24
25namespace llvm {
26
27struct VGPRThresholdParser : public cl::parser<unsigned> {
29 bool parse(cl::Option &O, StringRef ArgName, StringRef Arg, unsigned &Value);
30};
31
32extern cl::opt<unsigned, false, VGPRThresholdParser> VGPRThresholdPercentOpt;
33
34class SIMachineFunctionInfo;
35class SIRegisterInfo;
36class GCNSubtarget;
37class GCNSchedStage;
38
49
50#ifndef NDEBUG
51raw_ostream &operator<<(raw_ostream &OS, const GCNSchedStageID &StageID);
52#endif
53
54/// This is a minimal scheduler strategy. The main difference between this
55/// and the GenericScheduler is that GCNSchedStrategy uses different
56/// heuristics to determine excess/critical pressure sets.
58protected:
59 SUnit *pickNodeBidirectional(bool &IsTopNode, bool &PickedPending);
60
61 void pickNodeFromQueue(SchedBoundary &Zone, const CandPolicy &ZonePolicy,
62 const RegPressureTracker &RPTracker,
63 SchedCandidate &Cand, bool &IsPending,
64 bool IsBottomUp);
65
66 void initCandidate(SchedCandidate &Cand, SUnit *SU, bool AtTop,
67 const RegPressureTracker &RPTracker,
68 const SIRegisterInfo *SRI, unsigned SGPRPressure,
69 unsigned VGPRPressure, unsigned AGPRPressure,
70 bool IsBottomUp);
71
72 /// Evaluates instructions in the pending queue using a subset of scheduling
73 /// heuristics.
74 ///
75 /// Instructions that cannot be issued due to hardware constraints are placed
76 /// in the pending queue rather than the available queue, making them normally
77 /// invisible to scheduling heuristics. However, in certain scenarios (such as
78 /// avoiding register spilling), it may be beneficial to consider scheduling
79 /// these not-yet-ready instructions.
81 SchedBoundary *Zone) const;
82
83 void printCandidateDecision(const SchedCandidate &Current,
84 const SchedCandidate &Preferred);
85
86 /// \returns the GCN trackers' pressure after scheduling \p SU.
88 const SIRegisterInfo *SRI) const;
89
90 /// \returns the ArchVGPR and AGPR pressure of \p RP after distributing
91 /// bank-agnostic AVGPR pressure across the two banks.
92 std::pair<unsigned, unsigned>
93 getBankedPressure(const GCNRegPressure &RP) const;
94
95 const AMDGPUOptions &CLOpts;
96
97 std::vector<unsigned> Pressure;
98
99 std::vector<unsigned> MaxPressure;
100
101 /// Capacity of the ArchVGPR bank, captured before VGPRExcessLimit is cut
102 /// down by ErrorMargin, VGPRLimitBias, or VGPRThresholdPercent.
103 unsigned ArchVGPRBankLimit = 0;
104
105 /// Capacity of the AGPR bank, captured before AGPRExcessLimit is cut down by
106 /// ErrorMargin and VGPRLimitBias. Zero when no AGPRs are allocatable.
107 unsigned AGPRBankLimit = 0;
108
109 /// Budget for the combined ArchVGPR + AGPR file, or zero on targets without
110 /// one.
112
114
116
117 // Scheduling stages for this strategy.
119
120 // Pointer to the current SchedStageID.
122
123 // GCN RP Tracker for top-down scheduling
125
126 // GCN RP Tracker for botttom-up scheduling
128
129 bool UseGCNTrackers = false;
130
131 std::optional<bool> GCNTrackersOverride;
132
133public:
134 // schedule() have seen register pressure over the critical limits and had to
135 // track register pressure for actual scheduling heuristics.
137
138 // Schedule known to have excess register pressure. Be more conservative in
139 // increasing ILP and preserving VGPRs.
140 bool KnownExcessRP = false;
141
142 // An error margin is necessary because of poor performance of the generic RP
143 // tracker and can be adjusted up for tuning heuristics to try and more
144 // aggressively reduce register pressure.
145 unsigned ErrorMargin = 3;
146
147 // Bias for SGPR limits under a high register pressure.
148 const unsigned HighRPSGPRBias = 7;
149
150 // Bias for VGPR limits under a high register pressure.
151 const unsigned HighRPVGPRBias = 7;
152
153 unsigned SGPRExcessLimit = 0;
154
155 unsigned VGPRExcessLimit = 0;
156
157 unsigned AGPRExcessLimit = 0;
158
159 /// \returns the allocatable ArchVGPR and AGPR counts.
160 std::pair<unsigned, unsigned> getBankLimits() const {
162 }
163
164 unsigned SGPRCriticalLimit = 0;
165
166 unsigned VGPRCriticalLimit = 0;
167
168 // Occupancy budget for the combined VGPR/AGPR allocation on unified targets.
169 // Unlike the per-bank limit, this is not clamped to allocatable VGPRs.
171
172 unsigned AGPRCriticalLimit = 0;
173
174 unsigned SGPRLimitBias = 0;
175
176 unsigned VGPRLimitBias = 0;
177
179
181
182 SUnit *pickNode(bool &IsTopNode) override;
183
184 void schedNode(SUnit *SU, bool IsTopNode) override;
185
186 void initialize(ScheduleDAGMI *DAG) override;
187
188 unsigned getTargetOccupancy() { return TargetOccupancy; }
189
190 void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; }
191
193
194 // Advances stage. Returns true if there are remaining stages.
195 bool advanceStage();
196
197 bool hasNextStage() const;
198
199 bool useGCNTrackers() const {
200 return GCNTrackersOverride.value_or(UseGCNTrackers);
201 }
202
204
206};
207
208/// The goal of this scheduling strategy is to maximize kernel occupancy (i.e.
209/// maximum number of waves per simd).
211public:
213 bool IsLegacyScheduler = false);
214};
215
216/// The goal of this scheduling strategy is to maximize ILP for a single wave
217/// (i.e. latency hiding).
219protected:
220 bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand,
221 SchedBoundary *Zone) const override;
222
223public:
225};
226
227/// The goal of this scheduling strategy is to maximize memory clause for a
228/// single wave.
230protected:
231 bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand,
232 SchedBoundary *Zone) const override;
233
234public:
236};
237
239 unsigned ScheduleLength;
240 unsigned BubbleCycles;
241
242public:
243 ScheduleMetrics() = default;
244 ScheduleMetrics(unsigned L, unsigned BC)
245 : ScheduleLength(L), BubbleCycles(BC) {}
246 unsigned getLength() const { return ScheduleLength; }
247 unsigned getBubbles() const { return BubbleCycles; }
248 unsigned getMetric() const {
249 unsigned Metric = (BubbleCycles * ScaleFactor) / ScheduleLength;
250 // Metric is zero if the amount of bubbles is less than 1% which is too
251 // small. So, return 1.
252 return Metric ? Metric : 1;
253 }
254 static const unsigned ScaleFactor;
255};
256
258 dbgs() << "\n Schedule Metric (scaled by " << ScheduleMetrics::ScaleFactor
259 << " ) is: " << Sm.getMetric() << " [ " << Sm.getBubbles() << "/"
260 << Sm.getLength() << " ]\n";
261 return OS;
262}
263
264class GCNScheduleDAGMILive;
267 // The live in/out pressure as indexed by the first or last MI in the region
268 // before scheduling.
270 // The mapping of RegionIDx to key instruction
271 DenseMap<unsigned, MachineInstr *> IdxToInstruction;
272 // Whether we are calculating LiveOuts or LiveIns
273 bool IsLiveOut;
274
275public:
276 RegionPressureMap() = default;
278 : DAG(GCNDAG), IsLiveOut(LiveOut) {}
279 // Build the Instr->LiveReg and RegionIdx->Instr maps
280 void buildLiveRegMap();
281
282 // Retrieve the LiveReg for a given RegionIdx
284 assert(IdxToInstruction.contains(RegionIdx));
285 MachineInstr *Key = IdxToInstruction[RegionIdx];
286 return RegionLiveRegMap[Key];
287 }
288};
289
290/// A region's boundaries i.e. a pair of instruction bundle iterators. The lower
291/// boundary is inclusive, the upper boundary is exclusive.
293 std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>;
294
296 friend class GCNSchedStage;
301 friend class PreRARematStage;
304 friend class RegionPressureMap;
305
306 const GCNSubtarget &ST;
307
309
310 // Occupancy target at the beginning of function scheduling cycle.
311 unsigned StartingOccupancy;
312
313 // Minimal real occupancy recorder for the function.
314 unsigned MinOccupancy;
315
316 // Vector of regions recorder for later rescheduling
318
319 // Record regions with high register pressure.
320 BitVector RegionsWithHighRP;
321
322 // Record regions with excess register pressure over the physical register
323 // limit. Register pressure in these regions usually will result in spilling.
324 BitVector RegionsWithExcessRP;
325
326 // Regions that have IGLP instructions (SCHED_GROUP_BARRIER or IGLP_OPT).
327 BitVector RegionsWithIGLPInstrs;
328
329 // Region live-in cache.
331
332 // Region pressure cache.
334
335 // Temporary basic block live-in cache.
337
338 // The map of the initial first region instruction to region live in registers
340
341 // Calculate the map of the initial first region instruction to region live in
342 // registers
344
345 // Calculate the map of the initial last region instruction to region live out
346 // registers
348 getRegionLiveOutMap() const;
349
350 // The live out registers per region. These are internally stored as a map of
351 // the initial last region instruction to region live out registers, but can
352 // be retreived with the regionIdx by calls to getLiveRegsForRegionIdx.
353 RegionPressureMap RegionLiveOuts;
354
355 // Return current region pressure.
356 /// \returns the maximum pressure of region \p RegionIdx. If set, \p
357 /// PressureCallback is called with the pressure of every program point of
358 /// the region.
359 GCNRegPressure getRealRegPressure(unsigned RegionIdx,
360 std::function<void(const GCNRegPressure &)>
361 PressureCallback = nullptr) const;
362
363 // Compute and cache live-ins and pressure for all regions in block.
364 void computeBlockPressure(unsigned RegionIdx, const MachineBasicBlock *MBB);
365
366 /// Makes the scheduler try to achieve an occupancy of \p TargetOccupancy.
367 void setTargetOccupancy(unsigned TargetOccupancy);
368
369 void runSchedStages();
370
371 std::unique_ptr<GCNSchedStage> createSchedStage(GCNSchedStageID SchedStageID);
372
373public:
375 std::unique_ptr<MachineSchedStrategy> S);
376
377 void schedule() override;
378
379 void finalizeSchedule() override;
380};
381
382// GCNSchedStrategy applies multiple scheduling stages to a function.
384protected:
386
388
390
392
394
396
397 // The current block being scheduled.
399
400 // Current region index.
401 unsigned RegionIdx = 0;
402
403 // Record the original order of instructions before scheduling.
404 std::vector<MachineInstr *> Unsched;
405
406 // RP before scheduling the current region.
408
409 // RP after scheduling the current region.
411
412 std::vector<std::unique_ptr<ScheduleDAGMutation>> SavedMutations;
413
415
416public:
417 // Initialize state for a scheduling stage. Returns false if the current stage
418 // should be skipped.
419 virtual bool initGCNSchedStage();
420
421 // Finalize state after finishing a scheduling pass on the function.
422 virtual void finalizeGCNSchedStage();
423
424 // Setup for scheduling a region. Returns false if the current region should
425 // be skipped.
426 virtual bool initGCNRegion();
427
428 // Finalize state after scheduling a region.
429 virtual void finalizeGCNRegion();
430
431 // Track whether a new region is also a new MBB.
432 void setupNewBlock();
433
434 // Check result of scheduling.
435 void checkScheduling();
436
437 // computes the given schedule virtual execution time in clocks
438 ScheduleMetrics getScheduleMetrics(const std::vector<SUnit> &InputSchedule);
440 unsigned computeSUnitReadyCycle(const SUnit &SU, unsigned CurrCycle,
441 DenseMap<unsigned, unsigned> &ReadyCycles,
442 const TargetSchedModel &SM);
443
444 // Returns true if scheduling should be reverted.
445 virtual bool shouldRevertScheduling(unsigned WavesAfter);
446
447 // Returns true if current region has known excess pressure.
448 bool isRegionWithExcessRP() const {
449 return DAG.RegionsWithExcessRP[RegionIdx];
450 }
451
452 // The region number this stage is currently working on
453 unsigned getRegionIdx() { return RegionIdx; }
454
455 // Returns true if the new schedule may result in more spilling.
456 bool mayCauseSpilling(unsigned WavesAfter);
457
458 // Returns true if the new schedule has a better latency metric than the old
459 // one.
460 bool reducesLatency();
461
462 // Returns true if the new schedule may result in more spilling, unless
463 // neither pressure is less than the other and the new schedule reduces
464 // latency. For the initial stages, whose old schedule is the input order,
465 // which was never selected for latency.
466 bool shouldRevertInitialSchedule(unsigned WavesAfter);
467
468 /// Sets the schedule of region \p RegionIdx to \p MIOrder. The MIs in \p
469 /// MIOrder must be exactly the same as the ones currently existing inside the
470 /// region, only in a different order that honors def-use chains.
471 void modifyRegionSchedule(unsigned RegionIdx,
473
475
476 virtual ~GCNSchedStage() = default;
477};
478
486
488private:
489 // Record regions with excess archvgpr register pressure over the physical
490 // register limit. Register pressure in these regions usually will result in
491 // spilling.
492 BitVector RegionsWithExcessArchVGPR;
493
494 const SIInstrInfo *TII;
495 const SIRegisterInfo *SRI;
496
497 /// Per-candidate cache of the src2 "needs VGPR" decision, computed once
498 /// and reused on-demand.
499 DenseMap<const MachineInstr *, bool> Src2NeedsVGPRCache;
500
501 /// Do a speculative rewrite and collect copy locations. The speculative
502 /// rewrite allows us to calculate the RP of the code after the rewrite, and
503 /// the copy locations allow us to calculate the total cost of copies required
504 /// for the rewrite. Stores the rewritten instructions in \p RewriteCands ,
505 /// the copy locations for uses (of the MFMA result) in \p CopyForUse and the
506 /// copy locations for defs (of the MFMA operands) in \p CopyForDef
507 bool
508 initHeuristics(std::vector<std::pair<MachineInstr *, unsigned>> &RewriteCands,
509 DenseMap<MachineBasicBlock *, std::set<Register>> &CopyForUse,
511
512 /// Calculate the rewrite cost and undo the state change (e.g. rewriting) done
513 /// in initHeuristics. Uses \p CopyForUse and \p CopyForDef to calculate copy
514 /// costs, and \p RewriteCands to undo rewriting.
515 int64_t getRewriteCost(
516 ArrayRef<std::pair<MachineInstr *, unsigned>> RewriteCands,
517 const DenseMap<MachineBasicBlock *, std::set<Register>> &CopyForUse,
518 const SmallPtrSetImpl<MachineInstr *> &CopyForDef);
519
520 /// Do the final rewrite on \p RewriteCands and insert any needed copies.
521 bool rewrite(ArrayRef<std::pair<MachineInstr *, unsigned>> RewriteCands);
522
523 /// \returns true if this MI is a rewrite candidate.
524 bool isRewriteCandidate(MachineInstr *MI) const;
525
526 /// Resets all candidates in \p RewriteCands back to VGPR form.
527 void resetRewriteCandsToVGPR(
528 ArrayRef<std::pair<MachineInstr *, unsigned>> RewriteCands);
529
530 /// Finds all the reaching defs of \p UseMO and stores the SlotIndexes into \p
531 /// DefIdxs
532 void findReachingDefs(MachineOperand &UseMO, LiveIntervals *LIS,
534
535 /// Finds all the reaching uses of \p DefMI and stores the use operands in \p
536 /// ReachingUses
537 void findReachingUses(const MachineInstr *DefMI, LiveIntervals *LIS,
539
540 /// Returns true if the src2 register with reaching defs \p Src2ReachingDefs
541 /// has a use other than a group MFMA (in \p RewriteSet) or a copy, which
542 /// would keep it in VGPR form rather than let it be reclassified to AGPR.
543 bool hasUseRequiringVGPR(ArrayRef<SlotIndex> Src2ReachingDefs,
544 const SmallPtrSetImpl<MachineInstr *> &RewriteSet);
545
546public:
547 bool initGCNSchedStage() override;
548
551};
552
554private:
555 // Save the initial occupancy before starting this stage.
556 unsigned InitialOccupancy;
557 // Save the temporary target occupancy before starting this stage.
558 unsigned TempTargetOccupancy;
559 // Track whether any region was scheduled by this stage.
560 bool IsAnyRegionScheduled;
561
562public:
563 bool initGCNSchedStage() override;
564
565 void finalizeGCNSchedStage() override;
566
567 bool initGCNRegion() override;
568
569 bool shouldRevertScheduling(unsigned WavesAfter) override;
570
573};
574
575// Retry function scheduling if we found resulting occupancy and it is
576// lower than used for other scheduling passes. This will give more freedom
577// to schedule low register pressure blocks.
579public:
580 bool initGCNSchedStage() override;
581
582 bool initGCNRegion() override;
583
584 bool shouldRevertScheduling(unsigned WavesAfter) override;
585
588};
589
590/// Attempts to reduce function spilling or, if there is no spilling, to
591/// increase function occupancy by one with respect to register usage by sinking
592/// rematerializable instructions to their use. When the stage estimates that
593/// reducing spilling or increasing occupancy is possible, it tries to
594/// rematerialize as few registers as possible to reduce potential negative
595/// effects on function latency. Uses `GCNRematStrategy` to drive
596/// rematerializations.
598private:
599 /// Live-outs are not maintained in a contiguous array so we have to have one
600 /// here to give to the strategy.
602 /// Rematerialization strategy.
603 std::unique_ptr<GCNRematStrategy> Strategy;
604 /// The target occupancy the stage is tring to achieve. Empty when the
605 /// objective is spill reduction.
606 std::optional<unsigned> TargetOcc;
607 /// Achieved occupancy *only* through rematerializations (pre-rescheduling).
608 unsigned AchievedOcc;
609 /// After successful stage initialization, indicates which regions should be
610 /// rescheduled.
611 BitVector RescheduleRegions;
612
613 /// State of a region pre-re-scheduling but post-rematerializations that we
614 /// must keep to be able to revert re-scheduling effects.
615 struct RegionSchedRevert {
616 /// Region number.
617 unsigned RegionIdx;
618 /// Original instruction order (both debug and non-debug MIs).
619 std::vector<MachineInstr *> OrigMIOrder;
620 /// Maximum pressure recorded in the region.
621 GCNRegPressure MaxPressure;
622
623 RegionSchedRevert(unsigned RegionIdx, ArrayRef<MachineInstr *> OrigMIOrder,
624 const GCNRegPressure &MaxPressure)
625 : RegionIdx(RegionIdx), OrigMIOrder(OrigMIOrder),
626 MaxPressure(MaxPressure) {}
627 };
628 /// After re-scheduling, contains pre-re-scheduling data for all re-scheduled
629 /// regions.
630 SmallVector<RegionSchedRevert> RegionReverts;
631 /// Whether we should revert all re-scheduled regions.
632 bool RevertAllRegions = false;
633
634 /// Returns the occupancy the stage is trying to achieve.
635 unsigned getStageTargetOccupancy() const;
636
637 /// If remat alone did not increase occupancy to the target one, rollbacks all
638 /// rematerializations and resets live-ins/RP in all regions impacted by the
639 /// stage to their pre-stage values.
640 void finalizeGCNSchedStage() override;
641
642public:
643 bool initGCNSchedStage() override;
644
645 bool initGCNRegion() override;
646
647 void finalizeGCNRegion() override;
648
649 bool shouldRevertScheduling(unsigned WavesAfter) override;
650
653};
654
662
671
672// Live interval register pressure stage:
673// estimates register pressure accounting for live interval interference,
674// optionally reschedules the region with tigher register bounds.
676public:
677 bool initGCNSchedStage() override;
678 bool initGCNRegion() override;
679 void finalizeGCNRegion() override;
680
683
684private:
685 unsigned SavedVGPRThresholdPercent = 0;
686 unsigned SavedVGPRExcessLimit = 0;
687 unsigned SavedVGPRCriticalLimit = 0;
688 unsigned SavedUnifiedVGPRCriticalLimit = 0;
689};
690
692private:
693 std::vector<std::unique_ptr<ScheduleDAGMutation>> SavedMutations;
694
695 bool HasIGLPInstrs = false;
696
697public:
698 void schedule() override;
699
700 void finalizeSchedule() override;
701
703 std::unique_ptr<MachineSchedStrategy> S,
704 bool RemoveKillFlags);
705};
706
707} // End namespace llvm
708
709#endif // LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file defines the DenseMap class.
This file defines the GCNRegPressure class, which tracks registry pressure by bookkeeping number of S...
Rematerialization strategy, based on the target-independent rematerializer.
IRTranslator LLVM IR MI
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
bool shouldRevertScheduling(unsigned WavesAfter) override
ClusteredLowOccStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
Common behavior for downward RP trackers. Unconstructible directly.
Downward RP tracker that relies on the user to provide the next instruction down the instruction stre...
GCNMaxILPSchedStrategy(const MachineSchedContext *C)
bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand, SchedBoundary *Zone) const override
Apply a set of heuristics to a new candidate.
bool tryCandidate(SchedCandidate &Cand, SchedCandidate &TryCand, SchedBoundary *Zone) const override
GCNMaxMemoryClauseSchedStrategy tries best to clause memory instructions as much as possible.
GCNMaxMemoryClauseSchedStrategy(const MachineSchedContext *C)
GCNMaxOccupancySchedStrategy(const MachineSchedContext *C, bool IsLegacyScheduler=false)
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
void schedule() override
Orders nodes according to selected style.
GCNPostScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S, bool RemoveKillFlags)
DenseMap< unsigned, LaneBitmask > LiveRegSet
GCNSchedStrategy & S
GCNRegPressure PressureBefore
bool isRegionWithExcessRP() const
void modifyRegionSchedule(unsigned RegionIdx, ArrayRef< MachineInstr * > MIOrder)
Sets the schedule of region RegionIdx to MIOrder.
bool mayCauseSpilling(unsigned WavesAfter)
ScheduleMetrics getScheduleMetrics(const std::vector< SUnit > &InputSchedule)
GCNScheduleDAGMILive & DAG
const GCNSchedStageID StageID
std::vector< MachineInstr * > Unsched
GCNRegPressure PressureAfter
bool shouldRevertInitialSchedule(unsigned WavesAfter)
MachineFunction & MF
virtual void finalizeGCNRegion()
SIMachineFunctionInfo & MFI
unsigned computeSUnitReadyCycle(const SUnit &SU, unsigned CurrCycle, DenseMap< unsigned, unsigned > &ReadyCycles, const TargetSchedModel &SM)
virtual ~GCNSchedStage()=default
virtual void finalizeGCNSchedStage()
virtual bool initGCNSchedStage()
virtual bool shouldRevertScheduling(unsigned WavesAfter)
std::vector< std::unique_ptr< ScheduleDAGMutation > > SavedMutations
GCNSchedStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
MachineBasicBlock * CurrentMBB
const GCNSubtarget & ST
This is a minimal scheduler strategy.
const unsigned HighRPSGPRBias
GCNSchedStrategy(const MachineSchedContext *C)
SmallVector< GCNSchedStageID, 4 > SchedStages
std::vector< unsigned > MaxPressure
SUnit * pickNodeBidirectional(bool &IsTopNode, bool &PickedPending)
GCNSchedStageID getCurrentStage()
bool tryPendingCandidate(SchedCandidate &Cand, SchedCandidate &TryCand, SchedBoundary *Zone) const
Evaluates instructions in the pending queue using a subset of scheduling heuristics.
SmallVectorImpl< GCNSchedStageID >::iterator CurrentStage
std::pair< unsigned, unsigned > getBankedPressure(const GCNRegPressure &RP) const
void schedNode(SUnit *SU, bool IsTopNode) override
Notify MachineSchedStrategy that ScheduleDAGMI has scheduled an instruction and updated scheduled/rem...
GCNRegPressure getGCNTrackerPressure(bool AtTop, SUnit *SU, const SIRegisterInfo *SRI) const
unsigned AGPRBankLimit
Capacity of the AGPR bank, captured before AGPRExcessLimit is cut down by ErrorMargin and VGPRLimitBi...
unsigned ArchVGPRBankLimit
Capacity of the ArchVGPR bank, captured before VGPRExcessLimit is cut down by ErrorMargin,...
std::optional< bool > GCNTrackersOverride
std::vector< unsigned > Pressure
std::pair< unsigned, unsigned > getBankLimits() const
void initialize(ScheduleDAGMI *DAG) override
Initialize the strategy after building the DAG for a new region.
GCNUpwardRPTracker UpwardTracker
void printCandidateDecision(const SchedCandidate &Current, const SchedCandidate &Preferred)
const unsigned HighRPVGPRBias
void pickNodeFromQueue(SchedBoundary &Zone, const CandPolicy &ZonePolicy, const RegPressureTracker &RPTracker, SchedCandidate &Cand, bool &IsPending, bool IsBottomUp)
GCNManualDownwardRPTracker DownwardTracker
GCNUpwardRPTracker & getUpwardTracker()
const AMDGPUOptions & CLOpts
void initCandidate(SchedCandidate &Cand, SUnit *SU, bool AtTop, const RegPressureTracker &RPTracker, const SIRegisterInfo *SRI, unsigned SGPRPressure, unsigned VGPRPressure, unsigned AGPRPressure, bool IsBottomUp)
void setTargetOccupancy(unsigned Occ)
GCNDownwardRPTrackerBase & getDownwardTracker()
SUnit * pickNode(bool &IsTopNode) override
Pick the next node to schedule, or return NULL.
unsigned UnifiedVGPRExcessLimit
Budget for the combined ArchVGPR + AGPR file, or zero on targets without one.
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
void schedule() override
Orders nodes according to selected style.
GCNScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
ScheduleDAGMILive * DAG
GenericScheduler(const MachineSchedContext *C)
bool shouldRevertScheduling(unsigned WavesAfter) override
ILPInitialScheduleStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
LiveIntervalRPStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
bool shouldRevertScheduling(unsigned WavesAfter) override
MemoryClauseInitialScheduleStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
bool shouldRevertScheduling(unsigned WavesAfter) override
OccInitialScheduleStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
PreRARematStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
bool shouldRevertScheduling(unsigned WavesAfter) override
void finalizeGCNRegion() override
bool initGCNSchedStage() override
Track the current register pressure at some position in the instruction stream, and remember the high...
GCNRPTracker::LiveRegSet & getLiveRegsForRegionIdx(unsigned RegionIdx)
RegionPressureMap(GCNScheduleDAGMILive *GCNDAG, bool LiveOut)
RewriteMFMAFormStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Scheduling unit. This is a node in the scheduling DAG.
Each Scheduling boundary is associated with ready queues.
bool RemoveKillFlags
True if the DAG builder should remove kill flags (in preparation for rescheduling).
ScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
ScheduleDAGMI(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S, bool RemoveKillFlags)
unsigned getBubbles() const
ScheduleMetrics(unsigned L, unsigned BC)
unsigned getLength() const
static const unsigned ScaleFactor
unsigned getMetric() const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
typename SuperClass::iterator iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Provide an instruction scheduling machine model to CodeGen passes.
UnclusteredHighRPStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
bool shouldRevertScheduling(unsigned WavesAfter) override
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This namespace contains all of the command line option processing machinery.
This is an optimization pass for GlobalISel generic memory operations.
std::pair< MachineBasicBlock::iterator, MachineBasicBlock::iterator > RegionBoundaries
A region's boundaries i.e.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
cl::opt< unsigned, false, VGPRThresholdParser > VGPRThresholdPercentOpt
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Policy for scheduling the next instruction in the candidate's zone.
Store the state used by GenericScheduler heuristics, required for the lifetime of one invocation of p...
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
bool parse(cl::Option &O, StringRef ArgName, StringRef Arg, unsigned &Value)
VGPRThresholdParser(cl::Option &O)