‘py’ Interfaces#

Op Interfaces#

CopyObjectInterface (CopyObjectInterface)

This interface signifies that an operation does a copy operation of a builtin. The resulting object may have a new type which must be a subtype of the builtin type the operation operates on.

By default, this interface expects the type object for the result to be an ODS operand called $type_object. The operand that is being copied should be marked via Copied.

Note: If you are applying this interface you likely also want: ObjectFromTypeObjectInterface, MemAlloc on the result, RefinedObjectFromTypeObject and OnlyReadsValueInterface. You may also want AlwaysBound.

Methods:

getTypeObject
::mlir::Value getTypeObject();
getCopiedOperand
::mlir::OpOperand&getCopiedOperand();

AddableExceptionHandlingInterface (AddableExceptionHandlingInterface)

Interface implemented by any operation for which an exception handling version exists. The exception handling version must be identical to the normal version but have the successors and extra operands required by ExceptionHandlingInterface added.

See CreateExceptionHandlingVariant in ExceptionHandlingInterface.td for a macro to easily create such operations.

Methods:

cloneWithExceptionHandling
::mlir::Operation*cloneWithExceptionHandling(::mlir::OpBuilder&builder, ::mlir::Block*happy_path, ::mlir::Block*exception_path, ::mlir::ValueRange unwind_operands);

ExceptionHandlingInterface (ExceptionHandlingInterface)

Interface implemented by any operation performing CFG-base exception handling. Every such operation is a terminator that has two successors that are branched to if an exception was thrown or not. The unwind successor additionally reserves the first block argument of the successor block and sets it to the exception object that was thrown. It must be of type !py.dynamic.

Methods:

getHappyPath
::mlir::Block*getHappyPath();

Returns the successor used if no exception was thrown.

getExceptionPath
::mlir::Block*getExceptionPath();

Returns the successor used if an exception was thrown.

getNormalDestOperandsMutable
::mlir::MutableOperandRange getNormalDestOperandsMutable();

Returns the operands passed to the block arguments of the block returned by getHappyPath.

getUnwindDestOperandsMutable
::mlir::MutableOperandRange getUnwindDestOperandsMutable();

Returns the operands passed to the block arguments of the block returned by getExceptionPath.

cloneWithoutExceptionHandling
::mlir::Operation*cloneWithoutExceptionHandling(::mlir::OpBuilder&builder);

Creates a non-exception handling version copy of this operation using builder.


KnownTypeObjectInterface (KnownTypeObjectInterface)

Methods:

getKnownTypeObject
::mlir::OpFoldResult getKnownTypeObject();

Returns the type object of the result of this operation or nullptr if unknown. The type object may either be a value or an attribute.


OnlyReadsValueInterface (OnlyReadsValueInterface)

Warning: This interface may only be attached to operations operating on immutable objects.

This interface signifies that specific operands of an operation only read the value part of an operand. The value part of an operand is defined by everything part of the memory of the object that is:

  • NOT the type object

  • NOT any slots

For user created objects not deriving from any builtin types but object, it is therefore nonsensical. For builtin types such as int or str however, it signifies reading the memory used to represent their value.

To use this interface, simply attach OnlyReadsValue to operands using Arg.

Methods:

onlyReadsValue
bool onlyReadsValue(::mlir::OpOperand&operand);

Attribute Interfaces#

BoolAttrInterface (BoolAttrInterface)

Interface implemented by any attribute that subclasses builtins.bool.

Implies an implementation of IntAttrInterface.

Methods:

getBoolean
bool getBoolean();

Returns the boolean value of this attribute.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::BoolAttrInterface> tagType);

This method is used by the classof mechanism of BoolAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing BoolAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes BoolAttrInterface is directly attached to in ODS.

ConstObjectAttrInterface (ConstObjectAttrInterface)

This interface is a specialization of ObjectAttrInterface, representing instances of constant python objects. Note that “constant” here refers to constant in the IR and compiler sense, as in, a known value that cannot change, not immutable in the Python sense (e.g. a tuple). This interface is therefore implemented by all concrete object attributes including attributes used to represent otherwise mutable objects as attributes such as #py.dict.

The methods on this interface are intended to return data that would only be valid on a constant as its value may change throughout the program otherwise. Immutable data is accessible via the ObjectAttrInterface.

Implies an implementation of ObjectAttrInterface.

Methods:

getSlots
::mlir::DictionaryAttr getSlots();

Returns a dictionary containing all slots of the attribute. Mustn’t be null.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::ConstObjectAttrInterface> tagType);

This method is used by the classof mechanism of ConstObjectAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing ConstObjectAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes ConstObjectAttrInterface is directly attached to in ODS.

DictAttrInterface (DictAttrInterface)

Interface implemented by any attribute that subclasses builtins.dict.

Implies an implementation of ConstObjectAttrInterface.

Methods:

lookup
mlir::Attribute lookup(mlir::Attribute key);

Returns the value for a given key in the dictionary. Returns a null attribute if not found. The key must be a RefAttr or ObjectAttrInterface.

getKeyValuePairs
llvm::ArrayRef<std::pair<mlir::Attribute, mlir::Attribute>> getKeyValuePairs();

Returns the list of key-value pairs of the dictionary in insertion order.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::DictAttrInterface> tagType);

This method is used by the classof mechanism of DictAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing DictAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes DictAttrInterface is directly attached to in ODS.

EqualsAttrInterface (EqualsAttrInterface)

Interface used to support equality as specified in Python in attributes.

Methods:

getCanonicalAttribute
mlir::Attribute getCanonicalAttribute();

Returns the attribute acting as the canonical form for checking equality. The precise kind of attribute returned is unspecified. However, all instances of a python attribute that should compare equal must return the exact same attribute from this function. This makes it possible to compare the attributes returned by this function to check for equality in python semantics.

Must not return null.

FloatAttrInterface (FloatAttrInterface)

Interface implemented by any attribute that subclasses builtins.float.

Implies an implementation of ObjectAttrInterface.

Methods:

getDoubleValue
double getDoubleValue();

Returns double value of this attribute.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::FloatAttrInterface> tagType);

This method is used by the classof mechanism of FloatAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing FloatAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes FloatAttrInterface is directly attached to in ODS.

FunctionAttrInterface (FunctionAttrInterface)

Interface implemented by any attribute that subclasses builtins.function.

Implies an implementation of ObjectAttrInterface.

Methods:

getValue
mlir::FlatSymbolRefAttr getValue();

Returns a symbol reference to the py.func this function attribute refers to.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::FunctionAttrInterface> tagType);

This method is used by the classof mechanism of FunctionAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing FunctionAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes FunctionAttrInterface is directly attached to in ODS.

IntAttrInterface (IntAttrInterface)

Interface implemented by any attribute that subclasses builtins.int. Implies an implementation of ObjectAttrInterface.

Methods:

getInteger
pylir::BigInt getInteger();

Returns the big integer value of this attribute.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::IntAttrInterface> tagType);

This method is used by the classof mechanism of IntAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing IntAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes IntAttrInterface is directly attached to in ODS.

ObjectAttrInterface (ObjectAttrInterface)

This interface is the base interface used by all object attributes and interfaces. It represents the immutable properties of all python object attributes.

Methods:

getTypeObject
::pylir::Py::ObjectBaseAttribute getTypeObject();

Returns the attribute representing the type object of this attribute. Mustn’t be null.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::ObjectAttrInterface> tagType);

This method is used by the classof mechanism of ObjectAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing ObjectAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes ObjectAttrInterface is directly attached to in ODS.

StrAttrInterface (StrAttrInterface)

Interface implemented by any attribute that subclasses builtins.str.

Implies an implementation of ObjectAttrInterface.

Methods:

getValue
llvm::StringRef getValue();

Returns string value of this attribute.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::StrAttrInterface> tagType);

This method is used by the classof mechanism of StrAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing StrAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes StrAttrInterface is directly attached to in ODS.

TupleAttrInterface (TupleAttrInterface)

Interface implemented by any attribute that subclasses builtins.tuple.

Implies an implementation of ObjectAttrInterface.

Methods:

getElements
llvm::ArrayRef<mlir::Attribute> getElements();

Returns the elements of this tuple.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::TupleAttrInterface> tagType);

This method is used by the classof mechanism of TupleAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing TupleAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes TupleAttrInterface is directly attached to in ODS.

TypeAttrInterface (TypeAttrInterface)

Interface implemented by any attribute that subclasses builtins.type.

Implies an implementation of ObjectAttrInterface.

Methods:

getMroTuple
mlir::Attribute getMroTuple();

Returns the MRO tuple of this type.

getInstanceSlots
pylir::Py::TupleAttrInterface getInstanceSlots();

Returns the list of slots that an instance of this type contains. This must be a tuple of strings.

canImplement
bool canImplement(std::in_place_type_t<::pylir::Py::TypeAttrInterface> tagType);

This method is used by the classof mechanism of TypeAttrInterface to allow an implementation to dynamically determine whether it implements the interface. The implementation has a parameter containing TypeAttrInterface to avoid clashing with corresponding methods of any other interfaces implemented.

Returns true for attributes TypeAttrInterface is directly attached to in ODS.

Type Interfaces#