Skip to content

Call Graph

CallGraph dataclass

CallGraph(mt: ir.Method)

Bases: Printable

Call graph for a given ir.Method.

This class implements the kirin.graph.Graph protocol.

Pretty Printing

This object is pretty printable via .print() method.

Source code in src/kirin/analysis/callgraph.py
26
27
28
29
def __init__(self, mt: ir.Method):
    self.defs = {}
    self.backedges = {}
    self.__build(mt)

backedges class-attribute instance-attribute

backedges: dict[str, set[str]] = {}

Mapping from symbol names to backedges.

defs class-attribute instance-attribute

defs: dict[str, Method] = {}

Mapping from symbol names to methods.

get_edges

get_edges() -> Iterable[tuple[str, str]]

Get the edges of the call graph.

Source code in src/kirin/analysis/callgraph.py
43
44
45
46
47
def get_edges(self) -> Iterable[tuple[str, str]]:
    """Get the edges of the call graph."""
    for node, neighbors in self.backedges.items():
        for neighbor in neighbors:
            yield node, neighbor

get_neighbors

get_neighbors(node: str) -> Iterable[str]

Get the neighbors of a node in the call graph.

Source code in src/kirin/analysis/callgraph.py
39
40
41
def get_neighbors(self, node: str) -> Iterable[str]:
    """Get the neighbors of a node in the call graph."""
    return self.backedges.get(node, ())

get_nodes

get_nodes() -> Iterable[str]

Get the nodes of the call graph.

Source code in src/kirin/analysis/callgraph.py
49
50
51
def get_nodes(self) -> Iterable[str]:
    """Get the nodes of the call graph."""
    return self.defs.keys()