]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/GCNSchedStrategy.h
Merge ^/head r317503 through r317807.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / GCNSchedStrategy.h
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
21 class SIMachineFunctionInfo;
22 class SIRegisterInfo;
23 class SISubtarget;
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 {
30   friend class GCNScheduleDAGMILive;
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,
41                      unsigned SGPRPressure, unsigned VGPRPressure);
42
43   unsigned SGPRExcessLimit;
44   unsigned VGPRExcessLimit;
45   unsigned SGPRCriticalLimit;
46   unsigned VGPRCriticalLimit;
47
48   unsigned TargetOccupancy;
49
50   MachineFunction *MF;
51
52 public:
53   GCNMaxOccupancySchedStrategy(const MachineSchedContext *C);
54
55   SUnit *pickNode(bool &IsTopNode) override;
56
57   void initialize(ScheduleDAGMI *DAG) override;
58
59   void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; }
60 };
61
62 class GCNScheduleDAGMILive : public ScheduleDAGMILive {
63
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<MachineBasicBlock::iterator,
79                         MachineBasicBlock::iterator>, 32> Regions;
80
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
93 public:
94   GCNScheduleDAGMILive(MachineSchedContext *C,
95                        std::unique_ptr<MachineSchedStrategy> S);
96
97   void schedule() override;
98
99   void finalizeSchedule() override;
100 };
101
102 } // End namespace llvm
103
104 #endif // GCNSCHEDSTRATEGY_H