Skip to content

Predicate

predicate

This file implements some of the core data structures used in the pdl-to-pdl-interp conversion.

POSITION_COSTS = {OperationPosition: 1, OperandPosition: 2, OperandGroupPosition: 3, AttributePosition: 4, ConstraintPosition: 5, ResultPosition: 6, ResultGroupPosition: 7, TypePosition: 8, AttributeLiteralPosition: 9, TypeLiteralPosition: 10, UsersPosition: 11, ForEachPosition: 12} module-attribute

Different position types are ranked by priority. A lower cost means a higher priority. This is used to decide which position to branch on first when evaluating predicates.

QUESTION_COSTS = {IsNotNullQuestion: 1, OperationNameQuestion: 2, OperandCountAtLeastQuestion: 3, OperandCountQuestion: 4, ResultCountAtLeastQuestion: 5, ResultCountQuestion: 6, EqualToQuestion: 7, AttributeConstraintQuestion: 8, TypeConstraintQuestion: 9, ConstraintQuestion: 10} module-attribute

Different question types are ranked by priority. A lower cost means a higher priority. This is used to decide which question to branch on first when evaluating predicates.

Position dataclass

Bases: ABC

The position class encodes a location in a pattern. Each pattern has a root position. From there, other positions can be reached representing operands, results, and more.

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@dataclass(frozen=True)
class Position(ABC):
    """The position class encodes a location in a pattern.
    Each pattern has a root position. From there, other positions can be reached representing operands, results, and more.
    """

    parent: Optional["Position"] = None

    def get_operation_depth(self) -> int:
        """Returns depth of first ancestor operation position"""
        op = self.get_base_operation()
        if op is None:
            return 0
        return op.depth

    def get_base_operation(self) -> "OperationPosition|None":
        pos = self
        while not isinstance(pos, OperationPosition):
            if pos.parent is None:
                return None
            pos = pos.parent
        return pos

parent: Optional[Position] = None class-attribute instance-attribute

__init__(parent: Optional[Position] = None) -> None

get_operation_depth() -> int

Returns depth of first ancestor operation position

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
27
28
29
30
31
32
def get_operation_depth(self) -> int:
    """Returns depth of first ancestor operation position"""
    op = self.get_base_operation()
    if op is None:
        return 0
    return op.depth

get_base_operation() -> OperationPosition | None

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
34
35
36
37
38
39
40
def get_base_operation(self) -> "OperationPosition|None":
    pos = self
    while not isinstance(pos, OperationPosition):
        if pos.parent is None:
            return None
        pos = pos.parent
    return pos

OperationPosition dataclass

Bases: Position

Represents an operation in the IR

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
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
80
81
82
83
84
85
86
87
88
89
90
91
@dataclass(frozen=True, kw_only=True)
class OperationPosition(Position):
    """Represents an operation in the IR"""

    depth: int

    def is_root(self) -> bool:
        return self.depth == 0

    def is_operand_defining_op(self) -> bool:
        return isinstance(self.parent, OperandPosition | OperandGroupPosition)

    def __repr__(self):
        if self.is_root():
            return "root"
        else:
            return self.parent.__repr__() + ".defining_op"

    def get_operand(self, operand_num: int) -> "OperandPosition":
        return OperandPosition(operand_number=operand_num, parent=self)

    def get_operand_group(
        self, group_num: int, is_variadic: bool
    ) -> "OperandGroupPosition":
        return OperandGroupPosition(
            group_number=group_num, is_variadic=is_variadic, parent=self
        )

    def get_all_operands(self) -> "OperandGroupPosition":
        return OperandGroupPosition(group_number=None, is_variadic=True, parent=self)

    def get_result(self, result_num: int) -> "ResultPosition":
        return ResultPosition(result_number=result_num, parent=self)

    def get_result_group(
        self, group_num: int | None, is_variadic: bool
    ) -> "ResultGroupPosition":
        return ResultGroupPosition(
            group_number=group_num, is_variadic=is_variadic, parent=self
        )

    def get_all_results(self) -> "ResultGroupPosition":
        return ResultGroupPosition(group_number=None, is_variadic=True, parent=self)

    def get_attribute(self, attr_name: str) -> "AttributePosition":
        return AttributePosition(attribute_name=attr_name, parent=self)

    def get_attribute_literal(self, value: Attribute) -> "AttributeLiteralPosition":
        return AttributeLiteralPosition(value=value, parent=None)

depth: int instance-attribute

__init__(parent: Optional[Position] = None, *, depth: int) -> None

is_root() -> bool

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
49
50
def is_root(self) -> bool:
    return self.depth == 0

is_operand_defining_op() -> bool

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
52
53
def is_operand_defining_op(self) -> bool:
    return isinstance(self.parent, OperandPosition | OperandGroupPosition)

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
55
56
57
58
59
def __repr__(self):
    if self.is_root():
        return "root"
    else:
        return self.parent.__repr__() + ".defining_op"

get_operand(operand_num: int) -> OperandPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
61
62
def get_operand(self, operand_num: int) -> "OperandPosition":
    return OperandPosition(operand_number=operand_num, parent=self)

get_operand_group(group_num: int, is_variadic: bool) -> OperandGroupPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
64
65
66
67
68
69
def get_operand_group(
    self, group_num: int, is_variadic: bool
) -> "OperandGroupPosition":
    return OperandGroupPosition(
        group_number=group_num, is_variadic=is_variadic, parent=self
    )

get_all_operands() -> OperandGroupPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
71
72
def get_all_operands(self) -> "OperandGroupPosition":
    return OperandGroupPosition(group_number=None, is_variadic=True, parent=self)

get_result(result_num: int) -> ResultPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
74
75
def get_result(self, result_num: int) -> "ResultPosition":
    return ResultPosition(result_number=result_num, parent=self)

get_result_group(group_num: int | None, is_variadic: bool) -> ResultGroupPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
77
78
79
80
81
82
def get_result_group(
    self, group_num: int | None, is_variadic: bool
) -> "ResultGroupPosition":
    return ResultGroupPosition(
        group_number=group_num, is_variadic=is_variadic, parent=self
    )

get_all_results() -> ResultGroupPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
84
85
def get_all_results(self) -> "ResultGroupPosition":
    return ResultGroupPosition(group_number=None, is_variadic=True, parent=self)

get_attribute(attr_name: str) -> AttributePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
87
88
def get_attribute(self, attr_name: str) -> "AttributePosition":
    return AttributePosition(attribute_name=attr_name, parent=self)

get_attribute_literal(value: Attribute) -> AttributeLiteralPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
90
91
def get_attribute_literal(self, value: Attribute) -> "AttributeLiteralPosition":
    return AttributeLiteralPosition(value=value, parent=None)

ValuePosition dataclass

Bases: Position

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
class ValuePosition(Position):
    def get_defining_op(self) -> OperationPosition:
        return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

    def get_type(self) -> "TypePosition":
        return TypePosition(parent=self)

    def get_type_literal(self, value: Attribute) -> "TypeLiteralPosition":
        return TypeLiteralPosition(value=value, parent=None)

    def get_users(self, use_representative: bool) -> "UsersPosition":
        return UsersPosition(parent=self, use_representative=use_representative)

get_defining_op() -> OperationPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
95
96
def get_defining_op(self) -> OperationPosition:
    return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

get_type() -> TypePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
98
99
def get_type(self) -> "TypePosition":
    return TypePosition(parent=self)

get_type_literal(value: Attribute) -> TypeLiteralPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
101
102
def get_type_literal(self, value: Attribute) -> "TypeLiteralPosition":
    return TypeLiteralPosition(value=value, parent=None)

get_users(use_representative: bool) -> UsersPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
104
105
def get_users(self, use_representative: bool) -> "UsersPosition":
    return UsersPosition(parent=self, use_representative=use_representative)

OperandPosition dataclass

Bases: ValuePosition

Represents an operand of an operation

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
108
109
110
111
112
113
114
115
@dataclass(frozen=True, kw_only=True)
class OperandPosition(ValuePosition):
    """Represents an operand of an operation"""

    operand_number: int

    def __repr__(self):
        return f"{self.parent.__repr__()}.operand[{self.operand_number}]"

operand_number: int instance-attribute

__init__(parent: Optional[Position] = None, *, operand_number: int) -> None

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
114
115
def __repr__(self):
    return f"{self.parent.__repr__()}.operand[{self.operand_number}]"

OperandGroupPosition dataclass

Bases: Position

Represents a group of operands

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
118
119
120
121
122
123
124
125
126
127
128
129
@dataclass(frozen=True, kw_only=True)
class OperandGroupPosition(Position):
    """Represents a group of operands"""

    group_number: int | None
    is_variadic: bool

    def get_defining_op(self) -> "OperationPosition":
        return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

    def get_type(self) -> "TypePosition":
        return TypePosition(parent=self)

group_number: int | None instance-attribute

is_variadic: bool instance-attribute

__init__(parent: Optional[Position] = None, *, group_number: int | None, is_variadic: bool) -> None

get_defining_op() -> OperationPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
125
126
def get_defining_op(self) -> "OperationPosition":
    return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

get_type() -> TypePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
128
129
def get_type(self) -> "TypePosition":
    return TypePosition(parent=self)

ResultPosition dataclass

Bases: ValuePosition

Represents a result of an operation

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
132
133
134
135
136
137
138
139
@dataclass(frozen=True, kw_only=True)
class ResultPosition(ValuePosition):
    """Represents a result of an operation"""

    result_number: int

    def __repr__(self):
        return f"{self.parent.__repr__()}.result[{self.result_number}]"

result_number: int instance-attribute

__init__(parent: Optional[Position] = None, *, result_number: int) -> None

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
138
139
def __repr__(self):
    return f"{self.parent.__repr__()}.result[{self.result_number}]"

AttributePosition dataclass

Bases: Position

Represents an attribute of an operation

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
142
143
144
145
146
147
148
149
150
151
152
@dataclass(frozen=True, kw_only=True)
class AttributePosition(Position):
    """Represents an attribute of an operation"""

    attribute_name: str

    def __repr__(self):
        return f"{self.parent.__repr__()}.attribute[{self.attribute_name}]"

    def get_type(self) -> "TypePosition":
        return TypePosition(parent=self)

attribute_name: str instance-attribute

__init__(parent: Optional[Position] = None, *, attribute_name: str) -> None

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
148
149
def __repr__(self):
    return f"{self.parent.__repr__()}.attribute[{self.attribute_name}]"

get_type() -> TypePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
151
152
def get_type(self) -> "TypePosition":
    return TypePosition(parent=self)

TypePosition dataclass

Bases: Position

Represents the type of a value

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
155
156
157
158
159
160
161
162
163
@dataclass(frozen=True)
class TypePosition(Position):
    """Represents the type of a value"""

    def __repr__(self):
        return f"{self.parent.__repr__()}.type"

    def get_type_literal(self, value: Attribute) -> "TypeLiteralPosition":
        return TypeLiteralPosition(value=value, parent=None)

__init__(parent: Optional[Position] = None) -> None

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
159
160
def __repr__(self):
    return f"{self.parent.__repr__()}.type"

get_type_literal(value: Attribute) -> TypeLiteralPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
162
163
def get_type_literal(self, value: Attribute) -> "TypeLiteralPosition":
    return TypeLiteralPosition(value=value, parent=None)

UsersPosition dataclass

Bases: Position

Represents users of a value

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
166
167
168
169
170
171
172
173
@dataclass(frozen=True, kw_only=True)
class UsersPosition(Position):
    """Represents users of a value"""

    use_representative: bool

    def get_for_each(self, for_each_id: int) -> "ForEachPosition":
        return ForEachPosition(parent=self, id=for_each_id)

use_representative: bool instance-attribute

__init__(parent: Optional[Position] = None, *, use_representative: bool) -> None

get_for_each(for_each_id: int) -> ForEachPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
172
173
def get_for_each(self, for_each_id: int) -> "ForEachPosition":
    return ForEachPosition(parent=self, id=for_each_id)

ForEachPosition dataclass

Bases: Position

Represents an iterative choice of an operation from a set of users.

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
176
177
178
179
180
181
182
183
@dataclass(frozen=True, kw_only=True)
class ForEachPosition(Position):
    """Represents an iterative choice of an operation from a set of users."""

    id: int

    def get_passthrough_op(self) -> "OperationPosition":
        return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

id: int instance-attribute

__init__(parent: Optional[Position] = None, *, id: int) -> None

get_passthrough_op() -> OperationPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
182
183
def get_passthrough_op(self) -> "OperationPosition":
    return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

ResultGroupPosition dataclass

Bases: Position

Represents a group of results

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
186
187
188
189
190
191
192
193
194
@dataclass(frozen=True, kw_only=True)
class ResultGroupPosition(Position):
    """Represents a group of results"""

    group_number: int | None
    is_variadic: bool

    def get_type(self) -> "TypePosition":
        return TypePosition(parent=self)

group_number: int | None instance-attribute

is_variadic: bool instance-attribute

__init__(parent: Optional[Position] = None, *, group_number: int | None, is_variadic: bool) -> None

get_type() -> TypePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
193
194
def get_type(self) -> "TypePosition":
    return TypePosition(parent=self)

AttributeLiteralPosition dataclass

Bases: Position

Represents a literal attribute value

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
197
198
199
200
201
@dataclass(frozen=True, kw_only=True)
class AttributeLiteralPosition(Position):
    """Represents a literal attribute value"""

    value: Attribute

value: Attribute instance-attribute

__init__(parent: Optional[Position] = None, *, value: Attribute) -> None

TypeLiteralPosition dataclass

Bases: Position

Represents a literal type value

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
204
205
206
207
208
209
210
211
212
@dataclass(frozen=True, kw_only=True)
class TypeLiteralPosition(Position):
    """Represents a literal type value"""

    value: Attribute  # Can be a single type or array of types

    @staticmethod
    def get_type_literal(value: Attribute) -> "TypeLiteralPosition":
        return TypeLiteralPosition(value=value, parent=None)

value: Attribute instance-attribute

__init__(parent: Optional[Position] = None, *, value: Attribute) -> None

get_type_literal(value: Attribute) -> TypeLiteralPosition staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
210
211
212
@staticmethod
def get_type_literal(value: Attribute) -> "TypeLiteralPosition":
    return TypeLiteralPosition(value=value, parent=None)

ConstraintPosition dataclass

Bases: Position

Represents a result from a constraint

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
@dataclass(frozen=True, kw_only=True)
class ConstraintPosition(Position):
    """Represents a result from a constraint"""

    constraint: "ConstraintQuestion"
    result_index: int

    @staticmethod
    def get_constraint(
        constraint_question: "ConstraintQuestion", result_index: int
    ) -> "ConstraintPosition":
        return ConstraintPosition(
            constraint=constraint_question, result_index=result_index, parent=None
        )

constraint: ConstraintQuestion instance-attribute

result_index: int instance-attribute

__init__(parent: Optional[Position] = None, *, constraint: ConstraintQuestion, result_index: int) -> None

get_constraint(constraint_question: ConstraintQuestion, result_index: int) -> ConstraintPosition staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
222
223
224
225
226
227
228
@staticmethod
def get_constraint(
    constraint_question: "ConstraintQuestion", result_index: int
) -> "ConstraintPosition":
    return ConstraintPosition(
        constraint=constraint_question, result_index=result_index, parent=None
    )

Question dataclass

Represents a question/check to perform

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
256
257
258
259
260
@dataclass(frozen=True)
class Question:
    """Represents a question/check to perform"""

    pass

__init__() -> None

Answer dataclass

Represents an expected answer to a question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
263
264
265
266
267
@dataclass(frozen=True)
class Answer:
    """Represents an expected answer to a question"""

    pass

__init__() -> None

Predicate dataclass

Base predicate class

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
@dataclass()
class Predicate:
    """Base predicate class"""

    q: Question
    a: Answer

    @staticmethod
    def get_is_not_null() -> "Predicate":
        return Predicate(IsNotNullQuestion(), TrueAnswer())

    @staticmethod
    def get_operation_name(name: str) -> "Predicate":
        return Predicate(OperationNameQuestion(), StringAnswer(value=name))

    @staticmethod
    def get_operand_count(count: int) -> "Predicate":
        return Predicate(OperandCountQuestion(), UnsignedAnswer(value=count))

    @staticmethod
    def get_result_count(count: int) -> "Predicate":
        return Predicate(ResultCountQuestion(), UnsignedAnswer(value=count))

    @staticmethod
    def get_equal_to(other_position: Position) -> "Predicate":
        return Predicate(EqualToQuestion(other_position=other_position), TrueAnswer())

    @staticmethod
    def get_operand_count_at_least(count: int) -> "Predicate":
        """Get predicate for minimum operand count (variadic case)"""
        return Predicate(OperandCountAtLeastQuestion(), UnsignedAnswer(value=count))

    @staticmethod
    def get_result_count_at_least(count: int) -> "Predicate":
        """Get predicate for minimum result count (variadic case)"""
        return Predicate(ResultCountAtLeastQuestion(), UnsignedAnswer(value=count))

    @staticmethod
    def get_attribute_constraint(attr_value: Attribute) -> "Predicate":
        """Get predicate for attribute value constraint"""
        return Predicate(
            AttributeConstraintQuestion(), AttributeAnswer(value=attr_value)
        )

    @staticmethod
    def get_type_constraint(
        type_value: TypeAttribute | ArrayAttr[TypeAttribute],
    ) -> "Predicate":
        """Get predicate for type value constraint"""
        return Predicate(TypeConstraintQuestion(), TypeAnswer(value=type_value))

    @staticmethod
    def get_constraint(
        name: str,
        arg_positions: tuple[Position, ...],
        result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...],
        is_negated: bool = False,
    ) -> "Predicate":
        """Get predicate for a native constraint"""
        question = ConstraintQuestion(
            name=name,
            arg_positions=tuple(arg_positions),
            result_types=tuple(result_types),
            is_negated=is_negated,
        )
        return Predicate(question, TrueAnswer())

q: Question instance-attribute

a: Answer instance-attribute

__init__(q: Question, a: Answer) -> None

get_is_not_null() -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
277
278
279
@staticmethod
def get_is_not_null() -> "Predicate":
    return Predicate(IsNotNullQuestion(), TrueAnswer())

get_operation_name(name: str) -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
281
282
283
@staticmethod
def get_operation_name(name: str) -> "Predicate":
    return Predicate(OperationNameQuestion(), StringAnswer(value=name))

get_operand_count(count: int) -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
285
286
287
@staticmethod
def get_operand_count(count: int) -> "Predicate":
    return Predicate(OperandCountQuestion(), UnsignedAnswer(value=count))

get_result_count(count: int) -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
289
290
291
@staticmethod
def get_result_count(count: int) -> "Predicate":
    return Predicate(ResultCountQuestion(), UnsignedAnswer(value=count))

get_equal_to(other_position: Position) -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
293
294
295
@staticmethod
def get_equal_to(other_position: Position) -> "Predicate":
    return Predicate(EqualToQuestion(other_position=other_position), TrueAnswer())

get_operand_count_at_least(count: int) -> Predicate staticmethod

Get predicate for minimum operand count (variadic case)

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
297
298
299
300
@staticmethod
def get_operand_count_at_least(count: int) -> "Predicate":
    """Get predicate for minimum operand count (variadic case)"""
    return Predicate(OperandCountAtLeastQuestion(), UnsignedAnswer(value=count))

get_result_count_at_least(count: int) -> Predicate staticmethod

Get predicate for minimum result count (variadic case)

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
302
303
304
305
@staticmethod
def get_result_count_at_least(count: int) -> "Predicate":
    """Get predicate for minimum result count (variadic case)"""
    return Predicate(ResultCountAtLeastQuestion(), UnsignedAnswer(value=count))

get_attribute_constraint(attr_value: Attribute) -> Predicate staticmethod

Get predicate for attribute value constraint

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
307
308
309
310
311
312
@staticmethod
def get_attribute_constraint(attr_value: Attribute) -> "Predicate":
    """Get predicate for attribute value constraint"""
    return Predicate(
        AttributeConstraintQuestion(), AttributeAnswer(value=attr_value)
    )

get_type_constraint(type_value: TypeAttribute | ArrayAttr[TypeAttribute]) -> Predicate staticmethod

Get predicate for type value constraint

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
314
315
316
317
318
319
@staticmethod
def get_type_constraint(
    type_value: TypeAttribute | ArrayAttr[TypeAttribute],
) -> "Predicate":
    """Get predicate for type value constraint"""
    return Predicate(TypeConstraintQuestion(), TypeAnswer(value=type_value))

get_constraint(name: str, arg_positions: tuple[Position, ...], result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...], is_negated: bool = False) -> Predicate staticmethod

Get predicate for a native constraint

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
@staticmethod
def get_constraint(
    name: str,
    arg_positions: tuple[Position, ...],
    result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...],
    is_negated: bool = False,
) -> "Predicate":
    """Get predicate for a native constraint"""
    question = ConstraintQuestion(
        name=name,
        arg_positions=tuple(arg_positions),
        result_types=tuple(result_types),
        is_negated=is_negated,
    )
    return Predicate(question, TrueAnswer())

IsNotNullQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
339
340
341
@dataclass(frozen=True)
class IsNotNullQuestion(Question):
    pass

__init__() -> None

OperationNameQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
344
345
346
@dataclass(frozen=True)
class OperationNameQuestion(Question):
    pass

__init__() -> None

OperandCountQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
349
350
351
@dataclass(frozen=True)
class OperandCountQuestion(Question):
    pass

__init__() -> None

ResultCountQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
354
355
356
@dataclass(frozen=True)
class ResultCountQuestion(Question):
    pass

__init__() -> None

EqualToQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
359
360
361
@dataclass(frozen=True)
class EqualToQuestion(Question):
    other_position: Position

other_position: Position instance-attribute

__init__(other_position: Position) -> None

OperandCountAtLeastQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
364
365
366
@dataclass(frozen=True)
class OperandCountAtLeastQuestion(Question):
    pass

__init__() -> None

ResultCountAtLeastQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
369
370
371
@dataclass(frozen=True)
class ResultCountAtLeastQuestion(Question):
    pass

__init__() -> None

AttributeConstraintQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
374
375
376
@dataclass(frozen=True)
class AttributeConstraintQuestion(Question):
    pass

__init__() -> None

TypeConstraintQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
379
380
381
@dataclass(frozen=True)
class TypeConstraintQuestion(Question):
    pass

__init__() -> None

ConstraintQuestion dataclass

Bases: Question

Represents a native constraint check

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
384
385
386
387
388
389
390
391
@dataclass(frozen=True)
class ConstraintQuestion(Question):
    """Represents a native constraint check"""

    name: str
    arg_positions: tuple[Position, ...]
    result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...]
    is_negated: bool

name: str instance-attribute

arg_positions: tuple[Position, ...] instance-attribute

result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...] instance-attribute

is_negated: bool instance-attribute

__init__(name: str, arg_positions: tuple[Position, ...], result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...], is_negated: bool) -> None

TrueAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
426
427
428
@dataclass(frozen=True)
class TrueAnswer(Answer):
    pass

__init__() -> None

FalseAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
431
432
433
@dataclass(frozen=True)
class FalseAnswer(Answer):
    pass

__init__() -> None

UnsignedAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
436
437
438
@dataclass(frozen=True)
class UnsignedAnswer(Answer):
    value: int

value: int instance-attribute

__init__(value: int) -> None

StringAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
441
442
443
@dataclass(frozen=True)
class StringAnswer(Answer):
    value: str

value: str instance-attribute

__init__(value: str) -> None

AttributeAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
446
447
448
@dataclass(frozen=True)
class AttributeAnswer(Answer):
    value: Attribute

value: Attribute instance-attribute

__init__(value: Attribute) -> None

TypeAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
451
452
453
@dataclass(frozen=True)
class TypeAnswer(Answer):
    value: TypeAttribute | ArrayAttr[TypeAttribute]

value: TypeAttribute | ArrayAttr[TypeAttribute] instance-attribute

__init__(value: TypeAttribute | ArrayAttr[TypeAttribute]) -> None

PositionalPredicate dataclass

Bases: Predicate

A predicate applied to a specific position

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
461
462
463
464
465
@dataclass
class PositionalPredicate(Predicate):
    """A predicate applied to a specific position"""

    position: Position

position: Position instance-attribute

__init__(q: Question, a: Answer, position: Position) -> None

get_position_cost(position: Position) -> int

Get cost for a position type, with fallback for unknown types.

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
413
414
415
416
def get_position_cost(position: Position) -> int:
    """Get cost for a position type, with fallback for unknown types."""
    assert (t := type(position)) in POSITION_COSTS
    return POSITION_COSTS[t]

get_question_cost(question: Question) -> int

Get cost for a question type, with fallback for unknown types.

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
419
420
421
422
def get_question_cost(question: Question) -> int:
    """Get cost for a question type, with fallback for unknown types."""
    assert (t := type(question)) in QUESTION_COSTS
    return QUESTION_COSTS[t]