qat.experimental.dialect.q1_cf.transforms.linearise_q1_cf module

Linearise a multi-block q1_cf CFG to a single flat q1 block.

q1_cf expresses control flow as a graph: branch terminators carry named successor blocks and per-successor SSA block arguments, with conditions held as register operands plus a predicate attribute. The Q1 processor executes a flat instruction stream whose only block structure is fall-through and whose control transfer is by label. This pass collapses the graph into that flat stream inside each SequenceOp through the following stages:

  1. Statically decided branches fold through const_evaluate() to an unconditional branch, and blocks left unreachable are pruned.

  1. Blocks are kept in producer order. For conditional branches, else is the next block in the layout (fall-through). Other successors are reached via explicit jumps. Each block is assigned a label.

  1. Block arguments are erased by register coalescing. q1_cf requires every forwarded operand to share the register of the successor argument it feeds, so an argument and its incoming values already occupy one register. Erasure is a rename: uses of the argument are redirected to the value from its nearest forward predecessor, and the register itself carries the value across edges.

  2. Each terminator lowers to flat jumps that target labels: an unconditional jump, a cmp/test plus the conditional jump selected by the predicate, or a counted loop.

  3. All blocks inline into one, referenced heads carrying a q1.x.label. A jump to the immediately following label is dropped as a fall-through, and any label that no remaining jump targets is removed as dead. Halts of one terminal state converge to a single Stop*, a clean stop and an illegal error trap being distinct states that cannot. The result is a single block of q1 instructions ending in that halt with no q1_cf residue.

Reference: https://docs.qblox.com/en/main/products/qblox_instruments/q1/index.html

class LineariseQ1CfToQ1Pass

Bases: ModulePass

Lower every q1_cf CFG in the module to a single flat q1 block.

apply(ctx, op)
Return type:

None

name: ClassVar[str] = 'linearise-q1-cf-to-q1'