Skip to content

Conversation

@PragmaTwice
Copy link
Member

@PragmaTwice PragmaTwice commented Nov 20, 2025

Two years ago, operand_segment_sizes and result_segment_sizes were renamed to operandSegmentSizes and resultSegmentSizes (check related commits, e.g. 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.

@llvmbot
Copy link
Member

llvmbot commented Nov 20, 2025

@llvm/pr-subscribers-mlir-irdl

Author: Twice (PragmaTwice)

Changes

In 2 years ago, operand_segment_sizes and result_segment_sizes were renamed to operandSegmentSizes and resultSegmentSizes (check related commits, e.g. 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 to avoid breaking change operand_segment_sizes and result_segment_sizes can still be used if operandSegmentSizes and resultSegmentSizes is not found. (not sure this is good or not though.)


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

2 Files Affected:

  • (modified) mlir/lib/Dialect/IRDL/IRDLLoading.cpp (+10-4)
  • (modified) mlir/test/Dialect/IRDL/variadics.mlir (+25)
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}}

@llvmbot
Copy link
Member

llvmbot commented Nov 20, 2025

@llvm/pr-subscribers-mlir

Author: Twice (PragmaTwice)

Changes

In 2 years ago, operand_segment_sizes and result_segment_sizes were renamed to operandSegmentSizes and resultSegmentSizes (check related commits, e.g. 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 to avoid breaking change operand_segment_sizes and result_segment_sizes can still be used if operandSegmentSizes and resultSegmentSizes is not found. (not sure this is good or not though.)


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

2 Files Affected:

  • (modified) mlir/lib/Dialect/IRDL/IRDLLoading.cpp (+10-4)
  • (modified) mlir/test/Dialect/IRDL/variadics.mlir (+25)
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}}

@github-actions
Copy link

github-actions bot commented Nov 20, 2025

🐧 Linux x64 Test Results

  • 7118 tests passed
  • 594 tests skipped

Copy link
Contributor

@math-fehr math-fehr left a 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?

@PragmaTwice
Copy link
Member Author

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 operand_segment_sizes to make the code and behavior more clear.

I'll make this change soon.

@PragmaTwice
Copy link
Member Author

I'll make this change soon.

Done in 895aa68.

@math-fehr math-fehr self-requested a review November 24, 2025 03:49
Copy link
Contributor

@math-fehr math-fehr left a 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!

@PragmaTwice
Copy link
Member Author

Thank you for your review. I'll merge it soon.

@PragmaTwice PragmaTwice merged commit 202d784 into llvm:main Nov 24, 2025
10 checks passed
aadeshps-mcw pushed a commit to aadeshps-mcw/llvm-project that referenced this pull request Nov 26, 2025
…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.
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Nov 26, 2025
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants