Skip to content

Constant materialization

constant_materialization

ConstantMaterializationInterface

Bases: DialectInterface, ABC

An interface for dialects that support constant materialization.

A dialect that implements this interface should provide the materialize_constant method, which creates a constant operation of the dialect given a value and a type.

This is useful for transformations that need to create constants in a dialect-specific way.

Source code in xdsl/dialect_interfaces/constant_materialization.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class ConstantMaterializationInterface(DialectInterface, ABC):
    """
    An interface for dialects that support constant materialization.

    A dialect that implements this interface should provide the `materialize_constant` method,
    which creates a constant operation of the dialect given a value and a type.

    This is useful for transformations that need to create constants in a dialect-specific way.
    """

    @abstractmethod
    def materialize_constant(
        self, value: Attribute, type: Attribute
    ) -> Operation | None:
        """
        Materializes a constant operation in the dialect.

        Args:
            value (Attribute): The attribute representing the constant value.
            type (Attribute): The type of the constant.

        Returns:
            Operation: The created constant operation.
        """
        raise NotImplementedError("Dialect does not implement materialize_constant")

materialize_constant(value: Attribute, type: Attribute) -> Operation | None abstractmethod

Materializes a constant operation in the dialect.

Parameters:

Name Type Description Default
value Attribute

The attribute representing the constant value.

required
type Attribute

The type of the constant.

required

Returns:

Name Type Description
Operation Operation | None

The created constant operation.

Source code in xdsl/dialect_interfaces/constant_materialization.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@abstractmethod
def materialize_constant(
    self, value: Attribute, type: Attribute
) -> Operation | None:
    """
    Materializes a constant operation in the dialect.

    Args:
        value (Attribute): The attribute representing the constant value.
        type (Attribute): The type of the constant.

    Returns:
        Operation: The created constant operation.
    """
    raise NotImplementedError("Dialect does not implement materialize_constant")