23 std::optional<RegisteredOperationName> opNameFound =
25 assert(opNameFound &&
"operation name must be registered in the context");
33 static_cast<RegisteredOperationNameWithImpl &
>(*opNameFound).getImpl();
35 std::unique_ptr<DynamicOpTrait> trait(
unwrap(dynamicOpTrait));
66 delete unwrap(dynamicOpTrait);
75 : typeID(typeID), callbacks(callbacks), userData(userData) {
76 if (callbacks.construct)
77 callbacks.construct(userData);
80 if (callbacks.destruct)
81 callbacks.destruct(userData);
85 return unwrap(callbacks.verifyTrait(
wrap(op), userData));
88 return unwrap(callbacks.verifyRegionTrait(
wrap(op), userData));
108 return llvm::isa<mlir::ExtensibleDialect>(
unwrap(dialect));
111MlirDynamicTypeDefinition
114 return wrap(llvm::cast<mlir::ExtensibleDialect>(
unwrap(dialect))
115 ->lookupTypeDefinition(
unwrap(typeName)));
119 return llvm::isa<mlir::DynamicType>(
unwrap(type));
127 MlirAttribute *attrs,
intptr_t numAttrs) {
129 attributes.reserve(numAttrs);
130 for (
intptr_t i = 0; i < numAttrs; ++i)
131 attributes.push_back(
unwrap(attrs[i]));
137 return llvm::cast<mlir::DynamicType>(
unwrap(type)).getParams().size();
141 return wrap(llvm::cast<mlir::DynamicType>(
unwrap(type)).getParams()[
index]);
145 return wrap(llvm::cast<mlir::DynamicType>(
unwrap(type)).getTypeDef());
163MlirDynamicAttrDefinition
166 return wrap(llvm::cast<mlir::ExtensibleDialect>(
unwrap(dialect))
167 ->lookupAttrDefinition(
unwrap(attrName)));
171 return llvm::isa<mlir::DynamicAttr>(
unwrap(attr));
179 MlirAttribute *attrs,
intptr_t numAttrs) {
181 attributes.reserve(numAttrs);
182 for (
intptr_t i = 0; i < numAttrs; ++i)
183 attributes.push_back(
unwrap(attrs[i]));
189 return llvm::cast<mlir::DynamicAttr>(
unwrap(attr)).getParams().size();
193 return wrap(llvm::cast<mlir::DynamicAttr>(
unwrap(attr)).getParams()[
index]);
197 return wrap(llvm::cast<mlir::DynamicAttr>(
unwrap(attr)).getAttrDef());
bool mlirTypeIsADynamicType(MlirType type)
Check if the given type is a dynamic type.
MlirDialect mlirDynamicTypeDefinitionGetDialect(MlirDynamicTypeDefinition typeDef)
Get the dialect that the given dynamic type definition belongs to.
MlirDynamicTypeDefinition mlirDynamicTypeGetTypeDef(MlirType type)
Get the type definition of the given dynamic type.
MlirType mlirDynamicTypeGet(MlirDynamicTypeDefinition typeDef, MlirAttribute *attrs, intptr_t numAttrs)
Get a dynamic type by instantiating the given type definition with the provided attributes.
bool mlirDialectIsAExtensibleDialect(MlirDialect dialect)
Check if the given dialect is an extensible dialect.
MlirDynamicOpTrait mlirDynamicOpTraitCreate(MlirTypeID typeID, MlirDynamicOpTraitCallbacks callbacks, void *userData)
Create a custom dynamic op trait with the given type ID and callbacks.
MlirDynamicAttrDefinition mlirDynamicAttrGetAttrDef(MlirAttribute attr)
Get the attribute definition of the given dynamic attribute.
MlirDynamicTypeDefinition mlirExtensibleDialectLookupTypeDefinition(MlirDialect dialect, MlirStringRef typeName)
Look up a registered type definition by type name in the given dialect.
MlirDynamicOpTrait mlirDynamicOpTraitIsTerminatorCreate()
Get the dynamic op trait that indicates the operation is a terminator.
MlirStringRef mlirDynamicAttrDefinitionGetName(MlirDynamicAttrDefinition attrDef)
Get the name of the given dynamic attribute definition.
MlirDynamicOpTrait mlirDynamicOpTraitIsIsolatedFromAboveCreate()
Get the dynamic op trait that indicates regions are isolated from above.
void mlirDynamicOpTraitDestroy(MlirDynamicOpTrait dynamicOpTrait)
Destroy the dynamic op trait.
MlirTypeID mlirDynamicOpTraitIsTerminatorGetTypeID()
Get the type ID of the dynamic op trait that indicates the operation is a terminator.
MlirAttribute mlirDynamicAttrGet(MlirDynamicAttrDefinition attrDef, MlirAttribute *attrs, intptr_t numAttrs)
Get a dynamic attribute by instantiating the given attribute definition with the provided attributes.
MlirTypeID mlirDynamicAttrDefinitionGetTypeID(MlirDynamicAttrDefinition attrDef)
Get the type ID of a dynamic attribute definition.
MlirDynamicAttrDefinition mlirExtensibleDialectLookupAttrDefinition(MlirDialect dialect, MlirStringRef attrName)
Look up a registered attribute definition by attribute name in the given dialect.
MlirDialect mlirDynamicAttrDefinitionGetDialect(MlirDynamicAttrDefinition attrDef)
Get the dialect that the given dynamic attribute definition belongs to.
MlirTypeID mlirDynamicTypeDefinitionGetTypeID(MlirDynamicTypeDefinition typeDef)
Get the type ID of a dynamic type definition.
intptr_t mlirDynamicTypeGetNumParams(MlirType type)
Get the number of parameters in the given dynamic type.
MlirTypeID mlirDynamicTypeGetTypeID()
MlirStringRef mlirDynamicTypeDefinitionGetName(MlirDynamicTypeDefinition typeDef)
Get the name of the given dynamic type definition.
MlirAttribute mlirDynamicAttrGetParam(MlirAttribute attr, intptr_t index)
Get the parameter at the given index in the provided dynamic attribute.
MlirAttribute mlirDynamicTypeGetParam(MlirType type, intptr_t index)
Get the parameter at the given index in the provided dynamic type.
intptr_t mlirDynamicAttrGetNumParams(MlirAttribute attr)
Get the number of parameters in the given dynamic attribute.
MlirTypeID mlirDynamicOpTraitIsIsolatedFromAboveGetTypeID()
Get the type ID of the dynamic op trait that indicates regions are isolated from above.
bool mlirAttributeIsADynamicAttr(MlirAttribute attr)
Check if the given attribute is a dynamic attribute.
MlirTypeID mlirDynamicAttrGetTypeID(void)
MlirDynamicOpTrait mlirDynamicOpTraitNoTerminatorCreate()
Get the dynamic op trait that indicates regions have no terminator.
MlirTypeID mlirDynamicOpTraitNoTerminatorGetTypeID()
Get the type ID of the dynamic op trait that indicates regions have no terminator.
#define DEFINE_C_API_PTR_METHODS(name, cpptype)
The definition of a dynamic attribute.
static DynamicAttr get(DynamicAttrDefinition *attrDef, ArrayRef< Attribute > params={})
Return an instance of a dynamic attribute given a dynamic attribute definition and attribute paramete...
The definition of a dynamic op.
static TypeID getStaticTypeID()
Base class of traits for dynamic-defined operations.
The definition of a dynamic type.
static DynamicType get(DynamicTypeDefinition *typeDef, ArrayRef< Attribute > params={})
Return an instance of a dynamic type given a dynamic type definition and type parameters.
~ExternalDynamicOpTrait()
ExternalDynamicOpTrait(TypeID typeID, MlirDynamicOpTraitCallbacks callbacks, void *userData)
TypeID getTypeID() const override
Returns the TypeID of the trait.
LogicalResult verifyRegionTrait(Operation *op) const override
LogicalResult verifyTrait(Operation *op) const override
Operation is the basic unit of execution within MLIR.
This is a "type erased" representation of a registered operation.
static std::optional< RegisteredOperationName > lookup(StringRef name, MLIRContext *ctx)
Lookup the registered operation information for the given operation.
This class provides an efficient unique identifier for a specific C++ type.
static TypeID getTypeID()
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MLIR_CAPI_EXPORTED bool mlirDynamicOpTraitAttach(MlirDynamicOpTrait dynamicOpTrait, MlirStringRef opName, MlirContext context)
Attach a dynamic op trait to the given operation name.
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.