[Mlir-commits] [mlir] ef2b880 - [mlir][vector] Implement `InferTypeOpInterface` on `vector.to_elements` (#153172)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Aug 12 06:15:33 PDT 2025
Author: Matthias Springer
Date: 2025-08-12T15:15:30+02:00
New Revision: ef2b8805bf30ddb4720bb167ee7427070c8be7ce
URL: https://github.com/llvm/llvm-project/commit/ef2b8805bf30ddb4720bb167ee7427070c8be7ce
DIFF: https://github.com/llvm/llvm-project/commit/ef2b8805bf30ddb4720bb167ee7427070c8be7ce.diff
LOG: [mlir][vector] Implement `InferTypeOpInterface` on `vector.to_elements` (#153172)
Just for convenience. This auto-generates an additional builder that
infers the result type.
Added:
Modified:
mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index b3b8afdd8b4c1..30c1d97ba58f1 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -754,7 +754,7 @@ def Vector_FMAOp :
}
def Vector_ToElementsOp : Vector_Op<"to_elements", [
- Pure,
+ InferTypeOpAdaptor, Pure,
ShapedTypeMatchesElementCountAndTypes<"source", "elements">]> {
let summary = "operation that decomposes a vector into all its scalar elements";
let description = [{
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index cb4783d26a114..74e48b59b6460 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -2402,6 +2402,16 @@ LogicalResult ToElementsOp::fold(FoldAdaptor adaptor,
return foldToElementsFromElements(*this, results);
}
+LogicalResult
+ToElementsOp::inferReturnTypes(MLIRContext *ctx, std::optional<Location> loc,
+ ToElementsOp::Adaptor adaptor,
+ SmallVectorImpl<Type> &inferredReturnTypes) {
+ auto vecType = cast<VectorType>(adaptor.getSource().getType());
+ Type elType = vecType.getElementType();
+ inferredReturnTypes.append(vecType.getNumElements(), elType);
+ return success();
+}
+
//===----------------------------------------------------------------------===//
// FromElementsOp
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list