Skip to content

Commit 05dcfcf

Browse files
ricejasonfkcloudy0717
authored andcommitted
[MLIR] Test generated build functions with move-only parameter types (llvm#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.
1 parent b0055f6 commit 05dcfcf

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

mlir/test/lib/Dialect/Test/TestOpDefs.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,3 +1637,14 @@ test::TestCreateTensorOp::getBufferType(
16371637

16381638
return convertTensorToBuffer(getOperation(), options, type);
16391639
}
1640+
1641+
// Define a custom builder for ManyRegionsOp declared in TestOps.td.
1642+
// OpBuilder<(ins "::std::unique_ptr<::mlir::Region>":$firstRegion,
1643+
// "::std::unique_ptr<::mlir::Region>":$secondRegion)>
1644+
void test::ManyRegionsOp::build(
1645+
mlir::OpBuilder &builder, mlir::OperationState &state,
1646+
llvm::SmallVectorImpl<std::unique_ptr<mlir::Region>> &&regions) {
1647+
for (auto &&regionPtr : std::move(regions))
1648+
state.addRegion(std::move(regionPtr));
1649+
ManyRegionsOp::build(builder, state, {}, regions.size());
1650+
}

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,24 @@ def IsolatedGraphRegionOp : TEST_Op<"isolated_graph_region", [
23522352
let assemblyFormat = "attr-dict-with-keyword $region";
23532353
}
23542354

2355+
def ManyRegionsOp : TEST_Op<"many_regions", []> {
2356+
let summary = "operation created with move-only objects";
2357+
let description = [{
2358+
Test op with multiple regions with a `create` function that
2359+
takes parameters containing move-only objects.
2360+
}];
2361+
2362+
let regions = (region VariadicRegion<AnyRegion>:$regions);
2363+
let builders =
2364+
[OpBuilder<(ins "::std::unique_ptr<::mlir::Region>":$singleRegion), [{
2365+
$_state.addRegion(std::move(singleRegion));
2366+
build($_builder, $_state, {}, /*regionsCount=*/1);
2367+
}]>,
2368+
// Define in TestOps.cpp.
2369+
OpBuilder<(ins "::llvm::SmallVectorImpl<::std::unique_ptr<::mlir::"
2370+
"Region>>&&":$regions)>];
2371+
}
2372+
23552373
def AffineScopeOp : TEST_Op<"affine_scope", [AffineScope]> {
23562374
let summary = "affine scope operation";
23572375
let description = [{

0 commit comments

Comments
 (0)