1/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 3Licensed under the Apache License, Version 2.0 (the "License"); 4you may not use this file except in compliance with the License. 5You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9Unless required by applicable law or agreed to in writing, software 10distributed under the License is distributed on an "AS IS" BASIS, 11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12See the License for the specific language governing permissions and 13limitations under the License. 14==============================================================================*/ 15 16// TFLite legalization patterns 17 18include "mlir/IR/OpBase.td" 19include "mlir/IR/PatternBase.td" 20include "mlir/Dialect/Func/IR/FuncOps.td" 21include "tensorflow/compiler/mlir/lite/ir/tfl_ops.td" 22include "tensorflow/compiler/mlir/lite/quantization/ir/QuantOps.td" 23include "mlir/Dialect/Tosa/IR/TosaOps.td" 24 25//===----------------------------------------------------------------------===// 26// Unary ops patterns. 27//===----------------------------------------------------------------------===// 28 29def ConvertTFLAbsOp : Pat<(TFL_AbsOp $arg), (Tosa_AbsOp $arg)>; 30def ConvertTFLCeilOp : Pat<(TFL_CeilOp $arg), (Tosa_CeilOp $arg)>; 31def ConvertTFLFloorOp : Pat<(TFL_FloorOp $arg), (Tosa_FloorOp $arg)>; 32def ConvertTFLExpOp : Pat<(TFL_ExpOp $arg), (Tosa_ExpOp $arg)>; 33def ConvertTFLLogOp : Pat<(TFL_LogOp $arg), (Tosa_LogOp $arg)>; 34def ConvertTFLRsqrtOp : Pat<(TFL_RsqrtOp $arg), (Tosa_RsqrtOp $arg)>; 35def ConvertTFLLogicalNotOp : Pat<(TFL_LogicalNotOp $arg), (Tosa_LogicalNotOp $arg)>; 36def ConvertTFLCastOp: Pat<(TFL_CastOp $in), (Tosa_CastOp $in)>; 37 38// Removing the quant.stats op for unquantized models. 39def ConvertQuantStatOp : Pat<(quantfork_StatisticsOp $value, $layer_stats, $axis_stats, $axis), 40 (replaceWithValue $value)>; 41 42//===----------------------------------------------------------------------===// 43// Binary ops patterns. 44//===----------------------------------------------------------------------===// 45 46def ConvertTFLLogicalAndOp : Pat<(TFL_LogicalAndOp $l, $r), (Tosa_LogicalAndOp $l, $r)>; 47def ConvertTFLLogicalOrOp : Pat<(TFL_LogicalOrOp $l, $r), (Tosa_LogicalOrOp $l, $r)>; 48def ConvertTFLPowOp : Pat<(TFL_PowOp $l, $r), (Tosa_PowOp $l, $r)>; 49 50//===----------------------------------------------------------------------===// 51// Ternary ops patterns. 52//===----------------------------------------------------------------------===// 53