qir-alliance / qir-runner

QIR bytecode runner to assist with QIR development and validation
https://qir-alliance.github.io/qir-runner
MIT License
24 stars 4 forks source link

Upgrade to new LLVM pass manager #180

Closed ausbin closed 4 months ago

ausbin commented 4 months ago

Background (Personal Problems)

I generate the QIR I test with qir-runner using LLVM 18, so the LLVM IR contains only opaque pointers. This causes errors like the following:

$ target/debug/qir-runner --file bv1101.ll 
bv1101.ll:8:40: warning: ptr type is only supported in -opaque-pointers mode
  call void @__quantum__rt__initialize(ptr null)
                                       ^
Error: "bv1101.ll:8:40: error: expected type\n  call void @__quantum__rt__initialize(ptr null)\n                                       ^\n"

Building qir-runner with LLVM 18 (which supports only opaque pointers) works great except that qir-runner still uses the legacy pass manager, which was removed in LLVM 17.

This PR

Because the new LLVM pass manager has existed since LLVM 13, it is safe even on y'all's version (LLVM 14) to upgrade to the new pass manager instead of using the legacy pass manager.

I scoured the LLVM C API and could not find bindings for the new pass manager beyond LLVMRunPasses(), which Inkwell uses to implement Module::run_passes(), which I use here. (Please check my work)

Pros:

Cons:

Testing

  1. Builds on both LLVM 14.0.6 and 18.1.5
  2. The unit tests (cargo test) pass
  3. If I comment out the call to run_basic_passes_on() and my .ll file contains the following:
    declare void @__quantum__qis__chickennugget__body(ptr %0)

    I get the following error when I run qir-runner:

    Error: "Failed to link some declared functions: __quantum__qis__chickennugget__body"

    This indicates that the passes are running when the call is not commented (or at least strip-dead-prototypes is)