From 9e07bdf4eadb005e3a88cc875634376788556382 Mon Sep 17 00:00:00 2001 From: Alexander Belyaev Date: Mon, 18 Jan 2021 06:46:28 -0800 Subject: [PATCH] [HLO] Move `SameOperandsAndResultShape` trait to Unary/BinaryElemenwiseOp classes. PiperOrigin-RevId: 352404756 --- include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td | 27 ++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td index 60250f0..144d3f9 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td @@ -120,7 +120,9 @@ def HLO_CreateTokenOp : HLO_Op<"create_token", [NoSideEffect]> { class HLO_UnaryElementwiseOp traits, Type TensorType>: HLO_Op { + !listconcat(traits, + [InferShapedTypeOpInterface, InferFusibilityOpInterface, + SameOperandsAndResultShape])> { let arguments = (ins TensorType:$operand); let results = (outs TensorType); let extraClassDeclaration = [{ @@ -146,7 +148,7 @@ class HLO_UnaryElementwiseOp traits, // Abs supports complex to real, so element type is not guaranteed to match. def HLO_AbsOp: HLO_UnaryElementwiseOp<"abs", - [NoSideEffect, SameOperandsAndResultShape, + [NoSideEffect, DeclareOpInterfaceMethods], TensorOf<[HLO_SInt, AnyFloat, HLO_Complex]>>, BASE_HLO_AbsOp { } @@ -157,10 +159,8 @@ def HLO_CbrtOp: HLO_UnaryElementwiseOp<"cbrt", def HLO_CeilOp: HLO_UnaryElementwiseOp<"ceil", [NoSideEffect, SameOperandsAndResultType], HLO_FpTensor>, BASE_HLO_CeilOp; -def HLO_ConvertOp : HLO_UnaryElementwiseOp< - "convert", [NoSideEffect, SameOperandsAndResultShape], HLO_Tensor>, - BASE_HLO_ConvertOp { - +def HLO_ConvertOp : HLO_UnaryElementwiseOp<"convert", + [NoSideEffect], HLO_Tensor>, BASE_HLO_ConvertOp { let builders = [ OpBuilderDAG<(ins "Value":$operand, "Type":$result_element_ty)>]; @@ -189,15 +189,14 @@ def HLO_FloorOp: HLO_UnaryElementwiseOp<"floor", [NoSideEffect, SameOperandsAndResultType], HLO_FpTensor>, BASE_HLO_FloorOp; def HLO_ImagOp: HLO_UnaryElementwiseOp<"imag", - [NoSideEffect, SameOperandsAndResultShape, - DeclareOpInterfaceMethods], + [NoSideEffect, DeclareOpInterfaceMethods], HLO_ComplexTensor>, BASE_HLO_ImagOp { let results = (outs HLO_FpTensor); let hasFolder = 1; } def HLO_IsFiniteOp: HLO_UnaryElementwiseOp<"is_finite", - [NoSideEffect, SameOperandsAndResultShape], HLO_Tensor>, + [NoSideEffect], HLO_Tensor>, BASE_HLO_IsFiniteOp { let arguments = (ins HLO_FpTensor:$x); let results = (outs HLO_PredTensor:$y); @@ -231,8 +230,7 @@ def HLO_PopulationCountOp: HLO_UnaryElementwiseOp<"popcnt", BASE_HLO_PopulationCountOp; def HLO_RealOp: HLO_UnaryElementwiseOp<"real", - [NoSideEffect, SameOperandsAndResultShape, - DeclareOpInterfaceMethods], + [NoSideEffect, DeclareOpInterfaceMethods], HLO_ComplexTensor>, BASE_HLO_RealOp { let results = (outs HLO_FpTensor); let hasFolder = 1; @@ -272,7 +270,9 @@ def HLO_TanhOp: HLO_UnaryElementwiseOp<"tanh", // See https://www.tensorflow.org/xla/operation_semantics#element-wise_binary_arithmetic_operations class HLO_BinaryElementwiseOp traits> : - HLO_Op { + HLO_Op { let arguments = (ins HLO_Tensor:$lhs, HLO_Tensor:$rhs @@ -315,8 +315,7 @@ def HLO_Atan2Op : HLO_BinaryElementwiseOp<"atan2", [NoSideEffect, SameOperandsAndResultType]>, BASE_HLO_Atan2Op; def HLO_ComplexOp: HLO_BinaryElementwiseOp<"complex", - [NoSideEffect, SameOperandsAndResultShape, - DeclareOpInterfaceMethods]>, + [NoSideEffect, DeclareOpInterfaceMethods]>, BASE_HLO_ComplexOp { let arguments = (ins HLO_FpTensor:$lhs, HLO_FpTensor:$rhs); let results = (outs HLO_ComplexTensor);