summaryrefslogtreecommitdiff
path: root/mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp
AgeCommit message (Collapse)Author
2025-07-25[mlir][NFC] update `mlir` create APIs (34/n) (#150660)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-23[mlir][NFC] update `Conversion` create APIs (4/n) (#149879)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-04[mlir] Remove unused includes (NFC) (#147101)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-07-03[mlir][bufferization] Do not access operation after it was replaced (#146860)Matthias Springer
Accessing an erased operation will no longer work during a One-Shot Dialect Conversion.
2025-02-17[MLIR][NFC] Retire `let constructor` for passes in Conversion directory ↵lorenzo chelini
(part1) (#127403) `let constructor` is deprecated since the table gen backend emits most of the glue logic to build a pass. This PR retires the td method for most (I need another pass) passes in the Conversion directory.
2024-09-30[mlir][NFC] Minor cleanup around `ModuleOp` usage (#110498)Matthias Springer
Use `moduleOp.getBody()` instead of `moduleOp.getBodyRegion().front()`.
2024-07-15[mlir] [bufferize] fix bufferize deallocation error in nest symbol table ↵donald chen
(#98476) In nested symbols, the dealloc_helper function generated by lower deallocations pass was incorrectly positioned, causing calls fail. This patch fixes this issue.
2024-07-02mlir/LogicalResult: move into llvm (#97309)Ramkumar Ramachandra
This patch is part of a project to move the Presburger library into LLVM.
2024-06-13[mlir][bufferization] Unranked memref support for clone (#94757)ryankima
bufferization.clone does not currently support lowering to memref for unranked memrefs. This interferes with bufferizing unranked tensors at boundaries where a clone operation is needed. ``` func.func @foo(%input: memref<*xf32>, %shape: memref<?xindex>) -> memref<*xf32> { %reshape = memref.reshape %input(%shape) : (memref<*xf32>, memref<?xindex>) -> memref<*xf32> %copy = bufferization.clone %reshape : memref<*xf32> to memref<*xf32> return %copy : memref<*xf32> } ``` Patterns such as that are possibly when bufferizing functions with input and output unranked tensors. The clone operation currently fails to legalize during the bufferization-to-memref conversion with unranked memrefs. This change modifies the conversion of bufferization.clone to memref to generate the runtime calculations and allocation to allow for cloning an unranked memref.
2023-08-31[mlir][bufferization] Factor out bufferization.dealloc lowering into ↵Martin Erhart
separate pass Moves the lowering of `bufferization.dealloc` to memref into a separate pass, but still registers the pattern in the conversion pass. This is helpful when some tensor values (and thus `to_memref` or `to_tensor` operations) still remain, e.g., when the function boundaries are not converted, or when constant tensors are converted to memref.get_global at a later point. However, it is still recommended to perform all bufferization before deallocation to avoid memory leaks as all memref allocations inserted after the deallocation pass was applied, have to be handled manually. Note: The buffer deallocation pass assumes that memref values defined by `bufferization.to_memref` don't return ownership and don't have to be deallocated. `bufferization.to_tensor` operations are handled similarly to `bufferization.clone` operations with the exception that the result value is not handled because it's a tensor (not a memref). Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D159180
2023-08-28[mlir][bufferization] Enable BufferizationToMemRef to run on functionsMartin Erhart
Modify the `convert-bufferization-to-memref` pass to be applicable to `builtin.module` and `FunctionOpInterface`. In many cases the lowering using the library function is not needed because enough static information is available to simplify the dealloc operations enough to use the more light-weight lowerings. In those situations, it is better to allow the pass to run on functions for additional parallelization and for easier use with the transform dialect (e.g., when the transform ops are in the same `builtin.module` as the function to be transformed). Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D158969
2023-08-14[mlir][bufferization] Add specialized lowering for deallocs with one memref ↵Martin Erhart
but arbitrary retains It is often the case that many values in the `memrefs` operand list can be split off to speparate dealloc operations by the `--buffer-deallocation-simplification` pass, however, the retain list has to be preserved initially. Further canonicalization can often trim it down considerable, but some retains may remain. In those cases, the general lowering would be chosen, but is very inefficient. This commit adds another lowering for those cases which avoids allocation of auxillary memrefs and the helper function while still producing code that is linear in the number of operands of the dealloc operation. Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D157692
2023-08-04[mlir][bufferization] Change semantics of DeallocOp result valuesMartin Erhart
This change allows supporting operations for which we don't get precise aliasing information without the need to insert clone operations. E.g., `arith.select`. Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D156992
2023-07-19[mlir][bufferization] Add lowering of bufferization.dealloc to memref.deallocMartin Erhart
Adds a generic lowering that suppors all cases of bufferization.dealloc and one specialized, more efficient lowering for the simple case. Using a helper function with for loops in the general case enables O(|num_dealloc_memrefs|+|num_retain_memrefs|) size of the lowered code. Depends on D155467 Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D155468
2023-06-30[mlir][NFC] Clean up builder usage around constants/non-foldable opsMatthias Springer
* Use `create` instead of `createOrFold` for constant ops. Constants cannot be folded any further. * Use `create` instead of `createOrFold` for ops that do not have a folder. * Use C++ op builders that take an `int` instead of creating a `ConstantIndexOp`. * Create `tensor::DimOp` instead of `linalg::createOrFoldDimOp` when it is certain that the operand is a tensor. Differential Revision: https://reviews.llvm.org/D154196
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
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-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-07-14[mlir] (NFC) run clang-format on all filesJeff Niu
2022-06-18[mlir][bufferization] Set emitAccessorPrefix dialect flagMatthias Springer
Generate get/set accessors on all bufferization ops. Also update all internal uses. Differential Revision: https://reviews.llvm.org/D128057
2022-03-16[mlir][bufferize] Support layout maps in bufferization.clone loweringMatthias Springer
Differential Revision: https://reviews.llvm.org/D121278
2021-11-30[mlir] Decompose Bufferization Clone operation into Memref Alloc and Copy.Julian Gross
This patch introduces a new conversion to convert bufferization.clone operations into a memref.alloc and a memref.copy operation. This transformation is needed to transform all remaining clones which "survive" all previous transformations, before a given program is lowered further (to LLVM e.g.). Otherwise, these operations cannot be handled anymore and lead to compile errors. See: https://llvm.discourse.group/t/bufferization-error-related-to-memref-clone/4665 Differential Revision: https://reviews.llvm.org/D114233