Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 1 | //===-- GCNSchedStrategy.h - GCN Scheduler Strategy -*- C++ -*-------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | /// \file |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H |
| 15 | #define LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H |
| 16 | |
Stanislav Mekhanoshin | 464cecf | 2017-05-16 15:43:52 +0000 | [diff] [blame] | 17 | #include "GCNRegPressure.h" |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineScheduler.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 22 | class SIMachineFunctionInfo; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 23 | class SIRegisterInfo; |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 24 | class SISubtarget; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 25 | |
| 26 | /// This is a minimal scheduler strategy. The main difference between this |
| 27 | /// and the GenericScheduler is that GCNSchedStrategy uses different |
| 28 | /// heuristics to determine excess/critical pressure sets. Its goal is to |
| 29 | /// maximize kernel occupancy (i.e. maximum number of waves per simd). |
| 30 | class GCNMaxOccupancySchedStrategy : public GenericScheduler { |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 31 | friend class GCNScheduleDAGMILive; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 32 | |
| 33 | SUnit *pickNodeBidirectional(bool &IsTopNode); |
| 34 | |
| 35 | void pickNodeFromQueue(SchedBoundary &Zone, const CandPolicy &ZonePolicy, |
| 36 | const RegPressureTracker &RPTracker, |
| 37 | SchedCandidate &Cand); |
| 38 | |
| 39 | void initCandidate(SchedCandidate &Cand, SUnit *SU, |
| 40 | bool AtTop, const RegPressureTracker &RPTracker, |
| 41 | const SIRegisterInfo *SRI, |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 42 | unsigned SGPRPressure, unsigned VGPRPressure); |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 43 | |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 44 | unsigned SGPRExcessLimit; |
| 45 | unsigned VGPRExcessLimit; |
| 46 | unsigned SGPRCriticalLimit; |
| 47 | unsigned VGPRCriticalLimit; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 48 | |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 49 | unsigned TargetOccupancy; |
| 50 | |
| 51 | MachineFunction *MF; |
| 52 | |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 53 | public: |
| 54 | GCNMaxOccupancySchedStrategy(const MachineSchedContext *C); |
| 55 | |
| 56 | SUnit *pickNode(bool &IsTopNode) override; |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 57 | |
| 58 | void initialize(ScheduleDAGMI *DAG) override; |
Valery Pykhtin | fd4c410 | 2017-03-21 13:15:46 +0000 | [diff] [blame] | 59 | |
| 60 | void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; } |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | class GCNScheduleDAGMILive : public ScheduleDAGMILive { |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 64 | |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 65 | const SISubtarget &ST; |
| 66 | |
| 67 | const SIMachineFunctionInfo &MFI; |
| 68 | |
| 69 | // Occupancy target at the begining of function scheduling cycle. |
| 70 | unsigned StartingOccupancy; |
| 71 | |
| 72 | // Minimal real occupancy recorder for the function. |
| 73 | unsigned MinOccupancy; |
| 74 | |
| 75 | // Scheduling stage number. |
| 76 | unsigned Stage; |
| 77 | |
Stanislav Mekhanoshin | b108607 | 2017-05-16 16:11:26 +0000 | [diff] [blame] | 78 | // Current region index. |
| 79 | size_t RegionIdx; |
| 80 | |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 81 | // Vecor of regions recorder for later rescheduling |
Stanislav Mekhanoshin | b933c3f | 2017-03-28 21:48:54 +0000 | [diff] [blame] | 82 | SmallVector<std::pair<MachineBasicBlock::iterator, |
| 83 | MachineBasicBlock::iterator>, 32> Regions; |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 84 | |
Stanislav Mekhanoshin | b108607 | 2017-05-16 16:11:26 +0000 | [diff] [blame] | 85 | // Region live-in cache. |
| 86 | SmallVector<GCNRPTracker::LiveRegSet, 32> LiveIns; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 87 | |
Stanislav Mekhanoshin | b108607 | 2017-05-16 16:11:26 +0000 | [diff] [blame] | 88 | // Region pressure cache. |
| 89 | SmallVector<GCNRegPressure, 32> Pressure; |
| 90 | |
| 91 | // Temporary basic block live-in cache. |
| 92 | DenseMap<const MachineBasicBlock*, GCNRPTracker::LiveRegSet> MBBLiveIns; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 93 | |
Stanislav Mekhanoshin | 464cecf | 2017-05-16 15:43:52 +0000 | [diff] [blame] | 94 | // Return current region pressure. |
| 95 | GCNRegPressure getRealRegPressure() const; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 96 | |
Stanislav Mekhanoshin | b108607 | 2017-05-16 16:11:26 +0000 | [diff] [blame] | 97 | // Compute and cache live-ins and pressure for all regions in block. |
| 98 | void computeBlockPressure(const MachineBasicBlock *MBB); |
| 99 | |
| 100 | |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 101 | public: |
| 102 | GCNScheduleDAGMILive(MachineSchedContext *C, |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 103 | std::unique_ptr<MachineSchedStrategy> S); |
| 104 | |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 105 | void schedule() override; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 106 | |
| 107 | void finalizeSchedule() override; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | } // End namespace llvm |
| 111 | |
| 112 | #endif // GCNSCHEDSTRATEGY_H |