-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[MLIR][IRDL] Support camelCase segment size attributes in IRDL verifier #168836
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
|
@llvm/pr-subscribers-mlir-irdl Author: Twice (PragmaTwice) ChangesIn 2 years ago, However, the op verifiers in IRDL loading phase is still using old attributes like This PR is to support to use camelCase segment size attributes in IRDL verifier. Note that to avoid breaking change Full diff: https://github.com/llvm/llvm-project/pull/168836.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/IRDL/IRDLLoading.cpp b/mlir/lib/Dialect/IRDL/IRDLLoading.cpp
index 212ccc931f6e0..22b91a844fa8d 100644
--- a/mlir/lib/Dialect/IRDL/IRDLLoading.cpp
+++ b/mlir/lib/Dialect/IRDL/IRDLLoading.cpp
@@ -169,8 +169,11 @@ LogicalResult getSegmentSizes(Operation *op, StringRef elemName,
LogicalResult getOperandSegmentSizes(Operation *op,
ArrayRef<Variadicity> variadicities,
SmallVectorImpl<int> &segmentSizes) {
- return getSegmentSizes(op, "operand", "operand_segment_sizes",
- op->getNumOperands(), variadicities, segmentSizes);
+ StringRef attrName = op->getAttr("operandSegmentSizes")
+ ? "operandSegmentSizes"
+ : "operand_segment_sizes";
+ return getSegmentSizes(op, "operand", attrName, op->getNumOperands(),
+ variadicities, segmentSizes);
}
/// Compute the segment sizes of the given results.
@@ -180,8 +183,11 @@ LogicalResult getOperandSegmentSizes(Operation *op,
LogicalResult getResultSegmentSizes(Operation *op,
ArrayRef<Variadicity> variadicities,
SmallVectorImpl<int> &segmentSizes) {
- return getSegmentSizes(op, "result", "result_segment_sizes",
- op->getNumResults(), variadicities, segmentSizes);
+ StringRef attrName = op->getAttr("resultSegmentSizes")
+ ? "resultSegmentSizes"
+ : "result_segment_sizes";
+ return getSegmentSizes(op, "result", attrName, op->getNumResults(),
+ variadicities, segmentSizes);
}
/// Verify that the given operation satisfies the given constraints.
diff --git a/mlir/test/Dialect/IRDL/variadics.mlir b/mlir/test/Dialect/IRDL/variadics.mlir
index a8871fcf5ebd9..97b28e0998e00 100644
--- a/mlir/test/Dialect/IRDL/variadics.mlir
+++ b/mlir/test/Dialect/IRDL/variadics.mlir
@@ -161,6 +161,18 @@ func.func @testMultOperands(%x: i16, %y: i32, %z: i64) {
// CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}) {operand_segment_sizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()
return
}
+// -----
+
+// Check that attribute 'operandSegmentSizes' can work well as 'operand_segment_sizes'
+func.func @testMultOperands(%x: i16, %y: i32, %z: i64) {
+ "testvar.var_and_opt_operand"(%x, %x, %z) {operandSegmentSizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> ()
+ // CHECK: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> ()
+ "testvar.var_and_opt_operand"(%x, %x, %y, %z) {operandSegmentSizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> ()
+ // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> ()
+ "testvar.var_and_opt_operand"(%y, %z) {operandSegmentSizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()
+ // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()
+ return
+}
// -----
@@ -365,6 +377,19 @@ func.func @testMultResults() {
// -----
+// Check that attribute 'resultSegmentSizes' can work well as 'result_segment_sizes'
+func.func @testMultResults() {
+ "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64)
+ // CHECK: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64)
+ "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64)
+ // CHECK-NEXT: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64)
+ "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 1, 1>} : () -> (i32, i64)
+ // CHECK-NEXT: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 1, 1>} : () -> (i32, i64)
+ return
+}
+
+// -----
+
// Check that the segment sizes expects non-negative values
func.func @testMultResultsSegmentNegative() {
// expected-error@+1 {{'result_segment_sizes' attribute for specifying result segments must have non-negative values}}
|
|
@llvm/pr-subscribers-mlir Author: Twice (PragmaTwice) ChangesIn 2 years ago, However, the op verifiers in IRDL loading phase is still using old attributes like This PR is to support to use camelCase segment size attributes in IRDL verifier. Note that to avoid breaking change Full diff: https://github.com/llvm/llvm-project/pull/168836.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/IRDL/IRDLLoading.cpp b/mlir/lib/Dialect/IRDL/IRDLLoading.cpp
index 212ccc931f6e0..22b91a844fa8d 100644
--- a/mlir/lib/Dialect/IRDL/IRDLLoading.cpp
+++ b/mlir/lib/Dialect/IRDL/IRDLLoading.cpp
@@ -169,8 +169,11 @@ LogicalResult getSegmentSizes(Operation *op, StringRef elemName,
LogicalResult getOperandSegmentSizes(Operation *op,
ArrayRef<Variadicity> variadicities,
SmallVectorImpl<int> &segmentSizes) {
- return getSegmentSizes(op, "operand", "operand_segment_sizes",
- op->getNumOperands(), variadicities, segmentSizes);
+ StringRef attrName = op->getAttr("operandSegmentSizes")
+ ? "operandSegmentSizes"
+ : "operand_segment_sizes";
+ return getSegmentSizes(op, "operand", attrName, op->getNumOperands(),
+ variadicities, segmentSizes);
}
/// Compute the segment sizes of the given results.
@@ -180,8 +183,11 @@ LogicalResult getOperandSegmentSizes(Operation *op,
LogicalResult getResultSegmentSizes(Operation *op,
ArrayRef<Variadicity> variadicities,
SmallVectorImpl<int> &segmentSizes) {
- return getSegmentSizes(op, "result", "result_segment_sizes",
- op->getNumResults(), variadicities, segmentSizes);
+ StringRef attrName = op->getAttr("resultSegmentSizes")
+ ? "resultSegmentSizes"
+ : "result_segment_sizes";
+ return getSegmentSizes(op, "result", attrName, op->getNumResults(),
+ variadicities, segmentSizes);
}
/// Verify that the given operation satisfies the given constraints.
diff --git a/mlir/test/Dialect/IRDL/variadics.mlir b/mlir/test/Dialect/IRDL/variadics.mlir
index a8871fcf5ebd9..97b28e0998e00 100644
--- a/mlir/test/Dialect/IRDL/variadics.mlir
+++ b/mlir/test/Dialect/IRDL/variadics.mlir
@@ -161,6 +161,18 @@ func.func @testMultOperands(%x: i16, %y: i32, %z: i64) {
// CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}) {operand_segment_sizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()
return
}
+// -----
+
+// Check that attribute 'operandSegmentSizes' can work well as 'operand_segment_sizes'
+func.func @testMultOperands(%x: i16, %y: i32, %z: i64) {
+ "testvar.var_and_opt_operand"(%x, %x, %z) {operandSegmentSizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> ()
+ // CHECK: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> ()
+ "testvar.var_and_opt_operand"(%x, %x, %y, %z) {operandSegmentSizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> ()
+ // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> ()
+ "testvar.var_and_opt_operand"(%y, %z) {operandSegmentSizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()
+ // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()
+ return
+}
// -----
@@ -365,6 +377,19 @@ func.func @testMultResults() {
// -----
+// Check that attribute 'resultSegmentSizes' can work well as 'result_segment_sizes'
+func.func @testMultResults() {
+ "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64)
+ // CHECK: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64)
+ "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64)
+ // CHECK-NEXT: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64)
+ "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 1, 1>} : () -> (i32, i64)
+ // CHECK-NEXT: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 1, 1>} : () -> (i32, i64)
+ return
+}
+
+// -----
+
// Check that the segment sizes expects non-negative values
func.func @testMultResultsSegmentNegative() {
// expected-error@+1 {{'result_segment_sizes' attribute for specifying result segments must have non-negative values}}
|
🐧 Linux x64 Test Results
|
math-fehr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Is it still worth it to support operand_segment_sizes at that point, since now everything should be moved to camelCase?
Ahh seems not. I have checked xdsl and found that it already did this replacement via xdslproject/xdsl@ca21d8e. I think we can drop the support to I'll make this change soon. |
Done in 895aa68. |
math-fehr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks a lot!
|
Thank you for your review. I'll merge it soon. |
…er (llvm#168836) Two years ago, `operand_segment_sizes` and `result_segment_sizes` were renamed to `operandSegmentSizes` and `resultSegmentSizes` (check related commits, e.g. llvm@363b655). However, the op verifiers in IRDL loading phase is still using old attributes like `operand_segment_sizes` and `result_segment_sizes`, which causes some conflict, e.g. it is not compatible with the OpView builder in MLIR python bindings (which generates camelCase segment attributes). This PR is to support to use camelCase segment size attributes in IRDL verifier. Note that support of `operand_segment_sizes` and `result_segment_sizes` is dropped. I found this issue since I'm working on a new IRDL wrapper in the MLIR python bindings.
…er (llvm#168836) Two years ago, `operand_segment_sizes` and `result_segment_sizes` were renamed to `operandSegmentSizes` and `resultSegmentSizes` (check related commits, e.g. llvm@363b655). However, the op verifiers in IRDL loading phase is still using old attributes like `operand_segment_sizes` and `result_segment_sizes`, which causes some conflict, e.g. it is not compatible with the OpView builder in MLIR python bindings (which generates camelCase segment attributes). This PR is to support to use camelCase segment size attributes in IRDL verifier. Note that support of `operand_segment_sizes` and `result_segment_sizes` is dropped. I found this issue since I'm working on a new IRDL wrapper in the MLIR python bindings.
Two years ago,
operand_segment_sizesandresult_segment_sizeswere renamed tooperandSegmentSizesandresultSegmentSizes(check related commits, e.g. 363b655).However, the op verifiers in IRDL loading phase is still using old attributes like
operand_segment_sizesandresult_segment_sizes, which causes some conflict, e.g. it is not compatible with the OpView builder in MLIR python bindings (which generates camelCase segment attributes).This PR is to support to use camelCase segment size attributes in IRDL verifier. Note that support of
operand_segment_sizesandresult_segment_sizesis dropped.I found this issue since I'm working on a new IRDL wrapper in the MLIR python bindings.