MLIR  19.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 ()
 Returns the argument types of the first block within the 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, Location loc)
 Add one value to the argument list. More...
 
BlockArgument insertArgument (args_iterator it, Type type, Location loc)
 Insert one value to the position in the argument list indicated by the given iterator. More...
 
iterator_range< args_iteratoraddArguments (TypeRange types, ArrayRef< Location > locs)
 Add one argument to the argument list for each type specified in the list. More...
 
BlockArgument insertArgument (unsigned index, Type type, Location loc)
 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, IRMapping &mapper)
 Clone the internal blocks from this region into dest. More...
 
void cloneInto (Region *dest, Region::iterator destPos, IRMapping &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 Iterator = ForwardIterator, typename FnT , typename ArgT = detail::first_argument<FnT>, typename RetT = detail::walkResultType<FnT>>
RetT walk (FnT &&callback)
 Walk all nested operations, blocks or regions (including this region), depending on the type of callback. 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 88 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 166 of file Region.h.

◆ reverse_args_iterator

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

Definition at line 89 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,
Location  loc 
)
inline

Add one value to the argument list.

Definition at line 98 of file Region.h.

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

◆ addArguments()

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

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

locs contains the locations for each of the new arguments, and must be of equal size to types.

Definition at line 41 of file Region.cpp.

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

◆ args_begin()

args_iterator mlir::Region::args_begin ( )
inline

Definition at line 90 of file Region.h.

References getArguments().

◆ args_empty()

bool mlir::Region::args_empty ( )
inline

Definition at line 95 of file Region.h.

References getArguments().

◆ args_end()

args_iterator mlir::Region::args_end ( )
inline

Definition at line 91 of file Region.h.

References getArguments().

◆ args_rbegin()

reverse_args_iterator mlir::Region::args_rbegin ( )
inline

Definition at line 92 of file Region.h.

References getArguments().

◆ args_rend()

reverse_args_iterator mlir::Region::args_rend ( )
inline

Definition at line 93 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,
IRMapping 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.

Calling this method from multiple threads is generally safe if through the process of cloning, no new uses of 'Value's from outside the region are created. Using the mapper, it is possible to avoid adding uses to outside operands by remapping them to 'Value's owned by the caller thread.

Any cloned blocks are appended to the back of dest.

Definition at line 70 of file Region.cpp.

References end().

Referenced by mlir::Operation::clone(), mlir::OpBuilder::cloneRegionBefore(), mlir::sparse_tensor::insertYieldOp(), and outlineKernelFuncImpl().

◆ cloneInto() [2/2]

void Region::cloneInto ( Region dest,
Region::iterator  destPos,
IRMapping 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 181 of file Region.cpp.

References mlir::Block::dropAllReferences().

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 addBodyWithPayloadOp().

◆ 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 121 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 154 of file Region.cpp.

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

Referenced by mlir::detail::DominanceInfoBase< IsPostDom >::properlyDominates().

◆ 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 168 of file Region.cpp.

Referenced by findCommonAncestor(), and mlir::PostDominanceInfo::properlyPostDominates().

◆ 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::OpBuilder::cloneRegionBefore(), convertOmpReductionOp(), mlir::detail::ConversionPatternRewriterImpl::convertRegionTypes(), deleteDeadness(), eraseArgument(), getArguments(), mlir::OpTrait::SingleBlock< ConcreteType >::getBody(), mlir::transform::PossibleTopLevelTransformOpTrait< OpTy >::getBodyBlock(), llvm::GraphTraits< mlir::Region * >::getEntryNode(), getModuleBody(), handleInlinedAllocas(), injectGpuIndexOperations(), mlir::inlineCall(), inlineConvertOmpRegions(), inlineIfCase(), mlir::RewriterBase::inlineRegionBefore(), inlineWhileCase(), mlir::SymbolTable::insert(), insertArgument(), insertCopies(), mlir::sparse_tensor::insertYieldOp(), mlir::Block::isEntryBlock(), mlir::detail::DominanceInfoBase< IsPostDom >::isReachableFromEntry(), makeAtomicReductionGen(), mlir::ForwardDominanceIterator< NoGraphRegions >::makeIterable(), mlir::ReverseDominanceIterator< NoGraphRegions >::makeIterable(), makeReductionGen(), mlir::makeRegionIsolatedFromAbove(), ConvertTypesInSCFForOp::matchAndRewrite(), mlirRegionGetFirstBlock(), moveRegionToNewWarpOpAndReplaceReturns(), mlir::OpBuilder::OpBuilder(), outlineKernelFuncImpl(), mlir::outlineSingleBlockRegion(), printBlock(), propagateLiveness(), ShardingPropagation::runOnOperation(), mlir::vector::splitFullAndPartialTransfer(), mlir::transformCFGToSCF(), updateExpandedGenericOpRegion(), and vectorizeLinalgOpPrecondition().

◆ getArgument()

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

Definition at line 124 of file Region.h.

References getArguments().

Referenced by convertOmpParallel().

◆ getArguments()

BlockArgListType mlir::Region::getArguments ( )
inline

◆ getArgumentTypes()

auto Region::getArgumentTypes ( )

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

Definition at line 36 of file Region.cpp.

◆ 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().

Referenced by mlir::applyPatternsAndFoldGreedily().

◆ 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::dataflow::CFGEdge::getLoc(), mlir::transformCFGToSCF(), and mlir::irdl::RegionConstraint::verify().

◆ getNumArguments()

unsigned mlir::Region::getNumArguments ( )
inline

Definition at line 123 of file Region.h.

References getArguments().

◆ getOps() [1/2]

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

◆ getOps() [2/2]

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

Definition at line 185 of file Region.h.

References 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 205 of file Region.h.

Referenced by mlir::FunctionCallBuilder::create(), generateCopy(), and mlir::outlineSingleBlockRegion().

◆ 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.

◆ 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< IsPostDom >::getDomTree(), mlir::outlineSingleBlockRegion(), ShardingPropagation::runOnOperation(), and mlir::transformCFGToSCF().

◆ insertArgument() [1/2]

BlockArgument mlir::Region::insertArgument ( args_iterator  it,
Type  type,
Location  loc 
)
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 105 of file Region.h.

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

◆ insertArgument() [2/2]

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

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

Definition at line 116 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 222 of file Region.h.

References isProperAncestor().

Referenced by mlir::replaceAllUsesInRegionWith(), 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 50 of file Region.cpp.

References getParentRegion().

Referenced by 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 170 of file Region.h.

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 177 of file Region.h.

References op_begin(), and op_end().

◆ op_end() [1/2]

OpIterator mlir::Region::op_end ( )
inline

Definition at line 171 of file Region.h.

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

◆ op_end() [2/2]

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

Definition at line 181 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 241 of file Region.h.

References dropAllReferences(), and getBlocks().

Referenced by mlir::affine::affineParallelize(), mlir::linalg::pack(), and transposeOneLinalgOperandAndReplace().

◆ viewGraph() [1/2]

void mlir::Region::viewGraph ( )

Definition at line 387 of file ViewOpGraph.cpp.

◆ viewGraph() [2/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 383 of file ViewOpGraph.cpp.

References llvmViewGraph().

◆ walk()

template<WalkOrder Order = WalkOrder::PostOrder, typename Iterator = ForwardIterator, typename FnT , typename ArgT = detail::first_argument<FnT>, typename RetT = detail::walkResultType<FnT>>
RetT mlir::Region::walk ( FnT &&  callback)
inline

Walk all nested operations, blocks or regions (including this region), depending on the type of callback.

The order in which operations, blocks or regions at the same nesting level are visited (e.g., lexicographical or reverse lexicographical order) is determined by Iterator. The walk order for enclosing operations, blocks or regions with respect to their nested ones is specified by Order (post-order by default).

A callback on a operation or block is allowed to erase that operation or block 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 285 of file Region.h.

References mlir::WalkResult::advance(), mlir::WalkResult::interrupt(), mlir::PostOrder, and mlir::PreOrder.

Referenced by checkTransformationPreconditions(), isProfitableToInline(), and mlir::visitUsedValuesDefinedAbove().


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