25 assert(container &&
"region is not attached to a container");
26 return container->getContext();
32 assert(container &&
"region is not attached to a container");
33 return container->getLoc();
46 assert(container &&
"region is not attached to a container");
47 return container->getParentRegion();
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);
127 clonedBlock.
push_back(op.clone(mapper, cloneOptions));
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); });
143 clone.setOperands(operands);
145 for (
auto regions : llvm::zip(source.
getRegions(),
clone.getRegions()))
146 std::get<0>(regions).cloneInto(&std::get<1>(regions), mapper);
155 Block *currBlock = █
158 if (!parentOp || !parentOp->
getBlock())
171 if (opRegion ==
this)
183 b.dropAllReferences();
186Region *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();
244void Region::OpIterator::skipOverBlocksWithNoOps() {
245 while (block != region->end() && block->empty())
250 if (block == region->end())
253 operation = block->begin();
258 os <<
"Region has no parent op";
263 for (
auto it : llvm::enumerate(region.
getBlocks())) {
264 os <<
"\n Block #" << it.index() <<
":";
265 for (
Operation &op : it.value().getOperations())
283RegionRange::OwnerT RegionRange::offset_base(
const OwnerT &owner,
285 if (
auto *region = llvm::dyn_cast_if_present<
const std::unique_ptr<Region> *>(owner))
286 return region +
index;
287 if (
auto **region = llvm::dyn_cast_if_present<Region **>(owner))
288 return region +
index;
289 return &cast<Region *>(owner)[
index];
292Region *RegionRange::dereference_iterator(
const OwnerT &owner,
294 if (
auto *region = llvm::dyn_cast_if_present<
const std::unique_ptr<Region> *>(owner))
295 return region[
index].get();
296 if (
auto **region = llvm::dyn_cast_if_present<Region **>(owner))
297 return region[
index];
298 return &cast<Region *>(owner)[
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 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.
Set of flags used to control the behavior of the various IR print methods (e.g.
A wrapper class that allows for printing an operation with a set of flags, useful to act as a "stream...
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.
Block * getBlock()
Returns the operation block that contains this operation.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
unsigned getNumOperands()
OperationName getName()
The name of an operation is the key identifier for it.
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
operand_range getOperands()
Returns an iterator on the underlying Value's.
Region * getParentRegion()
Returns the region to which the instruction belongs.
RegionRange(MutableArrayRef< Region > regions={})
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...
BlockArgListType getArguments()
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.
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.
Location getLoc()
Return a location for this region.
ValueTypeRange< BlockArgListType > getArgumentTypes()
Returns the argument types of the first block within the region.
Operation * getParentOp()
Return the parent operation this region is attached to.
MLIRContext * getContext()
Return the context this region is inserted in.
BlockListType & getBlocks()
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.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
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.