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

Support QASM's const in QUIR #18

Open
jlapeyre opened this issue Dec 29, 2022 · 1 comment
Open

Support QASM's const in QUIR #18

jlapeyre opened this issue Dec 29, 2022 · 1 comment

Comments

@jlapeyre
Copy link

jlapeyre commented Dec 29, 2022

QUIR should support const in statements like: const int[64] x = 2.

The QASM code uint x = 1; and const uint x = 1; emit the same mlir. Furthermore, in both cases, x may be mutated.

Suggestions

The information is available in the AST via node->IsConst(). So you would discrimination when processing the variable -declaration node here
https://github.com/Qiskit/qss-compiler/blob/7180bf9a96b6109c0ff9491c15f8330f5a4ff7ef/lib/Frontend/OpenQASM3/QUIRVariableBuilder.cpp#L34-L36
by including another parameter bool isConst. And select either
https://github.com/Qiskit/qss-compiler/blob/7180bf9a96b6109c0ff9491c15f8330f5a4ff7ef/lib/Frontend/OpenQASM3/QUIRVariableBuilder.cpp#L49
as now or declareOp = builder.create<mlir::quir::DeclareConstantOp>.

Then copy/paste this
https://github.com/Qiskit/qss-compiler/blob/7180bf9a96b6109c0ff9491c15f8330f5a4ff7ef/include/Dialect/QUIR/IR/QUIROps.td#L137-L138
like this:

def QUIR_DeclareConstantOp : QUIR_Op<"declare_constant", [Symbol]> {

And give the constant the same semantics except that it can't be assigned to. Even if adding an operation declare_constant is the right approach, some kind of refactoring rather than copying 50 lines verbatim should be done.

@mhillenbrand
Copy link
Contributor

I think extending the DeclareVariableOp to indicate whether a variable is a constant is cleaner than introducing a separate op for constant variables. In addition to the operation itself, we would also introduce (mostly) duplicate code in all scenarios that reference variables (be they constant or not).

  • Operations for variable assignment should have their MLIR verifier check that the target variable is not constant constant
  • The AST to MLIR generation step should check as well and provide an actionable diagnostic message.

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

No branches or pull requests

2 participants