Skip to content

Migrate control lowering pass to reference semantics - #3244

Open
hsajjad14 wants to merge 34 commits into
mainfrom
CtrlLoweringToQref
Open

hsajjad14 wants to merge 34 commits into
mainfrom
CtrlLoweringToQref

Conversation

@hsajjad14

@hsajjad14 hsajjad14 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Context:

This PR migrates the control lowering pass to reference semantics.
Control Lowering for value semantics was implemented in #3089, #3090, #3096.

Description of the Change:

Added method addControls in the QuantumGate interface. This function is implemented in UnitaryGate_Op, where the generated functions getCtrlQubitsMutable and getCtrlValuesMutable append the crtlQubits and ctrlValues. The MLIR type MutableOperandRange has a function append which appends values to a range and also updates the length of the operandSegment.

This allows an operation cast as dyn_cast<QuantumGate>(op) to call addControls which adds ctrlQubits and ctrlValues to itself.

For the CtrlOp case, it merges the old (outer) CtrlQubits and ctrlValues to the inner one. Afterwards the greedy pattern matcher gets run for the inner CtrlOp block and runs CtrlLoweringRewritePattern::matchAndRewrite again.

I then move the entire block outside the ctrlOp op with inlineBlockBefore and erase the op.

Benefits:
Simplifies the pass makes it more maintainable, scalable, faster, easier to debug, readable, and less prone to bugs.

Possible Drawbacks:
Additional calls to other passes, can increase compilation time. Needs to call convert-to-reference-semantics before the pass runs, and convert-to-value-semantics in the adjointLowering pass which follows this pass.

Related GitHub Issues:
#3192

[sc-129851]

Blockers:
This test CtrlTest.mlir fails because of the scf.execute_region not being implemented in convert-to-reference-semantics. I have the fix for it in #3238.

@hsajjad14
hsajjad14 marked this pull request as ready for review September 21, 2026 21:39
@hsajjad14
hsajjad14 requested review from kipawaa, maliasadi and paul0403 and removed request for maliasadi September 21, 2026 21:42
@hsajjad14 hsajjad14 linked an issue Sep 21, 2026 that may be closed by this pull request
@hsajjad14 hsajjad14 self-assigned this Sep 21, 2026
@hsajjad14
hsajjad14 requested a review from maliasadi September 21, 2026 21:46
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.

Migrate control-lowering pass to QRef

2 participants