Skip to content

Interfaces

interfaces

Interfaces are a convenience wrapper around traits, providing logic on the operation directly.

Operations inherit all the traits of their superclasses, allowing them to combine behaviours via sublcassing. This can be more convenient than adding the traits explicitly.

HasCanonicalizationPatternsInterface dataclass

Bases: Operation, ABC

An operation subclassing this interface must implement the get_canonicalization_patterns method, which returns a tuple of patterns that canonicalize this operation. Wraps CanonicalizationPatternsTrait.

Source code in xdsl/interfaces.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class HasCanonicalizationPatternsInterface(Operation, abc.ABC):
    """
    An operation subclassing this interface must implement the
    `get_canonicalization_patterns` method, which returns a tuple of patterns that
    canonicalize this operation.
    Wraps `CanonicalizationPatternsTrait`.
    """

    traits = traits_def(_HasCanonicalizationPatternsInterfaceTrait())

    @classmethod
    @abc.abstractmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        raise NotImplementedError()

traits = traits_def(_HasCanonicalizationPatternsInterfaceTrait()) class-attribute instance-attribute

get_canonicalization_patterns() -> tuple[RewritePattern, ...] abstractmethod classmethod

Source code in xdsl/interfaces.py
53
54
55
56
@classmethod
@abc.abstractmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    raise NotImplementedError()

HasFolderInterface dataclass

Bases: Operation, ABC

An operation subclassing this interface must implement the fold method, which attempts to fold the operation. Wraps HasFolderTrait.

Source code in xdsl/interfaces.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class HasFolderInterface(Operation, abc.ABC):
    """
    An operation subclassing this interface must implement the
    `fold` method, which attempts to fold the operation.
    Wraps `HasFolderTrait`.
    """

    traits = traits_def(_HasFolderInterfaceTrait())

    @abc.abstractmethod
    def fold(self) -> Sequence[SSAValue | Attribute] | None:
        """
        Attempts to fold the operation. The fold method cannot modify the IR.
        Returns either an existing SSAValue or an Attribute for each result of the operation.
        When folding is unsuccessful, returns None.

        The fold method is not allowed to mutate the operation being folded.
        """
        raise NotImplementedError()

traits = traits_def(_HasFolderInterfaceTrait()) class-attribute instance-attribute

fold() -> Sequence[SSAValue | Attribute] | None abstractmethod

Attempts to fold the operation. The fold method cannot modify the IR. Returns either an existing SSAValue or an Attribute for each result of the operation. When folding is unsuccessful, returns None.

The fold method is not allowed to mutate the operation being folded.

Source code in xdsl/interfaces.py
83
84
85
86
87
88
89
90
91
92
@abc.abstractmethod
def fold(self) -> Sequence[SSAValue | Attribute] | None:
    """
    Attempts to fold the operation. The fold method cannot modify the IR.
    Returns either an existing SSAValue or an Attribute for each result of the operation.
    When folding is unsuccessful, returns None.

    The fold method is not allowed to mutate the operation being folded.
    """
    raise NotImplementedError()

ConditionallySpeculatableInterface dataclass

Bases: Operation, ABC

An operation subclassing this interface must implement the is_speculatable method, which indicates whether the operation can be speculatively executed.

Source code in xdsl/interfaces.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
class ConditionallySpeculatableInterface(Operation, abc.ABC):
    """
    An operation subclassing this interface must implement the
    `is_speculatable` method, which indicates whether the operation
    can be speculatively executed.
    """

    traits = traits_def(_ConditionallySpeculatableInterfaceTrait())

    @abc.abstractmethod
    def is_speculatable(self) -> bool:
        """
        Returns True if this operation can be speculatively executed,
        False otherwise. Speculatable ops have no undefined behavior
        and no observable side effects.
        """
        raise NotImplementedError()

traits = traits_def(_ConditionallySpeculatableInterfaceTrait()) class-attribute instance-attribute

is_speculatable() -> bool abstractmethod

Returns True if this operation can be speculatively executed, False otherwise. Speculatable ops have no undefined behavior and no observable side effects.

Source code in xdsl/interfaces.py
120
121
122
123
124
125
126
127
@abc.abstractmethod
def is_speculatable(self) -> bool:
    """
    Returns True if this operation can be speculatively executed,
    False otherwise. Speculatable ops have no undefined behavior
    and no observable side effects.
    """
    raise NotImplementedError()