blob: 060d2ca72d93de790e392bb588796cca64dec295 [file] [log] [blame]
Tom Stellard0d23ebe2016-08-29 19:42:52 +00001//===-- 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 Mekhanoshin464cecf2017-05-16 15:43:52 +000017#include "GCNRegPressure.h"
Tom Stellard0d23ebe2016-08-29 19:42:52 +000018#include "llvm/CodeGen/MachineScheduler.h"
19
20namespace llvm {
21
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000022class SIMachineFunctionInfo;
Tom Stellard0d23ebe2016-08-29 19:42:52 +000023class SIRegisterInfo;
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000024class SISubtarget;
Tom Stellard0d23ebe2016-08-29 19:42:52 +000025
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).
30class GCNMaxOccupancySchedStrategy : public GenericScheduler {
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000031 friend class GCNScheduleDAGMILive;
Tom Stellard0d23ebe2016-08-29 19:42:52 +000032
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 Mekhanoshin582a5232017-02-15 17:19:50 +000042 unsigned SGPRPressure, unsigned VGPRPressure);
Tom Stellard0d23ebe2016-08-29 19:42:52 +000043
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000044 unsigned SGPRExcessLimit;
45 unsigned VGPRExcessLimit;
46 unsigned SGPRCriticalLimit;
47 unsigned VGPRCriticalLimit;
Tom Stellard0d23ebe2016-08-29 19:42:52 +000048
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000049 unsigned TargetOccupancy;
50
51 MachineFunction *MF;
52
Tom Stellard0d23ebe2016-08-29 19:42:52 +000053public:
54 GCNMaxOccupancySchedStrategy(const MachineSchedContext *C);
55
56 SUnit *pickNode(bool &IsTopNode) override;
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000057
58 void initialize(ScheduleDAGMI *DAG) override;
Valery Pykhtinfd4c4102017-03-21 13:15:46 +000059
60 void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; }
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000061};
62
63class GCNScheduleDAGMILive : public ScheduleDAGMILive {
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +000064
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000065 const SISubtarget &ST;
66
67 const SIMachineFunctionInfo &MFI;
68
Hiroshi Inouee9dea6e2017-07-13 06:48:39 +000069 // Occupancy target at the beginning of function scheduling cycle.
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000070 unsigned StartingOccupancy;
71
72 // Minimal real occupancy recorder for the function.
73 unsigned MinOccupancy;
74
75 // Scheduling stage number.
76 unsigned Stage;
77
Stanislav Mekhanoshinb1086072017-05-16 16:11:26 +000078 // Current region index.
79 size_t RegionIdx;
80
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000081 // Vecor of regions recorder for later rescheduling
Stanislav Mekhanoshinb933c3f2017-03-28 21:48:54 +000082 SmallVector<std::pair<MachineBasicBlock::iterator,
83 MachineBasicBlock::iterator>, 32> Regions;
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000084
Stanislav Mekhanoshinb1086072017-05-16 16:11:26 +000085 // Region live-in cache.
86 SmallVector<GCNRPTracker::LiveRegSet, 32> LiveIns;
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +000087
Stanislav Mekhanoshinb1086072017-05-16 16:11:26 +000088 // Region pressure cache.
89 SmallVector<GCNRegPressure, 32> Pressure;
90
91 // Temporary basic block live-in cache.
92 DenseMap<const MachineBasicBlock*, GCNRPTracker::LiveRegSet> MBBLiveIns;
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +000093
Stanislav Mekhanoshin464cecf2017-05-16 15:43:52 +000094 // Return current region pressure.
95 GCNRegPressure getRealRegPressure() const;
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +000096
Stanislav Mekhanoshinb1086072017-05-16 16:11:26 +000097 // Compute and cache live-ins and pressure for all regions in block.
98 void computeBlockPressure(const MachineBasicBlock *MBB);
99
100
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +0000101public:
102 GCNScheduleDAGMILive(MachineSchedContext *C,
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +0000103 std::unique_ptr<MachineSchedStrategy> S);
104
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +0000105 void schedule() override;
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +0000106
107 void finalizeSchedule() override;
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000108};
109
110} // End namespace llvm
111
112#endif // GCNSCHEDSTRATEGY_H