Skip to content

Commit 9aef0fd

Browse files
[mlir][tblgen] Add additional constructor to Adaptor class (#112144)
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); } }; ```
1 parent 0d906a4 commit 9aef0fd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

mlir/test/mlir-tblgen/op-decl-and-defs.td

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def NS_AOp : NS_Op<"a_op", [IsolatedFromAbove, IsolatedFromAbove]> {
7272
// CHECK: template <typename RangeT>
7373
// CHECK: class AOpGenericAdaptor : public detail::AOpGenericAdaptorBase {
7474
// CHECK: public:
75-
// CHECK: AOpGenericAdaptor(RangeT values,
76-
// CHECK-SAME: odsOperands(values)
75+
// CHECK: AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs = {}, const ::mlir::EmptyProperties &properties = {}, ::mlir::RegionRange regions = {}) : Base(attrs, properties, regions), odsOperands(values) {}
76+
// CHECK: AOpGenericAdaptor(RangeT values, ::mlir::DictionaryAttr attrs, ::mlir::OpaqueProperties properties, ::mlir::RegionRange regions = {}) : AOpGenericAdaptor(values, attrs, (properties ? *properties.as<::mlir::EmptyProperties *>() : ::mlir::EmptyProperties{}), regions) {}
77+
// CHECK: AOpGenericAdaptor(RangeT values, const AOpGenericAdaptorBase &base) : Base(base), odsOperands(values) {}
7778
// CHECK: RangeT getODSOperands(unsigned index) {
7879
// CHECK: ValueT getA() {
7980
// CHECK: RangeT getB() {

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -4282,6 +4282,19 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
42824282
}
42834283
}
42844284

4285+
// Create a constructor that creates a new generic adaptor by copying
4286+
// everything from another adaptor, except for the values.
4287+
{
4288+
SmallVector<MethodParameter> paramList;
4289+
paramList.emplace_back("RangeT", "values");
4290+
paramList.emplace_back("const " + op.getGenericAdaptorName() + "Base &",
4291+
"base");
4292+
auto *constructor =
4293+
genericAdaptor.addConstructor<Method::Inline>(paramList);
4294+
constructor->addMemberInitializer("Base", "base");
4295+
constructor->addMemberInitializer("odsOperands", "values");
4296+
}
4297+
42854298
// Create constructors constructing the adaptor from an instance of the op.
42864299
// This takes the attributes, properties and regions from the op instance
42874300
// and the value range from the parameter.

0 commit comments

Comments
 (0)