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/// Destroy the dynamic op trait.
76mlirDynamicOpTraitDestroy(MlirDynamicOpTrait dynamicOpTrait);
77
78typedef struct {
79 /// Optional constructor for the user data.
80 /// Set to nullptr to disable it.
81 void (*construct)(void *userData);
82 /// Optional destructor for the user data.
83 /// Set to nullptr to disable it.
84 void (*destruct)(void *userData);
85 /// The callback function to verify the operation.
86 MlirLogicalResult (*verifyTrait)(MlirOperation op, void *userData);
87 /// The callback function to verify the operation with access to regions.
88 MlirLogicalResult (*verifyRegionTrait)(MlirOperation op, void *userData);
90
91/// Create a custom dynamic op trait with the given type ID and callbacks.
93 MlirTypeID typeID, MlirDynamicOpTraitCallbacks callbacks, void *userData);
94
95/// Check if the given dialect is an extensible dialect.
97
98/// Look up a registered type definition by type name in the given dialect.
99/// Note that the dialect must be an extensible dialect.
100MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition
102 MlirStringRef typeName);
103
104/// Check if the given type is a dynamic type.
106
107/// Get a dynamic type by instantiating the given type definition with the
108/// provided attributes.
110 MlirDynamicTypeDefinition typeDef, MlirAttribute *attrs, intptr_t numAttrs);
111
112/// Get the number of parameters in the given dynamic type.
114
115/// Get the parameter at the given index in the provided dynamic type.
116MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicTypeGetParam(MlirType type,
117 intptr_t index);
118
119/// Get the type definition of the given dynamic type.
120MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition
121mlirDynamicTypeGetTypeDef(MlirType type);
122
123/// Get the type ID of a dynamic type definition.
124MLIR_CAPI_EXPORTED MlirTypeID
125mlirDynamicTypeDefinitionGetTypeID(MlirDynamicTypeDefinition typeDef);
126
127/// Get the name of the given dynamic type definition.
129mlirDynamicTypeDefinitionGetName(MlirDynamicTypeDefinition typeDef);
130
131/// Get the dialect that the given dynamic type definition belongs to.
132MLIR_CAPI_EXPORTED MlirDialect
133mlirDynamicTypeDefinitionGetDialect(MlirDynamicTypeDefinition typeDef);
134
135/// Look up a registered attribute definition by attribute name in the given
136/// dialect. Note that the dialect must be an extensible dialect.
137MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition
139 MlirStringRef attrName);
140
141/// Check if the given attribute is a dynamic attribute.
142MLIR_CAPI_EXPORTED bool mlirAttributeIsADynamicAttr(MlirAttribute attr);
143
144/// Get a dynamic attribute by instantiating the given attribute definition with
145/// the provided attributes.
147 MlirDynamicAttrDefinition attrDef, MlirAttribute *attrs, intptr_t numAttrs);
148
149/// Get the number of parameters in the given dynamic attribute.
151
152/// Get the parameter at the given index in the provided dynamic attribute.
153MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicAttrGetParam(MlirAttribute attr,
154 intptr_t index);
155
156/// Get the attribute definition of the given dynamic attribute.
157MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition
158mlirDynamicAttrGetAttrDef(MlirAttribute attr);
159
160/// Get the type ID of a dynamic attribute definition.
161MLIR_CAPI_EXPORTED MlirTypeID
162mlirDynamicAttrDefinitionGetTypeID(MlirDynamicAttrDefinition attrDef);
163
164/// Get the name of the given dynamic attribute definition.
166mlirDynamicAttrDefinitionGetName(MlirDynamicAttrDefinition attrDef);
167
168/// Get the dialect that the given dynamic attribute definition belongs to.
169MLIR_CAPI_EXPORTED MlirDialect
170mlirDynamicAttrDefinitionGetDialect(MlirDynamicAttrDefinition attrDef);
171
172#ifdef __cplusplus
173}
174#endif
175
176#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 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 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