[MLIR] Perform constant-folding on quantum.insert
and quantum.extract
indices
#161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: When extracting qubits from quantum registers, the frontend always materializes constant wire indices in the IR instead of as attributes on the
insert
orextract
op.Code such as:
results in:
Description of the Change: Known constants on
quantum.insert
andquantum.extract
ops are folded into attributes. The above example results in:There is also an additional verifier to make sure that an index is defined (this previously caused a segfault if an insert or extract was created without an index. The MLIR parser disallows this, but it can be done from C++/Python).
Benefits: Intermediate transformations (such as quantum function splitting) will be able to more easily tell if wires are constant or dynamic when they operate on the IR.