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/Arithmetic/IR/Arithmetic.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 ®istry) const override { 28 registry.insert<arith::ArithmeticDialect, math::MathDialect, 29 vector::VectorDialect>(); 30 } 31 StringRef getArgument() const final { 32 return "test-math-polynomial-approximation"; 33 } 34 StringRef getDescription() const final { 35 return "Test math polynomial approximations"; 36 } 37 }; 38 } // end anonymous namespace 39 40 void TestMathPolynomialApproximationPass::runOnFunction() { 41 RewritePatternSet patterns(&getContext()); 42 populateMathPolynomialApproximationPatterns(patterns); 43 (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); 44 } 45 46 namespace mlir { 47 namespace test { 48 void registerTestMathPolynomialApproximationPass() { 49 PassRegistration<TestMathPolynomialApproximationPass>(); 50 } 51 } // namespace test 52 } // namespace mlir 53