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:
Statically decided branches fold through
const_evaluate()to an unconditional branch, and blocks left unreachable are pruned.
Blocks are kept in producer order. For conditional branches,
elseis the next block in the layout (fall-through). Other successors are reached via explicit jumps. Each block is assigned a label.
Block arguments are erased by register coalescing.
q1_cfrequires 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.Each terminator lowers to flat jumps that target labels: an unconditional jump, a
cmp/testplus the conditional jump selected by the predicate, or a countedloop.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 singleStop*, a cleanstopand anillegalerror trap being distinct states that cannot. The result is a single block ofq1instructions ending in that halt with noq1_cfresidue.
Reference: https://docs.qblox.com/en/main/products/qblox_instruments/q1/index.html