]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: clean up ssa.Value memory arg usage
authorPhilip Hofer <phofer@umich.edu>
Fri, 3 Mar 2017 21:44:18 +0000 (13:44 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 9 Mar 2017 21:40:47 +0000 (21:40 +0000)
This change adds a method to replace expressions
of the form

   v.Args[len(v.Args)-1]

so that the code's intention to walk memory arguments
is explicit.

Passes toolstash-check.

Change-Id: I0c80d73bc00989dd3cdf72b4f2c8e1075a2515e0
Reviewed-on: https://go-review.googlesource.com/37757
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/rewrite.go
src/cmd/compile/internal/ssa/schedule.go
src/cmd/compile/internal/ssa/tighten.go
src/cmd/compile/internal/ssa/value.go
src/cmd/compile/internal/ssa/writebarrier.go

index b0a16296cd78d5236769b21e8f55c7630f862685..9c9c6b5ecc772499e22c79b27068742bd1c087de 100644 (file)
@@ -158,7 +158,7 @@ func canMergeLoad(target, load *Value) bool {
                // If the load is in a different block do not merge it.
                return false
        }
-       mem := load.Args[len(load.Args)-1]
+       mem := load.MemoryArg()
 
        // We need the load's memory arg to still be alive at target. That
        // can't be the case if one of target's args depends on a memory
@@ -230,7 +230,7 @@ search:
                                        if len(m.Args) == 0 {
                                                break
                                        }
-                                       m = m.Args[len(m.Args)-1]
+                                       m = m.MemoryArg()
                                }
                        }
 
index b0a2f231028b3c7055336950ebd7f8cad59438e3..356d44787fb85b624e73cf32f8a994fbabdb30ef 100644 (file)
@@ -314,11 +314,11 @@ func storeOrder(values []*Value, sset *sparseSet, storeNumber []int32) []*Value
                        if v.Op == OpInitMem || v.Op == OpPhi {
                                continue
                        }
-                       a := v.Args[len(v.Args)-1]
+                       a := v
                        if v.Op == OpSelect1 {
-                               a = a.Args[len(a.Args)-1]
+                               a = a.Args[0]
                        }
-                       sset.add(a.ID) // record that a is used
+                       sset.add(a.MemoryArg().ID) // record that v's memory arg is used
                }
                if v.Op == OpNilCheck {
                        hasNilCheck = true
@@ -364,7 +364,7 @@ func storeOrder(values []*Value, sset *sparseSet, storeNumber []int32) []*Value
                if w.Op == OpSelect1 {
                        w = w.Args[0]
                }
-               w = w.Args[len(w.Args)-1]
+               w = w.MemoryArg()
        }
        var stack []*Value
        for _, v := range values {
index 6f192630551ac52970cc255ff359d9c05f185779..45cfb06a75aa99630584998728dce4d91a68b0eb 100644 (file)
@@ -20,7 +20,7 @@ func tighten(f *Func) {
                                // Tuple selectors must stay with the tuple generator.
                                continue
                        }
-                       if len(v.Args) > 0 && v.Args[len(v.Args)-1].Type.IsMemory() {
+                       if v.MemoryArg() != nil {
                                // We can't move values which have a memory arg - it might
                                // make two memory values live across a block boundary.
                                continue
index 00f2454bf6c841f18b7cedcb6938c218cff9a2c8..93172bc45ac42ee62baee46166c60d41a0d4a1e6 100644 (file)
@@ -311,3 +311,23 @@ func (v *Value) RegName() string {
        }
        return reg.(*Register).name
 }
+
+// MemoryArg returns the memory argument for the Value.
+// The returned value, if non-nil, will be memory-typed,
+// except in the case where v is Select1, in which case
+// the returned value will be a tuple containing a memory
+// type. Otherwise, nil is returned.
+func (v *Value) MemoryArg() *Value {
+       if v.Op == OpPhi {
+               v.Fatalf("MemoryArg on Phi")
+       }
+       na := len(v.Args)
+       if na == 0 {
+               return nil
+       }
+       if m := v.Args[na-1]; m.Type.IsMemory() ||
+               (v.Op == OpSelect1 && m.Type.FieldType(1).IsMemory()) {
+               return m
+       }
+       return nil
+}
index 53bbc4af96bc013d7bbd255247c724995ec6c315..0b82a5ba4cf1fb75d26de05fdfe16a6221feb084 100644 (file)
@@ -120,7 +120,7 @@ func writebarrier(f *Func) {
                b.Values = b.Values[:start]
 
                // find the memory before the WB stores
-               mem := stores[0].Args[len(stores[0].Args)-1]
+               mem := stores[0].MemoryArg()
                pos := stores[0].Pos
                bThen := f.NewBlock(BlockPlain)
                bElse := f.NewBlock(BlockPlain)