You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/DeveloperGuide/DynamaticFeaturesAndOptimizations/FTD/GSAAnalysis.md
+54-1Lines changed: 54 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ Consider the following control-flow graph and its corresponding `cf_dyn_transfor
18
18
19
19
- The argument of bb3 (%7) comes from two mutually exclusive control-flow paths (bb1 or bb2). This corresponds to a γ function.
20
20
21
-

21
+

22
22
23
23
```
24
24
module {
@@ -96,6 +96,59 @@ For each block in the region:
96
96
```
97
97
After all ϕ gates are created, the final step is to connect the missing inputs recorded in phisToConnect.
98
98
99
+
### What is a “missing phi”?
100
+
The input of a ϕ gate can itself be another ϕ. This happens when the input comes from a block argument of another block (excluding bb0). In this case, the ϕ input cannot be connected immediately. Instead, it is marked as missing and the necessary information is stored. After all ϕ gates are extracted, these missing inputs are revisited and the connections are reconstructed.
101
+
102
+
### `isBlockArgAlreadyPresent` and `isValueAlreadyPresent`
103
+
These helper functions prevent duplicate inputs from being recorded.
104
+
105
+
// TODO: explain their implementation details later.
106
+
107
+
### Why can a value appear multiple times?
108
+
// TODo
109
+
99
110
## Convert ϕ Gates into μ Gates
100
111
112
+
### Checks
113
+
A ϕ gate is classified as a μ gate if the following conditions hold:
114
+
115
+
1. It is inside a loop.
116
+
117
+
2. It has at least two operands.
118
+
119
+
3. It is located in the loop header.
120
+
121
+
### Input Grouping
122
+
123
+
Once a candidate μ is identified, its operands (inputs) are divided into two groups:
124
+
125
+
-**Loop inputs:** values produced inside the same loop as the ϕ.
126
+
127
+
-**Initial inputs:** values originating from outside the loop.
128
+
129
+
#### Notice: Inputs from Nested Loops
130
+
Blocks only report their innermost loop as the one they belong to. Because of this, inputs from nested loops might be mistakenly recognized as “initial inputs” instead of loop inputs.
131
+
132
+
*Example:* in the CFG below, an input value from block `bb3` may appear to belong to a different loop than the one containing `bb1` (the ϕ’s loop). To prevent this, the `IsBlockInLoop` function checks whether any parent loop of the input matches the ϕ’s loop.
133
+
134
+

135
+
136
+
### Creating μ Gates
137
+
138
+
A valid μ gate must have exactly two inputs: one from outside the loop and one from inside the loop. The grouping step above ensures we can identify these two roles.
139
+
140
+
- If either group is empty → the ϕ cannot be a μ.
141
+
142
+
- If a group has exactly one member → that value becomes the corresponding μ input (loop or initial).
143
+
144
+
- If a group has multiple members → an intermediate ϕ is created in the block to merge them. This extra ϕ will later be replaced by a γ (or tree of γs) during the ϕ to γ conversion phase.
145
+
146
+
### Condition of the μ Gate
147
+
148
+
The μ gate outputs its initial value during the first iteration of the loop. On subsequent iterations, if the loop continues (i.e., the exit condition is false), it selects the loop-generated value. When the loop finally exits, the initial input will be used again if the loop is re-entered.
149
+
150
+
Therefore, the condition of a μ gate is defined as the **negation of the loop exit condition**.
151
+
152
+
#### Note:
153
+
The `getLoopExitCondition` function computes the overall exit condition by OR-ing the conditions of all loop exiting blocks. This function relies on `getBlockLoopExitCondition`, which computes the exit condition for a single block.
0 commit comments