Skip to content

Forward Dataflow

Forward dataclass

Forward(
    dialects: ir.DialectGroup,
    *,
    max_depth: int = 800,
    max_python_recursion_depth: int = 131072,
    debug: bool = False
)

Bases: ForwardExtra[ForwardFrame[LatticeType], LatticeType], ABC

Forward dataflow analysis.

This is the base class for forward dataflow analysis. If your analysis requires extra information per frame, you should subclass ForwardExtra instead.

initialize_frame

initialize_frame(
    node: ir.Statement, *, has_parent_access: bool = False
) -> ForwardFrame[LatticeType]

Initialize a new call frame for the given callable node.

Source code in src/kirin/analysis/forward.py
66
67
68
69
def initialize_frame(
    self, node: ir.Statement, *, has_parent_access: bool = False
) -> ForwardFrame[LatticeType]:
    return ForwardFrame(node, has_parent_access=has_parent_access)

ForwardExtra dataclass

ForwardExtra(
    dialects: ir.DialectGroup,
    *,
    max_depth: int = 800,
    max_python_recursion_depth: int = 131072,
    debug: bool = False
)

Bases: AbstractInterpreter[FrameType, LatticeType], ABC

Forward dataflow analysis but with custom frame for extra information/state per call frame.

Parameters:

Name Type Description Default
FrameType

The type of the frame used for the analysis.

required
LatticeType

The type of the lattice used for the analysis.

required

method_self abstractmethod

method_self(method: ir.Method) -> LatticeType

Return the self value for the given method.

Source code in src/kirin/analysis/forward.py
51
52
53
54
@abstractmethod
def method_self(self, method: ir.Method) -> LatticeType:
    """Return the self value for the given method."""
    ...

ForwardFrame dataclass

ForwardFrame(
    code: Statement,
    worklist: WorkList[Successor[ResultType]] = WorkList(),
    visited: dict[
        ir.Block, set[Successor[ResultType]]
    ] = dict(),
    *,
    parent: Self | None = None,
    has_parent_access: bool = False,
    lineno_offset: int = 0,
    entries: dict[SSAValue, ValueType] = dict()
)

Bases: AbstractFrame[LatticeType]

set_values

set_values(
    keys: Iterable[ir.SSAValue],
    values: Iterable[LatticeType],
) -> None

Set the values of the given keys. This is a convenience method to set multiple values at once.

Parameters:

Name Type Description Default
keys(Iterable[KeyType])

The keys to set the values for.

required
values(Iterable[ValueType])

The values.

required
Source code in src/kirin/analysis/forward.py
15
16
17
18
19
20
21
22
def set_values(
    self, keys: Iterable[ir.SSAValue], values: Iterable[LatticeType]
) -> None:
    for ssa_value, result in zip(keys, values):
        if ssa_value in self.entries:
            self.entries[ssa_value] = self.entries[ssa_value].join(result)
        else:
            self.entries[ssa_value] = result