1//===-- LLVMIR.h - C Interface for MLIR LLVMIR Target -------------*- C -*-===//
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// This header declares the C interface to target LLVMIR with MLIR.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_C_TARGET_LLVMIR_H
15#define MLIR_C_TARGET_LLVMIR_H
16
17#include "mlir-c/IR.h"
18#include "mlir-c/Support.h"
19#include "llvm-c/Core.h"
20#include "llvm-c/Support.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/// Translate operation that satisfies LLVM dialect module requirements into an
27/// LLVM IR module living in the given context. This translates operations from
28/// any dilalect that has a registered implementation of
29/// LLVMTranslationDialectInterface.
30///
31/// \returns the generated LLVM IR Module from the translated MLIR module, it is
32/// owned by the caller.
33MLIR_CAPI_EXPORTED LLVMModuleRef
34mlirTranslateModuleToLLVMIR(MlirOperation module, LLVMContextRef context);
35
36struct MlirTypeFromLLVMIRTranslator {
37 void *ptr;
38};
39
40typedef struct MlirTypeFromLLVMIRTranslator MlirTypeFromLLVMIRTranslator;
41
42/// Create an LLVM::TypeFromLLVMIRTranslator and transfer ownership to the
43/// caller.
44MLIR_CAPI_EXPORTED MlirTypeFromLLVMIRTranslator
45mlirTypeFromLLVMIRTranslatorCreate(MlirContext ctx);
46
47/// Takes an LLVM::TypeFromLLVMIRTranslator owned by the caller and destroys it.
48/// It is the responsibility of the user to only pass an
49/// LLVM::TypeFromLLVMIRTranslator class.
50MLIR_CAPI_EXPORTED void
51mlirTypeFromLLVMIRTranslatorDestroy(MlirTypeFromLLVMIRTranslator translator);
52
53/// Translates the given LLVM IR type to the MLIR LLVM dialect.
54MLIR_CAPI_EXPORTED MlirType mlirTypeFromLLVMIRTranslatorTranslateType(
55 MlirTypeFromLLVMIRTranslator translator, LLVMTypeRef llvmType);
56
57struct MlirTypeToLLVMIRTranslator {
58 void *ptr;
59};
60
61typedef struct MlirTypeToLLVMIRTranslator MlirTypeToLLVMIRTranslator;
62
63/// Create an LLVM::TypeToLLVMIRTranslator and transfer ownership to the
64/// caller.
65MLIR_CAPI_EXPORTED MlirTypeToLLVMIRTranslator
66mlirTypeToLLVMIRTranslatorCreate(LLVMContextRef ctx);
67
68/// Takes an LLVM::TypeToLLVMIRTranslator owned by the caller and destroys it.
69/// It is the responsibility of the user to only pass an
70/// LLVM::TypeToLLVMIRTranslator class.
71MLIR_CAPI_EXPORTED void
72mlirTypeToLLVMIRTranslatorDestroy(MlirTypeToLLVMIRTranslator translator);
73
74/// Translates the given MLIR LLVM dialect to the LLVM IR type.
75MLIR_CAPI_EXPORTED LLVMTypeRef mlirTypeToLLVMIRTranslatorTranslateType(
76 MlirTypeToLLVMIRTranslator translator, MlirType mlirType);
77
78#ifdef __cplusplus
79}
80#endif
81
82#endif // MLIR_C_TARGET_LLVMIR_H
83

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of mlir/include/mlir-c/Target/LLVMIR.h