summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Bufferization/Transforms/OwnershipBasedBufferDeallocation.cpp
AgeCommit message (Collapse)Author
2025-10-28 [MLIR] Revamp RegionBranchOpInterface (#165429)Mehdi Amini
This is still somehow a WIP, we have some issues with this interface that are not trivial to solve. This patch tries to make the concepts of RegionBranchPoint and RegionSuccessor more robust and aligned with their definition: - A `RegionBranchPoint` is either the parent (`RegionBranchOpInterface`) op or a `RegionBranchTerminatorOpInterface` operation in a nested region. - A `RegionSuccessor` is either one of the nested region or the parent `RegionBranchOpInterface` Some new methods with reasonnable default implementation are added to help resolving the flow of values across the RegionBranchOpInterface. It is still not trivial in the current state to walk the def-use chain backward with this interface. For example when you have the 3rd block argument in the entry block of a for-loop, finding the matching operands requires to know about the hidden loop iterator block argument and where the iterargs start. The API is designed around forward-tracking of the chain unfortunately. Try to reland #161575 ; I suspect a buildbot incremental build issue.
2025-10-28Revert " [MLIR] Revamp RegionBranchOpInterface " (#165356)Mehdi Amini
Reverts llvm/llvm-project#161575 Broke Windows on ARM buildbot build, needs investigations.
2025-10-28 [MLIR] Revamp RegionBranchOpInterface (#161575)Mehdi Amini
This is still somehow a WIP, we have some issues with this interface that are not trivial to solve. This patch tries to make the concepts of RegionBranchPoint and RegionSuccessor more robust and aligned with their definition: - A `RegionBranchPoint` is either the parent (`RegionBranchOpInterface`) op or a `RegionBranchTerminatorOpInterface` operation in a nested region. - A `RegionSuccessor` is either one of the nested region or the parent `RegionBranchOpInterface` Some new methods with reasonnable default implementation are added to help resolving the flow of values across the RegionBranchOpInterface. It is still not trivial in the current state to walk the def-use chain backward with this interface. For example when you have the 3rd block argument in the entry block of a for-loop, finding the matching operands requires to know about the hidden loop iterator block argument and where the iterargs start. The API is designed around forward-tracking of the chain unfortunately.
2025-08-20[mlir][Interfaces] Add `hasUnknownEffects` helper function (#154523)Matthias Springer
I have seen misuse of the `hasEffect` API in downstream projects: users sometimes think that `hasEffect == false` indicates that the operation does not have a certain memory effect. That's not necessarily the case. When the op does not implement the `MemoryEffectsOpInterface`, it is unknown whether it has the specified effect. "false" can also mean "maybe". This commit clarifies the semantics in the documentation. Also adds `hasUnknownEffects` and `mightHaveEffect` convenience functions. Also simplifies a few call sites.
2025-07-25[mlir][NFC] update `mlir/Dialect` create APIs (33/n) (#150659)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-24[mlir][NFC] update `mlir/Dialect` create APIs (15/n) (#149921)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-06-06[MLIR] Keep cached symbol tables across buffer deallocation insertions (#141956)Michele Scuttari
The `DeallocationState` class has been modified to keep a reference to an externally owned `SymbolTableCollection` class, to preserve the cached symbol tables across multiple insertions of deallocation instructions.
2025-03-06[MLIR][NFC] Retire let constructor for Bufferization (#129850)lorenzo chelini
`let constructor` is legacy (do not use in tree!) since the table gen backend emits most of the glue logic to build a pass.
2024-09-10Reland [MLIR] Make resolveCallable customizable in CallOpInterface (#107989)Henrich Lauko
Relands #100361 with fixed dependencies.
2024-09-10Revert "[MLIR] Make `resolveCallable` customizable in `CallOpInterface`" ↵Matthias Springer
(#107984) Reverts llvm/llvm-project#100361 This commit caused some linker errors. (Missing `MLIRCallInterfaces` dependency.)
2024-09-10[MLIR] Make `resolveCallable` customizable in `CallOpInterface` (#100361)Henrich Lauko
Allow customization of the `resolveCallable` method in the `CallOpInterface`. This change allows for operations implementing this interface to provide their own logic for resolving callables. - Introduce the `resolveCallable` method, which does not include the optional symbol table parameter. This method replaces the previously existing extra class declaration `resolveCallable`. - Introduce the `resolveCallableInTable` method, which incorporates the symbol table parameter. This method replaces the previous extra class declaration `resolveCallable` that used the optional symbol table parameter.
2024-06-26Bufferization with ControlFlow Asserts (#95868)McCowan Zhang
Fixed incorrect bufferization interaction with cf.assert - reordered bufferization condition checking - fixed hasNeitherAllocateNorFreeSideEffect checking bug - implemented memory interface for cf.assert --------- Co-authored-by: McCowan Zhang <mccowan.z@ssi.samsung.com>
2024-06-10[mlir][bufferization] Fix handling of indirect function calls (#94896)Matthias Springer
This commit fixes a crash in the ownership-based buffer deallocation pass when indirectly calling a function via SSA value. Such functions must be conservatively assumed to be public. Fixes #94780.
2024-04-19Switch member calls to `isa/dyn_cast/cast/...` to free function calls. (#89356)Christian Sigg
This change cleans up call sites. Next step is to mark the member functions deprecated. See https://mlir.llvm.org/deprecation and https://discourse.llvm.org/t/preferred-casting-style-going-forward.
2024-03-05Fix remaining build failures with GCC 8.3 (#83266)Thomas Preud'homme
When compiling for GCC 8.x (< 8.4), SFINAE is disabled for iterator_range constructor causing ambiguous resolution to construct an OperandRange from a MutableOperatorRange, even in the presence of a static_cast<OperatorRange>. This adds an explicit conversion method to lift the ambiguity. Tested with a full MLIR build with GCC 8.3.
2024-02-05[mlir][bufferization][NFC] Pass `DeallocationOptions` instead of flags (#80675)Matthias Springer
Pass `DeallocationOptions` instead of `privateFuncDynamicOwnership`. This will make it easier to add new options in the future.
2024-02-05[mlir][bufferization] Never pass ownership to functions (#80655)Matthias Springer
Even when `private-function-dynamic-ownership` is set, ownership should never be passed to the callee. This can lead to double deallocs (#77096) or use-after-free in the caller because ownership is currently passed regardless of whether there are any further uses of the buffer in the caller or not. Note: This is consistent with the fact that ownership is never passed to nested regions. This commit fixes #77096.
2024-01-21[mlir][bufferization] Buffer deallocation: Make op preconditions stricter ↵Matthias Springer
(#75127) The buffer deallocation pass checks the IR ("operation preconditions") to make sure that there is no IR that is unsupported. In such a case, the pass signals a failure. The pass now rejects all ops with unknown memory effects. We do not know whether such an op allocates memory or not. Therefore, the buffer deallocation pass does not know whether a deallocation op should be inserted or not. Memory effects are queried from the `MemoryEffectOpInterface` interface. Ops that do not implement this interface but have the `RecursiveMemoryEffects` trait do not have any side effects (apart from the ones that their nested ops may have). Unregistered ops are now rejected by the pass because they do not implement the `MemoryEffectOpInterface` and neither do we know if they have `RecursiveMemoryEffects` or not. All test cases that currently have unregistered ops are updated to use registered ops.
2024-01-05[mlir][bufferization][NFC] Buffer deallocation: Add comment to ↵Matthias Springer
`handleInterface` (#76956) This is a follow-up for #68648.
2023-12-20[mlir][IR] Change block/region walkers to enumerate `this` block/region (#75020)Matthias Springer
This change makes block/region walkers consistent with operation walkers. An operation walk enumerates the current operation. Similarly, block/region walks should enumerate the current block/region. Example: ``` // Current behavior: op1->walk([](Operation *op2) { /* op1 is enumerated */ }); block1->walk([](Block *block2) { /* block1 is NOT enumerated */ }); region1->walk([](Block *block) { /* blocks of region1 are NOT enumerated */ }); region1->walk([](Region *region2) { /* region1 is NOT enumerated }); // New behavior: op1->walk([](Operation *op2) { /* op1 is enumerated */ }); block1->walk([](Block *block2) { /* block1 IS enumerated */ }); region1->walk([](Block *block) { /* blocks of region1 ARE enumerated */ }); region1->walk([](Region *region2) { /* region1 IS enumerated }); ```
2023-12-12[mlir][bufferization] Fix `regionOperatesOnMemrefValues` (#75016)Matthias Springer
`Region::walk([](Block *b) {...})` does not enumerate blocks that are direct children of the region. These blocks must be checked manually.
2023-11-01[mlir][bufferization] Fix ownership computation of unknown ops (#70773)Matthias Springer
No ownership is assumed for memref results of ops that implement none of the relevant interfaces and have no memref operands. This fixes #68948.
2023-10-23[mlir][bufferization] Ownership-based deallocation: Allow manual (de)allocs ↵Matthias Springer
(#68648) Add a new attribute `bufferization.manual_deallocation` that can be attached to allocation and deallocation ops. Buffers that are allocated with this attribute are assigned an ownership of "false". Such buffers can be deallocated manually (e.g., with `memref.dealloc`) if the deallocation op also has the attribute set. Previously, the ownership-based buffer deallocation pass used to reject IR with existing deallocation ops. This is no longer the case if such ops have this new attribute. This change is useful for the sparse compiler, which currently deallocates the sparse tensor buffers by itself.
2023-09-28Revert "[mlir][bufferization] Don't clone on unknown ownership and verify ↵Martin Erhart
function boundary ABI (#66626)" This reverts commit aa9eb47da2e501d3505de733240eb89c9a0ea2cf. It introduced a double free in a test case. Reverting to have some time for fixing this and relanding later.
2023-09-28[mlir][bufferization] Don't clone on unknown ownership and verify function ↵Martin Erhart
boundary ABI (#66626) Inserting clones requires a lot of assumptions to hold on the input IR, e.g., all writes to a buffer need to dominate all reads. This is not guaranteed by one-shot bufferization and isn't easy to verify, thus it could quickly lead to incorrect results that are hard to debug. This commit changes the mechanism of how an ownership indicator is materialized when there is not already a unique ownership present. Additionally, we don't create copies of returned memrefs anymore when we don't have ownership. Instead, we insert assert operations to make sure we have ownership at runtime, or otherwise report to the user that correctness could not be guaranteed.
2023-09-27[mlir][bufferization] Make buffer deallocation pipeline op type independent ↵Matthias Springer
(#67546) The buffer deallocation pipeline now works on modules and functions. Also add extra test cases that run the buffer deallocation pipeline on modules and functions. (Test cases that insert a helper function.)
2023-09-27[mlir][bufferization] OwnershipBasedBufferDeallocation fixes (#67418)Martin Erhart
* Properly handle the case where an op is deleted and thus no other interfaces should be processed anymore. * Don't add ownership indicator arguments and results to function declarations
2023-09-20[mlir][gpu][bufferization] Implement BufferDeallocationOpInterface for ↵Martin Erhart
gpu.terminator (#66880) This is necessary to support deallocation of IR with gpu.launch operations because it does not implement the RegionBranchOpInterface. Implementing the interface would require it to support regions with unstructured control flow and produced arguments/results.
2023-09-19[mlir][IR] Change `MutableArrayRange` to enumerate `OpOperand &` (#66622)Matthias Springer
In line with #66515, change `MutableArrayRange::begin`/`end` to enumerate `OpOperand &` instead of `Value`. Also remove `ForOp::getIterOpOperands`/`setIterArg`, which are now redundant. Note: `MutableOperandRange` cannot be made a derived class of `indexed_accessor_range_base` (like `OperandRange`), because `MutableOperandRange::assign` can change the number of operands in the range.
2023-09-15[mlir][bufferization] Define a pipeline for buffer deallocation (#66352)Martin Erhart
Since ownership based buffer deallocation requires a few passes to be run in a somewhat fixed sequence, it makes sense to have a pipeline for convenience (and to reduce the number of transform ops to represent default deallocation).
2023-09-14[mlir][bufferization] BufferDeallocationOpInterface: support custom ↵Martin Erhart
ownership update logic (#66350) Add a method to the BufferDeallocationOpInterface that allows operations to implement the interface and provide custom logic to compute the ownership indicators of values it defines. As a demonstrating example, this new method is implemented by the `arith.select` operation.
2023-09-14[mlir][bufferization][NFC] Introduce BufferDeallocationOpInterface (#66349)Martin Erhart
This new interface allows operations to implement custom handling of ownership values and insertion of dealloc operations which is useful when an op cannot implement the interfaces supported by default by the buffer deallocation pass (e.g., because they are not exactly compatible or because there are some additional semantics to it that would render the default implementations in buffer deallocation invalid, or because no interfaces exist for this kind of behavior and it's not worth introducing one plus a default implementation in buffer deallocation). Additionally, it can also be used to provide more efficient handling for a specific op than the interface based default implementations can.
2023-09-14[mlir][bufferization] Add an ownership based buffer deallocation pass (#66337)Martin Erhart
Add a new Buffer Deallocation pass with the intend to replace the old one. For now it is added as a separate pass alongside in order to allow downstream users to migrate over gradually. This new pass has the goal of inserting fewer clone operations and supporting additional use-cases. Please refer to the Buffer Deallocation section in the updated Bufferization.md file for more information on how this new pass works.