Stmt
ArgumentList dataclass
ArgumentList(node: NodeType, field: FieldType)
Bases: MutableSequenceView[tuple[SSAValue, ...], 'Statement', SSAValue]
, Printable
A View object that contains a list of Arguemnts of a Statement.
Description
This is a proxy object that provide safe API to manipulate the arguemnts of a statement.
Pretty Printing
This object is pretty printable via .print()
method.
get_slice
get_slice(name: str) -> slice
Get the slice of the arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the slice. | required |
Returns:
Name | Type | Description |
---|---|---|
slice | slice | The slice of the arguments. |
Source code in src/kirin/ir/nodes/stmt.py
75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
insert
insert(idx: int, value: SSAValue) -> None
Insert the argument SSAValue at the specified index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx | int | The index to insert the value. | required |
value | SSAValue | The value to insert. | required |
Source code in src/kirin/ir/nodes/stmt.py
62 63 64 65 66 67 68 69 70 71 72 73 |
|
set_item
set_item(idx: int, value: SSAValue) -> None
Set the argument SSAVAlue at the specified index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx | int | The index of the item to set. | required |
value | SSAValue | The value to set. | required |
Source code in src/kirin/ir/nodes/stmt.py
48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
ResultList dataclass
ResultList(node: NodeType, field: FieldType)
Bases: MutableSequenceView[list[ResultValue], 'Statement', ResultValue]
A View object that contains a list of ResultValue of a Statement.
Description
This is a proxy object that provide safe API to manipulate the result values of a statement
Pretty Printing
This object is pretty printable via .print()
method.
types property
types: Sequence[TypeAttribute]
Get the result types of the Statement.
Returns:
Type | Description |
---|---|
Sequence[TypeAttribute] | Sequence[TypeAttribute]: type of each result value. |
Statement dataclass
Statement(
*,
args: Sequence[SSAValue] = (),
regions: Sequence[Region] = (),
successors: Sequence[Block] = (),
attributes: Mapping[str, Attribute] = {},
results: Sequence[ResultValue] = (),
result_types: Sequence[TypeAttribute] = (),
args_slice: Mapping[str, int | slice] = {},
source: SourceInfo | None = None
)
Bases: IRNode['Block']
The Statment is an instruction in the IR
Pretty Printing
This object is pretty printable via .print()
method.
Source code in src/kirin/ir/nodes/stmt.py
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 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
|
args instance-attribute
property
writable
args: ArgumentList = args
Get the arguments of the Statement.
Returns:
Name | Type | Description |
---|---|---|
ArgumentList | ArgumentList | The arguments View of the Statement. |
next_stmt property
writable
next_stmt: Statement | None
Get the next statement.
parent_block property
parent_block: Block | None
parent_node property
writable
parent_node: Block | None
parent_region property
parent_region: Region | None
Get the parent Region. Returns: Region | None: The parent Region.
parent_stmt property
parent_stmt: Statement | None
Get the parent statement.
Returns:
Type | Description |
---|---|
Statement | None | Statement | None: The parent statement. |
prev_stmt property
writable
prev_stmt: Statement | None
Get the previous statement.
regions instance-attribute
property
writable
regions: list[Region] = list(regions)
Get a list of regions of the Statement.
Returns:
Type | Description |
---|---|
list[Region] | list[Region]: The list of regions of the Statement. |
results property
results: ResultList
Get the result values of the Statement.
Returns:
Name | Type | Description |
---|---|---|
ResultList | ResultList | The result values View of the Statement. |
source class-attribute
instance-attribute
source: SourceInfo | None = source
The source information of the Statement for debugging/stacktracing.
check
check() -> None
Check the statement. Raises Exception
if the statement is not correct. This method is called by the verify
method, which will detect the source of the error in the IR. One should always call the verify
method to verify the IR.
The difference between check
and check_type
is that check
is called at any time to check the structure of the IR by verify
, while check_type
is called after the type inference to check the types of the IR.
Source code in src/kirin/ir/nodes/stmt.py
727 728 729 730 731 732 733 734 735 736 737 |
|
check_type
check_type() -> None
Check the types of the Block. Raises Exception
if the types are not correct. This method is called by the verify_type
method, which will detect the source of the error in the IR. One should always call the verify_type
method to verify the types of the IR.
Note
This method is generated by the @statement
decorator. But can be overridden if needed.
Source code in src/kirin/ir/nodes/stmt.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
|
delete
delete(safe: bool = True) -> None
Delete the Statement completely from the IR graph.
Note
This method will detach + remove references of the Statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
safe | bool | If True, raise error if there is anything that still reference components in the Statement. Defaults to True. | True |
Source code in src/kirin/ir/nodes/stmt.py
380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
detach
detach() -> None
detach the statement from its parent block.
Source code in src/kirin/ir/nodes/stmt.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|
drop_all_references
drop_all_references() -> None
Remove all the dependency that reference/uses this Statement.
Source code in src/kirin/ir/nodes/stmt.py
372 373 374 375 376 377 378 |
|
expect_one_result
expect_one_result() -> ResultValue
Check if the statement contain only one result, and return it
Source code in src/kirin/ir/nodes/stmt.py
706 707 708 709 710 |
|
from_stmt classmethod
from_stmt(
other: Statement,
args: Sequence[SSAValue] | None = None,
regions: list[Region] | None = None,
successors: list[Block] | None = None,
attributes: dict[str, Attribute] | None = None,
) -> Self
Create a similar Statement with new ResultValue
and without attaching to any parent block. This still references to the old successor and regions.
Source code in src/kirin/ir/nodes/stmt.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
|
get_attribute
get_attribute(
key: str, default: Attribute | None = None
) -> Attribute | None
Get the attribute or property of the Statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | str | The key of the attribute or property. | required |
Returns:
Type | Description |
---|---|
Attribute | None | Attribute | None: The attribute or property of the Statement. |
Source code in src/kirin/ir/nodes/stmt.py
659 660 661 662 663 664 665 666 667 668 669 670 |
|
get_present_trait classmethod
get_present_trait(trait: type[TraitType]) -> TraitType
Just like get_trait, but expects the trait to be there. Useful for linter checks, when you know the trait is present.
Source code in src/kirin/ir/nodes/stmt.py
697 698 699 700 701 702 703 704 |
|
get_trait classmethod
get_trait(trait: type[TraitType]) -> TraitType | None
Get the trait of the Statement.
Source code in src/kirin/ir/nodes/stmt.py
689 690 691 692 693 694 695 |
|
has_trait classmethod
has_trait(trait_type: type[Trait['Statement']]) -> bool
Check if the Statement has a specific trait.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trait_type | type[StmtTrait] | The type of trait to check for. | required |
Returns:
Name | Type | Description |
---|---|---|
bool | bool | True if the class has the specified trait, False otherwise. |
Source code in src/kirin/ir/nodes/stmt.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 |
|
insert_after
insert_after(stmt: Statement) -> None
Insert the current Statement after the input Statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stmt | Statement | Input Statement. | required |
Example
The following example demonstrates how to insert a Statement after another Statement. After insert_after
is called, stmt1
will be inserted after stmt2
, which appears in IR in the order (stmt2 -> stmt1)
stmt1 = Statement()
stmt2 = Statement()
stmt1.insert_after(stmt2)
Source code in src/kirin/ir/nodes/stmt.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
insert_before
insert_before(stmt: Statement) -> None
Insert the current Statement before the input Statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stmt | Statement | Input Statement. | required |
Example
The following example demonstrates how to insert a Statement before another Statement. After insert_before
is called, stmt1
will be inserted before stmt2
, which appears in IR in the order (stmt1 -> stmt2)
stmt1 = Statement()
stmt2 = Statement()
stmt1.insert_before(stmt2)
Source code in src/kirin/ir/nodes/stmt.py
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 |
|
is_structurally_equal
is_structurally_equal(
other: Self,
context: (
dict[IRNode | SSAValue, IRNode | SSAValue] | None
) = None,
) -> bool
Check if the Statement is structurally equal to another Statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | Self | The other Statelemt to compare with. | required |
context | dict[IRNode | SSAValue, IRNode | SSAValue] | None | A map of IRNode/SSAValue to hint that they are equivalent so the check will treat them as equivalent. Defaults to None. | None |
Returns:
Name | Type | Description |
---|---|---|
bool | bool | True if the IRNode is structurally equal to the other. |
Source code in src/kirin/ir/nodes/stmt.py
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 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
|
replace_by
replace_by(stmt: Statement) -> None
Replace the current Statement by the input Statement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stmt | Statement | Input Statement. | required |
Source code in src/kirin/ir/nodes/stmt.py
309 310 311 312 313 314 315 316 317 318 319 320 |
|
verify
verify() -> None
run mandatory validation checks. This is not same as verify_type, which may be optional.
Source code in src/kirin/ir/nodes/stmt.py
739 740 741 742 743 744 745 |
|
verify_type
verify_type() -> None
Verify the type of the statement.
Note
This API should be called after all the types are figured out (by typeinfer)
Source code in src/kirin/ir/nodes/stmt.py
747 748 749 750 751 752 753 754 755 756 757 758 |
|
walk
walk(
*,
reverse: bool = False,
region_first: bool = False,
include_self: bool = True
) -> Iterator[Statement]
Traversal the Statements of Regions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reverse | bool | If walk in the reversed manner. Defaults to False. | False |
region_first | bool | If the walk should go through the Statement first or the Region of a Statement first. Defaults to False. | False |
include_self | bool | If the walk should include the Statement itself. Defaults to True. | True |
Yields:
Type | Description |
---|---|
Statement | Iterator[Statement]: An iterator that yield Statements of Blocks in the Region, in the specified order. |
Source code in src/kirin/ir/nodes/stmt.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
|