Skip to content

Conversation

@matthias-springer
Copy link
Member

Add an additional adaptor constructor that copies everything except for the values. The values 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

template <typename SourceOp>
class OpConversionPattern : public ConversionPattern {
 public:
  using OneToNOpAdaptor =
      typename SourceOp::template GenericAdaptor<ArrayRef<ArrayRef<Value>>>;

  virtual LogicalResult
  matchAndRewrite(SourceOp op, OneToNOpAdaptor adaptor,
                  ConversionPatternRewriter &rewriter) const {
    SmallVector<Value> oneToOneOperands =
        getOneToOneAdaptorOperands(adaptor.getOperands());

    // This OpAdaptor constructor is added by this commit.
    return matchAndRewrite(op, OpAdaptor(oneToOneOperands, adaptor), rewriter);
  }
};

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 <typename SourceOp>
class OpConversionPattern : public ConversionPattern {
 public:
  virtual LogicalResult
  matchAndRewrite(SourceOp op, OneToNOpAdaptor adaptor,
                  ConversionPatternRewriter &rewriter) const {
    SmallVector<Value> oneToOneOperands =
        getOneToOneAdaptorOperands(adaptor.getOperands());

    // This OpAdaptor constructor is added by this commit.
    return matchAndRewrite(op, OpAdaptor(oneToOneOperands, adaptor), rewriter);
  }
};
```
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Oct 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 13, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Matthias Springer (matthias-springer)

Changes

Add an additional adaptor constructor that copies everything except for the values. The values 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

template &lt;typename SourceOp&gt;
class OpConversionPattern : public ConversionPattern {
 public:
  using OneToNOpAdaptor =
      typename SourceOp::template GenericAdaptor&lt;ArrayRef&lt;ArrayRef&lt;Value&gt;&gt;&gt;;

  virtual LogicalResult
  matchAndRewrite(SourceOp op, OneToNOpAdaptor adaptor,
                  ConversionPatternRewriter &amp;rewriter) const {
    SmallVector&lt;Value&gt; oneToOneOperands =
        getOneToOneAdaptorOperands(adaptor.getOperands());

    // This OpAdaptor constructor is added by this commit.
    return matchAndRewrite(op, OpAdaptor(oneToOneOperands, adaptor), rewriter);
  }
};

Full diff: https://github.com/llvm/llvm-project/pull/112144.diff

2 Files Affected:

  • (modified) mlir/test/mlir-tblgen/op-decl-and-defs.td (+3-2)
  • (modified) mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp (+13)
diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td
index f6fe45007d9e05..31dd53725c59ac 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 <typename RangeT>
 // 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 67df002ce38181..ce2b6ed94c3949 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<MethodParameter> paramList;
+    paramList.emplace_back("RangeT", "values");
+    paramList.emplace_back("const " + op.getGenericAdaptorName() + "Base &",
+                           "base");
+    auto *constructor =
+        genericAdaptor.addConstructor<Method::Inline>(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.

@matthias-springer matthias-springer merged commit 9aef0fd into main Oct 15, 2024
11 checks passed
@matthias-springer matthias-springer deleted the users/matthias-springer/tblgen_copy branch October 15, 2024 06:52
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
Add an additional adaptor constructor that copies everything except for
the values. The values 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 <typename SourceOp>
class OpConversionPattern : public ConversionPattern {
 public:
  using OneToNOpAdaptor =
      typename SourceOp::template GenericAdaptor<ArrayRef<ArrayRef<Value>>>;

  virtual LogicalResult
  matchAndRewrite(SourceOp op, OneToNOpAdaptor adaptor,
                  ConversionPatternRewriter &rewriter) const {
    SmallVector<Value> oneToOneOperands =
        getOneToOneAdaptorOperands(adaptor.getOperands());

    // This OpAdaptor constructor is added by this commit.
    return matchAndRewrite(op, OpAdaptor(oneToOneOperands, adaptor), rewriter);
  }
};
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants