[mlir] Add a generic mem2reg implementation.
authorThéo Degioanni <theo.degioanni@nextsilicon.com>
Thu, 27 Apr 2023 06:00:39 +0000 (06:00 +0000)
committerTobias Gysi <tobias.gysi@nextsilicon.com>
Thu, 27 Apr 2023 06:00:48 +0000 (06:00 +0000)
commitf88f8fd0bca34dc8e5571cb828b1a159a50fd504
treeffa24b2b6200845f4e641da7cac0689a28d3d2d4
parentc00b7c84c7cb1d528464bf68305fd23a9755768c
[mlir] Add a generic mem2reg implementation.

This patch introduces a generic implementation of mem2reg on
unstructured control-flow, along with a specialization for LLVM IR. This
is achieved by defining three new interfaces, representing 1. allocating
operations, 2. operations doing memory accesses, 3. operations that can
be rewired and/or deleted to stop using a specific use.

The file containing the core implementation of the algorithm
(`Mem2Reg.cpp`) contains a detailed explanation of how the algorithm
works. The contract for this pass is that given a memory slot with a
single non-aliased pointer, the pass will either remove all the uses of
the pointer or not change anything.

To help review this patch, I recommend starting by looking at the
interfaces defined in `Mem2Reg.td`, along with their reference
implementation for LLVM IR defined in `LLVMMem2Reg.cpp`. Then, the core
algorithm is implemented in `Mem2Reg.cpp`.

If this is all good I also have an implementation of the interfaces for
0-dimensional memref promotion that I can upstream afterwards.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D148109
18 files changed:
llvm/include/llvm/ADT/DenseMap.h
mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/include/mlir/Interfaces/CMakeLists.txt
mlir/include/mlir/Interfaces/Mem2RegInterfaces.h [new file with mode: 0644]
mlir/include/mlir/Interfaces/Mem2RegInterfaces.td [new file with mode: 0644]
mlir/include/mlir/Transforms/Mem2Reg.h [new file with mode: 0644]
mlir/include/mlir/Transforms/Passes.h
mlir/include/mlir/Transforms/Passes.td
mlir/lib/Dialect/LLVMIR/CMakeLists.txt
mlir/lib/Dialect/LLVMIR/IR/LLVMMem2Reg.cpp [new file with mode: 0644]
mlir/lib/Interfaces/CMakeLists.txt
mlir/lib/Interfaces/Mem2RegInterfaces.cpp [new file with mode: 0644]
mlir/lib/Transforms/CMakeLists.txt
mlir/lib/Transforms/Mem2Reg.cpp [new file with mode: 0644]
mlir/test/Transforms/mem2reg-llvmir-dbginfo.mlir [new file with mode: 0644]
mlir/test/Transforms/mem2reg-llvmir.mlir [new file with mode: 0644]