summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Vector/Transforms/VectorDropLeadUnitDim.cpp
AgeCommit message (Collapse)Author
2025-10-11[mlir] Use llvm accumulate wrappers. NFCI. (#162957)Jakub Kuderski
Use wrappers around `std::accumulate` to make the code more concise and less bug-prone: https://github.com/llvm/llvm-project/pull/162129. With `std::accumulate`, it's the initial value that determines the accumulator type. `llvm::sum_of` and `llvm::product_of` pick the right accumulator type based on the range element type. Found some funny bugs like a local accumulate helper that calculated a sum with initial value of 1 -- we didn't hit the bug because the code was actually dead...
2025-10-02[mlir][vector] Simplify op rewrite pattern inheriting constructors. NFC. ↵Jakub Kuderski
(#161670) Use the `Base` type alias from https://github.com/llvm/llvm-project/pull/158433.
2025-09-15[mlir][vector] Use `source` as the source argument name (#158258)Andrzej Warzyński
This patch updates the following ops to use `source` (instead of `vector`) as the name for their source argument: * `vector.extract` * `vector.scalable.extract` * `vector.extract_strided_slice` This change ensures naming consistency with the "builders" for these Ops that already use the name `source` rather than `vector`. It also addresses part of: * https://github.com/llvm/llvm-project/issues/131602 Specifically, it ensures that we use `source` and `dest` for read and write operations, respectively (as opposed to `vector` and `dest`).
2025-07-25[mlir][NFC] update `mlir/Dialect` create APIs (32/n) (#150657)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
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-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-16[mlir][vector] Remove redundant shape_cast(shape_cast(x)) pattern (#135447)James Newling
This PR removes one OpRewritePattern `shape_cast(shape_cast(x)) -> x` that is already handled by `ShapeCastOp::fold`. Note that this might affect downstream users who indirectly call `populateShapeCastFoldingPatterns(RewritePatternSet &patterns, PatternBenefit)` and then use `patterns` with a `GreedyRewriteConfig config` that has `config.fold = false`. (only user I've checked is IREE, that never uses config.fold = false).
2025-04-07[mlir][vector] Standardise `valueToStore` Naming Across Vector Ops (NFC) ↵Andrzej Warzyński
(#134206) This change standardises the naming convention for the argument representing the value to store in various vector operations. Specifically, it ensures that all vector ops storing a value—whether into memory, a tensor, or another vector — use `valueToStore` for the corresponding argument name. Updated operations: * `vector.transfer_write`, `vector.insert`, `vector.scalable_insert`, `vector.insert_strided_slice`. For reference, here are operations that currently use `valueToStore`: * `vector.store` `vector.scatter`, `vector.compressstore`, `vector.maskedstore`. This change is non-functional (NFC) and does not affect the functionality of these operations. Implements #131602
2025-01-29Fix typo "tranpose" (#124929)Jay Foad
2025-01-21[mlir][NFC] Avoid using braced initializer lists to call a constructor. ↵Han-Chung Wang
(#123714) In the LLVM style guide, we prefer not using braced initializer lists to call a constructor. Also, we prefer using an equal before the open curly brace if we use a braced initializer list when initializing a variable. See https://llvm.org/docs/CodingStandards.html#do-not-use-braced-initializer-lists-to-call-a-constructor for more details. The style guide does not explain the reason well. There is an article from abseil, which mentions few benefits. E.g., we can avoid the most vexing parse, etc. See https://abseil.io/tips/88 for more details. Signed-off-by: hanhanW <hanhan0912@gmail.com>
2024-07-29[mlir][vector] Use `DenseI64ArrayAttr` for constant_mask dim sizes (#100997)Benjamin Maxwell
This prevents a bunch of boilerplate conversions to/from IntegerAttrs and int64_ts. Other than that this is a NFC.
2024-04-19Switch member calls to `isa/dyn_cast/cast/...` to free function calls. (#89356)Christian Sigg
This change cleans up call sites. Next step is to mark the member functions deprecated. See https://mlir.llvm.org/deprecation and https://discourse.llvm.org/t/preferred-casting-style-going-forward.
2024-04-03[mlir][vector] Update `castAwayContractionLeadingOneDim` to omit transposes ↵Kojo Acquah
solely on leading unit dims. (#85694) Updates `castAwayContractionLeadingOneDim` to check for leading unit dimensions before inserting `vector.transpose` ops. Currently `castAwayContractionLeadingOneDim` removes all leading unit dims based on the accumulator and transpose any subsequent operands to match the accumulator indexing. This does not take into account if the transpose is strictly necessary, for instance when given this vector-matrix contract: ```mlir %result = vector.contract {indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d1, d2)>], iterator_types = ["parallel", "parallel", "parallel", "reduction"], kind = #vector.kind<add>} %lhs, %rhs, %acc : vector<1x1x8xi32>, vector<1x8x8xi32> into vector<1x8xi32> ``` Passing this through `castAwayContractionLeadingOneDim` pattern produces the following: ```mlir %0 = vector.transpose %arg0, [1, 0, 2] : vector<1x1x8xi32> to vector<1x1x8xi32> %1 = vector.extract %0[0] : vector<1x8xi32> from vector<1x1x8xi32> %2 = vector.extract %arg2[0] : vector<8xi32> from vector<1x8xi32> %3 = vector.contract {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d1)>], iterator_types = ["parallel", "parallel", "reduction"], kind = #vector.kind<add>} %1, %arg1, %2 : vector<1x8xi32>, vector<1x8x8xi32> into vector<8xi32> %4 = vector.broadcast %3 : vector<8xi32> to vector<1x8xi32> ``` The `vector.transpose` introduced does not affect the underlying data layout (effectively a no op), but it cannot be folded automatically. This change avoids inserting transposes when only leading unit dimensions are involved. Fixes #85691
2024-03-22[mlir][vector] Add support for masks in castAwayContractionLeadingOneDim ↵Andrzej Warzyński
(#81906) Updates `castAwayContractionLeadingOneDim` to inherit from `MaskableOpRewritePattern` so that this pattern can support masking. Builds on top of #83827
2024-02-09[mlir][Vector] Fix "scalability" in CastAwayExtractStridedSliceLeadingOneDim ↵Andrzej Warzyński
(#81187) Makes sure that "scalability" flags in the `CastAwayExtractStridedSliceLeadingOneDim` pattern are correctly updated.
2024-01-20[mlir] Exclude masked ops in VectorDropLeadUnitDim (#76468)Jerry Wu
Don't insert cast ops for ops in `vector.mask` region in `VectorDropLeadUnitDim`.
2023-11-27[mlir][vector] Fix patterns for dropping leading unit dims from masks (#73525)Quinn Dawkins
Previously the pattern only worked when the permutation map was a minor identity. Infer the new mask type from the new transfer map after dropping leading unit dims.
2023-11-06[mlir][vector] Add leading unit dim folding patterns for masked transfers ↵Quinn Dawkins
(#71466) This handles `vector.transfer_read`, `vector.transfer_write`, and `vector.constant_mask`. The unit dims are only relevant for masks created by `create_mask` and `constant_mask` if the mask size for the unit dim is non-one, in which case all subsequent sizes must also be zero. From the perspective of the vector transfers, however, these unit dims can just be dropped directly.
2023-09-22[mlir][Vector] Add support for Value indices to vector.extract/insertDiego Caballero
`vector.extract/insert` ops only support constant indices. This PR is extending them so that arbitrary values can be used instead. This work is part of the RFC: https://discourse.llvm.org/t/rfc-psa-remove-vector-extractelement-and-vector-insertelement-ops-in-favor-of-vector-extract-and-vector-insert-ops Differential Revision: https://reviews.llvm.org/D155034
2023-08-22[mlir][vector] Enable CastAwayElementwiseLeadingOneDim for scalable vecAndrzej Warzynski
This patch effectively enables the CastAwayElementwiseLeadingOneDim rewrite pattern for scalable vectors. To this end, `ExtractOp::inferReturnTypes` is updated so that scalable dimensions are correctly recognised. The change to ExtractOp will likely make also other conversion patterns valid for scalable vectors, but this patch focuses on just one case. Other conversion patterns will be enabled in the forthcoming patches. Depends on D157993 Differential Revision: https://reviews.llvm.org/D158335
2023-08-22[mlir][vector] Add support for scalable vectors in `trimLeadingOneDims`Andrzej Warzynski
This patch updates one specific hook in "VectorDropLeadUnitDim.cpp" to make sure that "scalable dims" are handled correctly. While this change affects multiple patterns, I am only adding one regression tests that captures one specific case that affects me right now. I am also adding Vector dialect to the list of dependencies of `-test-vector-to-vector-lowering`. Otherwise my test case won't work as a standalone test. Differential Revision: https://reviews.llvm.org/D157993
2023-07-31[mlir][vector] Use DenseI64ArrayAttr for ExtractOp/InsertOp positionsMatthias Springer
`DenseI64ArrayAttr` provides a better API than `I64ArrayAttr`. E.g., accessors returning `ArrayRef<int64_t>` (instead of `ArrayAttr`) are generated. Differential Revision: https://reviews.llvm.org/D156684
2023-06-05[mlir][vector][NFC] Clean up headersMatthias Springer
Certain functions were declared in `VectorOps.h` instead of `VectorTransforms.h` or `VectorRewritePatterns.h`. Differential Revision: https://reviews.llvm.org/D152146
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-21[mlir][vector] NFC: Expose castAwayContractionLeadingOneDimLei Zhang
This commit exposes the transformation behind the pattern. It is useful for more targeted application on a specific op for once. Reviewed By: kuhar Differential Revision: https://reviews.llvm.org/D148758
2023-04-18[vector] When trimming leading insertion dimensions, base the final result ↵Benjamin Kramer
on the ranks This was incorrect when the number of dropped source dims was smaller than the number of dropped dst dims. We still need to insert zeros if there is anything dropped from the src. Differential Revision: https://reviews.llvm.org/D148636
2023-03-31[mlir] Fix casting of leading unit dims for vector.inserttyb0807
When dropping leading unit dims of vector.insert's operands and creating a new vector.insert, its new position rank should be computed explicitly in two steps: first based on the numbers of leading unit dims dropped from the vector.insert's destination, then based on the numbers of leading unit dims dropped from its source. Reviewed By: pifon2a Differential Revision: https://reviews.llvm.org/D147280
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-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
2022-09-18[mlir] Use empty (NFC)Kazu Hirata
2022-09-09[mlir][vector] NFC - Clean up vector patterns and propagate benefit through ↵Nicolas Vasilache
populate functions Differential Revision: https://reviews.llvm.org/D133559
2022-07-19[mlir] Flip LinAlg dialect to _BothJacques Pienaar
This one required more changes than ideal due to overlapping generated name with different return types. Changed getIndexingMaps to getIndexingMapsArray to move it out of the way/highlight that it returns (more expensively) a SmallVector and uses the prefixed name for the Attribute. Differential Revision: https://reviews.llvm.org/D129919
2022-04-14[mlir][vector] Cast away leading one dims for insert opsLei Zhang
Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D123621
2022-03-28[mlir] Flip Vector dialect accessors used to prefixed form.Jacques Pienaar
This has been on _Both for a couple of weeks. Flip usages in core with intention to flip flag to _Prefixed in follow up. Needed to add a couple of helper methods in AffineOps and Linalg to facilitate a pure flag flip in follow up as some of these classes are used in templates and so sensitive to Vector dialect changes. Differential Revision: https://reviews.llvm.org/D122151
2022-03-23[mlir] Make OpBuilder::createOperation to accept raw inputsChia-hung Duan
This provides a way to create an operation without manipulating OperationState directly. This is useful for creating unregistered ops. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D120787
2022-02-10[mlir][vector] Add pattern to drop lead unit dim for Contraction OpNirvedh
If the result operand has a unit leading dim it is removed from all operands. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D119206
2022-01-31[mlir][vector][NFC] Split into IR, Transforms and UtilsMatthias Springer
This reduces the dependencies of the MLIRVector target and makes the dialect consistent with other dialects. Differential Revision: https://reviews.llvm.org/D118533