MikeInnes / Charlotte.jl

Charlotte's Web Scale
Other
113 stars 13 forks source link

New SSA IR #5

Open tshort opened 6 years ago

tshort commented 6 years ago

Does anyone know if Keno's new SSA IR will change the output of code_typed? I thought it might, but I haven't been able to figure that out.

If it does, it's something to keep track of here.

MikeInnes commented 6 years ago

Since we're immediately throwing out the SSA values themselves anyway, I expect this will be easy to update if it does change. The main change on 0.7 is linear IR, but I think even that'll work without any changes on our end.

tshort commented 6 years ago

Phi nodes was a complication I was worried about, but maybe those can be thrown out, too.

MikeInnes commented 6 years ago

Even with phi nodes it should be straightforward to turn them into locals. We'll probably want some way to coalesce and/or remove locals entirely to clean up the code, which is a little harder, but tools like Binaryen will also do that for us for now.

MikeInnes commented 6 years ago

Quick example to give a flavour of what this looks like on 0.7:

julia> function pow(x, n)
         r = 1
         while n > 0
           r *= x
           n -= 1
         end
         return r
       end
pow (generic function with 1 method)

julia> @code_ir pow(1,2)
Code
1 ─      nothing
2 ┄ %2 = φ (1 => 1, 3 => %6)::Int64
│   %3 = φ (1 => %%3, 3 => %7)::Int64
│   %4 = Main.:>(%3, 0)::Bool
└──      goto 4 if not %4
3 ─ %6 = Main.:*(%2, %%2)::Int64
│   %7 = Main.:-(%3, 1)::Int64
└──      goto 2
4 ─      return %2