Files
clang-p2996/mlir/test/lib/Transforms/TestExpandTanh.cpp
Hanhan Wang 9cb10296ec [mlir] Add support for lowering tanh to LLVMIR.
Summary:
Fixed build of D81618

Add a pattern for expanding tanh op into exp form.
A `tanh` is expanded into:
   1) 1-exp^{-2x} / 1+exp^{-2x}, if x => 0
   2) exp^{2x}-1 / exp^{2x}+1  , if x < 0.

Differential Revision: https://reviews.llvm.org/D82040
2020-06-18 10:42:13 -07:00

38 lines
1.2 KiB
C++

//===- TestExpandTanh.cpp - Test expand tanh op into exp form ------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains test passes for expanding tanh.
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/StandardOps/Transforms/Passes.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
namespace {
struct TestExpandTanhPass
: public PassWrapper<TestExpandTanhPass, FunctionPass> {
void runOnFunction() override;
};
} // end anonymous namespace
void TestExpandTanhPass::runOnFunction() {
OwningRewritePatternList patterns;
populateExpandTanhPattern(patterns, &getContext());
applyPatternsAndFoldGreedily(getOperation(), patterns);
}
namespace mlir {
void registerTestExpandTanhPass() {
PassRegistration<TestExpandTanhPass> pass("test-expand-tanh",
"Test expanding tanh");
}
} // namespace mlir