mlir.extras.meta

Functions

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.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.