[mlir] Introduce dialect interfaces for translation to LLVM IR
authorAlex Zinenko <zinenko@google.com>
Thu, 11 Feb 2021 14:01:33 +0000 (15:01 +0100)
committerAlex Zinenko <zinenko@google.com>
Fri, 12 Feb 2021 16:49:44 +0000 (17:49 +0100)
commitb77bac0572340d4e5b6095a82e0fcbcc01870645
treef92fe17e0584a4eca86203e412a0e0e7b9bd454f
parent33f35a4b793bb53b830f8893110af57672e1dc79
[mlir] Introduce dialect interfaces for translation to LLVM IR

The existing approach to translation to the LLVM IR relies on a single
translation supporting the base LLVM dialect, extensible through inheritance to
support intrinsic-based dialects also derived from LLVM IR such as NVVM and
AVX512. This approach does not scale well as it requires additional
translations to be created for each new intrinsic-based dialect and does not
allow them to mix in the same module, contrary to the rest of the MLIR
infrastructure. Furthermore, OpenMP translation ingrained itself into the main
translation mechanism.

Start refactoring the translation to LLVM IR to operate using dialect
interfaces. Each dialect that contains ops translatable to LLVM IR can
implement the interface for translating them, and the top-level translation
driver can operate on interfaces without knowing about specific dialects.
Furthermore, the delayed dialect registration mechanism allows one to avoid a
dependency on LLVM IR in the dialect that is translated to it by implementing
the translation as a separate library and only registering it at the client
level.

This change introduces the new mechanism and factors out the translation of the
"main" LLVM dialect. The remaining dialects will follow suit.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D96503
24 files changed:
mlir/examples/toy/Ch6/toyc.cpp
mlir/examples/toy/Ch7/toyc.cpp
mlir/include/mlir/Target/LLVMIR.h
mlir/include/mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h [new file with mode: 0644]
mlir/include/mlir/Target/LLVMIR/LLVMTranslationInterface.h [new file with mode: 0644]
mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
mlir/lib/Target/CMakeLists.txt
mlir/lib/Target/LLVMIR/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
mlir/lib/Target/LLVMIR/ConvertToNVVMIR.cpp
mlir/lib/Target/LLVMIR/ConvertToROCDLIR.cpp
mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Target/LLVMIR/Dialect/LLVMIR/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp [new file with mode: 0644]
mlir/lib/Target/LLVMIR/LLVMAVX512Intr.cpp
mlir/lib/Target/LLVMIR/LLVMArmNeonIntr.cpp
mlir/lib/Target/LLVMIR/LLVMArmSVEIntr.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/tools/mlir-cpu-runner/mlir-cpu-runner.cpp
mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
mlir/tools/mlir-rocm-runner/mlir-rocm-runner.cpp
mlir/tools/mlir-spirv-cpu-runner/mlir-spirv-cpu-runner.cpp
mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
mlir/unittests/ExecutionEngine/Invoke.cpp