Skip to content

Wrap analysis

AddressAttribute dataclass

AddressAttribute(address: Address)

Bases: Attribute


              flowchart TD
              bloqade.squin.rewrite.wrap_analysis.AddressAttribute[AddressAttribute]

              

              click bloqade.squin.rewrite.wrap_analysis.AddressAttribute href "" "bloqade.squin.rewrite.wrap_analysis.AddressAttribute"
            

IR attribute carrying an address-analysis result.

__hash__

__hash__() -> int

Return a hash based on the wrapped address.

Source code in .venv/lib/python3.12/site-packages/bloqade/squin/rewrite/wrap_analysis.py
23
24
25
26
def __hash__(self) -> int:
    """Return a hash based on the wrapped address."""

    return hash((type(self.address), repr(self.address)))

print_impl

print_impl(printer: Printer) -> None

Print the wrapped address.

Source code in .venv/lib/python3.12/site-packages/bloqade/squin/rewrite/wrap_analysis.py
28
29
30
31
def print_impl(self, printer: Printer) -> None:
    """Print the wrapped address."""

    printer.print(self.address)

WrapAddressAnalysis dataclass

WrapAddressAnalysis(
    address_analysis: dict[SSAValue, Address],
)

Bases: WrapAnalysis


              flowchart TD
              bloqade.squin.rewrite.wrap_analysis.WrapAddressAnalysis[WrapAddressAnalysis]
              bloqade.squin.rewrite.wrap_analysis.WrapAnalysis[WrapAnalysis]

                              bloqade.squin.rewrite.wrap_analysis.WrapAnalysis --> bloqade.squin.rewrite.wrap_analysis.WrapAddressAnalysis
                


              click bloqade.squin.rewrite.wrap_analysis.WrapAddressAnalysis href "" "bloqade.squin.rewrite.wrap_analysis.WrapAddressAnalysis"
              click bloqade.squin.rewrite.wrap_analysis.WrapAnalysis href "" "bloqade.squin.rewrite.wrap_analysis.WrapAnalysis"
            

Wrap address-analysis results into SSA value hints.

wrap

wrap(value: SSAValue) -> bool

Attach an address hint to a value when analysis produced one.

Source code in .venv/lib/python3.12/site-packages/bloqade/squin/rewrite/wrap_analysis.py
63
64
65
66
67
68
69
70
71
72
73
74
def wrap(self, value: ir.SSAValue) -> bool:
    """Attach an address hint to a value when analysis produced one."""

    address_analysis_result = self.address_analysis.get(value)
    if address_analysis_result is None:
        return False

    if value.hints.get("address") is not None:
        return False

    value.hints["address"] = AddressAttribute(address_analysis_result)
    return True

WrapAnalysis dataclass

WrapAnalysis()

Bases: RewriteRule


              flowchart TD
              bloqade.squin.rewrite.wrap_analysis.WrapAnalysis[WrapAnalysis]

              

              click bloqade.squin.rewrite.wrap_analysis.WrapAnalysis href "" "bloqade.squin.rewrite.wrap_analysis.WrapAnalysis"
            

Base rewrite rule that wraps analysis data onto SSA values.

rewrite_Block

rewrite_Block(node: Block) -> RewriteResult

Wrap block arguments.

Source code in .venv/lib/python3.12/site-packages/bloqade/squin/rewrite/wrap_analysis.py
44
45
46
47
48
def rewrite_Block(self, node: ir.Block) -> RewriteResult:
    """Wrap block arguments."""

    has_done_something = any(self.wrap(arg) for arg in node.args)
    return RewriteResult(has_done_something=has_done_something)

rewrite_Statement

rewrite_Statement(node: Statement) -> RewriteResult

Wrap statement results.

Source code in .venv/lib/python3.12/site-packages/bloqade/squin/rewrite/wrap_analysis.py
50
51
52
53
54
def rewrite_Statement(self, node: ir.Statement) -> RewriteResult:
    """Wrap statement results."""

    has_done_something = any(self.wrap(result) for result in node.results)
    return RewriteResult(has_done_something=has_done_something)

wrap abstractmethod

wrap(value: SSAValue) -> bool

Wrap one SSA value and report whether it changed.

Source code in .venv/lib/python3.12/site-packages/bloqade/squin/rewrite/wrap_analysis.py
38
39
40
41
42
@abstractmethod
def wrap(self, value: ir.SSAValue) -> bool:
    """Wrap one SSA value and report whether it changed."""

    return False