IR Construction and Traversal

class mlir.ir.Attribute
property context

Context that owns the Attribute

dump(self: _mlir.ir.Attribute) → None

Dumps a debug representation of the object to stderr.

get_named(self: _mlir.ir.Attribute, arg0: str) → mlir::python::PyNamedAttribute

Binds a name to the attribute

property type
class mlir.ir.BF16Type
static get(arg0: _mlir.ir.Context) → _mlir.ir.BF16Type

Create a bf16 type.

class mlir.ir.Block
property arguments

Returns a list of block arguments.

property operations

Returns a forward-optimized sequence of operations.

class mlir.ir.BlockArgument
property arg_number
property owner
set_type(self: _mlir.ir.BlockArgument, arg0: _mlir.ir.Type) → None
class mlir.ir.BlockArgumentList
class mlir.ir.BlockIterator
class mlir.ir.BlockList
append(self: _mlir.ir.BlockList, *args) → _mlir.ir.Block

Appends a new block, with argument types as positional args.

Returns

The created block.

class mlir.ir.BoolAttr
static get(context: _mlir.ir.Context, value: bool) → _mlir.ir.BoolAttr

Gets an uniqued bool attribute

property value

Returns the value of the bool attribute

class mlir.ir.ComplexType
property element_type

Returns element type.

static get(arg0: _mlir.ir.Type) → _mlir.ir.ComplexType

Create a complex type

class mlir.ir.Context
property allow_unregistered_dialects
create_module(self: _mlir.ir.Context, loc: mlir::python::PyLocation) → object

Creates an empty module

create_operation(self: _mlir.ir.Context, name: str, location: mlir::python::PyLocation, operands: Optional[List[mlir::python::PyValue]] = None, results: Optional[List[mlir::python::PyType]] = None, attributes: Optional[dict] = None, successors: Optional[List[mlir::python::PyBlock]] = None, regions: int = 0) → object

Creates a new operation.

Parameters
  • name – Operation name (e.g. “dialect.operation”).

  • location – A Location object.

  • results – Sequence of Type representing op result types.

  • attributes – Dict of str:Attribute.

  • successors – List of Block for the operation’s successors.

  • regions – Number of regions to create.

Returns

A new “detached” Operation object. Detached operations can be added to blocks, which causes them to become “attached.”

property d

Alias for ‘dialect’

property dialects

Gets a container for accessing dialects by name

get_dialect_descriptor(self: _mlir.ir.Context, arg0: str) → mlir::python::PyDialectDescriptor

Gets or loads a dialect by name, returning its descriptor object

get_file_location(self: _mlir.ir.Context, filename: str, line: int, col: int) → mlir::python::PyLocation

Gets a Location representing a file, line and column

get_unknown_location(self: _mlir.ir.Context) → mlir::python::PyLocation

Gets a Location representing an unknown location

parse_attr(self: _mlir.ir.Context, arg0: str) → mlir::python::PyAttribute
parse_module(self: _mlir.ir.Context, arg0: str) → object

Parses a module’s assembly format from a string.

Returns a new MlirModule or raises a ValueError if the parsing fails.

See also: https://mlir.llvm.org/docs/LangRef/

parse_type(self: _mlir.ir.Context, arg0: str) → mlir::python::PyType

Parses the assembly form of a type.

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

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

class mlir.ir.DenseElementsAttr
static get(context: _mlir.ir.Context, array: buffer, signless: bool = True) → _mlir.ir.DenseElementsAttr

Gets from a buffer or ndarray

static get_splat(shaped_type: mlir::python::PyType, element_attr: _mlir.ir.Attribute) → _mlir.ir.DenseElementsAttr

Gets a DenseElementsAttr where all values are the same

property is_splat
class mlir.ir.Dialect
property descriptor
class mlir.ir.DialectDescriptor
property namespace
class mlir.ir.Dialects
class mlir.ir.F16Type
static get(arg0: _mlir.ir.Context) → _mlir.ir.F16Type

Create a f16 type.

class mlir.ir.F32Type
static get(arg0: _mlir.ir.Context) → _mlir.ir.F32Type

Create a f32 type.

class mlir.ir.F64Type
static get(arg0: _mlir.ir.Context) → _mlir.ir.F64Type

Create a f64 type.

class mlir.ir.FloatAttr
static get(type: mlir::python::PyType, value: float, loc: _mlir.ir.Location) → _mlir.ir.FloatAttr

Gets an uniqued float point attribute associated to a type

static get_f32(context: _mlir.ir.Context, value: float) → _mlir.ir.FloatAttr

Gets an uniqued float point attribute associated to a f32 type

static get_f64(context: _mlir.ir.Context, value: float) → _mlir.ir.FloatAttr

Gets an uniqued float point attribute associated to a f64 type

property value

Returns the value of the float point attribute

class mlir.ir.FunctionType
static get(context: _mlir.ir.Context, inputs: List[_mlir.ir.Type], results: List[_mlir.ir.Type]) → _mlir.ir.FunctionType

Gets a FunctionType from a list of input and result types

property inputs

Returns the list of input types in the FunctionType.

property results

Returns the list of result types in the FunctionType.

class mlir.ir.IndexType
static get(arg0: _mlir.ir.Context) → _mlir.ir.IndexType

Create a index type.

class mlir.ir.IntegerAttr
static get(type: mlir::python::PyType, value: int) → _mlir.ir.IntegerAttr

Gets an uniqued integer attribute associated to a type

property value

Returns the value of the integer attribute

class mlir.ir.IntegerType
static get_signed(arg0: _mlir.ir.Context, arg1: int) → _mlir.ir.IntegerType

Create a signed integer type

static get_signless(arg0: _mlir.ir.Context, arg1: int) → _mlir.ir.IntegerType

Create a signless integer type

static get_unsigned(arg0: _mlir.ir.Context, arg1: int) → _mlir.ir.IntegerType

Create an unsigned integer type

property is_signed

Returns whether this is a signed integer

property is_signless

Returns whether this is a signless integer

property is_unsigned

Returns whether this is an unsigned integer

property width

Returns the width of the integer type

class mlir.ir.Location
property context

Context that owns the Location

class mlir.ir.MemRefType
static get_contiguous_memref(arg0: _mlir.ir.Type, arg1: List[int], arg2: int, arg3: _mlir.ir.Location) → _mlir.ir.MemRefType

Create a memref type

property memory_space

Returns the memory space of the given MemRef type.

property num_affine_maps

Returns the number of affine layout maps in the given MemRef type.

class mlir.ir.Module
property context

Context that created the Module

dump(self: _mlir.ir.Module) → None

Dumps a debug representation of the object to stderr.

property operation

Accesses the module as an operation

class mlir.ir.NamedAttribute
property attr

The underlying generic attribute of the NamedAttribute binding

property name

The name of the NamedAttribute binding

class mlir.ir.NoneType
static get(arg0: _mlir.ir.Context) → _mlir.ir.NoneType

Create a none type.

class mlir.ir.OpOperandList
class mlir.ir.OpResult
property owner
property result_number
class mlir.ir.OpResultList
class mlir.ir.OpView
property operation
class mlir.ir.Operation
property context

Context that owns the Operation

get_asm(self: _mlir.ir.Operation, binary: bool = False, large_elements_limit: Optional[int] = None, enable_debug_info: bool = False, pretty_debug_info: bool = False, print_generic_op_form: bool = False, use_local_scope: bool = False) → object

Gets the assembly form of the operation with all options available.

Parameters
  • binary – Whether to return a bytes (True) or str (False) object. Defaults to False.

  • others ... (..) – See the print() method for common keyword arguments for configuring the printout.

Returns

Either a bytes or str object, depending on the setting of the ‘binary’ argument.

property operands
print(self: _mlir.ir.Operation, file: object = None, binary: bool = False, large_elements_limit: Optional[int] = None, enable_debug_info: bool = False, pretty_debug_info: bool = False, print_generic_op_form: bool = False, use_local_scope: bool = False) → None

Prints the assembly form of the operation to a file like object.

Parameters
  • file – The file like object to write to. Defaults to sys.stdout.

  • binary – Whether to write bytes (True) or str (False). Defaults to False.

  • large_elements_limit – Whether to elide elements attributes above this number of elements. Defaults to None (no limit).

  • enable_debug_info – Whether to print debug/location information. Defaults to False.

  • pretty_debug_info – Whether to format debug information for easier reading by a human (warning: the result is unparseable).

  • print_generic_op_form – Whether to print the generic assembly forms of all ops. Defaults to False.

  • use_local_Scope – Whether to print in a way that is more optimized for multi-threaded access but may not be consistent with how the overall module prints.

property regions
property results

Returns the list of Operation results.

class mlir.ir.OperationIterator
class mlir.ir.OperationList
insert(self: _mlir.ir.OperationList, index: int, operation: _mlir.ir.Operation) → None

Inserts an operation at an indexed position

class mlir.ir.RankedTensorType
static get(arg0: List[int], arg1: _mlir.ir.Type, arg2: _mlir.ir.Location) → _mlir.ir.RankedTensorType

Create a ranked tensor type

class mlir.ir.Region
property blocks

Returns a forward-optimized sequence of blocks.

class mlir.ir.RegionIterator
class mlir.ir.ReqionSequence
class mlir.ir.ShapedType
property element_type

Returns the element type of the shaped type.

get_dim_size(self: _mlir.ir.ShapedType, arg0: int) → int

Returns the dim-th dimension of the given ranked shaped type.

property has_rank

Returns whether the given shaped type is ranked.

property has_static_shape

Returns whether the given shaped type has a static shape.

is_dynamic_dim(self: _mlir.ir.ShapedType, arg0: int) → bool

Returns whether the dim-th dimension of the given shaped type is dynamic.

static is_dynamic_size(arg0: int) → bool

Returns whether the given dimension size indicates a dynamic dimension.

is_dynamic_stride_or_offset(self: _mlir.ir.ShapedType, arg0: int) → bool

Returns whether the given value is used as a placeholder for dynamic strides and offsets in shaped types.

property rank

Returns the rank of the given ranked shaped type.

class mlir.ir.StringAttr
static get(arg0: _mlir.ir.Context, arg1: str) → _mlir.ir.StringAttr

Gets a uniqued string attribute

static get_typed(arg0: mlir::python::PyType, arg1: str) → _mlir.ir.StringAttr

Gets a uniqued string attribute associated to a type

property value

Returns the value of the string attribute

class mlir.ir.TupleType
static get_tuple(arg0: _mlir.ir.Context, arg1: list) → _mlir.ir.TupleType

Create a tuple type

get_type(self: _mlir.ir.TupleType, arg0: int) → _mlir.ir.Type

Returns the pos-th type in the tuple type.

property num_types

Returns the number of types contained in a tuple.

class mlir.ir.Type
property context

Context that owns the Type

dump(self: _mlir.ir.Type) → None

Dumps a debug representation of the object to stderr.

class mlir.ir.UnrankedMemRefType
static get(arg0: _mlir.ir.Type, arg1: int, arg2: _mlir.ir.Location) → _mlir.ir.UnrankedMemRefType

Create a unranked memref type

property memory_space

Returns the memory space of the given Unranked MemRef type.

class mlir.ir.UnrankedTensorType
static get(arg0: _mlir.ir.Type, arg1: _mlir.ir.Location) → _mlir.ir.UnrankedTensorType

Create a unranked tensor type

class mlir.ir.Value
property context

Context in which the value lives.

dump(self: _mlir.ir.Value) → None

Dumps a debug representation of the object to stderr.

property type
class mlir.ir.VectorType
static get(arg0: List[int], arg1: _mlir.ir.Type, arg2: _mlir.ir.Location) → _mlir.ir.VectorType

Create a vector type