MLIR  20.0.0git
Public Types | Public Member Functions | List of all members
mlir::PatternApplicator Class Reference

This class manages the application of a group of rewrite patterns, with a user-provided cost model. More...

#include "mlir/Rewrite/PatternApplicator.h"

Public Types

using CostModel = function_ref< PatternBenefit(const Pattern &)>
 The cost model dynamically assigns a PatternBenefit to a particular pattern. More...
 

Public Member Functions

 PatternApplicator (const FrozenRewritePatternSet &frozenPatternList)
 
 ~PatternApplicator ()
 
LogicalResult matchAndRewrite (Operation *op, PatternRewriter &rewriter, function_ref< bool(const Pattern &)> canApply={}, function_ref< void(const Pattern &)> onFailure={}, function_ref< LogicalResult(const Pattern &)> onSuccess={})
 Attempt to match and rewrite the given op with any pattern, allowing a predicate to decide if a pattern can be applied or not, and hooks for if the pattern match was a success or failure. More...
 
void applyCostModel (CostModel model)
 Apply a cost model to the patterns within this applicator. More...
 
void applyDefaultCostModel ()
 Apply the default cost model that solely uses the pattern's static benefit. More...
 
void walkAllPatterns (function_ref< void(const Pattern &)> walk)
 Walk all of the patterns within the applicator. More...
 

Detailed Description

This class manages the application of a group of rewrite patterns, with a user-provided cost model.

Definition at line 49 of file PatternApplicator.h.

Member Typedef Documentation

◆ CostModel

The cost model dynamically assigns a PatternBenefit to a particular pattern.

Users can query contained patterns and pass analysis results to applyCostModel. Patterns to be discarded should have a benefit of impossibleToMatch.

Definition at line 55 of file PatternApplicator.h.

Constructor & Destructor Documentation

◆ PatternApplicator()

PatternApplicator::PatternApplicator ( const FrozenRewritePatternSet frozenPatternList)
explicit

◆ ~PatternApplicator()

PatternApplicator::~PatternApplicator ( )
default

Member Function Documentation

◆ applyCostModel()

void PatternApplicator::applyCostModel ( CostModel  model)

◆ applyDefaultCostModel()

void mlir::PatternApplicator::applyDefaultCostModel ( )
inline

Apply the default cost model that solely uses the pattern's static benefit.

Definition at line 80 of file PatternApplicator.h.

References applyCostModel(), and mlir::Pattern::getBenefit().

Referenced by mlir::walkAndApplyPatterns().

◆ matchAndRewrite()

LogicalResult PatternApplicator::matchAndRewrite ( Operation op,
PatternRewriter rewriter,
function_ref< bool(const Pattern &)>  canApply = {},
function_ref< void(const Pattern &)>  onFailure = {},
function_ref< LogicalResult(const Pattern &)>  onSuccess = {} 
)

Attempt to match and rewrite the given op with any pattern, allowing a predicate to decide if a pattern can be applied or not, and hooks for if the pattern match was a success or failure.

canApply: called before each match and rewrite attempt; return false to skip pattern. onFailure: called when a pattern fails to match to perform cleanup. onSuccess: called when a pattern match succeeds; return failure() to invalidate the match and try another pattern.

Operation specific patterns.

Operation agnostic patterns.

PDL patterns.

Definition at line 130 of file PatternApplicator.cpp.

References mlir::MLIRContext::executeAction(), mlir::Pattern::getBenefit(), mlir::Operation::getContext(), mlir::Pattern::getDebugName(), getDumpRootOp(), mlir::Operation::getName(), mlir::FrozenRewritePatternSet::getPDLByteCode(), logSucessfulPatternApplication(), mlir::detail::PDLByteCode::match(), mlir::RewritePattern::matchAndRewrite(), mlir::detail::PDLByteCode::MatchResult::pattern, mlir::detail::PDLByteCode::rewrite(), and mlir::OpBuilder::setInsertionPoint().

Referenced by mlir::walkAndApplyPatterns().

◆ walkAllPatterns()

void PatternApplicator::walkAllPatterns ( function_ref< void(const Pattern &)>  walk)

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