CIRCT 22.0.0git
Loading...
Searching...
No Matches
ExportLLVM.cpp
Go to the documentation of this file.
1//===- ExportLLVM.cpp - C Interface to LLVM IR export ---------------------===//
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
10#include "mlir/CAPI/IR.h"
11#include "mlir/CAPI/Support.h"
12#include "mlir/CAPI/Utils.h"
13#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h"
14#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
15#include "mlir/Target/LLVMIR/Export.h"
16#include "llvm/IR/LLVMContext.h"
17#include "llvm/IR/Module.h"
18#include "llvm/Support/raw_ostream.h"
19
20MlirLogicalResult mlirExportLLVMIR(MlirModule module,
21 MlirStringCallback callback,
22 void *userData) {
23 mlir::ModuleOp moduleOp = unwrap(module);
24 mlir::detail::CallbackOstream stream(callback, userData);
25
26 mlir::registerBuiltinDialectTranslation(*moduleOp->getContext());
27 mlir::registerLLVMDialectTranslation(*moduleOp->getContext());
28
29 llvm::LLVMContext llvmContext;
30 auto llvmModule = mlir::translateModuleToLLVMIR(moduleOp, llvmContext);
31 if (!llvmModule)
32 return mlirLogicalResultFailure();
33
34 llvmModule->print(stream, nullptr);
35 return mlirLogicalResultSuccess();
36}
MlirLogicalResult mlirExportLLVMIR(MlirModule module, MlirStringCallback callback, void *userData)
Exports LLVM IR for the specified module using the provided callback and user data.
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition OM.cpp:111