Passes

Passes that belong to a single dialect are documented on that dialect’s page: QC, QCO, and QTensor. The remaining passes are documented here.

Shared Passes

The following passes are not tied to a single dialect.

-drop-global-phases

Discard final-program QC and QCO global phases

Erases direct global phases in the function marked mqt.entry_point, including its classical execution paths. Phases in helper functions and quantum modifier bodies are retained: they can become observable relative phases under coherent control or non-integer powers. Modules without an entry point are unchanged.

This pass preserves measurement probabilities, not exact statevectors or unitaries. Run it only when the final program’s global phase is irrelevant. It does not remove angle producers; subsequent dead-code elimination may remove unused pure computations. Normalize modifiers separately to expose further disposable phases while retaining relative phases.

-legalize-control-flow

Adapt SCF control flow to the selected execution format

Uses an explicit payload-spec attribute when set, otherwise reads mqt.target_env. Retains covered SCF branches and loops, lowers unsupported index switches to nested forward branches when possible, and rejects unsupported residual control flow. Loop bounds and steps must be literal constants when the execution format requires a known trip count. Switch expansion respects the forward-branching depth limit and a maximum generated nesting depth of 256.

Run after constant propagation and cleanup. For QCO programs, use legalize-qco-control-flow, which also checks quantum state and handles QCO branches.

Options

-payload-spec : Explicit #mqt.payload_spec; defaults to mqt.target_env.

-lower-quantum-modifiers

Lower quantum modifiers to supported gate forms

Lowers nested controls, inverses and supported powers, preserving controlled relative phase and folding generated arithmetic. Fixed single-qubit QCO gates support runtime powers; other powers require constant parameters. Unsupported powers remain for the consuming conversion to diagnose.

Run after inlining and modifier unrolling to prepare gates for conversion. Adjacent-gate optimization and CFG cleanup are separate passes.

-normalize-global-phases

Normalize scoped QC and QCO global phases

Combines direct qc.gphase and qco.gphase operations into at most one operation per basic block, placed at the last phase contribution. Nested regions are normalized independently, except power subtrees, which remain unchanged: phase rounding can be amplified by a large exponent.

A normalized phase is moved out of inv, negating its angle. A phase in a ctrl body becomes a relative phase on the control register: p for one control or a smaller controlled p for multiple controls. Eager classical computations in verified modifier bodies move once, in source order, before the outermost enclosing inv or ctrl.

Constant angles are reduced modulo 2π. Symbolic sums are balanced and reduced with 2 * atan(tan(angle / 2)) to keep runtime phases in range. Function, CFG, structured-control-flow, and unknown region boundaries are preserved. The pass does not scan an enclosing module from individual rewrite patterns.

-promote-classical-memory

Promote local classical memory to SSA values

Folds access indices, splits local allocations with SROA, and promotes supported loads and stores with Mem2Reg. Local CBit registers support up to 256 bits with static accesses. Packed reads support up to 64 bits; wider reads are expanded at their snapshot point when all reads of the register feed constant comparisons. Escaping registers retain storage.

Modules without promotable or destructurable allocations are left unchanged. Run again after static loop expansion to expose constant-index accesses.

-remove-unused-qubits

Remove unused quantum allocation and release pairs

Removes unused QC and QCO qubits and QTensor registers. Gate-set targets retain their program qubits. Run after canonicalization and before device placement to avoid counting idle allocations against device capacity. Register shrinking is handled by the corresponding QC and QTensor passes.

-simplify-classical-control

Propagate known QCO branch conditions

Within each QCO if branch, replaces uses of its condition with the known boolean value. A following canonicalizer folds the exposed expressions and static branches. Run after inlining and again after static loop unrolling.

-simplify-quantum

Simplify quantum gates and modifiers

Eliminates identity gates, cancels inverse pairs, combines rotations and specializes gates and modifiers in QC or QCO programs. Generated arithmetic is folded. Rotation elimination uses an absolute parameter tolerance of 1e-15, not a circuit error bound.

Use this pass when the gate sequence may change. Use canonicalization for classical and structural cleanup. CFG simplification is separate.

-unroll-modifiers

Unroll multi-operation modifiers into single-operation ones

Expands unitary function calls inside quantum modifiers and normalizes exposed global phases before splitting modifiers. Calls outside modifiers remain reusable. Functions marked no_inline remain calls.

Splits ctrl and inv modifiers whose body holds more than one unitary operation into a sequence of modifiers that each hold a single operation. For inv, the order of the operations is reversed. Classical operations of the body are moved in front of the new modifiers.

A pow modifier is only unrolled if its exponent is a compile-time known integer and its operations act on disjoint qubits. Otherwise, pow(r) { a; b } is generally not equivalent to pow(r) { a }; pow(r) { b }: the operations do not commute if they share a qubit, and for a non-integer exponent, the principal branch of the matrix power does not distribute over them. Modifiers nested in a pow body are unrolled either way.

If a modifier cannot be unrolled, the modifier is left untouched. Such modifiers are skipped silently.

QIR Passes

The following passes operate on modules that have already been lowered to the LLVM dialect by the QIR conversions. They prepare such a module for emission as QIR.

-qir-cleanup

Remove redundant QIR runtime bookkeeping.

Removes redundant QIR runtime qubit-array allocation/release pairs that do not contribute to observable behavior, and keeps QIR modules compact.

-set-qir-attributes-and-metadata

Sets the required attributes to the entry point function and adds the required module flags, selecting the minimum required QIR version

Input must already conform to the selected profile. Base uses QIR 2.0; Adaptive requires 2.1 for dynamic resources or runtime arrays. Static resource counts specify the capacity through the highest qubit ID used by a quantum instruction and the highest used result ID. Rejects IDs whose required capacity cannot fit in an unsigned 64-bit integer. Qubit capacity includes static IDs in compiler-marked qubit stores, including packed arguments and registers accessed with runtime indices. Arbitrary external pointer aliases are not inferred. Direct helper arguments and CFG forwarding contribute to resource counts. Capabilities cover all emitted function definitions. Loop exits with unknown measurement dependence require both backward-branch capabilities. Native pointer buffers conservatively require arrays, including static resources.

Options

-use-adaptive : Specifies the profile.