MLIR 22.0.0git
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.

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.
void applyCostModel (CostModel model)
 Apply a cost model to the patterns within this applicator.
void applyDefaultCostModel ()
 Apply the default cost model that solely uses the pattern's static benefit.
void walkAllPatterns (function_ref< void(const Pattern &)> walk)
 Walk all of the patterns within the applicator.

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

Definition at line 27 of file PatternApplicator.cpp.

◆ ~PatternApplicator()

PatternApplicator::~PatternApplicator ( )
default

Member Function Documentation

◆ applyCostModel()

void PatternApplicator::applyCostModel ( CostModel model)

Apply a cost model to the patterns within this applicator.

Definition at line 58 of file PatternApplicator.cpp.

References mlir::Pattern::getBenefit(), mlir::PatternBenefit::isImpossibleToMatch(), lhs, logImpossibleToMatch(), and rhs.

Referenced by applyDefaultCostModel().

◆ 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 132 of file PatternApplicator.cpp.

References mlir::MLIRContext::executeAction(), mlir::Pattern::getBenefit(), mlir::PatternBenefit::getBenefit(), mlir::Operation::getContext(), mlir::Pattern::getDebugName(), getDumpRootOp(), mlir::OpBuilder::getListener(), mlir::Operation::getName(), logSucessfulPatternApplication(), mlir::detail::PDLByteCode::MatchResult::pattern, result, mlir::OpBuilder::setInsertionPoint(), and mlir::OpBuilder::setListener().

Referenced by mlir::walkAndApplyPatterns().

◆ walkAllPatterns()

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

Walk all of the patterns within the applicator.

Definition at line 119 of file PatternApplicator.cpp.

References mlir::detail::walk().


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