github.com/zebozhuang/go@v0.0.0-20200207033046-f8a98f6f5c5d/src/cmd/compile/internal/ssa/cache.go (about)

     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 "sort"
     8  
     9  // A Cache holds reusable compiler state.
    10  // It is intended to be re-used for multiple Func compilations.
    11  type Cache struct {
    12  	// Storage for low-numbered values and blocks.
    13  	values [2000]Value
    14  	blocks [200]Block
    15  	locs   [2000]Location
    16  
    17  	// Reusable stackAllocState.
    18  	// See stackalloc.go's {new,put}StackAllocState.
    19  	stackAllocState *stackAllocState
    20  
    21  	domblockstore []ID         // scratch space for computing dominators
    22  	scrSparse     []*sparseSet // scratch sparse sets to be re-used.
    23  }
    24  
    25  func (c *Cache) Reset() {
    26  	nv := sort.Search(len(c.values), func(i int) bool { return c.values[i].ID == 0 })
    27  	xv := c.values[:nv]
    28  	for i := range xv {
    29  		xv[i] = Value{}
    30  	}
    31  	nb := sort.Search(len(c.blocks), func(i int) bool { return c.blocks[i].ID == 0 })
    32  	xb := c.blocks[:nb]
    33  	for i := range xb {
    34  		xb[i] = Block{}
    35  	}
    36  	nl := sort.Search(len(c.locs), func(i int) bool { return c.locs[i] == nil })
    37  	xl := c.locs[:nl]
    38  	for i := range xl {
    39  		xl[i] = nil
    40  	}
    41  }