kirin.ir.nodes.stmt.Statement
classStatement¶source
kirin.ir.nodes.stmt.Statement
Bases: IRNode['Block']
The Statement is an instruction in the IR
Signature
class 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)!!! note “Pretty Printing” This object is pretty printable via .print() method.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
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 |
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
IS_STATEMENT | bool | True | |
name | str | required | |
dialect | Dialect | None | field(default=None, init=False, repr=False) | |
traits | frozenset[Trait['Statement']] | frozenset() | |
successors | list[Block] | list(successors) | |
attributes | dict[str, Attribute] | dict(attributes) | |
parent | Block | None | None | |
source | SourceInfo | None | source | The source information of the Statement for debugging/stacktracing. |
AttributeType | — | TypeVar('AttributeType', bound=Attribute) | |
TraitType | — | TypeVar('TraitType', bound=(Trait['Statement'])) |
propertyparent_stmt¶source
kirin.ir.nodes.stmt.Statement.parent_stmt
parent_stmt: Statement | NoneGet the parent statement.
Returns
Statement | NoneThe parent statement.
propertyparent_node¶source
kirin.ir.nodes.stmt.Statement.parent_node
propertyparent_region¶source
kirin.ir.nodes.stmt.Statement.parent_region
propertyparent_block¶source
kirin.ir.nodes.stmt.Statement.parent_block
propertynext_stmt¶source
kirin.ir.nodes.stmt.Statement.next_stmt
propertyprev_stmt¶source
kirin.ir.nodes.stmt.Statement.prev_stmt
methodinsert_after¶source
kirin.ir.nodes.stmt.Statement.insert_after
def insert_after(stmt: Statement) -> NoneInsert the current Statement after the input Statement.
Parameters
| Name | Type | Description |
|---|---|---|
stmt | Statement | Input Statement. |
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)methodinsert_before¶source
kirin.ir.nodes.stmt.Statement.insert_before
def insert_before(stmt: Statement) -> NoneInsert the current Statement before the input Statement.
Parameters
| Name | Type | Description |
|---|---|---|
stmt | Statement | Input Statement. |
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)methodreplace_by¶source
kirin.ir.nodes.stmt.Statement.replace_by
def replace_by(stmt: Statement) -> NoneReplace the current Statement by the input Statement.
Parameters
| Name | Type | Description |
|---|---|---|
stmt | Statement | Input Statement. |
propertyargs¶source
kirin.ir.nodes.stmt.Statement.args
args: ArgumentListGet the arguments of the Statement.
Returns
ArgumentListArgumentList: The arguments View of the Statement.
propertyresults¶source
kirin.ir.nodes.stmt.Statement.results
results: ResultListGet the result values of the Statement.
Returns
ResultListResultList: The result values View of the Statement.
propertyregions¶source
kirin.ir.nodes.stmt.Statement.regions
regions: list[Region]Get a list of regions of the Statement.
Returns
list[Region]The list of regions of the Statement.
methoddrop_all_references¶source
kirin.ir.nodes.stmt.Statement.drop_all_references
def drop_all_references() -> NoneRemove all the dependency that reference/uses this Statement.
sourcemethoddelete¶source
kirin.ir.nodes.stmt.Statement.delete
def delete(safe: bool = True) -> NoneDelete the Statement completely from the IR graph.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
safe | bool | True | If True, raise error if there is anything that still reference components in the Statement. Defaults to True. |
Note
This method will detach + remove references of the Statement.
sourcemethoddetach¶source
kirin.ir.nodes.stmt.Statement.detach
methodfrom_stmt¶source
kirin.ir.nodes.stmt.Statement.from_stmt
Signature
def 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) -> SelfCreate a similar Statement with new ResultValue and without
attaching to any parent block. This still references to the old successor
and regions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
other | Statement | required | |
args | Sequence[SSAValue] | None | None | |
regions | list[Region] | None | None | |
successors | list[Block] | None | None | |
attributes | dict[str, Attribute] | None | None |
Returns
Self
methodwalk¶source
kirin.ir.nodes.stmt.Statement.walk
Signature
def walk(*, reverse: bool = False, region_first: bool = False, include_self: bool = True) -> Iterator[Statement]Traversal the Statements of Regions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
reverse | bool | False | If walk in the reversed manner. Defaults to False. |
region_first | bool | False | If the walk should go through the Statement first or the Region of a Statement first. Defaults to False. |
include_self | bool | True | If the walk should include the Statement itself. Defaults to True. |
Returns
Iterator[Statement]
Yields
Statement — Iterator[Statement]: An iterator that yield Statements of Blocks in the Region, in the specified order.
methodis_structurally_equal¶source
kirin.ir.nodes.stmt.Statement.is_structurally_equal
Signature
def is_structurally_equal(other: IRNode, context: dict[IRNode | SSAValue, IRNode | SSAValue] | None = None) -> boolCheck if the Statement is structurally equal to another Statement.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
other | IRNode | required | The other node to compare with. |
context | dict[IRNode | SSAValue, IRNode | SSAValue] | None | None | A map of IRNode/SSAValue to hint that they are equivalent so the check will treat them as equivalent. Defaults to None. |
Returns
boolbool: True if the IRNode is structurally equal to the other.
methodprint_impl¶source
kirin.ir.nodes.stmt.Statement.print_impl
methodget_attribute¶source
kirin.ir.nodes.stmt.Statement.get_attribute
Signature
def get_attribute(key: str, default: Attribute | None = None) -> Attribute | NoneGet the attribute or property of the Statement.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | str | required | The key of the attribute or property. |
default | Attribute | None | None |
Returns
Attribute | NoneThe attribute or property of the Statement.
methodget_attribute_casted¶source
kirin.ir.nodes.stmt.Statement.get_attribute_casted
Signature
def get_attribute_casted(key: str, expect: type[AttributeType], default: AttributeType | None = None) -> AttributeType | NoneGet the attribute or property of the Statement.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | str | required | The key of the attribute or property. |
expect | type[AttributeType] | required | The expected type of the attribute. |
default | AttributeType | None | None | The default value to return if the attribute is not found. Defaults to None. |
Returns
AttributeType | NoneAttributeType: The attribute or property of the Statement.
methodget_attribute_typed¶source
kirin.ir.nodes.stmt.Statement.get_attribute_typed
Signature
def get_attribute_typed(key: str, expect: type[AttributeType], default: AttributeType | None = None) -> AttributeType | NoneGet the attribute or property of the Statement.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
key | str | required | The key of the attribute or property. |
expect | type[AttributeType] | required | The expected type of the attribute. |
default | AttributeType | None | None | The default value to return if the attribute is not found. Defaults to None. |
Returns
AttributeType | NoneAttributeType: The attribute or property of the Statement.
methodhas_trait¶source
kirin.ir.nodes.stmt.Statement.has_trait
def has_trait(trait_type: type[Trait['Statement']]) -> boolCheck if the Statement has a specific trait.
Parameters
| Name | Type | Description |
|---|---|---|
trait_type | type[Trait['Statement']] | The type of trait to check for. |
Returns
boolbool: True if the class has the specified trait, False otherwise.
methodget_trait¶source
kirin.ir.nodes.stmt.Statement.get_trait
def get_trait(trait: type[TraitType]) -> TraitType | NoneGet the trait of the Statement.
Parameters
| Name | Type | Description |
|---|---|---|
trait | type[TraitType] |
Returns
TraitType | None
methodget_present_trait¶source
kirin.ir.nodes.stmt.Statement.get_present_trait
def get_present_trait(trait: type[TraitType]) -> TraitTypeJust like get_trait, but expects the trait to be there. Useful for linter checks, when you know the trait is present.
Parameters
| Name | Type | Description |
|---|---|---|
trait | type[TraitType] |
Returns
TraitType
methodexpect_one_result¶source
kirin.ir.nodes.stmt.Statement.expect_one_result
def expect_one_result() -> ResultValueCheck if the statement contain only one result, and return it
Returns
ResultValue
methodcheck_type¶source
kirin.ir.nodes.stmt.Statement.check_type
def check_type() -> NoneCheck 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.
methodcheck¶source
kirin.ir.nodes.stmt.Statement.check
def check() -> NoneCheck 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.
methodverify¶source
kirin.ir.nodes.stmt.Statement.verify
def verify() -> Nonemethodverify_type¶source
kirin.ir.nodes.stmt.Statement.verify_type
def verify_type() -> NoneVerify the type of the statement.
Note
This API should be called after all the types are figured out (by typeinfer)
source