1 //===- TestPolynomialApproximation.cpp - Test math ops approximations -----===//
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 // This file contains test passes for expanding math operations into
10 // polynomial approximations.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
15 #include "mlir/Dialect/Math/IR/Math.h"
16 #include "mlir/Dialect/Math/Transforms/Passes.h"
17 #include "mlir/Dialect/Vector/VectorOps.h"
18 #include "mlir/Pass/Pass.h"
19 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
20 
21 using namespace mlir;
22 
23 namespace {
24 struct TestMathPolynomialApproximationPass
25     : public PassWrapper<TestMathPolynomialApproximationPass, FunctionPass> {
26   void runOnFunction() override;
27   void getDependentDialects(DialectRegistry &registry) const override {
28     registry
29         .insert<vector::VectorDialect, math::MathDialect, LLVM::LLVMDialect>();
30   }
31 };
32 } // end anonymous namespace
33 
34 void TestMathPolynomialApproximationPass::runOnFunction() {
35   RewritePatternSet patterns(&getContext());
36   populateMathPolynomialApproximationPatterns(patterns);
37   (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns));
38 }
39 
40 namespace mlir {
41 namespace test {
42 void registerTestMathPolynomialApproximationPass() {
43   PassRegistration<TestMathPolynomialApproximationPass> pass(
44       "test-math-polynomial-approximation",
45       "Test math polynomial approximations");
46 }
47 } // namespace test
48 } // namespace mlir
49