25 assert(container &&
"region is not attached to a container");
32 assert(container &&
"region is not attached to a container");
33 return container->
getLoc();
46 assert(container &&
"region is not attached to a container");
71 assert(dest &&
"expected valid region to clone into");
78 assert(dest &&
"expected valid region to clone into");
79 assert(
this != dest &&
"cannot clone region into itself");
97 for (
Block &block : *
this) {
99 mapper.
map(&block, newBlock);
106 mapper.
map(arg, newBlock->
addArgument(arg.getType(), arg.getLoc()));
108 dest->
getBlocks().insert(destPos, newBlock);
111 auto newBlocksRange =
122 for (
auto zippedBlocks : llvm::zip(*
this, newBlocksRange)) {
123 Block &sourceBlock = std::get<0>(zippedBlocks);
124 Block &clonedBlock = std::get<1>(zippedBlocks);
133 for (
auto zippedBlocks : llvm::zip(*
this, newBlocksRange)) {
135 llvm::zip(std::get<0>(zippedBlocks), std::get<1>(zippedBlocks))) {
142 [&](
Value operand) { return mapper.lookupOrDefault(operand); });
146 std::get<0>(regions).cloneInto(&std::get<1>(regions), mapper);
155 Block *currBlock = █
158 if (!parentOp || !parentOp->
getBlock())
171 if (opRegion ==
this)
182 for (
Block &b : *
this)
186 Region *llvm::ilist_traits<::mlir::Block>::getParentRegion() {
189 iplist<Block> *anchor(
static_cast<iplist<Block> *
>(
this));
190 return reinterpret_cast<Region *
>(
reinterpret_cast<char *
>(anchor) - offset);
196 assert(!block->
getParent() &&
"already in a region!");
197 block->parentValidOpOrderPair.setPointer(getParentRegion());
203 assert(block->
getParent() &&
"not already in a region!");
204 block->parentValidOpOrderPair.setPointer(
nullptr);
213 auto *curParent = getParentRegion();
214 if (curParent == otherList.getParentRegion())
218 for (; first != last; ++first)
219 first->parentValidOpOrderPair.setPointer(curParent);
227 : region(region), block(end ? region->end() : region->begin()) {
228 if (!region->
empty())
229 skipOverBlocksWithNoOps();
235 if (operation != block->end())
237 if (operation == block->end()) {
239 skipOverBlocksWithNoOps();
244 void Region::OpIterator::skipOverBlocksWithNoOps() {
245 while (block != region->end() && block->empty())
250 if (block == region->end())
253 operation = block->begin();
270 if (
auto *region = llvm::dyn_cast_if_present<
const std::unique_ptr<Region> *>(owner))
271 return region + index;
272 if (
auto **region = llvm::dyn_cast_if_present<Region **>(owner))
273 return region + index;
274 return &owner.get<
Region *>()[index];
277 Region *RegionRange::dereference_iterator(
const OwnerT &owner,
279 if (
auto *region = llvm::dyn_cast_if_present<
const std::unique_ptr<Region> *>(owner))
280 return region[index].get();
281 if (
auto **region = llvm::dyn_cast_if_present<Region **>(owner))
282 return region[index];
283 return &owner.get<
Region *>()[index];
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.
Operation * clone(IRMapping &mapper, CloneOptions options=CloneOptions::all())
Create a deep copy of this operation, remapping any operands that use values outside of the operation...
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.