My Project
Public Member Functions | Protected Member Functions | List of all members
mlir::PatternRewriter Class Referenceabstract

#include <PatternMatch.h>

Inheritance diagram for mlir::PatternRewriter:
Inheritance graph
[legend]
Collaboration diagram for mlir::PatternRewriter:
Collaboration graph
[legend]

Public Member Functions

template<typename OpTy , typename... Args>
OpTy create (Location location, Args... args)
 
template<typename OpTy , typename... Args>
OpTy createChecked (Location location, Args... args)
 
virtual Operationinsert (Operation *op)=0
 
virtual void inlineRegionBefore (Region &region, Region &parent, Region::iterator before)
 
void inlineRegionBefore (Region &region, Block *before)
 
virtual void cloneRegionBefore (Region &region, Region &parent, Region::iterator before, BlockAndValueMapping &mapping)
 
void cloneRegionBefore (Region &region, Region &parent, Region::iterator before)
 
void cloneRegionBefore (Region &region, Block *before)
 
virtual void replaceOp (Operation *op, ValueRange newValues, ValueRange valuesToRemoveIfDead)
 
void replaceOp (Operation *op, ValueRange newValues)
 
template<typename OpTy , typename... Args>
void replaceOpWithNewOp (Operation *op, Args &&... args)
 
template<typename OpTy , typename... Args>
void replaceOpWithNewOp (ValueRange valuesToRemoveIfDead, Operation *op, Args &&... args)
 
virtual void eraseOp (Operation *op)
 This method erases an operation that is known to have no uses. More...
 
virtual void mergeBlocks (Block *source, Block *dest, ValueRange argValues=llvm::None)
 
virtual BlocksplitBlock (Block *block, Block::iterator before)
 
virtual void startRootUpdate (Operation *op)
 
virtual void finalizeRootUpdate (Operation *op)
 
virtual void cancelRootUpdate (Operation *op)
 
template<typename CallableT >
void updateRootInPlace (Operation *root, CallableT &&callable)
 
- Public Member Functions inherited from mlir::OpBuilder
 OpBuilder (MLIRContext *ctx)
 Create a builder with the given context. More...
 
 OpBuilder (Region *region)
 Create a builder and set the insertion point to the start of the region. More...
 
 OpBuilder (Region &region)
 
virtual ~OpBuilder ()
 
 OpBuilder (Operation *op)
 
 OpBuilder (Block *block)
 
 OpBuilder (Block *block, Block::iterator insertPoint)
 
void clearInsertionPoint ()
 
InsertPoint saveInsertionPoint () const
 Return a saved insertion point. More...
 
void restoreInsertionPoint (InsertPoint ip)
 Restore the insert point to a previously saved point. More...
 
void setInsertionPoint (Block *block, Block::iterator insertPoint)
 Set the insertion point to the specified location. More...
 
void setInsertionPoint (Operation *op)
 
void setInsertionPointAfter (Operation *op)
 
void setInsertionPointToStart (Block *block)
 Sets the insertion point to the start of the specified block. More...
 
void setInsertionPointToEnd (Block *block)
 Sets the insertion point to the end of the specified block. More...
 
BlockgetInsertionBlock () const
 
Block::iterator getInsertionPoint () const
 Returns the current insertion point of the builder. More...
 
BlockcreateBlock (Region *parent, Region::iterator insertPt={})
 
BlockcreateBlock (Block *insertBefore)
 
BlockgetBlock () const
 Returns the current block of the builder. More...
 
OperationcreateOperation (const OperationState &state)
 Creates an operation given the fields represented as an OperationState. More...
 
template<typename OpTy , typename... Args>
OpTy create (Location location, Args &&... args)
 Create an operation of specific op type at the current insertion point. More...
 
template<typename OpTy , typename... Args>
void createOrFold (SmallVectorImpl< Value > &results, Location location, Args &&... args)
 
template<typename OpTy , typename... Args>
std::enable_if< OpTy::template hasTrait< OpTrait::OneResult >), Value >::type createOrFold (Location location, Args &&... args)
 Overload to create or fold a single result operation. More...
 
template<typename OpTy , typename... Args>
std::enable_if< OpTy::template hasTrait< OpTrait::ZeroResult >), OpTy >::type createOrFold (Location location, Args &&... args)
 Overload to create or fold a zero result operation. More...
 
LogicalResult tryFold (Operation *op, SmallVectorImpl< Value > &results)
 
Operationclone (Operation &op, BlockAndValueMapping &mapper)
 
Operationclone (Operation &op)
 
OperationcloneWithoutRegions (Operation &op, BlockAndValueMapping &mapper)
 
OperationcloneWithoutRegions (Operation &op)
 
template<typename OpT >
OpT cloneWithoutRegions (OpT op)
 
- Public Member Functions inherited from mlir::Builder
 Builder (MLIRContext *context)
 
 Builder (ModuleOp module)
 
MLIRContextgetContext () const
 
Identifier getIdentifier (StringRef str)
 
Location getUnknownLoc ()
 
Location getFileLineColLoc (Identifier filename, unsigned line, unsigned column)
 
Location getFusedLoc (ArrayRef< Location > locs, Attribute metadata=Attribute())
 
FloatType getBF16Type ()
 
FloatType getF16Type ()
 
FloatType getF32Type ()
 
FloatType getF64Type ()
 
IndexType getIndexType ()
 
IntegerType getI1Type ()
 
IntegerType getIntegerType (unsigned width)
 
FunctionType getFunctionType (ArrayRef< Type > inputs, ArrayRef< Type > results)
 
TupleType getTupleType (ArrayRef< Type > elementTypes)
 
NoneType getNoneType ()
 
template<typename Ty , typename... Args>
Ty getType (Args... args)
 Get or construct an instance of the type 'ty' with provided arguments. More...
 
NamedAttribute getNamedAttr (StringRef name, Attribute val)
 
UnitAttr getUnitAttr ()
 
BoolAttr getBoolAttr (bool value)
 
DictionaryAttr getDictionaryAttr (ArrayRef< NamedAttribute > value)
 
IntegerAttr getIntegerAttr (Type type, int64_t value)
 
IntegerAttr getIntegerAttr (Type type, const APInt &value)
 
FloatAttr getFloatAttr (Type type, double value)
 
FloatAttr getFloatAttr (Type type, const APFloat &value)
 
StringAttr getStringAttr (StringRef bytes)
 
ArrayAttr getArrayAttr (ArrayRef< Attribute > value)
 
FlatSymbolRefAttr getSymbolRefAttr (Operation *value)
 
FlatSymbolRefAttr getSymbolRefAttr (StringRef value)
 
SymbolRefAttr getSymbolRefAttr (StringRef value, ArrayRef< FlatSymbolRefAttr > nestedReferences)
 
Attribute getZeroAttr (Type type)
 
FloatAttr getF16FloatAttr (float value)
 
FloatAttr getF32FloatAttr (float value)
 
FloatAttr getF64FloatAttr (double value)
 
IntegerAttr getI8IntegerAttr (int8_t value)
 
IntegerAttr getI16IntegerAttr (int16_t value)
 
IntegerAttr getI32IntegerAttr (int32_t value)
 
IntegerAttr getI64IntegerAttr (int64_t value)
 
DenseIntElementsAttr getI32VectorAttr (ArrayRef< int32_t > values)
 
ArrayAttr getAffineMapArrayAttr (ArrayRef< AffineMap > values)
 
ArrayAttr getI32ArrayAttr (ArrayRef< int32_t > values)
 
ArrayAttr getI64ArrayAttr (ArrayRef< int64_t > values)
 
ArrayAttr getIndexArrayAttr (ArrayRef< int64_t > values)
 
ArrayAttr getF32ArrayAttr (ArrayRef< float > values)
 
ArrayAttr getF64ArrayAttr (ArrayRef< double > values)
 
ArrayAttr getStrArrayAttr (ArrayRef< StringRef > values)
 
AffineExpr getAffineDimExpr (unsigned position)
 
AffineExpr getAffineSymbolExpr (unsigned position)
 
AffineExpr getAffineConstantExpr (int64_t constant)
 
AffineMap getEmptyAffineMap ()
 Returns a zero result affine map with no dimensions or symbols: () -> (). More...
 
AffineMap getConstantAffineMap (int64_t val)
 
AffineMap getDimIdentityMap ()
 
AffineMap getMultiDimIdentityMap (unsigned rank)
 
AffineMap getSymbolIdentityMap ()
 
AffineMap getSingleDimShiftAffineMap (int64_t shift)
 
AffineMap getShiftedAffineMap (AffineMap map, int64_t shift)
 

Protected Member Functions

 PatternRewriter (MLIRContext *ctx)
 
virtual ~PatternRewriter ()
 
virtual void notifyRootReplaced (Operation *op)
 
virtual void notifyOperationRemoved (Operation *op)
 

Additional Inherited Members

- Protected Attributes inherited from mlir::Builder
MLIRContextcontext
 

Detailed Description

This class coordinates the application of a pattern to the current function, providing a way to create operations and keep track of what gets deleted.

These class serves two purposes: 1) it is the interface that patterns interact with to make mutations to the IR they are being applied to. 2) It is a base class that clients of the PatternMatcher use when they want to apply patterns and observe their effects (e.g. to keep worklists or other data structures up to date).

Constructor & Destructor Documentation

◆ PatternRewriter()

mlir::PatternRewriter::PatternRewriter ( MLIRContext ctx)
inlineexplicitprotected

◆ ~PatternRewriter()

PatternRewriter::~PatternRewriter ( )
protectedvirtual

Member Function Documentation

◆ cancelRootUpdate()

virtual void mlir::PatternRewriter::cancelRootUpdate ( Operation op)
inlinevirtual

This method cancels a pending root update. This can only be called on operations that were provided to a call to startRootUpdate.

Reimplemented in mlir::ConversionPatternRewriter.

◆ cloneRegionBefore() [1/3]

void PatternRewriter::cloneRegionBefore ( Region region,
Region parent,
Region::iterator  before,
BlockAndValueMapping mapping 
)
virtual

Clone the blocks that belong to "region" before the given position in another region "parent". The two regions must be different. The caller is responsible for creating or updating the operation transferring flow of control to the region and passing it the correct block arguments.

Reimplemented in mlir::ConversionPatternRewriter.

◆ cloneRegionBefore() [2/3]

void PatternRewriter::cloneRegionBefore ( Region region,
Region parent,
Region::iterator  before 
)

◆ cloneRegionBefore() [3/3]

void PatternRewriter::cloneRegionBefore ( Region region,
Block before 
)

◆ create()

template<typename OpTy , typename... Args>
OpTy mlir::PatternRewriter::create ( Location  location,
Args...  args 
)
inline

Create operation of specific op type at the current insertion point without verifying to see if it is valid.

◆ createChecked()

template<typename OpTy , typename... Args>
OpTy mlir::PatternRewriter::createChecked ( Location  location,
Args...  args 
)
inline

Creates an operation of specific op type at the current insertion point. If the result is an invalid op (the verifier hook fails), emit an error and return null.

◆ eraseOp()

void PatternRewriter::eraseOp ( Operation op)
virtual

This method erases an operation that is known to have no uses.

This method erases an operation that is known to have no uses. The uses of the given operation must be known to be dead.

Reimplemented in mlir::ConversionPatternRewriter.

◆ finalizeRootUpdate()

virtual void mlir::PatternRewriter::finalizeRootUpdate ( Operation op)
inlinevirtual

This method is used to signal the end of a root update on the given operation. This can only be called on operations that were provided to a call to startRootUpdate.

Reimplemented in mlir::ConversionPatternRewriter.

◆ inlineRegionBefore() [1/2]

void PatternRewriter::inlineRegionBefore ( Region region,
Region parent,
Region::iterator  before 
)
virtual

Move the blocks that belong to "region" before the given position in another region "parent". The two regions must be different. The caller is responsible for creating or updating the operation transferring flow of control to the region and passing it the correct block arguments.

Move the blocks that belong to "region" before the given position in another region. The two regions must be different. The caller is in charge to update create the operation transferring the control flow to the region and pass it the correct block arguments.

Reimplemented in mlir::ConversionPatternRewriter.

◆ inlineRegionBefore() [2/2]

void PatternRewriter::inlineRegionBefore ( Region region,
Block before 
)

◆ insert()

virtual Operation* mlir::PatternRewriter::insert ( Operation op)
pure virtual

This is implemented to insert the specified operation and serves as a notification hook for rewriters that want to know about new operations.

Reimplemented from mlir::OpBuilder.

Implemented in mlir::ConversionPatternRewriter.

◆ mergeBlocks()

void PatternRewriter::mergeBlocks ( Block source,
Block dest,
ValueRange  argValues = llvm::None 
)
virtual

Merge the operations of block 'source' into the end of block 'dest'. 'source's predecessors must either be empty or only contain 'dest`. 'argValues' is used to replace the block arguments of 'source' after merging.

Merge the operations of block 'source' into the end of block 'dest'. 'source's predecessors must be empty or only contain 'dest`. 'argValues' is used to replace the block arguments of 'source' after merging.

Reimplemented in mlir::ConversionPatternRewriter.

◆ notifyOperationRemoved()

virtual void mlir::PatternRewriter::notifyOperationRemoved ( Operation op)
inlineprotectedvirtual

This is called on an operation that a pattern match is removing, right before the operation is deleted. At this point, the operation has zero uses.

◆ notifyRootReplaced()

virtual void mlir::PatternRewriter::notifyRootReplaced ( Operation op)
inlineprotectedvirtual

Notify the pattern rewriter that the specified operation is about to be replaced with another set of operations. This is called before the uses of the operation have been changed.

◆ replaceOp() [1/2]

void PatternRewriter::replaceOp ( Operation op,
ValueRange  newValues,
ValueRange  valuesToRemoveIfDead 
)
virtual

This method performs the final replacement for a pattern, where the results of the operation are updated to use the specified list of SSA values. In addition to replacing and removing the specified operation, clients can specify a list of other nodes that this replacement may make (perhaps transitively) dead. If any of those values are dead, this will remove them as well.

This method performs the final replacement for a pattern, where the results of the operation are updated to use the specified list of SSA values. In addition to replacing and removing the specified operation, clients can specify a list of other nodes that this replacement may make (perhaps transitively) dead. If any of those ops are dead, this will remove them as well.

Reimplemented in mlir::ConversionPatternRewriter.

◆ replaceOp() [2/2]

void mlir::PatternRewriter::replaceOp ( Operation op,
ValueRange  newValues 
)
inline

◆ replaceOpWithNewOp() [1/2]

template<typename OpTy , typename... Args>
void mlir::PatternRewriter::replaceOpWithNewOp ( Operation op,
Args &&...  args 
)
inline

Replaces the result op with a new op that is created without verification. The result values of the two ops must be the same types.

◆ replaceOpWithNewOp() [2/2]

template<typename OpTy , typename... Args>
void mlir::PatternRewriter::replaceOpWithNewOp ( ValueRange  valuesToRemoveIfDead,
Operation op,
Args &&...  args 
)
inline

Replaces the result op with a new op that is created without verification. The result values of the two ops must be the same types. This allows specifying a list of ops that may be removed if dead.

◆ splitBlock()

Block * PatternRewriter::splitBlock ( Block block,
Block::iterator  before 
)
virtual

Split the operations starting at "before" (inclusive) out of the given block into a new block, and return it.

Reimplemented in mlir::ConversionPatternRewriter.

◆ startRootUpdate()

virtual void mlir::PatternRewriter::startRootUpdate ( Operation op)
inlinevirtual

This method is used to notify the rewriter that an in-place operation modification is about to happen. A call to this function must be followed by a call to either finalizeRootUpdate or cancelRootUpdate. This is a minor efficiency win (it avoids creating a new operation and removing the old one) but also often allows simpler code in the client.

Reimplemented in mlir::ConversionPatternRewriter.

◆ updateRootInPlace()

template<typename CallableT >
void mlir::PatternRewriter::updateRootInPlace ( Operation root,
CallableT &&  callable 
)
inline

This method is a utility wrapper around a root update of an operation. It wraps calls to startRootUpdate and finalizeRootUpdate around the given callable.


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