1 //===-- GCNSchedStrategy.h - GCN Scheduler Strategy -*- C++ -*-------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
15 #define LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_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 : 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 unsigned SGPRExcessLimit;
44 unsigned VGPRExcessLimit;
45 unsigned SGPRCriticalLimit;
46 unsigned VGPRCriticalLimit;
48 unsigned TargetOccupancy;
53 GCNMaxOccupancySchedStrategy(const MachineSchedContext *C);
55 SUnit *pickNode(bool &IsTopNode) override;
57 void initialize(ScheduleDAGMI *DAG) override;
59 void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; }
62 class GCNScheduleDAGMILive : public ScheduleDAGMILive {
64 const SISubtarget &ST;
66 const SIMachineFunctionInfo &MFI;
68 // Occupancy target at the begining of function scheduling cycle.
69 unsigned StartingOccupancy;
71 // Minimal real occupancy recorder for the function.
72 unsigned MinOccupancy;
74 // Scheduling stage number.
77 // Vecor of regions recorder for later rescheduling
78 SmallVector<std::pair<MachineBasicBlock::iterator,
79 MachineBasicBlock::iterator>, 32> Regions;
82 DenseMap<unsigned, LaneBitmask> LiveIns;
84 // Number of live-ins to the current region, first SGPR then VGPR.
85 std::pair<unsigned, unsigned> LiveInPressure;
87 // Collect current region live-ins.
88 void discoverLiveIns();
90 // Return current region pressure. First value is SGPR number, second is VGPR.
91 std::pair<unsigned, unsigned> getRealRegPressure() const;
94 GCNScheduleDAGMILive(MachineSchedContext *C,
95 std::unique_ptr<MachineSchedStrategy> S);
97 void schedule() override;
99 void finalizeSchedule() override;
102 } // End namespace llvm
104 #endif // GCNSCHEDSTRATEGY_H