Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to new LLVM pass manager #180

Merged
merged 1 commit into from
May 30, 2024

Conversation

ausbin
Copy link
Contributor

@ausbin ausbin commented May 28, 2024

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:

  • Allows qir-runner to be built with the latest version of LLVM without disturbing LLVM 14 support
  • Saves y'all effort later when you eventually upgrade LLVM

Cons:

  • Less type safety (if you typo the name of a pass, you will find out only at runtime)
  • Creating the TargetMachine is ugly (any ideas?)

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)

@ausbin ausbin requested review from idavis, billti and swernli as code owners May 28, 2024 19:35
@ausbin ausbin force-pushed the feature/new-pass-manager branch from 304cadb to 9f0e8a8 Compare May 28, 2024 19:41
@swernli swernli merged commit ea536a8 into qir-alliance:main May 30, 2024
15 checks passed
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.

2 participants