20 #define GEN_PASS_DEF_CANONICALIZER
21 #include "mlir/Transforms/Passes.h.inc"
28 struct Canonicalizer :
public impl::CanonicalizerBase<Canonicalizer> {
29 Canonicalizer() =
default;
34 this->topDownProcessingEnabled =
config.useTopDownTraversal;
35 this->enableRegionSimplification =
config.enableRegionSimplification;
36 this->maxIterations =
config.maxIterations;
37 this->maxNumRewrites =
config.maxNumRewrites;
38 this->disabledPatterns = disabledPatterns;
39 this->enabledPatterns = enabledPatterns;
44 LogicalResult initialize(
MLIRContext *context)
override {
46 config.useTopDownTraversal = topDownProcessingEnabled;
47 config.enableRegionSimplification = enableRegionSimplification;
48 config.maxIterations = maxIterations;
49 config.maxNumRewrites = maxNumRewrites;
53 dialect->getCanonicalizationPatterns(owningPatterns);
55 op.getCanonicalizationPatterns(owningPatterns, context);
57 patterns = std::make_shared<FrozenRewritePatternSet>(
58 std::move(owningPatterns), disabledPatterns, enabledPatterns);
61 void runOnOperation()
override {
62 LogicalResult converged =
65 if (testConvergence && failed(converged))
69 std::shared_ptr<const FrozenRewritePatternSet>
patterns;
75 return std::make_unique<Canonicalizer>();
83 return std::make_unique<Canonicalizer>(
config, disabledPatterns,
This class allows control over how the GreedyPatternRewriteDriver works.
MLIRContext is the top-level object for a collection of MLIR operations.
std::vector< Dialect * > getLoadedDialects()
Return information about all IR dialects loaded in the context.
ArrayRef< RegisteredOperationName > getRegisteredOperations()
Return a sorted array containing the information about all registered operations.
This is a "type erased" representation of a registered operation.
Include the generated interface declarations.
const FrozenRewritePatternSet GreedyRewriteConfig config
LogicalResult applyPatternsGreedily(Region ®ion, const FrozenRewritePatternSet &patterns, GreedyRewriteConfig config=GreedyRewriteConfig(), bool *changed=nullptr)
Rewrite ops in the given region, which must be isolated from above, by repeatedly applying the highes...
const FrozenRewritePatternSet & patterns
std::unique_ptr< Pass > createCanonicalizerPass()
Creates an instance of the Canonicalizer pass, configured with default settings (which can be overrid...