LLVM: lib/Target/AMDGPU/GCNRegPressure.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17#ifndef LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H

18#define LLVM_LIB_TARGET_AMDGPU_GCNREGPRESSURE_H

19

23#include

24#include

25

26namespace llvm {

27

31

34

36 const char *Names[] = {"SGPR", "VGPR", "AGPR", "AVGPR"};

38 return Names[Kind];

39 }

40

44

48

49 void clear() { Value.fill(0); }

50

53 return Value[Kind];

54 }

55

56

58

59

60 unsigned getVGPRNum(bool UnifiedVGPRFile) const {

61 if (UnifiedVGPRFile) {

62 return Value[AGPR]

65 }

66

67

68 return std::max(Value[VGPR] + Value[AVGPR], Value[AGPR]);

69 }

70

71

72

73

75 unsigned NumAGPRs,

76 unsigned NumAVGPRs) {

77

78

79 return alignTo(NumArchVGPRs + NumAVGPRs,

81 NumAGPRs;

82 }

83

84

85

87

89

91

97

99 unsigned DynamicVGPRBlockSize) const {

100 return std::min(ST.getOccupancyWithNumSGPRs(getSGPRNum()),

101 ST.getOccupancyWithNumVGPRs(getVGPRNum(ST.hasGFX90AInsts()),

102 DynamicVGPRBlockSize));

103 }

104

105 void inc(unsigned Reg,

109

111 unsigned DynamicVGPRBlockSize) const {

112 return getOccupancy(ST, DynamicVGPRBlockSize) >

113 O.getOccupancy(ST, DynamicVGPRBlockSize);

114 }

115

116

117

118

119

120

121

122

123

124

125

126

127

129 unsigned MaxOccupancy = std::numeric_limits::max()) const;

130

132

134 return !(*this == O);

135 }

136

138 for (unsigned I = 0; I < ValueArraySize; ++I)

139 Value[I] += RHS.Value[I];

140 return *this;

141 }

142

144 for (unsigned I = 0; I < ValueArraySize; ++I)

145 Value[I] -= RHS.Value[I];

146 return *this;

147 }

148

149 void dump() const;

150

156

157private:

158 static constexpr unsigned ValueArraySize = TOTAL_KINDS * 2;

159

160

161

162 std::array<unsigned, ValueArraySize> Value;

163

166

169

171 unsigned DynamicVGPRBlockSize);

172};

173

176 for (unsigned I = 0; I < GCNRegPressure::ValueArraySize; ++I)

177 Res.Value[I] = std::max(P1.Value[I], P2.Value[I]);

178 return Res;

179}

180

184 Sum += P2;

185 return Sum;

186}

187

191 Diff -= P2;

192 return Diff;

193}

194

195

196

197

198

199

201public:

202

203

204

206

207

208

209

212

213

214

215

218

219

220 void setTarget(unsigned NumSGPRs, unsigned NumVGPRs);

221

223

225

226

227

229

230

234

235

237

238#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

240 OS << "Actual/Target: " << Target.RP.getSGPRNum() << '/' << Target.MaxSGPRs

241 << " SGPRs, " << Target.RP.getArchVGPRNum() << '/' << Target.MaxVGPRs

242 << " ArchVGPRs, " << Target.RP.getAGPRNum() << '/' << Target.MaxVGPRs

243 << " AGPRs";

244

245 if (Target.MaxUnifiedVGPRs) {

246 OS << ", " << Target.RP.getVGPRNum(true) << '/' << Target.MaxUnifiedVGPRs

247 << " VGPRs (unified)";

248 }

249 return OS;

250 }

251#endif

252

253private:

255 const bool UnifiedRF;

256

257

259

260

261 unsigned MaxSGPRs;

262

263 unsigned MaxVGPRs;

264

265

266 unsigned MaxUnifiedVGPRs;

267

269 : MF(MF), UnifiedRF(MF.getSubtarget<GCNSubtarget>().hasGFX90AInsts()),

270 RP(RP) {}

271};

272

273

274

275

277public:

279

280protected:

286

288

290 bool After);

291

292

294

296

297public:

298

300

303

305

307

311};

312

314getLiveRegs(SlotIndex SI, const LiveIntervals &LIS,

315 const MachineRegisterInfo &MRI,

317

318

319

320

322public:

324

326

327

331

332

334 SlotIndex MBBLastSlot = LIS.getSlotIndexes()->getMBBLastIdx(&MBB);

335 reset(MBB.getParent()->getRegInfo(), MBBLastSlot);

336 }

337

338

340 reset(MI.getMF()->getRegInfo(), LIS.getInstructionIndex(MI).getDeadSlot());

341 }

342

343

344

345

347

348

349

351

353

355

361};

362

363

364

365

367

369

371

372public:

374

376

378

379

385

386

387

388

390

391

392

393

394

395

396

397

398

400 bool UseInternalIterator = true);

401

402

403

404

405

406

407

409 bool UseInternalIterator = true);

410

411

412

413

414

415

416

417

419

420

422

423

426 const LiveRegSet *LiveRegsCopy = nullptr);

427

428

429

430

431

434};

435

436

437

438

439

441 const LiveIntervals &LIS,

442 const MachineRegisterInfo &MRI,

444

446 const MachineRegisterInfo &MRI,

448

449

450

451

452

453

454template

455DenseMap<MachineInstr*, GCNRPTracker::LiveRegSet>

457 std::vector Indexes;

461 auto SI = SII.getInstructionIndex(*I);

462 Indexes.push_back(After ? SI.getDeadSlot() : SI.getBaseIndex());

463 }

465

466 auto &MRI = (*R.begin())->getMF()->getRegInfo();

469 for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {

472 continue;

474 LiveIdxs.clear();

475 if (!LI.findIndexesLiveAt(Indexes, std::back_inserter(LiveIdxs)))

476 continue;

477 if (!LI.hasSubRanges()) {

478 for (auto SI : LiveIdxs)

479 LiveRegMap[SII.getInstructionFromIndex(SI)][Reg] =

480 MRI.getMaxLaneMaskForVReg(Reg);

481 } else

482 for (const auto &S : LI.subranges()) {

483

484 SRLiveIdxs.clear();

485 S.findIndexesLiveAt(LiveIdxs, std::back_inserter(SRLiveIdxs));

486 for (auto SI : SRLiveIdxs)

487 LiveRegMap[SII.getInstructionFromIndex(SI)][Reg] |= S.LaneMask;

488 }

489 }

490 return LiveRegMap;

491}

492

496 MI.getMF()->getRegInfo());

497}

498

502 MI.getMF()->getRegInfo());

503}

504

505template

509 for (const auto &RM : LiveRegs)

511 return Res;

512}

513

516

517Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST = nullptr,

518 unsigned DynamicVGPRBlockSize = 0);

519

521 const MachineRegisterInfo &MRI);

522

525 const TargetRegisterInfo *TRI, StringRef Pfx = " ");

526

529

530public:

532

534

540};

541

544 LiveIntervals &LIS,

545 const MachineLoopInfo *MLI);

546

547}

548

549#endif

unsigned const MachineRegisterInfo * MRI

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

AMD GCN specific subclass of TargetSubtarget.

Register const TargetRegisterInfo * TRI

ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))

StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)

Represent the analysis usage information of a pass.

AnalysisUsage & addRequired()

void setPreservesAll()

Set by analyses that do not transform their input at all.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

GCNRegPressure moveMaxPressure()

return MaxPressure and clear it.

Definition GCNRegPressure.h:380

bool advanceBeforeNext(MachineInstr *MI=nullptr, bool UseInternalIterator=true)

Move to the state right before the next MI or after the end of MBB.

bool advance(MachineInstr *MI=nullptr, bool UseInternalIterator=true)

Move to the state at the next MI.

GCNRegPressure bumpDownwardPressure(const MachineInstr *MI, const SIRegisterInfo *TRI) const

Mostly copy/paste from CodeGen/RegisterPressure.cpp Calculate the impact MI will have on CurPressure ...

MachineBasicBlock::const_iterator getNext() const

Definition GCNRegPressure.h:377

GCNDownwardRPTracker(const LiveIntervals &LIS_)

Definition GCNRegPressure.h:373

bool reset(const MachineInstr &MI, const LiveRegSet *LiveRegs=nullptr)

Reset tracker to the point before the MI filling LiveRegs upon this point using LIS.

void advanceToNext(MachineInstr *MI=nullptr, bool UseInternalIterator=true)

Move to the state at the MI, advanceBeforeNext has to be called first.

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 ...

bool isSaveBeneficial(Register Reg) const

Determines whether saving virtual register Reg will be beneficial towards achieving the RP target.

void saveReg(Register Reg, LaneBitmask Mask, const MachineRegisterInfo &MRI)

Saves virtual register Reg with lanemask Mask.

Definition GCNRegPressure.h:231

bool satisfied() const

Whether the current RP is at or below the defined pressure target.

void setRP(const GCNRegPressure &NewRP)

Definition GCNRegPressure.h:224

const GCNRegPressure & getCurrentRP() const

Definition GCNRegPressure.h:222

void setTarget(unsigned NumSGPRs, unsigned NumVGPRs)

Changes the target (same semantics as constructor).

friend raw_ostream & operator<<(raw_ostream &OS, const GCNRPTarget &Target)

Definition GCNRegPressure.h:239

LiveRegSet LiveRegs

Definition GCNRegPressure.h:282

GCNRegPressure getPressure() const

Definition GCNRegPressure.h:306

const decltype(LiveRegs) & getLiveRegs() const

Definition GCNRegPressure.h:301

const MachineInstr * LastTrackedMI

Definition GCNRegPressure.h:284

decltype(LiveRegs) moveLiveRegs()

Definition GCNRegPressure.h:308

GCNRegPressure CurPressure

Definition GCNRegPressure.h:283

DenseMap< unsigned, LaneBitmask > LiveRegSet

Definition GCNRegPressure.h:278

void clearMaxPressure()

Definition GCNRegPressure.h:304

LaneBitmask getLastUsedLanes(Register Reg, SlotIndex Pos) const

Mostly copy/paste from CodeGen/RegisterPressure.cpp.

GCNRPTracker(const LiveIntervals &LIS_)

Definition GCNRegPressure.h:287

GCNRegPressure MaxPressure

Definition GCNRegPressure.h:283

void reset(const MachineInstr &MI, const LiveRegSet *LiveRegsCopy, bool After)

void bumpDeadDefs(ArrayRef< VRegMaskOrUnit > DeadDefs)

Mostly copy/paste from CodeGen/RegisterPressure.cpp.

const MachineInstr * getLastTrackedMI() const

Definition GCNRegPressure.h:302

const MachineRegisterInfo * MRI

Definition GCNRegPressure.h:285

const LiveIntervals & LIS

Definition GCNRegPressure.h:281

GCNUpwardRPTracker(const LiveIntervals &LIS_)

Definition GCNRegPressure.h:323

GCNRegPressure getMaxPressureAndReset()

Definition GCNRegPressure.h:356

void reset(const MachineRegisterInfo &MRI, SlotIndex SI)

reset tracker at the specified slot index SI.

Definition GCNRegPressure.h:328

void recede(const MachineInstr &MI)

Move to the state of RP just before the MI .

const GCNRegPressure & getMaxPressure() const

Definition GCNRegPressure.h:352

void resetMaxPressure()

Definition GCNRegPressure.h:354

void reset(const MachineBasicBlock &MBB)

reset tracker to the end of the MBB.

Definition GCNRegPressure.h:333

bool isValid() const

returns whether the tracker's state after receding MI corresponds to reported by LIS.

void reset(const MachineInstr &MI)

reset tracker to the point just after MI (in program order).

Definition GCNRegPressure.h:339

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

MachineFunctionPass(char &ID)

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

Representation of each machine instruction.

MachineRegisterInfo - Keep track of information for virtual and physical registers,...

Simple wrapper around std::function<void(raw_ostream&)>.

Wrapper class representing virtual and physical registers.

static Register index2VirtReg(unsigned Index)

Convert a 0-based index to a virtual register number.

SlotIndex - An opaque wrapper around machine indexes.

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.

This class implements an extremely fast bulk output stream that can only output to a stream.

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.

GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)

Definition GCNRegPressure.h:174

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.

GCNRPTracker::LiveRegSet getLiveRegs(SlotIndex SI, const LiveIntervals &LIS, const MachineRegisterInfo &MRI, GCNRegPressure::RegKind RegKind=GCNRegPressure::TOTAL_KINDS)

GCNRegPressure getRegPressure(const MachineRegisterInfo &MRI, Range &&LiveRegs)

Definition GCNRegPressure.h:506

GCNRPTracker::LiveRegSet getLiveRegsAfter(const MachineInstr &MI, const LiveIntervals &LIS)

Definition GCNRegPressure.h:493

void sort(IteratorTy Start, IteratorTy End)

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

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...

Definition GCNRegPressure.h:456

APInt operator+(APInt a, const APInt &b)

GCNRPTracker::LiveRegSet getLiveRegsBefore(const MachineInstr &MI, const LiveIntervals &LIS)

Definition GCNRegPressure.h:499

LLVM_ABI void dumpMaxRegPressure(MachineFunction &MF, GCNRegPressure::RegKind Kind, LiveIntervals &LIS, const MachineLoopInfo *MLI)

Printable reportMismatch(const GCNRPTracker::LiveRegSet &LISLR, const GCNRPTracker::LiveRegSet &TrackedL, const TargetRegisterInfo *TRI, StringRef Pfx=" ")

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...

Definition GCNRegPressure.h:535

bool runOnMachineFunction(MachineFunction &MF) override

runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...

static char ID

Definition GCNRegPressure.h:528

GCNRegPressurePrinter()

Definition GCNRegPressure.h:531

Definition GCNRegPressure.h:32

static RegKind getRegKind(unsigned Reg, const MachineRegisterInfo &MRI)

Definition GCNRegPressure.h:151

static constexpr const char * getName(RegKind Kind)

Definition GCNRegPressure.h:35

bool operator!=(const GCNRegPressure &O) const

Definition GCNRegPressure.h:133

GCNRegPressure & operator+=(const GCNRegPressure &RHS)

Definition GCNRegPressure.h:137

unsigned getNumRegs(RegKind Kind) const

Definition GCNRegPressure.h:51

unsigned getVGPRTuplesWeight() const

Definition GCNRegPressure.h:92

bool empty() const

Definition GCNRegPressure.h:45

GCNRegPressure & operator-=(const GCNRegPressure &RHS)

Definition GCNRegPressure.h:143

void clear()

Definition GCNRegPressure.h:49

unsigned getVGPRNum(bool UnifiedVGPRFile) const

Definition GCNRegPressure.h:60

friend Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST, unsigned DynamicVGPRBlockSize)

unsigned getOccupancy(const GCNSubtarget &ST, unsigned DynamicVGPRBlockSize) const

Definition GCNRegPressure.h:98

GCNRegPressure()

Definition GCNRegPressure.h:41

friend GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)

Definition GCNRegPressure.h:174

void inc(unsigned Reg, LaneBitmask PrevMask, LaneBitmask NewMask, const MachineRegisterInfo &MRI)

bool higherOccupancy(const GCNSubtarget &ST, const GCNRegPressure &O, unsigned DynamicVGPRBlockSize) const

Definition GCNRegPressure.h:110

RegKind

Definition GCNRegPressure.h:33

@ AVGPR

Definition GCNRegPressure.h:33

@ TOTAL_KINDS

Definition GCNRegPressure.h:33

@ AGPR

Definition GCNRegPressure.h:33

@ SGPR

Definition GCNRegPressure.h:33

@ VGPR

Definition GCNRegPressure.h:33

unsigned getArchVGPRNum() const

Definition GCNRegPressure.h:86

unsigned getAGPRNum() const

Definition GCNRegPressure.h:88

unsigned getSGPRNum() const

Definition GCNRegPressure.h:57

unsigned getSGPRTuplesWeight() const

Definition GCNRegPressure.h:96

bool operator==(const GCNRegPressure &O) const

Definition GCNRegPressure.h:131

static unsigned getUnifiedVGPRNum(unsigned NumArchVGPRs, unsigned NumAGPRs, unsigned NumAVGPRs)

Returns the aggregated VGPR pressure, assuming NumArchVGPRs ArchVGPRs NumAGPRs AGPRS,...

Definition GCNRegPressure.h:74

unsigned getAVGPRNum() const

Definition GCNRegPressure.h:90

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()

static constexpr LaneBitmask getNone()