Traits
traits
OpTraitInvT = TypeVar('OpTraitInvT', bound=OpTrait)
module-attribute
OpTrait
dataclass
A trait attached to an operation definition. Traits can be used to define operation invariants, additional semantic information, or to group operations that have similar properties. Note that traits are the merge of traits and interfaces in MLIR.
Source code in xdsl/traits.py
19 20 21 22 23 24 25 26 27 28 29 30 | |
__init__() -> None
verify(op: Operation) -> None
Check that the operation satisfies the trait requirements.
Source code in xdsl/traits.py
28 29 30 | |
ConstantLike
dataclass
Bases: OpTrait, ABC
Operation known to be constant-like.
See external documentation.
Source code in xdsl/traits.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
get_constant_value(op: Operation) -> Attribute
abstractmethod
classmethod
Get the constant value from this constant-like operation.
Returns:
| Type | Description |
|---|---|
Attribute
|
The constant value as an Attribute, or None if the value cannot be determined. |
Source code in xdsl/traits.py
43 44 45 46 47 48 49 50 51 52 | |
HasFolder
dataclass
Bases: OpTrait
Operation known to support folding.
Source code in xdsl/traits.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
fold(op: Operation) -> Sequence[SSAValue | Attribute] | None
abstractmethod
classmethod
Attempts to fold the operation. The fold method cannot modify the IR. Returns either an existing SSAValue or an Attribute for each result of the operation. When folding is unsuccessful, returns None.
Source code in xdsl/traits.py
60 61 62 63 64 65 66 67 68 | |
HasParent
dataclass
Bases: OpTrait
Constraint the operation to have a specific parent operation.
Source code in xdsl/traits.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
op_types: tuple[type[Operation], ...]
instance-attribute
__init__(head_param: type[Operation], *tail_params: type[Operation])
Source code in xdsl/traits.py
77 78 | |
verify(op: Operation) -> None
Source code in xdsl/traits.py
80 81 82 83 84 85 86 87 88 89 90 91 92 | |
HasAncestor
dataclass
Bases: OpTrait
Constraint the operation to have a specific operation as ancestor, i.e. transitive parent.
Source code in xdsl/traits.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
op_types: tuple[type[Operation], ...]
instance-attribute
__init__(head_param: type[Operation], *tail_params: type[Operation])
Source code in xdsl/traits.py
104 105 | |
verify(op: Operation) -> None
Source code in xdsl/traits.py
107 108 109 110 111 112 113 114 115 116 | |
walk_ancestors(op: Operation) -> Iterator[Operation]
Iterates over the ancestors of an operation, including the input
Source code in xdsl/traits.py
118 119 120 121 122 123 | |
get_ancestor(op: Operation) -> Operation | None
Source code in xdsl/traits.py
125 126 127 128 | |
IsTerminator
dataclass
Bases: OpTrait
This trait provides verification and functionality for operations that are known to be terminators.
See external documentation.
Source code in xdsl/traits.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
verify(op: Operation) -> None
Check that the operation satisfies the IsTerminator trait requirements.
Source code in xdsl/traits.py
139 140 141 142 143 144 | |
ReturnLike
dataclass
Bases: OpTrait
This trait indicates that a terminator operation is "return-like". This means that it exits its current region and forwards its operands as "exit" values to the parent region. Operations with this trait are not permitted to contain successors or produce results.
Source code in xdsl/traits.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
verify(op: Operation) -> None
Source code in xdsl/traits.py
155 156 157 158 159 160 161 | |
NoTerminator
dataclass
Bases: OpTrait
Allow an operation to have single block regions with no terminator.
See external documentation.
Source code in xdsl/traits.py
164 165 166 167 168 169 170 171 172 173 174 175 176 | |
verify(op: Operation) -> None
Source code in xdsl/traits.py
171 172 173 174 175 176 | |
SingleBlockImplicitTerminator
dataclass
Bases: OpTrait
Checks the existence of the specified terminator to an operation which has
single-block regions.
The conditions for the implicit creation of the terminator depend on the operation
and occur during its creation using the ensure_terminator method.
This should be fully compatible with MLIR's Trait.
See external documentation.
Source code in xdsl/traits.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
op_type: type[Operation]
instance-attribute
__init__(op_type: type[Operation]) -> None
verify(op: Operation) -> None
Source code in xdsl/traits.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
IsolatedFromAbove
dataclass
Bases: OpTrait
Constrains the contained operations to use only values defined inside this operation.
This should be fully compatible with MLIR's Trait.
See external documentation.
Source code in xdsl/traits.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
verify(op: Operation) -> None
Source code in xdsl/traits.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
SymbolUserOpInterface
dataclass
Bases: OpTrait, ABC
Used to represent operations that reference Symbol operations. This provides the ability to perform safe and efficient verification of symbol uses, as well as additional functionality.
See external documentation.
Source code in xdsl/traits.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
verify(op: Operation) -> None
abstractmethod
This method should be adapted to the requirements of specific symbol users per operation.
It corresponds to the verifySymbolUses in upstream MLIR.
Source code in xdsl/traits.py
299 300 301 302 303 304 305 306 307 | |
SymbolTable
dataclass
Bases: OpTrait
SymbolTable operations are containers for Symbol operations. They offer lookup functionality for Symbols, and enforce unique symbols amongst its children.
A SymbolTable operation is constrained to have a single single-block region.
Source code in xdsl/traits.py
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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
verify(op: Operation)
Source code in xdsl/traits.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
lookup_symbol(op: Operation, name: str | StringAttr | SymbolRefAttr) -> Operation | None
staticmethod
Lookup a symbol by reference, starting from a specific operation's closest SymbolTable parent.
Source code in xdsl/traits.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
insert_or_update(symbol_table_op: Operation, symbol_op: Operation) -> Operation | None
staticmethod
This takes a symbol_table_op and a symbol_op. It looks if another operation inside symbol_table_op already defines symbol_ops symbol. If another operation is found, it replaces that operation with symbol_op. Otherwise, symbol_op is inserted at the end of symbol_table_op.
This method returns the operation that was replaced or None if no operation was replaced.
Source code in xdsl/traits.py
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
SymbolOpInterface
dataclass
Bases: OpTrait
A Symbol is a named operation that resides immediately within a region that defines
a SymbolTable (TODO). A Symbol operation should use the SymbolOpInterface interface to
provide the necessary verification and accessors.
A Symbol operation may be optional or not. If - the default - it is not optional,
a sym_name attribute of type StringAttr is required. If it is optional,
the attribute is optional too.
xDSL offers OptionalSymbolOpInterface as an always-optional SymbolOpInterface helper.
More requirements are defined in MLIR; Please see MLIR documentation for Symbol and SymbolTable for the requirements that are upcoming in xDSL.
See external documentation.
Source code in xdsl/traits.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
get_sym_attr_name(op: Operation) -> StringAttr | None
Returns the symbol of the operation, if any
Source code in xdsl/traits.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
is_optional_symbol(op: Operation) -> bool
Returns true if this operation optionally defines a symbol based on the presence of the symbol name.
Source code in xdsl/traits.py
448 449 450 451 452 453 | |
verify(op: Operation) -> None
Source code in xdsl/traits.py
455 456 457 458 459 | |
OptionalSymbolOpInterface
dataclass
Bases: SymbolOpInterface
Helper interface specialization for an optional SymbolOpInterface.
Source code in xdsl/traits.py
462 463 464 465 466 467 468 | |
is_optional_symbol(op: Operation) -> bool
Source code in xdsl/traits.py
467 468 | |
CallableOpInterface
dataclass
Bases: OpTrait, ABC
Interface for function-like Operations that can be called in a generic way.
Please see MLIR documentation for CallOpInterface and CallableOpInterface for more information.
See external documentation.
Source code in xdsl/traits.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
get_callable_region(op: Operation) -> Region
abstractmethod
classmethod
Returns the body of the operation
Source code in xdsl/traits.py
481 482 483 484 485 486 487 | |
get_argument_types(op: Operation) -> tuple[Attribute, ...]
abstractmethod
classmethod
Source code in xdsl/traits.py
489 490 491 492 | |
get_result_types(op: Operation) -> tuple[Attribute, ...]
abstractmethod
classmethod
Source code in xdsl/traits.py
494 495 496 497 | |
HasCanonicalizationPatternsTrait
dataclass
Bases: OpTrait
Provides the rewrite passes to canonicalize an operation.
Each rewrite pattern must have the trait's op as root.
Source code in xdsl/traits.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | |
__init__() -> None
get_patterns(op: type[Operation]) -> tuple[RewritePattern, ...]
Source code in xdsl/traits.py
508 509 510 511 512 | |
get_canonicalization_patterns() -> tuple[RewritePattern, ...]
abstractmethod
classmethod
Source code in xdsl/traits.py
514 515 516 517 | |
HasShapeInferencePatternsTrait
dataclass
Bases: OpTrait
Provides the rewrite passes to shape infer an operation.
Each rewrite pattern must have the trait's op as root.
Source code in xdsl/traits.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | |
__init__() -> None
verify(op: Operation) -> None
Source code in xdsl/traits.py
528 529 | |
get_shape_inference_patterns() -> tuple[RewritePattern, ...]
abstractmethod
classmethod
Source code in xdsl/traits.py
531 532 533 534 | |
MemoryEffectKind
Bases: Enum
The kind of side effect an operation can have.
MLIR has a more detailed version of this, able to tie effects to specfic resources or values. Here, everything has its effect on the universe.
Source code in xdsl/traits.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
READ = auto()
class-attribute
instance-attribute
Indicates that the operation reads from some resource. A 'read' effect implies only dereferencing of the resource, and not any visible mutation.
WRITE = auto()
class-attribute
instance-attribute
Indicates that the operation writes to some resource. A 'write' effect implies only mutating a resource, and not any visible dereference or read.
ALLOC = auto()
class-attribute
instance-attribute
Indicates that the operation allocates from some resource. An 'allocate' effect implies only allocation of the resource, and not any visible mutation or dereference.
FREE = auto()
class-attribute
instance-attribute
Indicates that the operation frees some resource that has been allocated. A 'free' effect implies only de-allocation of the resource, and not any visible allocation, mutation or dereference.
Resource
dataclass
Bases: ABC
This class represents a specific resource that an effect applies to.
Source code in xdsl/traits.py
571 572 573 574 575 576 577 578 579 | |
__init__() -> None
name() -> str
abstractmethod
Source code in xdsl/traits.py
577 578 579 | |
DefaultResource
dataclass
Bases: Resource
A conservative default resource kind.
Source code in xdsl/traits.py
582 583 584 585 586 587 588 589 | |
__init__() -> None
name() -> str
Source code in xdsl/traits.py
588 589 | |
EffectInstance
dataclass
An instance of a side effect.
Source code in xdsl/traits.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
kind: MemoryEffectKind
instance-attribute
The kind of side effect.
value: SSAValue | SymbolRefAttr | None = field(default=None)
class-attribute
instance-attribute
The value or symbol that is affected by the side effect, if known.
resource: Resource = field(default=(DefaultResource()))
class-attribute
instance-attribute
The resource that the effect applies to.
__init__(kind: MemoryEffectKind, value: SSAValue | SymbolRefAttr | None = None, resource: Resource = DefaultResource()) -> None
MemoryEffect
dataclass
Bases: OpTrait
A trait that enables operations to expose their side-effects or absence thereof.
Source code in xdsl/traits.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 | |
get_effects(op: Operation) -> set[EffectInstance] | None
abstractmethod
classmethod
Returns the concrete side effects of the operation.
Return None if the operation cannot conclude - interpreted as if the operation had no MemoryEffect interface in the first place.
Source code in xdsl/traits.py
619 620 621 622 623 624 625 626 627 628 | |
NoMemoryEffect
dataclass
Bases: MemoryEffect
A trait that signals that an operation never has side effects.
Source code in xdsl/traits.py
684 685 686 687 688 689 690 691 | |
get_effects(op: Operation) -> set[EffectInstance]
classmethod
Source code in xdsl/traits.py
689 690 691 | |
MemoryReadEffect
dataclass
Bases: MemoryEffect
A trait that signals that an operation always has read side effects.
Source code in xdsl/traits.py
694 695 696 697 698 699 700 701 | |
get_effects(op: Operation) -> set[EffectInstance]
classmethod
Source code in xdsl/traits.py
699 700 701 | |
MemoryWriteEffect
dataclass
Bases: MemoryEffect
A trait that signals that an operation always has write side effects.
Source code in xdsl/traits.py
704 705 706 707 708 709 710 711 | |
get_effects(op: Operation) -> set[EffectInstance]
classmethod
Source code in xdsl/traits.py
709 710 711 | |
MemoryAllocEffect
dataclass
Bases: MemoryEffect
A trait that signals that an operation always has alloc side effects.
Source code in xdsl/traits.py
714 715 716 717 718 719 720 721 | |
get_effects(op: Operation) -> set[EffectInstance]
classmethod
Source code in xdsl/traits.py
719 720 721 | |
MemoryFreeEffect
dataclass
Bases: MemoryEffect
A trait that signals that an operation always has deallocation side effects.
Source code in xdsl/traits.py
724 725 726 727 728 729 730 731 | |
get_effects(op: Operation) -> set[EffectInstance]
classmethod
Source code in xdsl/traits.py
729 730 731 | |
RecursiveMemoryEffect
dataclass
Bases: MemoryEffect
A trait that signals that an operation has the side effects of its contained operations.
Source code in xdsl/traits.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
get_effects(op: Operation)
classmethod
Source code in xdsl/traits.py
740 741 742 743 744 745 746 747 748 749 750 | |
ConditionallySpeculatable
dataclass
Bases: OpTrait
Source code in xdsl/traits.py
753 754 755 756 757 | |
is_speculatable(op: Operation) -> bool
abstractmethod
classmethod
Source code in xdsl/traits.py
754 755 756 757 | |
AlwaysSpeculatable
dataclass
Bases: ConditionallySpeculatable
Source code in xdsl/traits.py
760 761 762 763 | |
is_speculatable(op: Operation)
classmethod
Source code in xdsl/traits.py
761 762 763 | |
RecursivelySpeculatable
dataclass
Bases: ConditionallySpeculatable
Source code in xdsl/traits.py
766 767 768 769 770 771 | |
is_speculatable(op: Operation)
classmethod
Source code in xdsl/traits.py
767 768 769 770 771 | |
Pure
dataclass
Bases: NoMemoryEffect, AlwaysSpeculatable
In MLIR, Pure is NoMemoryEffect + AlwaysSpeculatable, but the latter is nowhere to be found here.
Source code in xdsl/traits.py
779 780 781 782 783 | |
Commutative
dataclass
Bases: OpTrait
A trait that signals that an operation is commutative.
Source code in xdsl/traits.py
786 787 788 789 | |
HasInsnRepresentation
dataclass
Bases: OpTrait, ABC
A trait providing information on how to encode an operation using a .insn assember directive.
The returned string contains python string.format placeholders where formatted operands are inserted during printing.
See external documentation.
Source code in xdsl/traits.py
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 | |
get_insn(op: Operation) -> str
abstractmethod
Return the insn representation of the operation for printing.
Source code in xdsl/traits.py
802 803 804 805 806 807 | |
SameOperandsAndResultType
dataclass
Bases: OpTrait
Constrain the operation to have the same operands and result type.
Source code in xdsl/traits.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 | |
__init__() -> None
verify(op: Operation) -> None
Source code in xdsl/traits.py
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 | |
ensure_terminator(op: Operation, trait: SingleBlockImplicitTerminator) -> None
Method that helps with the creation of an implicit terminator. This should be explicitly called during the creation of an operation that has the SingleBlockImplicitTerminator trait.
Source code in xdsl/traits.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
has_effects(op: Operation, effect: MemoryEffectKind) -> bool
Returns if the operation has side effects of this kind.
Source code in xdsl/traits.py
631 632 633 634 635 636 | |
has_exact_effect(op: Operation, effect: MemoryEffectKind) -> bool
Returns if the operation has the given side effects and no others.
proxy for only_has_effect
Source code in xdsl/traits.py
639 640 641 642 643 644 645 | |
only_has_effect(op: Operation, effect: MemoryEffectKind) -> bool
Returns if the operation has the given side effects and no others.
Source code in xdsl/traits.py
648 649 650 651 652 653 | |
is_side_effect_free(op: Operation) -> bool
Boilerplate helper to check if a generic operation is side effect free for sure.
Source code in xdsl/traits.py
656 657 658 659 660 661 | |
get_effects(op: Operation) -> set[EffectInstance] | None
Helper to get known side effects of an operation. None means that the operation has unknown effects, for safety.
Source code in xdsl/traits.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | |
is_speculatable(op: Operation)
Source code in xdsl/traits.py
774 775 776 | |