LLVM  5.0.0
GCNRegPressure.h
Go to the documentation of this file.
1 //===---------------------- GCNRegPressure.h -*- 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_GCNREGPRESSURE_H
15 #define LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H
16 
17 #include "AMDGPUSubtarget.h"
18 
19 #include <limits>
20 
21 namespace llvm {
22 
24  enum RegKind {
30  };
31 
33  clear();
34  }
35 
36  bool empty() const { return getSGPRNum() == 0 && getVGPRNum() == 0; }
37 
38  void clear() { std::fill(&Value[0], &Value[TOTAL_KINDS], 0); }
39 
40  unsigned getSGPRNum() const { return Value[SGPR32]; }
41  unsigned getVGPRNum() const { return Value[VGPR32]; }
42 
43  unsigned getVGPRTuplesWeight() const { return Value[VGPR_TUPLE]; }
44  unsigned getSGPRTuplesWeight() const { return Value[SGPR_TUPLE]; }
45 
46  unsigned getOccupancy(const SISubtarget &ST) const {
49  }
50 
51  void inc(unsigned Reg,
52  LaneBitmask PrevMask,
53  LaneBitmask NewMask,
54  const MachineRegisterInfo &MRI);
55 
56  bool higherOccupancy(const SISubtarget &ST, const GCNRegPressure& O) const {
57  return getOccupancy(ST) > O.getOccupancy(ST);
58  }
59 
60  bool less(const SISubtarget &ST, const GCNRegPressure& O,
61  unsigned MaxOccupancy = std::numeric_limits<unsigned>::max()) const;
62 
63  bool operator==(const GCNRegPressure &O) const {
64  return std::equal(&Value[0], &Value[TOTAL_KINDS], O.Value);
65  }
66 
67  bool operator!=(const GCNRegPressure &O) const {
68  return !(*this == O);
69  }
70 
71  void print(raw_ostream &OS, const SISubtarget *ST=nullptr) const;
72  void dump() const { print(dbgs()); }
73 
74 private:
75  unsigned Value[TOTAL_KINDS];
76 
77  static unsigned getRegKind(unsigned Reg, const MachineRegisterInfo &MRI);
78 
79  friend GCNRegPressure max(const GCNRegPressure &P1,
80  const GCNRegPressure &P2);
81 };
82 
83 inline GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2) {
84  GCNRegPressure Res;
85  for (unsigned I = 0; I < GCNRegPressure::TOTAL_KINDS; ++I)
86  Res.Value[I] = std::max(P1.Value[I], P2.Value[I]);
87  return Res;
88 }
89 
90 class GCNRPTracker {
91 public:
93 
94 protected:
98  const MachineInstr *LastTrackedMI = nullptr;
99  mutable const MachineRegisterInfo *MRI = nullptr;
100  GCNRPTracker(const LiveIntervals &LIS_) : LIS(LIS_) {}
101 public:
102  // live regs for the current state
103  const decltype(LiveRegs) &getLiveRegs() const { return LiveRegs; }
104  const MachineInstr *getLastTrackedMI() const { return LastTrackedMI; }
105 
107 
108  // returns MaxPressure, resetting it
110  auto Res = MaxPressure;
111  MaxPressure.clear();
112  return Res;
113  }
114  decltype(LiveRegs) moveLiveRegs() {
115  return std::move(LiveRegs);
116  }
117  static void printLiveRegs(raw_ostream &OS, const LiveRegSet& LiveRegs,
118  const MachineRegisterInfo &MRI);
119 };
120 
122 public:
124  // reset tracker to the point just below MI
125  // filling live regs upon this point using LIS
126  void reset(const MachineInstr &MI, const LiveRegSet *LiveRegs = nullptr);
127 
128  // move to the state just above the MI
129  void recede(const MachineInstr &MI);
130 
131  // checks whether the tracker's state after receding MI corresponds
132  // to reported by LIS
133  bool isValid() const;
134 };
135 
137  // Last position of reset or advanceBeforeNext
139 
141 
142 public:
144 
145  const MachineBasicBlock::const_iterator getNext() const { return NextMI; }
146 
147  // Reset tracker to the point before the MI
148  // filling live regs upon this point using LIS.
149  // Returns false if block is empty except debug values.
150  bool reset(const MachineInstr &MI, const LiveRegSet *LiveRegs = nullptr);
151 
152  // Move to the state right before the next MI. Returns false if reached
153  // end of the block.
154  bool advanceBeforeNext();
155 
156  // Move to the state at the MI, advanceBeforeNext has to be called first.
157  void advanceToNext();
158 
159  // Move to the state at the next MI. Returns false if reached end of block.
160  bool advance();
161 
162  // Advance instructions until before End.
164 
165  // Reset to Begin and advance to End.
168  const LiveRegSet *LiveRegsCopy = nullptr);
169 };
170 
171 LaneBitmask getLiveLaneMask(unsigned Reg,
172  SlotIndex SI,
173  const LiveIntervals &LIS,
174  const MachineRegisterInfo &MRI);
175 
177  const LiveIntervals &LIS,
178  const MachineRegisterInfo &MRI);
179 
181  const LiveIntervals &LIS) {
182  return getLiveRegs(LIS.getInstructionIndex(MI).getDeadSlot(), LIS,
183  MI.getParent()->getParent()->getRegInfo());
184 }
185 
187  const LiveIntervals &LIS) {
188  return getLiveRegs(LIS.getInstructionIndex(MI).getBaseIndex(), LIS,
189  MI.getParent()->getParent()->getRegInfo());
190 }
191 
192 template <typename Range>
194  Range &&LiveRegs) {
195  GCNRegPressure Res;
196  for (const auto &RM : LiveRegs)
197  Res.inc(RM.first, LaneBitmask::getNone(), RM.second, MRI);
198  return Res;
199 }
200 
201 void printLivesAt(SlotIndex SI,
202  const LiveIntervals &LIS,
203  const MachineRegisterInfo &MRI);
204 
205 } // End namespace llvm
206 
207 #endif // LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool empty() const
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
AMDGPU specific subclass of TargetSubtarget.
static void printLiveRegs(raw_ostream &OS, const LiveRegSet &LiveRegs, const MachineRegisterInfo &MRI)
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
Definition: SlotIndexes.h:242
decltype(MaxPressure) moveMaxPressure()
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
GCNRPTracker(const LiveIntervals &LIS_)
const MachineInstr * LastTrackedMI
bool reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)
GCNRPTracker::LiveRegSet getLiveRegs(SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
friend GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool operator!=(const GCNRegPressure &O) const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
const LiveIntervals & LIS
decltype(LiveRegs) moveLiveRegs()
unsigned getOccupancyWithNumSGPRs(unsigned SGPRs) const
Return the maximum number of waves per SIMD for kernels using SGPRs SGPRs.
Reg
All possible values of the reg field in the ModR/M byte.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
Definition: SlotIndexes.h:260
DenseMap< unsigned, LaneBitmask > LiveRegSet
void inc(unsigned Reg, LaneBitmask PrevMask, LaneBitmask NewMask, const MachineRegisterInfo &MRI)
GCNRPTracker::LiveRegSet getLiveRegsBefore(const MachineInstr &MI, const LiveIntervals &LIS)
unsigned getSGPRTuplesWeight() const
GCNRegPressure CurPressure
void print(raw_ostream &OS, const SISubtarget *ST=nullptr) const
void reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:139
unsigned const MachineRegisterInfo * MRI
decltype(LiveRegs) const & getLiveRegs() const
const MachineInstr * getLastTrackedMI() const
unsigned getOccupancyWithNumVGPRs(unsigned VGPRs) const
Return the maximum number of waves per SIMD for kernels using VGPRs VGPRs.
static const unsigned End
A set of live virtual registers and physical register units.
GCNRPTracker::LiveRegSet getLiveRegsAfter(const MachineInstr &MI, const LiveIntervals &LIS)
unsigned getVGPRTuplesWeight() const
GCNUpwardRPTracker(const LiveIntervals &LIS_)
void printLivesAt(SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
void dump() const
static LaneBitmask getNone()
Definition: LaneBitmask.h:76
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
bool less(const SISubtarget &ST, const GCNRegPressure &O, unsigned MaxOccupancy=std::numeric_limits< unsigned >::max()) const
const MachineBasicBlock::const_iterator getNext() const
unsigned getOccupancy(const SISubtarget &ST) const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
GCNRegPressure getRegPressure(const MachineRegisterInfo &MRI, Range &&LiveRegs)
Representation of each machine instruction.
Definition: MachineInstr.h:59
unsigned getSGPRNum() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned getVGPRNum() const
bool higherOccupancy(const SISubtarget &ST, const GCNRegPressure &O) const
LaneBitmask getLiveLaneMask(unsigned Reg, SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI)
LLVM Value Representation.
Definition: Value.h:73
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
IRTranslator LLVM IR MI
GCNRegPressure MaxPressure
GCNDownwardRPTracker(const LiveIntervals &LIS_)
bool operator==(const GCNRegPressure &O) const
void recede(const MachineInstr &MI)
const MachineRegisterInfo * MRI