[mlir] Support lowering of dialect attributes attached to top-level modules
authorSergio Afonso <safonsof@amd.com>
Mon, 13 Mar 2023 12:51:18 +0000 (12:51 +0000)
committerSergio Afonso <safonsof@amd.com>
Tue, 21 Mar 2023 12:54:26 +0000 (12:54 +0000)
commit0e9523efda8a4ad95ecb1d5b5e65e10bcc3711f5
tree52af06f42e6aa1a6786dced7e864cf775ba1c3cb
parentcdccea8eb3b739ce11c2bab7b9c561b5a80abbf7
[mlir] Support lowering of dialect attributes attached to top-level modules

This patch supports the processing of dialect attributes attached to top-level
module-type operations during MLIR-to-LLVMIR lowering.

This approach modifies the `mlir::translateModuleToLLVMIR()` function to call
`ModuleTranslation::convertOperation()` on the top-level operation, after its
body has been lowered. This, in turn, will get the
`LLVMTranslationDialectInterface` object associated to that operation's dialect
before trying to use it for lowering prior to processing dialect attributes
attached to the operation.

Since there are no `LLVMTranslationDialectInterface`s for the builtin and GPU
dialects, which define their own module-type operations, this patch also adds
and registers them. The requirement for always calling
`mlir::registerBuiltinDialectTranslation()` before any translation of MLIR to
LLVM IR where builtin module operations are present is introduced. The purpose
of these new translation interfaces is to succeed when processing module-type
operations, allowing the lowering process to continue and to prevent the
introduction of failures related to not finding such interfaces.

Differential Revision: https://reviews.llvm.org/D145932
31 files changed:
flang/lib/Frontend/CMakeLists.txt
flang/lib/Optimizer/CodeGen/CMakeLists.txt
flang/lib/Optimizer/Dialect/CMakeLists.txt
flang/lib/Optimizer/Support/CMakeLists.txt
flang/lib/Optimizer/Support/InitFIR.cpp
flang/tools/tco/CMakeLists.txt
mlir/examples/toy/Ch6/CMakeLists.txt
mlir/examples/toy/Ch6/toyc.cpp
mlir/examples/toy/Ch7/CMakeLists.txt
mlir/examples/toy/Ch7/toyc.cpp
mlir/include/mlir/Target/LLVMIR/Dialect/All.h
mlir/include/mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h [new file with mode: 0644]
mlir/include/mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h [new file with mode: 0644]
mlir/lib/CAPI/ExecutionEngine/CMakeLists.txt
mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp
mlir/lib/CAPI/RegisterEverything/CMakeLists.txt
mlir/lib/CAPI/RegisterEverything/RegisterEverything.cpp
mlir/lib/Dialect/GPU/CMakeLists.txt
mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp
mlir/lib/ExecutionEngine/CMakeLists.txt
mlir/lib/Target/LLVMIR/CMakeLists.txt
mlir/lib/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.cpp [new file with mode: 0644]
mlir/lib/Target/LLVMIR/Dialect/Builtin/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt
mlir/lib/Target/LLVMIR/Dialect/GPU/CMakeLists.txt [new file with mode: 0644]
mlir/lib/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.cpp [new file with mode: 0644]
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/tools/mlir-cpu-runner/CMakeLists.txt
mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt
mlir/tools/mlir-vulkan-runner/CMakeLists.txt
mlir/unittests/ExecutionEngine/Invoke.cpp