Skip to content

feat: support QIR 2.0 conversion#34

Open
qartik wants to merge 11 commits intomainfrom
ks/qir2-core
Open

feat: support QIR 2.0 conversion#34
qartik wants to merge 11 commits intomainfrom
ks/qir2-core

Conversation

@qartik
Copy link
Member

@qartik qartik commented Mar 6, 2026

Summary

Support QIR 2.0 conversion and fold in the LLVM 21 CI, wheel, and release updates needed for this work to validate cleanly.

Closes #3

Included

  • QIR 2.0 conversion pipeline and verifier updates
  • conversion safety fixes and fixture and snapshot updates
  • LLVM 21 test, lint, wheel, and release workflow updates
  • Windows-safe Rust and Python smoke examples
  • workflow cancellation for superseded PR runs

Limitations

  • Windows example smoke runs validate host-target code generation (native, opt_level=0) rather than the cross-target aarch64 optimized path still exercised on Linux and macOS.
  • Rationale: the LLVM 21 Windows CI setup has been reliable for host-target smoke coverage, but cross-target aarch64 optimized example compilation has been flaky there. Keeping Windows on the host-target path preserves meaningful API and codegen coverage without blocking the PR on a Windows-specific backend issue.

Copilot AI review requested due to automatic review settings March 6, 2026 18:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades the QIR-QIS compiler from LLVM 14 to LLVM 21 and adds support for QIR 2.0 (opaque pointer) conversion. The changes span the entire compilation pipeline: parsing, decomposition, conversion, optimization, verification, and testing. Significant effort is spent on Windows compatibility workarounds where LLVM 21 APIs behave differently.

Changes:

  • Upgrade from LLVM 14 (llvm-sys 140, inkwell llvm14-0) to LLVM 21 (llvm-sys 211, inkwell llvm21-1), migrating all typed pointer APIs (%Qubit*, i8*, i64*) to opaque pointer (ptr) APIs and updating build_gep/build_load signatures to include explicit types.
  • Add QIR 2.0 support: new test fixtures (qir2_base.ll, qir2_adaptive.ll), updated module flag validation to accept qir_major_version 1 or 2, new parse_gep logic to resolve unnamed globals via LLVM C APIs, and direct-to-module decomposition building (replacing module linking + inlining).
  • Windows-specific safety workarounds: custom llvm_verify module, #[cfg(windows)] guards for target initialization, CPU feature detection, metadata validation, and test snapshot skipping; plus build system updates (pyproject.toml, Cargo.toml) for LLVM 21 on all platforms.

Reviewed changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Cargo.toml / Cargo.lock Upgrade inkwell to llvm21-1 and llvm-sys to 211.0.0
src/lib.rs Update entry processing to pass array types, Windows cfg guards, QIR 2.0 major version acceptance, trace logging, attribute cleanup changes
src/convert.rs Migrate to opaque pointer LLVM APIs, new get_required_num_qubits_strict, parse_gep rewrite with LLVM C API fallback, prune_unused_ir_qis_helpers, sanitize_label_for_global_name, test helper changes
src/decompose.rs Build decompositions directly into module (no linking), add per-step verification, use get_or_create_decomposition_function, change linkage from LinkOnceODR to External for native gates
src/opt.rs Early return for O0, Windows cfg guards for CPU features and native target init, trace logging
src/llvm_verify.rs New module for platform-safe LLVM module verification via C API
pyproject.toml Update build config for LLVM 21 on Linux/macOS/Windows
README.md / qtm-qir-reference.md Document LLVM 21 requirement and QIR 1.0/2.0 pointer forms
tests/data/qir2_base.ll / tests/data/qir2_adaptive.ll New QIR 2.0 test fixtures
tests/snaps/*.snap Updated snapshots for opaque pointer output, new global naming, and reordered declarations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support QIR 2.0 with opaque pointers

2 participants