LLVM 24.0.0git
GCNRegPressure.h
Go to the documentation of this file.
1//===- GCNRegPressure.h -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file defines the GCNRegPressure class, which tracks registry pressure
11/// by bookkeeping number of SGPR/VGPRs used, weights for large SGPR/VGPRs. It
12/// also implements a compare function, which compares different register
13/// pressures, and declares one with max occupancy as winner.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H
18#define LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H
19
20#include "GCNSubtarget.h"
23#include <algorithm>
24#include <array>
25
26namespace llvm {
27
29class raw_ostream;
30class SlotIndex;
31
34
35 static constexpr const char *getName(RegKind Kind) {
36 const char *Names[] = {"SGPR", "VGPR", "AGPR", "AVGPR"};
37 assert(Kind < TOTAL_KINDS);
38 return Names[Kind];
39 }
40
42 clear();
43 }
44
45 bool empty() const {
46 return !Value[SGPR] && !Value[VGPR] && !Value[AGPR] && !Value[AVGPR];
47 }
48
49 void clear() { Value.fill(0); }
50
51 unsigned getNumRegs(RegKind Kind) const {
52 assert(Kind < TOTAL_KINDS);
53 return Value[Kind];
54 }
55
56 /// \returns the SGPR32 pressure
57 unsigned getSGPRNum() const { return Value[SGPR]; }
58 /// \returns the aggregated ArchVGPR32, AccVGPR32, and Pseudo AVGPR pressure
59 /// dependent upon \p UnifiedVGPRFile
60 unsigned getVGPRNum(bool UnifiedVGPRFile) const {
61 if (UnifiedVGPRFile) {
62 return Value[AGPR]
63 ? getUnifiedVGPRNum(Value[VGPR], Value[AGPR], Value[AVGPR])
64 : Value[VGPR] + Value[AVGPR];
65 }
66 // AVGPR assignment priority is based on the width of the register. Account
67 // AVGPR pressure as VGPR.
68 return std::max(Value[VGPR] + Value[AVGPR], Value[AGPR]);
69 }
70
71 /// Returns the aggregated VGPR pressure, assuming \p NumArchVGPRs ArchVGPRs
72 /// \p NumAGPRs AGPRS, and \p NumAVGPRs AVGPRs for a target with a unified
73 /// VGPR file.
74 inline static unsigned getUnifiedVGPRNum(unsigned NumArchVGPRs,
75 unsigned NumAGPRs,
76 unsigned NumAVGPRs) {
77
78 // Assume AVGPRs will be assigned as VGPRs.
79 return alignTo(NumArchVGPRs + NumAVGPRs,
81 NumAGPRs;
82 }
83
84 /// \returns the ArchVGPR32 pressure, plus the AVGPRS which we assume will be
85 /// allocated as VGPR
86 unsigned getArchVGPRNum() const { return Value[VGPR] + Value[AVGPR]; }
87 /// \returns the AccVGPR32 pressure
88 unsigned getAGPRNum() const { return Value[AGPR]; }
89
90 unsigned getVGPRTuplesWeight() const {
91 return std::max(Value[TOTAL_KINDS + VGPR] + Value[TOTAL_KINDS + AVGPR],
92 Value[TOTAL_KINDS + AGPR]);
93 }
94 unsigned getSGPRTuplesWeight() const { return Value[TOTAL_KINDS + SGPR]; }
95
96 unsigned getOccupancy(const GCNSubtarget &ST,
97 unsigned DynamicVGPRBlockSize) const {
98 return std::min(ST.getOccupancyWithNumSGPRs(getSGPRNum()),
99 ST.getOccupancyWithNumVGPRs(getVGPRNum(ST.hasGFX90AInsts()),
100 DynamicVGPRBlockSize));
101 }
102
103 unsigned getVGPRSpills(MachineFunction &MF, unsigned ArchVGPRThreshold,
104 unsigned AGPRThreshold, unsigned CombinedThreshold) {
105 const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
106 if (!ST.hasGFX90AInsts())
107 return 0;
108
109 unsigned ArchPressure = getArchVGPRNum();
110 unsigned AGPRPressure = getAGPRNum();
111
112 unsigned ArchSpill = ArchPressure > ArchVGPRThreshold
113 ? (ArchPressure - ArchVGPRThreshold)
114 : 0;
115 unsigned AGPRSpill =
116 AGPRPressure > AGPRThreshold ? (AGPRPressure - AGPRThreshold) : 0;
117
118 unsigned UnifiedPressure = getVGPRNum(/*UnifiedVGPRFile=*/true);
119 unsigned UnifiedSpill = UnifiedPressure > CombinedThreshold
120 ? (UnifiedPressure - CombinedThreshold)
121 : 0;
122
123 return std::max(UnifiedSpill, ArchSpill + AGPRSpill);
124 }
125
126 void inc(unsigned Reg,
127 LaneBitmask PrevMask,
128 LaneBitmask NewMask,
129 const MachineRegisterInfo &MRI);
130
131 /// Compares \p this GCNRegpressure to \p O, returning true if \p this is
132 /// less. Since GCNRegpressure contains different types of pressures, and due
133 /// to target-specific pecularities (e.g. we care about occupancy rather than
134 /// raw register usage), we determine if \p this GCNRegPressure is less than
135 /// \p O based on the following tiered comparisons (in order order of
136 /// precedence):
137 /// 1. Better occupancy
138 /// 2. Less spilling (first preference to VGPR spills, then to SGPR spills)
139 /// 3. Less tuple register pressure (first preference to VGPR tuples if we
140 /// determine that SGPR pressure is not important)
141 /// 4. Less raw register pressure (first preference to VGPR tuples if we
142 /// determine that SGPR pressure is not important)
143 bool less(const MachineFunction &MF, const GCNRegPressure &O,
144 unsigned MaxOccupancy = std::numeric_limits<unsigned>::max()) const;
145
146 bool operator==(const GCNRegPressure &O) const { return Value == O.Value; }
147
148 bool operator!=(const GCNRegPressure &O) const {
149 return !(*this == O);
150 }
151
153 for (unsigned I = 0; I < ValueArraySize; ++I)
154 Value[I] += RHS.Value[I];
155 return *this;
156 }
157
159 for (unsigned I = 0; I < ValueArraySize; ++I)
160 Value[I] -= RHS.Value[I];
161 return *this;
162 }
163
164 void dump() const;
165
166 static RegKind getRegKind(unsigned Reg, const MachineRegisterInfo &MRI) {
168 const SIRegisterInfo *STI = static_cast<const SIRegisterInfo *>(TRI);
169 return (RegKind)getRegKind(MRI.getRegClass(Reg), STI);
170 }
171
172private:
173 static constexpr unsigned ValueArraySize = TOTAL_KINDS * 2;
174
175 /// Pressure for all register kinds (first all regular registers kinds, then
176 /// all tuple register kinds).
177 std::array<unsigned, ValueArraySize> Value;
178
179 static unsigned getRegKind(const TargetRegisterClass *RC,
180 const SIRegisterInfo *STI);
181
182 friend GCNRegPressure max(const GCNRegPressure &P1,
183 const GCNRegPressure &P2);
184
185 friend Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST,
186 unsigned DynamicVGPRBlockSize);
187};
188
189inline GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2) {
190 GCNRegPressure Res;
191 for (unsigned I = 0; I < GCNRegPressure::ValueArraySize; ++I)
192 Res.Value[I] = std::max(P1.Value[I], P2.Value[I]);
193 return Res;
194}
195
197 const GCNRegPressure &P2) {
198 GCNRegPressure Sum = P1;
199 Sum += P2;
200 return Sum;
201}
202
204 const GCNRegPressure &P2) {
205 GCNRegPressure Diff = P1;
206 Diff -= P2;
207 return Diff;
208}
209
210////////////////////////////////////////////////////////////////////////////////
211// GCNRPTarget
212
213/// Models a register pressure target, allowing to evaluate and track register
214/// savings against that target from a starting \ref GCNRegPressure.
216public:
217 /// Sets up the target such that the register pressure starting at \p RP does
218 /// not show register spilling on function \p MF (w.r.t. the function's
219 /// mininum target occupancy).
220 GCNRPTarget(const MachineFunction &MF, const GCNRegPressure &RP);
221
222 /// Sets up the target such that the register pressure starting at \p RP does
223 /// not use more than \p NumSGPRs SGPRs and \p NumVGPRs VGPRs on function \p
224 /// MF.
225 GCNRPTarget(unsigned NumSGPRs, unsigned NumVGPRs, const MachineFunction &MF,
226 const GCNRegPressure &RP);
227
228 /// Sets up the target such that the register pressure starting at \p RP does
229 /// not prevent achieving an occupancy of at least \p Occupancy on function
230 /// \p MF.
231 GCNRPTarget(unsigned Occupancy, const MachineFunction &MF,
232 const GCNRegPressure &RP);
233
234 /// Changes the target (same semantics as constructor).
235 void setTarget(unsigned NumSGPRs, unsigned NumVGPRs);
236
237 const GCNRegPressure &getCurrentRP() const { return RP; }
238
239 void setRP(const GCNRegPressure &NewRP) { RP = NewRP; }
240
241 /// Determines whether saving virtual register \p Reg will be beneficial
242 /// towards achieving the RP target.
243 bool isSaveBeneficial(Register Reg) const;
244
245 /// Returns whether the benefit that saving \p SaveRP represents will be
246 /// beneficial towards achieving the RP target.
247 bool isSaveBeneficial(const GCNRegPressure &SaveRP) const;
248
249 /// Returns the benefit towards achieving the RP target that saving \p SaveRP
250 /// represents, in total number of registers saved across all classes.
251 unsigned getNumRegsBenefit(const GCNRegPressure &SaveRP) const;
252
253 /// Saves a total pressure of \p SaveRP.
254 void saveRP(const GCNRegPressure &SaveRP) {
255 assert(!RP.less(MF, SaveRP) && "saving beyond current RP");
256 RP -= SaveRP;
257 }
258
259 /// Whether \p TestRP is at or below the defined pressure target.
260 bool satisfied(const GCNRegPressure &TestRP) const;
261 /// Whether the current RP is at or below the defined pressure target.
262 bool satisfied() const { return satisfied(RP); }
263 bool hasVectorRegisterExcess() const;
264
265 unsigned getMaxSGPRs() const { return MaxSGPRs; }
266 unsigned getMaxVGPRs() const {
267 return UnifiedRF ? MaxUnifiedVGPRs : MaxVGPRs;
268 }
269
270#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
272 OS << "Actual/Target: " << Target.RP.getSGPRNum() << '/' << Target.MaxSGPRs
273 << " SGPRs, " << Target.RP.getArchVGPRNum() << '/' << Target.MaxVGPRs
274 << " ArchVGPRs, " << Target.RP.getAGPRNum() << '/' << Target.MaxVGPRs
275 << " AGPRs";
276
277 if (Target.MaxUnifiedVGPRs) {
278 OS << ", " << Target.RP.getVGPRNum(true) << '/' << Target.MaxUnifiedVGPRs
279 << " VGPRs (unified)";
280 }
281 return OS;
282 }
283#endif
284
285private:
286 const MachineFunction &MF;
287 const bool UnifiedRF;
288
289 /// Current register pressure.
291
292 /// Target number of SGPRs.
293 unsigned MaxSGPRs = 0;
294 /// Target number of ArchVGPRs and AGPRs.
295 unsigned MaxVGPRs = 0;
296 /// Target number of overall VGPRs for subtargets with unified RFs. Always 0
297 /// for subtargets with non-unified RFs.
298 unsigned MaxUnifiedVGPRs = 0;
299
300 GCNRPTarget(const GCNRegPressure &RP, const MachineFunction &MF)
301 : MF(MF), UnifiedRF(MF.getSubtarget<GCNSubtarget>().hasGFX90AInsts()),
302 RP(RP) {}
303};
304
305///////////////////////////////////////////////////////////////////////////////
306// GCNRPTracker
307
309public:
311
312protected:
316 const MachineInstr *LastTrackedMI = nullptr;
317 mutable const MachineRegisterInfo *MRI = nullptr;
318
320
321 /// Resets tracker before or \p After the provided \p MI, which can be a debug
322 /// instruction.
323 void reset(const MachineInstr &MI, bool After);
324
325 /// Resets tracker at the start or \p End of the \p MBB.
326 void reset(const MachineBasicBlock &MBB, bool End);
327
328 /// Resets tracker at the specified slot index \p SI.
330
332
333public:
334 /// Resets tracker with the provided \p LiveRegs.
335 void reset(const MachineRegisterInfo &MRI, const LiveRegSet &LiveRegs);
336
337 // live regs for the current state
338 const decltype(LiveRegs) &getLiveRegs() const { return LiveRegs; }
339 const MachineInstr *getLastTrackedMI() const { return LastTrackedMI; }
340
341 void clearMaxPressure() { MaxPressure.clear(); }
342
343 const GCNRegPressure &getMaxPressure() const { return MaxPressure; }
344
346
348
349 decltype(LiveRegs) moveLiveRegs() {
350 return std::move(LiveRegs);
351 }
352};
353
355getLiveRegs(SlotIndex SI, const LiveIntervals &LIS,
356 const MachineRegisterInfo &MRI,
358
359////////////////////////////////////////////////////////////////////////////////
360// GCNUpwardRPTracker
361
363public:
365
367
368 /// Resets tracker to the point just after \p MI (in program order), which can
369 /// be a debug instruction.
370 void reset(const MachineInstr &MI) { reset(MI, /*After=*/true); }
371
372 /// Move to the state of RP just before the \p MI.
373 void recede(const MachineInstr &MI);
374
375 /// \p returns whether the tracker's state after receding MI corresponds
376 /// to reported by LIS.
377 bool isValid() const;
378
384};
385
386////////////////////////////////////////////////////////////////////////////////
387// GCNDownwardRPTracker
388
389/// Common behavior for downward RP trackers. Unconstructible directly.
391public:
392 /// Mostly copy/paste from CodeGen/RegisterPressure.cpp
393 /// Calculate the impact \p MI will have on CurPressure and \return the
394 /// speculated pressure. In order to support RP Speculation, this does not
395 /// rely on the implicit program ordering in the LiveIntervals.
397 const SIRegisterInfo *TRI) const;
398
399protected:
401
402 /// Retires all lanes of \p MI's register operands that are dead at \p SI,
403 /// according to LIS.
405
406 /// Adds all lanes (dead or not) defined by \p MI's register operands to \ref
407 /// CurPressure.
408 void addDefs(const MachineInstr &MI);
409
410private:
411 /// Drop the lanes of \p Reg that are no longer live at \p SI, decreasing
412 /// CurPressure accordingly. \p Reg must be a virtual register that is
413 /// currently tracked as live.
414 void retireVirtReg(Register Reg, SlotIndex SI);
415};
416
417/// Downward RP tracker that relies on program order to advance down the
418/// instruction stream.
420private:
421 /// Next MI to advance over.
423 /// End iterator for basic block being advanced in.
425
426public:
428
430
431 /// Returns the next MI that will be advanced over.
433
434 /// \p return MaxPressure and clear it.
436 auto Res = MaxPressure;
437 MaxPressure.clear();
438 return Res;
439 }
440
441 /// Reset tracker to the point before the \p MI (filling \ref LiveRegs upon
442 /// this point using \p LiveRegsCopy if provided or LIS otherwise) point using
443 /// LIS. \p End must be between the MI and the end of its parent block
444 /// (inclusive). \p returns false if the range [MI, End) is empty except debug
445 /// values.
447 const LiveRegSet *LiveRegsCopy = nullptr);
448
449 /// Move to the state right before \ref NextMI or the end of the MBB. This
450 /// retires defs/uses of \ref LastTrackedMI that are dead after the
451 /// instruction. \p returns false if it reached the end of the block.
452 bool advanceBeforeNext();
453
454 /// Move to the state at \ref NextMI. This adds register lanes define by \p
455 /// NextMI to \ref CurPressure. Has to be called after \ref advanceBeforeNext.
456 void advanceToNext();
457
458 /// Advance to the state at the next MI in program order. \p returns false if
459 /// it reached end of block.
460 bool advance();
461
462 /// Advance in program order until before \p End. Returns whether it actually
463 /// had to advance to reach \p End.
465
466 /// Reset tracker to \p Begin (filling \ref LiveRegs upon this point using \p
467 /// LiveRegsCopy if provided or LIS otherwise) and advance to \p End, which
468 /// must be between \p Begin and the end of its parent block (inclusive). \p
469 /// returns false if the range [Begin, End) is empty except debug values.
472 const LiveRegSet *LiveRegsCopy = nullptr);
473};
474
475/// Downward RP tracker that relies on the user to provide the next instruction
476/// down the instruction stream. It still uses LIS for liveness queries.
478public:
481
483
484 /// Advances to the state after \p MI.
485 void advance(const MachineInstr &MI);
486};
487
488/// \returns the LaneMask of live lanes of \p Reg at position \p SI. Only the
489/// active lanes of \p LaneMaskFilter will be set in the return value. This is
490/// used, for example, to limit the live lanes to a specific subreg when
491/// calculating use masks.
492LaneBitmask getLiveLaneMask(unsigned Reg, SlotIndex SI,
493 const LiveIntervals &LIS,
494 const MachineRegisterInfo &MRI,
495 LaneBitmask LaneMaskFilter = LaneBitmask::getAll());
496
497LaneBitmask getLiveLaneMask(const LiveInterval &LI, SlotIndex SI,
498 const MachineRegisterInfo &MRI,
499 LaneBitmask LaneMaskFilter = LaneBitmask::getAll());
500
501/// creates a map MachineInstr -> LiveRegSet
502/// R - range of iterators on instructions
503/// After - upon entry or exit of every instruction
504/// Note: there is no entry in the map for instructions with empty live reg set
505/// Complexity = O(NumVirtRegs * averageLiveRangeSegmentsPerReg * lg(R))
506template <typename Range>
507DenseMap<MachineInstr*, GCNRPTracker::LiveRegSet>
508getLiveRegMap(Range &&R, bool After, LiveIntervals &LIS) {
509 std::vector<SlotIndex> Indexes;
510 Indexes.reserve(llvm::size(R));
511 auto &SII = *LIS.getSlotIndexes();
512 for (MachineInstr *I : R) {
513 auto SI = SII.getInstructionIndex(*I);
514 Indexes.push_back(After ? SI.getDeadSlot() : SI.getBaseIndex());
515 }
516 llvm::sort(Indexes);
517
518 auto &MRI = (*R.begin())->getMF()->getRegInfo();
520 SmallVector<SlotIndex, 32> LiveIdxs, SRLiveIdxs;
521 for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
523 if (!LIS.hasInterval(Reg))
524 continue;
525 auto &LI = LIS.getInterval(Reg);
526 LiveIdxs.clear();
527 if (!LI.findIndexesLiveAt(Indexes, std::back_inserter(LiveIdxs)))
528 continue;
529 if (!LI.hasSubRanges()) {
530 for (auto SI : LiveIdxs)
531 LiveRegMap[SII.getInstructionFromIndex(SI)][Reg] =
532 MRI.getMaxLaneMaskForVReg(Reg);
533 } else
534 for (const auto &S : LI.subranges()) {
535 // constrain search for subranges by indexes live at main range
536 SRLiveIdxs.clear();
537 S.findIndexesLiveAt(LiveIdxs, std::back_inserter(SRLiveIdxs));
538 for (auto SI : SRLiveIdxs)
539 LiveRegMap[SII.getInstructionFromIndex(SI)][Reg] |= S.LaneMask;
540 }
541 }
542 return LiveRegMap;
543}
544
546 const LiveIntervals &LIS) {
548 MI.getMF()->getRegInfo());
549}
550
552 const LiveIntervals &LIS) {
554 MI.getMF()->getRegInfo());
555}
556
557template <typename Range>
559 Range &&LiveRegs) {
560 GCNRegPressure Res;
561 for (const auto &RM : LiveRegs)
562 Res.inc(RM.first, LaneBitmask::getNone(), RM.second, MRI);
563 return Res;
564}
565
567 const GCNRPTracker::LiveRegSet &S2);
568
569Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST = nullptr,
570 unsigned DynamicVGPRBlockSize = 0);
571
573 const MachineRegisterInfo &MRI);
574
575Printable reportMismatch(const GCNRPTracker::LiveRegSet &LISLR,
576 const GCNRPTracker::LiveRegSet &TrackedL,
577 const TargetRegisterInfo *TRI, StringRef Pfx = " ");
578
580 static char ID;
581
582public:
584
585 bool runOnMachineFunction(MachineFunction &MF) override;
586
592};
593
596 LiveIntervals &LIS,
597 const MachineLoopInfo *MLI);
598
599/// Estimate VGPR pressure using greedy, non-splitting register allocation
600/// simulation, accounting for live interval interference.
601/// \param RegionBegin Start iterator of the region
602/// \param RegionEnd End iterator of the region
603/// \param LiveIns Live-in registers for the region
604/// \returns estimated VGPR pressure
608 const GCNRPTracker::LiveRegSet &LiveIns, const LiveIntervals &LIS,
609 const MachineRegisterInfo &MRI, const SIRegisterInfo &TRI);
610
611} // end namespace llvm
612
613#endif // LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
constexpr LLT S1
MachineBasicBlock & MBB
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
AMD GCN specific subclass of TargetSubtarget.
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
Value * RHS
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
void retireDeadOperands(const MachineInstr &MI, SlotIndex SI)
Retires all lanes of MI's register operands that are dead at SI, according to LIS.
GCNDownwardRPTrackerBase(LiveIntervals &LIS)
GCNRegPressure bumpDownwardPressure(const MachineInstr *MI, const SIRegisterInfo *TRI) const
Mostly copy/paste from CodeGen/RegisterPressure.cpp Calculate the impact MI will have on CurPressure ...
void addDefs(const MachineInstr &MI)
Adds all lanes (dead or not) defined by MI's register operands to CurPressure.
bool advance()
Advance to the state at the next MI in program order.
GCNRegPressure moveMaxPressure()
return MaxPressure and clear it.
GCNDownwardRPTracker(LiveIntervals &LIS)
MachineBasicBlock::const_iterator getNext() const
Returns the next MI that will be advanced over.
void advanceToNext()
Move to the state at NextMI.
bool advanceBeforeNext()
Move to the state right before NextMI or the end of the MBB.
bool reset(const MachineInstr &MI, MachineBasicBlock::const_iterator End, const LiveRegSet *LiveRegsCopy=nullptr)
Reset tracker to the point before the MI (filling LiveRegs upon this point using LiveRegsCopy if prov...
GCNManualDownwardRPTracker(LiveIntervals &LIS)
void advance(const MachineInstr &MI)
Advances to the state after MI.
GCNRPTarget(const MachineFunction &MF, const GCNRegPressure &RP)
Sets up the target such that the register pressure starting at RP does not show register spilling on ...
unsigned getMaxVGPRs() const
bool isSaveBeneficial(Register Reg) const
Determines whether saving virtual register Reg will be beneficial towards achieving the RP target.
bool hasVectorRegisterExcess() const
void setRP(const GCNRegPressure &NewRP)
bool satisfied() const
Whether the current RP is at or below the defined pressure target.
unsigned getMaxSGPRs() const
const GCNRegPressure & getCurrentRP() const
void setTarget(unsigned NumSGPRs, unsigned NumVGPRs)
Changes the target (same semantics as constructor).
friend raw_ostream & operator<<(raw_ostream &OS, const GCNRPTarget &Target)
void saveRP(const GCNRegPressure &SaveRP)
Saves a total pressure of SaveRP.
unsigned getNumRegsBenefit(const GCNRegPressure &SaveRP) const
Returns the benefit towards achieving the RP target that saving SaveRP represents,...
const GCNRegPressure & getMaxPressure() const
GCNRegPressure getPressure() const
const decltype(LiveRegs) & getLiveRegs() const
const MachineInstr * LastTrackedMI
decltype(LiveRegs) moveLiveRegs()
GCNRegPressure CurPressure
GCNRPTracker(LiveIntervals &LIS_)
DenseMap< unsigned, LaneBitmask > LiveRegSet
LiveIntervals & LIS
LaneBitmask getLastUsedLanes(Register Reg, SlotIndex Pos) const
Mostly copy/paste from CodeGen/RegisterPressure.cpp.
GCNRegPressure MaxPressure
const MachineInstr * getLastTrackedMI() const
const MachineRegisterInfo * MRI
void reset(const MachineInstr &MI, bool After)
Resets tracker before or After the provided MI, which can be a debug instruction.
GCNRegPressure getMaxPressureAndReset()
GCNUpwardRPTracker(LiveIntervals &LIS_)
void recede(const MachineInstr &MI)
Move to the state of RP just before the MI.
bool isValid() const
returns whether the tracker's state after receding MI corresponds to reported by LIS.
void reset(const MachineInstr &MI)
Resets tracker to the point just after MI (in program order), which can be a debug instruction.
bool hasInterval(Register Reg) const
SlotIndexes * getSlotIndexes() const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
LiveInterval & getInterval(Register Reg)
A set of live virtual registers and physical register units.
MachineInstrBundleIterator< const MachineInstr > const_iterator
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
const TargetRegisterInfo * getTargetRegisterInfo() const
Simple wrapper around std::function<void(raw_ostream&)>.
Definition Printable.h:38
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:72
SlotIndex - An opaque wrapper around machine indexes.
Definition SlotIndexes.h:66
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Target - Wrapper for Target specific information.
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
unsigned getArchVGPRAllocGranule()
For subtargets with a unified VGPR file and mixed ArchVGPR/AGPR usage, returns the allocation granule...
This is an optimization pass for GlobalISel generic memory operations.
LaneBitmask getLiveLaneMask(unsigned Reg, SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI, LaneBitmask LaneMaskFilter=LaneBitmask::getAll())
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
GCNRPTracker::LiveRegSet getLiveRegs(SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI, GCNRegPressure::RegKind RegKind=GCNRegPressure::TOTAL_KINDS)
GCNRegPressure getRegPressure(const MachineRegisterInfo &MRI, Range &&LiveRegs)
GCNRPTracker::LiveRegSet getLiveRegsAfter(const MachineInstr &MI, const LiveIntervals &LIS)
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1652
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
constexpr NextUseDistance max(NextUseDistance A, NextUseDistance B)
APInt operator-(APInt)
Definition APInt.h:2214
DenseMap< MachineInstr *, GCNRPTracker::LiveRegSet > getLiveRegMap(Range &&R, bool After, LiveIntervals &LIS)
creates a map MachineInstr -> LiveRegSet R - range of iterators on instructions After - upon entry or...
APInt operator+(APInt a, const APInt &b)
Definition APInt.h:2219
GCNRPTracker::LiveRegSet getLiveRegsBefore(const MachineInstr &MI, const LiveIntervals &LIS)
LLVM_ABI void dumpMaxRegPressure(MachineFunction &MF, GCNRegPressure::RegKind Kind, LiveIntervals &LIS, const MachineLoopInfo *MLI)
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:267
unsigned estimateGreedyVGPRPressure(MachineBasicBlock::const_iterator RegionBegin, MachineBasicBlock::const_iterator RegionEnd, const GCNRPTracker::LiveRegSet &LiveIns, const LiveIntervals &LIS, const MachineRegisterInfo &MRI, const SIRegisterInfo &TRI)
Estimate VGPR pressure using greedy, non-splitting register allocation simulation,...
Printable reportMismatch(const GCNRPTracker::LiveRegSet &LISLR, const GCNRPTracker::LiveRegSet &TrackedL, const TargetRegisterInfo *TRI, StringRef Pfx=" ")
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
static RegKind getRegKind(unsigned Reg, const MachineRegisterInfo &MRI)
static constexpr const char * getName(RegKind Kind)
bool operator!=(const GCNRegPressure &O) const
GCNRegPressure & operator+=(const GCNRegPressure &RHS)
unsigned getNumRegs(RegKind Kind) const
unsigned getVGPRTuplesWeight() const
GCNRegPressure & operator-=(const GCNRegPressure &RHS)
unsigned getVGPRSpills(MachineFunction &MF, unsigned ArchVGPRThreshold, unsigned AGPRThreshold, unsigned CombinedThreshold)
unsigned getVGPRNum(bool UnifiedVGPRFile) const
friend Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST, unsigned DynamicVGPRBlockSize)
unsigned getOccupancy(const GCNSubtarget &ST, unsigned DynamicVGPRBlockSize) const
friend GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
void inc(unsigned Reg, LaneBitmask PrevMask, LaneBitmask NewMask, const MachineRegisterInfo &MRI)
unsigned getArchVGPRNum() const
unsigned getAGPRNum() const
unsigned getSGPRNum() const
unsigned getSGPRTuplesWeight() const
bool operator==(const GCNRegPressure &O) const
static unsigned getUnifiedVGPRNum(unsigned NumArchVGPRs, unsigned NumAGPRs, unsigned NumAVGPRs)
Returns the aggregated VGPR pressure, assuming NumArchVGPRs ArchVGPRs NumAGPRs AGPRS,...
bool less(const MachineFunction &MF, const GCNRegPressure &O, unsigned MaxOccupancy=std::numeric_limits< unsigned >::max()) const
Compares this GCNRegpressure to O, returning true if this is less.
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
static constexpr LaneBitmask getNone()
Definition LaneBitmask.h:81