LLVM: include/llvm/CodeGen/RegisterPressure.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CODEGEN_REGISTERPRESSURE_H

15#define LLVM_CODEGEN_REGISTERPRESSURE_H

16

25#include

26#include

27#include

28#include

29#include

30

31namespace llvm {

32

38

46

47

58

59

60

61

62

63

64

65

66

67

79

80

81

82

94

95

96

97

98

99

100

101

102

104 uint16_t PSetID = 0;

105 int16_t UnitInc = 0;

106

107public:

110 assert(id < std::numeric_limits<uint16_t>::max() && "PSetID overflow.");

111 }

112

113 bool isValid() const { return PSetID > 0; }

114

117 return PSetID - 1;

118 }

119

120

122 return (PSetID - 1) & std::numeric_limits<uint16_t>::max();

123 }

124

126

128

130 return PSetID == RHS.PSetID && UnitInc == RHS.UnitInc;

131 }

132

134};

135

136

137

138

139

140

142

143

144

145 enum { MaxPSets = 16 };

146

148

150

151 iterator nonconst_begin() { return &PressureChanges[0]; }

152 iterator nonconst_end() { return &PressureChanges[MaxPSets]; }

153

154public:

156

159

162

164};

165

166

168public:

169

171

172

174

175

177

178

179

182 bool IgnoreDead);

183

184

185

188

189

190

191

192

197};

198

199

202 unsigned Size = 0;

203 unsigned Max = 0;

204

205public:

210

212

214

216 assert(Idx < Size && "PressureDiff index out of bounds");

217 return PDiffArray[Idx];

218 }

220 return const_cast<PressureDiffs*>(this)->operator[](Idx);

221 }

222

223

224

227};

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

259

260

261

262

263

265private:

266 struct IndexMaskPair {

267 unsigned Index;

269

270 IndexMaskPair(unsigned Index, LaneBitmask LaneMask)

271 : Index(Index), LaneMask(LaneMask) {}

272

273 unsigned getSparseSetIndex() const {

274 return Index;

275 }

276 };

277

279 RegSet Regs;

280 unsigned NumRegUnits = 0u;

281

282 unsigned getSparseIndexFromVirtRegOrUnit(VirtRegOrUnit VRegOrUnit) const {

285 assert(static_cast<unsigned>(VRegOrUnit.asMCRegUnit()) < NumRegUnits);

286 return static_cast<unsigned>(VRegOrUnit.asMCRegUnit());

287 }

288

289 VirtRegOrUnit getVirtRegOrUnitFromSparseIndex(unsigned SparseIndex) const {

290 if (SparseIndex >= NumRegUnits)

292 return VirtRegOrUnit(static_cast<MCRegUnit>(SparseIndex));

293 }

294

295public:

298

300 unsigned SparseIndex = getSparseIndexFromVirtRegOrUnit(VRegOrUnit);

302 if (I == Regs.end())

304 return I->LaneMask;

305 }

306

307

308

310 unsigned SparseIndex = getSparseIndexFromVirtRegOrUnit(Pair.VRegOrUnit);

311 auto InsertRes = Regs.insert(IndexMaskPair(SparseIndex, Pair.LaneMask));

312 if (!InsertRes.second) {

313 LaneBitmask PrevMask = InsertRes.first->LaneMask;

314 InsertRes.first->LaneMask |= Pair.LaneMask;

315 return PrevMask;

316 }

318 }

319

320

321

323 unsigned SparseIndex = getSparseIndexFromVirtRegOrUnit(Pair.VRegOrUnit);

325 if (I == Regs.end())

328 I->LaneMask &= ~Pair.LaneMask;

329 return PrevMask;

330 }

331

333 return Regs.size();

334 }

335

337 for (const IndexMaskPair &P : Regs) {

338 VirtRegOrUnit VRegOrUnit = getVirtRegOrUnitFromSparseIndex(P.Index);

339 if (P.LaneMask.any())

341 }

342 }

343};

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

367

368

370

371

373

374

375

376 bool RequireIntervals;

377

378

379 bool TrackUntiedDefs = false;

380

381

382 bool TrackLaneMasks = false;

383

384

385

386

388

389

390 std::vector CurrSetPressure;

391

392

394

395

397

398 std::vector LiveThruPressure;

399

400public:

403

405

409 bool TrackUntiedDefs);

410

411

412

413

415

416

418

419

420

421

422

424

425

427

428

429

430

431

434

435

437

438

440

441

442

443

445

446

448

449

450

452

453

455 LiveThruPressure.assign(PressureSet.begin(), PressureSet.end());

456 }

457

459

460

461

464

465

466

468 return CurrSetPressure;

469 }

470

473

476

477

478

479

480

486

492

493

494

495

496

501

502

503

504

511 MaxPressureLimit);

512

515 MaxPressureLimit);

516 }

517

518

520 std::vector &PressureResult,

521 std::vector &MaxPressureResult);

522

523

525 std::vector &PressureResult,

526 std::vector &MaxPressureResult);

527

529 std::vector &PressureResult,

530 std::vector &MaxPressureResult) {

533

536 }

537

539 return UntiedDefs.count(VirtReg);

540 }

541

543

550

551protected:

552

554

556

557

558

560

562

565

569

576};

577

579 const TargetRegisterInfo *TRI);

580

581}

582

583#endif

unsigned const MachineRegisterInfo * MRI

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

A common definition of LaneBitmask for use in TableGen and CodeGen.

Register const TargetRegisterInfo * TRI

This file defines the SmallVector class.

This file defines the SparseSet class derived from the version described in Briggs,...

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

A set of live virtual registers and physical register units.

Definition RegisterPressure.h:264

LaneBitmask erase(VRegMaskOrUnit Pair)

Clears the Pair.LaneMask lanes of Pair.Reg (mark them as dead).

Definition RegisterPressure.h:322

LaneBitmask contains(VirtRegOrUnit VRegOrUnit) const

Definition RegisterPressure.h:299

LLVM_ABI void init(const MachineRegisterInfo &MRI)

LaneBitmask insert(VRegMaskOrUnit Pair)

Mark the Pair.LaneMask lanes of Pair.Reg as live.

Definition RegisterPressure.h:309

size_t size() const

Definition RegisterPressure.h:332

void appendTo(SmallVectorImpl< VRegMaskOrUnit > &To) const

Definition RegisterPressure.h:336

MachineInstrBundleIterator< const MachineInstr > const_iterator

Representation of each machine instruction.

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

Capture a change in pressure for a single pressure set.

Definition RegisterPressure.h:103

int getUnitInc() const

Definition RegisterPressure.h:125

unsigned getPSetOrMax() const

Definition RegisterPressure.h:121

LLVM_ABI void dump() const

bool isValid() const

Definition RegisterPressure.h:113

void setUnitInc(int Inc)

Definition RegisterPressure.h:127

bool operator==(const PressureChange &RHS) const

Definition RegisterPressure.h:129

PressureChange(unsigned id)

Definition RegisterPressure.h:109

unsigned getPSet() const

Definition RegisterPressure.h:115

List of PressureChanges in order of increasing, unique PSetID.

Definition RegisterPressure.h:141

const PressureChange * const_iterator

Definition RegisterPressure.h:155

LLVM_ABI void dump(const TargetRegisterInfo &TRI) const

const_iterator end() const

Definition RegisterPressure.h:158

LLVM_ABI void addPressureChange(VirtRegOrUnit VRegOrUnit, bool IsDec, const MachineRegisterInfo *MRI)

Add a change in pressure to the pressure diff of a given instruction.

const_iterator begin() const

Definition RegisterPressure.h:157

const PressureDiff & operator[](unsigned Idx) const

Definition RegisterPressure.h:219

void clear()

Definition RegisterPressure.h:211

~PressureDiffs()

Definition RegisterPressure.h:209

PressureDiffs & operator=(const PressureDiffs &other)=delete

PressureDiff & operator[](unsigned Idx)

Definition RegisterPressure.h:215

PressureDiffs(const PressureDiffs &other)=delete

LLVM_ABI void addInstruction(unsigned Idx, const RegisterOperands &RegOpers, const MachineRegisterInfo &MRI)

Record pressure difference induced by the given operand list to node with index Idx.

LLVM_ABI void init(unsigned N)

Initialize an array of N PressureDiffs.

Track the current register pressure at some position in the instruction stream, and remember the high...

Definition RegisterPressure.h:361

LLVM_ABI void closeRegion()

Finalize the region boundaries and recored live ins and live outs.

LLVM_ABI void discoverLiveIn(VRegMaskOrUnit Pair)

Add Reg to the live in set and increase max pressure.

void setPos(MachineBasicBlock::const_iterator Pos)

Definition RegisterPressure.h:423

ArrayRef< unsigned > getLiveThru() const

Definition RegisterPressure.h:458

LLVM_ABI void closeBottom()

Set the boundary for the bottom of the region and summarize live outs.

LLVM_ABI void recede(SmallVectorImpl< VRegMaskOrUnit > *LiveUses=nullptr)

Recede across the previous instruction.

void getPressureAfterInst(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)

Definition RegisterPressure.h:528

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:505

RegisterPressure & getPressure()

Get the resulting register pressure over the traversed region.

Definition RegisterPressure.h:462

LLVM_ABI void bumpDownwardPressure(const MachineInstr *MI)

Record the downward impact of a single instruction on current register pressure.

LLVM_ABI void addLiveRegs(ArrayRef< VRegMaskOrUnit > Regs)

Force liveness of virtual registers or physical register units.

LLVM_ABI void recedeSkipDebugValues()

Recede until we find an instruction which is not a DebugValue.

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

LLVM_ABI void initLiveThru(const RegPressureTracker &RPTracker)

Initialize the LiveThru pressure set based on the untied defs found in RPTracker.

LLVM_ABI void bumpDeadDefs(ArrayRef< VRegMaskOrUnit > DeadDefs)

void initLiveThru(ArrayRef< unsigned > PressureSet)

Copy an existing live thru pressure result.

Definition RegisterPressure.h:454

RegPressureTracker(RegionPressure &rp)

Definition RegisterPressure.h:402

RegPressureTracker(IntervalPressure &rp)

Definition RegisterPressure.h:401

LLVM_ABI void dump() const

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

LLVM_ABI void discoverLiveInOrOut(VRegMaskOrUnit Pair, SmallVectorImpl< VRegMaskOrUnit > &LiveInOrOut)

LLVM_ABI LaneBitmask getLiveThroughAt(VirtRegOrUnit VRegOrUnit, SlotIndex Pos) const

LLVM_ABI bool isBottomClosed() const

Does this pressure result have a valid bottom position and live outs.

LLVM_ABI LaneBitmask getLiveLanesAt(VirtRegOrUnit VRegOrUnit, SlotIndex Pos) const

bool hasUntiedDef(Register VirtReg) const

Definition RegisterPressure.h:538

MachineBasicBlock::const_iterator getPos() const

Get the MI position corresponding to this register pressure.

Definition RegisterPressure.h:417

LLVM_ABI void closeTop()

Set the boundary for the top of the region and summarize live ins.

LLVM_ABI void getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)

Consider the pressure increase caused by traversing this instruction top-down.

const RegisterPressure & getPressure() const

Definition RegisterPressure.h:463

LLVM_ABI void advance()

Advance across the current instruction.

LLVM_ABI bool isTopClosed() const

Does this pressure result have a valid top position and live ins.

LLVM_ABI void bumpUpwardPressure(const MachineInstr *MI)

Record the upward impact of a single instruction on current register pressure.

LLVM_ABI LaneBitmask getLastUsedLanes(VirtRegOrUnit VRegOrUnit, SlotIndex Pos) const

LLVM_ABI void increaseRegPressure(VirtRegOrUnit VRegOrUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)

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

LLVM_ABI SlotIndex getCurrSlot() const

Get the SlotIndex for the first nondebug instruction including or after the current position.

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:467

LLVM_ABI void decreaseRegPressure(VirtRegOrUnit VRegOrUnit, LaneBitmask PreviousMask, LaneBitmask NewMask)

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

LLVM_ABI void discoverLiveOut(VRegMaskOrUnit Pair)

Add Reg to the live out set and increase max pressure.

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

List of registers defined and used by a machine instruction.

Definition RegisterPressure.h:167

SmallVector< VRegMaskOrUnit, 8 > Defs

List of virtual registers and register units defined by the instruction which are not dead.

Definition RegisterPressure.h:173

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

SmallVector< VRegMaskOrUnit, 8 > DeadDefs

List of virtual registers and register units defined by the instruction but dead.

Definition RegisterPressure.h:176

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

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

SmallVector< VRegMaskOrUnit, 8 > Uses

List of virtual registers and register units read by the instruction.

Definition RegisterPressure.h:170

Wrapper class representing virtual and physical registers.

static Register index2VirtReg(unsigned Index)

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

unsigned virtRegIndex() const

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

SlotIndex - An opaque wrapper around machine indexes.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

reference emplace_back(ArgTypes &&... Args)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

SparseSet - Fast set implementation for objects that can be identified by small unsigned keys.

typename DenseT::const_iterator const_iterator

typename DenseT::iterator iterator

TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...

Wrapper class representing a virtual register or register unit.

constexpr bool isVirtualReg() const

constexpr MCRegUnit asMCRegUnit() const

constexpr Register asVirtualReg() const

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI void dumpRegSetPressure(ArrayRef< unsigned > SetPressure, const TargetRegisterInfo *TRI)

RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx.

Definition RegisterPressure.h:68

LLVM_ABI void reset()

Clear the result so it can be used for another round of pressure tracking.

LLVM_ABI void openBottom(SlotIndex PrevBottom)

If the current bottom is not greater than the previous index, open it.

SlotIndex BottomIdx

Definition RegisterPressure.h:71

SlotIndex TopIdx

Record the boundary of the region being tracked.

Definition RegisterPressure.h:70

LLVM_ABI void openTop(SlotIndex NextTop)

If the current top is not less than or equal to the next index, open it.

static constexpr LaneBitmask getNone()

Store the effects of a change in pressure on things that MI scheduler cares about.

Definition RegisterPressure.h:243

PressureChange CriticalMax

Definition RegisterPressure.h:245

PressureChange CurrentMax

Definition RegisterPressure.h:246

RegPressureDelta()=default

bool operator==(const RegPressureDelta &RHS) const

Definition RegisterPressure.h:250

LLVM_ABI void dump() const

bool operator!=(const RegPressureDelta &RHS) const

Definition RegisterPressure.h:254

PressureChange Excess

Definition RegisterPressure.h:244

RegisterPressure computed within a region of instructions delimited by TopPos and BottomPos.

Definition RegisterPressure.h:83

MachineBasicBlock::const_iterator TopPos

Record the boundary of the region being tracked.

Definition RegisterPressure.h:85

MachineBasicBlock::const_iterator BottomPos

Definition RegisterPressure.h:86

LLVM_ABI void openTop(MachineBasicBlock::const_iterator PrevTop)

If the current top is the previous instruction (before receding), open it.

LLVM_ABI void reset()

Clear the result so it can be used for another round of pressure tracking.

LLVM_ABI void openBottom(MachineBasicBlock::const_iterator PrevBottom)

If the current bottom is the previous instr (before advancing), open it.

Base class for register pressure results.

Definition RegisterPressure.h:48

SmallVector< VRegMaskOrUnit, 8 > LiveOutRegs

Definition RegisterPressure.h:54

SmallVector< VRegMaskOrUnit, 8 > LiveInRegs

List of live in virtual registers or physical register units.

Definition RegisterPressure.h:53

LLVM_ABI void dump(const TargetRegisterInfo *TRI) const

std::vector< unsigned > MaxSetPressure

Map of max reg pressure indexed by pressure set ID, not class ID.

Definition RegisterPressure.h:50

Definition RegisterPressure.h:39

LaneBitmask LaneMask

Definition RegisterPressure.h:41

VRegMaskOrUnit(VirtRegOrUnit VRegOrUnit, LaneBitmask LaneMask)

Definition RegisterPressure.h:43

VirtRegOrUnit VRegOrUnit

Definition RegisterPressure.h:40