Conversions

Classical Register Conversion

-convert-cbit-to-memref

Lower CBit registers to memrefs

This pass explicitly lowers CBit register types and operations to memrefs. A zero-initialized register becomes an allocation followed by a loop that stores false to each element. An undefined register becomes an allocation only. The pass also converts function signatures, calls, returns, branches, and structural SCF operation types. It does not infer CBit registers from existing memrefs.

Internal Conversions

-qc-to-qco

Convert QC dialect to QCO dialect.

This pass converts QC qubit references to QCO qubit values and threads their state through quantum operations, functions and structured control flow. Control flow must use structured SCF operations. Operations with block successors, including cf.br, cf.cond_br, and cf.switch, are diagnosed before conversion. Quantum allocations must be in a function’s entry block. Nested regions may use outer allocations through the supported SCF operations. Private helpers may borrow fixed-size rank-one qubit memrefs with identity layout and default memory space. They become qubit tensors. Updated scalar qubits and complete tensors are appended to ordinary results in argument order. Duplicate register operands, register/element aliases, and consumption or explicit returns of borrowed registers are diagnosed before conversion. Register slots retain their qubit identities. Loads refer to stable slots; identity stores are erased. Local fixed-size registers with constant-index accesses confined to one block can keep accessed slots in scalar SSA form until deallocation. Registers that escape or have other accesses use per-operation extraction and reinsertion. Entry-block physical reference buffers may be initialized once with distinct static qubits and become tensors of those qubits. Other reference stores are unsupported. Loaded references remain valid across helper calls. Bounds, disjoint runtime operands, and matching dynamic store indices are program preconditions; this pass diagnoses known violations without inserting runtime checks. See the shared quantum resource rules. Static qubit references are hoisted and coalesced when needed. General classical folding and common subexpression elimination are not guaranteed by this conversion; use the corresponding simplification passes when needed.

-qco-to-qc

Convert QCO dialect to QC dialect.

Convert QCO qubit values to QC references and QTensor registers to memrefs. Scalar qubits and fixed-size rank-one qubit-tensor arguments become in-place references; each function must return its quantum arguments as a positional suffix. Register helpers must be private. Registers must be complete when passed through calls or structured regions, returned, or dynamically freed. Extracted qubits may be passed to scalar helpers while their remaining tensor stays in the caller. Transferring the register itself is unsupported. Other results remain explicit, including qubits created by a function.

Before rewriting, prove that quantum values yielded by modifiers, branches, and loops correspond positionally to their region arguments. Reject wire permutations and changes to quantum loop-state counts or types. Classical loop state can change type in scf.while. Extraction becomes memref.load; reinsertion preserves the same slot and needs no store. Extraction and insertion indices must be the same value, equal constants, or expressions whose equality MLIR value-bounds analysis can prove. Unproved equalities are rejected before rewriting. See the shared quantum resource rules.

Determine the module’s allocation mode before converting any function. Dynamic qubit sinks become deallocations; static qubit sinks are removed. Mixing static and dynamic allocation roots is unsupported. Tensors of existing qubits must contain static qubits, assigned by placement, and use local reference buffers. Static tensor release does not release physical qubits. Dynamic tensors must restore every extracted slot before region exit or deallocation. Unsupported lifetimes fail before rewriting.

jeff Conversions

-qco-to-jeff

Convert QCO operations to jeff operations

This pass converts all operations from the QCO dialect to their equivalent operations in the jeff dialect. It ensures that the returned module is a valid jeff module that can be serialized.

Defined single-block functions and their calls are preserved. Mutable classical-register arguments in helpers are not supported. Unitary calls inside quantum modifiers must be expanded with unroll-modifiers first. Each remaining modifier must contain one unitary using all body arguments in order. Canonicalize or unroll modifiers outside this normal form before conversion.

Fixed-size contiguous classical stack arrays become flat jeff arrays in row-major order. Views and copies are normalized before conversion; residual runtime safety assertions are rejected. Array lengths must fit signed i32. Mutable array arguments in helpers remain unsupported.

qco.static exports as jeff.qubit_alloc; static site indices are not preserved. Exchange programs before device mapping.

-jeff-to-qco

Convert jeff operations to QCO operations

This pass converts all operations from the jeff dialect to their equivalent operations in the QCO dialect. It ensures that the returned module is a valid QCO module.

Note that this pass is still in development as QCO and jeff do not have full feature parity yet.

Known limitations:

  • Only specific CustomOps are currently supported

  • Only specific PPROps are currently supported

  • The entry function must have a single block ending in func.return

  • Mutable classical-register arguments in helper functions are not supported

  • Live old or duplicate array operands across mutating control-flow regions require numeric literals or zero arrays

Static classical arrays use internal reference storage. Non-Boolean arrays become stack memrefs in programs without non-Boolean array arguments or results. Programs with these interfaces retain tensor value semantics; positive-width Boolean arrays use CBit registers. Updates reuse storage unless an earlier array value remains live. Loop-carried stack arrays must keep their incoming storage.

Function definitions, results, and calls are preserved. Only the designated entry point remains public; helper functions become private. Calls remain generic func.call operations because jeff does not specify function unitarity.

QIR Conversions

-qc-to-qir-base

Lower the QC dialect to the LLVM dialect compliant with the QIR Base Profile

Lower supported QC operations to QIR Base Profile runtime calls and LLVM dialect operations. Attach QIR attributes and module flags, then validate the emitted requirements against a matching attached target payload.

Requirements:

  • Stores to returned CBit registers must write measurement results at indices defined by constant operations. Constant expressions must be folded before conversion; constant operations may move before the measurement. The store and measurement must share a block. Intervening effects must be limited to quantum resources or stores to distinct constant indices of the same register.

  • Input is a valid module in the QC dialect.

  • The entry function must be marked with mqt.entry_point and have no arguments. Bind program parameters before conversion.

  • Measurements and CBit allocations must be in the entry function. Returns may contain only direct measurements and direct CBit allocations. Other scalar program outputs are not supported. A returned scalar measurement can share register storage only when constant indices prove that other stores cannot overwrite it.

  • The input entry function must consist of a single block.

  • The program must have straight-line control flow (i.e., Base Profile QIR).

  • A measured qubit must not be used by another quantum instruction, including another measurement. Gates on independent qubits may follow measurements in the input.

  • Explicit static qubit IDs cannot be mixed with qubit allocations.

  • Qubit-register loads require constant, in-bounds indices into statically sized allocations. Register aliases must be resolved before conversion.

Behavior:

  • Outputs retain return order and repetitions. Every record has a unique label.

  • The entry function returns an i64 zero execution status after output recording.

  • Classical storage and computations must be eliminated before conversion. The compiler preparation pipeline promotes eligible stack arrays to SSA values and unrolls counted loops whose bounds and steps fold to constants, within a budget of one billion cloned body operations. Residual control flow, memory operations, runtime computations, and nonconstant call arguments are rejected.

  • Each QC quantum operation is replaced in place by its QIR call. After validating qubit usage in instruction order, the pass moves terminal measurements to the irreversible operations block.

  • The pass transforms the single-block entry function into four blocks to satisfy QIR Base Profile constraints: 0. Initialization block: Sets up the execution environment and performs required runtime initialization.

    1. Reversible operations block: Contains only void-returning calls to reversible quantum operations.

    2. Irreversible operations block: Contains terminal measurement calls (__quantum__qis__mz__body). Reset operations are not supported.

    3. Epilogue block: Records measurement results and returns from the entry function.

  • Blocks are connected via unconditional branches in the order listed above.

  • Non-quantum dialects are lowered via MLIR’s built-in conversions and checked against the Base Profile instruction subset.

-qc-to-qir-adaptive

Lower the QC dialect to the LLVM dialect compliant with the QIR Adaptive Profile

Lower supported QC operations to QIR Adaptive Profile runtime calls and LLVM dialect operations. Attach QIR attributes and module flags, then validate the emitted requirements against a matching attached target payload.

Requirements:

  • Input is a valid module in the QC dialect.

  • The entry function must be marked with mqt.entry_point, have no arguments, and have a single return. Bind program parameters before conversion.

  • Measurements and CBit allocations must be in the entry function. Returns may contain direct measurements, direct CBit allocations, and Boolean scalar values. Other scalar program outputs are not supported.

Behavior:

  • Outputs retain return order and repetitions. Every record has a unique label. Computed Boolean scalars use Boolean output records without register storage.

  • Returned registers use Result arrays when measurement stores can fuse safely and preserve returned measurement snapshots. Other stores use Boolean storage, including runtime-indexed accesses. Boolean output loads precede all output recording.

  • The entry function returns an i64 zero execution status after output recording.

  • Each QC quantum operation is replaced by a call to the corresponding QIR function in the LLVM dialect.

  • Counted-loop constraints are checked before lowering, including loops generated by classical copies. Programs containing scf.while require unconstrained emitted loop capabilities because QIR classifies loops by data dependence. Target metadata is preserved.

  • Switch constraints are checked before lowering. Switches exceeding those limits lower to conditional branches when the target permits that expansion.

  • Operations from the scf dialect are lowered into the cf dialect before they are lowered to the LLVM dialect.

  • The pass extends the existing block structure of the entry function with an entry block and an epilogue block: 0. Initialization block: Sets up the execution environment and performs required runtime initialization.

    1. Epilogue block: Records measurement results and returns from the entry function. Any blocks in-between have no restrictions regarding their operations as long as they are supported.

  • Quantum releases retain their original control-flow positions.

  • Local qubit-reference buffers support loads, stores, and shape casts without allocating qubits.

  • Measurements use static result IDs, including fixed-width returned Result arrays. Non-output measurements share one reusable scratch ID.

  • Measurement results may be used as classical values to drive conditional branches.

  • Non-quantum dialects are lowered via MLIR’s built-in conversions.

  • Constant classical tensors and element reads are lowered to constant LLVM arrays and loads, including reads with runtime indices. Other classical tensor operations must be lowered before this pass.

  • Statically shaped classical stack memrefs lower to native LLVM arrays, loads, and stores. Classical heap allocation is rejected. These operations require the Adaptive array capability and the stored element types.

  • Classical array indices must be in bounds. No runtime checks are inserted.