[Mlir-commits] [mlir] [MLIR] Test generated build functions with move-only parameter types (PR #170391)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Dec 2 15:43:58 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Jason Rice (ricejasonf)
<details>
<summary>Changes</summary>
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`.
---
Full diff: https://github.com/llvm/llvm-project/pull/170391.diff
2 Files Affected:
- (modified) mlir/test/lib/Dialect/Test/TestOpDefs.cpp (+13)
- (modified) mlir/test/lib/Dialect/Test/TestOps.td (+18)
``````````diff
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 = [{
``````````
</details>
https://github.com/llvm/llvm-project/pull/170391
More information about the Mlir-commits
mailing list