]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/GCNIterativeScheduler.h
MFV r326785: 8880 improve DTrace error checking
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / GCNIterativeScheduler.h
1 //===--------- GCNIterativeScheduler.h - GCN Scheduler -*- 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_GCNITERATIVESCHEDULER_H
15 #define LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
16
17 #include "GCNRegPressure.h"
18
19 #include "llvm/CodeGen/MachineScheduler.h"
20
21 namespace llvm {
22
23 class GCNIterativeScheduler : public ScheduleDAGMILive {
24   typedef ScheduleDAGMILive BaseClass;
25 public:
26   enum StrategyKind {
27     SCHEDULE_MINREGONLY,
28     SCHEDULE_MINREGFORCED,
29     SCHEDULE_LEGACYMAXOCCUPANCY
30   };
31
32   GCNIterativeScheduler(MachineSchedContext *C,
33                         StrategyKind S);
34
35   void schedule() override;
36
37   void enterRegion(MachineBasicBlock *BB,
38                    MachineBasicBlock::iterator Begin,
39                    MachineBasicBlock::iterator End,
40                    unsigned RegionInstrs) override;
41
42   void finalizeSchedule() override;
43
44 protected:
45
46   typedef ArrayRef<const SUnit*> ScheduleRef;
47
48   struct TentativeSchedule {
49     std::vector<MachineInstr*> Schedule;
50     GCNRegPressure MaxPressure;
51   };
52
53   struct Region {
54     // Fields except for BestSchedule are supposed to reflect current IR state
55     // `const` fields are to emphasize they shouldn't change for any schedule.
56     MachineBasicBlock::iterator Begin;
57     // End is either a boundary instruction or end of basic block
58     const MachineBasicBlock::iterator End;
59     const unsigned NumRegionInstrs;
60     GCNRegPressure MaxPressure;
61
62     // best schedule for the region so far (not scheduled yet)
63     std::unique_ptr<TentativeSchedule> BestSchedule;
64   };
65
66   SpecificBumpPtrAllocator<Region> Alloc;
67   std::vector<Region*> Regions;
68
69   MachineSchedContext *Context;
70   const StrategyKind Strategy;
71   mutable GCNUpwardRPTracker UPTracker;
72
73   class BuildDAG;
74   class OverrideLegacyStrategy;
75
76   template <typename Range>
77   GCNRegPressure getSchedulePressure(const Region &R,
78                                      Range &&Schedule) const;
79
80   GCNRegPressure getRegionPressure(MachineBasicBlock::iterator Begin,
81                                    MachineBasicBlock::iterator End) const;
82
83   GCNRegPressure getRegionPressure(const Region &R) const {
84     return getRegionPressure(R.Begin, R.End);
85   }
86
87   void setBestSchedule(Region &R,
88                        ScheduleRef Schedule,
89                        const GCNRegPressure &MaxRP = GCNRegPressure());
90
91   void scheduleBest(Region &R);
92
93   std::vector<MachineInstr*> detachSchedule(ScheduleRef Schedule) const;
94
95   void sortRegionsByPressure(unsigned TargetOcc);
96
97   template <typename Range>
98   void scheduleRegion(Region &R, Range &&Schedule,
99                       const GCNRegPressure &MaxRP = GCNRegPressure());
100
101   unsigned tryMaximizeOccupancy(unsigned TargetOcc =
102                                 std::numeric_limits<unsigned>::max());
103
104   void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy = true);
105   void scheduleMinReg(bool force = false);
106
107   void printRegions(raw_ostream &OS) const;
108   void printSchedResult(raw_ostream &OS,
109                         const Region *R,
110                         const GCNRegPressure &RP) const;
111   void printSchedRP(raw_ostream &OS,
112                     const GCNRegPressure &Before,
113                     const GCNRegPressure &After) const;
114 };
115
116 } // End namespace llvm
117
118 #endif // LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H