-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Fix tblgen properties printing #79243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir Author: None (arthurqiu) ChangesThis is to fix the bug reported in https://discourse.llvm.org/t/whats-the-recommended-way-to-use-prop-dict/75921 When Full diff: https://github.com/llvm/llvm-project/pull/79243.diff 2 Files Affected:
diff --git a/mlir/test/IR/properties.mlir b/mlir/test/IR/properties.mlir
index 2aef2abc81f7908..3c4bd57859ef917 100644
--- a/mlir/test/IR/properties.mlir
+++ b/mlir/test/IR/properties.mlir
@@ -2,31 +2,31 @@
// # 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
-// CHECK-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>
+// CHECK-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>{{$}}
// GENERIC: "test.with_properties"()
// GENERIC-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}> : () -> ()
test.with_properties <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>
// CHECK: test.with_nice_properties
-// CHECK-SAME: "foo bar" is -3
+// CHECK-SAME: "foo bar" is -3{{$}}
// GENERIC: "test.with_nice_properties"()
// GENERIC-SAME: <{prop = {label = "foo bar", value = -3 : i32}}> : () -> ()
test.with_nice_properties "foo bar" is -3
// CHECK: test.with_wrapped_properties
-// CHECK-SAME: "content for properties"
+// CHECK-SAME: <{prop = "content for properties"}>{{$}}
// GENERIC: "test.with_wrapped_properties"()
// GENERIC-SAME: <{prop = "content for properties"}> : () -> ()
test.with_wrapped_properties <{prop = "content for properties"}>
// CHECK: test.using_property_in_custom
-// CHECK-SAME: [1, 4, 20]
+// CHECK-SAME: [1, 4, 20]{{$}}
// GENERIC: "test.using_property_in_custom"()
// GENERIC-SAME: prop = array<i64: 1, 4, 20>
test.using_property_in_custom [1, 4, 20]
// CHECK: test.using_property_ref_in_custom
-// CHECK-SAME: 1 + 4 = 5
+// CHECK-SAME: 1 + 4 = 5{{$}}
// GENERIC: "test.using_property_ref_in_custom"()
// GENERIC-SAME: <{
// GENERIC-SAME: first = 1
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index b6405baef28e84a..34921d1d538cb0f 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -366,6 +366,9 @@ struct OperationFormat {
/// Indicate whether attribute are stored in properties.
bool useProperties;
+ /// Indicate whether prop-dict is used in the format
+ bool hasPropDict;
+
/// The Operation class name
StringRef opCppClassName;
@@ -1810,9 +1813,14 @@ static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
body << " }\n";
}
}
- body << " _odsPrinter.printOptionalAttrDict"
- << (withKeyword ? "WithKeyword" : "")
- << "((*this)->getAttrs(), elidedAttrs);\n";
+ if (fmt.hasPropDict)
+ body << " _odsPrinter.printOptionalAttrDict"
+ << (withKeyword ? "WithKeyword" : "")
+ << "((*this)->getDiscardableAttrs(), elidedAttrs);\n";
+ else
+ body << " _odsPrinter.printOptionalAttrDict"
+ << (withKeyword ? "WithKeyword" : "")
+ << "((*this)->getAttrs(), elidedAttrs);\n";
}
/// Generate the printer for a literal value. `shouldEmitSpace` is true if a
@@ -2560,6 +2568,9 @@ LogicalResult OpFormatParser::verify(SMLoc loc,
// Collect the set of used attributes in the format.
fmt.usedAttributes = seenAttrs.takeVector();
+
+ // Set whether prop-dict is used in the format
+ fmt.hasPropDict = hasPropDict;
return success();
}
|
@llvm/pr-subscribers-mlir-core Author: None (arthurqiu) ChangesThis is to fix the bug reported in https://discourse.llvm.org/t/whats-the-recommended-way-to-use-prop-dict/75921 When Full diff: https://github.com/llvm/llvm-project/pull/79243.diff 2 Files Affected:
diff --git a/mlir/test/IR/properties.mlir b/mlir/test/IR/properties.mlir
index 2aef2abc81f7908..3c4bd57859ef917 100644
--- a/mlir/test/IR/properties.mlir
+++ b/mlir/test/IR/properties.mlir
@@ -2,31 +2,31 @@
// # 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
-// CHECK-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>
+// CHECK-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>{{$}}
// GENERIC: "test.with_properties"()
// GENERIC-SAME: <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}> : () -> ()
test.with_properties <{a = 32 : i64, array = array<i64: 1, 2, 3, 4>, b = "foo"}>
// CHECK: test.with_nice_properties
-// CHECK-SAME: "foo bar" is -3
+// CHECK-SAME: "foo bar" is -3{{$}}
// GENERIC: "test.with_nice_properties"()
// GENERIC-SAME: <{prop = {label = "foo bar", value = -3 : i32}}> : () -> ()
test.with_nice_properties "foo bar" is -3
// CHECK: test.with_wrapped_properties
-// CHECK-SAME: "content for properties"
+// CHECK-SAME: <{prop = "content for properties"}>{{$}}
// GENERIC: "test.with_wrapped_properties"()
// GENERIC-SAME: <{prop = "content for properties"}> : () -> ()
test.with_wrapped_properties <{prop = "content for properties"}>
// CHECK: test.using_property_in_custom
-// CHECK-SAME: [1, 4, 20]
+// CHECK-SAME: [1, 4, 20]{{$}}
// GENERIC: "test.using_property_in_custom"()
// GENERIC-SAME: prop = array<i64: 1, 4, 20>
test.using_property_in_custom [1, 4, 20]
// CHECK: test.using_property_ref_in_custom
-// CHECK-SAME: 1 + 4 = 5
+// CHECK-SAME: 1 + 4 = 5{{$}}
// GENERIC: "test.using_property_ref_in_custom"()
// GENERIC-SAME: <{
// GENERIC-SAME: first = 1
diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index b6405baef28e84a..34921d1d538cb0f 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -366,6 +366,9 @@ struct OperationFormat {
/// Indicate whether attribute are stored in properties.
bool useProperties;
+ /// Indicate whether prop-dict is used in the format
+ bool hasPropDict;
+
/// The Operation class name
StringRef opCppClassName;
@@ -1810,9 +1813,14 @@ static void genAttrDictPrinter(OperationFormat &fmt, Operator &op,
body << " }\n";
}
}
- body << " _odsPrinter.printOptionalAttrDict"
- << (withKeyword ? "WithKeyword" : "")
- << "((*this)->getAttrs(), elidedAttrs);\n";
+ if (fmt.hasPropDict)
+ body << " _odsPrinter.printOptionalAttrDict"
+ << (withKeyword ? "WithKeyword" : "")
+ << "((*this)->getDiscardableAttrs(), elidedAttrs);\n";
+ else
+ body << " _odsPrinter.printOptionalAttrDict"
+ << (withKeyword ? "WithKeyword" : "")
+ << "((*this)->getAttrs(), elidedAttrs);\n";
}
/// Generate the printer for a literal value. `shouldEmitSpace` is true if a
@@ -2560,6 +2568,9 @@ LogicalResult OpFormatParser::verify(SMLoc loc,
// Collect the set of used attributes in the format.
fmt.usedAttributes = seenAttrs.takeVector();
+
+ // Set whether prop-dict is used in the format
+ fmt.hasPropDict = hasPropDict;
return success();
}
|
Thanks! |
This is to fix the bug reported in https://discourse.llvm.org/t/whats-the-recommended-way-to-use-prop-dict/75921
When
prop-dict
is used in the assembly format,attr-dict
should print discardable attributes only.