| 1 |
// Copyright 2017 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package ssa |
| 6 |
|
| 7 |
import ( |
| 8 |
"cmd/internal/obj" |
| 9 |
"sort" |
| 10 |
) |
| 11 |
|
| 12 |
// A Cache holds reusable compiler state. |
| 13 |
// It is intended to be re-used for multiple Func compilations. |
| 14 |
type Cache struct { |
| 15 |
// Storage for low-numbered values and blocks. |
| 16 |
values [2000]Value |
| 17 |
blocks [200]Block |
| 18 |
locs [2000]Location |
| 19 |
|
| 20 |
// Reusable stackAllocState. |
| 21 |
// See stackalloc.go's {new,put}StackAllocState. |
| 22 |
stackAllocState *stackAllocState |
| 23 |
|
| 24 |
scrPoset []*poset // scratch poset to be reused |
| 25 |
|
| 26 |
// Reusable regalloc state. |
| 27 |
regallocValues []valState |
| 28 |
|
| 29 |
ValueToProgAfter []*obj.Prog |
| 30 |
debugState debugState |
| 31 |
|
| 32 |
Liveness any // *gc.livenessFuncCache |
| 33 |
|
| 34 |
// Free "headers" for use by the allocators in allocators.go. |
| 35 |
// Used to put slices in sync.Pools without allocation. |
| 36 |
hdrValueSlice []*[]*Value |
| 37 |
hdrLimitSlice []*[]limit |
| 38 |
} |
| 39 |
|
| 40 |
func (c *Cache) Reset() { |
| 41 |
nv := sort.Search(len(c.values), func(i int) bool { return c.values[i].ID == 0 }) |
| 42 |
clear(c.values[:nv]) |
| 43 |
nb := sort.Search(len(c.blocks), func(i int) bool { return c.blocks[i].ID == 0 }) |
| 44 |
clear(c.blocks[:nb]) |
| 45 |
nl := sort.Search(len(c.locs), func(i int) bool { return c.locs[i] == nil }) |
| 46 |
clear(c.locs[:nl]) |
| 47 |
|
| 48 |
// regalloc sets the length of c.regallocValues to whatever it may use, |
| 49 |
// so clear according to length. |
| 50 |
clear(c.regallocValues) |
| 51 |
} |