MLIR  14.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
mlir::Region Class Reference

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

#include "mlir/IR/Region.h"

Classes

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

Public Types

using BlockListType = llvm::iplist< Block >
 
using iterator = BlockListType::iterator
 
using reverse_iterator = BlockListType::reverse_iterator
 
using BlockArgListType = MutableArrayRef< BlockArgument >
 
using args_iterator = BlockArgListType::iterator
 
using reverse_args_iterator = BlockArgListType::reverse_iterator
 
template<typename OpT >
using op_iterator = detail::op_iterator< OpT, OpIterator >
 This class provides iteration over the held operations of a region for a specific operation type. More...
 

Public Member Functions

 Region ()=default
 
 Region (Operation *container)
 
 ~Region ()
 
MLIRContextgetContext ()
 Return the context this region is inserted in. More...
 
Location getLoc ()
 Return a location for this region. More...
 
BlockListTypegetBlocks ()
 
BlockemplaceBlock ()
 
iterator begin ()
 
iterator end ()
 
reverse_iterator rbegin ()
 
reverse_iterator rend ()
 
bool empty ()
 
void push_back (Block *block)
 
void push_front (Block *block)
 
Blockback ()
 
Blockfront ()
 
bool hasOneBlock ()
 Return true if this region has exactly one block. More...
 
BlockArgListType getArguments ()
 
ValueTypeRange< BlockArgListTypegetArgumentTypes ()
 Return a range containing the types of the arguments for this region. More...
 
args_iterator args_begin ()
 
args_iterator args_end ()
 
reverse_args_iterator args_rbegin ()
 
reverse_args_iterator args_rend ()
 
bool args_empty ()
 
BlockArgument addArgument (Type type)
 Add one value to the argument list. More...
 
BlockArgument insertArgument (args_iterator it, Type type)
 Insert one value to the position in the argument list indicated by the given iterator. More...
 
iterator_range< args_iteratoraddArguments (TypeRange types)
 Add one argument to the argument list for each type specified in the list. More...
 
BlockArgument insertArgument (unsigned index, Type type)
 Add one value to the argument list at the specified position. More...
 
void eraseArgument (unsigned index)
 Erase the argument at 'index' and remove it from the argument list. More...
 
unsigned getNumArguments ()
 
BlockArgument getArgument (unsigned i)
 
OpIterator op_begin ()
 Return iterators that walk the operations nested directly within this region. More...
 
OpIterator op_end ()
 
iterator_range< OpIteratorgetOps ()
 
template<typename OpT >
op_iterator< OpT > op_begin ()
 Return iterators that walk operations of type 'T' nested directly within this region. More...
 
template<typename OpT >
op_iterator< OpT > op_end ()
 
template<typename OpT >
iterator_range< op_iterator< OpT > > getOps ()
 
RegiongetParentRegion ()
 Return the region containing this region or nullptr if the region is attached to a top-level operation. More...
 
OperationgetParentOp ()
 Return the parent operation this region is attached to. More...
 
template<typename ParentT >
ParentT getParentOfType ()
 Find the first parent operation of the given type, or nullptr if there is no ancestor operation. More...
 
unsigned getRegionNumber ()
 Return the number of this region in the parent operation. More...
 
bool isProperAncestor (Region *other)
 Return true if this region is a proper ancestor of the other region. More...
 
bool isAncestor (Region *other)
 Return true if this region is ancestor of the other region. More...
 
void cloneInto (Region *dest, BlockAndValueMapping &mapper)
 Clone the internal blocks from this region into dest. More...
 
void cloneInto (Region *dest, Region::iterator destPos, BlockAndValueMapping &mapper)
 Clone this region into 'dest' before the given position in 'dest'. More...
 
void takeBody (Region &other)
 Takes body of another region (that region will have no body after this operation completes). More...
 
BlockfindAncestorBlockInRegion (Block &block)
 Returns 'block' if 'block' lies in this region, or otherwise finds the ancestor of 'block' that lies in this region. More...
 
OperationfindAncestorOpInRegion (Operation &op)
 Returns 'op' if 'op' lies in this region, or otherwise finds the ancestor of 'op' that lies in this region. More...
 
void dropAllReferences ()
 Drop all operand uses from operations within this region, which is an essential step in breaking cyclic dependences between references when they are to be deleted. More...
 
template<WalkOrder Order = WalkOrder::PostOrder, typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if< std::is_same< RetT, void >::value, RetT >::type walk (FnT &&callback)
 Walk the operations in this region. More...
 
template<WalkOrder Order = WalkOrder::PostOrder, typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if< std::is_same< RetT, WalkResult >::value, RetT >::type walk (FnT &&callback)
 Walk the operations in this region. More...
 
void viewGraph (const Twine &regionName)
 Displays the CFG in a window. More...
 
void viewGraph ()
 

Static Public Member Functions

static BlockListType Region::* getSublistAccess (Block *)
 getSublistAccess() - Returns pointer to member of region. More...
 

Detailed Description

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

Definition at line 26 of file Region.h.

Member Typedef Documentation

◆ args_iterator

using mlir::Region::args_iterator = BlockArgListType::iterator

Definition at line 87 of file Region.h.

◆ BlockArgListType

Definition at line 80 of file Region.h.

◆ BlockListType

using mlir::Region::BlockListType = llvm::iplist<Block>

Definition at line 44 of file Region.h.

◆ iterator

using mlir::Region::iterator = BlockListType::iterator

Definition at line 52 of file Region.h.

◆ op_iterator

template<typename OpT >
using mlir::Region::op_iterator = detail::op_iterator<OpT, OpIterator>

This class provides iteration over the held operations of a region for a specific operation type.

Definition at line 160 of file Region.h.

◆ reverse_args_iterator

using mlir::Region::reverse_args_iterator = BlockArgListType::reverse_iterator

Definition at line 88 of file Region.h.

◆ reverse_iterator

using mlir::Region::reverse_iterator = BlockListType::reverse_iterator

Definition at line 53 of file Region.h.

Constructor & Destructor Documentation

◆ Region() [1/2]

mlir::Region::Region ( )
default

◆ Region() [2/2]

Region::Region ( Operation container)
explicit

Definition at line 14 of file Region.cpp.

◆ ~Region()

Region::~Region ( )

Definition at line 16 of file Region.cpp.

References dropAllReferences().

Member Function Documentation

◆ addArgument()

BlockArgument mlir::Region::addArgument ( Type  type)
inline

Add one value to the argument list.

Definition at line 97 of file Region.h.

References mlir::Block::addArgument(), and front().

◆ addArguments()

iterator_range< Region::args_iterator > Region::addArguments ( TypeRange  types)

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

Definition at line 42 of file Region.cpp.

References mlir::Block::addArguments(), and front().

Referenced by insertArgument().

◆ args_begin()

args_iterator mlir::Region::args_begin ( )
inline

Definition at line 89 of file Region.h.

References getArguments().

◆ args_empty()

bool mlir::Region::args_empty ( )
inline

Definition at line 94 of file Region.h.

References getArguments().

◆ args_end()

args_iterator mlir::Region::args_end ( )
inline

Definition at line 90 of file Region.h.

References getArguments().

◆ args_rbegin()

reverse_args_iterator mlir::Region::args_rbegin ( )
inline

Definition at line 91 of file Region.h.

References getArguments().

◆ args_rend()

reverse_args_iterator mlir::Region::args_rend ( )
inline

Definition at line 92 of file Region.h.

References getArguments().

◆ back()

Block& mlir::Region::back ( )
inline

◆ begin()

iterator mlir::Region::begin ( )
inline

◆ cloneInto() [1/2]

void Region::cloneInto ( Region dest,
BlockAndValueMapping mapper 
)

Clone the internal blocks from this region into dest.

Clone the internal blocks from this region into dest.

Any cloned blocks are appended to the back of dest. If the mapper contains entries for block arguments, these arguments are not included in the respective cloned block.

Any cloned blocks are appended to the back of dest.

Definition at line 71 of file Region.cpp.

References end().

Referenced by mlir::Operation::clone(), mlir::RewriterBase::cloneRegionBefore(), inlineRegionImpl(), isAncestor(), and verify().

◆ cloneInto() [2/2]

void Region::cloneInto ( Region dest,
Region::iterator  destPos,
BlockAndValueMapping mapper 
)

◆ dropAllReferences()

void Region::dropAllReferences ( )

Drop all operand uses from operations within this region, which is an essential step in breaking cyclic dependences between references when they are to be deleted.

Definition at line 149 of file Region.cpp.

References mlir::Block::dropAllReferences(), and getSublistAccess().

Referenced by takeBody(), and ~Region().

◆ emplaceBlock()

Block& mlir::Region::emplaceBlock ( )
inline

Definition at line 46 of file Region.h.

References back(), and push_back().

Referenced by verify(), and walkReferenceCountedValues().

◆ empty()

bool mlir::Region::empty ( )
inline

◆ end()

iterator mlir::Region::end ( )
inline

◆ eraseArgument()

void mlir::Region::eraseArgument ( unsigned  index)
inline

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

Definition at line 115 of file Region.h.

References mlir::Block::eraseArgument(), and front().

◆ findAncestorBlockInRegion()

Block * Region::findAncestorBlockInRegion ( Block block)

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

Returns nullptr if the latter fails.

Definition at line 122 of file Region.cpp.

References mlir::Operation::getBlock(), mlir::Block::getParent(), and mlir::Block::getParentOp().

Referenced by mlir::NumberOfExecutions::getNumberOfExecutions(), mlir::detail::DominanceInfoBase< true >::properlyDominates(), and takeBody().

◆ findAncestorOpInRegion()

Operation * Region::findAncestorOpInRegion ( Operation op)

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

Returns nullptr if the latter fails.

Definition at line 136 of file Region.cpp.

References mlir::Operation::getParentOp(), and mlir::Operation::getParentRegion().

Referenced by mlir::detail::DominanceInfoBase< true >::isReachableFromEntry(), mlir::PostDominanceInfo::properlyPostDominates(), and takeBody().

◆ front()

Block& mlir::Region::front ( )
inline

Definition at line 65 of file Region.h.

Referenced by addArgument(), addArguments(), mlir::detail::ConversionPatternRewriterImpl::applySignatureConversion(), mlir::async::cloneConstantsIntoTheRegion(), cloneInto(), mlir::ConversionPatternRewriter::cloneRegionBefore(), computeRegionBlockNumberOfExecutions(), convertOmpReductionOp(), mlir::detail::ConversionPatternRewriterImpl::convertRegionTypes(), createDecl(), deleteDeadness(), eraseArgument(), mlir::function_like_impl::eraseFunctionArguments(), mlir::eraseUnreachableBlocks(), mlir::AffineDmaWaitOp::fold(), getArguments(), getBlockIt(), mlir::OpTrait::SingleBlock< ConcreteType >::getBody(), llvm::GraphTraits< mlir::Region * >::getEntryNode(), getModuleBody(), mlir::OperationFolder::getOrCreateConstant(), mlir::spirv::getPushConstantValue(), hasOnlyScalarElementwiseOp(), injectGpuIndexOperations(), mlir::inlineCall(), inlineConvertOmpRegions(), inlineIfCase(), inlineRegionImpl(), inlineWhileCase(), mlir::SymbolTable::insert(), insertArgument(), insertCopies(), mlir::function_like_impl::insertFunctionArguments(), mlir::Block::isEntryBlock(), mlir::detail::DominanceInfoBase< true >::isReachableFromEntry(), mlir::SymbolTable::lookupSymbolIn(), mlirRegionGetFirstBlock(), moveInsertionPointToAllocationHoistingBarrier(), mlir::OpBuilder::OpBuilder(), mlir::outlineIfOp(), outlineKernelFuncImpl(), print(), mlir::AsmPrinter::Impl::printIntegerSet(), propagateLiveness(), remainsLegalAfterInline(), replaceOpWithRegion(), shouldPrintElementsAttrWithHex(), mlir::SymbolTable::SymbolTable(), updateExpandedGenericOpRegion(), validateSupportedControlFlow(), verify(), mlir::OpTrait::SingleBlock< ConcreteType >::verifyTrait(), and mlir::OpTrait::SingleBlockImplicitTerminator< TerminatorOpType >::Impl< ConcreteType >::verifyTrait().

◆ getArgument()

BlockArgument mlir::Region::getArgument ( unsigned  i)
inline

Definition at line 118 of file Region.h.

References getArguments().

Referenced by mlir::function_like_impl::printFunctionSignature(), and verifyRegionAttribute().

◆ getArguments()

BlockArgListType mlir::Region::getArguments ( )
inline

◆ getArgumentTypes()

auto Region::getArgumentTypes ( )

Return a range containing the types of the arguments for this region.

Definition at line 37 of file Region.cpp.

References getArguments().

Referenced by getArguments().

◆ getBlocks()

BlockListType& mlir::Region::getBlocks ( )
inline

◆ getContext()

MLIRContext * Region::getContext ( )

Return the context this region is inserted in.

The region must have a valid parent container.

Definition at line 24 of file Region.cpp.

References mlir::Operation::getContext().

◆ getLoc()

Location Region::getLoc ( )

Return a location for this region.

This is the location attached to the parent container. The region must have a valid parent container.

Definition at line 31 of file Region.cpp.

References mlir::Operation::getLoc().

Referenced by mlir::ConversionPatternRewriter::cloneRegionBefore(), and mayBeValidWithoutTerminator().

◆ getNumArguments()

unsigned mlir::Region::getNumArguments ( )
inline

Definition at line 117 of file Region.h.

References getArguments().

Referenced by verifyTypesAlongAllEdges().

◆ getOps() [1/2]

iterator_range<OpIterator> mlir::Region::getOps ( )
inline

Definition at line 166 of file Region.h.

References op_begin(), and op_end().

Referenced by applyPatterns(), printOperation(), and mlir::SymbolUserMap::SymbolUserMap().

◆ getOps() [2/2]

template<typename OpT >
iterator_range<op_iterator<OpT> > mlir::Region::getOps ( )
inline

Definition at line 179 of file Region.h.

References getParentRegion(), op_begin(), and op_end().

◆ getParentOfType()

template<typename ParentT >
ParentT mlir::Region::getParentOfType ( )
inline

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

Definition at line 199 of file Region.h.

References getParentRegion(), getRegionNumber(), and isProperAncestor().

Referenced by generateCopy(), and printValueInfo().

◆ getParentOp()

Operation* mlir::Region::getParentOp ( )
inline

◆ getParentRegion()

Region * Region::getParentRegion ( )

◆ getRegionNumber()

unsigned Region::getRegionNumber ( )

◆ getSublistAccess()

static BlockListType Region::* mlir::Region::getSublistAccess ( Block )
inlinestatic

getSublistAccess() - Returns pointer to member of region.

Definition at line 71 of file Region.h.

Referenced by dropAllReferences().

◆ hasOneBlock()

bool mlir::Region::hasOneBlock ( )
inline

Return true if this region has exactly one block.

Definition at line 68 of file Region.h.

References begin(), empty(), and end().

Referenced by mlir::detail::DominanceInfoBase< true >::getDomTree().

◆ insertArgument() [1/2]

BlockArgument mlir::Region::insertArgument ( args_iterator  it,
Type  type 
)
inline

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

The existing arguments are shifted. The block is expected not to have predecessors.

Definition at line 102 of file Region.h.

References addArguments(), front(), and mlir::Block::insertArgument().

◆ insertArgument() [2/2]

BlockArgument mlir::Region::insertArgument ( unsigned  index,
Type  type 
)
inline

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

Definition at line 110 of file Region.h.

References front(), and mlir::Block::insertArgument().

◆ isAncestor()

bool mlir::Region::isAncestor ( Region other)
inline

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

A region is considered as its own ancestor, use isProperAncestor to avoid this.

Definition at line 216 of file Region.h.

References cloneInto(), and isProperAncestor().

Referenced by hasNoInterveningEffect(), hasTrivialZeroTripCount(), parseForOp(), parseTiledLoopOp(), print(), mlir::replaceAllUsesInRegionWith(), verify(), and mlir::visitUsedValuesDefinedAbove().

◆ isProperAncestor()

bool Region::isProperAncestor ( Region other)

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

Definition at line 51 of file Region.cpp.

References getParentRegion().

Referenced by diagnoseInvalidOperandDominance(), getParentOfType(), and isAncestor().

◆ op_begin() [1/2]

OpIterator mlir::Region::op_begin ( )
inline

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

Definition at line 164 of file Region.h.

References mlir::Region::OpIterator::OpIterator().

Referenced by findOptimal(), getOps(), op_begin(), and mlir::ReductionNode::update().

◆ op_begin() [2/2]

template<typename OpT >
op_iterator<OpT> mlir::Region::op_begin ( )
inline

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

Definition at line 171 of file Region.h.

References op_begin(), and op_end().

◆ op_end() [1/2]

OpIterator mlir::Region::op_end ( )
inline

◆ op_end() [2/2]

template<typename OpT >
op_iterator<OpT> mlir::Region::op_end ( )
inline

Definition at line 175 of file Region.h.

References op_end().

◆ push_back()

void mlir::Region::push_back ( Block block)
inline

◆ push_front()

void mlir::Region::push_front ( Block block)
inline

Definition at line 62 of file Region.h.

◆ rbegin()

reverse_iterator mlir::Region::rbegin ( )
inline

Definition at line 57 of file Region.h.

◆ rend()

reverse_iterator mlir::Region::rend ( )
inline

Definition at line 58 of file Region.h.

◆ takeBody()

void mlir::Region::takeBody ( Region other)
inline

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

The current body of this region is cleared.

Definition at line 231 of file Region.h.

References dropAllReferences(), findAncestorBlockInRegion(), findAncestorOpInRegion(), getBlocks(), mlir::PostOrder, and value.

Referenced by mlir::Operation::create(), and isMemRefNormalizable().

◆ viewGraph() [1/2]

void mlir::Region::viewGraph ( const Twine &  regionName)

Displays the CFG in a window.

This is for use from the debugger and depends on Graphviz to generate the graph. This function is defined in ViewOpGraph.cpp and only works with that target linked.

Definition at line 333 of file ViewOpGraph.cpp.

References llvmViewGraph().

◆ viewGraph() [2/2]

void mlir::Region::viewGraph ( )

Definition at line 337 of file ViewOpGraph.cpp.

Referenced by walk().

◆ walk() [1/2]

template<WalkOrder Order = WalkOrder::PostOrder, typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if<std::is_same<RetT, void>::value, RetT>::type mlir::Region::walk ( FnT &&  callback)
inline

Walk the operations in this region.

The callback method is called for each nested region, block or operation, depending on the callback provided. Regions, blocks and operations at the same nesting level are visited in lexicographical order. The walk order for enclosing regions, blocks and operations with respect to their nested ones is specified by 'Order' (post-order by default). This method is invoked for void-returning callbacks. A callback on a block or operation is allowed to erase that block or operation only if the walk is in post-order. See non-void method for pre-order erasure. See Operation::walk for more details.

Definition at line 267 of file Region.h.

References mlir::PostOrder, value, and mlir::Block::walk().

Referenced by mlir::greedilyMapParallelSCFToGPU(), validateSupportedControlFlow(), verify(), and mlir::visitUsedValuesDefinedAbove().

◆ walk() [2/2]

template<WalkOrder Order = WalkOrder::PostOrder, typename FnT , typename RetT = detail::walkResultType<FnT>>
std::enable_if<std::is_same<RetT, WalkResult>::value, RetT>::type mlir::Region::walk ( FnT &&  callback)
inline

Walk the operations in this region.

The callback method is called for each nested region, block or operation, depending on the callback provided. Regions, blocks and operations at the same nesting level are visited in lexicographical order. The walk order for enclosing regions, blocks and operations with respect to their nested ones is specified by 'Order' (post-order by default). This method is invoked for skippable or interruptible callbacks. A callback on a block or operation is allowed to erase that block or operation if either:

  • the walk is in post-order,
  • or the walk is in pre-order and the walk is skipped after the erasure. See Operation::walk for more details.

Definition at line 286 of file Region.h.

References mlir::WalkResult::advance(), mlir::WalkResult::interrupt(), viewGraph(), and mlir::Block::walk().


The documentation for this class was generated from the following files: