| 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 |
| 23 | extern "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. |
| 33 | MLIR_CAPI_EXPORTED LLVMModuleRef |
| 34 | mlirTranslateModuleToLLVMIR(MlirOperation module, LLVMContextRef context); |
| 35 | |
| 36 | struct MlirTypeFromLLVMIRTranslator { |
| 37 | void *ptr; |
| 38 | }; |
| 39 | |
| 40 | typedef struct MlirTypeFromLLVMIRTranslator MlirTypeFromLLVMIRTranslator; |
| 41 | |
| 42 | /// Create an LLVM::TypeFromLLVMIRTranslator and transfer ownership to the |
| 43 | /// caller. |
| 44 | MLIR_CAPI_EXPORTED MlirTypeFromLLVMIRTranslator |
| 45 | mlirTypeFromLLVMIRTranslatorCreate(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. |
| 50 | MLIR_CAPI_EXPORTED void |
| 51 | mlirTypeFromLLVMIRTranslatorDestroy(MlirTypeFromLLVMIRTranslator translator); |
| 52 | |
| 53 | /// Translates the given LLVM IR type to the MLIR LLVM dialect. |
| 54 | MLIR_CAPI_EXPORTED MlirType mlirTypeFromLLVMIRTranslatorTranslateType( |
| 55 | MlirTypeFromLLVMIRTranslator translator, LLVMTypeRef llvmType); |
| 56 | |
| 57 | struct MlirTypeToLLVMIRTranslator { |
| 58 | void *ptr; |
| 59 | }; |
| 60 | |
| 61 | typedef struct MlirTypeToLLVMIRTranslator MlirTypeToLLVMIRTranslator; |
| 62 | |
| 63 | /// Create an LLVM::TypeToLLVMIRTranslator and transfer ownership to the |
| 64 | /// caller. |
| 65 | MLIR_CAPI_EXPORTED MlirTypeToLLVMIRTranslator |
| 66 | mlirTypeToLLVMIRTranslatorCreate(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. |
| 71 | MLIR_CAPI_EXPORTED void |
| 72 | mlirTypeToLLVMIRTranslatorDestroy(MlirTypeToLLVMIRTranslator translator); |
| 73 | |
| 74 | /// Translates the given MLIR LLVM dialect to the LLVM IR type. |
| 75 | MLIR_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 |
