]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: cache sparse sets in Config
authorTodd Neal <todd@tneal.org>
Tue, 2 Feb 2016 11:35:34 +0000 (06:35 -0500)
committerTodd Neal <todd@tneal.org>
Tue, 2 Feb 2016 18:08:46 +0000 (18:08 +0000)
Move the cached sparse sets to the Config.  I tested make.bash with
pre-allocating sets of size 150 and not caching very small sets, but the
difference between this implementation (no min size, no preallocation)
and a min size with preallocation was fairly negligible:

Number of sparse sets allocated:
Cached in Config w/none preallocated no min size    3684 *this CL*
Cached in Config w/three preallocated no min size   3370
Cached in Config w/three preallocated min size=150  3370
Cached in Config w/none preallocated min size=150  15947
Cached in Func,  w/no min                          96996 *previous code*

Change-Id: I7f9de8a7cae192648a7413bfb18a6690fad34375
Reviewed-on: https://go-review.googlesource.com/19152
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/func.go

index 060eec233585b41feb06e238e8242d2806c71529..530c48000417237027408b3fe6dc57828a38c5d3 100644 (file)
@@ -23,6 +23,8 @@ type Config struct {
        // Storage for low-numbered values and blocks.
        values [2000]Value
        blocks [200]Block
+
+       scrSparse []*sparseSet // scratch sparse sets to be re-used.
 }
 
 type TypeSource interface {
index 9da390904d8ac3d4ae5c284f4d94975e0cc0fb1a..6e101ec1cbb3841d7957f360f875c4d187f8ce7d 100644 (file)
@@ -31,8 +31,6 @@ type Func struct {
 
        freeValues *Value // free Values linked by argstorage[0].  All other fields except ID are 0/nil.
        freeBlocks *Block // free Blocks linked by succstorage[0].  All other fields except ID are 0/nil.
-
-       scrSparse []*sparseSet // sparse sets to be re-used.
 }
 
 // NumBlocks returns an integer larger than the id of any Block in the Func.
@@ -47,9 +45,9 @@ func (f *Func) NumValues() int {
 
 // newSparseSet returns a sparse set that can store at least up to n integers.
 func (f *Func) newSparseSet(n int) *sparseSet {
-       for i, scr := range f.scrSparse {
+       for i, scr := range f.Config.scrSparse {
                if scr != nil && scr.cap() >= n {
-                       f.scrSparse[i] = nil
+                       f.Config.scrSparse[i] = nil
                        scr.clear()
                        return scr
                }
@@ -57,15 +55,15 @@ func (f *Func) newSparseSet(n int) *sparseSet {
        return newSparseSet(n)
 }
 
-// retSparseSet returns a sparse set to the function's cache to be reused by f.newSparseSet.
+// retSparseSet returns a sparse set to the config's cache of sparse sets to be reused by f.newSparseSet.
 func (f *Func) retSparseSet(ss *sparseSet) {
-       for i, scr := range f.scrSparse {
+       for i, scr := range f.Config.scrSparse {
                if scr == nil {
-                       f.scrSparse[i] = ss
+                       f.Config.scrSparse[i] = ss
                        return
                }
        }
-       f.scrSparse = append(f.scrSparse, ss)
+       f.Config.scrSparse = append(f.Config.scrSparse, ss)
 }
 
 // newValue allocates a new Value with the given fields and places it at the end of b.Values.