1 //===-- LLVMIR.h - C Interface for MLIR LLVMIR Target ---------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 4 // Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "mlir-c/Target/LLVMIR.h" 11 #include "llvm-c/Support.h" 12 13 #include "llvm/IR/LLVMContext.h" 14 #include "llvm/IR/Module.h" 15 #include <memory> 16 17 #include "mlir/CAPI/IR.h" 18 #include "mlir/CAPI/Support.h" 19 #include "mlir/CAPI/Wrap.h" 20 #include "mlir/Target/LLVMIR/ModuleTranslation.h" 21 22 using namespace mlir; 23 mlirTranslateModuleToLLVMIR(MlirOperation module,LLVMContextRef context)24LLVMModuleRef mlirTranslateModuleToLLVMIR(MlirOperation module, 25 LLVMContextRef context) { 26 Operation *moduleOp = unwrap(module); 27 28 llvm::LLVMContext *ctx = llvm::unwrap(context); 29 30 std::unique_ptr<llvm::Module> llvmModule = 31 mlir::translateModuleToLLVMIR(moduleOp, *ctx); 32 33 LLVMModuleRef moduleRef = llvm::wrap(llvmModule.release()); 34 35 return moduleRef; 36 } 37