Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 1 | //===-- GCNSchedStrategy.h - GCN Scheduler Strategy -*- C++ -*-------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | /// \file |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H |
| 14 | #define LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H |
| 15 | |
Stanislav Mekhanoshin | 464cecf | 2017-05-16 15:43:52 +0000 | [diff] [blame] | 16 | #include "GCNRegPressure.h" |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineScheduler.h" |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 21 | class SIMachineFunctionInfo; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 22 | class SIRegisterInfo; |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 23 | class GCNSubtarget; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 24 | |
| 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). |
Matt Arsenault | 462403a | 2019-05-08 22:10:04 +0000 | [diff] [blame] | 29 | class GCNMaxOccupancySchedStrategy final : public GenericScheduler { |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 30 | friend class GCNScheduleDAGMILive; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 31 | |
| 32 | SUnit *pickNodeBidirectional(bool &IsTopNode); |
| 33 | |
| 34 | void pickNodeFromQueue(SchedBoundary &Zone, const CandPolicy &ZonePolicy, |
| 35 | const RegPressureTracker &RPTracker, |
| 36 | SchedCandidate &Cand); |
| 37 | |
| 38 | void initCandidate(SchedCandidate &Cand, SUnit *SU, |
| 39 | bool AtTop, const RegPressureTracker &RPTracker, |
| 40 | const SIRegisterInfo *SRI, |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 41 | unsigned SGPRPressure, unsigned VGPRPressure); |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 42 | |
Matt Arsenault | f54daff | 2019-09-05 22:44:06 +0000 | [diff] [blame] | 43 | std::vector<unsigned> Pressure; |
| 44 | std::vector<unsigned> MaxPressure; |
| 45 | |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 46 | unsigned SGPRExcessLimit; |
| 47 | unsigned VGPRExcessLimit; |
| 48 | unsigned SGPRCriticalLimit; |
| 49 | unsigned VGPRCriticalLimit; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 50 | |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 51 | unsigned TargetOccupancy; |
| 52 | |
| 53 | MachineFunction *MF; |
| 54 | |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 55 | public: |
| 56 | GCNMaxOccupancySchedStrategy(const MachineSchedContext *C); |
| 57 | |
| 58 | SUnit *pickNode(bool &IsTopNode) override; |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 59 | |
| 60 | void initialize(ScheduleDAGMI *DAG) override; |
Valery Pykhtin | fd4c410 | 2017-03-21 13:15:46 +0000 | [diff] [blame] | 61 | |
| 62 | void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; } |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
Matt Arsenault | 462403a | 2019-05-08 22:10:04 +0000 | [diff] [blame] | 65 | class GCNScheduleDAGMILive final : public ScheduleDAGMILive { |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 66 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 67 | const GCNSubtarget &ST; |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 68 | |
Stanislav Mekhanoshin | d4b500c | 2018-05-31 05:36:04 +0000 | [diff] [blame] | 69 | SIMachineFunctionInfo &MFI; |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 70 | |
Hiroshi Inoue | e9dea6e | 2017-07-13 06:48:39 +0000 | [diff] [blame] | 71 | // Occupancy target at the beginning of function scheduling cycle. |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 72 | unsigned StartingOccupancy; |
| 73 | |
| 74 | // Minimal real occupancy recorder for the function. |
| 75 | unsigned MinOccupancy; |
| 76 | |
| 77 | // Scheduling stage number. |
| 78 | unsigned Stage; |
| 79 | |
Stanislav Mekhanoshin | b108607 | 2017-05-16 16:11:26 +0000 | [diff] [blame] | 80 | // Current region index. |
| 81 | size_t RegionIdx; |
| 82 | |
Austin Kerbow | 83e5214 | 2019-04-24 23:32:21 +0000 | [diff] [blame] | 83 | // Vector of regions recorder for later rescheduling |
Stanislav Mekhanoshin | b933c3f | 2017-03-28 21:48:54 +0000 | [diff] [blame] | 84 | SmallVector<std::pair<MachineBasicBlock::iterator, |
| 85 | MachineBasicBlock::iterator>, 32> Regions; |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 86 | |
Stanislav Mekhanoshin | b108607 | 2017-05-16 16:11:26 +0000 | [diff] [blame] | 87 | // Region live-in cache. |
| 88 | SmallVector<GCNRPTracker::LiveRegSet, 32> LiveIns; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 89 | |
Stanislav Mekhanoshin | b108607 | 2017-05-16 16:11:26 +0000 | [diff] [blame] | 90 | // Region pressure cache. |
| 91 | SmallVector<GCNRegPressure, 32> Pressure; |
| 92 | |
| 93 | // Temporary basic block live-in cache. |
| 94 | DenseMap<const MachineBasicBlock*, GCNRPTracker::LiveRegSet> MBBLiveIns; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 95 | |
Valery Pykhtin | 7e854e1 | 2019-06-18 11:43:17 +0000 | [diff] [blame] | 96 | DenseMap<MachineInstr *, GCNRPTracker::LiveRegSet> BBLiveInMap; |
| 97 | DenseMap<MachineInstr *, GCNRPTracker::LiveRegSet> getBBLiveInMap() const; |
| 98 | |
Stanislav Mekhanoshin | 464cecf | 2017-05-16 15:43:52 +0000 | [diff] [blame] | 99 | // Return current region pressure. |
| 100 | GCNRegPressure getRealRegPressure() const; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 101 | |
Stanislav Mekhanoshin | b108607 | 2017-05-16 16:11:26 +0000 | [diff] [blame] | 102 | // Compute and cache live-ins and pressure for all regions in block. |
| 103 | void computeBlockPressure(const MachineBasicBlock *MBB); |
| 104 | |
| 105 | |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 106 | public: |
| 107 | GCNScheduleDAGMILive(MachineSchedContext *C, |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 108 | std::unique_ptr<MachineSchedStrategy> S); |
| 109 | |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 110 | void schedule() override; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 111 | |
| 112 | void finalizeSchedule() override; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } // End namespace llvm |
| 116 | |
| 117 | #endif // GCNSCHEDSTRATEGY_H |