summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Utils/StaticValueUtils.cpp
AgeCommit message (Collapse)Author
2025-09-17[MLIR] Cleanup `constantTripCount()` (NFC) (#159307)Mehdi Amini
Add post-merge review comments on #158679
2025-09-17[MLIR] Add a getStaticTripCount method to LoopLikeOpInterface (#158679)Mehdi Amini
This patch adds a `getStaticTripCount` to the LoopLikeOpInterface, allowing loops to optionally return a static trip count when possible. This is implemented on SCF ForOp, revamping the implementation of `constantTripCount`, removing redundant duplicate implementations from SCF.cpp.
2025-08-13[mlir][DialectUtils] Fix div by zero crash (#153380)Matthias Springer
2025-07-20[mlir] ViewLikeInterface - verify ranks in verifyOffsetSizeAndStrideOp (#147926)Maya Amrami
getMixedOffsets() calls getMixedValues() with `static_offsets` and `offsets`. It is assumed that the number of dynamic offsets in `static_offsets` equals the rank of `offsets`. Otherwise, we fail on assert when trying to access an array out of its bounds. The same applies to getMixedStrides() and getMixedOffsets(). A verification of this assumption is added to verifyOffsetSizeAndStrideOp() and a clear assert is added in getMixedValues().
2025-07-07[mlir] Add `isStatic`* size check for `ShapedType`s. NFCI. (#147085)Jakub Kuderski
The motivation is to avoid having to negate `isDynamic*` checks, avoid double negations, and allow for `ShapedType::isStaticDim` to be used in ADT functions without having to wrap it in a lambda performing the negation. Also add the new functions to C and Python bindings.
2025-06-23[mlir][PartialReductionTilingInterface] Add support for ↵MaheshRavishankar
`ReductionTilingStrategy::PartialReductionOuterParallel` in `tileUsingSCF`. (#143988) Following up from https://github.com/llvm/llvm-project/pull/143467, this PR adds support for `ReductionTilingStrategy::PartialReductionOuterParallel` to `tileUsingSCF`. The implementation of `PartialReductionTilingInterface` for `Linalg` ops has been updated to support this strategy as well. This makes the `tileUsingSCF` come on par with `linalg::tileReductionUsingForall` which will be deprecated subsequently. Changes summary - `PartialReductionTilingInterface` changes : - `tileToPartialReduction` method needed to get the induction variables of the generated tile loops. This was needed to keep the generated code similar to `linalg::tileReductionUsingForall`, specifically to create a simplified access for slicing the intermediate partial results tensor when tiled in `num_threads` mode. - `getPartialResultTilePosition` methods needs the induction varialbes for the generated tile loops for the same reason above, and also needs the `tilingStrategy` to be passed in to generate correct code. The tests in `transform-tile-reduction.mlir` testing the `linalg::tileReductionUsingForall` have been moved over to test `scf::tileUsingSCF` with `ReductionTilingStrategy::PartialReductionOuterParallel` strategy. Some of the test that were doing further cyclic distribution of the transformed code from tiling are removed. Those seem like two separate transformation that were merged into one. Ideally that would need to happen when resolving the `scf.forall` rather than during tiling. Please review only the top commit. Depends on https://github.com/llvm/llvm-project/pull/143467 Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
2025-06-14[mlir] Compare std::optional<T> to values directly (NFC) (#144241)Kazu Hirata
This patch transforms: X && *X == Y to: X == Y where X is of std::optional<T>, and Y is of T or similar.
2025-05-20[mlir][NFC] Simplify constant checks with isOneInteger and renamed ↵Han-Chung Wang
isZeroInteger. (#139340) The revision adds isOneInteger helper, and simplifies the existing code with the two methods. It removes some lambda, which makes code cleaner. For downstream users, you can update the code with the below script. ```bash sed -i "s/isZeroIndex/isZeroInteger/g" **/*.h sed -i "s/isZeroIndex/isZeroInteger/g" **/*.cpp ``` --------- Signed-off-by: hanhanW <hanhan0912@gmail.com>
2025-05-16[mlir][NFC] Use `llvm::sort` (#140261)Iris Shi
2025-01-27[mlir][Tensor] Rework `ReifyRankedShapedTypeInterface` implementation for ↵MaheshRavishankar
`tensor.expand_shape` op. (#113501) The op carries the output-shape directly. This can be used directly. Also adds a method to get the shape as a `SmallVector<OpFoldResult>`. Signed-off-by: MaheshRavishankar <mahesh.ravishankar@gmail.com>
2024-12-21[Dialect] Migrate away from PointerUnion::{is,get} (NFC) (#120818)Kazu Hirata
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
2024-11-06[mlir][tensor] Generalize/restrict `GeneralizeOuterUnitDimsPackOpPattern` ↵Andrzej Warzyński
(#114315) This PR *restricts* `GeneralizeOuterUnitDimsPackOpPattern` to follow its intended purpose (as per the documentation), which is to: > require all outer dimensions of tensor.pack to be 1. There was one in-tree test that violated this assumption (and happened to work) – see `@simple_KCRS_to_KRSCsr` in "generalize-tensor-pack.mlir". That test has been updated to satisfy the new requirements of the pattern. By enforcing the pattern to follow its intended design (i.e., making it stricter), the calculation of shapes and sizes for various Ops that the pattern generates (PadOp, ExtractSliceOp, EmptyOp, TensorOp, and InsertSliceOp) becomes much simpler and easier to document. This also helped *generalize* the pattern to support cases like the one below: ```mlir func.func @simple_pad_and_pack_dynamic_tile_cst( %src: tensor<5x1xf32>, %dest: tensor<1x1x?x2xf32>, %pad: f32) -> tensor<1x1x?x2xf32> { %tile_dim_0 = arith.constant 8 : index %0 = tensor.pack %src padding_value(%pad : f32) inner_dims_pos = [0, 1] inner_tiles = [%tile_dim_0, 2] into %dest : tensor<5x1xf32> -> tensor<1x1x?x2xf32> return %0 : tensor<1x1x?x2xf32> } ``` Note that the inner tile slice is dynamic but compile-time constant. `getPackOpSourceOrPaddedSource`, which is used to generate PadOp, detects this and generates a PadOp with static shapes. This is a good optimization, but it means that all shapes/sizes for Ops generated by `GeneralizeOuterUnitDimsPackOpPattern` also need to be updated to be constant/static. By restricting the pattern and simplifying the size/shape calculation, supporting the case above becomes much easier. Notable implementation changes: * PadOp processes the original source (no change in dimensions/rank). ExtractSliceOp extracts the tile to pack and may reduce the rank. All following ops work on the tile extracted by ExtractSliceOp (possibly rank-reduced). * All shape/size calculations assume that trailing dimensions match inner_tiles from tensor.pack. All leading dimensions (i.e., outer dimensions) are assumed to be 1. * Dynamic sizes for ops like ExtractSliceOp are taken from inner_tiles rather than computed as, for example, tensor.dim %dest, 2. It’s the responsibility of the "producers" of tensor.pack to ensure that dimensions in %dest match the specified tile sizes.
2024-10-18[mlir] Do not bufferize parallel_insert_slice dest to read for full slices ↵Max191
(#112761) In the insert_slice bufferization interface implementation, the destination tensor is not considered read if the full tensor is overwritten by the slice. This PR adds the same check for tensor.parallel_insert_slice. Adds two new StaticValueUtils: - `isAllConstantIntValue` checks if an array of `OpFoldResult` are all equal to a passed `int64_t` value. - `areConstantIntValues` checks if an array of `OpFoldResult` are all equal to a passed array of `int64_t` values. fixes https://github.com/llvm/llvm-project/issues/112435 --------- Signed-off-by: Max Dawkins <max.dawkins@gmail.com>
2024-09-26[mlir] Use std::optional::value_or (NFC) (#109893)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-04-30[MLIR] Generalize expand_shape to take shape as explicit input (#90040)Gaurav Shukla
This patch generalizes tensor.expand_shape and memref.expand_shape to consume the output shape as a list of SSA values. This enables us to implement generic reshape operations with dynamic shapes using collapse_shape/expand_shape pairs. The output_shape input to expand_shape follows the static/dynamic representation that's also used in `tensor.extract_slice`. Differential Revision: https://reviews.llvm.org/D140821 --------- Signed-off-by: Gaurav Shukla<gaurav.shukla@amd.com> Signed-off-by: Gaurav Shukla <gaurav.shukla@amd.com> Co-authored-by: Ramiro Leal-Cavazos <ramiroleal050@gmail.com>
2024-04-21Revert "[MLIR] Generalize expand_shape to take shape as explicit input" (#89540)Mehdi Amini
Reverts llvm/llvm-project#69267 this broke some bots.
2024-04-21[MLIR] Generalize expand_shape to take shape as explicit input (#69267)Gaurav Shukla
This patch generalizes tensor.expand_shape and memref.expand_shape to consume the output shape as a list of SSA values. This enables us to implement generic reshape operations with dynamic shapes using collapse_shape/expand_shape pairs. The output_shape input to expand_shape follows the static/dynamic representation that's also used in `tensor.extract_slice`. Differential Revision: https://reviews.llvm.org/D140821 Co-authored-by: Ramiro Leal-Cavazos <ramiroleal050@gmail.com>
2024-03-20[MLIR] Remove UtilsDialect dep on ArithUtils (#85919)Thomas Preud'homme
This will reduce the amount of libraries pulled through the de facto dependency of TilingInterface on UtilsDialect for its IteratorType.
2023-12-06[mlir] Fix a zero stride canonicalizer crash (#74200)Rik Huijzer
This PR fixes https://github.com/llvm/llvm-project/issues/73383 and is another shot at the refactoring proposed in https://github.com/llvm/llvm-project/pull/72885. --------- Co-authored-by: Kai Sasaki <lewuathe@gmail.com>
2023-11-21[mlir][tensor] Fix crash when canonicalizing invalid IR (#72888)Matthias Springer
This commit fixes a crash of the canonicalizer when there are slice ops with offset/size SSA values that have a negative constant value. Such ops are invalid if they are reachable and their offsets/sizes should not be folded to static integer values. (But such ops may appear in non-reachable block.) This commit fixes #71150.
2023-07-31[mlir][NFC] Move offsets/sizes/strides helper to dialect utils and interface ↵Matthias Springer
header * Move `foldDynamicIndexList` to `DialectUtils` and simplify function. * Move `OpWithOffsetSizesAndStridesConstantArgumentFolder` to `ViewLikeInterface` and add documentation. Differential Revision: https://reviews.llvm.org/D156581
2023-07-25[mlir][linalg] NFC - Move some utils in preparation for revamping mapping of ↵Nicolas Vasilache
scf.forall
2023-07-12[mlir][DialectUtils] Generalize `extractFromI64ArrayAttr` helperMatthias Springer
Generalize `extractFromI64ArrayAttr` to `extractFromIntegerArrayAttr`, so that arbitrary integer/bool types can be extracted. Differential Revision: https://reviews.llvm.org/D154974
2023-05-26[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. 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 patch updates all remaining uses of the deprecated functionality in mlir/. This was done with clang-tidy as described below and further modifications to GPUBase.td and OpenMPOpsInterfaces.td. 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: 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. ``` 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 ``` Differential Revision: https://reviews.llvm.org/D151542
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-03-21[mlir] Add a pattern to fold single- and zero-iteration scf.forall ops.Alexander Belyaev
Differential Revision: https://reviews.llvm.org/D145368
2023-03-15[mlir][Transform] NFC - Refactor forall mapping to threads and blocks into ↵Nicolas Vasilache
one thing Differential Revision: https://reviews.llvm.org/D146095
2023-03-14[mlir][GPUTransforms] NFC - Refactor GPUTransforms.cpp in preparation for ↵Nicolas Vasilache
improvements. Depends on: D145977 Differential Revision: https://reviews.llvm.org/D145980
2023-03-12[mlir] NFC - Add some more static value utilsNicolas Vasilache
Differential Revision: https://reviews.llvm.org/D145875
2023-03-01[mlir][MemRef] Rewrite multi-buffering with proper composable abstractionsNicolas Vasilache
Rewrite and document multi-buffering properly: 1. Use IndexingUtils / StaticValueUtils instead of duplicating functionality 2. Properly plumb RewriterBase through. 3. Add support 4. Better debug messages. This revision is otherwise almost NFC, if it weren't for the extra DeallocOp support that would previoulsy make multi-buffering fail. Depends on: D145036 Differential Revision: https://reviews.llvm.org/D145055
2023-02-27[mlir][Linalg] Reimplement hoisting on tensors as a subset-based transformationNicolas Vasilache
This revision significantly rewrites hoisting on tensors. Previously, `vector.transfer_read/write` and `tensor.extract/insert_slice` would be clumped together when looking for candidate pairs. This would significantly increase the complexity of the logic and would not apply independently to `tensor.extract/insert_slice`. The new implementation decouples the cases and starts to cast the problem as a generic matching subset extract/insert, which will be future proof when other such operation pairs are introduced. Lastly, the implementation makes the distinction clear between `vector.transfer_read/write` for which we allow bypasses of the disjoint subsets from `tensor.extract/insert_slice` for which we do not yet allow it. This can be extended in the future and unified once we have subset disjunction implemented more generally. The algorithm can be rewritten to be less of a fixed point with interspersed canonicalizations. As a consequence, the test explicitly adds a canonicalization to clean up the IR and verify we end up in the same state. That extra canonicalization exhibited that one of the uses in one of the tests was dead, so we fix the appropriate test. Differential Revision: https://reviews.llvm.org/D144656
2023-02-16[mlir][Linalg] Add a transform dialect op to rewrite ops to destination ↵Nicolas Vasilache
passing style. A new transform dialect op is introduced to perform the rewrite. The test pass option is now obsolete and is removed in favor of the transform. In the process I realized the tensor.pad nofold attribute was not taken into account and added support to emit a bufferization.alloc_tensor + linalg.copy. Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D143943
2022-12-17mlir/tblgen: use std::optional in generationRamkumar Ramachandra
This is part of an effort to migrate from llvm::Optional to std::optional. This patch changes the way mlir-tblgen generates .inc files, and modifies tests and documentation appropriately. It is a "no compromises" patch, and doesn't leave the user with an unpleasant mix of llvm::Optional and std::optional. A non-trivial change has been made to ControlFlowInterfaces to split one constructor into two, relating to a build failure on Windows. See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Signed-off-by: Ramkumar Ramachandra <r@artagnon.com> Differential Revision: https://reviews.llvm.org/D138934
2022-12-13Remove sentinel argument from dispatchIndexOpFoldResults.Aliia Khasanova
Post clean-up after merger of kDynamicSize and kDynamicStrideOrOffset. Differential Revision: https://reviews.llvm.org/D139929
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-25[MLIR] Adopt `DenseI64ArrayAttr` in tensor, memref and linalg transformLorenzo Chelini
This commit is a first step toward removing inconsistencies between dynamic and static attributes (i64 v. index) by dropping `I64ArrayAttr` and using `DenseI64ArrayAttr` in Tensor, Memref and Linalg Transform ops. In Linalg Transform ops only `TileToScfForOp` and `TileOp` have been updated. See related discussion: https://discourse.llvm.org/t/rfc-inconsistency-between-dynamic-and-static-attributes-i64-v-index/66612/1 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D138567
2022-09-29[mlir][arith] Change dialect name from Arithmetic to ArithJakub Kuderski
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22. Tested with: `ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples` and `bazel build --config=generic_clang @llvm-project//mlir:all`. Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini Differential Revision: https://reviews.llvm.org/D134762
2022-09-27[MLIR] Expose `getAsValues` in `StaticValueUtils.h` (NFC) [reland]Lorenzo Chelini
The utility function should live in `StaticValueUtils.h` as it provides a convenient way to convert a vector of OpFoldResults into a vector of Values. Reviewed By: nicolasvasilache, cota Differential Revision: https://reviews.llvm.org/D134451
2022-09-26Revert "[MLIR] Expose `getAsValues` in `StaticValueUtils.h` (NFC)"Lorenzo Chelini
It introduces a circular build dependence: DialectUtils <- ArithmeticUtils <- ArithDialect <- DialectUtils This reverts commit 27224fe7272a791bcc9f28c997ce322f7d3856cd.
2022-09-26[MLIR] Expose `getAsValues` in `StaticValueUtils.h` (NFC)Lorenzo Chelini
The utility function should live in `StaticValueUtils.h` as it provides a convenient way to convert a vector of OpFoldResults into a vector of Values. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D134451
2022-09-26Revert "[MLIR] Expose `getAsValues` in `StaticValueUtils.h` (NFC)"Lorenzo Chelini
This reverts commit 730ae80d3e1c47f93f725acb2d37f06fcba06953. It fails with a linking errors: `undefined reference to `mlir::getValueOrCreateConstantIndexOp` in `libMLIRDialectUtils`.
2022-09-26[MLIR] Expose `getAsValues` in `StaticValueUtils.h` (NFC)Lorenzo Chelini
The utility function should live in `StaticValueUtils.h` as it provides a convenient way to convert a vector of OpFoldResults into a vector of Values. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D134451
2022-09-08[mlir][Tensor] Add rewrites to extract slices through `tensor.collape_shape`Christopher Bate
This change adds a set of utilities to replace the result of a `tensor.collapse_shape -> tensor.extract_slice` chain with the equivalent result formed by aggregating slices of the `tensor.collapse_shape` source. In general, it is not possible to commute `extract_slice` and `collapse_shape` if linearized dimensions are sliced. The i-th dimension of the `tensor.collapse_shape` result is a "linearized sliced dimension" if: 1) Reassociation indices of tensor.collapse_shape in the i'th position is greater than size 1 (multiple dimensions of the input are collapsed) 2) The i-th dimension is sliced by `tensor.extract_slice`. We can work around this by stitching together the result of `tensor.extract_slice` by iterating over any linearized sliced dimensions. This is equivalent to "tiling" the linearized-and-sliced dimensions of the `tensor.collapse_shape` operation in order to manifest the result tile (the result of the `tensor.extract_slice`). The user of the utilities must provide the mechanism to create the tiling (e.g. a loop). In the tests, it is demonstrated how to apply the utilities using either `scf.for` or `scf.foreach_thread`. The below example illustrates the pattern using `scf.for`: ``` %0 = linalg.generic ... -> tensor<3x7x11x10xf32> %1 = tensor.collapse_shape %0 [[0, 1, 2], [3]] : ... to tensor<341x10xf32> %2 = tensor.extract_slice %1 [13, 0] [10, 10] [2, 1] : .... tensor<10x10xf32> ``` We can construct %2 by generating the following IR: ``` %dest = linalg.init_tensor() : tensor<10x10xf32> %2 = scf.for %iv = %c0 to %c10 step %c1 iter_args(%arg0) -> tensor<10x10xf32> { // Step 1: Map this output idx (%iv) to a multi-index for the input (%3): %linear_index = affine.apply affine_map<(d0)[]->(d0*2 + 11)>(%iv) %3:3 = arith.delinearize_index %iv into (3, 7, 11) // Step 2: Extract the slice from the input %4 = tensor.extract_slice %0 [%3#0, %3#1, %3#2, 0] [1, 1, 1, 10] [1, 1, 1, 1] : tensor<3x7x11x10xf32> to tensor<1x1x1x10xf32> %5 = tensor.collapse_shape %4 [[0, 1, 2], [3]] : tensor<1x1x1x10xf32> into tensor<1x10xf32> // Step 3: Insert the slice into the destination %6 = tensor.insert_slice %5 into %arg0 [%iv, 0] [1, 10] [1, 1] : tensor<1x10xf32> into tensor<10x10xf32> scf.yield %6 : tensor<10x10xf32> } ``` The pattern was discussed in the RFC here: https://discourse.llvm.org/t/rfc-tensor-extracting-slices-from-tensor-collapse-shape/64034 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D129699
2022-07-31Revert "[mlir] Reuse the code between `getMixed*s()` funcs in ↵Alexander Belyaev
ViewLikeInterface.cpp." This reverts commit e8c2877565149587fd66fbee591b7d44eecd667d.
2022-07-31[mlir] Reuse the code between `getMixed*s()` funcs in ViewLikeInterface.cpp.Alexander Belyaev
Differential Revision: https://reviews.llvm.org/D130706
2022-07-28[mlir][TilingInterface] Add a method to generate scalar implementation of ↵Mahesh Ravishankar
the op. While The tiling interface provides a mechanism for operations to be tiled into tiled version of the op (or another op at the same level of abstraction), the `generateScalarImplementation` method added here is the "exit point" after all transformations have been done. Ops that implement this method are expected to generate IR that are directly lowerable to backend dialects like LLVM or SPIR-V dialects. Differential Revision: https://reviews.llvm.org/D130612
2022-07-27[mlir] more aggressive folding in tiling/fusion transformationsAlex Zinenko
Combine the recently added utilities for folded-by-construction affine operations with the attribute-based Range to enable more folding. This decreases the amount of emitted code but has little effect on test precisely because the tests are not checking for the spurious constants. The difference in the shape of affine maps comes from the internals of affine folding. Depends on D129633 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D130167
2022-07-19[mlir][Linalg] Add a TileToForeachThread transform.Nicolas Vasilache
This revision adds a new transformation to tile a TilingInterface `op` to a tiled `scf.foreach_thread`, applying tiling by `num_threads`. If non-empty, the `threadDimMapping` is added as an attribute to the resulting `scf.foreach_thread`. 0-tile sizes (i.e. tile by the full size of the data) are used to encode that a dimension is not tiled. Differential Revision: https://reviews.llvm.org/D129577
2022-03-11[mlir][memref] memref.reinterpret_cast foldingIvan Butygin
* reinterpret_cast(reinterpret_cast(x)) -> reinterpret_cast(x) * reinterpret_cast(cast(x)) -> reinterpret_cast(x) * reinterpret_cast(subview(x)) -> reinterpret_cast(x) if subview offsets are 0 Differential Revision: https://reviews.llvm.org/D120242