MLIR 22.0.0git
ReductionPatternInterface.h
Go to the documentation of this file.
1//===- ReducePatternInterface.h - Collecting Reduce Patterns ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef MLIR_REDUCER_REDUCTIONPATTERNINTERFACE_H
10#define MLIR_REDUCER_REDUCTIONPATTERNINTERFACE_H
11
13#include "mlir/Reducer/Tester.h"
14
15namespace mlir {
16
18
19/// This is used to report the reduction patterns for a Dialect. While using
20/// mlir-reduce to reduce a module, we may want to transform certain cases into
21/// simpler forms by applying certain rewrite patterns. Implement the
22/// `populateReductionPatterns` to report those patterns by adding them to the
23/// RewritePatternSet.
24///
25/// Example:
26/// MyDialectReductionPattern::populateReductionPatterns(
27/// RewritePatternSet &patterns) {
28/// patterns.add<TensorOpReduction>(patterns.getContext());
29/// }
30///
31/// For DRR, mlir-tblgen will generate a helper function
32/// `populateWithGenerated` which has the same signature therefore you can
33/// delegate to the helper function as well.
34///
35/// Example:
36/// MyDialectReductionPattern::populateReductionPatterns(
37/// RewritePatternSet &patterns) {
38/// // Include the autogen file somewhere above.
39/// populateWithGenerated(patterns);
40/// }
42 : public DialectInterface::Base<DialectReductionPatternInterface> {
43public:
44 /// Patterns provided here are intended to transform operations from a complex
45 /// form to a simpler form, without breaking the semantics of the program
46 /// being reduced. For example, you may want to replace the
47 /// tensor<?xindex> with a known rank and type, e.g. tensor<1xi32>, or
48 /// replacing an operation with a constant.
50
51 /// This method extends `populateReductionPatterns` by allowing reduction
52 /// patterns to use a `Tester` instance. Some reduction patterns may need to
53 /// run tester to determine whether certain transformations preserve the
54 /// "interesting" behavior of the program. This is mostly useful when pattern
55 /// should choose between multiple modifications.
58
59protected:
61};
62} // namespace mlir
63
64#endif // MLIR_REDUCER_REDUCTIONPATTERNINTERFACE_H
detail::DialectInterfaceBase< ConcreteType, DialectInterface > Base
The base class used for all derived interface types.
virtual void populateReductionPatterns(RewritePatternSet &patterns) const =0
Patterns provided here are intended to transform operations from a complex form to a simpler form,...
virtual void populateReductionPatternsWithTester(RewritePatternSet &patterns, Tester &tester) const
This method extends populateReductionPatterns by allowing reduction patterns to use a Tester instance...
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition Dialect.h:38
This class is used to keep track of the testing environment of the tool.
Definition Tester.h:31
DialectInterfaceBase< ConcreteType, DialectInterface > Base
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns