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 namespace mlir { 29 void registerToLLVMIRTranslation() { 30 TranslateFromMLIRRegistration registration( 31 "mlir-to-llvmir", [](ModuleOp module, raw_ostream &output) { 32 auto llvmModule = LLVM::ModuleTranslation::translateModule<>(module); 33 if (!llvmModule) 34 return failure(); 35 36 llvmModule->print(output, nullptr); 37 return success(); 38 }); 39 } 40 } // namespace mlir 41