sway
sway copied to clipboard
Remove PHIs and introduce block args
The Sway-IR currently limits basic blocks to have only a single PHI node. That wouldn't work, for example, in the following case:
let mut x;
let mut y;
if (...) {
x = 10;
y = 11;
} else {
x = 11;
y = 10;
}
merge_block:
= x;
= y;
At the merge block we'll need two PHIs, one for x
and another for y
.
We have two choices:
- Remodel the IR to allow multiple PHIs and teach the various IR transformations / analyses about it.
- Go for the "more modern" block argument approach.
Working with multiple PHIs is a bit clumsy, and in our case, since there is an assumption throughout the IR that there is only a single PHI, making changes to it to accept multiple PHIs has the risk of breaking this assumption somewhere. It's safer to just remove PHIs altogether and move to block arguments.