MLIR 23.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 dynamic op trait that indicates regions have no terminator.
54MLIR_CAPI_EXPORTED MlirDynamicOpTrait
56
57/// Destroy the dynamic op trait.
59mlirDynamicOpTraitDestroy(MlirDynamicOpTrait dynamicOpTrait);
60
61typedef struct {
62 /// Optional constructor for the user data.
63 /// Set to nullptr to disable it.
64 void (*construct)(void *userData);
65 /// Optional destructor for the user data.
66 /// Set to nullptr to disable it.
67 void (*destruct)(void *userData);
68 /// The callback function to verify the operation.
69 MlirLogicalResult (*verifyTrait)(MlirOperation op, void *userData);
70 /// The callback function to verify the operation with access to regions.
71 MlirLogicalResult (*verifyRegionTrait)(MlirOperation op, void *userData);
73
74/// Create a custom dynamic op trait with the given type ID and callbacks.
76 MlirTypeID typeID, MlirDynamicOpTraitCallbacks callbacks, void *userData);
77
78/// Check if the given dialect is an extensible dialect.
80
81/// Look up a registered type definition by type name in the given dialect.
82/// Note that the dialect must be an extensible dialect.
83MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition
85 MlirStringRef typeName);
86
87/// Check if the given type is a dynamic type.
89
90/// Get a dynamic type by instantiating the given type definition with the
91/// provided attributes.
93 MlirDynamicTypeDefinition typeDef, MlirAttribute *attrs, intptr_t numAttrs);
94
95/// Get the number of parameters in the given dynamic type.
97
98/// Get the parameter at the given index in the provided dynamic type.
99MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicTypeGetParam(MlirType type,
100 intptr_t index);
101
102/// Get the type definition of the given dynamic type.
103MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition
104mlirDynamicTypeGetTypeDef(MlirType type);
105
106/// Get the type ID of a dynamic type definition.
107MLIR_CAPI_EXPORTED MlirTypeID
108mlirDynamicTypeDefinitionGetTypeID(MlirDynamicTypeDefinition typeDef);
109
110/// Get the name of the given dynamic type definition.
112mlirDynamicTypeDefinitionGetName(MlirDynamicTypeDefinition typeDef);
113
114/// Get the dialect that the given dynamic type definition belongs to.
115MLIR_CAPI_EXPORTED MlirDialect
116mlirDynamicTypeDefinitionGetDialect(MlirDynamicTypeDefinition typeDef);
117
118/// Look up a registered attribute definition by attribute name in the given
119/// dialect. Note that the dialect must be an extensible dialect.
120MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition
122 MlirStringRef attrName);
123
124/// Check if the given attribute is a dynamic attribute.
125MLIR_CAPI_EXPORTED bool mlirAttributeIsADynamicAttr(MlirAttribute attr);
126
127/// Get a dynamic attribute by instantiating the given attribute definition with
128/// the provided attributes.
130 MlirDynamicAttrDefinition attrDef, MlirAttribute *attrs, intptr_t numAttrs);
131
132/// Get the number of parameters in the given dynamic attribute.
134
135/// Get the parameter at the given index in the provided dynamic attribute.
136MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicAttrGetParam(MlirAttribute attr,
137 intptr_t index);
138
139/// Get the attribute definition of the given dynamic attribute.
140MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition
141mlirDynamicAttrGetAttrDef(MlirAttribute attr);
142
143/// Get the type ID of a dynamic attribute definition.
144MLIR_CAPI_EXPORTED MlirTypeID
145mlirDynamicAttrDefinitionGetTypeID(MlirDynamicAttrDefinition attrDef);
146
147/// Get the name of the given dynamic attribute definition.
149mlirDynamicAttrDefinitionGetName(MlirDynamicAttrDefinition attrDef);
150
151/// Get the dialect that the given dynamic attribute definition belongs to.
152MLIR_CAPI_EXPORTED MlirDialect
153mlirDynamicAttrDefinitionGetDialect(MlirDynamicAttrDefinition attrDef);
154
155#ifdef __cplusplus
156}
157#endif
158
159#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.
#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 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 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 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