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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64#ifndef LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H

65#define LLVM_CODEGEN_GLOBALISEL_REGBANKSELECT_H

66

73#include

74#include

75#include

76

77namespace llvm {

78

88

89

90

92public:

93 static char ID;

94

95

104

105

106

107

108

109

110

112 protected:

113

115

116

117

118

119

120

121

122

123

125

126

127

128

129

131

132

133

134

135

137

138 public:

140

141

142

143

144

145

146

147

148

159

160

161

162

163

164

165

166

167

178

179

183

184

185

186

187

188 virtual bool isSplit() const { return false; }

189

190

191

192

193

194

196

197

198

199

201 };

202

203

205 private:

206

208

209

210 bool Before;

211

213

215 if (Before)

216 return Instr;

217 return Instr.getNextNode() ? *Instr.getNextNode()

218 : Instr.getParent()->end();

219 }

220

223 }

224

225 public:

226

228

229 bool isSplit() const override;

231

232

234 };

235

236

238 private:

239

241

242

243 bool Beginning;

244

245 void materialize() override {

246 }

247

249 return Beginning ? MBB.begin() : MBB.end();

250 }

251

253

254 public:

256 : MBB(MBB), Beginning(Beginning) {

257

258

259 assert((!Beginning || MBB.getFirstNonPHI() == MBB.begin()) &&

260 "Invalid beginning point");

261

262

263 assert((Beginning || MBB.getFirstTerminator() == MBB.end()) &&

264 "Invalid end point");

265 }

266

267 bool isSplit() const override { return false; }

270 };

271

272

274 private:

275

277

278

279

280

282

283

285

287

289

290

291

292 assert(DstOrSplit && DstOrSplit->isPredecessor(&Src) &&

293 DstOrSplit->pred_size() == 1 && DstOrSplit->succ_size() == 1 &&

294 "Did not split?!");

295 return DstOrSplit->begin();

296 }

297

299

300 public:

302 : Src(Src), DstOrSplit(&Dst), P(P) {}

303

305 return Src.succ_size() > 1 && DstOrSplit->pred_size() > 1;

306 }

307

310 };

311

312

313

315 public:

316

327

328

329

333

334

335 private:

336

338

339 unsigned OpIdx;

340

341 bool CanMaterialize;

342

343 bool HasSplit = false;

344

345

347

349

350 public:

351

352

353

354

355

359

360

361

363 unsigned getOpIdx() const { return OpIdx; }

366

367

368

369

370

372

374

376

377

379

380

381

382

385

388

390

391

392

393

394

395

396

397

398

400 assert(NewKind != Kind && "Already of the right Kind");

401 Kind = NewKind;

402 InsertPoints.clear();

404 HasSplit = false;

406 "We would need more MI to switch to Insert");

407 }

408 };

409

410protected:

411

412

413

414

415

416

417

418

419

420

421

422 class MappingCost {

423 private:

424

425

427

428

430

432

434 : LocalCost(LocalCost), NonLocalCost(NonLocalCost),

435 LocalFreq(LocalFreq) {}

436

437

438 bool isSaturated() const;

439

440 public:

441

442

444

445

446

448

449

450

451

453

454

456

457

458

460

461

463

465

467

469 return *this != Cost && Cost < *this;

470 }

471

472

473 void dump() const;

474

475

477

478

480 Cost.print(OS);

481 return OS;

482 }

483 };

484

485

486

488

489

490

492

493

495

496

497

499

500

501

503

504

505 std::unique_ptr MORE;

506

507

509

510

512

513

514

516

517

519

520

521

522

523

526 bool &OnlyAssign) const;

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

564 &NewVRegs);

565

566

567

568

569

570

574

575

576

581

582

583

584

585

586

587

588

594

595

596

597

598

599

600

601

602

606

607

608

609

610

614

615public:

616

618

620

622

626

630

634

635

636

637

638

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

665

667};

668

669}

670

671#endif

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

This file declares the MachineIRBuilder class.

This file defines the SmallVector class.

Represent the analysis usage information of a pass.

LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)

Insert MI into the instruction list before I, possibly inside a bundle.

const MachineFunction * getParent() const

Return the MachineFunction containing this basic block.

MachineInstrBundleIterator< MachineInstr > iterator

MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...

MachineFunctionPass(char &ID)

Properties which a MachineFunction may have at a given point in time.

Helper class to build MachineInstr.

Representation of each machine instruction.

MachineOperand class - Representation of each machine instruction operand.

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

Pass interface - Implemented by all 'passes'.

uint64_t frequency(const Pass &P) const override

Frequency of the insertion point.

EdgeInsertPoint(MachineBasicBlock &Src, MachineBasicBlock &Dst, Pass &P)

Definition RegBankSelect.h:301

bool isSplit() const override

Does this point involve splitting an edge or block?

Definition RegBankSelect.h:304

bool canMaterialize() const override

Check whether this insertion point can be materialized.

Abstract class used to represent an insertion point in a CFG.

Definition RegBankSelect.h:111

virtual uint64_t frequency(const Pass &P) const

Frequency of the insertion point.

Definition RegBankSelect.h:195

MachineBasicBlock & getInsertMBB()

The first call to this method will cause the splitting to happen if need be, then sub sequent calls j...

Definition RegBankSelect.h:168

virtual MachineBasicBlock & getInsertMBBImpl()=0

Return the materialized insertion basic block.

MachineBasicBlock::iterator getPoint()

The first call to this method will cause the splitting to happen if need be, then sub sequent calls j...

Definition RegBankSelect.h:149

bool WasMaterialized

Tell if the insert point has already been materialized.

Definition RegBankSelect.h:114

virtual ~InsertPoint()=default

MachineBasicBlock::iterator insert(MachineInstr &MI)

Insert MI in the just before getPoint()

Definition RegBankSelect.h:180

virtual void materialize()=0

Materialize the insertion point.

virtual bool canMaterialize() const

Check whether this insertion point can be materialized.

Definition RegBankSelect.h:200

virtual bool isSplit() const

Does this point involve splitting an edge or block?

Definition RegBankSelect.h:188

virtual MachineBasicBlock::iterator getPointImpl()=0

Return the materialized insertion point.

bool canMaterialize() const override

Check whether this insertion point can be materialized.

Definition RegBankSelect.h:233

InstrInsertPoint(MachineInstr &Instr, bool Before=true)

Create an insertion point before (Before=true) or after Instr.

bool isSplit() const override

Does this point involve splitting an edge or block?

uint64_t frequency(const Pass &P) const override

Frequency of the insertion point.

bool canMaterialize() const override

Check whether this insertion point can be materialized.

Definition RegBankSelect.h:269

MBBInsertPoint(MachineBasicBlock &MBB, bool Beginning=true)

Definition RegBankSelect.h:255

bool isSplit() const override

Does this point involve splitting an edge or block?

Definition RegBankSelect.h:267

uint64_t frequency(const Pass &P) const override

Frequency of the insertion point.

Helper class used to represent the cost for mapping an instruction.

Definition RegBankSelect.h:422

bool operator!=(const MappingCost &Cost) const

Check if this is not equal to Cost.

Definition RegBankSelect.h:466

void saturate()

Saturate the cost to the maximal representable value.

bool operator==(const MappingCost &Cost) const

Check if this is equal to Cost.

bool addLocalCost(uint64_t Cost)

Add Cost to the local cost.

void dump() const

Print this on dbgs() stream.

static MappingCost ImpossibleCost()

Return an instance of MappingCost that represents an impossible mapping.

bool addNonLocalCost(uint64_t Cost)

Add Cost to the non-local cost.

bool operator<(const MappingCost &Cost) const

Check if this is less than Cost.

friend raw_ostream & operator<<(raw_ostream &OS, const MappingCost &Cost)

Overload the stream operator for easy debug printing.

Definition RegBankSelect.h:479

void print(raw_ostream &OS) const

Print this on OS;.

bool operator>(const MappingCost &Cost) const

Check if this is greater than Cost.

Definition RegBankSelect.h:468

Struct used to represent the placement of a repairing point for a given operand.

Definition RegBankSelect.h:314

bool hasSplit()

Definition RegBankSelect.h:365

unsigned getNumInsertPoints() const

Definition RegBankSelect.h:389

insertpt_iterator end()

Definition RegBankSelect.h:384

bool canMaterialize() const

Definition RegBankSelect.h:364

InsertionPoints::const_iterator const_insertpt_iterator

Definition RegBankSelect.h:332

RepairingPlacement(MachineInstr &MI, unsigned OpIdx, const TargetRegisterInfo &TRI, Pass &P, RepairingKind Kind=RepairingKind::Insert)

Create a repairing placement for the OpIdx-th operand of MI.

unsigned getOpIdx() const

Definition RegBankSelect.h:363

RepairingKind

Define the kind of action this repairing needs.

Definition RegBankSelect.h:317

@ Insert

Reparing code needs to happen before InsertPoints.

Definition RegBankSelect.h:321

@ None

Nothing to repair, just drop this action.

Definition RegBankSelect.h:319

@ Reassign

(Re)assign the register bank of the operand.

Definition RegBankSelect.h:323

@ Impossible

Mark this repairing placement as impossible.

Definition RegBankSelect.h:325

const_insertpt_iterator begin() const

Definition RegBankSelect.h:386

insertpt_iterator begin()

Definition RegBankSelect.h:383

const_insertpt_iterator end() const

Definition RegBankSelect.h:387

RepairingKind getKind() const

Definition RegBankSelect.h:362

SmallVector< std::unique_ptr< InsertPoint >, 2 > InsertionPoints

Definition RegBankSelect.h:330

InsertionPoints::iterator insertpt_iterator

Definition RegBankSelect.h:331

void switchTo(RepairingKind NewKind)

Change the type of this repairing placement to NewKind.

Definition RegBankSelect.h:399

void addInsertPoint(MachineBasicBlock &MBB, bool Beginning)

Mode

List of the modes supported by the RegBankSelect pass.

Definition RegBankSelect.h:96

@ Fast

Assign the register banks as fast as possible (default).

Definition RegBankSelect.h:98

@ Greedy

Greedily minimize the cost of assigning register banks.

Definition RegBankSelect.h:102

bool checkFunctionIsLegal(MachineFunction &MF) const

Check that our input is fully legal: we require the function to have the Legalized property,...

static char ID

Definition RegBankSelect.h:93

MachineIRBuilder MIRBuilder

Helper class used for every code morphing.

Definition RegBankSelect.h:508

MachineBlockFrequencyInfo * MBFI

Get the frequency of blocks.

Definition RegBankSelect.h:498

MachineFunctionProperties getClearedProperties() const override

Definition RegBankSelect.h:631

MachineFunctionProperties getSetProperties() const override

Definition RegBankSelect.h:627

Mode OptMode

Optimization mode of the pass.

Definition RegBankSelect.h:511

const RegisterBankInfo::InstructionMapping & findBestMapping(MachineInstr &MI, RegisterBankInfo::InstructionMappings &PossibleMappings, SmallVectorImpl< RepairingPlacement > &RepairPts)

Find the best mapping for MI from PossibleMappings.

MachineFunctionProperties getRequiredProperties() const override

Definition RegBankSelect.h:623

RegBankSelect(Mode RunningMode=Fast)

Create a RegBankSelect pass with the specified RunningMode.

bool assignInstr(MachineInstr &MI)

Assign the register bank of each operand of MI.

bool assignRegisterBanks(MachineFunction &MF)

Walk through MF and assign a register bank to every virtual register that are still mapped to nothing...

void init(MachineFunction &MF)

Initialize the field members using MF.

void tryAvoidingSplit(RegBankSelect::RepairingPlacement &RepairPt, const MachineOperand &MO, const RegisterBankInfo::ValueMapping &ValMapping) const

When RepairPt involves splitting to repair MO for the given ValMapping, try to change the way we repa...

const TargetRegisterInfo * TRI

Information on the register classes for the current function.

Definition RegBankSelect.h:494

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.

MachineBranchProbabilityInfo * MBPI

Get the frequency of the edges.

Definition RegBankSelect.h:502

bool assignmentMatch(Register Reg, const RegisterBankInfo::ValueMapping &ValMapping, bool &OnlyAssign) const

Check if Reg is already assigned what is described by ValMapping.

uint64_t getRepairCost(const MachineOperand &MO, const RegisterBankInfo::ValueMapping &ValMapping) const

Return the cost of the instruction needed to map MO to ValMapping.

MappingCost computeMapping(MachineInstr &MI, const RegisterBankInfo::InstructionMapping &InstrMapping, SmallVectorImpl< RepairingPlacement > &RepairPts, const MappingCost *BestCost=nullptr)

Compute the cost of mapping MI with InstrMapping and compute the repairing placement for such mapping...

bool repairReg(MachineOperand &MO, const RegisterBankInfo::ValueMapping &ValMapping, RegBankSelect::RepairingPlacement &RepairPt, const iterator_range< SmallVectorImpl< Register >::const_iterator > &NewVRegs)

Insert repairing code for Reg as specified by ValMapping.

StringRef getPassName() const override

getPassName - Return a nice clean name for a pass.

Definition RegBankSelect.h:619

MachineRegisterInfo * MRI

MRI contains all the register class/bank information that this pass uses and updates.

Definition RegBankSelect.h:491

bool runOnMachineFunction(MachineFunction &MF) override

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

const RegisterBankInfo * RBI

Interface to the target lowering info related to register banks.

Definition RegBankSelect.h:487

std::unique_ptr< MachineOptimizationRemarkEmitter > MORE

Current optimization remark emitter. Used to report failures.

Definition RegBankSelect.h:505

bool applyMapping(MachineInstr &MI, const RegisterBankInfo::InstructionMapping &InstrMapping, SmallVectorImpl< RepairingPlacement > &RepairPts)

Apply Mapping to MI.

Helper class that represents how the value of an instruction may be mapped and what is the related co...

Holds all the information related to register banks.

SmallVector< const InstructionMapping *, 4 > InstructionMappings

Convenient type to represent the alternatives for mapping an instruction.

Wrapper class representing virtual and physical registers.

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

typename SuperClass::const_iterator const_iterator

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

StringRef - Represent a constant reference to a string, i.e.

Target-Independent Code Generator Pass Configuration Options.

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

A range adaptor for a pair of iterators.

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

This is an optimization pass for GlobalISel generic memory operations.

Helper struct that represents how a value is mapped through different register banks.