Skip to content

bloqade.lanes.rewrite.measure_lower.MeasureLower

← Module overview

classMeasureLowersource

bloqade.lanes.rewrite.measure_lower.MeasureLower

Bases: RewriteRule

Lower move.Measure stmts to move.EndMeasure.

class MeasureLower(frame: ForwardFrame[MoveExecution])

Driven by an AtomAnalysis frame: each move.Measure’s future SSA result is looked up in the frame, and the associated MeasureFuture lattice element supplies both the measurement ordinal (measurement_count) and the set of zones actually observed (the keys of results, whose iteration order mirrors insertion order and therefore the original zone order).

The rewrite gives up silently (returns RewriteResult() with has_done_something=False) when:

  1. The frame has no MeasureFuture for the node’s future SSA.
  2. measurement_count on that future != 1 — the move.Measure is not the first/only final measurement in the program.
  3. len(results) on that future != 1 — the measurement spans multiple zones.

Validating these invariants as hard errors is the job of dedicated validation passes that run between dialect transformations; rewrite rules just attempt the rewrite and back off when preconditions aren’t met.

Parameters

NameTypeDescription
frameForwardFrame[MoveExecution]

Attributes

NameTypeDescription
frameForwardFrame[MoveExecution]

methodfrom_methodsource

bloqade.lanes.rewrite.measure_lower.MeasureLower.from_method

def from_method(method: ir.Method, arch_spec) -> MeasureLower

Build a MeasureLower by running AtomAnalysis on the given method.

Stashes the returned ForwardFrame so that rewrite_Statement can look up each move.Measure’s future to get both the measurement ordinal and zone set from the MeasureFuture lattice element.

Parameters

NameTypeDescription
methodir.Method
arch_spec—

Returns

MeasureLower

source

methodrewrite_Statementsource

bloqade.lanes.rewrite.measure_lower.MeasureLower.rewrite_Statement

def rewrite_Statement(node: ir.Statement) -> RewriteResult

Parameters

NameTypeDescription
nodeir.Statement

Returns

RewriteResult

source