1 //===- LLVM.cpp - C Interface for LLVM dialect ----------------------------===//
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
9 #include "mlir-c/Dialect/LLVM.h"
10 #include "mlir/CAPI/Registration.h"
11 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
12 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
13
14 using namespace mlir;
15 using namespace mlir::LLVM;
16
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLVM,llvm,LLVMDialect)17 MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLVM, llvm, LLVMDialect)
18
19 MlirType mlirLLVMPointerTypeGet(MlirType pointee, unsigned addressSpace) {
20 return wrap(LLVMPointerType::get(unwrap(pointee), addressSpace));
21 }
22
mlirLLVMVoidTypeGet(MlirContext ctx)23 MlirType mlirLLVMVoidTypeGet(MlirContext ctx) {
24 return wrap(LLVMVoidType::get(unwrap(ctx)));
25 }
26
mlirLLVMArrayTypeGet(MlirType elementType,unsigned numElements)27 MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements) {
28 return wrap(LLVMArrayType::get(unwrap(elementType), numElements));
29 }
30
mlirLLVMFunctionTypeGet(MlirType resultType,intptr_t nArgumentTypes,MlirType const * argumentTypes,bool isVarArg)31 MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,
32 MlirType const *argumentTypes, bool isVarArg) {
33 SmallVector<Type, 2> argumentStorage;
34 return wrap(LLVMFunctionType::get(
35 unwrap(resultType),
36 unwrapList(nArgumentTypes, argumentTypes, argumentStorage), isVarArg));
37 }
38
mlirLLVMStructTypeLiteralGet(MlirContext ctx,intptr_t nFieldTypes,MlirType const * fieldTypes,bool isPacked)39 MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes,
40 MlirType const *fieldTypes,
41 bool isPacked) {
42 SmallVector<Type, 2> fieldStorage;
43 return wrap(LLVMStructType::getLiteral(
44 unwrap(ctx), unwrapList(nFieldTypes, fieldTypes, fieldStorage),
45 isPacked));
46 }
47