17 #include "llvm-c/Core.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/SmallVectorExtras.h"
31 return isa<LLVM::LLVMPointerType>(
unwrap(type));
35 return cast<LLVM::LLVMPointerType>(
unwrap(pointerType)).getAddressSpace();
47 MlirType
const *argumentTypes,
bool isVarArg) {
51 unwrapList(nArgumentTypes, argumentTypes, argumentStorage), isVarArg));
55 return isa<LLVM::LLVMStructType>(
unwrap(type));
59 return !cast<LLVM::LLVMStructType>(
unwrap(type)).isIdentified();
63 return cast<LLVM::LLVMStructType>(
unwrap(type)).getBody().size();
67 return wrap(cast<LLVM::LLVMStructType>(
unwrap(type)).getBody()[position]);
71 return cast<LLVM::LLVMStructType>(
unwrap(type)).isPacked();
75 return wrap(cast<LLVM::LLVMStructType>(
unwrap(type)).getName());
79 return cast<LLVM::LLVMStructType>(
unwrap(type)).isOpaque();
83 MlirType
const *fieldTypes,
93 MlirType
const *fieldTypes,
98 unwrapList(nFieldTypes, fieldTypes, fieldStorage), isPacked));
110 intptr_t nFieldTypes,
111 MlirType
const *fieldTypes,
120 intptr_t nFieldTypes,
121 MlirType
const *fieldTypes,
125 cast<LLVM::LLVMStructType>(
unwrap(structType))
126 .setBody(
unwrapList(nFieldTypes, fieldTypes, fields), isPacked));
132 uint64_t
const *arguments) {
138 MlirAttribute
const *operations) {
140 attrStorage.reserve(nOperations);
145 unwrapList(nOperations, operations, attrStorage),
146 [](
Attribute a) {
return cast<DIExpressionElemAttr>(a); })));
159 unwrap(ctx), tag, cast<StringAttr>(
unwrap(name)), sizeInBits, encoding));
163 MlirContext ctx,
unsigned int tag, MlirAttribute recId, MlirAttribute name,
164 MlirAttribute file, uint32_t line, MlirAttribute scope,
165 MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
166 uint64_t alignInBits, intptr_t nElements, MlirAttribute
const *elements,
167 MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
168 MlirAttribute associated) {
170 elementsStorage.reserve(nElements);
174 cast<StringAttr>(
unwrap(name)), cast<DIFileAttr>(
unwrap(file)), line,
175 cast<DIScopeAttr>(
unwrap(scope)), cast<DITypeAttr>(
unwrap(baseType)),
176 DIFlags(flags), sizeInBits, alignInBits,
177 llvm::map_to_vector(
unwrapList(nElements, elements, elementsStorage),
178 [](
Attribute a) {
return cast<DINodeAttr>(a); }),
179 cast<DIExpressionAttr>(
unwrap(dataLocation)),
180 cast<DIExpressionAttr>(
unwrap(rank)),
181 cast<DIExpressionAttr>(
unwrap(allocated)),
182 cast<DIExpressionAttr>(
unwrap(associated))));
186 MlirContext ctx,
unsigned int tag, MlirAttribute name,
187 MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits,
188 uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute extraData) {
189 std::optional<unsigned> addressSpace = std::nullopt;
190 if (dwarfAddressSpace >= 0)
191 addressSpace = (unsigned)dwarfAddressSpace;
194 cast<DITypeAttr>(
unwrap(baseType)), sizeInBits, alignInBits, offsetInBits,
195 addressSpace, cast<DINodeAttr>(
unwrap(extraData))));
199 MlirContext ctx,
unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
200 uint32_t alignInBits, MlirAttribute stringLength,
201 MlirAttribute stringLengthExp, MlirAttribute stringLocationExp,
204 unwrap(ctx), tag, cast<StringAttr>(
unwrap(name)), sizeInBits, alignInBits,
205 cast<DIVariableAttr>(
unwrap(stringLength)),
206 cast<DIExpressionAttr>(
unwrap(stringLengthExp)),
207 cast<DIExpressionAttr>(
unwrap(stringLocationExp)), encoding));
212 return wrap(cast<DIDerivedTypeAttr>(
unwrap(diDerivedType)).getBaseType());
228 MlirAttribute directory) {
230 cast<StringAttr>(
unwrap(directory))));
235 unsigned int sourceLanguage, MlirAttribute file,
236 MlirAttribute producer,
bool isOptimized,
240 unwrap(ctx), cast<DistinctAttr>(
unwrap(
id)), sourceLanguage,
241 cast<DIFileAttr>(
unwrap(file)), cast<StringAttr>(
unwrap(producer)),
242 isOptimized, DIEmissionKind(emissionKind),
243 DINameTableKind(nameTableKind)));
254 unsigned int column) {
257 cast<DIFileAttr>(
unwrap(file)), line, column));
263 unsigned int discriminator) {
266 cast<DIFileAttr>(
unwrap(file)), discriminator));
270 MlirContext ctx, MlirAttribute scope, MlirAttribute name,
271 MlirAttribute diFile,
unsigned int line,
unsigned int arg,
272 unsigned int alignInBits, MlirAttribute diType, int64_t flags) {
275 cast<StringAttr>(
unwrap(name)), cast<DIFileAttr>(
unwrap(diFile)), line,
276 arg, alignInBits, cast<DITypeAttr>(
unwrap(diType)), DIFlags(flags)));
280 unsigned int callingConvention,
282 MlirAttribute
const *types) {
284 attrStorage.reserve(nTypes);
287 unwrap(ctx), callingConvention,
288 llvm::map_to_vector(
unwrapList(nTypes, types, attrStorage),
289 [](
Attribute a) {
return cast<DITypeAttr>(a); })));
293 MlirContext ctx, MlirAttribute
id, MlirAttribute compileUnit,
294 MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName,
295 MlirAttribute file,
unsigned int line,
unsigned int scopeLine,
296 uint64_t subprogramFlags, MlirAttribute type) {
299 cast<DICompileUnitAttr>(
unwrap(compileUnit)),
300 cast<DIScopeAttr>(
unwrap(scope)), cast<StringAttr>(
unwrap(name)),
301 cast<StringAttr>(
unwrap(linkageName)), cast<DIFileAttr>(
unwrap(file)),
302 line, scopeLine, DISubprogramFlags(subprogramFlags),
303 cast<DISubroutineTypeAttr>(
unwrap(type))));
307 return wrap(cast<DISubprogramAttr>(
unwrap(diSubprogram)).getScope());
311 return cast<DISubprogramAttr>(
unwrap(diSubprogram)).getLine();
315 return cast<DISubprogramAttr>(
unwrap(diSubprogram)).getScopeLine();
320 return wrap(cast<DISubprogramAttr>(
unwrap(diSubprogram)).getCompileUnit());
324 return wrap(cast<DISubprogramAttr>(
unwrap(diSubprogram)).getFile());
332 MlirAttribute scope, MlirAttribute name,
333 MlirAttribute configMacros,
334 MlirAttribute includePath,
335 MlirAttribute apinotes,
unsigned int line,
339 cast<DIScopeAttr>(
unwrap(scope)), cast<StringAttr>(
unwrap(name)),
340 cast<StringAttr>(
unwrap(configMacros)),
341 cast<StringAttr>(
unwrap(includePath)), cast<StringAttr>(
unwrap(apinotes)),
346 return wrap(cast<DIModuleAttr>(
unwrap(diModule)).getScope());
bool mlirLLVMStructTypeIsLiteral(MlirType type)
Returns true if the type is a literal (unnamed) LLVM struct type.
MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage)
Creates a LLVM Linkage attribute.
MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram)
Gets the file from this DISubprogramAttr.
MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes, MlirType const *argumentTypes, bool isVarArg)
Creates an llvm.func type.
MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule)
Gets the scope of this DIModuleAttr.
intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type)
Returns the number of fields in the struct.
MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx)
Creates a LLVM DINullType attribute.
MlirLogicalResult mlirLLVMStructTypeSetBody(MlirType structType, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Sets the body of the identified struct if it hasn't been set yet.
MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name, MlirAttribute directory)
Creates a LLVM DIFileAttr attribute.
MlirAttribute mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute id, unsigned int sourceLanguage, MlirAttribute file, MlirAttribute producer, bool isOptimized, MlirLLVMDIEmissionKind emissionKind, MlirLLVMDINameTableKind nameTableKind)
Creates a LLVM DICompileUnit attribute.
bool mlirTypeIsALLVMStructType(MlirType type)
Returns true if the type is an LLVM dialect struct type.
MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type)
Returns the identifier of the identified struct.
MlirAttribute mlirLLVMDIStringTypeAttrGet(MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits, uint32_t alignInBits, MlirAttribute stringLength, MlirAttribute stringLengthExp, MlirAttribute stringLocationExp, MlirLLVMTypeEncoding encoding)
MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram)
Gets the scope from this DISubprogramAttr.
MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line, unsigned int column)
Creates a LLVM DILexicalBlock attribute.
MlirAttribute mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, unsigned int opcode, intptr_t nArguments, uint64_t const *arguments)
Creates a LLVM DIExpressionElem attribute.
MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits, MlirLLVMTypeEncoding encoding)
Creates a LLVM DIBasicType attribute.
MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat)
Creates a LLVM Comdat attribute.
MlirAttribute mlirLLVMDISubprogramAttrGet(MlirContext ctx, MlirAttribute id, MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName, MlirAttribute file, unsigned int line, unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type)
Creates a LLVM DISubprogramAttr attribute.
MlirType mlirLLVMVoidTypeGet(MlirContext ctx)
Creates an llmv.void type.
MlirType mlirLLVMStructTypeIdentifiedNewGet(MlirContext ctx, MlirStringRef name, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM identified struct type with no body and a name starting with the given prefix.
MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position)
Returns the positions-th field of the struct.
MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx, MlirStringRef name)
MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements)
Creates an llvm.array type.
MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram)
Gets the type from this DISubprogramAttr.
MlirAttribute mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram)
Gets the compile unit from this DISubprogram.
MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file, MlirAttribute scope, MlirAttribute name, MlirAttribute configMacros, MlirAttribute includePath, MlirAttribute apinotes, unsigned int line, bool isDecl)
Creates a LLVM DIModuleAttr attribute.
MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv)
Creates a LLVM CConv attribute.
MlirType mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM literal (unnamed) struct type if possible.
MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int discriminator)
Creates a LLVM DILexicalBlockFile attribute.
MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations, MlirAttribute const *operations)
Creates a LLVM DIExpression attribute.
bool mlirLLVMStructTypeIsPacked(MlirType type)
Returns true if the struct is packed.
unsigned mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType)
Returns address space of llvm.ptr.
MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value)
Creates a LLVM DIFlags attribute.
MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx, MlirStringRef name)
Creates an LLVM identified struct type with no body.
MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, unsigned int callingConvention, intptr_t nTypes, MlirAttribute const *types)
Creates a LLVM DISubroutineTypeAttr attribute.
MlirAttribute mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType)
Gets the base type from a LLVM DIDerivedType attribute.
bool mlirLLVMStructTypeIsOpaque(MlirType type)
Returns true is the struct is explicitly opaque (will not have a body) or uninitialized (will eventua...
MlirAttribute mlirLLVMDICompositeTypeAttrGet(MlirContext ctx, unsigned int tag, MlirAttribute recId, MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope, MlirAttribute baseType, int64_t flags, uint64_t sizeInBits, uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements, MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated, MlirAttribute associated)
Creates a LLVM DICompositeType attribute.
bool mlirTypeIsALLVMPointerType(MlirType type)
Returns true if the type is an LLVM dialect pointer type.
unsigned int mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram)
Gets the line from this DISubprogramAttr.
MlirAttribute mlirLLVMDILocalVariableAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute name, MlirAttribute diFile, unsigned int line, unsigned int arg, unsigned int alignInBits, MlirAttribute diType, int64_t flags)
Creates a LLVM DILocalVariableAttr attribute.
MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace)
Creates an llvm.ptr type.
unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram)
Gets the scope line from this DISubprogram.
MlirAttribute mlirLLVMDIDerivedTypeAttrGet(MlirContext ctx, unsigned int tag, MlirAttribute name, MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits, uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute extraData)
Creates a LLVM DIDerivedType attribute.
MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM literal (unnamed) struct type.
#define MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Name, Namespace, ClassName)
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Attributes are known-constant values of operations.
static LLVMStructType getLiteralChecked(function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, ArrayRef< Type > types, bool isPacked=false)
static LLVMStructType getLiteral(MLIRContext *context, ArrayRef< Type > types, bool isPacked=false)
Gets or creates a literal struct with the given body in the provided context.
static LLVMStructType getNewIdentified(MLIRContext *context, StringRef name, ArrayRef< Type > elements, bool isPacked=false)
Gets a new identified struct with the given body.
static LLVMStructType getIdentified(MLIRContext *context, StringRef name)
Gets or creates an identified struct with the given name in the provided context.
static LLVMStructType getOpaque(StringRef name, MLIRContext *context)
Gets or creates an intentionally-opaque identified struct.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Include the generated interface declarations.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
A logical result value, essentially a boolean with named states.
A pointer to a sized fragment of a string, not necessarily null-terminated.