[all-commits] [llvm/llvm-project] 86771d: Introduce a ConditionallySpeculatable op interface

Sanjoy Das via All-commits all-commits at lists.llvm.org
Wed Oct 12 10:56:32 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 86771d0b65ee13242f89b8dfdf3c66f738eae4e5
      https://github.com/llvm/llvm-project/commit/86771d0b65ee13242f89b8dfdf3c66f738eae4e5
  Author: Sanjoy Das <sanjoy.das at getcruise.com>
  Date:   2022-10-12 (Wed, 12 Oct 2022)

  Changed paths:
    M mlir/docs/OpDefinitions.md
    M mlir/docs/Tutorials/QuickstartRewrites.md
    M mlir/docs/Tutorials/Toy/Ch-3.md
    M mlir/docs/Tutorials/Toy/Ch-4.md
    M mlir/examples/standalone/include/Standalone/StandaloneOps.td
    M mlir/examples/toy/Ch2/include/toy/Ops.td
    M mlir/examples/toy/Ch3/include/toy/Ops.td
    M mlir/examples/toy/Ch4/include/toy/Ops.td
    M mlir/examples/toy/Ch5/include/toy/Ops.td
    M mlir/examples/toy/Ch6/include/toy/Ops.td
    M mlir/examples/toy/Ch7/include/toy/Ops.td
    M mlir/include/mlir/Dialect/AMDGPU/AMDGPU.td
    M mlir/include/mlir/Dialect/AMX/AMX.td
    M mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
    M mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
    M mlir/include/mlir/Dialect/ArmNeon/ArmNeon.td
    M mlir/include/mlir/Dialect/ArmSVE/ArmSVE.td
    M mlir/include/mlir/Dialect/Async/IR/AsyncOps.td
    M mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td
    M mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
    M mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td
    M mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
    M mlir/include/mlir/Dialect/Func/IR/FuncOps.td
    M mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    M mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
    M mlir/include/mlir/Dialect/LLVMIR/ROCDLOps.td
    M mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
    M mlir/include/mlir/Dialect/MLProgram/IR/MLProgramOps.td
    M mlir/include/mlir/Dialect/Math/IR/MathOps.td
    M mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
    M mlir/include/mlir/Dialect/NVGPU/IR/NVGPU.td
    M mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
    M mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
    M mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
    M mlir/include/mlir/Dialect/Quant/QuantOps.td
    M mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBitOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCLOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCastOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCompositeOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVCooperativeMatrixOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGLOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVGroupOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVImageOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVJointMatrixOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVLogicalOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMatrixOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMemoryOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVMiscOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVNonUniformOps.td
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
    M mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
    M mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorOps.td
    M mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
    M mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
    M mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td
    M mlir/include/mlir/Dialect/Transform/IR/TransformOps.td
    M mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
    M mlir/include/mlir/Dialect/X86Vector/X86Vector.td
    M mlir/include/mlir/IR/BuiltinOps.td
    M mlir/include/mlir/Interfaces/SideEffectInterfaceBase.td
    M mlir/include/mlir/Interfaces/SideEffectInterfaces.h
    M mlir/include/mlir/Interfaces/SideEffectInterfaces.td
    M mlir/include/mlir/Transforms/SideEffectUtils.h
    M mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp
    M mlir/lib/Dialect/Affine/Utils/Utils.cpp
    M mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
    M mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp
    M mlir/lib/Dialect/Vector/Transforms/VectorTransferOpTransforms.cpp
    M mlir/lib/Interfaces/SideEffectInterfaces.cpp
    M mlir/lib/Transforms/ControlFlowSink.cpp
    M mlir/lib/Transforms/Utils/LoopInvariantCodeMotionUtils.cpp
    M mlir/lib/Transforms/Utils/SideEffectUtils.cpp
    M mlir/test/Transforms/loop-invariant-code-motion.mlir
    M mlir/test/lib/Dialect/Test/TestOps.td
    M mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td
    M mlir/test/mlir-tblgen/gen-dialect-doc.td
    M mlir/test/mlir-tblgen/llvm-intrinsics.td
    M mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp

  Log Message:
  -----------
  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




More information about the All-commits mailing list