stackAllocState *stackAllocState
domblockstore []ID // scratch space for computing dominators
- scrSparse []*sparseSet // scratch sparse sets to be re-used.
+ scrSparseSet []*sparseSet // scratch sparse sets to be re-used.
+ scrSparseMap []*sparseMap // scratch sparse maps to be re-used.
ValueToProgAfter []*obj.Prog
debugState debugState
defer f.retSparseSet(loadUse)
storeUse := f.newSparseSet(f.NumValues())
defer f.retSparseSet(storeUse)
- shadowed := newSparseMap(f.NumValues()) // TODO: cache
+ shadowed := f.newSparseMap(f.NumValues())
+ defer f.retSparseMap(shadowed)
for _, b := range f.Blocks {
// Find all the stores in this block. Categorize their uses:
// loadUse contains stores which are used by a subsequent load.
// 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.Cache.scrSparse {
+ for i, scr := range f.Cache.scrSparseSet {
if scr != nil && scr.cap() >= n {
- f.Cache.scrSparse[i] = nil
+ f.Cache.scrSparseSet[i] = nil
scr.clear()
return scr
}
return newSparseSet(n)
}
-// retSparseSet returns a sparse set to the config's cache of sparse sets 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.Cache.scrSparse {
+ for i, scr := range f.Cache.scrSparseSet {
if scr == nil {
- f.Cache.scrSparse[i] = ss
+ f.Cache.scrSparseSet[i] = ss
return
}
}
- f.Cache.scrSparse = append(f.Cache.scrSparse, ss)
+ f.Cache.scrSparseSet = append(f.Cache.scrSparseSet, ss)
+}
+
+// newSparseMap returns a sparse map that can store at least up to n integers.
+func (f *Func) newSparseMap(n int) *sparseMap {
+ for i, scr := range f.Cache.scrSparseMap {
+ if scr != nil && scr.cap() >= n {
+ f.Cache.scrSparseMap[i] = nil
+ scr.clear()
+ return scr
+ }
+ }
+ return newSparseMap(n)
+}
+
+// retSparseMap returns a sparse map to the config's cache of sparse
+// sets to be reused by f.newSparseMap.
+func (f *Func) retSparseMap(ss *sparseMap) {
+ for i, scr := range f.Cache.scrSparseMap {
+ if scr == nil {
+ f.Cache.scrSparseMap[i] = ss
+ return
+ }
+ }
+ f.Cache.scrSparseMap = append(f.Cache.scrSparseMap, ss)
}
// newValue allocates a new Value with the given fields and places it at the end of b.Values.
s.desired = make([]desiredState, f.NumBlocks())
var phis []*Value
- live := newSparseMap(f.NumValues())
- t := newSparseMap(f.NumValues())
+ live := f.newSparseMap(f.NumValues())
+ defer f.retSparseMap(live)
+ t := f.newSparseMap(f.NumValues())
+ defer f.retSparseMap(t)
// Keep track of which value we want in each register.
var desired desiredState