LLVM: include/llvm/Transforms/Utils/BasicBlockUtils.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H

15#define LLVM_TRANSFORMS_UTILS_BASICBLOCKUTILS_H

16

17

18

23#include

24

25namespace llvm {

26class BranchInst;

27class LandingPadInst;

28class Loop;

29class PHINode;

30template class SmallPtrSetImpl;

31class BlockFrequencyInfo;

32class BranchProbabilityInfo;

33class DomTreeUpdater;

35class IRBuilderBase;

36class LoopInfo;

37class MDNode;

38class MemoryDependenceResults;

39class MemorySSAUpdater;

40class PostDominatorTree;

41class ReturnInst;

42class TargetLibraryInfo;

44

45

46

47

48

50 SmallVectorImplDominatorTree::UpdateType *Updates,

51 bool KeepOneInputPHIs = false);

52

53

54void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU = nullptr,

55 bool KeepOneInputPHIs = false);

56

57

58

59

60

61

62

64 DomTreeUpdater *DTU = nullptr,

65 bool KeepOneInputPHIs = false);

66

67

68

69

71 bool KeepOneInputPHIs = false);

72

73

74

75

76

78 MemoryDependenceResults *MemDep = nullptr);

79

80

81

82

83

84bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI = nullptr,

85 MemorySSAUpdater *MSSAU = nullptr);

86

87

88

89

90

91

92

93

94

95

97 LoopInfo *LI = nullptr,

98 MemorySSAUpdater *MSSAU = nullptr,

99 MemoryDependenceResults *MemDep = nullptr,

100 bool PredecessorWithTwoSuccessors = false,

101 DominatorTree *DT = nullptr);

102

103

104

105

106

107

108

109

111 SmallPtrSetImpl<BasicBlock *> &MergeBlocks, Loop *L = nullptr,

112 DomTreeUpdater *DTU = nullptr, LoopInfo *LI = nullptr);

113

114

115

116

118

119

120

122

123

124

125

126

128 Instruction *I);

129

130

131

133

134

135

136

137

138

140

141

142

143

144

154

155

156

158

164

167 return *this;

168 }

169

172 return *this;

173 }

174

177 return *this;

178 }

179

182 return *this;

183 }

184

187 return *this;

188 }

189};

190

191

192

193

194

196 BasicBlock *SplitBB, BasicBlock *DestBB);

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

215 const CriticalEdgeSplittingOptions &Options =

216 CriticalEdgeSplittingOptions(),

217 const Twine &BBName = "");

218

219

220

222 const CriticalEdgeSplittingOptions &Options =

223 CriticalEdgeSplittingOptions(),

224 const Twine &BBName = "");

225

226

227

228

229inline BasicBlock *

234 unsigned i = 0;

235 while (true) {

239 ++i;

240 }

241}

242

243

244

246 const CriticalEdgeSplittingOptions &Options =

247 CriticalEdgeSplittingOptions());

248

249

250

251BasicBlock *SplitEdge(BasicBlock *From, BasicBlock *To,

252 DominatorTree *DT = nullptr, LoopInfo *LI = nullptr,

253 MemorySSAUpdater *MSSAU = nullptr,

254 const Twine &BBName = "");

255

256

258

259

260

261void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred,

262 BasicBlock *NewPred, PHINode *Until = nullptr);

263

264

265

266BasicBlock *ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ,

267 LandingPadInst *OriginalPad = nullptr,

268 PHINode *LandingPadReplacement = nullptr,

269 const CriticalEdgeSplittingOptions &Options =

270 CriticalEdgeSplittingOptions(),

271 const Twine &BBName = "");

272

273

274

275

276

277

278

279

280

281

282

284 LoopInfo *LI = nullptr,

285 MemorySSAUpdater *MSSAU = nullptr,

286 const Twine &BBName = "", bool Before = false);

290 const Twine &BBName = "", bool Before = false) {

292}

293

294

295

296

297

298

299

300

301

303 DomTreeUpdater *DTU = nullptr, LoopInfo *LI = nullptr,

304 MemorySSAUpdater *MSSAU = nullptr,

305 const Twine &BBName = "", bool Before = false);

309 const Twine &BBName = "", bool Before = false) {

311}

312

313

314

315

316

317

319 DomTreeUpdater *DTU, LoopInfo *LI,

320 MemorySSAUpdater *MSSAU, const Twine &BBName = "");

325}

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

344 const char *Suffix, DominatorTree *DT,

345 LoopInfo *LI = nullptr,

346 MemorySSAUpdater *MSSAU = nullptr,

347 bool PreserveLCSSA = false);

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

364 const char *Suffix,

365 DomTreeUpdater *DTU = nullptr,

366 LoopInfo *LI = nullptr,

367 MemorySSAUpdater *MSSAU = nullptr,

368 bool PreserveLCSSA = false);

369

370

371

372

373

374

375

376

377

378

379

380

382 BasicBlock *OrigBB, ArrayRef<BasicBlock *> Preds, const char *Suffix,

383 const char *Suffix2, SmallVectorImpl<BasicBlock *> &NewBBs,

384 DomTreeUpdater *DTU = nullptr, LoopInfo *LI = nullptr,

385 MemorySSAUpdater *MSSAU = nullptr, bool PreserveLCSSA = false);

386

387

388

389

390

392 BasicBlock *Pred,

393 DomTreeUpdater *DTU = nullptr);

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

417 bool Unreachable,

418 MDNode *BranchWeights = nullptr,

419 DomTreeUpdater *DTU = nullptr,

420 LoopInfo *LI = nullptr,

421 BasicBlock *ThenBlock = nullptr);

422

424 bool Unreachable,

425 MDNode *BranchWeights = nullptr,

430 Unreachable, BranchWeights, DTU, LI,

431 ThenBlock);

432}

433

434

435

437 bool Unreachable,

438 MDNode *BranchWeights = nullptr,

439 DomTreeUpdater *DTU = nullptr,

440 LoopInfo *LI = nullptr,

441 BasicBlock *ElseBlock = nullptr);

442

444 bool Unreachable,

445 MDNode *BranchWeights = nullptr,

450 Unreachable, BranchWeights, DTU, LI,

451 ElseBlock);

452}

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

472 Instruction **ThenTerm,

473 Instruction **ElseTerm,

474 MDNode *BranchWeights = nullptr,

475 DomTreeUpdater *DTU = nullptr,

476 LoopInfo *LI = nullptr);

477

481 MDNode *BranchWeights = nullptr,

484{

486 ElseTerm, BranchWeights, DTU, LI);

487}

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

518 BasicBlock **ThenBlock,

519 BasicBlock **ElseBlock,

520 bool UnreachableThen = false,

521 bool UnreachableElse = false,

522 MDNode *BranchWeights = nullptr,

523 DomTreeUpdater *DTU = nullptr,

524 LoopInfo *LI = nullptr);

525

529 bool UnreachableThen = false,

530 bool UnreachableElse = false,

531 MDNode *BranchWeights = nullptr,

535 ElseBlock, UnreachableThen, UnreachableElse, BranchWeights, DTU, LI);

536}

537

538

539

540

541

542std::pair<Instruction*, Value*>

544

545

546

547

548

549

550

551

552

554 Instruction *InsertBefore,

555 std::function<void(IRBuilderBase&, Value*)> Func);

556

557

558

559

560

561

562

563

564

566 Value *End, Instruction *InsertBefore,

567 std::function<void(IRBuilderBase &, Value *)> Func);

568

569

570

571

572

573

574

575

576

577BranchInst *GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,

578 BasicBlock *&IfFalse);

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

602 BranchProbabilityInfo *BPI = nullptr,

603 BlockFrequencyInfo *BFI = nullptr);

604

605

606

607void InvertBranch(BranchInst *PBI, IRBuilderBase &Builder);

608

609

610

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

630 const BasicBlock &Dest);

631}

632

633#endif

BlockVerifier::State From

static cl::opt< bool > SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false), cl::Hidden, cl::desc("Split all critical edges during " "PHI elimination"))

const SmallVectorImpl< MachineOperand > & Cond

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file implements a set that has insertion order iteration characteristics.

LLVM Basic Block Representation.

InstListType::iterator iterator

Instruction iterators...

Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.

unsigned getNumSuccessors() const LLVM_READONLY

Return the number of successors that this instruction has.

BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY

Return the specified successor. This instruction must be a terminator.

PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

LLVM Value Representation.

self_iterator getIterator()

This is an optimization pass for GlobalISel generic memory operations.

void ReplaceInstWithInst(BasicBlock *BB, BasicBlock::iterator &BI, Instruction *I)

Replace the instruction specified by BI with the instruction specified by I.

bool RemoveRedundantDbgInstrs(BasicBlock *BB)

Try to remove redundant dbg.value instructions from given basic block.

bool IsBlockFollowedByDeoptOrUnreachable(const BasicBlock *BB)

Check if we can prove that all paths starting from this block converge to a block that either has a @...

BranchInst * GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue, BasicBlock *&IfFalse)

Check whether BB is the merge point of a if-region.

void detachDeadBlocks(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< DominatorTree::UpdateType > *Updates, bool KeepOneInputPHIs=false)

Replace contents of every block in BBs with single unreachable instruction.

bool hasOnlySimpleTerminator(const Function &F)

ReturnInst * FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, BasicBlock *Pred, DomTreeUpdater *DTU=nullptr)

This method duplicates the specified return instruction into a predecessor which ends in an unconditi...

BasicBlock * splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt, DomTreeUpdater *DTU, LoopInfo *LI, MemorySSAUpdater *MSSAU, const Twine &BBName="")

Split the specified block at the specified instruction SplitPt.

Instruction * SplitBlockAndInsertIfElse(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ElseBlock=nullptr)

Similar to SplitBlockAndInsertIfThen, but the inserted block is on the false path of the branch.

void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)

Delete the specified block, which must have no predecessors.

void ReplaceInstWithValue(BasicBlock::iterator &BI, Value *V)

Replace all uses of an instruction (specified by BI) with a value, then remove and delete the origina...

BasicBlock * SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")

If it is known that an edge is critical, SplitKnownCriticalEdge can be called directly,...

bool SplitIndirectBrCriticalEdges(Function &F, bool IgnoreBlocksWithoutPHI, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr)

bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)

Examine each PHI in the given block and delete it if it is dead.

void InvertBranch(BranchInst *PBI, IRBuilderBase &Builder)

bool EliminateUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)

Delete all basic blocks from F that are not reachable from its entry node.

bool MergeBlockSuccessorsIntoGivenBlocks(SmallPtrSetImpl< BasicBlock * > &MergeBlocks, Loop *L=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)

Merge block(s) sucessors, if possible.

void SplitBlockAndInsertIfThenElse(Value *Cond, BasicBlock::iterator SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)

SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...

void SplitBlockAndInsertForEachLane(ElementCount EC, Type *IndexTy, Instruction *InsertBefore, std::function< void(IRBuilderBase &, Value *)> Func)

Utility function for performing a given action on each lane of a vector with EC elements.

BasicBlock * ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ, LandingPadInst *OriginalPad=nullptr, PHINode *LandingPadReplacement=nullptr, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")

Split the edge connect the specficed blocks in the case that Succ is an Exception Handling Block.

void SplitLandingPadPredecessors(BasicBlock *OrigBB, ArrayRef< BasicBlock * > Preds, const char *Suffix, const char *Suffix2, SmallVectorImpl< BasicBlock * > &NewBBs, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)

This method transforms the landing pad, OrigBB, by introducing two new basic blocks into the function...

BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)

This method introduces at least one new basic block into the function and moves some of the predecess...

void createPHIsForSplitLoopExit(ArrayRef< BasicBlock * > Preds, BasicBlock *SplitBB, BasicBlock *DestBB)

When a loop exit edge is split, LCSSA form may require new PHIs in the new exit block.

bool MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, MemoryDependenceResults *MemDep=nullptr, bool PredecessorWithTwoSuccessors=false, DominatorTree *DT=nullptr)

Attempts to merge a block into its predecessor, if possible.

std::pair< Instruction *, Value * > SplitBlockAndInsertSimpleForLoop(Value *End, Instruction *SplitBefore)

Insert a for (int i = 0; i < End; i++) loop structure (with the exception that End is assumed > 0,...

BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")

If this edge is a critical edge, insert a new node to split the critical edge.

bool FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)

We know that BB has one predecessor.

void updatePhiNodes(BasicBlock *DestBB, BasicBlock *OldPred, BasicBlock *NewPred, PHINode *Until=nullptr)

Replaces all uses of OldPred with the NewPred block in all PHINodes in a block.

bool isPresplitCoroSuspendExitEdge(const BasicBlock &Src, const BasicBlock &Dest)

BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)

Split the specified block at the specified instruction.

Instruction * SplitBlockAndInsertIfThen(Value *Cond, BasicBlock::iterator SplitBefore, bool Unreachable, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr, BasicBlock *ThenBlock=nullptr)

Split the containing block at the specified instruction - everything before SplitBefore stays in the ...

void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)

Delete the specified blocks from BB.

BasicBlock * SplitEdge(BasicBlock *From, BasicBlock *To, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")

Split the edge connecting the specified blocks, and return the newly created basic block between From...

void setUnwindEdgeTo(Instruction *TI, BasicBlock *Succ)

Sets the unwind edge of an instruction to a particular successor.

Option class for critical edge splitting.

CriticalEdgeSplittingOptions(DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, PostDominatorTree *PDT=nullptr)

CriticalEdgeSplittingOptions & setMergeIdenticalEdges()

bool IgnoreUnreachableDests

CriticalEdgeSplittingOptions & setKeepOneInputPHIs()

bool PreserveLoopSimplify

SplitCriticalEdge is guaranteed to preserve loop-simplify form if LI is provided.

CriticalEdgeSplittingOptions & unsetPreserveLoopSimplify()

CriticalEdgeSplittingOptions & setPreserveLCSSA()

CriticalEdgeSplittingOptions & setIgnoreUnreachableDests()