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 | |
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 | |
ConstantLikeInterface
dataclass
Bases: Operation, ABC
An operation subclassing this interface must implement the
get_constant_value method, which returns the constant value of this operation.
Wraps ConstantLikeTrait.
Source code in xdsl/interfaces.py
74 75 76 77 78 79 80 81 82 83 84 85 | |
traits = traits_def(_ConstantLikeInterfaceTrait())
class-attribute
instance-attribute
get_constant_value() -> Attribute
abstractmethod
Source code in xdsl/interfaces.py
83 84 85 | |
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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
traits = traits_def(_HasFolderInterfaceTrait())
class-attribute
instance-attribute
get_constant(operand: SSAValue) -> Attribute | None
Source code in xdsl/interfaces.py
112 113 114 115 116 117 | |
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
119 120 121 122 123 124 125 126 127 128 | |