Skip to content

Ub

ub

The ub (undefined behavior) dialect.

Mirrors MLIR's UB dialect, which provides operations and attributes for representing deferred undefined behavior.

UB = Dialect('ub', [PoisonOp, UnreachableOp], [PoisonAttr]) module-attribute

PoisonAttr dataclass

Bases: ParametrizedAttribute

Attribute carrying poison semantics for ub.poison.

A default (empty) #ub.poison indicates a fully poisoned result. Other attributes (e.g. partially poisoned vectors) may be used to indicate additional poison semantics; in MLIR this is modelled via the PoisonAttrInterface.

Source code in xdsl/dialects/ub.py
23
24
25
26
27
28
29
30
31
32
33
34
@irdl_attr_definition
class PoisonAttr(ParametrizedAttribute):
    """
    Attribute carrying poison semantics for `ub.poison`.

    A default (empty) `#ub.poison` indicates a fully poisoned result. Other
    attributes (e.g. partially poisoned vectors) may be used to indicate
    additional poison semantics; in MLIR this is modelled via the
    `PoisonAttrInterface`.
    """

    name = "ub.poison"

name = 'ub.poison' class-attribute instance-attribute

PoisonOp

Bases: IRDLOperation

Materializes a compile-time poisoned constant value to indicate deferred undefined behavior.

The value attribute indicates optional additional poison semantics (e.g. partially poisoned vectors); the default value indicates the result is fully poisoned.

Examples:

// Short form (fully poisoned)
%0 = ub.poison : i32
// Long form (additional poison semantics)
%1 = ub.poison <#custom_poison_elements_attr> : vector<4xi64>
Source code in xdsl/dialects/ub.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@irdl_op_definition
class PoisonOp(IRDLOperation):
    """
    Materializes a compile-time poisoned constant value to indicate deferred
    undefined behavior.

    The `value` attribute indicates optional additional poison semantics (e.g.
    partially poisoned vectors); the default value indicates the result is
    fully poisoned.

    Examples:

    ```mlir
    // Short form (fully poisoned)
    %0 = ub.poison : i32
    // Long form (additional poison semantics)
    %1 = ub.poison <#custom_poison_elements_attr> : vector<4xi64>
    ```
    """

    name = "ub.poison"

    # MLIR constrains this to `PoisonAttrInterface` (an attribute interface).
    # xDSL does not model that interface yet, so we accept any `Attribute` for
    # now; this should be tightened to a `PoisonAttrInterface` check once the
    # interface is available.
    value = prop_def(Attribute, default_value=PoisonAttr())

    result = result_def()

    traits = traits_def(ConstantLike(), Pure())

    assembly_format = "attr-dict (`<` $value^ `>`)? `:` type($result)"

    def __init__(
        self,
        result_type: Attribute,
        value: Attribute | None = None,
    ):
        super().__init__(
            result_types=[result_type],
            properties={"value": value},
        )

name = 'ub.poison' class-attribute instance-attribute

value = prop_def(Attribute, default_value=(PoisonAttr())) class-attribute instance-attribute

result = result_def() class-attribute instance-attribute

traits = traits_def(ConstantLike(), Pure()) class-attribute instance-attribute

assembly_format = 'attr-dict (`<` $value^ `>`)? `:` type($result)' class-attribute instance-attribute

__init__(result_type: Attribute, value: Attribute | None = None)

Source code in xdsl/dialects/ub.py
71
72
73
74
75
76
77
78
79
def __init__(
    self,
    result_type: Attribute,
    value: Attribute | None = None,
):
    super().__init__(
        result_types=[result_type],
        properties={"value": value},
    )

UnreachableOp dataclass

Bases: IRDLOperation

Triggers immediate undefined behavior if executed.

Example:

ub.unreachable
Source code in xdsl/dialects/ub.py
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@irdl_op_definition
class UnreachableOp(IRDLOperation):
    """
    Triggers immediate undefined behavior if executed.

    Example:

    ```mlir
    ub.unreachable
    ```
    """

    name = "ub.unreachable"

    traits = traits_def(IsTerminator())

    assembly_format = "attr-dict"

name = 'ub.unreachable' class-attribute instance-attribute

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

assembly_format = 'attr-dict' class-attribute instance-attribute