From e77b5ae534fa286ea0f0d05998fcd96d1e5bb539 Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Wed, 28 Oct 2020 13:15:35 -0700 Subject: [PATCH] Update MLIR ODS syntax to use OpBuidlerDAG instead of OpBuilder The latter has been deprecated in favor of the former and will be removed. PiperOrigin-RevId: 339523966 --- include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td | 16 ++++---- include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td | 43 ++++++++------------ include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td | 16 ++++---- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td index a6f5308..a65d825 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/chlo_ops.td @@ -89,10 +89,9 @@ class HLOClient_BroadcastBinaryElementwiseOp< OptionalAttr:$broadcast_dimensions ); - let builders = [OpBuilder< - "OpBuilder &builder, OperationState &result, Value left, Value right, " - "DenseIntElementsAttr broadcast_dimensions" - >]; + let builders = [ + OpBuilderDAG<(ins "Value":$left, "Value":$right, + "DenseIntElementsAttr":$broadcast_dimensions)>]; let results = (outs HLO_Tensor); @@ -445,11 +444,10 @@ def HLOClient_BroadcastCompareOp : HLOClient_BroadcastBinaryElementwiseOp< ); let results = (outs HLO_PredTensor); - let builders = [OpBuilder< - "OpBuilder &builder, OperationState &result, Value lhs, Value rhs, " - "DenseIntElementsAttr broadcast_dimensions, " - "StringAttr comparison_direction, StringAttr compare_type = {}" - >]; + let builders = [ + OpBuilderDAG<(ins "Value":$lhs, "Value":$rhs, + "DenseIntElementsAttr":$broadcast_dimensions, + "StringAttr":$comparison_direction, CArg<"StringAttr", "{}">:$compare_type)>]; } #endif // CHLO_OPS diff --git a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td index 0b52ed2..42db595 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/hlo_ops.td @@ -58,9 +58,8 @@ def HLO_ConstOp : HLO_Op<"constant", HLO_StaticShapeTensor:$output ); - let builders = [OpBuilder< - "OpBuilder &builder, OperationState &result, Attribute value" - >]; + let builders = [ + OpBuilderDAG<(ins "Attribute":$value)>]; let assemblyFormat = "attr-dict $value"; @@ -147,9 +146,8 @@ class HLO_UnaryElementwiseOp traits, def HLO_AbsOp: HLO_UnaryElementwiseOp<"abs", [NoSideEffect, SameOperandsAndResultShape], TensorOf<[HLO_SInt, AnyFloat, HLO_Complex]>>, BASE_HLO_AbsOp { - let builders = [OpBuilder< - "Value operand" - >]; + let builders = [ + OpBuilderDAG<(ins "Value":$operand)>]; } def HLO_CbrtOp: HLO_UnaryElementwiseOp<"cbrt", @@ -162,9 +160,8 @@ def HLO_ConvertOp : HLO_UnaryElementwiseOp< "convert", [NoSideEffect, SameOperandsAndResultShape], HLO_Tensor>, BASE_HLO_ConvertOp { - let builders = [OpBuilder< - "Value operand, Type result_element_ty" - >]; + let builders = [ + OpBuilderDAG<(ins "Value":$operand, "Type":$result_element_ty)>]; let hasFolder = 1; @@ -618,10 +615,9 @@ def HLO_ReduceOp: HLO_Op<"reduce", [ let results = (outs Variadic); - let builders = [OpBuilder< - "OpBuilder &, OperationState &state, ValueRange operands, " - "ValueRange init_values, DenseIntElementsAttr dimensions" - >]; + let builders = [ + OpBuilderDAG<(ins "ValueRange":$operands, "ValueRange":$init_values, + "DenseIntElementsAttr":$dimensions)>]; let extraClassDeclaration = [{ bool isFusibleWithConsumer() { @@ -657,18 +653,16 @@ def HLO_GetTupleElementOp: HLO_Op<"get_tuple_element", [NoSideEffect]>, BASE_HLO let hasFolder = 1; - let builders = [OpBuilder< - "OpBuilder &builder, OperationState &results, " - "Value value, int32_t index">]; + let builders = [ + OpBuilderDAG<(ins "Value":$value, "int32_t":$index)>]; } def HLO_TupleOp : HLO_Op<"tuple", [NoSideEffect]>, BASE_HLO_TupleOp { let arguments = (ins Variadic:$val); let results = (outs HLO_Tuple); - let builders = [OpBuilder< - "OpBuilder &builder, OperationState &results, " - "ValueRange values">]; + let builders = [ + OpBuilderDAG<(ins "ValueRange":$values)>]; let hasCanonicalizer = 1; } @@ -688,8 +682,8 @@ def HLO_CompareOp: HLO_Op<"compare", [NoSideEffect, SameTypeOperands, let hasFolder = 1; let builders = [ - OpBuilder<"OpBuilder &builder, OperationState &result, Value lhs, Value rhs, " - "StringAttr comparison_direction, StringAttr compare_type = {}">, + OpBuilderDAG<(ins "Value":$lhs, "Value":$rhs, + "StringAttr":$comparison_direction, CArg<"StringAttr", "{}">:$compare_type)>, ]; let hasCustomHLOConverter = 1; @@ -1151,10 +1145,9 @@ def HLO_SortOp : HLO_Op<"sort", [RecursiveSideEffects, SameOperandsAndResultShap let regions = (region SizedRegion<1>:$comparator); - let builders = [OpBuilder< - "OpBuilder &builder, OperationState &state, ValueRange operands, " - "int64_t dimension = -1, bool is_stable = false" - >]; + let builders = [ + OpBuilderDAG<(ins "ValueRange":$operands, CArg<"int64_t", "-1">:$dimension, + CArg<"bool", "false">:$is_stable)>]; // TODO(b/129422361): SortOp has special conversion logic to HLO. let hasCustomHLOConverter = 1; diff --git a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td index 3873724..32901f4 100644 --- a/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td +++ b/include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td @@ -341,7 +341,8 @@ def HLO_StaticMemRefCastOp: Op:$operand); let results = (outs Res:$result); - let builders = [OpBuilder<"MemRefType resultType, Value operand", + let builders = [ + OpBuilderDAG<(ins "MemRefType":$resultType, "Value":$operand), [{ $_state.addOperands(operand); $_state.types.push_back(resultType); @@ -387,8 +388,9 @@ def HLO_DynamicMemRefCastOp: Op:$result); let builders = [ - OpBuilder<"MemRefType resultType, Value operand, ValueRange sizes, " - "ValueRange strides", [{ + OpBuilderDAG<(ins "MemRefType":$resultType, "Value":$operand, + "ValueRange":$sizes, "ValueRange":$strides), + [{ $_state.addOperands(operand); $_state.addOperands(sizes); $_state.addOperands(strides); @@ -813,7 +815,7 @@ def FusionOp : LHLO_Op<"fusion", [SingleBlockImplicitTerminator<"TerminatorOp">] let skipDefaultBuilders = 1; let builders = [ - OpBuilder<"ArrayRef attributes"> + OpBuilderDAG<(ins "ArrayRef":$attributes)> ]; } @@ -823,9 +825,9 @@ def TerminatorOp : let description = [{ Terminator operation for the LHLO dialect. }]; - let builders = [OpBuilder<"ValueRange operands", - [{ build($_builder, $_state, llvm::None, operands, llvm::None); }] - >]; + let builders = [ + OpBuilderDAG<(ins "ValueRange":$operands), + [{ build($_builder, $_state, llvm::None, operands, llvm::None); }]>]; } #endif // LHLO_OPS