mlir.dialects.ext

Attributes

Exceptions

DialectAlreadyLoadedError

Raised when a dialect is loaded more than once in the current context.

Classes

Operation

Base class of Python-defined operations.

Type

Base class of Python-defined types.

Attribute

Base class of Python-defined attributes.

Dialect

Base class of a Python-defined dialect.

NoMemoryEffect

Operation that has no effect on memory.

AlwaysSpeculatable

Operation that is always speculatable.

RecursivelySpeculatable

Operation that is speculatable if all operations in all its regions are speculatable.

Pure

Always speculatable operation that does not touch memory.

Functions

result(→ Result)

A field specifier for Result definitions.

infer_result(→ Result)

A field specifier for Result definitions with type inference enabled.

operand(→ Operand)

A field specifier for Operand definitions.

attribute(→ ir)

A field specifier for attribute definitions.

Module Contents

mlir.dialects.ext.Operand
mlir.dialects.ext.Result
mlir.dialects.ext.Region
exception mlir.dialects.ext.DialectAlreadyLoadedError

Bases: RuntimeError

Raised when a dialect is loaded more than once in the current context.

mlir.dialects.ext.result(*, default_factory: Callable[[], Any] | None = None, kw_only: bool = False) Result

A field specifier for Result definitions.

mlir.dialects.ext.infer_result() Result

A field specifier for Result definitions with type inference enabled.

mlir.dialects.ext.operand(*, kw_only: bool = False) Operand

A field specifier for Operand definitions.

mlir.dialects.ext.attribute(*, default_factory: Callable[[], Any] | None = None, kw_only: bool = False) ir

A field specifier for attribute definitions.

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]) 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.Attribute(cast_from_attr: Attribute)

Bases: ir

Base class of Python-defined attributes.

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

class MyAttr(MyDialect.Attribute, name=..):
  ...

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

Create a dynamic attribute.

classmethod _emit_attr() 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] = infer_result()

class AddOp(MyInt.Operation, name="add"):
    lhs: Operand[i32]
    rhs: Operand[i32]
    res: Result[i32] = infer_result()
classmethod __init_subclass__(name: str, **kwargs)
classmethod _emit_dialect() None
classmethod _emit_module() ir
classmethod load() None
class mlir.dialects.ext.NoMemoryEffect(object: MemoryEffectsOpInterface.__init__.object, context: Context | None = None)

Bases: ir

Operation that has no effect on memory.

static get_effects(op)

Returns the memory effects of the operation.

class mlir.dialects.ext.AlwaysSpeculatable(object: ConditionallySpeculatable.__init__.object, context: Context | None = None)

Bases: ir

Operation that is always speculatable.

static get_speculatability(op)
class mlir.dialects.ext.RecursivelySpeculatable(object: ConditionallySpeculatable.__init__.object, context: Context | None = None)

Bases: ir

Operation that is speculatable if all operations in all its regions are speculatable.

static get_speculatability(op)
class mlir.dialects.ext.Pure

Always speculatable operation that does not touch memory.

static attach(op_name)