From d83d437588bc24faa55c964b577b2e1c13901bed Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Thu, 30 Jul 2020 12:07:36 -0700 Subject: [PATCH] Add chlo.acos and legalization Add client HLO op for arc cosine and legalize TF op to it & legalization from it to HLO. PiperOrigin-RevId: 324053167 --- include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.h | 1 + include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td | 26 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.h b/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.h index c5483e9..14a22e9 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.h +++ b/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.h @@ -17,6 +17,7 @@ limitations under the License. #define TENSORFLOW_COMPILER_MLIR_HLO_INCLUDE_MLIR_HLO_DIALECT_MHLO_IR_CHLO_OPS_H_ #include "llvm/ADT/StringRef.h" +#include "mlir-hlo/Dialect/mhlo/IR/infer_fusibility_op_interface.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/DialectImplementation.h" #include "mlir/IR/MLIRContext.h" diff --git a/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td index 79d6fb2..d7cdd12 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td @@ -33,6 +33,7 @@ include "mlir/IR/OpBase.td" include "mlir/Interfaces/InferTypeOpInterface.td" include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir-hlo/Dialect/mhlo/IR/hlo_ops_base.td" +include "mlir-hlo/Dialect/mhlo/IR/infer_fusibility_op_interface.td" def HLOClient_Dialect : Dialect { let name = "chlo"; @@ -338,6 +339,31 @@ def HLOClient_BroadcastComplexOp : HLOClient_BroadcastBinaryElementwiseOp< let results = (outs HLO_ComplexTensor); } +//===----------------------------------------------------------------------===// +// Unary op +//===----------------------------------------------------------------------===// + +class HLOClient_UnaryElementwiseOp traits, + Type TensorType>: HLOClient_Op { + let arguments = (ins TensorType:$operand); + let results = (outs TensorType); +} + +def HLOClient_AcosOp: HLOClient_UnaryElementwiseOp<"acos", + [NoSideEffect, SameOperandsAndResultType], HLO_FpOrComplexTensor> { + let summary = "Acos operator"; + + let description = [{ + Returns `Acos(operand)` element-wise. + + $$ + \acos(x) = 2 * \atan(\sqrt(1 - x^2) / (1 + x)) if x != -1 + = pi if x == -1 + $$ + }]; +} + //===----------------------------------------------------------------------===// // Broadcasting compare op //===----------------------------------------------------------------------===//