llvm-project/mlir/lib
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
..
Analysis Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
AsmParser [mlir:Parser] Always splice parsed operations to the end of the parsed block 2022-10-05 13:11:38 -07:00
Bindings/Python [mlir] add OperationType to the Transform dialect 2022-10-11 09:55:19 +00:00
Bytecode [mlir:Parser] Always splice parsed operations to the end of the parsed block 2022-10-05 13:11:38 -07:00
CAPI [mlir] add OperationType to the Transform dialect 2022-10-11 09:55:19 +00:00
Conversion [mlir] Fix bitwidth of memref-to-llvm constant. 2022-10-12 17:13:01 +03:00
Dialect Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
ExecutionEngine [mlir][sparse] Add MLIR interface for sparse tensor file input and output. 2022-10-11 16:25:13 -07:00
IR [mlir][NFC] Make 'printOp' public in AsmPrinter 2022-10-05 19:00:53 +00:00
Interfaces Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
Parser [mlir] Add initial support for a binary serialization format 2022-08-22 00:36:26 -07:00
Pass [LLVM][Support] Support for `llvm:🆑:list`'s default values 2022-10-06 17:50:40 +00:00
Reducer [mlir-reduce] Support parsing operations other than 'builtin.module' as top-level 2022-10-03 16:15:53 -04:00
Rewrite [mlir] Use x.empty() instead of llvm::empty(x) (NFC) 2022-09-18 10:53:49 -07:00
Support [mlir] Generate C++ doc comments for interfaces 2022-08-10 15:12:29 +02:00
TableGen [mlir][ods] Generalize default/optional parameters 2022-09-20 11:07:53 -07:00
Target [mlir][llvm] Tablegen based operation import from LLVM IR. 2022-10-12 14:36:41 +03:00
Tools [mlir][mlir-translation] patch for standalone-translation command line description missing. 2022-10-04 09:14:40 +08:00
Transforms Introduce a ConditionallySpeculatable op interface 2022-10-12 10:56:12 -07:00
CMakeLists.txt [mlir] Add initial support for a binary serialization format 2022-08-22 00:36:26 -07:00