]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: refactor assign
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 29 Aug 2015 21:54:45 +0000 (14:54 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 11 Sep 2015 20:50:46 +0000 (20:50 +0000)
Move the AST to SSA conversion to the caller.
This enables it to be used in contexts in which
the RHS is already an *ssa.Value.

Change-Id: Ibb87210fb9fda095a9b7c7f4ad1264a7cbd269bf
Reviewed-on: https://go-review.googlesource.com/14521
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/ssa.go

index b68a8b1a3656bc7f75efe235bdbfee894a844a01..7086a4f84a8146e66e6613d95b6a774e0b3e7e33 100644 (file)
@@ -461,7 +461,8 @@ func (s *state) stmt(n *Node) {
                        palloc = callnew(n.Left.Type)
                        prealloc[n.Left] = palloc
                }
-               s.assign(OAS, n.Left.Name.Heapaddr, palloc)
+               r := s.expr(palloc)
+               s.assign(n.Left.Name.Heapaddr, r, false)
 
        case OLABEL:
                sym := n.Left.Sym
@@ -530,7 +531,11 @@ func (s *state) stmt(n *Node) {
                        s.f.StaticData = append(data, n)
                        return
                }
-               s.assign(n.Op, n.Left, n.Right)
+               var r *ssa.Value
+               if n.Right != nil {
+                       r = s.expr(n.Right)
+               }
+               s.assign(n.Left, r, n.Op == OASWB)
 
        case OIF:
                cond := s.expr(n.Left)
@@ -1864,18 +1869,14 @@ func (s *state) expr(n *Node) *ssa.Value {
        }
 }
 
-func (s *state) assign(op uint8, left *Node, right *Node) {
+func (s *state) assign(left *Node, right *ssa.Value, wb bool) {
        if left.Op == ONAME && isblank(left) {
-               if right != nil {
-                       s.expr(right)
-               }
                return
        }
        // TODO: do write barrier
-       // if op == OASWB
+       // if wb
        t := left.Type
        dowidth(t)
-       var val *ssa.Value
        if right == nil {
                // right == nil means use the zero value of the assigned type.
                if !canSSA(left) {
@@ -1887,13 +1888,11 @@ func (s *state) assign(op uint8, left *Node, right *Node) {
                        s.vars[&memvar] = s.newValue2I(ssa.OpZero, ssa.TypeMem, t.Size(), addr, s.mem())
                        return
                }
-               val = s.zeroVal(t)
-       } else {
-               val = s.expr(right)
+               right = s.zeroVal(t)
        }
        if left.Op == ONAME && canSSA(left) {
                // Update variable assignment.
-               s.vars[left] = val
+               s.vars[left] = right
                return
        }
        // not ssa-able.  Treat as a store.
@@ -1901,7 +1900,7 @@ func (s *state) assign(op uint8, left *Node, right *Node) {
        if left.Op == ONAME {
                s.vars[&memvar] = s.newValue1A(ssa.OpVarDef, ssa.TypeMem, left, s.mem())
        }
-       s.vars[&memvar] = s.newValue3I(ssa.OpStore, ssa.TypeMem, t.Size(), addr, val, s.mem())
+       s.vars[&memvar] = s.newValue3I(ssa.OpStore, ssa.TypeMem, t.Size(), addr, right, s.mem())
 }
 
 // zeroVal returns the zero value for type t.