C_qir is an LLVM pass that transforms C programs into Quantum Intermediate Representation (QIR) — a bridge between classical and quantum computation.
This project provides both the transformation logic and a reproducible Docker-based environment for development and testing.
The recommended environment uses a Debian Bookworm image (silkeh/clang) with LLVM 20 and Python-based tooling for QIR execution.
git clone https://github.com/feelerx/C_qir.git
cd C_qirA ready-to-use Dockerfile is included.
docker build -t c_qir_env .Mount your working directory for easy file access:
docker run -it --name c_qir_dev -v $(pwd):/workspace c_qir_env /bin/bashThe environment includes:
- LLVM 20.1.8 (via Debian backports)
- Clang 20 and build tools (CMake, Make, etc.)
- Python 3.11 + pipx
- qirrunner 0.8.2 (installed via pipx)
You can verify setup with:
clang --version
opt --version
qir-runner --version- Create a build directory and configure CMake:
mkdir build && cd build cmake .. -DLLVM_DIR=/usr/lib/llvm-20/cmake -DBUILD_SHARED_LIBS=ON make
- The compiled plugin will be generated at:
build/libCToQIRPass.so
Compile a C program into LLVM IR:
clang -O0 -emit-llvm -S program.c -o program.llRun the C→QIR transformation:
/usr/lib/llvm-20/bin/opt -load-pass-plugin ./build/libCToQIRPass.so -passes="c-to-qir" program.ll -S -o program_qir.llThe resulting program_qir.ll is your QIR output.
You can execute or validate the generated QIR using qirrunner:
qir-runner program_qir.llThis allows quick iteration and debugging of quantum-classical pipelines.
| File / Folder | Description |
|---|---|
CToQIRPass.cpp |
Main source file implementing the LLVM pass |
CMakeLists.txt |
CMake configuration for building the shared library |
Dockerfile |
Reproducible environment definition |
program.c |
Example C input |
program_qir.ll |
Sample QIR output produced by the pass |
- Based on LLVM 20 (Debian package build).
- The pass links to core LLVM libraries:
support,core,irreader, andpasses. - To modify or extend the transformation logic, edit
CToQIRPass.cpp, then rebuild via CMake.
MIT License © 2025
Developed as part of the C_qir project for exploring quantum compilation workflows.