[Mlir-commits] [mlir] [mlir][vector] Add vector.to_elements unrolling (PR #157142)
Erick Ochoa Lopez
llvmlistbot at llvm.org
Thu Sep 11 09:28:20 PDT 2025
================
@@ -0,0 +1,54 @@
+//===- LowerVectorToElements.cpp - Lower 'vector.to_elements' op ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements target-independent rewrites and utilities to lower the
+// 'vector.to_elements' operation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Vector/IR/VectorOps.h"
+#include "mlir/Dialect/Vector/Transforms/LoweringPatterns.h"
+
+#define DEBUG_TYPE "lower-vector-to-elements"
+
+using namespace mlir;
+
+namespace {
+
+struct UnrollToElements final : OpRewritePattern<vector::ToElementsOp> {
+ using OpRewritePattern::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(vector::ToElementsOp op,
+ PatternRewriter &rewriter) const override {
+
+ TypedValue<VectorType> source = op.getSource();
+ FailureOr<SmallVector<Value>> result =
+ vector::unrollVectorValue(source, rewriter);
+ if (failed(result)) {
+ return failure();
+ }
+ SmallVector<Value> vectors = *result;
+
+ // May be a large vector.
+ SmallVector<Value, 0> results;
----------------
amd-eochoalo wrote:
`SmallVector<Type, 0>` is used throughout LLVM's code base. I found this relevant example with a relevant comment.
```cxx
llvm/include/llvm/ADT/IndexedMap.h- // Prefer SmallVector with zero inline storage over std::vector. IndexedMaps
llvm/include/llvm/ADT/IndexedMap.h- // can grow very large and SmallVector grows more efficiently as long as T
llvm/include/llvm/ADT/IndexedMap.h- // is trivially copyable.
llvm/include/llvm/ADT/IndexedMap.h: using StorageT = SmallVector<T, 0>;
```
https://github.com/llvm/llvm-project/pull/157142
More information about the Mlir-commits
mailing list