mlir.dialects.ext

Attributes

Classes

Operation

Base class of Python-defined operation.

Dialect

Base class of a Python-defined dialect.

Module Contents

mlir.dialects.ext.Operand
mlir.dialects.ext.Result
mlir.dialects.ext.Region
class mlir.dialects.ext.Operation(operation: Operation)
class mlir.dialects.ext.Operation(name: str, opRegionSpec: tuple[int, bool], operandSegmentSpecObj: object | None = None, resultSegmentSpecObj: object | None = None, results: list | None = None, operands: list | None = None, attributes: dict | None = None, successors: collections.abc.Sequence[Block] | None = None, regions: int | None = None, loc: Location | None = None, ip: object | None = None)

Bases: ir

Base class of Python-defined operation.

NOTE: Usually you don’t need to use it directly. Use Dialect and .Operation of Dialect subclasses instead.

classmethod __init_subclass__(*, name: str = 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]
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 _emit_operation() 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() None