72 lines
3.0 KiB
TableGen
72 lines
3.0 KiB
TableGen
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
==============================================================================*/
|
|
|
|
// This is the legalization pattern definition file for MHLO to StandardOps.
|
|
|
|
include "third_party/llvm/llvm-project/mlir/include/mlir/IR/OpBase.td"
|
|
include "third_party/llvm/llvm-project/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td"
|
|
include "third_party/tensorflow/compiler/mlir/hlo/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td"
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Nullary op patterns.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
def : Pat<(HLO_ConstOp ElementsAttr:$value),
|
|
(ConstantOp $value)>;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Binary op patterns.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
def IsSameSizePred : CPred<
|
|
"$0.getType().cast<ShapedType>().getShape() "
|
|
"== $1.getType().cast<ShapedType>().getShape()">;
|
|
def IsSameSizeConstraint : Constraint<IsSameSizePred, "inputs are same size">;
|
|
|
|
|
|
def : Pat<(HLO_AndOp HLO_PredTensor:$l, HLO_PredTensor:$r),
|
|
(AndOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_AddOp HLO_FpTensor:$l, HLO_FpTensor:$r),
|
|
(AddFOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_SubOp HLO_FpTensor:$l, HLO_FpTensor:$r),
|
|
(SubFOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_MulOp HLO_FpTensor:$l, HLO_FpTensor:$r),
|
|
(MulFOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_DivOp HLO_FpTensor:$l, HLO_FpTensor:$r),
|
|
(DivFOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_RemOp HLO_FpTensor:$l, HLO_FpTensor:$r),
|
|
(RemFOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_AddOp HLO_IntTensor:$l, HLO_IntTensor:$r),
|
|
(AddIOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_SubOp HLO_IntTensor:$l, HLO_IntTensor:$r),
|
|
(SubIOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_MulOp HLO_IntTensor:$l, HLO_IntTensor:$r),
|
|
(MulIOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_DivOp HLO_IntTensor:$l, HLO_IntTensor:$r),
|
|
(SignedDivIOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|
|
def : Pat<(HLO_RemOp HLO_IntTensor:$l, HLO_IntTensor:$r),
|
|
(SignedRemIOp $l, $r),
|
|
[(IsSameSizeConstraint $l, $r)]>;
|