13 #ifndef MLIR_IR_REGION_H
14 #define MLIR_IR_REGION_H
20 template <
typename ValueRangeT>
60 bool empty() {
return blocks.empty(); }
72 return &Region::blocks;
133 :
public llvm::iterator_facade_base<OpIterator, std::forward_iterator_tag,
140 using llvm::iterator_facade_base<
OpIterator, std::forward_iterator_tag,
148 return operation == rhs.operation;
153 void skipOverBlocksWithNoOps();
165 template <
typename OpT>
176 template <
typename OpT>
180 template <
typename OpT>
184 template <
typename OpT>
204 template <
typename ParentT>
208 if (
auto parent = dyn_cast_or_null<ParentT>(region->container))
210 }
while ((region = region->getParentRegion()));
244 blocks.splice(blocks.end(), other.
getBlocks());
279 std::enable_if_t<std::is_same<RetT, void>::value, RetT>
walk(FnT &&callback) {
280 for (
auto &block : *
this)
281 block.walk<Order, Iterator>(callback);
299 std::enable_if_t<std::is_same<RetT, WalkResult>::value, RetT>
301 for (
auto &block : *
this)
302 if (block.walk<Order, Iterator>(callback).wasInterrupted())
333 PointerUnion<Region *, const std::unique_ptr<Region> *, Region **>,
334 Region *, Region *, Region *> {
342 using RangeBaseT::RangeBaseT;
346 template <
typename Arg,
typename = std::enable_if_t<std::is_constructible<
351 template <
typename Arg>
362 static OwnerT offset_base(
const OwnerT &owner, ptrdiff_t index);
364 static Region *dereference_iterator(
const OwnerT &owner, ptrdiff_t index);
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, 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
std::enable_if_t< std::is_same< RetT, WalkResult >::value, RetT > walk(FnT &&callback)
Walk the operations in this region.
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()
std::enable_if_t< std::is_same< RetT, void >::value, RetT > walk(FnT &&callback)
Walk the operations in this 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.
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.
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.
This header declares functions that assist transformations in the MemRef dialect.
WalkOrder
Traversal order for region, block and operation walk utilities.
This iterator enumerates the elements in "forward" order.