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