On Mon Jan 29 07:24:50 2024 +0000, Conor McCarthy wrote:
If I understand correctly, this takes the place of `phi`, and copies to a new temp the result from the branch which was taken. Another way to do this is force the temp dst register indices to be equal in both branches, unless there's an issue with it I'm missing.
Mmmh, what you are describing seems more what is happening in `materialize_ssa_to_temps()`: there SSA registers are converted to TEMP registers, and PHI nodes must be converted to MOV/MOVC because they're not allowed with TEMPs. So in practice that transformation does something like this: ``` label l10 ... add sr20, sr18, sr19 branch l11 label l11 phi sr21, l9, sr20, ... ... ``` is converted to ``` label l10 ... add r20, r18, r19 mov r21, r20 branch l11 label l11 [phi is removed] ... ``` In other words, not only we're converting PHI to MOV/MOVC, but we're also moving it before than BRANCH (otherwise the predecessor information is lost).
The structurizer is dispatched after this has already happened, so there are no PHIs nor SSAs in sight. It converts this: ``` label l10 ... branch l11 ``` to something like this: ``` # Introduce a fresh TEMP to represent the currently executing block r100 = 1 loop switch r100 ... case l(10) # Do whatever block l10 is supposed to do mov r100, l(11) break ... endswitch endloop ``` Of course the MOV becomes a MOVC if the BRANCH was conditional. So now the program is structured in the sense of TPF programs, and it can be passed to the CF flattener pass and then to the SPIR-V backend.