13#ifndef LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
14#define LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
61 unsigned VGPRPressure,
bool IsBottomUp);
160 bool IsLegacyScheduler =
false);
186 unsigned ScheduleLength;
187 unsigned BubbleCycles;
192 : ScheduleLength(L), BubbleCycles(BC) {}
196 unsigned Metric = (BubbleCycles *
ScaleFactor) / ScheduleLength;
199 return Metric ? Metric : 1;
211class GCNScheduleDAGMILive;
225 : DAG(GCNDAG), IsLiveOut(LiveOut) {}
231 assert(IdxToInstruction.contains(RegionIdx));
233 return RegionLiveRegMap[
Key];
240 std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>;
257 unsigned StartingOccupancy;
260 unsigned MinOccupancy;
294 getRegionLiveOutMap()
const;
308 void setTargetOccupancy(
unsigned TargetOccupancy);
310 void runSchedStages();
312 std::unique_ptr<GCNSchedStage> createSchedStage(
GCNSchedStageID SchedStageID);
318 std::unique_ptr<MachineSchedStrategy> S);
438 initHeuristics(std::vector<std::pair<MachineInstr *, unsigned>> &RewriteCands,
445 int64_t getRewriteCost(
446 const std::vector<std::pair<MachineInstr *, unsigned>> &RewriteCands,
452 rewrite(
const std::vector<std::pair<MachineInstr *, unsigned>> &RewriteCands);
477 unsigned InitialOccupancy;
479 unsigned TempTargetOccupancy;
481 bool IsAnyRegionScheduled;
543 unsigned DefRegion, UseRegion;
555 bool maybeBeneficial(
const BitVector &TargetRegions,
560 bool isUnusedLiveThrough(
unsigned I)
const {
561 assert(
I < Live.
size() &&
"region index out of range");
562 return LiveIn[
I] && LiveOut[
I] &&
I != UseRegion;
591 static const uint64_t ScaleFactor = 1024;
596 ScoredRemat(RematReg *Remat,
const FreqInfo &Freq,
602 const FreqInfo &Freq,
bool ReduceSpill);
606 bool hasNullScore()
const {
return !RegionImpact; }
610 bool operator<(
const ScoredRemat &O)
const {
612 return !O.hasNullScore();
613 if (O.hasNullScore())
615 if (MaxFreq != O.MaxFreq)
616 return MaxFreq < O.MaxFreq;
617 if (FreqDiff != O.FreqDiff)
618 return FreqDiff < O.FreqDiff;
619 if (RegionImpact != O.RegionImpact)
620 return RegionImpact < O.RegionImpact;
626 return Remat > O.Remat;
629#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
650 unsigned RegionImpact;
654 int64_t getFreqDiff(
const FreqInfo &Freq)
const;
662 BitVector TargetRegions;
665 std::optional<unsigned> TargetOcc;
667 unsigned AchievedOcc;
670 BitVector RescheduleRegions;
673 SmallVector<RematReg> RematRegs;
677 struct RollbackInfo {
679 const RematReg *Remat;
681 MachineInstr *RematMI;
683 SmallDenseMap<unsigned, Register, 4> RegMap;
685 RollbackInfo(
const RematReg *Remat) : Remat(Remat) {}
689 SmallVector<RollbackInfo> Rollbacks;
693 struct RegionSchedRevert {
697 std::vector<MachineInstr *> OrigMIOrder;
699 GCNRegPressure MaxPressure;
702 const GCNRegPressure &MaxPressure)
703 : RegionIdx(RegionIdx), OrigMIOrder(OrigMIOrder),
704 MaxPressure(MaxPressure) {}
708 SmallVector<RegionSchedRevert> RegionReverts;
711 unsigned getStageTargetOccupancy()
const;
720 void unsetSatisifedRPTargets(
const BitVector &Regions);
725 bool updateAndVerifyRPTargets(
const BitVector &Regions);
730 bool collectRematRegs(
const DenseMap<MachineInstr *, unsigned> &MIRegion);
738 void rematerialize(
const RematReg &Remat, BitVector &RecomputeRP,
739 RollbackInfo *Rollback);
743 void commitRematerializations()
const;
746 bool isReMaterializable(
const MachineInstr &
MI);
764 RescheduleRegions(
DAG.Regions.
size()) {
765 const unsigned NumRegions =
DAG.Regions.size();
766 RPTargets.reserve(NumRegions);
767 RegionBB.reserve(NumRegions);
790 std::vector<std::unique_ptr<ScheduleDAGMutation>> SavedMutations;
792 bool HasIGLPInstrs =
false;
800 std::unique_ptr<MachineSchedStrategy> S,
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
This file defines the GCNRegPressure class, which tracks registry pressure by bookkeeping number of S...
This file implements a map that provides insertion order iteration.
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static constexpr unsigned SM(unsigned Version)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_type size() const
size - Returns the number of bits in this bitvector.
bool initGCNSchedStage() override
bool shouldRevertScheduling(unsigned WavesAfter) override
bool initGCNRegion() override
ClusteredLowOccStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
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
virtual bool initGCNRegion()
GCNRegPressure PressureBefore
bool isRegionWithExcessRP() const
bool mayCauseSpilling(unsigned WavesAfter)
ScheduleMetrics getScheduleMetrics(const std::vector< SUnit > &InputSchedule)
GCNScheduleDAGMILive & DAG
const GCNSchedStageID StageID
std::vector< MachineInstr * > Unsched
GCNRegPressure PressureAfter
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)
void modifyRegionSchedule(unsigned RegionIdx, MachineBasicBlock *MBB, ArrayRef< MachineInstr * > MIOrder)
Sets the schedule of region RegionIdx in block MBB to MIOrder.
MachineBasicBlock * CurrentMBB
This is a minimal scheduler strategy.
const unsigned HighRPSGPRBias
GCNDownwardRPTracker DownwardTracker
GCNSchedStrategy(const MachineSchedContext *C)
SmallVector< GCNSchedStageID, 4 > SchedStages
unsigned SGPRCriticalLimit
std::vector< unsigned > MaxPressure
bool hasNextStage() const
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
unsigned VGPRCriticalLimit
void schedNode(SUnit *SU, bool IsTopNode) override
Notify MachineSchedStrategy that ScheduleDAGMI has scheduled an instruction and updated scheduled/rem...
GCNDownwardRPTracker * getDownwardTracker()
std::vector< unsigned > Pressure
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)
void initCandidate(SchedCandidate &Cand, SUnit *SU, bool AtTop, const RegPressureTracker &RPTracker, const SIRegisterInfo *SRI, unsigned SGPRPressure, unsigned VGPRPressure, bool IsBottomUp)
unsigned getTargetOccupancy()
void setTargetOccupancy(unsigned Occ)
SUnit * pickNode(bool &IsTopNode) override
Pick the next node to schedule, or return NULL.
GCNUpwardRPTracker * getUpwardTracker()
GCNSchedStageID getNextStage() const
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
friend class RegionPressureMap
friend class GCNSchedStage
void schedule() override
Orders nodes according to selected style.
friend class RewriteMFMAFormStage
GCNScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
friend class PreRARematStage
friend class ClusteredLowOccStage
friend class ILPInitialScheduleStage
friend class OccInitialScheduleStage
friend class UnclusteredHighRPStage
GenericScheduler(const MachineSchedContext *C)
bool shouldRevertScheduling(unsigned WavesAfter) override
ILPInitialScheduleStage(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 initGCNRegion() override
bool initGCNSchedStage() override
Simple wrapper around std::function<void(raw_ostream&)>.
Track the current register pressure at some position in the instruction stream, and remember the high...
GCNRPTracker::LiveRegSet & getLiveRegsForRegionIdx(unsigned RegionIdx)
RegionPressureMap()=default
RegionPressureMap(GCNScheduleDAGMILive *GCNDAG, bool LiveOut)
Wrapper class representing virtual and physical registers.
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)
ScheduleMetrics()=default
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.
Provide an instruction scheduling machine model to CodeGen passes.
UnclusteredHighRPStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
bool initGCNSchedStage() override
bool initGCNRegion() override
void finalizeGCNSchedStage() override
bool shouldRevertScheduling(unsigned WavesAfter) override
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::pair< MachineBasicBlock::iterator, MachineBasicBlock::iterator > RegionBoundaries
A region's boundaries i.e.
@ UnclusteredHighRPReschedule
@ MemoryClauseInitialSchedule
@ ClusteredLowOccupancyReschedule
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
ArrayRef(const T &OneElt) -> ArrayRef< T >
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...
Execution frequency information required by scoring heuristics.
SmallVector< uint64_t > Regions
Per-region execution frequencies. 0 when unknown.
uint64_t MinFreq
Minimum and maximum observed frequencies.
FreqInfo(MachineFunction &MF, const GCNScheduleDAGMILive &DAG)