MLIR
15.0.0git
|
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... | |
This class manages the application of a group of rewrite patterns, with a user-provided cost model.
Definition at line 28 of file PatternApplicator.h.
using mlir::PatternApplicator::CostModel = function_ref<PatternBenefit(const Pattern &)> |
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 34 of file PatternApplicator.h.
|
explicit |
Definition at line 23 of file PatternApplicator.cpp.
References mlir::FrozenRewritePatternSet::getPDLByteCode(), and ~PatternApplicator().
|
default |
Referenced by PatternApplicator().
Apply a cost model to the patterns within this applicator.
Definition at line 52 of file PatternApplicator.cpp.
References mlir::detail::enumerate(), mlir::Pattern::getBenefit(), mlir::FrozenRewritePatternSet::getMatchAnyOpNativePatterns(), mlir::FrozenRewritePatternSet::getOpSpecificNativePatterns(), mlir::FrozenRewritePatternSet::getPDLByteCode(), mlir::PatternBenefit::isImpossibleToMatch(), and logImpossibleToMatch().
|
inline |
Apply the default cost model that solely uses the pattern's static benefit.
Definition at line 59 of file PatternApplicator.h.
References mlir::Pattern::getBenefit(), and mlir::detail::walk().
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 126 of file PatternApplicator.cpp.
References mlir::failed(), mlir::failure(), mlir::Pattern::getBenefit(), getDumpRootOp(), mlir::Operation::getName(), mlir::FrozenRewritePatternSet::getPDLByteCode(), logSucessfulPatternApplication(), mlir::detail::PDLByteCode::match(), mlir::detail::PDLByteCode::MatchResult::pattern, mlir::detail::PDLByteCode::rewrite(), mlir::OpBuilder::setInsertionPoint(), mlir::succeeded(), and mlir::success().
void PatternApplicator::walkAllPatterns | ( | function_ref< void(const Pattern &)> | walk | ) |
Walk all of the patterns within the applicator.
Definition at line 113 of file PatternApplicator.cpp.
References mlir::FrozenRewritePatternSet::getMatchAnyOpNativePatterns(), mlir::FrozenRewritePatternSet::getOpSpecificNativePatterns(), mlir::FrozenRewritePatternSet::getPDLByteCode(), and mlir::detail::walk().