QIR

Also known as: Quantum Intermediate Representation

On this page 7

QIR (Quantum Intermediate Representation) is a hardware-agnostic program format in quantum software that expresses quantum programs as LLVM intermediate representation, the same compiler format used by C, C++, Rust and Swift toolchains. It sits between source languages such as Q# or Python SDKs and the hardware backends that execute circuits, so one compiler front end can reach many processors.

Microsoft introduced QIR in 2020, and the specification is now maintained by the QIR Alliance, an industry group under the Linux Foundation. Its central idea is that quantum computing programs increasingly mix quantum gates with classical logic, and LLVM already provides a mature, optimizable representation for that classical part.

How QIR represents a quantum program

QIR does not add new instructions to LLVM. Instead, it represents quantum data with opaque pointer types, %Qubit* and %Result*, and expresses every quantum operation as a call to an externally declared function. A Hadamard gate becomes a call to __quantum__qis__h__body, and a measurement becomes __quantum__qis__mz__body, which writes into a result value.

Because these calls look like ordinary function calls, standard LLVM tools can parse, verify and optimize the classical parts of the program, such as loops, arithmetic and branches. A backend or runtime later supplies the meaning of each quantum function, either by mapping it to native gates or by linking it to a simulator.

The QIR specification groups these functions into named families, summarized below.

ElementPrefix or typeRole
Qubit handle%Qubit*Opaque reference to a physical or virtual qubit
Result handle%Result*Opaque reference to a measurement outcome
Quantum instruction set__quantum__qis__Gates, measurements and resets
Runtime functions__quantum__rt__Output recording, allocation and arrays
Entry point attributesFunction attributesRequired qubits, results and profile name
Main building blocks of a QIR program

Output is written through result recording functions, such as __quantum__rt__result_record_output, so every backend returns measurement data in a predictable format regardless of hardware vendor.

QIR profiles and hardware capabilities

Not every quantum computer can run arbitrary classical code during a circuit. QIR therefore defines profiles, which are restricted subsets of the representation that match what a class of hardware can execute. A compiler targets a profile, and a backend rejects programs that use features outside the profile it supports.

ProfileAllowed featuresTypical hardware fit
Base ProfileStraight-line gates, measurements at the endMost cloud processors without real-time control
Adaptive ProfileMid-circuit measurement, conditional branches, limited classical arithmeticTrapped-ion and superconducting systems with fast feedback
Full QIRArbitrary LLVM code, dynamic allocation, recursionSimulators and future integrated controllers
QIR profiles and what they allow

The Adaptive Profile matters most for the near future, because quantum error correction, repeat-until-success circuits and teleportation all require decisions based on mid-circuit measurement results. Its optional capabilities, such as integer computation or loops, are declared explicitly so a backend can state exactly what it supports.

QIR compared with other quantum representations

QIR is one of several formats for describing quantum programs below the level of an SDK. The main difference is that QIR is a compiler-internal representation, while formats such as OpenQASM and Quil are human-readable assembly languages.

FormatFoundationClassical controlMain strength
QIRLLVM IRFull LLVM control flow, limited by profileReuses mature compiler tooling
OpenQASM 3Custom text languageLoops, branches, timingReadable, widely supported by IBM tools
QuilCustom text languageClassical memory and jumpsClose fit to Rigetti hardware
MLIR quantum dialectsMLIR frameworkDepends on the dialectMulti-level optimization before lowering to QIR
QIR and related quantum program formats

These formats often cooperate rather than compete. A toolchain may parse OpenQASM, optimize it in an MLIR dialect, lower it to QIR and finally translate QIR into a vendor’s native pulse or gate instructions. CUDA-Q, for example, uses its own MLIR dialect and can emit QIR for supported backends.

Where QIR is used in practice

QIR is the common submission format of Azure Quantum, where Q# programs and Python programs are compiled to QIR before being sent to partner hardware. The QIR Alliance members include hardware vendors, national laboratories and software companies, which helps keep the specification aligned with real devices.

  • Compiler front ends: the Q# compiler, PyQIR for generating QIR from Python, and converters from Qiskit circuits.
  • Runtimes and simulators: QIR runners link the quantum functions to state vector or sparse simulators for testing.
  • Hardware backends: vendors translate Base or Adaptive Profile QIR into native gate sequences and control instructions.
  • Analysis tools: resource estimators read QIR to count qubits, T gates and circuit depth before execution.

For software teams, the practical benefit is portability: a program compiled once to a profile can run on any backend that declares support for that profile, without rewriting it for each vendor’s SDK.

Limitations and common pitfalls

QIR solves the interface problem, but it introduces its own constraints that developers should understand before relying on it.

ProblemCauseRemedy
Program rejected by backendUses features beyond the target profileCompile for the correct profile
Unexpected classical overheadReal-time branches exceed controller limitsMove logic before or after the circuit
Hard-to-read outputLLVM text is verboseInspect circuits in the SDK, not raw QIR
Inconsistent results formatMissing output recording callsRecord every result explicitly
Typical QIR problems and their remedies

QIR also does not describe pulse-level control or detailed timing in the way OpenQASM 3 can. It is a gate and control flow representation, and work on hardware-specific details still happens in the backend that consumes it.

A plain-language summary

QIR is a shared translation layer for quantum programs. People write programs in many languages, and quantum computers come from many companies. Instead of building a separate translator for every pair, each language translates into QIR, and each machine learns to read QIR.

It works much like a universal power adapter: one plug shape in the middle lets many devices connect to many sockets. QIR also handles the ordinary computer logic mixed into quantum programs, such as making a decision based on a measurement, by borrowing tools that regular software compilers have used for decades.

An example from practice

Consider a university research group developing a repeat-until-success circuit that prepares a special quantum state. The circuit measures an ancilla qubit in the middle, and if the result is wrong, it resets the qubits and tries again, up to five times.

The group writes the program once in Q#, compiles it to the Adaptive Profile of QIR and first runs it on a local simulator to confirm the logic. It then submits the same QIR file to two different cloud backends that support mid-circuit measurement and conditional branching. Both machines accept the program without changes, and the group compares their success rates directly, an outcome that would otherwise require maintaining two separate code bases.