Commit b0e91d83 authored by Philip Hofer's avatar Philip Hofer Committed by Matthew Dempsky

cmd/compile: clean up ssa.Value memory arg usage

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: default avatarKeith Randall <khr@golang.org>
parent e471ad91
...@@ -158,7 +158,7 @@ func canMergeLoad(target, load *Value) bool { ...@@ -158,7 +158,7 @@ func canMergeLoad(target, load *Value) bool {
// If the load is in a different block do not merge it. // If the load is in a different block do not merge it.
return false 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 // 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 // can't be the case if one of target's args depends on a memory
...@@ -230,7 +230,7 @@ search: ...@@ -230,7 +230,7 @@ search:
if len(m.Args) == 0 { if len(m.Args) == 0 {
break break
} }
m = m.Args[len(m.Args)-1] m = m.MemoryArg()
} }
} }
......
...@@ -314,11 +314,11 @@ func storeOrder(values []*Value, sset *sparseSet, storeNumber []int32) []*Value ...@@ -314,11 +314,11 @@ func storeOrder(values []*Value, sset *sparseSet, storeNumber []int32) []*Value
if v.Op == OpInitMem || v.Op == OpPhi { if v.Op == OpInitMem || v.Op == OpPhi {
continue continue
} }
a := v.Args[len(v.Args)-1] a := v
if v.Op == OpSelect1 { 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 { if v.Op == OpNilCheck {
hasNilCheck = true hasNilCheck = true
...@@ -364,7 +364,7 @@ func storeOrder(values []*Value, sset *sparseSet, storeNumber []int32) []*Value ...@@ -364,7 +364,7 @@ func storeOrder(values []*Value, sset *sparseSet, storeNumber []int32) []*Value
if w.Op == OpSelect1 { if w.Op == OpSelect1 {
w = w.Args[0] w = w.Args[0]
} }
w = w.Args[len(w.Args)-1] w = w.MemoryArg()
} }
var stack []*Value var stack []*Value
for _, v := range values { for _, v := range values {
......
...@@ -20,7 +20,7 @@ func tighten(f *Func) { ...@@ -20,7 +20,7 @@ func tighten(f *Func) {
// Tuple selectors must stay with the tuple generator. // Tuple selectors must stay with the tuple generator.
continue 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 // We can't move values which have a memory arg - it might
// make two memory values live across a block boundary. // make two memory values live across a block boundary.
continue continue
......
...@@ -311,3 +311,23 @@ func (v *Value) RegName() string { ...@@ -311,3 +311,23 @@ func (v *Value) RegName() string {
} }
return reg.(*Register).name 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
}
...@@ -120,7 +120,7 @@ func writebarrier(f *Func) { ...@@ -120,7 +120,7 @@ func writebarrier(f *Func) {
b.Values = b.Values[:start] b.Values = b.Values[:start]
// find the memory before the WB stores // find the memory before the WB stores
mem := stores[0].Args[len(stores[0].Args)-1] mem := stores[0].MemoryArg()
pos := stores[0].Pos pos := stores[0].Pos
bThen := f.NewBlock(BlockPlain) bThen := f.NewBlock(BlockPlain)
bElse := f.NewBlock(BlockPlain) bElse := f.NewBlock(BlockPlain)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment