summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Utils/IndexingUtils.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-06-23[MLIR] Determine contiguousness of memrefs with dynamic dimensions (#142421)Momchil Velikov
This patch enhances `MemRefType::areTrailingDimsContiguous` to also handle memrefs with dynamic dimensions. The implementation itself is based on a new member function `MemRefType::getMaxCollapsableTrailingDims` that return the maximum number of trailing dimensions that can be collapsed - trivially all dimensions for memrefs with identity layout, or by examining the memref strides stopping at discontiguous or statically unknown strides.
2025-05-19[MLIR][Utils] Fix the overflow issue in computeSuffixProductImpl for 32-bit ↵Chao Chen
system. (#140567) In `int64_t r = strides.size() - 2`, it may cause overflow on 32-bit system when strides.size() is 1, because `strides.size()` is defined as `unsigned int`
2025-03-18[mlir] Fix crash when verifying linalg.transpose (#131733)Ian Wood
Adds checks in `isPermutationVector` for indices that are outside of the bounds and removes the assert. Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
2024-07-23[mlir] [linalg] Add pattern to swap transpose with broadcast (#97063)donald chen
Add a pattern that implement: transpose(broadcast(input)) -> broadcast(transpose(input))
2024-06-06[mlir][tensor] Implement constant folder for tensor.pad (#92691)Spenser Bauman
Extend the folding ability of the RewriteAsConstant patterns to include tensor.pad operations on constants. The new pattern with constant fold tensor.pad operations which operate on tensor constants and have statically resolvable padding sizes/values. %init = arith.constant dense<[[6, 7], [8, 9]]> : tensor<2x2xi32> %pad_value = arith.constant 0 : i32 %0 = tensor.pad %init low[1, 1] high[1, 1] { ^bb0(%arg1: index, %arg2: index): tensor.yield %pad_value : i32 } : tensor<2x2xi32> to tensor<4x4xi32> becomes %cst = arith.constant dense<[[0, 0, 0, 0], [0, 6, 7, 0], [0, 8, 9, 0], [0, 0, 0, 0]]> : tensor<4x4xi32> Co-authored-by: Spenser Bauman <sabauma@fastmail>
2024-02-22[mlir][Vector] Fix bug in vector xfer op flattening transformation (#81964)Diego Caballero
It looks like the affine map generated to compute the indices of the collapsed dimensions used the wrong dim size. For indices `[idx0][idx1]` we computed the collapsed index as `idx0*size0 + idx1` instead of `idx0*size1 + idx1`. This led to correctness issues in convolution tests when enabling this transformation internally.
2024-02-14Apply clang-tidy fixes for llvm-else-after-return in IndexingUtils.cpp (NFC)Mehdi Amini
2024-01-10[mlir][tensor] Enhance pack/unpack simplification for identity ↵Han-Chung Wang
outer_dims_perm cases. (#77409) They can be simplified to reshape ops if outer_dims_perm is an identity permutation. The revision adds a `isIdentityPermutation` method to IndexingUtils.
2023-12-08[mlir][memref] extract_strided_metadata for zero-sized memref (#74835)Guray Ozen
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-08-10[mlir][gpu] Add DecomposeMemrefsPassIvan Butygin
Some GPU backends (SPIR-V) lower memrefs to bare pointers, so for dynamically sized/strided memrefs it will fail. This pass extracts sizes and strides via `memref.extract_strrided_metadata` outside `gpu.launch` body and do index/offset calculation explicitly and then reconstructs memrefs via `memref.reinterpret_cast`. `memref.reinterpret_cast` then lowered via https://reviews.llvm.org/D155011 Differential Revision: https://reviews.llvm.org/D155247
2023-08-10Revert "[mlir][gpu] Add DecomposeMemrefsPass"Ivan Butygin
Broke some bots This reverts commit 2b5b2bfef102b1021d91f2b9485e2443bdea9df5.
2023-08-10[mlir][gpu] Add DecomposeMemrefsPassIvan Butygin
Some GPU backends (SPIR-V) lower memrefs to bare pointers, so for dynamically sized/strided memrefs it will fail. This pass extracts sizes and strides via `memref.extract_strrided_metadata` outside `gpu.launch` body and do index/offset calculation explicitly and then reconstructs memrefs via `memref.reinterpret_cast`. `memref.reinterpret_cast` then lowered via https://reviews.llvm.org/D155011 Differential Revision: https://reviews.llvm.org/D155247
2023-08-08[mlir][nvgpu] Add a nvgpu.rewrite_copy_as_tma transform operation.Nicolas Vasilache
This revision adds support for direct lowering of a linalg.copy on buffers between global and shared memory to a tma async load + synchronization operations. This uses the recently introduced Hopper NVVM and NVGPU abstraction to connect things end to end. Differential Revision: https://reviews.llvm.org/D157087
2023-07-14[mlir] NFC - Basic improvements to IndexingUtils (product and sum)Nicolas Vasilache
2023-04-13[mlir][TransformDialect] Simplify the lowering of pack/unpack when these are ↵Quentin Colombet
just pad/unpad This patch recognizes when tensor.pack/unpack operations are simple tensor.pad/unpad (a.k.a. tensor.extract_slice) and lowers them in a simpler sequence of instruction. For pack, instead of doing: ``` pad expand_shape transpose ``` we do ``` pad insert_slice ``` For unpack, instead of doing: ``` transpose collapse_shape extract_slice ``` we do ``` extract_slice ``` Note: returning nullptr for the transform dialect is fine. The related handles are just ignored by the following transformation. Differential Revision: https://reviews.llvm.org/D148159
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-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-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-12-02[mlir] Factor more common utils to IndexingUtilsHanhan Wang
Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D139159
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-08-28Fold memref.expand_shape and memref.collapse_shape opsArnab Dutta
Fold memref.expand_shape and memref.collapse_shape ops into their memref/affine load/store ops. Reviewed By: bondhugula, nicolasvasilache Differential Revision: https://reviews.llvm.org/D128986
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