summaryrefslogtreecommitdiff
path: root/mlir/lib/Interfaces/SideEffectInterfaces.cpp
AgeCommit message (Collapse)Author
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-15[mlir] Remove unused includes (NFC) (#148872)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-02-11Revert "[mlir] Enable LICM for ops with only read side effects in scf.for" ↵Hongtao Yu
(#126840) Reverts llvm/llvm-project#120302
2025-02-11[mlir] Enable LICM for ops with only read side effects in scf.for (#120302)Arda Unal
Enable ops with only read side effects in scf.for to be hoisted with a scf.if guard that checks against the trip count This patch takes a step towards a less conservative LICM in MLIR as discussed in the following discourse thread: [Speculative LICM?](https://discourse.llvm.org/t/speculative-licm/80977) This patch in particular does the following: 1. Relaxes the original constraint for hoisting that only hoists ops without any side effects. This patch also allows the ops with only read side effects to be hoisted into an scf.if guard only if every op in the loop or its nested regions is side-effect free or has only read side effects. This scf.if guard wraps the original scf.for and checks for **trip_count > 0**. 2. To support this, two new interface methods are added to **LoopLikeInterface**: _wrapInTripCountCheck_ and _unwrapTripCountCheck_. Implementation starts with wrapping the scf.for loop into scf.if guard using _wrapInTripCountCheck_ and if there is no op hoisted into the this guard after we are done processing the worklist, it unwraps the guard by calling _unwrapTripCountCheck_.
2025-01-25Hold a queue of iterator ranges (not operations) in wouldOpBeTriviallyDead ↵Adam Paszke
(#123642) Ranges let us push the whole blocks onto the queue in constant time. If one of the first ops in the block is side-effecting we'll be able to provide the answer quickly. The previous implementation had to walk the block and queue all the operations only to start traversing them again, which was a considerable slowdown for compile times of large MLIR programs in our benchmarks. --------- Co-authored-by: Jacques Pienaar <jpienaar@google.com>
2024-06-19[mlir][side effect] refactor(*): Include more precise side effects (#94213)donald chen
This patch adds more precise side effects to the current ops with memory effects, allowing us to determine which OpOperand/OpResult/BlockArgument the operation reads or writes, rather than just recording the reading and writing of values. This allows for convenient use of precise side effects to achieve analysis and optimization. Related discussions: https://discourse.llvm.org/t/rfc-add-operandindex-to-sideeffect-instance/79243
2023-08-10[mlir][Transforms] teach CSE about recursive memory effectsTom Eccles
Add support for reasoning about operations with recursive memory effects to CSE. The recursive effects are gathered by a helper function. I decided to allow returning duplicates from the helper function because there's no benefit to spending the computation time to remove them in the existing use case. Differential Revision: https://reviews.llvm.org/D156805
2023-06-15[mlir][Interfaces] Symbols are not trivially deadMatthias Springer
The greedy pattern rewrite driver removes ops that are "trivially dead". This could include symbols that are still referenced by other ops. Dead symbols should be removed with the `-symbol-dce` pass instead. This bug was not triggered for `func::FuncOp`, because ops are not considered "trivally dead" if they do not implement the `MemoryEffectOpInterface`, indicating that the op may or may not have side effects. It is, however, triggered for `transform::NamedSequenceOp`, which implements that interface because it is required for all transform dialect ops. Differential Revision: https://reviews.llvm.org/D152994
2022-12-14Allow inline of all pure ops from the LLVM dialect.Ingo Müller
This allows to inline regions containing pure LLVM ops into their call sites. (Note that this is not related to inlining of llvm.func but to any the inlining of any Callable.) For now, we only allow the inlining of Pure ops to be conservative but other ops may be considered inlinable in the future. Testing for purity of ops requires the C++ equivalent of the Pure trait from SideEffectInterfaces.td, which this patch also provide. Its implementation calls the C++ equivalents of the two traits that the Pure trait is based on and, thus, has to be kept with the tablegen trait. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D139187
2022-11-15[mlir] Remove `Transforms/SideEffectUtils.h` and move the methods into ↵Mahesh Ravishankar
`Interface/SideEffectInterfaces.h`. The methods in `SideEffectUtils.h` (and their implementations in `SideEffectUtils.cpp`) seem to have similar intent to methods already existing in `SideEffectInterfaces.h`. Move the decleration (and implementation) from `SideEffectUtils.h` (and `SideEffectUtils.cpp`) into `SideEffectInterfaces.h` (and `SideEffectInterface.cpp`). Also drop the `SideEffectInterface::hasNoEffect` method in favor of `mlir::isMemoryEffectFree` which actually recurses into the operation instead of just relying on the `hasRecursiveMemoryEffectTrait` exclusively. Differential Revision: https://reviews.llvm.org/D137857
2022-10-12Introduce a ConditionallySpeculatable op interfaceSanjoy Das
This patch takes the first step towards a more principled modeling of undefined behavior in MLIR as discussed in the following discourse threads: 1. https://discourse.llvm.org/t/semantics-modeling-undefined-behavior-and-side-effects/4812 2. https://discourse.llvm.org/t/rfc-mark-tensor-dim-and-memref-dim-as-side-effecting/65729 This patch in particular does the following: 1. Introduces a ConditionallySpeculatable OpInterface that dynamically determines whether an Operation can be speculated. 2. Re-defines `NoSideEffect` to allow undefined behavior, making it necessary but not sufficient for speculation. Also renames it to `NoMemoryEffect`. 3. Makes LICM respect the above semantics. 4. Changes all ops tagged with `NoSideEffect` today to additionally implement ConditionallySpeculatable and mark themselves as always speculatable. This combined trait is named `Pure`. This makes this change NFC. For out of tree dialects: 1. Replace `NoSideEffect` with `Pure` if the operation does not have any memory effects, undefined behavior or infinite loops. 2. Replace `NoSideEffect` with `NoSideEffect` otherwise. The next steps in this process are (I'm proposing to do these in upcoming patches): 1. Update operations like `tensor.dim`, `memref.dim`, `scf.for`, `affine.for` to implement a correct hook for `ConditionallySpeculatable`. I'm also happy to update ops in other dialects if the respective dialect owners would like to and can give me some pointers. 2. Update other passes that speculate operations to consult `ConditionallySpeculatable` in addition to `NoMemoryEffect`. I could not find any other than LICM on a quick skim, but I could have missed some. 3. Add some documentation / FAQs detailing the differences between side effects, undefined behavior, speculatabilty. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D135505
2022-09-07[MLIR] NFC. Introduce mlir::hasEffect and refactor usages dialect utilUday Bondhugula
Introduce mlir::hasEffect and refactor existing usage to use utility. NFC. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D132117
2022-07-19[mlir] Ignore effects on allocated results when checking whether the op is ↵Markus Böck
trivially dead. In the current state, this is only special cased for Allocation effects, but any effects on results allocated by the operation may be ignored when checking whether the op may be removed, as none of them are possible to be observed if the result is unused. A use case for this is for IRs for languages which always initialize on allocation. To correctly model such operations, a Write as well as an Allocation effect should be placed on the result. This would prevent the Op from being deleted if unused however. This patch fixes that issue. Differential Revision: https://reviews.llvm.org/D129854
2022-07-16[MLIR] Clean up checks for alloc-like ops in analysisUday Bondhugula
Clean up checks for alloc-like ops in analysis. Use the analysis utility to properly check for the desired kind of effects. The previous locality utility worked for all practical purposes but wasn't sound and was locally duplicate code. Instead, use mlir::hasSingleEffect. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D129439
2022-07-16[MLIR] NFC. Clean up logic of hasSingleEffectUday Bondhugula
Clean up conditional logic of hasSingleEffect. NFC. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D129438
2022-05-14[MLIR][GPU] Add canonicalizer for gpu.memcpyArnab Dutta
Erase gpu.memcpy op when only uses of dest are the memcpy op in question, its allocation and deallocation ops. Reviewed By: bondhugula, csigg Differential Revision: https://reviews.llvm.org/D124257
2021-12-20Fix clang-tidy issues in mlir/ (NFC)Mehdi Amini
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D115956
2021-02-09[mlir][IR] Remove the concept of `OperationProperties`River Riddle
These properties were useful for a few things before traits had a better integration story, but don't really carry their weight well these days. Most of these properties are already checked via traits in most of the code. It is better to align the system around traits, and improve the performance/cost of traits in general. Differential Revision: https://reviews.llvm.org/D96088
2020-06-24[MLIR][NFC] Adopt variadic isa<>Rahul Joshi
Differential Revision: https://reviews.llvm.org/D82489
2020-05-15[MLIR] Continue renaming of "SideEffects"Stephen Neuendorffer
MLIRSideEffects -> MLIRSideEffectInterfaces SideEffects.h -> SideEffectInterfaces.h SideEffects.cpp -> SideEffectInterface.cpp Note that I haven't renamed TableGen/SideEffects.h or TableGen/SideEffects.cpp find -name "*.h" -exec sed -i "s/SideEffects.h/SideEffectInterfaces.h/" "{}" \; find -name "CMakeLists.txt" -exec sed -i "s/MLIRSideEffects/MLIRSideEffectInterfaces/" "{}" \; Differential Revision: https://reviews.llvm.org/D79890