1 //===-- GCNSchedStrategy.h - GCN Scheduler Strategy -*- C++ -*-------------===//
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
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
14 #define LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
16 #include "GCNRegPressure.h"
17 #include "llvm/CodeGen/MachineScheduler.h"
21 class SIMachineFunctionInfo
;
25 /// This is a minimal scheduler strategy. The main difference between this
26 /// and the GenericScheduler is that GCNSchedStrategy uses different
27 /// heuristics to determine excess/critical pressure sets. Its goal is to
28 /// maximize kernel occupancy (i.e. maximum number of waves per simd).
29 class GCNMaxOccupancySchedStrategy final
: public GenericScheduler
{
30 friend class GCNScheduleDAGMILive
;
32 SUnit
*pickNodeBidirectional(bool &IsTopNode
);
34 void pickNodeFromQueue(SchedBoundary
&Zone
, const CandPolicy
&ZonePolicy
,
35 const RegPressureTracker
&RPTracker
,
36 SchedCandidate
&Cand
);
38 void initCandidate(SchedCandidate
&Cand
, SUnit
*SU
,
39 bool AtTop
, const RegPressureTracker
&RPTracker
,
40 const SIRegisterInfo
*SRI
,
41 unsigned SGPRPressure
, unsigned VGPRPressure
);
43 std::vector
<unsigned> Pressure
;
44 std::vector
<unsigned> MaxPressure
;
46 unsigned SGPRExcessLimit
;
47 unsigned VGPRExcessLimit
;
48 unsigned SGPRCriticalLimit
;
49 unsigned VGPRCriticalLimit
;
51 unsigned TargetOccupancy
;
53 // schedule() have seen a clustered memory operation. Set it to false
54 // before a region scheduling to know if the region had such clusters.
55 bool HasClusteredNodes
;
57 // schedule() have seen a an excess register pressure and had to track
58 // register pressure for actual scheduling heuristics.
59 bool HasExcessPressure
;
64 GCNMaxOccupancySchedStrategy(const MachineSchedContext
*C
);
66 SUnit
*pickNode(bool &IsTopNode
) override
;
68 void initialize(ScheduleDAGMI
*DAG
) override
;
70 void setTargetOccupancy(unsigned Occ
) { TargetOccupancy
= Occ
; }
73 class GCNScheduleDAGMILive final
: public ScheduleDAGMILive
{
78 UnclusteredReschedule
,
79 ClusteredLowOccupancyReschedule
,
80 LastStage
= ClusteredLowOccupancyReschedule
83 const GCNSubtarget
&ST
;
85 SIMachineFunctionInfo
&MFI
;
87 // Occupancy target at the beginning of function scheduling cycle.
88 unsigned StartingOccupancy
;
90 // Minimal real occupancy recorder for the function.
91 unsigned MinOccupancy
;
93 // Scheduling stage number.
96 // Current region index.
99 // Vector of regions recorder for later rescheduling
100 SmallVector
<std::pair
<MachineBasicBlock::iterator
,
101 MachineBasicBlock::iterator
>, 32> Regions
;
103 // Records if a region is not yet scheduled, or schedule has been reverted,
104 // or we generally desire to reschedule it.
105 BitVector RescheduleRegions
;
107 // Record regions which use clustered loads/stores.
108 BitVector RegionsWithClusters
;
110 // Record regions with high register pressure.
111 BitVector RegionsWithHighRP
;
113 // Region live-in cache.
114 SmallVector
<GCNRPTracker::LiveRegSet
, 32> LiveIns
;
116 // Region pressure cache.
117 SmallVector
<GCNRegPressure
, 32> Pressure
;
119 // Temporary basic block live-in cache.
120 DenseMap
<const MachineBasicBlock
*, GCNRPTracker::LiveRegSet
> MBBLiveIns
;
122 DenseMap
<MachineInstr
*, GCNRPTracker::LiveRegSet
> BBLiveInMap
;
123 DenseMap
<MachineInstr
*, GCNRPTracker::LiveRegSet
> getBBLiveInMap() const;
125 // Return current region pressure.
126 GCNRegPressure
getRealRegPressure() const;
128 // Compute and cache live-ins and pressure for all regions in block.
129 void computeBlockPressure(const MachineBasicBlock
*MBB
);
133 GCNScheduleDAGMILive(MachineSchedContext
*C
,
134 std::unique_ptr
<MachineSchedStrategy
> S
);
136 void schedule() override
;
138 void finalizeSchedule() override
;
141 } // End namespace llvm
143 #endif // GCNSCHEDSTRATEGY_H