My Project
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mlir::RewritePattern Class Reference

#include <PatternMatch.h>

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

Public Member Functions

virtual void rewrite (Operation *op, std::unique_ptr< PatternState > state, PatternRewriter &rewriter) const
 
virtual void rewrite (Operation *op, PatternRewriter &rewriter) const
 
PatternMatchResult match (Operation *op) const override
 
virtual PatternMatchResult matchAndRewrite (Operation *op, PatternRewriter &rewriter) const
 
ArrayRef< OperationNamegetGeneratedOps () const
 
- Public Member Functions inherited from mlir::Pattern
PatternBenefit getBenefit () const
 
OperationName getRootKind () const
 
virtual ~Pattern ()
 
PatternMatchResult matchSuccess (std::unique_ptr< PatternState > state={}) const
 This method indicates that a match was found and has the specified cost. More...
 

Protected Member Functions

 RewritePattern (StringRef rootName, PatternBenefit benefit, MLIRContext *context)
 
 RewritePattern (StringRef rootName, ArrayRef< StringRef > generatedNames, PatternBenefit benefit, MLIRContext *context)
 
- Protected Member Functions inherited from mlir::Pattern
 Pattern (StringRef rootName, PatternBenefit benefit, MLIRContext *context)
 

Protected Attributes

SmallVector< OperationName, 2 > generatedOps
 

Additional Inherited Members

- Static Public Member Functions inherited from mlir::Pattern
static PatternMatchResult matchFailure ()
 This method indicates that no match was found. More...
 

Detailed Description

RewritePattern is the common base class for all DAG to DAG replacements. There are two possible usages of this class:

Constructor & Destructor Documentation

◆ RewritePattern() [1/2]

mlir::RewritePattern::RewritePattern ( StringRef  rootName,
PatternBenefit  benefit,
MLIRContext context 
)
inlineprotected

Patterns must specify the root operation name they match against, and can also specify the benefit of the pattern matching.

◆ RewritePattern() [2/2]

RewritePattern::RewritePattern ( StringRef  rootName,
ArrayRef< StringRef >  generatedNames,
PatternBenefit  benefit,
MLIRContext context 
)
protected

Patterns must specify the root operation name they match against, and can also specify the benefit of the pattern matching. They can also specify the names of operations that may be generated during a successful rewrite.

Member Function Documentation

◆ getGeneratedOps()

ArrayRef<OperationName> mlir::RewritePattern::getGeneratedOps ( ) const
inline

Return a list of operations that may be generated when rewriting an operation instance with this pattern.

◆ match()

PatternMatchResult RewritePattern::match ( Operation op) const
overridevirtual

Attempt to match against code rooted at the specified operation, which is the same operation code as getRootKind(). On failure, this returns a None value. On success, it returns a (possibly null) pattern-specific state wrapped in an Optional. This state is passed back into the rewrite function if this match is selected.

Implements mlir::Pattern.

Reimplemented in mlir::OpRewritePattern< SourceOp >, mlir::OpRewritePattern< FakeQuantOp >, mlir::OpRewritePattern< CopyOp >, mlir::OpRewritePattern< IndexedGenericOp >, mlir::OpRewritePattern< vector::TupleGetOp >, mlir::OpRewritePattern< InsertStridedSliceOp >, mlir::OpRewritePattern< LinalgOp >, mlir::OpRewritePattern< vector::TransferReadOp >, mlir::OpRewritePattern< StridedSliceOp >, and mlir::OpRewritePattern< vector::TransferWriteOp >.

◆ matchAndRewrite()

virtual PatternMatchResult mlir::RewritePattern::matchAndRewrite ( Operation op,
PatternRewriter rewriter 
) const
inlinevirtual

◆ rewrite() [1/2]

void RewritePattern::rewrite ( Operation op,
std::unique_ptr< PatternState state,
PatternRewriter rewriter 
) const
virtual

Rewrite the IR rooted at the specified operation with the result of this pattern, generating any new operations with the specified rewriter. If an unexpected error is encountered (an internal compiler error), it is emitted through the normal MLIR diagnostic hooks and the IR is left in a valid state.

Reimplemented in mlir::OpRewritePattern< SourceOp >, mlir::OpRewritePattern< FakeQuantOp >, mlir::OpRewritePattern< CopyOp >, mlir::OpRewritePattern< IndexedGenericOp >, mlir::OpRewritePattern< vector::TupleGetOp >, mlir::OpRewritePattern< InsertStridedSliceOp >, mlir::OpRewritePattern< LinalgOp >, mlir::OpRewritePattern< vector::TransferReadOp >, mlir::OpRewritePattern< StridedSliceOp >, and mlir::OpRewritePattern< vector::TransferWriteOp >.

◆ rewrite() [2/2]

void RewritePattern::rewrite ( Operation op,
PatternRewriter rewriter 
) const
virtual

Rewrite the IR rooted at the specified operation with the result of this pattern, generating any new operations with the specified builder. If an unexpected error is encountered (an internal compiler error), it is emitted through the normal MLIR diagnostic hooks and the IR is left in a valid state.

Reimplemented in mlir::OpRewritePattern< SourceOp >, mlir::OpRewritePattern< FakeQuantOp >, mlir::OpRewritePattern< CopyOp >, mlir::OpRewritePattern< IndexedGenericOp >, mlir::OpRewritePattern< vector::TupleGetOp >, mlir::OpRewritePattern< InsertStridedSliceOp >, mlir::OpRewritePattern< LinalgOp >, mlir::OpRewritePattern< vector::TransferReadOp >, mlir::OpRewritePattern< StridedSliceOp >, and mlir::OpRewritePattern< vector::TransferWriteOp >.

Member Data Documentation

◆ generatedOps

SmallVector<OperationName, 2> mlir::RewritePattern::generatedOps
protected

A list of the potential operations that may be generated when rewriting an op with this pattern.


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