MLIR: lib/IR/Region.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

12 using namespace mlir;

13

15

17

18

20 }

21

22

23

25 assert(container && "region is not attached to a container");

27 }

28

29

30

32 assert(container && "region is not attached to a container");

33 return container->getLoc();

34 }

35

38 }

39

43 }

44

46 assert(container && "region is not attached to a container");

48 }

49

51 if (this == other)

52 return false;

53

55 if (this == other)

56 return true;

57 }

58 return false;

59 }

60

61

63

64

66 }

67

68

69

71 assert(dest && "expected valid region to clone into");

73 }

74

75

78 assert(dest && "expected valid region to clone into");

79 assert(this != dest && "cannot clone region into itself");

80

81

83 return;

84

85

86

87

88

89

90

91

92

93

94

95

96

97 for (Block &block : *this) {

99 mapper.map(&block, newBlock);

100

101

102

103

106 mapper.map(arg, newBlock->addArgument(arg.getType(), arg.getLoc()));

107

108 dest->getBlocks().insert(destPos, newBlock);

109 }

110

111 auto newBlocksRange =

113

114

115

116

117

118

119

120 auto cloneOptions =

122 for (auto zippedBlocks : llvm::zip(*this, newBlocksRange)) {

123 Block &sourceBlock = std::get<0>(zippedBlocks);

124 Block &clonedBlock = std::get<1>(zippedBlocks);

125

126 for (Operation &op : sourceBlock)

127 clonedBlock.push_back(op.clone(mapper, cloneOptions));

128 }

129

130

131

133 for (auto zippedBlocks : llvm::zip(*this, newBlocksRange)) {

134 for (auto ops :

135 llvm::zip(std::get<0>(zippedBlocks), std::get<1>(zippedBlocks))) {

136 Operation &source = std::get<0>(ops);

138

140 llvm::transform(

142 [&](Value operand) { return mapper.lookupOrDefault(operand); });

144

146 std::get<0>(regions).cloneInto(&std::get<1>(regions), mapper);

147 }

148 }

149 }

150

151

152

153

155 Block *currBlock = █

156 while (currBlock->getParent() != this) {

158 if (!parentOp || !parentOp->getBlock())

159 return nullptr;

160 currBlock = parentOp->getBlock();

161 }

162 return currBlock;

163 }

164

165

166

167

171 if (opRegion == this)

172 return curOp;

173

175 if (!curOp)

176 return nullptr;

177 }

178 return nullptr;

179 }

180

182 for (Block &b : *this)

184 }

185

186 Region *llvm::ilist_traits<::mlir::Block>::getParentRegion() {

187 size_t offset(

189 iplist *anchor(static_cast<iplist *>(this));

190 return reinterpret_cast<Region *>(reinterpret_cast<char *>(anchor) - offset);

191 }

192

193

194

196 assert(!block->getParent() && "already in a region!");

197 block->parentValidOpOrderPair.setPointer(getParentRegion());

198 }

199

200

201

203 assert(block->getParent() && "not already in a region!");

204 block->parentValidOpOrderPair.setPointer(nullptr);

205 }

206

207

208

211

212

213 auto *curParent = getParentRegion();

214 if (curParent == otherList.getParentRegion())

215 return;

216

217

218 for (; first != last; ++first)

219 first->parentValidOpOrderPair.setPointer(curParent);

220 }

221

222

223

224

225

227 : region(region), block(end ? region->end() : region->begin()) {

228 if (!region->empty())

229 skipOverBlocksWithNoOps();

230 }

231

233

234

235 if (operation != block->end())

236 ++operation;

237 if (operation == block->end()) {

238 ++block;

239 skipOverBlocksWithNoOps();

240 }

241 return *this;

242 }

243

244 void Region::OpIterator::skipOverBlocksWithNoOps() {

245 while (block != region->end() && block->empty())

246 ++block;

247

248

249

250 if (block == region->end())

251 operation = {};

252 else

253 operation = block->begin();

254 }

255

256

257

258

259

261 : RegionRange(regions.data(), regions.size()) {}

263 : RegionRange(regions.data(), regions.size()) {}

265 : RegionRange(const_cast<Region **>(regions.data()), regions.size()) {}

266

267

269 ptrdiff_t index) {

270 if (auto *region = llvm::dyn_cast_if_present<const std::unique_ptr *>(owner))

271 return region + index;

272 if (auto **region = llvm::dyn_cast_if_present<Region **>(owner))

273 return region + index;

274 return &cast<Region *>(owner)[index];

275 }

276

277 Region *RegionRange::dereference_iterator(const OwnerT &owner,

278 ptrdiff_t index) {

279 if (auto *region = llvm::dyn_cast_if_present<const std::unique_ptr *>(owner))

280 return region[index].get();

281 if (auto **region = llvm::dyn_cast_if_present<Region **>(owner))

282 return region[index];

283 return &cast<Region *>(owner)[index];

284 }

Block represents an ordered list of Operations.

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

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

Region * getParent() const

Provide a 'getParent' method for ilist_node_with_parent methods.

BlockArgument addArgument(Type type, Location loc)

Add one value to the argument list.

BlockArgListType getArguments()

void dropAllReferences()

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

void push_back(Operation *op)

Operation * getParentOp()

Returns the closest surrounding operation that contains this block.

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

auto lookup(T from) const

Lookup a mapped value within the map.

void map(Value from, Value to)

Inserts a new mapping for 'from' to 'to'.

bool contains(T from) const

Checks to see if a mapping for 'from' exists.

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.

static CloneOptions all()

Returns an instance with all flags set to true.

CloneOptions & cloneRegions(bool enable=true)

Configures whether cloning should traverse into any of the regions of the operation.

CloneOptions & cloneOperands(bool enable=true)

Configures whether operation' operands should be cloned.

Operation is the basic unit of execution within MLIR.

MLIRContext * getContext()

Return the context this operation is associated with.

Location getLoc()

The source location the operation was defined or derived from.

unsigned getNumOperands()

Operation * getParentOp()

Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...

Block * getBlock()

Returns the operation block that contains this operation.

MutableArrayRef< Region > getRegions()

Returns the regions held by this operation.

operand_range getOperands()

Returns an iterator on the underlying Value's.

void setOperands(ValueRange operands)

Replace the current operands of this operation with the ones provided in 'operands'.

Region * getParentRegion()

Returns the region to which the instruction belongs.

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

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

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

OpIterator(Region *region, bool end=false)

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

OpIterator & operator++()

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

Region * getParentRegion()

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

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.

void dropAllReferences()

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

static BlockListType Region::* getSublistAccess(Block *)

getSublistAccess() - Returns pointer to member of region.

Operation * getParentOp()

Return the parent operation this region is attached to.

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.

BlockListType & getBlocks()

Location getLoc()

Return a location for this region.

ValueTypeRange< BlockArgListType > getArgumentTypes()

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

MLIRContext * getContext()

Return the context this region is inserted in.

BlockListType::iterator iterator

Block * findAncestorBlockInRegion(Block &block)

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

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

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

This class represents an instance of an SSA value in the MLIR system, representing a computable value...

Include the generated interface declarations.

Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)

void transferNodesFromList(ilist_traits< Block > &otherList, block_iterator first, block_iterator last)

This is a trait method invoked when an operation is moved from one block to another.

simple_ilist<::mlir::Block >::iterator block_iterator

void removeNodeFromList(Block *block)

This is a trait method invoked when an operation is removed from a region.

void addNodeToList(Block *block)

This is a trait method invoked when a basic block is added to a region.