Enzyme main
Loading...
Searching...
No Matches
SimplifyMath.cpp
Go to the documentation of this file.
1//===- SimpliyMath.cpp - Simplify Mathematical operations ------------------ //
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 implements a pass to lower custom ops generated by the Enzyme AD
10// procedure to the MemRef dialect.
11//===----------------------------------------------------------------------===//
12
13#include "Dialect/Ops.h"
15#include "PassDetails.h"
16#include "Passes/Passes.h"
17#include "mlir/Dialect/Arith/IR/Arith.h"
18#include "mlir/Dialect/Complex/IR/Complex.h"
19
20#include "mlir/IR/Matchers.h"
21#include "mlir/IR/PatternMatch.h"
22#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
23
24using namespace mlir;
25using namespace mlir::enzyme;
26
27namespace mlir {
28namespace enzyme {
29using namespace mlir::enzyme;
30#define GEN_PASS_DEF_MATHEMATICSIMPLIFICATIONPASS
31#include "Passes/Passes.h.inc"
32} // namespace enzyme
33} // namespace mlir
34
35using llvm::errs;
36namespace {
37
38struct ApplySimplificationPattern
39 : public OpInterfaceRewritePattern<enzyme::MathSimplifyInterface> {
40 using OpInterfaceRewritePattern<
41 enzyme::MathSimplifyInterface>::OpInterfaceRewritePattern;
42
43 LogicalResult matchAndRewrite(enzyme::MathSimplifyInterface op,
44 PatternRewriter &rewriter) const override {
45 return op.simplifyMath(rewriter);
46 }
47};
48
49struct MathematicSimplification
50 : public enzyme::impl::MathematicSimplificationPassBase<
51 MathematicSimplification> {
52 void runOnOperation() override {
53
54 RewritePatternSet patterns(&getContext());
55 patterns.insert<ApplySimplificationPattern>(&getContext());
56
57 GreedyRewriteConfig config;
58 config.enableFolding();
59 (void)applyPatternsGreedily(getOperation(), std::move(patterns), config);
60 };
61};
62} // end anonymous namespace