mlir.dialects.ext

Attributes

Classes

Operation

Base class of Python-defined operations.

Type

Base class of Python-defined types.

Dialect

Base class of a Python-defined dialect.

Functions

register_operation(→ Callable[[type], type])

Module Contents

mlir.dialects.ext.Operand
mlir.dialects.ext.Result
mlir.dialects.ext.Region
mlir.dialects.ext.register_dialect
mlir.dialects.ext.register_operation(dialect_cls: type) Callable[[type], type]
class mlir.dialects.ext.Operation(**kwargs)

Bases: ir

Base class of Python-defined operations.

The following example shows two ways to define operations via this class:

class MyOp(MyDialect.Operation, name=..):
  ...

class MyOp(Operation, dialect=MyDialect, name=..):
  ...
classmethod __init_subclass__(*, name: str | None = None, traits: list[type] | None = None, dialect: type | None = None, **kwargs)

This method is to perform all magic to make a Operation subclass works like a dataclass, like:

  • generate the method to emit IRDL operations,

  • generate __init__ method as an operation builder function,

  • generate operand, result and attribute accessors

static _variadicity_to_segment(variadicity: mlir.dialects.irdl.Variadicity) int
static _generate_segments(operands_or_results: List[OperandDef | ResultDef]) List[int] | None
static _generate_init_signature(fields: List[FieldDef], can_infer_types: bool) inspect.Signature
classmethod _generate_init_method(fields: List[FieldDef]) None
classmethod _generate_class_attributes(dialect_name: str, op_name: str, fields: List[FieldDef]) None
classmethod _generate_attr_properties(attrs: List[AttributeDef]) None
classmethod _generate_region_properties(regions: List[RegionDef]) None
classmethod _generate_operand_properties(operands: List[OperandDef]) None
classmethod _generate_result_properties(results: List[ResultDef]) None
classmethod _attach_traits() None
classmethod _emit_operation() None
class mlir.dialects.ext.Type(cast_from_type: Type)

Bases: ir

Base class of Python-defined types.

The following example shows two ways to define types via this class:

class MyType(MyDialect.Type, name=..):
  ...

class MyType(Type, dialect=MyDialect, name=..):
  ...
classmethod __init_subclass__(*, name: str | None = None, dialect: type | None = None, **kwargs)
classmethod get(*args, context=None)

Create a dynamic type.

classmethod _emit_type() None
class mlir.dialects.ext.Dialect(descriptor: object)

Bases: ir

Base class of a Python-defined dialect.

It can be used like the following example:

class MyInt(Dialect, name="myint"):
    pass

i32 = IntegerType[32]

class ConstantOp(MyInt.Operation, name="constant"):
    value: IntegerAttr
    cst: Result[i32]

class AddOp(MyInt.Operation, name="add"):
    lhs: Operand[i32]
    rhs: Operand[i32]
    res: Result[i32]
classmethod __init_subclass__(name: str, **kwargs)
classmethod _emit_dialect() None
classmethod _emit_module() ir
classmethod load(register=True, reload=False) None