135d4593eSAdam Paszke //===- LLVM.cpp - C Interface for LLVM dialect ----------------------------===//
235d4593eSAdam Paszke //
335d4593eSAdam Paszke // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
435d4593eSAdam Paszke // See https://llvm.org/LICENSE.txt for license information.
535d4593eSAdam Paszke // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
635d4593eSAdam Paszke //
735d4593eSAdam Paszke //===----------------------------------------------------------------------===//
835d4593eSAdam Paszke
935d4593eSAdam Paszke #include "mlir-c/Dialect/LLVM.h"
1035d4593eSAdam Paszke #include "mlir/CAPI/Registration.h"
1135d4593eSAdam Paszke #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1235d4593eSAdam Paszke #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
1335d4593eSAdam Paszke
1435d4593eSAdam Paszke using namespace mlir;
1535d4593eSAdam Paszke using namespace mlir::LLVM;
1635d4593eSAdam Paszke
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLVM,llvm,LLVMDialect)1735d4593eSAdam Paszke MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLVM, llvm, LLVMDialect)
1835d4593eSAdam Paszke
1935d4593eSAdam Paszke MlirType mlirLLVMPointerTypeGet(MlirType pointee, unsigned addressSpace) {
2035d4593eSAdam Paszke return wrap(LLVMPointerType::get(unwrap(pointee), addressSpace));
2135d4593eSAdam Paszke }
22*8a2720d8SAdam Paszke
mlirLLVMVoidTypeGet(MlirContext ctx)23*8a2720d8SAdam Paszke MlirType mlirLLVMVoidTypeGet(MlirContext ctx) {
24*8a2720d8SAdam Paszke return wrap(LLVMVoidType::get(unwrap(ctx)));
25*8a2720d8SAdam Paszke }
26*8a2720d8SAdam Paszke
mlirLLVMArrayTypeGet(MlirType elementType,unsigned numElements)27*8a2720d8SAdam Paszke MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements) {
28*8a2720d8SAdam Paszke return wrap(LLVMArrayType::get(unwrap(elementType), numElements));
29*8a2720d8SAdam Paszke }
30*8a2720d8SAdam Paszke
mlirLLVMFunctionTypeGet(MlirType resultType,intptr_t nArgumentTypes,MlirType const * argumentTypes,bool isVarArg)31*8a2720d8SAdam Paszke MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,
32*8a2720d8SAdam Paszke MlirType const *argumentTypes, bool isVarArg) {
33*8a2720d8SAdam Paszke SmallVector<Type, 2> argumentStorage;
34*8a2720d8SAdam Paszke return wrap(LLVMFunctionType::get(
35*8a2720d8SAdam Paszke unwrap(resultType),
36*8a2720d8SAdam Paszke unwrapList(nArgumentTypes, argumentTypes, argumentStorage), isVarArg));
37*8a2720d8SAdam Paszke }
38*8a2720d8SAdam Paszke
mlirLLVMStructTypeLiteralGet(MlirContext ctx,intptr_t nFieldTypes,MlirType const * fieldTypes,bool isPacked)39*8a2720d8SAdam Paszke MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes,
40*8a2720d8SAdam Paszke MlirType const *fieldTypes,
41*8a2720d8SAdam Paszke bool isPacked) {
42*8a2720d8SAdam Paszke SmallVector<Type, 2> fieldStorage;
43*8a2720d8SAdam Paszke return wrap(LLVMStructType::getLiteral(
44*8a2720d8SAdam Paszke unwrap(ctx), unwrapList(nFieldTypes, fieldTypes, fieldStorage),
45*8a2720d8SAdam Paszke isPacked));
46*8a2720d8SAdam Paszke }
47