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
41
@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
28
29
30
31
32
33
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
35
36
37
38
39
40
41
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
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
92
@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
50
51
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
53
54
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
56
57
58
59
60
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
62
63
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
65
66
67
68
69
70
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
72
73
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
75
76
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
78
79
80
81
82
83
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
85
86
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
88
89
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
91
92
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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
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
96
97
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
 99
100
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
102
103
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
105
106
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
109
110
111
112
113
114
115
116
@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
115
116
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
119
120
121
122
123
124
125
126
127
128
129
130
@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
126
127
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
129
130
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
133
134
135
136
137
138
139
140
@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
139
140
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
143
144
145
146
147
148
149
150
151
152
153
@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
149
150
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
152
153
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
156
157
158
159
160
161
162
163
164
@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
160
161
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
163
164
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
167
168
169
170
171
172
173
174
@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
173
174
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
177
178
179
180
181
182
183
184
@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
183
184
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
187
188
189
190
191
192
193
194
195
@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
194
195
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
198
199
200
201
202
@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
205
206
207
208
209
210
211
212
213
@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
211
212
213
@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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
@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
223
224
225
226
227
228
229
@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
257
258
259
260
261
@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
264
265
266
267
268
@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
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
336
@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
278
279
280
@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
282
283
284
@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
286
287
288
@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
290
291
292
@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
294
295
296
@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
298
299
300
301
@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
303
304
305
306
@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
308
309
310
311
312
313
@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
315
316
317
318
319
320
@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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
@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
340
341
342
@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
345
346
347
@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
350
351
352
@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
355
356
357
@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
360
361
362
@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
365
366
367
@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
370
371
372
@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
375
376
377
@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
380
381
382
@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
385
386
387
388
389
390
391
392
@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
429
430
431
@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
434
435
436
@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
439
440
441
@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
444
445
446
@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
449
450
451
@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
454
455
456
@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
464
465
466
467
468
@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
414
415
416
417
418
def get_position_cost(position: Position) -> int:
    """Get cost for a position type, with fallback for unknown types."""
    t = type(position)
    assert t 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
421
422
423
424
425
def get_question_cost(question: Question) -> int:
    """Get cost for a question type, with fallback for unknown types."""
    t = type(question)
    assert t in QUESTION_COSTS
    return QUESTION_COSTS[t]