Skip to content

IRNode

IRNode dataclass

Bases: ABC

Source code in xdsl/ir/core.py
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
@dataclass(init=False)
class IRNode(ABC):
    def is_ancestor(self, op: IRNode) -> bool:
        "Returns true if the IRNode is an ancestor of another IRNode."
        if op is self:
            return True
        if (parent := op.parent_node) is None:
            return False
        return self.is_ancestor(parent)

    def get_toplevel_object(self) -> IRNode:
        """Get the operation, block, or region ancestor that has no parents."""
        if (parent := self.parent_node) is None:
            return self
        return parent.get_toplevel_object()

    def is_structurally_equivalent(
        self,
        other: IRNode,
        context: dict[IRNode | SSAValue, IRNode | SSAValue] | None = None,
    ) -> bool:
        """Check if two IR nodes are structurally equivalent."""
        ...

    @property
    @abstractmethod
    def parent_node(self) -> IRNode | None: ...

    @abstractmethod
    def __eq__(self, other: object) -> bool: ...

    @abstractmethod
    def __hash__(self) -> int: ...

is_ancestor(op: IRNode) -> bool

Returns true if the IRNode is an ancestor of another IRNode.

Source code in xdsl/ir/core.py
643
644
645
646
647
648
649
def is_ancestor(self, op: IRNode) -> bool:
    "Returns true if the IRNode is an ancestor of another IRNode."
    if op is self:
        return True
    if (parent := op.parent_node) is None:
        return False
    return self.is_ancestor(parent)

get_toplevel_object() -> IRNode

Get the operation, block, or region ancestor that has no parents.

Source code in xdsl/ir/core.py
651
652
653
654
655
def get_toplevel_object(self) -> IRNode:
    """Get the operation, block, or region ancestor that has no parents."""
    if (parent := self.parent_node) is None:
        return self
    return parent.get_toplevel_object()

is_structurally_equivalent(other: IRNode, context: dict[IRNode | SSAValue, IRNode | SSAValue] | None = None) -> bool

Check if two IR nodes are structurally equivalent.

Source code in xdsl/ir/core.py
657
658
659
660
661
662
663
def is_structurally_equivalent(
    self,
    other: IRNode,
    context: dict[IRNode | SSAValue, IRNode | SSAValue] | None = None,
) -> bool:
    """Check if two IR nodes are structurally equivalent."""
    ...