On Wednesday, September 18, 2019 at 1:50:27 PM UTC-7, Mohit Verma wrote:
>
> Hi All,
>
> I was reading Go compiler's SSA backend code at 
> cmd/compile/internal/gc/ssa/go 
> <https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/ssa.go> 
> & 
> cmd/compile/internal/ssa 
> <https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa>, 
> and I keep on seeing some code generation logic depending on if a type is 
> "SSA-able". 
> For example, 
> While building SSA tree for an assignment operation, I see comments like 
> this 
> <https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/ssa.go#L2719>
> :
>
>
>
>
>
>
> *// We're assigning to a field of an ssa-able value. We need to build a 
> new structure with the new value for the field we're assigning and the old 
> values for the other fields. For instance:// type T struct {a, b, c int}// 
> var T x// x.b = 5// For the x.b = 5 assignment we want to generate x = 
> T{x.a, 5, x.c}*
>  
>
which seems like a sub-optimal way of updating only one element of a 
> struct. 
>

If T is SSAable, then one of the optimization passes decomposes x into its 
constituent parts.
So we effectively rewrite this to:

var x_a int  \
var x_b int   |  from var T x
var x_c int  /
x.a = x.a \
x.b = 5     | from x.b = 5
x.c = x.c  /

The two trivial assignments are then quickly optimized away.

My question is: 
> *What is a SSA-able value/type for Go compiler? What is a SSA-able node in 
> Go's AST representation? How is it different from other non SSA-able 
> values? What special purpose does it serve?*
>
>
First types. An array type with len>1 can't be represented in SSA, because 
there is no way to encode indexing operations.
In addition, as a heuristic we don't SSA large types, as SSAing them 
usually means breaking them up into their component values, and that can 
run the compiler out of registers pretty quickly.
(this is canSSAType)

Then variables. If a variable doesn't have an SSAable type, then we won't 
generate any SSA for it. In addition, if its address is taken we can't SSA 
it, because SSA representation has no way to represent possible side 
effects through pointers. There are a few other cases which also forbid 
making a variable SSAable.
(this is (*state).canSSA)


 

> Can anyone help me understand this/point me to links to existing 
> literature around this?
>
> Thanks!
> Mohit
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3f598d78-a0de-45b1-9cc3-2073c85804ef%40googlegroups.com.

Reply via email to