[Codegen] Alter the default promotion for saturating adds and subs
[llvm-complete.git] / lib / Target / AMDGPU / GCNIterativeScheduler.h
blobe6f83914af5ba3c92047de8ad96d9bf1e0dc1216
1 //===- GCNIterativeScheduler.h - GCN Scheduler ------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
10 #define LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
12 #include "GCNRegPressure.h"
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/CodeGen/MachineBasicBlock.h"
15 #include "llvm/CodeGen/MachineScheduler.h"
16 #include "llvm/Support/Allocator.h"
17 #include <limits>
18 #include <memory>
19 #include <vector>
21 namespace llvm {
23 class MachineInstr;
24 class SUnit;
25 class raw_ostream;
27 class GCNIterativeScheduler : public ScheduleDAGMILive {
28 using BaseClass = ScheduleDAGMILive;
30 public:
31 enum StrategyKind {
32 SCHEDULE_MINREGONLY,
33 SCHEDULE_MINREGFORCED,
34 SCHEDULE_LEGACYMAXOCCUPANCY,
35 SCHEDULE_ILP
38 GCNIterativeScheduler(MachineSchedContext *C,
39 StrategyKind S);
41 void schedule() override;
43 void enterRegion(MachineBasicBlock *BB,
44 MachineBasicBlock::iterator Begin,
45 MachineBasicBlock::iterator End,
46 unsigned RegionInstrs) override;
48 void finalizeSchedule() override;
50 protected:
51 using ScheduleRef = ArrayRef<const SUnit *>;
53 struct TentativeSchedule {
54 std::vector<MachineInstr *> Schedule;
55 GCNRegPressure MaxPressure;
58 struct Region {
59 // Fields except for BestSchedule are supposed to reflect current IR state
60 // `const` fields are to emphasize they shouldn't change for any schedule.
61 MachineBasicBlock::iterator Begin;
62 // End is either a boundary instruction or end of basic block
63 const MachineBasicBlock::iterator End;
64 const unsigned NumRegionInstrs;
65 GCNRegPressure MaxPressure;
67 // best schedule for the region so far (not scheduled yet)
68 std::unique_ptr<TentativeSchedule> BestSchedule;
71 SpecificBumpPtrAllocator<Region> Alloc;
72 std::vector<Region*> Regions;
74 MachineSchedContext *Context;
75 const StrategyKind Strategy;
76 mutable GCNUpwardRPTracker UPTracker;
78 class BuildDAG;
79 class OverrideLegacyStrategy;
81 template <typename Range>
82 GCNRegPressure getSchedulePressure(const Region &R,
83 Range &&Schedule) const;
85 GCNRegPressure getRegionPressure(MachineBasicBlock::iterator Begin,
86 MachineBasicBlock::iterator End) const;
88 GCNRegPressure getRegionPressure(const Region &R) const {
89 return getRegionPressure(R.Begin, R.End);
92 void setBestSchedule(Region &R,
93 ScheduleRef Schedule,
94 const GCNRegPressure &MaxRP = GCNRegPressure());
96 void scheduleBest(Region &R);
98 std::vector<MachineInstr*> detachSchedule(ScheduleRef Schedule) const;
100 void sortRegionsByPressure(unsigned TargetOcc);
102 template <typename Range>
103 void scheduleRegion(Region &R, Range &&Schedule,
104 const GCNRegPressure &MaxRP = GCNRegPressure());
106 unsigned tryMaximizeOccupancy(unsigned TargetOcc =
107 std::numeric_limits<unsigned>::max());
109 void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy = true);
110 void scheduleMinReg(bool force = false);
111 void scheduleILP(bool TryMaximizeOccupancy = true);
113 void printRegions(raw_ostream &OS) const;
114 void printSchedResult(raw_ostream &OS,
115 const Region *R,
116 const GCNRegPressure &RP) const;
117 void printSchedRP(raw_ostream &OS,
118 const GCNRegPressure &Before,
119 const GCNRegPressure &After) const;
122 } // end namespace llvm
124 #endif // LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H