Skip to content

feelerx/C_qir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C_qir — C to QIR Conversion Pass

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.


Environment Setup (Docker)

The recommended environment uses a Debian Bookworm image (silkeh/clang) with LLVM 20 and Python-based tooling for QIR execution.

1. Clone the Repository

git clone https://github.com/feelerx/C_qir.git
cd C_qir

2. Build the Docker Image

A ready-to-use Dockerfile is included.

docker build -t c_qir_env .

3. Start a Container

Mount your working directory for easy file access:

docker run -it --name c_qir_dev -v $(pwd):/workspace c_qir_env /bin/bash

Inside the Container

The 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

Building the CToQIRPass

  1. Create a build directory and configure CMake:
    mkdir build && cd build
    cmake .. -DLLVM_DIR=/usr/lib/llvm-20/cmake -DBUILD_SHARED_LIBS=ON
    make
  2. The compiled plugin will be generated at:
    build/libCToQIRPass.so
    

Running the Pass

Compile a C program into LLVM IR:

clang -O0 -emit-llvm -S program.c -o program.ll

Run 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.ll

The resulting program_qir.ll is your QIR output.


Running and Testing QIR

You can execute or validate the generated QIR using qirrunner:

qir-runner program_qir.ll

This allows quick iteration and debugging of quantum-classical pipelines.


File Overview

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

Development Notes

  • Based on LLVM 20 (Debian package build).
  • The pass links to core LLVM libraries: support, core, irreader, and passes.
  • To modify or extend the transformation logic, edit CToQIRPass.cpp, then rebuild via CMake.

License

MIT License © 2025
Developed as part of the C_qir project for exploring quantum compilation workflows.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors