
Swiftc – SIL and its not-so-basic blocks - tambourine_man
http://swiftc.io/post/132392598484/sil-and-its-not-so-basic-blocks
======
DannyBee
A few issues:

One, passes have to special case BB arguments whether they are phi nodes or
not ;)

IE this doesn't actually make something like constant propagation easier. You
still have to perform the meet operations. You still have to go and look what
arguments were passed to your basic block.

In the phi node case, they are right there. I assume they link the basic block
parameters to things passing those parameters, in which case: they are
essentially phi nodes.

Second. It's really easy to create phi nodes. Creating basic blocks is a
heavyweight thing (maybe not in SIL, but in general).

For most compilers, creating basic blocks requires messing with the CFG,
update dominator info, etc.

However, if want to put something in loop closed SSA form, i can just drop in
a bunch of phi nodes without messing with the CFG. In their form, i'd have to
add basic block arguments to a bunch of blocks.

Additionally, phi nodes have natural analogues, like in SSI form, etc.

It's harder to represent the splitting operating sigma nodes perform in a
basic block form. ;-)

~~~
Rusky
I've seen another IR that replaced phi nodes with BB arguments, but they also
replaced return with continuations, leading to a kind of best-of-both-worlds
cross between SSA and CPS. They were able to implement a bunch of interesting
optimizations on closures, in an imperative language.

[http://compilers.cs.uni-
saarland.de/papers/lkh15_cgo.pdf](http://compilers.cs.uni-
saarland.de/papers/lkh15_cgo.pdf)

------
l_dopa
People recognized ~20 years ago that, semantically, SSA is just reinventing
lexical scope:

[http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.3...](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.3282)

~~~
DannyBee
IBM knew this when they invented it (note: Ken Zadeck was my officemate when i
worked at IBM ;P)

The original pass was called RNN - right number of names.

------
gsg
Interesting. MLton did the basic-blocks-with-arguments thing too:

    
    
      http://mlton.org/pipermail/mlton/2007-February/029597.html
      http://mlton.org/pipermail/mlton/2003-January/023061.html

------
prestonbriggs
Reminds me of Steele's Rabbit compiler (as noted by Appel and probably
others). Always made a lot of sense to me, though I never worked out the
details. I thought in terms of every basic block taking arguments (in
registers), and every branch passing some arguments. Lexical scoping gives us
a way to express common arguments. This should be interesting to read and
think about.

