[Mlir-commits] [mlir] [MLIR] Test generated build functions with move-only parameter types (PR #170391)
Jason Rice
llvmlistbot at llvm.org
Tue Dec 2 16:02:20 PST 2025
https://github.com/ricejasonf updated https://github.com/llvm/llvm-project/pull/170391
>From ab7898cf71496a7ed98be0c0ff24581940412928 Mon Sep 17 00:00:00 2001
From: Jason Rice <ricejasonf at gmail.com>
Date: Tue, 2 Dec 2025 15:25:18 -0800
Subject: [PATCH 1/2] [MLIR] Test generated build functions with move-only
parameter types
---
mlir/test/lib/Dialect/Test/TestOpDefs.cpp | 13 +++++++++++++
mlir/test/lib/Dialect/Test/TestOps.td | 18 ++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
index c153211c68f92..0631af8b47fc2 100644
--- a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
+++ b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
@@ -33,6 +33,8 @@ static StringLiteral getVisibilityString(SymbolTable::Visibility visibility) {
return "nested";
case SymbolTable::Visibility::Public:
return "public";
+ default:
+ llvm_unreachable("invalid symboltable visibility type");
}
}
@@ -1637,3 +1639,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>> &®ions) {
+ for (auto &®ionPtr : 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 = [{
>From f476aaac34d77acb66c117e380ca310217a3b3ff Mon Sep 17 00:00:00 2001
From: Jason Rice <ricejasonf at gmail.com>
Date: Tue, 2 Dec 2025 15:59:06 -0800
Subject: [PATCH 2/2] [MLIR] Test generated build functions with move-only
parameter types
---
mlir/test/lib/Dialect/Test/TestOpDefs.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
index 0631af8b47fc2..868926520af05 100644
--- a/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
+++ b/mlir/test/lib/Dialect/Test/TestOpDefs.cpp
@@ -33,8 +33,6 @@ static StringLiteral getVisibilityString(SymbolTable::Visibility visibility) {
return "nested";
case SymbolTable::Visibility::Public:
return "public";
- default:
- llvm_unreachable("invalid symboltable visibility type");
}
}
More information about the Mlir-commits
mailing list