Skip to content

SSA values

BlockArgument dataclass

BlockArgument(
    block: Block,
    index: int,
    type: TypeAttribute = AnyType(),
)

Bases: SSAValue

SSAValue that is an argument to a Block.

Source code in src/kirin/ir/ssa.py
143
144
145
146
147
148
149
def __init__(
    self, block: Block, index: int, type: TypeAttribute = AnyType()
) -> None:
    super().__init__()
    self.type = type
    self.block = block
    self.index = index

block class-attribute instance-attribute

block: Block = block

The block that this argument belongs to.

index class-attribute instance-attribute

index: int = index

The index of this argument in the block's argument list.

owner property

owner: Block

The object that owns this SSA value.

type instance-attribute

type = type

The type of this SSA value.

delete

delete(safe: bool = True) -> None

Delete this SSA value. If safe is True, raise an error if there are uses.

Source code in src/kirin/ir/ssa.py
155
156
def delete(self, safe: bool = True) -> None:
    self.block.args.delete(self, safe=safe)

DeletedSSAValue dataclass

DeletedSSAValue(value: SSAValue)

Bases: SSAValue

Source code in src/kirin/ir/ssa.py
178
179
180
181
def __init__(self, value: SSAValue) -> None:
    super().__init__()
    self.value = value
    self.type = value.type

owner property

owner: Statement | Block

The object that owns this SSA value.

type instance-attribute

type = type

The type of this SSA value.

ResultValue dataclass

ResultValue(
    stmt: Statement,
    index: int,
    type: TypeAttribute | None = None,
)

Bases: SSAValue

SSAValue that is a result of a Statement.

Source code in src/kirin/ir/ssa.py
106
107
108
109
110
111
112
def __init__(
    self, stmt: Statement, index: int, type: TypeAttribute | None = None
) -> None:
    super().__init__()
    self.type = type or AnyType()
    self.stmt = stmt
    self.index = index

index class-attribute instance-attribute

index: int = index

The index of this value in the statement's result list.

owner property

owner: Statement

The object that owns this SSA value.

stmt class-attribute instance-attribute

stmt: Statement = stmt

The statement that this value is a result of.

type instance-attribute

type = type or AnyType()

The type of this SSA value.

SSAValue dataclass

SSAValue()

Bases: ABC, Printable

Base class for all SSA values in the IR.

hints class-attribute instance-attribute

hints: dict[str, Attribute] = field(
    default_factory=dict, init=False, repr=False
)

Hints for this SSA value.

name property writable

name: str | None

The name of this SSA value.

name_pattern class-attribute

name_pattern: Pattern[str] = compile(
    "([A-Za-z_$.-][\\w$.-]*)"
)

The pattern that the name of this SSA value must match.

owner abstractmethod property

owner: Statement | Block

The object that owns this SSA value.

type class-attribute instance-attribute

type: TypeAttribute = field(
    default_factory=AnyType, init=False, repr=True
)

The type of this SSA value.

uses class-attribute instance-attribute

uses: set[Use] = field(
    init=False, default_factory=set, repr=False
)

The uses of this SSA value.

add_use

add_use(use: Use) -> Self

Add a use to this SSA value.

Source code in src/kirin/ir/ssa.py
60
61
62
63
def add_use(self, use: Use) -> Self:
    """Add a use to this SSA value."""
    self.uses.add(use)
    return self

delete

delete(safe: bool = True) -> None

Delete this SSA value. If safe is True, raise an error if there are uses.

Source code in src/kirin/ir/ssa.py
84
85
86
87
88
def delete(self, safe: bool = True) -> None:
    """Delete this SSA value. If `safe` is `True`, raise an error if there are uses."""
    if safe and len(self.uses) > 0:
        raise ValueError("Cannot delete SSA value with uses")
    self.replace_by(DeletedSSAValue(self))

remove_use

remove_use(use: Use) -> Self

Remove a use from this SSA value.

Source code in src/kirin/ir/ssa.py
65
66
67
68
69
70
71
def remove_use(self, use: Use) -> Self:
    """Remove a use from this SSA value."""
    # print(use)
    # assert use in self.uses, "Use not found"
    if use in self.uses:
        self.uses.remove(use)
    return self

replace_by

replace_by(other: SSAValue) -> None

Replace this SSA value with another SSA value. Update all uses.

Source code in src/kirin/ir/ssa.py
73
74
75
76
77
78
79
80
81
def replace_by(self, other: SSAValue) -> None:
    """Replace this SSA value with another SSA value. Update all uses."""
    for use in self.uses.copy():
        use.stmt.args[use.index] = other

    if other.name is None and self.name is not None:
        other.name = self.name

    assert len(self.uses) == 0, "Uses not empty"

TestValue dataclass

TestValue(type: TypeAttribute = AnyType())

Bases: SSAValue

Test SSAValue for testing IR construction.

Source code in src/kirin/ir/ssa.py
198
199
200
def __init__(self, type: TypeAttribute = AnyType()) -> None:
    super().__init__()
    self.type = type

owner property

owner: Statement | Block

The object that owns this SSA value.

type instance-attribute

type = type

The type of this SSA value.