Base
IRNode dataclass
IRNode()
Bases: Generic[ParentType]
, ABC
, Printable
Base class for all IR nodes. All IR nodes are hashable and can be compared for equality. The hash of an IR node is the same as the id of the object.
Pretty Printing
This object is pretty printable via .print()
method.
parent_node abstractmethod
property
writable
parent_node: ParentType | None
Parent node of the current node.
attach
attach(parent: ParentType) -> None
Attach the current node to the parent node.
Source code in src/kirin/ir/nodes/base.py
80 81 82 83 84 85 86 87 88 |
|
delete abstractmethod
delete(safe: bool = True) -> None
Delete the current node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
safe | bool | If True, check if the node has any references before deleting. | True |
Source code in src/kirin/ir/nodes/base.py
100 101 102 103 104 105 106 107 |
|
detach abstractmethod
detach() -> None
Detach the current node from the parent node.
Source code in src/kirin/ir/nodes/base.py
90 91 92 93 |
|
drop_all_references abstractmethod
drop_all_references() -> None
Drop all references to other nodes.
Source code in src/kirin/ir/nodes/base.py
95 96 97 98 |
|
get_root
get_root() -> IRNode
Get the root node of the current node.
Source code in src/kirin/ir/nodes/base.py
55 56 57 58 59 |
|
is_ancestor
is_ancestor(op: IRNode) -> bool
Check if the given node is an ancestor of the current node.
Source code in src/kirin/ir/nodes/base.py
47 48 49 50 51 52 53 |
|
is_equal
is_equal(other: IRNode, context: dict = {}) -> bool
Check if the current node is equal to the other node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | IRNode | The other node to compare. | required |
context | dict | The context to store the visited nodes. Defaults to {}. | {} |
Returns:
Type | Description |
---|---|
bool | True if the nodes are equal, False otherwise. |
Note
This method is not the same as the ==
operator. It checks for structural equality rather than identity. To change the behavior of structural equality, override the is_structurally_equal
method.
Source code in src/kirin/ir/nodes/base.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
is_structurally_equal abstractmethod
is_structurally_equal(
other: Self,
context: (
dict[IRNode | SSAValue, IRNode | SSAValue] | None
) = None,
) -> bool
Check if the current node is structurally equal to the other node.
Note
This method is for tweaking the behavior of structural equality. To check if two nodes are structurally equal, use the is_equal
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | Self | The other node to compare. | required |
context | dict[IRNode | SSAValue, IRNode | SSAValue] | None | The context to store the visited nodes. | None |
Returns:
Type | Description |
---|---|
bool | True if the nodes are structurally equal, False otherwise. |
Source code in src/kirin/ir/nodes/base.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
verify abstractmethod
verify() -> None
run mandatory validation checks. This is not same as verify_type, which may be optional.
Source code in src/kirin/ir/nodes/base.py
144 145 146 147 |
|
verify_type abstractmethod
verify_type() -> None
verify the type of the node.
Source code in src/kirin/ir/nodes/base.py
149 150 151 152 |
|