Source file src/cmd/compile/internal/ssa/cache.go

     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  	"sort"
     9  
    10  	"cmd/internal/obj"
    11  )
    12  
    13  // A Cache holds reusable compiler state.
    14  // It is intended to be re-used for multiple Func compilations.
    15  type Cache struct {
    16  	// Storage for low-numbered values and blocks.
    17  	values [2000]Value
    18  	blocks [200]Block
    19  	Locs   [2000]Location
    20  
    21  	// Reusable stackAllocState.
    22  	// See stackalloc.go's {new,put}StackAllocState.
    23  	stackAllocState *StackAllocState
    24  
    25  	scrPoset []*Poset // scratch poset to be reused
    26  
    27  	// Reusable regalloc state.
    28  	RegallocValues []ValState
    29  
    30  	ValueToProgAfter []*obj.Prog
    31  	DebugState       DebugState
    32  
    33  	Liveness any // *gc.livenessFuncCache
    34  
    35  	// Free "headers" for use by the allocators in allocators.go.
    36  	// Used to put slices in sync.Pools without allocation.
    37  	hdrValueSlice []*[]*Value
    38  	hdrLimitSlice []*[]Limit
    39  }
    40  
    41  func (c *Cache) Reset() {
    42  	nv := sort.Search(len(c.values), func(i int) bool { return c.values[i].ID == 0 })
    43  	clear(c.values[:nv])
    44  	nb := sort.Search(len(c.blocks), func(i int) bool { return c.blocks[i].ID == 0 })
    45  	clear(c.blocks[:nb])
    46  	nl := sort.Search(len(c.Locs), func(i int) bool { return c.Locs[i] == nil })
    47  	clear(c.Locs[:nl])
    48  
    49  	// regalloc sets the length of c.regallocValues to whatever it may use,
    50  	// so clear according to length.
    51  	clear(c.RegallocValues)
    52  }
    53  

View as plain text