diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index b96c0360316ad..f440580f0878a 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -3624,12 +3624,6 @@ def fir_LocalitySpecifierOp : fir_Op<"local", [IsolatedFromAbove]> { attr-dict }]; - let builders = [ - OpBuilder<(ins CArg<"mlir::TypeRange">:$result, - CArg<"mlir::StringAttr">:$sym_name, - CArg<"mlir::TypeAttr">:$type)> - ]; - let extraClassDeclaration = [{ mlir::BlockArgument getInitMoldArg() { auto ®ion = getInitRegion(); diff --git a/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td b/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td index 4360055e78691..b4dde776822a1 100644 --- a/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td +++ b/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td @@ -582,9 +582,6 @@ def LinalgCopyToMemrefOp : let assemblyFormat = "$target attr-dict `:` " "functional-type(operands, results) "; - let builders = [ - OpBuilder<(ins "Value":$target)>, - ]; let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -997,13 +994,6 @@ def PackGreedilyOp : Op]>:$matmul_inner_dims_order); let results = (outs TransformHandleTypeInterface:$packed_op); - let builders = [ - OpBuilder<(ins "Value":$target, - "ArrayRef":$mixedMatmulPackedSizes, - "ArrayRef":$matmulPaddededSizesNextMultipleOf, - CArg<"ArrayRef", "{}">:$matmulDimsInnerDimsOrder)> - ]; - let assemblyFormat = [{ $target oilist( @@ -2509,10 +2499,6 @@ def HoistRedundantVectorTransfersOp : let assemblyFormat = "$target attr-dict `:` functional-type(operands, results) "; - let builders = [ - OpBuilder<(ins "Value":$target, - CArg<"bool", "false">:$verify_non_zero_trip)>, - ]; let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2546,9 +2532,6 @@ def HoistRedundantVectorBroadcastsOp : let assemblyFormat = "$target attr-dict `:` functional-type(operands, results) "; - let builders = [ - OpBuilder<(ins "Value":$target)>, - ]; let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2623,10 +2606,6 @@ def ConvertConv2DToImg2ColOp : Op - ]; - let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2666,10 +2645,6 @@ def FlattenElementwiseLinalgOp : Op - ]; - let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2715,10 +2690,6 @@ def TransposeConv2DOp : Op - ]; - let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2761,10 +2732,6 @@ def TransposeMatmulOp : Op - ]; - let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2801,9 +2768,6 @@ def InsertSliceToCopyOp : let assemblyFormat = "$target attr-dict `:` functional-type(operands, results) "; - let builders = [ - OpBuilder<(ins "Value":$target)>, - ]; let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2859,9 +2823,6 @@ def MapCopyToThreadsOp : `:` functional-type(operands, results) }]; - let builders = [ - OpBuilder<(ins "Value":$target)>, - ]; let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2910,10 +2871,6 @@ def WinogradConv2DOp : Op - ]; - let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, @@ -2947,10 +2904,6 @@ def DecomposeWinogradOp : Op - ]; - let extraClassDeclaration = [{ ::mlir::DiagnosedSilenceableFailure applyToOne( ::mlir::transform::TransformRewriter &rewriter, diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index ac80926053a2d..dffb3c5e14b62 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -1751,10 +1751,6 @@ def DeclareMapperInfoOp : OpenMP_Op<"declare_mapper.info", [ parent DeclareMapperOp. }] # clausesDescription; - let builders = [ - OpBuilder<(ins CArg<"const DeclareMapperInfoOperands &">:$clauses)> - ]; - let extraClassDeclaration = [{ // Override BlockArgOpenMPOpInterface method because `map` clauses have no // associated entry block arguments in this operation. diff --git a/mlir/include/mlir/Dialect/Ptr/IR/PtrOps.td b/mlir/include/mlir/Dialect/Ptr/IR/PtrOps.td index 1523762efc18f..440f6e571eec5 100644 --- a/mlir/include/mlir/Dialect/Ptr/IR/PtrOps.td +++ b/mlir/include/mlir/Dialect/Ptr/IR/PtrOps.td @@ -171,9 +171,6 @@ def Ptr_TypeOffsetOp : Pointer_Op<"type_offset", [Pure]> { let arguments = (ins TypeAttr:$elementType); let results = (outs AnySignlessIntegerOrIndex:$result); - let builders = [ - OpBuilder<(ins "Type":$elementType)> - ]; let assemblyFormat = [{ $elementType attr-dict `:` type($result) }]; diff --git a/mlir/include/mlir/Dialect/SMT/IR/SMTIntOps.td b/mlir/include/mlir/Dialect/SMT/IR/SMTIntOps.td index ea94dfd8fbd2a..4aa07a1283461 100644 --- a/mlir/include/mlir/Dialect/SMT/IR/SMTIntOps.td +++ b/mlir/include/mlir/Dialect/SMT/IR/SMTIntOps.td @@ -52,12 +52,6 @@ class VariadicIntOp : SMTIntOp { let arguments = (ins Variadic:$inputs); let results = (outs IntType:$result); let assemblyFormat = "$inputs attr-dict"; - - let builders = [ - OpBuilder<(ins "mlir::ValueRange":$inputs), [{ - build($_builder, $_state, $_builder.getType(), inputs); - }]>, - ]; } class BinaryIntOp : SMTIntOp { diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td index ec2c87ca1cf44..cbe490f6e4dd1 100644 --- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td +++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td @@ -3011,12 +3011,7 @@ def Vector_ScanOp : vector<4x8x16x32xf32>, vector<4x16x32xf32> ``` }]; - let builders = [ - OpBuilder<(ins "Value":$source, "Value":$initial_value, - "CombiningKind":$kind, - CArg<"int64_t", "0">:$reduction_dim, - CArg<"bool", "true">:$inclusive)> - ]; + let extraClassDeclaration = [{ VectorType getSourceType() { return ::llvm::cast(getSource().getType()); diff --git a/mlir/include/mlir/TableGen/Class.h b/mlir/include/mlir/TableGen/Class.h index f750a34a3b2ba..69cefbbc43e0a 100644 --- a/mlir/include/mlir/TableGen/Class.h +++ b/mlir/include/mlir/TableGen/Class.h @@ -71,6 +71,8 @@ class MethodParameter { StringRef getName() const { return name; } /// Returns true if the parameter has a default value. bool hasDefaultValue() const { return !defaultValue.empty(); } + StringRef getDefaultValue() const { return defaultValue; } + bool isOptional() const { return optional; } private: /// The C++ type. diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index 535f5e9b4a15d..ab3f847ca2acf 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -1192,7 +1192,6 @@ def OpFuncRef : TEST_Op<"op_funcref"> { let description = [{ The "test.op_funcref" is a test op with a reference to a function symbol. }]; - let builders = [OpBuilder<(ins "::mlir::func::FuncOp":$function)>]; } // Pattern add the argument plus a increasing static number hidden in diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index cbb4030f3adb4..d50500851ac9b 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -230,6 +230,14 @@ static const char *const opCommentHeader = R"( )"; +static const char *const inlineCreateBody = R"( + ::mlir::OperationState __state__({0}, getOperationName()); + build(builder, __state__{1}); + auto __res__ = ::llvm::dyn_cast<{2}>(builder.create(__state__)); + assert(__res__ && "builder didn't return the right type"); + return __res__; +)"; + //===----------------------------------------------------------------------===// // Utility structs and functions //===----------------------------------------------------------------------===// @@ -665,6 +673,7 @@ class OpEmitter { // Generates the build() method that takes each operand/attribute // as a stand-alone parameter. void genSeparateArgParamBuilder(); + void genInlineCreateBody(const SmallVector ¶mList); // Generates the build() method that takes each operand/attribute as a // stand-alone parameter. The generated build() method uses first operand's @@ -2568,6 +2577,39 @@ static bool canInferType(const Operator &op) { return op.getTrait("::mlir::InferTypeOpInterface::Trait"); } +void OpEmitter::genInlineCreateBody( + const SmallVector ¶mList) { + SmallVector createParamList; + SmallVector nonBuilderStateArgsList; + createParamList.emplace_back("::mlir::OpBuilder &", "builder"); + std::string locParamName = "location"; + while (llvm::find_if(paramList, [&locParamName](const MethodParameter &p) { + return p.getName() == locParamName; + }) != paramList.end()) { + locParamName += "_"; + } + createParamList.emplace_back("::mlir::Location", locParamName); + + for (auto ¶m : paramList) { + if (param.getType() == "::mlir::OpBuilder &" || + param.getType() == "::mlir::OperationState &") + continue; + createParamList.emplace_back(param.getType(), param.getName(), + param.getDefaultValue(), param.isOptional()); + nonBuilderStateArgsList.push_back(param.getName()); + } + auto *c = opClass.addStaticMethod(opClass.getClassName(), "create", + createParamList); + std::string nonBuilderStateArgs = ""; + if (!nonBuilderStateArgsList.empty()) { + llvm::raw_string_ostream nonBuilderStateArgsOS(nonBuilderStateArgs); + interleaveComma(nonBuilderStateArgsList, nonBuilderStateArgsOS); + nonBuilderStateArgs = ", " + nonBuilderStateArgs; + } + c->body() << llvm::formatv(inlineCreateBody, locParamName, + nonBuilderStateArgs, opClass.getClassName()); +} + void OpEmitter::genSeparateArgParamBuilder() { SmallVector attrBuilderType; attrBuilderType.push_back(AttrParamKind::WrappedAttr); @@ -2584,10 +2626,12 @@ void OpEmitter::genSeparateArgParamBuilder() { buildParamList(paramList, inferredAttributes, resultNames, paramKind, attrType); - auto *m = opClass.addStaticMethod("void", "build", std::move(paramList)); + auto *m = opClass.addStaticMethod("void", "build", paramList); // If the builder is redundant, skip generating the method. if (!m) return; + genInlineCreateBody(paramList); + auto &body = m->body(); genCodeForAddingArgAndRegionForBuilder(body, inferredAttributes, /*isRawValueAttr=*/attrType == @@ -2712,10 +2756,11 @@ void OpEmitter::genUseOperandAsResultTypeCollectiveParamBuilder( if (op.getNumVariadicRegions()) paramList.emplace_back("unsigned", "numRegions"); - auto *m = opClass.addStaticMethod("void", "build", std::move(paramList)); + auto *m = opClass.addStaticMethod("void", "build", paramList); // If the builder is redundant, skip generating the method if (!m) return; + genInlineCreateBody(paramList); auto &body = m->body(); // Operands @@ -2826,10 +2871,11 @@ void OpEmitter::genInferredTypeCollectiveParamBuilder( if (op.getNumVariadicRegions()) paramList.emplace_back("unsigned", "numRegions"); - auto *m = opClass.addStaticMethod("void", "build", std::move(paramList)); + auto *m = opClass.addStaticMethod("void", "build", paramList); // If the builder is redundant, skip generating the method if (!m) return; + genInlineCreateBody(paramList); auto &body = m->body(); int numResults = op.getNumResults(); @@ -2906,10 +2952,11 @@ void OpEmitter::genUseOperandAsResultTypeSeparateParamBuilder() { buildParamList(paramList, inferredAttributes, resultNames, TypeParamKind::None, attrType); - auto *m = opClass.addStaticMethod("void", "build", std::move(paramList)); + auto *m = opClass.addStaticMethod("void", "build", paramList); // If the builder is redundant, skip generating the method if (!m) return; + genInlineCreateBody(paramList); auto &body = m->body(); genCodeForAddingArgAndRegionForBuilder(body, inferredAttributes, /*isRawValueAttr=*/attrType == @@ -2948,10 +2995,11 @@ void OpEmitter::genUseAttrAsResultTypeCollectiveParamBuilder( : "attributes"; paramList.emplace_back("::llvm::ArrayRef<::mlir::NamedAttribute>", attributesName, "{}"); - auto *m = opClass.addStaticMethod("void", "build", std::move(paramList)); + auto *m = opClass.addStaticMethod("void", "build", paramList); // If the builder is redundant, skip generating the method if (!m) return; + genInlineCreateBody(paramList); auto &body = m->body(); @@ -3052,6 +3100,7 @@ void OpEmitter::genBuilder() { fctx.addSubst("_state", builderOpState); if (body) method->body() << tgfmt(*body, &fctx); + genInlineCreateBody(arguments); } // Generate default builders that requires all result type, operands, and @@ -3114,10 +3163,11 @@ void OpEmitter::genCollectiveParamBuilder(CollectiveBuilderKind kind) { if (op.getNumVariadicRegions()) paramList.emplace_back("unsigned", "numRegions"); - auto *m = opClass.addStaticMethod("void", "build", std::move(paramList)); + auto *m = opClass.addStaticMethod("void", "build", paramList); // If the builder is redundant, skip generating the method if (!m) return; + genInlineCreateBody(paramList); auto &body = m->body(); // Operands