[Mlir-commits] [mlir] bdf9022 - [MLIR] Test generated build functions with move-only parameter types (#170391)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Dec 3 11:15:05 PST 2025


Author: Jason Rice
Date: 2025-12-03T20:15:00+01:00
New Revision: bdf90227abd55b24821b126a50ab89e49a39a2b5

URL: https://github.com/llvm/llvm-project/commit/bdf90227abd55b24821b126a50ab89e49a39a2b5
DIFF: https://github.com/llvm/llvm-project/commit/bdf90227abd55b24821b126a50ab89e49a39a2b5.diff

LOG: [MLIR] Test generated build functions with move-only parameter types (#170391)

This adds a test of the MLIR TableGen `OpBuilder` syntax with move-only
parameters types. Additionally, an overload is added to test defining a
builder outside of the TableGen interface.

Added: 
    

Modified: 
    mlir/test/lib/Dialect/Test/TestOpDefs.cpp
    mlir/test/lib/Dialect/Test/TestOps.td

Removed: 
    


################################################################################
diff  --git a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
index c153211c68f92..868926520af05 100644
--- a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
+++ b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
@@ -1637,3 +1637,14 @@ test::TestCreateTensorOp::getBufferType(
 
   return convertTensorToBuffer(getOperation(), options, type);
 }
+
+// Define a custom builder for ManyRegionsOp declared in TestOps.td.
+//  OpBuilder<(ins "::std::unique_ptr<::mlir::Region>":$firstRegion,
+//                 "::std::unique_ptr<::mlir::Region>":$secondRegion)>
+void test::ManyRegionsOp::build(
+    mlir::OpBuilder &builder, mlir::OperationState &state,
+    llvm::SmallVectorImpl<std::unique_ptr<mlir::Region>> &&regions) {
+  for (auto &&regionPtr : std::move(regions))
+    state.addRegion(std::move(regionPtr));
+  ManyRegionsOp::build(builder, state, {}, regions.size());
+}

diff  --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index 670223984fd95..5417ae94f00d7 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -2352,6 +2352,24 @@ def IsolatedGraphRegionOp : TEST_Op<"isolated_graph_region",  [
   let assemblyFormat = "attr-dict-with-keyword $region";
 }
 
+def ManyRegionsOp : TEST_Op<"many_regions", []> {
+  let summary = "operation created with move-only objects";
+  let description = [{
+    Test op with multiple regions with a `create` function that
+    takes parameters containing move-only objects.
+  }];
+
+  let regions = (region VariadicRegion<AnyRegion>:$regions);
+  let builders =
+      [OpBuilder<(ins "::std::unique_ptr<::mlir::Region>":$singleRegion), [{
+      $_state.addRegion(std::move(singleRegion));
+      build($_builder, $_state, {}, /*regionsCount=*/1);
+    }]>,
+       // Define in TestOps.cpp.
+       OpBuilder<(ins "::llvm::SmallVectorImpl<::std::unique_ptr<::mlir::"
+                      "Region>>&&":$regions)>];
+}
+
 def AffineScopeOp : TEST_Op<"affine_scope", [AffineScope]> {
   let summary =  "affine scope operation";
   let description = [{


        


More information about the Mlir-commits mailing list