Charlotte.jl icon indicating copy to clipboard operation
Charlotte.jl copied to clipboard

New SSA IR

Open tshort opened this issue 6 years ago • 4 comments

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.

tshort avatar Mar 23 '18 20:03 tshort

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.

MikeInnes avatar Mar 23 '18 20:03 MikeInnes

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

tshort avatar Mar 23 '18 20:03 tshort

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 avatar Mar 23 '18 20:03 MikeInnes

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

MikeInnes avatar Apr 16 '18 18:04 MikeInnes