Skip to content

[FTD] Support Multi-Exit Loops#604

Merged
AyaElAkhras merged 8 commits into
mainfrom
multi-exit-support
Oct 27, 2025
Merged

[FTD] Support Multi-Exit Loops#604
AyaElAkhras merged 8 commits into
mainfrom
multi-exit-support

Conversation

@zeinabPourgheisari

Copy link
Copy Markdown
Collaborator

The previous fast token delivery crashed when running into loops with multiple exits (see example CFG below).
This happened because gates (Mu gates in this case) stored only one block as their condition block, which fails when multiple blocks are needed as conditions.

linear_search_CFG

To fix this, two new attributes were added to Gate:

  • a boolean expression for the condition
  • a list of cofactors, representing the variables used in the condition expression.

For each Mu gate, the loop exit condition is computed by OR-ing the exit conditions of all exiting blocks. The condition of the Mu is then set as the negation of this exit condition (i.e., the loop iteration condition).
For Gamma gates, the condition remains the same as before, taken from the condition block.

In FtdImplementation.cpp, whenever the condition value of a gate/loop is needed:

  • If there is a single cofactor, the same process as before is used,
  • If there are multiple cofactors, a Binary Decision Diagram (BDD) is built, translated into a circuit, and used as the condition value.

In addition, in boolVariableToCircuit function, conditions generated for gates with multiple exiting blocks do not require channelification.

Comment thread experimental/lib/Support/FtdImplementation.cpp Outdated
@AyaElAkhras

Copy link
Copy Markdown
Member

Could you also push the changes that we discussed to unify the if-else here

if (Block *loopExit = loop->getExitingBlock(); loopExit) {
?

@zeinabPourgheisari zeinabPourgheisari marked this pull request as ready for review October 21, 2025 12:30
Comment thread experimental/lib/Support/FtdImplementation.cpp Outdated
Comment thread experimental/lib/Support/FtdImplementation.cpp Outdated
Comment thread experimental/lib/Support/FtdImplementation.cpp Outdated
Comment thread experimental/lib/Support/FtdImplementation.cpp Outdated
Comment thread experimental/lib/Support/FtdImplementation.cpp
@AyaElAkhras AyaElAkhras merged commit 7a20c33 into main Oct 27, 2025
4 checks passed
QinYuan2000 pushed a commit to QinYuan2000/dynamatic that referenced this pull request Feb 13, 2026
The previous fast token delivery crashed when running into loops with
multiple exits (see example CFG below).
This happened because gates (Mu gates in this case) stored only one
block as their condition block, which fails when multiple blocks are
needed as conditions.

<img width="200" height="388" alt="linear_search_CFG"
src="https://github.com/user-attachments/assets/d2b59e5e-a8b1-42a9-b51a-141755eeb216"
/>

To fix this, two new attributes were added to `Gate`:
- a boolean expression for the condition
- a list of cofactors, representing the variables used in the condition
expression.

For each Mu gate, the loop exit condition is computed by OR-ing the exit
conditions of all exiting blocks. The condition of the Mu is then set as
the negation of this exit condition (i.e., the loop iteration
condition).
For Gamma gates, the condition remains the same as before, taken from
the condition block.

In `FtdImplementation.cpp`, whenever the condition value of a gate/loop
is needed:
- If there is a single cofactor, the same process as before is used,
- If there are multiple cofactors, a Binary Decision Diagram (BDD) is
built, translated into a circuit, and used as the condition value.

In addition, in `boolVariableToCircuit` function, conditions generated
for gates with multiple exiting blocks do not require channelification.
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