diff options
author | Philip Hofer <phofer@umich.edu> | 2017-03-03 13:44:18 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2017-03-09 21:40:47 +0000 |
commit | b0e91d836a0abd46899cf78fdd93303afcf6c637 (patch) | |
tree | 161359a455652648f81b967f834be8fe39ece98d /src/cmd/compile/internal/ssa/value.go | |
parent | e471ad9189d1eba54c8cb5414c47e413cea78df2 (diff) | |
download | go-b0e91d836a0abd46899cf78fdd93303afcf6c637.tar.gz go-b0e91d836a0abd46899cf78fdd93303afcf6c637.zip |
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: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/value.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/value.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/value.go b/src/cmd/compile/internal/ssa/value.go index 00f2454bf6..93172bc45a 100644 --- a/src/cmd/compile/internal/ssa/value.go +++ b/src/cmd/compile/internal/ssa/value.go @@ -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 +} |