2016-10-13 06:57:00 -04:00
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package ssa
|
|
|
|
|
|
2016-12-06 17:08:06 -08:00
|
|
|
import (
|
2020-12-29 01:22:50 -08:00
|
|
|
"cmd/compile/internal/reflectdata"
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
"cmd/compile/internal/types"
|
2017-02-06 13:30:40 -08:00
|
|
|
"cmd/internal/obj"
|
2020-04-28 10:20:55 -07:00
|
|
|
"cmd/internal/objabi"
|
2016-12-06 17:08:06 -08:00
|
|
|
"cmd/internal/src"
|
2019-10-06 17:38:39 -07:00
|
|
|
"fmt"
|
2016-12-06 17:08:06 -08:00
|
|
|
)
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2019-10-06 17:38:39 -07:00
|
|
|
// A ZeroRegion records parts of an object which are known to be zero.
|
2019-01-04 17:34:33 -08:00
|
|
|
// A ZeroRegion only applies to a single memory state.
|
2019-10-06 17:38:39 -07:00
|
|
|
// Each bit in mask is set if the corresponding pointer-sized word of
|
|
|
|
|
// the base object is known to be zero.
|
|
|
|
|
// In other words, if mask & (1<<i) != 0, then [base+i*ptrSize, base+(i+1)*ptrSize)
|
|
|
|
|
// is known to be zero.
|
2019-01-04 17:34:33 -08:00
|
|
|
type ZeroRegion struct {
|
|
|
|
|
base *Value
|
2019-10-06 17:38:39 -07:00
|
|
|
mask uint64
|
2019-01-04 17:34:33 -08:00
|
|
|
}
|
|
|
|
|
|
2018-11-22 11:46:44 +01:00
|
|
|
// needwb reports whether we need write barrier for store op v.
|
2017-02-05 23:43:31 -05:00
|
|
|
// v must be Store/Move/Zero.
|
2019-01-04 17:34:33 -08:00
|
|
|
// zeroes provides known zero information (keyed by ID of memory-type values).
|
|
|
|
|
func needwb(v *Value, zeroes map[ID]ZeroRegion) bool {
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
t, ok := v.Aux.(*types.Type)
|
2017-02-05 23:43:31 -05:00
|
|
|
if !ok {
|
|
|
|
|
v.Fatalf("store aux is not a type: %s", v.LongString())
|
|
|
|
|
}
|
2020-08-21 20:20:12 -07:00
|
|
|
if !t.HasPointers() {
|
2017-02-05 23:43:31 -05:00
|
|
|
return false
|
|
|
|
|
}
|
2017-03-17 11:53:24 -04:00
|
|
|
if IsStackAddr(v.Args[0]) {
|
2017-02-05 23:43:31 -05:00
|
|
|
return false // write on stack doesn't need write barrier
|
|
|
|
|
}
|
2018-11-27 12:40:16 -08:00
|
|
|
if v.Op == OpMove && IsReadOnlyGlobalAddr(v.Args[1]) && IsNewObject(v.Args[0], v.MemoryArg()) {
|
|
|
|
|
// Copying data from readonly memory into a fresh object doesn't need a write barrier.
|
|
|
|
|
return false
|
|
|
|
|
}
|
2019-01-04 17:34:33 -08:00
|
|
|
if v.Op == OpStore && IsGlobalAddr(v.Args[1]) {
|
|
|
|
|
// Storing pointers to non-heap locations into zeroed memory doesn't need a write barrier.
|
|
|
|
|
ptr := v.Args[0]
|
|
|
|
|
var off int64
|
|
|
|
|
size := v.Aux.(*types.Type).Size()
|
|
|
|
|
for ptr.Op == OpOffPtr {
|
|
|
|
|
off += ptr.AuxInt
|
|
|
|
|
ptr = ptr.Args[0]
|
|
|
|
|
}
|
2019-10-06 17:38:39 -07:00
|
|
|
ptrSize := v.Block.Func.Config.PtrSize
|
|
|
|
|
if off%ptrSize != 0 || size%ptrSize != 0 {
|
|
|
|
|
v.Fatalf("unaligned pointer write")
|
|
|
|
|
}
|
|
|
|
|
if off < 0 || off+size > 64*ptrSize {
|
|
|
|
|
// write goes off end of tracked offsets
|
|
|
|
|
return true
|
|
|
|
|
}
|
2019-01-04 17:34:33 -08:00
|
|
|
z := zeroes[v.MemoryArg().ID]
|
2019-10-06 17:38:39 -07:00
|
|
|
if ptr != z.base {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
for i := off; i < off+size; i += ptrSize {
|
|
|
|
|
if z.mask>>uint(i/ptrSize)&1 == 0 {
|
|
|
|
|
return true // not known to be zero
|
|
|
|
|
}
|
2019-01-04 17:34:33 -08:00
|
|
|
}
|
2019-10-06 17:38:39 -07:00
|
|
|
// All written locations are known to be zero - write barrier not needed.
|
|
|
|
|
return false
|
2019-01-04 17:34:33 -08:00
|
|
|
}
|
2017-02-05 23:43:31 -05:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// writebarrier pass inserts write barriers for store ops (Store, Move, Zero)
|
|
|
|
|
// when necessary (the condition above). It rewrites store ops to branches
|
|
|
|
|
// and runtime calls, like
|
2016-10-13 06:57:00 -04:00
|
|
|
//
|
|
|
|
|
// if writeBarrier.enabled {
|
2018-01-15 12:27:17 -05:00
|
|
|
// gcWriteBarrier(ptr, val) // Not a regular Go call
|
2016-10-13 06:57:00 -04:00
|
|
|
// } else {
|
|
|
|
|
// *ptr = val
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// A sequence of WB stores for many pointer fields of a single type will
|
|
|
|
|
// be emitted together, with a single branch.
|
|
|
|
|
func writebarrier(f *Func) {
|
2017-03-16 22:42:10 -07:00
|
|
|
if !f.fe.UseWriteBarrier() {
|
2017-02-05 23:43:31 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
var sb, sp, wbaddr, const0 *Value
|
2018-01-15 12:27:17 -05:00
|
|
|
var typedmemmove, typedmemclr, gcWriteBarrier *obj.LSym
|
2017-02-01 14:27:40 -05:00
|
|
|
var stores, after []*Value
|
|
|
|
|
var sset *sparseSet
|
|
|
|
|
var storeNumber []int32
|
|
|
|
|
|
2019-01-04 17:34:33 -08:00
|
|
|
zeroes := f.computeZeroMap()
|
2017-02-01 14:27:40 -05:00
|
|
|
for _, b := range f.Blocks { // range loop is safe since the blocks we added contain no stores to expand
|
2017-02-05 23:43:31 -05:00
|
|
|
// first, identify all the stores that need to insert a write barrier.
|
|
|
|
|
// mark them with WB ops temporarily. record presence of WB ops.
|
2017-08-30 11:12:52 -04:00
|
|
|
nWBops := 0 // count of temporarily created WB ops remaining to be rewritten in the current block
|
2017-02-01 14:27:40 -05:00
|
|
|
for _, v := range b.Values {
|
2016-10-13 06:57:00 -04:00
|
|
|
switch v.Op {
|
2017-02-05 23:43:31 -05:00
|
|
|
case OpStore, OpMove, OpZero:
|
2019-01-04 17:34:33 -08:00
|
|
|
if needwb(v, zeroes) {
|
2016-10-13 06:57:00 -04:00
|
|
|
switch v.Op {
|
2017-02-05 23:43:31 -05:00
|
|
|
case OpStore:
|
|
|
|
|
v.Op = OpStoreWB
|
|
|
|
|
case OpMove:
|
|
|
|
|
v.Op = OpMoveWB
|
|
|
|
|
case OpZero:
|
|
|
|
|
v.Op = OpZeroWB
|
2016-10-13 06:57:00 -04:00
|
|
|
}
|
2017-08-30 11:12:52 -04:00
|
|
|
nWBops++
|
2016-10-13 06:57:00 -04:00
|
|
|
}
|
2017-02-01 14:27:40 -05:00
|
|
|
}
|
|
|
|
|
}
|
2017-08-30 11:12:52 -04:00
|
|
|
if nWBops == 0 {
|
2017-02-01 14:27:40 -05:00
|
|
|
continue
|
|
|
|
|
}
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
if wbaddr == nil {
|
|
|
|
|
// lazily initialize global values for write barrier test and calls
|
|
|
|
|
// find SB and SP values in entry block
|
|
|
|
|
initpos := f.Entry.Pos
|
2020-07-09 15:47:26 -04:00
|
|
|
sp, sb = f.spSb()
|
2017-09-18 14:53:56 -07:00
|
|
|
wbsym := f.fe.Syslook("writeBarrier")
|
2017-03-18 10:16:03 -07:00
|
|
|
wbaddr = f.Entry.NewValue1A(initpos, OpAddr, f.Config.Types.UInt32Ptr, wbsym, sb)
|
2018-01-15 12:27:17 -05:00
|
|
|
gcWriteBarrier = f.fe.Syslook("gcWriteBarrier")
|
2017-03-16 22:42:10 -07:00
|
|
|
typedmemmove = f.fe.Syslook("typedmemmove")
|
|
|
|
|
typedmemclr = f.fe.Syslook("typedmemclr")
|
2018-04-03 15:52:30 +01:00
|
|
|
const0 = f.ConstInt32(f.Config.Types.UInt32, 0)
|
2017-02-01 14:27:40 -05:00
|
|
|
|
|
|
|
|
// allocate auxiliary data structures for computing store order
|
|
|
|
|
sset = f.newSparseSet(f.NumValues())
|
|
|
|
|
defer f.retSparseSet(sset)
|
|
|
|
|
storeNumber = make([]int32, f.NumValues())
|
|
|
|
|
}
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
// order values in store order
|
|
|
|
|
b.Values = storeOrder(b.Values, sset, storeNumber)
|
|
|
|
|
|
2018-02-26 20:48:53 -05:00
|
|
|
firstSplit := true
|
2017-02-01 14:27:40 -05:00
|
|
|
again:
|
|
|
|
|
// find the start and end of the last contiguous WB store sequence.
|
|
|
|
|
// a branch will be inserted there. values after it will be moved
|
|
|
|
|
// to a new block.
|
|
|
|
|
var last *Value
|
|
|
|
|
var start, end int
|
|
|
|
|
values := b.Values
|
2017-04-27 11:56:46 -07:00
|
|
|
FindSeq:
|
2017-02-01 14:27:40 -05:00
|
|
|
for i := len(values) - 1; i >= 0; i-- {
|
|
|
|
|
w := values[i]
|
2017-04-27 11:56:46 -07:00
|
|
|
switch w.Op {
|
|
|
|
|
case OpStoreWB, OpMoveWB, OpZeroWB:
|
|
|
|
|
start = i
|
2017-02-01 14:27:40 -05:00
|
|
|
if last == nil {
|
|
|
|
|
last = w
|
|
|
|
|
end = i + 1
|
2016-12-03 19:17:16 -05:00
|
|
|
}
|
2017-04-27 11:56:46 -07:00
|
|
|
case OpVarDef, OpVarLive, OpVarKill:
|
|
|
|
|
continue
|
|
|
|
|
default:
|
|
|
|
|
if last == nil {
|
|
|
|
|
continue
|
2016-10-13 06:57:00 -04:00
|
|
|
}
|
2017-04-27 11:56:46 -07:00
|
|
|
break FindSeq
|
2017-02-01 14:27:40 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
stores = append(stores[:0], b.Values[start:end]...) // copy to avoid aliasing
|
|
|
|
|
after = append(after[:0], b.Values[end:]...)
|
|
|
|
|
b.Values = b.Values[:start]
|
|
|
|
|
|
|
|
|
|
// find the memory before the WB stores
|
2017-03-03 13:44:18 -08:00
|
|
|
mem := stores[0].MemoryArg()
|
2017-02-01 14:27:40 -05:00
|
|
|
pos := stores[0].Pos
|
|
|
|
|
bThen := f.NewBlock(BlockPlain)
|
|
|
|
|
bElse := f.NewBlock(BlockPlain)
|
|
|
|
|
bEnd := f.NewBlock(b.Kind)
|
|
|
|
|
bThen.Pos = pos
|
|
|
|
|
bElse.Pos = pos
|
|
|
|
|
bEnd.Pos = b.Pos
|
|
|
|
|
b.Pos = pos
|
|
|
|
|
|
|
|
|
|
// set up control flow for end block
|
2019-08-12 20:19:58 +01:00
|
|
|
bEnd.CopyControls(b)
|
2017-02-01 14:27:40 -05:00
|
|
|
bEnd.Likely = b.Likely
|
|
|
|
|
for _, e := range b.Succs {
|
|
|
|
|
bEnd.Succs = append(bEnd.Succs, e)
|
|
|
|
|
e.b.Preds[e.i].b = bEnd
|
|
|
|
|
}
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
// set up control flow for write barrier test
|
|
|
|
|
// load word, test word, avoiding partial register write from load byte.
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
cfgtypes := &f.Config.Types
|
|
|
|
|
flag := b.NewValue2(pos, OpLoad, cfgtypes.UInt32, wbaddr, mem)
|
|
|
|
|
flag = b.NewValue2(pos, OpNeq32, cfgtypes.Bool, flag, const0)
|
2017-02-01 14:27:40 -05:00
|
|
|
b.Kind = BlockIf
|
|
|
|
|
b.SetControl(flag)
|
|
|
|
|
b.Likely = BranchUnlikely
|
|
|
|
|
b.Succs = b.Succs[:0]
|
|
|
|
|
b.AddEdgeTo(bThen)
|
|
|
|
|
b.AddEdgeTo(bElse)
|
2017-10-26 12:33:04 -04:00
|
|
|
// TODO: For OpStoreWB and the buffered write barrier,
|
|
|
|
|
// we could move the write out of the write barrier,
|
|
|
|
|
// which would lead to fewer branches. We could do
|
|
|
|
|
// something similar to OpZeroWB, since the runtime
|
|
|
|
|
// could provide just the barrier half and then we
|
|
|
|
|
// could unconditionally do an OpZero (which could
|
|
|
|
|
// also generate better zeroing code). OpMoveWB is
|
|
|
|
|
// trickier and would require changing how
|
|
|
|
|
// cgoCheckMemmove works.
|
2017-02-01 14:27:40 -05:00
|
|
|
bThen.AddEdgeTo(bEnd)
|
|
|
|
|
bElse.AddEdgeTo(bEnd)
|
|
|
|
|
|
|
|
|
|
// for each write barrier store, append write barrier version to bThen
|
|
|
|
|
// and simple store version to bElse
|
|
|
|
|
memThen := mem
|
|
|
|
|
memElse := mem
|
2019-03-21 13:40:28 -04:00
|
|
|
|
|
|
|
|
// If the source of a MoveWB is volatile (will be clobbered by a
|
|
|
|
|
// function call), we need to copy it to a temporary location, as
|
|
|
|
|
// marshaling the args of typedmemmove might clobber the value we're
|
|
|
|
|
// trying to move.
|
|
|
|
|
// Look for volatile source, copy it to temporary before we emit any
|
|
|
|
|
// call.
|
|
|
|
|
// It is unlikely to have more than one of them. Just do a linear
|
|
|
|
|
// search instead of using a map.
|
|
|
|
|
type volatileCopy struct {
|
|
|
|
|
src *Value // address of original volatile value
|
|
|
|
|
tmp *Value // address of temporary we've copied the volatile value into
|
|
|
|
|
}
|
|
|
|
|
var volatiles []volatileCopy
|
|
|
|
|
copyLoop:
|
|
|
|
|
for _, w := range stores {
|
|
|
|
|
if w.Op == OpMoveWB {
|
|
|
|
|
val := w.Args[1]
|
|
|
|
|
if isVolatile(val) {
|
|
|
|
|
for _, c := range volatiles {
|
|
|
|
|
if val == c.src {
|
|
|
|
|
continue copyLoop // already copied
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t := val.Type.Elem()
|
|
|
|
|
tmp := f.fe.Auto(w.Pos, t)
|
|
|
|
|
memThen = bThen.NewValue1A(w.Pos, OpVarDef, types.TypeMem, tmp, memThen)
|
|
|
|
|
tmpaddr := bThen.NewValue2A(w.Pos, OpLocalAddr, t.PtrTo(), tmp, sp, memThen)
|
|
|
|
|
siz := t.Size()
|
|
|
|
|
memThen = bThen.NewValue3I(w.Pos, OpMove, types.TypeMem, siz, tmpaddr, val, memThen)
|
|
|
|
|
memThen.Aux = t
|
|
|
|
|
volatiles = append(volatiles, volatileCopy{val, tmpaddr})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
for _, w := range stores {
|
|
|
|
|
ptr := w.Args[0]
|
2017-04-27 06:00:18 -07:00
|
|
|
pos := w.Pos
|
2017-02-01 14:27:40 -05:00
|
|
|
|
|
|
|
|
var fn *obj.LSym
|
2017-09-18 14:53:56 -07:00
|
|
|
var typ *obj.LSym
|
2017-04-27 06:00:18 -07:00
|
|
|
var val *Value
|
2017-02-01 14:27:40 -05:00
|
|
|
switch w.Op {
|
|
|
|
|
case OpStoreWB:
|
|
|
|
|
val = w.Args[1]
|
2017-08-30 11:12:52 -04:00
|
|
|
nWBops--
|
2017-02-02 19:47:59 -05:00
|
|
|
case OpMoveWB:
|
2017-02-01 14:27:40 -05:00
|
|
|
fn = typedmemmove
|
|
|
|
|
val = w.Args[1]
|
2020-12-29 01:22:50 -08:00
|
|
|
typ = reflectdata.TypeLinksym(w.Aux.(*types.Type))
|
2017-08-30 11:12:52 -04:00
|
|
|
nWBops--
|
2017-02-01 14:27:40 -05:00
|
|
|
case OpZeroWB:
|
|
|
|
|
fn = typedmemclr
|
2020-12-29 01:22:50 -08:00
|
|
|
typ = reflectdata.TypeLinksym(w.Aux.(*types.Type))
|
2017-08-30 11:12:52 -04:00
|
|
|
nWBops--
|
2017-04-27 11:56:46 -07:00
|
|
|
case OpVarDef, OpVarLive, OpVarKill:
|
2017-02-01 14:27:40 -05:00
|
|
|
}
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
// then block: emit write barrier call
|
2017-04-27 11:56:46 -07:00
|
|
|
switch w.Op {
|
|
|
|
|
case OpStoreWB, OpMoveWB, OpZeroWB:
|
2018-01-15 12:27:17 -05:00
|
|
|
if w.Op == OpStoreWB {
|
2017-10-26 12:33:04 -04:00
|
|
|
memThen = bThen.NewValue3A(pos, OpWB, types.TypeMem, gcWriteBarrier, ptr, val, memThen)
|
|
|
|
|
} else {
|
2019-03-21 13:40:28 -04:00
|
|
|
srcval := val
|
|
|
|
|
if w.Op == OpMoveWB && isVolatile(srcval) {
|
|
|
|
|
for _, c := range volatiles {
|
|
|
|
|
if srcval == c.src {
|
|
|
|
|
srcval = c.tmp
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
memThen = wbcall(pos, bThen, fn, typ, ptr, srcval, memThen, sp, sb)
|
2017-10-26 12:33:04 -04:00
|
|
|
}
|
2018-01-15 12:27:17 -05:00
|
|
|
// Note that we set up a writebarrier function call.
|
|
|
|
|
f.fe.SetWBPos(pos)
|
2017-04-27 11:56:46 -07:00
|
|
|
case OpVarDef, OpVarLive, OpVarKill:
|
|
|
|
|
memThen = bThen.NewValue1A(pos, w.Op, types.TypeMem, w.Aux, memThen)
|
|
|
|
|
}
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
// else block: normal store
|
2017-03-13 21:51:08 -04:00
|
|
|
switch w.Op {
|
|
|
|
|
case OpStoreWB:
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
memElse = bElse.NewValue3A(pos, OpStore, types.TypeMem, w.Aux, ptr, val, memElse)
|
2017-03-13 21:51:08 -04:00
|
|
|
case OpMoveWB:
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
memElse = bElse.NewValue3I(pos, OpMove, types.TypeMem, w.AuxInt, ptr, val, memElse)
|
2017-03-13 21:51:08 -04:00
|
|
|
memElse.Aux = w.Aux
|
|
|
|
|
case OpZeroWB:
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
memElse = bElse.NewValue2I(pos, OpZero, types.TypeMem, w.AuxInt, ptr, memElse)
|
2017-03-13 21:51:08 -04:00
|
|
|
memElse.Aux = w.Aux
|
2017-04-27 11:56:46 -07:00
|
|
|
case OpVarDef, OpVarLive, OpVarKill:
|
|
|
|
|
memElse = bElse.NewValue1A(pos, w.Op, types.TypeMem, w.Aux, memElse)
|
2017-02-01 14:27:40 -05:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2019-03-21 13:40:28 -04:00
|
|
|
// mark volatile temps dead
|
|
|
|
|
for _, c := range volatiles {
|
|
|
|
|
tmpNode := c.tmp.Aux
|
|
|
|
|
memThen = bThen.NewValue1A(memThen.Pos, OpVarKill, types.TypeMem, tmpNode, memThen)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
// merge memory
|
|
|
|
|
// Splice memory Phi into the last memory of the original sequence,
|
|
|
|
|
// which may be used in subsequent blocks. Other memories in the
|
|
|
|
|
// sequence must be dead after this block since there can be only
|
|
|
|
|
// one memory live.
|
|
|
|
|
bEnd.Values = append(bEnd.Values, last)
|
|
|
|
|
last.Block = bEnd
|
|
|
|
|
last.reset(OpPhi)
|
2019-10-30 10:29:47 -07:00
|
|
|
last.Pos = last.Pos.WithNotStmt()
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
last.Type = types.TypeMem
|
2017-02-01 14:27:40 -05:00
|
|
|
last.AddArg(memThen)
|
|
|
|
|
last.AddArg(memElse)
|
|
|
|
|
for _, w := range stores {
|
|
|
|
|
if w != last {
|
|
|
|
|
w.resetArgs()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, w := range stores {
|
|
|
|
|
if w != last {
|
|
|
|
|
f.freeValue(w)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// put values after the store sequence into the end block
|
|
|
|
|
bEnd.Values = append(bEnd.Values, after...)
|
|
|
|
|
for _, w := range after {
|
|
|
|
|
w.Block = bEnd
|
|
|
|
|
}
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2018-02-26 20:48:53 -05:00
|
|
|
// Preemption is unsafe between loading the write
|
|
|
|
|
// barrier-enabled flag and performing the write
|
|
|
|
|
// because that would allow a GC phase transition,
|
|
|
|
|
// which would invalidate the flag. Remember the
|
|
|
|
|
// conditional block so liveness analysis can disable
|
|
|
|
|
// safe-points. This is somewhat subtle because we're
|
|
|
|
|
// splitting b bottom-up.
|
|
|
|
|
if firstSplit {
|
|
|
|
|
// Add b itself.
|
|
|
|
|
b.Func.WBLoads = append(b.Func.WBLoads, b)
|
|
|
|
|
firstSplit = false
|
|
|
|
|
} else {
|
|
|
|
|
// We've already split b, so we just pushed a
|
|
|
|
|
// write barrier test into bEnd.
|
|
|
|
|
b.Func.WBLoads = append(b.Func.WBLoads, bEnd)
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 14:27:40 -05:00
|
|
|
// if we have more stores in this block, do this block again
|
2017-08-30 11:12:52 -04:00
|
|
|
if nWBops > 0 {
|
|
|
|
|
goto again
|
2016-10-13 06:57:00 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 17:34:33 -08:00
|
|
|
// computeZeroMap returns a map from an ID of a memory value to
|
|
|
|
|
// a set of locations that are known to be zeroed at that memory value.
|
|
|
|
|
func (f *Func) computeZeroMap() map[ID]ZeroRegion {
|
2019-10-06 17:38:39 -07:00
|
|
|
ptrSize := f.Config.PtrSize
|
2019-01-04 17:34:33 -08:00
|
|
|
// Keep track of which parts of memory are known to be zero.
|
|
|
|
|
// This helps with removing write barriers for various initialization patterns.
|
|
|
|
|
// This analysis is conservative. We only keep track, for each memory state, of
|
2019-10-06 17:38:39 -07:00
|
|
|
// which of the first 64 words of a single object are known to be zero.
|
2019-01-04 17:34:33 -08:00
|
|
|
zeroes := map[ID]ZeroRegion{}
|
|
|
|
|
// Find new objects.
|
|
|
|
|
for _, b := range f.Blocks {
|
|
|
|
|
for _, v := range b.Values {
|
|
|
|
|
if v.Op != OpLoad {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
mem := v.MemoryArg()
|
|
|
|
|
if IsNewObject(v, mem) {
|
2019-10-06 17:38:39 -07:00
|
|
|
nptr := v.Type.Elem().Size() / ptrSize
|
|
|
|
|
if nptr > 64 {
|
|
|
|
|
nptr = 64
|
|
|
|
|
}
|
|
|
|
|
zeroes[mem.ID] = ZeroRegion{base: v, mask: 1<<uint(nptr) - 1}
|
2019-01-04 17:34:33 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Find stores to those new objects.
|
|
|
|
|
for {
|
|
|
|
|
changed := false
|
|
|
|
|
for _, b := range f.Blocks {
|
|
|
|
|
// Note: iterating forwards helps convergence, as values are
|
|
|
|
|
// typically (but not always!) in store order.
|
|
|
|
|
for _, v := range b.Values {
|
|
|
|
|
if v.Op != OpStore {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
z, ok := zeroes[v.MemoryArg().ID]
|
|
|
|
|
if !ok {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
ptr := v.Args[0]
|
|
|
|
|
var off int64
|
|
|
|
|
size := v.Aux.(*types.Type).Size()
|
|
|
|
|
for ptr.Op == OpOffPtr {
|
|
|
|
|
off += ptr.AuxInt
|
|
|
|
|
ptr = ptr.Args[0]
|
|
|
|
|
}
|
|
|
|
|
if ptr != z.base {
|
|
|
|
|
// Different base object - we don't know anything.
|
|
|
|
|
// We could even be writing to the base object we know
|
|
|
|
|
// about, but through an aliased but offset pointer.
|
|
|
|
|
// So we have to throw all the zero information we have away.
|
|
|
|
|
continue
|
|
|
|
|
}
|
2019-10-06 17:38:39 -07:00
|
|
|
// Round to cover any partially written pointer slots.
|
|
|
|
|
// Pointer writes should never be unaligned like this, but non-pointer
|
|
|
|
|
// writes to pointer-containing types will do this.
|
|
|
|
|
if d := off % ptrSize; d != 0 {
|
|
|
|
|
off -= d
|
|
|
|
|
size += d
|
2019-01-04 17:34:33 -08:00
|
|
|
}
|
2019-10-06 17:38:39 -07:00
|
|
|
if d := size % ptrSize; d != 0 {
|
|
|
|
|
size += ptrSize - d
|
|
|
|
|
}
|
|
|
|
|
// Clip to the 64 words that we track.
|
|
|
|
|
min := off
|
|
|
|
|
max := off + size
|
|
|
|
|
if min < 0 {
|
|
|
|
|
min = 0
|
|
|
|
|
}
|
|
|
|
|
if max > 64*ptrSize {
|
|
|
|
|
max = 64 * ptrSize
|
|
|
|
|
}
|
|
|
|
|
// Clear bits for parts that we are writing (and hence
|
|
|
|
|
// will no longer necessarily be zero).
|
|
|
|
|
for i := min; i < max; i += ptrSize {
|
|
|
|
|
bit := i / ptrSize
|
|
|
|
|
z.mask &^= 1 << uint(bit)
|
2019-01-04 17:34:33 -08:00
|
|
|
}
|
2019-10-06 17:38:39 -07:00
|
|
|
if z.mask == 0 {
|
|
|
|
|
// No more known zeros - don't bother keeping.
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
// Save updated known zero contents for new store.
|
2019-01-04 17:34:33 -08:00
|
|
|
if zeroes[v.ID] != z {
|
|
|
|
|
zeroes[v.ID] = z
|
|
|
|
|
changed = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !changed {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-06 17:38:39 -07:00
|
|
|
if f.pass.debug > 0 {
|
|
|
|
|
fmt.Printf("func %s\n", f.Name)
|
|
|
|
|
for mem, z := range zeroes {
|
|
|
|
|
fmt.Printf(" memory=v%d ptr=%v zeromask=%b\n", mem, z.base, z.mask)
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-04 17:34:33 -08:00
|
|
|
return zeroes
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 06:57:00 -04:00
|
|
|
// wbcall emits write barrier runtime call in b, returns memory.
|
2019-03-21 13:40:28 -04:00
|
|
|
func wbcall(pos src.XPos, b *Block, fn, typ *obj.LSym, ptr, val, mem, sp, sb *Value) *Value {
|
2016-10-13 06:57:00 -04:00
|
|
|
config := b.Func.Config
|
|
|
|
|
|
|
|
|
|
// put arguments on stack
|
|
|
|
|
off := config.ctxt.FixedFrameSize()
|
|
|
|
|
|
2020-06-19 15:29:51 -04:00
|
|
|
var ACArgs []Param
|
2021-02-04 16:42:35 -05:00
|
|
|
var argTypes []*types.Type
|
2016-10-13 06:57:00 -04:00
|
|
|
if typ != nil { // for typedmemmove
|
2017-03-17 16:04:46 -07:00
|
|
|
taddr := b.NewValue1A(pos, OpAddr, b.Func.Config.Types.Uintptr, typ, sb)
|
2017-04-28 00:19:49 +00:00
|
|
|
off = round(off, taddr.Type.Alignment())
|
2016-12-08 13:49:51 -08:00
|
|
|
arg := b.NewValue1I(pos, OpOffPtr, taddr.Type.PtrTo(), off, sp)
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
mem = b.NewValue3A(pos, OpStore, types.TypeMem, ptr.Type, arg, taddr, mem)
|
2020-06-19 15:29:51 -04:00
|
|
|
ACArgs = append(ACArgs, Param{Type: b.Func.Config.Types.Uintptr, Offset: int32(off)})
|
2021-02-04 16:42:35 -05:00
|
|
|
argTypes = append(argTypes, b.Func.Config.Types.Uintptr)
|
2017-04-28 00:19:49 +00:00
|
|
|
off += taddr.Type.Size()
|
2016-10-13 06:57:00 -04:00
|
|
|
}
|
|
|
|
|
|
2017-04-28 00:19:49 +00:00
|
|
|
off = round(off, ptr.Type.Alignment())
|
2016-12-08 13:49:51 -08:00
|
|
|
arg := b.NewValue1I(pos, OpOffPtr, ptr.Type.PtrTo(), off, sp)
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
mem = b.NewValue3A(pos, OpStore, types.TypeMem, ptr.Type, arg, ptr, mem)
|
2020-06-19 15:29:51 -04:00
|
|
|
ACArgs = append(ACArgs, Param{Type: ptr.Type, Offset: int32(off)})
|
2021-02-04 16:42:35 -05:00
|
|
|
argTypes = append(argTypes, ptr.Type)
|
2017-04-28 00:19:49 +00:00
|
|
|
off += ptr.Type.Size()
|
2016-10-13 06:57:00 -04:00
|
|
|
|
2016-10-18 11:06:28 -04:00
|
|
|
if val != nil {
|
2017-04-28 00:19:49 +00:00
|
|
|
off = round(off, val.Type.Alignment())
|
2016-12-08 13:49:51 -08:00
|
|
|
arg = b.NewValue1I(pos, OpOffPtr, val.Type.PtrTo(), off, sp)
|
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>
2017-04-28 14:12:28 -07:00
|
|
|
mem = b.NewValue3A(pos, OpStore, types.TypeMem, val.Type, arg, val, mem)
|
2020-06-19 15:29:51 -04:00
|
|
|
ACArgs = append(ACArgs, Param{Type: val.Type, Offset: int32(off)})
|
2021-02-04 16:42:35 -05:00
|
|
|
argTypes = append(argTypes, val.Type)
|
2017-04-28 00:19:49 +00:00
|
|
|
off += val.Type.Size()
|
2016-10-18 11:06:28 -04:00
|
|
|
}
|
2016-10-13 06:57:00 -04:00
|
|
|
off = round(off, config.PtrSize)
|
|
|
|
|
|
|
|
|
|
// issue call
|
2021-02-04 16:42:35 -05:00
|
|
|
mem = b.NewValue1A(pos, OpStaticCall, types.TypeResultMem, StaticAuxCall(fn, ACArgs, nil, b.Func.ABIDefault.ABIAnalyzeTypes(nil, argTypes, nil)), mem)
|
2016-10-13 06:57:00 -04:00
|
|
|
mem.AuxInt = off - config.ctxt.FixedFrameSize()
|
2021-02-04 16:42:35 -05:00
|
|
|
return b.NewValue1I(pos, OpSelectN, types.TypeMem, 0, mem)
|
2016-10-13 06:57:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// round to a multiple of r, r is a power of 2
|
|
|
|
|
func round(o int64, r int64) int64 {
|
|
|
|
|
return (o + r - 1) &^ (r - 1)
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-27 12:40:16 -08:00
|
|
|
// IsStackAddr reports whether v is known to be an address of a stack slot.
|
2017-03-17 11:53:24 -04:00
|
|
|
func IsStackAddr(v *Value) bool {
|
2016-10-13 06:57:00 -04:00
|
|
|
for v.Op == OpOffPtr || v.Op == OpAddPtr || v.Op == OpPtrIndex || v.Op == OpCopy {
|
|
|
|
|
v = v.Args[0]
|
|
|
|
|
}
|
|
|
|
|
switch v.Op {
|
2020-07-27 16:46:35 -04:00
|
|
|
case OpSP, OpLocalAddr, OpSelectNAddr:
|
2016-10-13 06:57:00 -04:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2017-02-02 19:47:59 -05:00
|
|
|
|
2019-01-04 17:34:33 -08:00
|
|
|
// IsGlobalAddr reports whether v is known to be an address of a global (or nil).
|
2018-11-27 12:40:16 -08:00
|
|
|
func IsGlobalAddr(v *Value) bool {
|
2019-01-04 17:34:33 -08:00
|
|
|
if v.Op == OpAddr && v.Args[0].Op == OpSB {
|
|
|
|
|
return true // address of a global
|
|
|
|
|
}
|
2019-09-04 17:45:50 -07:00
|
|
|
if v.Op == OpConstNil {
|
|
|
|
|
return true
|
2019-01-04 17:34:33 -08:00
|
|
|
}
|
2019-10-06 17:38:39 -07:00
|
|
|
if v.Op == OpLoad && IsReadOnlyGlobalAddr(v.Args[0]) {
|
|
|
|
|
return true // loading from a read-only global - the resulting address can't be a heap address.
|
|
|
|
|
}
|
2019-01-04 17:34:33 -08:00
|
|
|
return false
|
2018-11-27 12:40:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsReadOnlyGlobalAddr reports whether v is known to be an address of a read-only global.
|
|
|
|
|
func IsReadOnlyGlobalAddr(v *Value) bool {
|
2019-09-04 17:45:50 -07:00
|
|
|
if v.Op == OpConstNil {
|
2019-08-02 10:36:03 -07:00
|
|
|
// Nil pointers are read only. See issue 33438.
|
|
|
|
|
return true
|
|
|
|
|
}
|
2020-04-28 10:20:55 -07:00
|
|
|
if v.Op == OpAddr && v.Aux.(*obj.LSym).Type == objabi.SRODATA {
|
2019-10-06 17:38:39 -07:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
2018-11-27 12:40:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsNewObject reports whether v is a pointer to a freshly allocated & zeroed object at memory state mem.
|
|
|
|
|
func IsNewObject(v *Value, mem *Value) bool {
|
2021-02-04 16:42:35 -05:00
|
|
|
// TODO this will need updating for register args; the OpLoad is wrong.
|
2018-11-27 12:40:16 -08:00
|
|
|
if v.Op != OpLoad {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if v.MemoryArg() != mem {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2021-02-04 16:42:35 -05:00
|
|
|
if mem.Op != OpSelectN {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if mem.Type != types.TypeMem {
|
|
|
|
|
return false
|
|
|
|
|
} // assume it is the right selection if true
|
|
|
|
|
mem = mem.Args[0]
|
2018-11-27 12:40:16 -08:00
|
|
|
if mem.Op != OpStaticCall {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2020-06-12 13:48:26 -04:00
|
|
|
if !isSameCall(mem.Aux, "runtime.newobject") {
|
2018-11-27 12:40:16 -08:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if v.Args[0].Op != OpOffPtr {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if v.Args[0].Args[0].Op != OpSP {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
c := v.Block.Func.Config
|
|
|
|
|
if v.Args[0].AuxInt != c.ctxt.FixedFrameSize()+c.RegSize { // offset of return value
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-27 13:50:08 -07:00
|
|
|
// IsSanitizerSafeAddr reports whether v is known to be an address
|
|
|
|
|
// that doesn't need instrumentation.
|
|
|
|
|
func IsSanitizerSafeAddr(v *Value) bool {
|
|
|
|
|
for v.Op == OpOffPtr || v.Op == OpAddPtr || v.Op == OpPtrIndex || v.Op == OpCopy {
|
|
|
|
|
v = v.Args[0]
|
|
|
|
|
}
|
|
|
|
|
switch v.Op {
|
2020-07-27 16:46:35 -04:00
|
|
|
case OpSP, OpLocalAddr, OpSelectNAddr:
|
2018-03-27 13:50:08 -07:00
|
|
|
// Stack addresses are always safe.
|
|
|
|
|
return true
|
|
|
|
|
case OpITab, OpStringPtr, OpGetClosurePtr:
|
|
|
|
|
// Itabs, string data, and closure fields are
|
|
|
|
|
// read-only once initialized.
|
|
|
|
|
return true
|
|
|
|
|
case OpAddr:
|
2020-04-28 10:20:55 -07:00
|
|
|
return v.Aux.(*obj.LSym).Type == objabi.SRODATA
|
2018-03-27 13:50:08 -07:00
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-27 12:40:16 -08:00
|
|
|
// isVolatile reports whether v is a pointer to argument region on stack which
|
2017-02-02 19:47:59 -05:00
|
|
|
// will be clobbered by a function call.
|
|
|
|
|
func isVolatile(v *Value) bool {
|
2020-07-27 16:46:35 -04:00
|
|
|
for v.Op == OpOffPtr || v.Op == OpAddPtr || v.Op == OpPtrIndex || v.Op == OpCopy || v.Op == OpSelectNAddr {
|
2017-02-02 19:47:59 -05:00
|
|
|
v = v.Args[0]
|
|
|
|
|
}
|
|
|
|
|
return v.Op == OpSP
|
|
|
|
|
}
|