13#ifndef LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
14#define LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
34class SIMachineFunctionInfo;
69 unsigned VGPRPressure,
unsigned AGPRPressure,
190 bool IsLegacyScheduler =
false);
216 unsigned ScheduleLength;
217 unsigned BubbleCycles;
222 : ScheduleLength(L), BubbleCycles(BC) {}
226 unsigned Metric = (BubbleCycles *
ScaleFactor) / ScheduleLength;
229 return Metric ? Metric : 1;
241class GCNScheduleDAGMILive;
255 : DAG(GCNDAG), IsLiveOut(LiveOut) {}
261 assert(IdxToInstruction.contains(RegionIdx));
263 return RegionLiveRegMap[
Key];
270 std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>;
288 unsigned StartingOccupancy;
291 unsigned MinOccupancy;
325 getRegionLiveOutMap()
const;
339 void setTargetOccupancy(
unsigned TargetOccupancy);
341 void runSchedStages();
343 std::unique_ptr<GCNSchedStage> createSchedStage(
GCNSchedStageID SchedStageID);
347 std::unique_ptr<MachineSchedStrategy> S);
470 initHeuristics(std::vector<std::pair<MachineInstr *, unsigned>> &RewriteCands,
477 int64_t getRewriteCost(
478 ArrayRef<std::pair<MachineInstr *, unsigned>> RewriteCands,
483 bool rewrite(
ArrayRef<std::pair<MachineInstr *, unsigned>> RewriteCands);
489 void resetRewriteCandsToVGPR(
490 ArrayRef<std::pair<MachineInstr *, unsigned>> RewriteCands);
518 unsigned InitialOccupancy;
520 unsigned TempTargetOccupancy;
522 bool IsAnyRegionScheduled;
591 ScoredRemat(RegisterIdx RegIdx,
unsigned NumRegions)
592 : RegIdx(RegIdx), LiveIn(NumRegions), LiveOut(NumRegions),
593 Live(NumRegions), UnpredictableRPSave(NumRegions) {}
607 static const uint64_t ScaleFactor = 1024;
621 bool maybeBeneficial(
const BitVector &TargetRegions,
627 const FreqInfo &Freq,
bool ReduceSpill);
631 bool hasNullScore()
const {
return !RegionImpact; }
635 bool operator<(
const ScoredRemat &O)
const {
636 assert(!hasNullScore() &&
"this has null score");
637 assert(!O.hasNullScore() &&
"other has null score");
638 if (MaxFreq != O.MaxFreq)
639 return MaxFreq < O.MaxFreq;
640 if (FreqDiff != O.FreqDiff)
641 return FreqDiff < O.FreqDiff;
642 if (RegionImpact != O.RegionImpact)
643 return RegionImpact < O.RegionImpact;
653 return RegIdx > O.RegIdx;
656#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
674 unsigned RegionImpact;
680 BitVector TargetRegions;
683 std::optional<unsigned> TargetOcc;
685 unsigned AchievedOcc;
688 BitVector RescheduleRegions;
691 Rematerializer Remater;
693 struct RollbackSupport {
712 RollbackSupport(
Rematerializer &Remater) { Remater.addListener(&Listener); }
718 std::unique_ptr<RollbackSupport> Rollback;
722 struct RegionSchedRevert {
726 std::vector<MachineInstr *> OrigMIOrder;
728 GCNRegPressure MaxPressure;
731 const GCNRegPressure &MaxPressure)
733 MaxPressure(MaxPressure) {}
737 SmallVector<RegionSchedRevert> RegionReverts;
739 bool RevertAllRegions =
false;
742 unsigned getStageTargetOccupancy()
const;
752 void updateRPTargets(
const BitVector &Regions,
const GCNRegPressure &RPSave);
757 bool updateAndVerifyRPTargets(
const BitVector &Regions);
761 void removeFromLiveMaps(
Register Reg,
const BitVector &LiveIn,
762 const BitVector &LiveOut);
766 void addToLiveMaps(
Register Reg, LaneBitmask Mask,
const BitVector &LiveIn,
767 const BitVector &LiveOut);
785 RescheduleRegions(
DAG.Regions.
size()),
786 Remater(
MF,
DAG.Regions, *
DAG.LIS) {
787 const unsigned NumRegions =
DAG.Regions.size();
788 RPTargets.reserve(NumRegions);
822 unsigned SavedVGPRThresholdPercent = 0;
823 unsigned SavedVGPRExcessLimit = 0;
824 unsigned SavedVGPRCriticalLimit = 0;
829 std::vector<std::unique_ptr<ScheduleDAGMutation>> SavedMutations;
831 bool HasIGLPInstrs =
false;
839 std::unique_ptr<MachineSchedStrategy> S,
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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...
Promote Memory to Register
MIR-level target-independent rematerialization helpers.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
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
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
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
This is a minimal scheduler strategy.
const unsigned HighRPSGPRBias
GCNDownwardRPTracker DownwardTracker
bool useGCNTrackers() const
void getRegisterPressures(bool AtTop, const RegPressureTracker &RPTracker, SUnit *SU, std::vector< unsigned > &Pressure, std::vector< unsigned > &MaxPressure, GCNDownwardRPTracker &DownwardTracker, GCNUpwardRPTracker &UpwardTracker, ScheduleDAGMI *DAG, const SIRegisterInfo *SRI)
GCNSchedStrategy(const MachineSchedContext *C)
SmallVector< GCNSchedStageID, 4 > SchedStages
unsigned SGPRCriticalLimit
unsigned VGPRThresholdPercent
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...
std::optional< bool > GCNTrackersOverride
GCNDownwardRPTracker * getDownwardTracker()
unsigned AGPRCriticalLimit
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)
unsigned getTargetOccupancy()
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)
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 LiveIntervalRPStage
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)
LiveIntervalRPStage(GCNSchedStageID StageID, GCNScheduleDAGMILive &DAG)
void finalizeGCNRegion() override
bool initGCNRegion() override
bool initGCNSchedStage() override
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)
MIR-level target-independent rematerializer.
unsigned RegisterIdx
Index type for rematerializable registers.
Rematerializer listener with the ability to re-create deleted registers and rollback rematerializatio...
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.
Represent a constant reference to a string, i.e.
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
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
This namespace contains all of the command line option processing machinery.
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
@ LiveIntervalRPReschedule
@ ClusteredLowOccupancyReschedule
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
cl::opt< unsigned, false, VGPRThresholdParser > VGPRThresholdPercentOpt
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...
BitVector LiveIn
Regions in which the original register was live-in or live-out.
LiveMapUpdate(RegisterIdx RegIdx, const BitVector &LiveIn, const BitVector &LiveOut)
RegisterIdx RegIdx
The register index handle in the rematerializer.
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)
bool parse(cl::Option &O, StringRef ArgName, StringRef Arg, unsigned &Value)
VGPRThresholdParser(cl::Option &O)