cmd/compile: add cache of sizeable objects so they can be reused

We kind of have this mechanism already, just normalizing it and
using it in a bunch of places. Previously a bunch of places cached
slices only for the duration of a single function compilation. Now
we can reuse slices across a whole compiler run.

Use a sync.Pool of powers-of-two sizes. This lets us use not
too much memory, and avoid holding onto memory we're no longer
using when a GC happens.

There's a few different types we need, so generate the code for it.
Generics would be useful here, but we can't use generics in the
compiler because of bootstrapping.

Change-Id: I6cf37e7b7b2e802882aaa723a0b29770511ccd82
Reviewed-on: https://go-review.googlesource.com/c/go/+/444820
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Keith Randall 2022-10-18 16:07:36 -07:00 committed by Keith Randall
parent 7ddc45263c
commit 68bd383368
21 changed files with 656 additions and 213 deletions

View file

@ -20,9 +20,12 @@ func layoutRegallocOrder(f *Func) []*Block {
func layoutOrder(f *Func) []*Block {
order := make([]*Block, 0, f.NumBlocks())
scheduled := make([]bool, f.NumBlocks())
idToBlock := make([]*Block, f.NumBlocks())
indegree := make([]int, f.NumBlocks())
scheduled := f.Cache.allocBoolSlice(f.NumBlocks())
defer f.Cache.freeBoolSlice(scheduled)
idToBlock := f.Cache.allocBlockSlice(f.NumBlocks())
defer f.Cache.freeBlockSlice(idToBlock)
indegree := f.Cache.allocIntSlice(f.NumBlocks())
defer f.Cache.freeIntSlice(indegree)
posdegree := f.newSparseSet(f.NumBlocks()) // blocks with positive remaining degree
defer f.retSparseSet(posdegree)
// blocks with zero remaining degree. Use slice to simulate a LIFO queue to implement