| 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/Dialect/DLTI/DLTI.h" |
| 14 | #include "mlir/Dialect/Func/IR/FuncOps.h" |
| 15 | #include "mlir/IR/BuiltinOps.h" |
| 16 | #include "mlir/Target/LLVMIR/Dialect/All.h" |
| 17 | #include "mlir/Target/LLVMIR/Export.h" |
| 18 | #include "mlir/Tools/mlir-translate/Translation.h" |
| 19 | #include "llvm/IR/DebugProgramInstruction.h" |
| 20 | #include "llvm/IR/LLVMContext.h" |
| 21 | #include "llvm/IR/Module.h" |
| 22 | |
| 23 | using namespace mlir; |
| 24 | |
| 25 | namespace mlir { |
| 26 | void registerToLLVMIRTranslation() { |
| 27 | TranslateFromMLIRRegistration registration( |
| 28 | "mlir-to-llvmir", "Translate MLIR to LLVMIR", |
| 29 | [](Operation *op, raw_ostream &output) { |
| 30 | llvm::LLVMContext llvmContext; |
| 31 | auto llvmModule = translateModuleToLLVMIR(module: op, llvmContext); |
| 32 | if (!llvmModule) |
| 33 | return failure(); |
| 34 | |
| 35 | llvmModule->removeDebugIntrinsicDeclarations(); |
| 36 | llvmModule->print(OS&: output, AAW: nullptr); |
| 37 | return success(); |
| 38 | }, |
| 39 | [](DialectRegistry ®istry) { |
| 40 | registry.insert<DLTIDialect, func::FuncDialect>(); |
| 41 | registerAllToLLVMIRTranslations(registry); |
| 42 | }); |
| 43 | } |
| 44 | } // namespace mlir |
| 45 |
