Skip to content

Commit ef2b880

Browse files
[mlir][vector] Implement InferTypeOpInterface on vector.to_elements (#153172)
Just for convenience. This auto-generates an additional builder that infers the result type.
1 parent 475921d commit ef2b880

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mlir/include/mlir/Dialect/Vector/IR/VectorOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def Vector_FMAOp :
754754
}
755755

756756
def Vector_ToElementsOp : Vector_Op<"to_elements", [
757-
Pure,
757+
InferTypeOpAdaptor, Pure,
758758
ShapedTypeMatchesElementCountAndTypes<"source", "elements">]> {
759759
let summary = "operation that decomposes a vector into all its scalar elements";
760760
let description = [{

mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,6 +2402,16 @@ LogicalResult ToElementsOp::fold(FoldAdaptor adaptor,
24022402
return foldToElementsFromElements(*this, results);
24032403
}
24042404

2405+
LogicalResult
2406+
ToElementsOp::inferReturnTypes(MLIRContext *ctx, std::optional<Location> loc,
2407+
ToElementsOp::Adaptor adaptor,
2408+
SmallVectorImpl<Type> &inferredReturnTypes) {
2409+
auto vecType = cast<VectorType>(adaptor.getSource().getType());
2410+
Type elType = vecType.getElementType();
2411+
inferredReturnTypes.append(vecType.getNumElements(), elType);
2412+
return success();
2413+
}
2414+
24052415
//===----------------------------------------------------------------------===//
24062416
// FromElementsOp
24072417
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)