aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/export_test.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2017-04-28 14:12:28 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2017-05-09 23:01:51 +0000
commit46b88c9fbccad489aed53a77afa680792fff6eaa (patch)
treea1fcd0d8b8134f4be9eaf2a3bb16e8cc813d8724 /src/cmd/compile/internal/ssa/export_test.go
parent6a24b2d0c1f5a8e2fa5ddb56db5a207671e8beb8 (diff)
downloadgo-46b88c9fbccad489aed53a77afa680792fff6eaa.tar.gz
go-46b88c9fbccad489aed53a77afa680792fff6eaa.zip
cmd/compile: change ssa.Type into *types.Type
When package ssa was created, Type was in package gc. To avoid circular dependencies, we used an interface (ssa.Type) to represent type information in SSA. In the Go 1.9 cycle, gri extricated the Type type from package gc. As a result, we can now use it in package ssa. Now, instead of package types depending on package ssa, it is the other way. This is a more sensible dependency tree, and helps compiler performance a bit. Though this is a big CL, most of the changes are mechanical and uninteresting. Interesting bits: * Add new singleton globals to package types for the special SSA types Memory, Void, Invalid, Flags, and Int128. * Add two new Types, TSSA for the special types, and TTUPLE, for SSA tuple types. ssa.MakeTuple is now types.NewTuple. * Move type comparison result constants CMPlt, CMPeq, and CMPgt to package types. * We had picked the name "types" in our rules for the handy list of types provided by ssa.Config. That conflicted with the types package name, so change it to "typ". * Update the type comparison routine to handle tuples and special types inline. * Teach gc/fmt.go how to print special types. * We can now eliminate ElemTypes in favor of just Elem, and probably also some other duplicated Type methods designed to return ssa.Type instead of *types.Type. * The ssa tests were using their own dummy types, and they were not particularly careful about types in general. Of necessity, this CL switches them to use *types.Type; it does not make them more type-accurate. Unfortunately, using types.Type means initializing a bit of the types universe. This is prime for refactoring and improvement. This shrinks ssa.Value; it now fits in a smaller size class on 64 bit systems. This doesn't have a giant impact, though, since most Values are preallocated in a chunk. name old alloc/op new alloc/op delta Template 37.9MB ± 0% 37.7MB ± 0% -0.57% (p=0.000 n=10+8) Unicode 28.9MB ± 0% 28.7MB ± 0% -0.52% (p=0.000 n=10+10) GoTypes 110MB ± 0% 109MB ± 0% -0.88% (p=0.000 n=10+10) Flate 24.7MB ± 0% 24.6MB ± 0% -0.66% (p=0.000 n=10+10) GoParser 31.1MB ± 0% 30.9MB ± 0% -0.61% (p=0.000 n=10+9) Reflect 73.9MB ± 0% 73.4MB ± 0% -0.62% (p=0.000 n=10+8) Tar 25.8MB ± 0% 25.6MB ± 0% -0.77% (p=0.000 n=9+10) XML 41.2MB ± 0% 40.9MB ± 0% -0.80% (p=0.000 n=10+10) [Geo mean] 40.5MB 40.3MB -0.68% name old allocs/op new allocs/op delta Template 385k ± 0% 386k ± 0% ~ (p=0.356 n=10+9) Unicode 343k ± 1% 344k ± 0% ~ (p=0.481 n=10+10) GoTypes 1.16M ± 0% 1.16M ± 0% -0.16% (p=0.004 n=10+10) Flate 238k ± 1% 238k ± 1% ~ (p=0.853 n=10+10) GoParser 320k ± 0% 320k ± 0% ~ (p=0.720 n=10+9) Reflect 957k ± 0% 957k ± 0% ~ (p=0.460 n=10+8) Tar 252k ± 0% 252k ± 0% ~ (p=0.133 n=9+10) XML 400k ± 0% 400k ± 0% ~ (p=0.796 n=10+10) [Geo mean] 428k 428k -0.01% Removing all the interface calls helps non-trivially with CPU, though. name old time/op new time/op delta Template 178ms ± 4% 173ms ± 3% -2.90% (p=0.000 n=94+96) Unicode 85.0ms ± 4% 83.9ms ± 4% -1.23% (p=0.000 n=96+96) GoTypes 543ms ± 3% 528ms ± 3% -2.73% (p=0.000 n=98+96) Flate 116ms ± 3% 113ms ± 4% -2.34% (p=0.000 n=96+99) GoParser 144ms ± 3% 140ms ± 4% -2.80% (p=0.000 n=99+97) Reflect 344ms ± 3% 334ms ± 4% -3.02% (p=0.000 n=100+99) Tar 106ms ± 5% 103ms ± 4% -3.30% (p=0.000 n=98+94) XML 198ms ± 5% 192ms ± 4% -2.88% (p=0.000 n=92+95) [Geo mean] 178ms 173ms -2.65% name old user-time/op new user-time/op delta Template 229ms ± 5% 224ms ± 5% -2.36% (p=0.000 n=95+99) Unicode 107ms ± 6% 106ms ± 5% -1.13% (p=0.001 n=93+95) GoTypes 696ms ± 4% 679ms ± 4% -2.45% (p=0.000 n=97+99) Flate 137ms ± 4% 134ms ± 5% -2.66% (p=0.000 n=99+96) GoParser 176ms ± 5% 172ms ± 8% -2.27% (p=0.000 n=98+100) Reflect 430ms ± 6% 411ms ± 5% -4.46% (p=0.000 n=100+92) Tar 128ms ±13% 123ms ±13% -4.21% (p=0.000 n=100+100) XML 239ms ± 6% 233ms ± 6% -2.50% (p=0.000 n=95+97) [Geo mean] 220ms 213ms -2.76% Change-Id: I15c7d6268347f8358e75066dfdbd77db24e8d0c1 Reviewed-on: https://go-review.googlesource.com/42145 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/export_test.go')
-rw-r--r--src/cmd/compile/internal/ssa/export_test.go103
1 files changed, 76 insertions, 27 deletions
diff --git a/src/cmd/compile/internal/ssa/export_test.go b/src/cmd/compile/internal/ssa/export_test.go
index 228a33697e..3bb67a951b 100644
--- a/src/cmd/compile/internal/ssa/export_test.go
+++ b/src/cmd/compile/internal/ssa/export_test.go
@@ -5,10 +5,12 @@
package ssa
import (
+ "cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/obj/s390x"
"cmd/internal/obj/x86"
"cmd/internal/src"
+ "fmt"
"testing"
)
@@ -61,11 +63,11 @@ type DummyFrontend struct {
}
type DummyAuto struct {
- t Type
+ t *types.Type
s string
}
-func (d *DummyAuto) Typ() Type {
+func (d *DummyAuto) Typ() *types.Type {
return d.t
}
@@ -76,7 +78,7 @@ func (d *DummyAuto) String() string {
func (DummyFrontend) StringData(s string) interface{} {
return nil
}
-func (DummyFrontend) Auto(pos src.XPos, t Type) GCNode {
+func (DummyFrontend) Auto(pos src.XPos, t *types.Type) GCNode {
return &DummyAuto{t: t, s: "aDummyAuto"}
}
func (d DummyFrontend) SplitString(s LocalSlot) (LocalSlot, LocalSlot) {
@@ -128,34 +130,81 @@ func (d DummyFrontend) Warnl(_ src.XPos, msg string, args ...interface{}) { d.t
func (d DummyFrontend) Debug_checknil() bool { return false }
func (d DummyFrontend) Debug_wb() bool { return false }
-var dummyTypes = Types{
- Bool: TypeBool,
- Int8: TypeInt8,
- Int16: TypeInt16,
- Int32: TypeInt32,
- Int64: TypeInt64,
- UInt8: TypeUInt8,
- UInt16: TypeUInt16,
- UInt32: TypeUInt32,
- UInt64: TypeUInt64,
- Float32: TypeFloat32,
- Float64: TypeFloat64,
- Int: TypeInt64,
- Uintptr: TypeUInt64,
- String: nil,
- BytePtr: TypeBytePtr,
- Int32Ptr: TypeInt32.PtrTo(),
- UInt32Ptr: TypeUInt32.PtrTo(),
- IntPtr: TypeInt64.PtrTo(),
- UintptrPtr: TypeUInt64.PtrTo(),
- Float32Ptr: TypeFloat32.PtrTo(),
- Float64Ptr: TypeFloat64.PtrTo(),
- BytePtrPtr: TypeBytePtr.PtrTo(),
+var dummyTypes Types
+
+func init() {
+ // Initialize just enough of the universe and the types package to make our tests function.
+ // TODO(josharian): move universe initialization to the types package,
+ // so this test setup can share it.
+
+ types.Tconv = func(t *types.Type, flag, mode, depth int) string {
+ return t.Etype.String()
+ }
+ types.Sconv = func(s *types.Sym, flag, mode int) string {
+ return "sym"
+ }
+ types.FormatSym = func(sym *types.Sym, s fmt.State, verb rune, mode int) {
+ fmt.Fprintf(s, "sym")
+ }
+ types.FormatType = func(t *types.Type, s fmt.State, verb rune, mode int) {
+ fmt.Fprintf(s, "%v", t.Etype)
+ }
+ types.Dowidth = func(t *types.Type) {}
+
+ types.Tptr = types.TPTR64
+ for _, typ := range [...]struct {
+ width int64
+ et types.EType
+ }{
+ {1, types.TINT8},
+ {1, types.TUINT8},
+ {1, types.TBOOL},
+ {2, types.TINT16},
+ {2, types.TUINT16},
+ {4, types.TINT32},
+ {4, types.TUINT32},
+ {4, types.TFLOAT32},
+ {4, types.TFLOAT64},
+ {8, types.TUINT64},
+ {8, types.TINT64},
+ {8, types.TINT},
+ {8, types.TUINTPTR},
+ } {
+ t := types.New(typ.et)
+ t.Width = typ.width
+ t.Align = uint8(typ.width)
+ types.Types[typ.et] = t
+ }
+
+ dummyTypes = Types{
+ Bool: types.Types[types.TBOOL],
+ Int8: types.Types[types.TINT8],
+ Int16: types.Types[types.TINT16],
+ Int32: types.Types[types.TINT32],
+ Int64: types.Types[types.TINT64],
+ UInt8: types.Types[types.TUINT8],
+ UInt16: types.Types[types.TUINT16],
+ UInt32: types.Types[types.TUINT32],
+ UInt64: types.Types[types.TUINT64],
+ Float32: types.Types[types.TFLOAT32],
+ Float64: types.Types[types.TFLOAT64],
+ Int: types.Types[types.TINT],
+ Uintptr: types.Types[types.TUINTPTR],
+ String: types.Types[types.TSTRING],
+ BytePtr: types.NewPtr(types.Types[types.TUINT8]),
+ Int32Ptr: types.NewPtr(types.Types[types.TINT32]),
+ UInt32Ptr: types.NewPtr(types.Types[types.TUINT32]),
+ IntPtr: types.NewPtr(types.Types[types.TINT]),
+ UintptrPtr: types.NewPtr(types.Types[types.TUINTPTR]),
+ Float32Ptr: types.NewPtr(types.Types[types.TFLOAT32]),
+ Float64Ptr: types.NewPtr(types.Types[types.TFLOAT64]),
+ BytePtrPtr: types.NewPtr(types.NewPtr(types.Types[types.TUINT8])),
+ }
}
func (d DummyFrontend) DerefItab(sym *obj.LSym, off int64) *obj.LSym { return nil }
-func (d DummyFrontend) CanSSA(t Type) bool {
+func (d DummyFrontend) CanSSA(t *types.Type) bool {
// There are no un-SSAable types in dummy land.
return true
}