diff --git a/mlir/test/mlir-tblgen/op-decl.td b/mlir/test/mlir-tblgen/op-decl.td --- a/mlir/test/mlir-tblgen/op-decl.td +++ b/mlir/test/mlir-tblgen/op-decl.td @@ -221,6 +221,30 @@ // CHECK-NOT: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llvm::ArrayRef<::mlir::Type> b, ::mlir::ValueRange a); // CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::llvm::ArrayRef<::mlir::Type> resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); +// Check default value of `attributes` for the `genUseOperandAsResultTypeCollectiveParamBuilder` builder +def NS_IOp : NS_Op<"op_with_same_operands_and_result_types_trait", [SameOperandsAndResultType]> { + let arguments = (ins AnyType:$a, AnyType:$b); + let results = (outs AnyType:$r); +} +// CHECK_LABEL: class NS_IOp : +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llvm::ArrayRef<::mlir::Type> resultTypes, ::mlir::Value a, ::mlir::Value b); +// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::llvm::ArrayRef<::mlir::Type> resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a, ::mlir::Value b); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); + +// Check default value of `attributes` for the `genInferredTypeCollectiveParamBuilder` builder +def NS_JOp : NS_Op<"op_with_InferTypeOpInterface_interface", [DeclareOpInterfaceMethods]> { + let arguments = (ins AnyType:$a, AnyType:$b); + let results = (outs AnyType:$r); +} +// CHECK_LABEL: class NS_JOp : +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type r, ::mlir::Value a, ::mlir::Value b); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value a, ::mlir::Value b); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::llvm::ArrayRef<::mlir::Type> resultTypes, ::mlir::Value a, ::mlir::Value b); +// CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::llvm::ArrayRef<::mlir::Type> resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); +// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); + // Check that default builders can be suppressed. // --- diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -1026,8 +1026,12 @@ builderOpState + ", ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> " "attributes"; - if (op.getNumVariadicRegions()) + if (op.getNumVariadicRegions()) { params += ", unsigned numRegions"; + } else { + // Provide default value for `attributes` since its the last parameter + params += " = {}"; + } auto &m = opClass.newMethod("void", "build", params, OpMethod::MP_Static); auto &body = m.body(); @@ -1053,13 +1057,12 @@ void OpEmitter::genInferredTypeCollectiveParamBuilder() { // TODO: Expand to support regions. - const char *params = - "::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &{0}, " - "::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> " - "attributes"; - auto &m = - opClass.newMethod("void", "build", formatv(params, builderOpState).str(), - OpMethod::MP_Static); + std::string params = + std::string("::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &") + + builderOpState + + ", ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> " + "attributes = {}"; + auto &m = opClass.newMethod("void", "build", params, OpMethod::MP_Static); auto &body = m.body(); int numResults = op.getNumResults();