summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Vector/Transforms/VectorUnroll.cpp
AgeCommit message (Collapse)Author
2025-11-19[MLIR][Vector] Add unroll pattern for vector.shape_cast (#167738)Nishant Patel
This PR adds pattern for unrolling shape_cast given a targetShape. This PR is a follow up of #164010 which was very general and was using inserts and extracts on each element (which is also LowerVectorShapeCast.cpp is doing). After doing some more research on use cases, we (me and @Jianhui-Li ) realized that the previous version in #164010 is unnecessarily generic and doesn't fit our performance needs. Our use case requires that targetShape is contiguous in both source and result vector. This pattern only applies when contiguous slices can be extracted from the source vector and inserted into the result vector such that each slice remains in vector form with targetShape (and not decompose to scalars). In these cases, the unrolling proceeds as: vector.extract_strided_slice -> vector.shape_cast (on the slice unrolled) -> vector.insert_strided_slice
2025-10-15[MLIR][Vector] Extend elementwise pattern to support unrolling from higher ↵Nishant Patel
rank to lower rank (#162515) This PR enhances the elementwise unrolling pattern to support higher rank to lower rank unroll. The approach is to add leading unit dims to lower rank targetShape to match the rank of original vector (because ExtractStridedSlice requires same rank to extractSlices), extract slice, reshape to targetShape's rank and perform the operation.
2025-09-18[mlir] Move vector.{to_elements,from_elements} unrolling to ↵Erick Ochoa Lopez
`VectorUnroll.cpp` (#159118) This PR moves the patterns that unroll vector.to_elements and vector.from_elements into the file with other vector unrolling operations. This PR also adds these unrolling patterns into the `populateVectorUnrollPatterns`. And renames `populateVectorToElementsLoweringPatterns` `populateVectorFromElementsLoweringPatterns` to `populateVectorToElementsUnrollPatterns` `populateVectorFromElementsUnrollPatterns`.
2025-09-16[MLIR][Vector] Add unrolling pattern for vector StepOp (#157752)Nishant Patel
This PR adds unrolling pattern for vector.step op to VectorUnroll transform.
2025-08-25[mlir][vector] Rename gather/scatter arguments (nfc) (#153640)Andrzej Warzyński
Renames `indices` as `offsets` and `index_vec` as `indices`. This is primarily to make clearer distinction between the arguments.
2025-07-25[mlir] Switch to new LDBG macro (#150616)Jacques Pienaar
Change local variants to use new central one.
2025-07-25[mlir][vector] Add a check to ensure input vector rank equals target shape ↵Longsheng Mou
rank (#149239) The crash is caused because, during IR transformation, the vector-unrolling pass (using ExtractStridedSliceOp) attempts to slice an input vector of higher rank using a target vector of lower rank, which is not supported. Fixes #148368.
2025-07-22[mlir][NFC] update `mlir/Dialect` create APIs (24/n) (#149931)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-06-20[mlir][vector] Add unroll patterns for vector.load and vector.store (#143420)Nishant Patel
This PR adds unroll patterns for vector.load and vector.store. This PR is follow up of #137558
2025-06-05[mlir][vector] add unroll pattern for broadcast (#142011)Chao Chen
This PR adds `UnrollBroadcastPattern` to `VectorUnroll` transform. To support this, it also extends `BroadcastOp` definition with `VectorUnrollOpInterface`
2025-05-12[mlir][vector] Standardize `base` Naming Across Vector Ops (NFC) (#137859)Andrzej Warzyński
[mlir][vector] Standardize base Naming Across Vector Ops (NFC) This change standardizes the naming convention for the argument representing the value to read from or write to in Vector ops that interface with Tensors or MemRefs. Specifically, it ensures that all such ops use the name `base` (i.e., the base address or location to which offsets are applied). Updated operations: * `vector.transfer_read`, * `vector.transfer_write`. For reference, these ops already use `base`: * `vector.load`, `vector.store`, `vector.scatter`, `vector.gather`, `vector.expandload`, `vector.compressstore`, `vector.maskedstore`, `vector.maskedload`. This is a non-functional change (NFC) and does not alter the semantics of these operations. However, it does require users of the XFer ops to switch from `op.getSource()` to `op.getBase()`. To ease the transition, this PR temporarily adds a `getSource()` interface method for compatibility. This is intended for downstream use only and should not be relied on upstream. The method will be removed prior to the LLVM 21 release. Implements #131602
2025-04-20[mlir] Call hash_combine_range with ranges (NFC) (#136512)Kazu Hirata
2025-04-18[mlir][vector] Switch to `llvm::interleaved` in debug prints. NFC. (#136248)Jakub Kuderski
Clean up printing code by switching to `llvm::interleaved` from https://github.com/llvm/llvm-project/pull/135517.
2025-03-08[mlir]Add a check to ensure bailing out when reducing to a scalar (#129694)Prakhar Dixit
Fixes issue #64075 Referencing this comment for more detailed view -> https://github.com/llvm/llvm-project/issues/64075#issuecomment-2694112594 **Minimal example crashing :** ``` func.func @multi_reduction(%0: vector<4x2xf32>, %acc1: f32) -> f32 { %2 = vector.multi_reduction <add>, %0, %acc1 [0, 1] : vector<4x2xf32> to f32 return %2 : f32 } ```
2025-02-26[mlir][vector] Add a check to ensure input vector rank equals target shape ↵Prakhar Dixit
rank (#127706) Fixes issue #126197 The crash is caused because, during IR transformation, the vector-unrolling pass (using ExtractStridedSliceOp) attempts to slice an input vector of higher rank using a target vector of lower rank, which is not supported. Specific example : ``` module { func.func @func1() { %cst_25 = arith.constant dense<3.718400e+04> : vector<4x2x2xf16> %cst_26 = arith.constant dense<1.000000e+00> : vector<24x2x2xf32> %47 = vector.fma %cst_26, %cst_26, %cst_26 : vector<24x2x2xf32> %818 = scf.execute_region -> vector<24x2x2xf32> { scf.yield %47 : vector<24x2x2xf32> } %823 = vector.extract_strided_slice %cst_25 {offsets = [2], sizes = [1], strides = [1]} : vector<4x2x2xf16> to vector<1x2x2xf16> return } } ``` --------- Co-authored-by: Kai Sasaki <lewuathe@gmail.com>
2025-02-07[mlir][Vector] Fold `vector.extract` from poison vector (#126122)Diego Caballero
This PR adds a folder for `vector.extract(ub.poison) -> ub.poison`. It also replaces `create` with `createOrFold` insert/extract ops in vector unroll and transpose lowering patterns to trigger the poison foldings introduced recently.
2024-08-04[mlir] Construct SmallVector with ArrayRef (NFC) (#101896)Kazu Hirata
2024-06-11mlir/MathExtras: consolidate with llvm/MathExtras (#95087)Ramkumar Ramachandra
This patch is part of a project to move the Presburger library into LLVM.
2024-02-14Apply clang-tidy fixes for llvm-qualified-auto in VectorUnroll.cpp (NFC)Mehdi Amini
2023-11-20[mlir][vector] Modernize `vector.transpose` op (#72594)Matthias Springer
* Declare arguments/results with `let` statements. * Rename `transp` to `permutation`. * Change type of `transp` from `I64ArrayAttr` to `DenseI64ArrayAttr` (provides direct access to `ArrayRef<int64_t>` instead of `ArrayAttr`).
2023-11-14[mlir][affine][nfc] cleanup deprecated T.cast style functions (#71269)long.chen
detail see the docment: https://mlir.llvm.org/deprecation/ Not all changes are made manually, most of them are made through a clang tool I wrote https://github.com/lipracer/cpp-refactor.
2023-09-14[mlir][vector] Cleanup VectorUnroll and create a generic tile iteration utilityChristopher Bate
This change refactors some of the utilities used to unroll larger vector computations into smaller vector computations. In fact, the indexing computations used here are rather generic and are useful in other dialects or downstream projects. Therefore, a utility for iterating over all possible tile offsets for a particular pair of static (shape, tiled shape) is introduced in IndexingUtils and replaces the existing computations in the vector unrolling transformations. This builds off of the refactoring of IndexingUtils introduced in 203fad476b7e. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D150000
2023-06-08[mlir][vector] NFC - Add debug information to vector unrolling patternsNicolas Vasilache
2023-05-12[mlir] Move casting calls from methods to function callsTres Popp
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Caveats include: - This clang-tidy script probably has more problems. - This only touches C++ code, so nothing that is being generated. Context: - https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" - Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This first patch was created with the following steps. The intention is to only do automated changes at first, so I waste less time if it's reverted, and so the first mass change is more clear as an example to other teams that will need to follow similar steps. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. 4. Some changes have been deleted for the following reasons: - Some files had a variable also named cast - Some files had not included a header file that defines the cast functions - Some files are definitions of the classes that have the casting methods, so the code still refers to the method instead of the function without adding a prefix or removing the method declaration at the same time. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\ mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\ mlir/lib/**/IR/\ mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\ mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\ mlir/test/lib/Dialect/Test/TestTypes.cpp\ mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\ mlir/test/lib/Dialect/Test/TestAttributes.cpp\ mlir/unittests/TableGen/EnumsGenTest.cpp\ mlir/test/python/lib/PythonTestCAPI.cpp\ mlir/include/mlir/IR/ ``` Differential Revision: https://reviews.llvm.org/D150123
2023-04-24[mlir][vector] Add unroll pattern for vector.gatherQuinn Dawkins
This pattern is useful for SPIR-V to unroll to a supported vector size before later lowerings. The unrolling pattern is closer to an elementwise op than the transfer ops because the index values from which to extract elements are captured by the index vector and thus there is no need to update the base offsets when unrolling gather. Differential Revision: https://reviews.llvm.org/D149066
2023-04-20[mlir][Affine][NFC] Wrap dialect in "affine" namespaceMatthias Springer
This cleanup aligns the affine dialect with all the other dialects. Differential Revision: https://reviews.llvm.org/D148687
2023-03-29[mlir][Vector] Remove lhs and rhs masks from vector.contractDiego Caballero
This patch removes the historical lhs and rhs masks in vector.contract, now that vector.mask supports vector.contract and the lhs and rhs masks are barely supported by all the vector.contract lowerings and transformations. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D144430
2023-03-15[ADT][mlir][NFCI] Do not use non-const lvalue-refs with enumerateJakub Kuderski
Replace references to enumerate results with either result_pairs (reference wrapper type) or structured bindings. I did not use structured bindings everywhere as it wasn't clear to me it would improve readability. This is in preparation to the switch to zip semantics which won't support non-const lvalue reference to elements: https://reviews.llvm.org/D144503. I chose to use values instead of const lvalue-refs because MLIR is biased towards avoiding `const` local variables. This won't degrade performance because currently `result_pair` is cheap to copy (size_t + iterator), and in the future, the enumerator iterator dereference will return temporaries anyway. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D146006
2023-03-14[mlir][DialectUtils] Cleanup IndexingUtils and provide more affine variants ↵Nicolas Vasilache
while reusing implementations Differential Revision: https://reviews.llvm.org/D145784
2023-02-16[mlir][vector] NFC: Improve vector type accessor methodsLei Zhang
Plain `getVectorType()` can be quite confusing and error-prone given that, well, vector ops always work on vector types, and it can commonly involve both source and result vectors. So this commit makes various such accessor methods to be explicit w.r.t. source or result vectors. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D144159
2023-01-14[mlir] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-13[mlir] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-28[mlir][vector] Fix typo, NFC.jacquesguan
Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D140681
2022-12-04[mlir] Use std::nullopt instead of None in comments (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[mlir] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-22[NFC][mlir] VectorUtils / IndexingUtils simplifications and cleanupsNicolas Vasilache
This revision refactors and cleans up a bunch of infra related to vector, shapes and indexing into more reusable APIs. Differential Revision: https://reviews.llvm.org/D138501
2022-09-16[mlir][vector] Remove ExtractMap/InsertMap operationsThomas Raoux
As discussed on discourse: https://discourse.llvm.org/t/vector-vector-distribution-large-vector-to-small-vector/1983/22 removing insert_map/extract_map op as vector distribution now uses warp_execute_on_lane_0 op. Differential Revision: https://reviews.llvm.org/D134000