qir-alliance / pyqir

PyQIR is a set of APIs for generating, parsing, and evaluating Quantum Intermediate Representation (QIR).
https://qir-alliance.github.io/pyqir
MIT License
57 stars 24 forks source link

Support constant string values as arguments to functions #188

Closed bamarsha closed 1 year ago

bamarsha commented 1 year ago

For QIR output recording, code like the following needs to be emitted:

@0 = internal constant [5 x i8] c"0_t0\00"
@1 = internal constant [5 x i8] c"0_t1\00"
...
call void @__quantum__rt__result_record_output(%Result* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0))
call void @__quantum__rt__result_record_output(%Result* nonnull inttoptr (i64 1 to %Result*), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @1, i32 0, i32 0))
...
declare void @__quantum__rt__result_record_output(%Result*, i8*)

This requires:

  1. Creating a global constant string value in the module.
  2. Passing it as a pointer as an argument to a record output function.