llvm-project/mlir
Sanjoy Das 86771d0b65 Introduce a ConditionallySpeculatable op interface
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-10-12 10:56:12 -07:00
..
benchmark/python [mlir][sparse] Expose SparseTensor passes as enums instead of opaque numbers for vectorization and parallelization options. 2022-09-04 01:39:35 +00:00
cmake/modules [CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited, part 2 2022-09-14 15:48:58 -04:00
docs Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
examples Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
include Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
lib Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
python [mlir] switch the transform loop extension to use types 2022-10-11 09:55:23 +00:00
test Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
tools Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
unittests [mlir][sparse] Favors synthetic tensor over other undefined tensors 2022-10-06 20:51:38 +00:00
utils [vscode-mlir] Bump to version 0.0.11 2022-09-28 02:50:24 -07:00
.clang-format
.clang-tidy [mlir] Disable `misc-const-correctness` clang-tidy check. 2022-08-03 10:18:43 +02:00
CMakeLists.txt Revert "[cmake] Use `CMAKE_INSTALL_LIBDIR` too" 2022-08-18 22:46:32 -04:00
LICENSE.TXT
README.md

README.md

Multi-Level Intermediate Representation

See https://mlir.llvm.org/ for more information.