Skip to content

kirin.ir.nodes.base.IRNode

← Module overview

classIRNodesource

kirin.ir.nodes.base.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.

class IRNode

!!! note “Pretty Printing” This object is pretty printable via .print() method.

Attributes

NameTypeDefaultDescription
sourceSourceInfo | Nonefield(default=None, init=False, repr=False)
IS_REGIONboolFalse
IS_BLOCKboolFalse
IS_STATEMENTboolFalse

methodassert_parentsource

kirin.ir.nodes.base.IRNode.assert_parent

def assert_parent(type_: type[IRNode], parent) -> None

Parameters

NameTypeDescription
type_type[IRNode]
parent—
source

propertyparent_nodesource

kirin.ir.nodes.base.IRNode.parent_node

parent_node: ParentType | None

Parent node of the current node.

source

methodis_ancestorsource

kirin.ir.nodes.base.IRNode.is_ancestor

def is_ancestor(op: IRNode) -> bool

Check if the given node is an ancestor of the current node.

Parameters

NameTypeDescription
opIRNode

Returns

bool

source

methodget_rootsource

kirin.ir.nodes.base.IRNode.get_root

def get_root() -> IRNode

Get the root node of the current node.

Returns

IRNode

source

methodattachsource

kirin.ir.nodes.base.IRNode.attach

def attach(parent: ParentType) -> None

Attach the current node to the parent node.

Parameters

NameTypeDescription
parentParentType
source

methoddetachsource

kirin.ir.nodes.base.IRNode.detach

def detach() -> None

Detach the current node from the parent node.

source

methoddrop_all_referencessource

kirin.ir.nodes.base.IRNode.drop_all_references

def drop_all_references() -> None

Drop all references to other nodes.

source

methoddeletesource

kirin.ir.nodes.base.IRNode.delete

def delete(safe: bool = True) -> None

Delete the current node.

Parameters

NameTypeDefaultDescription
safeboolTrueIf True, check if the node has any references before deleting.
source

methodis_structurally_equalsource

kirin.ir.nodes.base.IRNode.is_structurally_equal

Signature
def is_structurally_equal(other: 'IRNode', 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_structurally_equal method.

Parameters

NameTypeDefaultDescription
other'IRNode'requiredThe other node to compare.
contextdict[IRNode | SSAValue, IRNode | SSAValue] | NoneNoneThe context to store the visited nodes.

Returns

boolTrue if the nodes are structurally equal, False otherwise.

source

methodwalksource

kirin.ir.nodes.base.IRNode.walk

Signature
def walk(*, reverse: bool = False, region_first: bool = False) -> Iterator[Statement]

Parameters

NameTypeDefaultDescription
reverseboolFalse
region_firstboolFalse

Returns

Iterator[Statement]

source

methodprint_implsource

kirin.ir.nodes.base.IRNode.print_impl

def print_impl(printer: Printer) -> None

Parameters

NameTypeDescription
printerPrinter
source

methodverifysource

kirin.ir.nodes.base.IRNode.verify

def verify() -> None

run mandatory validation checks. This is not same as verify_type, which may be optional.

source

methodverify_typesource

kirin.ir.nodes.base.IRNode.verify_type

def verify_type() -> None

verify the type of the node.

source