1 //===- TestExpandMath.cpp - Test expand math op into exp form -------------===//
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.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
14 #include "mlir/Dialect/Math/Transforms/Passes.h"
15 #include "mlir/Dialect/SCF/SCF.h"
16 #include "mlir/Pass/Pass.h"
17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
18 
19 using namespace mlir;
20 
21 namespace {
22 struct TestExpandMathPass
23     : public PassWrapper<TestExpandMathPass, OperationPass<>> {
24   MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestExpandMathPass)
25 
26   void runOnOperation() override;
27   StringRef getArgument() const final { return "test-expand-math"; }
28   void getDependentDialects(DialectRegistry &registry) const override {
29     registry.insert<arith::ArithmeticDialect, scf::SCFDialect>();
30   }
31   StringRef getDescription() const final { return "Test expanding math"; }
32 };
33 } // namespace
34 
35 void TestExpandMathPass::runOnOperation() {
36   RewritePatternSet patterns(&getContext());
37   populateExpandCtlzPattern(patterns);
38   populateExpandTanhPattern(patterns);
39   (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns));
40 }
41 
42 namespace mlir {
43 namespace test {
44 void registerTestExpandMathPass() { PassRegistration<TestExpandMathPass>(); }
45 } // namespace test
46 } // namespace mlir
47