MLIR  19.0.0git
LLVMIR.cpp
Go to the documentation of this file.
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"
21 
22 using namespace mlir;
23 
24 LLVMModuleRef 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 }
LLVMModuleRef mlirTranslateModuleToLLVMIR(MlirOperation module, LLVMContextRef context)
Translate operation that satisfies LLVM dialect module requirements into an LLVM IR module living in ...
Definition: LLVMIR.cpp:24
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
Include the generated interface declarations.
std::unique_ptr< llvm::Module > translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext, llvm::StringRef name="LLVMDialectModule")
Translate operation that satisfies LLVM dialect module requirements into an LLVM IR module living in ...