LLVM: include/llvm/IR/CFG.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19#ifndef LLVM_IR_CFG_H

20#define LLVM_IR_CFG_H

21

28#include

29#include

30#include

31

32namespace llvm {

33

36

37

38

39

40

41template <class Ptr, class USE_iterator>

43public:

49

50protected:

52 USE_iterator It;

53

55

56 while (It.atEnd()) {

58 assert(Inst->isTerminator() && "BasicBlock used in non-terminator");

59 break;

60 }

61

63 }

64 }

65

66public:

72

75

77 assert(It.atEnd() && "pred_iterator out of range!");

79 }

81

83 assert(It.atEnd() && "pred_iterator out of range!");

85 return *this;

86 }

87

89 Self tmp = *this; ++*this; return tmp;

90 }

91

92

93

95 return It.getOperandNo();

96 }

97

98

99

101 return It.getUse();

102 }

103};

104

110

122

123

133

134

135

136

137

138template <class InstructionT, class BlockT>

141 std::random_access_iterator_tag, BlockT, int,

142 BlockT *, BlockT *> {

143public:

148

149private:

150 InstructionT *Inst;

151 int Idx;

153

154 inline bool index_is_valid(int Idx) {

155

156

157 return Idx >= 0 && (Idx == 0 || Idx <= (int)Inst->getNumSuccessors());

158 }

159

160

161 class SuccessorProxy {

162 Self It;

163

164 public:

165 explicit SuccessorProxy(const Self &It) : It(It) {}

166

167 SuccessorProxy(const SuccessorProxy &) = default;

168

169 SuccessorProxy &operator=(SuccessorProxy RHS) {

171 return *this;

172 }

173

175 It.Inst->setSuccessor(It.Idx, RHS);

176 return *this;

177 }

178

179 operator reference() const { return *It; }

180 };

181

182public:

183

184 explicit inline SuccIterator(InstructionT *Inst) : Inst(Inst), Idx(0) {}

185

186 inline SuccIterator(InstructionT *Inst, bool) : Inst(Inst) {

187 if (Inst)

188 Idx = Inst->getNumSuccessors();

189 else

190

191

192

193

194

195

196 Idx = 0;

197 }

198

199

200

202

203 inline bool operator==(const Self &x) const { return Idx == x.Idx; }

204

205 inline BlockT *operator*() const { return Inst->getSuccessor(Idx); }

206

207

209

211 assert(Inst == RHS.Inst && "Cannot compare iterators of different blocks!");

212 return Idx < RHS.Idx;

213 }

214

216 assert(Inst == RHS.Inst && "Cannot compare iterators of different blocks!");

217 return Idx - RHS.Idx;

218 }

219

221 int NewIdx = Idx + RHS;

222 assert(index_is_valid(NewIdx) && "Iterator index out of bound");

223 Idx = NewIdx;

224 return *this;

225 }

226

228

229

230

232 Self TmpIt = *this;

234 return SuccessorProxy(TmpIt);

235 }

236

237

239 assert(Inst && "Source not available, if basic block was malformed");

240 return Inst->getParent();

241 }

242};

243

248

269

294

295

296

297

298

299

300

301

312

314 "GraphTraits getNumber() not detected");

315

327

329 "GraphTraits getNumber() not detected");

330

331

332

333

334

335

346

348 "GraphTraits getNumber() not detected");

349

360

362 "GraphTraits getNumber() not detected");

363

364

365

366

367

368

369

370

371

374

375

377

381

385

387

389 return F->getMaxBlockNumber();

390 }

392 return F->getBlockNumberEpoch();

393 }

394};

398

399

401

405

409

411

413 return F->getMaxBlockNumber();

414 }

416 return F->getBlockNumberEpoch();

417 }

418};

419

420

421

422

423

424

428 return &G.Graph->getEntryBlock();

429 }

430

432 return F->getMaxBlockNumber();

433 }

435 return F->getBlockNumberEpoch();

436 }

437};

441 return &G.Graph->getEntryBlock();

442 }

443

445 return F->getMaxBlockNumber();

446 }

448 return F->getBlockNumberEpoch();

449 }

450};

451

452}

453

454#endif

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

This file defines the little GraphTraits template class that should be specialized by classes that...

LLVM Basic Block Representation.

unsigned getNumber() const

const Instruction * getTerminator() const LLVM_READONLY

Returns the terminator instruction if the block is well formed or null if the block is not well forme...

bool operator==(const Self &x) const

Definition CFG.h:73

Self & operator++()

Definition CFG.h:82

PredIterator(Ptr *bb)

Definition CFG.h:68

void advancePastNonTerminators()

Definition CFG.h:54

Self operator++(int)

Definition CFG.h:88

PredIterator(Ptr *bb, bool)

Definition CFG.h:71

bool operator!=(const Self &x) const

Definition CFG.h:74

Value::user_iterator It

Definition CFG.h:52

Ptr ** pointer

Definition CFG.h:47

std::forward_iterator_tag iterator_category

Definition CFG.h:44

reference operator*() const

Definition CFG.h:76

PredIterator< Ptr, USE_iterator > Self

Definition CFG.h:51

std::ptrdiff_t difference_type

Definition CFG.h:46

pointer * operator->() const

Definition CFG.h:80

unsigned getOperandNo() const

getOperandNo - Return the operand number in the predecessor's terminator of the successor.

Definition CFG.h:94

Ptr * value_type

Definition CFG.h:45

Use & getUse() const

getUse - Return the operand Use in the predecessor's terminator of the successor.

Definition CFG.h:100

Ptr * reference

Definition CFG.h:48

std::ptrdiff_t difference_type

Definition CFG.h:145

BlockT * value_type

Definition CFG.h:144

bool operator==(const Self &x) const

Definition CFG.h:203

SuccIterator(InstructionT *Inst, bool)

Definition CFG.h:186

Self & operator-=(int RHS)

Definition CFG.h:227

BlockT * reference

Definition CFG.h:147

int getSuccessorIndex() const

This is used to interface between code that wants to operate on terminator instructions directly.

Definition CFG.h:201

BlockT * operator->() const

Definition CFG.h:208

bool operator<(const Self &RHS) const

Definition CFG.h:210

BlockT * operator*() const

Definition CFG.h:205

BlockT * getSource()

Get the source BlockT of this iterator.

Definition CFG.h:238

SuccessorProxy operator[](int Offset)

Definition CFG.h:231

BlockT * pointer

Definition CFG.h:146

Self & operator+=(int RHS)

Definition CFG.h:220

int operator-(const Self &RHS) const

Definition CFG.h:215

SuccIterator(InstructionT *Inst)

Definition CFG.h:184

A Use represents the edge between a Value definition and its users.

CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...

A range adaptor for a pair of iterators.

This provides a very simple, boring adaptor for a begin and end iterator into a range type.

This is an optimization pass for GlobalISel generic memory operations.

bool succ_empty(const Instruction *I)

Definition CFG.h:257

iterator_range< pred_iterator > pred_range

Definition CFG.h:108

iterator_range< succ_iterator > succ_range

Definition CFG.h:246

auto pred_end(const MachineBasicBlock *BB)

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

auto successors(const MachineBasicBlock *BB)

constexpr bool GraphHasNodeNumbers

Indicate whether a GraphTraits::getNumber() is supported.

iterator_range< const_pred_iterator > const_pred_range

Definition CFG.h:109

auto pred_size(const MachineBasicBlock *BB)

PredIterator< const BasicBlock, Value::const_user_iterator > const_pred_iterator

Definition CFG.h:106

auto succ_size(const MachineBasicBlock *BB)

RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)

RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)

PredIterator< BasicBlock, Value::user_iterator > pred_iterator

Definition CFG.h:105

auto pred_begin(const MachineBasicBlock *BB)

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

auto predecessors(const MachineBasicBlock *BB)

SuccIterator< Instruction, BasicBlock > succ_iterator

Definition CFG.h:244

bool pred_empty(const BasicBlock *BB)

Definition CFG.h:119

SuccIterator< const Instruction, const BasicBlock > const_succ_iterator

Definition CFG.h:245

iterator_range< const_succ_iterator > const_succ_range

Definition CFG.h:247

BasicBlock * NodeRef

Definition CFG.h:303

static NodeRef getEntryNode(BasicBlock *BB)

Definition CFG.h:306

succ_iterator ChildIteratorType

Definition CFG.h:304

static ChildIteratorType child_begin(NodeRef N)

Definition CFG.h:307

static unsigned getNumber(const BasicBlock *BB)

Definition CFG.h:310

static ChildIteratorType child_end(NodeRef N)

Definition CFG.h:308

static unsigned getMaxNumber(const Function *F)

Definition CFG.h:388

static nodes_iterator nodes_begin(Function *F)

Definition CFG.h:378

static unsigned getNumberEpoch(const Function *F)

Definition CFG.h:391

static nodes_iterator nodes_end(Function *F)

Definition CFG.h:382

static size_t size(Function *F)

Definition CFG.h:386

static NodeRef getEntryNode(Function *F)

Definition CFG.h:373

pointer_iterator< Function::iterator > nodes_iterator

Definition CFG.h:376

static ChildIteratorType child_begin(NodeRef N)

Definition CFG.h:341

static unsigned getNumber(const BasicBlock *BB)

Definition CFG.h:344

BasicBlock * NodeRef

Definition CFG.h:337

static ChildIteratorType child_end(NodeRef N)

Definition CFG.h:342

pred_iterator ChildIteratorType

Definition CFG.h:338

static NodeRef getEntryNode(Inverse< BasicBlock * > G)

Definition CFG.h:340

static unsigned getNumberEpoch(const Function *F)

Definition CFG.h:434

static unsigned getMaxNumber(const Function *F)

Definition CFG.h:431

static NodeRef getEntryNode(Inverse< Function * > G)

Definition CFG.h:427

static ChildIteratorType child_end(NodeRef N)

Definition CFG.h:356

const_pred_iterator ChildIteratorType

Definition CFG.h:352

const BasicBlock * NodeRef

Definition CFG.h:351

static NodeRef getEntryNode(Inverse< const BasicBlock * > G)

Definition CFG.h:354

static ChildIteratorType child_begin(NodeRef N)

Definition CFG.h:355

static unsigned getNumber(const BasicBlock *BB)

Definition CFG.h:358

static unsigned getMaxNumber(const Function *F)

Definition CFG.h:444

static NodeRef getEntryNode(Inverse< const Function * > G)

Definition CFG.h:440

static unsigned getNumberEpoch(const Function *F)

Definition CFG.h:447

const BasicBlock * NodeRef

Definition CFG.h:317

static ChildIteratorType child_begin(NodeRef N)

Definition CFG.h:322

static unsigned getNumber(const BasicBlock *BB)

Definition CFG.h:325

static NodeRef getEntryNode(const BasicBlock *BB)

Definition CFG.h:320

const_succ_iterator ChildIteratorType

Definition CFG.h:318

static ChildIteratorType child_end(NodeRef N)

Definition CFG.h:323

static size_t size(const Function *F)

Definition CFG.h:410

static nodes_iterator nodes_begin(const Function *F)

Definition CFG.h:402

static NodeRef getEntryNode(const Function *F)

Definition CFG.h:397

static unsigned getNumberEpoch(const Function *F)

Definition CFG.h:415

static unsigned getMaxNumber(const Function *F)

Definition CFG.h:412

static nodes_iterator nodes_end(const Function *F)

Definition CFG.h:406

pointer_iterator< Function::const_iterator > nodes_iterator

Definition CFG.h:400

typename Function *::UnknownGraphTypeError NodeRef