diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2017-03-15 11:15:13 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2017-03-17 05:21:42 +0000 |
commit | a5e3cac89587d2d6235e9a7217185dee9be6852a (patch) | |
tree | 016d9b235505e45e7938769e19ae7ce58b78995b /src/cmd/compile/internal/ssa/cache.go | |
parent | ccaa8e3c6fbba08f238c5ccea437b7cac513685f (diff) | |
download | go-a5e3cac89587d2d6235e9a7217185dee9be6852a.tar.gz go-a5e3cac89587d2d6235e9a7217185dee9be6852a.zip |
cmd/compile: rearrange fields between ssa.Func, ssa.Cache, and ssa.Config
This makes ssa.Func, ssa.Cache, and ssa.Config fulfill
the roles laid out for them in CL 38160.
The only non-trivial change in this CL is how cached
values and blocks get IDs. Prior to this CL, their IDs were
assigned as part of resetting the cache, and only modified
IDs were reset. This required knowing how many values and
blocks were modified, which required a tight coupling between
ssa.Func and ssa.Config. To eliminate that coupling,
we now zero values and blocks during reset,
and assign their IDs when they are used.
Since unused values and blocks have ID == 0,
we can efficiently find the last used value/block,
to avoid zeroing everything.
Bulk zeroing is efficient, but not efficient enough
to obviate the need to avoid zeroing everything every time.
As a happy side-effect, ssa.Func.Free is no longer necessary.
DebugHashMatch and friends now belong in func.go.
They have been left in place for clarity and review.
I will move them in a subsequent CL.
Passes toolstash -cmp. No compiler performance impact.
No change in 'go test cmd/compile/internal/ssa' execution time.
Change-Id: I2eb7af58da067ef6a36e815a6f386cfe8634d098
Reviewed-on: https://go-review.googlesource.com/38167
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/cache.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/cache.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/cache.go b/src/cmd/compile/internal/ssa/cache.go index 64f9659520..f1018da497 100644 --- a/src/cmd/compile/internal/ssa/cache.go +++ b/src/cmd/compile/internal/ssa/cache.go @@ -4,7 +4,38 @@ package ssa +import "sort" + // A Cache holds reusable compiler state. // It is intended to be re-used for multiple Func compilations. type Cache struct { + // Storage for low-numbered values and blocks. + values [2000]Value + blocks [200]Block + locs [2000]Location + + // Reusable stackAllocState. + // See stackalloc.go's {new,put}StackAllocState. + stackAllocState *stackAllocState + + domblockstore []ID // scratch space for computing dominators + scrSparse []*sparseSet // scratch sparse sets to be re-used. +} + +func (c *Cache) Reset() { + nv := sort.Search(len(c.values), func(i int) bool { return c.values[i].ID == 0 }) + xv := c.values[:nv] + for i := range xv { + xv[i] = Value{} + } + nb := sort.Search(len(c.blocks), func(i int) bool { return c.blocks[i].ID == 0 }) + xb := c.blocks[:nb] + for i := range xb { + xb[i] = Block{} + } + nl := sort.Search(len(c.locs), func(i int) bool { return c.locs[i] == nil }) + xl := c.locs[:nl] + for i := range xl { + xl[i] = nil + } } |