MLIR 24.0.0git
ExtensibleDialect.h
Go to the documentation of this file.
1//===-- mlir-c/ExtensibleDialect.h - Extensible dialect APIs -----*- 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 provides APIs for extensible dialects.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_C_EXTENSIBLEDIALECT_H
15#define MLIR_C_EXTENSIBLEDIALECT_H
16
17#include "mlir-c/IR.h"
18#include "mlir-c/Support.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24//===----------------------------------------------------------------------===//
25/// Opaque type declarations (see mlir-c/IR.h for more details).
26//===----------------------------------------------------------------------===//
27
28#define DEFINE_C_API_STRUCT(name, storage) \
29 struct name { \
30 storage *ptr; \
31 }; \
32 typedef struct name name
33
34DEFINE_C_API_STRUCT(MlirDynamicOpTrait, void);
35DEFINE_C_API_STRUCT(MlirDynamicTypeDefinition, void);
36DEFINE_C_API_STRUCT(MlirDynamicAttrDefinition, void);
37
38#undef DEFINE_C_API_STRUCT
39
40/// Attach a dynamic op trait to the given operation name.
41/// Note that the operation name must be modeled by dynamic dialect and must be
42/// registered.
43/// The ownership of the trait will be transferred to the operation name
44/// after this call.
46mlirDynamicOpTraitAttach(MlirDynamicOpTrait dynamicOpTrait,
47 MlirStringRef opName, MlirContext context);
48
49/// Get the dynamic op trait that indicates the operation is a terminator.
50MLIR_CAPI_EXPORTED MlirDynamicOpTrait
52
53/// Get the type ID of the dynamic op trait that indicates the operation is a
54/// terminator.
56
57/// Get the dynamic op trait that indicates regions are isolated from above.
58MLIR_CAPI_EXPORTED MlirDynamicOpTrait
60
61/// Get the type ID of the dynamic op trait that indicates regions are isolated
62/// from above.
63MLIR_CAPI_EXPORTED MlirTypeID
65
66/// Get the dynamic op trait that indicates regions have no terminator.
67MLIR_CAPI_EXPORTED MlirDynamicOpTrait
69
70/// Get the type ID of the dynamic op trait that indicates regions have no
71/// terminator.
73
74/// Get the dynamic op trait that indicates memory effects of an operation
75/// includes the effects of operations nested within its regions.
76MLIR_CAPI_EXPORTED MlirDynamicOpTrait
78
79/// Get the type ID of the dynamic op trait that indicates memory effects of an
80/// operation includes the effects of operations nested within its regions.
81MLIR_CAPI_EXPORTED MlirTypeID
83
84/// Destroy the dynamic op trait.
86mlirDynamicOpTraitDestroy(MlirDynamicOpTrait dynamicOpTrait);
87
88typedef struct {
89 /// Optional constructor for the user data.
90 /// Set to nullptr to disable it.
91 void (*construct)(void *userData);
92 /// Optional destructor for the user data.
93 /// Set to nullptr to disable it.
94 void (*destruct)(void *userData);
95 /// The callback function to verify the operation.
96 MlirLogicalResult (*verifyTrait)(MlirOperation op, void *userData);
97 /// The callback function to verify the operation with access to regions.
98 MlirLogicalResult (*verifyRegionTrait)(MlirOperation op, void *userData);
100
101/// Create a custom dynamic op trait with the given type ID and callbacks.
103 MlirTypeID typeID, MlirDynamicOpTraitCallbacks callbacks, void *userData);
104
105/// Check if the given dialect is an extensible dialect.
107
108/// Look up a registered type definition by type name in the given dialect.
109/// Note that the dialect must be an extensible dialect.
110MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition
112 MlirStringRef typeName);
113
114/// Check if the given type is a dynamic type.
116
117/// Get a dynamic type by instantiating the given type definition with the
118/// provided attributes.
120 MlirDynamicTypeDefinition typeDef, MlirAttribute *attrs, intptr_t numAttrs);
121
122/// Get the number of parameters in the given dynamic type.
124
125/// Get the parameter at the given index in the provided dynamic type.
126MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicTypeGetParam(MlirType type,
127 intptr_t index);
128
129/// Get the type definition of the given dynamic type.
130MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition
131mlirDynamicTypeGetTypeDef(MlirType type);
132
133/// Get the type ID of a dynamic type definition.
134MLIR_CAPI_EXPORTED MlirTypeID
135mlirDynamicTypeDefinitionGetTypeID(MlirDynamicTypeDefinition typeDef);
136
137/// Get the name of the given dynamic type definition.
139mlirDynamicTypeDefinitionGetName(MlirDynamicTypeDefinition typeDef);
140
141/// Get the dialect that the given dynamic type definition belongs to.
142MLIR_CAPI_EXPORTED MlirDialect
143mlirDynamicTypeDefinitionGetDialect(MlirDynamicTypeDefinition typeDef);
144
145/// Look up a registered attribute definition by attribute name in the given
146/// dialect. Note that the dialect must be an extensible dialect.
147MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition
149 MlirStringRef attrName);
150
151/// Check if the given attribute is a dynamic attribute.
152MLIR_CAPI_EXPORTED bool mlirAttributeIsADynamicAttr(MlirAttribute attr);
153
154/// Get a dynamic attribute by instantiating the given attribute definition with
155/// the provided attributes.
157 MlirDynamicAttrDefinition attrDef, MlirAttribute *attrs, intptr_t numAttrs);
158
159/// Get the number of parameters in the given dynamic attribute.
161
162/// Get the parameter at the given index in the provided dynamic attribute.
163MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicAttrGetParam(MlirAttribute attr,
164 intptr_t index);
165
166/// Get the attribute definition of the given dynamic attribute.
167MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition
168mlirDynamicAttrGetAttrDef(MlirAttribute attr);
169
170/// Get the type ID of a dynamic attribute definition.
171MLIR_CAPI_EXPORTED MlirTypeID
172mlirDynamicAttrDefinitionGetTypeID(MlirDynamicAttrDefinition attrDef);
173
174/// Get the name of the given dynamic attribute definition.
176mlirDynamicAttrDefinitionGetName(MlirDynamicAttrDefinition attrDef);
177
178/// Get the dialect that the given dynamic attribute definition belongs to.
179MLIR_CAPI_EXPORTED MlirDialect
180mlirDynamicAttrDefinitionGetDialect(MlirDynamicAttrDefinition attrDef);
181
182#ifdef __cplusplus
183}
184#endif
185
186#endif // MLIR_C_EXTENSIBLEDIALECT_H
MLIR_CAPI_EXPORTED bool mlirAttributeIsADynamicAttr(MlirAttribute attr)
Check if the given attribute is a dynamic attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicAttrGetParam(MlirAttribute attr, intptr_t index)
Get the parameter at the given index in the provided dynamic attribute.
MLIR_CAPI_EXPORTED void mlirDynamicOpTraitDestroy(MlirDynamicOpTrait dynamicOpTrait)
Destroy the dynamic op trait.
MLIR_CAPI_EXPORTED MlirDialect mlirDynamicAttrDefinitionGetDialect(MlirDynamicAttrDefinition attrDef)
Get the dialect that the given dynamic attribute definition belongs to.
MLIR_CAPI_EXPORTED bool mlirTypeIsADynamicType(MlirType type)
Check if the given type is a dynamic type.
MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition mlirDynamicTypeGetTypeDef(MlirType type)
Get the type definition of the given dynamic type.
MLIR_CAPI_EXPORTED MlirDynamicOpTrait mlirDynamicOpTraitIsTerminatorCreate(void)
Get the dynamic op trait that indicates the operation is a terminator.
MLIR_CAPI_EXPORTED MlirDynamicOpTrait mlirDynamicOpTraitIsIsolatedFromAboveCreate(void)
Get the dynamic op trait that indicates regions are isolated from above.
#define DEFINE_C_API_STRUCT(name, storage)
Opaque type declarations (see mlir-c/IR.h for more details).
MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicAttrGet(MlirDynamicAttrDefinition attrDef, MlirAttribute *attrs, intptr_t numAttrs)
Get a dynamic attribute by instantiating the given attribute definition with the provided attributes.
MLIR_CAPI_EXPORTED bool mlirDialectIsAExtensibleDialect(MlirDialect dialect)
Check if the given dialect is an extensible dialect.
MLIR_CAPI_EXPORTED MlirTypeID mlirDynamicOpTraitRecursiveMemoryEffectsGetTypeID(void)
Get the type ID of the dynamic op trait that indicates memory effects of an operation includes the ef...
MLIR_CAPI_EXPORTED MlirTypeID mlirDynamicOpTraitIsIsolatedFromAboveGetTypeID(void)
Get the type ID of the dynamic op trait that indicates regions are isolated from above.
MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition mlirDynamicAttrGetAttrDef(MlirAttribute attr)
Get the attribute definition of the given dynamic attribute.
MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition mlirExtensibleDialectLookupAttrDefinition(MlirDialect dialect, MlirStringRef attrName)
Look up a registered attribute definition by attribute name in the given dialect.
MLIR_CAPI_EXPORTED MlirDialect mlirDynamicTypeDefinitionGetDialect(MlirDynamicTypeDefinition typeDef)
Get the dialect that the given dynamic type definition belongs to.
MLIR_CAPI_EXPORTED intptr_t mlirDynamicTypeGetNumParams(MlirType type)
Get the number of parameters in the given dynamic type.
MLIR_CAPI_EXPORTED MlirTypeID mlirDynamicAttrDefinitionGetTypeID(MlirDynamicAttrDefinition attrDef)
Get the type ID of a dynamic attribute definition.
MLIR_CAPI_EXPORTED MlirType mlirDynamicTypeGet(MlirDynamicTypeDefinition typeDef, MlirAttribute *attrs, intptr_t numAttrs)
Get a dynamic type by instantiating the given type definition with the provided attributes.
MLIR_CAPI_EXPORTED MlirTypeID mlirDynamicOpTraitIsTerminatorGetTypeID(void)
Get the type ID of the dynamic op trait that indicates the operation is a terminator.
MLIR_CAPI_EXPORTED MlirDynamicOpTrait mlirDynamicOpTraitRecursiveMemoryEffectsCreate(void)
Get the dynamic op trait that indicates memory effects of an operation includes the effects of operat...
MLIR_CAPI_EXPORTED MlirDynamicOpTrait mlirDynamicOpTraitCreate(MlirTypeID typeID, MlirDynamicOpTraitCallbacks callbacks, void *userData)
Create a custom dynamic op trait with the given type ID and callbacks.
MLIR_CAPI_EXPORTED bool mlirDynamicOpTraitAttach(MlirDynamicOpTrait dynamicOpTrait, MlirStringRef opName, MlirContext context)
Attach a dynamic op trait to the given operation name.
MLIR_CAPI_EXPORTED MlirStringRef mlirDynamicAttrDefinitionGetName(MlirDynamicAttrDefinition attrDef)
Get the name of the given dynamic attribute definition.
MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition mlirExtensibleDialectLookupTypeDefinition(MlirDialect dialect, MlirStringRef typeName)
Look up a registered type definition by type name in the given dialect.
MLIR_CAPI_EXPORTED MlirTypeID mlirDynamicTypeDefinitionGetTypeID(MlirDynamicTypeDefinition typeDef)
Get the type ID of a dynamic type definition.
MLIR_CAPI_EXPORTED intptr_t mlirDynamicAttrGetNumParams(MlirAttribute attr)
Get the number of parameters in the given dynamic attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicTypeGetParam(MlirType type, intptr_t index)
Get the parameter at the given index in the provided dynamic type.
MLIR_CAPI_EXPORTED MlirStringRef mlirDynamicTypeDefinitionGetName(MlirDynamicTypeDefinition typeDef)
Get the name of the given dynamic type definition.
MLIR_CAPI_EXPORTED MlirTypeID mlirDynamicOpTraitNoTerminatorGetTypeID(void)
Get the type ID of the dynamic op trait that indicates regions have no terminator.
MLIR_CAPI_EXPORTED MlirDynamicOpTrait mlirDynamicOpTraitNoTerminatorCreate(void)
Get the dynamic op trait that indicates regions have no terminator.
struct MlirLogicalResult MlirLogicalResult
Definition Support.h:124
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
MlirLogicalResult(* verifyTrait)(MlirOperation op, void *userData)
The callback function to verify the operation.
void(* construct)(void *userData)
Optional constructor for the user data.
void(* destruct)(void *userData)
Optional destructor for the user data.
MlirLogicalResult(* verifyRegionTrait)(MlirOperation op, void *userData)
The callback function to verify the operation with access to regions.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78