MLIR: include/mlir/IR/Block.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13 #ifndef MLIR_IR_BLOCK_H

14 #define MLIR_IR_BLOCK_H

15

18

19 #include "llvm/ADT/SmallPtrSet.h"

20

21 namespace llvm {

22 class BitVector;

23 class raw_ostream;

24 }

25

26 namespace mlir {

27 class TypeRange;

28 template

29 class ValueTypeRange;

30

31

33 public llvm::ilist_node_with_parent<Block, Region> {

34 public:

35 explicit Block() = default;

37

39

41

42

43

45 operations.pop_back();

46 }

47

48

49

50

51

52

54

55

57

58

60

61

62

64

65

66

68

69

70

72

73

74

76

77

79

80

81

82

83

84

86

88

89

91

98

99 bool args_empty() { return arguments.empty(); }

100

101

103

104

105

106

108

109

110

113

114

116

117

119

121

122

124

125

127

130

131

132

133

134

135

138

139

142

147

148 bool empty() { return operations.empty(); }

151

154

155

156

157

158

159

161

162

163

164

166

167

168

170

171

172

174

175

177

178

179

181

182

184

185

186

187 template

189

190

191

192 template

194 auto endIt = end();

197 }

198 template

201 }

202 template

205 }

206

207

208

212 auto endIt = --end();

213 return {begin(), endIt};

214 }

215

216

217

218

219

220

221

223

224

226

227

228

229

230

231

235 }

239 }

240

241

243

244

246

247

248

249

250

251

252

254

255

256

258

259

262

263

268

269

270

271

272

273

274

275

276

277

278

279

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

302 typename Iterator = ForwardIterator, typename FnT,

303 typename ArgT = detail::first_argument,

304 typename RetT = detail::walkResultType>

305 RetT walk(FnT &&callback) {

306 if constexpr (std::is_same<ArgT, Block *>::value &&

308

309 if constexpr (std::is_same<RetT, void>::value) {

310 callback(this);

311 } else {

312 RetT result = callback(this);

313 if (result.wasSkipped())

315 if (result.wasInterrupted())

317 }

318 }

319

320

321 if constexpr (std::is_same<RetT, void>::value) {

322 walk<Order, Iterator>(begin(), end(), std::forward(callback));

323 } else {

324 if (walk<Order, Iterator>(begin(), end(), std::forward(callback))

325 .wasInterrupted())

327 }

328

329 if constexpr (std::is_same<ArgT, Block *>::value &&

331

332 return callback(this);

333 }

334 if constexpr (!std::is_same<RetT, void>::value)

336 }

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

358 for (auto &op : llvm::make_early_inc_range(llvm::make_range(begin, end))) {

359 if constexpr (std::is_same<RetT, WalkResult>::value) {

360 if (detail::walk<Order, Iterator>(&op, callback).wasInterrupted())

362 } else {

363 detail::walk<Order, Iterator>(&op, callback);

364 }

365 }

366 if constexpr (std::is_same<RetT, WalkResult>::value)

368 }

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

387 }

388

389

391 return &Block::operations;

392 }

393

394 void print(raw_ostream &os);

397

398

399

400

403

404 private:

405

406

407 llvm::PointerIntPair<Region *, 1, bool> parentValidOpOrderPair;

408

409

411

412

413 std::vector arguments;

414

416 void operator=(Block &) = delete;

417

418 friend struct llvm::ilist_traits<Block>;

419 };

420

422 }

423

424 namespace llvm {

425 template <>

430 }

434 }

436 return hash_value(iter.getNodePtr());

437 }

439 return lhs == rhs;

440 }

441 };

442

443 }

444

445 #endif

This class provides management for the lifetime of the state used when printing the IR.

This class represents an argument of a Block.

A block operand represents an operand that holds a reference to a Block, e.g.

Block represents an ordered list of Operations.

void recomputeOpOrder()

Recomputes the ordering of child operations within the block.

MutableArrayRef< BlockArgument > BlockArgListType

OpListType::iterator iterator

Block * splitBlock(Operation *splitBeforeOp)

Operation * findAncestorOpInBlock(Operation &op)

Returns 'op' if 'op' lies in this block, or otherwise finds the ancestor operation of 'op' that lies ...

ValueTypeRange< BlockArgListType > getArgumentTypes()

Return a range containing the types of the arguments for this block.

unsigned getNumSuccessors()

void push_front(Operation *op)

SuccessorRange::iterator succ_iterator

BlockArgument getArgument(unsigned i)

bool hasNoSuccessors()

Returns true if this blocks has no successors.

unsigned getNumArguments()

void erase()

Unlink this Block from its parent region and delete it.

BlockArgument insertArgument(args_iterator it, Type type, Location loc)

Insert one value to the position in the argument list indicated by the given iterator.

iterator_range< args_iterator > addArguments(TypeRange types, ArrayRef< Location > locs)

Add one argument to the argument list for each type specified in the list.

Block * splitBlock(iterator splitBefore)

Split the block into two blocks before the specified operation or iterator.

Region * getParent() const

Provide a 'getParent' method for ilist_node_with_parent methods.

bool isOpOrderValid()

Returns true if the ordering of the child operations is valid, false otherwise.

op_iterator< OpT > op_begin()

BlockArgListType::reverse_iterator reverse_args_iterator

pred_iterator pred_begin()

void dropAllDefinedValueUses()

This drops all uses of values defined in this block or in the blocks of nested regions wherever the u...

bool verifyOpOrder()

Verifies the current ordering of child operations matches the validOpOrder flag.

SuccessorRange getSuccessors()

void invalidateOpOrder()

Invalidates the current ordering of operations.

Block * getSinglePredecessor()

If this block has exactly one predecessor, return it.

void printAsOperand(raw_ostream &os, bool printType=true)

Print out the name of the block without printing its body.

reverse_args_iterator args_rend()

RetT walk(FnT &&callback)

Walk all nested operations, blocks (including this block) or regions, depending on the type of callba...

void insertAfter(Block *block)

Insert this block (which must not already be in a region) right after the specified block.

Operation * getTerminator()

Get the terminator operation of this block.

succ_iterator succ_begin()

iterator_range< pred_iterator > getPredecessors()

BlockArgument addArgument(Type type, Location loc)

Add one value to the argument list.

RetT walk(Block::iterator begin, Block::iterator end, FnT &&callback)

Walk all nested operations, blocks (excluding this block) or regions, depending on the type of callba...

void eraseArguments(unsigned start, unsigned num)

Erases 'num' arguments from the index 'start'.

OpListType & getOperations()

void print(raw_ostream &os)

bool mightHaveTerminator()

Check whether this block might have a terminator.

BlockArgListType getArguments()

PredecessorIterator pred_iterator

bool isReachable(Block *other, SmallPtrSet< Block *, 16 > &&except={})

Return "true" if there is a path from this block to the given block (according to the successors rela...

Block * getUniquePredecessor()

If this block has a unique predecessor, i.e., all incoming edges originate from one block,...

op_iterator< OpT > op_end()

void eraseArgument(unsigned index)

Erase the argument at 'index' and remove it from the argument list.

iterator_range< op_iterator< OpT > > getOps()

Return an iterator range over the operations within this block that are of 'OpT'.

Block * getSuccessor(unsigned i)

args_iterator args_begin()

bool isEntryBlock()

Return if this block is the entry block in the parent region.

void dropAllReferences()

This drops all operand uses from operations within this block, which is an essential step in breaking...

void insertBefore(Block *block)

Insert this block (which must not already be in a region) right before the specified block.

void moveBefore(Block *block)

Unlink this block from its current region and insert it right before the specific block.

void push_back(Operation *op)

reverse_args_iterator args_rbegin()

bool hasNoPredecessors()

Return true if this block has no predecessors.

static OpListType Block::* getSublistAccess(Operation *)

Returns pointer to member of operation list.

iterator_range< iterator > without_terminator()

Return an iterator range over the operation within this block excluding the terminator operation at t...

Operation * getParentOp()

Returns the closest surrounding operation that contains this block.

BlockArgListType::iterator args_iterator

reverse_iterator rbegin()

OpListType::reverse_iterator reverse_iterator

llvm::iplist< Operation > OpListType

This is the list of operations in the block.

This class represents a single IR object that contains a use list.

BlockOperand * getFirstUse() const

Return the first operand that is using this value, for use by custom use/def iterators.

This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...

Operation is the basic unit of execution within MLIR.

Implement a predecessor iterator for blocks.

This class contains a list of basic blocks and a link to the parent operation it is attached to.

This class implements the successor iterators for Block.

This class provides an abstraction over the various different ranges of value types.

Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...

This class implements iteration on the types of a given range of values.

static WalkResult advance()

static WalkResult interrupt()

A utility iterator that filters out operations that are not 'OpT'.

This class provides iteration over the held operations of a block for a specific operation type.

The OpAsmOpInterface, see OpAsmInterface.td for more details.

void printType(Type type, AsmPrinter &printer)

Prints an LLVM Dialect type.

decltype(walk(nullptr, std::declval< FnT >())) walkResultType

Utility to provide the return type of a templated walk method.

llvm::hash_code hash_value(const StructType::MemberDecorationInfo &memberDecorationInfo)

Include the generated interface declarations.

WalkOrder

Traversal order for region, block and operation walk utilities.

raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)

static mlir::Block::iterator getEmptyKey()

static bool isEqual(mlir::Block::iterator lhs, mlir::Block::iterator rhs)

static mlir::Block::iterator getTombstoneKey()

static unsigned getHashValue(mlir::Block::iterator iter)

This iterator enumerates the elements in "forward" order.