MLIR
20.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 49 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 55 of file PatternApplicator.h.
|
explicit |
Definition at line 23 of file PatternApplicator.cpp.
References mlir::FrozenRewritePatternSet::getPDLByteCode().
|
default |
void PatternApplicator::applyCostModel | ( | CostModel | model | ) |
Apply a cost model to the patterns within this applicator.
Definition at line 56 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().
Referenced by 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().
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().
void PatternApplicator::walkAllPatterns | ( | function_ref< void(const Pattern &)> | walk | ) |
Walk all of the patterns within the applicator.
Definition at line 117 of file PatternApplicator.cpp.
References mlir::FrozenRewritePatternSet::getMatchAnyOpNativePatterns(), mlir::FrozenRewritePatternSet::getOpSpecificNativePatterns(), mlir::FrozenRewritePatternSet::getPDLByteCode(), and mlir::detail::walk().