150
|
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
|
221
|
13 #include "mlir/IR/BuiltinOps.h"
|
|
14 #include "mlir/Target/LLVMIR/Dialect/All.h"
|
|
15 #include "mlir/Target/LLVMIR/Export.h"
|
150
|
16 #include "mlir/Translation.h"
|
221
|
17 #include "llvm/IR/LLVMContext.h"
|
150
|
18 #include "llvm/IR/Module.h"
|
|
19
|
|
20 using namespace mlir;
|
|
21
|
173
|
22 namespace mlir {
|
|
23 void registerToLLVMIRTranslation() {
|
|
24 TranslateFromMLIRRegistration registration(
|
221
|
25 "mlir-to-llvmir",
|
|
26 [](ModuleOp module, raw_ostream &output) {
|
|
27 llvm::LLVMContext llvmContext;
|
|
28 auto llvmModule = translateModuleToLLVMIR(module, llvmContext);
|
173
|
29 if (!llvmModule)
|
|
30 return failure();
|
150
|
31
|
173
|
32 llvmModule->print(output, nullptr);
|
|
33 return success();
|
221
|
34 },
|
|
35 [](DialectRegistry ®istry) {
|
|
36 registerAllToLLVMIRTranslations(registry);
|
173
|
37 });
|
|
38 }
|
|
39 } // namespace mlir
|