brintos

brintos / llvm-project-archived public Read only

0
0
Text · 16.1 KiB · cc7f09f Raw
403 lines · c
1//===-- mlir-c/Dialect/LLVM.h - C API for LLVM --------------------*- C -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM4// Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef MLIR_C_DIALECT_LLVM_H11#define MLIR_C_DIALECT_LLVM_H12 13#include "mlir-c/IR.h"14#include "mlir-c/Support.h"15 16#ifdef __cplusplus17extern "C" {18#endif19 20MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(LLVM, llvm);21 22/// Creates an llvm.ptr type.23MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirContext ctx,24                                                   unsigned addressSpace);25 26MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMPointerTypeGetTypeID(void);27 28/// Returns `true` if the type is an LLVM dialect pointer type.29MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMPointerType(MlirType type);30 31/// Returns address space of llvm.ptr32MLIR_CAPI_EXPORTED unsigned33mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType);34 35/// Creates an llmv.void type.36MLIR_CAPI_EXPORTED MlirType mlirLLVMVoidTypeGet(MlirContext ctx);37 38/// Creates an llvm.array type.39MLIR_CAPI_EXPORTED MlirType mlirLLVMArrayTypeGet(MlirType elementType,40                                                 unsigned numElements);41 42/// Returns the element type of the llvm.array type.43MLIR_CAPI_EXPORTED MlirType mlirLLVMArrayTypeGetElementType(MlirType type);44 45/// Creates an llvm.func type.46MLIR_CAPI_EXPORTED MlirType47mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,48                        MlirType const *argumentTypes, bool isVarArg);49 50/// Returns the number of input types.51MLIR_CAPI_EXPORTED intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type);52 53/// Returns the pos-th input type.54MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetInput(MlirType type,55                                                         intptr_t pos);56 57/// Returns the return type of the function type.58MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type);59 60/// Returns `true` if the type is an LLVM dialect struct type.61MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMStructType(MlirType type);62 63MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMStructTypeGetTypeID(void);64 65/// Returns `true` if the type is a literal (unnamed) LLVM struct type.66MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsLiteral(MlirType type);67 68/// Returns the number of fields in the struct. Asserts if the struct is opaque69/// or not yet initialized.70MLIR_CAPI_EXPORTED intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type);71 72/// Returns the `positions`-th field of the struct. Asserts if the struct is73/// opaque, not yet initialized or if the position is out of range.74MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeGetElementType(MlirType type,75                                                             intptr_t position);76 77/// Returns `true` if the struct is packed.78MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsPacked(MlirType type);79 80/// Returns the identifier of the identified struct. Asserts that the struct is81/// identified, i.e., not literal.82MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type);83 84/// Returns `true` is the struct is explicitly opaque (will not have a body) or85/// uninitialized (will eventually have a body).86MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsOpaque(MlirType type);87 88/// Creates an LLVM literal (unnamed) struct type. This may assert if the fields89/// have types not compatible with the LLVM dialect. For a graceful failure, use90/// the checked version.91MLIR_CAPI_EXPORTED MlirType92mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes,93                             MlirType const *fieldTypes, bool isPacked);94 95/// Creates an LLVM literal (unnamed) struct type if possible. Emits a96/// diagnostic at the given location and returns null otherwise.97MLIR_CAPI_EXPORTED MlirType98mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc, intptr_t nFieldTypes,99                                    MlirType const *fieldTypes, bool isPacked);100 101/// Creates an LLVM identified struct type with no body. If a struct type with102/// this name already exists in the context, returns that type. Use103/// mlirLLVMStructTypeIdentifiedNewGet to create a fresh struct type,104/// potentially renaming it. The body should be set separatelty by calling105/// mlirLLVMStructTypeSetBody, if it isn't set already.106MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx,107                                                            MlirStringRef name);108 109/// Creates an LLVM identified struct type with no body and a name starting with110/// the given prefix. If a struct with the exact name as the given prefix111/// already exists, appends an unspecified suffix to the name so that the name112/// is unique in context.113MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeIdentifiedNewGet(114    MlirContext ctx, MlirStringRef name, intptr_t nFieldTypes,115    MlirType const *fieldTypes, bool isPacked);116 117MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx,118                                                        MlirStringRef name);119 120/// Sets the body of the identified struct if it hasn't been set yet. Returns121/// whether the operation was successful.122MLIR_CAPI_EXPORTED MlirLogicalResult123mlirLLVMStructTypeSetBody(MlirType structType, intptr_t nFieldTypes,124                          MlirType const *fieldTypes, bool isPacked);125 126enum MlirLLVMCConv {127  MlirLLVMCConvC = 0,128  MlirLLVMCConvFast = 8,129  MlirLLVMCConvCold = 9,130  MlirLLVMCConvGHC = 10,131  MlirLLVMCConvHiPE = 11,132  MlirLLVMCConvAnyReg = 13,133  MlirLLVMCConvPreserveMost = 14,134  MlirLLVMCConvPreserveAll = 15,135  MlirLLVMCConvSwift = 16,136  MlirLLVMCConvCXX_FAST_TLS = 17,137  MlirLLVMCConvTail = 18,138  MlirLLVMCConvCFGuard_Check = 19,139  MlirLLVMCConvSwiftTail = 20,140  MlirLLVMCConvX86_StdCall = 64,141  MlirLLVMCConvX86_FastCall = 65,142  MlirLLVMCConvARM_APCS = 66,143  MlirLLVMCConvARM_AAPCS = 67,144  MlirLLVMCConvARM_AAPCS_VFP = 68,145  MlirLLVMCConvMSP430_INTR = 69,146  MlirLLVMCConvX86_ThisCall = 70,147  MlirLLVMCConvPTX_Kernel = 71,148  MlirLLVMCConvPTX_Device = 72,149  MlirLLVMCConvSPIR_FUNC = 75,150  MlirLLVMCConvSPIR_KERNEL = 76,151  MlirLLVMCConvIntel_OCL_BI = 77,152  MlirLLVMCConvX86_64_SysV = 78,153  MlirLLVMCConvWin64 = 79,154  MlirLLVMCConvX86_VectorCall = 80,155  MlirLLVMCConvDUMMY_HHVM = 81,156  MlirLLVMCConvDUMMY_HHVM_C = 82,157  MlirLLVMCConvX86_INTR = 83,158  MlirLLVMCConvAVR_INTR = 84,159  MlirLLVMCConvAVR_BUILTIN = 86,160  MlirLLVMCConvAMDGPU_VS = 87,161  MlirLLVMCConvAMDGPU_GS = 88,162  MlirLLVMCConvAMDGPU_CS = 90,163  MlirLLVMCConvAMDGPU_KERNEL = 91,164  MlirLLVMCConvX86_RegCall = 92,165  MlirLLVMCConvAMDGPU_HS = 93,166  MlirLLVMCConvMSP430_BUILTIN = 94,167  MlirLLVMCConvAMDGPU_LS = 95,168  MlirLLVMCConvAMDGPU_ES = 96,169  MlirLLVMCConvAArch64_VectorCall = 97,170  MlirLLVMCConvAArch64_SVE_VectorCall = 98,171  MlirLLVMCConvWASM_EmscriptenInvoke = 99,172  MlirLLVMCConvAMDGPU_Gfx = 100,173  MlirLLVMCConvM68k_INTR = 101,174};175typedef enum MlirLLVMCConv MlirLLVMCConv;176 177/// Creates a LLVM CConv attribute.178MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx,179                                                      MlirLLVMCConv cconv);180 181enum MlirLLVMComdat {182  MlirLLVMComdatAny = 0,183  MlirLLVMComdatExactMatch = 1,184  MlirLLVMComdatLargest = 2,185  MlirLLVMComdatNoDeduplicate = 3,186  MlirLLVMComdatSameSize = 4,187};188typedef enum MlirLLVMComdat MlirLLVMComdat;189 190/// Creates a LLVM Comdat attribute.191MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx,192                                                       MlirLLVMComdat comdat);193 194enum MlirLLVMLinkage {195  MlirLLVMLinkageExternal = 0,196  MlirLLVMLinkageAvailableExternally = 1,197  MlirLLVMLinkageLinkonce = 2,198  MlirLLVMLinkageLinkonceODR = 3,199  MlirLLVMLinkageWeak = 4,200  MlirLLVMLinkageWeakODR = 5,201  MlirLLVMLinkageAppending = 6,202  MlirLLVMLinkageInternal = 7,203  MlirLLVMLinkagePrivate = 8,204  MlirLLVMLinkageExternWeak = 9,205  MlirLLVMLinkageCommon = 10,206};207typedef enum MlirLLVMLinkage MlirLLVMLinkage;208 209/// Creates a LLVM Linkage attribute.210MLIR_CAPI_EXPORTED MlirAttribute211mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage);212 213/// Creates a LLVM DINullType attribute.214MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx);215 216/// Creates a LLVM DIExpressionElem attribute.217MLIR_CAPI_EXPORTED MlirAttribute218mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, unsigned int opcode,219                                intptr_t nArguments, uint64_t const *arguments);220 221/// Creates a LLVM DIExpression attribute.222MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIExpressionAttrGet(223    MlirContext ctx, intptr_t nOperations, MlirAttribute const *operations);224 225enum MlirLLVMTypeEncoding {226  MlirLLVMTypeEncodingAddress = 0x1,227  MlirLLVMTypeEncodingBoolean = 0x2,228  MlirLLVMTypeEncodingComplexFloat = 0x31,229  MlirLLVMTypeEncodingFloatT = 0x4,230  MlirLLVMTypeEncodingSigned = 0x5,231  MlirLLVMTypeEncodingSignedChar = 0x6,232  MlirLLVMTypeEncodingUnsigned = 0x7,233  MlirLLVMTypeEncodingUnsignedChar = 0x08,234  MlirLLVMTypeEncodingImaginaryFloat = 0x09,235  MlirLLVMTypeEncodingPackedDecimal = 0x0a,236  MlirLLVMTypeEncodingNumericString = 0x0b,237  MlirLLVMTypeEncodingEdited = 0x0c,238  MlirLLVMTypeEncodingSignedFixed = 0x0d,239  MlirLLVMTypeEncodingUnsignedFixed = 0x0e,240  MlirLLVMTypeEncodingDecimalFloat = 0x0f,241  MlirLLVMTypeEncodingUTF = 0x10,242  MlirLLVMTypeEncodingUCS = 0x11,243  MlirLLVMTypeEncodingASCII = 0x12,244  MlirLLVMTypeEncodingLoUser = 0x80,245  MlirLLVMTypeEncodingHiUser = 0xff,246};247typedef enum MlirLLVMTypeEncoding MlirLLVMTypeEncoding;248 249/// Creates a LLVM DIBasicType attribute.250MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIBasicTypeAttrGet(251    MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,252    MlirLLVMTypeEncoding encoding);253 254/// Creates a self-referencing LLVM DICompositeType attribute.255MLIR_CAPI_EXPORTED MlirAttribute256mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId);257 258/// Creates a LLVM DICompositeType attribute.259MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(260    MlirContext ctx, MlirAttribute recId, bool isRecSelf, unsigned int tag,261    MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope,262    MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,263    uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,264    MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,265    MlirAttribute associated);266 267/// Creates a LLVM DIDerivedType attribute.  Note that `dwarfAddressSpace` is an268/// optional field, where `MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL` indicates null269/// and non-negative values indicate a value present.270MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIDerivedTypeAttrGet(271    MlirContext ctx, unsigned int tag, MlirAttribute name,272    MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits,273    uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute extraData);274 275MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIStringTypeAttrGet(276    MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,277    uint32_t alignInBits, MlirAttribute stringLength,278    MlirAttribute stringLengthExp, MlirAttribute stringLocationExp,279    MlirLLVMTypeEncoding encoding);280 281/// Constant to represent std::nullopt for dwarfAddressSpace to omit the field.282#define MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL -1283 284/// Gets the base type from a LLVM DIDerivedType attribute.285MLIR_CAPI_EXPORTED MlirAttribute286mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType);287 288/// Creates a LLVM DIFileAttr attribute.289MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx,290                                                       MlirAttribute name,291                                                       MlirAttribute directory);292 293enum MlirLLVMDIEmissionKind {294  MlirLLVMDIEmissionKindNone = 0,295  MlirLLVMDIEmissionKindFull = 1,296  MlirLLVMDIEmissionKindLineTablesOnly = 2,297  MlirLLVMDIEmissionKindDebugDirectivesOnly = 3,298};299typedef enum MlirLLVMDIEmissionKind MlirLLVMDIEmissionKind;300 301enum MlirLLVMDINameTableKind {302  MlirLLVMDINameTableKindDefault = 0,303  MlirLLVMDINameTableKindGNU = 1,304  MlirLLVMDINameTableKindNone = 2,305  MlirLLVMDINameTableKindApple = 3,306};307typedef enum MlirLLVMDINameTableKind MlirLLVMDINameTableKind;308 309/// Creates a LLVM DICompileUnit attribute.310MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompileUnitAttrGet(311    MlirContext ctx, MlirAttribute id, unsigned int sourceLanguage,312    MlirAttribute file, MlirAttribute producer, bool isOptimized,313    MlirLLVMDIEmissionKind emissionKind, MlirLLVMDINameTableKind nameTableKind,314    MlirAttribute splitDebugFilename);315 316/// Creates a LLVM DIFlags attribute.317MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx,318                                                        uint64_t value);319 320/// Creates a LLVM DILexicalBlock attribute.321MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockAttrGet(322    MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line,323    unsigned int column);324 325/// Creates a LLVM DILexicalBlockFile attribute.326MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(327    MlirContext ctx, MlirAttribute scope, MlirAttribute file,328    unsigned int discriminator);329 330/// Creates a LLVM DILocalVariableAttr attribute.331MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILocalVariableAttrGet(332    MlirContext ctx, MlirAttribute scope, MlirAttribute name,333    MlirAttribute diFile, unsigned int line, unsigned int arg,334    unsigned int alignInBits, MlirAttribute diType, int64_t flags);335 336/// Creates a self-referencing LLVM DISubprogramAttr attribute.337MLIR_CAPI_EXPORTED MlirAttribute338mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId);339 340/// Creates a LLVM DISubprogramAttr attribute.341MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubprogramAttrGet(342    MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,343    MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,344    MlirAttribute linkageName, MlirAttribute file, unsigned int line,345    unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,346    intptr_t nRetainedNodes, MlirAttribute const *retainedNodes,347    intptr_t nAnnotations, MlirAttribute const *annotations);348 349/// Creates a LLVM DIAnnotation attribute.350MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIAnnotationAttrGet(351    MlirContext ctx, MlirAttribute name, MlirAttribute value);352 353/// Gets the scope from this DISubprogramAttr.354MLIR_CAPI_EXPORTED MlirAttribute355mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram);356 357/// Gets the line from this DISubprogramAttr.358MLIR_CAPI_EXPORTED unsigned int359mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram);360 361/// Gets the scope line from this DISubprogram.362MLIR_CAPI_EXPORTED unsigned int363mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram);364 365/// Gets the compile unit from this DISubprogram.366MLIR_CAPI_EXPORTED MlirAttribute367mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram);368 369/// Gets the file from this DISubprogramAttr.370MLIR_CAPI_EXPORTED MlirAttribute371mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram);372 373/// Gets the type from this DISubprogramAttr.374MLIR_CAPI_EXPORTED MlirAttribute375mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram);376 377/// Creates a LLVM DISubroutineTypeAttr attribute.378MLIR_CAPI_EXPORTED MlirAttribute379mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, unsigned int callingConvention,380                                intptr_t nTypes, MlirAttribute const *types);381 382/// Creates a LLVM DIModuleAttr attribute.383MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIModuleAttrGet(384    MlirContext ctx, MlirAttribute file, MlirAttribute scope,385    MlirAttribute name, MlirAttribute configMacros, MlirAttribute includePath,386    MlirAttribute apinotes, unsigned int line, bool isDecl);387 388/// Creates a LLVM DIImportedEntityAttr attribute.389MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIImportedEntityAttrGet(390    MlirContext ctx, unsigned int tag, MlirAttribute scope,391    MlirAttribute entity, MlirAttribute file, unsigned int line,392    MlirAttribute name, intptr_t nElements, MlirAttribute const *elements);393 394/// Gets the scope of this DIModuleAttr.395MLIR_CAPI_EXPORTED MlirAttribute396mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule);397 398#ifdef __cplusplus399}400#endif401 402#endif // MLIR_C_DIALECT_LLVM_H403