aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/rewritedec.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2016-03-28 11:25:17 -0700
committerKeith Randall <khr@golang.org>2016-03-31 22:18:26 +0000
commit4a7aba775d6886109e0d4117d8c0a02112568686 (patch)
tree6e04167acfe2b55efd377ff6b5f31f293f298be2 /src/cmd/compile/internal/ssa/rewritedec.go
parente55896b9f421aeb6c33056a7cf6d7f90f8e36365 (diff)
downloadgo-4a7aba775d6886109e0d4117d8c0a02112568686.tar.gz
go-4a7aba775d6886109e0d4117d8c0a02112568686.zip
cmd/compile: better job of naming compound types
Compound AUTO types weren't named previously. That was because live variable analysis (plive.go) doesn't handle spilling to compound types. It can't handle them because there is no valid place to put VARDEFs when regalloc is spilling compound types. compound types = multiword builtin types: complex, string, slice, and interface. Instead, we split named AUTOs into individual one-word variables. For example, a string s gets split into a byte ptr s.ptr and an integer s.len. Those two variables can be spilled to / restored from independently. As a result, live variable analysis can handle them because they are one-word objects. This CL will change how AUTOs are described in DWARF information. Consider the code: func f(s string, i int) int { x := s[i:i+5] g() return lookup(x) } The old compiler would spill x to two consecutive slots on the stack, both named x (at offsets 0 and 8). The new compiler spills the pointer of x to a slot named x.ptr. It doesn't spill x.len at all, as it is a constant (5) and can be rematerialized for the call to lookup. So compound objects may not be spilled in their entirety, and even if they are they won't necessarily be contiguous. Such is the price of optimization. Re-enable live variable analysis tests. One test remains disabled, it fails because of #14904. Change-Id: I8ef2b5ab91e43a0d2136bfc231c05d100ec0b801 Reviewed-on: https://go-review.googlesource.com/21233 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewritedec.go')
-rw-r--r--src/cmd/compile/internal/ssa/rewritedec.go384
1 files changed, 384 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/rewritedec.go b/src/cmd/compile/internal/ssa/rewritedec.go
index c51cd88833..c32d54e1f5 100644
--- a/src/cmd/compile/internal/ssa/rewritedec.go
+++ b/src/cmd/compile/internal/ssa/rewritedec.go
@@ -8,12 +8,24 @@ import "math"
var _ = math.MinInt8 // in case not otherwise used
func rewriteValuedec(v *Value, config *Config) bool {
switch v.Op {
+ case OpComplexImag:
+ return rewriteValuedec_OpComplexImag(v, config)
+ case OpComplexReal:
+ return rewriteValuedec_OpComplexReal(v, config)
+ case OpIData:
+ return rewriteValuedec_OpIData(v, config)
+ case OpITab:
+ return rewriteValuedec_OpITab(v, config)
+ case OpLoad:
+ return rewriteValuedec_OpLoad(v, config)
case OpSliceCap:
return rewriteValuedec_OpSliceCap(v, config)
case OpSliceLen:
return rewriteValuedec_OpSliceLen(v, config)
case OpSlicePtr:
return rewriteValuedec_OpSlicePtr(v, config)
+ case OpStore:
+ return rewriteValuedec_OpStore(v, config)
case OpStringLen:
return rewriteValuedec_OpStringLen(v, config)
case OpStringPtr:
@@ -21,6 +33,214 @@ func rewriteValuedec(v *Value, config *Config) bool {
}
return false
}
+func rewriteValuedec_OpComplexImag(v *Value, config *Config) bool {
+ b := v.Block
+ _ = b
+ // match: (ComplexImag (ComplexMake _ imag ))
+ // cond:
+ // result: imag
+ for {
+ v_0 := v.Args[0]
+ if v_0.Op != OpComplexMake {
+ break
+ }
+ imag := v_0.Args[1]
+ v.reset(OpCopy)
+ v.Type = imag.Type
+ v.AddArg(imag)
+ return true
+ }
+ return false
+}
+func rewriteValuedec_OpComplexReal(v *Value, config *Config) bool {
+ b := v.Block
+ _ = b
+ // match: (ComplexReal (ComplexMake real _ ))
+ // cond:
+ // result: real
+ for {
+ v_0 := v.Args[0]
+ if v_0.Op != OpComplexMake {
+ break
+ }
+ real := v_0.Args[0]
+ v.reset(OpCopy)
+ v.Type = real.Type
+ v.AddArg(real)
+ return true
+ }
+ return false
+}
+func rewriteValuedec_OpIData(v *Value, config *Config) bool {
+ b := v.Block
+ _ = b
+ // match: (IData (IMake _ data))
+ // cond:
+ // result: data
+ for {
+ v_0 := v.Args[0]
+ if v_0.Op != OpIMake {
+ break
+ }
+ data := v_0.Args[1]
+ v.reset(OpCopy)
+ v.Type = data.Type
+ v.AddArg(data)
+ return true
+ }
+ return false
+}
+func rewriteValuedec_OpITab(v *Value, config *Config) bool {
+ b := v.Block
+ _ = b
+ // match: (ITab (IMake itab _))
+ // cond:
+ // result: itab
+ for {
+ v_0 := v.Args[0]
+ if v_0.Op != OpIMake {
+ break
+ }
+ itab := v_0.Args[0]
+ v.reset(OpCopy)
+ v.Type = itab.Type
+ v.AddArg(itab)
+ return true
+ }
+ return false
+}
+func rewriteValuedec_OpLoad(v *Value, config *Config) bool {
+ b := v.Block
+ _ = b
+ // match: (Load <t> ptr mem)
+ // cond: t.IsComplex() && t.Size() == 8
+ // result: (ComplexMake (Load <config.fe.TypeFloat32()> ptr mem) (Load <config.fe.TypeFloat32()> (OffPtr <config.fe.TypeFloat32().PtrTo()> [4] ptr) mem) )
+ for {
+ t := v.Type
+ ptr := v.Args[0]
+ mem := v.Args[1]
+ if !(t.IsComplex() && t.Size() == 8) {
+ break
+ }
+ v.reset(OpComplexMake)
+ v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeFloat32())
+ v0.AddArg(ptr)
+ v0.AddArg(mem)
+ v.AddArg(v0)
+ v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeFloat32())
+ v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeFloat32().PtrTo())
+ v2.AuxInt = 4
+ v2.AddArg(ptr)
+ v1.AddArg(v2)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ return true
+ }
+ // match: (Load <t> ptr mem)
+ // cond: t.IsComplex() && t.Size() == 16
+ // result: (ComplexMake (Load <config.fe.TypeFloat64()> ptr mem) (Load <config.fe.TypeFloat64()> (OffPtr <config.fe.TypeFloat64().PtrTo()> [8] ptr) mem) )
+ for {
+ t := v.Type
+ ptr := v.Args[0]
+ mem := v.Args[1]
+ if !(t.IsComplex() && t.Size() == 16) {
+ break
+ }
+ v.reset(OpComplexMake)
+ v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeFloat64())
+ v0.AddArg(ptr)
+ v0.AddArg(mem)
+ v.AddArg(v0)
+ v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeFloat64())
+ v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeFloat64().PtrTo())
+ v2.AuxInt = 8
+ v2.AddArg(ptr)
+ v1.AddArg(v2)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ return true
+ }
+ // match: (Load <t> ptr mem)
+ // cond: t.IsString()
+ // result: (StringMake (Load <config.fe.TypeBytePtr()> ptr mem) (Load <config.fe.TypeInt()> (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] ptr) mem))
+ for {
+ t := v.Type
+ ptr := v.Args[0]
+ mem := v.Args[1]
+ if !(t.IsString()) {
+ break
+ }
+ v.reset(OpStringMake)
+ v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeBytePtr())
+ v0.AddArg(ptr)
+ v0.AddArg(mem)
+ v.AddArg(v0)
+ v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeInt())
+ v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
+ v2.AuxInt = config.PtrSize
+ v2.AddArg(ptr)
+ v1.AddArg(v2)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ return true
+ }
+ // match: (Load <t> ptr mem)
+ // cond: t.IsSlice()
+ // result: (SliceMake (Load <t.ElemType().PtrTo()> ptr mem) (Load <config.fe.TypeInt()> (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] ptr) mem) (Load <config.fe.TypeInt()> (OffPtr <config.fe.TypeInt().PtrTo()> [2*config.PtrSize] ptr) mem))
+ for {
+ t := v.Type
+ ptr := v.Args[0]
+ mem := v.Args[1]
+ if !(t.IsSlice()) {
+ break
+ }
+ v.reset(OpSliceMake)
+ v0 := b.NewValue0(v.Line, OpLoad, t.ElemType().PtrTo())
+ v0.AddArg(ptr)
+ v0.AddArg(mem)
+ v.AddArg(v0)
+ v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeInt())
+ v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
+ v2.AuxInt = config.PtrSize
+ v2.AddArg(ptr)
+ v1.AddArg(v2)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ v3 := b.NewValue0(v.Line, OpLoad, config.fe.TypeInt())
+ v4 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
+ v4.AuxInt = 2 * config.PtrSize
+ v4.AddArg(ptr)
+ v3.AddArg(v4)
+ v3.AddArg(mem)
+ v.AddArg(v3)
+ return true
+ }
+ // match: (Load <t> ptr mem)
+ // cond: t.IsInterface()
+ // result: (IMake (Load <config.fe.TypeBytePtr()> ptr mem) (Load <config.fe.TypeBytePtr()> (OffPtr <config.fe.TypeBytePtr().PtrTo()> [config.PtrSize] ptr) mem))
+ for {
+ t := v.Type
+ ptr := v.Args[0]
+ mem := v.Args[1]
+ if !(t.IsInterface()) {
+ break
+ }
+ v.reset(OpIMake)
+ v0 := b.NewValue0(v.Line, OpLoad, config.fe.TypeBytePtr())
+ v0.AddArg(ptr)
+ v0.AddArg(mem)
+ v.AddArg(v0)
+ v1 := b.NewValue0(v.Line, OpLoad, config.fe.TypeBytePtr())
+ v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeBytePtr().PtrTo())
+ v2.AuxInt = config.PtrSize
+ v2.AddArg(ptr)
+ v1.AddArg(v2)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ return true
+ }
+ return false
+}
func rewriteValuedec_OpSliceCap(v *Value, config *Config) bool {
b := v.Block
_ = b
@@ -78,6 +298,170 @@ func rewriteValuedec_OpSlicePtr(v *Value, config *Config) bool {
}
return false
}
+func rewriteValuedec_OpStore(v *Value, config *Config) bool {
+ b := v.Block
+ _ = b
+ // match: (Store [8] dst (ComplexMake real imag) mem)
+ // cond:
+ // result: (Store [4] (OffPtr <config.fe.TypeFloat32().PtrTo()> [4] dst) imag (Store [4] dst real mem))
+ for {
+ if v.AuxInt != 8 {
+ break
+ }
+ dst := v.Args[0]
+ v_1 := v.Args[1]
+ if v_1.Op != OpComplexMake {
+ break
+ }
+ real := v_1.Args[0]
+ imag := v_1.Args[1]
+ mem := v.Args[2]
+ v.reset(OpStore)
+ v.AuxInt = 4
+ v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeFloat32().PtrTo())
+ v0.AuxInt = 4
+ v0.AddArg(dst)
+ v.AddArg(v0)
+ v.AddArg(imag)
+ v1 := b.NewValue0(v.Line, OpStore, TypeMem)
+ v1.AuxInt = 4
+ v1.AddArg(dst)
+ v1.AddArg(real)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ return true
+ }
+ // match: (Store [16] dst (ComplexMake real imag) mem)
+ // cond:
+ // result: (Store [8] (OffPtr <config.fe.TypeFloat64().PtrTo()> [8] dst) imag (Store [8] dst real mem))
+ for {
+ if v.AuxInt != 16 {
+ break
+ }
+ dst := v.Args[0]
+ v_1 := v.Args[1]
+ if v_1.Op != OpComplexMake {
+ break
+ }
+ real := v_1.Args[0]
+ imag := v_1.Args[1]
+ mem := v.Args[2]
+ v.reset(OpStore)
+ v.AuxInt = 8
+ v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeFloat64().PtrTo())
+ v0.AuxInt = 8
+ v0.AddArg(dst)
+ v.AddArg(v0)
+ v.AddArg(imag)
+ v1 := b.NewValue0(v.Line, OpStore, TypeMem)
+ v1.AuxInt = 8
+ v1.AddArg(dst)
+ v1.AddArg(real)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ return true
+ }
+ // match: (Store [2*config.PtrSize] dst (StringMake ptr len) mem)
+ // cond:
+ // result: (Store [config.PtrSize] (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] dst) len (Store [config.PtrSize] dst ptr mem))
+ for {
+ if v.AuxInt != 2*config.PtrSize {
+ break
+ }
+ dst := v.Args[0]
+ v_1 := v.Args[1]
+ if v_1.Op != OpStringMake {
+ break
+ }
+ ptr := v_1.Args[0]
+ len := v_1.Args[1]
+ mem := v.Args[2]
+ v.reset(OpStore)
+ v.AuxInt = config.PtrSize
+ v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
+ v0.AuxInt = config.PtrSize
+ v0.AddArg(dst)
+ v.AddArg(v0)
+ v.AddArg(len)
+ v1 := b.NewValue0(v.Line, OpStore, TypeMem)
+ v1.AuxInt = config.PtrSize
+ v1.AddArg(dst)
+ v1.AddArg(ptr)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ return true
+ }
+ // match: (Store [3*config.PtrSize] dst (SliceMake ptr len cap) mem)
+ // cond:
+ // result: (Store [config.PtrSize] (OffPtr <config.fe.TypeInt().PtrTo()> [2*config.PtrSize] dst) cap (Store [config.PtrSize] (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] dst) len (Store [config.PtrSize] dst ptr mem)))
+ for {
+ if v.AuxInt != 3*config.PtrSize {
+ break
+ }
+ dst := v.Args[0]
+ v_1 := v.Args[1]
+ if v_1.Op != OpSliceMake {
+ break
+ }
+ ptr := v_1.Args[0]
+ len := v_1.Args[1]
+ cap := v_1.Args[2]
+ mem := v.Args[2]
+ v.reset(OpStore)
+ v.AuxInt = config.PtrSize
+ v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
+ v0.AuxInt = 2 * config.PtrSize
+ v0.AddArg(dst)
+ v.AddArg(v0)
+ v.AddArg(cap)
+ v1 := b.NewValue0(v.Line, OpStore, TypeMem)
+ v1.AuxInt = config.PtrSize
+ v2 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeInt().PtrTo())
+ v2.AuxInt = config.PtrSize
+ v2.AddArg(dst)
+ v1.AddArg(v2)
+ v1.AddArg(len)
+ v3 := b.NewValue0(v.Line, OpStore, TypeMem)
+ v3.AuxInt = config.PtrSize
+ v3.AddArg(dst)
+ v3.AddArg(ptr)
+ v3.AddArg(mem)
+ v1.AddArg(v3)
+ v.AddArg(v1)
+ return true
+ }
+ // match: (Store [2*config.PtrSize] dst (IMake itab data) mem)
+ // cond:
+ // result: (Store [config.PtrSize] (OffPtr <config.fe.TypeBytePtr().PtrTo()> [config.PtrSize] dst) data (Store [config.PtrSize] dst itab mem))
+ for {
+ if v.AuxInt != 2*config.PtrSize {
+ break
+ }
+ dst := v.Args[0]
+ v_1 := v.Args[1]
+ if v_1.Op != OpIMake {
+ break
+ }
+ itab := v_1.Args[0]
+ data := v_1.Args[1]
+ mem := v.Args[2]
+ v.reset(OpStore)
+ v.AuxInt = config.PtrSize
+ v0 := b.NewValue0(v.Line, OpOffPtr, config.fe.TypeBytePtr().PtrTo())
+ v0.AuxInt = config.PtrSize
+ v0.AddArg(dst)
+ v.AddArg(v0)
+ v.AddArg(data)
+ v1 := b.NewValue0(v.Line, OpStore, TypeMem)
+ v1.AuxInt = config.PtrSize
+ v1.AddArg(dst)
+ v1.AddArg(itab)
+ v1.AddArg(mem)
+ v.AddArg(v1)
+ return true
+ }
+ return false
+}
func rewriteValuedec_OpStringLen(v *Value, config *Config) bool {
b := v.Block
_ = b