summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/MemRef/Transforms/FoldMemRefAliasOps.cpp
AgeCommit message (Collapse)Author
2025-10-06[mlir] Simplify unreachable type switch cases. NFC. (#162032)Jakub Kuderski
Use `DefaultUnreachable` from https://github.com/llvm/llvm-project/pull/161970.
2025-07-24Reapply "[AMDGPU] fold `memref.subview/expand_shape/collapse_shape` into ↵Alan Li
`amdgpu.gather_to_lds`" (#150334) This is a reapply of patch #149851. The reapply also fixes a CMake/Bazel build issue, which was the reason of the revert. (Thanks @rupprecht ) Original patch (#149851) message: ----- This PR adds a new optimization pass to fold `memref.subview/expand_shape/collapse_shape` ops into consumer `amdgpu.gather_to_lds` operations. * Implements a new pass `AmdgpuFoldMemRefOpsPass` with pattern `FoldMemRefOpsIntoGatherToLDSOp` * Adds corresponding folding tests
2025-07-23Revert "[AMDGPU] fold `memref.subview/expand_shape/collapse_shape` in… ↵Alan Li
(#150256) …to `amdgpu.gather_to_lds` (#149851)" This reverts commit dbc63f1e3724b6f2348c431dc1216537d9c042e8. Having build deps issue.
2025-07-23[AMDGPU] fold `memref.subview/expand_shape/collapse_shape` into ↵Alan Li
`amdgpu.gather_to_lds` (#149851) This PR adds a new optimization pass to fold `memref.subview/expand_shape/collapse_shape` ops into consumer `amdgpu.gather_to_lds` operations. * Implements a new pass `AmdgpuFoldMemRefOpsPass` with pattern `FoldMemRefOpsIntoGatherToLDSOp` * Adds corresponding folding tests --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-07-12[llvm] Remove unused includes (NFC) (#148342)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-13[mlir] Fix a warningKazu Hirata
This patch fixes: mlir/lib/Dialect/MemRef/Transforms/FoldMemRefAliasOps.cpp:106:14: error: unused variable 'sourceType' [-Werror,-Wunused-variable]
2025-05-13[mlir][MemRef] Use specialized index ops to fold expand/collapse_shape (#138930)Krzysztof Drewniak
This PR updates the FoldMemRefAliasOps to use `affine.linearize_index` and `affine.delinearize_index` to perform the index computations needed to fold a `memref.expand_shape` or `memref.collapse_shape` into its consumers, respectively. This also loosens some limitations of the pass: 1. The existing `output_shape` argument to `memref.expand_shape` is now used, eliminating the need to re-infer this shape or call `memref.dim`. 2. Because we're using `affine.delinearize_index`, the restriction that each group in a `memref.collapse_shape` can only have one dynamic dimension is removed.
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-05-05[mlir] Remove unused local variables (NFC) (#138481)Kazu Hirata
2025-04-23[MLIR][NFC] Retire let constructor for MemRef (#134788)lorenzo chelini
let constructor is legacy (do not use in tree!) since the tableGen backend emits most of the glue logic to build a pass. Note: The following constructor has been retired: ```cpp std::unique_ptr<Pass> createExpandReallocPass(bool emitDeallocs = true); ``` To update your codebase, replace it with the new options-based API: ```cpp memref::ExpandReallocPassOptions expandAllocPassOptions{ /*emitDeallocs=*/false}; pm.addPass(memref::createExpandReallocPass(expandAllocPassOptions)); ```
2024-12-20[mlir] Enable decoupling two kinds of greedy behavior. (#104649)Jacques Pienaar
The greedy rewriter is used in many different flows and it has a lot of convenience (work list management, debugging actions, tracing, etc). But it combines two kinds of greedy behavior 1) how ops are matched, 2) folding wherever it can. These are independent forms of greedy and leads to inefficiency. E.g., cases where one need to create different phases in lowering and is required to applying patterns in specific order split across different passes. Using the driver one ends up needlessly retrying folding/having multiple rounds of folding attempts, where one final run would have sufficed. Of course folks can locally avoid this behavior by just building their own, but this is also a common requested feature that folks keep on working around locally in suboptimal ways. For downstream users, there should be no behavioral change. Updating from the deprecated should just be a find and replace (e.g., `find ./ -type f -exec sed -i 's|applyPatternsAndFoldGreedily|applyPatternsGreedily|g' {} \;` variety) as the API arguments hasn't changed between the two.
2024-06-12[mlir][memref] Add memref alias folders for expand/collapse_shape for vector ↵Kunwar Grover
load/store (#95223) This patch adds adds patterns to fold memref alias for expand_shape/collapse_shape feeding into vector.load/vector.store and vector.maskedload/vector.maskedstore
2024-05-13[NFC] Make NVGPU casing consistent (#91903)tyb0807
2024-05-08[mlir][fold-memref-alias-ops] Add support for folding memref.expand_shape ↵Prathamesh Tagore
involving dynamic dims (#89093) `fold-memref-alias-ops` bails out in presence of dynamic shapes in `memref.expand_shape` op. Handle this case.
2023-11-14[mlir] Add `vector.store/maskedstore` of `memref.subview` memref alias ↵Max191
folding (#72184) Fixes https://github.com/openxla/iree/issues/15575
2023-11-07[mlir][memref] Add memref alias folding for masked transfers (#71476)Quinn Dawkins
The contents of a mask on a masked transfer are unaffected by the particular region of memory being read/stored to, so just forward the mask in subview folding patterns.
2023-11-06[mlir][MemRef] Add subview folding pattern for vector.maskedload (#71380)tyb0807
This is required for fixing https://github.com/openxla/iree/issues/15031
2023-10-12[mlir][memref] Fix index delinearization for CollapseShapeOp folding (#68833)Felix Schneider
The `resolveSourceIndicesCollapseShape` method is used to compute indices into the source `MemRef` of a `CollapseShapeOp` from the collapsed indices. This method didn't check for dynamic sizes of the source shape which led to a crash. Fix https://github.com/llvm/llvm-project/issues/68483
2023-08-11[mlir][MemRef] Bail out for unsupported cases in FoldMemRefAliasOps passHanhan Wang
The pass uses `computeSuffixProduct` method which only allows static shapes. This revision adds an early-exit for dynamic cases to avoid crash. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D157668
2023-05-25[mlir] Enable folding memref alias for`vector.load`Guray Ozen
This work enables folding memref alias pass for`vector.load` Reviewed By: qcolombet Differential Revision: https://reviews.llvm.org/D151447
2023-05-25[mlir] Enable folding memref alias for `ldmatrix`Guray Ozen
Folding mechanism does not recognize `ldmatrix` op. This work helps pass to recognize the op and fold the memref aliases. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D151412
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-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-04-20[mlir][Memref] Fold nvgpu device cp.async on src memref to dst memrefManish Gupta
Differential Revision: https://reviews.llvm.org/D148161
2023-04-14[mlir][Tensor] Add support for insert_slice in FoldTensorSubsetOpsNicolas Vasilache
Differential Revision: https://reviews.llvm.org/D148334
2023-03-28[mlir][MemRef] Move transform related functions in Transforms.hQuentin Colombet
NFC
2023-03-23[mlir][Tensor] Add a FoldTensorSubsetOps pass and patternsNicolas Vasilache
These patterns follow FoldMemRefAliasOps which is further refactored for reuse. In the process, fix FoldMemRefAliasOps handling of strides for vector.transfer ops which was previously incorrect. These opt-in patterns generalize the existing canonicalizations on vector.transfer ops. In the future the blanket canonicalizations will be retired. They are kept for now to minimize porting disruptions. Differential Revision: https://reviews.llvm.org/D146624
2023-03-21[mlir][memref] Use folded composed affine apply ops in FoldMemRefAliasOpsNicolas Vasilache
Creating maximally folded and composd affine.apply operation during FoldMemRefAliasOps composes better with other transformations without having to interleave canonicalization passes. Differential Revision: https://reviews.llvm.org/D146515
2023-03-15[mlir][memref] Fold subview into GPU subgroup MMA load/store opsLei Zhang
This commits adds support for folding subview into GPU subgroup MMA load/store ops. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D146150
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-03[mlir] Add nontemporal field to memref.load/store and convey to llvm.load/storeGuray Ozen
`llvm.load` op has nonTemporal field which is missing for `memref.load` and `memref.store`. This revision first adds nonTemporal field to memref's load/store op, then it lowers the field to llvm.load/store ops. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D142616
2023-01-27[mlir] GreedyPatternRewriteDriver: Entry point takes single regionMatthias Springer
The rewrite driver is typically applied to a single region or all regions of the same op. There is no longer an overload to apply the rewrite driver to a list of regions. This simplifies the rewrite driver implementation because the scope is now a single region as opposed to a list of regions. Note: This change is not NFC because `config.maxIterations` and `config.maxNumRewrites` is now counted for each region separately. Furthermore, worklist filtering (`scope`) is now applied to each region separately. Differential Revision: https://reviews.llvm.org/D142611
2022-12-15[mlir][memref] Fold subview(subview(x))Matthias Springer
Folding of rank-reduced subviews is also supported. Differential Revision: https://reviews.llvm.org/D140110
2022-09-30[mlir] Flip Async/GPU/MemRef/OpenACC/OpenMP/PDL dialects to prefixedRiver Riddle
This flips all of the remaining dialects to prefixed except for linalg, which will be done in a followup. Differential Revision: https://reviews.llvm.org/D134995
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-08[mlir][memref] Add support for 0-D transfer / subview fold.Nicolas Vasilache
The 0-d case simply forwards the indexing from the source memref and works out of the box. Differential Revision: https://reviews.llvm.org/D133536
2022-09-05Apply clang-tidy fixes for performance-unnecessary-value-param in ↵Mehdi Amini
FoldMemRefAliasOps.cpp (NFC)
2022-08-31[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
2022-08-30Revert "[MLIR] Update pass declarations to new autogenerated files"Michele Scuttari
This reverts commit 2be8af8f0e0780901213b6fd3013a5268ddc3359.
2022-08-30[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
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