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
22using namespace mlir;
23
24LLVMModuleRef mlirTranslateModuleToLLVMIR(MlirOperation module,
25 LLVMContextRef context) {
26 Operation *moduleOp = unwrap(c: module);
27
28 llvm::LLVMContext *ctx = llvm::unwrap(P: context);
29
30 std::unique_ptr<llvm::Module> llvmModule =
31 mlir::translateModuleToLLVMIR(module: moduleOp, llvmContext&: *ctx);
32
33 LLVMModuleRef moduleRef = llvm::wrap(P: llvmModule.release());
34
35 return moduleRef;
36}
37

source code of mlir/lib/CAPI/Target/LLVMIR.cpp