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 | |
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 | |
get_base_operation() -> OperationPosition | None
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
34 35 36 37 38 39 40 | |
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 | |
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 | |
is_operand_defining_op() -> bool
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
52 53 | |
__repr__()
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
55 56 57 58 59 | |
get_operand(operand_num: int) -> OperandPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
61 62 | |
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 | |
get_all_operands() -> OperandGroupPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
71 72 | |
get_result(result_num: int) -> ResultPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
74 75 | |
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 | |
get_all_results() -> ResultGroupPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
84 85 | |
get_attribute(attr_name: str) -> AttributePosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
87 88 | |
get_attribute_literal(value: Attribute) -> AttributeLiteralPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
90 91 | |
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 | |
get_defining_op() -> OperationPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
95 96 | |
get_type() -> TypePosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
98 99 | |
get_type_literal(value: Attribute) -> TypeLiteralPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
101 102 | |
get_users(use_representative: bool) -> UsersPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
104 105 | |
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 | |
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 | |
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 | |
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 | |
get_type() -> TypePosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
128 129 | |
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 | |
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 | |
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 | |
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 | |
get_type() -> TypePosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
151 152 | |
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 | |
__init__(parent: Optional[Position] = None) -> None
__repr__()
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
159 160 | |
get_type_literal(value: Attribute) -> TypeLiteralPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
162 163 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
__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 | |
__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 | |
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 | |
get_operation_name(name: str) -> Predicate
staticmethod
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
281 282 283 | |
get_operand_count(count: int) -> Predicate
staticmethod
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
285 286 287 | |
get_result_count(count: int) -> Predicate
staticmethod
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
289 290 291 | |
get_equal_to(other_position: Position) -> Predicate
staticmethod
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
293 294 295 | |
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 | |
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 | |
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 | |
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 | |
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 | |
IsNotNullQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
339 340 341 | |
__init__() -> None
OperationNameQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
344 345 346 | |
__init__() -> None
OperandCountQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
349 350 351 | |
__init__() -> None
ResultCountQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
354 355 356 | |
__init__() -> None
EqualToQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
359 360 361 | |
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 | |
__init__() -> None
ResultCountAtLeastQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
369 370 371 | |
__init__() -> None
AttributeConstraintQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
374 375 376 | |
__init__() -> None
TypeConstraintQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
379 380 381 | |
__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 | |
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 | |
__init__() -> None
FalseAnswer
dataclass
Bases: Answer
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
431 432 433 | |
__init__() -> None
UnsignedAnswer
dataclass
Bases: Answer
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
436 437 438 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |