mlir.extras.meta

Classes

Functions

get_op_result_or_op_results(...)

op_region_builder(op, op_region[, terminator])

region_op(op_constructor[, terminator])

Decorator to define an MLIR Op specified as a python function.

Module Contents

mlir.extras.meta.get_op_result_or_op_results(op: mlir._mlir_libs._mlir.ir.OpView | mlir._mlir_libs._mlir.ir.Operation) mlir._mlir_libs._mlir.ir.Operation | mlir._mlir_libs._mlir.ir.OpResult | Sequence[mlir._mlir_libs._mlir.ir.OpResult]
class mlir.extras.meta.Type(cast_from_type: Type)
property _CAPIPtr: object

Gets a capsule wrapping the MlirType.

static _CAPICreate(arg: object, /) Type

Creates a Type from a capsule wrapping MlirType.

static parse(asm: str, context: Context | None = None) Type

Parses the assembly form of a type.

Returns a Type object or raises an MLIRError if the type cannot be parsed.

See also: https://mlir.llvm.org/docs/LangRef/#type-system

property context: Context

Context that owns the Type.

__eq__(arg: Type, /) bool
__eq__(other: object | None) bool

Compares type with non-type object (always returns False).

__hash__() int

Returns the hash value of the Type.

dump() None

Dumps a debug representation of the object to stderr.

__str__() str

Returns the assembly form of the Type.

__repr__() str

Returns a string representation of the Type.

maybe_downcast() Type

Downcasts the Type to a more specific Type if possible.

property typeid: TypeID

Returns the TypeID of the Type, or raises ValueError if Type has no TypeID.

class mlir.extras.meta.InsertionPoint(block: Block)
class mlir.extras.meta.InsertionPoint(beforeOperation: _OperationBase)
__enter__(/) InsertionPoint

Enters the insertion point as a context manager.

__exit__(exc_type: object | None, exc_value: object | None, traceback: object | None) None

Exits the insertion point context manager.

current: InsertionPoint = Ellipsis

Gets the InsertionPoint bound to the current thread or raises ValueError if none has been set.

static at_block_begin(block: Block) InsertionPoint

Creates an insertion point at the beginning of a block.

Parameters:

block – The block at whose beginning operations should be inserted.

Returns:

An InsertionPoint at the block’s beginning.

static at_block_terminator(block: Block) InsertionPoint

Creates an insertion point before a block’s terminator.

Parameters:

block – The block whose terminator to insert before.

Returns:

An InsertionPoint before the terminator.

Raises:

ValueError – If the block has no terminator.

static after(operation: _OperationBase) InsertionPoint

Creates an insertion point immediately after an operation.

Parameters:

operation – The operation after which to insert.

Returns:

An InsertionPoint after the operation.

insert(operation: _OperationBase) None

Inserts an operation at this insertion point.

Parameters:

operation – The operation to insert.

property block: Block

Returns the block that this InsertionPoint points to.

property ref_operation: Operation | None

The reference operation before which new operations are inserted, or None if the insertion point is at the end of the block.

mlir.extras.meta.op_region_builder(op, op_region, terminator=None)
mlir.extras.meta.region_op(op_constructor, terminator=None)

Decorator to define an MLIR Op specified as a python function.

Requires that an mlir.ir.InsertionPoint and mlir.ir.Location are active for the current thread (i.e. established in a with block).

Supports “naked” usage i.e., no parens if no args need to be passed to the Op constructor.

When applied as a decorator to a Python function, an entry block will be constructed for the Op with types as specified as type hints on the args of the function. The block arguments will be passed positionally to the Python function.

If a terminator is specified then the return from the decorated function will be passed to the terminator as the last statement in the entry block. Note, the API for the terminator is a (possibly empty) list; terminator accepting single values should be wrapped in a lambda args: term(args[0])

The identifier (name) of the function will become:

  1. A single value result if the Op returns a single value;

  2. An OpResultList (as a list) if the Op returns multiple values;

  3. The Operation if the Op returns no results.

See examples in tensor.py and transform.extras.