sway icon indicating copy to clipboard operation
sway copied to clipboard

Remove PHIs and introduce block args

Open vaivaswatha opened this issue 2 years ago • 0 comments

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:

  1. Remodel the IR to allow multiple PHIs and teach the various IR transformations / analyses about it.
  2. 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.

vaivaswatha avatar Sep 13 '22 04:09 vaivaswatha