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/Math/IR/Math.h" 15 #include "mlir/Dialect/Math/Transforms/Passes.h" 16 #include "mlir/Dialect/Vector/VectorOps.h" 17 #include "mlir/Pass/Pass.h" 18 #include "mlir/Transforms/GreedyPatternRewriteDriver.h" 19 20 using namespace mlir; 21 22 namespace { 23 struct TestMathPolynomialApproximationPass 24 : public PassWrapper<TestMathPolynomialApproximationPass, FunctionPass> { 25 void runOnFunction() override; 26 void getDependentDialects(DialectRegistry ®istry) const override { 27 registry.insert<vector::VectorDialect, math::MathDialect>(); 28 } 29 StringRef getArgument() const final { 30 return "test-math-polynomial-approximation"; 31 } 32 StringRef getDescription() const final { 33 return "Test math polynomial approximations"; 34 } 35 }; 36 } // end anonymous namespace 37 38 void TestMathPolynomialApproximationPass::runOnFunction() { 39 RewritePatternSet patterns(&getContext()); 40 populateMathPolynomialApproximationPatterns(patterns); 41 (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); 42 } 43 44 namespace mlir { 45 namespace test { 46 void registerTestMathPolynomialApproximationPass() { 47 PassRegistration<TestMathPolynomialApproximationPass>(); 48 } 49 } // namespace test 50 } // namespace mlir 51