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 | |
| 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; |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 23 | class SISubtarget; |
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). |
| 29 | class GCNMaxOccupancySchedStrategy : 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 | |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 43 | unsigned SGPRExcessLimit; |
| 44 | unsigned VGPRExcessLimit; |
| 45 | unsigned SGPRCriticalLimit; |
| 46 | unsigned VGPRCriticalLimit; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 47 | |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 48 | unsigned TargetOccupancy; |
| 49 | |
| 50 | MachineFunction *MF; |
| 51 | |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 52 | public: |
| 53 | GCNMaxOccupancySchedStrategy(const MachineSchedContext *C); |
| 54 | |
| 55 | SUnit *pickNode(bool &IsTopNode) override; |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 56 | |
| 57 | void initialize(ScheduleDAGMI *DAG) override; |
Valery Pykhtin | fd4c410 | 2017-03-21 13:15:46 +0000 | [diff] [blame^] | 58 | |
| 59 | void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; } |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | class GCNScheduleDAGMILive : public ScheduleDAGMILive { |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 63 | |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 64 | const SISubtarget &ST; |
| 65 | |
| 66 | const SIMachineFunctionInfo &MFI; |
| 67 | |
| 68 | // Occupancy target at the begining of function scheduling cycle. |
| 69 | unsigned StartingOccupancy; |
| 70 | |
| 71 | // Minimal real occupancy recorder for the function. |
| 72 | unsigned MinOccupancy; |
| 73 | |
| 74 | // Scheduling stage number. |
| 75 | unsigned Stage; |
| 76 | |
| 77 | // Vecor of regions recorder for later rescheduling |
| 78 | SmallVector<std::pair<const MachineBasicBlock::iterator, |
| 79 | const MachineBasicBlock::iterator>, 32> Regions; |
| 80 | |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 81 | // Region live-ins. |
| 82 | DenseMap<unsigned, LaneBitmask> LiveIns; |
| 83 | |
| 84 | // Number of live-ins to the current region, first SGPR then VGPR. |
| 85 | std::pair<unsigned, unsigned> LiveInPressure; |
| 86 | |
| 87 | // Collect current region live-ins. |
| 88 | void discoverLiveIns(); |
| 89 | |
| 90 | // Return current region pressure. First value is SGPR number, second is VGPR. |
| 91 | std::pair<unsigned, unsigned> getRealRegPressure() const; |
| 92 | |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 93 | public: |
| 94 | GCNScheduleDAGMILive(MachineSchedContext *C, |
Stanislav Mekhanoshin | 357d3db | 2017-02-28 19:20:33 +0000 | [diff] [blame] | 95 | std::unique_ptr<MachineSchedStrategy> S); |
| 96 | |
| 97 | void enterRegion(MachineBasicBlock *bb, |
| 98 | MachineBasicBlock::iterator begin, |
| 99 | MachineBasicBlock::iterator end, |
| 100 | unsigned regioninstrs) override; |
Stanislav Mekhanoshin | 582a523 | 2017-02-15 17:19:50 +0000 | [diff] [blame] | 101 | |
| 102 | void schedule() override; |
Stanislav Mekhanoshin | 282e8e4 | 2017-02-28 17:22:39 +0000 | [diff] [blame] | 103 | |
| 104 | void finalizeSchedule() override; |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | } // End namespace llvm |
| 108 | |
| 109 | #endif // GCNSCHEDSTRATEGY_H |