summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Shape/Transforms/BufferizableOpInterfaceImpl.cpp
AgeCommit message (Collapse)Author
2025-07-24[mlir][NFC] update `mlir/Dialect` create APIs (20/n) (#149927)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-24[mlir][NFC] Use `hasOneBlock` instead of `llvm::hasSingleElement(region)` ↵Longsheng Mou
(#149809)
2025-07-14[mlir] Remove unused includes (NFC) (#148769)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-06-18[mlir][bufferization] Support custom types (1/N) (#142986)Andrei Golubev
Following the addition of TensorLike and BufferLike type interfaces (see 00eaff3e9c897c263a879416d0f151d7ca7eeaff), introduce minimal changes required to bufferize a custom tensor operation into a custom buffer operation. To achieve this, new interface methods are added to TensorLike type interface that abstract away the differences between existing (tensor -> memref) and custom conversions. The scope of the changes is intentionally limited (for example, BufferizableOpInterface is untouched) in order to first understand the basics and reach consensus design-wise. --- Notable changes: * mlir::bufferization::getBufferType() returns BufferLikeType (instead of BaseMemRefType) * ToTensorOp / ToBufferOp operate on TensorLikeType / BufferLikeType. Operation argument "memref" renamed to "buffer" * ToTensorOp's tensor type inferring builder is dropped (users now need to provide the tensor type explicitly)
2025-05-28[MLIR] Add bufferization state to `getBufferType` and `resolveConflicts` ↵Michele Scuttari
interface methods (#141466) The PR continues the work started in #141019 by adding the `BufferizationState` class also to the `getBufferType` and `resolveConflicts` interface methods, together with the additional support functions that are used throughout the bufferization infrastructure.
2025-05-23[MLIR] Add bufferization state class to OneShotBufferization pass (#141019)Michele Scuttari
Follow-up on #138143, which was reverted due to a missing update a method signature (more specifically, the bufferization interface for `tensor::ConcatOp`) that was not catched before merging. The old PR description is reported in the next lines. This PR is a follow-up on https://github.com/llvm/llvm-project/pull/138125, and adds a bufferization state class providing information about the IR. The information currently consists of a cached list of symbol tables, which aims to solve the quadratic scaling of the bufferization task with respect to the number of symbols. The PR breaks API compatibility: the bufferize method of the BufferizableOpInterface has been enriched with a reference to a BufferizationState object. The bufferization state must be kept in a valid state by the interface implementations. For example, if an operation with the Symbol trait is inserted or replaced, its parent SymbolTable must be updated accordingly (see, for example, the bufferization of arith::ConstantOp, where the symbol table of the module gets the new global symbol inserted). Similarly, the invalidation of a symbol table must be performed if an operation with the SymbolTable trait is removed (this can be performed using the invalidateSymbolTable method, introduced in https://github.com/llvm/llvm-project/pull/138014).
2025-05-22Revert "[MLIR] Add bufferization state class to OneShotBufferization pass" ↵Michele Scuttari
(#141012) Reverts llvm/llvm-project#138143 The PR for the BufferizationState is temporarily reverted due to API incompatibilities that have been initially missed during the update and were not catched by PR checks.
2025-05-22[MLIR] Add bufferization state class to OneShotBufferization pass (#138143)Michele Scuttari
This PR is a follow-up on #138125, and adds a bufferization state class providing information about the IR. The information currently consists of a cached list of symbol tables, which aims to solve the quadratic scaling of the bufferization task with respect to the number of symbols. The PR breaks API compatibility: the `bufferize` method of the `BufferizableOpInterface` has been enriched with a reference to a `BufferizationState` object. The bufferization state must be kept in a valid state by the interface implementations. For example, if an operation with the `Symbol` trait is inserted or replaced, its parent `SymbolTable` must be updated accordingly (see, for example, the bufferization of `arith::ConstantOp`, where the symbol table of the module gets the new global symbol inserted). Similarly, the invalidation of a symbol table must be performed if an operation with the `SymbolTable` trait is removed (this can be performed using the `invalidateSymbolTable` method, introduced in #138014).
2025-03-17[mlir] Use `getSingleElement`/`hasSingleElement` in various places (#131460)Matthias Springer
This is a code cleanup. Update a few places in MLIR that should use `hasSingleElement`/`getSingleElement`. Note: `hasSingleElement` is faster than `.getSize() == 1` when it is used with linked lists etc. Depends on #131508.
2023-08-15[mlir][bufferization] Generalize getAliasingOpResults to getAliasingValuesMatthias Springer
This revision is needed to support bufferization of `cf.br`/`cf.cond_br`. It will also be useful for better analysis of loop ops. This revision generalizes `getAliasingOpResults` to `getAliasingValues`. An OpOperand can now not only alias with OpResults but also with BlockArguments. In the case of `cf.br` (will be added in a later revision): a `cf.br` operand will alias with the corresponding argument of the destination block. If an op does not implement the `BufferizableOpInterface`, the analysis in conservative. It previously assumed that an OpOperand may alias with each OpResult. It now assumes that an OpOperand may alias with each OpResult and each BlockArgument of the entry block. Differential Revision: https://reviews.llvm.org/D157957
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-02-09[mlir][bufferization] Improve aliasing OpOperand/OpResult propertyMatthias Springer
`getAliasingOpOperands`/`getAliasingOpResults` now encodes OpOperand/OpResult, buffer relation and a degree of certainty. E.g.: ``` // aliasingOpOperands(%r) = {(%t, EQUIV, DEFINITE)} // aliasingOpResults(%t) = {(%r, EQUIV, DEFINITE)} %r = tensor.insert %f into %t[%idx] : tensor<?xf32> // aliasingOpOperands(%r) = {(%t0, EQUIV, MAYBE), (%t1, EQUIV, MAYBE)} // aliasingOpResults(%t0) = {(%r, EQUIV, MAYBE)} // aliasingOpResults(%t1) = {(%r, EQUIV, MAYBE)} %r = arith.select %c, %t0, %t1 : tensor<?xf32> ``` `BufferizableOpInterface::bufferRelation` is removed, as it is now part of `getAliasingOpOperands`/`getAliasingOpResults`. This change allows for better analysis, in particular wrt. equivalence. This allows additional optimizations and better error checking (which is sometimes overly conservative). Examples: * EmptyTensorElimination can eliminate `tensor.empty` inside `scf.if` blocks. This requires a modeling of equivalence: It is not a per-OpResult property anymore. Instead, it can be specified for each OpOperand and OpResult. This is important because `tensor.empty` may be eliminated only if all values on the SSA use-def chain to the final consumer (`tensor.insert_slice`) are equivalent. * The detection of "returning allocs from a block" can be improved. (Addresses a TODO in `assertNoAllocsReturned`.) This allows us to bufferize IR such as "yielding a `tensor.extract_slice` result from an `scf.if` branch", which currently fails to bufferize because the alloc detection is too conservative. * Better bufferization of loops. Aliases of the iter_arg can be yielded (even if they are not equivalent) without having to realloc and copy the entire buffer on each iteration. The above-mentioned examples are not yet implemented with this change. This change just improves the BufferizableOpInterface, its implementations and related helper functions, so that better aliasing information is available for each op. Differential Revision: https://reviews.llvm.org/D142129
2023-02-01[mlir][bufferization][NFC] Rename getAliasingOpOperand/getAliasingOpResultMatthias Springer
* `getAliasingOpOperand` => `getAliasingOpOperands` * `getAliasingOpResult` => `getAliasingOpResults` Also a few minor code cleanups and better documentation. Differential Revision: https://reviews.llvm.org/D142979
2023-01-30[mlir][bufferization] Generalize and rename isMemoryWriteMatthias Springer
The name of the method was confusing. It is bufferizesToMemoryWrite, but from the perspective of OpResults. `bufferizesToMemoryWrite(OpResult)` now supports ops with regions that do not have aliasing OpOperands (such as `scf.if`). These ops no longer need to implement `isMemoryWrite`. Differential Revision: https://reviews.llvm.org/D141684
2022-12-02[mlir] Remove support for non-prefixed accessorsRiver Riddle
This finishes off a year long pursuit to LLVMify the generated operation accessors, prefixing them with get/set. Support for any other accessor naming is fully removed after this commit. https://discourse.llvm.org/t/psa-raw-accessors-are-being-removed/65629 Differential Revision: https://reviews.llvm.org/D136727
2022-06-27[mlir][bufferization][NFC] Add error handling to getBufferMatthias Springer
This is in preparation of adding memory space support. Differential Revision: https://reviews.llvm.org/D128277
2022-06-27[mlir][shape][bufferize][NFC] Bufferize block terminators separatelyMatthias Springer
This allows for better type inference during bufferization and is in preparation of supporting memory spaces. Differential Revision: https://reviews.llvm.org/D128579
2022-06-27[mlir][bufferization][NFC] Bufferize with PostOrder traversalMatthias Springer
This is useful because the result type of an op can sometimes be inferred from its body (e.g., `scf.if`). This will be utilized in subsequent changes. Also introduces a new `getBufferType` interface method on BufferizableOpInterface. This method is useful for computing a bufferized block argument type with respect to OpOperand types of the parent op. Differential Revision: https://reviews.llvm.org/D128420
2022-06-17[mlir][bufferize][NFC] Remove BufferizationStateMatthias Springer
With the recent refactorings, this class is no longer needed. We can use BufferizationOptions in all places were BufferizationState was used. Differential Revision: https://reviews.llvm.org/D127653
2022-06-13[mlir][shape][bufferize] Fix typo in external modelMatthias Springer
Differential Revision: https://reviews.llvm.org/D127639
2022-05-25[mlir][bufferize] Remove hoisting functionality from One-Shot BufferizeMatthias Springer
The same functionality is already provided by `-buffer-hoisting` and `-buffer-loop-hoisting`. Differential Revision: https://reviews.llvm.org/D126251
2022-05-16[mlir][bufferize] Infer memref types when possibleMatthias Springer
Instead of recomputing memref types from tensor types, try to infer them when possible. This results in more precise layout maps. Differential Revision: https://reviews.llvm.org/D125614
2022-03-16[mlir] Refactor DialectRegistry delayed interface support into a general ↵River Riddle
DialectExtension mechanism The current dialect registry allows for attaching delayed interfaces, that are added to attrs/dialects/ops/etc. when the owning dialect gets loaded. This is clunky for quite a few reasons, e.g. each interface type has a separate tracking structure, and is also quite limiting. This commit refactors this delayed mutation of dialect constructs into a more general DialectExtension mechanism. This mechanism is essentially a registration callback that is invoked when a set of dialects have been loaded. This allows for attaching interfaces directly on the loaded constructs, and also allows for loading new dependent dialects. The latter of which is extremely useful as it will now enable dependent dialects to only apply in the contexts in which they are necessary. For example, a dialect dependency can now be conditional on if a user actually needs the interface that relies on it. Differential Revision: https://reviews.llvm.org/D120367
2022-03-15[mlir][bufferize] Extract buffer hoisting into separate functionMatthias Springer
This improves the modularity of the bufferization. From now on, all ops that do not implement BufferizableOpInterface are considered hoisting barriers. Previously, all ops that do not implement the interface were not considered barriers and such ops had to be marked as barriers explicitly. This was unsafe because we could've hoisted across unknown ops where it was not safe to hoist. As a side effect, this allows for cleaning up AffineBufferizableOpInterfaceImpl. This build unit no longer needed and can be deleted. Differential Revision: https://reviews.llvm.org/D121519
2022-03-15[mlir][bufferize][NFC] Split BufferizationState into ↵Matthias Springer
AnalysisState/BufferizationState Differential Revision: https://reviews.llvm.org/D121361
2022-03-07[mlir][shape] Migrate bufferization to BufferizableOpInterfaceMatthias Springer
Differential Revision: https://reviews.llvm.org/D121043