blob: 82ad089a5524b4ab8af756e1b6baa94208931d5c [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
17#include "llvm/CodeGen/MachineScheduler.h"
18
19namespace llvm {
20
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000021class SIMachineFunctionInfo;
Tom Stellard0d23ebe2016-08-29 19:42:52 +000022class SIRegisterInfo;
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000023class SISubtarget;
Tom Stellard0d23ebe2016-08-29 19:42:52 +000024
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).
29class GCNMaxOccupancySchedStrategy : public GenericScheduler {
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000030 friend class GCNScheduleDAGMILive;
Tom Stellard0d23ebe2016-08-29 19:42:52 +000031
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 Mekhanoshin582a5232017-02-15 17:19:50 +000041 unsigned SGPRPressure, unsigned VGPRPressure);
Tom Stellard0d23ebe2016-08-29 19:42:52 +000042
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000043 unsigned SGPRExcessLimit;
44 unsigned VGPRExcessLimit;
45 unsigned SGPRCriticalLimit;
46 unsigned VGPRCriticalLimit;
Tom Stellard0d23ebe2016-08-29 19:42:52 +000047
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000048 unsigned TargetOccupancy;
49
50 MachineFunction *MF;
51
Tom Stellard0d23ebe2016-08-29 19:42:52 +000052public:
53 GCNMaxOccupancySchedStrategy(const MachineSchedContext *C);
54
55 SUnit *pickNode(bool &IsTopNode) override;
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000056
57 void initialize(ScheduleDAGMI *DAG) override;
58};
59
60class GCNScheduleDAGMILive : public ScheduleDAGMILive {
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +000061
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000062 const SISubtarget &ST;
63
64 const SIMachineFunctionInfo &MFI;
65
66 // Occupancy target at the begining of function scheduling cycle.
67 unsigned StartingOccupancy;
68
69 // Minimal real occupancy recorder for the function.
70 unsigned MinOccupancy;
71
72 // Scheduling stage number.
73 unsigned Stage;
74
75 // Vecor of regions recorder for later rescheduling
76 SmallVector<std::pair<const MachineBasicBlock::iterator,
77 const MachineBasicBlock::iterator>, 32> Regions;
78
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +000079 // Region live-ins.
80 DenseMap<unsigned, LaneBitmask> LiveIns;
81
82 // Number of live-ins to the current region, first SGPR then VGPR.
83 std::pair<unsigned, unsigned> LiveInPressure;
84
85 // Collect current region live-ins.
86 void discoverLiveIns();
87
88 // Return current region pressure. First value is SGPR number, second is VGPR.
89 std::pair<unsigned, unsigned> getRealRegPressure() const;
90
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000091public:
92 GCNScheduleDAGMILive(MachineSchedContext *C,
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000093 std::unique_ptr<MachineSchedStrategy> S);
94
95 void enterRegion(MachineBasicBlock *bb,
96 MachineBasicBlock::iterator begin,
97 MachineBasicBlock::iterator end,
98 unsigned regioninstrs) override;
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000099
100 void schedule() override;
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +0000101
102 void finalizeSchedule() override;
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000103};
104
105} // End namespace llvm
106
107#endif // GCNSCHEDSTRATEGY_H