[Mlir-commits] [mlir] [MLIR] Test generated build functions with move-only parameter types (PR #170391)
Jason Rice
llvmlistbot at llvm.org
Tue Dec 2 15:43:27 PST 2025
https://github.com/ricejasonf created https://github.com/llvm/llvm-project/pull/170391
This adds a test of the MLIR TableGen `OpBuilder` syntax with move-only parameters types. Additionally, a test is added to define a builder outside of the TableGen interface. Incidentally, a GCC 15 warning for reaching the end of control flow without returning was fixed in another function defined in `TestOpDefs.cpp`.
>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] [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 = [{
More information about the Mlir-commits
mailing list