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 | |
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 | |
get_base_operation() -> OperationPosition | None
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
35 36 37 38 39 40 41 | |
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 | |
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 | |
is_operand_defining_op() -> bool
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
53 54 | |
__repr__()
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
56 57 58 59 60 | |
get_operand(operand_num: int) -> OperandPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
62 63 | |
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 | |
get_all_operands() -> OperandGroupPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
72 73 | |
get_result(result_num: int) -> ResultPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
75 76 | |
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 | |
get_all_results() -> ResultGroupPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
85 86 | |
get_attribute(attr_name: str) -> AttributePosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
88 89 | |
get_attribute_literal(value: Attribute) -> AttributeLiteralPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
91 92 | |
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 | |
get_defining_op() -> OperationPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
96 97 | |
get_type() -> TypePosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
99 100 | |
get_type_literal(value: Attribute) -> TypeLiteralPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
102 103 | |
get_users(use_representative: bool) -> UsersPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
105 106 | |
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 | |
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 | |
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 | |
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 | |
get_type() -> TypePosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
129 130 | |
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 | |
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 | |
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 | |
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 | |
get_type() -> TypePosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
152 153 | |
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 | |
__init__(parent: Optional[Position] = None) -> None
__repr__()
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
160 161 | |
get_type_literal(value: Attribute) -> TypeLiteralPosition
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
163 164 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
__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 | |
__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 | |
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 | |
get_operation_name(name: str) -> Predicate
staticmethod
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
282 283 284 | |
get_operand_count(count: int) -> Predicate
staticmethod
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
286 287 288 | |
get_result_count(count: int) -> Predicate
staticmethod
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
290 291 292 | |
get_equal_to(other_position: Position) -> Predicate
staticmethod
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
294 295 296 | |
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 | |
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 | |
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 | |
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 | |
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 | |
IsNotNullQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
340 341 342 | |
__init__() -> None
OperationNameQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
345 346 347 | |
__init__() -> None
OperandCountQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
350 351 352 | |
__init__() -> None
ResultCountQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
355 356 357 | |
__init__() -> None
EqualToQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
360 361 362 | |
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 | |
__init__() -> None
ResultCountAtLeastQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
370 371 372 | |
__init__() -> None
AttributeConstraintQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
375 376 377 | |
__init__() -> None
TypeConstraintQuestion
dataclass
Bases: Question
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
380 381 382 | |
__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 | |
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 | |
__init__() -> None
FalseAnswer
dataclass
Bases: Answer
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
434 435 436 | |
__init__() -> None
UnsignedAnswer
dataclass
Bases: Answer
Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
439 440 441 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |