1 //===- TestPolynomialApproximation.cpp - Test math ops approximations -----===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains test passes for expanding math operations into
10 // polynomial approximations.
12 //===----------------------------------------------------------------------===//
14 #include "mlir/Dialect/Arith/IR/Arith.h"
15 #include "mlir/Dialect/Math/IR/Math.h"
16 #include "mlir/Dialect/Math/Transforms/Passes.h"
17 #include "mlir/Dialect/Vector/IR/VectorOps.h"
18 #include "mlir/Dialect/X86Vector/X86VectorDialect.h"
19 #include "mlir/Pass/Pass.h"
20 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
25 struct TestMathPolynomialApproximationPass
26 : public PassWrapper
<TestMathPolynomialApproximationPass
, OperationPass
<>> {
27 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
28 TestMathPolynomialApproximationPass
)
30 TestMathPolynomialApproximationPass() = default;
31 TestMathPolynomialApproximationPass(
32 const TestMathPolynomialApproximationPass
&pass
)
33 : PassWrapper(pass
) {}
35 void runOnOperation() override
;
36 void getDependentDialects(DialectRegistry
®istry
) const override
{
37 registry
.insert
<arith::ArithDialect
, math::MathDialect
,
38 vector::VectorDialect
>();
40 registry
.insert
<x86vector::X86VectorDialect
>();
42 StringRef
getArgument() const final
{
43 return "test-math-polynomial-approximation";
45 StringRef
getDescription() const final
{
46 return "Test math polynomial approximations";
49 Option
<bool> enableAvx2
{
51 llvm::cl::desc("Enable approximations that emit AVX2 intrinsics via the "
53 llvm::cl::init(false)};
57 void TestMathPolynomialApproximationPass::runOnOperation() {
58 RewritePatternSet
patterns(&getContext());
59 MathPolynomialApproximationOptions approxOptions
;
60 approxOptions
.enableAvx2
= enableAvx2
;
61 populateMathPolynomialApproximationPatterns(patterns
, approxOptions
);
62 (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns
));
67 void registerTestMathPolynomialApproximationPass() {
68 PassRegistration
<TestMathPolynomialApproximationPass
>();