diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt --- a/flang/lib/Frontend/CMakeLists.txt +++ b/flang/lib/Frontend/CMakeLists.txt @@ -34,6 +34,7 @@ HLFIRDialect HLFIRTransforms MLIRTransforms + MLIRBuiltinToLLVMIRTranslation MLIRLLVMToLLVMIRTranslation MLIRSCFToControlFlow MLIRTargetLLVMIRImport diff --git a/flang/lib/Optimizer/CodeGen/CMakeLists.txt b/flang/lib/Optimizer/CodeGen/CMakeLists.txt --- a/flang/lib/Optimizer/CodeGen/CMakeLists.txt +++ b/flang/lib/Optimizer/CodeGen/CMakeLists.txt @@ -23,6 +23,7 @@ MLIRMathToLLVM MLIRMathToLibm MLIROpenMPToLLVM + MLIRBuiltinToLLVMIRTranslation MLIRLLVMToLLVMIRTranslation MLIRTargetLLVMIRExport diff --git a/flang/lib/Optimizer/Dialect/CMakeLists.txt b/flang/lib/Optimizer/Dialect/CMakeLists.txt --- a/flang/lib/Optimizer/Dialect/CMakeLists.txt +++ b/flang/lib/Optimizer/Dialect/CMakeLists.txt @@ -17,6 +17,7 @@ LINK_LIBS FIRDialectSupport MLIRArithDialect + MLIRBuiltinToLLVMIRTranslation MLIROpenMPToLLVM MLIRLLVMToLLVMIRTranslation MLIRTargetLLVMIRExport diff --git a/flang/lib/Optimizer/Support/CMakeLists.txt b/flang/lib/Optimizer/Support/CMakeLists.txt --- a/flang/lib/Optimizer/Support/CMakeLists.txt +++ b/flang/lib/Optimizer/Support/CMakeLists.txt @@ -12,6 +12,7 @@ LINK_LIBS ${dialect_libs} + MLIRBuiltinToLLVMIRTranslation MLIROpenMPToLLVMIRTranslation MLIRLLVMToLLVMIRTranslation MLIRTargetLLVMIRExport diff --git a/flang/lib/Optimizer/Support/InitFIR.cpp b/flang/lib/Optimizer/Support/InitFIR.cpp --- a/flang/lib/Optimizer/Support/InitFIR.cpp +++ b/flang/lib/Optimizer/Support/InitFIR.cpp @@ -7,14 +7,17 @@ //===----------------------------------------------------------------------===// #include "flang/Optimizer/Support/InitFIR.h" +#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h" void fir::support::registerLLVMTranslation(mlir::MLIRContext &context) { mlir::DialectRegistry registry; // Register OpenMP dialect interface here as well. - mlir::registerOpenMPDialectTranslation(registry); + registerOpenMPDialectTranslation(registry); // Register LLVM-IR dialect interface. registerLLVMDialectTranslation(registry); + // Register builtin dialect interface. + registerBuiltinDialectTranslation(registry); context.appendDialectRegistry(registry); } diff --git a/flang/tools/tco/CMakeLists.txt b/flang/tools/tco/CMakeLists.txt --- a/flang/tools/tco/CMakeLists.txt +++ b/flang/tools/tco/CMakeLists.txt @@ -17,6 +17,7 @@ ${dialect_libs} MLIRIR MLIRLLVMDialect + MLIRBuiltinToLLVMIRTranslation MLIRLLVMToLLVMIRTranslation MLIRTargetLLVMIRExport MLIRPass diff --git a/mlir/examples/toy/Ch6/CMakeLists.txt b/mlir/examples/toy/Ch6/CMakeLists.txt --- a/mlir/examples/toy/Ch6/CMakeLists.txt +++ b/mlir/examples/toy/Ch6/CMakeLists.txt @@ -44,6 +44,7 @@ ${dialect_libs} ${conversion_libs} MLIRAnalysis + MLIRBuiltinToLLVMIRTranslation MLIRCallInterfaces MLIRCastInterfaces MLIRExecutionEngine diff --git a/mlir/examples/toy/Ch6/toyc.cpp b/mlir/examples/toy/Ch6/toyc.cpp --- a/mlir/examples/toy/Ch6/toyc.cpp +++ b/mlir/examples/toy/Ch6/toyc.cpp @@ -27,6 +27,7 @@ #include "mlir/Parser/Parser.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" +#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Export.h" #include "mlir/Transforms/Passes.h" @@ -200,6 +201,7 @@ int dumpLLVMIR(mlir::ModuleOp module) { // Register the translation to LLVM IR with the MLIR context. + mlir::registerBuiltinDialectTranslation(*module->getContext()); mlir::registerLLVMDialectTranslation(*module->getContext()); // Convert the module to LLVM IR in a new LLVM IR context. @@ -234,6 +236,7 @@ // Register the translation from MLIR to LLVM IR, which must happen before we // can JIT-compile. + mlir::registerBuiltinDialectTranslation(*module->getContext()); mlir::registerLLVMDialectTranslation(*module->getContext()); // An optimization pipeline to use within the execution engine. diff --git a/mlir/examples/toy/Ch7/CMakeLists.txt b/mlir/examples/toy/Ch7/CMakeLists.txt --- a/mlir/examples/toy/Ch7/CMakeLists.txt +++ b/mlir/examples/toy/Ch7/CMakeLists.txt @@ -43,6 +43,7 @@ ${dialect_libs} ${conversion_libs} MLIRAnalysis + MLIRBuiltinToLLVMIRTranslation MLIRCallInterfaces MLIRCastInterfaces MLIRExecutionEngine diff --git a/mlir/examples/toy/Ch7/toyc.cpp b/mlir/examples/toy/Ch7/toyc.cpp --- a/mlir/examples/toy/Ch7/toyc.cpp +++ b/mlir/examples/toy/Ch7/toyc.cpp @@ -27,6 +27,7 @@ #include "mlir/Parser/Parser.h" #include "mlir/Pass/Pass.h" #include "mlir/Pass/PassManager.h" +#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Export.h" #include "mlir/Transforms/Passes.h" @@ -201,6 +202,7 @@ int dumpLLVMIR(mlir::ModuleOp module) { // Register the translation to LLVM IR with the MLIR context. + mlir::registerBuiltinDialectTranslation(*module->getContext()); mlir::registerLLVMDialectTranslation(*module->getContext()); // Convert the module to LLVM IR in a new LLVM IR context. @@ -235,6 +237,7 @@ // Register the translation from MLIR to LLVM IR, which must happen before we // can JIT-compile. + mlir::registerBuiltinDialectTranslation(*module->getContext()); mlir::registerLLVMDialectTranslation(*module->getContext()); // An optimization pipeline to use within the execution engine. diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h --- a/mlir/include/mlir/Target/LLVMIR/Dialect/All.h +++ b/mlir/include/mlir/Target/LLVMIR/Dialect/All.h @@ -17,6 +17,8 @@ #include "mlir/Target/LLVMIR/Dialect/AMX/AMXToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/ArmNeon/ArmNeonToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/ArmSVE/ArmSVEToLLVMIRTranslation.h" +#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" +#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.h" @@ -34,6 +36,8 @@ registerArmNeonDialectTranslation(registry); registerAMXDialectTranslation(registry); registerArmSVEDialectTranslation(registry); + registerBuiltinDialectTranslation(registry); + registerGPUDialectTranslation(registry); registerLLVMDialectTranslation(registry); registerNVVMDialectTranslation(registry); registerOpenACCDialectTranslation(registry); diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h b/mlir/include/mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h @@ -0,0 +1,32 @@ +//===- BuiltinToLLVMIRTranslation.h - Builtin Dialect to LLVM IR --*- C++ +//-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This provides registration calls for builtin dialect to LLVM IR translation. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TARGET_LLVMIR_DIALECT_BUILTIN_BUILTINTOLLVMIRTRANSLATION_H +#define MLIR_TARGET_LLVMIR_DIALECT_BUILTIN_BUILTINTOLLVMIRTRANSLATION_H + +namespace mlir { + +class DialectRegistry; +class MLIRContext; + +/// Register the translation from the builtin dialect to the LLVM IR in the +/// given registry. +void registerBuiltinDialectTranslation(DialectRegistry ®istry); + +/// Register the translation from the builtin dialect in the registry associated +/// with the given context. +void registerBuiltinDialectTranslation(MLIRContext &context); + +} // namespace mlir + +#endif // MLIR_TARGET_LLVMIR_DIALECT_BUILTIN_BUILTINTOLLVMIRTRANSLATION_H diff --git a/mlir/include/mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h b/mlir/include/mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h @@ -0,0 +1,32 @@ +//===- GPUToLLVMIRTranslation.h - GPU Dialect to LLVM IR --*- C++ +//-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This provides registration calls for GPU dialect to LLVM IR translation. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_TARGET_LLVMIR_DIALECT_GPU_GPUTOLLVMIRTRANSLATION_H +#define MLIR_TARGET_LLVMIR_DIALECT_GPU_GPUTOLLVMIRTRANSLATION_H + +namespace mlir { + +class DialectRegistry; +class MLIRContext; + +/// Register the GPU dialect and the translation from it to the LLVM IR in +/// the given registry; +void registerGPUDialectTranslation(DialectRegistry ®istry); + +/// Register the GPU dialect and the translation from it in the registry +/// associated with the given context. +void registerGPUDialectTranslation(MLIRContext &context); + +} // namespace mlir + +#endif // MLIR_TARGET_LLVMIR_DIALECT_GPU_GPUTOLLVMIRTRANSLATION_H diff --git a/mlir/lib/CAPI/ExecutionEngine/CMakeLists.txt b/mlir/lib/CAPI/ExecutionEngine/CMakeLists.txt --- a/mlir/lib/CAPI/ExecutionEngine/CMakeLists.txt +++ b/mlir/lib/CAPI/ExecutionEngine/CMakeLists.txt @@ -8,6 +8,7 @@ ExecutionEngine.cpp LINK_LIBS PUBLIC + MLIRBuiltinToLLVMIRTranslation MLIRExecutionEngine MLIRLLVMToLLVMIRTranslation ) diff --git a/mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp --- a/mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp +++ b/mlir/lib/CAPI/ExecutionEngine/ExecutionEngine.cpp @@ -11,6 +11,7 @@ #include "mlir/CAPI/IR.h" #include "mlir/CAPI/Support.h" #include "mlir/ExecutionEngine/OptUtils.h" +#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "llvm/ExecutionEngine/Orc/Mangling.h" #include "llvm/Support/TargetSelect.h" @@ -29,7 +30,9 @@ }(); (void)initOnce; - mlir::registerLLVMDialectTranslation(*unwrap(op)->getContext()); + auto &ctx = *unwrap(op)->getContext(); + mlir::registerBuiltinDialectTranslation(ctx); + mlir::registerLLVMDialectTranslation(ctx); auto tmBuilderOrError = llvm::orc::JITTargetMachineBuilder::detectHost(); if (!tmBuilderOrError) { diff --git a/mlir/lib/CAPI/RegisterEverything/CMakeLists.txt b/mlir/lib/CAPI/RegisterEverything/CMakeLists.txt --- a/mlir/lib/CAPI/RegisterEverything/CMakeLists.txt +++ b/mlir/lib/CAPI/RegisterEverything/CMakeLists.txt @@ -10,6 +10,7 @@ ${translation_libs} ${conversion_libs} + MLIRBuiltinToLLVMIRTranslation MLIRCAPIIR MLIRLLVMToLLVMIRTranslation MLIRCAPITransforms diff --git a/mlir/lib/CAPI/RegisterEverything/RegisterEverything.cpp b/mlir/lib/CAPI/RegisterEverything/RegisterEverything.cpp --- a/mlir/lib/CAPI/RegisterEverything/RegisterEverything.cpp +++ b/mlir/lib/CAPI/RegisterEverything/RegisterEverything.cpp @@ -11,6 +11,7 @@ #include "mlir/CAPI/IR.h" #include "mlir/InitAllDialects.h" #include "mlir/InitAllPasses.h" +#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" void mlirRegisterAllDialects(MlirDialectRegistry registry) { @@ -18,7 +19,9 @@ } void mlirRegisterAllLLVMTranslations(MlirContext context) { - mlir::registerLLVMDialectTranslation(*unwrap(context)); + auto &ctx = *unwrap(context); + mlir::registerBuiltinDialectTranslation(ctx); + mlir::registerLLVMDialectTranslation(ctx); } void mlirRegisterAllPasses() { mlir::registerAllPasses(); } diff --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt --- a/mlir/lib/Dialect/GPU/CMakeLists.txt +++ b/mlir/lib/Dialect/GPU/CMakeLists.txt @@ -70,11 +70,13 @@ MLIRAffineUtils MLIRArithDialect MLIRAsyncDialect + MLIRBuiltinToLLVMIRTranslation MLIRDataLayoutInterfaces MLIRExecutionEngineUtils MLIRGPUOps MLIRIR MLIRLLVMDialect + MLIRGPUToLLVMIRTranslation MLIRLLVMToLLVMIRTranslation MLIRMemRefDialect MLIRPass diff --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp --- a/mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToBlob.cpp @@ -14,6 +14,7 @@ #include "mlir/Dialect/GPU/Transforms/Passes.h" #include "mlir/Pass/Pass.h" +#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Export.h" #include "llvm/IR/LegacyPassManager.h" @@ -108,6 +109,7 @@ void gpu::SerializeToBlobPass::getDependentDialects( DialectRegistry ®istry) const { + registerGPUDialectTranslation(registry); registerLLVMDialectTranslation(registry); OperationPass::getDependentDialects(registry); } diff --git a/mlir/lib/ExecutionEngine/CMakeLists.txt b/mlir/lib/ExecutionEngine/CMakeLists.txt --- a/mlir/lib/ExecutionEngine/CMakeLists.txt +++ b/mlir/lib/ExecutionEngine/CMakeLists.txt @@ -86,6 +86,7 @@ ${LLVM_JIT_LISTENER_LIB} LINK_LIBS PUBLIC + MLIRBuiltinToLLVMIRTranslation MLIRExecutionEngineUtils MLIRLLVMDialect MLIRLLVMToLLVMIRTranslation diff --git a/mlir/lib/Target/LLVMIR/CMakeLists.txt b/mlir/lib/Target/LLVMIR/CMakeLists.txt --- a/mlir/lib/Target/LLVMIR/CMakeLists.txt +++ b/mlir/lib/Target/LLVMIR/CMakeLists.txt @@ -46,6 +46,8 @@ MLIRArmNeonToLLVMIRTranslation MLIRArmSVEToLLVMIRTranslation MLIRAMXToLLVMIRTranslation + MLIRBuiltinToLLVMIRTranslation + MLIRGPUToLLVMIRTranslation MLIRX86VectorToLLVMIRTranslation MLIRLLVMToLLVMIRTranslation MLIRNVVMToLLVMIRTranslation diff --git a/mlir/lib/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.cpp @@ -0,0 +1,46 @@ +//===- BuiltinToLLVMIRTranslation.cpp - Translate builtin to LLVM IR ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a translation between the MLIR builtin dialect and LLVM +// IR. +// +//===----------------------------------------------------------------------===// +#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" +#include "mlir/IR/BuiltinDialect.h" +#include "mlir/IR/BuiltinOps.h" +#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h" + +using namespace mlir; + +namespace { + +class BuiltinDialectLLVMIRTranslationInterface + : public LLVMTranslationDialectInterface { +public: + using LLVMTranslationDialectInterface::LLVMTranslationDialectInterface; + + LogicalResult + convertOperation(Operation *op, llvm::IRBuilderBase &builder, + LLVM::ModuleTranslation &moduleTranslation) const override { + return isa(op) ? success() : failure(); + } +}; + +} // namespace + +void mlir::registerBuiltinDialectTranslation(DialectRegistry ®istry) { + registry.addExtension(+[](MLIRContext *ctx, BuiltinDialect *dialect) { + dialect->addInterfaces(); + }); +} + +void mlir::registerBuiltinDialectTranslation(MLIRContext &context) { + DialectRegistry registry; + registerBuiltinDialectTranslation(registry); + context.appendDialectRegistry(registry); +} diff --git a/mlir/lib/Target/LLVMIR/Dialect/Builtin/CMakeLists.txt b/mlir/lib/Target/LLVMIR/Dialect/Builtin/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/Target/LLVMIR/Dialect/Builtin/CMakeLists.txt @@ -0,0 +1,12 @@ +add_mlir_translation_library(MLIRBuiltinToLLVMIRTranslation + BuiltinToLLVMIRTranslation.cpp + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + MLIRIR + MLIRLLVMDialect + MLIRSupport + MLIRTargetLLVMIRExport + ) diff --git a/mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt b/mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt --- a/mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt +++ b/mlir/lib/Target/LLVMIR/Dialect/CMakeLists.txt @@ -1,6 +1,8 @@ add_subdirectory(ArmNeon) add_subdirectory(ArmSVE) add_subdirectory(AMX) +add_subdirectory(Builtin) +add_subdirectory(GPU) add_subdirectory(LLVMIR) add_subdirectory(NVVM) add_subdirectory(OpenACC) diff --git a/mlir/lib/Target/LLVMIR/Dialect/GPU/CMakeLists.txt b/mlir/lib/Target/LLVMIR/Dialect/GPU/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/Target/LLVMIR/Dialect/GPU/CMakeLists.txt @@ -0,0 +1,13 @@ +add_mlir_translation_library(MLIRGPUToLLVMIRTranslation + GPUToLLVMIRTranslation.cpp + + LINK_COMPONENTS + Core + + LINK_LIBS PUBLIC + MLIRIR + MLIRGPUOps + MLIRLLVMDialect + MLIRSupport + MLIRTargetLLVMIRExport + ) diff --git a/mlir/lib/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.cpp @@ -0,0 +1,45 @@ +//===- GPUToLLVMIRTranslation.cpp - Translate GPU dialect to LLVM IR ------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a translation between the MLIR GPU dialect and LLVM IR. +// +//===----------------------------------------------------------------------===// +#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h" +#include "mlir/Dialect/GPU/IR/GPUDialect.h" +#include "mlir/Target/LLVMIR/LLVMTranslationInterface.h" + +using namespace mlir; + +namespace { + +class GPUDialectLLVMIRTranslationInterface + : public LLVMTranslationDialectInterface { +public: + using LLVMTranslationDialectInterface::LLVMTranslationDialectInterface; + + LogicalResult + convertOperation(Operation *op, llvm::IRBuilderBase &builder, + LLVM::ModuleTranslation &moduleTranslation) const override { + return isa(op) ? success() : failure(); + } +}; + +} // namespace + +void mlir::registerGPUDialectTranslation(DialectRegistry ®istry) { + registry.insert(); + registry.addExtension(+[](MLIRContext *ctx, gpu::GPUDialect *dialect) { + dialect->addInterfaces(); + }); +} + +void mlir::registerGPUDialectTranslation(MLIRContext &context) { + DialectRegistry registry; + registerGPUDialectTranslation(registry); + context.appendDialectRegistry(registry); +} diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -1320,6 +1320,10 @@ } } + // Convert module itself. + if (failed(translator.convertOperation(*module, llvmBuilder))) + return nullptr; + if (llvm::verifyModule(*translator.llvmModule, &llvm::errs())) return nullptr; diff --git a/mlir/tools/mlir-cpu-runner/CMakeLists.txt b/mlir/tools/mlir-cpu-runner/CMakeLists.txt --- a/mlir/tools/mlir-cpu-runner/CMakeLists.txt +++ b/mlir/tools/mlir-cpu-runner/CMakeLists.txt @@ -11,6 +11,7 @@ llvm_update_compile_flags(mlir-cpu-runner) target_link_libraries(mlir-cpu-runner PRIVATE MLIRAnalysis + MLIRBuiltinToLLVMIRTranslation MLIRExecutionEngine MLIRIR MLIRJitRunner diff --git a/mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt b/mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt --- a/mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt +++ b/mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt @@ -17,6 +17,7 @@ ${conversion_libs} MLIRAnalysis MLIRArithDialect + MLIRBuiltinToLLVMIRTranslation MLIRExecutionEngine MLIRFuncDialect MLIRGPUOps diff --git a/mlir/tools/mlir-vulkan-runner/CMakeLists.txt b/mlir/tools/mlir-vulkan-runner/CMakeLists.txt --- a/mlir/tools/mlir-vulkan-runner/CMakeLists.txt +++ b/mlir/tools/mlir-vulkan-runner/CMakeLists.txt @@ -57,6 +57,7 @@ ${conversion_libs} MLIRAnalysis MLIRArithDialect + MLIRBuiltinToLLVMIRTranslation MLIRExecutionEngine MLIRFuncDialect MLIRGPUOps diff --git a/mlir/unittests/ExecutionEngine/Invoke.cpp b/mlir/unittests/ExecutionEngine/Invoke.cpp --- a/mlir/unittests/ExecutionEngine/Invoke.cpp +++ b/mlir/unittests/ExecutionEngine/Invoke.cpp @@ -23,6 +23,7 @@ #include "mlir/InitAllDialects.h" #include "mlir/Parser/Parser.h" #include "mlir/Pass/PassManager.h" +#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" #include "mlir/Target/LLVMIR/Export.h" #include "llvm/Support/TargetSelect.h" @@ -69,6 +70,7 @@ )mlir"; DialectRegistry registry; registerAllDialects(registry); + registerBuiltinDialectTranslation(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); OwningOpRef module = @@ -95,6 +97,7 @@ )mlir"; DialectRegistry registry; registerAllDialects(registry); + registerBuiltinDialectTranslation(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); OwningOpRef module = @@ -126,6 +129,7 @@ )mlir"; DialectRegistry registry; registerAllDialects(registry); + registerBuiltinDialectTranslation(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); auto module = parseSourceString(moduleStr, &context); @@ -161,6 +165,7 @@ )mlir"; DialectRegistry registry; registerAllDialects(registry); + registerBuiltinDialectTranslation(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); auto module = parseSourceString(moduleStr, &context); @@ -215,6 +220,7 @@ )mlir"; DialectRegistry registry; registerAllDialects(registry); + registerBuiltinDialectTranslation(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); OwningOpRef module = @@ -264,6 +270,7 @@ )mlir"; DialectRegistry registry; registerAllDialects(registry); + registerBuiltinDialectTranslation(registry); registerLLVMDialectTranslation(registry); MLIRContext context(registry); auto module = parseSourceString(moduleStr, &context);