MLIR  16.0.0git
Public Member Functions | Protected Member Functions | List of all members
mlir::RewriterBase Class Reference

This class coordinates the application of a rewrite on a set of IR, providing a way for clients to track mutations and create new operations. More...

#include "mlir/IR/PatternMatch.h"

+ Inheritance diagram for mlir::RewriterBase:
+ Collaboration diagram for mlir::RewriterBase:

Public Member Functions

virtual void inlineRegionBefore (Region &region, Region &parent, Region::iterator before)
 Move the blocks that belong to "region" before the given position in another region "parent". More...
 
void inlineRegionBefore (Region &region, Block *before)
 
virtual void cloneRegionBefore (Region &region, Region &parent, Region::iterator before, BlockAndValueMapping &mapping)
 Clone the blocks that belong to "region" before the given position in another region "parent". More...
 
void cloneRegionBefore (Region &region, Region &parent, Region::iterator before)
 
void cloneRegionBefore (Region &region, Block *before)
 
virtual void replaceOpWithIf (Operation *op, ValueRange newValues, bool *allUsesReplaced, llvm::unique_function< bool(OpOperand &) const > functor)
 This method replaces the uses of the results of op with the values in newValues when the provided functor returns true for a specific use. More...
 
void replaceOpWithIf (Operation *op, ValueRange newValues, llvm::unique_function< bool(OpOperand &) const > functor)
 
void replaceOpWithinBlock (Operation *op, ValueRange newValues, Block *block, bool *allUsesReplaced=nullptr)
 This method replaces the uses of the results of op with the values in newValues when a use is nested within the given block. More...
 
virtual void replaceOp (Operation *op, ValueRange newValues)
 This method replaces the results of the operation with the specified list of values. More...
 
template<typename OpTy , typename... Args>
OpTy replaceOpWithNewOp (Operation *op, Args &&...args)
 Replaces the result op with a new op that is created without verification. More...
 
virtual void eraseOp (Operation *op)
 This method erases an operation that is known to have no uses. More...
 
virtual void eraseBlock (Block *block)
 This method erases all operations in a block. More...
 
virtual void mergeBlocks (Block *source, Block *dest, ValueRange argValues=llvm::None)
 Merge the operations of block 'source' into the end of block 'dest'. More...
 
void mergeBlockBefore (Block *source, Operation *op, ValueRange argValues=llvm::None)
 
virtual BlocksplitBlock (Block *block, Block::iterator before)
 Split the operations starting at "before" (inclusive) out of the given block into a new block, and return it. More...
 
virtual void startRootUpdate (Operation *op)
 This method is used to notify the rewriter that an in-place operation modification is about to happen. More...
 
virtual void finalizeRootUpdate (Operation *op)
 This method is used to signal the end of a root update on the given operation. More...
 
virtual void cancelRootUpdate (Operation *op)
 This method cancels a pending root update. More...
 
template<typename CallableT >
void updateRootInPlace (Operation *root, CallableT &&callable)
 This method is a utility wrapper around a root update of an operation. More...
 
template<typename CallbackT >
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResultnotifyMatchFailure (Location loc, CallbackT &&reasonCallback)
 Used to notify the rewriter that the IR failed to be rewritten because of a match failure, and provide a callback to populate a diagnostic with the reason why the failure occurred. More...
 
template<typename CallbackT >
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResultnotifyMatchFailure (Operation *op, CallbackT &&reasonCallback)
 
template<typename ArgT >
LogicalResult notifyMatchFailure (ArgT &&arg, const Twine &msg)
 
template<typename ArgT >
LogicalResult notifyMatchFailure (ArgT &&arg, const char *msg)
 
- Public Member Functions inherited from mlir::OpBuilder
 OpBuilder (MLIRContext *ctx, Listener *listener=nullptr)
 Create a builder with the given context. More...
 
 OpBuilder (Region *region, Listener *listener=nullptr)
 Create a builder and set the insertion point to the start of the region. More...
 
 OpBuilder (Region &region, Listener *listener=nullptr)
 
 OpBuilder (Operation *op, Listener *listener=nullptr)
 Create a builder and set insertion point to the given operation, which will cause subsequent insertions to go right before it. More...
 
 OpBuilder (Block *block, Block::iterator insertPoint, Listener *listener=nullptr)
 
void setListener (Listener *newListener)
 Sets the listener of this builder to the one provided. More...
 
ListenergetListener () const
 Returns the current listener of this builder, or nullptr if this builder doesn't have a listener. More...
 
void clearInsertionPoint ()
 Reset the insertion point to no location. More...
 
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)
 Sets the insertion point to the specified operation, which will cause subsequent insertions to go right before it. More...
 
void setInsertionPointAfter (Operation *op)
 Sets the insertion point to the node after the specified operation, which will cause subsequent insertions to go right after it. More...
 
void setInsertionPointAfterValue (Value val)
 Sets the insertion point to the node after the specified value. More...
 
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
 Return the block the current insertion point belongs to. More...
 
Block::iterator getInsertionPoint () const
 Returns the current insertion point of the builder. More...
 
BlockgetBlock () const
 Returns the current block of the builder. More...
 
BlockcreateBlock (Region *parent, Region::iterator insertPt={}, TypeRange argTypes=llvm::None, ArrayRef< Location > locs=llvm::None)
 Add new block with 'argTypes' arguments and set the insertion point to the end of it. More...
 
BlockcreateBlock (Block *insertBefore, TypeRange argTypes=llvm::None, ArrayRef< Location > locs=llvm::None)
 Add new block with 'argTypes' arguments and set the insertion point to the end of it. More...
 
Operationinsert (Operation *op)
 Insert the given operation at the current insertion point and return it. More...
 
Operationcreate (const OperationState &state)
 Creates an operation given the fields represented as an OperationState. More...
 
Operationcreate (Location loc, StringAttr opName, ValueRange operands, TypeRange types={}, ArrayRef< NamedAttribute > attributes={}, BlockRange successors={}, MutableArrayRef< std::unique_ptr< Region >> regions={})
 Creates an operation with the given fields. 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)
 Create an operation of specific op type at the current insertion point, and immediately try to fold it. More...
 
template<typename OpTy , typename... Args>
std::enable_if_t< OpTy::template hasTrait< OpTrait::OneResult >), ValuecreateOrFold (Location location, Args &&...args)
 Overload to create or fold a single result operation. More...
 
template<typename OpTy , typename... Args>
std::enable_if_t< OpTy::template hasTrait< OpTrait::ZeroResults >), OpTy > createOrFold (Location location, Args &&...args)
 Overload to create or fold a zero result operation. More...
 
LogicalResult tryFold (Operation *op, SmallVectorImpl< Value > &results)
 Attempts to fold the given operation and places new results within 'results'. More...
 
Operationclone (Operation &op, BlockAndValueMapping &mapper)
 Creates a deep copy of the specified operation, remapping any operands that use values outside of the operation using the map that is provided ( leaving them alone if no entry is present). More...
 
Operationclone (Operation &op)
 
OperationcloneWithoutRegions (Operation &op, BlockAndValueMapping &mapper)
 Creates a deep copy of this operation but keep the operation regions empty. More...
 
OperationcloneWithoutRegions (Operation &op)
 
template<typename OpT >
OpT cloneWithoutRegions (OpT op)
 
- Public Member Functions inherited from mlir::Builder
 Builder (MLIRContext *context)
 
 Builder (Operation *op)
 
MLIRContextgetContext () const
 
Location getUnknownLoc ()
 
Location getFusedLoc (ArrayRef< Location > locs, Attribute metadata=Attribute())
 
FloatType getFloat8E5M2Type ()
 
FloatType getBF16Type ()
 
FloatType getF16Type ()
 
FloatType getF32Type ()
 
FloatType getF64Type ()
 
FloatType getF80Type ()
 
FloatType getF128Type ()
 
IndexType getIndexType ()
 
IntegerType getI1Type ()
 
IntegerType getI2Type ()
 
IntegerType getI4Type ()
 
IntegerType getI8Type ()
 
IntegerType getI16Type ()
 
IntegerType getI32Type ()
 
IntegerType getI64Type ()
 
IntegerType getIntegerType (unsigned width)
 
IntegerType getIntegerType (unsigned width, bool isSigned)
 
FunctionType getFunctionType (TypeRange inputs, TypeRange results)
 
TupleType getTupleType (TypeRange 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...
 
template<typename Attr , typename... Args>
Attr getAttr (Args &&...args)
 Get or construct an instance of the attribute Attr 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 (const Twine &bytes)
 
ArrayAttr getArrayAttr (ArrayRef< Attribute > value)
 
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)
 
IntegerAttr getIndexAttr (int64_t value)
 
IntegerAttr getSI32IntegerAttr (int32_t value)
 Signed and unsigned integer attribute getters. More...
 
IntegerAttr getUI32IntegerAttr (uint32_t value)
 
DenseIntElementsAttr getBoolVectorAttr (ArrayRef< bool > values)
 Vector-typed DenseIntElementsAttr getters. values must not be empty. More...
 
DenseIntElementsAttr getI32VectorAttr (ArrayRef< int32_t > values)
 
DenseIntElementsAttr getI64VectorAttr (ArrayRef< int64_t > values)
 
DenseIntElementsAttr getIndexVectorAttr (ArrayRef< int64_t > values)
 
DenseIntElementsAttr getI32TensorAttr (ArrayRef< int32_t > values)
 Tensor-typed DenseIntElementsAttr getters. More...
 
DenseIntElementsAttr getI64TensorAttr (ArrayRef< int64_t > values)
 
DenseIntElementsAttr getIndexTensorAttr (ArrayRef< int64_t > values)
 
DenseBoolArrayAttr getDenseBoolArrayAttr (ArrayRef< bool > values)
 Tensor-typed DenseArrayAttr getters. More...
 
DenseI8ArrayAttr getDenseI8ArrayAttr (ArrayRef< int8_t > values)
 
DenseI16ArrayAttr getDenseI16ArrayAttr (ArrayRef< int16_t > values)
 
DenseI32ArrayAttr getDenseI32ArrayAttr (ArrayRef< int32_t > values)
 
DenseI64ArrayAttr getDenseI64ArrayAttr (ArrayRef< int64_t > values)
 
DenseF32ArrayAttr getDenseF32ArrayAttr (ArrayRef< float > values)
 
DenseF64ArrayAttr getDenseF64ArrayAttr (ArrayRef< double > values)
 
ArrayAttr getAffineMapArrayAttr (ArrayRef< AffineMap > values)
 
ArrayAttr getBoolArrayAttr (ArrayRef< bool > 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)
 
ArrayAttr getTypeArrayAttr (TypeRange 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)
 Returns a single constant result affine map with 0 dimensions and 0 symbols. More...
 
AffineMap getDimIdentityMap ()
 
AffineMap getMultiDimIdentityMap (unsigned rank)
 
AffineMap getSymbolIdentityMap ()
 
AffineMap getSingleDimShiftAffineMap (int64_t shift)
 Returns a map that shifts its (single) input dimension by 'shift'. More...
 
AffineMap getShiftedAffineMap (AffineMap map, int64_t shift)
 Returns an affine map that is a translation (shift) of all result expressions in 'map' by 'shift'. More...
 
- Public Member Functions inherited from mlir::OpBuilder::Listener
virtual ~Listener ()
 
virtual void notifyOperationInserted (Operation *op)
 Notification handler for when an operation is inserted into the builder. More...
 
virtual void notifyBlockCreated (Block *block)
 Notification handler for when a block is created using the builder. More...
 

Protected Member Functions

 RewriterBase (MLIRContext *ctx)
 Initialize the builder with this rewriter as the listener. More...
 
 RewriterBase (const OpBuilder &otherBuilder)
 
 ~RewriterBase () override
 
virtual void notifyRootReplaced (Operation *op, ValueRange replacement)
 These are the callback methods that subclasses can choose to implement if they would like to be notified about certain types of mutations. More...
 
virtual void notifyOperationRemoved (Operation *op)
 This is called on an operation that a rewrite is removing, right before the operation is deleted. More...
 
virtual LogicalResult notifyMatchFailure (Location loc, function_ref< void(Diagnostic &)> reasonCallback)
 Notify the rewriter that the pattern failed to match the given operation, and provide a callback to populate a diagnostic with the reason why the failure occurred. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from mlir::OpBuilder
static OpBuilder atBlockBegin (Block *block, Listener *listener=nullptr)
 Create a builder and set the insertion point to before the first operation in the block but still inside the block. More...
 
static OpBuilder atBlockEnd (Block *block, Listener *listener=nullptr)
 Create a builder and set the insertion point to after the last operation in the block but still inside the block. More...
 
static OpBuilder atBlockTerminator (Block *block, Listener *listener=nullptr)
 Create a builder and set the insertion point to before the block terminator. More...
 
- Protected Attributes inherited from mlir::Builder
MLIRContextcontext
 

Detailed Description

This class coordinates the application of a rewrite on a set of IR, providing a way for clients to track mutations and create new operations.

This class serves as a common API for IR mutation between pattern rewrites and non-pattern rewrites, and facilitates the development of shared IR transformation utilities.

Definition at line 398 of file PatternMatch.h.

Constructor & Destructor Documentation

◆ RewriterBase() [1/2]

mlir::RewriterBase::RewriterBase ( MLIRContext ctx)
inlineexplicitprotected

Initialize the builder with this rewriter as the listener.

Definition at line 538 of file PatternMatch.h.

◆ RewriterBase() [2/2]

mlir::RewriterBase::RewriterBase ( const OpBuilder otherBuilder)
inlineexplicitprotected

Definition at line 539 of file PatternMatch.h.

◆ ~RewriterBase()

RewriterBase::~RewriterBase ( )
overrideprotected

Definition at line 204 of file PatternMatch.cpp.

Member Function Documentation

◆ cancelRootUpdate()

virtual void mlir::RewriterBase::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.

Definition at line 493 of file PatternMatch.h.

Referenced by collapseGenericOpIterationDims(), and mlir::vector::VectorTransferFullPartialRewriter::matchAndRewrite().

◆ cloneRegionBefore() [1/3]

void RewriterBase::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.

Definition at line 351 of file PatternMatch.cpp.

References mlir::Region::cloneInto().

Referenced by mlir::ConversionPatternRewriter::cloneRegionBefore(), collapseGenericOpIterationDims(), fuseWithReshapeByExpansion(), mlir::scf::getParallelForInductionVarOwner(), inlineIfCase(), and inlineWhileCase().

◆ cloneRegionBefore() [2/3]

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

Definition at line 356 of file PatternMatch.cpp.

◆ cloneRegionBefore() [3/3]

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

Definition at line 361 of file PatternMatch.cpp.

References mlir::Block::getParent().

◆ eraseBlock()

void RewriterBase::eraseBlock ( Block block)
virtual

◆ eraseOp()

void RewriterBase::eraseOp ( Operation op)
virtual

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.

Definition at line 259 of file PatternMatch.cpp.

References mlir::Operation::erase(), and mlir::Operation::use_empty().

Referenced by mlir::scf::buildLoopNest(), deleteDeadness(), doSequentialDispatch(), eachHasOnlyOneOfTypes(), findAncestorOpInRegion(), foldMemRefCast(), foldTransferInBoundsAttribute(), mlir::linalg::fuseElementwiseOps(), mlir::linalg::generateLibraryCallName(), getGenericEffectsImpl(), getUnorderedCOOFromType(), getUnrollOrder(), inlineIfCase(), inlineWhileCase(), mlir::sparse_tensor::insertYieldOp(), mlir::scf::insideMutuallyExclusiveBranches(), isComputeOperation(), linalgOpToLoopsImpl(), mlir::transform::gpu::mapForeachToBlocksImpl(), MultiBlockExecuteInliner::matchAndRewrite(), AllocaScopeInliner::matchAndRewrite(), AllocaScopeHoister::matchAndRewrite(), mlir::linalg::LinalgLoweringPattern< OpTy >::matchAndRewrite(), mlir::linalg::LinalgCopyVTWForwardingPattern::matchAndRewrite(), VectorizeConvolution::matchAndRewrite(), mlir::outlineSingleBlockRegion(), mlir::bufferization::populateDynamicDimSizes(), printAtomicReductionRegion(), processParallelLoop(), mlir::replaceForOpWithNewYields(), replaceOpWithRegion(), mlir::scf::ForLoopPipeliningPattern::returningMatchAndRewrite(), rewriteOneForeachThreadToGpuThreads(), simplifyBrToBlockWithSinglePred(), tileAndFuseFirstExtractUseThroughContainingOpBlockArgument(), tileToForeachThreadOpImpl(), mlir::linalg::vectorize(), verifyAllocLikeOp(), and yieldTiledValues().

◆ finalizeRootUpdate()

virtual void mlir::RewriterBase::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.

Definition at line 489 of file PatternMatch.h.

Referenced by mlir::scf::buildLoopNest(), collapseGenericOpIterationDims(), mlir::scf::getParallelForInductionVarOwner(), mlir::scf::insideMutuallyExclusiveBranches(), mlir::linalg::interchangeGenericOp(), mlir::vector::VectorTransferFullPartialRewriter::matchAndRewrite(), mlir::replaceForOpWithNewYields(), and replaceUnitDimIndexOps().

◆ inlineRegionBefore() [1/2]

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

Move the blocks that belong to "region" before the given position in another region "parent".

Move the blocks that belong to "region" before the given position in another region.

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.

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.

Definition at line 339 of file PatternMatch.cpp.

References mlir::Region::getBlocks().

Referenced by createDecl(), declareReduction(), eachHasOnlyOneOfTypes(), mlir::linalg::generalizeNamedOp(), mlir::scf::getParallelForInductionVarOwner(), mlir::ConversionPatternRewriter::inlineRegionBefore(), mlir::scf::insideMutuallyExclusiveBranches(), mlir::lowerAffineLowerBound(), MultiBlockExecuteInliner::matchAndRewrite(), moveRegionToNewWarpOpAndReplaceReturns(), parseInferType(), mlir::linalg::splitReduction(), mlir::linalg::splitReductionByScaling(), verifyGatherOrScatterDims(), and wrapInExecuteRegion().

◆ inlineRegionBefore() [2/2]

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

Definition at line 343 of file PatternMatch.cpp.

References mlir::Block::getParent().

◆ mergeBlockBefore()

void RewriterBase::mergeBlockBefore ( Block source,
Operation op,
ValueRange  argValues = llvm::None 
)

◆ mergeBlocks()

void RewriterBase::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.

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

Definition at line 277 of file PatternMatch.cpp.

References mlir::IRObjectWithUseList< OperandType >::dropAllUses(), mlir::Block::end(), mlir::Block::erase(), mlir::Block::getArguments(), mlir::Block::getNumArguments(), mlir::Block::getOperations(), and mlir::Block::getPredecessors().

Referenced by mlir::scf::buildLoopNest(), collapseGenericOpIterationDims(), declareReduction(), eachHasOnlyOneOfTypes(), getGenericEffectsImpl(), mlir::scf::getParallelForInductionVarOwner(), mlir::scf::insideMutuallyExclusiveBranches(), mlir::outlineSingleBlockRegion(), and simplifyBrToBlockWithSinglePred().

◆ notifyMatchFailure() [1/5]

template<typename CallbackT >
std::enable_if_t<!std::is_convertible<CallbackT, Twine>::value, LogicalResult> mlir::RewriterBase::notifyMatchFailure ( Location  loc,
CallbackT &&  reasonCallback 
)
inline

Used to notify the rewriter that the IR failed to be rewritten because of a match failure, and provide a callback to populate a diagnostic with the reason why the failure occurred.

This method allows for derived rewriters to optionally hook into the reason why a rewrite failed, and display it to users.

Definition at line 512 of file PatternMatch.h.

References mlir::failure(), and value.

Referenced by mlir::linalg::LinalgTransformationFilter::checkAndNotify(), mlir::tosa::checkHasDynamicBatchDims(), collapseGenericOpIterationDims(), createDepthwiseConvCollapseMap(), createElementIPowIFunc(), createLinalgBodyCalculationForElementwiseOp(), createReassociationMapsForCollapse(), elementwiseMatchAndRewriteHelper(), foldMemRefCast(), foldTransferInBoundsAttribute(), mlir::linalg::fuseElementwiseOps(), fuseWithReshapeByExpansion(), mlir::linalg::generalizeNamedOp(), getDimPosition(), getZero(), insertCasts(), mlir::linalg::interchangeGenericOp(), isGenericOpExpandable(), joinShapes(), mlir::lowerAffineLowerBound(), mlir::scf::lowerToLoopsUsingSCFForOp(), mlir::math::ErfPolynomialApproximation::matchAndRewrite(), TransposeOpLowering::matchAndRewrite(), MaterializePadValue::matchAndRewrite(), TransferWriteToVectorStoreLowering::matchAndRewrite(), parseInferType(), processParallelLoop(), reduceMatchAndRewriteHelper(), mlir::linalg::LinalgTileAndFuseTensorOpsPattern::returningMatchAndRewrite(), mlir::linalg::splitReduction(), mlir::linalg::splitReductionByScaling(), mlir::scf::tileConsumerAndFuseProducerGreedilyUsingSCFForOp(), mlir::scf::tileUsingSCFForOp(), and mlir::detail::pdl_function_builder::verifyAsArgs().

◆ notifyMatchFailure() [2/5]

template<typename CallbackT >
std::enable_if_t<!std::is_convertible<CallbackT, Twine>::value, LogicalResult> mlir::RewriterBase::notifyMatchFailure ( Operation op,
CallbackT &&  reasonCallback 
)
inline

Definition at line 522 of file PatternMatch.h.

References mlir::Operation::getLoc().

◆ notifyMatchFailure() [3/5]

template<typename ArgT >
LogicalResult mlir::RewriterBase::notifyMatchFailure ( ArgT &&  arg,
const Twine &  msg 
)
inline

Definition at line 527 of file PatternMatch.h.

References diag().

◆ notifyMatchFailure() [4/5]

template<typename ArgT >
LogicalResult mlir::RewriterBase::notifyMatchFailure ( ArgT &&  arg,
const char *  msg 
)
inline

Definition at line 532 of file PatternMatch.h.

◆ notifyMatchFailure() [5/5]

virtual LogicalResult mlir::RewriterBase::notifyMatchFailure ( Location  loc,
function_ref< void(Diagnostic &)>  reasonCallback 
)
inlineprotectedvirtual

Notify the rewriter that the pattern failed to match the given operation, and provide a callback to populate a diagnostic with the reason why the failure occurred.

This method allows for derived rewriters to optionally hook into the reason why a rewrite failed, and display it to users.

Reimplemented in mlir::ConversionPatternRewriter.

Definition at line 562 of file PatternMatch.h.

References mlir::failure(), and mlir::PatternBenefit::operator=().

◆ notifyOperationRemoved()

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

This is called on an operation that a rewrite is removing, right before the operation is deleted.

At this point, the operation has zero uses.

Definition at line 555 of file PatternMatch.h.

Referenced by hasTensorSemantics().

◆ notifyRootReplaced()

virtual void mlir::RewriterBase::notifyRootReplaced ( Operation op,
ValueRange  replacement 
)
inlineprotectedvirtual

These are the callback methods that subclasses can choose to implement if they would like to be notified about certain types of mutations.

Notify the rewriter that the specified operation is about to be replaced with the set of values potentially produced by new operations. This is called before the uses of the operation have been changed.

Definition at line 551 of file PatternMatch.h.

◆ replaceOp()

void RewriterBase::replaceOp ( Operation op,
ValueRange  newValues 
)
virtual

This method replaces the results of the operation with the specified list of values.

The number of provided values must match the number of results of the operation.

Reimplemented in mlir::ConversionPatternRewriter.

Definition at line 245 of file PatternMatch.cpp.

References mlir::Operation::erase(), mlir::Operation::getNumResults(), and mlir::Operation::replaceAllUsesWith().

Referenced by mlir::scf::buildLoopNest(), canonicalizeLoopBounds(), collapseGenericOpIterationDims(), computeMemRefRankReductionMask(), convertCtlzOp(), createDepthwiseConvCollapseMap(), createReassociationMapsForCollapse(), createSortFunc(), eachHasOnlyOneOfTypes(), elementwiseMatchAndRewriteHelper(), mlir::bufferization::eliminateAllocTensors(), executeGetOperandsResults(), foldInsertAfterExtractSlice(), foldMemRefCast(), mlir::bufferization::foldToMemrefToTensorPair(), foldTransferInBoundsAttribute(), forwardTerminatorOperands(), mlir::linalg::fuseElementwiseOps(), fuseWithReshapeByExpansion(), mlir::linalg::generalizeNamedOp(), generateCollapsedIndexingRegion(), mlir::linalg::generateLibraryCallName(), getDimPosition(), getGenericEffectsImpl(), mlir::scf::getParallelForInductionVarOwner(), getUnorderedCOOFromType(), getUnrollOrder(), mlir::vector::getVectorReductionOp(), getZero(), inlineWhileCase(), insertCasts(), mlir::scf::insideMutuallyExclusiveBranches(), isTrivialSubViewOp(), joinShapes(), linalgOpToLoopsImpl(), mlir::lowerAffineLowerBound(), makeI64ArrayAttr(), ConcatOptimization::matchAndRewrite(), ReduceMultiDimReductionRank::matchAndRewrite(), ConvertSameRankInsertStridedSliceIntoShuffle::matchAndRewrite(), NoOpOptimization::matchAndRewrite(), AddZeroOptimization::matchAndRewrite(), MulOneOptimization::matchAndRewrite(), TwoDimMultiReductionToElementWise::matchAndRewrite(), TwoDimMultiReductionToReduction::matchAndRewrite(), MaxPool2dIsNoOp::matchAndRewrite(), ClampIsNoOp::matchAndRewrite(), AllocaScopeInliner::matchAndRewrite(), mlir::vector::ContractionOpToOuterProductOpLowering::matchAndRewrite(), AllocaScopeHoister::matchAndRewrite(), mlir::vector::ContractionOpLowering::matchAndRewrite(), CanonicalizeContractAdd< AddOpType >::matchAndRewrite(), mlir::linalg::ExtractSliceOfPadTensorSwapPattern::matchAndRewrite(), VectorizeConvolution::matchAndRewrite(), TransferReadToVectorLoadLowering::matchAndRewrite(), VectorCreateMaskOpConversion::matchAndRewrite(), moveRegionToNewWarpOpAndAppendReturns(), SliceCanonicalizer::operator()(), parseGlobalMemrefOpTypeAndInitialValue(), parseInferType(), mlir::bufferization::populateDynamicDimSizes(), mlir::replaceForOpWithNewYields(), replaceIndexOpsByInductionVariables(), mlir::bufferization::replaceOpWithBufferizedValues(), replaceOpWithRegion(), mlir::scf::ForLoopPipeliningPattern::returningMatchAndRewrite(), mlir::linalg::LinalgPaddingPattern::returningMatchAndRewrite(), mlir::linalg::DownscaleSizeOneWindowed2DConvolution< Conv2DOp, Conv1DOp >::returningMatchAndRewrite(), mlir::linalg::DownscaleDepthwiseConv2DNhwcHwcOp::returningMatchAndRewrite(), PadOpVectorizationWithTransferWritePattern::rewriteUser(), mlir::linalg::splitOp(), mlir::linalg::splitReductionByScaling(), tileAndFuseFirstExtractUse(), tileAndFuseFirstExtractUseThroughContainingOpBlockArgument(), mlir::scf::tileConsumerAndFuseProducerGreedilyUsingSCFForOp(), tilePadOp(), mlir::transform::tileToForeachThreadOpImpl(), updateExpandedGenericOpRegion(), mlir::linalg::vectorize(), mlir::linalg::vectorizeCopy(), verifyAllocLikeOp(), verifyAttributions(), verifyGatherOrScatterDims(), and wrapInExecuteRegion().

◆ replaceOpWithIf() [1/2]

void RewriterBase::replaceOpWithIf ( Operation op,
ValueRange  newValues,
bool *  allUsesReplaced,
llvm::unique_function< bool(OpOperand &) const >  functor 
)
virtual

This method replaces the uses of the results of op with the values in newValues when the provided functor returns true for a specific use.

The number of values in newValues is required to match the number of results of op. allUsesReplaced, if non-null, is set to true if all of the uses of op were replaced. Note that in some rewriters, the given 'functor' may be stored beyond the lifetime of the rewrite being applied. As such, the function should not capture by reference and instead use value capture as necessary.

The number of values in newValues is required to match the number of results of op.

Reimplemented in mlir::ConversionPatternRewriter.

Definition at line 212 of file PatternMatch.cpp.

References mlir::Operation::getNumResults(), and mlir::Operation::getResults().

Referenced by mlir::scf::buildLoopNest(), and mlir::linalg::offsetIndices().

◆ replaceOpWithIf() [2/2]

void mlir::RewriterBase::replaceOpWithIf ( Operation op,
ValueRange  newValues,
llvm::unique_function< bool(OpOperand &) const >  functor 
)
inline

Definition at line 430 of file PatternMatch.h.

◆ replaceOpWithinBlock()

void RewriterBase::replaceOpWithinBlock ( Operation op,
ValueRange  newValues,
Block block,
bool *  allUsesReplaced = nullptr 
)

This method replaces the uses of the results of op with the values in newValues when a use is nested within the given block.

The number of values in newValues is required to match the number of results of op. If all uses of this operation are replaced, the operation is erased.

Definition at line 235 of file PatternMatch.cpp.

References mlir::detail::IROperandBase::getOwner(), mlir::Block::getParentOp(), and mlir::Operation::isProperAncestor().

Referenced by getZero().

◆ replaceOpWithNewOp()

template<typename OpTy , typename... Args>
OpTy mlir::RewriterBase::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.

Definition at line 451 of file PatternMatch.h.

References mlir::Operation::getLoc().

Referenced by addResumeFunction(), mlir::scf::buildLoopNest(), calculateExpandedAccessIndices(), canonicalizeMinMaxOp(), mlir::canonicalizeSetAndOperands(), castBoolToIntN(), castDataPtr(), constructResultVector(), convertCmpPredicate(), convertStructType(), convertTanhOp(), createConst(), createDecl(), createDepthwiseConvCollapseMap(), createElementIPowIFunc(), createI32Constant(), createReassociationMapsForCollapse(), createSortFunc(), declareReduction(), mlir::ValueDecomposer::decomposeValue(), dropSwitchCasesThatMatchDefault(), eachHasOnlyOneOfTypes(), encodeKernelName(), extractCompositeElement(), findAncestorOpInRegion(), foldExtractStridedOpFromInsertChain(), foldInsertAfterExtractSlice(), foldMemRefCast(), foldSwitch(), mlir::bufferization::foldToMemrefToTensorPair(), foldTransferInBoundsAttribute(), getAsValue(), getDefaultABIAttrs(), getDimPosition(), getFirstIntValue(), getGenericEffectsImpl(), mlir::scf::getParallelForInductionVarOwner(), getPtrToElementType(), getScalarOrVectorI32Constant(), getSrcVectorElementType(), getUnorderedCOOFromType(), hasSameBitwidth(), mlir::ComplexStructBuilder::imaginary(), insertCasts(), mlir::scf::insideMutuallyExclusiveBranches(), mlir::linalg::interchangeGenericOp(), mlir::vector::isBroadcastableTo(), isTrivialSubViewOp(), joinShapes(), linalgOpToLoopsImpl(), mlir::lowerAffineLowerBound(), matchAndReplaceDepthwiseConv(), SwapExtractSliceOfFill::matchAndRewrite(), mlir::linalg::LinalgOpToLibraryCallRewrite::matchAndRewrite(), InnerOuterDimReductionConversion::matchAndRewrite(), ConcatOptimization::matchAndRewrite(), TransferReadPermutationLowering::matchAndRewrite(), DecomposeDifferentRankInsertStridedSlice::matchAndRewrite(), ReshapeReshapeOptimization::matchAndRewrite(), mlir::GPUReturnOpLowering::matchAndRewrite(), ReshapeConstOptimization::matchAndRewrite(), ReduceMultiDimReductionRank::matchAndRewrite(), TransferWritePermutationLowering::matchAndRewrite(), mlir::ComposeReassociativeReshapeOps< ReshapeOpTy >::matchAndRewrite(), Convert1DExtractStridedSliceIntoShuffle::matchAndRewrite(), TransferOpReduceRank::matchAndRewrite(), mlir::ComposeCollapseOfExpandOp< CollapseOpTy, ExpandOpTy >::matchAndRewrite(), MaterializePadValue::matchAndRewrite(), mlir::ComposeExpandOfCollapseOp< ExpandOpTy, CollapseOpTy >::matchAndRewrite(), OneDimMultiReductionToTwoDim::matchAndRewrite(), ConvertAddressOf::matchAndRewrite(), ConvertAccessChain::matchAndRewrite(), ClampClampOptimization::matchAndRewrite(), ConvertStore::matchAndRewrite(), YieldOpLowering::matchAndRewrite(), mlir::linalg::PadOpTransformationPattern::matchAndRewrite(), mlir::linalg::GeneralizePadOpPattern::matchAndRewrite(), SelectI1Simplify::matchAndRewrite(), SelectToExtUI::matchAndRewrite(), TransferReadToVectorLoadLowering::matchAndRewrite(), VectorLoadToMemrefLoadLowering::matchAndRewrite(), VectorStoreToMemrefStoreLowering::matchAndRewrite(), CollapseShapeOpMemRefCastFolder::matchAndRewrite(), TransferWriteToVectorStoreLowering::matchAndRewrite(), BubbleDownVectorBitCastForExtract::matchAndRewrite(), BubbleDownBitCastForStridedSliceExtract::matchAndRewrite(), BubbleUpBitCastForStridedSliceInsert::matchAndRewrite(), DeduplicateAffineMinMaxExpressions< T >::matchAndRewrite(), MergeAffineMinMaxOp< T >::matchAndRewrite(), CanonicalizeAffineMinMaxOpExprAndTermOrder< T >::matchAndRewrite(), CanonicalizeSingleResultAffineMinMaxOp< T >::matchAndRewrite(), SubViewCanonicalizer::operator()(), outlineExecuteOp(), parseGlobalMemrefOpTypeAndInitialValue(), parseInferType(), mlir::bufferization::populateDynamicDimSizes(), printAtomicReductionRegion(), produceSliceErrorMsg(), reduceMatchAndRewriteHelper(), replaceUnitDimIndexOps(), replaceWithLoadOrStore(), reshapeLowerToHigher(), PadOpVectorizationWithTransferWritePattern::rewriteUser(), PadOpVectorizationWithInsertSlicePattern::rewriteUser(), mlir::DataDescriptor::setSize(), simplifyPassThroughBr(), simplifyPassThroughSwitch(), simplifySwitchFromDefaultSwitchOnSameCondition(), simplifySwitchFromSwitchOnSameCondition(), simplifySwitchWithOnlyDefault(), splatZero(), toUnsignedPred(), GenericPadOpVectorizationPattern::tryVectorizeCopy(), verifyGatherOrScatterDims(), verifyTensorReshapeOp(), and wrapExternalFunction().

◆ splitBlock()

Block * RewriterBase::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.

Definition at line 320 of file PatternMatch.cpp.

References mlir::Operation::getNumResults(), mlir::Operation::getResult(), mlir::Operation::getResults(), and mlir::Block::splitBlock().

Referenced by declareReduction(), eachHasOnlyOneOfTypes(), MultiBlockExecuteInliner::matchAndRewrite(), and mlir::ConversionPatternRewriter::splitBlock().

◆ startRootUpdate()

virtual void mlir::RewriterBase::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.

Definition at line 484 of file PatternMatch.h.

Referenced by mlir::scf::buildLoopNest(), collapseGenericOpIterationDims(), mlir::scf::getParallelForInductionVarOwner(), mlir::scf::insideMutuallyExclusiveBranches(), mlir::linalg::interchangeGenericOp(), mlir::vector::VectorTransferFullPartialRewriter::matchAndRewrite(), mlir::replaceForOpWithNewYields(), and replaceUnitDimIndexOps().

◆ updateRootInPlace()

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

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