1 //===- TestExpandMath.cpp - Test expand math op into exp form -------------===//
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.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Dialect/Arith/IR/Arith.h"
14 #include "mlir/Dialect/Math/Transforms/Passes.h"
15 #include "mlir/Dialect/SCF/IR/SCF.h"
16 #include "mlir/Dialect/Vector/IR/VectorOps.h"
17 #include "mlir/Pass/Pass.h"
18 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
23 struct TestExpandMathPass
24 : public PassWrapper
<TestExpandMathPass
, OperationPass
<>> {
25 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestExpandMathPass
)
27 void runOnOperation() override
;
28 StringRef
getArgument() const final
{ return "test-expand-math"; }
29 void getDependentDialects(DialectRegistry
®istry
) const override
{
31 .insert
<arith::ArithDialect
, scf::SCFDialect
, vector::VectorDialect
>();
33 StringRef
getDescription() const final
{ return "Test expanding math"; }
37 void TestExpandMathPass::runOnOperation() {
38 RewritePatternSet
patterns(&getContext());
39 populateExpandCtlzPattern(patterns
);
40 populateExpandExp2FPattern(patterns
);
41 populateExpandTanPattern(patterns
);
42 populateExpandSinhPattern(patterns
);
43 populateExpandCoshPattern(patterns
);
44 populateExpandTanhPattern(patterns
);
45 populateExpandAsinhPattern(patterns
);
46 populateExpandAcoshPattern(patterns
);
47 populateExpandAtanhPattern(patterns
);
48 populateExpandFmaFPattern(patterns
);
49 populateExpandFloorFPattern(patterns
);
50 populateExpandCeilFPattern(patterns
);
51 populateExpandPowFPattern(patterns
);
52 populateExpandFPowIPattern(patterns
);
53 populateExpandRoundFPattern(patterns
);
54 populateExpandRoundEvenPattern(patterns
);
55 populateExpandRsqrtPattern(patterns
);
56 (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns
));
61 void registerTestExpandMathPass() { PassRegistration
<TestExpandMathPass
>(); }