blob: daf0d71f47be609157ba4b7c72fc2b6366d2c11b [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;
Valery Pykhtinfd4c4102017-03-21 13:15:46 +000058
59 void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; }
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +000060};
61
62class GCNScheduleDAGMILive : public ScheduleDAGMILive {
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +000063
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000064 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 Mekhanoshin282e8e42017-02-28 17:22:39 +000081 // 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 Mekhanoshin582a5232017-02-15 17:19:50 +000093public:
94 GCNScheduleDAGMILive(MachineSchedContext *C,
Stanislav Mekhanoshin357d3db2017-02-28 19:20:33 +000095 std::unique_ptr<MachineSchedStrategy> S);
96
97 void enterRegion(MachineBasicBlock *bb,
98 MachineBasicBlock::iterator begin,
99 MachineBasicBlock::iterator end,
100 unsigned regioninstrs) override;
Stanislav Mekhanoshin582a5232017-02-15 17:19:50 +0000101
102 void schedule() override;
Stanislav Mekhanoshin282e8e42017-02-28 17:22:39 +0000103
104 void finalizeSchedule() override;
Tom Stellard0d23ebe2016-08-29 19:42:52 +0000105};
106
107} // End namespace llvm
108
109#endif // GCNSCHEDSTRATEGY_H