xref: /llvm-project/mlir/test/lib/Dialect/Math/TestAlgebraicSimplification.cpp (revision 09dfc5713d7e2342bea4c8447d1ed76c85eb8225)
1d94426d2SEugene Zhulenev //===- TestAlgebraicSimplification.cpp - Test algebraic simplification ----===//
2d94426d2SEugene Zhulenev //
3d94426d2SEugene Zhulenev // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4d94426d2SEugene Zhulenev // See https://llvm.org/LICENSE.txt for license information.
5d94426d2SEugene Zhulenev // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d94426d2SEugene Zhulenev //
7d94426d2SEugene Zhulenev //===----------------------------------------------------------------------===//
8d94426d2SEugene Zhulenev //
9d94426d2SEugene Zhulenev // This file contains test passes for algebraic simplification patterns.
10d94426d2SEugene Zhulenev //
11d94426d2SEugene Zhulenev //===----------------------------------------------------------------------===//
12d94426d2SEugene Zhulenev 
13d94426d2SEugene Zhulenev #include "mlir/Dialect/Math/IR/Math.h"
14d94426d2SEugene Zhulenev #include "mlir/Dialect/Math/Transforms/Passes.h"
1599ef9eebSMatthias Springer #include "mlir/Dialect/Vector/IR/VectorOps.h"
16d94426d2SEugene Zhulenev #include "mlir/Pass/Pass.h"
17d94426d2SEugene Zhulenev #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
18d94426d2SEugene Zhulenev 
19d94426d2SEugene Zhulenev using namespace mlir;
20d94426d2SEugene Zhulenev 
21d94426d2SEugene Zhulenev namespace {
22d94426d2SEugene Zhulenev struct TestMathAlgebraicSimplificationPass
2387d6bf37SRiver Riddle     : public PassWrapper<TestMathAlgebraicSimplificationPass, OperationPass<>> {
245e50dd04SRiver Riddle   MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
255e50dd04SRiver Riddle       TestMathAlgebraicSimplificationPass)
265e50dd04SRiver Riddle 
2741574554SRiver Riddle   void runOnOperation() override;
28d94426d2SEugene Zhulenev   void getDependentDialects(DialectRegistry &registry) const override {
29d94426d2SEugene Zhulenev     registry.insert<vector::VectorDialect, math::MathDialect>();
30d94426d2SEugene Zhulenev   }
31d94426d2SEugene Zhulenev   StringRef getArgument() const final {
32d94426d2SEugene Zhulenev     return "test-math-algebraic-simplification";
33d94426d2SEugene Zhulenev   }
34d94426d2SEugene Zhulenev   StringRef getDescription() const final {
35d94426d2SEugene Zhulenev     return "Test math algebraic simplification";
36d94426d2SEugene Zhulenev   }
37d94426d2SEugene Zhulenev };
38be0a7e9fSMehdi Amini } // namespace
39d94426d2SEugene Zhulenev 
4041574554SRiver Riddle void TestMathAlgebraicSimplificationPass::runOnOperation() {
41d94426d2SEugene Zhulenev   RewritePatternSet patterns(&getContext());
42d94426d2SEugene Zhulenev   populateMathAlgebraicSimplificationPatterns(patterns);
43*09dfc571SJacques Pienaar   (void)applyPatternsGreedily(getOperation(), std::move(patterns));
44d94426d2SEugene Zhulenev }
45d94426d2SEugene Zhulenev 
46d94426d2SEugene Zhulenev namespace mlir {
47d94426d2SEugene Zhulenev namespace test {
48d94426d2SEugene Zhulenev void registerTestMathAlgebraicSimplificationPass() {
49d94426d2SEugene Zhulenev   PassRegistration<TestMathAlgebraicSimplificationPass>();
50d94426d2SEugene Zhulenev }
51d94426d2SEugene Zhulenev } // namespace test
52d94426d2SEugene Zhulenev } // namespace mlir
53