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

1

2

3

4

5

6

7

8

9

10

11

12

13 #ifndef MLIR_IR_REGION_H

14 #define MLIR_IR_REGION_H

15

17

18 namespace mlir {

19 class TypeRange;

20 template

21 class ValueTypeRange;

22 class IRMapping;

23

24

25

27 public:

31

32

33

35

36

37

39

40

41

42

43

48 return back();

49 }

50

51

52 using iterator = BlockListType::iterator;

54

59

60 bool empty() { return blocks.empty(); }

63

66

67

69

70

72 return &Region::blocks;

73 }

74

75

76

77

78

79

83 }

84

85

87

94

96

97

100 }

101

102

103

104

107 }

108

109

110

111

114

115

118 }

119

120

122

125

126

127

128

129

130

131

133 : public llvm::iterator_facade_base<OpIterator, std::forward_iterator_tag,

134 Operation> {

135 public:

136

137

139

140 using llvm::iterator_facade_base<OpIterator, std::forward_iterator_tag,

145

146

148 return operation == rhs.operation;

149 }

151

152 private:

153 void skipOverBlocksWithNoOps();

154

155

157

159

161 };

162

163

164

165 template

167

168

169

173

174

175

176 template

179 }

180 template

183 }

184 template

186 auto endIt = op_end();

189 }

190

191

192

193

194

195

196

198

199

201

202

203

204 template

206 auto *region = this;

207 do {

208 if (auto parent = dyn_cast_or_null(region->container))

209 return parent;

210 } while ((region = region->getParentRegion()));

211 return ParentT();

212 }

213

214

216

217

219

220

221

224 }

225

226

227

228

229

230

231

232

233

234

236

238

239

240

243 blocks.clear();

244 blocks.splice(blocks.end(), other.getBlocks());

245 }

246

247

248

249

251

252

253

254

256

257

258

259

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

285 RetT walk(FnT &&callback) {

286 if constexpr (std::is_same<ArgT, Region *>::value &&

288

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

290 callback(this);

291 } else {

292 RetT result = callback(this);

293 if (result.wasSkipped())

295 if (result.wasInterrupted())

297 }

298 }

299

300

301 for (auto &block : *this) {

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

303 block.walk<Order, Iterator>(callback);

304 } else {

305 if (block.walk<Order, Iterator>(callback).wasInterrupted())

307 }

308 }

309

310 if constexpr (std::is_same<ArgT, Region *>::value &&

312

313 return callback(this);

314 }

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

317 }

318

319

320

321

322

323

324

325

326

327 void viewGraph(const Twine &regionName);

329

330 private:

332

333

335 };

336

337

338

339

340

341

344 RegionRange,

345 PointerUnion<Region *, const std::unique_ptr *, Region **>,

346 Region *, Region *, Region *> {

347

348

349

352

353 public:

354 using RangeBaseT::RangeBaseT;

355

357

358 template <typename Arg, typename = std::enable_if_t<std::is_constructible<

362 }

363 template

365 Arg &&arg LLVM_LIFETIME_BOUND,

366 std::enable_if_t<std::is_constructible<ArrayRef<Region *>, Arg>::value>

367 * = nullptr)

371

372 private:

373

374 static OwnerT offset_base(const OwnerT &owner, ptrdiff_t index);

375

376 static Region *dereference_iterator(const OwnerT &owner, ptrdiff_t index);

377

378

379 friend RangeBaseT;

380 };

381

382 }

383

384 #endif

This class represents an argument of a Block.

Block represents an ordered list of Operations.

OpListType::iterator iterator

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

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

BlockArgument addArgument(Type type, Location loc)

Add one value to the argument list.

BlockArgListType getArguments()

void eraseArgument(unsigned index)

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

This is a utility class for mapping one set of IR entities to another.

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

MLIRContext is the top-level object for a collection of MLIR operations.

Operation is the basic unit of execution within MLIR.

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

RegionRange(Arg &&arg LLVM_LIFETIME_BOUND)

RegionRange(Arg &&arg LLVM_LIFETIME_BOUND, std::enable_if_t< std::is_constructible< ArrayRef< Region * >, Arg >::value > *=nullptr)

RegionRange(MutableArrayRef< Region > regions=std::nullopt)

This class provides iteration over the held operations of blocks directly within a region.

Operation & operator*() const

OpIterator(Region *region, bool end=false)

Initialize OpIterator for a region, specify end to return the iterator to last operation.

bool operator==(const OpIterator &rhs) const

Compare this iterator with another.

Operation * operator->() const

OpIterator & operator++()

bool operator!=(const OpIterator &rhs) const

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

iterator_range< OpIterator > getOps()

llvm::iplist< Block > BlockListType

Region * getParentRegion()

Return the region containing this region or nullptr if the region is attached to a top-level operatio...

reverse_args_iterator args_rend()

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

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

void eraseArgument(unsigned index)

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

BlockArgListType getArguments()

op_iterator< OpT > op_begin()

Return iterators that walk operations of type 'T' nested directly within this region.

args_iterator args_begin()

iterator_range< op_iterator< OpT > > getOps()

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

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

Operation * findAncestorOpInRegion(Operation &op)

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

unsigned getRegionNumber()

Return the number of this region in the parent operation.

OpIterator op_begin()

Return iterators that walk the operations nested directly within this region.

void dropAllReferences()

Drop all operand uses from operations within this region, which is an essential step in breaking cycl...

bool isAncestor(Region *other)

Return true if this region is ancestor of the other region.

void push_back(Block *block)

BlockArgListType::iterator args_iterator

BlockArgument insertArgument(unsigned index, Type type, Location loc)

Add one value to the argument list at the specified position.

static BlockListType Region::* getSublistAccess(Block *)

getSublistAccess() - Returns pointer to member of region.

Operation * getParentOp()

Return the parent operation this region is attached to.

op_iterator< OpT > op_end()

BlockListType::reverse_iterator reverse_iterator

void cloneInto(Region *dest, IRMapping &mapper)

Clone the internal blocks from this region into dest.

bool isProperAncestor(Region *other)

Return true if this region is a proper ancestor of the other region.

unsigned getNumArguments()

BlockListType & getBlocks()

Location getLoc()

Return a location for this region.

ValueTypeRange< BlockArgListType > getArgumentTypes()

Returns the argument types of the first block within the region.

BlockArgument getArgument(unsigned i)

MutableArrayRef< BlockArgument > BlockArgListType

MLIRContext * getContext()

Return the context this region is inserted in.

reverse_args_iterator args_rbegin()

BlockListType::iterator iterator

void push_front(Block *block)

void takeBody(Region &other)

Takes body of another region (that region will have no body after this operation completes).

reverse_iterator rbegin()

ParentT getParentOfType()

Find the first parent operation of the given type, or nullptr if there is no ancestor operation.

Block * findAncestorBlockInRegion(Block &block)

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

BlockArgListType::reverse_iterator reverse_args_iterator

BlockArgument addArgument(Type type, Location loc)

Add one value to the argument list.

bool hasOneBlock()

Return true if this region has exactly one block.

RetT walk(FnT &&callback)

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

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.

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

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

decltype(first_argument_type(std::declval< T >())) first_argument

Type definition of the first argument to the given callable 'T'.

Include the generated interface declarations.

WalkOrder

Traversal order for region, block and operation walk utilities.

This iterator enumerates the elements in "forward" order.