[Mlir-commits] [mlir] [mlir][ods] Fix missing property elision for variadic segment properties (PR #115930)
Théo Degioanni
llvmlistbot at llvm.org
Sat Nov 23 10:24:06 PST 2024
https://github.com/Moxinilian updated https://github.com/llvm/llvm-project/pull/115930
>From 9afde67bad8a15c00741aa6352822f7e2db2cf30 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Degioanni?=
<theo.degioanni.llvm.deluge062 at simplelogin.fr>
Date: Tue, 12 Nov 2024 20:09:58 +0100
Subject: [PATCH 1/3] add variadic segment size elision to properties
---
mlir/test/IR/properties.mlir | 10 +++++++++-
mlir/test/lib/Dialect/Test/TestOps.td | 9 +++++++++
mlir/tools/mlir-tblgen/OpFormatGen.cpp | 9 +++++++++
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/mlir/test/IR/properties.mlir b/mlir/test/IR/properties.mlir
index 9a1c49cb7dabf3..b339a03812badb 100644
--- a/mlir/test/IR/properties.mlir
+++ b/mlir/test/IR/properties.mlir
@@ -1,4 +1,4 @@
-// # RUN: mlir-opt %s -split-input-file | mlir-opt |FileCheck %s
+// # RUN: mlir-opt %s -split-input-file | mlir-opt | FileCheck %s
// # RUN: mlir-opt %s -mlir-print-op-generic -split-input-file | mlir-opt -mlir-print-op-generic | FileCheck %s --check-prefix=GENERIC
// CHECK: test.with_properties
@@ -38,6 +38,14 @@ test.using_property_in_custom [1, 4, 20]
// GENERIC-SAME: }>
test.using_property_ref_in_custom 1 + 4 = 5
+// Tests that the variadic segment size properties are elided.
+// CHECK: %[[CI64:.*]] = arith.constant
+// CHECK-NEXT: test.variadic_segment_prop %[[CI64]], %[[CI64]] : %[[CI64]] : i64, i64 : i64 end
+// GENERIC: %[[CI64:.*]] = "arith.constant"()
+// GENERIC-NEXT: "test.variadic_segment_prop"(%[[CI64]], %[[CI64]], %[[CI64]]) <{operandSegmentSizes = array<i32: 2, 1>, resultSegmentSizes = array<i32: 2, 1>}> : (i64, i64, i64) -> (i64, i64, i64)
+%ci64 = arith.constant 0 : i64
+test.variadic_segment_prop %ci64, %ci64 : %ci64 : i64, i64 : i64 end
+
// CHECK: test.with_default_valued_properties na{{$}}
// GENERIC: "test.with_default_valued_properties"()
// GENERIC-SAME: <{a = 0 : i32, b = "", c = -1 : i32, unit = false}> : () -> ()
diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index cfe19a2fd5c08b..6752113cab8d41 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -3047,6 +3047,15 @@ def TestOpUsingPropertyInCustomAndOther
);
}
+def TestOpWithVariadicSegmentProperties : TEST_Op<"variadic_segment_prop",
+ [AttrSizedOperandSegments, AttrSizedResultSegments]> {
+ let arguments = (ins Variadic<I64>:$a1, Variadic<I64>:$a2);
+ let results = (outs Variadic<I64>:$b1, Variadic<I64>:$b2);
+ let assemblyFormat = [{
+ $a1 `:` $a2 `:` type($b1) `:` type($b2) prop-dict attr-dict `end`
+ }];
+}
+
def TestOpUsingPropertyRefInCustom : TEST_Op<"using_property_ref_in_custom"> {
let assemblyFormat = "custom<IntProperty>($first) `+` custom<SumProperty>($second, ref($first)) attr-dict";
let arguments = (ins IntProperty<"int64_t">:$first, IntProperty<"int64_t">:$second);
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 7e2b0694a860a3..121e7fb4309805 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -2012,6 +2012,15 @@ static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
MethodBody &body) {
body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedProps;\n";
+
+ // Elide the variadic segment size properties if necessary.
+ if (!fmt.allOperands &&
+ op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
+ body << " elidedProps.push_back(\"operandSegmentSizes\");\n";
+ if (!fmt.allResultTypes &&
+ op.getTrait("::mlir::OpTrait::AttrSizedResultSegments"))
+ body << " elidedProps.push_back(\"resultSegmentSizes\");\n";
+
for (const NamedProperty *namedProperty : fmt.usedProperties)
body << " elidedProps.push_back(\"" << namedProperty->name << "\");\n";
for (const NamedAttribute *namedAttr : fmt.usedAttributes)
>From 41971f7c5abc27a39ec64584a314434b4481c578 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Degioanni?=
<theo.degioanni.llvm.deluge062 at simplelogin.fr>
Date: Tue, 12 Nov 2024 22:44:28 +0100
Subject: [PATCH 2/3] unify with the attribute elision
---
mlir/tools/mlir-tblgen/OpFormatGen.cpp | 31 ++++++++++++++------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index 121e7fb4309805..b18d91323a8987 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -2008,18 +2008,25 @@ static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
<< "() != " << propElement.getVar()->prop.getDefaultValue();
}
+/// Elide the variadic segment size properties if necessary.
+/// Pushes elided attribute names in `elidedStorage`.
+static void genVariadicSegmentElision(OperationFormat &fmt, Operator &op,
+ MethodBody &body,
+ const char *elidedStorage) {
+ if (!fmt.allOperands &&
+ op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
+ body << " " << elidedStorage << ".push_back(\"operandSegmentSizes\");\n";
+ if (!fmt.allResultTypes &&
+ op.getTrait("::mlir::OpTrait::AttrSizedResultSegments"))
+ body << " " << elidedStorage << ".push_back(\"resultSegmentSizes\");\n";
+}
+
/// Generate the printer for the 'prop-dict' directive.
static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
MethodBody &body) {
body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedProps;\n";
- // Elide the variadic segment size properties if necessary.
- if (!fmt.allOperands &&
- op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
- body << " elidedProps.push_back(\"operandSegmentSizes\");\n";
- if (!fmt.allResultTypes &&
- op.getTrait("::mlir::OpTrait::AttrSizedResultSegments"))
- body << " elidedProps.push_back(\"resultSegmentSizes\");\n";
+ genVariadicSegmentElision(fmt, op, body, "elidedProps");
for (const NamedProperty *namedProperty : fmt.usedProperties)
body << " elidedProps.push_back(\"" << namedProperty->name << "\");\n";
@@ -2066,13 +2073,9 @@ static void genPropDictPrinter(OperationFormat &fmt, Operator &op,
static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
MethodBody &body, bool withKeyword) {
body << " ::llvm::SmallVector<::llvm::StringRef, 2> elidedAttrs;\n";
- // Elide the variadic segment size attributes if necessary.
- if (!fmt.allOperands &&
- op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
- body << " elidedAttrs.push_back(\"operandSegmentSizes\");\n";
- if (!fmt.allResultTypes &&
- op.getTrait("::mlir::OpTrait::AttrSizedResultSegments"))
- body << " elidedAttrs.push_back(\"resultSegmentSizes\");\n";
+
+ genVariadicSegmentElision(fmt, op, body, "elidedAttrs");
+
for (const StringRef key : fmt.inferredAttributes.keys())
body << " elidedAttrs.push_back(\"" << key << "\");\n";
for (const NamedAttribute *attr : fmt.usedAttributes)
>From 1878be6622505a0eb16cc0f2b5b5eba5984c477a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Degioanni?=
<theo.degioanni.llvm.deluge062 at simplelogin.fr>
Date: Tue, 12 Nov 2024 22:48:22 +0100
Subject: [PATCH 3/3] adjust doc
---
mlir/tools/mlir-tblgen/OpFormatGen.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index b18d91323a8987..8d2e15a941370c 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -2008,8 +2008,8 @@ static void genNonDefaultValueCheck(MethodBody &body, const Operator &op,
<< "() != " << propElement.getVar()->prop.getDefaultValue();
}
-/// Elide the variadic segment size properties if necessary.
-/// Pushes elided attribute names in `elidedStorage`.
+/// Elide the variadic segment size attributes if necessary.
+/// This pushes elided attribute names in `elidedStorage`.
static void genVariadicSegmentElision(OperationFormat &fmt, Operator &op,
MethodBody &body,
const char *elidedStorage) {
More information about the Mlir-commits
mailing list