1 //===- ConvertToLLVMIR.cpp - MLIR to LLVM IR conversion -------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a translation between the MLIR LLVM dialect and LLVM IR.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "mlir/IR/BuiltinOps.h"
14 #include "mlir/Target/LLVMIR/Dialect/All.h"
15 #include "mlir/Target/LLVMIR/Export.h"
16 #include "mlir/Translation.h"
17 #include "llvm/IR/LLVMContext.h"
18 #include "llvm/IR/Module.h"
19 
20 using namespace mlir;
21 
22 namespace mlir {
23 void registerToLLVMIRTranslation() {
24   TranslateFromMLIRRegistration registration(
25       "mlir-to-llvmir",
26       [](ModuleOp module, raw_ostream &output) {
27         llvm::LLVMContext llvmContext;
28         auto llvmModule = translateModuleToLLVMIR(module, llvmContext);
29         if (!llvmModule)
30           return failure();
31 
32         llvmModule->print(output, nullptr);
33         return success();
34       },
35       [](DialectRegistry &registry) {
36         registerAllToLLVMIRTranslations(registry);
37       });
38 }
39 } // namespace mlir
40