Stack move2move
stack_move2move — in-place rewrite from stack_move → multi-dialect IR.
Extends Kirin's RewriteRule with a rewrite_Block handler that walks the block's statements once and, for each stack_move statement, inserts the corresponding target-dialect statement(s) via insert_before and deletes the original. State threading is woven in along the way: move.Load at block start initialises the StateType SSA value, each stateful move.* op consumes the current state and produces a new one, and move.Store + func.Return close out the block.
Follows the same pattern as python/bloqade/lanes/rewrite/state.py's RewriteLoadStore.
RewriteStackMoveToMove
dataclass
RewriteStackMoveToMove(
arch_spec: ArchSpec,
ssa_to_attr: dict[SSAValue, Any] = dict(),
state: SSAValue | None = None,
)
Bases: RewriteRule
flowchart TD
bloqade.lanes.rewrite.stack_move2move.RewriteStackMoveToMove[RewriteStackMoveToMove]
click bloqade.lanes.rewrite.stack_move2move.RewriteStackMoveToMove href "" "bloqade.lanes.rewrite.stack_move2move.RewriteStackMoveToMove"
Rewrite a stack_move block into a multi-dialect block in place.
Constructor args:
- arch_spec: required. AwaitMeasure lowering iterates
arch_spec.yield_zone_locations(zone) for each zone on the
originating move.Measure to emit the GetFutureResult chain that
materialises the 1-D measurement-result array (element order is
defined by the ArchSpec).
Mutable state on the rule instance, carried across the walk: - ssa_to_attr: stack_move SSA → raw Python attribute value (float, int, LocationAddress, LaneAddress, ZoneAddress) for operands that need to be lifted into target-dialect attributes (addresses, rotation angles). SSA-to-attribute can't be expressed through SSA rewiring because attributes aren't SSA values, so we carry an explicit mapping. The value type is Any because the lifted values span heterogeneous scalar and address types. - state: the current StateType SSA value in the target IR.
For SSA-valued outputs (arrays, futures, detectors, observables,
constants that emit py.Constant), we use the Kirin idiom
old_ssa.replace_by(new_ssa) to redirect all uses in place — no
second mapping needed. This matches state.RewriteLoadStore's
next_use.replace_by(current_use) pattern.