From 6afeb419578efc0f9fa8855a7fe71df0113ed09c Mon Sep 17 00:00:00 2001 From: Matthias Springer Date: Sun, 13 Oct 2024 19:45:22 +0200 Subject: [PATCH] [mlir][tblgen] Add additional constructor to Adaptor class Add an additional adaptor constructor that copies everything except for the values. These are provided with by a second parameter. This commit is in preparation of merging the 1:1 and 1:N dialect conversions. As part of that, a new `matchAndRewrite` function is added. For details, see this RFC: https://discourse.llvm.org/t/rfc-merging-1-1-and-1-n-dialect-conversions/82513 ```c++ template class OpConversionPattern : public ConversionPattern { public: virtual LogicalResult matchAndRewrite(SourceOp op, OneToNOpAdaptor adaptor, ConversionPatternRewriter &rewriter) const { SmallVector oneToOneOperands = getOneToOneAdaptorOperands(adaptor.getOperands()); // This OpAdaptor constructor is added by this commit. return matchAndRewrite(op, OpAdaptor(oneToOneOperands, adaptor), rewriter); } }; ``` --- mlir/test/mlir-tblgen/op-decl-and-defs.td | 5 +++-- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td index f6fe45007d9e0..31dd53725c59a 100644 --- a/mlir/test/mlir-tblgen/op-decl-and-defs.td +++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td @@ -72,8 +72,9 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> { // CHECK: template // CHECK: class AOpGenericAdaptor : public detail::AOpGenericAdaptorBase { // CHECK: public: -// CHECK: AOpGenericAdaptor(RangeT values, -// CHECK-SAME: odsOperands(values) +// CHECK: AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = {}, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {} +// CHECK: AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {} +// CHECK: AOpGenericAdaptor(RangeT values, const AOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {} // CHECK: RangeT getODSOperands(unsigned index) { // CHECK: ValueT getA() { // CHECK: RangeT getB() { diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp index 67df002ce3818..ce2b6ed94c394 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -4282,6 +4282,19 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter( } } + // Create a constructor that creates a new generic adaptor by copying + // everything from another adaptor, except for the values. + { + SmallVector paramList; + paramList.emplace_back("RangeT", "values"); + paramList.emplace_back("const " + op.getGenericAdaptorName() + "Base &", + "base"); + auto *constructor = + genericAdaptor.addConstructor(paramList); + constructor->addMemberInitializer("Base", "base"); + constructor->addMemberInitializer("odsOperands", "values"); + } + // Create constructors constructing the adaptor from an instance of the op. // This takes the attributes, properties and regions from the op instance // and the value range from the parameter.