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
|
|
13 #include "mlir/Target/LLVMIR.h"
|
|
14
|
|
15 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
|
|
16 #include "mlir/Translation.h"
|
|
17
|
|
18 #include "llvm/ADT/StringRef.h"
|
|
19 #include "llvm/IR/Module.h"
|
|
20 #include "llvm/Support/ToolOutputFile.h"
|
|
21
|
|
22 using namespace mlir;
|
|
23
|
|
24 std::unique_ptr<llvm::Module> mlir::translateModuleToLLVMIR(ModuleOp m) {
|
|
25 return LLVM::ModuleTranslation::translateModule<>(m);
|
|
26 }
|
|
27
|
|
28 static TranslateFromMLIRRegistration
|
|
29 registration("mlir-to-llvmir", [](ModuleOp module, raw_ostream &output) {
|
|
30 auto llvmModule = LLVM::ModuleTranslation::translateModule<>(module);
|
|
31 if (!llvmModule)
|
|
32 return failure();
|
|
33
|
|
34 llvmModule->print(output, nullptr);
|
|
35 return success();
|
|
36 });
|