LLVM  15.0.0git
RegisterPressure.h
Go to the documentation of this file.
1 //===- RegisterPressure.h - Dynamic Register Pressure -----------*- 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 // This file defines the RegisterPressure class which can be used to track
10 // MachineInstr level register pressure.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CODEGEN_REGISTERPRESSURE_H
15 #define LLVM_CODEGEN_REGISTERPRESSURE_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/SparseSet.h"
23 #include "llvm/MC/LaneBitmask.h"
24 #include <cassert>
25 #include <cstdint>
26 #include <cstdlib>
27 #include <limits>
28 #include <vector>
29 
30 namespace llvm {
31 
32 class LiveIntervals;
33 class MachineFunction;
34 class MachineInstr;
35 class MachineRegisterInfo;
36 class RegisterClassInfo;
37 
39  Register RegUnit; ///< Virtual register or register unit.
41 
44 };
45 
46 /// Base class for register pressure results.
48  /// Map of max reg pressure indexed by pressure set ID, not class ID.
49  std::vector<unsigned> MaxSetPressure;
50 
51  /// List of live in virtual registers or physical register units.
54 
55  void dump(const TargetRegisterInfo *TRI) const;
56 };
57 
58 /// RegisterPressure computed within a region of instructions delimited by
59 /// TopIdx and BottomIdx. During pressure computation, the maximum pressure per
60 /// register pressure set is increased. Once pressure within a region is fully
61 /// computed, the live-in and live-out sets are recorded.
62 ///
63 /// This is preferable to RegionPressure when LiveIntervals are available,
64 /// because delimiting regions by SlotIndex is more robust and convenient than
65 /// holding block iterators. The block contents can change without invalidating
66 /// the pressure result.
68  /// Record the boundary of the region being tracked.
71 
72  void reset();
73 
74  void openTop(SlotIndex NextTop);
75 
76  void openBottom(SlotIndex PrevBottom);
77 };
78 
79 /// RegisterPressure computed within a region of instructions delimited by
80 /// TopPos and BottomPos. This is a less precise version of IntervalPressure for
81 /// use when LiveIntervals are unavailable.
83  /// Record the boundary of the region being tracked.
86 
87  void reset();
88 
90 
92 };
93 
94 /// Capture a change in pressure for a single pressure set. UnitInc may be
95 /// expressed in terms of upward or downward pressure depending on the client
96 /// and will be dynamically adjusted for current liveness.
97 ///
98 /// Pressure increments are tiny, typically 1-2 units, and this is only for
99 /// heuristics, so we don't check UnitInc overflow. Instead, we may have a
100 /// higher level assert that pressure is consistent within a region. We also
101 /// effectively ignore dead defs which don't affect heuristics much.
103  uint16_t PSetID = 0; // ID+1. 0=Invalid.
104  int16_t UnitInc = 0;
105 
106 public:
107  PressureChange() = default;
108  PressureChange(unsigned id): PSetID(id + 1) {
109  assert(id < std::numeric_limits<uint16_t>::max() && "PSetID overflow.");
110  }
111 
112  bool isValid() const { return PSetID > 0; }
113 
114  unsigned getPSet() const {
115  assert(isValid() && "invalid PressureChange");
116  return PSetID - 1;
117  }
118 
119  // If PSetID is invalid, return UINT16_MAX to give it lowest priority.
120  unsigned getPSetOrMax() const {
121  return (PSetID - 1) & std::numeric_limits<uint16_t>::max();
122  }
123 
124  int getUnitInc() const { return UnitInc; }
125 
126  void setUnitInc(int Inc) { UnitInc = Inc; }
127 
128  bool operator==(const PressureChange &RHS) const {
129  return PSetID == RHS.PSetID && UnitInc == RHS.UnitInc;
130  }
131 
132  void dump() const;
133 };
134 
135 /// List of PressureChanges in order of increasing, unique PSetID.
136 ///
137 /// Use a small fixed number, because we can fit more PressureChanges in an
138 /// empty SmallVector than ever need to be tracked per register class. If more
139 /// PSets are affected, then we only track the most constrained.
141  // The initial design was for MaxPSets=4, but that requires PSet partitions,
142  // which are not yet implemented. (PSet partitions are equivalent PSets given
143  // the register classes actually in use within the scheduling region.)
144  enum { MaxPSets = 16 };
145 
146  PressureChange PressureChanges[MaxPSets];
147 
148  using iterator = PressureChange *;
149 
150  iterator nonconst_begin() { return &PressureChanges[0]; }
151  iterator nonconst_end() { return &PressureChanges[MaxPSets]; }
152 
153 public:
155 
156  const_iterator begin() const { return &PressureChanges[0]; }
157  const_iterator end() const { return &PressureChanges[MaxPSets]; }
158 
159  void addPressureChange(Register RegUnit, bool IsDec,
160  const MachineRegisterInfo *MRI);
161 
162  void dump(const TargetRegisterInfo &TRI) const;
163 };
164 
165 /// List of registers defined and used by a machine instruction.
167 public:
168  /// List of virtual registers and register units read by the instruction.
170  /// List of virtual registers and register units defined by the
171  /// instruction which are not dead.
173  /// List of virtual registers and register units defined by the
174  /// instruction but dead.
176 
177  /// Analyze the given instruction \p MI and fill in the Uses, Defs and
178  /// DeadDefs list based on the MachineOperand flags.
179  void collect(const MachineInstr &MI, const TargetRegisterInfo &TRI,
180  const MachineRegisterInfo &MRI, bool TrackLaneMasks,
181  bool IgnoreDead);
182 
183  /// Use liveness information to find dead defs not marked with a dead flag
184  /// and move them to the DeadDefs vector.
185  void detectDeadDefs(const MachineInstr &MI, const LiveIntervals &LIS);
186 
187  /// Use liveness information to find out which uses/defs are partially
188  /// undefined/dead and adjust the RegisterMaskPairs accordingly.
189  /// If \p AddFlagsMI is given then missing read-undef and dead flags will be
190  /// added to the instruction.
191  void adjustLaneLiveness(const LiveIntervals &LIS,
192  const MachineRegisterInfo &MRI, SlotIndex Pos,
193  MachineInstr *AddFlagsMI = nullptr);
194 };
195 
196 /// Array of PressureDiffs.
198  PressureDiff *PDiffArray = nullptr;
199  unsigned Size = 0;
200  unsigned Max = 0;
201 
202 public:
203  PressureDiffs() = default;
204  ~PressureDiffs() { free(PDiffArray); }
205 
206  void clear() { Size = 0; }
207 
208  void init(unsigned N);
209 
210  PressureDiff &operator[](unsigned Idx) {
211  assert(Idx < Size && "PressureDiff index out of bounds");
212  return PDiffArray[Idx];
213  }
214  const PressureDiff &operator[](unsigned Idx) const {
215  return const_cast<PressureDiffs*>(this)->operator[](Idx);
216  }
217 
218  /// Record pressure difference induced by the given operand list to
219  /// node with index \p Idx.
220  void addInstruction(unsigned Idx, const RegisterOperands &RegOpers,
221  const MachineRegisterInfo &MRI);
222 };
223 
224 /// Store the effects of a change in pressure on things that MI scheduler cares
225 /// about.
226 ///
227 /// Excess records the value of the largest difference in register units beyond
228 /// the target's pressure limits across the affected pressure sets, where
229 /// largest is defined as the absolute value of the difference. Negative
230 /// ExcessUnits indicates a reduction in pressure that had already exceeded the
231 /// target's limits.
232 ///
233 /// CriticalMax records the largest increase in the tracker's max pressure that
234 /// exceeds the critical limit for some pressure set determined by the client.
235 ///
236 /// CurrentMax records the largest increase in the tracker's max pressure that
237 /// exceeds the current limit for some pressure set determined by the client.
242 
243  RegPressureDelta() = default;
244 
245  bool operator==(const RegPressureDelta &RHS) const {
246  return Excess == RHS.Excess && CriticalMax == RHS.CriticalMax
247  && CurrentMax == RHS.CurrentMax;
248  }
249  bool operator!=(const RegPressureDelta &RHS) const {
250  return !operator==(RHS);
251  }
252  void dump() const;
253 };
254 
255 /// A set of live virtual registers and physical register units.
256 ///
257 /// This is a wrapper around a SparseSet which deals with mapping register unit
258 /// and virtual register indexes to an index usable by the sparse set.
259 class LiveRegSet {
260 private:
261  struct IndexMaskPair {
262  unsigned Index;
263  LaneBitmask LaneMask;
264 
265  IndexMaskPair(unsigned Index, LaneBitmask LaneMask)
266  : Index(Index), LaneMask(LaneMask) {}
267 
268  unsigned getSparseSetIndex() const {
269  return Index;
270  }
271  };
272 
274  RegSet Regs;
275  unsigned NumRegUnits;
276 
277  unsigned getSparseIndexFromReg(Register Reg) const {
278  if (Reg.isVirtual())
279  return Register::virtReg2Index(Reg) + NumRegUnits;
280  assert(Reg < NumRegUnits);
281  return Reg;
282  }
283 
284  Register getRegFromSparseIndex(unsigned SparseIndex) const {
285  if (SparseIndex >= NumRegUnits)
286  return Register::index2VirtReg(SparseIndex - NumRegUnits);
287  return Register(SparseIndex);
288  }
289 
290 public:
291  void clear();
292  void init(const MachineRegisterInfo &MRI);
293 
295  unsigned SparseIndex = getSparseIndexFromReg(Reg);
296  RegSet::const_iterator I = Regs.find(SparseIndex);
297  if (I == Regs.end())
298  return LaneBitmask::getNone();
299  return I->LaneMask;
300  }
301 
302  /// Mark the \p Pair.LaneMask lanes of \p Pair.Reg as live.
303  /// Returns the previously live lanes of \p Pair.Reg.
305  unsigned SparseIndex = getSparseIndexFromReg(Pair.RegUnit);
306  auto InsertRes = Regs.insert(IndexMaskPair(SparseIndex, Pair.LaneMask));
307  if (!InsertRes.second) {
308  LaneBitmask PrevMask = InsertRes.first->LaneMask;
309  InsertRes.first->LaneMask |= Pair.LaneMask;
310  return PrevMask;
311  }
312  return LaneBitmask::getNone();
313  }
314 
315  /// Clears the \p Pair.LaneMask lanes of \p Pair.Reg (mark them as dead).
316  /// Returns the previously live lanes of \p Pair.Reg.
318  unsigned SparseIndex = getSparseIndexFromReg(Pair.RegUnit);
319  RegSet::iterator I = Regs.find(SparseIndex);
320  if (I == Regs.end())
321  return LaneBitmask::getNone();
322  LaneBitmask PrevMask = I->LaneMask;
323  I->LaneMask &= ~Pair.LaneMask;
324  return PrevMask;
325  }
326 
327  size_t size() const {
328  return Regs.size();
329  }
330 
331  template<typename ContainerT>
332  void appendTo(ContainerT &To) const {
333  for (const IndexMaskPair &P : Regs) {
334  Register Reg = getRegFromSparseIndex(P.Index);
335  if (P.LaneMask.any())
336  To.push_back(RegisterMaskPair(Reg, P.LaneMask));
337  }
338  }
339 };
340 
341 /// Track the current register pressure at some position in the instruction
342 /// stream, and remember the high water mark within the region traversed. This
343 /// does not automatically consider live-through ranges. The client may
344 /// independently adjust for global liveness.
345 ///
346 /// Each RegPressureTracker only works within a MachineBasicBlock. Pressure can
347 /// be tracked across a larger region by storing a RegisterPressure result at
348 /// each block boundary and explicitly adjusting pressure to account for block
349 /// live-in and live-out register sets.
350 ///
351 /// RegPressureTracker holds a reference to a RegisterPressure result that it
352 /// computes incrementally. During downward tracking, P.BottomIdx or P.BottomPos
353 /// is invalid until it reaches the end of the block or closeRegion() is
354 /// explicitly called. Similarly, P.TopIdx is invalid during upward
355 /// tracking. Changing direction has the side effect of closing region, and
356 /// traversing past TopIdx or BottomIdx reopens it.
358  const MachineFunction *MF = nullptr;
359  const TargetRegisterInfo *TRI = nullptr;
360  const RegisterClassInfo *RCI = nullptr;
361  const MachineRegisterInfo *MRI;
362  const LiveIntervals *LIS = nullptr;
363 
364  /// We currently only allow pressure tracking within a block.
365  const MachineBasicBlock *MBB = nullptr;
366 
367  /// Track the max pressure within the region traversed so far.
368  RegisterPressure &P;
369 
370  /// Run in two modes dependending on whether constructed with IntervalPressure
371  /// or RegisterPressure. If requireIntervals is false, LIS are ignored.
372  bool RequireIntervals;
373 
374  /// True if UntiedDefs will be populated.
375  bool TrackUntiedDefs = false;
376 
377  /// True if lanemasks should be tracked.
378  bool TrackLaneMasks = false;
379 
380  /// Register pressure corresponds to liveness before this instruction
381  /// iterator. It may point to the end of the block or a DebugValue rather than
382  /// an instruction.
384 
385  /// Pressure map indexed by pressure set ID, not class ID.
386  std::vector<unsigned> CurrSetPressure;
387 
388  /// Set of live registers.
389  LiveRegSet LiveRegs;
390 
391  /// Set of vreg defs that start a live range.
393  /// Live-through pressure.
394  std::vector<unsigned> LiveThruPressure;
395 
396 public:
397  RegPressureTracker(IntervalPressure &rp) : P(rp), RequireIntervals(true) {}
398  RegPressureTracker(RegionPressure &rp) : P(rp), RequireIntervals(false) {}
399 
400  void reset();
401 
402  void init(const MachineFunction *mf, const RegisterClassInfo *rci,
403  const LiveIntervals *lis, const MachineBasicBlock *mbb,
405  bool TrackLaneMasks, bool TrackUntiedDefs);
406 
407  /// Force liveness of virtual registers or physical register
408  /// units. Particularly useful to initialize the livein/out state of the
409  /// tracker before the first call to advance/recede.
411 
412  /// Get the MI position corresponding to this register pressure.
413  MachineBasicBlock::const_iterator getPos() const { return CurrPos; }
414 
415  // Reset the MI position corresponding to the register pressure. This allows
416  // schedulers to move instructions above the RegPressureTracker's
417  // CurrPos. Since the pressure is computed before CurrPos, the iterator
418  // position changes while pressure does not.
419  void setPos(MachineBasicBlock::const_iterator Pos) { CurrPos = Pos; }
420 
421  /// Recede across the previous instruction.
422  void recede(SmallVectorImpl<RegisterMaskPair> *LiveUses = nullptr);
423 
424  /// Recede across the previous instruction.
425  /// This "low-level" variant assumes that recedeSkipDebugValues() was
426  /// called previously and takes precomputed RegisterOperands for the
427  /// instruction.
428  void recede(const RegisterOperands &RegOpers,
429  SmallVectorImpl<RegisterMaskPair> *LiveUses = nullptr);
430 
431  /// Recede until we find an instruction which is not a DebugValue.
432  void recedeSkipDebugValues();
433 
434  /// Advance across the current instruction.
435  void advance();
436 
437  /// Advance across the current instruction.
438  /// This is a "low-level" variant of advance() which takes precomputed
439  /// RegisterOperands of the instruction.
440  void advance(const RegisterOperands &RegOpers);
441 
442  /// Finalize the region boundaries and recored live ins and live outs.
443  void closeRegion();
444 
445  /// Initialize the LiveThru pressure set based on the untied defs found in
446  /// RPTracker.
447  void initLiveThru(const RegPressureTracker &RPTracker);
448 
449  /// Copy an existing live thru pressure result.
450  void initLiveThru(ArrayRef<unsigned> PressureSet) {
451  LiveThruPressure.assign(PressureSet.begin(), PressureSet.end());
452  }
453 
454  ArrayRef<unsigned> getLiveThru() const { return LiveThruPressure; }
455 
456  /// Get the resulting register pressure over the traversed region.
457  /// This result is complete if closeRegion() was explicitly invoked.
459  const RegisterPressure &getPressure() const { return P; }
460 
461  /// Get the register set pressure at the current position, which may be less
462  /// than the pressure across the traversed region.
463  const std::vector<unsigned> &getRegSetPressureAtPos() const {
464  return CurrSetPressure;
465  }
466 
467  bool isTopClosed() const;
468  bool isBottomClosed() const;
469 
470  void closeTop();
471  void closeBottom();
472 
473  /// Consider the pressure increase caused by traversing this instruction
474  /// bottom-up. Find the pressure set with the most change beyond its pressure
475  /// limit based on the tracker's current pressure, and record the number of
476  /// excess register units of that pressure set introduced by this instruction.
478  PressureDiff *PDiff,
479  RegPressureDelta &Delta,
480  ArrayRef<PressureChange> CriticalPSets,
481  ArrayRef<unsigned> MaxPressureLimit);
482 
484  /*const*/ PressureDiff &PDiff,
485  RegPressureDelta &Delta,
486  ArrayRef<PressureChange> CriticalPSets,
487  ArrayRef<unsigned> MaxPressureLimit) const;
488 
489  /// Consider the pressure increase caused by traversing this instruction
490  /// top-down. Find the pressure set with the most change beyond its pressure
491  /// limit based on the tracker's current pressure, and record the number of
492  /// excess register units of that pressure set introduced by this instruction.
494  RegPressureDelta &Delta,
495  ArrayRef<PressureChange> CriticalPSets,
496  ArrayRef<unsigned> MaxPressureLimit);
497 
498  /// Find the pressure set with the most change beyond its pressure limit after
499  /// traversing this instruction either upward or downward depending on the
500  /// closed end of the current region.
502  RegPressureDelta &Delta,
503  ArrayRef<PressureChange> CriticalPSets,
504  ArrayRef<unsigned> MaxPressureLimit) {
505  if (isTopClosed())
506  return getMaxDownwardPressureDelta(MI, Delta, CriticalPSets,
507  MaxPressureLimit);
508 
509  assert(isBottomClosed() && "Uninitialized pressure tracker");
510  return getMaxUpwardPressureDelta(MI, nullptr, Delta, CriticalPSets,
511  MaxPressureLimit);
512  }
513 
514  /// Get the pressure of each PSet after traversing this instruction bottom-up.
515  void getUpwardPressure(const MachineInstr *MI,
516  std::vector<unsigned> &PressureResult,
517  std::vector<unsigned> &MaxPressureResult);
518 
519  /// Get the pressure of each PSet after traversing this instruction top-down.
520  void getDownwardPressure(const MachineInstr *MI,
521  std::vector<unsigned> &PressureResult,
522  std::vector<unsigned> &MaxPressureResult);
523 
525  std::vector<unsigned> &PressureResult,
526  std::vector<unsigned> &MaxPressureResult) {
527  if (isTopClosed())
528  return getUpwardPressure(MI, PressureResult, MaxPressureResult);
529 
530  assert(isBottomClosed() && "Uninitialized pressure tracker");
531  return getDownwardPressure(MI, PressureResult, MaxPressureResult);
532  }
533 
534  bool hasUntiedDef(Register VirtReg) const {
535  return UntiedDefs.count(VirtReg);
536  }
537 
538  void dump() const;
539 
540 protected:
541  /// Add Reg to the live out set and increase max pressure.
543  /// Add Reg to the live in set and increase max pressure.
544  void discoverLiveIn(RegisterMaskPair Pair);
545 
546  /// Get the SlotIndex for the first nondebug instruction including or
547  /// after the current position.
548  SlotIndex getCurrSlot() const;
549 
550  void increaseRegPressure(Register RegUnit, LaneBitmask PreviousMask,
551  LaneBitmask NewMask);
552  void decreaseRegPressure(Register RegUnit, LaneBitmask PreviousMask,
553  LaneBitmask NewMask);
554 
556 
557  void bumpUpwardPressure(const MachineInstr *MI);
558  void bumpDownwardPressure(const MachineInstr *MI);
559 
561  SmallVectorImpl<RegisterMaskPair> &LiveInOrOut);
562 
563  LaneBitmask getLastUsedLanes(Register RegUnit, SlotIndex Pos) const;
564  LaneBitmask getLiveLanesAt(Register RegUnit, SlotIndex Pos) const;
565  LaneBitmask getLiveThroughAt(Register RegUnit, SlotIndex Pos) const;
566 };
567 
568 void dumpRegSetPressure(ArrayRef<unsigned> SetPressure,
569  const TargetRegisterInfo *TRI);
570 
571 } // end namespace llvm
572 
573 #endif // LLVM_CODEGEN_REGISTERPRESSURE_H
llvm::RegPressureTracker::hasUntiedDef
bool hasUntiedDef(Register VirtReg) const
Definition: RegisterPressure.h:534
llvm::LaneBitmask
Definition: LaneBitmask.h:40
llvm::PressureChange::getPSetOrMax
unsigned getPSetOrMax() const
Definition: RegisterPressure.h:120
llvm::RegionPressure::reset
void reset()
Clear the result so it can be used for another round of pressure tracking.
Definition: RegisterPressure.cpp:185
llvm::RegionPressure::BottomPos
MachineBasicBlock::const_iterator BottomPos
Definition: RegisterPressure.h:85
llvm::RegPressureTracker::getLiveThroughAt
LaneBitmask getLiveThroughAt(Register RegUnit, SlotIndex Pos) const
Definition: RegisterPressure.cpp:1266
llvm::SparseSet< IndexMaskPair >::iterator
typename DenseT::iterator iterator
Definition: SparseSet.h:172
llvm::RegisterOperands::detectDeadDefs
void detectDeadDefs(const MachineInstr &MI, const LiveIntervals &LIS)
Use liveness information to find dead defs not marked with a dead flag and move them to the DeadDefs ...
Definition: RegisterPressure.cpp:581
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:104
llvm::SparseSet< IndexMaskPair >::const_iterator
typename DenseT::const_iterator const_iterator
Definition: SparseSet.h:173
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::RegPressureTracker::getPressure
const RegisterPressure & getPressure() const
Definition: RegisterPressure.h:459
llvm::RegPressureTracker::addLiveRegs
void addLiveRegs(ArrayRef< RegisterMaskPair > Regs)
Force liveness of virtual registers or physical register units.
Definition: RegisterPressure.cpp:707
llvm::RegPressureTracker::init
void init(const MachineFunction *mf, const RegisterClassInfo *rci, const LiveIntervals *lis, const MachineBasicBlock *mbb, MachineBasicBlock::const_iterator pos, bool TrackLaneMasks, bool TrackUntiedDefs)
Setup the RegPressureTracker.
Definition: RegisterPressure.cpp:263
llvm::SparseSet::find
iterator find(const KeyT &Key)
find - Find an element by its key.
Definition: SparseSet.h:225
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:50
llvm::RegisterOperands::Defs
SmallVector< RegisterMaskPair, 8 > Defs
List of virtual registers and register units defined by the instruction which are not dead.
Definition: RegisterPressure.h:172
llvm::RegPressureTracker::getCurrSlot
SlotIndex getCurrSlot() const
Get the SlotIndex for the first nondebug instruction including or after the current position.
Definition: RegisterPressure.cpp:310
llvm::PressureDiffs::~PressureDiffs
~PressureDiffs()
Definition: RegisterPressure.h:204
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::RegisterOperands
List of registers defined and used by a machine instruction.
Definition: RegisterPressure.h:166
llvm::PressureDiff
List of PressureChanges in order of increasing, unique PSetID.
Definition: RegisterPressure.h:140
llvm::PressureDiffs::operator[]
PressureDiff & operator[](unsigned Idx)
Definition: RegisterPressure.h:210
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::RegPressureTracker::getUpwardPressure
void getUpwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction bottom-up.
Definition: RegisterPressure.cpp:1367
llvm::LiveRegSet::erase
LaneBitmask erase(RegisterMaskPair Pair)
Clears the Pair.LaneMask lanes of Pair.Reg (mark them as dead).
Definition: RegisterPressure.h:317
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
llvm::PressureChange::operator==
bool operator==(const PressureChange &RHS) const
Definition: RegisterPressure.h:128
llvm::IntervalPressure
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx.
Definition: RegisterPressure.h:67
llvm::RegPressureTracker::bumpDeadDefs
void bumpDeadDefs(ArrayRef< RegisterMaskPair > DeadDefs)
Definition: RegisterPressure.cpp:745
MachineBasicBlock.h
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:234
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1909
llvm::RegPressureTracker
Track the current register pressure at some position in the instruction stream, and remember the high...
Definition: RegisterPressure.h:357
llvm::PressureDiffs::clear
void clear()
Definition: RegisterPressure.h:206
llvm::LiveRegSet::insert
LaneBitmask insert(RegisterMaskPair Pair)
Mark the Pair.LaneMask lanes of Pair.Reg as live.
Definition: RegisterPressure.h:304
llvm::RegisterMaskPair
Definition: RegisterPressure.h:38
llvm::PressureDiffs
Array of PressureDiffs.
Definition: RegisterPressure.h:197
llvm::RegionPressure::TopPos
MachineBasicBlock::const_iterator TopPos
Record the boundary of the region being tracked.
Definition: RegisterPressure.h:84
llvm::RegionPressure::openBottom
void openBottom(MachineBasicBlock::const_iterator PrevBottom)
If the current bottom is the previous instr (before advancing), open it.
Definition: RegisterPressure.cpp:218
llvm::Register::index2VirtReg
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition: Register.h:84
llvm::RegPressureTracker::closeRegion
void closeRegion()
Finalize the region boundaries and recored live ins and live outs.
Definition: RegisterPressure.cpp:343
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::RegisterMaskPair::RegUnit
Register RegUnit
Virtual register or register unit.
Definition: RegisterPressure.h:39
llvm::PressureDiffs::init
void init(unsigned N)
Initialize an array of N PressureDiffs.
Definition: RegisterPressure.cpp:648
llvm::RegPressureTracker::getPressureAfterInst
void getPressureAfterInst(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Definition: RegisterPressure.h:524
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1620
llvm::RegPressureDelta::dump
void dump() const
Definition: RegisterPressure.cpp:143
llvm::RegisterMaskPair::LaneMask
LaneBitmask LaneMask
Definition: RegisterPressure.h:40
llvm::PressureDiffs::addInstruction
void addInstruction(unsigned Idx, const RegisterOperands &RegOpers, const MachineRegisterInfo &MRI)
Record pressure difference induced by the given operand list to node with index Idx.
Definition: RegisterPressure.cpp:659
llvm::SparseSet::size
size_type size() const
size - Returns the number of elements in the set.
Definition: SparseSet.h:191
llvm::RegPressureTracker::isBottomClosed
bool isBottomClosed() const
Does this pressure result have a valid bottom position and live outs.
Definition: RegisterPressure.cpp:303
llvm::PressureChange::PressureChange
PressureChange()=default
llvm::RegPressureTracker::setPos
void setPos(MachineBasicBlock::const_iterator Pos)
Definition: RegisterPressure.h:419
llvm::RegPressureDelta::CurrentMax
PressureChange CurrentMax
Definition: RegisterPressure.h:241
llvm::RegPressureTracker::getUpwardPressureDelta
void getUpwardPressureDelta(const MachineInstr *MI, PressureDiff &PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit) const
This is the fast version of querying register pressure that does not directly depend on current liven...
Definition: RegisterPressure.cpp:1163
llvm::PressureChange::PressureChange
PressureChange(unsigned id)
Definition: RegisterPressure.h:108
llvm::SparseSet::end
const_iterator end() const
Definition: SparseSet.h:176
llvm::PressureDiff::end
const_iterator end() const
Definition: RegisterPressure.h:157
llvm::RegPressureTracker::getDownwardPressure
void getDownwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction top-down.
Definition: RegisterPressure.cpp:1383
llvm::LaneBitmask::getNone
static constexpr LaneBitmask getNone()
Definition: LaneBitmask.h:83
llvm::IntervalPressure::TopIdx
SlotIndex TopIdx
Record the boundary of the region being tracked.
Definition: RegisterPressure.h:69
llvm::RegPressureTracker::getLiveThru
ArrayRef< unsigned > getLiveThru() const
Definition: RegisterPressure.h:454
false
Definition: StackSlotColoring.cpp:141
llvm::RegisterPressure::LiveOutRegs
SmallVector< RegisterMaskPair, 8 > LiveOutRegs
Definition: RegisterPressure.h:53
llvm::RegPressureTracker::initLiveThru
void initLiveThru(const RegPressureTracker &RPTracker)
Initialize the LiveThru pressure set based on the untied defs found in RPTracker.
Definition: RegisterPressure.cpp:359
llvm::RegPressureDelta::Excess
PressureChange Excess
Definition: RegisterPressure.h:239
llvm::SlotIndex
SlotIndex - An opaque wrapper around machine indexes.
Definition: SlotIndexes.h:82
llvm::RegPressureTracker::dump
void dump() const
Definition: RegisterPressure.cpp:117
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::RegisterOperands::collect
void collect(const MachineInstr &MI, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI, bool TrackLaneMasks, bool IgnoreDead)
Analyze the given instruction MI and fill in the Uses, Defs and DeadDefs list based on the MachineOpe...
Definition: RegisterPressure.cpp:570
llvm::RegPressureTracker::getRegSetPressureAtPos
const std::vector< unsigned > & getRegSetPressureAtPos() const
Get the register set pressure at the current position, which may be less than the pressure across the...
Definition: RegisterPressure.h:463
llvm::RegPressureTracker::recedeSkipDebugValues
void recedeSkipDebugValues()
Recede until we find an instruction which is not a DebugValue.
Definition: RegisterPressure.cpp:853
llvm::RegisterOperands::DeadDefs
SmallVector< RegisterMaskPair, 8 > DeadDefs
List of virtual registers and register units defined by the instruction but dead.
Definition: RegisterPressure.h:175
llvm::RegionPressure::openTop
void openTop(MachineBasicBlock::const_iterator PrevTop)
If the current top is the previous instruction (before receding), open it.
Definition: RegisterPressure.cpp:202
llvm::RegPressureTracker::closeBottom
void closeBottom()
Set the boundary for the bottom of the region and summarize live outs.
Definition: RegisterPressure.cpp:331
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
llvm::LiveRegSet::appendTo
void appendTo(ContainerT &To) const
Definition: RegisterPressure.h:332
llvm::RegPressureTracker::reset
void reset()
Definition: RegisterPressure.cpp:243
llvm::RegPressureTracker::getMaxPressureDelta
void getMaxPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Find the pressure set with the most change beyond its pressure limit after traversing this instructio...
Definition: RegisterPressure.h:501
llvm::PressureChange::isValid
bool isValid() const
Definition: RegisterPressure.h:112
llvm::PressureChange::setUnitInc
void setUnitInc(int Inc)
Definition: RegisterPressure.h:126
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::RegPressureTracker::closeTop
void closeTop()
Set the boundary for the top of the region and summarize live ins.
Definition: RegisterPressure.cpp:319
llvm::RegPressureTracker::advance
void advance()
Advance across the current instruction.
Definition: RegisterPressure.cpp:948
llvm::PressureChange::getUnitInc
int getUnitInc() const
Definition: RegisterPressure.h:124
ArrayRef.h
llvm::RegPressureTracker::getPressure
RegisterPressure & getPressure()
Get the resulting register pressure over the traversed region.
Definition: RegisterPressure.h:458
llvm::RegPressureDelta::CriticalMax
PressureChange CriticalMax
Definition: RegisterPressure.h:240
llvm::RegisterPressure::MaxSetPressure
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.
Definition: RegisterPressure.h:49
llvm::RegPressureTracker::getMaxDownwardPressureDelta
void getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction top-down.
Definition: RegisterPressure.cpp:1344
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::RegisterPressure::LiveInRegs
SmallVector< RegisterMaskPair, 8 > LiveInRegs
List of live in virtual registers or physical register units.
Definition: RegisterPressure.h:52
llvm::RegisterClassInfo
Definition: RegisterClassInfo.h:29
llvm::LiveRegSet::init
void init(const MachineRegisterInfo &MRI)
Definition: RegisterPressure.cpp:225
llvm::RegPressureDelta::operator!=
bool operator!=(const RegPressureDelta &RHS) const
Definition: RegisterPressure.h:249
llvm::RegPressureTracker::decreaseRegPressure
void decreaseRegPressure(Register RegUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)
Definition: RegisterPressure.cpp:170
llvm::PressureChange::getPSet
unsigned getPSet() const
Definition: RegisterPressure.h:114
llvm::RegPressureTracker::getMaxUpwardPressureDelta
void getMaxUpwardPressureDelta(const MachineInstr *MI, PressureDiff *PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction bottom-up.
Definition: RegisterPressure.cpp:1095
llvm::MachineFunction
Definition: MachineFunction.h:241
llvm::dumpRegSetPressure
void dumpRegSetPressure(ArrayRef< unsigned > SetPressure, const TargetRegisterInfo *TRI)
Definition: RegisterPressure.cpp:81
llvm::RegPressureTracker::isTopClosed
bool isTopClosed() const
Does this pressure result have a valid top position and live ins.
Definition: RegisterPressure.cpp:295
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::RegPressureTracker::getPos
MachineBasicBlock::const_iterator getPos() const
Get the MI position corresponding to this register pressure.
Definition: RegisterPressure.h:413
SparseSet.h
llvm::LiveRegSet
A set of live virtual registers and physical register units.
Definition: RegisterPressure.h:259
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::RegPressureDelta::RegPressureDelta
RegPressureDelta()=default
llvm::RegionPressure
RegisterPressure computed within a region of instructions delimited by TopPos and BottomPos.
Definition: RegisterPressure.h:82
llvm::RegPressureDelta
Store the effects of a change in pressure on things that MI scheduler cares about.
Definition: RegisterPressure.h:238
llvm::SparseSet::insert
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
Definition: SparseSet.h:253
llvm::RegPressureTracker::getLiveLanesAt
LaneBitmask getLiveLanesAt(Register RegUnit, SlotIndex Pos) const
Definition: RegisterPressure.cpp:1245
uint16_t
llvm::RegPressureDelta::operator==
bool operator==(const RegPressureDelta &RHS) const
Definition: RegisterPressure.h:245
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:152
llvm::IntervalPressure::openBottom
void openBottom(SlotIndex PrevBottom)
If the current bottom is not greater than the previous index, open it.
Definition: RegisterPressure.cpp:210
llvm::RegPressureTracker::bumpDownwardPressure
void bumpDownwardPressure(const MachineInstr *MI)
Record the downward impact of a single instruction on current register pressure.
Definition: RegisterPressure.cpp:1284
llvm::SparseSet::count
size_type count(const KeyT &Key) const
count - Returns 1 if this set contains an element identified by Key, 0 otherwise.
Definition: SparseSet.h:241
llvm::RegPressureTracker::initLiveThru
void initLiveThru(ArrayRef< unsigned > PressureSet)
Copy an existing live thru pressure result.
Definition: RegisterPressure.h:450
llvm::PressureChange
Capture a change in pressure for a single pressure set.
Definition: RegisterPressure.h:102
llvm::LiveIntervals
Definition: LiveIntervals.h:54
llvm::RegPressureTracker::discoverLiveInOrOut
void discoverLiveInOrOut(RegisterMaskPair Pair, SmallVectorImpl< RegisterMaskPair > &LiveInOrOut)
Definition: RegisterPressure.cpp:715
llvm::RegisterOperands::adjustLaneLiveness
void adjustLaneLiveness(const LiveIntervals &LIS, const MachineRegisterInfo &MRI, SlotIndex Pos, MachineInstr *AddFlagsMI=nullptr)
Use liveness information to find out which uses/defs are partially undefined/dead and adjust the Regi...
Definition: RegisterPressure.cpp:601
llvm::IntervalPressure::openTop
void openTop(SlotIndex NextTop)
If the current top is not less than or equal to the next index, open it.
Definition: RegisterPressure.cpp:194
llvm::RegisterPressure
Base class for register pressure results.
Definition: RegisterPressure.h:47
SmallVector.h
llvm::RegPressureTracker::discoverLiveIn
void discoverLiveIn(RegisterMaskPair Pair)
Add Reg to the live in set and increase max pressure.
Definition: RegisterPressure.cpp:737
llvm::RegPressureTracker::bumpUpwardPressure
void bumpUpwardPressure(const MachineInstr *MI)
Record the upward impact of a single instruction on current register pressure.
Definition: RegisterPressure.cpp:1043
N
#define N
P
#define P(N)
llvm::RegisterOperands::Uses
SmallVector< RegisterMaskPair, 8 > Uses
List of virtual registers and register units read by the instruction.
Definition: RegisterPressure.h:169
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::PressureDiff::addPressureChange
void addPressureChange(Register RegUnit, bool IsDec, const MachineRegisterInfo *MRI)
Add a change in pressure to the pressure diff of a given instruction.
Definition: RegisterPressure.cpp:672
LaneBitmask.h
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::RegisterPressure::dump
void dump(const TargetRegisterInfo *TRI) const
Definition: RegisterPressure.cpp:95
llvm::RegPressureTracker::getLastUsedLanes
LaneBitmask getLastUsedLanes(Register RegUnit, SlotIndex Pos) const
Definition: RegisterPressure.cpp:1255
llvm::SparseSet< IndexMaskPair >
llvm::Register::virtReg2Index
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
Definition: Register.h:77
llvm::RegPressureTracker::discoverLiveOut
void discoverLiveOut(RegisterMaskPair Pair)
Add Reg to the live out set and increase max pressure.
Definition: RegisterPressure.cpp:741
llvm::PressureDiff::dump
void dump(const TargetRegisterInfo &TRI) const
Definition: RegisterPressure.cpp:126
SlotIndexes.h
llvm::RegisterMaskPair::RegisterMaskPair
RegisterMaskPair(Register RegUnit, LaneBitmask LaneMask)
Definition: RegisterPressure.h:42
llvm::RegPressureTracker::RegPressureTracker
RegPressureTracker(RegionPressure &rp)
Definition: RegisterPressure.h:398
llvm::LiveRegSet::clear
void clear()
Definition: RegisterPressure.cpp:233
llvm::MachineInstrBundleIterator< const MachineInstr >
llvm::PressureDiffs::PressureDiffs
PressureDiffs()=default
llvm::RegPressureTracker::increaseRegPressure
void increaseRegPressure(Register RegUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)
Definition: RegisterPressure.cpp:155
llvm::IntervalPressure::BottomIdx
SlotIndex BottomIdx
Definition: RegisterPressure.h:70
TargetRegisterInfo.h
llvm::RegPressureTracker::recede
void recede(SmallVectorImpl< RegisterMaskPair > *LiveUses=nullptr)
Recede across the previous instruction.
Definition: RegisterPressure.cpp:874
llvm::PressureDiffs::operator[]
const PressureDiff & operator[](unsigned Idx) const
Definition: RegisterPressure.h:214
llvm::PressureChange::dump
void dump() const
Definition: RegisterPressure.cpp:139
llvm::LiveRegSet::contains
LaneBitmask contains(Register Reg) const
Definition: RegisterPressure.h:294
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:153
llvm::PressureDiff::begin
const_iterator begin() const
Definition: RegisterPressure.h:156
llvm::RegPressureTracker::RegPressureTracker
RegPressureTracker(IntervalPressure &rp)
Definition: RegisterPressure.h:397
llvm::LiveRegSet::size
size_t size() const
Definition: RegisterPressure.h:327
llvm::IntervalPressure::reset
void reset()
Clear the result so it can be used for another round of pressure tracking.
Definition: RegisterPressure.cpp:177