LLVM  12.0.0git
GCNIterativeScheduler.h
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file defines the class GCNIterativeScheduler, which uses an iterative
11 /// approach to find a best schedule for GCN architecture. It basically makes
12 /// use of various lightweight schedules, scores them, chooses best one based on
13 /// their scores, and finally implements the chosen one.
14 ///
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
18 #define LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
19 
20 #include "GCNRegPressure.h"
21 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/Support/Allocator.h"
25 #include <limits>
26 #include <memory>
27 #include <vector>
28 
29 namespace llvm {
30 
31 class MachineInstr;
32 class SUnit;
33 class raw_ostream;
34 
37 
38 public:
39  enum StrategyKind {
44  };
45 
47  StrategyKind S);
48 
49  void schedule() override;
50 
54  unsigned RegionInstrs) override;
55 
56  void finalizeSchedule() override;
57 
58 protected:
60 
62  std::vector<MachineInstr *> Schedule;
64  };
65 
66  struct Region {
67  // Fields except for BestSchedule are supposed to reflect current IR state
68  // `const` fields are to emphasize they shouldn't change for any schedule.
70  // End is either a boundary instruction or end of basic block
72  const unsigned NumRegionInstrs;
74 
75  // best schedule for the region so far (not scheduled yet)
76  std::unique_ptr<TentativeSchedule> BestSchedule;
77  };
78 
80  std::vector<Region*> Regions;
81 
85 
86  class BuildDAG;
88 
89  template <typename Range>
91  Range &&Schedule) const;
92 
94  MachineBasicBlock::iterator End) const;
95 
97  return getRegionPressure(R.Begin, R.End);
98  }
99 
100  void setBestSchedule(Region &R,
102  const GCNRegPressure &MaxRP = GCNRegPressure());
103 
104  void scheduleBest(Region &R);
105 
106  std::vector<MachineInstr*> detachSchedule(ScheduleRef Schedule) const;
107 
108  void sortRegionsByPressure(unsigned TargetOcc);
109 
110  template <typename Range>
111  void scheduleRegion(Region &R, Range &&Schedule,
112  const GCNRegPressure &MaxRP = GCNRegPressure());
113 
114  unsigned tryMaximizeOccupancy(unsigned TargetOcc =
116 
117  void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy = true);
118  void scheduleMinReg(bool force = false);
119  void scheduleILP(bool TryMaximizeOccupancy = true);
120 
121  void printRegions(raw_ostream &OS) const;
122  void printSchedResult(raw_ostream &OS,
123  const Region *R,
124  const GCNRegPressure &RP) const;
125  void printSchedRP(raw_ostream &OS,
126  const GCNRegPressure &Before,
127  const GCNRegPressure &After) const;
128 };
129 
130 } // end namespace llvm
131 
132 #endif // LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
unsigned tryMaximizeOccupancy(unsigned TargetOcc=std::numeric_limits< unsigned >::max())
uint64_t CallInst * C
void enterRegion(MachineBasicBlock *BB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned RegionInstrs) override
Implement the ScheduleDAGInstrs interface for handling the next scheduling region.
GCNRegPressure getRegionPressure(MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End) const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void sortRegionsByPressure(unsigned TargetOcc)
SpecificBumpPtrAllocator< Region > Alloc
std::vector< Region * > Regions
std::vector< MachineInstr * > detachSchedule(ScheduleRef Schedule) const
This file defines the BumpPtrAllocator interface.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
void printRegions(raw_ostream &OS) const
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy=true)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
void printSchedRP(raw_ostream &OS, const GCNRegPressure &Before, const GCNRegPressure &After) const
void setBestSchedule(Region &R, ScheduleRef Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
GCNRegPressure getSchedulePressure(const Region &R, Range &&Schedule) const
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:350
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
Definition: Allocator.h:377
const MachineBasicBlock::iterator End
ScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
void printSchedResult(raw_ostream &OS, const Region *R, const GCNRegPressure &RP) const
GCNIterativeScheduler(MachineSchedContext *C, StrategyKind S)
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
void scheduleRegion(Region &R, Range &&Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
This file defines the GCNRegPressure class, which tracks registry pressure by bookkeeping number of S...
void scheduleMinReg(bool force=false)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
MachineBasicBlock * BB
The block in which to insert instructions.
void scheduleILP(bool TryMaximizeOccupancy=true)
GCNRegPressure getRegionPressure(const Region &R) const
std::unique_ptr< TentativeSchedule > BestSchedule