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